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/Bundle/TagBundle/Tag/TagManager.php | TagManager.delete | public function delete($id)
{
$tag = $this->tagRepository->findTagById($id);
if (!$tag) {
throw new TagNotFoundException($id);
}
$this->em->remove($tag);
$this->em->flush();
// throw an tag.delete event
$event = new TagDeleteEvent($tag);
$this->eventDispatcher->dispatch(TagEvents::TAG_DELETE, $event);
} | php | public function delete($id)
{
$tag = $this->tagRepository->findTagById($id);
if (!$tag) {
throw new TagNotFoundException($id);
}
$this->em->remove($tag);
$this->em->flush();
// throw an tag.delete event
$event = new TagDeleteEvent($tag);
$this->eventDispatcher->dispatch(TagEvents::TAG_DELETE, $event);
} | [
"public",
"function",
"delete",
"(",
"$",
"id",
")",
"{",
"$",
"tag",
"=",
"$",
"this",
"->",
"tagRepository",
"->",
"findTagById",
"(",
"$",
"id",
")",
";",
"if",
"(",
"!",
"$",
"tag",
")",
"{",
"throw",
"new",
"TagNotFoundException",
"(",
"$",
"id",
")",
";",
"}",
"$",
"this",
"->",
"em",
"->",
"remove",
"(",
"$",
"tag",
")",
";",
"$",
"this",
"->",
"em",
"->",
"flush",
"(",
")",
";",
"// throw an tag.delete event",
"$",
"event",
"=",
"new",
"TagDeleteEvent",
"(",
"$",
"tag",
")",
";",
"$",
"this",
"->",
"eventDispatcher",
"->",
"dispatch",
"(",
"TagEvents",
"::",
"TAG_DELETE",
",",
"$",
"event",
")",
";",
"}"
] | Deletes the given Tag.
@param number $id The tag to delete
@throws Exception\TagNotFoundException | [
"Deletes",
"the",
"given",
"Tag",
"."
] | 6766a36cc2f0c807c59202bf7540a08c4ef31192 | https://github.com/sulu/sulu/blob/6766a36cc2f0c807c59202bf7540a08c4ef31192/src/Sulu/Bundle/TagBundle/Tag/TagManager.php#L144-L158 | train |
sulu/sulu | src/Sulu/Bundle/TagBundle/Tag/TagManager.php | TagManager.merge | public function merge($srcTagIds, $destTagId)
{
$srcTags = [];
$destTag = $this->tagRepository->findTagById($destTagId);
if (!$destTag) {
throw new TagNotFoundException($destTagId);
}
foreach ($srcTagIds as $srcTagId) {
$srcTag = $this->tagRepository->findTagById($srcTagId);
if (!$srcTag) {
throw new TagNotFoundException($srcTagId);
}
$this->em->remove($srcTag);
$srcTags[] = $srcTag;
}
$this->em->flush();
// throw an tag.merge event
$event = new TagMergeEvent($srcTags, $destTag);
$this->eventDispatcher->dispatch(TagEvents::TAG_MERGE, $event);
return $destTag;
} | php | public function merge($srcTagIds, $destTagId)
{
$srcTags = [];
$destTag = $this->tagRepository->findTagById($destTagId);
if (!$destTag) {
throw new TagNotFoundException($destTagId);
}
foreach ($srcTagIds as $srcTagId) {
$srcTag = $this->tagRepository->findTagById($srcTagId);
if (!$srcTag) {
throw new TagNotFoundException($srcTagId);
}
$this->em->remove($srcTag);
$srcTags[] = $srcTag;
}
$this->em->flush();
// throw an tag.merge event
$event = new TagMergeEvent($srcTags, $destTag);
$this->eventDispatcher->dispatch(TagEvents::TAG_MERGE, $event);
return $destTag;
} | [
"public",
"function",
"merge",
"(",
"$",
"srcTagIds",
",",
"$",
"destTagId",
")",
"{",
"$",
"srcTags",
"=",
"[",
"]",
";",
"$",
"destTag",
"=",
"$",
"this",
"->",
"tagRepository",
"->",
"findTagById",
"(",
"$",
"destTagId",
")",
";",
"if",
"(",
"!",
"$",
"destTag",
")",
"{",
"throw",
"new",
"TagNotFoundException",
"(",
"$",
"destTagId",
")",
";",
"}",
"foreach",
"(",
"$",
"srcTagIds",
"as",
"$",
"srcTagId",
")",
"{",
"$",
"srcTag",
"=",
"$",
"this",
"->",
"tagRepository",
"->",
"findTagById",
"(",
"$",
"srcTagId",
")",
";",
"if",
"(",
"!",
"$",
"srcTag",
")",
"{",
"throw",
"new",
"TagNotFoundException",
"(",
"$",
"srcTagId",
")",
";",
"}",
"$",
"this",
"->",
"em",
"->",
"remove",
"(",
"$",
"srcTag",
")",
";",
"$",
"srcTags",
"[",
"]",
"=",
"$",
"srcTag",
";",
"}",
"$",
"this",
"->",
"em",
"->",
"flush",
"(",
")",
";",
"// throw an tag.merge event",
"$",
"event",
"=",
"new",
"TagMergeEvent",
"(",
"$",
"srcTags",
",",
"$",
"destTag",
")",
";",
"$",
"this",
"->",
"eventDispatcher",
"->",
"dispatch",
"(",
"TagEvents",
"::",
"TAG_MERGE",
",",
"$",
"event",
")",
";",
"return",
"$",
"destTag",
";",
"}"
] | Merges the source tag into the destination tag.
The source tag will be deleted.
@param number $srcTagIds The source tags, which will be removed afterwards
@param number $destTagId The destination tag, which will replace the source tag
@throws Exception\TagNotFoundException
@return TagInterface The new Tag, which is valid for all given tags | [
"Merges",
"the",
"source",
"tag",
"into",
"the",
"destination",
"tag",
".",
"The",
"source",
"tag",
"will",
"be",
"deleted",
"."
] | 6766a36cc2f0c807c59202bf7540a08c4ef31192 | https://github.com/sulu/sulu/blob/6766a36cc2f0c807c59202bf7540a08c4ef31192/src/Sulu/Bundle/TagBundle/Tag/TagManager.php#L171-L199 | train |
sulu/sulu | src/Sulu/Bundle/TagBundle/Tag/TagManager.php | TagManager.resolveTagIds | public function resolveTagIds($tagIds)
{
$resolvedTags = [];
foreach ($tagIds as $tagId) {
$tag = $this->findById($tagId);
if (null !== $tag) {
$resolvedTags[] = $tag->getName();
}
}
return $resolvedTags;
} | php | public function resolveTagIds($tagIds)
{
$resolvedTags = [];
foreach ($tagIds as $tagId) {
$tag = $this->findById($tagId);
if (null !== $tag) {
$resolvedTags[] = $tag->getName();
}
}
return $resolvedTags;
} | [
"public",
"function",
"resolveTagIds",
"(",
"$",
"tagIds",
")",
"{",
"$",
"resolvedTags",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"tagIds",
"as",
"$",
"tagId",
")",
"{",
"$",
"tag",
"=",
"$",
"this",
"->",
"findById",
"(",
"$",
"tagId",
")",
";",
"if",
"(",
"null",
"!==",
"$",
"tag",
")",
"{",
"$",
"resolvedTags",
"[",
"]",
"=",
"$",
"tag",
"->",
"getName",
"(",
")",
";",
"}",
"}",
"return",
"$",
"resolvedTags",
";",
"}"
] | Resolves tag ids to names.
@param $tagIds
@return array | [
"Resolves",
"tag",
"ids",
"to",
"names",
"."
] | 6766a36cc2f0c807c59202bf7540a08c4ef31192 | https://github.com/sulu/sulu/blob/6766a36cc2f0c807c59202bf7540a08c4ef31192/src/Sulu/Bundle/TagBundle/Tag/TagManager.php#L208-L220 | train |
sulu/sulu | src/Sulu/Bundle/TagBundle/Tag/TagManager.php | TagManager.resolveTagNames | public function resolveTagNames($tagNames)
{
$resolvedTags = [];
foreach ($tagNames as $tagName) {
$tag = $this->findByName($tagName);
if (null !== $tag) {
$resolvedTags[] = $tag->getId();
}
}
return $resolvedTags;
} | php | public function resolveTagNames($tagNames)
{
$resolvedTags = [];
foreach ($tagNames as $tagName) {
$tag = $this->findByName($tagName);
if (null !== $tag) {
$resolvedTags[] = $tag->getId();
}
}
return $resolvedTags;
} | [
"public",
"function",
"resolveTagNames",
"(",
"$",
"tagNames",
")",
"{",
"$",
"resolvedTags",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"tagNames",
"as",
"$",
"tagName",
")",
"{",
"$",
"tag",
"=",
"$",
"this",
"->",
"findByName",
"(",
"$",
"tagName",
")",
";",
"if",
"(",
"null",
"!==",
"$",
"tag",
")",
"{",
"$",
"resolvedTags",
"[",
"]",
"=",
"$",
"tag",
"->",
"getId",
"(",
")",
";",
"}",
"}",
"return",
"$",
"resolvedTags",
";",
"}"
] | Resolves tag names to ids.
@param $tagNames
@return array | [
"Resolves",
"tag",
"names",
"to",
"ids",
"."
] | 6766a36cc2f0c807c59202bf7540a08c4ef31192 | https://github.com/sulu/sulu/blob/6766a36cc2f0c807c59202bf7540a08c4ef31192/src/Sulu/Bundle/TagBundle/Tag/TagManager.php#L229-L241 | train |
sulu/sulu | src/Sulu/Bundle/CoreBundle/Entity/ApiEntity.php | ApiEntity.createSelfLink | public function createSelfLink()
{
// if no apiPath is not set generate it from basepath
if (is_null($this->getApiPath())) {
$class = explode('\\', get_class($this));
$plural = Inflector::pluralize(strtolower(end($class)));
$this->apiPath = $this->apiBasePath . '/' . $plural;
}
// add id to path
$idPath = '';
if ($this->getId()) {
$idPath = '/' . $this->getId();
}
$this->_links = [
'self' => $this->getApiPath() . $idPath,
];
} | php | public function createSelfLink()
{
// if no apiPath is not set generate it from basepath
if (is_null($this->getApiPath())) {
$class = explode('\\', get_class($this));
$plural = Inflector::pluralize(strtolower(end($class)));
$this->apiPath = $this->apiBasePath . '/' . $plural;
}
// add id to path
$idPath = '';
if ($this->getId()) {
$idPath = '/' . $this->getId();
}
$this->_links = [
'self' => $this->getApiPath() . $idPath,
];
} | [
"public",
"function",
"createSelfLink",
"(",
")",
"{",
"// if no apiPath is not set generate it from basepath",
"if",
"(",
"is_null",
"(",
"$",
"this",
"->",
"getApiPath",
"(",
")",
")",
")",
"{",
"$",
"class",
"=",
"explode",
"(",
"'\\\\'",
",",
"get_class",
"(",
"$",
"this",
")",
")",
";",
"$",
"plural",
"=",
"Inflector",
"::",
"pluralize",
"(",
"strtolower",
"(",
"end",
"(",
"$",
"class",
")",
")",
")",
";",
"$",
"this",
"->",
"apiPath",
"=",
"$",
"this",
"->",
"apiBasePath",
".",
"'/'",
".",
"$",
"plural",
";",
"}",
"// add id to path",
"$",
"idPath",
"=",
"''",
";",
"if",
"(",
"$",
"this",
"->",
"getId",
"(",
")",
")",
"{",
"$",
"idPath",
"=",
"'/'",
".",
"$",
"this",
"->",
"getId",
"(",
")",
";",
"}",
"$",
"this",
"->",
"_links",
"=",
"[",
"'self'",
"=>",
"$",
"this",
"->",
"getApiPath",
"(",
")",
".",
"$",
"idPath",
",",
"]",
";",
"}"
] | creates the _links array including the self path. | [
"creates",
"the",
"_links",
"array",
"including",
"the",
"self",
"path",
"."
] | 6766a36cc2f0c807c59202bf7540a08c4ef31192 | https://github.com/sulu/sulu/blob/6766a36cc2f0c807c59202bf7540a08c4ef31192/src/Sulu/Bundle/CoreBundle/Entity/ApiEntity.php#L81-L98 | train |
sulu/sulu | src/Sulu/Component/Content/Compat/Block/BlockPropertyType.php | BlockPropertyType.getProperty | public function getProperty($name)
{
foreach ($this->getChildProperties() as $property) {
if ($property->getName() === $name) {
return $property;
}
}
return;
} | php | public function getProperty($name)
{
foreach ($this->getChildProperties() as $property) {
if ($property->getName() === $name) {
return $property;
}
}
return;
} | [
"public",
"function",
"getProperty",
"(",
"$",
"name",
")",
"{",
"foreach",
"(",
"$",
"this",
"->",
"getChildProperties",
"(",
")",
"as",
"$",
"property",
")",
"{",
"if",
"(",
"$",
"property",
"->",
"getName",
"(",
")",
"===",
"$",
"name",
")",
"{",
"return",
"$",
"property",
";",
"}",
"}",
"return",
";",
"}"
] | returns child property with given name.
@param string $name
@return null|PropertyInterface | [
"returns",
"child",
"property",
"with",
"given",
"name",
"."
] | 6766a36cc2f0c807c59202bf7540a08c4ef31192 | https://github.com/sulu/sulu/blob/6766a36cc2f0c807c59202bf7540a08c4ef31192/src/Sulu/Component/Content/Compat/Block/BlockPropertyType.php#L67-L76 | train |
sulu/sulu | src/Sulu/Component/Content/Compat/Block/BlockPropertyType.php | BlockPropertyType.getChild | public function getChild($name)
{
foreach ($this->childProperties as $child) {
if ($child->getName() === $name) {
return $child;
}
}
throw new NoSuchPropertyException();
} | php | public function getChild($name)
{
foreach ($this->childProperties as $child) {
if ($child->getName() === $name) {
return $child;
}
}
throw new NoSuchPropertyException();
} | [
"public",
"function",
"getChild",
"(",
"$",
"name",
")",
"{",
"foreach",
"(",
"$",
"this",
"->",
"childProperties",
"as",
"$",
"child",
")",
"{",
"if",
"(",
"$",
"child",
"->",
"getName",
"(",
")",
"===",
"$",
"name",
")",
"{",
"return",
"$",
"child",
";",
"}",
"}",
"throw",
"new",
"NoSuchPropertyException",
"(",
")",
";",
"}"
] | returns property with given name.
@param string $name of property
@throws NoSuchPropertyException
@return PropertyInterface | [
"returns",
"property",
"with",
"given",
"name",
"."
] | 6766a36cc2f0c807c59202bf7540a08c4ef31192 | https://github.com/sulu/sulu/blob/6766a36cc2f0c807c59202bf7540a08c4ef31192/src/Sulu/Component/Content/Compat/Block/BlockPropertyType.php#L95-L104 | train |
sulu/sulu | src/Sulu/Bundle/AudienceTargetingBundle/Rule/ReferrerRule.php | ReferrerRule.evaluate | public function evaluate(array $options)
{
$request = $this->requestStack->getCurrentRequest();
$referrer = $request->headers->get('referer');
if ($this->referrerHeader && $request->headers->has($this->referrerHeader)) {
$referrer = $request->headers->get($this->referrerHeader);
}
return (bool) preg_match(
'/^' . str_replace(['*', '/'], ['(.*)', '\/'], $options[static::REFERRER]) . '$/',
$referrer
);
} | php | public function evaluate(array $options)
{
$request = $this->requestStack->getCurrentRequest();
$referrer = $request->headers->get('referer');
if ($this->referrerHeader && $request->headers->has($this->referrerHeader)) {
$referrer = $request->headers->get($this->referrerHeader);
}
return (bool) preg_match(
'/^' . str_replace(['*', '/'], ['(.*)', '\/'], $options[static::REFERRER]) . '$/',
$referrer
);
} | [
"public",
"function",
"evaluate",
"(",
"array",
"$",
"options",
")",
"{",
"$",
"request",
"=",
"$",
"this",
"->",
"requestStack",
"->",
"getCurrentRequest",
"(",
")",
";",
"$",
"referrer",
"=",
"$",
"request",
"->",
"headers",
"->",
"get",
"(",
"'referer'",
")",
";",
"if",
"(",
"$",
"this",
"->",
"referrerHeader",
"&&",
"$",
"request",
"->",
"headers",
"->",
"has",
"(",
"$",
"this",
"->",
"referrerHeader",
")",
")",
"{",
"$",
"referrer",
"=",
"$",
"request",
"->",
"headers",
"->",
"get",
"(",
"$",
"this",
"->",
"referrerHeader",
")",
";",
"}",
"return",
"(",
"bool",
")",
"preg_match",
"(",
"'/^'",
".",
"str_replace",
"(",
"[",
"'*'",
",",
"'/'",
"]",
",",
"[",
"'(.*)'",
",",
"'\\/'",
"]",
",",
"$",
"options",
"[",
"static",
"::",
"REFERRER",
"]",
")",
".",
"'$/'",
",",
"$",
"referrer",
")",
";",
"}"
] | Returns a string representation of the evaluation of the rule for the current context.
@param array $options The options to evaluate against
@return bool | [
"Returns",
"a",
"string",
"representation",
"of",
"the",
"evaluation",
"of",
"the",
"rule",
"for",
"the",
"current",
"context",
"."
] | 6766a36cc2f0c807c59202bf7540a08c4ef31192 | https://github.com/sulu/sulu/blob/6766a36cc2f0c807c59202bf7540a08c4ef31192/src/Sulu/Bundle/AudienceTargetingBundle/Rule/ReferrerRule.php#L51-L63 | train |
sulu/sulu | src/Sulu/Bundle/MediaBundle/DependencyInjection/AbstractImageFormatCompilerPass.php | AbstractImageFormatCompilerPass.loadFormatsFromFile | private function loadFormatsFromFile($path, array &$formats)
{
$folder = dirname($path);
$file = basename($path);
$locator = new FileLocator($folder);
$xmlLoader10 = new XmlFormatLoader10($locator);
$xmlLoader11 = new XmlFormatLoader11($locator);
$xmlLoader10->setGlobalOptions($this->globalOptions);
$xmlLoader11->setGlobalOptions($this->globalOptions);
$resolver = new LoaderResolver([$xmlLoader10, $xmlLoader11]);
$loader = new DelegatingLoader($resolver);
$fileFormats = $loader->load($file);
foreach ($fileFormats as $format) {
if (array_key_exists($format['key'], $formats) && $formats[$format['key']] !== $format) {
throw new InvalidArgumentException(
sprintf('Media format with key "%s" already exists!', $format['key'])
);
}
$formats[$format['key']] = $format;
}
} | php | private function loadFormatsFromFile($path, array &$formats)
{
$folder = dirname($path);
$file = basename($path);
$locator = new FileLocator($folder);
$xmlLoader10 = new XmlFormatLoader10($locator);
$xmlLoader11 = new XmlFormatLoader11($locator);
$xmlLoader10->setGlobalOptions($this->globalOptions);
$xmlLoader11->setGlobalOptions($this->globalOptions);
$resolver = new LoaderResolver([$xmlLoader10, $xmlLoader11]);
$loader = new DelegatingLoader($resolver);
$fileFormats = $loader->load($file);
foreach ($fileFormats as $format) {
if (array_key_exists($format['key'], $formats) && $formats[$format['key']] !== $format) {
throw new InvalidArgumentException(
sprintf('Media format with key "%s" already exists!', $format['key'])
);
}
$formats[$format['key']] = $format;
}
} | [
"private",
"function",
"loadFormatsFromFile",
"(",
"$",
"path",
",",
"array",
"&",
"$",
"formats",
")",
"{",
"$",
"folder",
"=",
"dirname",
"(",
"$",
"path",
")",
";",
"$",
"file",
"=",
"basename",
"(",
"$",
"path",
")",
";",
"$",
"locator",
"=",
"new",
"FileLocator",
"(",
"$",
"folder",
")",
";",
"$",
"xmlLoader10",
"=",
"new",
"XmlFormatLoader10",
"(",
"$",
"locator",
")",
";",
"$",
"xmlLoader11",
"=",
"new",
"XmlFormatLoader11",
"(",
"$",
"locator",
")",
";",
"$",
"xmlLoader10",
"->",
"setGlobalOptions",
"(",
"$",
"this",
"->",
"globalOptions",
")",
";",
"$",
"xmlLoader11",
"->",
"setGlobalOptions",
"(",
"$",
"this",
"->",
"globalOptions",
")",
";",
"$",
"resolver",
"=",
"new",
"LoaderResolver",
"(",
"[",
"$",
"xmlLoader10",
",",
"$",
"xmlLoader11",
"]",
")",
";",
"$",
"loader",
"=",
"new",
"DelegatingLoader",
"(",
"$",
"resolver",
")",
";",
"$",
"fileFormats",
"=",
"$",
"loader",
"->",
"load",
"(",
"$",
"file",
")",
";",
"foreach",
"(",
"$",
"fileFormats",
"as",
"$",
"format",
")",
"{",
"if",
"(",
"array_key_exists",
"(",
"$",
"format",
"[",
"'key'",
"]",
",",
"$",
"formats",
")",
"&&",
"$",
"formats",
"[",
"$",
"format",
"[",
"'key'",
"]",
"]",
"!==",
"$",
"format",
")",
"{",
"throw",
"new",
"InvalidArgumentException",
"(",
"sprintf",
"(",
"'Media format with key \"%s\" already exists!'",
",",
"$",
"format",
"[",
"'key'",
"]",
")",
")",
";",
"}",
"$",
"formats",
"[",
"$",
"format",
"[",
"'key'",
"]",
"]",
"=",
"$",
"format",
";",
"}",
"}"
] | Adds the image formats from the file at the given path to the given array.
@param string $path
@param array $formats | [
"Adds",
"the",
"image",
"formats",
"from",
"the",
"file",
"at",
"the",
"given",
"path",
"to",
"the",
"given",
"array",
"."
] | 6766a36cc2f0c807c59202bf7540a08c4ef31192 | https://github.com/sulu/sulu/blob/6766a36cc2f0c807c59202bf7540a08c4ef31192/src/Sulu/Bundle/MediaBundle/DependencyInjection/AbstractImageFormatCompilerPass.php#L71-L96 | train |
sulu/sulu | src/Sulu/Bundle/CustomUrlBundle/Controller/CustomUrlController.php | CustomUrlController.cgetAction | public function cgetAction($webspace, Request $request)
{
// TODO pagination
$result = $this->get('sulu_custom_urls.manager')->findList($webspace);
$list = new RouteAwareRepresentation(
new CollectionRepresentation($result, self::$relationName),
'cget_webspace_custom-urls',
array_merge($request->request->all(), ['webspace' => $webspace])
);
return $this->handleView($this->view($list));
} | php | public function cgetAction($webspace, Request $request)
{
// TODO pagination
$result = $this->get('sulu_custom_urls.manager')->findList($webspace);
$list = new RouteAwareRepresentation(
new CollectionRepresentation($result, self::$relationName),
'cget_webspace_custom-urls',
array_merge($request->request->all(), ['webspace' => $webspace])
);
return $this->handleView($this->view($list));
} | [
"public",
"function",
"cgetAction",
"(",
"$",
"webspace",
",",
"Request",
"$",
"request",
")",
"{",
"// TODO pagination",
"$",
"result",
"=",
"$",
"this",
"->",
"get",
"(",
"'sulu_custom_urls.manager'",
")",
"->",
"findList",
"(",
"$",
"webspace",
")",
";",
"$",
"list",
"=",
"new",
"RouteAwareRepresentation",
"(",
"new",
"CollectionRepresentation",
"(",
"$",
"result",
",",
"self",
"::",
"$",
"relationName",
")",
",",
"'cget_webspace_custom-urls'",
",",
"array_merge",
"(",
"$",
"request",
"->",
"request",
"->",
"all",
"(",
")",
",",
"[",
"'webspace'",
"=>",
"$",
"webspace",
"]",
")",
")",
";",
"return",
"$",
"this",
"->",
"handleView",
"(",
"$",
"this",
"->",
"view",
"(",
"$",
"list",
")",
")",
";",
"}"
] | Returns a list of custom-urls.
@param string $webspace
@param Request $request
@return Response | [
"Returns",
"a",
"list",
"of",
"custom",
"-",
"urls",
"."
] | 6766a36cc2f0c807c59202bf7540a08c4ef31192 | https://github.com/sulu/sulu/blob/6766a36cc2f0c807c59202bf7540a08c4ef31192/src/Sulu/Bundle/CustomUrlBundle/Controller/CustomUrlController.php#L44-L57 | train |
sulu/sulu | src/Sulu/Bundle/CustomUrlBundle/Controller/CustomUrlController.php | CustomUrlController.getAction | public function getAction($webspace, $id, Request $request)
{
$document = $this->get('sulu_custom_urls.manager')->find($id);
// FIXME without this target-document will not be loaded (for serialization)
// - issue https://github.com/sulu-io/sulu-document-manager/issues/71
if (null !== $document->getTargetDocument()) {
$document->getTargetDocument()->getTitle();
}
$view = $this->view($document);
$context = new Context();
$context->setGroups(['defaultCustomUrl', 'fullRoute']);
$view->setContext($context);
return $this->handleView($view);
} | php | public function getAction($webspace, $id, Request $request)
{
$document = $this->get('sulu_custom_urls.manager')->find($id);
// FIXME without this target-document will not be loaded (for serialization)
// - issue https://github.com/sulu-io/sulu-document-manager/issues/71
if (null !== $document->getTargetDocument()) {
$document->getTargetDocument()->getTitle();
}
$view = $this->view($document);
$context = new Context();
$context->setGroups(['defaultCustomUrl', 'fullRoute']);
$view->setContext($context);
return $this->handleView($view);
} | [
"public",
"function",
"getAction",
"(",
"$",
"webspace",
",",
"$",
"id",
",",
"Request",
"$",
"request",
")",
"{",
"$",
"document",
"=",
"$",
"this",
"->",
"get",
"(",
"'sulu_custom_urls.manager'",
")",
"->",
"find",
"(",
"$",
"id",
")",
";",
"// FIXME without this target-document will not be loaded (for serialization)",
"// - issue https://github.com/sulu-io/sulu-document-manager/issues/71",
"if",
"(",
"null",
"!==",
"$",
"document",
"->",
"getTargetDocument",
"(",
")",
")",
"{",
"$",
"document",
"->",
"getTargetDocument",
"(",
")",
"->",
"getTitle",
"(",
")",
";",
"}",
"$",
"view",
"=",
"$",
"this",
"->",
"view",
"(",
"$",
"document",
")",
";",
"$",
"context",
"=",
"new",
"Context",
"(",
")",
";",
"$",
"context",
"->",
"setGroups",
"(",
"[",
"'defaultCustomUrl'",
",",
"'fullRoute'",
"]",
")",
";",
"$",
"view",
"->",
"setContext",
"(",
"$",
"context",
")",
";",
"return",
"$",
"this",
"->",
"handleView",
"(",
"$",
"view",
")",
";",
"}"
] | Returns a single custom-url identified by uuid.
@param string $webspace
@param string $id
@param Request $request
@return Response | [
"Returns",
"a",
"single",
"custom",
"-",
"url",
"identified",
"by",
"uuid",
"."
] | 6766a36cc2f0c807c59202bf7540a08c4ef31192 | https://github.com/sulu/sulu/blob/6766a36cc2f0c807c59202bf7540a08c4ef31192/src/Sulu/Bundle/CustomUrlBundle/Controller/CustomUrlController.php#L68-L85 | train |
sulu/sulu | src/Sulu/Bundle/CustomUrlBundle/Controller/CustomUrlController.php | CustomUrlController.postAction | public function postAction($webspace, Request $request)
{
$document = $this->get('sulu_custom_urls.manager')->create(
$webspace,
$request->request->all(),
$this->getRequestParameter($request, 'targetLocale', true)
);
$this->get('sulu_document_manager.document_manager')->flush();
$context = new Context();
$context->setGroups(['defaultCustomUrl', 'fullRoute']);
return $this->handleView($this->view($document)->setContext($context));
} | php | public function postAction($webspace, Request $request)
{
$document = $this->get('sulu_custom_urls.manager')->create(
$webspace,
$request->request->all(),
$this->getRequestParameter($request, 'targetLocale', true)
);
$this->get('sulu_document_manager.document_manager')->flush();
$context = new Context();
$context->setGroups(['defaultCustomUrl', 'fullRoute']);
return $this->handleView($this->view($document)->setContext($context));
} | [
"public",
"function",
"postAction",
"(",
"$",
"webspace",
",",
"Request",
"$",
"request",
")",
"{",
"$",
"document",
"=",
"$",
"this",
"->",
"get",
"(",
"'sulu_custom_urls.manager'",
")",
"->",
"create",
"(",
"$",
"webspace",
",",
"$",
"request",
"->",
"request",
"->",
"all",
"(",
")",
",",
"$",
"this",
"->",
"getRequestParameter",
"(",
"$",
"request",
",",
"'targetLocale'",
",",
"true",
")",
")",
";",
"$",
"this",
"->",
"get",
"(",
"'sulu_document_manager.document_manager'",
")",
"->",
"flush",
"(",
")",
";",
"$",
"context",
"=",
"new",
"Context",
"(",
")",
";",
"$",
"context",
"->",
"setGroups",
"(",
"[",
"'defaultCustomUrl'",
",",
"'fullRoute'",
"]",
")",
";",
"return",
"$",
"this",
"->",
"handleView",
"(",
"$",
"this",
"->",
"view",
"(",
"$",
"document",
")",
"->",
"setContext",
"(",
"$",
"context",
")",
")",
";",
"}"
] | Create a new custom-url object.
@param string $webspace
@param Request $request
@return Response | [
"Create",
"a",
"new",
"custom",
"-",
"url",
"object",
"."
] | 6766a36cc2f0c807c59202bf7540a08c4ef31192 | https://github.com/sulu/sulu/blob/6766a36cc2f0c807c59202bf7540a08c4ef31192/src/Sulu/Bundle/CustomUrlBundle/Controller/CustomUrlController.php#L95-L108 | train |
sulu/sulu | src/Sulu/Bundle/CustomUrlBundle/Controller/CustomUrlController.php | CustomUrlController.putAction | public function putAction($webspace, $id, Request $request)
{
$manager = $this->get('sulu_custom_urls.manager');
$document = $manager->save($id, $request->request->all());
$this->get('sulu_document_manager.document_manager')->flush();
$context = new Context();
$context->setGroups(['defaultCustomUrl', 'fullRoute']);
return $this->handleView($this->view($document)->setContext($context));
} | php | public function putAction($webspace, $id, Request $request)
{
$manager = $this->get('sulu_custom_urls.manager');
$document = $manager->save($id, $request->request->all());
$this->get('sulu_document_manager.document_manager')->flush();
$context = new Context();
$context->setGroups(['defaultCustomUrl', 'fullRoute']);
return $this->handleView($this->view($document)->setContext($context));
} | [
"public",
"function",
"putAction",
"(",
"$",
"webspace",
",",
"$",
"id",
",",
"Request",
"$",
"request",
")",
"{",
"$",
"manager",
"=",
"$",
"this",
"->",
"get",
"(",
"'sulu_custom_urls.manager'",
")",
";",
"$",
"document",
"=",
"$",
"manager",
"->",
"save",
"(",
"$",
"id",
",",
"$",
"request",
"->",
"request",
"->",
"all",
"(",
")",
")",
";",
"$",
"this",
"->",
"get",
"(",
"'sulu_document_manager.document_manager'",
")",
"->",
"flush",
"(",
")",
";",
"$",
"context",
"=",
"new",
"Context",
"(",
")",
";",
"$",
"context",
"->",
"setGroups",
"(",
"[",
"'defaultCustomUrl'",
",",
"'fullRoute'",
"]",
")",
";",
"return",
"$",
"this",
"->",
"handleView",
"(",
"$",
"this",
"->",
"view",
"(",
"$",
"document",
")",
"->",
"setContext",
"(",
"$",
"context",
")",
")",
";",
"}"
] | Update an existing custom-url object identified by uuid.
@param string $webspace
@param string $id
@param Request $request
@return Response | [
"Update",
"an",
"existing",
"custom",
"-",
"url",
"object",
"identified",
"by",
"uuid",
"."
] | 6766a36cc2f0c807c59202bf7540a08c4ef31192 | https://github.com/sulu/sulu/blob/6766a36cc2f0c807c59202bf7540a08c4ef31192/src/Sulu/Bundle/CustomUrlBundle/Controller/CustomUrlController.php#L119-L130 | train |
sulu/sulu | src/Sulu/Bundle/CustomUrlBundle/Controller/CustomUrlController.php | CustomUrlController.deleteAction | public function deleteAction($webspace, $id)
{
$manager = $this->get('sulu_custom_urls.manager');
$manager->delete($id);
$this->get('sulu_document_manager.document_manager')->flush();
return $this->handleView($this->view());
} | php | public function deleteAction($webspace, $id)
{
$manager = $this->get('sulu_custom_urls.manager');
$manager->delete($id);
$this->get('sulu_document_manager.document_manager')->flush();
return $this->handleView($this->view());
} | [
"public",
"function",
"deleteAction",
"(",
"$",
"webspace",
",",
"$",
"id",
")",
"{",
"$",
"manager",
"=",
"$",
"this",
"->",
"get",
"(",
"'sulu_custom_urls.manager'",
")",
";",
"$",
"manager",
"->",
"delete",
"(",
"$",
"id",
")",
";",
"$",
"this",
"->",
"get",
"(",
"'sulu_document_manager.document_manager'",
")",
"->",
"flush",
"(",
")",
";",
"return",
"$",
"this",
"->",
"handleView",
"(",
"$",
"this",
"->",
"view",
"(",
")",
")",
";",
"}"
] | Delete a single custom-url identified by uuid.
@param string $webspace
@param string $id
@return Response | [
"Delete",
"a",
"single",
"custom",
"-",
"url",
"identified",
"by",
"uuid",
"."
] | 6766a36cc2f0c807c59202bf7540a08c4ef31192 | https://github.com/sulu/sulu/blob/6766a36cc2f0c807c59202bf7540a08c4ef31192/src/Sulu/Bundle/CustomUrlBundle/Controller/CustomUrlController.php#L140-L147 | train |
sulu/sulu | src/Sulu/Bundle/CustomUrlBundle/Controller/CustomUrlController.php | CustomUrlController.cdeleteAction | public function cdeleteAction($webspace, Request $request)
{
$ids = array_filter(explode(',', $request->get('ids', '')));
$manager = $this->get('sulu_custom_urls.manager');
foreach ($ids as $ids) {
$manager->delete($ids);
}
$this->get('sulu_document_manager.document_manager')->flush();
return $this->handleView($this->view());
} | php | public function cdeleteAction($webspace, Request $request)
{
$ids = array_filter(explode(',', $request->get('ids', '')));
$manager = $this->get('sulu_custom_urls.manager');
foreach ($ids as $ids) {
$manager->delete($ids);
}
$this->get('sulu_document_manager.document_manager')->flush();
return $this->handleView($this->view());
} | [
"public",
"function",
"cdeleteAction",
"(",
"$",
"webspace",
",",
"Request",
"$",
"request",
")",
"{",
"$",
"ids",
"=",
"array_filter",
"(",
"explode",
"(",
"','",
",",
"$",
"request",
"->",
"get",
"(",
"'ids'",
",",
"''",
")",
")",
")",
";",
"$",
"manager",
"=",
"$",
"this",
"->",
"get",
"(",
"'sulu_custom_urls.manager'",
")",
";",
"foreach",
"(",
"$",
"ids",
"as",
"$",
"ids",
")",
"{",
"$",
"manager",
"->",
"delete",
"(",
"$",
"ids",
")",
";",
"}",
"$",
"this",
"->",
"get",
"(",
"'sulu_document_manager.document_manager'",
")",
"->",
"flush",
"(",
")",
";",
"return",
"$",
"this",
"->",
"handleView",
"(",
"$",
"this",
"->",
"view",
"(",
")",
")",
";",
"}"
] | Deletes a list of custom-urls identified by a list of uuids.
@param string $webspace
@param Request $request
@return Response | [
"Deletes",
"a",
"list",
"of",
"custom",
"-",
"urls",
"identified",
"by",
"a",
"list",
"of",
"uuids",
"."
] | 6766a36cc2f0c807c59202bf7540a08c4ef31192 | https://github.com/sulu/sulu/blob/6766a36cc2f0c807c59202bf7540a08c4ef31192/src/Sulu/Bundle/CustomUrlBundle/Controller/CustomUrlController.php#L157-L168 | train |
sulu/sulu | src/Sulu/Component/DocumentManager/DocumentInspector.php | DocumentInspector.getParent | public function getParent($document)
{
$parentNode = $this->getNode($document)->getParent();
if (!$parentNode) {
return;
}
return $this->proxyFactory->createProxyForNode($document, $parentNode);
} | php | public function getParent($document)
{
$parentNode = $this->getNode($document)->getParent();
if (!$parentNode) {
return;
}
return $this->proxyFactory->createProxyForNode($document, $parentNode);
} | [
"public",
"function",
"getParent",
"(",
"$",
"document",
")",
"{",
"$",
"parentNode",
"=",
"$",
"this",
"->",
"getNode",
"(",
"$",
"document",
")",
"->",
"getParent",
"(",
")",
";",
"if",
"(",
"!",
"$",
"parentNode",
")",
"{",
"return",
";",
"}",
"return",
"$",
"this",
"->",
"proxyFactory",
"->",
"createProxyForNode",
"(",
"$",
"document",
",",
"$",
"parentNode",
")",
";",
"}"
] | Return the parent document for the given document.
@param object $document
@return object|null | [
"Return",
"the",
"parent",
"document",
"for",
"the",
"given",
"document",
"."
] | 6766a36cc2f0c807c59202bf7540a08c4ef31192 | https://github.com/sulu/sulu/blob/6766a36cc2f0c807c59202bf7540a08c4ef31192/src/Sulu/Component/DocumentManager/DocumentInspector.php#L59-L68 | train |
sulu/sulu | src/Sulu/Bundle/MediaBundle/Api/Media.php | Media.getLocalizedMeta | private function getLocalizedMeta()
{
if ($this->localizedMeta) {
return $this->localizedMeta;
}
$metas = $this->getFileVersion()->getMeta();
$this->localizedMeta = $metas[0];
foreach ($metas as $key => $meta) {
if ($meta->getLocale() == $this->locale) {
$this->localizedMeta = $meta;
break;
}
}
return $this->localizedMeta;
} | php | private function getLocalizedMeta()
{
if ($this->localizedMeta) {
return $this->localizedMeta;
}
$metas = $this->getFileVersion()->getMeta();
$this->localizedMeta = $metas[0];
foreach ($metas as $key => $meta) {
if ($meta->getLocale() == $this->locale) {
$this->localizedMeta = $meta;
break;
}
}
return $this->localizedMeta;
} | [
"private",
"function",
"getLocalizedMeta",
"(",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"localizedMeta",
")",
"{",
"return",
"$",
"this",
"->",
"localizedMeta",
";",
"}",
"$",
"metas",
"=",
"$",
"this",
"->",
"getFileVersion",
"(",
")",
"->",
"getMeta",
"(",
")",
";",
"$",
"this",
"->",
"localizedMeta",
"=",
"$",
"metas",
"[",
"0",
"]",
";",
"foreach",
"(",
"$",
"metas",
"as",
"$",
"key",
"=>",
"$",
"meta",
")",
"{",
"if",
"(",
"$",
"meta",
"->",
"getLocale",
"(",
")",
"==",
"$",
"this",
"->",
"locale",
")",
"{",
"$",
"this",
"->",
"localizedMeta",
"=",
"$",
"meta",
";",
"break",
";",
"}",
"}",
"return",
"$",
"this",
"->",
"localizedMeta",
";",
"}"
] | Searches the meta for the file version in the media locale. Might also return a fallback.
@return FileVersionMeta
@throws FileVersionNotFoundException | [
"Searches",
"the",
"meta",
"for",
"the",
"file",
"version",
"in",
"the",
"media",
"locale",
".",
"Might",
"also",
"return",
"a",
"fallback",
"."
] | 6766a36cc2f0c807c59202bf7540a08c4ef31192 | https://github.com/sulu/sulu/blob/6766a36cc2f0c807c59202bf7540a08c4ef31192/src/Sulu/Bundle/MediaBundle/Api/Media.php#L954-L971 | train |
sulu/sulu | src/Sulu/Bundle/MediaBundle/Api/Media.php | Media.addCategory | public function addCategory(CategoryEntity $category)
{
$fileVersion = $this->getFileVersion();
$fileVersion->addCategory($category);
return $this;
} | php | public function addCategory(CategoryEntity $category)
{
$fileVersion = $this->getFileVersion();
$fileVersion->addCategory($category);
return $this;
} | [
"public",
"function",
"addCategory",
"(",
"CategoryEntity",
"$",
"category",
")",
"{",
"$",
"fileVersion",
"=",
"$",
"this",
"->",
"getFileVersion",
"(",
")",
";",
"$",
"fileVersion",
"->",
"addCategory",
"(",
"$",
"category",
")",
";",
"return",
"$",
"this",
";",
"}"
] | Adds a category to the entity.
@param CategoryEntity $category | [
"Adds",
"a",
"category",
"to",
"the",
"entity",
"."
] | 6766a36cc2f0c807c59202bf7540a08c4ef31192 | https://github.com/sulu/sulu/blob/6766a36cc2f0c807c59202bf7540a08c4ef31192/src/Sulu/Bundle/MediaBundle/Api/Media.php#L978-L984 | train |
sulu/sulu | src/Sulu/Bundle/MediaBundle/Api/Media.php | Media.getCategories | public function getCategories()
{
$apiCategories = [];
$fileVersion = $this->getFileVersion();
$categories = $fileVersion->getCategories();
return array_map(function(CategoryEntity $category) {
return $category->getId();
}, $categories->toArray());
} | php | public function getCategories()
{
$apiCategories = [];
$fileVersion = $this->getFileVersion();
$categories = $fileVersion->getCategories();
return array_map(function(CategoryEntity $category) {
return $category->getId();
}, $categories->toArray());
} | [
"public",
"function",
"getCategories",
"(",
")",
"{",
"$",
"apiCategories",
"=",
"[",
"]",
";",
"$",
"fileVersion",
"=",
"$",
"this",
"->",
"getFileVersion",
"(",
")",
";",
"$",
"categories",
"=",
"$",
"fileVersion",
"->",
"getCategories",
"(",
")",
";",
"return",
"array_map",
"(",
"function",
"(",
"CategoryEntity",
"$",
"category",
")",
"{",
"return",
"$",
"category",
"->",
"getId",
"(",
")",
";",
"}",
",",
"$",
"categories",
"->",
"toArray",
"(",
")",
")",
";",
"}"
] | Returns the categories of the media.
@VirtualProperty
@SerializedName("categories")
@return Category[] | [
"Returns",
"the",
"categories",
"of",
"the",
"media",
"."
] | 6766a36cc2f0c807c59202bf7540a08c4ef31192 | https://github.com/sulu/sulu/blob/6766a36cc2f0c807c59202bf7540a08c4ef31192/src/Sulu/Bundle/MediaBundle/Api/Media.php#L1007-L1016 | train |
sulu/sulu | src/Sulu/Bundle/MediaBundle/Api/Media.php | Media.addTargetGroup | public function addTargetGroup(TargetGroupInterface $targetGroup)
{
$fileVersion = $this->getFileVersion();
$fileVersion->addTargetGroup($targetGroup);
return $this;
} | php | public function addTargetGroup(TargetGroupInterface $targetGroup)
{
$fileVersion = $this->getFileVersion();
$fileVersion->addTargetGroup($targetGroup);
return $this;
} | [
"public",
"function",
"addTargetGroup",
"(",
"TargetGroupInterface",
"$",
"targetGroup",
")",
"{",
"$",
"fileVersion",
"=",
"$",
"this",
"->",
"getFileVersion",
"(",
")",
";",
"$",
"fileVersion",
"->",
"addTargetGroup",
"(",
"$",
"targetGroup",
")",
";",
"return",
"$",
"this",
";",
"}"
] | Adds a target group to the entity.
@param TargetGroupInterface $targetGroup
@return self | [
"Adds",
"a",
"target",
"group",
"to",
"the",
"entity",
"."
] | 6766a36cc2f0c807c59202bf7540a08c4ef31192 | https://github.com/sulu/sulu/blob/6766a36cc2f0c807c59202bf7540a08c4ef31192/src/Sulu/Bundle/MediaBundle/Api/Media.php#L1025-L1031 | train |
sulu/sulu | src/Sulu/Bundle/WebsiteBundle/Command/DumpSitemapCommand.php | DumpSitemapCommand.dumpWebspace | private function dumpWebspace(Webspace $webspace)
{
foreach ($webspace->getAllLocalizations() as $localization) {
$this->output->writeln(sprintf(' - %s (%s)', $webspace->getKey(), $localization->getLocale()));
$this->dumpPortalInformations(
$this->webspaceManager->findPortalInformationsByWebspaceKeyAndLocale(
$webspace->getKey(),
$localization->getLocale(),
$this->environment
)
);
}
} | php | private function dumpWebspace(Webspace $webspace)
{
foreach ($webspace->getAllLocalizations() as $localization) {
$this->output->writeln(sprintf(' - %s (%s)', $webspace->getKey(), $localization->getLocale()));
$this->dumpPortalInformations(
$this->webspaceManager->findPortalInformationsByWebspaceKeyAndLocale(
$webspace->getKey(),
$localization->getLocale(),
$this->environment
)
);
}
} | [
"private",
"function",
"dumpWebspace",
"(",
"Webspace",
"$",
"webspace",
")",
"{",
"foreach",
"(",
"$",
"webspace",
"->",
"getAllLocalizations",
"(",
")",
"as",
"$",
"localization",
")",
"{",
"$",
"this",
"->",
"output",
"->",
"writeln",
"(",
"sprintf",
"(",
"' - %s (%s)'",
",",
"$",
"webspace",
"->",
"getKey",
"(",
")",
",",
"$",
"localization",
"->",
"getLocale",
"(",
")",
")",
")",
";",
"$",
"this",
"->",
"dumpPortalInformations",
"(",
"$",
"this",
"->",
"webspaceManager",
"->",
"findPortalInformationsByWebspaceKeyAndLocale",
"(",
"$",
"webspace",
"->",
"getKey",
"(",
")",
",",
"$",
"localization",
"->",
"getLocale",
"(",
")",
",",
"$",
"this",
"->",
"environment",
")",
")",
";",
"}",
"}"
] | Dump given webspace.
@param Webspace $webspace | [
"Dump",
"given",
"webspace",
"."
] | 6766a36cc2f0c807c59202bf7540a08c4ef31192 | https://github.com/sulu/sulu/blob/6766a36cc2f0c807c59202bf7540a08c4ef31192/src/Sulu/Bundle/WebsiteBundle/Command/DumpSitemapCommand.php#L115-L127 | train |
sulu/sulu | src/Sulu/Bundle/WebsiteBundle/Command/DumpSitemapCommand.php | DumpSitemapCommand.dumpPortalInformations | private function dumpPortalInformations(array $portalInformations)
{
try {
foreach ($portalInformations as $portalInformation) {
$this->sitemapDumper->dumpPortalInformation($portalInformation, $this->scheme);
}
} catch (\InvalidArgumentException $exception) {
$this->clear();
throw $exception;
}
} | php | private function dumpPortalInformations(array $portalInformations)
{
try {
foreach ($portalInformations as $portalInformation) {
$this->sitemapDumper->dumpPortalInformation($portalInformation, $this->scheme);
}
} catch (\InvalidArgumentException $exception) {
$this->clear();
throw $exception;
}
} | [
"private",
"function",
"dumpPortalInformations",
"(",
"array",
"$",
"portalInformations",
")",
"{",
"try",
"{",
"foreach",
"(",
"$",
"portalInformations",
"as",
"$",
"portalInformation",
")",
"{",
"$",
"this",
"->",
"sitemapDumper",
"->",
"dumpPortalInformation",
"(",
"$",
"portalInformation",
",",
"$",
"this",
"->",
"scheme",
")",
";",
"}",
"}",
"catch",
"(",
"\\",
"InvalidArgumentException",
"$",
"exception",
")",
"{",
"$",
"this",
"->",
"clear",
"(",
")",
";",
"throw",
"$",
"exception",
";",
"}",
"}"
] | Dump given portal-informations.
@param PortalInformation[] $portalInformations | [
"Dump",
"given",
"portal",
"-",
"informations",
"."
] | 6766a36cc2f0c807c59202bf7540a08c4ef31192 | https://github.com/sulu/sulu/blob/6766a36cc2f0c807c59202bf7540a08c4ef31192/src/Sulu/Bundle/WebsiteBundle/Command/DumpSitemapCommand.php#L134-L145 | train |
sulu/sulu | src/Sulu/Bundle/ContactBundle/Contact/AccountManager.php | AccountManager.addAddress | public function addAddress($account, AddressEntity $address, $isMain = false)
{
if (!$account || !$address) {
throw new \Exception('Account and Address cannot be null');
}
$accountAddress = new AccountAddressEntity();
$accountAddress->setAccount($account);
$accountAddress->setAddress($address);
if ($isMain) {
$this->unsetMain($account->getAccountAddresses());
}
$accountAddress->setMain($isMain);
$account->addAccountAddress($accountAddress);
$address->addAccountAddress($accountAddress);
$this->em->persist($accountAddress);
return $accountAddress;
} | php | public function addAddress($account, AddressEntity $address, $isMain = false)
{
if (!$account || !$address) {
throw new \Exception('Account and Address cannot be null');
}
$accountAddress = new AccountAddressEntity();
$accountAddress->setAccount($account);
$accountAddress->setAddress($address);
if ($isMain) {
$this->unsetMain($account->getAccountAddresses());
}
$accountAddress->setMain($isMain);
$account->addAccountAddress($accountAddress);
$address->addAccountAddress($accountAddress);
$this->em->persist($accountAddress);
return $accountAddress;
} | [
"public",
"function",
"addAddress",
"(",
"$",
"account",
",",
"AddressEntity",
"$",
"address",
",",
"$",
"isMain",
"=",
"false",
")",
"{",
"if",
"(",
"!",
"$",
"account",
"||",
"!",
"$",
"address",
")",
"{",
"throw",
"new",
"\\",
"Exception",
"(",
"'Account and Address cannot be null'",
")",
";",
"}",
"$",
"accountAddress",
"=",
"new",
"AccountAddressEntity",
"(",
")",
";",
"$",
"accountAddress",
"->",
"setAccount",
"(",
"$",
"account",
")",
";",
"$",
"accountAddress",
"->",
"setAddress",
"(",
"$",
"address",
")",
";",
"if",
"(",
"$",
"isMain",
")",
"{",
"$",
"this",
"->",
"unsetMain",
"(",
"$",
"account",
"->",
"getAccountAddresses",
"(",
")",
")",
";",
"}",
"$",
"accountAddress",
"->",
"setMain",
"(",
"$",
"isMain",
")",
";",
"$",
"account",
"->",
"addAccountAddress",
"(",
"$",
"accountAddress",
")",
";",
"$",
"address",
"->",
"addAccountAddress",
"(",
"$",
"accountAddress",
")",
";",
"$",
"this",
"->",
"em",
"->",
"persist",
"(",
"$",
"accountAddress",
")",
";",
"return",
"$",
"accountAddress",
";",
"}"
] | Adds an address to the entity.
@param AccountApi $account The entity to add the address to
@param AddressEntity $address The address to be added
@param bool $isMain Defines if the address is the main Address of the contact
@throws \Exception
@return AccountAddressEntity | [
"Adds",
"an",
"address",
"to",
"the",
"entity",
"."
] | 6766a36cc2f0c807c59202bf7540a08c4ef31192 | https://github.com/sulu/sulu/blob/6766a36cc2f0c807c59202bf7540a08c4ef31192/src/Sulu/Bundle/ContactBundle/Contact/AccountManager.php#L92-L109 | train |
sulu/sulu | src/Sulu/Bundle/ContactBundle/Contact/AccountManager.php | AccountManager.removeAddressRelation | public function removeAddressRelation($account, $accountAddress)
{
if (!$account || !$accountAddress) {
throw new \Exception('Account and AccountAddress cannot be null');
}
// Reload address to get all data (including relational data).
/** @var AddressEntity $address */
$address = $accountAddress->getAddress();
$address = $this->em->getRepository('SuluContactBundle:Address')
->findById($address->getId());
$isMain = $accountAddress->getMain();
// Remove relation.
$address->removeAccountAddress($accountAddress);
$account->removeAccountAddress($accountAddress);
// If was main, set a new one.
if ($isMain) {
$this->setMainForCollection($account->getAccountContacts());
}
// Delete address if it has no more relations.
if (!$address->hasRelations()) {
$this->em->remove($address);
}
$this->em->remove($accountAddress);
} | php | public function removeAddressRelation($account, $accountAddress)
{
if (!$account || !$accountAddress) {
throw new \Exception('Account and AccountAddress cannot be null');
}
// Reload address to get all data (including relational data).
/** @var AddressEntity $address */
$address = $accountAddress->getAddress();
$address = $this->em->getRepository('SuluContactBundle:Address')
->findById($address->getId());
$isMain = $accountAddress->getMain();
// Remove relation.
$address->removeAccountAddress($accountAddress);
$account->removeAccountAddress($accountAddress);
// If was main, set a new one.
if ($isMain) {
$this->setMainForCollection($account->getAccountContacts());
}
// Delete address if it has no more relations.
if (!$address->hasRelations()) {
$this->em->remove($address);
}
$this->em->remove($accountAddress);
} | [
"public",
"function",
"removeAddressRelation",
"(",
"$",
"account",
",",
"$",
"accountAddress",
")",
"{",
"if",
"(",
"!",
"$",
"account",
"||",
"!",
"$",
"accountAddress",
")",
"{",
"throw",
"new",
"\\",
"Exception",
"(",
"'Account and AccountAddress cannot be null'",
")",
";",
"}",
"// Reload address to get all data (including relational data).",
"/** @var AddressEntity $address */",
"$",
"address",
"=",
"$",
"accountAddress",
"->",
"getAddress",
"(",
")",
";",
"$",
"address",
"=",
"$",
"this",
"->",
"em",
"->",
"getRepository",
"(",
"'SuluContactBundle:Address'",
")",
"->",
"findById",
"(",
"$",
"address",
"->",
"getId",
"(",
")",
")",
";",
"$",
"isMain",
"=",
"$",
"accountAddress",
"->",
"getMain",
"(",
")",
";",
"// Remove relation.",
"$",
"address",
"->",
"removeAccountAddress",
"(",
"$",
"accountAddress",
")",
";",
"$",
"account",
"->",
"removeAccountAddress",
"(",
"$",
"accountAddress",
")",
";",
"// If was main, set a new one.",
"if",
"(",
"$",
"isMain",
")",
"{",
"$",
"this",
"->",
"setMainForCollection",
"(",
"$",
"account",
"->",
"getAccountContacts",
"(",
")",
")",
";",
"}",
"// Delete address if it has no more relations.",
"if",
"(",
"!",
"$",
"address",
"->",
"hasRelations",
"(",
")",
")",
"{",
"$",
"this",
"->",
"em",
"->",
"remove",
"(",
"$",
"address",
")",
";",
"}",
"$",
"this",
"->",
"em",
"->",
"remove",
"(",
"$",
"accountAddress",
")",
";",
"}"
] | Removes the address relation from a contact and also deletes the address
if it has no more relations.
@param AccountInterface $account
@param AccountAddressEntity $accountAddress
@throws \Exception
@return mixed|void | [
"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/AccountManager.php#L122-L151 | train |
sulu/sulu | src/Sulu/Bundle/ContactBundle/Contact/AccountManager.php | AccountManager.getById | public function getById($id, $locale)
{
$account = $this->accountRepository->findAccountById($id);
if (!$account) {
throw new EntityNotFoundException($this->accountRepository->getClassName(), $id);
}
return $this->getApiObject($account, $locale);
} | php | public function getById($id, $locale)
{
$account = $this->accountRepository->findAccountById($id);
if (!$account) {
throw new EntityNotFoundException($this->accountRepository->getClassName(), $id);
}
return $this->getApiObject($account, $locale);
} | [
"public",
"function",
"getById",
"(",
"$",
"id",
",",
"$",
"locale",
")",
"{",
"$",
"account",
"=",
"$",
"this",
"->",
"accountRepository",
"->",
"findAccountById",
"(",
"$",
"id",
")",
";",
"if",
"(",
"!",
"$",
"account",
")",
"{",
"throw",
"new",
"EntityNotFoundException",
"(",
"$",
"this",
"->",
"accountRepository",
"->",
"getClassName",
"(",
")",
",",
"$",
"id",
")",
";",
"}",
"return",
"$",
"this",
"->",
"getApiObject",
"(",
"$",
"account",
",",
"$",
"locale",
")",
";",
"}"
] | Gets account by id.
@param int $id
@param string $locale
@throws EntityNotFoundException
@return mixed | [
"Gets",
"account",
"by",
"id",
"."
] | 6766a36cc2f0c807c59202bf7540a08c4ef31192 | https://github.com/sulu/sulu/blob/6766a36cc2f0c807c59202bf7540a08c4ef31192/src/Sulu/Bundle/ContactBundle/Contact/AccountManager.php#L175-L183 | train |
sulu/sulu | src/Sulu/Bundle/ContactBundle/Contact/AccountManager.php | AccountManager.getByIds | public function getByIds($ids, $locale)
{
if (!is_array($ids) || 0 === count($ids)) {
return [];
}
$accounts = $this->accountRepository->findByIds($ids);
return array_map(
function($account) use ($locale) {
return $this->getApiObject($account, $locale);
},
$accounts
);
} | php | public function getByIds($ids, $locale)
{
if (!is_array($ids) || 0 === count($ids)) {
return [];
}
$accounts = $this->accountRepository->findByIds($ids);
return array_map(
function($account) use ($locale) {
return $this->getApiObject($account, $locale);
},
$accounts
);
} | [
"public",
"function",
"getByIds",
"(",
"$",
"ids",
",",
"$",
"locale",
")",
"{",
"if",
"(",
"!",
"is_array",
"(",
"$",
"ids",
")",
"||",
"0",
"===",
"count",
"(",
"$",
"ids",
")",
")",
"{",
"return",
"[",
"]",
";",
"}",
"$",
"accounts",
"=",
"$",
"this",
"->",
"accountRepository",
"->",
"findByIds",
"(",
"$",
"ids",
")",
";",
"return",
"array_map",
"(",
"function",
"(",
"$",
"account",
")",
"use",
"(",
"$",
"locale",
")",
"{",
"return",
"$",
"this",
"->",
"getApiObject",
"(",
"$",
"account",
",",
"$",
"locale",
")",
";",
"}",
",",
"$",
"accounts",
")",
";",
"}"
] | Returns account entities by ids.
@param array $ids
@param string $locale
@return array | [
"Returns",
"account",
"entities",
"by",
"ids",
"."
] | 6766a36cc2f0c807c59202bf7540a08c4ef31192 | https://github.com/sulu/sulu/blob/6766a36cc2f0c807c59202bf7540a08c4ef31192/src/Sulu/Bundle/ContactBundle/Contact/AccountManager.php#L193-L207 | train |
sulu/sulu | src/Sulu/Bundle/ContactBundle/Contact/AccountManager.php | AccountManager.getByIdAndInclude | public function getByIdAndInclude($id, $locale, $includes)
{
$account = $this->accountRepository->findAccountById($id, in_array('contacts', $includes));
if (!$account) {
throw new EntityNotFoundException($this->accountRepository->getClassName(), $id);
}
return $this->getApiObject($account, $locale);
} | php | public function getByIdAndInclude($id, $locale, $includes)
{
$account = $this->accountRepository->findAccountById($id, in_array('contacts', $includes));
if (!$account) {
throw new EntityNotFoundException($this->accountRepository->getClassName(), $id);
}
return $this->getApiObject($account, $locale);
} | [
"public",
"function",
"getByIdAndInclude",
"(",
"$",
"id",
",",
"$",
"locale",
",",
"$",
"includes",
")",
"{",
"$",
"account",
"=",
"$",
"this",
"->",
"accountRepository",
"->",
"findAccountById",
"(",
"$",
"id",
",",
"in_array",
"(",
"'contacts'",
",",
"$",
"includes",
")",
")",
";",
"if",
"(",
"!",
"$",
"account",
")",
"{",
"throw",
"new",
"EntityNotFoundException",
"(",
"$",
"this",
"->",
"accountRepository",
"->",
"getClassName",
"(",
")",
",",
"$",
"id",
")",
";",
"}",
"return",
"$",
"this",
"->",
"getApiObject",
"(",
"$",
"account",
",",
"$",
"locale",
")",
";",
"}"
] | Gets account by id - can include relations.
@param int $id
@param string $locale
@param array $includes
@throws EntityNotFoundException
@return AccountApi | [
"Gets",
"account",
"by",
"id",
"-",
"can",
"include",
"relations",
"."
] | 6766a36cc2f0c807c59202bf7540a08c4ef31192 | https://github.com/sulu/sulu/blob/6766a36cc2f0c807c59202bf7540a08c4ef31192/src/Sulu/Bundle/ContactBundle/Contact/AccountManager.php#L220-L229 | train |
sulu/sulu | src/Sulu/Bundle/ContactBundle/Contact/AccountManager.php | AccountManager.findContactsByAccountId | public function findContactsByAccountId($id, $locale, $onlyFetchMainAccounts = false)
{
$contactsEntities = $this->contactRepository->findByAccountId(
$id,
null,
false,
$onlyFetchMainAccounts
);
if (!empty($contactsEntities)) {
$contacts = [];
foreach ($contactsEntities as $contact) {
$contacts[] = new Contact($contact, $locale);
}
return $contacts;
}
return;
} | php | public function findContactsByAccountId($id, $locale, $onlyFetchMainAccounts = false)
{
$contactsEntities = $this->contactRepository->findByAccountId(
$id,
null,
false,
$onlyFetchMainAccounts
);
if (!empty($contactsEntities)) {
$contacts = [];
foreach ($contactsEntities as $contact) {
$contacts[] = new Contact($contact, $locale);
}
return $contacts;
}
return;
} | [
"public",
"function",
"findContactsByAccountId",
"(",
"$",
"id",
",",
"$",
"locale",
",",
"$",
"onlyFetchMainAccounts",
"=",
"false",
")",
"{",
"$",
"contactsEntities",
"=",
"$",
"this",
"->",
"contactRepository",
"->",
"findByAccountId",
"(",
"$",
"id",
",",
"null",
",",
"false",
",",
"$",
"onlyFetchMainAccounts",
")",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"contactsEntities",
")",
")",
"{",
"$",
"contacts",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"contactsEntities",
"as",
"$",
"contact",
")",
"{",
"$",
"contacts",
"[",
"]",
"=",
"new",
"Contact",
"(",
"$",
"contact",
",",
"$",
"locale",
")",
";",
"}",
"return",
"$",
"contacts",
";",
"}",
"return",
";",
"}"
] | Returns contacts by account id.
@param int $id
@param string $locale
@param bool $onlyFetchMainAccounts
@return array|null | [
"Returns",
"contacts",
"by",
"account",
"id",
"."
] | 6766a36cc2f0c807c59202bf7540a08c4ef31192 | https://github.com/sulu/sulu/blob/6766a36cc2f0c807c59202bf7540a08c4ef31192/src/Sulu/Bundle/ContactBundle/Contact/AccountManager.php#L240-L259 | train |
sulu/sulu | src/Sulu/Bundle/ContactBundle/Contact/AccountManager.php | AccountManager.setMedias | public function setMedias(Account $account, $medias)
{
$mediaIds = array_map(
function($media) {
return $media['id'];
},
$medias
);
$foundMedias = $this->mediaRepository->findById($mediaIds);
$foundMediaIds = array_map(
function($mediaEntity) {
return $mediaEntity->getId();
},
$foundMedias
);
if ($missingMediaIds = array_diff($mediaIds, $foundMediaIds)) {
throw new EntityNotFoundException($this->mediaRepository->getClassName(), reset($missingMediaIds));
}
$account->getMedias()->clear();
foreach ($foundMedias as $media) {
$account->addMedia($media);
}
} | php | public function setMedias(Account $account, $medias)
{
$mediaIds = array_map(
function($media) {
return $media['id'];
},
$medias
);
$foundMedias = $this->mediaRepository->findById($mediaIds);
$foundMediaIds = array_map(
function($mediaEntity) {
return $mediaEntity->getId();
},
$foundMedias
);
if ($missingMediaIds = array_diff($mediaIds, $foundMediaIds)) {
throw new EntityNotFoundException($this->mediaRepository->getClassName(), reset($missingMediaIds));
}
$account->getMedias()->clear();
foreach ($foundMedias as $media) {
$account->addMedia($media);
}
} | [
"public",
"function",
"setMedias",
"(",
"Account",
"$",
"account",
",",
"$",
"medias",
")",
"{",
"$",
"mediaIds",
"=",
"array_map",
"(",
"function",
"(",
"$",
"media",
")",
"{",
"return",
"$",
"media",
"[",
"'id'",
"]",
";",
"}",
",",
"$",
"medias",
")",
";",
"$",
"foundMedias",
"=",
"$",
"this",
"->",
"mediaRepository",
"->",
"findById",
"(",
"$",
"mediaIds",
")",
";",
"$",
"foundMediaIds",
"=",
"array_map",
"(",
"function",
"(",
"$",
"mediaEntity",
")",
"{",
"return",
"$",
"mediaEntity",
"->",
"getId",
"(",
")",
";",
"}",
",",
"$",
"foundMedias",
")",
";",
"if",
"(",
"$",
"missingMediaIds",
"=",
"array_diff",
"(",
"$",
"mediaIds",
",",
"$",
"foundMediaIds",
")",
")",
"{",
"throw",
"new",
"EntityNotFoundException",
"(",
"$",
"this",
"->",
"mediaRepository",
"->",
"getClassName",
"(",
")",
",",
"reset",
"(",
"$",
"missingMediaIds",
")",
")",
";",
"}",
"$",
"account",
"->",
"getMedias",
"(",
")",
"->",
"clear",
"(",
")",
";",
"foreach",
"(",
"$",
"foundMedias",
"as",
"$",
"media",
")",
"{",
"$",
"account",
"->",
"addMedia",
"(",
"$",
"media",
")",
";",
"}",
"}"
] | Sets the medias of the given account to the given medias.
Currently associated medias are replaced.
@param Account $account
@param $medias
@throws EntityNotFoundException | [
"Sets",
"the",
"medias",
"of",
"the",
"given",
"account",
"to",
"the",
"given",
"medias",
".",
"Currently",
"associated",
"medias",
"are",
"replaced",
"."
] | 6766a36cc2f0c807c59202bf7540a08c4ef31192 | https://github.com/sulu/sulu/blob/6766a36cc2f0c807c59202bf7540a08c4ef31192/src/Sulu/Bundle/ContactBundle/Contact/AccountManager.php#L283-L308 | train |
sulu/sulu | src/Sulu/Bundle/ContactBundle/Contact/AccountManager.php | AccountManager.findAll | public function findAll($locale, $filter = null)
{
if ($filter) {
$accountEntities = $this->accountRepository->findByFilter($filter);
} else {
$accountEntities = $this->accountRepository->findAll();
}
if (!empty($accountEntities)) {
$accounts = [];
foreach ($accountEntities as $account) {
$accounts[] = $this->getApiObject($account, $locale);
}
return $accounts;
}
return;
} | php | public function findAll($locale, $filter = null)
{
if ($filter) {
$accountEntities = $this->accountRepository->findByFilter($filter);
} else {
$accountEntities = $this->accountRepository->findAll();
}
if (!empty($accountEntities)) {
$accounts = [];
foreach ($accountEntities as $account) {
$accounts[] = $this->getApiObject($account, $locale);
}
return $accounts;
}
return;
} | [
"public",
"function",
"findAll",
"(",
"$",
"locale",
",",
"$",
"filter",
"=",
"null",
")",
"{",
"if",
"(",
"$",
"filter",
")",
"{",
"$",
"accountEntities",
"=",
"$",
"this",
"->",
"accountRepository",
"->",
"findByFilter",
"(",
"$",
"filter",
")",
";",
"}",
"else",
"{",
"$",
"accountEntities",
"=",
"$",
"this",
"->",
"accountRepository",
"->",
"findAll",
"(",
")",
";",
"}",
"if",
"(",
"!",
"empty",
"(",
"$",
"accountEntities",
")",
")",
"{",
"$",
"accounts",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"accountEntities",
"as",
"$",
"account",
")",
"{",
"$",
"accounts",
"[",
"]",
"=",
"$",
"this",
"->",
"getApiObject",
"(",
"$",
"account",
",",
"$",
"locale",
")",
";",
"}",
"return",
"$",
"accounts",
";",
"}",
"return",
";",
"}"
] | Returns all accounts.
@param string $locale
@param null $filter
@return array|null | [
"Returns",
"all",
"accounts",
"."
] | 6766a36cc2f0c807c59202bf7540a08c4ef31192 | https://github.com/sulu/sulu/blob/6766a36cc2f0c807c59202bf7540a08c4ef31192/src/Sulu/Bundle/ContactBundle/Contact/AccountManager.php#L318-L336 | train |
sulu/sulu | src/Sulu/Bundle/ContactBundle/Contact/AccountManager.php | AccountManager.getApiObject | protected function getApiObject($account, $locale)
{
$apiObject = $this->accountFactory->createApiEntity($account, $locale);
if ($account->getLogo()) {
$apiLogo = $this->mediaManager->getById($account->getLogo()->getId(), $locale);
$apiObject->setLogo($apiLogo);
}
return $apiObject;
} | php | protected function getApiObject($account, $locale)
{
$apiObject = $this->accountFactory->createApiEntity($account, $locale);
if ($account->getLogo()) {
$apiLogo = $this->mediaManager->getById($account->getLogo()->getId(), $locale);
$apiObject->setLogo($apiLogo);
}
return $apiObject;
} | [
"protected",
"function",
"getApiObject",
"(",
"$",
"account",
",",
"$",
"locale",
")",
"{",
"$",
"apiObject",
"=",
"$",
"this",
"->",
"accountFactory",
"->",
"createApiEntity",
"(",
"$",
"account",
",",
"$",
"locale",
")",
";",
"if",
"(",
"$",
"account",
"->",
"getLogo",
"(",
")",
")",
"{",
"$",
"apiLogo",
"=",
"$",
"this",
"->",
"mediaManager",
"->",
"getById",
"(",
"$",
"account",
"->",
"getLogo",
"(",
")",
"->",
"getId",
"(",
")",
",",
"$",
"locale",
")",
";",
"$",
"apiObject",
"->",
"setLogo",
"(",
"$",
"apiLogo",
")",
";",
"}",
"return",
"$",
"apiObject",
";",
"}"
] | Takes a account entity and a locale and returns the api object.
@param Account $account
@param string $locale
@return AccountApi | [
"Takes",
"a",
"account",
"entity",
"and",
"a",
"locale",
"and",
"returns",
"the",
"api",
"object",
"."
] | 6766a36cc2f0c807c59202bf7540a08c4ef31192 | https://github.com/sulu/sulu/blob/6766a36cc2f0c807c59202bf7540a08c4ef31192/src/Sulu/Bundle/ContactBundle/Contact/AccountManager.php#L400-L409 | train |
sulu/sulu | src/Sulu/Component/Rest/ListBuilder/Doctrine/DoctrineListBuilderFactory.php | DoctrineListBuilderFactory.create | public function create($entityName)
{
return new DoctrineListBuilder($this->em, $entityName, $this->eventDispatcher, $this->permissions);
} | php | public function create($entityName)
{
return new DoctrineListBuilder($this->em, $entityName, $this->eventDispatcher, $this->permissions);
} | [
"public",
"function",
"create",
"(",
"$",
"entityName",
")",
"{",
"return",
"new",
"DoctrineListBuilder",
"(",
"$",
"this",
"->",
"em",
",",
"$",
"entityName",
",",
"$",
"this",
"->",
"eventDispatcher",
",",
"$",
"this",
"->",
"permissions",
")",
";",
"}"
] | Creates a new DoctrineListBuilder for the given entity name and returns it.
@param $entityName
@return DoctrineListBuilder | [
"Creates",
"a",
"new",
"DoctrineListBuilder",
"for",
"the",
"given",
"entity",
"name",
"and",
"returns",
"it",
"."
] | 6766a36cc2f0c807c59202bf7540a08c4ef31192 | https://github.com/sulu/sulu/blob/6766a36cc2f0c807c59202bf7540a08c4ef31192/src/Sulu/Component/Rest/ListBuilder/Doctrine/DoctrineListBuilderFactory.php#L56-L59 | train |
sulu/sulu | src/Sulu/Bundle/WebsiteBundle/EventListener/RedirectExceptionSubscriber.php | RedirectExceptionSubscriber.redirectTrailingSlashOrHtml | public function redirectTrailingSlashOrHtml(GetResponseForExceptionEvent $event)
{
if (!$event->getException() instanceof NotFoundHttpException) {
return;
}
$request = $event->getRequest();
/** @var RequestAttributes $attributes */
$attributes = $request->attributes->get('_sulu');
if (!$attributes) {
return;
}
$prefix = $attributes->getAttribute('resourceLocatorPrefix');
$resourceLocator = $attributes->getAttribute('resourceLocator');
$route = '/' . trim($prefix . $resourceLocator, '/');
if (!in_array($request->getRequestFormat(), ['htm', 'html'])
|| $route === $request->getPathInfo()
|| !$this->matchRoute($request->getSchemeAndHttpHost() . $route)
) {
return;
}
$event->setResponse(new RedirectResponse($route, 301));
} | php | public function redirectTrailingSlashOrHtml(GetResponseForExceptionEvent $event)
{
if (!$event->getException() instanceof NotFoundHttpException) {
return;
}
$request = $event->getRequest();
/** @var RequestAttributes $attributes */
$attributes = $request->attributes->get('_sulu');
if (!$attributes) {
return;
}
$prefix = $attributes->getAttribute('resourceLocatorPrefix');
$resourceLocator = $attributes->getAttribute('resourceLocator');
$route = '/' . trim($prefix . $resourceLocator, '/');
if (!in_array($request->getRequestFormat(), ['htm', 'html'])
|| $route === $request->getPathInfo()
|| !$this->matchRoute($request->getSchemeAndHttpHost() . $route)
) {
return;
}
$event->setResponse(new RedirectResponse($route, 301));
} | [
"public",
"function",
"redirectTrailingSlashOrHtml",
"(",
"GetResponseForExceptionEvent",
"$",
"event",
")",
"{",
"if",
"(",
"!",
"$",
"event",
"->",
"getException",
"(",
")",
"instanceof",
"NotFoundHttpException",
")",
"{",
"return",
";",
"}",
"$",
"request",
"=",
"$",
"event",
"->",
"getRequest",
"(",
")",
";",
"/** @var RequestAttributes $attributes */",
"$",
"attributes",
"=",
"$",
"request",
"->",
"attributes",
"->",
"get",
"(",
"'_sulu'",
")",
";",
"if",
"(",
"!",
"$",
"attributes",
")",
"{",
"return",
";",
"}",
"$",
"prefix",
"=",
"$",
"attributes",
"->",
"getAttribute",
"(",
"'resourceLocatorPrefix'",
")",
";",
"$",
"resourceLocator",
"=",
"$",
"attributes",
"->",
"getAttribute",
"(",
"'resourceLocator'",
")",
";",
"$",
"route",
"=",
"'/'",
".",
"trim",
"(",
"$",
"prefix",
".",
"$",
"resourceLocator",
",",
"'/'",
")",
";",
"if",
"(",
"!",
"in_array",
"(",
"$",
"request",
"->",
"getRequestFormat",
"(",
")",
",",
"[",
"'htm'",
",",
"'html'",
"]",
")",
"||",
"$",
"route",
"===",
"$",
"request",
"->",
"getPathInfo",
"(",
")",
"||",
"!",
"$",
"this",
"->",
"matchRoute",
"(",
"$",
"request",
"->",
"getSchemeAndHttpHost",
"(",
")",
".",
"$",
"route",
")",
")",
"{",
"return",
";",
"}",
"$",
"event",
"->",
"setResponse",
"(",
"new",
"RedirectResponse",
"(",
"$",
"route",
",",
"301",
")",
")",
";",
"}"
] | Redirect trailing slashes or ".html".
@param GetResponseForExceptionEvent $event | [
"Redirect",
"trailing",
"slashes",
"or",
".",
"html",
"."
] | 6766a36cc2f0c807c59202bf7540a08c4ef31192 | https://github.com/sulu/sulu/blob/6766a36cc2f0c807c59202bf7540a08c4ef31192/src/Sulu/Bundle/WebsiteBundle/EventListener/RedirectExceptionSubscriber.php#L89-L115 | train |
sulu/sulu | src/Sulu/Bundle/WebsiteBundle/EventListener/RedirectExceptionSubscriber.php | RedirectExceptionSubscriber.redirectPartialMatch | public function redirectPartialMatch(GetResponseForExceptionEvent $event)
{
if (!$event->getException() instanceof NotFoundHttpException) {
return;
}
$request = $event->getRequest();
/** @var RequestAttributes $attributes */
$attributes = $event->getRequest()->attributes->get('_sulu');
if (!$attributes) {
return;
}
$types = [RequestAnalyzerInterface::MATCH_TYPE_REDIRECT, RequestAnalyzerInterface::MATCH_TYPE_PARTIAL];
$matchType = $attributes->getAttribute('matchType');
if (!in_array($matchType, $types)) {
return;
}
$localization = $this->defaultLocaleProvider->getDefaultLocale();
$redirect = $attributes->getAttribute('redirect');
$redirect = $this->urlReplacer->replaceCountry($redirect, $localization->getCountry());
$redirect = $this->urlReplacer->replaceLanguage($redirect, $localization->getLanguage());
$redirect = $this->urlReplacer->replaceLocalization($redirect, $localization->getLocale(Localization::DASH));
$route = $this->resolveRedirectUrl(
$redirect,
$request->getUri(),
$attributes->getAttribute('resourceLocatorPrefix')
);
if (!$this->matchRoute($route)) {
return;
}
$event->setResponse(new RedirectResponse($route, 301));
} | php | public function redirectPartialMatch(GetResponseForExceptionEvent $event)
{
if (!$event->getException() instanceof NotFoundHttpException) {
return;
}
$request = $event->getRequest();
/** @var RequestAttributes $attributes */
$attributes = $event->getRequest()->attributes->get('_sulu');
if (!$attributes) {
return;
}
$types = [RequestAnalyzerInterface::MATCH_TYPE_REDIRECT, RequestAnalyzerInterface::MATCH_TYPE_PARTIAL];
$matchType = $attributes->getAttribute('matchType');
if (!in_array($matchType, $types)) {
return;
}
$localization = $this->defaultLocaleProvider->getDefaultLocale();
$redirect = $attributes->getAttribute('redirect');
$redirect = $this->urlReplacer->replaceCountry($redirect, $localization->getCountry());
$redirect = $this->urlReplacer->replaceLanguage($redirect, $localization->getLanguage());
$redirect = $this->urlReplacer->replaceLocalization($redirect, $localization->getLocale(Localization::DASH));
$route = $this->resolveRedirectUrl(
$redirect,
$request->getUri(),
$attributes->getAttribute('resourceLocatorPrefix')
);
if (!$this->matchRoute($route)) {
return;
}
$event->setResponse(new RedirectResponse($route, 301));
} | [
"public",
"function",
"redirectPartialMatch",
"(",
"GetResponseForExceptionEvent",
"$",
"event",
")",
"{",
"if",
"(",
"!",
"$",
"event",
"->",
"getException",
"(",
")",
"instanceof",
"NotFoundHttpException",
")",
"{",
"return",
";",
"}",
"$",
"request",
"=",
"$",
"event",
"->",
"getRequest",
"(",
")",
";",
"/** @var RequestAttributes $attributes */",
"$",
"attributes",
"=",
"$",
"event",
"->",
"getRequest",
"(",
")",
"->",
"attributes",
"->",
"get",
"(",
"'_sulu'",
")",
";",
"if",
"(",
"!",
"$",
"attributes",
")",
"{",
"return",
";",
"}",
"$",
"types",
"=",
"[",
"RequestAnalyzerInterface",
"::",
"MATCH_TYPE_REDIRECT",
",",
"RequestAnalyzerInterface",
"::",
"MATCH_TYPE_PARTIAL",
"]",
";",
"$",
"matchType",
"=",
"$",
"attributes",
"->",
"getAttribute",
"(",
"'matchType'",
")",
";",
"if",
"(",
"!",
"in_array",
"(",
"$",
"matchType",
",",
"$",
"types",
")",
")",
"{",
"return",
";",
"}",
"$",
"localization",
"=",
"$",
"this",
"->",
"defaultLocaleProvider",
"->",
"getDefaultLocale",
"(",
")",
";",
"$",
"redirect",
"=",
"$",
"attributes",
"->",
"getAttribute",
"(",
"'redirect'",
")",
";",
"$",
"redirect",
"=",
"$",
"this",
"->",
"urlReplacer",
"->",
"replaceCountry",
"(",
"$",
"redirect",
",",
"$",
"localization",
"->",
"getCountry",
"(",
")",
")",
";",
"$",
"redirect",
"=",
"$",
"this",
"->",
"urlReplacer",
"->",
"replaceLanguage",
"(",
"$",
"redirect",
",",
"$",
"localization",
"->",
"getLanguage",
"(",
")",
")",
";",
"$",
"redirect",
"=",
"$",
"this",
"->",
"urlReplacer",
"->",
"replaceLocalization",
"(",
"$",
"redirect",
",",
"$",
"localization",
"->",
"getLocale",
"(",
"Localization",
"::",
"DASH",
")",
")",
";",
"$",
"route",
"=",
"$",
"this",
"->",
"resolveRedirectUrl",
"(",
"$",
"redirect",
",",
"$",
"request",
"->",
"getUri",
"(",
")",
",",
"$",
"attributes",
"->",
"getAttribute",
"(",
"'resourceLocatorPrefix'",
")",
")",
";",
"if",
"(",
"!",
"$",
"this",
"->",
"matchRoute",
"(",
"$",
"route",
")",
")",
"{",
"return",
";",
"}",
"$",
"event",
"->",
"setResponse",
"(",
"new",
"RedirectResponse",
"(",
"$",
"route",
",",
"301",
")",
")",
";",
"}"
] | Redirect partial and redirect matches.
@param GetResponseForExceptionEvent $event | [
"Redirect",
"partial",
"and",
"redirect",
"matches",
"."
] | 6766a36cc2f0c807c59202bf7540a08c4ef31192 | https://github.com/sulu/sulu/blob/6766a36cc2f0c807c59202bf7540a08c4ef31192/src/Sulu/Bundle/WebsiteBundle/EventListener/RedirectExceptionSubscriber.php#L122-L160 | train |
sulu/sulu | src/Sulu/Bundle/WebsiteBundle/EventListener/RedirectExceptionSubscriber.php | RedirectExceptionSubscriber.matchUrl | private function matchUrl($url)
{
$request = Request::create($url);
$this->requestAnalyzer->analyze($request);
try {
return null !== $this->router->matchRequest($request);
} catch (ResourceNotFoundException $exception) {
return false;
}
} | php | private function matchUrl($url)
{
$request = Request::create($url);
$this->requestAnalyzer->analyze($request);
try {
return null !== $this->router->matchRequest($request);
} catch (ResourceNotFoundException $exception) {
return false;
}
} | [
"private",
"function",
"matchUrl",
"(",
"$",
"url",
")",
"{",
"$",
"request",
"=",
"Request",
"::",
"create",
"(",
"$",
"url",
")",
";",
"$",
"this",
"->",
"requestAnalyzer",
"->",
"analyze",
"(",
"$",
"request",
")",
";",
"try",
"{",
"return",
"null",
"!==",
"$",
"this",
"->",
"router",
"->",
"matchRequest",
"(",
"$",
"request",
")",
";",
"}",
"catch",
"(",
"ResourceNotFoundException",
"$",
"exception",
")",
"{",
"return",
"false",
";",
"}",
"}"
] | Returns true if given url exists.
@param string $url
@return bool | [
"Returns",
"true",
"if",
"given",
"url",
"exists",
"."
] | 6766a36cc2f0c807c59202bf7540a08c4ef31192 | https://github.com/sulu/sulu/blob/6766a36cc2f0c807c59202bf7540a08c4ef31192/src/Sulu/Bundle/WebsiteBundle/EventListener/RedirectExceptionSubscriber.php#L181-L191 | train |
sulu/sulu | src/Sulu/Bundle/WebsiteBundle/EventListener/RedirectExceptionSubscriber.php | RedirectExceptionSubscriber.resolveRedirectUrl | private function resolveRedirectUrl($redirectUrl, $requestUri, $resourceLocatorPrefix)
{
$redirectInfo = $this->parseUrl($redirectUrl);
$requestInfo = $this->parseUrl($requestUri);
$url = sprintf('%s://%s', $requestInfo['scheme'], $requestInfo['host']);
if (isset($redirectInfo['host'])) {
$url = sprintf('%s://%s', $requestInfo['scheme'], $redirectInfo['host']);
}
if (isset($requestInfo['port'])) {
$url .= ':' . $requestInfo['port'];
}
if (isset($redirectInfo['path'])
&& (// if requested url not starting with redirectUrl it need to be added
!isset($requestInfo['path'])
|| 0 !== strpos($requestInfo['path'], $redirectInfo['path'] . '/'))
) {
$url .= $redirectInfo['path'];
}
if (isset($requestInfo['path']) && $resourceLocatorPrefix !== $requestInfo['path']) {
$path = $requestInfo['path'];
if ($resourceLocatorPrefix && 0 === strpos($path, $resourceLocatorPrefix)) {
$path = substr($path, strlen($resourceLocatorPrefix));
}
$url .= $path;
$url = rtrim($url, '/');
}
if (isset($requestInfo['query'])) {
$url .= '?' . $requestInfo['query'];
}
if (isset($requestInfo['fragment'])) {
$url .= '#' . $requestInfo['fragment'];
}
return $url;
} | php | private function resolveRedirectUrl($redirectUrl, $requestUri, $resourceLocatorPrefix)
{
$redirectInfo = $this->parseUrl($redirectUrl);
$requestInfo = $this->parseUrl($requestUri);
$url = sprintf('%s://%s', $requestInfo['scheme'], $requestInfo['host']);
if (isset($redirectInfo['host'])) {
$url = sprintf('%s://%s', $requestInfo['scheme'], $redirectInfo['host']);
}
if (isset($requestInfo['port'])) {
$url .= ':' . $requestInfo['port'];
}
if (isset($redirectInfo['path'])
&& (// if requested url not starting with redirectUrl it need to be added
!isset($requestInfo['path'])
|| 0 !== strpos($requestInfo['path'], $redirectInfo['path'] . '/'))
) {
$url .= $redirectInfo['path'];
}
if (isset($requestInfo['path']) && $resourceLocatorPrefix !== $requestInfo['path']) {
$path = $requestInfo['path'];
if ($resourceLocatorPrefix && 0 === strpos($path, $resourceLocatorPrefix)) {
$path = substr($path, strlen($resourceLocatorPrefix));
}
$url .= $path;
$url = rtrim($url, '/');
}
if (isset($requestInfo['query'])) {
$url .= '?' . $requestInfo['query'];
}
if (isset($requestInfo['fragment'])) {
$url .= '#' . $requestInfo['fragment'];
}
return $url;
} | [
"private",
"function",
"resolveRedirectUrl",
"(",
"$",
"redirectUrl",
",",
"$",
"requestUri",
",",
"$",
"resourceLocatorPrefix",
")",
"{",
"$",
"redirectInfo",
"=",
"$",
"this",
"->",
"parseUrl",
"(",
"$",
"redirectUrl",
")",
";",
"$",
"requestInfo",
"=",
"$",
"this",
"->",
"parseUrl",
"(",
"$",
"requestUri",
")",
";",
"$",
"url",
"=",
"sprintf",
"(",
"'%s://%s'",
",",
"$",
"requestInfo",
"[",
"'scheme'",
"]",
",",
"$",
"requestInfo",
"[",
"'host'",
"]",
")",
";",
"if",
"(",
"isset",
"(",
"$",
"redirectInfo",
"[",
"'host'",
"]",
")",
")",
"{",
"$",
"url",
"=",
"sprintf",
"(",
"'%s://%s'",
",",
"$",
"requestInfo",
"[",
"'scheme'",
"]",
",",
"$",
"redirectInfo",
"[",
"'host'",
"]",
")",
";",
"}",
"if",
"(",
"isset",
"(",
"$",
"requestInfo",
"[",
"'port'",
"]",
")",
")",
"{",
"$",
"url",
".=",
"':'",
".",
"$",
"requestInfo",
"[",
"'port'",
"]",
";",
"}",
"if",
"(",
"isset",
"(",
"$",
"redirectInfo",
"[",
"'path'",
"]",
")",
"&&",
"(",
"// if requested url not starting with redirectUrl it need to be added",
"!",
"isset",
"(",
"$",
"requestInfo",
"[",
"'path'",
"]",
")",
"||",
"0",
"!==",
"strpos",
"(",
"$",
"requestInfo",
"[",
"'path'",
"]",
",",
"$",
"redirectInfo",
"[",
"'path'",
"]",
".",
"'/'",
")",
")",
")",
"{",
"$",
"url",
".=",
"$",
"redirectInfo",
"[",
"'path'",
"]",
";",
"}",
"if",
"(",
"isset",
"(",
"$",
"requestInfo",
"[",
"'path'",
"]",
")",
"&&",
"$",
"resourceLocatorPrefix",
"!==",
"$",
"requestInfo",
"[",
"'path'",
"]",
")",
"{",
"$",
"path",
"=",
"$",
"requestInfo",
"[",
"'path'",
"]",
";",
"if",
"(",
"$",
"resourceLocatorPrefix",
"&&",
"0",
"===",
"strpos",
"(",
"$",
"path",
",",
"$",
"resourceLocatorPrefix",
")",
")",
"{",
"$",
"path",
"=",
"substr",
"(",
"$",
"path",
",",
"strlen",
"(",
"$",
"resourceLocatorPrefix",
")",
")",
";",
"}",
"$",
"url",
".=",
"$",
"path",
";",
"$",
"url",
"=",
"rtrim",
"(",
"$",
"url",
",",
"'/'",
")",
";",
"}",
"if",
"(",
"isset",
"(",
"$",
"requestInfo",
"[",
"'query'",
"]",
")",
")",
"{",
"$",
"url",
".=",
"'?'",
".",
"$",
"requestInfo",
"[",
"'query'",
"]",
";",
"}",
"if",
"(",
"isset",
"(",
"$",
"requestInfo",
"[",
"'fragment'",
"]",
")",
")",
"{",
"$",
"url",
".=",
"'#'",
".",
"$",
"requestInfo",
"[",
"'fragment'",
"]",
";",
"}",
"return",
"$",
"url",
";",
"}"
] | Resolve the redirect URL, appending any additional path data.
@param string $redirectUrl Redirect webspace URI
@param string $requestUri The actual incoming request URI
@param string $resourceLocatorPrefix The prefix of the actual portal
@return string URL to redirect to | [
"Resolve",
"the",
"redirect",
"URL",
"appending",
"any",
"additional",
"path",
"data",
"."
] | 6766a36cc2f0c807c59202bf7540a08c4ef31192 | https://github.com/sulu/sulu/blob/6766a36cc2f0c807c59202bf7540a08c4ef31192/src/Sulu/Bundle/WebsiteBundle/EventListener/RedirectExceptionSubscriber.php#L202-L244 | train |
sulu/sulu | src/Sulu/Bundle/PageBundle/Form/Type/PageDocumentType.php | PageDocumentType.postSubmitDocumentParent | public function postSubmitDocumentParent(FormEvent $event)
{
$document = $event->getData();
if ($document->getParent()) {
return;
}
$form = $event->getForm();
$webspaceKey = $form->getConfig()->getAttribute('webspace_key');
$parent = $this->documentManager->find($this->sessionManager->getContentPath($webspaceKey));
if (null === $parent) {
throw new \InvalidArgumentException(
sprintf(
'Could not determine parent for document with title "%s" in webspace "%s"',
$document->getTitle(),
$webspaceKey
)
);
}
$document->setParent($parent);
} | php | public function postSubmitDocumentParent(FormEvent $event)
{
$document = $event->getData();
if ($document->getParent()) {
return;
}
$form = $event->getForm();
$webspaceKey = $form->getConfig()->getAttribute('webspace_key');
$parent = $this->documentManager->find($this->sessionManager->getContentPath($webspaceKey));
if (null === $parent) {
throw new \InvalidArgumentException(
sprintf(
'Could not determine parent for document with title "%s" in webspace "%s"',
$document->getTitle(),
$webspaceKey
)
);
}
$document->setParent($parent);
} | [
"public",
"function",
"postSubmitDocumentParent",
"(",
"FormEvent",
"$",
"event",
")",
"{",
"$",
"document",
"=",
"$",
"event",
"->",
"getData",
"(",
")",
";",
"if",
"(",
"$",
"document",
"->",
"getParent",
"(",
")",
")",
"{",
"return",
";",
"}",
"$",
"form",
"=",
"$",
"event",
"->",
"getForm",
"(",
")",
";",
"$",
"webspaceKey",
"=",
"$",
"form",
"->",
"getConfig",
"(",
")",
"->",
"getAttribute",
"(",
"'webspace_key'",
")",
";",
"$",
"parent",
"=",
"$",
"this",
"->",
"documentManager",
"->",
"find",
"(",
"$",
"this",
"->",
"sessionManager",
"->",
"getContentPath",
"(",
"$",
"webspaceKey",
")",
")",
";",
"if",
"(",
"null",
"===",
"$",
"parent",
")",
"{",
"throw",
"new",
"\\",
"InvalidArgumentException",
"(",
"sprintf",
"(",
"'Could not determine parent for document with title \"%s\" in webspace \"%s\"'",
",",
"$",
"document",
"->",
"getTitle",
"(",
")",
",",
"$",
"webspaceKey",
")",
")",
";",
"}",
"$",
"document",
"->",
"setParent",
"(",
"$",
"parent",
")",
";",
"}"
] | Set the document parent to be the webspace content path
when the document has no parent.
@param FormEvent $event | [
"Set",
"the",
"document",
"parent",
"to",
"be",
"the",
"webspace",
"content",
"path",
"when",
"the",
"document",
"has",
"no",
"parent",
"."
] | 6766a36cc2f0c807c59202bf7540a08c4ef31192 | https://github.com/sulu/sulu/blob/6766a36cc2f0c807c59202bf7540a08c4ef31192/src/Sulu/Bundle/PageBundle/Form/Type/PageDocumentType.php#L83-L106 | train |
sulu/sulu | src/Sulu/Component/Util/WildcardUrlUtil.php | WildcardUrlUtil.getRegularExpression | private static function getRegularExpression($portalUrl)
{
$patternUrl = rtrim($portalUrl, '/');
$patternUrl = preg_quote($patternUrl);
$patternUrl = str_replace(['/', '\*'], ['\/', '([^\/.]+)'], $patternUrl);
return sprintf('/^%s($|([\/].*)|([.].*))$/', $patternUrl);
} | php | private static function getRegularExpression($portalUrl)
{
$patternUrl = rtrim($portalUrl, '/');
$patternUrl = preg_quote($patternUrl);
$patternUrl = str_replace(['/', '\*'], ['\/', '([^\/.]+)'], $patternUrl);
return sprintf('/^%s($|([\/].*)|([.].*))$/', $patternUrl);
} | [
"private",
"static",
"function",
"getRegularExpression",
"(",
"$",
"portalUrl",
")",
"{",
"$",
"patternUrl",
"=",
"rtrim",
"(",
"$",
"portalUrl",
",",
"'/'",
")",
";",
"$",
"patternUrl",
"=",
"preg_quote",
"(",
"$",
"patternUrl",
")",
";",
"$",
"patternUrl",
"=",
"str_replace",
"(",
"[",
"'/'",
",",
"'\\*'",
"]",
",",
"[",
"'\\/'",
",",
"'([^\\/.]+)'",
"]",
",",
"$",
"patternUrl",
")",
";",
"return",
"sprintf",
"(",
"'/^%s($|([\\/].*)|([.].*))$/'",
",",
"$",
"patternUrl",
")",
";",
"}"
] | Returns regular expression to match given portal-url.
@param string $portalUrl
@return string | [
"Returns",
"regular",
"expression",
"to",
"match",
"given",
"portal",
"-",
"url",
"."
] | 6766a36cc2f0c807c59202bf7540a08c4ef31192 | https://github.com/sulu/sulu/blob/6766a36cc2f0c807c59202bf7540a08c4ef31192/src/Sulu/Component/Util/WildcardUrlUtil.php#L33-L40 | train |
sulu/sulu | src/Sulu/Component/Util/WildcardUrlUtil.php | WildcardUrlUtil.resolve | public static function resolve($url, $portalUrl)
{
$regexp = self::getRegularExpression($portalUrl);
if (preg_match($regexp, $url, $matches)) {
for ($i = 0, $countStar = substr_count($portalUrl, '*'); $i < $countStar; ++$i) {
$pos = strpos($portalUrl, '*');
if (false !== $pos) {
$portalUrl = substr_replace($portalUrl, $matches[$i + 1], $pos, 1);
}
}
return $portalUrl;
}
return;
} | php | public static function resolve($url, $portalUrl)
{
$regexp = self::getRegularExpression($portalUrl);
if (preg_match($regexp, $url, $matches)) {
for ($i = 0, $countStar = substr_count($portalUrl, '*'); $i < $countStar; ++$i) {
$pos = strpos($portalUrl, '*');
if (false !== $pos) {
$portalUrl = substr_replace($portalUrl, $matches[$i + 1], $pos, 1);
}
}
return $portalUrl;
}
return;
} | [
"public",
"static",
"function",
"resolve",
"(",
"$",
"url",
",",
"$",
"portalUrl",
")",
"{",
"$",
"regexp",
"=",
"self",
"::",
"getRegularExpression",
"(",
"$",
"portalUrl",
")",
";",
"if",
"(",
"preg_match",
"(",
"$",
"regexp",
",",
"$",
"url",
",",
"$",
"matches",
")",
")",
"{",
"for",
"(",
"$",
"i",
"=",
"0",
",",
"$",
"countStar",
"=",
"substr_count",
"(",
"$",
"portalUrl",
",",
"'*'",
")",
";",
"$",
"i",
"<",
"$",
"countStar",
";",
"++",
"$",
"i",
")",
"{",
"$",
"pos",
"=",
"strpos",
"(",
"$",
"portalUrl",
",",
"'*'",
")",
";",
"if",
"(",
"false",
"!==",
"$",
"pos",
")",
"{",
"$",
"portalUrl",
"=",
"substr_replace",
"(",
"$",
"portalUrl",
",",
"$",
"matches",
"[",
"$",
"i",
"+",
"1",
"]",
",",
"$",
"pos",
",",
"1",
")",
";",
"}",
"}",
"return",
"$",
"portalUrl",
";",
"}",
"return",
";",
"}"
] | Replaces wildcards with occurrences in the given url.
@param string $url
@param string $portalUrl
@return string | [
"Replaces",
"wildcards",
"with",
"occurrences",
"in",
"the",
"given",
"url",
"."
] | 6766a36cc2f0c807c59202bf7540a08c4ef31192 | https://github.com/sulu/sulu/blob/6766a36cc2f0c807c59202bf7540a08c4ef31192/src/Sulu/Component/Util/WildcardUrlUtil.php#L63-L79 | train |
sulu/sulu | src/Sulu/Bundle/ResourceBundle/Api/Filter.php | Filter.getConditionGroups | public function getConditionGroups()
{
$groups = $this->entity->getConditionGroups();
if ($groups) {
$result = [];
foreach ($groups as $group) {
$result[] = new ConditionGroup($group, $this->locale);
}
return $result;
}
return;
} | php | public function getConditionGroups()
{
$groups = $this->entity->getConditionGroups();
if ($groups) {
$result = [];
foreach ($groups as $group) {
$result[] = new ConditionGroup($group, $this->locale);
}
return $result;
}
return;
} | [
"public",
"function",
"getConditionGroups",
"(",
")",
"{",
"$",
"groups",
"=",
"$",
"this",
"->",
"entity",
"->",
"getConditionGroups",
"(",
")",
";",
"if",
"(",
"$",
"groups",
")",
"{",
"$",
"result",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"groups",
"as",
"$",
"group",
")",
"{",
"$",
"result",
"[",
"]",
"=",
"new",
"ConditionGroup",
"(",
"$",
"group",
",",
"$",
"this",
"->",
"locale",
")",
";",
"}",
"return",
"$",
"result",
";",
"}",
"return",
";",
"}"
] | Get conditionGroups.
@VirtualProperty
@SerializedName("conditionGroups")
@return null|ConditionGroup[] | [
"Get",
"conditionGroups",
"."
] | 6766a36cc2f0c807c59202bf7540a08c4ef31192 | https://github.com/sulu/sulu/blob/6766a36cc2f0c807c59202bf7540a08c4ef31192/src/Sulu/Bundle/ResourceBundle/Api/Filter.php#L100-L113 | train |
sulu/sulu | src/Sulu/Bundle/CustomUrlBundle/EventListener/CustomUrlSerializeEventSubscriber.php | CustomUrlSerializeEventSubscriber.onPostSerialize | public function onPostSerialize(ObjectEvent $event)
{
$customUrl = $event->getObject();
$visitor = $event->getVisitor();
if (!$customUrl instanceof CustomUrlDocument) {
return;
}
if (null !== $customUrl->getTargetDocument()) {
$visitor->addData('targetTitle', $customUrl->getTargetDocument()->getTitle());
$visitor->addData('targetDocument', $customUrl->getTargetDocument()->getUuid());
}
$visitor->addData(
'customUrl',
$this->generator->generate($customUrl->getBaseDomain(), $customUrl->getDomainParts())
);
$visitor->addData('creatorFullName', $this->userManager->getFullNameByUserId($customUrl->getCreator()));
$visitor->addData('changerFullName', $this->userManager->getFullNameByUserId($customUrl->getChanger()));
} | php | public function onPostSerialize(ObjectEvent $event)
{
$customUrl = $event->getObject();
$visitor = $event->getVisitor();
if (!$customUrl instanceof CustomUrlDocument) {
return;
}
if (null !== $customUrl->getTargetDocument()) {
$visitor->addData('targetTitle', $customUrl->getTargetDocument()->getTitle());
$visitor->addData('targetDocument', $customUrl->getTargetDocument()->getUuid());
}
$visitor->addData(
'customUrl',
$this->generator->generate($customUrl->getBaseDomain(), $customUrl->getDomainParts())
);
$visitor->addData('creatorFullName', $this->userManager->getFullNameByUserId($customUrl->getCreator()));
$visitor->addData('changerFullName', $this->userManager->getFullNameByUserId($customUrl->getChanger()));
} | [
"public",
"function",
"onPostSerialize",
"(",
"ObjectEvent",
"$",
"event",
")",
"{",
"$",
"customUrl",
"=",
"$",
"event",
"->",
"getObject",
"(",
")",
";",
"$",
"visitor",
"=",
"$",
"event",
"->",
"getVisitor",
"(",
")",
";",
"if",
"(",
"!",
"$",
"customUrl",
"instanceof",
"CustomUrlDocument",
")",
"{",
"return",
";",
"}",
"if",
"(",
"null",
"!==",
"$",
"customUrl",
"->",
"getTargetDocument",
"(",
")",
")",
"{",
"$",
"visitor",
"->",
"addData",
"(",
"'targetTitle'",
",",
"$",
"customUrl",
"->",
"getTargetDocument",
"(",
")",
"->",
"getTitle",
"(",
")",
")",
";",
"$",
"visitor",
"->",
"addData",
"(",
"'targetDocument'",
",",
"$",
"customUrl",
"->",
"getTargetDocument",
"(",
")",
"->",
"getUuid",
"(",
")",
")",
";",
"}",
"$",
"visitor",
"->",
"addData",
"(",
"'customUrl'",
",",
"$",
"this",
"->",
"generator",
"->",
"generate",
"(",
"$",
"customUrl",
"->",
"getBaseDomain",
"(",
")",
",",
"$",
"customUrl",
"->",
"getDomainParts",
"(",
")",
")",
")",
";",
"$",
"visitor",
"->",
"addData",
"(",
"'creatorFullName'",
",",
"$",
"this",
"->",
"userManager",
"->",
"getFullNameByUserId",
"(",
"$",
"customUrl",
"->",
"getCreator",
"(",
")",
")",
")",
";",
"$",
"visitor",
"->",
"addData",
"(",
"'changerFullName'",
",",
"$",
"this",
"->",
"userManager",
"->",
"getFullNameByUserId",
"(",
"$",
"customUrl",
"->",
"getChanger",
"(",
")",
")",
")",
";",
"}"
] | Add information to serialized custom-url document.
@param ObjectEvent $event | [
"Add",
"information",
"to",
"serialized",
"custom",
"-",
"url",
"document",
"."
] | 6766a36cc2f0c807c59202bf7540a08c4ef31192 | https://github.com/sulu/sulu/blob/6766a36cc2f0c807c59202bf7540a08c4ef31192/src/Sulu/Bundle/CustomUrlBundle/EventListener/CustomUrlSerializeEventSubscriber.php#L61-L82 | train |
sulu/sulu | src/Sulu/Bundle/WebsiteBundle/Analytics/AnalyticsManager.php | AnalyticsManager.setData | private function setData(Analytics $analytics, $webspaceKey, $data)
{
$analytics->setTitle($this->getValue($data, 'title'));
$analytics->setType($this->getValue($data, 'type'));
$analytics->setContent($this->getValue($data, 'content', ''));
$analytics->setAllDomains($this->getValue($data, 'allDomains', false));
$analytics->setWebspaceKey($webspaceKey);
$analytics->clearDomains();
if (!$analytics->isAllDomains()) {
foreach ($this->getValue($data, 'domains', []) as $domain) {
$domainEntity = $this->findOrCreateNewDomain($domain);
$analytics->addDomain($domainEntity);
}
}
} | php | private function setData(Analytics $analytics, $webspaceKey, $data)
{
$analytics->setTitle($this->getValue($data, 'title'));
$analytics->setType($this->getValue($data, 'type'));
$analytics->setContent($this->getValue($data, 'content', ''));
$analytics->setAllDomains($this->getValue($data, 'allDomains', false));
$analytics->setWebspaceKey($webspaceKey);
$analytics->clearDomains();
if (!$analytics->isAllDomains()) {
foreach ($this->getValue($data, 'domains', []) as $domain) {
$domainEntity = $this->findOrCreateNewDomain($domain);
$analytics->addDomain($domainEntity);
}
}
} | [
"private",
"function",
"setData",
"(",
"Analytics",
"$",
"analytics",
",",
"$",
"webspaceKey",
",",
"$",
"data",
")",
"{",
"$",
"analytics",
"->",
"setTitle",
"(",
"$",
"this",
"->",
"getValue",
"(",
"$",
"data",
",",
"'title'",
")",
")",
";",
"$",
"analytics",
"->",
"setType",
"(",
"$",
"this",
"->",
"getValue",
"(",
"$",
"data",
",",
"'type'",
")",
")",
";",
"$",
"analytics",
"->",
"setContent",
"(",
"$",
"this",
"->",
"getValue",
"(",
"$",
"data",
",",
"'content'",
",",
"''",
")",
")",
";",
"$",
"analytics",
"->",
"setAllDomains",
"(",
"$",
"this",
"->",
"getValue",
"(",
"$",
"data",
",",
"'allDomains'",
",",
"false",
")",
")",
";",
"$",
"analytics",
"->",
"setWebspaceKey",
"(",
"$",
"webspaceKey",
")",
";",
"$",
"analytics",
"->",
"clearDomains",
"(",
")",
";",
"if",
"(",
"!",
"$",
"analytics",
"->",
"isAllDomains",
"(",
")",
")",
"{",
"foreach",
"(",
"$",
"this",
"->",
"getValue",
"(",
"$",
"data",
",",
"'domains'",
",",
"[",
"]",
")",
"as",
"$",
"domain",
")",
"{",
"$",
"domainEntity",
"=",
"$",
"this",
"->",
"findOrCreateNewDomain",
"(",
"$",
"domain",
")",
";",
"$",
"analytics",
"->",
"addDomain",
"(",
"$",
"domainEntity",
")",
";",
"}",
"}",
"}"
] | Set data to given key.
@param Analytics $analytics
@param string $webspaceKey
@param array $data | [
"Set",
"data",
"to",
"given",
"key",
"."
] | 6766a36cc2f0c807c59202bf7540a08c4ef31192 | https://github.com/sulu/sulu/blob/6766a36cc2f0c807c59202bf7540a08c4ef31192/src/Sulu/Bundle/WebsiteBundle/Analytics/AnalyticsManager.php#L122-L138 | train |
sulu/sulu | src/Sulu/Bundle/ContactBundle/Entity/Url.php | Url.setUrlType | public function setUrlType(\Sulu\Bundle\ContactBundle\Entity\UrlType $urlType)
{
$this->urlType = $urlType;
return $this;
} | php | public function setUrlType(\Sulu\Bundle\ContactBundle\Entity\UrlType $urlType)
{
$this->urlType = $urlType;
return $this;
} | [
"public",
"function",
"setUrlType",
"(",
"\\",
"Sulu",
"\\",
"Bundle",
"\\",
"ContactBundle",
"\\",
"Entity",
"\\",
"UrlType",
"$",
"urlType",
")",
"{",
"$",
"this",
"->",
"urlType",
"=",
"$",
"urlType",
";",
"return",
"$",
"this",
";",
"}"
] | Set urlType.
@param \Sulu\Bundle\ContactBundle\Entity\UrlType $urlType
@return Url | [
"Set",
"urlType",
"."
] | 6766a36cc2f0c807c59202bf7540a08c4ef31192 | https://github.com/sulu/sulu/blob/6766a36cc2f0c807c59202bf7540a08c4ef31192/src/Sulu/Bundle/ContactBundle/Entity/Url.php#L101-L106 | train |
sulu/sulu | src/Sulu/Bundle/MediaBundle/Media/FormatCache/LocalFormatCache.php | LocalFormatCache.getIdFromUrl | protected function getIdFromUrl($url)
{
$fileName = basename($url);
$idParts = explode('-', $fileName);
if (count($idParts) < 2) {
throw new ImageProxyInvalidUrl('No `id` was found in the url');
}
$id = $idParts[0];
if (preg_match('/[^0-9]/', $id)) {
throw new ImageProxyInvalidUrl('The founded `id` was not a valid integer');
}
return $id;
} | php | protected function getIdFromUrl($url)
{
$fileName = basename($url);
$idParts = explode('-', $fileName);
if (count($idParts) < 2) {
throw new ImageProxyInvalidUrl('No `id` was found in the url');
}
$id = $idParts[0];
if (preg_match('/[^0-9]/', $id)) {
throw new ImageProxyInvalidUrl('The founded `id` was not a valid integer');
}
return $id;
} | [
"protected",
"function",
"getIdFromUrl",
"(",
"$",
"url",
")",
"{",
"$",
"fileName",
"=",
"basename",
"(",
"$",
"url",
")",
";",
"$",
"idParts",
"=",
"explode",
"(",
"'-'",
",",
"$",
"fileName",
")",
";",
"if",
"(",
"count",
"(",
"$",
"idParts",
")",
"<",
"2",
")",
"{",
"throw",
"new",
"ImageProxyInvalidUrl",
"(",
"'No `id` was found in the url'",
")",
";",
"}",
"$",
"id",
"=",
"$",
"idParts",
"[",
"0",
"]",
";",
"if",
"(",
"preg_match",
"(",
"'/[^0-9]/'",
",",
"$",
"id",
")",
")",
"{",
"throw",
"new",
"ImageProxyInvalidUrl",
"(",
"'The founded `id` was not a valid integer'",
")",
";",
"}",
"return",
"$",
"id",
";",
"}"
] | return the id of by a given url.
@param string $url
@return int
@throws \Sulu\Bundle\MediaBundle\Media\Exception\ImageProxyInvalidUrl | [
"return",
"the",
"id",
"of",
"by",
"a",
"given",
"url",
"."
] | 6766a36cc2f0c807c59202bf7540a08c4ef31192 | https://github.com/sulu/sulu/blob/6766a36cc2f0c807c59202bf7540a08c4ef31192/src/Sulu/Bundle/MediaBundle/Media/FormatCache/LocalFormatCache.php#L178-L194 | train |
sulu/sulu | src/Sulu/Bundle/MediaBundle/Media/FormatCache/LocalFormatCache.php | LocalFormatCache.getFormatFromUrl | protected function getFormatFromUrl($url)
{
$path = dirname($url);
$formatParts = array_reverse(explode('/', $path));
if (count($formatParts) < 2) {
throw new ImageProxyInvalidUrl('No `format` was found in the url');
}
$format = $formatParts[1];
return $format;
} | php | protected function getFormatFromUrl($url)
{
$path = dirname($url);
$formatParts = array_reverse(explode('/', $path));
if (count($formatParts) < 2) {
throw new ImageProxyInvalidUrl('No `format` was found in the url');
}
$format = $formatParts[1];
return $format;
} | [
"protected",
"function",
"getFormatFromUrl",
"(",
"$",
"url",
")",
"{",
"$",
"path",
"=",
"dirname",
"(",
"$",
"url",
")",
";",
"$",
"formatParts",
"=",
"array_reverse",
"(",
"explode",
"(",
"'/'",
",",
"$",
"path",
")",
")",
";",
"if",
"(",
"count",
"(",
"$",
"formatParts",
")",
"<",
"2",
")",
"{",
"throw",
"new",
"ImageProxyInvalidUrl",
"(",
"'No `format` was found in the url'",
")",
";",
"}",
"$",
"format",
"=",
"$",
"formatParts",
"[",
"1",
"]",
";",
"return",
"$",
"format",
";",
"}"
] | return the format by a given url.
@param string $url
@return string
@throws \Sulu\Bundle\MediaBundle\Media\Exception\ImageProxyInvalidUrl | [
"return",
"the",
"format",
"by",
"a",
"given",
"url",
"."
] | 6766a36cc2f0c807c59202bf7540a08c4ef31192 | https://github.com/sulu/sulu/blob/6766a36cc2f0c807c59202bf7540a08c4ef31192/src/Sulu/Bundle/MediaBundle/Media/FormatCache/LocalFormatCache.php#L215-L228 | train |
sulu/sulu | src/Sulu/Component/SmartContent/Orm/DataProviderRepositoryTrait.php | DataProviderRepositoryTrait.appendRelation | private function appendRelation(QueryBuilder $queryBuilder, $relation, $values, $operator, $alias)
{
switch ($operator) {
case 'or':
return $this->appendRelationOr($queryBuilder, $relation, $values, $alias);
case 'and':
return $this->appendRelationAnd($queryBuilder, $relation, $values, $alias);
}
return [];
} | php | private function appendRelation(QueryBuilder $queryBuilder, $relation, $values, $operator, $alias)
{
switch ($operator) {
case 'or':
return $this->appendRelationOr($queryBuilder, $relation, $values, $alias);
case 'and':
return $this->appendRelationAnd($queryBuilder, $relation, $values, $alias);
}
return [];
} | [
"private",
"function",
"appendRelation",
"(",
"QueryBuilder",
"$",
"queryBuilder",
",",
"$",
"relation",
",",
"$",
"values",
",",
"$",
"operator",
",",
"$",
"alias",
")",
"{",
"switch",
"(",
"$",
"operator",
")",
"{",
"case",
"'or'",
":",
"return",
"$",
"this",
"->",
"appendRelationOr",
"(",
"$",
"queryBuilder",
",",
"$",
"relation",
",",
"$",
"values",
",",
"$",
"alias",
")",
";",
"case",
"'and'",
":",
"return",
"$",
"this",
"->",
"appendRelationAnd",
"(",
"$",
"queryBuilder",
",",
"$",
"relation",
",",
"$",
"values",
",",
"$",
"alias",
")",
";",
"}",
"return",
"[",
"]",
";",
"}"
] | Append tags to query builder with given operator.
@param QueryBuilder $queryBuilder
@param string $relation
@param int[] $values
@param string $operator "and" or "or"
@param string $alias
@return array parameter for the query | [
"Append",
"tags",
"to",
"query",
"builder",
"with",
"given",
"operator",
"."
] | 6766a36cc2f0c807c59202bf7540a08c4ef31192 | https://github.com/sulu/sulu/blob/6766a36cc2f0c807c59202bf7540a08c4ef31192/src/Sulu/Component/SmartContent/Orm/DataProviderRepositoryTrait.php#L211-L221 | train |
sulu/sulu | src/Sulu/Component/SmartContent/Orm/DataProviderRepositoryTrait.php | DataProviderRepositoryTrait.appendRelationOr | private function appendRelationOr(QueryBuilder $queryBuilder, $relation, $values, $alias)
{
$queryBuilder->leftJoin($relation, $alias)
->andWhere($alias . '.id IN (:' . $alias . ')');
return [$alias => $values];
} | php | private function appendRelationOr(QueryBuilder $queryBuilder, $relation, $values, $alias)
{
$queryBuilder->leftJoin($relation, $alias)
->andWhere($alias . '.id IN (:' . $alias . ')');
return [$alias => $values];
} | [
"private",
"function",
"appendRelationOr",
"(",
"QueryBuilder",
"$",
"queryBuilder",
",",
"$",
"relation",
",",
"$",
"values",
",",
"$",
"alias",
")",
"{",
"$",
"queryBuilder",
"->",
"leftJoin",
"(",
"$",
"relation",
",",
"$",
"alias",
")",
"->",
"andWhere",
"(",
"$",
"alias",
".",
"'.id IN (:'",
".",
"$",
"alias",
".",
"')'",
")",
";",
"return",
"[",
"$",
"alias",
"=>",
"$",
"values",
"]",
";",
"}"
] | Append tags to query builder with "or" operator.
@param QueryBuilder $queryBuilder
@param string $relation
@param int[] $values
@param string $alias
@return array parameter for the query | [
"Append",
"tags",
"to",
"query",
"builder",
"with",
"or",
"operator",
"."
] | 6766a36cc2f0c807c59202bf7540a08c4ef31192 | https://github.com/sulu/sulu/blob/6766a36cc2f0c807c59202bf7540a08c4ef31192/src/Sulu/Component/SmartContent/Orm/DataProviderRepositoryTrait.php#L233-L239 | train |
sulu/sulu | src/Sulu/Component/SmartContent/Orm/DataProviderRepositoryTrait.php | DataProviderRepositoryTrait.appendRelationAnd | private function appendRelationAnd(QueryBuilder $queryBuilder, $relation, $values, $alias)
{
$parameter = [];
$expr = $queryBuilder->expr()->andX();
$length = count($values);
for ($i = 0; $i < $length; ++$i) {
$queryBuilder->leftJoin($relation, $alias . $i);
$expr->add($queryBuilder->expr()->eq($alias . $i . '.id', ':' . $alias . $i));
$parameter[$alias . $i] = $values[$i];
}
$queryBuilder->andWhere($expr);
return $parameter;
} | php | private function appendRelationAnd(QueryBuilder $queryBuilder, $relation, $values, $alias)
{
$parameter = [];
$expr = $queryBuilder->expr()->andX();
$length = count($values);
for ($i = 0; $i < $length; ++$i) {
$queryBuilder->leftJoin($relation, $alias . $i);
$expr->add($queryBuilder->expr()->eq($alias . $i . '.id', ':' . $alias . $i));
$parameter[$alias . $i] = $values[$i];
}
$queryBuilder->andWhere($expr);
return $parameter;
} | [
"private",
"function",
"appendRelationAnd",
"(",
"QueryBuilder",
"$",
"queryBuilder",
",",
"$",
"relation",
",",
"$",
"values",
",",
"$",
"alias",
")",
"{",
"$",
"parameter",
"=",
"[",
"]",
";",
"$",
"expr",
"=",
"$",
"queryBuilder",
"->",
"expr",
"(",
")",
"->",
"andX",
"(",
")",
";",
"$",
"length",
"=",
"count",
"(",
"$",
"values",
")",
";",
"for",
"(",
"$",
"i",
"=",
"0",
";",
"$",
"i",
"<",
"$",
"length",
";",
"++",
"$",
"i",
")",
"{",
"$",
"queryBuilder",
"->",
"leftJoin",
"(",
"$",
"relation",
",",
"$",
"alias",
".",
"$",
"i",
")",
";",
"$",
"expr",
"->",
"add",
"(",
"$",
"queryBuilder",
"->",
"expr",
"(",
")",
"->",
"eq",
"(",
"$",
"alias",
".",
"$",
"i",
".",
"'.id'",
",",
"':'",
".",
"$",
"alias",
".",
"$",
"i",
")",
")",
";",
"$",
"parameter",
"[",
"$",
"alias",
".",
"$",
"i",
"]",
"=",
"$",
"values",
"[",
"$",
"i",
"]",
";",
"}",
"$",
"queryBuilder",
"->",
"andWhere",
"(",
"$",
"expr",
")",
";",
"return",
"$",
"parameter",
";",
"}"
] | Append tags to query builder with "and" operator.
@param QueryBuilder $queryBuilder
@param string $relation
@param int[] $values
@param string $alias
@return array parameter for the query | [
"Append",
"tags",
"to",
"query",
"builder",
"with",
"and",
"operator",
"."
] | 6766a36cc2f0c807c59202bf7540a08c4ef31192 | https://github.com/sulu/sulu/blob/6766a36cc2f0c807c59202bf7540a08c4ef31192/src/Sulu/Component/SmartContent/Orm/DataProviderRepositoryTrait.php#L251-L267 | train |
sulu/sulu | src/Sulu/Component/Content/Mapper/Event/ContentNodeDeleteEvent.php | ContentNodeDeleteEvent.getStructure | public function getStructure($locale)
{
return $this->contentMapper->loadShallowStructureByNode($this->node, $locale, $this->webspace);
} | php | public function getStructure($locale)
{
return $this->contentMapper->loadShallowStructureByNode($this->node, $locale, $this->webspace);
} | [
"public",
"function",
"getStructure",
"(",
"$",
"locale",
")",
"{",
"return",
"$",
"this",
"->",
"contentMapper",
"->",
"loadShallowStructureByNode",
"(",
"$",
"this",
"->",
"node",
",",
"$",
"locale",
",",
"$",
"this",
"->",
"webspace",
")",
";",
"}"
] | Return the structure which was deleted.
@return StructureInterface | [
"Return",
"the",
"structure",
"which",
"was",
"deleted",
"."
] | 6766a36cc2f0c807c59202bf7540a08c4ef31192 | https://github.com/sulu/sulu/blob/6766a36cc2f0c807c59202bf7540a08c4ef31192/src/Sulu/Component/Content/Mapper/Event/ContentNodeDeleteEvent.php#L71-L74 | train |
sulu/sulu | src/Sulu/Component/Webspace/Analyzer/Attributes/PortalInformationRequestProcessor.php | PortalInformationRequestProcessor.getResourceLocatorFromRequest | private function getResourceLocatorFromRequest(PortalInformation $portalInformation, Request $request, $path)
{
// extract file and extension info
$pathParts = explode('/', $path);
$fileInfo = explode('.', array_pop($pathParts));
$path = rtrim(implode('/', $pathParts), '/') . '/' . $fileInfo[0];
$formatResult = null;
if (count($fileInfo) > 1) {
$formatResult = end($fileInfo);
}
$resourceLocator = substr(
$request->getHost() . $path,
strlen($portalInformation->getUrl())
);
return [$resourceLocator, $formatResult];
} | php | private function getResourceLocatorFromRequest(PortalInformation $portalInformation, Request $request, $path)
{
// extract file and extension info
$pathParts = explode('/', $path);
$fileInfo = explode('.', array_pop($pathParts));
$path = rtrim(implode('/', $pathParts), '/') . '/' . $fileInfo[0];
$formatResult = null;
if (count($fileInfo) > 1) {
$formatResult = end($fileInfo);
}
$resourceLocator = substr(
$request->getHost() . $path,
strlen($portalInformation->getUrl())
);
return [$resourceLocator, $formatResult];
} | [
"private",
"function",
"getResourceLocatorFromRequest",
"(",
"PortalInformation",
"$",
"portalInformation",
",",
"Request",
"$",
"request",
",",
"$",
"path",
")",
"{",
"// extract file and extension info",
"$",
"pathParts",
"=",
"explode",
"(",
"'/'",
",",
"$",
"path",
")",
";",
"$",
"fileInfo",
"=",
"explode",
"(",
"'.'",
",",
"array_pop",
"(",
"$",
"pathParts",
")",
")",
";",
"$",
"path",
"=",
"rtrim",
"(",
"implode",
"(",
"'/'",
",",
"$",
"pathParts",
")",
",",
"'/'",
")",
".",
"'/'",
".",
"$",
"fileInfo",
"[",
"0",
"]",
";",
"$",
"formatResult",
"=",
"null",
";",
"if",
"(",
"count",
"(",
"$",
"fileInfo",
")",
">",
"1",
")",
"{",
"$",
"formatResult",
"=",
"end",
"(",
"$",
"fileInfo",
")",
";",
"}",
"$",
"resourceLocator",
"=",
"substr",
"(",
"$",
"request",
"->",
"getHost",
"(",
")",
".",
"$",
"path",
",",
"strlen",
"(",
"$",
"portalInformation",
"->",
"getUrl",
"(",
")",
")",
")",
";",
"return",
"[",
"$",
"resourceLocator",
",",
"$",
"formatResult",
"]",
";",
"}"
] | Returns resource locator and format of current request.
@param PortalInformation $portalInformation
@param Request $request
@param string $path
@return array | [
"Returns",
"resource",
"locator",
"and",
"format",
"of",
"current",
"request",
"."
] | 6766a36cc2f0c807c59202bf7540a08c4ef31192 | https://github.com/sulu/sulu/blob/6766a36cc2f0c807c59202bf7540a08c4ef31192/src/Sulu/Component/Webspace/Analyzer/Attributes/PortalInformationRequestProcessor.php#L98-L116 | train |
sulu/sulu | src/Sulu/Component/SmartContent/ContentType.php | ContentType.getProvider | private function getProvider(PropertyInterface $property)
{
$params = $property->getParams();
$providerAlias = 'pages';
if (array_key_exists('provider', $params)) {
$providerAlias = $params['provider']->getValue();
}
return $this->dataProviderPool->get($providerAlias);
} | php | private function getProvider(PropertyInterface $property)
{
$params = $property->getParams();
$providerAlias = 'pages';
if (array_key_exists('provider', $params)) {
$providerAlias = $params['provider']->getValue();
}
return $this->dataProviderPool->get($providerAlias);
} | [
"private",
"function",
"getProvider",
"(",
"PropertyInterface",
"$",
"property",
")",
"{",
"$",
"params",
"=",
"$",
"property",
"->",
"getParams",
"(",
")",
";",
"$",
"providerAlias",
"=",
"'pages'",
";",
"if",
"(",
"array_key_exists",
"(",
"'provider'",
",",
"$",
"params",
")",
")",
"{",
"$",
"providerAlias",
"=",
"$",
"params",
"[",
"'provider'",
"]",
"->",
"getValue",
"(",
")",
";",
"}",
"return",
"$",
"this",
"->",
"dataProviderPool",
"->",
"get",
"(",
"$",
"providerAlias",
")",
";",
"}"
] | Returns provider for given property.
@param PropertyInterface $property
@return DataProviderInterface | [
"Returns",
"provider",
"for",
"given",
"property",
"."
] | 6766a36cc2f0c807c59202bf7540a08c4ef31192 | https://github.com/sulu/sulu/blob/6766a36cc2f0c807c59202bf7540a08c4ef31192/src/Sulu/Component/SmartContent/ContentType.php#L377-L387 | train |
sulu/sulu | src/Sulu/Component/SmartContent/ContentType.php | ContentType.getCurrentPage | private function getCurrentPage($pageParameter)
{
if (null === $this->requestStack->getCurrentRequest()) {
return 1;
}
$page = $this->requestStack->getCurrentRequest()->get($pageParameter, 1);
if ($page < 1 || $page > PHP_INT_MAX) {
throw new PageOutOfBoundsException($page);
}
return $page;
} | php | private function getCurrentPage($pageParameter)
{
if (null === $this->requestStack->getCurrentRequest()) {
return 1;
}
$page = $this->requestStack->getCurrentRequest()->get($pageParameter, 1);
if ($page < 1 || $page > PHP_INT_MAX) {
throw new PageOutOfBoundsException($page);
}
return $page;
} | [
"private",
"function",
"getCurrentPage",
"(",
"$",
"pageParameter",
")",
"{",
"if",
"(",
"null",
"===",
"$",
"this",
"->",
"requestStack",
"->",
"getCurrentRequest",
"(",
")",
")",
"{",
"return",
"1",
";",
"}",
"$",
"page",
"=",
"$",
"this",
"->",
"requestStack",
"->",
"getCurrentRequest",
"(",
")",
"->",
"get",
"(",
"$",
"pageParameter",
",",
"1",
")",
";",
"if",
"(",
"$",
"page",
"<",
"1",
"||",
"$",
"page",
">",
"PHP_INT_MAX",
")",
"{",
"throw",
"new",
"PageOutOfBoundsException",
"(",
"$",
"page",
")",
";",
"}",
"return",
"$",
"page",
";",
"}"
] | Determine current page from current request.
@param string $pageParameter
@return int
@throws PageOutOfBoundsException | [
"Determine",
"current",
"page",
"from",
"current",
"request",
"."
] | 6766a36cc2f0c807c59202bf7540a08c4ef31192 | https://github.com/sulu/sulu/blob/6766a36cc2f0c807c59202bf7540a08c4ef31192/src/Sulu/Component/SmartContent/ContentType.php#L398-L410 | train |
sulu/sulu | src/Sulu/Component/Rest/Csv/CsvHandler.php | CsvHandler.createResponse | public function createResponse(ViewHandler $handler, View $view, Request $request, $format)
{
if (!$view->getData() instanceof ListRepresentation) {
throw new ObjectNotSupportedException($view);
}
$viewData = $view->getData();
$data = new CallbackCollection($viewData->getData(), [$this, 'prepareData']);
$fileName = sprintf('%s.csv', $viewData->getRel());
$config = new ExporterConfig();
$exporter = new Exporter($config);
$data->rewind();
if ($row = $data->current()) {
$config->setColumnHeaders(array_keys($row));
}
$config->setDelimiter($this->convertValue($request->get('delimiter', ';'), self::$delimiterMap));
$config->setNewline($this->convertValue($request->get('newLine', '\\n'), self::$newLineMap));
$config->setEnclosure($request->get('enclosure', '"'));
$config->setEscape($request->get('escape', '\\'));
$response = new StreamedResponse();
$disposition = $response->headers->makeDisposition(
ResponseHeaderBag::DISPOSITION_ATTACHMENT,
$fileName,
$fileName
);
$response->headers->set('Content-Type', 'text/csv');
$response->headers->set('Content-Disposition', $disposition);
$response->setCallback(
function() use ($data, $exporter) {
$exporter->export('php://output', $data);
}
);
$response->send();
return $response;
} | php | public function createResponse(ViewHandler $handler, View $view, Request $request, $format)
{
if (!$view->getData() instanceof ListRepresentation) {
throw new ObjectNotSupportedException($view);
}
$viewData = $view->getData();
$data = new CallbackCollection($viewData->getData(), [$this, 'prepareData']);
$fileName = sprintf('%s.csv', $viewData->getRel());
$config = new ExporterConfig();
$exporter = new Exporter($config);
$data->rewind();
if ($row = $data->current()) {
$config->setColumnHeaders(array_keys($row));
}
$config->setDelimiter($this->convertValue($request->get('delimiter', ';'), self::$delimiterMap));
$config->setNewline($this->convertValue($request->get('newLine', '\\n'), self::$newLineMap));
$config->setEnclosure($request->get('enclosure', '"'));
$config->setEscape($request->get('escape', '\\'));
$response = new StreamedResponse();
$disposition = $response->headers->makeDisposition(
ResponseHeaderBag::DISPOSITION_ATTACHMENT,
$fileName,
$fileName
);
$response->headers->set('Content-Type', 'text/csv');
$response->headers->set('Content-Disposition', $disposition);
$response->setCallback(
function() use ($data, $exporter) {
$exporter->export('php://output', $data);
}
);
$response->send();
return $response;
} | [
"public",
"function",
"createResponse",
"(",
"ViewHandler",
"$",
"handler",
",",
"View",
"$",
"view",
",",
"Request",
"$",
"request",
",",
"$",
"format",
")",
"{",
"if",
"(",
"!",
"$",
"view",
"->",
"getData",
"(",
")",
"instanceof",
"ListRepresentation",
")",
"{",
"throw",
"new",
"ObjectNotSupportedException",
"(",
"$",
"view",
")",
";",
"}",
"$",
"viewData",
"=",
"$",
"view",
"->",
"getData",
"(",
")",
";",
"$",
"data",
"=",
"new",
"CallbackCollection",
"(",
"$",
"viewData",
"->",
"getData",
"(",
")",
",",
"[",
"$",
"this",
",",
"'prepareData'",
"]",
")",
";",
"$",
"fileName",
"=",
"sprintf",
"(",
"'%s.csv'",
",",
"$",
"viewData",
"->",
"getRel",
"(",
")",
")",
";",
"$",
"config",
"=",
"new",
"ExporterConfig",
"(",
")",
";",
"$",
"exporter",
"=",
"new",
"Exporter",
"(",
"$",
"config",
")",
";",
"$",
"data",
"->",
"rewind",
"(",
")",
";",
"if",
"(",
"$",
"row",
"=",
"$",
"data",
"->",
"current",
"(",
")",
")",
"{",
"$",
"config",
"->",
"setColumnHeaders",
"(",
"array_keys",
"(",
"$",
"row",
")",
")",
";",
"}",
"$",
"config",
"->",
"setDelimiter",
"(",
"$",
"this",
"->",
"convertValue",
"(",
"$",
"request",
"->",
"get",
"(",
"'delimiter'",
",",
"';'",
")",
",",
"self",
"::",
"$",
"delimiterMap",
")",
")",
";",
"$",
"config",
"->",
"setNewline",
"(",
"$",
"this",
"->",
"convertValue",
"(",
"$",
"request",
"->",
"get",
"(",
"'newLine'",
",",
"'\\\\n'",
")",
",",
"self",
"::",
"$",
"newLineMap",
")",
")",
";",
"$",
"config",
"->",
"setEnclosure",
"(",
"$",
"request",
"->",
"get",
"(",
"'enclosure'",
",",
"'\"'",
")",
")",
";",
"$",
"config",
"->",
"setEscape",
"(",
"$",
"request",
"->",
"get",
"(",
"'escape'",
",",
"'\\\\'",
")",
")",
";",
"$",
"response",
"=",
"new",
"StreamedResponse",
"(",
")",
";",
"$",
"disposition",
"=",
"$",
"response",
"->",
"headers",
"->",
"makeDisposition",
"(",
"ResponseHeaderBag",
"::",
"DISPOSITION_ATTACHMENT",
",",
"$",
"fileName",
",",
"$",
"fileName",
")",
";",
"$",
"response",
"->",
"headers",
"->",
"set",
"(",
"'Content-Type'",
",",
"'text/csv'",
")",
";",
"$",
"response",
"->",
"headers",
"->",
"set",
"(",
"'Content-Disposition'",
",",
"$",
"disposition",
")",
";",
"$",
"response",
"->",
"setCallback",
"(",
"function",
"(",
")",
"use",
"(",
"$",
"data",
",",
"$",
"exporter",
")",
"{",
"$",
"exporter",
"->",
"export",
"(",
"'php://output'",
",",
"$",
"data",
")",
";",
"}",
")",
";",
"$",
"response",
"->",
"send",
"(",
")",
";",
"return",
"$",
"response",
";",
"}"
] | Handles response for csv-request.
@param ViewHandler $handler
@param View $view
@param Request $request
@param string $format
@return Response
@throws ObjectNotSupportedException | [
"Handles",
"response",
"for",
"csv",
"-",
"request",
"."
] | 6766a36cc2f0c807c59202bf7540a08c4ef31192 | https://github.com/sulu/sulu/blob/6766a36cc2f0c807c59202bf7540a08c4ef31192/src/Sulu/Component/Rest/Csv/CsvHandler.php#L74-L113 | train |
sulu/sulu | src/Sulu/Component/Rest/Csv/CsvHandler.php | CsvHandler.prepareData | public function prepareData($row)
{
if (!$row) {
return $row;
}
if (!is_array($row)) {
$row = $this->serializer->serialize($row, 'array', SerializationContext::create()->setSerializeNull(true));
}
foreach ($row as $key => $value) {
if ($value instanceof \DateTime) {
$row[$key] = $value->format(\DateTime::RFC3339);
} elseif (is_bool($value)) {
$row[$key] = true === $value ? 1 : 0;
} elseif (is_array($value) || is_object($value)) {
$row[$key] = json_encode($value);
}
}
return $row;
} | php | public function prepareData($row)
{
if (!$row) {
return $row;
}
if (!is_array($row)) {
$row = $this->serializer->serialize($row, 'array', SerializationContext::create()->setSerializeNull(true));
}
foreach ($row as $key => $value) {
if ($value instanceof \DateTime) {
$row[$key] = $value->format(\DateTime::RFC3339);
} elseif (is_bool($value)) {
$row[$key] = true === $value ? 1 : 0;
} elseif (is_array($value) || is_object($value)) {
$row[$key] = json_encode($value);
}
}
return $row;
} | [
"public",
"function",
"prepareData",
"(",
"$",
"row",
")",
"{",
"if",
"(",
"!",
"$",
"row",
")",
"{",
"return",
"$",
"row",
";",
"}",
"if",
"(",
"!",
"is_array",
"(",
"$",
"row",
")",
")",
"{",
"$",
"row",
"=",
"$",
"this",
"->",
"serializer",
"->",
"serialize",
"(",
"$",
"row",
",",
"'array'",
",",
"SerializationContext",
"::",
"create",
"(",
")",
"->",
"setSerializeNull",
"(",
"true",
")",
")",
";",
"}",
"foreach",
"(",
"$",
"row",
"as",
"$",
"key",
"=>",
"$",
"value",
")",
"{",
"if",
"(",
"$",
"value",
"instanceof",
"\\",
"DateTime",
")",
"{",
"$",
"row",
"[",
"$",
"key",
"]",
"=",
"$",
"value",
"->",
"format",
"(",
"\\",
"DateTime",
"::",
"RFC3339",
")",
";",
"}",
"elseif",
"(",
"is_bool",
"(",
"$",
"value",
")",
")",
"{",
"$",
"row",
"[",
"$",
"key",
"]",
"=",
"true",
"===",
"$",
"value",
"?",
"1",
":",
"0",
";",
"}",
"elseif",
"(",
"is_array",
"(",
"$",
"value",
")",
"||",
"is_object",
"(",
"$",
"value",
")",
")",
"{",
"$",
"row",
"[",
"$",
"key",
"]",
"=",
"json_encode",
"(",
"$",
"value",
")",
";",
"}",
"}",
"return",
"$",
"row",
";",
"}"
] | The exporter is not able to write DateTime objects into csv. This method converts them to string.
@param mixed $row
@return array | [
"The",
"exporter",
"is",
"not",
"able",
"to",
"write",
"DateTime",
"objects",
"into",
"csv",
".",
"This",
"method",
"converts",
"them",
"to",
"string",
"."
] | 6766a36cc2f0c807c59202bf7540a08c4ef31192 | https://github.com/sulu/sulu/blob/6766a36cc2f0c807c59202bf7540a08c4ef31192/src/Sulu/Component/Rest/Csv/CsvHandler.php#L122-L143 | train |
sulu/sulu | src/Sulu/Bundle/PersistenceBundle/PersistenceBundleTrait.php | PersistenceBundleTrait.buildPersistence | public function buildPersistence(array $interfaces, ContainerBuilder $container)
{
if (!empty($interfaces)) {
$container->addCompilerPass(
new ResolveTargetEntitiesPass($interfaces)
);
}
} | php | public function buildPersistence(array $interfaces, ContainerBuilder $container)
{
if (!empty($interfaces)) {
$container->addCompilerPass(
new ResolveTargetEntitiesPass($interfaces)
);
}
} | [
"public",
"function",
"buildPersistence",
"(",
"array",
"$",
"interfaces",
",",
"ContainerBuilder",
"$",
"container",
")",
"{",
"if",
"(",
"!",
"empty",
"(",
"$",
"interfaces",
")",
")",
"{",
"$",
"container",
"->",
"addCompilerPass",
"(",
"new",
"ResolveTargetEntitiesPass",
"(",
"$",
"interfaces",
")",
")",
";",
"}",
"}"
] | Build persistence adds a `ResolveTargetEntitiesPass` for the given interfaces.
@param array $interfaces Target entities resolver configuration.
Mapping interfaces to a concrete implementation
@param ContainerBuilder $container | [
"Build",
"persistence",
"adds",
"a",
"ResolveTargetEntitiesPass",
"for",
"the",
"given",
"interfaces",
"."
] | 6766a36cc2f0c807c59202bf7540a08c4ef31192 | https://github.com/sulu/sulu/blob/6766a36cc2f0c807c59202bf7540a08c4ef31192/src/Sulu/Bundle/PersistenceBundle/PersistenceBundleTrait.php#L30-L37 | train |
sulu/sulu | src/Sulu/Bundle/PageBundle/Resources/phpcr-migrations/Version201511240844.php | Version201511240844.up | public function up(SessionInterface $session)
{
$this->session = $session;
$this->iterateStructures(true);
$this->upgradeExternalLinks(true);
} | php | public function up(SessionInterface $session)
{
$this->session = $session;
$this->iterateStructures(true);
$this->upgradeExternalLinks(true);
} | [
"public",
"function",
"up",
"(",
"SessionInterface",
"$",
"session",
")",
"{",
"$",
"this",
"->",
"session",
"=",
"$",
"session",
";",
"$",
"this",
"->",
"iterateStructures",
"(",
"true",
")",
";",
"$",
"this",
"->",
"upgradeExternalLinks",
"(",
"true",
")",
";",
"}"
] | Migrate the repository up.
@param SessionInterface $session | [
"Migrate",
"the",
"repository",
"up",
"."
] | 6766a36cc2f0c807c59202bf7540a08c4ef31192 | https://github.com/sulu/sulu/blob/6766a36cc2f0c807c59202bf7540a08c4ef31192/src/Sulu/Bundle/PageBundle/Resources/phpcr-migrations/Version201511240844.php#L79-L84 | train |
sulu/sulu | src/Sulu/Bundle/PageBundle/Resources/phpcr-migrations/Version201511240844.php | Version201511240844.down | public function down(SessionInterface $session)
{
$this->session = $session;
$this->iterateStructures(false);
$this->upgradeExternalLinks(false);
} | php | public function down(SessionInterface $session)
{
$this->session = $session;
$this->iterateStructures(false);
$this->upgradeExternalLinks(false);
} | [
"public",
"function",
"down",
"(",
"SessionInterface",
"$",
"session",
")",
"{",
"$",
"this",
"->",
"session",
"=",
"$",
"session",
";",
"$",
"this",
"->",
"iterateStructures",
"(",
"false",
")",
";",
"$",
"this",
"->",
"upgradeExternalLinks",
"(",
"false",
")",
";",
"}"
] | Migrate the system down.
@param SessionInterface $session | [
"Migrate",
"the",
"system",
"down",
"."
] | 6766a36cc2f0c807c59202bf7540a08c4ef31192 | https://github.com/sulu/sulu/blob/6766a36cc2f0c807c59202bf7540a08c4ef31192/src/Sulu/Bundle/PageBundle/Resources/phpcr-migrations/Version201511240844.php#L91-L96 | train |
sulu/sulu | src/Sulu/Bundle/PageBundle/Resources/phpcr-migrations/Version201511240844.php | Version201511240844.upgradeExternalLinks | private function upgradeExternalLinks($addScheme)
{
foreach ($this->localizationManager->getLocalizations() as $localization) {
$rows = $this->session->getWorkspace()->getQueryManager()->createQuery(
sprintf(
'SELECT * FROM [nt:unstructured] WHERE [%s] = "%s"',
$this->propertyEncoder->localizedSystemName('nodeType', $localization->getLocale()),
RedirectType::EXTERNAL
),
'JCR-SQL2'
)->execute();
$name = $this->propertyEncoder->localizedSystemName('external', $localization->getLocale());
foreach ($rows->getNodes() as $node) {
/** @var NodeInterface $node */
$value = $node->getPropertyValue($name);
if ($addScheme) {
$this->upgradeUrl($value);
} else {
$this->downgradeUrl($value);
}
$node->setProperty($name, $value);
}
}
} | php | private function upgradeExternalLinks($addScheme)
{
foreach ($this->localizationManager->getLocalizations() as $localization) {
$rows = $this->session->getWorkspace()->getQueryManager()->createQuery(
sprintf(
'SELECT * FROM [nt:unstructured] WHERE [%s] = "%s"',
$this->propertyEncoder->localizedSystemName('nodeType', $localization->getLocale()),
RedirectType::EXTERNAL
),
'JCR-SQL2'
)->execute();
$name = $this->propertyEncoder->localizedSystemName('external', $localization->getLocale());
foreach ($rows->getNodes() as $node) {
/** @var NodeInterface $node */
$value = $node->getPropertyValue($name);
if ($addScheme) {
$this->upgradeUrl($value);
} else {
$this->downgradeUrl($value);
}
$node->setProperty($name, $value);
}
}
} | [
"private",
"function",
"upgradeExternalLinks",
"(",
"$",
"addScheme",
")",
"{",
"foreach",
"(",
"$",
"this",
"->",
"localizationManager",
"->",
"getLocalizations",
"(",
")",
"as",
"$",
"localization",
")",
"{",
"$",
"rows",
"=",
"$",
"this",
"->",
"session",
"->",
"getWorkspace",
"(",
")",
"->",
"getQueryManager",
"(",
")",
"->",
"createQuery",
"(",
"sprintf",
"(",
"'SELECT * FROM [nt:unstructured] WHERE [%s] = \"%s\"'",
",",
"$",
"this",
"->",
"propertyEncoder",
"->",
"localizedSystemName",
"(",
"'nodeType'",
",",
"$",
"localization",
"->",
"getLocale",
"(",
")",
")",
",",
"RedirectType",
"::",
"EXTERNAL",
")",
",",
"'JCR-SQL2'",
")",
"->",
"execute",
"(",
")",
";",
"$",
"name",
"=",
"$",
"this",
"->",
"propertyEncoder",
"->",
"localizedSystemName",
"(",
"'external'",
",",
"$",
"localization",
"->",
"getLocale",
"(",
")",
")",
";",
"foreach",
"(",
"$",
"rows",
"->",
"getNodes",
"(",
")",
"as",
"$",
"node",
")",
"{",
"/** @var NodeInterface $node */",
"$",
"value",
"=",
"$",
"node",
"->",
"getPropertyValue",
"(",
"$",
"name",
")",
";",
"if",
"(",
"$",
"addScheme",
")",
"{",
"$",
"this",
"->",
"upgradeUrl",
"(",
"$",
"value",
")",
";",
"}",
"else",
"{",
"$",
"this",
"->",
"downgradeUrl",
"(",
"$",
"value",
")",
";",
"}",
"$",
"node",
"->",
"setProperty",
"(",
"$",
"name",
",",
"$",
"value",
")",
";",
"}",
"}",
"}"
] | External links are easily updated by fetching all nodes with the external redirect type, and add or remove the
scheme to the external property.
@param bool $addScheme Adds the scheme to URLs if true, removes the scheme otherwise | [
"External",
"links",
"are",
"easily",
"updated",
"by",
"fetching",
"all",
"nodes",
"with",
"the",
"external",
"redirect",
"type",
"and",
"add",
"or",
"remove",
"the",
"scheme",
"to",
"the",
"external",
"property",
"."
] | 6766a36cc2f0c807c59202bf7540a08c4ef31192 | https://github.com/sulu/sulu/blob/6766a36cc2f0c807c59202bf7540a08c4ef31192/src/Sulu/Bundle/PageBundle/Resources/phpcr-migrations/Version201511240844.php#L104-L130 | train |
sulu/sulu | src/Sulu/Bundle/PageBundle/Resources/phpcr-migrations/Version201511240844.php | Version201511240844.iterateStructures | private function iterateStructures($addScheme)
{
$properties = [];
// find templates containing URL fields
$structureMetadatas = array_merge(
$this->structureMetadataFactory->getStructures('page'),
$this->structureMetadataFactory->getStructures('snippet')
);
$structureMetadatas = array_filter(
$structureMetadatas,
function(StructureMetadata $structureMetadata) use (&$properties) {
$structureName = $structureMetadata->getName();
$this->findUrlProperties($structureMetadata, $properties);
return !empty($properties[$structureName]) || !empty($blockProperties[$structureName]);
}
);
foreach ($structureMetadatas as $structureMetadata) {
$this->iterateStructureNodes(
$structureMetadata,
$properties[$structureMetadata->getName()],
$addScheme
);
}
$this->documentManager->flush();
} | php | private function iterateStructures($addScheme)
{
$properties = [];
// find templates containing URL fields
$structureMetadatas = array_merge(
$this->structureMetadataFactory->getStructures('page'),
$this->structureMetadataFactory->getStructures('snippet')
);
$structureMetadatas = array_filter(
$structureMetadatas,
function(StructureMetadata $structureMetadata) use (&$properties) {
$structureName = $structureMetadata->getName();
$this->findUrlProperties($structureMetadata, $properties);
return !empty($properties[$structureName]) || !empty($blockProperties[$structureName]);
}
);
foreach ($structureMetadatas as $structureMetadata) {
$this->iterateStructureNodes(
$structureMetadata,
$properties[$structureMetadata->getName()],
$addScheme
);
}
$this->documentManager->flush();
} | [
"private",
"function",
"iterateStructures",
"(",
"$",
"addScheme",
")",
"{",
"$",
"properties",
"=",
"[",
"]",
";",
"// find templates containing URL fields",
"$",
"structureMetadatas",
"=",
"array_merge",
"(",
"$",
"this",
"->",
"structureMetadataFactory",
"->",
"getStructures",
"(",
"'page'",
")",
",",
"$",
"this",
"->",
"structureMetadataFactory",
"->",
"getStructures",
"(",
"'snippet'",
")",
")",
";",
"$",
"structureMetadatas",
"=",
"array_filter",
"(",
"$",
"structureMetadatas",
",",
"function",
"(",
"StructureMetadata",
"$",
"structureMetadata",
")",
"use",
"(",
"&",
"$",
"properties",
")",
"{",
"$",
"structureName",
"=",
"$",
"structureMetadata",
"->",
"getName",
"(",
")",
";",
"$",
"this",
"->",
"findUrlProperties",
"(",
"$",
"structureMetadata",
",",
"$",
"properties",
")",
";",
"return",
"!",
"empty",
"(",
"$",
"properties",
"[",
"$",
"structureName",
"]",
")",
"||",
"!",
"empty",
"(",
"$",
"blockProperties",
"[",
"$",
"structureName",
"]",
")",
";",
"}",
")",
";",
"foreach",
"(",
"$",
"structureMetadatas",
"as",
"$",
"structureMetadata",
")",
"{",
"$",
"this",
"->",
"iterateStructureNodes",
"(",
"$",
"structureMetadata",
",",
"$",
"properties",
"[",
"$",
"structureMetadata",
"->",
"getName",
"(",
")",
"]",
",",
"$",
"addScheme",
")",
";",
"}",
"$",
"this",
"->",
"documentManager",
"->",
"flush",
"(",
")",
";",
"}"
] | Structures are updated according to their xml definition.
@param bool $addScheme Adds the scheme to URLs if true, removes the scheme otherwise | [
"Structures",
"are",
"updated",
"according",
"to",
"their",
"xml",
"definition",
"."
] | 6766a36cc2f0c807c59202bf7540a08c4ef31192 | https://github.com/sulu/sulu/blob/6766a36cc2f0c807c59202bf7540a08c4ef31192/src/Sulu/Bundle/PageBundle/Resources/phpcr-migrations/Version201511240844.php#L137-L166 | train |
sulu/sulu | src/Sulu/Bundle/PageBundle/Resources/phpcr-migrations/Version201511240844.php | Version201511240844.findUrlProperties | private function findUrlProperties(StructureMetadata $structureMetadata, array &$properties)
{
$structureName = $structureMetadata->getName();
foreach ($structureMetadata->getProperties() as $property) {
if ('url' === $property->getType()) {
$properties[$structureName][] = ['property' => $property];
} elseif ($property instanceof BlockMetadata) {
$this->findUrlBlockProperties($property, $structureName, $properties);
}
}
} | php | private function findUrlProperties(StructureMetadata $structureMetadata, array &$properties)
{
$structureName = $structureMetadata->getName();
foreach ($structureMetadata->getProperties() as $property) {
if ('url' === $property->getType()) {
$properties[$structureName][] = ['property' => $property];
} elseif ($property instanceof BlockMetadata) {
$this->findUrlBlockProperties($property, $structureName, $properties);
}
}
} | [
"private",
"function",
"findUrlProperties",
"(",
"StructureMetadata",
"$",
"structureMetadata",
",",
"array",
"&",
"$",
"properties",
")",
"{",
"$",
"structureName",
"=",
"$",
"structureMetadata",
"->",
"getName",
"(",
")",
";",
"foreach",
"(",
"$",
"structureMetadata",
"->",
"getProperties",
"(",
")",
"as",
"$",
"property",
")",
"{",
"if",
"(",
"'url'",
"===",
"$",
"property",
"->",
"getType",
"(",
")",
")",
"{",
"$",
"properties",
"[",
"$",
"structureName",
"]",
"[",
"]",
"=",
"[",
"'property'",
"=>",
"$",
"property",
"]",
";",
"}",
"elseif",
"(",
"$",
"property",
"instanceof",
"BlockMetadata",
")",
"{",
"$",
"this",
"->",
"findUrlBlockProperties",
"(",
"$",
"property",
",",
"$",
"structureName",
",",
"$",
"properties",
")",
";",
"}",
"}",
"}"
] | Returns all properties which are a URL field.
@param StructureMetadata $structureMetadata The metadata in which the URL fields are searched
@param array $properties The properties which are URL fields are added to this array | [
"Returns",
"all",
"properties",
"which",
"are",
"a",
"URL",
"field",
"."
] | 6766a36cc2f0c807c59202bf7540a08c4ef31192 | https://github.com/sulu/sulu/blob/6766a36cc2f0c807c59202bf7540a08c4ef31192/src/Sulu/Bundle/PageBundle/Resources/phpcr-migrations/Version201511240844.php#L174-L184 | train |
sulu/sulu | src/Sulu/Bundle/PageBundle/Resources/phpcr-migrations/Version201511240844.php | Version201511240844.upgradeNode | private function upgradeNode(NodeInterface $node, $locale, array $properties, $addScheme)
{
/** @var BasePageDocument $document */
$document = $this->documentManager->find($node->getIdentifier(), $locale);
$documentLocales = $this->documentInspector->getLocales($document);
if (!in_array($locale, $documentLocales)) {
return;
}
foreach ($properties as $property) {
$propertyValue = $document->getStructure()->getProperty($property['property']->getName());
if ($property['property'] instanceof BlockMetadata) {
$this->upgradeBlockProperty($property['property'], $property['components'], $propertyValue, $addScheme);
} else {
$this->upgradeProperty($propertyValue, $addScheme);
}
}
$this->documentManager->persist($document, $locale, ['auto_name' => false]);
} | php | private function upgradeNode(NodeInterface $node, $locale, array $properties, $addScheme)
{
/** @var BasePageDocument $document */
$document = $this->documentManager->find($node->getIdentifier(), $locale);
$documentLocales = $this->documentInspector->getLocales($document);
if (!in_array($locale, $documentLocales)) {
return;
}
foreach ($properties as $property) {
$propertyValue = $document->getStructure()->getProperty($property['property']->getName());
if ($property['property'] instanceof BlockMetadata) {
$this->upgradeBlockProperty($property['property'], $property['components'], $propertyValue, $addScheme);
} else {
$this->upgradeProperty($propertyValue, $addScheme);
}
}
$this->documentManager->persist($document, $locale, ['auto_name' => false]);
} | [
"private",
"function",
"upgradeNode",
"(",
"NodeInterface",
"$",
"node",
",",
"$",
"locale",
",",
"array",
"$",
"properties",
",",
"$",
"addScheme",
")",
"{",
"/** @var BasePageDocument $document */",
"$",
"document",
"=",
"$",
"this",
"->",
"documentManager",
"->",
"find",
"(",
"$",
"node",
"->",
"getIdentifier",
"(",
")",
",",
"$",
"locale",
")",
";",
"$",
"documentLocales",
"=",
"$",
"this",
"->",
"documentInspector",
"->",
"getLocales",
"(",
"$",
"document",
")",
";",
"if",
"(",
"!",
"in_array",
"(",
"$",
"locale",
",",
"$",
"documentLocales",
")",
")",
"{",
"return",
";",
"}",
"foreach",
"(",
"$",
"properties",
"as",
"$",
"property",
")",
"{",
"$",
"propertyValue",
"=",
"$",
"document",
"->",
"getStructure",
"(",
")",
"->",
"getProperty",
"(",
"$",
"property",
"[",
"'property'",
"]",
"->",
"getName",
"(",
")",
")",
";",
"if",
"(",
"$",
"property",
"[",
"'property'",
"]",
"instanceof",
"BlockMetadata",
")",
"{",
"$",
"this",
"->",
"upgradeBlockProperty",
"(",
"$",
"property",
"[",
"'property'",
"]",
",",
"$",
"property",
"[",
"'components'",
"]",
",",
"$",
"propertyValue",
",",
"$",
"addScheme",
")",
";",
"}",
"else",
"{",
"$",
"this",
"->",
"upgradeProperty",
"(",
"$",
"propertyValue",
",",
"$",
"addScheme",
")",
";",
"}",
"}",
"$",
"this",
"->",
"documentManager",
"->",
"persist",
"(",
"$",
"document",
",",
"$",
"locale",
",",
"[",
"'auto_name'",
"=>",
"false",
"]",
")",
";",
"}"
] | Upgrades the node to new URL representation.
@param NodeInterface $node The node to be upgraded
@param string $locale The locale of the node to be upgraded
@param array $properties The properties which are or contain URL fields
@param bool $addScheme Adds the scheme to URLs if true, removes the scheme otherwise | [
"Upgrades",
"the",
"node",
"to",
"new",
"URL",
"representation",
"."
] | 6766a36cc2f0c807c59202bf7540a08c4ef31192 | https://github.com/sulu/sulu/blob/6766a36cc2f0c807c59202bf7540a08c4ef31192/src/Sulu/Bundle/PageBundle/Resources/phpcr-migrations/Version201511240844.php#L249-L270 | train |
sulu/sulu | src/Sulu/Bundle/PageBundle/Resources/phpcr-migrations/Version201511240844.php | Version201511240844.upgradeBlockProperty | private function upgradeBlockProperty(
BlockMetadata $blockProperty,
array $components,
PropertyValue $propertyValue,
$addScheme
) {
$componentNames = array_map(
function($item) {
return $item['component']->getName();
},
$components
);
$value = $propertyValue->getValue();
foreach ($value as &$item) {
if (!in_array($item['type'], $componentNames)) {
continue;
}
foreach ($components[$item['type']]['children'] as $child) {
if (!isset($item[$child->getName()])) {
continue;
}
if ($addScheme) {
$item[$child->getName()] = $this->upgradeUrl($item[$child->getName()]);
} else {
$item[$child->getName()] = $this->downgradeUrl($item[$child->getName()]);
}
}
}
$propertyValue->setValue($value);
} | php | private function upgradeBlockProperty(
BlockMetadata $blockProperty,
array $components,
PropertyValue $propertyValue,
$addScheme
) {
$componentNames = array_map(
function($item) {
return $item['component']->getName();
},
$components
);
$value = $propertyValue->getValue();
foreach ($value as &$item) {
if (!in_array($item['type'], $componentNames)) {
continue;
}
foreach ($components[$item['type']]['children'] as $child) {
if (!isset($item[$child->getName()])) {
continue;
}
if ($addScheme) {
$item[$child->getName()] = $this->upgradeUrl($item[$child->getName()]);
} else {
$item[$child->getName()] = $this->downgradeUrl($item[$child->getName()]);
}
}
}
$propertyValue->setValue($value);
} | [
"private",
"function",
"upgradeBlockProperty",
"(",
"BlockMetadata",
"$",
"blockProperty",
",",
"array",
"$",
"components",
",",
"PropertyValue",
"$",
"propertyValue",
",",
"$",
"addScheme",
")",
"{",
"$",
"componentNames",
"=",
"array_map",
"(",
"function",
"(",
"$",
"item",
")",
"{",
"return",
"$",
"item",
"[",
"'component'",
"]",
"->",
"getName",
"(",
")",
";",
"}",
",",
"$",
"components",
")",
";",
"$",
"value",
"=",
"$",
"propertyValue",
"->",
"getValue",
"(",
")",
";",
"foreach",
"(",
"$",
"value",
"as",
"&",
"$",
"item",
")",
"{",
"if",
"(",
"!",
"in_array",
"(",
"$",
"item",
"[",
"'type'",
"]",
",",
"$",
"componentNames",
")",
")",
"{",
"continue",
";",
"}",
"foreach",
"(",
"$",
"components",
"[",
"$",
"item",
"[",
"'type'",
"]",
"]",
"[",
"'children'",
"]",
"as",
"$",
"child",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"item",
"[",
"$",
"child",
"->",
"getName",
"(",
")",
"]",
")",
")",
"{",
"continue",
";",
"}",
"if",
"(",
"$",
"addScheme",
")",
"{",
"$",
"item",
"[",
"$",
"child",
"->",
"getName",
"(",
")",
"]",
"=",
"$",
"this",
"->",
"upgradeUrl",
"(",
"$",
"item",
"[",
"$",
"child",
"->",
"getName",
"(",
")",
"]",
")",
";",
"}",
"else",
"{",
"$",
"item",
"[",
"$",
"child",
"->",
"getName",
"(",
")",
"]",
"=",
"$",
"this",
"->",
"downgradeUrl",
"(",
"$",
"item",
"[",
"$",
"child",
"->",
"getName",
"(",
")",
"]",
")",
";",
"}",
"}",
"}",
"$",
"propertyValue",
"->",
"setValue",
"(",
"$",
"value",
")",
";",
"}"
] | Upgrades the given block property to the new URL representation.
@param BlockMetadata $blockProperty
@param array $components
@param PropertyValue $propertyValue
@param bool $addScheme | [
"Upgrades",
"the",
"given",
"block",
"property",
"to",
"the",
"new",
"URL",
"representation",
"."
] | 6766a36cc2f0c807c59202bf7540a08c4ef31192 | https://github.com/sulu/sulu/blob/6766a36cc2f0c807c59202bf7540a08c4ef31192/src/Sulu/Bundle/PageBundle/Resources/phpcr-migrations/Version201511240844.php#L280-L313 | train |
sulu/sulu | src/Sulu/Bundle/PageBundle/Resources/phpcr-migrations/Version201511240844.php | Version201511240844.upgradeUrl | private function upgradeUrl(&$value)
{
if (!empty($value)
&& false === strpos($value, 'http://')
&& false === strpos($value, 'https://')
&& false === strpos($value, 'ftp://')
&& false === strpos($value, 'ftps://')
&& false === strpos($value, 'mailto:')
&& false === strpos($value, '//')
) {
$value = 'http://' . $value;
}
return $value;
} | php | private function upgradeUrl(&$value)
{
if (!empty($value)
&& false === strpos($value, 'http://')
&& false === strpos($value, 'https://')
&& false === strpos($value, 'ftp://')
&& false === strpos($value, 'ftps://')
&& false === strpos($value, 'mailto:')
&& false === strpos($value, '//')
) {
$value = 'http://' . $value;
}
return $value;
} | [
"private",
"function",
"upgradeUrl",
"(",
"&",
"$",
"value",
")",
"{",
"if",
"(",
"!",
"empty",
"(",
"$",
"value",
")",
"&&",
"false",
"===",
"strpos",
"(",
"$",
"value",
",",
"'http://'",
")",
"&&",
"false",
"===",
"strpos",
"(",
"$",
"value",
",",
"'https://'",
")",
"&&",
"false",
"===",
"strpos",
"(",
"$",
"value",
",",
"'ftp://'",
")",
"&&",
"false",
"===",
"strpos",
"(",
"$",
"value",
",",
"'ftps://'",
")",
"&&",
"false",
"===",
"strpos",
"(",
"$",
"value",
",",
"'mailto:'",
")",
"&&",
"false",
"===",
"strpos",
"(",
"$",
"value",
",",
"'//'",
")",
")",
"{",
"$",
"value",
"=",
"'http://'",
".",
"$",
"value",
";",
"}",
"return",
"$",
"value",
";",
"}"
] | Upgrades the given URL to the new representation.
@param string $value The url to change
@return string | [
"Upgrades",
"the",
"given",
"URL",
"to",
"the",
"new",
"representation",
"."
] | 6766a36cc2f0c807c59202bf7540a08c4ef31192 | https://github.com/sulu/sulu/blob/6766a36cc2f0c807c59202bf7540a08c4ef31192/src/Sulu/Bundle/PageBundle/Resources/phpcr-migrations/Version201511240844.php#L340-L354 | train |
sulu/sulu | src/Sulu/Component/DocumentManager/Subscriber/Behavior/Path/AutoNameSubscriber.php | AutoNameSubscriber.handleScheduleRename | public function handleScheduleRename(PersistEvent $event)
{
$document = $event->getDocument();
if (!$event->getOption('auto_name')
|| !$document instanceof AutoNameBehavior
|| $event->getOption('auto_name_locale') !== $event->getLocale()
|| !$event->hasNode()
|| $event->getNode()->isNew()
) {
return;
}
$node = $event->getNode();
$name = $this->getName($document, $event->getParentNode(), $event->getOption('auto_rename'), $node);
if ($name === $node->getName()) {
return;
}
$uuid = $event->getNode()->getIdentifier();
$this->scheduledRename[] = ['uuid' => $uuid, 'name' => $name, 'locale' => $event->getLocale()];
} | php | public function handleScheduleRename(PersistEvent $event)
{
$document = $event->getDocument();
if (!$event->getOption('auto_name')
|| !$document instanceof AutoNameBehavior
|| $event->getOption('auto_name_locale') !== $event->getLocale()
|| !$event->hasNode()
|| $event->getNode()->isNew()
) {
return;
}
$node = $event->getNode();
$name = $this->getName($document, $event->getParentNode(), $event->getOption('auto_rename'), $node);
if ($name === $node->getName()) {
return;
}
$uuid = $event->getNode()->getIdentifier();
$this->scheduledRename[] = ['uuid' => $uuid, 'name' => $name, 'locale' => $event->getLocale()];
} | [
"public",
"function",
"handleScheduleRename",
"(",
"PersistEvent",
"$",
"event",
")",
"{",
"$",
"document",
"=",
"$",
"event",
"->",
"getDocument",
"(",
")",
";",
"if",
"(",
"!",
"$",
"event",
"->",
"getOption",
"(",
"'auto_name'",
")",
"||",
"!",
"$",
"document",
"instanceof",
"AutoNameBehavior",
"||",
"$",
"event",
"->",
"getOption",
"(",
"'auto_name_locale'",
")",
"!==",
"$",
"event",
"->",
"getLocale",
"(",
")",
"||",
"!",
"$",
"event",
"->",
"hasNode",
"(",
")",
"||",
"$",
"event",
"->",
"getNode",
"(",
")",
"->",
"isNew",
"(",
")",
")",
"{",
"return",
";",
"}",
"$",
"node",
"=",
"$",
"event",
"->",
"getNode",
"(",
")",
";",
"$",
"name",
"=",
"$",
"this",
"->",
"getName",
"(",
"$",
"document",
",",
"$",
"event",
"->",
"getParentNode",
"(",
")",
",",
"$",
"event",
"->",
"getOption",
"(",
"'auto_rename'",
")",
",",
"$",
"node",
")",
";",
"if",
"(",
"$",
"name",
"===",
"$",
"node",
"->",
"getName",
"(",
")",
")",
"{",
"return",
";",
"}",
"$",
"uuid",
"=",
"$",
"event",
"->",
"getNode",
"(",
")",
"->",
"getIdentifier",
"(",
")",
";",
"$",
"this",
"->",
"scheduledRename",
"[",
"]",
"=",
"[",
"'uuid'",
"=>",
"$",
"uuid",
",",
"'name'",
"=>",
"$",
"name",
",",
"'locale'",
"=>",
"$",
"event",
"->",
"getLocale",
"(",
")",
"]",
";",
"}"
] | Renames node if necessary.
@param PersistEvent $event | [
"Renames",
"node",
"if",
"necessary",
"."
] | 6766a36cc2f0c807c59202bf7540a08c4ef31192 | https://github.com/sulu/sulu/blob/6766a36cc2f0c807c59202bf7540a08c4ef31192/src/Sulu/Component/DocumentManager/Subscriber/Behavior/Path/AutoNameSubscriber.php#L164-L186 | train |
sulu/sulu | src/Sulu/Component/DocumentManager/Subscriber/Behavior/Path/AutoNameSubscriber.php | AutoNameSubscriber.getName | private function getName(
AutoNameBehavior $document,
NodeInterface $parentNode,
$autoRename = true,
NodeInterface $node = null
) {
$title = $document->getTitle();
if (!$title) {
throw new DocumentManagerException(
sprintf(
'Document has no title (title is required for auto name behavior): %s)',
DocumentHelper::getDebugTitle($document)
)
);
}
$name = $this->slugifier->slugify($title);
return $this->resolver->resolveName($parentNode, $name, $node, $autoRename);
} | php | private function getName(
AutoNameBehavior $document,
NodeInterface $parentNode,
$autoRename = true,
NodeInterface $node = null
) {
$title = $document->getTitle();
if (!$title) {
throw new DocumentManagerException(
sprintf(
'Document has no title (title is required for auto name behavior): %s)',
DocumentHelper::getDebugTitle($document)
)
);
}
$name = $this->slugifier->slugify($title);
return $this->resolver->resolveName($parentNode, $name, $node, $autoRename);
} | [
"private",
"function",
"getName",
"(",
"AutoNameBehavior",
"$",
"document",
",",
"NodeInterface",
"$",
"parentNode",
",",
"$",
"autoRename",
"=",
"true",
",",
"NodeInterface",
"$",
"node",
"=",
"null",
")",
"{",
"$",
"title",
"=",
"$",
"document",
"->",
"getTitle",
"(",
")",
";",
"if",
"(",
"!",
"$",
"title",
")",
"{",
"throw",
"new",
"DocumentManagerException",
"(",
"sprintf",
"(",
"'Document has no title (title is required for auto name behavior): %s)'",
",",
"DocumentHelper",
"::",
"getDebugTitle",
"(",
"$",
"document",
")",
")",
")",
";",
"}",
"$",
"name",
"=",
"$",
"this",
"->",
"slugifier",
"->",
"slugify",
"(",
"$",
"title",
")",
";",
"return",
"$",
"this",
"->",
"resolver",
"->",
"resolveName",
"(",
"$",
"parentNode",
",",
"$",
"name",
",",
"$",
"node",
",",
"$",
"autoRename",
")",
";",
"}"
] | Returns unique name for given document and nodes.
@param AutoNameBehavior $document
@param NodeInterface $parentNode
@param NodeInterface|null $node
@param bool $autoRename
@return string
@throws DocumentManagerException | [
"Returns",
"unique",
"name",
"for",
"given",
"document",
"and",
"nodes",
"."
] | 6766a36cc2f0c807c59202bf7540a08c4ef31192 | https://github.com/sulu/sulu/blob/6766a36cc2f0c807c59202bf7540a08c4ef31192/src/Sulu/Component/DocumentManager/Subscriber/Behavior/Path/AutoNameSubscriber.php#L223-L243 | train |
sulu/sulu | src/Sulu/Component/DocumentManager/Subscriber/Behavior/Path/AutoNameSubscriber.php | AutoNameSubscriber.handleMoveCopy | private function handleMoveCopy(MoveEvent $event)
{
$document = $event->getDocument();
if (!$document instanceof AutoNameBehavior) {
return;
}
$destId = $event->getDestId();
$node = $this->registry->getNodeForDocument($document);
$destNode = $this->nodeManager->find($destId);
$nodeName = $this->resolver->resolveName($destNode, $node->getName());
$event->setDestName($nodeName);
} | php | private function handleMoveCopy(MoveEvent $event)
{
$document = $event->getDocument();
if (!$document instanceof AutoNameBehavior) {
return;
}
$destId = $event->getDestId();
$node = $this->registry->getNodeForDocument($document);
$destNode = $this->nodeManager->find($destId);
$nodeName = $this->resolver->resolveName($destNode, $node->getName());
$event->setDestName($nodeName);
} | [
"private",
"function",
"handleMoveCopy",
"(",
"MoveEvent",
"$",
"event",
")",
"{",
"$",
"document",
"=",
"$",
"event",
"->",
"getDocument",
"(",
")",
";",
"if",
"(",
"!",
"$",
"document",
"instanceof",
"AutoNameBehavior",
")",
"{",
"return",
";",
"}",
"$",
"destId",
"=",
"$",
"event",
"->",
"getDestId",
"(",
")",
";",
"$",
"node",
"=",
"$",
"this",
"->",
"registry",
"->",
"getNodeForDocument",
"(",
"$",
"document",
")",
";",
"$",
"destNode",
"=",
"$",
"this",
"->",
"nodeManager",
"->",
"find",
"(",
"$",
"destId",
")",
";",
"$",
"nodeName",
"=",
"$",
"this",
"->",
"resolver",
"->",
"resolveName",
"(",
"$",
"destNode",
",",
"$",
"node",
"->",
"getName",
"(",
")",
")",
";",
"$",
"event",
"->",
"setDestName",
"(",
"$",
"nodeName",
")",
";",
"}"
] | Resolve the destination name on move and copy events.
@param MoveEvent $event | [
"Resolve",
"the",
"destination",
"name",
"on",
"move",
"and",
"copy",
"events",
"."
] | 6766a36cc2f0c807c59202bf7540a08c4ef31192 | https://github.com/sulu/sulu/blob/6766a36cc2f0c807c59202bf7540a08c4ef31192/src/Sulu/Component/DocumentManager/Subscriber/Behavior/Path/AutoNameSubscriber.php#L267-L281 | train |
sulu/sulu | src/Sulu/Component/Hash/Serializer/Subscriber/HashSerializeEventSubscriber.php | HashSerializeEventSubscriber.onPostSerialize | public function onPostSerialize(ObjectEvent $event)
{
$object = $event->getObject();
// FIXME This can be removed, as soon as we've got rid of all ApiEntities.
if ($object instanceof ApiWrapper) {
$object = $object->getEntity();
}
if (!$object instanceof AuditableInterface && !$object instanceof LocalizedAuditableBehavior) {
return;
}
$visitor = $event->getVisitor();
if (!$visitor instanceof GenericSerializationVisitor) {
return;
}
$visitor->setData('_hash', $this->hasher->hash($object));
} | php | public function onPostSerialize(ObjectEvent $event)
{
$object = $event->getObject();
// FIXME This can be removed, as soon as we've got rid of all ApiEntities.
if ($object instanceof ApiWrapper) {
$object = $object->getEntity();
}
if (!$object instanceof AuditableInterface && !$object instanceof LocalizedAuditableBehavior) {
return;
}
$visitor = $event->getVisitor();
if (!$visitor instanceof GenericSerializationVisitor) {
return;
}
$visitor->setData('_hash', $this->hasher->hash($object));
} | [
"public",
"function",
"onPostSerialize",
"(",
"ObjectEvent",
"$",
"event",
")",
"{",
"$",
"object",
"=",
"$",
"event",
"->",
"getObject",
"(",
")",
";",
"// FIXME This can be removed, as soon as we've got rid of all ApiEntities.",
"if",
"(",
"$",
"object",
"instanceof",
"ApiWrapper",
")",
"{",
"$",
"object",
"=",
"$",
"object",
"->",
"getEntity",
"(",
")",
";",
"}",
"if",
"(",
"!",
"$",
"object",
"instanceof",
"AuditableInterface",
"&&",
"!",
"$",
"object",
"instanceof",
"LocalizedAuditableBehavior",
")",
"{",
"return",
";",
"}",
"$",
"visitor",
"=",
"$",
"event",
"->",
"getVisitor",
"(",
")",
";",
"if",
"(",
"!",
"$",
"visitor",
"instanceof",
"GenericSerializationVisitor",
")",
"{",
"return",
";",
"}",
"$",
"visitor",
"->",
"setData",
"(",
"'_hash'",
",",
"$",
"this",
"->",
"hasher",
"->",
"hash",
"(",
"$",
"object",
")",
")",
";",
"}"
] | Adds the hash of the given object to its serialization.
@param ObjectEvent $event | [
"Adds",
"the",
"hash",
"of",
"the",
"given",
"object",
"to",
"its",
"serialization",
"."
] | 6766a36cc2f0c807c59202bf7540a08c4ef31192 | https://github.com/sulu/sulu/blob/6766a36cc2f0c807c59202bf7540a08c4ef31192/src/Sulu/Component/Hash/Serializer/Subscriber/HashSerializeEventSubscriber.php#L52-L72 | train |
sulu/sulu | src/Sulu/Component/Media/SystemCollections/SystemCollectionManager.php | SystemCollectionManager.getSystemCollections | private function getSystemCollections()
{
if (!$this->systemCollections) {
if (!$this->cache->isFresh()) {
$systemCollections = $this->buildSystemCollections(
$this->locale,
$this->getUserId()
);
$this->cache->write($systemCollections);
}
$this->systemCollections = $this->cache->read();
}
return $this->systemCollections;
} | php | private function getSystemCollections()
{
if (!$this->systemCollections) {
if (!$this->cache->isFresh()) {
$systemCollections = $this->buildSystemCollections(
$this->locale,
$this->getUserId()
);
$this->cache->write($systemCollections);
}
$this->systemCollections = $this->cache->read();
}
return $this->systemCollections;
} | [
"private",
"function",
"getSystemCollections",
"(",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"systemCollections",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"cache",
"->",
"isFresh",
"(",
")",
")",
"{",
"$",
"systemCollections",
"=",
"$",
"this",
"->",
"buildSystemCollections",
"(",
"$",
"this",
"->",
"locale",
",",
"$",
"this",
"->",
"getUserId",
"(",
")",
")",
";",
"$",
"this",
"->",
"cache",
"->",
"write",
"(",
"$",
"systemCollections",
")",
";",
"}",
"$",
"this",
"->",
"systemCollections",
"=",
"$",
"this",
"->",
"cache",
"->",
"read",
"(",
")",
";",
"}",
"return",
"$",
"this",
"->",
"systemCollections",
";",
"}"
] | Returns system collections.
@return array | [
"Returns",
"system",
"collections",
"."
] | 6766a36cc2f0c807c59202bf7540a08c4ef31192 | https://github.com/sulu/sulu/blob/6766a36cc2f0c807c59202bf7540a08c4ef31192/src/Sulu/Component/Media/SystemCollections/SystemCollectionManager.php#L112-L128 | train |
sulu/sulu | src/Sulu/Component/Media/SystemCollections/SystemCollectionManager.php | SystemCollectionManager.getUserId | private function getUserId()
{
if (!$this->tokenProvider || null === ($token = $this->tokenProvider->getToken())) {
return;
}
if (!$token->getUser() instanceof UserInterface) {
return;
}
return $token->getUser()->getId();
} | php | private function getUserId()
{
if (!$this->tokenProvider || null === ($token = $this->tokenProvider->getToken())) {
return;
}
if (!$token->getUser() instanceof UserInterface) {
return;
}
return $token->getUser()->getId();
} | [
"private",
"function",
"getUserId",
"(",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"tokenProvider",
"||",
"null",
"===",
"(",
"$",
"token",
"=",
"$",
"this",
"->",
"tokenProvider",
"->",
"getToken",
"(",
")",
")",
")",
"{",
"return",
";",
"}",
"if",
"(",
"!",
"$",
"token",
"->",
"getUser",
"(",
")",
"instanceof",
"UserInterface",
")",
"{",
"return",
";",
"}",
"return",
"$",
"token",
"->",
"getUser",
"(",
")",
"->",
"getId",
"(",
")",
";",
"}"
] | Returns current user.
@return int | [
"Returns",
"current",
"user",
"."
] | 6766a36cc2f0c807c59202bf7540a08c4ef31192 | https://github.com/sulu/sulu/blob/6766a36cc2f0c807c59202bf7540a08c4ef31192/src/Sulu/Component/Media/SystemCollections/SystemCollectionManager.php#L135-L146 | train |
sulu/sulu | src/Sulu/Component/Media/SystemCollections/SystemCollectionManager.php | SystemCollectionManager.buildSystemCollections | private function buildSystemCollections($locale, $userId)
{
$root = $this->getOrCreateRoot(SystemCollectionManagerInterface::COLLECTION_KEY, 'System', $locale, $userId);
$collections = ['root' => $root->getId()];
$collections = array_merge($collections, $this->iterateOverCollections($this->config, $userId, $root->getId()));
$this->entityManager->flush();
return $collections;
} | php | private function buildSystemCollections($locale, $userId)
{
$root = $this->getOrCreateRoot(SystemCollectionManagerInterface::COLLECTION_KEY, 'System', $locale, $userId);
$collections = ['root' => $root->getId()];
$collections = array_merge($collections, $this->iterateOverCollections($this->config, $userId, $root->getId()));
$this->entityManager->flush();
return $collections;
} | [
"private",
"function",
"buildSystemCollections",
"(",
"$",
"locale",
",",
"$",
"userId",
")",
"{",
"$",
"root",
"=",
"$",
"this",
"->",
"getOrCreateRoot",
"(",
"SystemCollectionManagerInterface",
"::",
"COLLECTION_KEY",
",",
"'System'",
",",
"$",
"locale",
",",
"$",
"userId",
")",
";",
"$",
"collections",
"=",
"[",
"'root'",
"=>",
"$",
"root",
"->",
"getId",
"(",
")",
"]",
";",
"$",
"collections",
"=",
"array_merge",
"(",
"$",
"collections",
",",
"$",
"this",
"->",
"iterateOverCollections",
"(",
"$",
"this",
"->",
"config",
",",
"$",
"userId",
",",
"$",
"root",
"->",
"getId",
"(",
")",
")",
")",
";",
"$",
"this",
"->",
"entityManager",
"->",
"flush",
"(",
")",
";",
"return",
"$",
"collections",
";",
"}"
] | Go thru configuration and build all system collections.
@param string $locale
@param int $userId
@return array | [
"Go",
"thru",
"configuration",
"and",
"build",
"all",
"system",
"collections",
"."
] | 6766a36cc2f0c807c59202bf7540a08c4ef31192 | https://github.com/sulu/sulu/blob/6766a36cc2f0c807c59202bf7540a08c4ef31192/src/Sulu/Component/Media/SystemCollections/SystemCollectionManager.php#L156-L165 | train |
sulu/sulu | src/Sulu/Component/Media/SystemCollections/SystemCollectionManager.php | SystemCollectionManager.iterateOverCollections | private function iterateOverCollections($children, $userId, $parent = null, $namespace = '')
{
$format = ('' !== $namespace ? '%s.%s' : '%s%s');
$collections = [];
foreach ($children as $collectionKey => $collectionItem) {
$key = sprintf($format, $namespace, $collectionKey);
$collections[$key] = $this->getOrCreateCollection(
$key,
$collectionItem['meta_title'],
$userId,
$parent
)->getId();
if (array_key_exists('collections', $collectionItem)) {
$childCollections = $this->iterateOverCollections(
$collectionItem['collections'],
$userId,
$collections[$key],
$key
);
$collections = array_merge($collections, $childCollections);
}
}
return $collections;
} | php | private function iterateOverCollections($children, $userId, $parent = null, $namespace = '')
{
$format = ('' !== $namespace ? '%s.%s' : '%s%s');
$collections = [];
foreach ($children as $collectionKey => $collectionItem) {
$key = sprintf($format, $namespace, $collectionKey);
$collections[$key] = $this->getOrCreateCollection(
$key,
$collectionItem['meta_title'],
$userId,
$parent
)->getId();
if (array_key_exists('collections', $collectionItem)) {
$childCollections = $this->iterateOverCollections(
$collectionItem['collections'],
$userId,
$collections[$key],
$key
);
$collections = array_merge($collections, $childCollections);
}
}
return $collections;
} | [
"private",
"function",
"iterateOverCollections",
"(",
"$",
"children",
",",
"$",
"userId",
",",
"$",
"parent",
"=",
"null",
",",
"$",
"namespace",
"=",
"''",
")",
"{",
"$",
"format",
"=",
"(",
"''",
"!==",
"$",
"namespace",
"?",
"'%s.%s'",
":",
"'%s%s'",
")",
";",
"$",
"collections",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"children",
"as",
"$",
"collectionKey",
"=>",
"$",
"collectionItem",
")",
"{",
"$",
"key",
"=",
"sprintf",
"(",
"$",
"format",
",",
"$",
"namespace",
",",
"$",
"collectionKey",
")",
";",
"$",
"collections",
"[",
"$",
"key",
"]",
"=",
"$",
"this",
"->",
"getOrCreateCollection",
"(",
"$",
"key",
",",
"$",
"collectionItem",
"[",
"'meta_title'",
"]",
",",
"$",
"userId",
",",
"$",
"parent",
")",
"->",
"getId",
"(",
")",
";",
"if",
"(",
"array_key_exists",
"(",
"'collections'",
",",
"$",
"collectionItem",
")",
")",
"{",
"$",
"childCollections",
"=",
"$",
"this",
"->",
"iterateOverCollections",
"(",
"$",
"collectionItem",
"[",
"'collections'",
"]",
",",
"$",
"userId",
",",
"$",
"collections",
"[",
"$",
"key",
"]",
",",
"$",
"key",
")",
";",
"$",
"collections",
"=",
"array_merge",
"(",
"$",
"collections",
",",
"$",
"childCollections",
")",
";",
"}",
"}",
"return",
"$",
"collections",
";",
"}"
] | Iterates over an array of children collections, creates them.
This function is recursive!
@param $children
@param $userId
@param null $parent
@param string $namespace
@return array | [
"Iterates",
"over",
"an",
"array",
"of",
"children",
"collections",
"creates",
"them",
".",
"This",
"function",
"is",
"recursive!"
] | 6766a36cc2f0c807c59202bf7540a08c4ef31192 | https://github.com/sulu/sulu/blob/6766a36cc2f0c807c59202bf7540a08c4ef31192/src/Sulu/Component/Media/SystemCollections/SystemCollectionManager.php#L178-L203 | train |
sulu/sulu | src/Sulu/Component/Media/SystemCollections/SystemCollectionManager.php | SystemCollectionManager.getOrCreateRoot | private function getOrCreateRoot($namespace, $title, $locale, $userId, $parent = null)
{
if (null !== ($collection = $this->collectionManager->getByKey($namespace, $locale))) {
$collection->setTitle($title);
return $collection;
}
return $this->createCollection($title, $namespace, $locale, $userId, $parent);
} | php | private function getOrCreateRoot($namespace, $title, $locale, $userId, $parent = null)
{
if (null !== ($collection = $this->collectionManager->getByKey($namespace, $locale))) {
$collection->setTitle($title);
return $collection;
}
return $this->createCollection($title, $namespace, $locale, $userId, $parent);
} | [
"private",
"function",
"getOrCreateRoot",
"(",
"$",
"namespace",
",",
"$",
"title",
",",
"$",
"locale",
",",
"$",
"userId",
",",
"$",
"parent",
"=",
"null",
")",
"{",
"if",
"(",
"null",
"!==",
"(",
"$",
"collection",
"=",
"$",
"this",
"->",
"collectionManager",
"->",
"getByKey",
"(",
"$",
"namespace",
",",
"$",
"locale",
")",
")",
")",
"{",
"$",
"collection",
"->",
"setTitle",
"(",
"$",
"title",
")",
";",
"return",
"$",
"collection",
";",
"}",
"return",
"$",
"this",
"->",
"createCollection",
"(",
"$",
"title",
",",
"$",
"namespace",
",",
"$",
"locale",
",",
"$",
"userId",
",",
"$",
"parent",
")",
";",
"}"
] | Finds or create a new system-collection namespace.
@param string $namespace
@param string $title
@param string $locale
@param int $userId
@param int|null $parent id of parent collection or null for root
@return Collection | [
"Finds",
"or",
"create",
"a",
"new",
"system",
"-",
"collection",
"namespace",
"."
] | 6766a36cc2f0c807c59202bf7540a08c4ef31192 | https://github.com/sulu/sulu/blob/6766a36cc2f0c807c59202bf7540a08c4ef31192/src/Sulu/Component/Media/SystemCollections/SystemCollectionManager.php#L216-L225 | train |
sulu/sulu | src/Sulu/Component/Media/SystemCollections/SystemCollectionManager.php | SystemCollectionManager.getOrCreateCollection | private function getOrCreateCollection($key, $localizedTitles, $userId, $parent)
{
$locales = array_keys($localizedTitles);
$firstLocale = array_shift($locales);
$collection = $this->collectionManager->getByKey($key, $firstLocale);
if (null === $collection) {
$collection = $this->createCollection($localizedTitles[$firstLocale], $key, $firstLocale, $userId, $parent);
} else {
$collection->setTitle($localizedTitles[$firstLocale]);
}
foreach ($locales as $locale) {
$this->createCollection($localizedTitles[$locale], $key, $locale, $userId, $parent, $collection->getId());
}
return $collection;
} | php | private function getOrCreateCollection($key, $localizedTitles, $userId, $parent)
{
$locales = array_keys($localizedTitles);
$firstLocale = array_shift($locales);
$collection = $this->collectionManager->getByKey($key, $firstLocale);
if (null === $collection) {
$collection = $this->createCollection($localizedTitles[$firstLocale], $key, $firstLocale, $userId, $parent);
} else {
$collection->setTitle($localizedTitles[$firstLocale]);
}
foreach ($locales as $locale) {
$this->createCollection($localizedTitles[$locale], $key, $locale, $userId, $parent, $collection->getId());
}
return $collection;
} | [
"private",
"function",
"getOrCreateCollection",
"(",
"$",
"key",
",",
"$",
"localizedTitles",
",",
"$",
"userId",
",",
"$",
"parent",
")",
"{",
"$",
"locales",
"=",
"array_keys",
"(",
"$",
"localizedTitles",
")",
";",
"$",
"firstLocale",
"=",
"array_shift",
"(",
"$",
"locales",
")",
";",
"$",
"collection",
"=",
"$",
"this",
"->",
"collectionManager",
"->",
"getByKey",
"(",
"$",
"key",
",",
"$",
"firstLocale",
")",
";",
"if",
"(",
"null",
"===",
"$",
"collection",
")",
"{",
"$",
"collection",
"=",
"$",
"this",
"->",
"createCollection",
"(",
"$",
"localizedTitles",
"[",
"$",
"firstLocale",
"]",
",",
"$",
"key",
",",
"$",
"firstLocale",
",",
"$",
"userId",
",",
"$",
"parent",
")",
";",
"}",
"else",
"{",
"$",
"collection",
"->",
"setTitle",
"(",
"$",
"localizedTitles",
"[",
"$",
"firstLocale",
"]",
")",
";",
"}",
"foreach",
"(",
"$",
"locales",
"as",
"$",
"locale",
")",
"{",
"$",
"this",
"->",
"createCollection",
"(",
"$",
"localizedTitles",
"[",
"$",
"locale",
"]",
",",
"$",
"key",
",",
"$",
"locale",
",",
"$",
"userId",
",",
"$",
"parent",
",",
"$",
"collection",
"->",
"getId",
"(",
")",
")",
";",
"}",
"return",
"$",
"collection",
";",
"}"
] | Finds or create a new system-collection.
@param string $key
@param array $localizedTitles
@param int $userId
@param int|null $parent id of parent collection or null for root
@return Collection | [
"Finds",
"or",
"create",
"a",
"new",
"system",
"-",
"collection",
"."
] | 6766a36cc2f0c807c59202bf7540a08c4ef31192 | https://github.com/sulu/sulu/blob/6766a36cc2f0c807c59202bf7540a08c4ef31192/src/Sulu/Component/Media/SystemCollections/SystemCollectionManager.php#L237-L254 | train |
sulu/sulu | src/Sulu/Component/Snippet/Export/SnippetExport.php | SnippetExport.getExportData | public function getExportData()
{
$snippets = $this->getSnippets();
$snippetsData = [];
$progress = new ProgressBar($this->output, count($snippets));
$progress->start();
/*
* @var SnippetDocument
*/
foreach ($snippets as $snippet) {
$contentData = $this->getContentData($snippet, $this->exportLocale);
$snippetsData[] = [
'uuid' => $snippet->getUuid(),
'locale' => $snippet->getLocale(),
'content' => $contentData,
];
$progress->advance();
}
$progress->finish();
return [
'locale' => $this->exportLocale,
'format' => $this->format,
'snippetData' => $snippetsData,
];
} | php | public function getExportData()
{
$snippets = $this->getSnippets();
$snippetsData = [];
$progress = new ProgressBar($this->output, count($snippets));
$progress->start();
/*
* @var SnippetDocument
*/
foreach ($snippets as $snippet) {
$contentData = $this->getContentData($snippet, $this->exportLocale);
$snippetsData[] = [
'uuid' => $snippet->getUuid(),
'locale' => $snippet->getLocale(),
'content' => $contentData,
];
$progress->advance();
}
$progress->finish();
return [
'locale' => $this->exportLocale,
'format' => $this->format,
'snippetData' => $snippetsData,
];
} | [
"public",
"function",
"getExportData",
"(",
")",
"{",
"$",
"snippets",
"=",
"$",
"this",
"->",
"getSnippets",
"(",
")",
";",
"$",
"snippetsData",
"=",
"[",
"]",
";",
"$",
"progress",
"=",
"new",
"ProgressBar",
"(",
"$",
"this",
"->",
"output",
",",
"count",
"(",
"$",
"snippets",
")",
")",
";",
"$",
"progress",
"->",
"start",
"(",
")",
";",
"/*\n * @var SnippetDocument\n */",
"foreach",
"(",
"$",
"snippets",
"as",
"$",
"snippet",
")",
"{",
"$",
"contentData",
"=",
"$",
"this",
"->",
"getContentData",
"(",
"$",
"snippet",
",",
"$",
"this",
"->",
"exportLocale",
")",
";",
"$",
"snippetsData",
"[",
"]",
"=",
"[",
"'uuid'",
"=>",
"$",
"snippet",
"->",
"getUuid",
"(",
")",
",",
"'locale'",
"=>",
"$",
"snippet",
"->",
"getLocale",
"(",
")",
",",
"'content'",
"=>",
"$",
"contentData",
",",
"]",
";",
"$",
"progress",
"->",
"advance",
"(",
")",
";",
"}",
"$",
"progress",
"->",
"finish",
"(",
")",
";",
"return",
"[",
"'locale'",
"=>",
"$",
"this",
"->",
"exportLocale",
",",
"'format'",
"=>",
"$",
"this",
"->",
"format",
",",
"'snippetData'",
"=>",
"$",
"snippetsData",
",",
"]",
";",
"}"
] | Returns all data that we need to create a xliff-File.
@return array
@throws DocumentManagerException | [
"Returns",
"all",
"data",
"that",
"we",
"need",
"to",
"create",
"a",
"xliff",
"-",
"File",
"."
] | 6766a36cc2f0c807c59202bf7540a08c4ef31192 | https://github.com/sulu/sulu/blob/6766a36cc2f0c807c59202bf7540a08c4ef31192/src/Sulu/Component/Snippet/Export/SnippetExport.php#L85-L115 | train |
sulu/sulu | src/Sulu/Component/DocumentManager/DocumentRegistry.php | DocumentRegistry.registerDocument | public function registerDocument($document, NodeInterface $node, $locale)
{
$oid = $this->getObjectIdentifier($document);
$uuid = $node->getIdentifier();
// do not allow nodes without UUIDs or reregistration of documents
$this->validateDocumentRegistration($document, $locale, $node, $oid, $uuid);
$this->documentMap[$oid] = $document;
$this->documentNodeMap[$oid] = $uuid;
$this->nodeMap[$node->getIdentifier()] = $node;
$this->nodeDocumentMap[$this->getNodeLocaleKey($node->getIdentifier(), $locale)] = $document;
$this->documentLocaleMap[$oid] = $locale;
} | php | public function registerDocument($document, NodeInterface $node, $locale)
{
$oid = $this->getObjectIdentifier($document);
$uuid = $node->getIdentifier();
// do not allow nodes without UUIDs or reregistration of documents
$this->validateDocumentRegistration($document, $locale, $node, $oid, $uuid);
$this->documentMap[$oid] = $document;
$this->documentNodeMap[$oid] = $uuid;
$this->nodeMap[$node->getIdentifier()] = $node;
$this->nodeDocumentMap[$this->getNodeLocaleKey($node->getIdentifier(), $locale)] = $document;
$this->documentLocaleMap[$oid] = $locale;
} | [
"public",
"function",
"registerDocument",
"(",
"$",
"document",
",",
"NodeInterface",
"$",
"node",
",",
"$",
"locale",
")",
"{",
"$",
"oid",
"=",
"$",
"this",
"->",
"getObjectIdentifier",
"(",
"$",
"document",
")",
";",
"$",
"uuid",
"=",
"$",
"node",
"->",
"getIdentifier",
"(",
")",
";",
"// do not allow nodes without UUIDs or reregistration of documents",
"$",
"this",
"->",
"validateDocumentRegistration",
"(",
"$",
"document",
",",
"$",
"locale",
",",
"$",
"node",
",",
"$",
"oid",
",",
"$",
"uuid",
")",
";",
"$",
"this",
"->",
"documentMap",
"[",
"$",
"oid",
"]",
"=",
"$",
"document",
";",
"$",
"this",
"->",
"documentNodeMap",
"[",
"$",
"oid",
"]",
"=",
"$",
"uuid",
";",
"$",
"this",
"->",
"nodeMap",
"[",
"$",
"node",
"->",
"getIdentifier",
"(",
")",
"]",
"=",
"$",
"node",
";",
"$",
"this",
"->",
"nodeDocumentMap",
"[",
"$",
"this",
"->",
"getNodeLocaleKey",
"(",
"$",
"node",
"->",
"getIdentifier",
"(",
")",
",",
"$",
"locale",
")",
"]",
"=",
"$",
"document",
";",
"$",
"this",
"->",
"documentLocaleMap",
"[",
"$",
"oid",
"]",
"=",
"$",
"locale",
";",
"}"
] | Register a document.
@param mixed $document
@param NodeInterface $node
@param NodeInterface $node
@param string $locale
@throws DocumentManagerException | [
"Register",
"a",
"document",
"."
] | 6766a36cc2f0c807c59202bf7540a08c4ef31192 | https://github.com/sulu/sulu/blob/6766a36cc2f0c807c59202bf7540a08c4ef31192/src/Sulu/Component/DocumentManager/DocumentRegistry.php#L76-L89 | train |
sulu/sulu | src/Sulu/Component/DocumentManager/DocumentRegistry.php | DocumentRegistry.hasDocument | public function hasDocument($document)
{
$oid = $this->getObjectIdentifier($document);
return isset($this->documentMap[$oid]);
} | php | public function hasDocument($document)
{
$oid = $this->getObjectIdentifier($document);
return isset($this->documentMap[$oid]);
} | [
"public",
"function",
"hasDocument",
"(",
"$",
"document",
")",
"{",
"$",
"oid",
"=",
"$",
"this",
"->",
"getObjectIdentifier",
"(",
"$",
"document",
")",
";",
"return",
"isset",
"(",
"$",
"this",
"->",
"documentMap",
"[",
"$",
"oid",
"]",
")",
";",
"}"
] | Return true if the document is managed.
@param object $document
@return bool | [
"Return",
"true",
"if",
"the",
"document",
"is",
"managed",
"."
] | 6766a36cc2f0c807c59202bf7540a08c4ef31192 | https://github.com/sulu/sulu/blob/6766a36cc2f0c807c59202bf7540a08c4ef31192/src/Sulu/Component/DocumentManager/DocumentRegistry.php#L98-L103 | train |
sulu/sulu | src/Sulu/Component/DocumentManager/DocumentRegistry.php | DocumentRegistry.hasNode | public function hasNode(NodeInterface $node, $locale)
{
return array_key_exists($this->getNodeLocaleKey($node->getIdentifier(), $locale), $this->nodeDocumentMap);
} | php | public function hasNode(NodeInterface $node, $locale)
{
return array_key_exists($this->getNodeLocaleKey($node->getIdentifier(), $locale), $this->nodeDocumentMap);
} | [
"public",
"function",
"hasNode",
"(",
"NodeInterface",
"$",
"node",
",",
"$",
"locale",
")",
"{",
"return",
"array_key_exists",
"(",
"$",
"this",
"->",
"getNodeLocaleKey",
"(",
"$",
"node",
"->",
"getIdentifier",
"(",
")",
",",
"$",
"locale",
")",
",",
"$",
"this",
"->",
"nodeDocumentMap",
")",
";",
"}"
] | Return true if the node is managed.
@param NodeInterface $node
@param string $locale
@return bool | [
"Return",
"true",
"if",
"the",
"node",
"is",
"managed",
"."
] | 6766a36cc2f0c807c59202bf7540a08c4ef31192 | https://github.com/sulu/sulu/blob/6766a36cc2f0c807c59202bf7540a08c4ef31192/src/Sulu/Component/DocumentManager/DocumentRegistry.php#L113-L116 | train |
sulu/sulu | src/Sulu/Component/DocumentManager/DocumentRegistry.php | DocumentRegistry.deregisterDocument | public function deregisterDocument($document)
{
$oid = $this->getObjectIdentifier($document);
$this->assertDocumentExists($document);
$nodeIdentifier = $this->documentNodeMap[$oid];
$locale = $this->documentLocaleMap[$oid];
unset($this->nodeMap[$nodeIdentifier]);
unset($this->nodeDocumentMap[$this->getNodeLocaleKey($nodeIdentifier, $locale)]);
unset($this->documentMap[$oid]);
unset($this->documentNodeMap[$oid]);
unset($this->documentLocaleMap[$oid]);
unset($this->hydrationState[$oid]);
} | php | public function deregisterDocument($document)
{
$oid = $this->getObjectIdentifier($document);
$this->assertDocumentExists($document);
$nodeIdentifier = $this->documentNodeMap[$oid];
$locale = $this->documentLocaleMap[$oid];
unset($this->nodeMap[$nodeIdentifier]);
unset($this->nodeDocumentMap[$this->getNodeLocaleKey($nodeIdentifier, $locale)]);
unset($this->documentMap[$oid]);
unset($this->documentNodeMap[$oid]);
unset($this->documentLocaleMap[$oid]);
unset($this->hydrationState[$oid]);
} | [
"public",
"function",
"deregisterDocument",
"(",
"$",
"document",
")",
"{",
"$",
"oid",
"=",
"$",
"this",
"->",
"getObjectIdentifier",
"(",
"$",
"document",
")",
";",
"$",
"this",
"->",
"assertDocumentExists",
"(",
"$",
"document",
")",
";",
"$",
"nodeIdentifier",
"=",
"$",
"this",
"->",
"documentNodeMap",
"[",
"$",
"oid",
"]",
";",
"$",
"locale",
"=",
"$",
"this",
"->",
"documentLocaleMap",
"[",
"$",
"oid",
"]",
";",
"unset",
"(",
"$",
"this",
"->",
"nodeMap",
"[",
"$",
"nodeIdentifier",
"]",
")",
";",
"unset",
"(",
"$",
"this",
"->",
"nodeDocumentMap",
"[",
"$",
"this",
"->",
"getNodeLocaleKey",
"(",
"$",
"nodeIdentifier",
",",
"$",
"locale",
")",
"]",
")",
";",
"unset",
"(",
"$",
"this",
"->",
"documentMap",
"[",
"$",
"oid",
"]",
")",
";",
"unset",
"(",
"$",
"this",
"->",
"documentNodeMap",
"[",
"$",
"oid",
"]",
")",
";",
"unset",
"(",
"$",
"this",
"->",
"documentLocaleMap",
"[",
"$",
"oid",
"]",
")",
";",
"unset",
"(",
"$",
"this",
"->",
"hydrationState",
"[",
"$",
"oid",
"]",
")",
";",
"}"
] | Remove all references to the given document and its
associated node.
@param object $document | [
"Remove",
"all",
"references",
"to",
"the",
"given",
"document",
"and",
"its",
"associated",
"node",
"."
] | 6766a36cc2f0c807c59202bf7540a08c4ef31192 | https://github.com/sulu/sulu/blob/6766a36cc2f0c807c59202bf7540a08c4ef31192/src/Sulu/Component/DocumentManager/DocumentRegistry.php#L137-L150 | train |
sulu/sulu | src/Sulu/Component/DocumentManager/DocumentRegistry.php | DocumentRegistry.getNodeForDocument | public function getNodeForDocument($document)
{
$oid = $this->getObjectIdentifier($document);
$this->assertDocumentExists($document);
return $this->nodeMap[$this->documentNodeMap[$oid]];
} | php | public function getNodeForDocument($document)
{
$oid = $this->getObjectIdentifier($document);
$this->assertDocumentExists($document);
return $this->nodeMap[$this->documentNodeMap[$oid]];
} | [
"public",
"function",
"getNodeForDocument",
"(",
"$",
"document",
")",
"{",
"$",
"oid",
"=",
"$",
"this",
"->",
"getObjectIdentifier",
"(",
"$",
"document",
")",
";",
"$",
"this",
"->",
"assertDocumentExists",
"(",
"$",
"document",
")",
";",
"return",
"$",
"this",
"->",
"nodeMap",
"[",
"$",
"this",
"->",
"documentNodeMap",
"[",
"$",
"oid",
"]",
"]",
";",
"}"
] | Return the node for the given managed document.
@param object $document
@throws \RuntimeException If the node is not managed
@return NodeInterface | [
"Return",
"the",
"node",
"for",
"the",
"given",
"managed",
"document",
"."
] | 6766a36cc2f0c807c59202bf7540a08c4ef31192 | https://github.com/sulu/sulu/blob/6766a36cc2f0c807c59202bf7540a08c4ef31192/src/Sulu/Component/DocumentManager/DocumentRegistry.php#L161-L167 | train |
sulu/sulu | src/Sulu/Component/DocumentManager/DocumentRegistry.php | DocumentRegistry.getLocaleForDocument | public function getLocaleForDocument($document)
{
$oid = $this->getObjectIdentifier($document);
$this->assertDocumentExists($document);
return $this->documentLocaleMap[$oid];
} | php | public function getLocaleForDocument($document)
{
$oid = $this->getObjectIdentifier($document);
$this->assertDocumentExists($document);
return $this->documentLocaleMap[$oid];
} | [
"public",
"function",
"getLocaleForDocument",
"(",
"$",
"document",
")",
"{",
"$",
"oid",
"=",
"$",
"this",
"->",
"getObjectIdentifier",
"(",
"$",
"document",
")",
";",
"$",
"this",
"->",
"assertDocumentExists",
"(",
"$",
"document",
")",
";",
"return",
"$",
"this",
"->",
"documentLocaleMap",
"[",
"$",
"oid",
"]",
";",
"}"
] | Return the current locale for the given document.
@param object $document
@return string | [
"Return",
"the",
"current",
"locale",
"for",
"the",
"given",
"document",
"."
] | 6766a36cc2f0c807c59202bf7540a08c4ef31192 | https://github.com/sulu/sulu/blob/6766a36cc2f0c807c59202bf7540a08c4ef31192/src/Sulu/Component/DocumentManager/DocumentRegistry.php#L176-L182 | train |
sulu/sulu | src/Sulu/Component/DocumentManager/DocumentRegistry.php | DocumentRegistry.getOriginalLocaleForDocument | public function getOriginalLocaleForDocument($document)
{
$this->assertDocumentExists($document);
if ($document instanceof LocaleBehavior) {
return $document->getOriginalLocale() ?: $document->getLocale();
}
return $this->getLocaleForDocument($document);
} | php | public function getOriginalLocaleForDocument($document)
{
$this->assertDocumentExists($document);
if ($document instanceof LocaleBehavior) {
return $document->getOriginalLocale() ?: $document->getLocale();
}
return $this->getLocaleForDocument($document);
} | [
"public",
"function",
"getOriginalLocaleForDocument",
"(",
"$",
"document",
")",
"{",
"$",
"this",
"->",
"assertDocumentExists",
"(",
"$",
"document",
")",
";",
"if",
"(",
"$",
"document",
"instanceof",
"LocaleBehavior",
")",
"{",
"return",
"$",
"document",
"->",
"getOriginalLocale",
"(",
")",
"?",
":",
"$",
"document",
"->",
"getLocale",
"(",
")",
";",
"}",
"return",
"$",
"this",
"->",
"getLocaleForDocument",
"(",
"$",
"document",
")",
";",
"}"
] | Return the original locale for the document.
@param object $document
@return string | [
"Return",
"the",
"original",
"locale",
"for",
"the",
"document",
"."
] | 6766a36cc2f0c807c59202bf7540a08c4ef31192 | https://github.com/sulu/sulu/blob/6766a36cc2f0c807c59202bf7540a08c4ef31192/src/Sulu/Component/DocumentManager/DocumentRegistry.php#L191-L200 | train |
sulu/sulu | src/Sulu/Component/DocumentManager/DocumentRegistry.php | DocumentRegistry.getDocumentForNode | public function getDocumentForNode(NodeInterface $node, $locale)
{
$identifier = $node->getIdentifier();
$this->assertNodeExists($identifier);
return $this->nodeDocumentMap[$this->getNodeLocaleKey($node->getIdentifier(), $locale)];
} | php | public function getDocumentForNode(NodeInterface $node, $locale)
{
$identifier = $node->getIdentifier();
$this->assertNodeExists($identifier);
return $this->nodeDocumentMap[$this->getNodeLocaleKey($node->getIdentifier(), $locale)];
} | [
"public",
"function",
"getDocumentForNode",
"(",
"NodeInterface",
"$",
"node",
",",
"$",
"locale",
")",
"{",
"$",
"identifier",
"=",
"$",
"node",
"->",
"getIdentifier",
"(",
")",
";",
"$",
"this",
"->",
"assertNodeExists",
"(",
"$",
"identifier",
")",
";",
"return",
"$",
"this",
"->",
"nodeDocumentMap",
"[",
"$",
"this",
"->",
"getNodeLocaleKey",
"(",
"$",
"node",
"->",
"getIdentifier",
"(",
")",
",",
"$",
"locale",
")",
"]",
";",
"}"
] | Return the document for the given managed node.
@param NodeInterface $node
@param string $locale
@return mixed If the node is not managed | [
"Return",
"the",
"document",
"for",
"the",
"given",
"managed",
"node",
"."
] | 6766a36cc2f0c807c59202bf7540a08c4ef31192 | https://github.com/sulu/sulu/blob/6766a36cc2f0c807c59202bf7540a08c4ef31192/src/Sulu/Component/DocumentManager/DocumentRegistry.php#L210-L216 | train |
sulu/sulu | src/Sulu/Component/DocumentManager/DocumentRegistry.php | DocumentRegistry.validateDocumentRegistration | private function validateDocumentRegistration($document, $locale, NodeInterface $node, $oid, $uuid)
{
if (null === $uuid) {
throw new DocumentManagerException(sprintf(
'Node "%s" of type "%s" has no UUID. Only referencable nodes can be registered by the document manager',
$node->getPath(), $node->getPrimaryNodeType()->getName()
));
}
$documentNodeKey = $this->getNodeLocaleKey($node->getIdentifier(), $locale);
if (array_key_exists($uuid, $this->nodeMap) && array_key_exists($documentNodeKey, $this->nodeDocumentMap)) {
$registeredDocument = $this->nodeDocumentMap[$documentNodeKey];
throw new \RuntimeException(sprintf(
'Document "%s" (%s) is already registered for node "%s" (%s) when trying to register document "%s" (%s)',
spl_object_hash($registeredDocument),
get_class($registeredDocument),
$uuid,
$node->getPath(),
$oid,
get_class($document)
));
}
} | php | private function validateDocumentRegistration($document, $locale, NodeInterface $node, $oid, $uuid)
{
if (null === $uuid) {
throw new DocumentManagerException(sprintf(
'Node "%s" of type "%s" has no UUID. Only referencable nodes can be registered by the document manager',
$node->getPath(), $node->getPrimaryNodeType()->getName()
));
}
$documentNodeKey = $this->getNodeLocaleKey($node->getIdentifier(), $locale);
if (array_key_exists($uuid, $this->nodeMap) && array_key_exists($documentNodeKey, $this->nodeDocumentMap)) {
$registeredDocument = $this->nodeDocumentMap[$documentNodeKey];
throw new \RuntimeException(sprintf(
'Document "%s" (%s) is already registered for node "%s" (%s) when trying to register document "%s" (%s)',
spl_object_hash($registeredDocument),
get_class($registeredDocument),
$uuid,
$node->getPath(),
$oid,
get_class($document)
));
}
} | [
"private",
"function",
"validateDocumentRegistration",
"(",
"$",
"document",
",",
"$",
"locale",
",",
"NodeInterface",
"$",
"node",
",",
"$",
"oid",
",",
"$",
"uuid",
")",
"{",
"if",
"(",
"null",
"===",
"$",
"uuid",
")",
"{",
"throw",
"new",
"DocumentManagerException",
"(",
"sprintf",
"(",
"'Node \"%s\" of type \"%s\" has no UUID. Only referencable nodes can be registered by the document manager'",
",",
"$",
"node",
"->",
"getPath",
"(",
")",
",",
"$",
"node",
"->",
"getPrimaryNodeType",
"(",
")",
"->",
"getName",
"(",
")",
")",
")",
";",
"}",
"$",
"documentNodeKey",
"=",
"$",
"this",
"->",
"getNodeLocaleKey",
"(",
"$",
"node",
"->",
"getIdentifier",
"(",
")",
",",
"$",
"locale",
")",
";",
"if",
"(",
"array_key_exists",
"(",
"$",
"uuid",
",",
"$",
"this",
"->",
"nodeMap",
")",
"&&",
"array_key_exists",
"(",
"$",
"documentNodeKey",
",",
"$",
"this",
"->",
"nodeDocumentMap",
")",
")",
"{",
"$",
"registeredDocument",
"=",
"$",
"this",
"->",
"nodeDocumentMap",
"[",
"$",
"documentNodeKey",
"]",
";",
"throw",
"new",
"\\",
"RuntimeException",
"(",
"sprintf",
"(",
"'Document \"%s\" (%s) is already registered for node \"%s\" (%s) when trying to register document \"%s\" (%s)'",
",",
"spl_object_hash",
"(",
"$",
"registeredDocument",
")",
",",
"get_class",
"(",
"$",
"registeredDocument",
")",
",",
"$",
"uuid",
",",
"$",
"node",
"->",
"getPath",
"(",
")",
",",
"$",
"oid",
",",
"get_class",
"(",
"$",
"document",
")",
")",
")",
";",
"}",
"}"
] | Ensure that the document is not already registered and that the node
has a UUID.
@param object $document
@param NodeInterface $node
@param string $oid
@param string $uuid
@throws DocumentManagerException | [
"Ensure",
"that",
"the",
"document",
"is",
"not",
"already",
"registered",
"and",
"that",
"the",
"node",
"has",
"a",
"UUID",
"."
] | 6766a36cc2f0c807c59202bf7540a08c4ef31192 | https://github.com/sulu/sulu/blob/6766a36cc2f0c807c59202bf7540a08c4ef31192/src/Sulu/Component/DocumentManager/DocumentRegistry.php#L279-L302 | train |
sulu/sulu | src/Sulu/Bundle/ResourceBundle/Entity/FilterRepository.php | FilterRepository.getFilterQuery | protected function getFilterQuery($locale)
{
$qb = $this->createQueryBuilder('filter')
->addSelect('conditionGroups')
->addSelect('translations')
->addSelect('conditions')
->leftJoin(
'filter.translations',
'translations',
'WITH',
'translations.locale = :locale'
)
->leftJoin('filter.conditionGroups', 'conditionGroups')
->leftJoin('conditionGroups.conditions', 'conditions')
->setParameter('locale', $locale);
return $qb;
} | php | protected function getFilterQuery($locale)
{
$qb = $this->createQueryBuilder('filter')
->addSelect('conditionGroups')
->addSelect('translations')
->addSelect('conditions')
->leftJoin(
'filter.translations',
'translations',
'WITH',
'translations.locale = :locale'
)
->leftJoin('filter.conditionGroups', 'conditionGroups')
->leftJoin('conditionGroups.conditions', 'conditions')
->setParameter('locale', $locale);
return $qb;
} | [
"protected",
"function",
"getFilterQuery",
"(",
"$",
"locale",
")",
"{",
"$",
"qb",
"=",
"$",
"this",
"->",
"createQueryBuilder",
"(",
"'filter'",
")",
"->",
"addSelect",
"(",
"'conditionGroups'",
")",
"->",
"addSelect",
"(",
"'translations'",
")",
"->",
"addSelect",
"(",
"'conditions'",
")",
"->",
"leftJoin",
"(",
"'filter.translations'",
",",
"'translations'",
",",
"'WITH'",
",",
"'translations.locale = :locale'",
")",
"->",
"leftJoin",
"(",
"'filter.conditionGroups'",
",",
"'conditionGroups'",
")",
"->",
"leftJoin",
"(",
"'conditionGroups.conditions'",
",",
"'conditions'",
")",
"->",
"setParameter",
"(",
"'locale'",
",",
"$",
"locale",
")",
";",
"return",
"$",
"qb",
";",
"}"
] | Returns the query for filters.
@param string $locale The locale to load
@return \Doctrine\ORM\QueryBuilder | [
"Returns",
"the",
"query",
"for",
"filters",
"."
] | 6766a36cc2f0c807c59202bf7540a08c4ef31192 | https://github.com/sulu/sulu/blob/6766a36cc2f0c807c59202bf7540a08c4ef31192/src/Sulu/Bundle/ResourceBundle/Entity/FilterRepository.php#L68-L85 | train |
sulu/sulu | src/Sulu/Bundle/ResourceBundle/Entity/FilterRepository.php | FilterRepository.deleteByIds | public function deleteByIds($ids)
{
$qb = $this->createQueryBuilder('filter')->delete()->where(
'filter.id IN (:ids)'
)->setParameter('ids', $ids);
$qb->getQuery()->execute();
} | php | public function deleteByIds($ids)
{
$qb = $this->createQueryBuilder('filter')->delete()->where(
'filter.id IN (:ids)'
)->setParameter('ids', $ids);
$qb->getQuery()->execute();
} | [
"public",
"function",
"deleteByIds",
"(",
"$",
"ids",
")",
"{",
"$",
"qb",
"=",
"$",
"this",
"->",
"createQueryBuilder",
"(",
"'filter'",
")",
"->",
"delete",
"(",
")",
"->",
"where",
"(",
"'filter.id IN (:ids)'",
")",
"->",
"setParameter",
"(",
"'ids'",
",",
"$",
"ids",
")",
";",
"$",
"qb",
"->",
"getQuery",
"(",
")",
"->",
"execute",
"(",
")",
";",
"}"
] | Deletes multiple filters.
@param $ids
@return mixed | [
"Deletes",
"multiple",
"filters",
"."
] | 6766a36cc2f0c807c59202bf7540a08c4ef31192 | https://github.com/sulu/sulu/blob/6766a36cc2f0c807c59202bf7540a08c4ef31192/src/Sulu/Bundle/ResourceBundle/Entity/FilterRepository.php#L110-L116 | train |
sulu/sulu | src/Sulu/Bundle/SnippetBundle/Snippet/SnippetRepository.php | SnippetRepository.getReferences | public function getReferences($uuid)
{
$session = $this->sessionManager->getSession();
$node = $session->getNodeByIdentifier($uuid);
return iterator_to_array($node->getReferences());
} | php | public function getReferences($uuid)
{
$session = $this->sessionManager->getSession();
$node = $session->getNodeByIdentifier($uuid);
return iterator_to_array($node->getReferences());
} | [
"public",
"function",
"getReferences",
"(",
"$",
"uuid",
")",
"{",
"$",
"session",
"=",
"$",
"this",
"->",
"sessionManager",
"->",
"getSession",
"(",
")",
";",
"$",
"node",
"=",
"$",
"session",
"->",
"getNodeByIdentifier",
"(",
"$",
"uuid",
")",
";",
"return",
"iterator_to_array",
"(",
"$",
"node",
"->",
"getReferences",
"(",
")",
")",
";",
"}"
] | Return the nodes which refer to the structure with the
given UUID.
@param string $uuid
@return \PHPCR\NodeInterface[] | [
"Return",
"the",
"nodes",
"which",
"refer",
"to",
"the",
"structure",
"with",
"the",
"given",
"UUID",
"."
] | 6766a36cc2f0c807c59202bf7540a08c4ef31192 | https://github.com/sulu/sulu/blob/6766a36cc2f0c807c59202bf7540a08c4ef31192/src/Sulu/Bundle/SnippetBundle/Snippet/SnippetRepository.php#L70-L76 | train |
sulu/sulu | src/Sulu/Bundle/SnippetBundle/Snippet/SnippetRepository.php | SnippetRepository.getSnippetsByUuids | public function getSnippetsByUuids(array $uuids, $locale, $loadGhostContent = false)
{
$snippets = [];
foreach ($uuids as $uuid) {
try {
$snippet = $this->documentManager->find($uuid, $locale, [
'load_ghost_content' => $loadGhostContent,
]);
$snippets[] = $snippet;
} catch (DocumentNotFoundException $e) {
// ignore not found items
}
}
return $snippets;
} | php | public function getSnippetsByUuids(array $uuids, $locale, $loadGhostContent = false)
{
$snippets = [];
foreach ($uuids as $uuid) {
try {
$snippet = $this->documentManager->find($uuid, $locale, [
'load_ghost_content' => $loadGhostContent,
]);
$snippets[] = $snippet;
} catch (DocumentNotFoundException $e) {
// ignore not found items
}
}
return $snippets;
} | [
"public",
"function",
"getSnippetsByUuids",
"(",
"array",
"$",
"uuids",
",",
"$",
"locale",
",",
"$",
"loadGhostContent",
"=",
"false",
")",
"{",
"$",
"snippets",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"uuids",
"as",
"$",
"uuid",
")",
"{",
"try",
"{",
"$",
"snippet",
"=",
"$",
"this",
"->",
"documentManager",
"->",
"find",
"(",
"$",
"uuid",
",",
"$",
"locale",
",",
"[",
"'load_ghost_content'",
"=>",
"$",
"loadGhostContent",
",",
"]",
")",
";",
"$",
"snippets",
"[",
"]",
"=",
"$",
"snippet",
";",
"}",
"catch",
"(",
"DocumentNotFoundException",
"$",
"e",
")",
"{",
"// ignore not found items",
"}",
"}",
"return",
"$",
"snippets",
";",
"}"
] | Return snippets identified by the given UUIDs.
UUIDs which fail to resolve to a snippet will be ignored.
@param array $uuids
@param string $locale
@param bool $loadGhostContent
@return SnippetDocument | [
"Return",
"snippets",
"identified",
"by",
"the",
"given",
"UUIDs",
"."
] | 6766a36cc2f0c807c59202bf7540a08c4ef31192 | https://github.com/sulu/sulu/blob/6766a36cc2f0c807c59202bf7540a08c4ef31192/src/Sulu/Bundle/SnippetBundle/Snippet/SnippetRepository.php#L89-L105 | train |
sulu/sulu | src/Sulu/Bundle/SnippetBundle/Snippet/SnippetRepository.php | SnippetRepository.getSnippets | public function getSnippets(
$locale,
$type = null,
$offset = null,
$max = null,
$search = null,
$sortBy = null,
$sortOrder = null
) {
$query = $this->getSnippetsQuery($locale, $type, $offset, $max, $search, $sortBy, $sortOrder);
$documents = $this->documentManager->createQuery($query, $locale, [
'load_ghost_content' => true,
])->execute();
return $documents;
} | php | public function getSnippets(
$locale,
$type = null,
$offset = null,
$max = null,
$search = null,
$sortBy = null,
$sortOrder = null
) {
$query = $this->getSnippetsQuery($locale, $type, $offset, $max, $search, $sortBy, $sortOrder);
$documents = $this->documentManager->createQuery($query, $locale, [
'load_ghost_content' => true,
])->execute();
return $documents;
} | [
"public",
"function",
"getSnippets",
"(",
"$",
"locale",
",",
"$",
"type",
"=",
"null",
",",
"$",
"offset",
"=",
"null",
",",
"$",
"max",
"=",
"null",
",",
"$",
"search",
"=",
"null",
",",
"$",
"sortBy",
"=",
"null",
",",
"$",
"sortOrder",
"=",
"null",
")",
"{",
"$",
"query",
"=",
"$",
"this",
"->",
"getSnippetsQuery",
"(",
"$",
"locale",
",",
"$",
"type",
",",
"$",
"offset",
",",
"$",
"max",
",",
"$",
"search",
",",
"$",
"sortBy",
",",
"$",
"sortOrder",
")",
";",
"$",
"documents",
"=",
"$",
"this",
"->",
"documentManager",
"->",
"createQuery",
"(",
"$",
"query",
",",
"$",
"locale",
",",
"[",
"'load_ghost_content'",
"=>",
"true",
",",
"]",
")",
"->",
"execute",
"(",
")",
";",
"return",
"$",
"documents",
";",
"}"
] | Return snippets.
If $type is given then only return the snippets of that type.
@param string $locale
@param string $type Optional snippet type
@param int $offset Optional offset
@param int $max Optional max
@param string $search
@param string $sortBy
@param string $sortOrder
@throws \InvalidArgumentException
@return SnippetDocument[] | [
"Return",
"snippets",
"."
] | 6766a36cc2f0c807c59202bf7540a08c4ef31192 | https://github.com/sulu/sulu/blob/6766a36cc2f0c807c59202bf7540a08c4ef31192/src/Sulu/Bundle/SnippetBundle/Snippet/SnippetRepository.php#L124-L139 | train |
sulu/sulu | src/Sulu/Bundle/SnippetBundle/Snippet/SnippetRepository.php | SnippetRepository.getSnippetsAmount | public function getSnippetsAmount(
$locale,
$type = null,
$search = null,
$sortBy = null,
$sortOrder = null
) {
$query = $this->getSnippetsQuery($locale, $type, null, null, $search, $sortBy, $sortOrder);
$result = $query->execute();
return count(iterator_to_array($result->getRows()));
} | php | public function getSnippetsAmount(
$locale,
$type = null,
$search = null,
$sortBy = null,
$sortOrder = null
) {
$query = $this->getSnippetsQuery($locale, $type, null, null, $search, $sortBy, $sortOrder);
$result = $query->execute();
return count(iterator_to_array($result->getRows()));
} | [
"public",
"function",
"getSnippetsAmount",
"(",
"$",
"locale",
",",
"$",
"type",
"=",
"null",
",",
"$",
"search",
"=",
"null",
",",
"$",
"sortBy",
"=",
"null",
",",
"$",
"sortOrder",
"=",
"null",
")",
"{",
"$",
"query",
"=",
"$",
"this",
"->",
"getSnippetsQuery",
"(",
"$",
"locale",
",",
"$",
"type",
",",
"null",
",",
"null",
",",
"$",
"search",
",",
"$",
"sortBy",
",",
"$",
"sortOrder",
")",
";",
"$",
"result",
"=",
"$",
"query",
"->",
"execute",
"(",
")",
";",
"return",
"count",
"(",
"iterator_to_array",
"(",
"$",
"result",
"->",
"getRows",
"(",
")",
")",
")",
";",
"}"
] | Return snippets amount.
If $type is given then only return the snippets of that type.
@param string $locale
@param string $type Optional snippet type
@param string $search
@param string $sortBy
@param string $sortOrder
@throws \InvalidArgumentException
@return SnippetBridge[] | [
"Return",
"snippets",
"amount",
"."
] | 6766a36cc2f0c807c59202bf7540a08c4ef31192 | https://github.com/sulu/sulu/blob/6766a36cc2f0c807c59202bf7540a08c4ef31192/src/Sulu/Bundle/SnippetBundle/Snippet/SnippetRepository.php#L156-L167 | train |
sulu/sulu | src/Sulu/Bundle/SnippetBundle/Snippet/SnippetRepository.php | SnippetRepository.copyLocale | public function copyLocale($uuid, $userId, $srcLocale, $destLocales)
{
return $this->contentMapper->copyLanguage(
$uuid,
$userId,
null,
$srcLocale,
$destLocales,
Structure::TYPE_SNIPPET
);
} | php | public function copyLocale($uuid, $userId, $srcLocale, $destLocales)
{
return $this->contentMapper->copyLanguage(
$uuid,
$userId,
null,
$srcLocale,
$destLocales,
Structure::TYPE_SNIPPET
);
} | [
"public",
"function",
"copyLocale",
"(",
"$",
"uuid",
",",
"$",
"userId",
",",
"$",
"srcLocale",
",",
"$",
"destLocales",
")",
"{",
"return",
"$",
"this",
"->",
"contentMapper",
"->",
"copyLanguage",
"(",
"$",
"uuid",
",",
"$",
"userId",
",",
"null",
",",
"$",
"srcLocale",
",",
"$",
"destLocales",
",",
"Structure",
"::",
"TYPE_SNIPPET",
")",
";",
"}"
] | Copy snippet from src-locale to dest-locale.
TODO: We currently need the content mapper to copy the locale, it should be
removed, see https://github.com/sulu-io/sulu/issues/1998
@param string $uuid
@param int $userId
@param string $srcLocale
@param array $destLocales
@return SnippetBridge | [
"Copy",
"snippet",
"from",
"src",
"-",
"locale",
"to",
"dest",
"-",
"locale",
"."
] | 6766a36cc2f0c807c59202bf7540a08c4ef31192 | https://github.com/sulu/sulu/blob/6766a36cc2f0c807c59202bf7540a08c4ef31192/src/Sulu/Bundle/SnippetBundle/Snippet/SnippetRepository.php#L182-L192 | train |
sulu/sulu | src/Sulu/Bundle/SnippetBundle/Snippet/SnippetRepository.php | SnippetRepository.getSnippetsQuery | private function getSnippetsQuery(
$locale,
$type = null,
$offset = null,
$max = null,
$search = null,
$sortBy = null,
$sortOrder = null
) {
$snippetNode = $this->sessionManager->getSnippetNode($type);
$workspace = $this->sessionManager->getSession()->getWorkspace();
$queryManager = $workspace->getQueryManager();
$qf = $queryManager->getQOMFactory();
$qb = new QueryBuilder($qf);
$qb->from(
$qb->qomf()->selector('a', 'nt:unstructured')
);
if (null === $type) {
$qb->where(
$qb->qomf()->descendantNode('a', $snippetNode->getPath())
);
} else {
$qb->where(
$qb->qomf()->childNode('a', $snippetNode->getPath())
);
}
$qb->andWhere(
$qb->qomf()->comparison(
$qb->qomf()->propertyValue('a', 'jcr:mixinTypes'),
QueryObjectModelConstantsInterface::JCR_OPERATOR_EQUAL_TO,
$qb->qomf()->literal('sulu:snippet')
)
);
if (null !== $offset) {
$qb->setFirstResult($offset);
if (null === $max) {
// we get zero results if no max specified
throw new \InvalidArgumentException(
'If you specify an offset then you must also specify $max'
);
}
$qb->setMaxResults($max);
}
if (null !== $search) {
$search = str_replace('*', '%', $search);
$searchConstraint = $qf->orConstraint(
$qf->comparison(
$qf->propertyValue('a', 'i18n:' . $locale . '-title'),
QueryObjectModelConstantsInterface::JCR_OPERATOR_LIKE,
$qf->literal('%' . $search . '%')
),
$qf->comparison(
$qf->propertyValue('a', 'template'),
QueryObjectModelConstantsInterface::JCR_OPERATOR_LIKE,
$qf->literal('%' . $search . '%')
)
);
$qb->andWhere($searchConstraint);
}
// Title is a mandatory property for snippets
// NOTE: Prefixing the language code and namespace here is bad. But the solution is
// refactoring (i.e. a node property name translator service).
$sortOrder = (null !== $sortOrder ? strtoupper($sortOrder) : 'ASC');
$sortBy = (null !== $sortBy ? $sortBy : 'title');
$qb->orderBy(
$qb->qomf()->propertyValue('a', 'i18n:' . $locale . '-' . $sortBy),
null !== $sortOrder ? strtoupper($sortOrder) : 'ASC'
);
return $qb->getQuery();
} | php | private function getSnippetsQuery(
$locale,
$type = null,
$offset = null,
$max = null,
$search = null,
$sortBy = null,
$sortOrder = null
) {
$snippetNode = $this->sessionManager->getSnippetNode($type);
$workspace = $this->sessionManager->getSession()->getWorkspace();
$queryManager = $workspace->getQueryManager();
$qf = $queryManager->getQOMFactory();
$qb = new QueryBuilder($qf);
$qb->from(
$qb->qomf()->selector('a', 'nt:unstructured')
);
if (null === $type) {
$qb->where(
$qb->qomf()->descendantNode('a', $snippetNode->getPath())
);
} else {
$qb->where(
$qb->qomf()->childNode('a', $snippetNode->getPath())
);
}
$qb->andWhere(
$qb->qomf()->comparison(
$qb->qomf()->propertyValue('a', 'jcr:mixinTypes'),
QueryObjectModelConstantsInterface::JCR_OPERATOR_EQUAL_TO,
$qb->qomf()->literal('sulu:snippet')
)
);
if (null !== $offset) {
$qb->setFirstResult($offset);
if (null === $max) {
// we get zero results if no max specified
throw new \InvalidArgumentException(
'If you specify an offset then you must also specify $max'
);
}
$qb->setMaxResults($max);
}
if (null !== $search) {
$search = str_replace('*', '%', $search);
$searchConstraint = $qf->orConstraint(
$qf->comparison(
$qf->propertyValue('a', 'i18n:' . $locale . '-title'),
QueryObjectModelConstantsInterface::JCR_OPERATOR_LIKE,
$qf->literal('%' . $search . '%')
),
$qf->comparison(
$qf->propertyValue('a', 'template'),
QueryObjectModelConstantsInterface::JCR_OPERATOR_LIKE,
$qf->literal('%' . $search . '%')
)
);
$qb->andWhere($searchConstraint);
}
// Title is a mandatory property for snippets
// NOTE: Prefixing the language code and namespace here is bad. But the solution is
// refactoring (i.e. a node property name translator service).
$sortOrder = (null !== $sortOrder ? strtoupper($sortOrder) : 'ASC');
$sortBy = (null !== $sortBy ? $sortBy : 'title');
$qb->orderBy(
$qb->qomf()->propertyValue('a', 'i18n:' . $locale . '-' . $sortBy),
null !== $sortOrder ? strtoupper($sortOrder) : 'ASC'
);
return $qb->getQuery();
} | [
"private",
"function",
"getSnippetsQuery",
"(",
"$",
"locale",
",",
"$",
"type",
"=",
"null",
",",
"$",
"offset",
"=",
"null",
",",
"$",
"max",
"=",
"null",
",",
"$",
"search",
"=",
"null",
",",
"$",
"sortBy",
"=",
"null",
",",
"$",
"sortOrder",
"=",
"null",
")",
"{",
"$",
"snippetNode",
"=",
"$",
"this",
"->",
"sessionManager",
"->",
"getSnippetNode",
"(",
"$",
"type",
")",
";",
"$",
"workspace",
"=",
"$",
"this",
"->",
"sessionManager",
"->",
"getSession",
"(",
")",
"->",
"getWorkspace",
"(",
")",
";",
"$",
"queryManager",
"=",
"$",
"workspace",
"->",
"getQueryManager",
"(",
")",
";",
"$",
"qf",
"=",
"$",
"queryManager",
"->",
"getQOMFactory",
"(",
")",
";",
"$",
"qb",
"=",
"new",
"QueryBuilder",
"(",
"$",
"qf",
")",
";",
"$",
"qb",
"->",
"from",
"(",
"$",
"qb",
"->",
"qomf",
"(",
")",
"->",
"selector",
"(",
"'a'",
",",
"'nt:unstructured'",
")",
")",
";",
"if",
"(",
"null",
"===",
"$",
"type",
")",
"{",
"$",
"qb",
"->",
"where",
"(",
"$",
"qb",
"->",
"qomf",
"(",
")",
"->",
"descendantNode",
"(",
"'a'",
",",
"$",
"snippetNode",
"->",
"getPath",
"(",
")",
")",
")",
";",
"}",
"else",
"{",
"$",
"qb",
"->",
"where",
"(",
"$",
"qb",
"->",
"qomf",
"(",
")",
"->",
"childNode",
"(",
"'a'",
",",
"$",
"snippetNode",
"->",
"getPath",
"(",
")",
")",
")",
";",
"}",
"$",
"qb",
"->",
"andWhere",
"(",
"$",
"qb",
"->",
"qomf",
"(",
")",
"->",
"comparison",
"(",
"$",
"qb",
"->",
"qomf",
"(",
")",
"->",
"propertyValue",
"(",
"'a'",
",",
"'jcr:mixinTypes'",
")",
",",
"QueryObjectModelConstantsInterface",
"::",
"JCR_OPERATOR_EQUAL_TO",
",",
"$",
"qb",
"->",
"qomf",
"(",
")",
"->",
"literal",
"(",
"'sulu:snippet'",
")",
")",
")",
";",
"if",
"(",
"null",
"!==",
"$",
"offset",
")",
"{",
"$",
"qb",
"->",
"setFirstResult",
"(",
"$",
"offset",
")",
";",
"if",
"(",
"null",
"===",
"$",
"max",
")",
"{",
"// we get zero results if no max specified",
"throw",
"new",
"\\",
"InvalidArgumentException",
"(",
"'If you specify an offset then you must also specify $max'",
")",
";",
"}",
"$",
"qb",
"->",
"setMaxResults",
"(",
"$",
"max",
")",
";",
"}",
"if",
"(",
"null",
"!==",
"$",
"search",
")",
"{",
"$",
"search",
"=",
"str_replace",
"(",
"'*'",
",",
"'%'",
",",
"$",
"search",
")",
";",
"$",
"searchConstraint",
"=",
"$",
"qf",
"->",
"orConstraint",
"(",
"$",
"qf",
"->",
"comparison",
"(",
"$",
"qf",
"->",
"propertyValue",
"(",
"'a'",
",",
"'i18n:'",
".",
"$",
"locale",
".",
"'-title'",
")",
",",
"QueryObjectModelConstantsInterface",
"::",
"JCR_OPERATOR_LIKE",
",",
"$",
"qf",
"->",
"literal",
"(",
"'%'",
".",
"$",
"search",
".",
"'%'",
")",
")",
",",
"$",
"qf",
"->",
"comparison",
"(",
"$",
"qf",
"->",
"propertyValue",
"(",
"'a'",
",",
"'template'",
")",
",",
"QueryObjectModelConstantsInterface",
"::",
"JCR_OPERATOR_LIKE",
",",
"$",
"qf",
"->",
"literal",
"(",
"'%'",
".",
"$",
"search",
".",
"'%'",
")",
")",
")",
";",
"$",
"qb",
"->",
"andWhere",
"(",
"$",
"searchConstraint",
")",
";",
"}",
"// Title is a mandatory property for snippets",
"// NOTE: Prefixing the language code and namespace here is bad. But the solution is",
"// refactoring (i.e. a node property name translator service).",
"$",
"sortOrder",
"=",
"(",
"null",
"!==",
"$",
"sortOrder",
"?",
"strtoupper",
"(",
"$",
"sortOrder",
")",
":",
"'ASC'",
")",
";",
"$",
"sortBy",
"=",
"(",
"null",
"!==",
"$",
"sortBy",
"?",
"$",
"sortBy",
":",
"'title'",
")",
";",
"$",
"qb",
"->",
"orderBy",
"(",
"$",
"qb",
"->",
"qomf",
"(",
")",
"->",
"propertyValue",
"(",
"'a'",
",",
"'i18n:'",
".",
"$",
"locale",
".",
"'-'",
".",
"$",
"sortBy",
")",
",",
"null",
"!==",
"$",
"sortOrder",
"?",
"strtoupper",
"(",
"$",
"sortOrder",
")",
":",
"'ASC'",
")",
";",
"return",
"$",
"qb",
"->",
"getQuery",
"(",
")",
";",
"}"
] | Return snippets load query.
If $type is given then only return the snippets of that type.
@param string $locale
@param string $type Optional snippet type
@param int $offset Optional offset
@param int $max Optional max
@param string $search
@param string $sortBy
@param string $sortOrder
@return Query | [
"Return",
"snippets",
"load",
"query",
"."
] | 6766a36cc2f0c807c59202bf7540a08c4ef31192 | https://github.com/sulu/sulu/blob/6766a36cc2f0c807c59202bf7540a08c4ef31192/src/Sulu/Bundle/SnippetBundle/Snippet/SnippetRepository.php#L209-L289 | train |
sulu/sulu | src/Sulu/Bundle/PageBundle/Controller/VersionController.php | VersionController.cgetAction | public function cgetAction(Request $request, $uuid)
{
$locale = $this->getRequestParameter($request, 'language', true);
$document = $this->get('sulu_document_manager.document_manager')->find($uuid, $request->query->get('language'));
$versions = array_reverse(array_filter($document->getVersions(), function($version) use ($locale) {
/* @var Version $version */
return $version->getLocale() === $locale;
}));
$total = count($versions);
$listRestHelper = $this->get('sulu_core.list_rest_helper');
$limit = $listRestHelper->getLimit();
$versions = array_slice($versions, $listRestHelper->getOffset(), $limit);
$userIds = array_unique(array_map(function($version) {
/* @var Version $version */
return $version->getAuthor();
}, $versions));
$users = $this->get('sulu_security.user_repository')->findUsersById($userIds);
$fullNamesByIds = [];
foreach ($users as $user) {
$fullNamesByIds[$user->getId()] = $user->getContact()->getFullName();
}
$versionData = [];
foreach ($versions as $version) {
$versionData[] = [
'id' => str_replace('.', '_', $version->getId()),
'locale' => $version->getLocale(),
'author' => array_key_exists($version->getAuthor(), $fullNamesByIds)
? $fullNamesByIds[$version->getAuthor()] : '',
'authored' => $version->getAuthored(),
];
}
$versionCollection = new ListRepresentation(
$versionData,
'versions',
'get_node_versions',
[
'uuid' => $uuid,
'language' => $locale,
'webspace' => $request->get('webspace'),
],
$listRestHelper->getPage(),
$limit,
$total
);
return $this->handleView($this->view($versionCollection));
} | php | public function cgetAction(Request $request, $uuid)
{
$locale = $this->getRequestParameter($request, 'language', true);
$document = $this->get('sulu_document_manager.document_manager')->find($uuid, $request->query->get('language'));
$versions = array_reverse(array_filter($document->getVersions(), function($version) use ($locale) {
/* @var Version $version */
return $version->getLocale() === $locale;
}));
$total = count($versions);
$listRestHelper = $this->get('sulu_core.list_rest_helper');
$limit = $listRestHelper->getLimit();
$versions = array_slice($versions, $listRestHelper->getOffset(), $limit);
$userIds = array_unique(array_map(function($version) {
/* @var Version $version */
return $version->getAuthor();
}, $versions));
$users = $this->get('sulu_security.user_repository')->findUsersById($userIds);
$fullNamesByIds = [];
foreach ($users as $user) {
$fullNamesByIds[$user->getId()] = $user->getContact()->getFullName();
}
$versionData = [];
foreach ($versions as $version) {
$versionData[] = [
'id' => str_replace('.', '_', $version->getId()),
'locale' => $version->getLocale(),
'author' => array_key_exists($version->getAuthor(), $fullNamesByIds)
? $fullNamesByIds[$version->getAuthor()] : '',
'authored' => $version->getAuthored(),
];
}
$versionCollection = new ListRepresentation(
$versionData,
'versions',
'get_node_versions',
[
'uuid' => $uuid,
'language' => $locale,
'webspace' => $request->get('webspace'),
],
$listRestHelper->getPage(),
$limit,
$total
);
return $this->handleView($this->view($versionCollection));
} | [
"public",
"function",
"cgetAction",
"(",
"Request",
"$",
"request",
",",
"$",
"uuid",
")",
"{",
"$",
"locale",
"=",
"$",
"this",
"->",
"getRequestParameter",
"(",
"$",
"request",
",",
"'language'",
",",
"true",
")",
";",
"$",
"document",
"=",
"$",
"this",
"->",
"get",
"(",
"'sulu_document_manager.document_manager'",
")",
"->",
"find",
"(",
"$",
"uuid",
",",
"$",
"request",
"->",
"query",
"->",
"get",
"(",
"'language'",
")",
")",
";",
"$",
"versions",
"=",
"array_reverse",
"(",
"array_filter",
"(",
"$",
"document",
"->",
"getVersions",
"(",
")",
",",
"function",
"(",
"$",
"version",
")",
"use",
"(",
"$",
"locale",
")",
"{",
"/* @var Version $version */",
"return",
"$",
"version",
"->",
"getLocale",
"(",
")",
"===",
"$",
"locale",
";",
"}",
")",
")",
";",
"$",
"total",
"=",
"count",
"(",
"$",
"versions",
")",
";",
"$",
"listRestHelper",
"=",
"$",
"this",
"->",
"get",
"(",
"'sulu_core.list_rest_helper'",
")",
";",
"$",
"limit",
"=",
"$",
"listRestHelper",
"->",
"getLimit",
"(",
")",
";",
"$",
"versions",
"=",
"array_slice",
"(",
"$",
"versions",
",",
"$",
"listRestHelper",
"->",
"getOffset",
"(",
")",
",",
"$",
"limit",
")",
";",
"$",
"userIds",
"=",
"array_unique",
"(",
"array_map",
"(",
"function",
"(",
"$",
"version",
")",
"{",
"/* @var Version $version */",
"return",
"$",
"version",
"->",
"getAuthor",
"(",
")",
";",
"}",
",",
"$",
"versions",
")",
")",
";",
"$",
"users",
"=",
"$",
"this",
"->",
"get",
"(",
"'sulu_security.user_repository'",
")",
"->",
"findUsersById",
"(",
"$",
"userIds",
")",
";",
"$",
"fullNamesByIds",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"users",
"as",
"$",
"user",
")",
"{",
"$",
"fullNamesByIds",
"[",
"$",
"user",
"->",
"getId",
"(",
")",
"]",
"=",
"$",
"user",
"->",
"getContact",
"(",
")",
"->",
"getFullName",
"(",
")",
";",
"}",
"$",
"versionData",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"versions",
"as",
"$",
"version",
")",
"{",
"$",
"versionData",
"[",
"]",
"=",
"[",
"'id'",
"=>",
"str_replace",
"(",
"'.'",
",",
"'_'",
",",
"$",
"version",
"->",
"getId",
"(",
")",
")",
",",
"'locale'",
"=>",
"$",
"version",
"->",
"getLocale",
"(",
")",
",",
"'author'",
"=>",
"array_key_exists",
"(",
"$",
"version",
"->",
"getAuthor",
"(",
")",
",",
"$",
"fullNamesByIds",
")",
"?",
"$",
"fullNamesByIds",
"[",
"$",
"version",
"->",
"getAuthor",
"(",
")",
"]",
":",
"''",
",",
"'authored'",
"=>",
"$",
"version",
"->",
"getAuthored",
"(",
")",
",",
"]",
";",
"}",
"$",
"versionCollection",
"=",
"new",
"ListRepresentation",
"(",
"$",
"versionData",
",",
"'versions'",
",",
"'get_node_versions'",
",",
"[",
"'uuid'",
"=>",
"$",
"uuid",
",",
"'language'",
"=>",
"$",
"locale",
",",
"'webspace'",
"=>",
"$",
"request",
"->",
"get",
"(",
"'webspace'",
")",
",",
"]",
",",
"$",
"listRestHelper",
"->",
"getPage",
"(",
")",
",",
"$",
"limit",
",",
"$",
"total",
")",
";",
"return",
"$",
"this",
"->",
"handleView",
"(",
"$",
"this",
"->",
"view",
"(",
"$",
"versionCollection",
")",
")",
";",
"}"
] | Returns the versions for the node with the given UUID.
@param Request $request
@param string $uuid
@return Response | [
"Returns",
"the",
"versions",
"for",
"the",
"node",
"with",
"the",
"given",
"UUID",
"."
] | 6766a36cc2f0c807c59202bf7540a08c4ef31192 | https://github.com/sulu/sulu/blob/6766a36cc2f0c807c59202bf7540a08c4ef31192/src/Sulu/Bundle/PageBundle/Controller/VersionController.php#L47-L100 | train |
sulu/sulu | src/Sulu/Bundle/CategoryBundle/Category/CategoryManager.php | CategoryManager.findOrCreateCategoryTranslation | private function findOrCreateCategoryTranslation(
CategoryInterface $category,
CategoryWrapper $categoryWrapper,
$locale
) {
$translationEntity = $category->findTranslationByLocale($locale);
if (!$translationEntity) {
$translationEntity = $this->categoryTranslationRepository->createNew();
$translationEntity->setLocale($locale);
$categoryWrapper->setTranslation($translationEntity);
}
return $translationEntity;
} | php | private function findOrCreateCategoryTranslation(
CategoryInterface $category,
CategoryWrapper $categoryWrapper,
$locale
) {
$translationEntity = $category->findTranslationByLocale($locale);
if (!$translationEntity) {
$translationEntity = $this->categoryTranslationRepository->createNew();
$translationEntity->setLocale($locale);
$categoryWrapper->setTranslation($translationEntity);
}
return $translationEntity;
} | [
"private",
"function",
"findOrCreateCategoryTranslation",
"(",
"CategoryInterface",
"$",
"category",
",",
"CategoryWrapper",
"$",
"categoryWrapper",
",",
"$",
"locale",
")",
"{",
"$",
"translationEntity",
"=",
"$",
"category",
"->",
"findTranslationByLocale",
"(",
"$",
"locale",
")",
";",
"if",
"(",
"!",
"$",
"translationEntity",
")",
"{",
"$",
"translationEntity",
"=",
"$",
"this",
"->",
"categoryTranslationRepository",
"->",
"createNew",
"(",
")",
";",
"$",
"translationEntity",
"->",
"setLocale",
"(",
"$",
"locale",
")",
";",
"$",
"categoryWrapper",
"->",
"setTranslation",
"(",
"$",
"translationEntity",
")",
";",
"}",
"return",
"$",
"translationEntity",
";",
"}"
] | Returns category-translation or create a new one.
@param CategoryInterface $category
@param CategoryWrapper $categoryWrapper
@param string $locale
@return CategoryTranslationInterface | [
"Returns",
"category",
"-",
"translation",
"or",
"create",
"a",
"new",
"one",
"."
] | 6766a36cc2f0c807c59202bf7540a08c4ef31192 | https://github.com/sulu/sulu/blob/6766a36cc2f0c807c59202bf7540a08c4ef31192/src/Sulu/Bundle/CategoryBundle/Category/CategoryManager.php#L165-L178 | train |
sulu/sulu | src/Sulu/Bundle/CategoryBundle/Category/CategoryManager.php | CategoryManager.getApiObject | public function getApiObject($category, $locale)
{
if ($category instanceof CategoryWrapper) {
$category = $category->getEntity();
}
if (!$category instanceof CategoryInterface) {
return;
}
return new CategoryWrapper($category, $locale);
} | php | public function getApiObject($category, $locale)
{
if ($category instanceof CategoryWrapper) {
$category = $category->getEntity();
}
if (!$category instanceof CategoryInterface) {
return;
}
return new CategoryWrapper($category, $locale);
} | [
"public",
"function",
"getApiObject",
"(",
"$",
"category",
",",
"$",
"locale",
")",
"{",
"if",
"(",
"$",
"category",
"instanceof",
"CategoryWrapper",
")",
"{",
"$",
"category",
"=",
"$",
"category",
"->",
"getEntity",
"(",
")",
";",
"}",
"if",
"(",
"!",
"$",
"category",
"instanceof",
"CategoryInterface",
")",
"{",
"return",
";",
"}",
"return",
"new",
"CategoryWrapper",
"(",
"$",
"category",
",",
"$",
"locale",
")",
";",
"}"
] | Returns an API-Object for a given category-entity. The API-Object wraps the entity
and provides neat getters and setters. If the given object is already an API-object,
the associated entity is used for wrapping.
@param $category
@param string $locale
@return null|CategoryWrapper | [
"Returns",
"an",
"API",
"-",
"Object",
"for",
"a",
"given",
"category",
"-",
"entity",
".",
"The",
"API",
"-",
"Object",
"wraps",
"the",
"entity",
"and",
"provides",
"neat",
"getters",
"and",
"setters",
".",
"If",
"the",
"given",
"object",
"is",
"already",
"an",
"API",
"-",
"object",
"the",
"associated",
"entity",
"is",
"used",
"for",
"wrapping",
"."
] | 6766a36cc2f0c807c59202bf7540a08c4ef31192 | https://github.com/sulu/sulu/blob/6766a36cc2f0c807c59202bf7540a08c4ef31192/src/Sulu/Bundle/CategoryBundle/Category/CategoryManager.php#L319-L329 | train |
sulu/sulu | src/Sulu/Bundle/CategoryBundle/Category/CategoryManager.php | CategoryManager.getApiObjects | public function getApiObjects($entities, $locale)
{
return array_map(
function($entity) use ($locale) {
return $this->getApiObject($entity, $locale);
},
$entities
);
} | php | public function getApiObjects($entities, $locale)
{
return array_map(
function($entity) use ($locale) {
return $this->getApiObject($entity, $locale);
},
$entities
);
} | [
"public",
"function",
"getApiObjects",
"(",
"$",
"entities",
",",
"$",
"locale",
")",
"{",
"return",
"array_map",
"(",
"function",
"(",
"$",
"entity",
")",
"use",
"(",
"$",
"locale",
")",
"{",
"return",
"$",
"this",
"->",
"getApiObject",
"(",
"$",
"entity",
",",
"$",
"locale",
")",
";",
"}",
",",
"$",
"entities",
")",
";",
"}"
] | Returns an array of API-Objects for a given array of category-entities.
The returned array can contain null-values, if the given entities are not valid.
@param $entities
@param $locale
@return array | [
"Returns",
"an",
"array",
"of",
"API",
"-",
"Objects",
"for",
"a",
"given",
"array",
"of",
"category",
"-",
"entities",
".",
"The",
"returned",
"array",
"can",
"contain",
"null",
"-",
"values",
"if",
"the",
"given",
"entities",
"are",
"not",
"valid",
"."
] | 6766a36cc2f0c807c59202bf7540a08c4ef31192 | https://github.com/sulu/sulu/blob/6766a36cc2f0c807c59202bf7540a08c4ef31192/src/Sulu/Bundle/CategoryBundle/Category/CategoryManager.php#L340-L348 | train |
sulu/sulu | src/Sulu/Bundle/MediaBundle/Entity/FileVersionMetaRepository.php | FileVersionMetaRepository.getQueryBuilderWithoutSecurity | public function getQueryBuilderWithoutSecurity(QueryBuilder $queryBuilder)
{
$queryBuilder->addSelect('fileVersion')
->addSelect('file')
->addSelect('media')
->addSelect('collection')
->leftJoin('d.fileVersion', 'fileVersion')
->leftJoin('fileVersion.file', 'file')
->leftJoin('file.media', 'media')
->leftJoin('media.collection', 'collection')
->leftJoin(
AccessControl::class,
'accessControl',
'WITH',
'accessControl.entityClass = :entityClass AND accessControl.entityId = collection.id'
)
->where('file.version = fileVersion.version')
->andWhere('accessControl.id is null')
->setParameter('entityClass', Collection::class);
return $queryBuilder;
} | php | public function getQueryBuilderWithoutSecurity(QueryBuilder $queryBuilder)
{
$queryBuilder->addSelect('fileVersion')
->addSelect('file')
->addSelect('media')
->addSelect('collection')
->leftJoin('d.fileVersion', 'fileVersion')
->leftJoin('fileVersion.file', 'file')
->leftJoin('file.media', 'media')
->leftJoin('media.collection', 'collection')
->leftJoin(
AccessControl::class,
'accessControl',
'WITH',
'accessControl.entityClass = :entityClass AND accessControl.entityId = collection.id'
)
->where('file.version = fileVersion.version')
->andWhere('accessControl.id is null')
->setParameter('entityClass', Collection::class);
return $queryBuilder;
} | [
"public",
"function",
"getQueryBuilderWithoutSecurity",
"(",
"QueryBuilder",
"$",
"queryBuilder",
")",
"{",
"$",
"queryBuilder",
"->",
"addSelect",
"(",
"'fileVersion'",
")",
"->",
"addSelect",
"(",
"'file'",
")",
"->",
"addSelect",
"(",
"'media'",
")",
"->",
"addSelect",
"(",
"'collection'",
")",
"->",
"leftJoin",
"(",
"'d.fileVersion'",
",",
"'fileVersion'",
")",
"->",
"leftJoin",
"(",
"'fileVersion.file'",
",",
"'file'",
")",
"->",
"leftJoin",
"(",
"'file.media'",
",",
"'media'",
")",
"->",
"leftJoin",
"(",
"'media.collection'",
",",
"'collection'",
")",
"->",
"leftJoin",
"(",
"AccessControl",
"::",
"class",
",",
"'accessControl'",
",",
"'WITH'",
",",
"'accessControl.entityClass = :entityClass AND accessControl.entityId = collection.id'",
")",
"->",
"where",
"(",
"'file.version = fileVersion.version'",
")",
"->",
"andWhere",
"(",
"'accessControl.id is null'",
")",
"->",
"setParameter",
"(",
"'entityClass'",
",",
"Collection",
"::",
"class",
")",
";",
"return",
"$",
"queryBuilder",
";",
"}"
] | Returns query-builder to find file-version-meta without permissions.
@param QueryBuilder $queryBuilder
@return QueryBuilder | [
"Returns",
"query",
"-",
"builder",
"to",
"find",
"file",
"-",
"version",
"-",
"meta",
"without",
"permissions",
"."
] | 6766a36cc2f0c807c59202bf7540a08c4ef31192 | https://github.com/sulu/sulu/blob/6766a36cc2f0c807c59202bf7540a08c4ef31192/src/Sulu/Bundle/MediaBundle/Entity/FileVersionMetaRepository.php#L54-L75 | train |
sulu/sulu | src/Sulu/Component/Content/SmartContent/QueryBuilder.php | QueryBuilder.buildPropertiesSelect | private function buildPropertiesSelect($locale, &$additionalFields)
{
foreach ($this->propertiesConfig as $parameter) {
$alias = $parameter->getName();
$propertyName = $parameter->getValue();
if (false !== strpos($propertyName, '.')) {
$parts = explode('.', $propertyName);
$this->buildExtensionSelect($alias, $parts[0], $parts[1], $locale, $additionalFields);
} else {
$this->buildPropertySelect($alias, $propertyName, $locale, $additionalFields);
}
}
} | php | private function buildPropertiesSelect($locale, &$additionalFields)
{
foreach ($this->propertiesConfig as $parameter) {
$alias = $parameter->getName();
$propertyName = $parameter->getValue();
if (false !== strpos($propertyName, '.')) {
$parts = explode('.', $propertyName);
$this->buildExtensionSelect($alias, $parts[0], $parts[1], $locale, $additionalFields);
} else {
$this->buildPropertySelect($alias, $propertyName, $locale, $additionalFields);
}
}
} | [
"private",
"function",
"buildPropertiesSelect",
"(",
"$",
"locale",
",",
"&",
"$",
"additionalFields",
")",
"{",
"foreach",
"(",
"$",
"this",
"->",
"propertiesConfig",
"as",
"$",
"parameter",
")",
"{",
"$",
"alias",
"=",
"$",
"parameter",
"->",
"getName",
"(",
")",
";",
"$",
"propertyName",
"=",
"$",
"parameter",
"->",
"getValue",
"(",
")",
";",
"if",
"(",
"false",
"!==",
"strpos",
"(",
"$",
"propertyName",
",",
"'.'",
")",
")",
"{",
"$",
"parts",
"=",
"explode",
"(",
"'.'",
",",
"$",
"propertyName",
")",
";",
"$",
"this",
"->",
"buildExtensionSelect",
"(",
"$",
"alias",
",",
"$",
"parts",
"[",
"0",
"]",
",",
"$",
"parts",
"[",
"1",
"]",
",",
"$",
"locale",
",",
"$",
"additionalFields",
")",
";",
"}",
"else",
"{",
"$",
"this",
"->",
"buildPropertySelect",
"(",
"$",
"alias",
",",
"$",
"propertyName",
",",
"$",
"locale",
",",
"$",
"additionalFields",
")",
";",
"}",
"}",
"}"
] | build select for properties. | [
"build",
"select",
"for",
"properties",
"."
] | 6766a36cc2f0c807c59202bf7540a08c4ef31192 | https://github.com/sulu/sulu/blob/6766a36cc2f0c807c59202bf7540a08c4ef31192/src/Sulu/Component/Content/SmartContent/QueryBuilder.php#L215-L229 | train |
sulu/sulu | src/Sulu/Component/Content/SmartContent/QueryBuilder.php | QueryBuilder.buildPropertySelect | private function buildPropertySelect($alias, $propertyName, $locale, &$additionalFields)
{
foreach ($this->structureManager->getStructures(static::$structureType) as $structure) {
if ($structure->hasProperty($propertyName)) {
$property = $structure->getProperty($propertyName);
$additionalFields[$locale][] = [
'name' => $alias,
'property' => $property,
'templateKey' => $structure->getKey(),
];
}
}
} | php | private function buildPropertySelect($alias, $propertyName, $locale, &$additionalFields)
{
foreach ($this->structureManager->getStructures(static::$structureType) as $structure) {
if ($structure->hasProperty($propertyName)) {
$property = $structure->getProperty($propertyName);
$additionalFields[$locale][] = [
'name' => $alias,
'property' => $property,
'templateKey' => $structure->getKey(),
];
}
}
} | [
"private",
"function",
"buildPropertySelect",
"(",
"$",
"alias",
",",
"$",
"propertyName",
",",
"$",
"locale",
",",
"&",
"$",
"additionalFields",
")",
"{",
"foreach",
"(",
"$",
"this",
"->",
"structureManager",
"->",
"getStructures",
"(",
"static",
"::",
"$",
"structureType",
")",
"as",
"$",
"structure",
")",
"{",
"if",
"(",
"$",
"structure",
"->",
"hasProperty",
"(",
"$",
"propertyName",
")",
")",
"{",
"$",
"property",
"=",
"$",
"structure",
"->",
"getProperty",
"(",
"$",
"propertyName",
")",
";",
"$",
"additionalFields",
"[",
"$",
"locale",
"]",
"[",
"]",
"=",
"[",
"'name'",
"=>",
"$",
"alias",
",",
"'property'",
"=>",
"$",
"property",
",",
"'templateKey'",
"=>",
"$",
"structure",
"->",
"getKey",
"(",
")",
",",
"]",
";",
"}",
"}",
"}"
] | build select for single property. | [
"build",
"select",
"for",
"single",
"property",
"."
] | 6766a36cc2f0c807c59202bf7540a08c4ef31192 | https://github.com/sulu/sulu/blob/6766a36cc2f0c807c59202bf7540a08c4ef31192/src/Sulu/Component/Content/SmartContent/QueryBuilder.php#L234-L246 | train |
sulu/sulu | src/Sulu/Component/Content/SmartContent/QueryBuilder.php | QueryBuilder.buildExtensionSelect | private function buildExtensionSelect($alias, $extension, $propertyName, $locale, &$additionalFields)
{
$extension = $this->extensionManager->getExtension('all', $extension);
$additionalFields[$locale][] = [
'name' => $alias,
'extension' => $extension,
'property' => $propertyName,
];
} | php | private function buildExtensionSelect($alias, $extension, $propertyName, $locale, &$additionalFields)
{
$extension = $this->extensionManager->getExtension('all', $extension);
$additionalFields[$locale][] = [
'name' => $alias,
'extension' => $extension,
'property' => $propertyName,
];
} | [
"private",
"function",
"buildExtensionSelect",
"(",
"$",
"alias",
",",
"$",
"extension",
",",
"$",
"propertyName",
",",
"$",
"locale",
",",
"&",
"$",
"additionalFields",
")",
"{",
"$",
"extension",
"=",
"$",
"this",
"->",
"extensionManager",
"->",
"getExtension",
"(",
"'all'",
",",
"$",
"extension",
")",
";",
"$",
"additionalFields",
"[",
"$",
"locale",
"]",
"[",
"]",
"=",
"[",
"'name'",
"=>",
"$",
"alias",
",",
"'extension'",
"=>",
"$",
"extension",
",",
"'property'",
"=>",
"$",
"propertyName",
",",
"]",
";",
"}"
] | build select for extension property. | [
"build",
"select",
"for",
"extension",
"property",
"."
] | 6766a36cc2f0c807c59202bf7540a08c4ef31192 | https://github.com/sulu/sulu/blob/6766a36cc2f0c807c59202bf7540a08c4ef31192/src/Sulu/Component/Content/SmartContent/QueryBuilder.php#L251-L259 | train |
sulu/sulu | src/Sulu/Component/Content/SmartContent/QueryBuilder.php | QueryBuilder.buildDatasourceWhere | private function buildDatasourceWhere()
{
$dataSource = $this->getConfig('dataSource');
$includeSubFolders = $this->getConfig('includeSubFolders', false);
$sqlFunction = false !== $includeSubFolders && 'false' !== $includeSubFolders ?
'ISDESCENDANTNODE' : 'ISCHILDNODE';
$node = $this->sessionManager->getSession()->getNodeByIdentifier($dataSource);
return $sqlFunction . '(page, \'' . $node->getPath() . '\')';
} | php | private function buildDatasourceWhere()
{
$dataSource = $this->getConfig('dataSource');
$includeSubFolders = $this->getConfig('includeSubFolders', false);
$sqlFunction = false !== $includeSubFolders && 'false' !== $includeSubFolders ?
'ISDESCENDANTNODE' : 'ISCHILDNODE';
$node = $this->sessionManager->getSession()->getNodeByIdentifier($dataSource);
return $sqlFunction . '(page, \'' . $node->getPath() . '\')';
} | [
"private",
"function",
"buildDatasourceWhere",
"(",
")",
"{",
"$",
"dataSource",
"=",
"$",
"this",
"->",
"getConfig",
"(",
"'dataSource'",
")",
";",
"$",
"includeSubFolders",
"=",
"$",
"this",
"->",
"getConfig",
"(",
"'includeSubFolders'",
",",
"false",
")",
";",
"$",
"sqlFunction",
"=",
"false",
"!==",
"$",
"includeSubFolders",
"&&",
"'false'",
"!==",
"$",
"includeSubFolders",
"?",
"'ISDESCENDANTNODE'",
":",
"'ISCHILDNODE'",
";",
"$",
"node",
"=",
"$",
"this",
"->",
"sessionManager",
"->",
"getSession",
"(",
")",
"->",
"getNodeByIdentifier",
"(",
"$",
"dataSource",
")",
";",
"return",
"$",
"sqlFunction",
".",
"'(page, \\''",
".",
"$",
"node",
"->",
"getPath",
"(",
")",
".",
"'\\')'",
";",
"}"
] | build datasource where clause. | [
"build",
"datasource",
"where",
"clause",
"."
] | 6766a36cc2f0c807c59202bf7540a08c4ef31192 | https://github.com/sulu/sulu/blob/6766a36cc2f0c807c59202bf7540a08c4ef31192/src/Sulu/Component/Content/SmartContent/QueryBuilder.php#L264-L274 | train |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.