repo stringlengths 6 63 | path stringlengths 5 140 | func_name stringlengths 3 151 | original_string stringlengths 84 13k | language stringclasses 1 value | code stringlengths 84 13k | code_tokens list | docstring stringlengths 3 47.2k | docstring_tokens list | sha stringlengths 40 40 | url stringlengths 91 247 | partition stringclasses 1 value |
|---|---|---|---|---|---|---|---|---|---|---|---|
sulu/sulu | src/Sulu/Component/Rest/Listing/ListRestHelper.php | ListRestHelper.getSorting | public function getSorting()
{
$sortOrder = $this->getRequest()->get('sortOrder', 'asc');
$sortBy = $this->getRequest()->get('sortBy', 'id');
return [$sortBy => $sortOrder];
} | php | public function getSorting()
{
$sortOrder = $this->getRequest()->get('sortOrder', 'asc');
$sortBy = $this->getRequest()->get('sortBy', 'id');
return [$sortBy => $sortOrder];
} | [
"public",
"function",
"getSorting",
"(",
")",
"{",
"$",
"sortOrder",
"=",
"$",
"this",
"->",
"getRequest",
"(",
")",
"->",
"get",
"(",
"'sortOrder'",
",",
"'asc'",
")",
";",
"$",
"sortBy",
"=",
"$",
"this",
"->",
"getRequest",
"(",
")",
"->",
"get",
"(",
"'sortBy'",
",",
"'id'",
")",
";",
"return",
"[",
"$",
"sortBy",
"=>",
"$",
"sortOrder",
"]",
";",
"}"
] | Returns an array containing the desired sorting.
@return array | [
"Returns",
"an",
"array",
"containing",
"the",
"desired",
"sorting",
"."
] | 6766a36cc2f0c807c59202bf7540a08c4ef31192 | https://github.com/sulu/sulu/blob/6766a36cc2f0c807c59202bf7540a08c4ef31192/src/Sulu/Component/Rest/Listing/ListRestHelper.php#L102-L108 | train |
sulu/sulu | src/Sulu/Component/Rest/Listing/ListRestHelper.php | ListRestHelper.getOffset | public function getOffset()
{
$page = $this->getRequest()->get('page', 1);
$limit = $this->getRequest()->get('limit');
return (null != $limit) ? $limit * ($page - 1) : null;
} | php | public function getOffset()
{
$page = $this->getRequest()->get('page', 1);
$limit = $this->getRequest()->get('limit');
return (null != $limit) ? $limit * ($page - 1) : null;
} | [
"public",
"function",
"getOffset",
"(",
")",
"{",
"$",
"page",
"=",
"$",
"this",
"->",
"getRequest",
"(",
")",
"->",
"get",
"(",
"'page'",
",",
"1",
")",
";",
"$",
"limit",
"=",
"$",
"this",
"->",
"getRequest",
"(",
")",
"->",
"get",
"(",
"'limit'",
")",
";",
"return",
"(",
"null",
"!=",
"$",
"limit",
")",
"?",
"$",
"limit",
"*",
"(",
"$",
"page",
"-",
"1",
")",
":",
"null",
";",
"}"
] | Returns the calculated value for the starting position based
on the page and limit values.
@return int|null | [
"Returns",
"the",
"calculated",
"value",
"for",
"the",
"starting",
"position",
"based",
"on",
"the",
"page",
"and",
"limit",
"values",
"."
] | 6766a36cc2f0c807c59202bf7540a08c4ef31192 | https://github.com/sulu/sulu/blob/6766a36cc2f0c807c59202bf7540a08c4ef31192/src/Sulu/Component/Rest/Listing/ListRestHelper.php#L126-L132 | train |
sulu/sulu | src/Sulu/Component/Rest/Listing/ListRestHelper.php | ListRestHelper.getTotalPages | public function getTotalPages($totalNumber = null)
{
if (is_null($totalNumber)) {
$totalNumber = $this->totalNumberOfElements;
}
return $this->getLimit() ? (ceil($totalNumber / $this->getLimit())) : 1;
} | php | public function getTotalPages($totalNumber = null)
{
if (is_null($totalNumber)) {
$totalNumber = $this->totalNumberOfElements;
}
return $this->getLimit() ? (ceil($totalNumber / $this->getLimit())) : 1;
} | [
"public",
"function",
"getTotalPages",
"(",
"$",
"totalNumber",
"=",
"null",
")",
"{",
"if",
"(",
"is_null",
"(",
"$",
"totalNumber",
")",
")",
"{",
"$",
"totalNumber",
"=",
"$",
"this",
"->",
"totalNumberOfElements",
";",
"}",
"return",
"$",
"this",
"->",
"getLimit",
"(",
")",
"?",
"(",
"ceil",
"(",
"$",
"totalNumber",
"/",
"$",
"this",
"->",
"getLimit",
"(",
")",
")",
")",
":",
"1",
";",
"}"
] | returns total amount of pages.
@param int $totalNumber if not defined the total number is requested from DB
@return float|int | [
"returns",
"total",
"amount",
"of",
"pages",
"."
] | 6766a36cc2f0c807c59202bf7540a08c4ef31192 | https://github.com/sulu/sulu/blob/6766a36cc2f0c807c59202bf7540a08c4ef31192/src/Sulu/Component/Rest/Listing/ListRestHelper.php#L151-L158 | train |
sulu/sulu | src/Sulu/Bundle/SecurityBundle/EventListener/SuluSecurityListener.php | SuluSecurityListener.onKernelController | public function onKernelController(FilterControllerEvent $event)
{
$controllerDefinition = $event->getController();
$controller = $controllerDefinition[0];
if (
!$controller instanceof SecuredControllerInterface &&
!$controller instanceof SecuredObjectControllerInterface
) {
return;
}
$request = $event->getRequest();
// find appropriate permission type for request
$permission = '';
switch ($request->getMethod()) {
case 'GET':
$permission = PermissionTypes::VIEW;
break;
case 'POST':
if ('postAction' == $controllerDefinition[1]) { // means that the ClassResourceInterface has to be used
$permission = PermissionTypes::ADD;
} else {
$permission = PermissionTypes::EDIT;
}
break;
case 'PUT':
case 'PATCH':
$permission = PermissionTypes::EDIT;
break;
case 'DELETE':
$permission = PermissionTypes::DELETE;
break;
}
$securityContext = null;
$locale = $controller->getLocale($request);
$objectType = null;
$objectId = null;
if ($controller instanceof SecuredObjectControllerInterface) {
$objectType = $controller->getSecuredClass();
$objectId = $controller->getSecuredObjectId($request);
}
// check permission
if ($controller instanceof SecuredControllerInterface) {
$securityContext = $controller->getSecurityContext();
}
if (null !== $securityContext) {
$this->securityChecker->checkPermission(
new SecurityCondition($securityContext, $locale, $objectType, $objectId),
$permission
);
}
} | php | public function onKernelController(FilterControllerEvent $event)
{
$controllerDefinition = $event->getController();
$controller = $controllerDefinition[0];
if (
!$controller instanceof SecuredControllerInterface &&
!$controller instanceof SecuredObjectControllerInterface
) {
return;
}
$request = $event->getRequest();
// find appropriate permission type for request
$permission = '';
switch ($request->getMethod()) {
case 'GET':
$permission = PermissionTypes::VIEW;
break;
case 'POST':
if ('postAction' == $controllerDefinition[1]) { // means that the ClassResourceInterface has to be used
$permission = PermissionTypes::ADD;
} else {
$permission = PermissionTypes::EDIT;
}
break;
case 'PUT':
case 'PATCH':
$permission = PermissionTypes::EDIT;
break;
case 'DELETE':
$permission = PermissionTypes::DELETE;
break;
}
$securityContext = null;
$locale = $controller->getLocale($request);
$objectType = null;
$objectId = null;
if ($controller instanceof SecuredObjectControllerInterface) {
$objectType = $controller->getSecuredClass();
$objectId = $controller->getSecuredObjectId($request);
}
// check permission
if ($controller instanceof SecuredControllerInterface) {
$securityContext = $controller->getSecurityContext();
}
if (null !== $securityContext) {
$this->securityChecker->checkPermission(
new SecurityCondition($securityContext, $locale, $objectType, $objectId),
$permission
);
}
} | [
"public",
"function",
"onKernelController",
"(",
"FilterControllerEvent",
"$",
"event",
")",
"{",
"$",
"controllerDefinition",
"=",
"$",
"event",
"->",
"getController",
"(",
")",
";",
"$",
"controller",
"=",
"$",
"controllerDefinition",
"[",
"0",
"]",
";",
"if",
"(",
"!",
"$",
"controller",
"instanceof",
"SecuredControllerInterface",
"&&",
"!",
"$",
"controller",
"instanceof",
"SecuredObjectControllerInterface",
")",
"{",
"return",
";",
"}",
"$",
"request",
"=",
"$",
"event",
"->",
"getRequest",
"(",
")",
";",
"// find appropriate permission type for request",
"$",
"permission",
"=",
"''",
";",
"switch",
"(",
"$",
"request",
"->",
"getMethod",
"(",
")",
")",
"{",
"case",
"'GET'",
":",
"$",
"permission",
"=",
"PermissionTypes",
"::",
"VIEW",
";",
"break",
";",
"case",
"'POST'",
":",
"if",
"(",
"'postAction'",
"==",
"$",
"controllerDefinition",
"[",
"1",
"]",
")",
"{",
"// means that the ClassResourceInterface has to be used",
"$",
"permission",
"=",
"PermissionTypes",
"::",
"ADD",
";",
"}",
"else",
"{",
"$",
"permission",
"=",
"PermissionTypes",
"::",
"EDIT",
";",
"}",
"break",
";",
"case",
"'PUT'",
":",
"case",
"'PATCH'",
":",
"$",
"permission",
"=",
"PermissionTypes",
"::",
"EDIT",
";",
"break",
";",
"case",
"'DELETE'",
":",
"$",
"permission",
"=",
"PermissionTypes",
"::",
"DELETE",
";",
"break",
";",
"}",
"$",
"securityContext",
"=",
"null",
";",
"$",
"locale",
"=",
"$",
"controller",
"->",
"getLocale",
"(",
"$",
"request",
")",
";",
"$",
"objectType",
"=",
"null",
";",
"$",
"objectId",
"=",
"null",
";",
"if",
"(",
"$",
"controller",
"instanceof",
"SecuredObjectControllerInterface",
")",
"{",
"$",
"objectType",
"=",
"$",
"controller",
"->",
"getSecuredClass",
"(",
")",
";",
"$",
"objectId",
"=",
"$",
"controller",
"->",
"getSecuredObjectId",
"(",
"$",
"request",
")",
";",
"}",
"// check permission",
"if",
"(",
"$",
"controller",
"instanceof",
"SecuredControllerInterface",
")",
"{",
"$",
"securityContext",
"=",
"$",
"controller",
"->",
"getSecurityContext",
"(",
")",
";",
"}",
"if",
"(",
"null",
"!==",
"$",
"securityContext",
")",
"{",
"$",
"this",
"->",
"securityChecker",
"->",
"checkPermission",
"(",
"new",
"SecurityCondition",
"(",
"$",
"securityContext",
",",
"$",
"locale",
",",
"$",
"objectType",
",",
"$",
"objectId",
")",
",",
"$",
"permission",
")",
";",
"}",
"}"
] | Checks if the action is allowed for the current user, and throws an Exception otherwise.
@param FilterControllerEvent $event
@throws AccessDeniedException | [
"Checks",
"if",
"the",
"action",
"is",
"allowed",
"for",
"the",
"current",
"user",
"and",
"throws",
"an",
"Exception",
"otherwise",
"."
] | 6766a36cc2f0c807c59202bf7540a08c4ef31192 | https://github.com/sulu/sulu/blob/6766a36cc2f0c807c59202bf7540a08c4ef31192/src/Sulu/Bundle/SecurityBundle/EventListener/SuluSecurityListener.php#L44-L102 | train |
sulu/sulu | src/Sulu/Component/CustomUrl/Generator/Generator.php | Generator.localizeDomain | protected function localizeDomain($domain, Localization $locale)
{
if (!$this->urlReplacer->hasLocalizationReplacer($domain)
&& !$this->urlReplacer->hasLanguageReplacer($domain)
) {
$domain = $this->urlReplacer->appendLocalizationReplacer($domain);
}
$domain = $this->urlReplacer->replaceLanguage($domain, $locale->getLanguage());
$domain = $this->urlReplacer->replaceCountry($domain, $locale->getCountry());
$domain = $this->urlReplacer->replaceLocalization($domain, $locale->getLocale());
return $this->urlReplacer->cleanup($domain);
} | php | protected function localizeDomain($domain, Localization $locale)
{
if (!$this->urlReplacer->hasLocalizationReplacer($domain)
&& !$this->urlReplacer->hasLanguageReplacer($domain)
) {
$domain = $this->urlReplacer->appendLocalizationReplacer($domain);
}
$domain = $this->urlReplacer->replaceLanguage($domain, $locale->getLanguage());
$domain = $this->urlReplacer->replaceCountry($domain, $locale->getCountry());
$domain = $this->urlReplacer->replaceLocalization($domain, $locale->getLocale());
return $this->urlReplacer->cleanup($domain);
} | [
"protected",
"function",
"localizeDomain",
"(",
"$",
"domain",
",",
"Localization",
"$",
"locale",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"urlReplacer",
"->",
"hasLocalizationReplacer",
"(",
"$",
"domain",
")",
"&&",
"!",
"$",
"this",
"->",
"urlReplacer",
"->",
"hasLanguageReplacer",
"(",
"$",
"domain",
")",
")",
"{",
"$",
"domain",
"=",
"$",
"this",
"->",
"urlReplacer",
"->",
"appendLocalizationReplacer",
"(",
"$",
"domain",
")",
";",
"}",
"$",
"domain",
"=",
"$",
"this",
"->",
"urlReplacer",
"->",
"replaceLanguage",
"(",
"$",
"domain",
",",
"$",
"locale",
"->",
"getLanguage",
"(",
")",
")",
";",
"$",
"domain",
"=",
"$",
"this",
"->",
"urlReplacer",
"->",
"replaceCountry",
"(",
"$",
"domain",
",",
"$",
"locale",
"->",
"getCountry",
"(",
")",
")",
";",
"$",
"domain",
"=",
"$",
"this",
"->",
"urlReplacer",
"->",
"replaceLocalization",
"(",
"$",
"domain",
",",
"$",
"locale",
"->",
"getLocale",
"(",
")",
")",
";",
"return",
"$",
"this",
"->",
"urlReplacer",
"->",
"cleanup",
"(",
"$",
"domain",
")",
";",
"}"
] | Localize given domain.
@param string $domain
@param Localization $locale
@return string | [
"Localize",
"given",
"domain",
"."
] | 6766a36cc2f0c807c59202bf7540a08c4ef31192 | https://github.com/sulu/sulu/blob/6766a36cc2f0c807c59202bf7540a08c4ef31192/src/Sulu/Component/CustomUrl/Generator/Generator.php#L66-L79 | train |
sulu/sulu | src/Sulu/Component/DocumentManager/PathBuilder.php | PathBuilder.build | public function build(array $segments)
{
$results = [];
foreach ($segments as $segment) {
$result = $this->buildSegment($segment);
if (null === $result) {
continue;
}
$results[] = $result;
}
return '/' . implode('/', $results);
} | php | public function build(array $segments)
{
$results = [];
foreach ($segments as $segment) {
$result = $this->buildSegment($segment);
if (null === $result) {
continue;
}
$results[] = $result;
}
return '/' . implode('/', $results);
} | [
"public",
"function",
"build",
"(",
"array",
"$",
"segments",
")",
"{",
"$",
"results",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"segments",
"as",
"$",
"segment",
")",
"{",
"$",
"result",
"=",
"$",
"this",
"->",
"buildSegment",
"(",
"$",
"segment",
")",
";",
"if",
"(",
"null",
"===",
"$",
"result",
")",
"{",
"continue",
";",
"}",
"$",
"results",
"[",
"]",
"=",
"$",
"result",
";",
"}",
"return",
"'/'",
".",
"implode",
"(",
"'/'",
",",
"$",
"results",
")",
";",
"}"
] | Build a path from an array of path segments.
Segments demarcated by "%" characters will be interpreted as path
segment *names* and their value will be resolved from the PathSegmentRegistry.
Other segments will be interpreted literally.
The following:
````
$path = $pathBuilder->build(array('%base%', 'hello', '%articles%'));
````
Will yield `/cms/hello/articleDirectory` where `%base%` is "cms" and
`%articles` is "articleDirectory"
@see Sulu\Component\DocumentManager\PathSegmentRegistry
@param array $segments
@return string | [
"Build",
"a",
"path",
"from",
"an",
"array",
"of",
"path",
"segments",
"."
] | 6766a36cc2f0c807c59202bf7540a08c4ef31192 | https://github.com/sulu/sulu/blob/6766a36cc2f0c807c59202bf7540a08c4ef31192/src/Sulu/Component/DocumentManager/PathBuilder.php#L55-L69 | train |
sulu/sulu | src/Sulu/Bundle/ResourceBundle/DependencyInjection/SuluResourceExtension.php | SuluResourceExtension.createOrGetFolder | private function createOrGetFolder($directory, ContainerBuilder $container)
{
$filesystem = new Filesystem();
$directory = $container->getParameterBag()->resolveValue($directory);
if (!file_exists($directory)) {
$filesystem->mkdir($directory);
}
return $directory;
} | php | private function createOrGetFolder($directory, ContainerBuilder $container)
{
$filesystem = new Filesystem();
$directory = $container->getParameterBag()->resolveValue($directory);
if (!file_exists($directory)) {
$filesystem->mkdir($directory);
}
return $directory;
} | [
"private",
"function",
"createOrGetFolder",
"(",
"$",
"directory",
",",
"ContainerBuilder",
"$",
"container",
")",
"{",
"$",
"filesystem",
"=",
"new",
"Filesystem",
"(",
")",
";",
"$",
"directory",
"=",
"$",
"container",
"->",
"getParameterBag",
"(",
")",
"->",
"resolveValue",
"(",
"$",
"directory",
")",
";",
"if",
"(",
"!",
"file_exists",
"(",
"$",
"directory",
")",
")",
"{",
"$",
"filesystem",
"->",
"mkdir",
"(",
"$",
"directory",
")",
";",
"}",
"return",
"$",
"directory",
";",
"}"
] | Create and return directory.
@param string $directory
@param ContainerBuilder $container
@return string | [
"Create",
"and",
"return",
"directory",
"."
] | 6766a36cc2f0c807c59202bf7540a08c4ef31192 | https://github.com/sulu/sulu/blob/6766a36cc2f0c807c59202bf7540a08c4ef31192/src/Sulu/Bundle/ResourceBundle/DependencyInjection/SuluResourceExtension.php#L60-L70 | train |
sulu/sulu | src/Sulu/Bundle/ResourceBundle/DependencyInjection/SuluResourceExtension.php | SuluResourceExtension.setDefaultForFilterConditionsConjunction | private function setDefaultForFilterConditionsConjunction(&$config)
{
if (!array_key_exists('filters', $config) ||
!array_key_exists('conjunctions', $config['filters']) ||
0 === count($config['filters']['conjunctions'])
) {
$config['filters'] = [];
$config['filters']['conjunctions'] = [
[
'id' => 'and',
'translation' => 'resource.filter.conjunction.and',
],
[
'id' => 'or',
'translation' => 'resource.filter.conjunction.or',
],
];
}
} | php | private function setDefaultForFilterConditionsConjunction(&$config)
{
if (!array_key_exists('filters', $config) ||
!array_key_exists('conjunctions', $config['filters']) ||
0 === count($config['filters']['conjunctions'])
) {
$config['filters'] = [];
$config['filters']['conjunctions'] = [
[
'id' => 'and',
'translation' => 'resource.filter.conjunction.and',
],
[
'id' => 'or',
'translation' => 'resource.filter.conjunction.or',
],
];
}
} | [
"private",
"function",
"setDefaultForFilterConditionsConjunction",
"(",
"&",
"$",
"config",
")",
"{",
"if",
"(",
"!",
"array_key_exists",
"(",
"'filters'",
",",
"$",
"config",
")",
"||",
"!",
"array_key_exists",
"(",
"'conjunctions'",
",",
"$",
"config",
"[",
"'filters'",
"]",
")",
"||",
"0",
"===",
"count",
"(",
"$",
"config",
"[",
"'filters'",
"]",
"[",
"'conjunctions'",
"]",
")",
")",
"{",
"$",
"config",
"[",
"'filters'",
"]",
"=",
"[",
"]",
";",
"$",
"config",
"[",
"'filters'",
"]",
"[",
"'conjunctions'",
"]",
"=",
"[",
"[",
"'id'",
"=>",
"'and'",
",",
"'translation'",
"=>",
"'resource.filter.conjunction.and'",
",",
"]",
",",
"[",
"'id'",
"=>",
"'or'",
",",
"'translation'",
"=>",
"'resource.filter.conjunction.or'",
",",
"]",
",",
"]",
";",
"}",
"}"
] | Sets default values for filter condition conjunction.
@param $config | [
"Sets",
"default",
"values",
"for",
"filter",
"condition",
"conjunction",
"."
] | 6766a36cc2f0c807c59202bf7540a08c4ef31192 | https://github.com/sulu/sulu/blob/6766a36cc2f0c807c59202bf7540a08c4ef31192/src/Sulu/Bundle/ResourceBundle/DependencyInjection/SuluResourceExtension.php#L77-L95 | train |
sulu/sulu | src/Sulu/Component/Content/Document/Extension/ManagedExtensionContainer.php | ManagedExtensionContainer.offsetGet | public function offsetGet($extensionName)
{
if (isset($this->data[$extensionName])) {
return $this->data[$extensionName];
}
$extension = $this->extensionManager->getExtension($this->structureType, $extensionName);
// TODO: should not pass namespace here.
// and indeed this call should be removed and the extension should be
// passed the document.
$extension->setLanguageCode($this->locale, $this->prefix, $this->internalPrefix);
// passing the webspace and locale would also be unnecessary if we passed the
// document
$data = $extension->load($this->node, $this->webspaceName, $this->locale);
$this->data[$extensionName] = $data;
return $data;
} | php | public function offsetGet($extensionName)
{
if (isset($this->data[$extensionName])) {
return $this->data[$extensionName];
}
$extension = $this->extensionManager->getExtension($this->structureType, $extensionName);
// TODO: should not pass namespace here.
// and indeed this call should be removed and the extension should be
// passed the document.
$extension->setLanguageCode($this->locale, $this->prefix, $this->internalPrefix);
// passing the webspace and locale would also be unnecessary if we passed the
// document
$data = $extension->load($this->node, $this->webspaceName, $this->locale);
$this->data[$extensionName] = $data;
return $data;
} | [
"public",
"function",
"offsetGet",
"(",
"$",
"extensionName",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"data",
"[",
"$",
"extensionName",
"]",
")",
")",
"{",
"return",
"$",
"this",
"->",
"data",
"[",
"$",
"extensionName",
"]",
";",
"}",
"$",
"extension",
"=",
"$",
"this",
"->",
"extensionManager",
"->",
"getExtension",
"(",
"$",
"this",
"->",
"structureType",
",",
"$",
"extensionName",
")",
";",
"// TODO: should not pass namespace here.",
"// and indeed this call should be removed and the extension should be",
"// passed the document.",
"$",
"extension",
"->",
"setLanguageCode",
"(",
"$",
"this",
"->",
"locale",
",",
"$",
"this",
"->",
"prefix",
",",
"$",
"this",
"->",
"internalPrefix",
")",
";",
"// passing the webspace and locale would also be unnecessary if we passed the",
"// document",
"$",
"data",
"=",
"$",
"extension",
"->",
"load",
"(",
"$",
"this",
"->",
"node",
",",
"$",
"this",
"->",
"webspaceName",
",",
"$",
"this",
"->",
"locale",
")",
";",
"$",
"this",
"->",
"data",
"[",
"$",
"extensionName",
"]",
"=",
"$",
"data",
";",
"return",
"$",
"data",
";",
"}"
] | Lazily evaluate the value for the given extension.
@param string $extensionName
@return mixed | [
"Lazily",
"evaluate",
"the",
"value",
"for",
"the",
"given",
"extension",
"."
] | 6766a36cc2f0c807c59202bf7540a08c4ef31192 | https://github.com/sulu/sulu/blob/6766a36cc2f0c807c59202bf7540a08c4ef31192/src/Sulu/Component/Content/Document/Extension/ManagedExtensionContainer.php#L100-L120 | train |
sulu/sulu | src/Sulu/Bundle/SearchBundle/Controller/WebsiteSearchController.php | WebsiteSearchController.queryAction | public function queryAction(Request $request)
{
$query = $this->getRequestParameter($request, 'q', true);
$locale = $this->requestAnalyzer->getCurrentLocalization()->getLocale();
$webspace = $this->requestAnalyzer->getWebspace();
$queryString = '';
if (strlen($query) < 3) {
$queryString .= '+("' . self::escapeDoubleQuotes($query) . '") ';
} else {
$queryValues = explode(' ', $query);
foreach ($queryValues as $queryValue) {
if (strlen($queryValue) > 2) {
$queryString .= '+("' . self::escapeDoubleQuotes($queryValue) . '" OR ' .
'"' . preg_replace('/([^\pL\s\d])/u', '?', $queryValue) . '*" OR ' .
'"' . preg_replace('/([^\pL\s\d])/u', '', $queryValue) . '~") ';
} else {
$queryString .= '+("' . self::escapeDoubleQuotes($queryValue) . '") ';
}
}
}
$hits = $this->searchManager
->createSearch($queryString)
->locale($locale)
->index('page_' . $webspace->getKey() . '_published')
->execute();
$template = $webspace->getTemplate('search', $request->getRequestFormat());
if (!$this->twig->getLoader()->exists($template)) {
throw new NotFoundHttpException();
}
return new Response($this->twig->render(
$template,
$this->parameterResolver->resolve(
['query' => $query, 'hits' => $hits],
$this->requestAnalyzer
)
));
} | php | public function queryAction(Request $request)
{
$query = $this->getRequestParameter($request, 'q', true);
$locale = $this->requestAnalyzer->getCurrentLocalization()->getLocale();
$webspace = $this->requestAnalyzer->getWebspace();
$queryString = '';
if (strlen($query) < 3) {
$queryString .= '+("' . self::escapeDoubleQuotes($query) . '") ';
} else {
$queryValues = explode(' ', $query);
foreach ($queryValues as $queryValue) {
if (strlen($queryValue) > 2) {
$queryString .= '+("' . self::escapeDoubleQuotes($queryValue) . '" OR ' .
'"' . preg_replace('/([^\pL\s\d])/u', '?', $queryValue) . '*" OR ' .
'"' . preg_replace('/([^\pL\s\d])/u', '', $queryValue) . '~") ';
} else {
$queryString .= '+("' . self::escapeDoubleQuotes($queryValue) . '") ';
}
}
}
$hits = $this->searchManager
->createSearch($queryString)
->locale($locale)
->index('page_' . $webspace->getKey() . '_published')
->execute();
$template = $webspace->getTemplate('search', $request->getRequestFormat());
if (!$this->twig->getLoader()->exists($template)) {
throw new NotFoundHttpException();
}
return new Response($this->twig->render(
$template,
$this->parameterResolver->resolve(
['query' => $query, 'hits' => $hits],
$this->requestAnalyzer
)
));
} | [
"public",
"function",
"queryAction",
"(",
"Request",
"$",
"request",
")",
"{",
"$",
"query",
"=",
"$",
"this",
"->",
"getRequestParameter",
"(",
"$",
"request",
",",
"'q'",
",",
"true",
")",
";",
"$",
"locale",
"=",
"$",
"this",
"->",
"requestAnalyzer",
"->",
"getCurrentLocalization",
"(",
")",
"->",
"getLocale",
"(",
")",
";",
"$",
"webspace",
"=",
"$",
"this",
"->",
"requestAnalyzer",
"->",
"getWebspace",
"(",
")",
";",
"$",
"queryString",
"=",
"''",
";",
"if",
"(",
"strlen",
"(",
"$",
"query",
")",
"<",
"3",
")",
"{",
"$",
"queryString",
".=",
"'+(\"'",
".",
"self",
"::",
"escapeDoubleQuotes",
"(",
"$",
"query",
")",
".",
"'\") '",
";",
"}",
"else",
"{",
"$",
"queryValues",
"=",
"explode",
"(",
"' '",
",",
"$",
"query",
")",
";",
"foreach",
"(",
"$",
"queryValues",
"as",
"$",
"queryValue",
")",
"{",
"if",
"(",
"strlen",
"(",
"$",
"queryValue",
")",
">",
"2",
")",
"{",
"$",
"queryString",
".=",
"'+(\"'",
".",
"self",
"::",
"escapeDoubleQuotes",
"(",
"$",
"queryValue",
")",
".",
"'\" OR '",
".",
"'\"'",
".",
"preg_replace",
"(",
"'/([^\\pL\\s\\d])/u'",
",",
"'?'",
",",
"$",
"queryValue",
")",
".",
"'*\" OR '",
".",
"'\"'",
".",
"preg_replace",
"(",
"'/([^\\pL\\s\\d])/u'",
",",
"''",
",",
"$",
"queryValue",
")",
".",
"'~\") '",
";",
"}",
"else",
"{",
"$",
"queryString",
".=",
"'+(\"'",
".",
"self",
"::",
"escapeDoubleQuotes",
"(",
"$",
"queryValue",
")",
".",
"'\") '",
";",
"}",
"}",
"}",
"$",
"hits",
"=",
"$",
"this",
"->",
"searchManager",
"->",
"createSearch",
"(",
"$",
"queryString",
")",
"->",
"locale",
"(",
"$",
"locale",
")",
"->",
"index",
"(",
"'page_'",
".",
"$",
"webspace",
"->",
"getKey",
"(",
")",
".",
"'_published'",
")",
"->",
"execute",
"(",
")",
";",
"$",
"template",
"=",
"$",
"webspace",
"->",
"getTemplate",
"(",
"'search'",
",",
"$",
"request",
"->",
"getRequestFormat",
"(",
")",
")",
";",
"if",
"(",
"!",
"$",
"this",
"->",
"twig",
"->",
"getLoader",
"(",
")",
"->",
"exists",
"(",
"$",
"template",
")",
")",
"{",
"throw",
"new",
"NotFoundHttpException",
"(",
")",
";",
"}",
"return",
"new",
"Response",
"(",
"$",
"this",
"->",
"twig",
"->",
"render",
"(",
"$",
"template",
",",
"$",
"this",
"->",
"parameterResolver",
"->",
"resolve",
"(",
"[",
"'query'",
"=>",
"$",
"query",
",",
"'hits'",
"=>",
"$",
"hits",
"]",
",",
"$",
"this",
"->",
"requestAnalyzer",
")",
")",
")",
";",
"}"
] | Returns the search results for the given query.
@param Request $request
@return Response | [
"Returns",
"the",
"search",
"results",
"for",
"the",
"given",
"query",
"."
] | 6766a36cc2f0c807c59202bf7540a08c4ef31192 | https://github.com/sulu/sulu/blob/6766a36cc2f0c807c59202bf7540a08c4ef31192/src/Sulu/Bundle/SearchBundle/Controller/WebsiteSearchController.php#L74-L116 | train |
sulu/sulu | src/Sulu/Bundle/AdminBundle/Navigation/NavigationItem.php | NavigationItem.copyChildless | public function copyChildless()
{
$new = $this->copyWithName();
$new->setAction($this->getAction());
$new->setMainRoute($this->getMainRoute());
$new->setChildRoutes($this->getChildRoutes());
$new->setEvent($this->getEvent());
$new->setEventArguments($this->getEventArguments());
$new->setIcon($this->getIcon());
$new->setHeaderIcon($this->getHeaderIcon());
$new->setHeaderTitle($this->getHeaderTitle());
$new->setId($this->getId());
$new->setHasSettings($this->getHasSettings());
$new->setPosition($this->getPosition());
$new->setLabel($this->getLabel());
return $new;
} | php | public function copyChildless()
{
$new = $this->copyWithName();
$new->setAction($this->getAction());
$new->setMainRoute($this->getMainRoute());
$new->setChildRoutes($this->getChildRoutes());
$new->setEvent($this->getEvent());
$new->setEventArguments($this->getEventArguments());
$new->setIcon($this->getIcon());
$new->setHeaderIcon($this->getHeaderIcon());
$new->setHeaderTitle($this->getHeaderTitle());
$new->setId($this->getId());
$new->setHasSettings($this->getHasSettings());
$new->setPosition($this->getPosition());
$new->setLabel($this->getLabel());
return $new;
} | [
"public",
"function",
"copyChildless",
"(",
")",
"{",
"$",
"new",
"=",
"$",
"this",
"->",
"copyWithName",
"(",
")",
";",
"$",
"new",
"->",
"setAction",
"(",
"$",
"this",
"->",
"getAction",
"(",
")",
")",
";",
"$",
"new",
"->",
"setMainRoute",
"(",
"$",
"this",
"->",
"getMainRoute",
"(",
")",
")",
";",
"$",
"new",
"->",
"setChildRoutes",
"(",
"$",
"this",
"->",
"getChildRoutes",
"(",
")",
")",
";",
"$",
"new",
"->",
"setEvent",
"(",
"$",
"this",
"->",
"getEvent",
"(",
")",
")",
";",
"$",
"new",
"->",
"setEventArguments",
"(",
"$",
"this",
"->",
"getEventArguments",
"(",
")",
")",
";",
"$",
"new",
"->",
"setIcon",
"(",
"$",
"this",
"->",
"getIcon",
"(",
")",
")",
";",
"$",
"new",
"->",
"setHeaderIcon",
"(",
"$",
"this",
"->",
"getHeaderIcon",
"(",
")",
")",
";",
"$",
"new",
"->",
"setHeaderTitle",
"(",
"$",
"this",
"->",
"getHeaderTitle",
"(",
")",
")",
";",
"$",
"new",
"->",
"setId",
"(",
"$",
"this",
"->",
"getId",
"(",
")",
")",
";",
"$",
"new",
"->",
"setHasSettings",
"(",
"$",
"this",
"->",
"getHasSettings",
"(",
")",
")",
";",
"$",
"new",
"->",
"setPosition",
"(",
"$",
"this",
"->",
"getPosition",
"(",
")",
")",
";",
"$",
"new",
"->",
"setLabel",
"(",
"$",
"this",
"->",
"getLabel",
"(",
")",
")",
";",
"return",
"$",
"new",
";",
"}"
] | Returns a copy of this navigation item without its children.
@return NavigationItem | [
"Returns",
"a",
"copy",
"of",
"this",
"navigation",
"item",
"without",
"its",
"children",
"."
] | 6766a36cc2f0c807c59202bf7540a08c4ef31192 | https://github.com/sulu/sulu/blob/6766a36cc2f0c807c59202bf7540a08c4ef31192/src/Sulu/Bundle/AdminBundle/Navigation/NavigationItem.php#L413-L430 | train |
sulu/sulu | src/Sulu/Bundle/AdminBundle/Navigation/NavigationItem.php | NavigationItem.find | public function find($navigationItem)
{
$stack = [$this];
while (!empty($stack)) {
/** @var NavigationItem $item */
$item = array_pop($stack);
if ($item->equalsChildless($navigationItem)) {
return $item;
}
foreach ($item->getChildren() as $child) {
/* @var NavigationItem $child */
$stack[] = $child;
}
}
return;
} | php | public function find($navigationItem)
{
$stack = [$this];
while (!empty($stack)) {
/** @var NavigationItem $item */
$item = array_pop($stack);
if ($item->equalsChildless($navigationItem)) {
return $item;
}
foreach ($item->getChildren() as $child) {
/* @var NavigationItem $child */
$stack[] = $child;
}
}
return;
} | [
"public",
"function",
"find",
"(",
"$",
"navigationItem",
")",
"{",
"$",
"stack",
"=",
"[",
"$",
"this",
"]",
";",
"while",
"(",
"!",
"empty",
"(",
"$",
"stack",
")",
")",
"{",
"/** @var NavigationItem $item */",
"$",
"item",
"=",
"array_pop",
"(",
"$",
"stack",
")",
";",
"if",
"(",
"$",
"item",
"->",
"equalsChildless",
"(",
"$",
"navigationItem",
")",
")",
"{",
"return",
"$",
"item",
";",
"}",
"foreach",
"(",
"$",
"item",
"->",
"getChildren",
"(",
")",
"as",
"$",
"child",
")",
"{",
"/* @var NavigationItem $child */",
"$",
"stack",
"[",
"]",
"=",
"$",
"child",
";",
"}",
"}",
"return",
";",
"}"
] | Searches for the equivalent of a specific NavigationItem.
@param NavigationItem $navigationItem The NavigationItem to look for
@return NavigationItem The item if it is found, otherwise false | [
"Searches",
"for",
"the",
"equivalent",
"of",
"a",
"specific",
"NavigationItem",
"."
] | 6766a36cc2f0c807c59202bf7540a08c4ef31192 | https://github.com/sulu/sulu/blob/6766a36cc2f0c807c59202bf7540a08c4ef31192/src/Sulu/Bundle/AdminBundle/Navigation/NavigationItem.php#L461-L477 | train |
sulu/sulu | src/Sulu/Bundle/AdminBundle/Navigation/NavigationItem.php | NavigationItem.findChildren | public function findChildren(self $navigationItem)
{
foreach ($this->getChildren() as $child) {
/** @var NavigationItem $child */
if ($child->equalsChildless($navigationItem)) {
return $child;
}
}
return;
} | php | public function findChildren(self $navigationItem)
{
foreach ($this->getChildren() as $child) {
/** @var NavigationItem $child */
if ($child->equalsChildless($navigationItem)) {
return $child;
}
}
return;
} | [
"public",
"function",
"findChildren",
"(",
"self",
"$",
"navigationItem",
")",
"{",
"foreach",
"(",
"$",
"this",
"->",
"getChildren",
"(",
")",
"as",
"$",
"child",
")",
"{",
"/** @var NavigationItem $child */",
"if",
"(",
"$",
"child",
"->",
"equalsChildless",
"(",
"$",
"navigationItem",
")",
")",
"{",
"return",
"$",
"child",
";",
"}",
"}",
"return",
";",
"}"
] | Searches for a specific NavigationItem in the children of this NavigationItem.
@param NavigationItem $navigationItem The navigationItem we look for
@return NavigationItem|null Null if the NavigationItem is not found, otherwise the found NavigationItem | [
"Searches",
"for",
"a",
"specific",
"NavigationItem",
"in",
"the",
"children",
"of",
"this",
"NavigationItem",
"."
] | 6766a36cc2f0c807c59202bf7540a08c4ef31192 | https://github.com/sulu/sulu/blob/6766a36cc2f0c807c59202bf7540a08c4ef31192/src/Sulu/Bundle/AdminBundle/Navigation/NavigationItem.php#L486-L496 | train |
sulu/sulu | src/Sulu/Bundle/AdminBundle/Navigation/NavigationItem.php | NavigationItem.merge | public function merge(self $other = null)
{
// Create new item
$new = $this->copyChildless();
// Add all children from this item
foreach ($this->getChildren() as $child) {
/* @var NavigationItem $child */
$new->addChild($child->merge((null != $other) ? $other->findChildren($child) : null));
}
// Add all children from the other item
if (null != $other) {
foreach ($other->getChildren() as $child) {
/** @var NavigationItem $child */
if (!$new->find($child)) {
$new->addChild($child->merge($this->copyChildless()));
}
}
}
return $new;
} | php | public function merge(self $other = null)
{
// Create new item
$new = $this->copyChildless();
// Add all children from this item
foreach ($this->getChildren() as $child) {
/* @var NavigationItem $child */
$new->addChild($child->merge((null != $other) ? $other->findChildren($child) : null));
}
// Add all children from the other item
if (null != $other) {
foreach ($other->getChildren() as $child) {
/** @var NavigationItem $child */
if (!$new->find($child)) {
$new->addChild($child->merge($this->copyChildless()));
}
}
}
return $new;
} | [
"public",
"function",
"merge",
"(",
"self",
"$",
"other",
"=",
"null",
")",
"{",
"// Create new item",
"$",
"new",
"=",
"$",
"this",
"->",
"copyChildless",
"(",
")",
";",
"// Add all children from this item",
"foreach",
"(",
"$",
"this",
"->",
"getChildren",
"(",
")",
"as",
"$",
"child",
")",
"{",
"/* @var NavigationItem $child */",
"$",
"new",
"->",
"addChild",
"(",
"$",
"child",
"->",
"merge",
"(",
"(",
"null",
"!=",
"$",
"other",
")",
"?",
"$",
"other",
"->",
"findChildren",
"(",
"$",
"child",
")",
":",
"null",
")",
")",
";",
"}",
"// Add all children from the other item",
"if",
"(",
"null",
"!=",
"$",
"other",
")",
"{",
"foreach",
"(",
"$",
"other",
"->",
"getChildren",
"(",
")",
"as",
"$",
"child",
")",
"{",
"/** @var NavigationItem $child */",
"if",
"(",
"!",
"$",
"new",
"->",
"find",
"(",
"$",
"child",
")",
")",
"{",
"$",
"new",
"->",
"addChild",
"(",
"$",
"child",
"->",
"merge",
"(",
"$",
"this",
"->",
"copyChildless",
"(",
")",
")",
")",
";",
"}",
"}",
"}",
"return",
"$",
"new",
";",
"}"
] | Merges this navigation item with the other parameter and returns a new NavigationItem.
Works only if there are no duplicate values on one level.
@param NavigationItem $other The navigation item this one should be merged with
@return NavigationItem | [
"Merges",
"this",
"navigation",
"item",
"with",
"the",
"other",
"parameter",
"and",
"returns",
"a",
"new",
"NavigationItem",
".",
"Works",
"only",
"if",
"there",
"are",
"no",
"duplicate",
"values",
"on",
"one",
"level",
"."
] | 6766a36cc2f0c807c59202bf7540a08c4ef31192 | https://github.com/sulu/sulu/blob/6766a36cc2f0c807c59202bf7540a08c4ef31192/src/Sulu/Bundle/AdminBundle/Navigation/NavigationItem.php#L506-L528 | train |
sulu/sulu | src/Sulu/Bundle/AdminBundle/Navigation/NavigationItem.php | NavigationItem.toArray | public function toArray()
{
$array = [
'title' => $this->getName(),
'label' => $this->getLabel(),
'icon' => $this->getIcon(),
'action' => $this->getAction(),
'mainRoute' => $this->getMainRoute(),
'event' => $this->getEvent(),
'eventArguments' => $this->getEventArguments(),
'hasSettings' => $this->getHasSettings(),
'disabled' => $this->getDisabled(),
'id' => (null != $this->getId()) ? $this->getId() : str_replace('.', '', uniqid('', true)), //FIXME don't use uniqid()
];
if (count($this->getChildRoutes()) > 0) {
$array['childRoutes'] = $this->getChildRoutes();
}
if (null != $this->getHeaderIcon() || null != $this->getHeaderTitle()) {
$array['header'] = [
'title' => $this->getHeaderTitle(),
'logo' => $this->getHeaderIcon(),
];
}
$children = $this->getChildren();
usort(
$children,
function(NavigationItem $a, NavigationItem $b) {
$aPosition = $a->getPosition() ?: PHP_INT_MAX;
$bPosition = $b->getPosition() ?: PHP_INT_MAX;
return $aPosition - $bPosition;
}
);
foreach ($children as $key => $child) {
/* @var NavigationItem $child */
$array['items'][$key] = $child->toArray();
}
return $array;
} | php | public function toArray()
{
$array = [
'title' => $this->getName(),
'label' => $this->getLabel(),
'icon' => $this->getIcon(),
'action' => $this->getAction(),
'mainRoute' => $this->getMainRoute(),
'event' => $this->getEvent(),
'eventArguments' => $this->getEventArguments(),
'hasSettings' => $this->getHasSettings(),
'disabled' => $this->getDisabled(),
'id' => (null != $this->getId()) ? $this->getId() : str_replace('.', '', uniqid('', true)), //FIXME don't use uniqid()
];
if (count($this->getChildRoutes()) > 0) {
$array['childRoutes'] = $this->getChildRoutes();
}
if (null != $this->getHeaderIcon() || null != $this->getHeaderTitle()) {
$array['header'] = [
'title' => $this->getHeaderTitle(),
'logo' => $this->getHeaderIcon(),
];
}
$children = $this->getChildren();
usort(
$children,
function(NavigationItem $a, NavigationItem $b) {
$aPosition = $a->getPosition() ?: PHP_INT_MAX;
$bPosition = $b->getPosition() ?: PHP_INT_MAX;
return $aPosition - $bPosition;
}
);
foreach ($children as $key => $child) {
/* @var NavigationItem $child */
$array['items'][$key] = $child->toArray();
}
return $array;
} | [
"public",
"function",
"toArray",
"(",
")",
"{",
"$",
"array",
"=",
"[",
"'title'",
"=>",
"$",
"this",
"->",
"getName",
"(",
")",
",",
"'label'",
"=>",
"$",
"this",
"->",
"getLabel",
"(",
")",
",",
"'icon'",
"=>",
"$",
"this",
"->",
"getIcon",
"(",
")",
",",
"'action'",
"=>",
"$",
"this",
"->",
"getAction",
"(",
")",
",",
"'mainRoute'",
"=>",
"$",
"this",
"->",
"getMainRoute",
"(",
")",
",",
"'event'",
"=>",
"$",
"this",
"->",
"getEvent",
"(",
")",
",",
"'eventArguments'",
"=>",
"$",
"this",
"->",
"getEventArguments",
"(",
")",
",",
"'hasSettings'",
"=>",
"$",
"this",
"->",
"getHasSettings",
"(",
")",
",",
"'disabled'",
"=>",
"$",
"this",
"->",
"getDisabled",
"(",
")",
",",
"'id'",
"=>",
"(",
"null",
"!=",
"$",
"this",
"->",
"getId",
"(",
")",
")",
"?",
"$",
"this",
"->",
"getId",
"(",
")",
":",
"str_replace",
"(",
"'.'",
",",
"''",
",",
"uniqid",
"(",
"''",
",",
"true",
")",
")",
",",
"//FIXME don't use uniqid()",
"]",
";",
"if",
"(",
"count",
"(",
"$",
"this",
"->",
"getChildRoutes",
"(",
")",
")",
">",
"0",
")",
"{",
"$",
"array",
"[",
"'childRoutes'",
"]",
"=",
"$",
"this",
"->",
"getChildRoutes",
"(",
")",
";",
"}",
"if",
"(",
"null",
"!=",
"$",
"this",
"->",
"getHeaderIcon",
"(",
")",
"||",
"null",
"!=",
"$",
"this",
"->",
"getHeaderTitle",
"(",
")",
")",
"{",
"$",
"array",
"[",
"'header'",
"]",
"=",
"[",
"'title'",
"=>",
"$",
"this",
"->",
"getHeaderTitle",
"(",
")",
",",
"'logo'",
"=>",
"$",
"this",
"->",
"getHeaderIcon",
"(",
")",
",",
"]",
";",
"}",
"$",
"children",
"=",
"$",
"this",
"->",
"getChildren",
"(",
")",
";",
"usort",
"(",
"$",
"children",
",",
"function",
"(",
"NavigationItem",
"$",
"a",
",",
"NavigationItem",
"$",
"b",
")",
"{",
"$",
"aPosition",
"=",
"$",
"a",
"->",
"getPosition",
"(",
")",
"?",
":",
"PHP_INT_MAX",
";",
"$",
"bPosition",
"=",
"$",
"b",
"->",
"getPosition",
"(",
")",
"?",
":",
"PHP_INT_MAX",
";",
"return",
"$",
"aPosition",
"-",
"$",
"bPosition",
";",
"}",
")",
";",
"foreach",
"(",
"$",
"children",
"as",
"$",
"key",
"=>",
"$",
"child",
")",
"{",
"/* @var NavigationItem $child */",
"$",
"array",
"[",
"'items'",
"]",
"[",
"$",
"key",
"]",
"=",
"$",
"child",
"->",
"toArray",
"(",
")",
";",
"}",
"return",
"$",
"array",
";",
"}"
] | Returns the content of the NavigationItem as array.
@return array | [
"Returns",
"the",
"content",
"of",
"the",
"NavigationItem",
"as",
"array",
"."
] | 6766a36cc2f0c807c59202bf7540a08c4ef31192 | https://github.com/sulu/sulu/blob/6766a36cc2f0c807c59202bf7540a08c4ef31192/src/Sulu/Bundle/AdminBundle/Navigation/NavigationItem.php#L592-L636 | train |
sulu/sulu | src/Sulu/Component/Content/Mapper/Translation/MultipleTranslatedProperties.php | MultipleTranslatedProperties.setLanguage | public function setLanguage($languageKey)
{
$this->translatedProperties = [];
foreach ($this->properties as $key => $property) {
$this->translatedProperties[$key] = new TranslatedProperty(
$property,
$languageKey,
$this->languageNamespace
);
}
} | php | public function setLanguage($languageKey)
{
$this->translatedProperties = [];
foreach ($this->properties as $key => $property) {
$this->translatedProperties[$key] = new TranslatedProperty(
$property,
$languageKey,
$this->languageNamespace
);
}
} | [
"public",
"function",
"setLanguage",
"(",
"$",
"languageKey",
")",
"{",
"$",
"this",
"->",
"translatedProperties",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"this",
"->",
"properties",
"as",
"$",
"key",
"=>",
"$",
"property",
")",
"{",
"$",
"this",
"->",
"translatedProperties",
"[",
"$",
"key",
"]",
"=",
"new",
"TranslatedProperty",
"(",
"$",
"property",
",",
"$",
"languageKey",
",",
"$",
"this",
"->",
"languageNamespace",
")",
";",
"}",
"}"
] | set language of translated property names.
@param string $languageKey | [
"set",
"language",
"of",
"translated",
"property",
"names",
"."
] | 6766a36cc2f0c807c59202bf7540a08c4ef31192 | https://github.com/sulu/sulu/blob/6766a36cc2f0c807c59202bf7540a08c4ef31192/src/Sulu/Component/Content/Mapper/Translation/MultipleTranslatedProperties.php#L62-L72 | train |
sulu/sulu | src/Sulu/Component/Content/Mapper/Translation/MultipleTranslatedProperties.php | MultipleTranslatedProperties.getName | public function getName($key)
{
// templates do not translate the template key
if (Structure::TYPE_SNIPPET === $this->structureType) {
if ('template' === $key) {
return $key;
}
}
if (isset($this->translatedProperties[$key])) {
return $this->translatedProperties[$key]->getName();
} else {
throw new NoSuchPropertyException($key);
}
} | php | public function getName($key)
{
// templates do not translate the template key
if (Structure::TYPE_SNIPPET === $this->structureType) {
if ('template' === $key) {
return $key;
}
}
if (isset($this->translatedProperties[$key])) {
return $this->translatedProperties[$key]->getName();
} else {
throw new NoSuchPropertyException($key);
}
} | [
"public",
"function",
"getName",
"(",
"$",
"key",
")",
"{",
"// templates do not translate the template key",
"if",
"(",
"Structure",
"::",
"TYPE_SNIPPET",
"===",
"$",
"this",
"->",
"structureType",
")",
"{",
"if",
"(",
"'template'",
"===",
"$",
"key",
")",
"{",
"return",
"$",
"key",
";",
"}",
"}",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"translatedProperties",
"[",
"$",
"key",
"]",
")",
")",
"{",
"return",
"$",
"this",
"->",
"translatedProperties",
"[",
"$",
"key",
"]",
"->",
"getName",
"(",
")",
";",
"}",
"else",
"{",
"throw",
"new",
"NoSuchPropertyException",
"(",
"$",
"key",
")",
";",
"}",
"}"
] | returns translated property name.
@param string $key
@throws \Sulu\Component\Content\Exception\NoSuchPropertyException
@return string | [
"returns",
"translated",
"property",
"name",
"."
] | 6766a36cc2f0c807c59202bf7540a08c4ef31192 | https://github.com/sulu/sulu/blob/6766a36cc2f0c807c59202bf7540a08c4ef31192/src/Sulu/Component/Content/Mapper/Translation/MultipleTranslatedProperties.php#L83-L97 | train |
sulu/sulu | src/Sulu/Bundle/SecurityBundle/Controller/ProfileController.php | ProfileController.putLanguageAction | public function putLanguageAction(Request $request)
{
$user = $this->tokenStorage->getToken()->getUser();
$user->setLocale($request->get('locale'));
$this->objectManager->flush();
return $this->viewHandler->handle(View::create(['locale' => $user->getLocale()]));
} | php | public function putLanguageAction(Request $request)
{
$user = $this->tokenStorage->getToken()->getUser();
$user->setLocale($request->get('locale'));
$this->objectManager->flush();
return $this->viewHandler->handle(View::create(['locale' => $user->getLocale()]));
} | [
"public",
"function",
"putLanguageAction",
"(",
"Request",
"$",
"request",
")",
"{",
"$",
"user",
"=",
"$",
"this",
"->",
"tokenStorage",
"->",
"getToken",
"(",
")",
"->",
"getUser",
"(",
")",
";",
"$",
"user",
"->",
"setLocale",
"(",
"$",
"request",
"->",
"get",
"(",
"'locale'",
")",
")",
";",
"$",
"this",
"->",
"objectManager",
"->",
"flush",
"(",
")",
";",
"return",
"$",
"this",
"->",
"viewHandler",
"->",
"handle",
"(",
"View",
"::",
"create",
"(",
"[",
"'locale'",
"=>",
"$",
"user",
"->",
"getLocale",
"(",
")",
"]",
")",
")",
";",
"}"
] | Sets the given language on the current user.
@param Request $request
@return Response | [
"Sets",
"the",
"given",
"language",
"on",
"the",
"current",
"user",
"."
] | 6766a36cc2f0c807c59202bf7540a08c4ef31192 | https://github.com/sulu/sulu/blob/6766a36cc2f0c807c59202bf7540a08c4ef31192/src/Sulu/Bundle/SecurityBundle/Controller/ProfileController.php#L78-L86 | train |
sulu/sulu | src/Sulu/Bundle/SecurityBundle/Controller/ProfileController.php | ProfileController.patchSettingsAction | public function patchSettingsAction(Request $request)
{
$settings = $request->request->all();
try {
$user = $this->tokenStorage->getToken()->getUser();
foreach ($settings as $settingKey => $settingValue) {
// get setting
// TODO: move this logic into own service (UserSettingManager?)
$setting = $this->userSettingRepository->findOneBy(['user' => $user, 'key' => $settingKey]);
// or create new one
if (!$setting) {
$setting = new UserSetting();
$setting->setKey($settingKey);
$setting->setUser($user);
$this->objectManager->persist($setting);
}
// persist setting
$setting->setValue(json_encode($settingValue));
}
$this->objectManager->flush();
//create view
$view = View::create($settings, 200);
} catch (RestException $exc) {
$view = View::create($exc->toArray(), 400);
}
return $this->viewHandler->handle($view);
} | php | public function patchSettingsAction(Request $request)
{
$settings = $request->request->all();
try {
$user = $this->tokenStorage->getToken()->getUser();
foreach ($settings as $settingKey => $settingValue) {
// get setting
// TODO: move this logic into own service (UserSettingManager?)
$setting = $this->userSettingRepository->findOneBy(['user' => $user, 'key' => $settingKey]);
// or create new one
if (!$setting) {
$setting = new UserSetting();
$setting->setKey($settingKey);
$setting->setUser($user);
$this->objectManager->persist($setting);
}
// persist setting
$setting->setValue(json_encode($settingValue));
}
$this->objectManager->flush();
//create view
$view = View::create($settings, 200);
} catch (RestException $exc) {
$view = View::create($exc->toArray(), 400);
}
return $this->viewHandler->handle($view);
} | [
"public",
"function",
"patchSettingsAction",
"(",
"Request",
"$",
"request",
")",
"{",
"$",
"settings",
"=",
"$",
"request",
"->",
"request",
"->",
"all",
"(",
")",
";",
"try",
"{",
"$",
"user",
"=",
"$",
"this",
"->",
"tokenStorage",
"->",
"getToken",
"(",
")",
"->",
"getUser",
"(",
")",
";",
"foreach",
"(",
"$",
"settings",
"as",
"$",
"settingKey",
"=>",
"$",
"settingValue",
")",
"{",
"// get setting",
"// TODO: move this logic into own service (UserSettingManager?)",
"$",
"setting",
"=",
"$",
"this",
"->",
"userSettingRepository",
"->",
"findOneBy",
"(",
"[",
"'user'",
"=>",
"$",
"user",
",",
"'key'",
"=>",
"$",
"settingKey",
"]",
")",
";",
"// or create new one",
"if",
"(",
"!",
"$",
"setting",
")",
"{",
"$",
"setting",
"=",
"new",
"UserSetting",
"(",
")",
";",
"$",
"setting",
"->",
"setKey",
"(",
"$",
"settingKey",
")",
";",
"$",
"setting",
"->",
"setUser",
"(",
"$",
"user",
")",
";",
"$",
"this",
"->",
"objectManager",
"->",
"persist",
"(",
"$",
"setting",
")",
";",
"}",
"// persist setting",
"$",
"setting",
"->",
"setValue",
"(",
"json_encode",
"(",
"$",
"settingValue",
")",
")",
";",
"}",
"$",
"this",
"->",
"objectManager",
"->",
"flush",
"(",
")",
";",
"//create view",
"$",
"view",
"=",
"View",
"::",
"create",
"(",
"$",
"settings",
",",
"200",
")",
";",
"}",
"catch",
"(",
"RestException",
"$",
"exc",
")",
"{",
"$",
"view",
"=",
"View",
"::",
"create",
"(",
"$",
"exc",
"->",
"toArray",
"(",
")",
",",
"400",
")",
";",
"}",
"return",
"$",
"this",
"->",
"viewHandler",
"->",
"handle",
"(",
"$",
"view",
")",
";",
"}"
] | Takes a key, value pair and stores it as settings for the user.
@param Request $request
@return Response | [
"Takes",
"a",
"key",
"value",
"pair",
"and",
"stores",
"it",
"as",
"settings",
"for",
"the",
"user",
"."
] | 6766a36cc2f0c807c59202bf7540a08c4ef31192 | https://github.com/sulu/sulu/blob/6766a36cc2f0c807c59202bf7540a08c4ef31192/src/Sulu/Bundle/SecurityBundle/Controller/ProfileController.php#L95-L127 | train |
sulu/sulu | src/Sulu/Bundle/SecurityBundle/Controller/ProfileController.php | ProfileController.deleteSettingsAction | public function deleteSettingsAction(Request $request)
{
$key = $request->get('key');
try {
if (!$key) {
throw new MissingArgumentException(static::$entityNameUserSetting, 'key');
}
$user = $this->tokenStorage->getToken()->getUser();
// get setting
// TODO: move this logic into own service (UserSettingManager?)
$setting = $this->userSettingRepository->findOneBy(['user' => $user, 'key' => $key]);
if ($setting) {
$this->objectManager->remove($setting);
$this->objectManager->flush();
$view = View::create(null, 204);
} else {
$view = View::create(null, 400);
}
} catch (RestException $exc) {
$view = View::create($exc->toArray(), 400);
}
return $this->viewHandler->handle($view);
} | php | public function deleteSettingsAction(Request $request)
{
$key = $request->get('key');
try {
if (!$key) {
throw new MissingArgumentException(static::$entityNameUserSetting, 'key');
}
$user = $this->tokenStorage->getToken()->getUser();
// get setting
// TODO: move this logic into own service (UserSettingManager?)
$setting = $this->userSettingRepository->findOneBy(['user' => $user, 'key' => $key]);
if ($setting) {
$this->objectManager->remove($setting);
$this->objectManager->flush();
$view = View::create(null, 204);
} else {
$view = View::create(null, 400);
}
} catch (RestException $exc) {
$view = View::create($exc->toArray(), 400);
}
return $this->viewHandler->handle($view);
} | [
"public",
"function",
"deleteSettingsAction",
"(",
"Request",
"$",
"request",
")",
"{",
"$",
"key",
"=",
"$",
"request",
"->",
"get",
"(",
"'key'",
")",
";",
"try",
"{",
"if",
"(",
"!",
"$",
"key",
")",
"{",
"throw",
"new",
"MissingArgumentException",
"(",
"static",
"::",
"$",
"entityNameUserSetting",
",",
"'key'",
")",
";",
"}",
"$",
"user",
"=",
"$",
"this",
"->",
"tokenStorage",
"->",
"getToken",
"(",
")",
"->",
"getUser",
"(",
")",
";",
"// get setting",
"// TODO: move this logic into own service (UserSettingManager?)",
"$",
"setting",
"=",
"$",
"this",
"->",
"userSettingRepository",
"->",
"findOneBy",
"(",
"[",
"'user'",
"=>",
"$",
"user",
",",
"'key'",
"=>",
"$",
"key",
"]",
")",
";",
"if",
"(",
"$",
"setting",
")",
"{",
"$",
"this",
"->",
"objectManager",
"->",
"remove",
"(",
"$",
"setting",
")",
";",
"$",
"this",
"->",
"objectManager",
"->",
"flush",
"(",
")",
";",
"$",
"view",
"=",
"View",
"::",
"create",
"(",
"null",
",",
"204",
")",
";",
"}",
"else",
"{",
"$",
"view",
"=",
"View",
"::",
"create",
"(",
"null",
",",
"400",
")",
";",
"}",
"}",
"catch",
"(",
"RestException",
"$",
"exc",
")",
"{",
"$",
"view",
"=",
"View",
"::",
"create",
"(",
"$",
"exc",
"->",
"toArray",
"(",
")",
",",
"400",
")",
";",
"}",
"return",
"$",
"this",
"->",
"viewHandler",
"->",
"handle",
"(",
"$",
"view",
")",
";",
"}"
] | Deletes a user setting by a given key.
@param Request $request
@return Response | [
"Deletes",
"a",
"user",
"setting",
"by",
"a",
"given",
"key",
"."
] | 6766a36cc2f0c807c59202bf7540a08c4ef31192 | https://github.com/sulu/sulu/blob/6766a36cc2f0c807c59202bf7540a08c4ef31192/src/Sulu/Bundle/SecurityBundle/Controller/ProfileController.php#L136-L163 | train |
sulu/sulu | src/Sulu/Bundle/AudienceTargetingBundle/EventListener/TargetGroupSubscriber.php | TargetGroupSubscriber.setTargetGroup | public function setTargetGroup(GetResponseEvent $event)
{
$request = $event->getRequest();
if ($targetGroupId = $request->headers->get($this->targetGroupHeader)) {
$this->targetGroupStore->setTargetGroupId($targetGroupId);
} elseif ($targetGroupId = $request->cookies->get($this->targetGroupCookie)) {
$visitorSession = $request->cookies->get($this->visitorSessionCookie);
if ($visitorSession) {
$this->targetGroupStore->setTargetGroupId($targetGroupId);
return;
}
$targetGroup = $this->targetGroupEvaluator->evaluate(
TargetGroupRuleInterface::FREQUENCY_SESSION,
$this->targetGroupRepository->find($targetGroupId)
);
if ($targetGroup) {
$this->targetGroupStore->updateTargetGroupId($targetGroup->getId());
}
} elseif ($request->getPathInfo() !== $this->targetGroupUrl) {
// this should not happen on the endpoint for the cache, because it is set there manually as a header
$targetGroup = $this->targetGroupEvaluator->evaluate();
$targetGroupId = 0;
if ($targetGroup) {
$targetGroupId = $targetGroup->getId();
}
$this->targetGroupStore->updateTargetGroupId($targetGroupId);
}
} | php | public function setTargetGroup(GetResponseEvent $event)
{
$request = $event->getRequest();
if ($targetGroupId = $request->headers->get($this->targetGroupHeader)) {
$this->targetGroupStore->setTargetGroupId($targetGroupId);
} elseif ($targetGroupId = $request->cookies->get($this->targetGroupCookie)) {
$visitorSession = $request->cookies->get($this->visitorSessionCookie);
if ($visitorSession) {
$this->targetGroupStore->setTargetGroupId($targetGroupId);
return;
}
$targetGroup = $this->targetGroupEvaluator->evaluate(
TargetGroupRuleInterface::FREQUENCY_SESSION,
$this->targetGroupRepository->find($targetGroupId)
);
if ($targetGroup) {
$this->targetGroupStore->updateTargetGroupId($targetGroup->getId());
}
} elseif ($request->getPathInfo() !== $this->targetGroupUrl) {
// this should not happen on the endpoint for the cache, because it is set there manually as a header
$targetGroup = $this->targetGroupEvaluator->evaluate();
$targetGroupId = 0;
if ($targetGroup) {
$targetGroupId = $targetGroup->getId();
}
$this->targetGroupStore->updateTargetGroupId($targetGroupId);
}
} | [
"public",
"function",
"setTargetGroup",
"(",
"GetResponseEvent",
"$",
"event",
")",
"{",
"$",
"request",
"=",
"$",
"event",
"->",
"getRequest",
"(",
")",
";",
"if",
"(",
"$",
"targetGroupId",
"=",
"$",
"request",
"->",
"headers",
"->",
"get",
"(",
"$",
"this",
"->",
"targetGroupHeader",
")",
")",
"{",
"$",
"this",
"->",
"targetGroupStore",
"->",
"setTargetGroupId",
"(",
"$",
"targetGroupId",
")",
";",
"}",
"elseif",
"(",
"$",
"targetGroupId",
"=",
"$",
"request",
"->",
"cookies",
"->",
"get",
"(",
"$",
"this",
"->",
"targetGroupCookie",
")",
")",
"{",
"$",
"visitorSession",
"=",
"$",
"request",
"->",
"cookies",
"->",
"get",
"(",
"$",
"this",
"->",
"visitorSessionCookie",
")",
";",
"if",
"(",
"$",
"visitorSession",
")",
"{",
"$",
"this",
"->",
"targetGroupStore",
"->",
"setTargetGroupId",
"(",
"$",
"targetGroupId",
")",
";",
"return",
";",
"}",
"$",
"targetGroup",
"=",
"$",
"this",
"->",
"targetGroupEvaluator",
"->",
"evaluate",
"(",
"TargetGroupRuleInterface",
"::",
"FREQUENCY_SESSION",
",",
"$",
"this",
"->",
"targetGroupRepository",
"->",
"find",
"(",
"$",
"targetGroupId",
")",
")",
";",
"if",
"(",
"$",
"targetGroup",
")",
"{",
"$",
"this",
"->",
"targetGroupStore",
"->",
"updateTargetGroupId",
"(",
"$",
"targetGroup",
"->",
"getId",
"(",
")",
")",
";",
"}",
"}",
"elseif",
"(",
"$",
"request",
"->",
"getPathInfo",
"(",
")",
"!==",
"$",
"this",
"->",
"targetGroupUrl",
")",
"{",
"// this should not happen on the endpoint for the cache, because it is set there manually as a header",
"$",
"targetGroup",
"=",
"$",
"this",
"->",
"targetGroupEvaluator",
"->",
"evaluate",
"(",
")",
";",
"$",
"targetGroupId",
"=",
"0",
";",
"if",
"(",
"$",
"targetGroup",
")",
"{",
"$",
"targetGroupId",
"=",
"$",
"targetGroup",
"->",
"getId",
"(",
")",
";",
"}",
"$",
"this",
"->",
"targetGroupStore",
"->",
"updateTargetGroupId",
"(",
"$",
"targetGroupId",
")",
";",
"}",
"}"
] | Evaluates the cookie holding the target group information. This has only an effect if there is no cache used,
since in that case the cache already did it.
@param GetResponseEvent $event | [
"Evaluates",
"the",
"cookie",
"holding",
"the",
"target",
"group",
"information",
".",
"This",
"has",
"only",
"an",
"effect",
"if",
"there",
"is",
"no",
"cache",
"used",
"since",
"in",
"that",
"case",
"the",
"cache",
"already",
"did",
"it",
"."
] | 6766a36cc2f0c807c59202bf7540a08c4ef31192 | https://github.com/sulu/sulu/blob/6766a36cc2f0c807c59202bf7540a08c4ef31192/src/Sulu/Bundle/AudienceTargetingBundle/EventListener/TargetGroupSubscriber.php#L160-L193 | train |
sulu/sulu | src/Sulu/Bundle/AudienceTargetingBundle/EventListener/TargetGroupSubscriber.php | TargetGroupSubscriber.addVaryHeader | public function addVaryHeader(FilterResponseEvent $event)
{
$request = $event->getRequest();
$response = $event->getResponse();
if ($this->targetGroupStore->hasInfluencedContent() && $request->getRequestUri() !== $this->targetGroupUrl) {
$response->setVary($this->targetGroupHeader, false);
}
} | php | public function addVaryHeader(FilterResponseEvent $event)
{
$request = $event->getRequest();
$response = $event->getResponse();
if ($this->targetGroupStore->hasInfluencedContent() && $request->getRequestUri() !== $this->targetGroupUrl) {
$response->setVary($this->targetGroupHeader, false);
}
} | [
"public",
"function",
"addVaryHeader",
"(",
"FilterResponseEvent",
"$",
"event",
")",
"{",
"$",
"request",
"=",
"$",
"event",
"->",
"getRequest",
"(",
")",
";",
"$",
"response",
"=",
"$",
"event",
"->",
"getResponse",
"(",
")",
";",
"if",
"(",
"$",
"this",
"->",
"targetGroupStore",
"->",
"hasInfluencedContent",
"(",
")",
"&&",
"$",
"request",
"->",
"getRequestUri",
"(",
")",
"!==",
"$",
"this",
"->",
"targetGroupUrl",
")",
"{",
"$",
"response",
"->",
"setVary",
"(",
"$",
"this",
"->",
"targetGroupHeader",
",",
"false",
")",
";",
"}",
"}"
] | Adds the vary header on the response, so that the cache takes the target group into account.
@param FilterResponseEvent $event | [
"Adds",
"the",
"vary",
"header",
"on",
"the",
"response",
"so",
"that",
"the",
"cache",
"takes",
"the",
"target",
"group",
"into",
"account",
"."
] | 6766a36cc2f0c807c59202bf7540a08c4ef31192 | https://github.com/sulu/sulu/blob/6766a36cc2f0c807c59202bf7540a08c4ef31192/src/Sulu/Bundle/AudienceTargetingBundle/EventListener/TargetGroupSubscriber.php#L200-L208 | train |
sulu/sulu | src/Sulu/Bundle/AudienceTargetingBundle/EventListener/TargetGroupSubscriber.php | TargetGroupSubscriber.addSetCookieHeader | public function addSetCookieHeader(FilterResponseEvent $event)
{
if (!$this->targetGroupStore->hasChangedTargetGroup()
|| $event->getRequest()->getPathInfo() === $this->targetGroupUrl
) {
return;
}
$response = $event->getResponse();
$response->headers->setCookie(
new Cookie(
$this->targetGroupCookie,
$this->targetGroupStore->getTargetGroupId(true),
AudienceTargetingCacheListener::TARGET_GROUP_COOKIE_LIFETIME
)
);
$response->headers->setCookie(
new Cookie(
$this->visitorSessionCookie,
time()
)
);
} | php | public function addSetCookieHeader(FilterResponseEvent $event)
{
if (!$this->targetGroupStore->hasChangedTargetGroup()
|| $event->getRequest()->getPathInfo() === $this->targetGroupUrl
) {
return;
}
$response = $event->getResponse();
$response->headers->setCookie(
new Cookie(
$this->targetGroupCookie,
$this->targetGroupStore->getTargetGroupId(true),
AudienceTargetingCacheListener::TARGET_GROUP_COOKIE_LIFETIME
)
);
$response->headers->setCookie(
new Cookie(
$this->visitorSessionCookie,
time()
)
);
} | [
"public",
"function",
"addSetCookieHeader",
"(",
"FilterResponseEvent",
"$",
"event",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"targetGroupStore",
"->",
"hasChangedTargetGroup",
"(",
")",
"||",
"$",
"event",
"->",
"getRequest",
"(",
")",
"->",
"getPathInfo",
"(",
")",
"===",
"$",
"this",
"->",
"targetGroupUrl",
")",
"{",
"return",
";",
"}",
"$",
"response",
"=",
"$",
"event",
"->",
"getResponse",
"(",
")",
";",
"$",
"response",
"->",
"headers",
"->",
"setCookie",
"(",
"new",
"Cookie",
"(",
"$",
"this",
"->",
"targetGroupCookie",
",",
"$",
"this",
"->",
"targetGroupStore",
"->",
"getTargetGroupId",
"(",
"true",
")",
",",
"AudienceTargetingCacheListener",
"::",
"TARGET_GROUP_COOKIE_LIFETIME",
")",
")",
";",
"$",
"response",
"->",
"headers",
"->",
"setCookie",
"(",
"new",
"Cookie",
"(",
"$",
"this",
"->",
"visitorSessionCookie",
",",
"time",
"(",
")",
")",
")",
";",
"}"
] | Adds the SetCookie header for the target group, if the user context has changed. In addition to that a second
cookie without a lifetime is set, whose expiration marks a new session.
@param FilterResponseEvent $event | [
"Adds",
"the",
"SetCookie",
"header",
"for",
"the",
"target",
"group",
"if",
"the",
"user",
"context",
"has",
"changed",
".",
"In",
"addition",
"to",
"that",
"a",
"second",
"cookie",
"without",
"a",
"lifetime",
"is",
"set",
"whose",
"expiration",
"marks",
"a",
"new",
"session",
"."
] | 6766a36cc2f0c807c59202bf7540a08c4ef31192 | https://github.com/sulu/sulu/blob/6766a36cc2f0c807c59202bf7540a08c4ef31192/src/Sulu/Bundle/AudienceTargetingBundle/EventListener/TargetGroupSubscriber.php#L216-L240 | train |
sulu/sulu | src/Sulu/Bundle/AudienceTargetingBundle/EventListener/TargetGroupSubscriber.php | TargetGroupSubscriber.addTargetGroupHitScript | public function addTargetGroupHitScript(FilterResponseEvent $event)
{
$request = $event->getRequest();
$response = $event->getResponse();
if ($this->preview
|| 0 !== strpos($response->headers->get('Content-Type'), 'text/html')
|| Request::METHOD_GET !== $request->getMethod()
) {
return;
}
$script = $this->twig->render('SuluAudienceTargetingBundle:Template:hit-script.html.twig', [
'url' => $this->targetGroupHitUrl,
'urlHeader' => $this->urlHeader,
'refererHeader' => $this->referrerHeader,
'uuidHeader' => $this->uuidHeader,
'uuid' => $request->attributes->has('structure') ? $request->attributes->get('structure')->getUuid() : null,
]);
$response->setContent(str_replace(
'</body>',
$script . '</body>',
$response->getContent()
));
} | php | public function addTargetGroupHitScript(FilterResponseEvent $event)
{
$request = $event->getRequest();
$response = $event->getResponse();
if ($this->preview
|| 0 !== strpos($response->headers->get('Content-Type'), 'text/html')
|| Request::METHOD_GET !== $request->getMethod()
) {
return;
}
$script = $this->twig->render('SuluAudienceTargetingBundle:Template:hit-script.html.twig', [
'url' => $this->targetGroupHitUrl,
'urlHeader' => $this->urlHeader,
'refererHeader' => $this->referrerHeader,
'uuidHeader' => $this->uuidHeader,
'uuid' => $request->attributes->has('structure') ? $request->attributes->get('structure')->getUuid() : null,
]);
$response->setContent(str_replace(
'</body>',
$script . '</body>',
$response->getContent()
));
} | [
"public",
"function",
"addTargetGroupHitScript",
"(",
"FilterResponseEvent",
"$",
"event",
")",
"{",
"$",
"request",
"=",
"$",
"event",
"->",
"getRequest",
"(",
")",
";",
"$",
"response",
"=",
"$",
"event",
"->",
"getResponse",
"(",
")",
";",
"if",
"(",
"$",
"this",
"->",
"preview",
"||",
"0",
"!==",
"strpos",
"(",
"$",
"response",
"->",
"headers",
"->",
"get",
"(",
"'Content-Type'",
")",
",",
"'text/html'",
")",
"||",
"Request",
"::",
"METHOD_GET",
"!==",
"$",
"request",
"->",
"getMethod",
"(",
")",
")",
"{",
"return",
";",
"}",
"$",
"script",
"=",
"$",
"this",
"->",
"twig",
"->",
"render",
"(",
"'SuluAudienceTargetingBundle:Template:hit-script.html.twig'",
",",
"[",
"'url'",
"=>",
"$",
"this",
"->",
"targetGroupHitUrl",
",",
"'urlHeader'",
"=>",
"$",
"this",
"->",
"urlHeader",
",",
"'refererHeader'",
"=>",
"$",
"this",
"->",
"referrerHeader",
",",
"'uuidHeader'",
"=>",
"$",
"this",
"->",
"uuidHeader",
",",
"'uuid'",
"=>",
"$",
"request",
"->",
"attributes",
"->",
"has",
"(",
"'structure'",
")",
"?",
"$",
"request",
"->",
"attributes",
"->",
"get",
"(",
"'structure'",
")",
"->",
"getUuid",
"(",
")",
":",
"null",
",",
"]",
")",
";",
"$",
"response",
"->",
"setContent",
"(",
"str_replace",
"(",
"'</body>'",
",",
"$",
"script",
".",
"'</body>'",
",",
"$",
"response",
"->",
"getContent",
"(",
")",
")",
")",
";",
"}"
] | Adds a script for triggering an ajax request, which updates the target group on every hit.
@param FilterResponseEvent $event | [
"Adds",
"a",
"script",
"for",
"triggering",
"an",
"ajax",
"request",
"which",
"updates",
"the",
"target",
"group",
"on",
"every",
"hit",
"."
] | 6766a36cc2f0c807c59202bf7540a08c4ef31192 | https://github.com/sulu/sulu/blob/6766a36cc2f0c807c59202bf7540a08c4ef31192/src/Sulu/Bundle/AudienceTargetingBundle/EventListener/TargetGroupSubscriber.php#L247-L272 | train |
sulu/sulu | src/Sulu/Bundle/AdminBundle/Admin/AdminPool.php | AdminPool.getNavigation | public function getNavigation()
{
/** @var Navigation $navigation */
$navigation = null;
$this->iterateAdmins(function(Admin $admin) use (&$navigation) {
if (null === $navigation) {
$navigation = $admin->getNavigation();
return;
}
$navigation = $navigation->merge($admin->getNavigation());
});
return $navigation;
} | php | public function getNavigation()
{
/** @var Navigation $navigation */
$navigation = null;
$this->iterateAdmins(function(Admin $admin) use (&$navigation) {
if (null === $navigation) {
$navigation = $admin->getNavigation();
return;
}
$navigation = $navigation->merge($admin->getNavigation());
});
return $navigation;
} | [
"public",
"function",
"getNavigation",
"(",
")",
"{",
"/** @var Navigation $navigation */",
"$",
"navigation",
"=",
"null",
";",
"$",
"this",
"->",
"iterateAdmins",
"(",
"function",
"(",
"Admin",
"$",
"admin",
")",
"use",
"(",
"&",
"$",
"navigation",
")",
"{",
"if",
"(",
"null",
"===",
"$",
"navigation",
")",
"{",
"$",
"navigation",
"=",
"$",
"admin",
"->",
"getNavigation",
"(",
")",
";",
"return",
";",
"}",
"$",
"navigation",
"=",
"$",
"navigation",
"->",
"merge",
"(",
"$",
"admin",
"->",
"getNavigation",
"(",
")",
")",
";",
"}",
")",
";",
"return",
"$",
"navigation",
";",
"}"
] | Returns the navigation combined from all Admin objects.
@return Navigation | [
"Returns",
"the",
"navigation",
"combined",
"from",
"all",
"Admin",
"objects",
"."
] | 6766a36cc2f0c807c59202bf7540a08c4ef31192 | https://github.com/sulu/sulu/blob/6766a36cc2f0c807c59202bf7540a08c4ef31192/src/Sulu/Bundle/AdminBundle/Admin/AdminPool.php#L51-L65 | train |
sulu/sulu | src/Sulu/Bundle/AdminBundle/Admin/AdminPool.php | AdminPool.getSecurityContexts | public function getSecurityContexts()
{
$contexts = [];
$this->iterateAdmins(function(Admin $admin) use (&$contexts) {
$contexts = array_merge_recursive($contexts, $admin->getSecurityContexts());
});
return $contexts;
} | php | public function getSecurityContexts()
{
$contexts = [];
$this->iterateAdmins(function(Admin $admin) use (&$contexts) {
$contexts = array_merge_recursive($contexts, $admin->getSecurityContexts());
});
return $contexts;
} | [
"public",
"function",
"getSecurityContexts",
"(",
")",
"{",
"$",
"contexts",
"=",
"[",
"]",
";",
"$",
"this",
"->",
"iterateAdmins",
"(",
"function",
"(",
"Admin",
"$",
"admin",
")",
"use",
"(",
"&",
"$",
"contexts",
")",
"{",
"$",
"contexts",
"=",
"array_merge_recursive",
"(",
"$",
"contexts",
",",
"$",
"admin",
"->",
"getSecurityContexts",
"(",
")",
")",
";",
"}",
")",
";",
"return",
"$",
"contexts",
";",
"}"
] | Returns the combined security contexts from all Admin objects.
@return array | [
"Returns",
"the",
"combined",
"security",
"contexts",
"from",
"all",
"Admin",
"objects",
"."
] | 6766a36cc2f0c807c59202bf7540a08c4ef31192 | https://github.com/sulu/sulu/blob/6766a36cc2f0c807c59202bf7540a08c4ef31192/src/Sulu/Bundle/AdminBundle/Admin/AdminPool.php#L72-L80 | train |
sulu/sulu | src/Sulu/Component/Util/ArrayUtils.php | ArrayUtils.filter | public static function filter(array $collection, $expression, array $context = [])
{
$language = new ExpressionLanguage();
$result = [];
foreach ($collection as $key => $item) {
if ($language->evaluate($expression, array_merge($context, ['item' => $item, 'key' => $key]))) {
$result[$key] = $item;
}
}
return $result;
} | php | public static function filter(array $collection, $expression, array $context = [])
{
$language = new ExpressionLanguage();
$result = [];
foreach ($collection as $key => $item) {
if ($language->evaluate($expression, array_merge($context, ['item' => $item, 'key' => $key]))) {
$result[$key] = $item;
}
}
return $result;
} | [
"public",
"static",
"function",
"filter",
"(",
"array",
"$",
"collection",
",",
"$",
"expression",
",",
"array",
"$",
"context",
"=",
"[",
"]",
")",
"{",
"$",
"language",
"=",
"new",
"ExpressionLanguage",
"(",
")",
";",
"$",
"result",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"collection",
"as",
"$",
"key",
"=>",
"$",
"item",
")",
"{",
"if",
"(",
"$",
"language",
"->",
"evaluate",
"(",
"$",
"expression",
",",
"array_merge",
"(",
"$",
"context",
",",
"[",
"'item'",
"=>",
"$",
"item",
",",
"'key'",
"=>",
"$",
"key",
"]",
")",
")",
")",
"{",
"$",
"result",
"[",
"$",
"key",
"]",
"=",
"$",
"item",
";",
"}",
"}",
"return",
"$",
"result",
";",
"}"
] | Filter array with given symfony-expression.
@param array $collection
@param string $expression
@param array $context
@return array | [
"Filter",
"array",
"with",
"given",
"symfony",
"-",
"expression",
"."
] | 6766a36cc2f0c807c59202bf7540a08c4ef31192 | https://github.com/sulu/sulu/blob/6766a36cc2f0c807c59202bf7540a08c4ef31192/src/Sulu/Component/Util/ArrayUtils.php#L34-L46 | train |
sulu/sulu | src/Sulu/Bundle/WebsiteBundle/Controller/WebsiteController.php | WebsiteController.renderStructure | protected function renderStructure(
StructureInterface $structure,
$attributes = [],
$preview = false,
$partial = false
) {
// extract format twig file
if (!$preview) {
$request = $this->getRequest();
$requestFormat = $request->getRequestFormat();
} else {
$requestFormat = 'html';
}
$viewTemplate = $structure->getView() . '.' . $requestFormat . '.twig';
try {
// get attributes to render template
$data = $this->getAttributes($attributes, $structure, $preview);
// if partial render only content block else full page
if ($partial) {
$content = $this->renderBlock(
$viewTemplate,
'content',
$data
);
} elseif ($preview) {
$content = $this->renderPreview(
$viewTemplate,
$data
);
} else {
$content = $this->renderView(
$viewTemplate,
$data
);
}
$response = new Response($content);
if (!$preview && $this->getCacheTimeLifeEnhancer()) {
$this->getCacheTimeLifeEnhancer()->enhance($response, $structure);
}
return $response;
} catch (InvalidArgumentException $e) {
// template not found
throw new HttpException(406, 'Error encountered when rendering content', $e);
}
} | php | protected function renderStructure(
StructureInterface $structure,
$attributes = [],
$preview = false,
$partial = false
) {
// extract format twig file
if (!$preview) {
$request = $this->getRequest();
$requestFormat = $request->getRequestFormat();
} else {
$requestFormat = 'html';
}
$viewTemplate = $structure->getView() . '.' . $requestFormat . '.twig';
try {
// get attributes to render template
$data = $this->getAttributes($attributes, $structure, $preview);
// if partial render only content block else full page
if ($partial) {
$content = $this->renderBlock(
$viewTemplate,
'content',
$data
);
} elseif ($preview) {
$content = $this->renderPreview(
$viewTemplate,
$data
);
} else {
$content = $this->renderView(
$viewTemplate,
$data
);
}
$response = new Response($content);
if (!$preview && $this->getCacheTimeLifeEnhancer()) {
$this->getCacheTimeLifeEnhancer()->enhance($response, $structure);
}
return $response;
} catch (InvalidArgumentException $e) {
// template not found
throw new HttpException(406, 'Error encountered when rendering content', $e);
}
} | [
"protected",
"function",
"renderStructure",
"(",
"StructureInterface",
"$",
"structure",
",",
"$",
"attributes",
"=",
"[",
"]",
",",
"$",
"preview",
"=",
"false",
",",
"$",
"partial",
"=",
"false",
")",
"{",
"// extract format twig file",
"if",
"(",
"!",
"$",
"preview",
")",
"{",
"$",
"request",
"=",
"$",
"this",
"->",
"getRequest",
"(",
")",
";",
"$",
"requestFormat",
"=",
"$",
"request",
"->",
"getRequestFormat",
"(",
")",
";",
"}",
"else",
"{",
"$",
"requestFormat",
"=",
"'html'",
";",
"}",
"$",
"viewTemplate",
"=",
"$",
"structure",
"->",
"getView",
"(",
")",
".",
"'.'",
".",
"$",
"requestFormat",
".",
"'.twig'",
";",
"try",
"{",
"// get attributes to render template",
"$",
"data",
"=",
"$",
"this",
"->",
"getAttributes",
"(",
"$",
"attributes",
",",
"$",
"structure",
",",
"$",
"preview",
")",
";",
"// if partial render only content block else full page",
"if",
"(",
"$",
"partial",
")",
"{",
"$",
"content",
"=",
"$",
"this",
"->",
"renderBlock",
"(",
"$",
"viewTemplate",
",",
"'content'",
",",
"$",
"data",
")",
";",
"}",
"elseif",
"(",
"$",
"preview",
")",
"{",
"$",
"content",
"=",
"$",
"this",
"->",
"renderPreview",
"(",
"$",
"viewTemplate",
",",
"$",
"data",
")",
";",
"}",
"else",
"{",
"$",
"content",
"=",
"$",
"this",
"->",
"renderView",
"(",
"$",
"viewTemplate",
",",
"$",
"data",
")",
";",
"}",
"$",
"response",
"=",
"new",
"Response",
"(",
"$",
"content",
")",
";",
"if",
"(",
"!",
"$",
"preview",
"&&",
"$",
"this",
"->",
"getCacheTimeLifeEnhancer",
"(",
")",
")",
"{",
"$",
"this",
"->",
"getCacheTimeLifeEnhancer",
"(",
")",
"->",
"enhance",
"(",
"$",
"response",
",",
"$",
"structure",
")",
";",
"}",
"return",
"$",
"response",
";",
"}",
"catch",
"(",
"InvalidArgumentException",
"$",
"e",
")",
"{",
"// template not found",
"throw",
"new",
"HttpException",
"(",
"406",
",",
"'Error encountered when rendering content'",
",",
"$",
"e",
")",
";",
"}",
"}"
] | Returns a rendered structure.
@param StructureInterface $structure The structure, which has been loaded for rendering
@param array $attributes Additional attributes, which will be passed to twig
@param bool $preview Defines if the site is rendered in preview mode
@param bool $partial Defines if only the content block of the template should be rendered
@return Response | [
"Returns",
"a",
"rendered",
"structure",
"."
] | 6766a36cc2f0c807c59202bf7540a08c4ef31192 | https://github.com/sulu/sulu/blob/6766a36cc2f0c807c59202bf7540a08c4ef31192/src/Sulu/Bundle/WebsiteBundle/Controller/WebsiteController.php#L38-L88 | train |
sulu/sulu | src/Sulu/Bundle/WebsiteBundle/Controller/WebsiteController.php | WebsiteController.getAttributes | protected function getAttributes($attributes, StructureInterface $structure = null, $preview = false)
{
return $this->get('sulu_website.resolver.parameter')->resolve(
$attributes,
$this->get('sulu_core.webspace.request_analyzer'),
$structure,
$preview
);
} | php | protected function getAttributes($attributes, StructureInterface $structure = null, $preview = false)
{
return $this->get('sulu_website.resolver.parameter')->resolve(
$attributes,
$this->get('sulu_core.webspace.request_analyzer'),
$structure,
$preview
);
} | [
"protected",
"function",
"getAttributes",
"(",
"$",
"attributes",
",",
"StructureInterface",
"$",
"structure",
"=",
"null",
",",
"$",
"preview",
"=",
"false",
")",
"{",
"return",
"$",
"this",
"->",
"get",
"(",
"'sulu_website.resolver.parameter'",
")",
"->",
"resolve",
"(",
"$",
"attributes",
",",
"$",
"this",
"->",
"get",
"(",
"'sulu_core.webspace.request_analyzer'",
")",
",",
"$",
"structure",
",",
"$",
"preview",
")",
";",
"}"
] | Generates attributes. | [
"Generates",
"attributes",
"."
] | 6766a36cc2f0c807c59202bf7540a08c4ef31192 | https://github.com/sulu/sulu/blob/6766a36cc2f0c807c59202bf7540a08c4ef31192/src/Sulu/Bundle/WebsiteBundle/Controller/WebsiteController.php#L93-L101 | train |
sulu/sulu | src/Sulu/Bundle/WebsiteBundle/Controller/WebsiteController.php | WebsiteController.renderBlock | protected function renderBlock($template, $block, $attributes = [])
{
$twig = $this->get('twig');
$attributes = $twig->mergeGlobals($attributes);
/** @var \Twig_Template $template */
$template = $twig->loadTemplate($template);
$level = ob_get_level();
ob_start();
try {
$rendered = $template->renderBlock($block, $attributes);
ob_end_clean();
return $rendered;
} catch (\Exception $e) {
while (ob_get_level() > $level) {
ob_end_clean();
}
throw $e;
}
} | php | protected function renderBlock($template, $block, $attributes = [])
{
$twig = $this->get('twig');
$attributes = $twig->mergeGlobals($attributes);
/** @var \Twig_Template $template */
$template = $twig->loadTemplate($template);
$level = ob_get_level();
ob_start();
try {
$rendered = $template->renderBlock($block, $attributes);
ob_end_clean();
return $rendered;
} catch (\Exception $e) {
while (ob_get_level() > $level) {
ob_end_clean();
}
throw $e;
}
} | [
"protected",
"function",
"renderBlock",
"(",
"$",
"template",
",",
"$",
"block",
",",
"$",
"attributes",
"=",
"[",
"]",
")",
"{",
"$",
"twig",
"=",
"$",
"this",
"->",
"get",
"(",
"'twig'",
")",
";",
"$",
"attributes",
"=",
"$",
"twig",
"->",
"mergeGlobals",
"(",
"$",
"attributes",
")",
";",
"/** @var \\Twig_Template $template */",
"$",
"template",
"=",
"$",
"twig",
"->",
"loadTemplate",
"(",
"$",
"template",
")",
";",
"$",
"level",
"=",
"ob_get_level",
"(",
")",
";",
"ob_start",
"(",
")",
";",
"try",
"{",
"$",
"rendered",
"=",
"$",
"template",
"->",
"renderBlock",
"(",
"$",
"block",
",",
"$",
"attributes",
")",
";",
"ob_end_clean",
"(",
")",
";",
"return",
"$",
"rendered",
";",
"}",
"catch",
"(",
"\\",
"Exception",
"$",
"e",
")",
"{",
"while",
"(",
"ob_get_level",
"(",
")",
">",
"$",
"level",
")",
"{",
"ob_end_clean",
"(",
")",
";",
"}",
"throw",
"$",
"e",
";",
"}",
"}"
] | Returns rendered part of template specified by block. | [
"Returns",
"rendered",
"part",
"of",
"template",
"specified",
"by",
"block",
"."
] | 6766a36cc2f0c807c59202bf7540a08c4ef31192 | https://github.com/sulu/sulu/blob/6766a36cc2f0c807c59202bf7540a08c4ef31192/src/Sulu/Bundle/WebsiteBundle/Controller/WebsiteController.php#L106-L129 | train |
sulu/sulu | src/Sulu/Bundle/MediaBundle/Api/Collection.php | Collection.addChild | public function addChild(self $child)
{
if (!is_array($this->children)) {
$this->children = [];
}
$this->children[] = $child;
} | php | public function addChild(self $child)
{
if (!is_array($this->children)) {
$this->children = [];
}
$this->children[] = $child;
} | [
"public",
"function",
"addChild",
"(",
"self",
"$",
"child",
")",
"{",
"if",
"(",
"!",
"is_array",
"(",
"$",
"this",
"->",
"children",
")",
")",
"{",
"$",
"this",
"->",
"children",
"=",
"[",
"]",
";",
"}",
"$",
"this",
"->",
"children",
"[",
"]",
"=",
"$",
"child",
";",
"}"
] | Add child to resource.
@param Collection $child | [
"Add",
"child",
"to",
"resource",
"."
] | 6766a36cc2f0c807c59202bf7540a08c4ef31192 | https://github.com/sulu/sulu/blob/6766a36cc2f0c807c59202bf7540a08c4ef31192/src/Sulu/Bundle/MediaBundle/Api/Collection.php#L156-L163 | train |
sulu/sulu | src/Sulu/Component/Content/Types/ResourceLocator/Strategy/TreeLeafEditStrategy.php | TreeLeafEditStrategy.adaptResourceLocators | private function adaptResourceLocators(ResourceSegmentBehavior $document, $userId)
{
if (!$document instanceof ChildrenBehavior) {
return;
}
$webspaceKey = $this->documentInspector->getWebspace($document);
$languageCode = $this->documentInspector->getOriginalLocale($document);
$node = $this->documentInspector->getNode($document);
$node->getSession()->save();
foreach ($document->getChildren() as $childDocument) {
// skip documents without assigned resource segment
if (!$childDocument instanceof ResourceSegmentBehavior
|| !($currentResourceLocator = $childDocument->getResourceSegment())
) {
$this->adaptResourceLocators($childDocument, $userId);
continue;
}
// build new resource segment based on parent changes
$parentUuid = $this->documentInspector->getUuid($document);
$childPart = $this->getChildPart($currentResourceLocator);
$newResourceLocator = $this->generate($childPart, $parentUuid, $webspaceKey, $languageCode);
// save new resource locator
$childNode = $this->documentInspector->getNode($childDocument);
$templatePropertyName = $this->nodeHelper->getTranslatedPropertyName('template', $languageCode);
$template = $childNode->getPropertyValue($templatePropertyName);
$structure = $this->structureManager->getStructure($template);
$property = $structure->getPropertyByTagName('sulu.rlp');
$property->setValue($newResourceLocator);
$contentType = $this->contentTypeManager->get($property->getContentTypeName());
$translatedProperty = $this->nodeHelper->getTranslatedProperty($property, $languageCode);
$contentType->write($childNode, $translatedProperty, $userId, $webspaceKey, $languageCode, null);
$childDocument->setResourceSegment($newResourceLocator);
// do not save routes if unpublished
if (!$childDocument->getPublished()) {
$this->adaptResourceLocators($childDocument, $userId);
} else {
$this->save($childDocument, $userId);
}
}
} | php | private function adaptResourceLocators(ResourceSegmentBehavior $document, $userId)
{
if (!$document instanceof ChildrenBehavior) {
return;
}
$webspaceKey = $this->documentInspector->getWebspace($document);
$languageCode = $this->documentInspector->getOriginalLocale($document);
$node = $this->documentInspector->getNode($document);
$node->getSession()->save();
foreach ($document->getChildren() as $childDocument) {
// skip documents without assigned resource segment
if (!$childDocument instanceof ResourceSegmentBehavior
|| !($currentResourceLocator = $childDocument->getResourceSegment())
) {
$this->adaptResourceLocators($childDocument, $userId);
continue;
}
// build new resource segment based on parent changes
$parentUuid = $this->documentInspector->getUuid($document);
$childPart = $this->getChildPart($currentResourceLocator);
$newResourceLocator = $this->generate($childPart, $parentUuid, $webspaceKey, $languageCode);
// save new resource locator
$childNode = $this->documentInspector->getNode($childDocument);
$templatePropertyName = $this->nodeHelper->getTranslatedPropertyName('template', $languageCode);
$template = $childNode->getPropertyValue($templatePropertyName);
$structure = $this->structureManager->getStructure($template);
$property = $structure->getPropertyByTagName('sulu.rlp');
$property->setValue($newResourceLocator);
$contentType = $this->contentTypeManager->get($property->getContentTypeName());
$translatedProperty = $this->nodeHelper->getTranslatedProperty($property, $languageCode);
$contentType->write($childNode, $translatedProperty, $userId, $webspaceKey, $languageCode, null);
$childDocument->setResourceSegment($newResourceLocator);
// do not save routes if unpublished
if (!$childDocument->getPublished()) {
$this->adaptResourceLocators($childDocument, $userId);
} else {
$this->save($childDocument, $userId);
}
}
} | [
"private",
"function",
"adaptResourceLocators",
"(",
"ResourceSegmentBehavior",
"$",
"document",
",",
"$",
"userId",
")",
"{",
"if",
"(",
"!",
"$",
"document",
"instanceof",
"ChildrenBehavior",
")",
"{",
"return",
";",
"}",
"$",
"webspaceKey",
"=",
"$",
"this",
"->",
"documentInspector",
"->",
"getWebspace",
"(",
"$",
"document",
")",
";",
"$",
"languageCode",
"=",
"$",
"this",
"->",
"documentInspector",
"->",
"getOriginalLocale",
"(",
"$",
"document",
")",
";",
"$",
"node",
"=",
"$",
"this",
"->",
"documentInspector",
"->",
"getNode",
"(",
"$",
"document",
")",
";",
"$",
"node",
"->",
"getSession",
"(",
")",
"->",
"save",
"(",
")",
";",
"foreach",
"(",
"$",
"document",
"->",
"getChildren",
"(",
")",
"as",
"$",
"childDocument",
")",
"{",
"// skip documents without assigned resource segment",
"if",
"(",
"!",
"$",
"childDocument",
"instanceof",
"ResourceSegmentBehavior",
"||",
"!",
"(",
"$",
"currentResourceLocator",
"=",
"$",
"childDocument",
"->",
"getResourceSegment",
"(",
")",
")",
")",
"{",
"$",
"this",
"->",
"adaptResourceLocators",
"(",
"$",
"childDocument",
",",
"$",
"userId",
")",
";",
"continue",
";",
"}",
"// build new resource segment based on parent changes",
"$",
"parentUuid",
"=",
"$",
"this",
"->",
"documentInspector",
"->",
"getUuid",
"(",
"$",
"document",
")",
";",
"$",
"childPart",
"=",
"$",
"this",
"->",
"getChildPart",
"(",
"$",
"currentResourceLocator",
")",
";",
"$",
"newResourceLocator",
"=",
"$",
"this",
"->",
"generate",
"(",
"$",
"childPart",
",",
"$",
"parentUuid",
",",
"$",
"webspaceKey",
",",
"$",
"languageCode",
")",
";",
"// save new resource locator",
"$",
"childNode",
"=",
"$",
"this",
"->",
"documentInspector",
"->",
"getNode",
"(",
"$",
"childDocument",
")",
";",
"$",
"templatePropertyName",
"=",
"$",
"this",
"->",
"nodeHelper",
"->",
"getTranslatedPropertyName",
"(",
"'template'",
",",
"$",
"languageCode",
")",
";",
"$",
"template",
"=",
"$",
"childNode",
"->",
"getPropertyValue",
"(",
"$",
"templatePropertyName",
")",
";",
"$",
"structure",
"=",
"$",
"this",
"->",
"structureManager",
"->",
"getStructure",
"(",
"$",
"template",
")",
";",
"$",
"property",
"=",
"$",
"structure",
"->",
"getPropertyByTagName",
"(",
"'sulu.rlp'",
")",
";",
"$",
"property",
"->",
"setValue",
"(",
"$",
"newResourceLocator",
")",
";",
"$",
"contentType",
"=",
"$",
"this",
"->",
"contentTypeManager",
"->",
"get",
"(",
"$",
"property",
"->",
"getContentTypeName",
"(",
")",
")",
";",
"$",
"translatedProperty",
"=",
"$",
"this",
"->",
"nodeHelper",
"->",
"getTranslatedProperty",
"(",
"$",
"property",
",",
"$",
"languageCode",
")",
";",
"$",
"contentType",
"->",
"write",
"(",
"$",
"childNode",
",",
"$",
"translatedProperty",
",",
"$",
"userId",
",",
"$",
"webspaceKey",
",",
"$",
"languageCode",
",",
"null",
")",
";",
"$",
"childDocument",
"->",
"setResourceSegment",
"(",
"$",
"newResourceLocator",
")",
";",
"// do not save routes if unpublished",
"if",
"(",
"!",
"$",
"childDocument",
"->",
"getPublished",
"(",
")",
")",
"{",
"$",
"this",
"->",
"adaptResourceLocators",
"(",
"$",
"childDocument",
",",
"$",
"userId",
")",
";",
"}",
"else",
"{",
"$",
"this",
"->",
"save",
"(",
"$",
"childDocument",
",",
"$",
"userId",
")",
";",
"}",
"}",
"}"
] | adopts resource locator of children by iteration.
@param ResourceSegmentBehavior $document
@param int $userId | [
"adopts",
"resource",
"locator",
"of",
"children",
"by",
"iteration",
"."
] | 6766a36cc2f0c807c59202bf7540a08c4ef31192 | https://github.com/sulu/sulu/blob/6766a36cc2f0c807c59202bf7540a08c4ef31192/src/Sulu/Component/Content/Types/ResourceLocator/Strategy/TreeLeafEditStrategy.php#L66-L114 | train |
sulu/sulu | src/Sulu/Component/Rest/RestController.php | RestController.replaceOrAddUrlString | public function replaceOrAddUrlString($url, $key, $value, $add = true)
{
if ($value) {
if ($pos = strpos($url, $key)) {
return preg_replace('/(.*' . $key . ')([\,|\w]*)(\&*.*)/', '${1}' . $value . '${3}', $url);
} else {
if ($add) {
$and = (false === strpos($url, '?')) ? '?' : '&';
return $url . $and . $key . $value;
}
}
} else {
// remove if key exists
if ($pos = strpos($url, $key)) {
$result = preg_replace('/(.*)([\\?|\&]{1}' . $key . ')([\,|\w]*)(\&*.*)/', '${1}${4}', $url);
// if was first variable, redo questionmark
if (strpos($url, '?' . $key)) {
$result = preg_replace('/&/', '?', $result, 1);
}
return $result;
}
}
return $url;
} | php | public function replaceOrAddUrlString($url, $key, $value, $add = true)
{
if ($value) {
if ($pos = strpos($url, $key)) {
return preg_replace('/(.*' . $key . ')([\,|\w]*)(\&*.*)/', '${1}' . $value . '${3}', $url);
} else {
if ($add) {
$and = (false === strpos($url, '?')) ? '?' : '&';
return $url . $and . $key . $value;
}
}
} else {
// remove if key exists
if ($pos = strpos($url, $key)) {
$result = preg_replace('/(.*)([\\?|\&]{1}' . $key . ')([\,|\w]*)(\&*.*)/', '${1}${4}', $url);
// if was first variable, redo questionmark
if (strpos($url, '?' . $key)) {
$result = preg_replace('/&/', '?', $result, 1);
}
return $result;
}
}
return $url;
} | [
"public",
"function",
"replaceOrAddUrlString",
"(",
"$",
"url",
",",
"$",
"key",
",",
"$",
"value",
",",
"$",
"add",
"=",
"true",
")",
"{",
"if",
"(",
"$",
"value",
")",
"{",
"if",
"(",
"$",
"pos",
"=",
"strpos",
"(",
"$",
"url",
",",
"$",
"key",
")",
")",
"{",
"return",
"preg_replace",
"(",
"'/(.*'",
".",
"$",
"key",
".",
"')([\\,|\\w]*)(\\&*.*)/'",
",",
"'${1}'",
".",
"$",
"value",
".",
"'${3}'",
",",
"$",
"url",
")",
";",
"}",
"else",
"{",
"if",
"(",
"$",
"add",
")",
"{",
"$",
"and",
"=",
"(",
"false",
"===",
"strpos",
"(",
"$",
"url",
",",
"'?'",
")",
")",
"?",
"'?'",
":",
"'&'",
";",
"return",
"$",
"url",
".",
"$",
"and",
".",
"$",
"key",
".",
"$",
"value",
";",
"}",
"}",
"}",
"else",
"{",
"// remove if key exists",
"if",
"(",
"$",
"pos",
"=",
"strpos",
"(",
"$",
"url",
",",
"$",
"key",
")",
")",
"{",
"$",
"result",
"=",
"preg_replace",
"(",
"'/(.*)([\\\\?|\\&]{1}'",
".",
"$",
"key",
".",
"')([\\,|\\w]*)(\\&*.*)/'",
",",
"'${1}${4}'",
",",
"$",
"url",
")",
";",
"// if was first variable, redo questionmark",
"if",
"(",
"strpos",
"(",
"$",
"url",
",",
"'?'",
".",
"$",
"key",
")",
")",
"{",
"$",
"result",
"=",
"preg_replace",
"(",
"'/&/'",
",",
"'?'",
",",
"$",
"result",
",",
"1",
")",
";",
"}",
"return",
"$",
"result",
";",
"}",
"}",
"return",
"$",
"url",
";",
"}"
] | function replaces a url parameter.
@param string $url String the complete url
@param string $key String parameter name (e.g. page=)
@param string $value replace value
@param bool $add defines if value should be added
@return mixed|string
@deprecated | [
"function",
"replaces",
"a",
"url",
"parameter",
"."
] | 6766a36cc2f0c807c59202bf7540a08c4ef31192 | https://github.com/sulu/sulu/blob/6766a36cc2f0c807c59202bf7540a08c4ef31192/src/Sulu/Component/Rest/RestController.php#L86-L113 | train |
sulu/sulu | src/Sulu/Component/Rest/RestController.php | RestController.responseGetById | protected function responseGetById($id, $findCallback)
{
$entity = $findCallback($id);
if (!$entity) {
$exception = new EntityNotFoundException(self::$entityName, $id);
// Return a 404 together with an error message, given by the exception, if the entity is not found
$view = $this->view(
$exception->toArray(),
404
);
} else {
$view = $this->view($entity, 200);
}
return $view;
} | php | protected function responseGetById($id, $findCallback)
{
$entity = $findCallback($id);
if (!$entity) {
$exception = new EntityNotFoundException(self::$entityName, $id);
// Return a 404 together with an error message, given by the exception, if the entity is not found
$view = $this->view(
$exception->toArray(),
404
);
} else {
$view = $this->view($entity, 200);
}
return $view;
} | [
"protected",
"function",
"responseGetById",
"(",
"$",
"id",
",",
"$",
"findCallback",
")",
"{",
"$",
"entity",
"=",
"$",
"findCallback",
"(",
"$",
"id",
")",
";",
"if",
"(",
"!",
"$",
"entity",
")",
"{",
"$",
"exception",
"=",
"new",
"EntityNotFoundException",
"(",
"self",
"::",
"$",
"entityName",
",",
"$",
"id",
")",
";",
"// Return a 404 together with an error message, given by the exception, if the entity is not found",
"$",
"view",
"=",
"$",
"this",
"->",
"view",
"(",
"$",
"exception",
"->",
"toArray",
"(",
")",
",",
"404",
")",
";",
"}",
"else",
"{",
"$",
"view",
"=",
"$",
"this",
"->",
"view",
"(",
"$",
"entity",
",",
"200",
")",
";",
"}",
"return",
"$",
"view",
";",
"}"
] | Returns the response with the entity with the given id, or a response with a status of 404, in case the entity
is not found. The find method is injected by a callback.
@param $id
@param callable $findCallback
@return View | [
"Returns",
"the",
"response",
"with",
"the",
"entity",
"with",
"the",
"given",
"id",
"or",
"a",
"response",
"with",
"a",
"status",
"of",
"404",
"in",
"case",
"the",
"entity",
"is",
"not",
"found",
".",
"The",
"find",
"method",
"is",
"injected",
"by",
"a",
"callback",
"."
] | 6766a36cc2f0c807c59202bf7540a08c4ef31192 | https://github.com/sulu/sulu/blob/6766a36cc2f0c807c59202bf7540a08c4ef31192/src/Sulu/Component/Rest/RestController.php#L124-L140 | train |
sulu/sulu | src/Sulu/Component/Rest/RestController.php | RestController.responseDelete | public function responseDelete($id, $deleteCallback)
{
try {
$deleteCallback($id);
$view = $this->view(null, 204);
} catch (EntityNotFoundException $enfe) {
$view = $this->view($enfe->toArray(), 404);
} catch (RestException $re) {
$view = $this->view($re->toArray(), 400);
}
return $view;
} | php | public function responseDelete($id, $deleteCallback)
{
try {
$deleteCallback($id);
$view = $this->view(null, 204);
} catch (EntityNotFoundException $enfe) {
$view = $this->view($enfe->toArray(), 404);
} catch (RestException $re) {
$view = $this->view($re->toArray(), 400);
}
return $view;
} | [
"public",
"function",
"responseDelete",
"(",
"$",
"id",
",",
"$",
"deleteCallback",
")",
"{",
"try",
"{",
"$",
"deleteCallback",
"(",
"$",
"id",
")",
";",
"$",
"view",
"=",
"$",
"this",
"->",
"view",
"(",
"null",
",",
"204",
")",
";",
"}",
"catch",
"(",
"EntityNotFoundException",
"$",
"enfe",
")",
"{",
"$",
"view",
"=",
"$",
"this",
"->",
"view",
"(",
"$",
"enfe",
"->",
"toArray",
"(",
")",
",",
"404",
")",
";",
"}",
"catch",
"(",
"RestException",
"$",
"re",
")",
"{",
"$",
"view",
"=",
"$",
"this",
"->",
"view",
"(",
"$",
"re",
"->",
"toArray",
"(",
")",
",",
"400",
")",
";",
"}",
"return",
"$",
"view",
";",
"}"
] | Deletes the entity with the given id using the deleteCallback and return a successful response, or an error
message with a 4xx status code.
@param $id
@param $deleteCallback
@return \FOS\RestBundle\View\View | [
"Deletes",
"the",
"entity",
"with",
"the",
"given",
"id",
"using",
"the",
"deleteCallback",
"and",
"return",
"a",
"successful",
"response",
"or",
"an",
"error",
"message",
"with",
"a",
"4xx",
"status",
"code",
"."
] | 6766a36cc2f0c807c59202bf7540a08c4ef31192 | https://github.com/sulu/sulu/blob/6766a36cc2f0c807c59202bf7540a08c4ef31192/src/Sulu/Component/Rest/RestController.php#L151-L163 | train |
sulu/sulu | src/Sulu/Bundle/MarkupBundle/Listener/MarkupListener.php | MarkupListener.replaceMarkup | public function replaceMarkup(FilterResponseEvent $event)
{
$request = $event->getRequest();
$response = $event->getResponse();
$format = $request->getRequestFormat();
$content = $response->getContent();
if (!$content || !array_key_exists($format, $this->markupParser)) {
return;
}
$response->setContent(
$this->markupParser[$format]->parse($content, $request->getLocale())
);
} | php | public function replaceMarkup(FilterResponseEvent $event)
{
$request = $event->getRequest();
$response = $event->getResponse();
$format = $request->getRequestFormat();
$content = $response->getContent();
if (!$content || !array_key_exists($format, $this->markupParser)) {
return;
}
$response->setContent(
$this->markupParser[$format]->parse($content, $request->getLocale())
);
} | [
"public",
"function",
"replaceMarkup",
"(",
"FilterResponseEvent",
"$",
"event",
")",
"{",
"$",
"request",
"=",
"$",
"event",
"->",
"getRequest",
"(",
")",
";",
"$",
"response",
"=",
"$",
"event",
"->",
"getResponse",
"(",
")",
";",
"$",
"format",
"=",
"$",
"request",
"->",
"getRequestFormat",
"(",
")",
";",
"$",
"content",
"=",
"$",
"response",
"->",
"getContent",
"(",
")",
";",
"if",
"(",
"!",
"$",
"content",
"||",
"!",
"array_key_exists",
"(",
"$",
"format",
",",
"$",
"this",
"->",
"markupParser",
")",
")",
"{",
"return",
";",
"}",
"$",
"response",
"->",
"setContent",
"(",
"$",
"this",
"->",
"markupParser",
"[",
"$",
"format",
"]",
"->",
"parse",
"(",
"$",
"content",
",",
"$",
"request",
"->",
"getLocale",
"(",
")",
")",
")",
";",
"}"
] | Parses content of response and set the replaced html as new content.
@param FilterResponseEvent $event | [
"Parses",
"content",
"of",
"response",
"and",
"set",
"the",
"replaced",
"html",
"as",
"new",
"content",
"."
] | 6766a36cc2f0c807c59202bf7540a08c4ef31192 | https://github.com/sulu/sulu/blob/6766a36cc2f0c807c59202bf7540a08c4ef31192/src/Sulu/Bundle/MarkupBundle/Listener/MarkupListener.php#L40-L54 | train |
sulu/sulu | src/Sulu/Bundle/ContactBundle/Api/Contact.php | Contact.getLocales | public function getLocales()
{
$entities = [];
if ($this->entity->getLocales()) {
foreach ($this->entity->getLocales() as $locale) {
$entities[] = new ContactLocale($locale);
}
}
return $entities;
} | php | public function getLocales()
{
$entities = [];
if ($this->entity->getLocales()) {
foreach ($this->entity->getLocales() as $locale) {
$entities[] = new ContactLocale($locale);
}
}
return $entities;
} | [
"public",
"function",
"getLocales",
"(",
")",
"{",
"$",
"entities",
"=",
"[",
"]",
";",
"if",
"(",
"$",
"this",
"->",
"entity",
"->",
"getLocales",
"(",
")",
")",
"{",
"foreach",
"(",
"$",
"this",
"->",
"entity",
"->",
"getLocales",
"(",
")",
"as",
"$",
"locale",
")",
"{",
"$",
"entities",
"[",
"]",
"=",
"new",
"ContactLocale",
"(",
"$",
"locale",
")",
";",
"}",
"}",
"return",
"$",
"entities",
";",
"}"
] | Get locales.
@return array
@VirtualProperty
@SerializedName("locales")
@Groups({"fullContact"}) | [
"Get",
"locales",
"."
] | 6766a36cc2f0c807c59202bf7540a08c4ef31192 | https://github.com/sulu/sulu/blob/6766a36cc2f0c807c59202bf7540a08c4ef31192/src/Sulu/Bundle/ContactBundle/Api/Contact.php#L343-L353 | train |
sulu/sulu | src/Sulu/Bundle/ContactBundle/Api/Contact.php | Contact.getAvatar | public function getAvatar()
{
if ($this->avatar) {
return [
'id' => $this->avatar->getId(),
'url' => $this->avatar->getUrl(),
'thumbnails' => $this->avatar->getFormats(),
];
}
return;
} | php | public function getAvatar()
{
if ($this->avatar) {
return [
'id' => $this->avatar->getId(),
'url' => $this->avatar->getUrl(),
'thumbnails' => $this->avatar->getFormats(),
];
}
return;
} | [
"public",
"function",
"getAvatar",
"(",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"avatar",
")",
"{",
"return",
"[",
"'id'",
"=>",
"$",
"this",
"->",
"avatar",
"->",
"getId",
"(",
")",
",",
"'url'",
"=>",
"$",
"this",
"->",
"avatar",
"->",
"getUrl",
"(",
")",
",",
"'thumbnails'",
"=>",
"$",
"this",
"->",
"avatar",
"->",
"getFormats",
"(",
")",
",",
"]",
";",
"}",
"return",
";",
"}"
] | Get the contacts avatar and return the array of different formats.
@return Media
@VirtualProperty
@SerializedName("avatar")
@Groups({"fullContact","partialContact"}) | [
"Get",
"the",
"contacts",
"avatar",
"and",
"return",
"the",
"array",
"of",
"different",
"formats",
"."
] | 6766a36cc2f0c807c59202bf7540a08c4ef31192 | https://github.com/sulu/sulu/blob/6766a36cc2f0c807c59202bf7540a08c4ef31192/src/Sulu/Bundle/ContactBundle/Api/Contact.php#L747-L758 | train |
sulu/sulu | src/Sulu/Bundle/ContactBundle/Api/Contact.php | Contact.getAccount | public function getAccount()
{
$mainAccount = $this->entity->getMainAccount();
if (!is_null($mainAccount)) {
return new Account($mainAccount, $this->locale);
}
return;
} | php | public function getAccount()
{
$mainAccount = $this->entity->getMainAccount();
if (!is_null($mainAccount)) {
return new Account($mainAccount, $this->locale);
}
return;
} | [
"public",
"function",
"getAccount",
"(",
")",
"{",
"$",
"mainAccount",
"=",
"$",
"this",
"->",
"entity",
"->",
"getMainAccount",
"(",
")",
";",
"if",
"(",
"!",
"is_null",
"(",
"$",
"mainAccount",
")",
")",
"{",
"return",
"new",
"Account",
"(",
"$",
"mainAccount",
",",
"$",
"this",
"->",
"locale",
")",
";",
"}",
"return",
";",
"}"
] | Returns main account.
@VirtualProperty
@SerializedName("account")
@Groups({"fullContact"}) | [
"Returns",
"main",
"account",
"."
] | 6766a36cc2f0c807c59202bf7540a08c4ef31192 | https://github.com/sulu/sulu/blob/6766a36cc2f0c807c59202bf7540a08c4ef31192/src/Sulu/Bundle/ContactBundle/Api/Contact.php#L883-L891 | train |
sulu/sulu | src/Sulu/Bundle/ContactBundle/Api/Contact.php | Contact.getAddresses | public function getAddresses()
{
$contactAddresses = $this->entity->getContactAddresses();
$addresses = [];
if (!is_null($contactAddresses)) {
/** @var ContactAddressEntity $contactAddress */
foreach ($contactAddresses as $contactAddress) {
$address = $contactAddress->getAddress();
$address->setPrimaryAddress($contactAddress->getMain());
$addresses[] = new Address($address, $this->locale);
}
}
return $addresses;
} | php | public function getAddresses()
{
$contactAddresses = $this->entity->getContactAddresses();
$addresses = [];
if (!is_null($contactAddresses)) {
/** @var ContactAddressEntity $contactAddress */
foreach ($contactAddresses as $contactAddress) {
$address = $contactAddress->getAddress();
$address->setPrimaryAddress($contactAddress->getMain());
$addresses[] = new Address($address, $this->locale);
}
}
return $addresses;
} | [
"public",
"function",
"getAddresses",
"(",
")",
"{",
"$",
"contactAddresses",
"=",
"$",
"this",
"->",
"entity",
"->",
"getContactAddresses",
"(",
")",
";",
"$",
"addresses",
"=",
"[",
"]",
";",
"if",
"(",
"!",
"is_null",
"(",
"$",
"contactAddresses",
")",
")",
"{",
"/** @var ContactAddressEntity $contactAddress */",
"foreach",
"(",
"$",
"contactAddresses",
"as",
"$",
"contactAddress",
")",
"{",
"$",
"address",
"=",
"$",
"contactAddress",
"->",
"getAddress",
"(",
")",
";",
"$",
"address",
"->",
"setPrimaryAddress",
"(",
"$",
"contactAddress",
"->",
"getMain",
"(",
")",
")",
";",
"$",
"addresses",
"[",
"]",
"=",
"new",
"Address",
"(",
"$",
"address",
",",
"$",
"this",
"->",
"locale",
")",
";",
"}",
"}",
"return",
"$",
"addresses",
";",
"}"
] | Returns main addresses.
@VirtualProperty
@SerializedName("addresses")
@Groups({"fullContact"}) | [
"Returns",
"main",
"addresses",
"."
] | 6766a36cc2f0c807c59202bf7540a08c4ef31192 | https://github.com/sulu/sulu/blob/6766a36cc2f0c807c59202bf7540a08c4ef31192/src/Sulu/Bundle/ContactBundle/Api/Contact.php#L900-L915 | train |
sulu/sulu | src/Sulu/Bundle/ContactBundle/Api/Contact.php | Contact.getMedias | public function getMedias()
{
$entities = [];
if ($this->entity->getMedias()) {
foreach ($this->entity->getMedias() as $media) {
$entities[] = new Media($media, $this->locale, null);
}
}
return $entities;
} | php | public function getMedias()
{
$entities = [];
if ($this->entity->getMedias()) {
foreach ($this->entity->getMedias() as $media) {
$entities[] = new Media($media, $this->locale, null);
}
}
return $entities;
} | [
"public",
"function",
"getMedias",
"(",
")",
"{",
"$",
"entities",
"=",
"[",
"]",
";",
"if",
"(",
"$",
"this",
"->",
"entity",
"->",
"getMedias",
"(",
")",
")",
"{",
"foreach",
"(",
"$",
"this",
"->",
"entity",
"->",
"getMedias",
"(",
")",
"as",
"$",
"media",
")",
"{",
"$",
"entities",
"[",
"]",
"=",
"new",
"Media",
"(",
"$",
"media",
",",
"$",
"this",
"->",
"locale",
",",
"null",
")",
";",
"}",
"}",
"return",
"$",
"entities",
";",
"}"
] | Get medias.
@return Media[]
@VirtualProperty
@SerializedName("medias")
@Groups({"fullContact"}) | [
"Get",
"medias",
"."
] | 6766a36cc2f0c807c59202bf7540a08c4ef31192 | https://github.com/sulu/sulu/blob/6766a36cc2f0c807c59202bf7540a08c4ef31192/src/Sulu/Bundle/ContactBundle/Api/Contact.php#L1085-L1095 | train |
sulu/sulu | src/Sulu/Bundle/MediaBundle/Entity/MediaRepository.php | MediaRepository.extractFilterVars | private function extractFilterVars(array $filter)
{
$collection = array_key_exists('collection', $filter) ? $filter['collection'] : null;
$systemCollections = array_key_exists('systemCollections', $filter) ? $filter['systemCollections'] : true;
$types = array_key_exists('types', $filter) ? $filter['types'] : null;
$search = array_key_exists('search', $filter) ? $filter['search'] : null;
$orderBy = array_key_exists('orderBy', $filter) ? $filter['orderBy'] : null;
$orderSort = array_key_exists('orderSort', $filter) ? $filter['orderSort'] : null;
$ids = array_key_exists('ids', $filter) ? $filter['ids'] : null;
return [$collection, $systemCollections, $types, $search, $orderBy, $orderSort, $ids];
} | php | private function extractFilterVars(array $filter)
{
$collection = array_key_exists('collection', $filter) ? $filter['collection'] : null;
$systemCollections = array_key_exists('systemCollections', $filter) ? $filter['systemCollections'] : true;
$types = array_key_exists('types', $filter) ? $filter['types'] : null;
$search = array_key_exists('search', $filter) ? $filter['search'] : null;
$orderBy = array_key_exists('orderBy', $filter) ? $filter['orderBy'] : null;
$orderSort = array_key_exists('orderSort', $filter) ? $filter['orderSort'] : null;
$ids = array_key_exists('ids', $filter) ? $filter['ids'] : null;
return [$collection, $systemCollections, $types, $search, $orderBy, $orderSort, $ids];
} | [
"private",
"function",
"extractFilterVars",
"(",
"array",
"$",
"filter",
")",
"{",
"$",
"collection",
"=",
"array_key_exists",
"(",
"'collection'",
",",
"$",
"filter",
")",
"?",
"$",
"filter",
"[",
"'collection'",
"]",
":",
"null",
";",
"$",
"systemCollections",
"=",
"array_key_exists",
"(",
"'systemCollections'",
",",
"$",
"filter",
")",
"?",
"$",
"filter",
"[",
"'systemCollections'",
"]",
":",
"true",
";",
"$",
"types",
"=",
"array_key_exists",
"(",
"'types'",
",",
"$",
"filter",
")",
"?",
"$",
"filter",
"[",
"'types'",
"]",
":",
"null",
";",
"$",
"search",
"=",
"array_key_exists",
"(",
"'search'",
",",
"$",
"filter",
")",
"?",
"$",
"filter",
"[",
"'search'",
"]",
":",
"null",
";",
"$",
"orderBy",
"=",
"array_key_exists",
"(",
"'orderBy'",
",",
"$",
"filter",
")",
"?",
"$",
"filter",
"[",
"'orderBy'",
"]",
":",
"null",
";",
"$",
"orderSort",
"=",
"array_key_exists",
"(",
"'orderSort'",
",",
"$",
"filter",
")",
"?",
"$",
"filter",
"[",
"'orderSort'",
"]",
":",
"null",
";",
"$",
"ids",
"=",
"array_key_exists",
"(",
"'ids'",
",",
"$",
"filter",
")",
"?",
"$",
"filter",
"[",
"'ids'",
"]",
":",
"null",
";",
"return",
"[",
"$",
"collection",
",",
"$",
"systemCollections",
",",
"$",
"types",
",",
"$",
"search",
",",
"$",
"orderBy",
",",
"$",
"orderSort",
",",
"$",
"ids",
"]",
";",
"}"
] | Extracts filter vars.
@param array $filter
@return array | [
"Extracts",
"filter",
"vars",
"."
] | 6766a36cc2f0c807c59202bf7540a08c4ef31192 | https://github.com/sulu/sulu/blob/6766a36cc2f0c807c59202bf7540a08c4ef31192/src/Sulu/Bundle/MediaBundle/Entity/MediaRepository.php#L258-L269 | train |
sulu/sulu | src/Sulu/Bundle/MediaBundle/Entity/MediaRepository.php | MediaRepository.findMediaWithFilenameInCollectionWithId | public function findMediaWithFilenameInCollectionWithId($filename, $collectionId)
{
$queryBuilder = $this->createQueryBuilder('media')
->innerJoin('media.files', 'files')
->innerJoin('files.fileVersions', 'versions', 'WITH', 'versions.version = files.version')
->join('media.collection', 'collection')
->where('collection.id = :collectionId')
->andWhere('versions.name = :filename')
->orderBy('versions.created')
->setMaxResults(1)
->setParameter('filename', $filename)
->setParameter('collectionId', $collectionId);
$result = $queryBuilder->getQuery()->getResult();
if (count($result) > 0) {
return $result[0];
}
return;
} | php | public function findMediaWithFilenameInCollectionWithId($filename, $collectionId)
{
$queryBuilder = $this->createQueryBuilder('media')
->innerJoin('media.files', 'files')
->innerJoin('files.fileVersions', 'versions', 'WITH', 'versions.version = files.version')
->join('media.collection', 'collection')
->where('collection.id = :collectionId')
->andWhere('versions.name = :filename')
->orderBy('versions.created')
->setMaxResults(1)
->setParameter('filename', $filename)
->setParameter('collectionId', $collectionId);
$result = $queryBuilder->getQuery()->getResult();
if (count($result) > 0) {
return $result[0];
}
return;
} | [
"public",
"function",
"findMediaWithFilenameInCollectionWithId",
"(",
"$",
"filename",
",",
"$",
"collectionId",
")",
"{",
"$",
"queryBuilder",
"=",
"$",
"this",
"->",
"createQueryBuilder",
"(",
"'media'",
")",
"->",
"innerJoin",
"(",
"'media.files'",
",",
"'files'",
")",
"->",
"innerJoin",
"(",
"'files.fileVersions'",
",",
"'versions'",
",",
"'WITH'",
",",
"'versions.version = files.version'",
")",
"->",
"join",
"(",
"'media.collection'",
",",
"'collection'",
")",
"->",
"where",
"(",
"'collection.id = :collectionId'",
")",
"->",
"andWhere",
"(",
"'versions.name = :filename'",
")",
"->",
"orderBy",
"(",
"'versions.created'",
")",
"->",
"setMaxResults",
"(",
"1",
")",
"->",
"setParameter",
"(",
"'filename'",
",",
"$",
"filename",
")",
"->",
"setParameter",
"(",
"'collectionId'",
",",
"$",
"collectionId",
")",
";",
"$",
"result",
"=",
"$",
"queryBuilder",
"->",
"getQuery",
"(",
")",
"->",
"getResult",
"(",
")",
";",
"if",
"(",
"count",
"(",
"$",
"result",
")",
">",
"0",
")",
"{",
"return",
"$",
"result",
"[",
"0",
"]",
";",
"}",
"return",
";",
"}"
] | Returns the most recent version of a media for the specified
filename within a collection.
@param string $filename
@param int $collectionId
@return Media | [
"Returns",
"the",
"most",
"recent",
"version",
"of",
"a",
"media",
"for",
"the",
"specified",
"filename",
"within",
"a",
"collection",
"."
] | 6766a36cc2f0c807c59202bf7540a08c4ef31192 | https://github.com/sulu/sulu/blob/6766a36cc2f0c807c59202bf7540a08c4ef31192/src/Sulu/Bundle/MediaBundle/Entity/MediaRepository.php#L280-L299 | train |
sulu/sulu | src/Sulu/Bundle/MediaBundle/Entity/MediaRepository.php | MediaRepository.getIdsQuery | private function getIdsQuery(
$collection = null,
$systemCollections = true,
$types = null,
$search = null,
$orderBy = null,
$orderSort = null,
$limit = null,
$offset = null,
$select = 'media.id'
) {
$queryBuilder = $this->createQueryBuilder('media')->select($select);
$queryBuilder->innerJoin('media.collection', 'collection');
if (!empty($collection)) {
$queryBuilder->andWhere('collection.id = :collection');
$queryBuilder->setParameter('collection', $collection);
}
if (!$systemCollections) {
$queryBuilder->leftJoin('collection.type', 'collectionType');
$queryBuilder->andWhere(
sprintf('collectionType.key != \'%s\'', SystemCollectionManagerInterface::COLLECTION_TYPE)
);
}
if (!empty($types)) {
$queryBuilder->innerJoin('media.type', 'type');
$queryBuilder->andWhere('type.name IN (:types)');
$queryBuilder->setParameter('types', $types);
}
if (!empty($search)) {
$queryBuilder
->innerJoin('media.files', 'file')
->innerJoin('file.fileVersions', 'fileVersion', 'WITH', 'fileVersion.version = file.version')
->leftJoin('fileVersion.meta', 'fileVersionMeta');
$queryBuilder->andWhere('fileVersionMeta.title LIKE :search');
$queryBuilder->setParameter('search', '%' . $search . '%');
}
if ($offset) {
$queryBuilder->setFirstResult($offset);
}
if ($limit) {
$queryBuilder->setMaxResults($limit);
}
if (!empty($orderBy)) {
$queryBuilder->addOrderBy($orderBy, $orderSort);
}
return $queryBuilder->getQuery();
} | php | private function getIdsQuery(
$collection = null,
$systemCollections = true,
$types = null,
$search = null,
$orderBy = null,
$orderSort = null,
$limit = null,
$offset = null,
$select = 'media.id'
) {
$queryBuilder = $this->createQueryBuilder('media')->select($select);
$queryBuilder->innerJoin('media.collection', 'collection');
if (!empty($collection)) {
$queryBuilder->andWhere('collection.id = :collection');
$queryBuilder->setParameter('collection', $collection);
}
if (!$systemCollections) {
$queryBuilder->leftJoin('collection.type', 'collectionType');
$queryBuilder->andWhere(
sprintf('collectionType.key != \'%s\'', SystemCollectionManagerInterface::COLLECTION_TYPE)
);
}
if (!empty($types)) {
$queryBuilder->innerJoin('media.type', 'type');
$queryBuilder->andWhere('type.name IN (:types)');
$queryBuilder->setParameter('types', $types);
}
if (!empty($search)) {
$queryBuilder
->innerJoin('media.files', 'file')
->innerJoin('file.fileVersions', 'fileVersion', 'WITH', 'fileVersion.version = file.version')
->leftJoin('fileVersion.meta', 'fileVersionMeta');
$queryBuilder->andWhere('fileVersionMeta.title LIKE :search');
$queryBuilder->setParameter('search', '%' . $search . '%');
}
if ($offset) {
$queryBuilder->setFirstResult($offset);
}
if ($limit) {
$queryBuilder->setMaxResults($limit);
}
if (!empty($orderBy)) {
$queryBuilder->addOrderBy($orderBy, $orderSort);
}
return $queryBuilder->getQuery();
} | [
"private",
"function",
"getIdsQuery",
"(",
"$",
"collection",
"=",
"null",
",",
"$",
"systemCollections",
"=",
"true",
",",
"$",
"types",
"=",
"null",
",",
"$",
"search",
"=",
"null",
",",
"$",
"orderBy",
"=",
"null",
",",
"$",
"orderSort",
"=",
"null",
",",
"$",
"limit",
"=",
"null",
",",
"$",
"offset",
"=",
"null",
",",
"$",
"select",
"=",
"'media.id'",
")",
"{",
"$",
"queryBuilder",
"=",
"$",
"this",
"->",
"createQueryBuilder",
"(",
"'media'",
")",
"->",
"select",
"(",
"$",
"select",
")",
";",
"$",
"queryBuilder",
"->",
"innerJoin",
"(",
"'media.collection'",
",",
"'collection'",
")",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"collection",
")",
")",
"{",
"$",
"queryBuilder",
"->",
"andWhere",
"(",
"'collection.id = :collection'",
")",
";",
"$",
"queryBuilder",
"->",
"setParameter",
"(",
"'collection'",
",",
"$",
"collection",
")",
";",
"}",
"if",
"(",
"!",
"$",
"systemCollections",
")",
"{",
"$",
"queryBuilder",
"->",
"leftJoin",
"(",
"'collection.type'",
",",
"'collectionType'",
")",
";",
"$",
"queryBuilder",
"->",
"andWhere",
"(",
"sprintf",
"(",
"'collectionType.key != \\'%s\\''",
",",
"SystemCollectionManagerInterface",
"::",
"COLLECTION_TYPE",
")",
")",
";",
"}",
"if",
"(",
"!",
"empty",
"(",
"$",
"types",
")",
")",
"{",
"$",
"queryBuilder",
"->",
"innerJoin",
"(",
"'media.type'",
",",
"'type'",
")",
";",
"$",
"queryBuilder",
"->",
"andWhere",
"(",
"'type.name IN (:types)'",
")",
";",
"$",
"queryBuilder",
"->",
"setParameter",
"(",
"'types'",
",",
"$",
"types",
")",
";",
"}",
"if",
"(",
"!",
"empty",
"(",
"$",
"search",
")",
")",
"{",
"$",
"queryBuilder",
"->",
"innerJoin",
"(",
"'media.files'",
",",
"'file'",
")",
"->",
"innerJoin",
"(",
"'file.fileVersions'",
",",
"'fileVersion'",
",",
"'WITH'",
",",
"'fileVersion.version = file.version'",
")",
"->",
"leftJoin",
"(",
"'fileVersion.meta'",
",",
"'fileVersionMeta'",
")",
";",
"$",
"queryBuilder",
"->",
"andWhere",
"(",
"'fileVersionMeta.title LIKE :search'",
")",
";",
"$",
"queryBuilder",
"->",
"setParameter",
"(",
"'search'",
",",
"'%'",
".",
"$",
"search",
".",
"'%'",
")",
";",
"}",
"if",
"(",
"$",
"offset",
")",
"{",
"$",
"queryBuilder",
"->",
"setFirstResult",
"(",
"$",
"offset",
")",
";",
"}",
"if",
"(",
"$",
"limit",
")",
"{",
"$",
"queryBuilder",
"->",
"setMaxResults",
"(",
"$",
"limit",
")",
";",
"}",
"if",
"(",
"!",
"empty",
"(",
"$",
"orderBy",
")",
")",
"{",
"$",
"queryBuilder",
"->",
"addOrderBy",
"(",
"$",
"orderBy",
",",
"$",
"orderSort",
")",
";",
"}",
"return",
"$",
"queryBuilder",
"->",
"getQuery",
"(",
")",
";",
"}"
] | create a query for ids with given filter.
@param string $collection
@param bool $systemCollections
@param array $types
@param string $search
@param string $orderBy
@param string $orderSort
@param int $limit
@param int $offset
@param string $select
@return Query | [
"create",
"a",
"query",
"for",
"ids",
"with",
"given",
"filter",
"."
] | 6766a36cc2f0c807c59202bf7540a08c4ef31192 | https://github.com/sulu/sulu/blob/6766a36cc2f0c807c59202bf7540a08c4ef31192/src/Sulu/Bundle/MediaBundle/Entity/MediaRepository.php#L347-L403 | train |
sulu/sulu | src/Sulu/Bundle/MediaBundle/Entity/MediaRepository.php | MediaRepository.getIds | private function getIds(
$collection = null,
$systemCollections = true,
$types = null,
$search = null,
$orderBy = null,
$orderSort = null,
$limit = null,
$offset = null
) {
$subQuery = $this->getIdsQuery(
$collection,
$systemCollections,
$types,
$search,
$orderBy,
$orderSort,
$limit,
$offset
);
return $subQuery->getScalarResult();
} | php | private function getIds(
$collection = null,
$systemCollections = true,
$types = null,
$search = null,
$orderBy = null,
$orderSort = null,
$limit = null,
$offset = null
) {
$subQuery = $this->getIdsQuery(
$collection,
$systemCollections,
$types,
$search,
$orderBy,
$orderSort,
$limit,
$offset
);
return $subQuery->getScalarResult();
} | [
"private",
"function",
"getIds",
"(",
"$",
"collection",
"=",
"null",
",",
"$",
"systemCollections",
"=",
"true",
",",
"$",
"types",
"=",
"null",
",",
"$",
"search",
"=",
"null",
",",
"$",
"orderBy",
"=",
"null",
",",
"$",
"orderSort",
"=",
"null",
",",
"$",
"limit",
"=",
"null",
",",
"$",
"offset",
"=",
"null",
")",
"{",
"$",
"subQuery",
"=",
"$",
"this",
"->",
"getIdsQuery",
"(",
"$",
"collection",
",",
"$",
"systemCollections",
",",
"$",
"types",
",",
"$",
"search",
",",
"$",
"orderBy",
",",
"$",
"orderSort",
",",
"$",
"limit",
",",
"$",
"offset",
")",
";",
"return",
"$",
"subQuery",
"->",
"getScalarResult",
"(",
")",
";",
"}"
] | returns ids with given filters.
@param string $collection
@param bool $systemCollections
@param array $types
@param string $search
@param string $orderBy
@param string $orderSort
@param int $limit
@param int $offset
@return array | [
"returns",
"ids",
"with",
"given",
"filters",
"."
] | 6766a36cc2f0c807c59202bf7540a08c4ef31192 | https://github.com/sulu/sulu/blob/6766a36cc2f0c807c59202bf7540a08c4ef31192/src/Sulu/Bundle/MediaBundle/Entity/MediaRepository.php#L419-L441 | train |
sulu/sulu | src/Sulu/Bundle/PageBundle/Command/ValidateWebspacesCommand.php | ValidateWebspacesCommand.outputWebspace | private function outputWebspace(Webspace $webspace)
{
$this->output->writeln(
sprintf(
'<info>%s</info> - <info>%s</info>',
$webspace->getKey(),
$webspace->getName()
)
);
$this->outputWebspaceDefaultTemplates($webspace);
$this->outputWebspacePageTemplates($webspace);
$this->outputWebspaceTemplates($webspace);
$this->outputWebspaceLocalizations($webspace);
} | php | private function outputWebspace(Webspace $webspace)
{
$this->output->writeln(
sprintf(
'<info>%s</info> - <info>%s</info>',
$webspace->getKey(),
$webspace->getName()
)
);
$this->outputWebspaceDefaultTemplates($webspace);
$this->outputWebspacePageTemplates($webspace);
$this->outputWebspaceTemplates($webspace);
$this->outputWebspaceLocalizations($webspace);
} | [
"private",
"function",
"outputWebspace",
"(",
"Webspace",
"$",
"webspace",
")",
"{",
"$",
"this",
"->",
"output",
"->",
"writeln",
"(",
"sprintf",
"(",
"'<info>%s</info> - <info>%s</info>'",
",",
"$",
"webspace",
"->",
"getKey",
"(",
")",
",",
"$",
"webspace",
"->",
"getName",
"(",
")",
")",
")",
";",
"$",
"this",
"->",
"outputWebspaceDefaultTemplates",
"(",
"$",
"webspace",
")",
";",
"$",
"this",
"->",
"outputWebspacePageTemplates",
"(",
"$",
"webspace",
")",
";",
"$",
"this",
"->",
"outputWebspaceTemplates",
"(",
"$",
"webspace",
")",
";",
"$",
"this",
"->",
"outputWebspaceLocalizations",
"(",
"$",
"webspace",
")",
";",
"}"
] | Output webspace.
@param Webspace $webspace | [
"Output",
"webspace",
"."
] | 6766a36cc2f0c807c59202bf7540a08c4ef31192 | https://github.com/sulu/sulu/blob/6766a36cc2f0c807c59202bf7540a08c4ef31192/src/Sulu/Bundle/PageBundle/Command/ValidateWebspacesCommand.php#L129-L143 | train |
sulu/sulu | src/Sulu/Bundle/PageBundle/Command/ValidateWebspacesCommand.php | ValidateWebspacesCommand.outputWebspacePageTemplates | private function outputWebspacePageTemplates(Webspace $webspace)
{
$this->output->writeln('Page Templates:');
$structures = $this->structureManager->getStructures();
$checkedTemplates = [];
foreach ($webspace->getDefaultTemplates() as $template) {
$checkedTemplates[] = $template;
}
foreach ($structures as $structure) {
$template = $structure->getKey();
if (!$structure->getInternal() && !in_array($template, $checkedTemplates)) {
$this->validatePageTemplate('page', $structure->getKey());
}
}
} | php | private function outputWebspacePageTemplates(Webspace $webspace)
{
$this->output->writeln('Page Templates:');
$structures = $this->structureManager->getStructures();
$checkedTemplates = [];
foreach ($webspace->getDefaultTemplates() as $template) {
$checkedTemplates[] = $template;
}
foreach ($structures as $structure) {
$template = $structure->getKey();
if (!$structure->getInternal() && !in_array($template, $checkedTemplates)) {
$this->validatePageTemplate('page', $structure->getKey());
}
}
} | [
"private",
"function",
"outputWebspacePageTemplates",
"(",
"Webspace",
"$",
"webspace",
")",
"{",
"$",
"this",
"->",
"output",
"->",
"writeln",
"(",
"'Page Templates:'",
")",
";",
"$",
"structures",
"=",
"$",
"this",
"->",
"structureManager",
"->",
"getStructures",
"(",
")",
";",
"$",
"checkedTemplates",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"webspace",
"->",
"getDefaultTemplates",
"(",
")",
"as",
"$",
"template",
")",
"{",
"$",
"checkedTemplates",
"[",
"]",
"=",
"$",
"template",
";",
"}",
"foreach",
"(",
"$",
"structures",
"as",
"$",
"structure",
")",
"{",
"$",
"template",
"=",
"$",
"structure",
"->",
"getKey",
"(",
")",
";",
"if",
"(",
"!",
"$",
"structure",
"->",
"getInternal",
"(",
")",
"&&",
"!",
"in_array",
"(",
"$",
"template",
",",
"$",
"checkedTemplates",
")",
")",
"{",
"$",
"this",
"->",
"validatePageTemplate",
"(",
"'page'",
",",
"$",
"structure",
"->",
"getKey",
"(",
")",
")",
";",
"}",
"}",
"}"
] | Output webspace page templates.
@param Webspace $webspace | [
"Output",
"webspace",
"page",
"templates",
"."
] | 6766a36cc2f0c807c59202bf7540a08c4ef31192 | https://github.com/sulu/sulu/blob/6766a36cc2f0c807c59202bf7540a08c4ef31192/src/Sulu/Bundle/PageBundle/Command/ValidateWebspacesCommand.php#L164-L183 | train |
sulu/sulu | src/Sulu/Bundle/PageBundle/Command/ValidateWebspacesCommand.php | ValidateWebspacesCommand.outputWebspaceLocalizations | private function outputWebspaceLocalizations(Webspace $webspace)
{
$this->output->writeln('Localizations:');
foreach ($webspace->getAllLocalizations() as $localization) {
$this->output->writeln(
sprintf(
' %s',
$localization->getLocale()
)
);
}
} | php | private function outputWebspaceLocalizations(Webspace $webspace)
{
$this->output->writeln('Localizations:');
foreach ($webspace->getAllLocalizations() as $localization) {
$this->output->writeln(
sprintf(
' %s',
$localization->getLocale()
)
);
}
} | [
"private",
"function",
"outputWebspaceLocalizations",
"(",
"Webspace",
"$",
"webspace",
")",
"{",
"$",
"this",
"->",
"output",
"->",
"writeln",
"(",
"'Localizations:'",
")",
";",
"foreach",
"(",
"$",
"webspace",
"->",
"getAllLocalizations",
"(",
")",
"as",
"$",
"localization",
")",
"{",
"$",
"this",
"->",
"output",
"->",
"writeln",
"(",
"sprintf",
"(",
"' %s'",
",",
"$",
"localization",
"->",
"getLocale",
"(",
")",
")",
")",
";",
"}",
"}"
] | Output webspace localizations.
@param Webspace $webspace | [
"Output",
"webspace",
"localizations",
"."
] | 6766a36cc2f0c807c59202bf7540a08c4ef31192 | https://github.com/sulu/sulu/blob/6766a36cc2f0c807c59202bf7540a08c4ef31192/src/Sulu/Bundle/PageBundle/Command/ValidateWebspacesCommand.php#L204-L216 | train |
sulu/sulu | src/Sulu/Bundle/PageBundle/Command/ValidateWebspacesCommand.php | ValidateWebspacesCommand.validatePageTemplate | private function validatePageTemplate($type, $template)
{
$status = '<info>ok</info>';
try {
$this->validateStructure($type, $template);
} catch (\Exception $e) {
$status = sprintf('<error>failed: %s</error>', $e->getMessage());
$this->errors[] = $e->getMessage();
}
$this->output->writeln(
sprintf(
' %s: %s -> %s',
$type,
$template,
$status
)
);
} | php | private function validatePageTemplate($type, $template)
{
$status = '<info>ok</info>';
try {
$this->validateStructure($type, $template);
} catch (\Exception $e) {
$status = sprintf('<error>failed: %s</error>', $e->getMessage());
$this->errors[] = $e->getMessage();
}
$this->output->writeln(
sprintf(
' %s: %s -> %s',
$type,
$template,
$status
)
);
} | [
"private",
"function",
"validatePageTemplate",
"(",
"$",
"type",
",",
"$",
"template",
")",
"{",
"$",
"status",
"=",
"'<info>ok</info>'",
";",
"try",
"{",
"$",
"this",
"->",
"validateStructure",
"(",
"$",
"type",
",",
"$",
"template",
")",
";",
"}",
"catch",
"(",
"\\",
"Exception",
"$",
"e",
")",
"{",
"$",
"status",
"=",
"sprintf",
"(",
"'<error>failed: %s</error>'",
",",
"$",
"e",
"->",
"getMessage",
"(",
")",
")",
";",
"$",
"this",
"->",
"errors",
"[",
"]",
"=",
"$",
"e",
"->",
"getMessage",
"(",
")",
";",
"}",
"$",
"this",
"->",
"output",
"->",
"writeln",
"(",
"sprintf",
"(",
"' %s: %s -> %s'",
",",
"$",
"type",
",",
"$",
"template",
",",
"$",
"status",
")",
")",
";",
"}"
] | Validate page templates.
@param string $type
@param string $template | [
"Validate",
"page",
"templates",
"."
] | 6766a36cc2f0c807c59202bf7540a08c4ef31192 | https://github.com/sulu/sulu/blob/6766a36cc2f0c807c59202bf7540a08c4ef31192/src/Sulu/Bundle/PageBundle/Command/ValidateWebspacesCommand.php#L224-L243 | train |
sulu/sulu | src/Sulu/Bundle/PageBundle/Command/ValidateWebspacesCommand.php | ValidateWebspacesCommand.validateStructure | private function validateStructure($type, $template)
{
$valid = true;
$metadata = $this->structureMetadataFactory->getStructureMetadata($type, $template);
if (!$metadata) {
throw new \RuntimeException(
sprintf(
'Structure meta data not found for type "%s" and template "%s".',
$type,
$template
)
);
}
foreach (['title', 'url'] as $property) {
if (!$metadata->hasProperty($property)) {
throw new \RuntimeException(
sprintf(
'No property "%s" found in "%s" template.',
$property,
$metadata->getName()
)
);
}
}
$this->validateTwigTemplate($metadata->getView() . '.html.twig');
$this->validateControllerAction($metadata->getController());
return $valid;
} | php | private function validateStructure($type, $template)
{
$valid = true;
$metadata = $this->structureMetadataFactory->getStructureMetadata($type, $template);
if (!$metadata) {
throw new \RuntimeException(
sprintf(
'Structure meta data not found for type "%s" and template "%s".',
$type,
$template
)
);
}
foreach (['title', 'url'] as $property) {
if (!$metadata->hasProperty($property)) {
throw new \RuntimeException(
sprintf(
'No property "%s" found in "%s" template.',
$property,
$metadata->getName()
)
);
}
}
$this->validateTwigTemplate($metadata->getView() . '.html.twig');
$this->validateControllerAction($metadata->getController());
return $valid;
} | [
"private",
"function",
"validateStructure",
"(",
"$",
"type",
",",
"$",
"template",
")",
"{",
"$",
"valid",
"=",
"true",
";",
"$",
"metadata",
"=",
"$",
"this",
"->",
"structureMetadataFactory",
"->",
"getStructureMetadata",
"(",
"$",
"type",
",",
"$",
"template",
")",
";",
"if",
"(",
"!",
"$",
"metadata",
")",
"{",
"throw",
"new",
"\\",
"RuntimeException",
"(",
"sprintf",
"(",
"'Structure meta data not found for type \"%s\" and template \"%s\".'",
",",
"$",
"type",
",",
"$",
"template",
")",
")",
";",
"}",
"foreach",
"(",
"[",
"'title'",
",",
"'url'",
"]",
"as",
"$",
"property",
")",
"{",
"if",
"(",
"!",
"$",
"metadata",
"->",
"hasProperty",
"(",
"$",
"property",
")",
")",
"{",
"throw",
"new",
"\\",
"RuntimeException",
"(",
"sprintf",
"(",
"'No property \"%s\" found in \"%s\" template.'",
",",
"$",
"property",
",",
"$",
"metadata",
"->",
"getName",
"(",
")",
")",
")",
";",
"}",
"}",
"$",
"this",
"->",
"validateTwigTemplate",
"(",
"$",
"metadata",
"->",
"getView",
"(",
")",
".",
"'.html.twig'",
")",
";",
"$",
"this",
"->",
"validateControllerAction",
"(",
"$",
"metadata",
"->",
"getController",
"(",
")",
")",
";",
"return",
"$",
"valid",
";",
"}"
] | Is template valid.
@param string $type
@param string $template
@return bool
@throws \Exception | [
"Is",
"template",
"valid",
"."
] | 6766a36cc2f0c807c59202bf7540a08c4ef31192 | https://github.com/sulu/sulu/blob/6766a36cc2f0c807c59202bf7540a08c4ef31192/src/Sulu/Bundle/PageBundle/Command/ValidateWebspacesCommand.php#L255-L287 | train |
sulu/sulu | src/Sulu/Bundle/PageBundle/Command/ValidateWebspacesCommand.php | ValidateWebspacesCommand.validateTemplate | private function validateTemplate($type, $template)
{
$status = '<info>ok</info>';
try {
$this->validateTwigTemplate($template);
} catch (\Exception $e) {
$status = sprintf('<error>failed: %s</error>', $e->getMessage());
$this->errors[] = $e->getMessage();
}
$this->output->writeln(
sprintf(
' %s: %s -> %s',
$type,
$template,
$status
)
);
} | php | private function validateTemplate($type, $template)
{
$status = '<info>ok</info>';
try {
$this->validateTwigTemplate($template);
} catch (\Exception $e) {
$status = sprintf('<error>failed: %s</error>', $e->getMessage());
$this->errors[] = $e->getMessage();
}
$this->output->writeln(
sprintf(
' %s: %s -> %s',
$type,
$template,
$status
)
);
} | [
"private",
"function",
"validateTemplate",
"(",
"$",
"type",
",",
"$",
"template",
")",
"{",
"$",
"status",
"=",
"'<info>ok</info>'",
";",
"try",
"{",
"$",
"this",
"->",
"validateTwigTemplate",
"(",
"$",
"template",
")",
";",
"}",
"catch",
"(",
"\\",
"Exception",
"$",
"e",
")",
"{",
"$",
"status",
"=",
"sprintf",
"(",
"'<error>failed: %s</error>'",
",",
"$",
"e",
"->",
"getMessage",
"(",
")",
")",
";",
"$",
"this",
"->",
"errors",
"[",
"]",
"=",
"$",
"e",
"->",
"getMessage",
"(",
")",
";",
"}",
"$",
"this",
"->",
"output",
"->",
"writeln",
"(",
"sprintf",
"(",
"' %s: %s -> %s'",
",",
"$",
"type",
",",
"$",
"template",
",",
"$",
"status",
")",
")",
";",
"}"
] | Validate template.
@param string $type
@param string $template | [
"Validate",
"template",
"."
] | 6766a36cc2f0c807c59202bf7540a08c4ef31192 | https://github.com/sulu/sulu/blob/6766a36cc2f0c807c59202bf7540a08c4ef31192/src/Sulu/Bundle/PageBundle/Command/ValidateWebspacesCommand.php#L295-L314 | train |
sulu/sulu | src/Sulu/Bundle/PageBundle/Command/ValidateWebspacesCommand.php | ValidateWebspacesCommand.validateTwigTemplate | private function validateTwigTemplate($template)
{
$loader = $this->twig->getLoader();
if (!$loader->exists($template)) {
throw new \Exception(sprintf(
'Unable to find template "%s".',
$template
));
}
} | php | private function validateTwigTemplate($template)
{
$loader = $this->twig->getLoader();
if (!$loader->exists($template)) {
throw new \Exception(sprintf(
'Unable to find template "%s".',
$template
));
}
} | [
"private",
"function",
"validateTwigTemplate",
"(",
"$",
"template",
")",
"{",
"$",
"loader",
"=",
"$",
"this",
"->",
"twig",
"->",
"getLoader",
"(",
")",
";",
"if",
"(",
"!",
"$",
"loader",
"->",
"exists",
"(",
"$",
"template",
")",
")",
"{",
"throw",
"new",
"\\",
"Exception",
"(",
"sprintf",
"(",
"'Unable to find template \"%s\".'",
",",
"$",
"template",
")",
")",
";",
"}",
"}"
] | Validate twig template.
@param string $template
@throws \Exception | [
"Validate",
"twig",
"template",
"."
] | 6766a36cc2f0c807c59202bf7540a08c4ef31192 | https://github.com/sulu/sulu/blob/6766a36cc2f0c807c59202bf7540a08c4ef31192/src/Sulu/Bundle/PageBundle/Command/ValidateWebspacesCommand.php#L323-L332 | train |
sulu/sulu | src/Sulu/Bundle/PageBundle/Command/ValidateWebspacesCommand.php | ValidateWebspacesCommand.validateControllerAction | private function validateControllerAction($controllerAction)
{
$result = $this->controllerNameConverter->parse($controllerAction);
list($class, $method) = explode('::', $result);
if (!method_exists($class, $method)) {
$reflector = new \ReflectionClass($class);
throw new \Exception(sprintf(
'Controller Action "%s" not exist in "%s" (looked into: %s).',
$method,
$class,
$reflector->getFileName()
));
}
} | php | private function validateControllerAction($controllerAction)
{
$result = $this->controllerNameConverter->parse($controllerAction);
list($class, $method) = explode('::', $result);
if (!method_exists($class, $method)) {
$reflector = new \ReflectionClass($class);
throw new \Exception(sprintf(
'Controller Action "%s" not exist in "%s" (looked into: %s).',
$method,
$class,
$reflector->getFileName()
));
}
} | [
"private",
"function",
"validateControllerAction",
"(",
"$",
"controllerAction",
")",
"{",
"$",
"result",
"=",
"$",
"this",
"->",
"controllerNameConverter",
"->",
"parse",
"(",
"$",
"controllerAction",
")",
";",
"list",
"(",
"$",
"class",
",",
"$",
"method",
")",
"=",
"explode",
"(",
"'::'",
",",
"$",
"result",
")",
";",
"if",
"(",
"!",
"method_exists",
"(",
"$",
"class",
",",
"$",
"method",
")",
")",
"{",
"$",
"reflector",
"=",
"new",
"\\",
"ReflectionClass",
"(",
"$",
"class",
")",
";",
"throw",
"new",
"\\",
"Exception",
"(",
"sprintf",
"(",
"'Controller Action \"%s\" not exist in \"%s\" (looked into: %s).'",
",",
"$",
"method",
",",
"$",
"class",
",",
"$",
"reflector",
"->",
"getFileName",
"(",
")",
")",
")",
";",
"}",
"}"
] | Validate controller action.
@param string $controllerAction
@throws \Exception | [
"Validate",
"controller",
"action",
"."
] | 6766a36cc2f0c807c59202bf7540a08c4ef31192 | https://github.com/sulu/sulu/blob/6766a36cc2f0c807c59202bf7540a08c4ef31192/src/Sulu/Bundle/PageBundle/Command/ValidateWebspacesCommand.php#L341-L357 | train |
sulu/sulu | src/Sulu/Bundle/CategoryBundle/Controller/KeywordController.php | KeywordController.cgetAction | public function cgetAction($categoryId, Request $request)
{
/** @var RestHelperInterface $restHelper */
$restHelper = $this->get('sulu_core.doctrine_rest_helper');
/** @var DoctrineListBuilderFactory $factory */
$factory = $this->get('sulu_core.doctrine_list_builder_factory');
/** @var CategoryInterface $category */
$category = $this->getCategoryRepository()->find($categoryId);
$fieldDescriptor = $this->getFieldDescriptors();
$listBuilder = $factory->create($this->getParameter('sulu.model.keyword.class'));
$restHelper->initializeListBuilder($listBuilder, $fieldDescriptor);
$listBuilder->where($fieldDescriptor['locale'], $request->get('locale'));
$listBuilder->where(
$fieldDescriptor['categoryTranslationIds'],
$category->findTranslationByLocale($request->get('locale'))
);
// should eliminate duplicates
$listBuilder->distinct(true);
$listBuilder->addGroupBy($fieldDescriptor['id']);
$listResponse = $listBuilder->execute();
$list = new ListRepresentation(
$listResponse,
self::$entityKey,
'get_category_keywords',
array_merge(['categoryId' => $categoryId], $request->query->all()),
$listBuilder->getCurrentPage(),
$listBuilder->getLimit(),
$listBuilder->count()
);
return $this->handleView($this->view($list, 200));
} | php | public function cgetAction($categoryId, Request $request)
{
/** @var RestHelperInterface $restHelper */
$restHelper = $this->get('sulu_core.doctrine_rest_helper');
/** @var DoctrineListBuilderFactory $factory */
$factory = $this->get('sulu_core.doctrine_list_builder_factory');
/** @var CategoryInterface $category */
$category = $this->getCategoryRepository()->find($categoryId);
$fieldDescriptor = $this->getFieldDescriptors();
$listBuilder = $factory->create($this->getParameter('sulu.model.keyword.class'));
$restHelper->initializeListBuilder($listBuilder, $fieldDescriptor);
$listBuilder->where($fieldDescriptor['locale'], $request->get('locale'));
$listBuilder->where(
$fieldDescriptor['categoryTranslationIds'],
$category->findTranslationByLocale($request->get('locale'))
);
// should eliminate duplicates
$listBuilder->distinct(true);
$listBuilder->addGroupBy($fieldDescriptor['id']);
$listResponse = $listBuilder->execute();
$list = new ListRepresentation(
$listResponse,
self::$entityKey,
'get_category_keywords',
array_merge(['categoryId' => $categoryId], $request->query->all()),
$listBuilder->getCurrentPage(),
$listBuilder->getLimit(),
$listBuilder->count()
);
return $this->handleView($this->view($list, 200));
} | [
"public",
"function",
"cgetAction",
"(",
"$",
"categoryId",
",",
"Request",
"$",
"request",
")",
"{",
"/** @var RestHelperInterface $restHelper */",
"$",
"restHelper",
"=",
"$",
"this",
"->",
"get",
"(",
"'sulu_core.doctrine_rest_helper'",
")",
";",
"/** @var DoctrineListBuilderFactory $factory */",
"$",
"factory",
"=",
"$",
"this",
"->",
"get",
"(",
"'sulu_core.doctrine_list_builder_factory'",
")",
";",
"/** @var CategoryInterface $category */",
"$",
"category",
"=",
"$",
"this",
"->",
"getCategoryRepository",
"(",
")",
"->",
"find",
"(",
"$",
"categoryId",
")",
";",
"$",
"fieldDescriptor",
"=",
"$",
"this",
"->",
"getFieldDescriptors",
"(",
")",
";",
"$",
"listBuilder",
"=",
"$",
"factory",
"->",
"create",
"(",
"$",
"this",
"->",
"getParameter",
"(",
"'sulu.model.keyword.class'",
")",
")",
";",
"$",
"restHelper",
"->",
"initializeListBuilder",
"(",
"$",
"listBuilder",
",",
"$",
"fieldDescriptor",
")",
";",
"$",
"listBuilder",
"->",
"where",
"(",
"$",
"fieldDescriptor",
"[",
"'locale'",
"]",
",",
"$",
"request",
"->",
"get",
"(",
"'locale'",
")",
")",
";",
"$",
"listBuilder",
"->",
"where",
"(",
"$",
"fieldDescriptor",
"[",
"'categoryTranslationIds'",
"]",
",",
"$",
"category",
"->",
"findTranslationByLocale",
"(",
"$",
"request",
"->",
"get",
"(",
"'locale'",
")",
")",
")",
";",
"// should eliminate duplicates",
"$",
"listBuilder",
"->",
"distinct",
"(",
"true",
")",
";",
"$",
"listBuilder",
"->",
"addGroupBy",
"(",
"$",
"fieldDescriptor",
"[",
"'id'",
"]",
")",
";",
"$",
"listResponse",
"=",
"$",
"listBuilder",
"->",
"execute",
"(",
")",
";",
"$",
"list",
"=",
"new",
"ListRepresentation",
"(",
"$",
"listResponse",
",",
"self",
"::",
"$",
"entityKey",
",",
"'get_category_keywords'",
",",
"array_merge",
"(",
"[",
"'categoryId'",
"=>",
"$",
"categoryId",
"]",
",",
"$",
"request",
"->",
"query",
"->",
"all",
"(",
")",
")",
",",
"$",
"listBuilder",
"->",
"getCurrentPage",
"(",
")",
",",
"$",
"listBuilder",
"->",
"getLimit",
"(",
")",
",",
"$",
"listBuilder",
"->",
"count",
"(",
")",
")",
";",
"return",
"$",
"this",
"->",
"handleView",
"(",
"$",
"this",
"->",
"view",
"(",
"$",
"list",
",",
"200",
")",
")",
";",
"}"
] | Returns list of keywords filtered by the category.
@param int $categoryId
@param Request $request
@return Response | [
"Returns",
"list",
"of",
"keywords",
"filtered",
"by",
"the",
"category",
"."
] | 6766a36cc2f0c807c59202bf7540a08c4ef31192 | https://github.com/sulu/sulu/blob/6766a36cc2f0c807c59202bf7540a08c4ef31192/src/Sulu/Bundle/CategoryBundle/Controller/KeywordController.php#L56-L95 | train |
sulu/sulu | src/Sulu/Bundle/CategoryBundle/Controller/KeywordController.php | KeywordController.postAction | public function postAction($categoryId, Request $request)
{
/** @var KeywordInterface $keyword */
$keyword = $this->getKeywordRepository()->createNew();
$category = $this->getCategoryRepository()->findCategoryById($categoryId);
$keyword->setKeyword($request->get('keyword'));
$keyword->setLocale($request->get('locale'));
$keyword = $this->getKeywordManager()->save($keyword, $category);
$this->getEntityManager()->persist($keyword);
$this->getEntityManager()->flush();
return $this->handleView($this->view($keyword));
} | php | public function postAction($categoryId, Request $request)
{
/** @var KeywordInterface $keyword */
$keyword = $this->getKeywordRepository()->createNew();
$category = $this->getCategoryRepository()->findCategoryById($categoryId);
$keyword->setKeyword($request->get('keyword'));
$keyword->setLocale($request->get('locale'));
$keyword = $this->getKeywordManager()->save($keyword, $category);
$this->getEntityManager()->persist($keyword);
$this->getEntityManager()->flush();
return $this->handleView($this->view($keyword));
} | [
"public",
"function",
"postAction",
"(",
"$",
"categoryId",
",",
"Request",
"$",
"request",
")",
"{",
"/** @var KeywordInterface $keyword */",
"$",
"keyword",
"=",
"$",
"this",
"->",
"getKeywordRepository",
"(",
")",
"->",
"createNew",
"(",
")",
";",
"$",
"category",
"=",
"$",
"this",
"->",
"getCategoryRepository",
"(",
")",
"->",
"findCategoryById",
"(",
"$",
"categoryId",
")",
";",
"$",
"keyword",
"->",
"setKeyword",
"(",
"$",
"request",
"->",
"get",
"(",
"'keyword'",
")",
")",
";",
"$",
"keyword",
"->",
"setLocale",
"(",
"$",
"request",
"->",
"get",
"(",
"'locale'",
")",
")",
";",
"$",
"keyword",
"=",
"$",
"this",
"->",
"getKeywordManager",
"(",
")",
"->",
"save",
"(",
"$",
"keyword",
",",
"$",
"category",
")",
";",
"$",
"this",
"->",
"getEntityManager",
"(",
")",
"->",
"persist",
"(",
"$",
"keyword",
")",
";",
"$",
"this",
"->",
"getEntityManager",
"(",
")",
"->",
"flush",
"(",
")",
";",
"return",
"$",
"this",
"->",
"handleView",
"(",
"$",
"this",
"->",
"view",
"(",
"$",
"keyword",
")",
")",
";",
"}"
] | Creates new keyword for given category.
@param int $categoryId
@param Request $request
@return Response | [
"Creates",
"new",
"keyword",
"for",
"given",
"category",
"."
] | 6766a36cc2f0c807c59202bf7540a08c4ef31192 | https://github.com/sulu/sulu/blob/6766a36cc2f0c807c59202bf7540a08c4ef31192/src/Sulu/Bundle/CategoryBundle/Controller/KeywordController.php#L105-L119 | train |
sulu/sulu | src/Sulu/Bundle/CategoryBundle/Controller/KeywordController.php | KeywordController.putAction | public function putAction($categoryId, $keywordId, Request $request)
{
$keyword = $this->getKeywordRepository()->findById($keywordId);
if (!$keyword) {
return $this->handleView($this->view(null, 404));
}
$force = $request->get('force');
$category = $this->getCategoryRepository()->findCategoryById($categoryId);
$keyword->setKeyword($request->get('keyword'));
$keyword = $this->getKeywordManager()->save($keyword, $category, $force);
$this->getEntityManager()->persist($keyword);
$this->getEntityManager()->flush();
return $this->handleView($this->view($keyword));
} | php | public function putAction($categoryId, $keywordId, Request $request)
{
$keyword = $this->getKeywordRepository()->findById($keywordId);
if (!$keyword) {
return $this->handleView($this->view(null, 404));
}
$force = $request->get('force');
$category = $this->getCategoryRepository()->findCategoryById($categoryId);
$keyword->setKeyword($request->get('keyword'));
$keyword = $this->getKeywordManager()->save($keyword, $category, $force);
$this->getEntityManager()->persist($keyword);
$this->getEntityManager()->flush();
return $this->handleView($this->view($keyword));
} | [
"public",
"function",
"putAction",
"(",
"$",
"categoryId",
",",
"$",
"keywordId",
",",
"Request",
"$",
"request",
")",
"{",
"$",
"keyword",
"=",
"$",
"this",
"->",
"getKeywordRepository",
"(",
")",
"->",
"findById",
"(",
"$",
"keywordId",
")",
";",
"if",
"(",
"!",
"$",
"keyword",
")",
"{",
"return",
"$",
"this",
"->",
"handleView",
"(",
"$",
"this",
"->",
"view",
"(",
"null",
",",
"404",
")",
")",
";",
"}",
"$",
"force",
"=",
"$",
"request",
"->",
"get",
"(",
"'force'",
")",
";",
"$",
"category",
"=",
"$",
"this",
"->",
"getCategoryRepository",
"(",
")",
"->",
"findCategoryById",
"(",
"$",
"categoryId",
")",
";",
"$",
"keyword",
"->",
"setKeyword",
"(",
"$",
"request",
"->",
"get",
"(",
"'keyword'",
")",
")",
";",
"$",
"keyword",
"=",
"$",
"this",
"->",
"getKeywordManager",
"(",
")",
"->",
"save",
"(",
"$",
"keyword",
",",
"$",
"category",
",",
"$",
"force",
")",
";",
"$",
"this",
"->",
"getEntityManager",
"(",
")",
"->",
"persist",
"(",
"$",
"keyword",
")",
";",
"$",
"this",
"->",
"getEntityManager",
"(",
")",
"->",
"flush",
"(",
")",
";",
"return",
"$",
"this",
"->",
"handleView",
"(",
"$",
"this",
"->",
"view",
"(",
"$",
"keyword",
")",
")",
";",
"}"
] | Updates given keyword for given category.
@param int $categoryId
@param int $keywordId
@param Request $request
@return Response
@throws KeywordIsMultipleReferencedException
@throws KeywordNotUniqueException | [
"Updates",
"given",
"keyword",
"for",
"given",
"category",
"."
] | 6766a36cc2f0c807c59202bf7540a08c4ef31192 | https://github.com/sulu/sulu/blob/6766a36cc2f0c807c59202bf7540a08c4ef31192/src/Sulu/Bundle/CategoryBundle/Controller/KeywordController.php#L133-L151 | train |
sulu/sulu | src/Sulu/Bundle/ContactBundle/Controller/ContactTitleController.php | ContactTitleController.postAction | public function postAction(Request $request)
{
$name = $request->get('title');
try {
if (null == $name) {
throw new RestException(
'There is no title-name for the given title'
);
}
$em = $this->getDoctrine()->getManager();
$title = new ContactTitle();
$title->setTitle($name);
$em->persist($title);
$em->flush();
$view = $this->view($title, 200);
} catch (EntityNotFoundException $enfe) {
$view = $this->view($enfe->toArray(), 404);
} catch (RestException $re) {
$view = $this->view($re->toArray(), 400);
}
return $this->handleView($view);
} | php | public function postAction(Request $request)
{
$name = $request->get('title');
try {
if (null == $name) {
throw new RestException(
'There is no title-name for the given title'
);
}
$em = $this->getDoctrine()->getManager();
$title = new ContactTitle();
$title->setTitle($name);
$em->persist($title);
$em->flush();
$view = $this->view($title, 200);
} catch (EntityNotFoundException $enfe) {
$view = $this->view($enfe->toArray(), 404);
} catch (RestException $re) {
$view = $this->view($re->toArray(), 400);
}
return $this->handleView($view);
} | [
"public",
"function",
"postAction",
"(",
"Request",
"$",
"request",
")",
"{",
"$",
"name",
"=",
"$",
"request",
"->",
"get",
"(",
"'title'",
")",
";",
"try",
"{",
"if",
"(",
"null",
"==",
"$",
"name",
")",
"{",
"throw",
"new",
"RestException",
"(",
"'There is no title-name for the given title'",
")",
";",
"}",
"$",
"em",
"=",
"$",
"this",
"->",
"getDoctrine",
"(",
")",
"->",
"getManager",
"(",
")",
";",
"$",
"title",
"=",
"new",
"ContactTitle",
"(",
")",
";",
"$",
"title",
"->",
"setTitle",
"(",
"$",
"name",
")",
";",
"$",
"em",
"->",
"persist",
"(",
"$",
"title",
")",
";",
"$",
"em",
"->",
"flush",
"(",
")",
";",
"$",
"view",
"=",
"$",
"this",
"->",
"view",
"(",
"$",
"title",
",",
"200",
")",
";",
"}",
"catch",
"(",
"EntityNotFoundException",
"$",
"enfe",
")",
"{",
"$",
"view",
"=",
"$",
"this",
"->",
"view",
"(",
"$",
"enfe",
"->",
"toArray",
"(",
")",
",",
"404",
")",
";",
"}",
"catch",
"(",
"RestException",
"$",
"re",
")",
"{",
"$",
"view",
"=",
"$",
"this",
"->",
"view",
"(",
"$",
"re",
"->",
"toArray",
"(",
")",
",",
"400",
")",
";",
"}",
"return",
"$",
"this",
"->",
"handleView",
"(",
"$",
"view",
")",
";",
"}"
] | Creates a new contact title.
@param \Symfony\Component\HttpFoundation\Request $request
@return \Symfony\Component\HttpFoundation\Response | [
"Creates",
"a",
"new",
"contact",
"title",
"."
] | 6766a36cc2f0c807c59202bf7540a08c4ef31192 | https://github.com/sulu/sulu/blob/6766a36cc2f0c807c59202bf7540a08c4ef31192/src/Sulu/Bundle/ContactBundle/Controller/ContactTitleController.php#L84-L110 | train |
sulu/sulu | src/Sulu/Bundle/ContactBundle/Controller/ContactTitleController.php | ContactTitleController.putAction | public function putAction(Request $request, $id)
{
try {
/** @var ContactTitle $title */
$title = $this->getDoctrine()
->getRepository(self::$entityName)
->find($id);
if (!$title) {
throw new EntityNotFoundException(self::$entityName, $id);
} else {
$name = $request->get('title');
if (empty($name)) {
throw new RestException('There is no title-name for the given title');
} else {
$em = $this->getDoctrine()->getManager();
$title->setTitle($name);
$em->flush();
$view = $this->view($title, 200);
}
}
} catch (EntityNotFoundException $enfe) {
$view = $this->view($enfe->toArray(), 404);
} catch (RestException $exc) {
$view = $this->view($exc->toArray(), 400);
}
return $this->handleView($view);
} | php | public function putAction(Request $request, $id)
{
try {
/** @var ContactTitle $title */
$title = $this->getDoctrine()
->getRepository(self::$entityName)
->find($id);
if (!$title) {
throw new EntityNotFoundException(self::$entityName, $id);
} else {
$name = $request->get('title');
if (empty($name)) {
throw new RestException('There is no title-name for the given title');
} else {
$em = $this->getDoctrine()->getManager();
$title->setTitle($name);
$em->flush();
$view = $this->view($title, 200);
}
}
} catch (EntityNotFoundException $enfe) {
$view = $this->view($enfe->toArray(), 404);
} catch (RestException $exc) {
$view = $this->view($exc->toArray(), 400);
}
return $this->handleView($view);
} | [
"public",
"function",
"putAction",
"(",
"Request",
"$",
"request",
",",
"$",
"id",
")",
"{",
"try",
"{",
"/** @var ContactTitle $title */",
"$",
"title",
"=",
"$",
"this",
"->",
"getDoctrine",
"(",
")",
"->",
"getRepository",
"(",
"self",
"::",
"$",
"entityName",
")",
"->",
"find",
"(",
"$",
"id",
")",
";",
"if",
"(",
"!",
"$",
"title",
")",
"{",
"throw",
"new",
"EntityNotFoundException",
"(",
"self",
"::",
"$",
"entityName",
",",
"$",
"id",
")",
";",
"}",
"else",
"{",
"$",
"name",
"=",
"$",
"request",
"->",
"get",
"(",
"'title'",
")",
";",
"if",
"(",
"empty",
"(",
"$",
"name",
")",
")",
"{",
"throw",
"new",
"RestException",
"(",
"'There is no title-name for the given title'",
")",
";",
"}",
"else",
"{",
"$",
"em",
"=",
"$",
"this",
"->",
"getDoctrine",
"(",
")",
"->",
"getManager",
"(",
")",
";",
"$",
"title",
"->",
"setTitle",
"(",
"$",
"name",
")",
";",
"$",
"em",
"->",
"flush",
"(",
")",
";",
"$",
"view",
"=",
"$",
"this",
"->",
"view",
"(",
"$",
"title",
",",
"200",
")",
";",
"}",
"}",
"}",
"catch",
"(",
"EntityNotFoundException",
"$",
"enfe",
")",
"{",
"$",
"view",
"=",
"$",
"this",
"->",
"view",
"(",
"$",
"enfe",
"->",
"toArray",
"(",
")",
",",
"404",
")",
";",
"}",
"catch",
"(",
"RestException",
"$",
"exc",
")",
"{",
"$",
"view",
"=",
"$",
"this",
"->",
"view",
"(",
"$",
"exc",
"->",
"toArray",
"(",
")",
",",
"400",
")",
";",
"}",
"return",
"$",
"this",
"->",
"handleView",
"(",
"$",
"view",
")",
";",
"}"
] | Edits the existing contact title for the given id.
@param \Symfony\Component\HttpFoundation\Request $request
@param int $id The id of the title to update
@return \Symfony\Component\HttpFoundation\Response | [
"Edits",
"the",
"existing",
"contact",
"title",
"for",
"the",
"given",
"id",
"."
] | 6766a36cc2f0c807c59202bf7540a08c4ef31192 | https://github.com/sulu/sulu/blob/6766a36cc2f0c807c59202bf7540a08c4ef31192/src/Sulu/Bundle/ContactBundle/Controller/ContactTitleController.php#L120-L150 | train |
sulu/sulu | src/Sulu/Bundle/ContactBundle/Controller/ContactTitleController.php | ContactTitleController.deleteAction | public function deleteAction($id)
{
try {
$delete = function($id) {
/* @var ContactTitle $title */
$title = $this->getDoctrine()
->getRepository(self::$entityName)
->find($id);
if (!$title) {
throw new EntityNotFoundException(self::$entityName, $id);
}
$em = $this->getDoctrine()->getManager();
$em->remove($title);
$em->flush();
};
$view = $this->responseDelete($id, $delete);
} catch (EntityNotFoundException $enfe) {
$view = $this->view($enfe->toArray(), 404);
}
return $this->handleView($view);
} | php | public function deleteAction($id)
{
try {
$delete = function($id) {
/* @var ContactTitle $title */
$title = $this->getDoctrine()
->getRepository(self::$entityName)
->find($id);
if (!$title) {
throw new EntityNotFoundException(self::$entityName, $id);
}
$em = $this->getDoctrine()->getManager();
$em->remove($title);
$em->flush();
};
$view = $this->responseDelete($id, $delete);
} catch (EntityNotFoundException $enfe) {
$view = $this->view($enfe->toArray(), 404);
}
return $this->handleView($view);
} | [
"public",
"function",
"deleteAction",
"(",
"$",
"id",
")",
"{",
"try",
"{",
"$",
"delete",
"=",
"function",
"(",
"$",
"id",
")",
"{",
"/* @var ContactTitle $title */",
"$",
"title",
"=",
"$",
"this",
"->",
"getDoctrine",
"(",
")",
"->",
"getRepository",
"(",
"self",
"::",
"$",
"entityName",
")",
"->",
"find",
"(",
"$",
"id",
")",
";",
"if",
"(",
"!",
"$",
"title",
")",
"{",
"throw",
"new",
"EntityNotFoundException",
"(",
"self",
"::",
"$",
"entityName",
",",
"$",
"id",
")",
";",
"}",
"$",
"em",
"=",
"$",
"this",
"->",
"getDoctrine",
"(",
")",
"->",
"getManager",
"(",
")",
";",
"$",
"em",
"->",
"remove",
"(",
"$",
"title",
")",
";",
"$",
"em",
"->",
"flush",
"(",
")",
";",
"}",
";",
"$",
"view",
"=",
"$",
"this",
"->",
"responseDelete",
"(",
"$",
"id",
",",
"$",
"delete",
")",
";",
"}",
"catch",
"(",
"EntityNotFoundException",
"$",
"enfe",
")",
"{",
"$",
"view",
"=",
"$",
"this",
"->",
"view",
"(",
"$",
"enfe",
"->",
"toArray",
"(",
")",
",",
"404",
")",
";",
"}",
"return",
"$",
"this",
"->",
"handleView",
"(",
"$",
"view",
")",
";",
"}"
] | Delete a contact title for the given id.
@param $id
@return \Symfony\Component\HttpFoundation\Response | [
"Delete",
"a",
"contact",
"title",
"for",
"the",
"given",
"id",
"."
] | 6766a36cc2f0c807c59202bf7540a08c4ef31192 | https://github.com/sulu/sulu/blob/6766a36cc2f0c807c59202bf7540a08c4ef31192/src/Sulu/Bundle/ContactBundle/Controller/ContactTitleController.php#L188-L212 | train |
sulu/sulu | src/Sulu/Bundle/ContactBundle/Controller/ContactTitleController.php | ContactTitleController.cpatchAction | public function cpatchAction(Request $request)
{
try {
$data = [];
$i = 0;
while ($item = $request->get($i)) {
if (!isset($item['title'])) {
throw new RestException(
'There is no title-name for the given title'
);
}
$data[] = $this->addAndUpdateTitles($item);
++$i;
}
$this->getDoctrine()->getManager()->flush();
$view = $this->view($data, 200);
} catch (EntityNotFoundException $enfe) {
$view = $this->view($enfe->toArray(), 404);
} catch (RestException $exc) {
$view = $this->view($exc->toArray(), 400);
}
return $this->handleView($view);
} | php | public function cpatchAction(Request $request)
{
try {
$data = [];
$i = 0;
while ($item = $request->get($i)) {
if (!isset($item['title'])) {
throw new RestException(
'There is no title-name for the given title'
);
}
$data[] = $this->addAndUpdateTitles($item);
++$i;
}
$this->getDoctrine()->getManager()->flush();
$view = $this->view($data, 200);
} catch (EntityNotFoundException $enfe) {
$view = $this->view($enfe->toArray(), 404);
} catch (RestException $exc) {
$view = $this->view($exc->toArray(), 400);
}
return $this->handleView($view);
} | [
"public",
"function",
"cpatchAction",
"(",
"Request",
"$",
"request",
")",
"{",
"try",
"{",
"$",
"data",
"=",
"[",
"]",
";",
"$",
"i",
"=",
"0",
";",
"while",
"(",
"$",
"item",
"=",
"$",
"request",
"->",
"get",
"(",
"$",
"i",
")",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"item",
"[",
"'title'",
"]",
")",
")",
"{",
"throw",
"new",
"RestException",
"(",
"'There is no title-name for the given title'",
")",
";",
"}",
"$",
"data",
"[",
"]",
"=",
"$",
"this",
"->",
"addAndUpdateTitles",
"(",
"$",
"item",
")",
";",
"++",
"$",
"i",
";",
"}",
"$",
"this",
"->",
"getDoctrine",
"(",
")",
"->",
"getManager",
"(",
")",
"->",
"flush",
"(",
")",
";",
"$",
"view",
"=",
"$",
"this",
"->",
"view",
"(",
"$",
"data",
",",
"200",
")",
";",
"}",
"catch",
"(",
"EntityNotFoundException",
"$",
"enfe",
")",
"{",
"$",
"view",
"=",
"$",
"this",
"->",
"view",
"(",
"$",
"enfe",
"->",
"toArray",
"(",
")",
",",
"404",
")",
";",
"}",
"catch",
"(",
"RestException",
"$",
"exc",
")",
"{",
"$",
"view",
"=",
"$",
"this",
"->",
"view",
"(",
"$",
"exc",
"->",
"toArray",
"(",
")",
",",
"400",
")",
";",
"}",
"return",
"$",
"this",
"->",
"handleView",
"(",
"$",
"view",
")",
";",
"}"
] | Add or update a bunch of contact titles.
@param \Symfony\Component\HttpFoundation\Request $request
@return \Symfony\Component\HttpFoundation\Response | [
"Add",
"or",
"update",
"a",
"bunch",
"of",
"contact",
"titles",
"."
] | 6766a36cc2f0c807c59202bf7540a08c4ef31192 | https://github.com/sulu/sulu/blob/6766a36cc2f0c807c59202bf7540a08c4ef31192/src/Sulu/Bundle/ContactBundle/Controller/ContactTitleController.php#L221-L247 | train |
sulu/sulu | src/Sulu/Component/Content/Mapper/ContentMapper.php | ContentMapper.getRootRouteNode | protected function getRootRouteNode($webspaceKey, $locale, $segment)
{
return $this->documentManager->find(
$this->sessionManager->getRoutePath($webspaceKey, $locale, $segment)
);
} | php | protected function getRootRouteNode($webspaceKey, $locale, $segment)
{
return $this->documentManager->find(
$this->sessionManager->getRoutePath($webspaceKey, $locale, $segment)
);
} | [
"protected",
"function",
"getRootRouteNode",
"(",
"$",
"webspaceKey",
",",
"$",
"locale",
",",
"$",
"segment",
")",
"{",
"return",
"$",
"this",
"->",
"documentManager",
"->",
"find",
"(",
"$",
"this",
"->",
"sessionManager",
"->",
"getRoutePath",
"(",
"$",
"webspaceKey",
",",
"$",
"locale",
",",
"$",
"segment",
")",
")",
";",
"}"
] | Return the node in the content repository which contains all of the routes.
@param $webspaceKey
@param string $locale
@param string $segment
@return NodeInterface | [
"Return",
"the",
"node",
"in",
"the",
"content",
"repository",
"which",
"contains",
"all",
"of",
"the",
"routes",
"."
] | 6766a36cc2f0c807c59202bf7540a08c4ef31192 | https://github.com/sulu/sulu/blob/6766a36cc2f0c807c59202bf7540a08c4ef31192/src/Sulu/Component/Content/Mapper/ContentMapper.php#L632-L637 | train |
sulu/sulu | src/Sulu/Component/Content/Mapper/ContentMapper.php | ContentMapper.getFieldData | private function getFieldData($field, Row $row, NodeInterface $node, $document, $templateKey, $webspaceKey, $locale)
{
if (isset($field['column'])) {
// normal data from node property
return $row->getValue($field['column']);
} elseif (isset($field['extension'])) {
// data from extension
return $this->getExtensionData(
$node,
$field['extension'],
$field['property'],
$webspaceKey,
$locale
);
} elseif (isset($field['property'])
&& (!isset($field['templateKey']) || $field['templateKey'] === $templateKey)
) {
// not extension data but property of node
return $this->getPropertyData($document, $field['property']);
}
return;
} | php | private function getFieldData($field, Row $row, NodeInterface $node, $document, $templateKey, $webspaceKey, $locale)
{
if (isset($field['column'])) {
// normal data from node property
return $row->getValue($field['column']);
} elseif (isset($field['extension'])) {
// data from extension
return $this->getExtensionData(
$node,
$field['extension'],
$field['property'],
$webspaceKey,
$locale
);
} elseif (isset($field['property'])
&& (!isset($field['templateKey']) || $field['templateKey'] === $templateKey)
) {
// not extension data but property of node
return $this->getPropertyData($document, $field['property']);
}
return;
} | [
"private",
"function",
"getFieldData",
"(",
"$",
"field",
",",
"Row",
"$",
"row",
",",
"NodeInterface",
"$",
"node",
",",
"$",
"document",
",",
"$",
"templateKey",
",",
"$",
"webspaceKey",
",",
"$",
"locale",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"field",
"[",
"'column'",
"]",
")",
")",
"{",
"// normal data from node property",
"return",
"$",
"row",
"->",
"getValue",
"(",
"$",
"field",
"[",
"'column'",
"]",
")",
";",
"}",
"elseif",
"(",
"isset",
"(",
"$",
"field",
"[",
"'extension'",
"]",
")",
")",
"{",
"// data from extension",
"return",
"$",
"this",
"->",
"getExtensionData",
"(",
"$",
"node",
",",
"$",
"field",
"[",
"'extension'",
"]",
",",
"$",
"field",
"[",
"'property'",
"]",
",",
"$",
"webspaceKey",
",",
"$",
"locale",
")",
";",
"}",
"elseif",
"(",
"isset",
"(",
"$",
"field",
"[",
"'property'",
"]",
")",
"&&",
"(",
"!",
"isset",
"(",
"$",
"field",
"[",
"'templateKey'",
"]",
")",
"||",
"$",
"field",
"[",
"'templateKey'",
"]",
"===",
"$",
"templateKey",
")",
")",
"{",
"// not extension data but property of node",
"return",
"$",
"this",
"->",
"getPropertyData",
"(",
"$",
"document",
",",
"$",
"field",
"[",
"'property'",
"]",
")",
";",
"}",
"return",
";",
"}"
] | Return data for one field. | [
"Return",
"data",
"for",
"one",
"field",
"."
] | 6766a36cc2f0c807c59202bf7540a08c4ef31192 | https://github.com/sulu/sulu/blob/6766a36cc2f0c807c59202bf7540a08c4ef31192/src/Sulu/Component/Content/Mapper/ContentMapper.php#L832-L854 | train |
sulu/sulu | src/Sulu/Component/Content/Mapper/ContentMapper.php | ContentMapper.getPropertyData | private function getPropertyData($document, LegacyProperty $property)
{
return $document->getStructure()->getContentViewProperty($property->getName())->getValue();
} | php | private function getPropertyData($document, LegacyProperty $property)
{
return $document->getStructure()->getContentViewProperty($property->getName())->getValue();
} | [
"private",
"function",
"getPropertyData",
"(",
"$",
"document",
",",
"LegacyProperty",
"$",
"property",
")",
"{",
"return",
"$",
"document",
"->",
"getStructure",
"(",
")",
"->",
"getContentViewProperty",
"(",
"$",
"property",
"->",
"getName",
"(",
")",
")",
"->",
"getValue",
"(",
")",
";",
"}"
] | Returns data for property. | [
"Returns",
"data",
"for",
"property",
"."
] | 6766a36cc2f0c807c59202bf7540a08c4ef31192 | https://github.com/sulu/sulu/blob/6766a36cc2f0c807c59202bf7540a08c4ef31192/src/Sulu/Component/Content/Mapper/ContentMapper.php#L859-L862 | train |
sulu/sulu | src/Sulu/Component/Content/Mapper/ContentMapper.php | ContentMapper.getExtensionData | private function getExtensionData(
NodeInterface $node,
ExtensionInterface $extension,
$propertyName,
$webspaceKey,
$locale
) {
// extension data: load ones
if (!$this->extensionDataCache->contains($extension->getName())) {
$this->extensionDataCache->save(
$extension->getName(),
$this->loadExtensionData(
$node,
$extension,
$webspaceKey,
$locale
)
);
}
// get extension data from cache
$data = $this->extensionDataCache->fetch($extension->getName());
// if property exists set it to target (with default value '')
return isset($data[$propertyName]) ? $data[$propertyName] : null;
} | php | private function getExtensionData(
NodeInterface $node,
ExtensionInterface $extension,
$propertyName,
$webspaceKey,
$locale
) {
// extension data: load ones
if (!$this->extensionDataCache->contains($extension->getName())) {
$this->extensionDataCache->save(
$extension->getName(),
$this->loadExtensionData(
$node,
$extension,
$webspaceKey,
$locale
)
);
}
// get extension data from cache
$data = $this->extensionDataCache->fetch($extension->getName());
// if property exists set it to target (with default value '')
return isset($data[$propertyName]) ? $data[$propertyName] : null;
} | [
"private",
"function",
"getExtensionData",
"(",
"NodeInterface",
"$",
"node",
",",
"ExtensionInterface",
"$",
"extension",
",",
"$",
"propertyName",
",",
"$",
"webspaceKey",
",",
"$",
"locale",
")",
"{",
"// extension data: load ones",
"if",
"(",
"!",
"$",
"this",
"->",
"extensionDataCache",
"->",
"contains",
"(",
"$",
"extension",
"->",
"getName",
"(",
")",
")",
")",
"{",
"$",
"this",
"->",
"extensionDataCache",
"->",
"save",
"(",
"$",
"extension",
"->",
"getName",
"(",
")",
",",
"$",
"this",
"->",
"loadExtensionData",
"(",
"$",
"node",
",",
"$",
"extension",
",",
"$",
"webspaceKey",
",",
"$",
"locale",
")",
")",
";",
"}",
"// get extension data from cache",
"$",
"data",
"=",
"$",
"this",
"->",
"extensionDataCache",
"->",
"fetch",
"(",
"$",
"extension",
"->",
"getName",
"(",
")",
")",
";",
"// if property exists set it to target (with default value '')",
"return",
"isset",
"(",
"$",
"data",
"[",
"$",
"propertyName",
"]",
")",
"?",
"$",
"data",
"[",
"$",
"propertyName",
"]",
":",
"null",
";",
"}"
] | Returns data for extension and property name. | [
"Returns",
"data",
"for",
"extension",
"and",
"property",
"name",
"."
] | 6766a36cc2f0c807c59202bf7540a08c4ef31192 | https://github.com/sulu/sulu/blob/6766a36cc2f0c807c59202bf7540a08c4ef31192/src/Sulu/Component/Content/Mapper/ContentMapper.php#L867-L892 | train |
sulu/sulu | src/Sulu/Component/Content/Mapper/ContentMapper.php | ContentMapper.loadExtensionData | private function loadExtensionData(NodeInterface $node, ExtensionInterface $extension, $webspaceKey, $locale)
{
$extension->setLanguageCode($locale, $this->namespaceRegistry->getPrefix('extension_localized'), '');
$data = $extension->load(
$node,
$webspaceKey,
$locale
);
return $extension->getContentData($data);
} | php | private function loadExtensionData(NodeInterface $node, ExtensionInterface $extension, $webspaceKey, $locale)
{
$extension->setLanguageCode($locale, $this->namespaceRegistry->getPrefix('extension_localized'), '');
$data = $extension->load(
$node,
$webspaceKey,
$locale
);
return $extension->getContentData($data);
} | [
"private",
"function",
"loadExtensionData",
"(",
"NodeInterface",
"$",
"node",
",",
"ExtensionInterface",
"$",
"extension",
",",
"$",
"webspaceKey",
",",
"$",
"locale",
")",
"{",
"$",
"extension",
"->",
"setLanguageCode",
"(",
"$",
"locale",
",",
"$",
"this",
"->",
"namespaceRegistry",
"->",
"getPrefix",
"(",
"'extension_localized'",
")",
",",
"''",
")",
";",
"$",
"data",
"=",
"$",
"extension",
"->",
"load",
"(",
"$",
"node",
",",
"$",
"webspaceKey",
",",
"$",
"locale",
")",
";",
"return",
"$",
"extension",
"->",
"getContentData",
"(",
"$",
"data",
")",
";",
"}"
] | load data from extension. | [
"load",
"data",
"from",
"extension",
"."
] | 6766a36cc2f0c807c59202bf7540a08c4ef31192 | https://github.com/sulu/sulu/blob/6766a36cc2f0c807c59202bf7540a08c4ef31192/src/Sulu/Component/Content/Mapper/ContentMapper.php#L897-L907 | train |
sulu/sulu | src/Sulu/Bundle/SecurityBundle/Serializer/Subscriber/SecuritySubscriber.php | SecuritySubscriber.onPostSerialize | public function onPostSerialize(ObjectEvent $event)
{
$document = $event->getObject();
if (!($document instanceof SecurityBehavior
&& $document instanceof LocaleBehavior
&& $document instanceof WebspaceBehavior
&& null !== $this->tokenStorage
&& null !== $this->tokenStorage->getToken()
&& $this->tokenStorage->getToken()->getUser() instanceof UserInterface)
) {
return;
}
/** @var JsonSerializationVisitor $visitor */
$visitor = $event->getVisitor();
$visitor->addData(
'_permissions',
$this->accessControlManager->getUserPermissionByArray(
$document->getLocale(),
PageAdmin::SECURITY_CONTEXT_PREFIX . $document->getWebspaceName(),
$document->getPermissions(),
$this->tokenStorage->getToken()->getUser()
)
);
} | php | public function onPostSerialize(ObjectEvent $event)
{
$document = $event->getObject();
if (!($document instanceof SecurityBehavior
&& $document instanceof LocaleBehavior
&& $document instanceof WebspaceBehavior
&& null !== $this->tokenStorage
&& null !== $this->tokenStorage->getToken()
&& $this->tokenStorage->getToken()->getUser() instanceof UserInterface)
) {
return;
}
/** @var JsonSerializationVisitor $visitor */
$visitor = $event->getVisitor();
$visitor->addData(
'_permissions',
$this->accessControlManager->getUserPermissionByArray(
$document->getLocale(),
PageAdmin::SECURITY_CONTEXT_PREFIX . $document->getWebspaceName(),
$document->getPermissions(),
$this->tokenStorage->getToken()->getUser()
)
);
} | [
"public",
"function",
"onPostSerialize",
"(",
"ObjectEvent",
"$",
"event",
")",
"{",
"$",
"document",
"=",
"$",
"event",
"->",
"getObject",
"(",
")",
";",
"if",
"(",
"!",
"(",
"$",
"document",
"instanceof",
"SecurityBehavior",
"&&",
"$",
"document",
"instanceof",
"LocaleBehavior",
"&&",
"$",
"document",
"instanceof",
"WebspaceBehavior",
"&&",
"null",
"!==",
"$",
"this",
"->",
"tokenStorage",
"&&",
"null",
"!==",
"$",
"this",
"->",
"tokenStorage",
"->",
"getToken",
"(",
")",
"&&",
"$",
"this",
"->",
"tokenStorage",
"->",
"getToken",
"(",
")",
"->",
"getUser",
"(",
")",
"instanceof",
"UserInterface",
")",
")",
"{",
"return",
";",
"}",
"/** @var JsonSerializationVisitor $visitor */",
"$",
"visitor",
"=",
"$",
"event",
"->",
"getVisitor",
"(",
")",
";",
"$",
"visitor",
"->",
"addData",
"(",
"'_permissions'",
",",
"$",
"this",
"->",
"accessControlManager",
"->",
"getUserPermissionByArray",
"(",
"$",
"document",
"->",
"getLocale",
"(",
")",
",",
"PageAdmin",
"::",
"SECURITY_CONTEXT_PREFIX",
".",
"$",
"document",
"->",
"getWebspaceName",
"(",
")",
",",
"$",
"document",
"->",
"getPermissions",
"(",
")",
",",
"$",
"this",
"->",
"tokenStorage",
"->",
"getToken",
"(",
")",
"->",
"getUser",
"(",
")",
")",
")",
";",
"}"
] | Adds the permissions for the current user to the serialization.
@param ObjectEvent $event | [
"Adds",
"the",
"permissions",
"for",
"the",
"current",
"user",
"to",
"the",
"serialization",
"."
] | 6766a36cc2f0c807c59202bf7540a08c4ef31192 | https://github.com/sulu/sulu/blob/6766a36cc2f0c807c59202bf7540a08c4ef31192/src/Sulu/Bundle/SecurityBundle/Serializer/Subscriber/SecuritySubscriber.php#L69-L95 | train |
sulu/sulu | src/Sulu/Bundle/MediaBundle/Entity/FileVersionPublishLanguage.php | FileVersionPublishLanguage.setFileVersion | public function setFileVersion(\Sulu\Bundle\MediaBundle\Entity\FileVersion $fileVersion = null)
{
$this->fileVersion = $fileVersion;
return $this;
} | php | public function setFileVersion(\Sulu\Bundle\MediaBundle\Entity\FileVersion $fileVersion = null)
{
$this->fileVersion = $fileVersion;
return $this;
} | [
"public",
"function",
"setFileVersion",
"(",
"\\",
"Sulu",
"\\",
"Bundle",
"\\",
"MediaBundle",
"\\",
"Entity",
"\\",
"FileVersion",
"$",
"fileVersion",
"=",
"null",
")",
"{",
"$",
"this",
"->",
"fileVersion",
"=",
"$",
"fileVersion",
";",
"return",
"$",
"this",
";",
"}"
] | Set fileVersion.
@param \Sulu\Bundle\MediaBundle\Entity\FileVersion $fileVersion
@return FileVersionPublishLanguage | [
"Set",
"fileVersion",
"."
] | 6766a36cc2f0c807c59202bf7540a08c4ef31192 | https://github.com/sulu/sulu/blob/6766a36cc2f0c807c59202bf7540a08c4ef31192/src/Sulu/Bundle/MediaBundle/Entity/FileVersionPublishLanguage.php#L89-L94 | train |
sulu/sulu | src/Sulu/Bundle/ContactBundle/Command/AccountRecoverCommand.php | AccountRecoverCommand.findInitialWrongDepthGap | private function findInitialWrongDepthGap()
{
// get nodes where difference to parents depth > 1
$qb = $this->accountRepository->createQueryBuilder('c2')
->select('count(c2.id) as results')
->join('c2.parent', 'c1')
->where('(c2.depth - 1) <> c1.depth');
$depthGapResult = $qb->getQuery()->getSingleScalarResult();
return $depthGapResult;
} | php | private function findInitialWrongDepthGap()
{
// get nodes where difference to parents depth > 1
$qb = $this->accountRepository->createQueryBuilder('c2')
->select('count(c2.id) as results')
->join('c2.parent', 'c1')
->where('(c2.depth - 1) <> c1.depth');
$depthGapResult = $qb->getQuery()->getSingleScalarResult();
return $depthGapResult;
} | [
"private",
"function",
"findInitialWrongDepthGap",
"(",
")",
"{",
"// get nodes where difference to parents depth > 1",
"$",
"qb",
"=",
"$",
"this",
"->",
"accountRepository",
"->",
"createQueryBuilder",
"(",
"'c2'",
")",
"->",
"select",
"(",
"'count(c2.id) as results'",
")",
"->",
"join",
"(",
"'c2.parent'",
",",
"'c1'",
")",
"->",
"where",
"(",
"'(c2.depth - 1) <> c1.depth'",
")",
";",
"$",
"depthGapResult",
"=",
"$",
"qb",
"->",
"getQuery",
"(",
")",
"->",
"getSingleScalarResult",
"(",
")",
";",
"return",
"$",
"depthGapResult",
";",
"}"
] | Find number of nodes where difference to parents depth > 1.
@return int Number of affected rows | [
"Find",
"number",
"of",
"nodes",
"where",
"difference",
"to",
"parents",
"depth",
">",
"1",
"."
] | 6766a36cc2f0c807c59202bf7540a08c4ef31192 | https://github.com/sulu/sulu/blob/6766a36cc2f0c807c59202bf7540a08c4ef31192/src/Sulu/Bundle/ContactBundle/Command/AccountRecoverCommand.php#L139-L149 | train |
sulu/sulu | src/Sulu/Bundle/ContactBundle/Command/AccountRecoverCommand.php | AccountRecoverCommand.findNodesWithoutParents | private function findNodesWithoutParents()
{
// get nodes that have no parent but depth > 0
$qb = $this->accountRepository->createQueryBuilder('c2')
->select('count(c2.id)')
->leftJoin('c2.parent', 'c1')
->where('c2.depth <> 0 AND c2.parent IS NULL');
return $qb->getQuery()->getSingleScalarResult();
} | php | private function findNodesWithoutParents()
{
// get nodes that have no parent but depth > 0
$qb = $this->accountRepository->createQueryBuilder('c2')
->select('count(c2.id)')
->leftJoin('c2.parent', 'c1')
->where('c2.depth <> 0 AND c2.parent IS NULL');
return $qb->getQuery()->getSingleScalarResult();
} | [
"private",
"function",
"findNodesWithoutParents",
"(",
")",
"{",
"// get nodes that have no parent but depth > 0",
"$",
"qb",
"=",
"$",
"this",
"->",
"accountRepository",
"->",
"createQueryBuilder",
"(",
"'c2'",
")",
"->",
"select",
"(",
"'count(c2.id)'",
")",
"->",
"leftJoin",
"(",
"'c2.parent'",
",",
"'c1'",
")",
"->",
"where",
"(",
"'c2.depth <> 0 AND c2.parent IS NULL'",
")",
";",
"return",
"$",
"qb",
"->",
"getQuery",
"(",
")",
"->",
"getSingleScalarResult",
"(",
")",
";",
"}"
] | Find number of nodes that have no parent but depth > 0.
@return int Number of nodes without a parent | [
"Find",
"number",
"of",
"nodes",
"that",
"have",
"no",
"parent",
"but",
"depth",
">",
"0",
"."
] | 6766a36cc2f0c807c59202bf7540a08c4ef31192 | https://github.com/sulu/sulu/blob/6766a36cc2f0c807c59202bf7540a08c4ef31192/src/Sulu/Bundle/ContactBundle/Command/AccountRecoverCommand.php#L156-L165 | train |
sulu/sulu | src/Sulu/Bundle/ContactBundle/Command/AccountRecoverCommand.php | AccountRecoverCommand.fixNodesWithoutParents | private function fixNodesWithoutParents()
{
// fix nodes that have no parent but depth > 0
$qb = $this->accountRepository->createQueryBuilder('c2')
->update()
->set('c2.depth', 0)
->where('c2.parent IS NULL AND depth != 0');
$qb->getQuery()->execute();
} | php | private function fixNodesWithoutParents()
{
// fix nodes that have no parent but depth > 0
$qb = $this->accountRepository->createQueryBuilder('c2')
->update()
->set('c2.depth', 0)
->where('c2.parent IS NULL AND depth != 0');
$qb->getQuery()->execute();
} | [
"private",
"function",
"fixNodesWithoutParents",
"(",
")",
"{",
"// fix nodes that have no parent but depth > 0",
"$",
"qb",
"=",
"$",
"this",
"->",
"accountRepository",
"->",
"createQueryBuilder",
"(",
"'c2'",
")",
"->",
"update",
"(",
")",
"->",
"set",
"(",
"'c2.depth'",
",",
"0",
")",
"->",
"where",
"(",
"'c2.parent IS NULL AND depth != 0'",
")",
";",
"$",
"qb",
"->",
"getQuery",
"(",
")",
"->",
"execute",
"(",
")",
";",
"}"
] | Set every node where depth > 0 and has no parents to depth 0. | [
"Set",
"every",
"node",
"where",
"depth",
">",
"0",
"and",
"has",
"no",
"parents",
"to",
"depth",
"0",
"."
] | 6766a36cc2f0c807c59202bf7540a08c4ef31192 | https://github.com/sulu/sulu/blob/6766a36cc2f0c807c59202bf7540a08c4ef31192/src/Sulu/Bundle/ContactBundle/Command/AccountRecoverCommand.php#L192-L201 | train |
sulu/sulu | src/Sulu/Bundle/PageBundle/Serializer/Subscriber/ParentSubscriber.php | ParentSubscriber.onPostSerialize | public function onPostSerialize(ObjectEvent $event)
{
$visitor = $event->getVisitor();
$document = $event->getObject();
if (!$document instanceof ParentBehavior || !$document->getParent() instanceof UuidBehavior) {
return;
}
$visitor->addData('parentUuid', $document->getParent()->getUuid());
} | php | public function onPostSerialize(ObjectEvent $event)
{
$visitor = $event->getVisitor();
$document = $event->getObject();
if (!$document instanceof ParentBehavior || !$document->getParent() instanceof UuidBehavior) {
return;
}
$visitor->addData('parentUuid', $document->getParent()->getUuid());
} | [
"public",
"function",
"onPostSerialize",
"(",
"ObjectEvent",
"$",
"event",
")",
"{",
"$",
"visitor",
"=",
"$",
"event",
"->",
"getVisitor",
"(",
")",
";",
"$",
"document",
"=",
"$",
"event",
"->",
"getObject",
"(",
")",
";",
"if",
"(",
"!",
"$",
"document",
"instanceof",
"ParentBehavior",
"||",
"!",
"$",
"document",
"->",
"getParent",
"(",
")",
"instanceof",
"UuidBehavior",
")",
"{",
"return",
";",
"}",
"$",
"visitor",
"->",
"addData",
"(",
"'parentUuid'",
",",
"$",
"document",
"->",
"getParent",
"(",
")",
"->",
"getUuid",
"(",
")",
")",
";",
"}"
] | Adds the identifier of the parent document to the serialization.
@param ObjectEvent $event | [
"Adds",
"the",
"identifier",
"of",
"the",
"parent",
"document",
"to",
"the",
"serialization",
"."
] | 6766a36cc2f0c807c59202bf7540a08c4ef31192 | https://github.com/sulu/sulu/blob/6766a36cc2f0c807c59202bf7540a08c4ef31192/src/Sulu/Bundle/PageBundle/Serializer/Subscriber/ParentSubscriber.php#L44-L54 | train |
sulu/sulu | src/Sulu/Bundle/DocumentManagerBundle/Session/SessionManager.php | SessionManager.setNodePropertyForSession | private function setNodePropertyForSession(SessionInterface $session, $nodePath, $propertyName, $value)
{
$session->getNode($nodePath)->setProperty($propertyName, $value);
} | php | private function setNodePropertyForSession(SessionInterface $session, $nodePath, $propertyName, $value)
{
$session->getNode($nodePath)->setProperty($propertyName, $value);
} | [
"private",
"function",
"setNodePropertyForSession",
"(",
"SessionInterface",
"$",
"session",
",",
"$",
"nodePath",
",",
"$",
"propertyName",
",",
"$",
"value",
")",
"{",
"$",
"session",
"->",
"getNode",
"(",
"$",
"nodePath",
")",
"->",
"setProperty",
"(",
"$",
"propertyName",
",",
"$",
"value",
")",
";",
"}"
] | Sets the property of the node at the given path to the given value. The change is only applied to the given
session.
@param SessionInterface $session
@param string $nodePath
@param string $propertyName
@param mixed $value | [
"Sets",
"the",
"property",
"of",
"the",
"node",
"at",
"the",
"given",
"path",
"to",
"the",
"given",
"value",
".",
"The",
"change",
"is",
"only",
"applied",
"to",
"the",
"given",
"session",
"."
] | 6766a36cc2f0c807c59202bf7540a08c4ef31192 | https://github.com/sulu/sulu/blob/6766a36cc2f0c807c59202bf7540a08c4ef31192/src/Sulu/Bundle/DocumentManagerBundle/Session/SessionManager.php#L64-L67 | train |
sulu/sulu | src/Sulu/Bundle/MediaBundle/Media/FormatOptions/FormatOptionsManager.php | FormatOptionsManager.getFileVersionForMedia | private function getFileVersionForMedia(MediaInterface $media)
{
/** @var File $file */
$file = $media->getFiles()->get(0);
if (!isset($file)) {
throw new FileVersionNotFoundException($media->getId(), 'latest');
}
$fileVersion = $file->getLatestFileVersion();
if (!isset($fileVersion)) {
throw new FileVersionNotFoundException($media->getId(), 'latest');
}
return $fileVersion;
} | php | private function getFileVersionForMedia(MediaInterface $media)
{
/** @var File $file */
$file = $media->getFiles()->get(0);
if (!isset($file)) {
throw new FileVersionNotFoundException($media->getId(), 'latest');
}
$fileVersion = $file->getLatestFileVersion();
if (!isset($fileVersion)) {
throw new FileVersionNotFoundException($media->getId(), 'latest');
}
return $fileVersion;
} | [
"private",
"function",
"getFileVersionForMedia",
"(",
"MediaInterface",
"$",
"media",
")",
"{",
"/** @var File $file */",
"$",
"file",
"=",
"$",
"media",
"->",
"getFiles",
"(",
")",
"->",
"get",
"(",
"0",
")",
";",
"if",
"(",
"!",
"isset",
"(",
"$",
"file",
")",
")",
"{",
"throw",
"new",
"FileVersionNotFoundException",
"(",
"$",
"media",
"->",
"getId",
"(",
")",
",",
"'latest'",
")",
";",
"}",
"$",
"fileVersion",
"=",
"$",
"file",
"->",
"getLatestFileVersion",
"(",
")",
";",
"if",
"(",
"!",
"isset",
"(",
"$",
"fileVersion",
")",
")",
"{",
"throw",
"new",
"FileVersionNotFoundException",
"(",
"$",
"media",
"->",
"getId",
"(",
")",
",",
"'latest'",
")",
";",
"}",
"return",
"$",
"fileVersion",
";",
"}"
] | Gets the latest file-version of a given media.
@param MediaInterface $media
@throws FileVersionNotFoundException
@return FileVersion | [
"Gets",
"the",
"latest",
"file",
"-",
"version",
"of",
"a",
"given",
"media",
"."
] | 6766a36cc2f0c807c59202bf7540a08c4ef31192 | https://github.com/sulu/sulu/blob/6766a36cc2f0c807c59202bf7540a08c4ef31192/src/Sulu/Bundle/MediaBundle/Media/FormatOptions/FormatOptionsManager.php#L186-L200 | train |
sulu/sulu | src/Sulu/Bundle/MediaBundle/Media/FormatOptions/FormatOptionsManager.php | FormatOptionsManager.setDataOnEntity | private function setDataOnEntity(FormatOptions $formatOptions, array $data)
{
if (!isset($data['cropX']) || !isset($data['cropY']) || !isset($data['cropWidth']) || !isset($data['cropHeight'])) {
throw new FormatOptionsMissingParameterException();
}
$formatOptions->setCropX($data['cropX']);
$formatOptions->setCropY($data['cropY']);
$formatOptions->setCropWidth($data['cropWidth']);
$formatOptions->setCropHeight($data['cropHeight']);
return $formatOptions;
} | php | private function setDataOnEntity(FormatOptions $formatOptions, array $data)
{
if (!isset($data['cropX']) || !isset($data['cropY']) || !isset($data['cropWidth']) || !isset($data['cropHeight'])) {
throw new FormatOptionsMissingParameterException();
}
$formatOptions->setCropX($data['cropX']);
$formatOptions->setCropY($data['cropY']);
$formatOptions->setCropWidth($data['cropWidth']);
$formatOptions->setCropHeight($data['cropHeight']);
return $formatOptions;
} | [
"private",
"function",
"setDataOnEntity",
"(",
"FormatOptions",
"$",
"formatOptions",
",",
"array",
"$",
"data",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"data",
"[",
"'cropX'",
"]",
")",
"||",
"!",
"isset",
"(",
"$",
"data",
"[",
"'cropY'",
"]",
")",
"||",
"!",
"isset",
"(",
"$",
"data",
"[",
"'cropWidth'",
"]",
")",
"||",
"!",
"isset",
"(",
"$",
"data",
"[",
"'cropHeight'",
"]",
")",
")",
"{",
"throw",
"new",
"FormatOptionsMissingParameterException",
"(",
")",
";",
"}",
"$",
"formatOptions",
"->",
"setCropX",
"(",
"$",
"data",
"[",
"'cropX'",
"]",
")",
";",
"$",
"formatOptions",
"->",
"setCropY",
"(",
"$",
"data",
"[",
"'cropY'",
"]",
")",
";",
"$",
"formatOptions",
"->",
"setCropWidth",
"(",
"$",
"data",
"[",
"'cropWidth'",
"]",
")",
";",
"$",
"formatOptions",
"->",
"setCropHeight",
"(",
"$",
"data",
"[",
"'cropHeight'",
"]",
")",
";",
"return",
"$",
"formatOptions",
";",
"}"
] | Sets a given array of data onto a given format-options entity.
@param FormatOptions $formatOptions
@param array $data
@throws FormatOptionsMissingParameterException
@return FormatOptions The format-options entity with set data | [
"Sets",
"a",
"given",
"array",
"of",
"data",
"onto",
"a",
"given",
"format",
"-",
"options",
"entity",
"."
] | 6766a36cc2f0c807c59202bf7540a08c4ef31192 | https://github.com/sulu/sulu/blob/6766a36cc2f0c807c59202bf7540a08c4ef31192/src/Sulu/Bundle/MediaBundle/Media/FormatOptions/FormatOptionsManager.php#L212-L224 | train |
sulu/sulu | src/Sulu/Bundle/MediaBundle/Media/FormatOptions/FormatOptionsManager.php | FormatOptionsManager.entityToArray | private function entityToArray(FormatOptions $formatOptions)
{
return [
'cropX' => $formatOptions->getCropX(),
'cropY' => $formatOptions->getCropY(),
'cropWidth' => $formatOptions->getCropWidth(),
'cropHeight' => $formatOptions->getCropHeight(),
];
} | php | private function entityToArray(FormatOptions $formatOptions)
{
return [
'cropX' => $formatOptions->getCropX(),
'cropY' => $formatOptions->getCropY(),
'cropWidth' => $formatOptions->getCropWidth(),
'cropHeight' => $formatOptions->getCropHeight(),
];
} | [
"private",
"function",
"entityToArray",
"(",
"FormatOptions",
"$",
"formatOptions",
")",
"{",
"return",
"[",
"'cropX'",
"=>",
"$",
"formatOptions",
"->",
"getCropX",
"(",
")",
",",
"'cropY'",
"=>",
"$",
"formatOptions",
"->",
"getCropY",
"(",
")",
",",
"'cropWidth'",
"=>",
"$",
"formatOptions",
"->",
"getCropWidth",
"(",
")",
",",
"'cropHeight'",
"=>",
"$",
"formatOptions",
"->",
"getCropHeight",
"(",
")",
",",
"]",
";",
"}"
] | Converts a given entity to its array representation.
@param FormatOptions $formatOptions
@return array | [
"Converts",
"a",
"given",
"entity",
"to",
"its",
"array",
"representation",
"."
] | 6766a36cc2f0c807c59202bf7540a08c4ef31192 | https://github.com/sulu/sulu/blob/6766a36cc2f0c807c59202bf7540a08c4ef31192/src/Sulu/Bundle/MediaBundle/Media/FormatOptions/FormatOptionsManager.php#L233-L241 | train |
sulu/sulu | src/Sulu/Bundle/MediaBundle/Media/FormatOptions/FormatOptionsManager.php | FormatOptionsManager.purgeMedia | private function purgeMedia($mediaId, FileVersion $fileVersion)
{
$this->formatManager->purge(
$mediaId,
$fileVersion->getName(),
$fileVersion->getMimeType(),
$fileVersion->getStorageOptions()
);
} | php | private function purgeMedia($mediaId, FileVersion $fileVersion)
{
$this->formatManager->purge(
$mediaId,
$fileVersion->getName(),
$fileVersion->getMimeType(),
$fileVersion->getStorageOptions()
);
} | [
"private",
"function",
"purgeMedia",
"(",
"$",
"mediaId",
",",
"FileVersion",
"$",
"fileVersion",
")",
"{",
"$",
"this",
"->",
"formatManager",
"->",
"purge",
"(",
"$",
"mediaId",
",",
"$",
"fileVersion",
"->",
"getName",
"(",
")",
",",
"$",
"fileVersion",
"->",
"getMimeType",
"(",
")",
",",
"$",
"fileVersion",
"->",
"getStorageOptions",
"(",
")",
")",
";",
"}"
] | Purges a file-version of a media with a given id.
@param int $mediaId
@param FileVersion $fileVersion | [
"Purges",
"a",
"file",
"-",
"version",
"of",
"a",
"media",
"with",
"a",
"given",
"id",
"."
] | 6766a36cc2f0c807c59202bf7540a08c4ef31192 | https://github.com/sulu/sulu/blob/6766a36cc2f0c807c59202bf7540a08c4ef31192/src/Sulu/Bundle/MediaBundle/Media/FormatOptions/FormatOptionsManager.php#L249-L257 | train |
sulu/sulu | src/Sulu/Bundle/PageBundle/Resources/phpcr-migrations/Version201510210733.php | Version201510210733.findUrlBlockProperties | private function findUrlBlockProperties(BlockMetadata $property, $structureName, array &$properties)
{
foreach ($property->getComponents() as $component) {
foreach ($component->getChildren() as $childProperty) {
if ('url' === $childProperty->getType()) {
$properties[$structureName][] = $property->getName();
}
}
}
} | php | private function findUrlBlockProperties(BlockMetadata $property, $structureName, array &$properties)
{
foreach ($property->getComponents() as $component) {
foreach ($component->getChildren() as $childProperty) {
if ('url' === $childProperty->getType()) {
$properties[$structureName][] = $property->getName();
}
}
}
} | [
"private",
"function",
"findUrlBlockProperties",
"(",
"BlockMetadata",
"$",
"property",
",",
"$",
"structureName",
",",
"array",
"&",
"$",
"properties",
")",
"{",
"foreach",
"(",
"$",
"property",
"->",
"getComponents",
"(",
")",
"as",
"$",
"component",
")",
"{",
"foreach",
"(",
"$",
"component",
"->",
"getChildren",
"(",
")",
"as",
"$",
"childProperty",
")",
"{",
"if",
"(",
"'url'",
"===",
"$",
"childProperty",
"->",
"getType",
"(",
")",
")",
"{",
"$",
"properties",
"[",
"$",
"structureName",
"]",
"[",
"]",
"=",
"$",
"property",
"->",
"getName",
"(",
")",
";",
"}",
"}",
"}",
"}"
] | Adds the block property to the list, if it contains a URL field.
@param BlockMetadata $property The block property to check
@param string $structureName The name of the structure the property belongs to
@param array $properties The list of properties, to which the block is added if it is a URL field | [
"Adds",
"the",
"block",
"property",
"to",
"the",
"list",
"if",
"it",
"contains",
"a",
"URL",
"field",
"."
] | 6766a36cc2f0c807c59202bf7540a08c4ef31192 | https://github.com/sulu/sulu/blob/6766a36cc2f0c807c59202bf7540a08c4ef31192/src/Sulu/Bundle/PageBundle/Resources/phpcr-migrations/Version201510210733.php#L191-L200 | train |
sulu/sulu | src/Sulu/Bundle/ResourceBundle/Controller/FilterController.php | FilterController.getAction | public function getAction(Request $request, $id)
{
$locale = $this->getRequestParameter($request, 'locale', true);
$view = $this->responseGetById(
$id,
function($id) use ($locale) {
return $this->getManager()->findByIdAndLocale($id, $locale);
}
);
return $this->handleView($view);
} | php | public function getAction(Request $request, $id)
{
$locale = $this->getRequestParameter($request, 'locale', true);
$view = $this->responseGetById(
$id,
function($id) use ($locale) {
return $this->getManager()->findByIdAndLocale($id, $locale);
}
);
return $this->handleView($view);
} | [
"public",
"function",
"getAction",
"(",
"Request",
"$",
"request",
",",
"$",
"id",
")",
"{",
"$",
"locale",
"=",
"$",
"this",
"->",
"getRequestParameter",
"(",
"$",
"request",
",",
"'locale'",
",",
"true",
")",
";",
"$",
"view",
"=",
"$",
"this",
"->",
"responseGetById",
"(",
"$",
"id",
",",
"function",
"(",
"$",
"id",
")",
"use",
"(",
"$",
"locale",
")",
"{",
"return",
"$",
"this",
"->",
"getManager",
"(",
")",
"->",
"findByIdAndLocale",
"(",
"$",
"id",
",",
"$",
"locale",
")",
";",
"}",
")",
";",
"return",
"$",
"this",
"->",
"handleView",
"(",
"$",
"view",
")",
";",
"}"
] | Retrieves a filter by id.
@param Request $request
@param $id
@return \Symfony\Component\HttpFoundation\Response | [
"Retrieves",
"a",
"filter",
"by",
"id",
"."
] | 6766a36cc2f0c807c59202bf7540a08c4ef31192 | https://github.com/sulu/sulu/blob/6766a36cc2f0c807c59202bf7540a08c4ef31192/src/Sulu/Bundle/ResourceBundle/Controller/FilterController.php#L57-L68 | train |
sulu/sulu | src/Sulu/Bundle/ResourceBundle/Controller/FilterController.php | FilterController.cgetAction | public function cgetAction(Request $request)
{
try {
// check if context exists and filters are enabled for the given context
$context = $request->get('context');
if (!$this->getManager()->hasContext($context)) {
throw new UnknownContextException($context);
}
if (!$this->getManager()->isFeatureEnabled($context, 'filters')) {
throw new MissingFeatureException($context, 'filters');
}
if ('true' == $request->get('flat')) {
$list = $this->getListRepresentation($request);
} else {
$list = new CollectionRepresentation(
$this->getManager()->findFiltersForUserAndContext(
$context,
$this->getUser()->getId(),
$this->getRequestParameter($request, 'locale', true)
),
self::$entityKey
);
}
$view = $this->view($list, 200);
} catch (UnknownContextException $exc) {
$exception = new RestException($exc->getMessage());
$view = $this->view($exception->toArray(), 400);
} catch (MissingFeatureException $exc) {
$exception = new RestException($exc->getMessage());
$view = $this->view($exception->toArray(), 400);
}
return $this->handleView($view);
} | php | public function cgetAction(Request $request)
{
try {
// check if context exists and filters are enabled for the given context
$context = $request->get('context');
if (!$this->getManager()->hasContext($context)) {
throw new UnknownContextException($context);
}
if (!$this->getManager()->isFeatureEnabled($context, 'filters')) {
throw new MissingFeatureException($context, 'filters');
}
if ('true' == $request->get('flat')) {
$list = $this->getListRepresentation($request);
} else {
$list = new CollectionRepresentation(
$this->getManager()->findFiltersForUserAndContext(
$context,
$this->getUser()->getId(),
$this->getRequestParameter($request, 'locale', true)
),
self::$entityKey
);
}
$view = $this->view($list, 200);
} catch (UnknownContextException $exc) {
$exception = new RestException($exc->getMessage());
$view = $this->view($exception->toArray(), 400);
} catch (MissingFeatureException $exc) {
$exception = new RestException($exc->getMessage());
$view = $this->view($exception->toArray(), 400);
}
return $this->handleView($view);
} | [
"public",
"function",
"cgetAction",
"(",
"Request",
"$",
"request",
")",
"{",
"try",
"{",
"// check if context exists and filters are enabled for the given context",
"$",
"context",
"=",
"$",
"request",
"->",
"get",
"(",
"'context'",
")",
";",
"if",
"(",
"!",
"$",
"this",
"->",
"getManager",
"(",
")",
"->",
"hasContext",
"(",
"$",
"context",
")",
")",
"{",
"throw",
"new",
"UnknownContextException",
"(",
"$",
"context",
")",
";",
"}",
"if",
"(",
"!",
"$",
"this",
"->",
"getManager",
"(",
")",
"->",
"isFeatureEnabled",
"(",
"$",
"context",
",",
"'filters'",
")",
")",
"{",
"throw",
"new",
"MissingFeatureException",
"(",
"$",
"context",
",",
"'filters'",
")",
";",
"}",
"if",
"(",
"'true'",
"==",
"$",
"request",
"->",
"get",
"(",
"'flat'",
")",
")",
"{",
"$",
"list",
"=",
"$",
"this",
"->",
"getListRepresentation",
"(",
"$",
"request",
")",
";",
"}",
"else",
"{",
"$",
"list",
"=",
"new",
"CollectionRepresentation",
"(",
"$",
"this",
"->",
"getManager",
"(",
")",
"->",
"findFiltersForUserAndContext",
"(",
"$",
"context",
",",
"$",
"this",
"->",
"getUser",
"(",
")",
"->",
"getId",
"(",
")",
",",
"$",
"this",
"->",
"getRequestParameter",
"(",
"$",
"request",
",",
"'locale'",
",",
"true",
")",
")",
",",
"self",
"::",
"$",
"entityKey",
")",
";",
"}",
"$",
"view",
"=",
"$",
"this",
"->",
"view",
"(",
"$",
"list",
",",
"200",
")",
";",
"}",
"catch",
"(",
"UnknownContextException",
"$",
"exc",
")",
"{",
"$",
"exception",
"=",
"new",
"RestException",
"(",
"$",
"exc",
"->",
"getMessage",
"(",
")",
")",
";",
"$",
"view",
"=",
"$",
"this",
"->",
"view",
"(",
"$",
"exception",
"->",
"toArray",
"(",
")",
",",
"400",
")",
";",
"}",
"catch",
"(",
"MissingFeatureException",
"$",
"exc",
")",
"{",
"$",
"exception",
"=",
"new",
"RestException",
"(",
"$",
"exc",
"->",
"getMessage",
"(",
")",
")",
";",
"$",
"view",
"=",
"$",
"this",
"->",
"view",
"(",
"$",
"exception",
"->",
"toArray",
"(",
")",
",",
"400",
")",
";",
"}",
"return",
"$",
"this",
"->",
"handleView",
"(",
"$",
"view",
")",
";",
"}"
] | Returns a list of filters.
@param \Symfony\Component\HttpFoundation\Request $request
@return \Symfony\Component\HttpFoundation\Response | [
"Returns",
"a",
"list",
"of",
"filters",
"."
] | 6766a36cc2f0c807c59202bf7540a08c4ef31192 | https://github.com/sulu/sulu/blob/6766a36cc2f0c807c59202bf7540a08c4ef31192/src/Sulu/Bundle/ResourceBundle/Controller/FilterController.php#L77-L113 | train |
sulu/sulu | src/Sulu/Bundle/ResourceBundle/Controller/FilterController.php | FilterController.postAction | public function postAction(Request $request)
{
try {
$filter = $this->getManager()->save(
$request->request->all(),
$this->getRequestParameter($request, 'locale', true),
$this->getUser()->getId()
);
$view = $this->view($filter, 200);
} catch (FilterDependencyNotFoundException $e) {
$exception = new EntityNotFoundException($e->getEntityName(), $e->getId());
$view = $this->view($exception->toArray(), 400);
} catch (MissingFilterException $e) {
$exception = new MissingArgumentException(self::$entityName, $e->getFilter());
$view = $this->view($exception->toArray(), 400);
} catch (MissingFilterAttributeException $e) {
$exception = new MissingArgumentException(self::$entityName, $e->getAttribute());
$view = $this->view($exception->toArray(), 400);
} catch (ConditionGroupMismatchException $e) {
$exception = new InvalidArgumentException(self::$groupConditionEntityName, $e->getId());
$view = $this->view($exception->toArray(), 400);
} catch (UnknownContextException $e) {
$exception = new RestException($e->getMessage());
$view = $this->view($exception->toArray(), 400);
}
return $this->handleView($view);
} | php | public function postAction(Request $request)
{
try {
$filter = $this->getManager()->save(
$request->request->all(),
$this->getRequestParameter($request, 'locale', true),
$this->getUser()->getId()
);
$view = $this->view($filter, 200);
} catch (FilterDependencyNotFoundException $e) {
$exception = new EntityNotFoundException($e->getEntityName(), $e->getId());
$view = $this->view($exception->toArray(), 400);
} catch (MissingFilterException $e) {
$exception = new MissingArgumentException(self::$entityName, $e->getFilter());
$view = $this->view($exception->toArray(), 400);
} catch (MissingFilterAttributeException $e) {
$exception = new MissingArgumentException(self::$entityName, $e->getAttribute());
$view = $this->view($exception->toArray(), 400);
} catch (ConditionGroupMismatchException $e) {
$exception = new InvalidArgumentException(self::$groupConditionEntityName, $e->getId());
$view = $this->view($exception->toArray(), 400);
} catch (UnknownContextException $e) {
$exception = new RestException($e->getMessage());
$view = $this->view($exception->toArray(), 400);
}
return $this->handleView($view);
} | [
"public",
"function",
"postAction",
"(",
"Request",
"$",
"request",
")",
"{",
"try",
"{",
"$",
"filter",
"=",
"$",
"this",
"->",
"getManager",
"(",
")",
"->",
"save",
"(",
"$",
"request",
"->",
"request",
"->",
"all",
"(",
")",
",",
"$",
"this",
"->",
"getRequestParameter",
"(",
"$",
"request",
",",
"'locale'",
",",
"true",
")",
",",
"$",
"this",
"->",
"getUser",
"(",
")",
"->",
"getId",
"(",
")",
")",
";",
"$",
"view",
"=",
"$",
"this",
"->",
"view",
"(",
"$",
"filter",
",",
"200",
")",
";",
"}",
"catch",
"(",
"FilterDependencyNotFoundException",
"$",
"e",
")",
"{",
"$",
"exception",
"=",
"new",
"EntityNotFoundException",
"(",
"$",
"e",
"->",
"getEntityName",
"(",
")",
",",
"$",
"e",
"->",
"getId",
"(",
")",
")",
";",
"$",
"view",
"=",
"$",
"this",
"->",
"view",
"(",
"$",
"exception",
"->",
"toArray",
"(",
")",
",",
"400",
")",
";",
"}",
"catch",
"(",
"MissingFilterException",
"$",
"e",
")",
"{",
"$",
"exception",
"=",
"new",
"MissingArgumentException",
"(",
"self",
"::",
"$",
"entityName",
",",
"$",
"e",
"->",
"getFilter",
"(",
")",
")",
";",
"$",
"view",
"=",
"$",
"this",
"->",
"view",
"(",
"$",
"exception",
"->",
"toArray",
"(",
")",
",",
"400",
")",
";",
"}",
"catch",
"(",
"MissingFilterAttributeException",
"$",
"e",
")",
"{",
"$",
"exception",
"=",
"new",
"MissingArgumentException",
"(",
"self",
"::",
"$",
"entityName",
",",
"$",
"e",
"->",
"getAttribute",
"(",
")",
")",
";",
"$",
"view",
"=",
"$",
"this",
"->",
"view",
"(",
"$",
"exception",
"->",
"toArray",
"(",
")",
",",
"400",
")",
";",
"}",
"catch",
"(",
"ConditionGroupMismatchException",
"$",
"e",
")",
"{",
"$",
"exception",
"=",
"new",
"InvalidArgumentException",
"(",
"self",
"::",
"$",
"groupConditionEntityName",
",",
"$",
"e",
"->",
"getId",
"(",
")",
")",
";",
"$",
"view",
"=",
"$",
"this",
"->",
"view",
"(",
"$",
"exception",
"->",
"toArray",
"(",
")",
",",
"400",
")",
";",
"}",
"catch",
"(",
"UnknownContextException",
"$",
"e",
")",
"{",
"$",
"exception",
"=",
"new",
"RestException",
"(",
"$",
"e",
"->",
"getMessage",
"(",
")",
")",
";",
"$",
"view",
"=",
"$",
"this",
"->",
"view",
"(",
"$",
"exception",
"->",
"toArray",
"(",
")",
",",
"400",
")",
";",
"}",
"return",
"$",
"this",
"->",
"handleView",
"(",
"$",
"view",
")",
";",
"}"
] | Creates and stores a new filter.
@param \Symfony\Component\HttpFoundation\Request $request
@return \Symfony\Component\HttpFoundation\Response | [
"Creates",
"and",
"stores",
"a",
"new",
"filter",
"."
] | 6766a36cc2f0c807c59202bf7540a08c4ef31192 | https://github.com/sulu/sulu/blob/6766a36cc2f0c807c59202bf7540a08c4ef31192/src/Sulu/Bundle/ResourceBundle/Controller/FilterController.php#L167-L194 | train |
sulu/sulu | src/Sulu/Bundle/ResourceBundle/Controller/FilterController.php | FilterController.fieldsAction | public function fieldsAction(Request $request)
{
$locale = $this->getRequestParameter($request, 'locale', true);
return $this->handleView(
$this->view(array_values($this->getManager()->getFieldDescriptors($locale)), 200)
);
} | php | public function fieldsAction(Request $request)
{
$locale = $this->getRequestParameter($request, 'locale', true);
return $this->handleView(
$this->view(array_values($this->getManager()->getFieldDescriptors($locale)), 200)
);
} | [
"public",
"function",
"fieldsAction",
"(",
"Request",
"$",
"request",
")",
"{",
"$",
"locale",
"=",
"$",
"this",
"->",
"getRequestParameter",
"(",
"$",
"request",
",",
"'locale'",
",",
"true",
")",
";",
"return",
"$",
"this",
"->",
"handleView",
"(",
"$",
"this",
"->",
"view",
"(",
"array_values",
"(",
"$",
"this",
"->",
"getManager",
"(",
")",
"->",
"getFieldDescriptors",
"(",
"$",
"locale",
")",
")",
",",
"200",
")",
")",
";",
"}"
] | returns all fields that can be used by list.
@param \Symfony\Component\HttpFoundation\Request $request
@return mixed | [
"returns",
"all",
"fields",
"that",
"can",
"be",
"used",
"by",
"list",
"."
] | 6766a36cc2f0c807c59202bf7540a08c4ef31192 | https://github.com/sulu/sulu/blob/6766a36cc2f0c807c59202bf7540a08c4ef31192/src/Sulu/Bundle/ResourceBundle/Controller/FilterController.php#L287-L294 | train |
sulu/sulu | src/Sulu/Bundle/ContactBundle/Controller/CountryController.php | CountryController.getAction | public function getAction($id)
{
return $this->handleView(
$this->view(
$this->get('sulu_contact.country_repository')->find($id)
)
);
} | php | public function getAction($id)
{
return $this->handleView(
$this->view(
$this->get('sulu_contact.country_repository')->find($id)
)
);
} | [
"public",
"function",
"getAction",
"(",
"$",
"id",
")",
"{",
"return",
"$",
"this",
"->",
"handleView",
"(",
"$",
"this",
"->",
"view",
"(",
"$",
"this",
"->",
"get",
"(",
"'sulu_contact.country_repository'",
")",
"->",
"find",
"(",
"$",
"id",
")",
")",
")",
";",
"}"
] | Returns country identified by code.
@param int $id
@return Response | [
"Returns",
"country",
"identified",
"by",
"code",
"."
] | 6766a36cc2f0c807c59202bf7540a08c4ef31192 | https://github.com/sulu/sulu/blob/6766a36cc2f0c807c59202bf7540a08c4ef31192/src/Sulu/Bundle/ContactBundle/Controller/CountryController.php#L31-L38 | train |
sulu/sulu | src/Sulu/Bundle/HttpCacheBundle/EventSubscriber/InvalidationSubscriber.php | InvalidationSubscriber.invalidateDocumentBeforeUnpublishing | public function invalidateDocumentBeforeUnpublishing(UnpublishEvent $event)
{
$document = $event->getDocument();
if ($document instanceof StructureBehavior) {
$this->invalidateDocumentStructure($document);
}
if ($document instanceof ResourceSegmentBehavior
&& $document instanceof WorkflowStageBehavior
&& $document->getPublished()
) {
$this->invalidateDocumentUrls($document, $this->documentInspector->getLocale($document));
}
} | php | public function invalidateDocumentBeforeUnpublishing(UnpublishEvent $event)
{
$document = $event->getDocument();
if ($document instanceof StructureBehavior) {
$this->invalidateDocumentStructure($document);
}
if ($document instanceof ResourceSegmentBehavior
&& $document instanceof WorkflowStageBehavior
&& $document->getPublished()
) {
$this->invalidateDocumentUrls($document, $this->documentInspector->getLocale($document));
}
} | [
"public",
"function",
"invalidateDocumentBeforeUnpublishing",
"(",
"UnpublishEvent",
"$",
"event",
")",
"{",
"$",
"document",
"=",
"$",
"event",
"->",
"getDocument",
"(",
")",
";",
"if",
"(",
"$",
"document",
"instanceof",
"StructureBehavior",
")",
"{",
"$",
"this",
"->",
"invalidateDocumentStructure",
"(",
"$",
"document",
")",
";",
"}",
"if",
"(",
"$",
"document",
"instanceof",
"ResourceSegmentBehavior",
"&&",
"$",
"document",
"instanceof",
"WorkflowStageBehavior",
"&&",
"$",
"document",
"->",
"getPublished",
"(",
")",
")",
"{",
"$",
"this",
"->",
"invalidateDocumentUrls",
"(",
"$",
"document",
",",
"$",
"this",
"->",
"documentInspector",
"->",
"getLocale",
"(",
"$",
"document",
")",
")",
";",
"}",
"}"
] | Invalidates the assigned structure and all urls in the locale of the document when a document gets unpublished.
This method is executed before the actual unpublishing of the document because the document must still
be published to gather the urls of the document.
@param UnpublishEvent $event | [
"Invalidates",
"the",
"assigned",
"structure",
"and",
"all",
"urls",
"in",
"the",
"locale",
"of",
"the",
"document",
"when",
"a",
"document",
"gets",
"unpublished",
".",
"This",
"method",
"is",
"executed",
"before",
"the",
"actual",
"unpublishing",
"of",
"the",
"document",
"because",
"the",
"document",
"must",
"still",
"be",
"published",
"to",
"gather",
"the",
"urls",
"of",
"the",
"document",
"."
] | 6766a36cc2f0c807c59202bf7540a08c4ef31192 | https://github.com/sulu/sulu/blob/6766a36cc2f0c807c59202bf7540a08c4ef31192/src/Sulu/Bundle/HttpCacheBundle/EventSubscriber/InvalidationSubscriber.php#L158-L172 | train |
sulu/sulu | src/Sulu/Bundle/HttpCacheBundle/EventSubscriber/InvalidationSubscriber.php | InvalidationSubscriber.invalidateDocumentBeforeRemoving | public function invalidateDocumentBeforeRemoving(RemoveEvent $event)
{
$document = $event->getDocument();
if ($document instanceof StructureBehavior) {
$this->invalidateDocumentStructure($document);
}
if ($document instanceof ResourceSegmentBehavior) {
foreach ($this->documentInspector->getPublishedLocales($document) as $locale) {
$this->invalidateDocumentUrls($document, $locale);
}
}
} | php | public function invalidateDocumentBeforeRemoving(RemoveEvent $event)
{
$document = $event->getDocument();
if ($document instanceof StructureBehavior) {
$this->invalidateDocumentStructure($document);
}
if ($document instanceof ResourceSegmentBehavior) {
foreach ($this->documentInspector->getPublishedLocales($document) as $locale) {
$this->invalidateDocumentUrls($document, $locale);
}
}
} | [
"public",
"function",
"invalidateDocumentBeforeRemoving",
"(",
"RemoveEvent",
"$",
"event",
")",
"{",
"$",
"document",
"=",
"$",
"event",
"->",
"getDocument",
"(",
")",
";",
"if",
"(",
"$",
"document",
"instanceof",
"StructureBehavior",
")",
"{",
"$",
"this",
"->",
"invalidateDocumentStructure",
"(",
"$",
"document",
")",
";",
"}",
"if",
"(",
"$",
"document",
"instanceof",
"ResourceSegmentBehavior",
")",
"{",
"foreach",
"(",
"$",
"this",
"->",
"documentInspector",
"->",
"getPublishedLocales",
"(",
"$",
"document",
")",
"as",
"$",
"locale",
")",
"{",
"$",
"this",
"->",
"invalidateDocumentUrls",
"(",
"$",
"document",
",",
"$",
"locale",
")",
";",
"}",
"}",
"}"
] | Invalidates the assigned structure and all urls in all locales of the document when a document gets removed.
This method is executed before the actual removing of the document because the document must still
exist to gather the urls of the document.
@param RemoveEvent $event | [
"Invalidates",
"the",
"assigned",
"structure",
"and",
"all",
"urls",
"in",
"all",
"locales",
"of",
"the",
"document",
"when",
"a",
"document",
"gets",
"removed",
".",
"This",
"method",
"is",
"executed",
"before",
"the",
"actual",
"removing",
"of",
"the",
"document",
"because",
"the",
"document",
"must",
"still",
"exist",
"to",
"gather",
"the",
"urls",
"of",
"the",
"document",
"."
] | 6766a36cc2f0c807c59202bf7540a08c4ef31192 | https://github.com/sulu/sulu/blob/6766a36cc2f0c807c59202bf7540a08c4ef31192/src/Sulu/Bundle/HttpCacheBundle/EventSubscriber/InvalidationSubscriber.php#L181-L194 | train |
sulu/sulu | src/Sulu/Bundle/HttpCacheBundle/EventSubscriber/InvalidationSubscriber.php | InvalidationSubscriber.invalidateDocumentStructure | private function invalidateDocumentStructure($document)
{
if (!$this->cacheManager) {
return;
}
$structureBridge = $this->structureManager->wrapStructure(
$this->documentInspector->getMetadata($document)->getAlias(),
$this->documentInspector->getStructureMetadata($document)
);
$structureBridge->setDocument($document);
$this->cacheManager->invalidateTag($document->getUuid());
} | php | private function invalidateDocumentStructure($document)
{
if (!$this->cacheManager) {
return;
}
$structureBridge = $this->structureManager->wrapStructure(
$this->documentInspector->getMetadata($document)->getAlias(),
$this->documentInspector->getStructureMetadata($document)
);
$structureBridge->setDocument($document);
$this->cacheManager->invalidateTag($document->getUuid());
} | [
"private",
"function",
"invalidateDocumentStructure",
"(",
"$",
"document",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"cacheManager",
")",
"{",
"return",
";",
"}",
"$",
"structureBridge",
"=",
"$",
"this",
"->",
"structureManager",
"->",
"wrapStructure",
"(",
"$",
"this",
"->",
"documentInspector",
"->",
"getMetadata",
"(",
"$",
"document",
")",
"->",
"getAlias",
"(",
")",
",",
"$",
"this",
"->",
"documentInspector",
"->",
"getStructureMetadata",
"(",
"$",
"document",
")",
")",
";",
"$",
"structureBridge",
"->",
"setDocument",
"(",
"$",
"document",
")",
";",
"$",
"this",
"->",
"cacheManager",
"->",
"invalidateTag",
"(",
"$",
"document",
"->",
"getUuid",
"(",
")",
")",
";",
"}"
] | Invalidates the structure of the given document.
@param $document | [
"Invalidates",
"the",
"structure",
"of",
"the",
"given",
"document",
"."
] | 6766a36cc2f0c807c59202bf7540a08c4ef31192 | https://github.com/sulu/sulu/blob/6766a36cc2f0c807c59202bf7540a08c4ef31192/src/Sulu/Bundle/HttpCacheBundle/EventSubscriber/InvalidationSubscriber.php#L201-L214 | train |
sulu/sulu | src/Sulu/Bundle/HttpCacheBundle/EventSubscriber/InvalidationSubscriber.php | InvalidationSubscriber.invalidateDocumentUrls | private function invalidateDocumentUrls($document, $locale)
{
if (!$this->cacheManager) {
return;
}
foreach ($this->getLocaleUrls($document, $locale) as $url) {
$this->cacheManager->invalidatePath($url);
}
} | php | private function invalidateDocumentUrls($document, $locale)
{
if (!$this->cacheManager) {
return;
}
foreach ($this->getLocaleUrls($document, $locale) as $url) {
$this->cacheManager->invalidatePath($url);
}
} | [
"private",
"function",
"invalidateDocumentUrls",
"(",
"$",
"document",
",",
"$",
"locale",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"cacheManager",
")",
"{",
"return",
";",
"}",
"foreach",
"(",
"$",
"this",
"->",
"getLocaleUrls",
"(",
"$",
"document",
",",
"$",
"locale",
")",
"as",
"$",
"url",
")",
"{",
"$",
"this",
"->",
"cacheManager",
"->",
"invalidatePath",
"(",
"$",
"url",
")",
";",
"}",
"}"
] | Invalidates all urls which are assigned to the given document in the given locale.
@param $document
@param $locale | [
"Invalidates",
"all",
"urls",
"which",
"are",
"assigned",
"to",
"the",
"given",
"document",
"in",
"the",
"given",
"locale",
"."
] | 6766a36cc2f0c807c59202bf7540a08c4ef31192 | https://github.com/sulu/sulu/blob/6766a36cc2f0c807c59202bf7540a08c4ef31192/src/Sulu/Bundle/HttpCacheBundle/EventSubscriber/InvalidationSubscriber.php#L222-L231 | train |
sulu/sulu | src/Sulu/Bundle/HttpCacheBundle/EventSubscriber/InvalidationSubscriber.php | InvalidationSubscriber.invalidateDocumentExcerpt | private function invalidateDocumentExcerpt(ExtensionBehavior $document)
{
if (!$this->cacheManager) {
return;
}
$extensionData = $document->getExtensionsData();
if (!isset($extensionData['excerpt'])) {
return;
}
$excerpt = $extensionData['excerpt'];
if (isset($excerpt['tags'])) {
foreach ($this->tagManager->resolveTagNames($excerpt['tags']) as $tag) {
$this->cacheManager->invalidateReference('tag', $tag);
}
}
if (isset($excerpt['categories'])) {
foreach ($excerpt['categories'] as $category) {
$this->cacheManager->invalidateReference('category', $category);
}
}
} | php | private function invalidateDocumentExcerpt(ExtensionBehavior $document)
{
if (!$this->cacheManager) {
return;
}
$extensionData = $document->getExtensionsData();
if (!isset($extensionData['excerpt'])) {
return;
}
$excerpt = $extensionData['excerpt'];
if (isset($excerpt['tags'])) {
foreach ($this->tagManager->resolveTagNames($excerpt['tags']) as $tag) {
$this->cacheManager->invalidateReference('tag', $tag);
}
}
if (isset($excerpt['categories'])) {
foreach ($excerpt['categories'] as $category) {
$this->cacheManager->invalidateReference('category', $category);
}
}
} | [
"private",
"function",
"invalidateDocumentExcerpt",
"(",
"ExtensionBehavior",
"$",
"document",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"cacheManager",
")",
"{",
"return",
";",
"}",
"$",
"extensionData",
"=",
"$",
"document",
"->",
"getExtensionsData",
"(",
")",
";",
"if",
"(",
"!",
"isset",
"(",
"$",
"extensionData",
"[",
"'excerpt'",
"]",
")",
")",
"{",
"return",
";",
"}",
"$",
"excerpt",
"=",
"$",
"extensionData",
"[",
"'excerpt'",
"]",
";",
"if",
"(",
"isset",
"(",
"$",
"excerpt",
"[",
"'tags'",
"]",
")",
")",
"{",
"foreach",
"(",
"$",
"this",
"->",
"tagManager",
"->",
"resolveTagNames",
"(",
"$",
"excerpt",
"[",
"'tags'",
"]",
")",
"as",
"$",
"tag",
")",
"{",
"$",
"this",
"->",
"cacheManager",
"->",
"invalidateReference",
"(",
"'tag'",
",",
"$",
"tag",
")",
";",
"}",
"}",
"if",
"(",
"isset",
"(",
"$",
"excerpt",
"[",
"'categories'",
"]",
")",
")",
"{",
"foreach",
"(",
"$",
"excerpt",
"[",
"'categories'",
"]",
"as",
"$",
"category",
")",
"{",
"$",
"this",
"->",
"cacheManager",
"->",
"invalidateReference",
"(",
"'category'",
",",
"$",
"category",
")",
";",
"}",
"}",
"}"
] | Invalidates all tags and categories from excerpt extension.
@param ExtensionBehavior $document | [
"Invalidates",
"all",
"tags",
"and",
"categories",
"from",
"excerpt",
"extension",
"."
] | 6766a36cc2f0c807c59202bf7540a08c4ef31192 | https://github.com/sulu/sulu/blob/6766a36cc2f0c807c59202bf7540a08c4ef31192/src/Sulu/Bundle/HttpCacheBundle/EventSubscriber/InvalidationSubscriber.php#L238-L262 | train |
sulu/sulu | src/Sulu/Bundle/HttpCacheBundle/EventSubscriber/InvalidationSubscriber.php | InvalidationSubscriber.findUrlsByResourceLocator | private function findUrlsByResourceLocator($resourceLocator, $locale, $webspace)
{
$scheme = 'http';
if ($request = $this->requestStack->getCurrentRequest()) {
$scheme = $request->getScheme();
}
return $this->webspaceManager->findUrlsByResourceLocator(
$resourceLocator,
$this->environment,
$locale,
$webspace,
null,
$scheme
);
} | php | private function findUrlsByResourceLocator($resourceLocator, $locale, $webspace)
{
$scheme = 'http';
if ($request = $this->requestStack->getCurrentRequest()) {
$scheme = $request->getScheme();
}
return $this->webspaceManager->findUrlsByResourceLocator(
$resourceLocator,
$this->environment,
$locale,
$webspace,
null,
$scheme
);
} | [
"private",
"function",
"findUrlsByResourceLocator",
"(",
"$",
"resourceLocator",
",",
"$",
"locale",
",",
"$",
"webspace",
")",
"{",
"$",
"scheme",
"=",
"'http'",
";",
"if",
"(",
"$",
"request",
"=",
"$",
"this",
"->",
"requestStack",
"->",
"getCurrentRequest",
"(",
")",
")",
"{",
"$",
"scheme",
"=",
"$",
"request",
"->",
"getScheme",
"(",
")",
";",
"}",
"return",
"$",
"this",
"->",
"webspaceManager",
"->",
"findUrlsByResourceLocator",
"(",
"$",
"resourceLocator",
",",
"$",
"this",
"->",
"environment",
",",
"$",
"locale",
",",
"$",
"webspace",
",",
"null",
",",
"$",
"scheme",
")",
";",
"}"
] | Returns array of resource-locators with "http" and "https".
@param string $resourceLocator
@param string $locale
@param string $webspace
@return string[] | [
"Returns",
"array",
"of",
"resource",
"-",
"locators",
"with",
"http",
"and",
"https",
"."
] | 6766a36cc2f0c807c59202bf7540a08c4ef31192 | https://github.com/sulu/sulu/blob/6766a36cc2f0c807c59202bf7540a08c4ef31192/src/Sulu/Bundle/HttpCacheBundle/EventSubscriber/InvalidationSubscriber.php#L316-L331 | train |
sulu/sulu | src/Sulu/Bundle/ContactBundle/Contact/ContactManager.php | ContactManager.getByIds | public function getByIds($ids, $locale)
{
if (!is_array($ids) || 0 === count($ids)) {
return [];
}
$contacts = $this->contactRepository->findByIds($ids);
return array_map(
function($contact) use ($locale) {
return $this->getApiObject($contact, $locale);
},
$contacts
);
} | php | public function getByIds($ids, $locale)
{
if (!is_array($ids) || 0 === count($ids)) {
return [];
}
$contacts = $this->contactRepository->findByIds($ids);
return array_map(
function($contact) use ($locale) {
return $this->getApiObject($contact, $locale);
},
$contacts
);
} | [
"public",
"function",
"getByIds",
"(",
"$",
"ids",
",",
"$",
"locale",
")",
"{",
"if",
"(",
"!",
"is_array",
"(",
"$",
"ids",
")",
"||",
"0",
"===",
"count",
"(",
"$",
"ids",
")",
")",
"{",
"return",
"[",
"]",
";",
"}",
"$",
"contacts",
"=",
"$",
"this",
"->",
"contactRepository",
"->",
"findByIds",
"(",
"$",
"ids",
")",
";",
"return",
"array_map",
"(",
"function",
"(",
"$",
"contact",
")",
"use",
"(",
"$",
"locale",
")",
"{",
"return",
"$",
"this",
"->",
"getApiObject",
"(",
"$",
"contact",
",",
"$",
"locale",
")",
";",
"}",
",",
"$",
"contacts",
")",
";",
"}"
] | Returns contact entities by ids.
@param $ids
@param $locale
@return mixed | [
"Returns",
"contact",
"entities",
"by",
"ids",
"."
] | 6766a36cc2f0c807c59202bf7540a08c4ef31192 | https://github.com/sulu/sulu/blob/6766a36cc2f0c807c59202bf7540a08c4ef31192/src/Sulu/Bundle/ContactBundle/Contact/ContactManager.php#L108-L122 | train |
sulu/sulu | src/Sulu/Bundle/ContactBundle/Contact/ContactManager.php | ContactManager.addAddress | public function addAddress($contact, Address $address, $isMain)
{
if (!$contact || !$address) {
throw new \Exception('Contact and Address cannot be null');
}
$contactAddress = new ContactAddress();
$contactAddress->setContact($contact);
$contactAddress->setAddress($address);
if ($isMain) {
$this->unsetMain($contact->getContactAddresses());
}
$contactAddress->setMain($isMain);
$this->em->persist($contactAddress);
$contact->addContactAddress($contactAddress);
return $contactAddress;
} | php | public function addAddress($contact, Address $address, $isMain)
{
if (!$contact || !$address) {
throw new \Exception('Contact and Address cannot be null');
}
$contactAddress = new ContactAddress();
$contactAddress->setContact($contact);
$contactAddress->setAddress($address);
if ($isMain) {
$this->unsetMain($contact->getContactAddresses());
}
$contactAddress->setMain($isMain);
$this->em->persist($contactAddress);
$contact->addContactAddress($contactAddress);
return $contactAddress;
} | [
"public",
"function",
"addAddress",
"(",
"$",
"contact",
",",
"Address",
"$",
"address",
",",
"$",
"isMain",
")",
"{",
"if",
"(",
"!",
"$",
"contact",
"||",
"!",
"$",
"address",
")",
"{",
"throw",
"new",
"\\",
"Exception",
"(",
"'Contact and Address cannot be null'",
")",
";",
"}",
"$",
"contactAddress",
"=",
"new",
"ContactAddress",
"(",
")",
";",
"$",
"contactAddress",
"->",
"setContact",
"(",
"$",
"contact",
")",
";",
"$",
"contactAddress",
"->",
"setAddress",
"(",
"$",
"address",
")",
";",
"if",
"(",
"$",
"isMain",
")",
"{",
"$",
"this",
"->",
"unsetMain",
"(",
"$",
"contact",
"->",
"getContactAddresses",
"(",
")",
")",
";",
"}",
"$",
"contactAddress",
"->",
"setMain",
"(",
"$",
"isMain",
")",
";",
"$",
"this",
"->",
"em",
"->",
"persist",
"(",
"$",
"contactAddress",
")",
";",
"$",
"contact",
"->",
"addContactAddress",
"(",
"$",
"contactAddress",
")",
";",
"return",
"$",
"contactAddress",
";",
"}"
] | adds an address to the entity.
@param Contact $contact The entity to add the address to
@param Address $address The address to be added
@param bool $isMain Defines if the address is the main Address of the contact
@return ContactAddress
@throws \Exception | [
"adds",
"an",
"address",
"to",
"the",
"entity",
"."
] | 6766a36cc2f0c807c59202bf7540a08c4ef31192 | https://github.com/sulu/sulu/blob/6766a36cc2f0c807c59202bf7540a08c4ef31192/src/Sulu/Bundle/ContactBundle/Contact/ContactManager.php#L379-L396 | train |
sulu/sulu | src/Sulu/Bundle/ContactBundle/Contact/ContactManager.php | ContactManager.removeAddressRelation | public function removeAddressRelation($contact, $contactAddress)
{
if (!$contact || !$contactAddress) {
throw new \Exception('Contact and ContactAddress cannot be null');
}
// reload address to get all data (including relational data)
/** @var Address $address */
$address = $contactAddress->getAddress();
$address = $this->em->getRepository(
'SuluContactBundle:Address'
)->findById($address->getId());
$isMain = $contactAddress->getMain();
// remove relation
$contact->removeContactAddress($contactAddress);
$address->removeContactAddress($contactAddress);
// if was main, set a new one
if ($isMain) {
$this->setMainForCollection($contact->getContactAddresses());
}
// delete address if it has no more relations
if (!$address->hasRelations()) {
$this->em->remove($address);
}
$this->em->remove($contactAddress);
} | php | public function removeAddressRelation($contact, $contactAddress)
{
if (!$contact || !$contactAddress) {
throw new \Exception('Contact and ContactAddress cannot be null');
}
// reload address to get all data (including relational data)
/** @var Address $address */
$address = $contactAddress->getAddress();
$address = $this->em->getRepository(
'SuluContactBundle:Address'
)->findById($address->getId());
$isMain = $contactAddress->getMain();
// remove relation
$contact->removeContactAddress($contactAddress);
$address->removeContactAddress($contactAddress);
// if was main, set a new one
if ($isMain) {
$this->setMainForCollection($contact->getContactAddresses());
}
// delete address if it has no more relations
if (!$address->hasRelations()) {
$this->em->remove($address);
}
$this->em->remove($contactAddress);
} | [
"public",
"function",
"removeAddressRelation",
"(",
"$",
"contact",
",",
"$",
"contactAddress",
")",
"{",
"if",
"(",
"!",
"$",
"contact",
"||",
"!",
"$",
"contactAddress",
")",
"{",
"throw",
"new",
"\\",
"Exception",
"(",
"'Contact and ContactAddress cannot be null'",
")",
";",
"}",
"// reload address to get all data (including relational data)",
"/** @var Address $address */",
"$",
"address",
"=",
"$",
"contactAddress",
"->",
"getAddress",
"(",
")",
";",
"$",
"address",
"=",
"$",
"this",
"->",
"em",
"->",
"getRepository",
"(",
"'SuluContactBundle:Address'",
")",
"->",
"findById",
"(",
"$",
"address",
"->",
"getId",
"(",
")",
")",
";",
"$",
"isMain",
"=",
"$",
"contactAddress",
"->",
"getMain",
"(",
")",
";",
"// remove relation",
"$",
"contact",
"->",
"removeContactAddress",
"(",
"$",
"contactAddress",
")",
";",
"$",
"address",
"->",
"removeContactAddress",
"(",
"$",
"contactAddress",
")",
";",
"// if was main, set a new one",
"if",
"(",
"$",
"isMain",
")",
"{",
"$",
"this",
"->",
"setMainForCollection",
"(",
"$",
"contact",
"->",
"getContactAddresses",
"(",
")",
")",
";",
"}",
"// delete address if it has no more relations",
"if",
"(",
"!",
"$",
"address",
"->",
"hasRelations",
"(",
")",
")",
"{",
"$",
"this",
"->",
"em",
"->",
"remove",
"(",
"$",
"address",
")",
";",
"}",
"$",
"this",
"->",
"em",
"->",
"remove",
"(",
"$",
"contactAddress",
")",
";",
"}"
] | removes the address relation from a contact and also deletes the address if it has no more relations.
@param Contact $contact
@param ContactAddress $contactAddress
@return mixed|void
@throws \Exception | [
"removes",
"the",
"address",
"relation",
"from",
"a",
"contact",
"and",
"also",
"deletes",
"the",
"address",
"if",
"it",
"has",
"no",
"more",
"relations",
"."
] | 6766a36cc2f0c807c59202bf7540a08c4ef31192 | https://github.com/sulu/sulu/blob/6766a36cc2f0c807c59202bf7540a08c4ef31192/src/Sulu/Bundle/ContactBundle/Contact/ContactManager.php#L408-L438 | train |
sulu/sulu | src/Sulu/Bundle/ContactBundle/Contact/ContactManager.php | ContactManager.setAvatar | private function setAvatar(Contact $contact, $avatar)
{
$mediaEntity = null;
if (is_array($avatar) && $this->getProperty($avatar, 'id')) {
$mediaId = $this->getProperty($avatar, 'id');
$mediaEntity = $this->mediaRepository->findMediaById($mediaId);
if (!$mediaEntity) {
throw new EntityNotFoundException($this->mediaRepository->getClassName(), $mediaId);
}
}
$contact->setAvatar($mediaEntity);
} | php | private function setAvatar(Contact $contact, $avatar)
{
$mediaEntity = null;
if (is_array($avatar) && $this->getProperty($avatar, 'id')) {
$mediaId = $this->getProperty($avatar, 'id');
$mediaEntity = $this->mediaRepository->findMediaById($mediaId);
if (!$mediaEntity) {
throw new EntityNotFoundException($this->mediaRepository->getClassName(), $mediaId);
}
}
$contact->setAvatar($mediaEntity);
} | [
"private",
"function",
"setAvatar",
"(",
"Contact",
"$",
"contact",
",",
"$",
"avatar",
")",
"{",
"$",
"mediaEntity",
"=",
"null",
";",
"if",
"(",
"is_array",
"(",
"$",
"avatar",
")",
"&&",
"$",
"this",
"->",
"getProperty",
"(",
"$",
"avatar",
",",
"'id'",
")",
")",
"{",
"$",
"mediaId",
"=",
"$",
"this",
"->",
"getProperty",
"(",
"$",
"avatar",
",",
"'id'",
")",
";",
"$",
"mediaEntity",
"=",
"$",
"this",
"->",
"mediaRepository",
"->",
"findMediaById",
"(",
"$",
"mediaId",
")",
";",
"if",
"(",
"!",
"$",
"mediaEntity",
")",
"{",
"throw",
"new",
"EntityNotFoundException",
"(",
"$",
"this",
"->",
"mediaRepository",
"->",
"getClassName",
"(",
")",
",",
"$",
"mediaId",
")",
";",
"}",
"}",
"$",
"contact",
"->",
"setAvatar",
"(",
"$",
"mediaEntity",
")",
";",
"}"
] | Sets a media with a given id as the avatar of a given contact.
@param Contact $contact
@param array $avatar with id property
@throws EntityNotFoundException | [
"Sets",
"a",
"media",
"with",
"a",
"given",
"id",
"as",
"the",
"avatar",
"of",
"a",
"given",
"contact",
"."
] | 6766a36cc2f0c807c59202bf7540a08c4ef31192 | https://github.com/sulu/sulu/blob/6766a36cc2f0c807c59202bf7540a08c4ef31192/src/Sulu/Bundle/ContactBundle/Contact/ContactManager.php#L556-L568 | train |
sulu/sulu | src/Sulu/Bundle/ContactBundle/Contact/ContactManager.php | ContactManager.getApiObject | protected function getApiObject($contact, $locale)
{
$apiObject = new ContactApi($contact, $locale);
if ($contact->getAvatar()) {
$apiAvatar = $this->mediaManager->getById($contact->getAvatar()->getId(), $locale);
$apiObject->setAvatar($apiAvatar);
}
return $apiObject;
} | php | protected function getApiObject($contact, $locale)
{
$apiObject = new ContactApi($contact, $locale);
if ($contact->getAvatar()) {
$apiAvatar = $this->mediaManager->getById($contact->getAvatar()->getId(), $locale);
$apiObject->setAvatar($apiAvatar);
}
return $apiObject;
} | [
"protected",
"function",
"getApiObject",
"(",
"$",
"contact",
",",
"$",
"locale",
")",
"{",
"$",
"apiObject",
"=",
"new",
"ContactApi",
"(",
"$",
"contact",
",",
"$",
"locale",
")",
";",
"if",
"(",
"$",
"contact",
"->",
"getAvatar",
"(",
")",
")",
"{",
"$",
"apiAvatar",
"=",
"$",
"this",
"->",
"mediaManager",
"->",
"getById",
"(",
"$",
"contact",
"->",
"getAvatar",
"(",
")",
"->",
"getId",
"(",
")",
",",
"$",
"locale",
")",
";",
"$",
"apiObject",
"->",
"setAvatar",
"(",
"$",
"apiAvatar",
")",
";",
"}",
"return",
"$",
"apiObject",
";",
"}"
] | Takes a contact entity and a locale and returns the api object.
@param Contact $contact
@param string $locale
@return ContactApi | [
"Takes",
"a",
"contact",
"entity",
"and",
"a",
"locale",
"and",
"returns",
"the",
"api",
"object",
"."
] | 6766a36cc2f0c807c59202bf7540a08c4ef31192 | https://github.com/sulu/sulu/blob/6766a36cc2f0c807c59202bf7540a08c4ef31192/src/Sulu/Bundle/ContactBundle/Contact/ContactManager.php#L614-L623 | train |
sulu/sulu | src/Sulu/Bundle/SecurityBundle/Controller/GroupController.php | GroupController.cgetAction | public function cgetAction(Request $request)
{
if ('true' == $request->get('flat')) {
/** @var RestHelperInterface $restHelper */
$restHelper = $this->get('sulu_core.doctrine_rest_helper');
/** @var DoctrineListBuilderFactory $factory */
$factory = $this->get('sulu_core.doctrine_list_builder_factory');
$listBuilder = $factory->create(static::$entityName);
$restHelper->initializeListBuilder($listBuilder, $this->fieldDescriptors);
$list = new ListRepresentation(
$listBuilder->execute(),
static::$entityKey,
'get_groups',
$request->query->all(),
$listBuilder->getCurrentPage(),
$listBuilder->getLimit(),
$listBuilder->count()
);
} else {
$list = new CollectionRepresentation(
$this->getDoctrine()->getRepository(static::$entityName)->findAllGroups(),
static::$entityKey
);
}
$view = $this->view($list, 200);
return $this->handleView($view);
} | php | public function cgetAction(Request $request)
{
if ('true' == $request->get('flat')) {
/** @var RestHelperInterface $restHelper */
$restHelper = $this->get('sulu_core.doctrine_rest_helper');
/** @var DoctrineListBuilderFactory $factory */
$factory = $this->get('sulu_core.doctrine_list_builder_factory');
$listBuilder = $factory->create(static::$entityName);
$restHelper->initializeListBuilder($listBuilder, $this->fieldDescriptors);
$list = new ListRepresentation(
$listBuilder->execute(),
static::$entityKey,
'get_groups',
$request->query->all(),
$listBuilder->getCurrentPage(),
$listBuilder->getLimit(),
$listBuilder->count()
);
} else {
$list = new CollectionRepresentation(
$this->getDoctrine()->getRepository(static::$entityName)->findAllGroups(),
static::$entityKey
);
}
$view = $this->view($list, 200);
return $this->handleView($view);
} | [
"public",
"function",
"cgetAction",
"(",
"Request",
"$",
"request",
")",
"{",
"if",
"(",
"'true'",
"==",
"$",
"request",
"->",
"get",
"(",
"'flat'",
")",
")",
"{",
"/** @var RestHelperInterface $restHelper */",
"$",
"restHelper",
"=",
"$",
"this",
"->",
"get",
"(",
"'sulu_core.doctrine_rest_helper'",
")",
";",
"/** @var DoctrineListBuilderFactory $factory */",
"$",
"factory",
"=",
"$",
"this",
"->",
"get",
"(",
"'sulu_core.doctrine_list_builder_factory'",
")",
";",
"$",
"listBuilder",
"=",
"$",
"factory",
"->",
"create",
"(",
"static",
"::",
"$",
"entityName",
")",
";",
"$",
"restHelper",
"->",
"initializeListBuilder",
"(",
"$",
"listBuilder",
",",
"$",
"this",
"->",
"fieldDescriptors",
")",
";",
"$",
"list",
"=",
"new",
"ListRepresentation",
"(",
"$",
"listBuilder",
"->",
"execute",
"(",
")",
",",
"static",
"::",
"$",
"entityKey",
",",
"'get_groups'",
",",
"$",
"request",
"->",
"query",
"->",
"all",
"(",
")",
",",
"$",
"listBuilder",
"->",
"getCurrentPage",
"(",
")",
",",
"$",
"listBuilder",
"->",
"getLimit",
"(",
")",
",",
"$",
"listBuilder",
"->",
"count",
"(",
")",
")",
";",
"}",
"else",
"{",
"$",
"list",
"=",
"new",
"CollectionRepresentation",
"(",
"$",
"this",
"->",
"getDoctrine",
"(",
")",
"->",
"getRepository",
"(",
"static",
"::",
"$",
"entityName",
")",
"->",
"findAllGroups",
"(",
")",
",",
"static",
"::",
"$",
"entityKey",
")",
";",
"}",
"$",
"view",
"=",
"$",
"this",
"->",
"view",
"(",
"$",
"list",
",",
"200",
")",
";",
"return",
"$",
"this",
"->",
"handleView",
"(",
"$",
"view",
")",
";",
"}"
] | returns all groups.
@param \Symfony\Component\HttpFoundation\Request $request
@return \Symfony\Component\HttpFoundation\Response | [
"returns",
"all",
"groups",
"."
] | 6766a36cc2f0c807c59202bf7540a08c4ef31192 | https://github.com/sulu/sulu/blob/6766a36cc2f0c807c59202bf7540a08c4ef31192/src/Sulu/Bundle/SecurityBundle/Controller/GroupController.php#L65-L96 | train |
sulu/sulu | src/Sulu/Bundle/SecurityBundle/Controller/GroupController.php | GroupController.getAction | public function getAction($id)
{
$find = function($id) {
/** @var Group $group */
$group = $this->getDoctrine()
->getRepository(static::$entityName)
->findGroupById($id);
return $group;
};
$view = $this->responseGetById($id, $find);
return $this->handleView($view);
} | php | public function getAction($id)
{
$find = function($id) {
/** @var Group $group */
$group = $this->getDoctrine()
->getRepository(static::$entityName)
->findGroupById($id);
return $group;
};
$view = $this->responseGetById($id, $find);
return $this->handleView($view);
} | [
"public",
"function",
"getAction",
"(",
"$",
"id",
")",
"{",
"$",
"find",
"=",
"function",
"(",
"$",
"id",
")",
"{",
"/** @var Group $group */",
"$",
"group",
"=",
"$",
"this",
"->",
"getDoctrine",
"(",
")",
"->",
"getRepository",
"(",
"static",
"::",
"$",
"entityName",
")",
"->",
"findGroupById",
"(",
"$",
"id",
")",
";",
"return",
"$",
"group",
";",
"}",
";",
"$",
"view",
"=",
"$",
"this",
"->",
"responseGetById",
"(",
"$",
"id",
",",
"$",
"find",
")",
";",
"return",
"$",
"this",
"->",
"handleView",
"(",
"$",
"view",
")",
";",
"}"
] | Returns the group with the given id.
@param $id
@return \Symfony\Component\HttpFoundation\Response | [
"Returns",
"the",
"group",
"with",
"the",
"given",
"id",
"."
] | 6766a36cc2f0c807c59202bf7540a08c4ef31192 | https://github.com/sulu/sulu/blob/6766a36cc2f0c807c59202bf7540a08c4ef31192/src/Sulu/Bundle/SecurityBundle/Controller/GroupController.php#L105-L119 | train |
sulu/sulu | src/Sulu/Bundle/SecurityBundle/Controller/GroupController.php | GroupController.postAction | public function postAction(Request $request)
{
$name = $request->get('name');
if (null != $name) {
$em = $this->getDoctrine()->getManager();
$group = new Group();
$group->setName($name);
$this->setParent($group, $request);
$roles = $request->get('roles');
if (!empty($roles)) {
foreach ($roles as $roleData) {
$this->addRole($group, $roleData);
}
}
$em->persist($group);
$em->flush();
$view = $this->view($group, 200);
} else {
$view = $this->view(null, 400);
}
return $this->handleView($view);
} | php | public function postAction(Request $request)
{
$name = $request->get('name');
if (null != $name) {
$em = $this->getDoctrine()->getManager();
$group = new Group();
$group->setName($name);
$this->setParent($group, $request);
$roles = $request->get('roles');
if (!empty($roles)) {
foreach ($roles as $roleData) {
$this->addRole($group, $roleData);
}
}
$em->persist($group);
$em->flush();
$view = $this->view($group, 200);
} else {
$view = $this->view(null, 400);
}
return $this->handleView($view);
} | [
"public",
"function",
"postAction",
"(",
"Request",
"$",
"request",
")",
"{",
"$",
"name",
"=",
"$",
"request",
"->",
"get",
"(",
"'name'",
")",
";",
"if",
"(",
"null",
"!=",
"$",
"name",
")",
"{",
"$",
"em",
"=",
"$",
"this",
"->",
"getDoctrine",
"(",
")",
"->",
"getManager",
"(",
")",
";",
"$",
"group",
"=",
"new",
"Group",
"(",
")",
";",
"$",
"group",
"->",
"setName",
"(",
"$",
"name",
")",
";",
"$",
"this",
"->",
"setParent",
"(",
"$",
"group",
",",
"$",
"request",
")",
";",
"$",
"roles",
"=",
"$",
"request",
"->",
"get",
"(",
"'roles'",
")",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"roles",
")",
")",
"{",
"foreach",
"(",
"$",
"roles",
"as",
"$",
"roleData",
")",
"{",
"$",
"this",
"->",
"addRole",
"(",
"$",
"group",
",",
"$",
"roleData",
")",
";",
"}",
"}",
"$",
"em",
"->",
"persist",
"(",
"$",
"group",
")",
";",
"$",
"em",
"->",
"flush",
"(",
")",
";",
"$",
"view",
"=",
"$",
"this",
"->",
"view",
"(",
"$",
"group",
",",
"200",
")",
";",
"}",
"else",
"{",
"$",
"view",
"=",
"$",
"this",
"->",
"view",
"(",
"null",
",",
"400",
")",
";",
"}",
"return",
"$",
"this",
"->",
"handleView",
"(",
"$",
"view",
")",
";",
"}"
] | Creates a new group with the given data.
@param \Symfony\Component\HttpFoundation\Request $request
@throws \Sulu\Component\Rest\Exception\EntityNotFoundException
@return \Symfony\Component\HttpFoundation\Response | [
"Creates",
"a",
"new",
"group",
"with",
"the",
"given",
"data",
"."
] | 6766a36cc2f0c807c59202bf7540a08c4ef31192 | https://github.com/sulu/sulu/blob/6766a36cc2f0c807c59202bf7540a08c4ef31192/src/Sulu/Bundle/SecurityBundle/Controller/GroupController.php#L130-L158 | train |
sulu/sulu | src/Sulu/Bundle/SecurityBundle/Controller/GroupController.php | GroupController.putAction | public function putAction(Request $request, $id)
{
/** @var Group $group */
$group = $this->getDoctrine()
->getRepository(static::$entityName)
->findGroupById($id);
try {
if (!$group) {
throw new EntityNotFoundException(static::$entityName, $id);
} else {
$em = $this->getDoctrine()->getManager();
$name = $request->get('name');
$group->setName($name);
$this->setParent($group, $request);
if (!$this->processRoles($group, $request->get('roles', []))) {
throw new RestException('Could not update dependencies!');
}
$em->flush();
$view = $this->view($group, 200);
}
} catch (EntityNotFoundException $enfe) {
$view = $this->view($enfe->toArray(), 404);
} catch (RestException $re) {
$view = $this->view($re->toArray(), 400);
}
return $this->handleView($view);
} | php | public function putAction(Request $request, $id)
{
/** @var Group $group */
$group = $this->getDoctrine()
->getRepository(static::$entityName)
->findGroupById($id);
try {
if (!$group) {
throw new EntityNotFoundException(static::$entityName, $id);
} else {
$em = $this->getDoctrine()->getManager();
$name = $request->get('name');
$group->setName($name);
$this->setParent($group, $request);
if (!$this->processRoles($group, $request->get('roles', []))) {
throw new RestException('Could not update dependencies!');
}
$em->flush();
$view = $this->view($group, 200);
}
} catch (EntityNotFoundException $enfe) {
$view = $this->view($enfe->toArray(), 404);
} catch (RestException $re) {
$view = $this->view($re->toArray(), 400);
}
return $this->handleView($view);
} | [
"public",
"function",
"putAction",
"(",
"Request",
"$",
"request",
",",
"$",
"id",
")",
"{",
"/** @var Group $group */",
"$",
"group",
"=",
"$",
"this",
"->",
"getDoctrine",
"(",
")",
"->",
"getRepository",
"(",
"static",
"::",
"$",
"entityName",
")",
"->",
"findGroupById",
"(",
"$",
"id",
")",
";",
"try",
"{",
"if",
"(",
"!",
"$",
"group",
")",
"{",
"throw",
"new",
"EntityNotFoundException",
"(",
"static",
"::",
"$",
"entityName",
",",
"$",
"id",
")",
";",
"}",
"else",
"{",
"$",
"em",
"=",
"$",
"this",
"->",
"getDoctrine",
"(",
")",
"->",
"getManager",
"(",
")",
";",
"$",
"name",
"=",
"$",
"request",
"->",
"get",
"(",
"'name'",
")",
";",
"$",
"group",
"->",
"setName",
"(",
"$",
"name",
")",
";",
"$",
"this",
"->",
"setParent",
"(",
"$",
"group",
",",
"$",
"request",
")",
";",
"if",
"(",
"!",
"$",
"this",
"->",
"processRoles",
"(",
"$",
"group",
",",
"$",
"request",
"->",
"get",
"(",
"'roles'",
",",
"[",
"]",
")",
")",
")",
"{",
"throw",
"new",
"RestException",
"(",
"'Could not update dependencies!'",
")",
";",
"}",
"$",
"em",
"->",
"flush",
"(",
")",
";",
"$",
"view",
"=",
"$",
"this",
"->",
"view",
"(",
"$",
"group",
",",
"200",
")",
";",
"}",
"}",
"catch",
"(",
"EntityNotFoundException",
"$",
"enfe",
")",
"{",
"$",
"view",
"=",
"$",
"this",
"->",
"view",
"(",
"$",
"enfe",
"->",
"toArray",
"(",
")",
",",
"404",
")",
";",
"}",
"catch",
"(",
"RestException",
"$",
"re",
")",
"{",
"$",
"view",
"=",
"$",
"this",
"->",
"view",
"(",
"$",
"re",
"->",
"toArray",
"(",
")",
",",
"400",
")",
";",
"}",
"return",
"$",
"this",
"->",
"handleView",
"(",
"$",
"view",
")",
";",
"}"
] | Updates the group with the given id and the data given by the request.
@param \Symfony\Component\HttpFoundation\Request $request
@param $id
@return \Symfony\Component\HttpFoundation\Response | [
"Updates",
"the",
"group",
"with",
"the",
"given",
"id",
"and",
"the",
"data",
"given",
"by",
"the",
"request",
"."
] | 6766a36cc2f0c807c59202bf7540a08c4ef31192 | https://github.com/sulu/sulu/blob/6766a36cc2f0c807c59202bf7540a08c4ef31192/src/Sulu/Bundle/SecurityBundle/Controller/GroupController.php#L168-L201 | train |
sulu/sulu | src/Sulu/Bundle/SecurityBundle/Controller/GroupController.php | GroupController.processRoles | protected function processRoles(Group $group, $roles)
{
/** @var RestHelperInterface $restHelper */
$restHelper = $this->get('sulu_core.doctrine_rest_helper');
$get = function($entity) {
/* @var RoleInterface $entity */
return $entity->getId();
};
$delete = function($role) {
$this->getDoctrine()->getManager()->remove($role);
};
$update = function($role, $roleData) {
return $this->updateRole($role, $roleData);
};
$add = function($role) use ($group) {
return $this->addRole($group, $role);
};
return $restHelper->processSubEntities($group->getRoles(), $roles, $get, $add, $update, $delete);
} | php | protected function processRoles(Group $group, $roles)
{
/** @var RestHelperInterface $restHelper */
$restHelper = $this->get('sulu_core.doctrine_rest_helper');
$get = function($entity) {
/* @var RoleInterface $entity */
return $entity->getId();
};
$delete = function($role) {
$this->getDoctrine()->getManager()->remove($role);
};
$update = function($role, $roleData) {
return $this->updateRole($role, $roleData);
};
$add = function($role) use ($group) {
return $this->addRole($group, $role);
};
return $restHelper->processSubEntities($group->getRoles(), $roles, $get, $add, $update, $delete);
} | [
"protected",
"function",
"processRoles",
"(",
"Group",
"$",
"group",
",",
"$",
"roles",
")",
"{",
"/** @var RestHelperInterface $restHelper */",
"$",
"restHelper",
"=",
"$",
"this",
"->",
"get",
"(",
"'sulu_core.doctrine_rest_helper'",
")",
";",
"$",
"get",
"=",
"function",
"(",
"$",
"entity",
")",
"{",
"/* @var RoleInterface $entity */",
"return",
"$",
"entity",
"->",
"getId",
"(",
")",
";",
"}",
";",
"$",
"delete",
"=",
"function",
"(",
"$",
"role",
")",
"{",
"$",
"this",
"->",
"getDoctrine",
"(",
")",
"->",
"getManager",
"(",
")",
"->",
"remove",
"(",
"$",
"role",
")",
";",
"}",
";",
"$",
"update",
"=",
"function",
"(",
"$",
"role",
",",
"$",
"roleData",
")",
"{",
"return",
"$",
"this",
"->",
"updateRole",
"(",
"$",
"role",
",",
"$",
"roleData",
")",
";",
"}",
";",
"$",
"add",
"=",
"function",
"(",
"$",
"role",
")",
"use",
"(",
"$",
"group",
")",
"{",
"return",
"$",
"this",
"->",
"addRole",
"(",
"$",
"group",
",",
"$",
"role",
")",
";",
"}",
";",
"return",
"$",
"restHelper",
"->",
"processSubEntities",
"(",
"$",
"group",
"->",
"getRoles",
"(",
")",
",",
"$",
"roles",
",",
"$",
"get",
",",
"$",
"add",
",",
"$",
"update",
",",
"$",
"delete",
")",
";",
"}"
] | Process all roles from request.
@param Group $group The contact on which is worked
@param array $roles The roles to process
@return bool True if the processing was successful, otherwise false | [
"Process",
"all",
"roles",
"from",
"request",
"."
] | 6766a36cc2f0c807c59202bf7540a08c4ef31192 | https://github.com/sulu/sulu/blob/6766a36cc2f0c807c59202bf7540a08c4ef31192/src/Sulu/Bundle/SecurityBundle/Controller/GroupController.php#L211-L234 | train |
sulu/sulu | src/Sulu/Bundle/SecurityBundle/Controller/GroupController.php | GroupController.deleteAction | public function deleteAction($id)
{
$delete = function($id) {
$group = $this->getDoctrine()
->getRepository(static::$entityName)
->findGroupById($id);
if (!$group) {
throw new EntityNotFoundException(static::$entityName, $id);
}
$em = $this->getDoctrine()->getManager();
$em->remove($group);
$em->flush();
};
$view = $this->responseDelete($id, $delete);
return $this->handleView($view);
} | php | public function deleteAction($id)
{
$delete = function($id) {
$group = $this->getDoctrine()
->getRepository(static::$entityName)
->findGroupById($id);
if (!$group) {
throw new EntityNotFoundException(static::$entityName, $id);
}
$em = $this->getDoctrine()->getManager();
$em->remove($group);
$em->flush();
};
$view = $this->responseDelete($id, $delete);
return $this->handleView($view);
} | [
"public",
"function",
"deleteAction",
"(",
"$",
"id",
")",
"{",
"$",
"delete",
"=",
"function",
"(",
"$",
"id",
")",
"{",
"$",
"group",
"=",
"$",
"this",
"->",
"getDoctrine",
"(",
")",
"->",
"getRepository",
"(",
"static",
"::",
"$",
"entityName",
")",
"->",
"findGroupById",
"(",
"$",
"id",
")",
";",
"if",
"(",
"!",
"$",
"group",
")",
"{",
"throw",
"new",
"EntityNotFoundException",
"(",
"static",
"::",
"$",
"entityName",
",",
"$",
"id",
")",
";",
"}",
"$",
"em",
"=",
"$",
"this",
"->",
"getDoctrine",
"(",
")",
"->",
"getManager",
"(",
")",
";",
"$",
"em",
"->",
"remove",
"(",
"$",
"group",
")",
";",
"$",
"em",
"->",
"flush",
"(",
")",
";",
"}",
";",
"$",
"view",
"=",
"$",
"this",
"->",
"responseDelete",
"(",
"$",
"id",
",",
"$",
"delete",
")",
";",
"return",
"$",
"this",
"->",
"handleView",
"(",
"$",
"view",
")",
";",
"}"
] | Deletes the group with the given id.
@param $id
@return \Symfony\Component\HttpFoundation\Response | [
"Deletes",
"the",
"group",
"with",
"the",
"given",
"id",
"."
] | 6766a36cc2f0c807c59202bf7540a08c4ef31192 | https://github.com/sulu/sulu/blob/6766a36cc2f0c807c59202bf7540a08c4ef31192/src/Sulu/Bundle/SecurityBundle/Controller/GroupController.php#L243-L262 | train |
sulu/sulu | src/Sulu/Bundle/SecurityBundle/Controller/GroupController.php | GroupController.addRole | private function addRole(Group $group, $roleData)
{
if (isset($roleData['id'])) {
$role = $this->get('sulu.repository.role')->findRoleById($roleData['id']);
if (!$role) {
throw new EntityNotFoundException($this->get('sulu.repository.role')->getClassName(), $roleData['id']);
}
if (!$group->getRoles()->contains($role)) {
$group->addRole($role);
}
}
return true;
} | php | private function addRole(Group $group, $roleData)
{
if (isset($roleData['id'])) {
$role = $this->get('sulu.repository.role')->findRoleById($roleData['id']);
if (!$role) {
throw new EntityNotFoundException($this->get('sulu.repository.role')->getClassName(), $roleData['id']);
}
if (!$group->getRoles()->contains($role)) {
$group->addRole($role);
}
}
return true;
} | [
"private",
"function",
"addRole",
"(",
"Group",
"$",
"group",
",",
"$",
"roleData",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"roleData",
"[",
"'id'",
"]",
")",
")",
"{",
"$",
"role",
"=",
"$",
"this",
"->",
"get",
"(",
"'sulu.repository.role'",
")",
"->",
"findRoleById",
"(",
"$",
"roleData",
"[",
"'id'",
"]",
")",
";",
"if",
"(",
"!",
"$",
"role",
")",
"{",
"throw",
"new",
"EntityNotFoundException",
"(",
"$",
"this",
"->",
"get",
"(",
"'sulu.repository.role'",
")",
"->",
"getClassName",
"(",
")",
",",
"$",
"roleData",
"[",
"'id'",
"]",
")",
";",
"}",
"if",
"(",
"!",
"$",
"group",
"->",
"getRoles",
"(",
")",
"->",
"contains",
"(",
"$",
"role",
")",
")",
"{",
"$",
"group",
"->",
"addRole",
"(",
"$",
"role",
")",
";",
"}",
"}",
"return",
"true",
";",
"}"
] | Adds the given role to the group.
@param Group $group
@param array $roleData
@return bool
@throws \Sulu\Component\Rest\Exception\EntityNotFoundException | [
"Adds",
"the",
"given",
"role",
"to",
"the",
"group",
"."
] | 6766a36cc2f0c807c59202bf7540a08c4ef31192 | https://github.com/sulu/sulu/blob/6766a36cc2f0c807c59202bf7540a08c4ef31192/src/Sulu/Bundle/SecurityBundle/Controller/GroupController.php#L274-L289 | train |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.