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/WebsiteBundle/Navigation/NavigationMapper.php | NavigationMapper.generateChildNavigation | private function generateChildNavigation(
StructureInterface $content,
$webspace,
$language,
$flat = false,
$context = null
) {
$children = [];
if (is_array($content->getChildren()) && count($content->getChildren()) > 0) {
$children = $this->generateNavigation(
$content->getChildren(),
$webspace,
$language,
$flat,
$context
);
}
return $children;
} | php | private function generateChildNavigation(
StructureInterface $content,
$webspace,
$language,
$flat = false,
$context = null
) {
$children = [];
if (is_array($content->getChildren()) && count($content->getChildren()) > 0) {
$children = $this->generateNavigation(
$content->getChildren(),
$webspace,
$language,
$flat,
$context
);
}
return $children;
} | [
"private",
"function",
"generateChildNavigation",
"(",
"StructureInterface",
"$",
"content",
",",
"$",
"webspace",
",",
"$",
"language",
",",
"$",
"flat",
"=",
"false",
",",
"$",
"context",
"=",
"null",
")",
"{",
"$",
"children",
"=",
"[",
"]",
";",
"if",
"(",
"is_array",
"(",
"$",
"content",
"->",
"getChildren",
"(",
")",
")",
"&&",
"count",
"(",
"$",
"content",
"->",
"getChildren",
"(",
")",
")",
">",
"0",
")",
"{",
"$",
"children",
"=",
"$",
"this",
"->",
"generateNavigation",
"(",
"$",
"content",
"->",
"getChildren",
"(",
")",
",",
"$",
"webspace",
",",
"$",
"language",
",",
"$",
"flat",
",",
"$",
"context",
")",
";",
"}",
"return",
"$",
"children",
";",
"}"
] | generate child navigation of given content. | [
"generate",
"child",
"navigation",
"of",
"given",
"content",
"."
] | 6766a36cc2f0c807c59202bf7540a08c4ef31192 | https://github.com/sulu/sulu/blob/6766a36cc2f0c807c59202bf7540a08c4ef31192/src/Sulu/Bundle/WebsiteBundle/Navigation/NavigationMapper.php#L209-L228 | train |
sulu/sulu | src/Sulu/Bundle/WebsiteBundle/Navigation/NavigationMapper.php | NavigationMapper.inNavigation | public function inNavigation(StructureInterface $content, $context = null)
{
$contexts = $content->getNavContexts();
if (Structure::STATE_PUBLISHED !== $content->getNodeState()) {
// if node state is not published do not show page
return false;
}
if (is_array($contexts) && (null === $context || in_array($context, $contexts))) {
// all contexts or content has context
return true;
}
// do not show
return false;
} | php | public function inNavigation(StructureInterface $content, $context = null)
{
$contexts = $content->getNavContexts();
if (Structure::STATE_PUBLISHED !== $content->getNodeState()) {
// if node state is not published do not show page
return false;
}
if (is_array($contexts) && (null === $context || in_array($context, $contexts))) {
// all contexts or content has context
return true;
}
// do not show
return false;
} | [
"public",
"function",
"inNavigation",
"(",
"StructureInterface",
"$",
"content",
",",
"$",
"context",
"=",
"null",
")",
"{",
"$",
"contexts",
"=",
"$",
"content",
"->",
"getNavContexts",
"(",
")",
";",
"if",
"(",
"Structure",
"::",
"STATE_PUBLISHED",
"!==",
"$",
"content",
"->",
"getNodeState",
"(",
")",
")",
"{",
"// if node state is not published do not show page",
"return",
"false",
";",
"}",
"if",
"(",
"is_array",
"(",
"$",
"contexts",
")",
"&&",
"(",
"null",
"===",
"$",
"context",
"||",
"in_array",
"(",
"$",
"context",
",",
"$",
"contexts",
")",
")",
")",
"{",
"// all contexts or content has context",
"return",
"true",
";",
"}",
"// do not show",
"return",
"false",
";",
"}"
] | checks if content should be displayed.
@param StructureInterface $content
@param string|null $context
@return bool | [
"checks",
"if",
"content",
"should",
"be",
"displayed",
"."
] | 6766a36cc2f0c807c59202bf7540a08c4ef31192 | https://github.com/sulu/sulu/blob/6766a36cc2f0c807c59202bf7540a08c4ef31192/src/Sulu/Bundle/WebsiteBundle/Navigation/NavigationMapper.php#L238-L254 | train |
sulu/sulu | src/Sulu/Bundle/SecurityBundle/Controller/UserController.php | UserController.getAction | public function getAction($id)
{
$find = function($id) {
return $this->getUserManager()->getUserById($id);
};
$view = $this->responseGetById($id, $find);
$this->addSerializationGroups($view);
return $this->handleView($view);
} | php | public function getAction($id)
{
$find = function($id) {
return $this->getUserManager()->getUserById($id);
};
$view = $this->responseGetById($id, $find);
$this->addSerializationGroups($view);
return $this->handleView($view);
} | [
"public",
"function",
"getAction",
"(",
"$",
"id",
")",
"{",
"$",
"find",
"=",
"function",
"(",
"$",
"id",
")",
"{",
"return",
"$",
"this",
"->",
"getUserManager",
"(",
")",
"->",
"getUserById",
"(",
"$",
"id",
")",
";",
"}",
";",
"$",
"view",
"=",
"$",
"this",
"->",
"responseGetById",
"(",
"$",
"id",
",",
"$",
"find",
")",
";",
"$",
"this",
"->",
"addSerializationGroups",
"(",
"$",
"view",
")",
";",
"return",
"$",
"this",
"->",
"handleView",
"(",
"$",
"view",
")",
";",
"}"
] | Returns the user with the given id.
@param int $id
@return \Symfony\Component\HttpFoundation\Response | [
"Returns",
"the",
"user",
"with",
"the",
"given",
"id",
"."
] | 6766a36cc2f0c807c59202bf7540a08c4ef31192 | https://github.com/sulu/sulu/blob/6766a36cc2f0c807c59202bf7540a08c4ef31192/src/Sulu/Bundle/SecurityBundle/Controller/UserController.php#L98-L109 | train |
sulu/sulu | src/Sulu/Bundle/SecurityBundle/Controller/UserController.php | UserController.postAction | public function postAction(Request $request)
{
try {
$this->checkArguments($request);
$locale = $this->getRequestParameter($request, 'locale', true);
$data = $request->request->all();
$data['contactId'] = $request->query->get('contactId');
$user = $this->getUserManager()->save($data, $locale);
$view = $this->view($user, 200);
} catch (UsernameNotUniqueException $exc) {
$view = $this->view($exc->toArray(), 409);
} catch (MissingPasswordException $exc) {
$view = $this->view($exc->toArray(), 400);
} catch (EmailNotUniqueException $exc) {
$view = $this->view($exc->toArray(), 409);
} catch (RestException $re) {
$view = $this->view($re->toArray(), 400);
}
$this->addSerializationGroups($view);
return $this->handleView($view);
} | php | public function postAction(Request $request)
{
try {
$this->checkArguments($request);
$locale = $this->getRequestParameter($request, 'locale', true);
$data = $request->request->all();
$data['contactId'] = $request->query->get('contactId');
$user = $this->getUserManager()->save($data, $locale);
$view = $this->view($user, 200);
} catch (UsernameNotUniqueException $exc) {
$view = $this->view($exc->toArray(), 409);
} catch (MissingPasswordException $exc) {
$view = $this->view($exc->toArray(), 400);
} catch (EmailNotUniqueException $exc) {
$view = $this->view($exc->toArray(), 409);
} catch (RestException $re) {
$view = $this->view($re->toArray(), 400);
}
$this->addSerializationGroups($view);
return $this->handleView($view);
} | [
"public",
"function",
"postAction",
"(",
"Request",
"$",
"request",
")",
"{",
"try",
"{",
"$",
"this",
"->",
"checkArguments",
"(",
"$",
"request",
")",
";",
"$",
"locale",
"=",
"$",
"this",
"->",
"getRequestParameter",
"(",
"$",
"request",
",",
"'locale'",
",",
"true",
")",
";",
"$",
"data",
"=",
"$",
"request",
"->",
"request",
"->",
"all",
"(",
")",
";",
"$",
"data",
"[",
"'contactId'",
"]",
"=",
"$",
"request",
"->",
"query",
"->",
"get",
"(",
"'contactId'",
")",
";",
"$",
"user",
"=",
"$",
"this",
"->",
"getUserManager",
"(",
")",
"->",
"save",
"(",
"$",
"data",
",",
"$",
"locale",
")",
";",
"$",
"view",
"=",
"$",
"this",
"->",
"view",
"(",
"$",
"user",
",",
"200",
")",
";",
"}",
"catch",
"(",
"UsernameNotUniqueException",
"$",
"exc",
")",
"{",
"$",
"view",
"=",
"$",
"this",
"->",
"view",
"(",
"$",
"exc",
"->",
"toArray",
"(",
")",
",",
"409",
")",
";",
"}",
"catch",
"(",
"MissingPasswordException",
"$",
"exc",
")",
"{",
"$",
"view",
"=",
"$",
"this",
"->",
"view",
"(",
"$",
"exc",
"->",
"toArray",
"(",
")",
",",
"400",
")",
";",
"}",
"catch",
"(",
"EmailNotUniqueException",
"$",
"exc",
")",
"{",
"$",
"view",
"=",
"$",
"this",
"->",
"view",
"(",
"$",
"exc",
"->",
"toArray",
"(",
")",
",",
"409",
")",
";",
"}",
"catch",
"(",
"RestException",
"$",
"re",
")",
"{",
"$",
"view",
"=",
"$",
"this",
"->",
"view",
"(",
"$",
"re",
"->",
"toArray",
"(",
")",
",",
"400",
")",
";",
"}",
"$",
"this",
"->",
"addSerializationGroups",
"(",
"$",
"view",
")",
";",
"return",
"$",
"this",
"->",
"handleView",
"(",
"$",
"view",
")",
";",
"}"
] | Creates a new user in the system.
@param \Symfony\Component\HttpFoundation\Request $request
@return \Symfony\Component\HttpFoundation\Response | [
"Creates",
"a",
"new",
"user",
"in",
"the",
"system",
"."
] | 6766a36cc2f0c807c59202bf7540a08c4ef31192 | https://github.com/sulu/sulu/blob/6766a36cc2f0c807c59202bf7540a08c4ef31192/src/Sulu/Bundle/SecurityBundle/Controller/UserController.php#L118-L140 | train |
sulu/sulu | src/Sulu/Bundle/SecurityBundle/Controller/UserController.php | UserController.putAction | public function putAction(Request $request, $id)
{
try {
$this->checkArguments($request);
$locale = $this->getRequestParameter($request, 'locale', true);
$user = $this->getUserManager()->save($request->request->all(), $locale, $id);
$view = $this->view($user, 200);
} catch (EntityNotFoundException $exc) {
$view = $this->view($exc->toArray(), 404);
} catch (UsernameNotUniqueException $exc) {
$view = $this->view($exc->toArray(), 409);
} catch (EmailNotUniqueException $exc) {
$view = $this->view($exc->toArray(), 409);
} catch (RestException $exc) {
$view = $this->view($exc->toArray(), 400);
}
$this->addSerializationGroups($view);
return $this->handleView($view);
} | php | public function putAction(Request $request, $id)
{
try {
$this->checkArguments($request);
$locale = $this->getRequestParameter($request, 'locale', true);
$user = $this->getUserManager()->save($request->request->all(), $locale, $id);
$view = $this->view($user, 200);
} catch (EntityNotFoundException $exc) {
$view = $this->view($exc->toArray(), 404);
} catch (UsernameNotUniqueException $exc) {
$view = $this->view($exc->toArray(), 409);
} catch (EmailNotUniqueException $exc) {
$view = $this->view($exc->toArray(), 409);
} catch (RestException $exc) {
$view = $this->view($exc->toArray(), 400);
}
$this->addSerializationGroups($view);
return $this->handleView($view);
} | [
"public",
"function",
"putAction",
"(",
"Request",
"$",
"request",
",",
"$",
"id",
")",
"{",
"try",
"{",
"$",
"this",
"->",
"checkArguments",
"(",
"$",
"request",
")",
";",
"$",
"locale",
"=",
"$",
"this",
"->",
"getRequestParameter",
"(",
"$",
"request",
",",
"'locale'",
",",
"true",
")",
";",
"$",
"user",
"=",
"$",
"this",
"->",
"getUserManager",
"(",
")",
"->",
"save",
"(",
"$",
"request",
"->",
"request",
"->",
"all",
"(",
")",
",",
"$",
"locale",
",",
"$",
"id",
")",
";",
"$",
"view",
"=",
"$",
"this",
"->",
"view",
"(",
"$",
"user",
",",
"200",
")",
";",
"}",
"catch",
"(",
"EntityNotFoundException",
"$",
"exc",
")",
"{",
"$",
"view",
"=",
"$",
"this",
"->",
"view",
"(",
"$",
"exc",
"->",
"toArray",
"(",
")",
",",
"404",
")",
";",
"}",
"catch",
"(",
"UsernameNotUniqueException",
"$",
"exc",
")",
"{",
"$",
"view",
"=",
"$",
"this",
"->",
"view",
"(",
"$",
"exc",
"->",
"toArray",
"(",
")",
",",
"409",
")",
";",
"}",
"catch",
"(",
"EmailNotUniqueException",
"$",
"exc",
")",
"{",
"$",
"view",
"=",
"$",
"this",
"->",
"view",
"(",
"$",
"exc",
"->",
"toArray",
"(",
")",
",",
"409",
")",
";",
"}",
"catch",
"(",
"RestException",
"$",
"exc",
")",
"{",
"$",
"view",
"=",
"$",
"this",
"->",
"view",
"(",
"$",
"exc",
"->",
"toArray",
"(",
")",
",",
"400",
")",
";",
"}",
"$",
"this",
"->",
"addSerializationGroups",
"(",
"$",
"view",
")",
";",
"return",
"$",
"this",
"->",
"handleView",
"(",
"$",
"view",
")",
";",
"}"
] | Updates the given user with the given data.
@param \Symfony\Component\HttpFoundation\Request $request
@param int $id
@return \Symfony\Component\HttpFoundation\Response | [
"Updates",
"the",
"given",
"user",
"with",
"the",
"given",
"data",
"."
] | 6766a36cc2f0c807c59202bf7540a08c4ef31192 | https://github.com/sulu/sulu/blob/6766a36cc2f0c807c59202bf7540a08c4ef31192/src/Sulu/Bundle/SecurityBundle/Controller/UserController.php#L183-L203 | train |
sulu/sulu | src/Sulu/Bundle/SecurityBundle/Controller/UserController.php | UserController.deleteAction | public function deleteAction($id)
{
$delete = $this->getUserManager()->delete();
$view = $this->responseDelete($id, $delete);
return $this->handleView($view);
} | php | public function deleteAction($id)
{
$delete = $this->getUserManager()->delete();
$view = $this->responseDelete($id, $delete);
return $this->handleView($view);
} | [
"public",
"function",
"deleteAction",
"(",
"$",
"id",
")",
"{",
"$",
"delete",
"=",
"$",
"this",
"->",
"getUserManager",
"(",
")",
"->",
"delete",
"(",
")",
";",
"$",
"view",
"=",
"$",
"this",
"->",
"responseDelete",
"(",
"$",
"id",
",",
"$",
"delete",
")",
";",
"return",
"$",
"this",
"->",
"handleView",
"(",
"$",
"view",
")",
";",
"}"
] | Deletes the user with the given id.
@param int $id
@return \Symfony\Component\HttpFoundation\Response | [
"Deletes",
"the",
"user",
"with",
"the",
"given",
"id",
"."
] | 6766a36cc2f0c807c59202bf7540a08c4ef31192 | https://github.com/sulu/sulu/blob/6766a36cc2f0c807c59202bf7540a08c4ef31192/src/Sulu/Bundle/SecurityBundle/Controller/UserController.php#L241-L247 | train |
sulu/sulu | src/Sulu/Bundle/SecurityBundle/Controller/UserController.php | UserController.cgetAction | public function cgetAction(Request $request)
{
$view = null;
if ('true' == $request->get('flat')) {
/** @var RestHelperInterface $restHelper */
$restHelper = $this->get('sulu_core.doctrine_rest_helper');
/** @var DoctrineListBuilderFactory $factory */
$factory = $this->get('sulu_core.doctrine_list_builder_factory');
$listBuilder = $factory->create($this->container->getParameter('sulu.model.user.class'));
$restHelper->initializeListBuilder($listBuilder, $this->getFieldDescriptors());
$list = new ListRepresentation(
$listBuilder->execute(),
static::$entityKey,
'get_users',
$request->query->all(),
$listBuilder->getCurrentPage(),
$listBuilder->getLimit(),
$listBuilder->count()
);
} else {
$contactId = $request->get('contactId');
if (null != $contactId) {
$user = $this->getDoctrine()->getRepository(
$this->container->getParameter('sulu.model.user.class')
)->findUserByContact($contactId);
$view = $this->view($user ?? new \stdClass(), 200);
} else {
$entities = $this->getUserManager()->findAll();
$list = new CollectionRepresentation($entities, static::$entityKey);
}
}
if (!$view) {
$view = $this->view($list, 200);
}
$this->addSerializationGroups($view);
return $this->handleView($view);
} | php | public function cgetAction(Request $request)
{
$view = null;
if ('true' == $request->get('flat')) {
/** @var RestHelperInterface $restHelper */
$restHelper = $this->get('sulu_core.doctrine_rest_helper');
/** @var DoctrineListBuilderFactory $factory */
$factory = $this->get('sulu_core.doctrine_list_builder_factory');
$listBuilder = $factory->create($this->container->getParameter('sulu.model.user.class'));
$restHelper->initializeListBuilder($listBuilder, $this->getFieldDescriptors());
$list = new ListRepresentation(
$listBuilder->execute(),
static::$entityKey,
'get_users',
$request->query->all(),
$listBuilder->getCurrentPage(),
$listBuilder->getLimit(),
$listBuilder->count()
);
} else {
$contactId = $request->get('contactId');
if (null != $contactId) {
$user = $this->getDoctrine()->getRepository(
$this->container->getParameter('sulu.model.user.class')
)->findUserByContact($contactId);
$view = $this->view($user ?? new \stdClass(), 200);
} else {
$entities = $this->getUserManager()->findAll();
$list = new CollectionRepresentation($entities, static::$entityKey);
}
}
if (!$view) {
$view = $this->view($list, 200);
}
$this->addSerializationGroups($view);
return $this->handleView($view);
} | [
"public",
"function",
"cgetAction",
"(",
"Request",
"$",
"request",
")",
"{",
"$",
"view",
"=",
"null",
";",
"if",
"(",
"'true'",
"==",
"$",
"request",
"->",
"get",
"(",
"'flat'",
")",
")",
"{",
"/** @var RestHelperInterface $restHelper */",
"$",
"restHelper",
"=",
"$",
"this",
"->",
"get",
"(",
"'sulu_core.doctrine_rest_helper'",
")",
";",
"/** @var DoctrineListBuilderFactory $factory */",
"$",
"factory",
"=",
"$",
"this",
"->",
"get",
"(",
"'sulu_core.doctrine_list_builder_factory'",
")",
";",
"$",
"listBuilder",
"=",
"$",
"factory",
"->",
"create",
"(",
"$",
"this",
"->",
"container",
"->",
"getParameter",
"(",
"'sulu.model.user.class'",
")",
")",
";",
"$",
"restHelper",
"->",
"initializeListBuilder",
"(",
"$",
"listBuilder",
",",
"$",
"this",
"->",
"getFieldDescriptors",
"(",
")",
")",
";",
"$",
"list",
"=",
"new",
"ListRepresentation",
"(",
"$",
"listBuilder",
"->",
"execute",
"(",
")",
",",
"static",
"::",
"$",
"entityKey",
",",
"'get_users'",
",",
"$",
"request",
"->",
"query",
"->",
"all",
"(",
")",
",",
"$",
"listBuilder",
"->",
"getCurrentPage",
"(",
")",
",",
"$",
"listBuilder",
"->",
"getLimit",
"(",
")",
",",
"$",
"listBuilder",
"->",
"count",
"(",
")",
")",
";",
"}",
"else",
"{",
"$",
"contactId",
"=",
"$",
"request",
"->",
"get",
"(",
"'contactId'",
")",
";",
"if",
"(",
"null",
"!=",
"$",
"contactId",
")",
"{",
"$",
"user",
"=",
"$",
"this",
"->",
"getDoctrine",
"(",
")",
"->",
"getRepository",
"(",
"$",
"this",
"->",
"container",
"->",
"getParameter",
"(",
"'sulu.model.user.class'",
")",
")",
"->",
"findUserByContact",
"(",
"$",
"contactId",
")",
";",
"$",
"view",
"=",
"$",
"this",
"->",
"view",
"(",
"$",
"user",
"??",
"new",
"\\",
"stdClass",
"(",
")",
",",
"200",
")",
";",
"}",
"else",
"{",
"$",
"entities",
"=",
"$",
"this",
"->",
"getUserManager",
"(",
")",
"->",
"findAll",
"(",
")",
";",
"$",
"list",
"=",
"new",
"CollectionRepresentation",
"(",
"$",
"entities",
",",
"static",
"::",
"$",
"entityKey",
")",
";",
"}",
"}",
"if",
"(",
"!",
"$",
"view",
")",
"{",
"$",
"view",
"=",
"$",
"this",
"->",
"view",
"(",
"$",
"list",
",",
"200",
")",
";",
"}",
"$",
"this",
"->",
"addSerializationGroups",
"(",
"$",
"view",
")",
";",
"return",
"$",
"this",
"->",
"handleView",
"(",
"$",
"view",
")",
";",
"}"
] | Returns a user with a specific contact id or all users
optional parameter 'flat' calls listAction.
@param Request $request
@return \Symfony\Component\HttpFoundation\Response | [
"Returns",
"a",
"user",
"with",
"a",
"specific",
"contact",
"id",
"or",
"all",
"users",
"optional",
"parameter",
"flat",
"calls",
"listAction",
"."
] | 6766a36cc2f0c807c59202bf7540a08c4ef31192 | https://github.com/sulu/sulu/blob/6766a36cc2f0c807c59202bf7540a08c4ef31192/src/Sulu/Bundle/SecurityBundle/Controller/UserController.php#L282-L327 | train |
sulu/sulu | src/Sulu/Bundle/CoreBundle/Controller/LocalizationController.php | LocalizationController.cgetAction | public function cgetAction()
{
/** @var LocalizationManagerInterface $localizationManager */
$localizationManager = $this->get('sulu.core.localization_manager');
$representation = new CollectionRepresentation(
array_values($localizationManager->getLocalizations()),
'localizations'
);
return $this->handleView(
$this->view($representation, 200)
);
} | php | public function cgetAction()
{
/** @var LocalizationManagerInterface $localizationManager */
$localizationManager = $this->get('sulu.core.localization_manager');
$representation = new CollectionRepresentation(
array_values($localizationManager->getLocalizations()),
'localizations'
);
return $this->handleView(
$this->view($representation, 200)
);
} | [
"public",
"function",
"cgetAction",
"(",
")",
"{",
"/** @var LocalizationManagerInterface $localizationManager */",
"$",
"localizationManager",
"=",
"$",
"this",
"->",
"get",
"(",
"'sulu.core.localization_manager'",
")",
";",
"$",
"representation",
"=",
"new",
"CollectionRepresentation",
"(",
"array_values",
"(",
"$",
"localizationManager",
"->",
"getLocalizations",
"(",
")",
")",
",",
"'localizations'",
")",
";",
"return",
"$",
"this",
"->",
"handleView",
"(",
"$",
"this",
"->",
"view",
"(",
"$",
"representation",
",",
"200",
")",
")",
";",
"}"
] | Returns all the localizations available in this system.
@return \Symfony\Component\HttpFoundation\Response | [
"Returns",
"all",
"the",
"localizations",
"available",
"in",
"this",
"system",
"."
] | 6766a36cc2f0c807c59202bf7540a08c4ef31192 | https://github.com/sulu/sulu/blob/6766a36cc2f0c807c59202bf7540a08c4ef31192/src/Sulu/Bundle/CoreBundle/Controller/LocalizationController.php#L29-L42 | train |
sulu/sulu | src/Sulu/Bundle/WebsiteBundle/Controller/SitemapController.php | SitemapController.indexAction | public function indexAction(Request $request)
{
if (null !== ($response = $this->getDumpedIndexResponse($request))) {
return $response;
}
$sitemap = $this->get('sulu_website.sitemap.xml_renderer')->renderIndex();
if (!$sitemap) {
$aliases = array_keys($this->get('sulu_website.sitemap.pool')->getProviders());
return $this->sitemapPaginatedAction($request, reset($aliases), 1);
}
return $this->setCacheLifetime(new Response($sitemap));
} | php | public function indexAction(Request $request)
{
if (null !== ($response = $this->getDumpedIndexResponse($request))) {
return $response;
}
$sitemap = $this->get('sulu_website.sitemap.xml_renderer')->renderIndex();
if (!$sitemap) {
$aliases = array_keys($this->get('sulu_website.sitemap.pool')->getProviders());
return $this->sitemapPaginatedAction($request, reset($aliases), 1);
}
return $this->setCacheLifetime(new Response($sitemap));
} | [
"public",
"function",
"indexAction",
"(",
"Request",
"$",
"request",
")",
"{",
"if",
"(",
"null",
"!==",
"(",
"$",
"response",
"=",
"$",
"this",
"->",
"getDumpedIndexResponse",
"(",
"$",
"request",
")",
")",
")",
"{",
"return",
"$",
"response",
";",
"}",
"$",
"sitemap",
"=",
"$",
"this",
"->",
"get",
"(",
"'sulu_website.sitemap.xml_renderer'",
")",
"->",
"renderIndex",
"(",
")",
";",
"if",
"(",
"!",
"$",
"sitemap",
")",
"{",
"$",
"aliases",
"=",
"array_keys",
"(",
"$",
"this",
"->",
"get",
"(",
"'sulu_website.sitemap.pool'",
")",
"->",
"getProviders",
"(",
")",
")",
";",
"return",
"$",
"this",
"->",
"sitemapPaginatedAction",
"(",
"$",
"request",
",",
"reset",
"(",
"$",
"aliases",
")",
",",
"1",
")",
";",
"}",
"return",
"$",
"this",
"->",
"setCacheLifetime",
"(",
"new",
"Response",
"(",
"$",
"sitemap",
")",
")",
";",
"}"
] | Render sitemap-index of all available sitemap.xml files.
If only one provider exists this provider will be rendered directly.
@param Request $request
@return \Symfony\Component\HttpFoundation\Response | [
"Render",
"sitemap",
"-",
"index",
"of",
"all",
"available",
"sitemap",
".",
"xml",
"files",
".",
"If",
"only",
"one",
"provider",
"exists",
"this",
"provider",
"will",
"be",
"rendered",
"directly",
"."
] | 6766a36cc2f0c807c59202bf7540a08c4ef31192 | https://github.com/sulu/sulu/blob/6766a36cc2f0c807c59202bf7540a08c4ef31192/src/Sulu/Bundle/WebsiteBundle/Controller/SitemapController.php#L33-L47 | train |
sulu/sulu | src/Sulu/Bundle/WebsiteBundle/Controller/SitemapController.php | SitemapController.sitemapAction | public function sitemapAction($alias)
{
if (!$this->get('sulu_website.sitemap.pool')->hasProvider($alias)) {
return new Response(null, 404);
}
return $this->redirectToRoute('sulu_website.paginated_sitemap', ['alias' => $alias, 'page' => 1], 301);
} | php | public function sitemapAction($alias)
{
if (!$this->get('sulu_website.sitemap.pool')->hasProvider($alias)) {
return new Response(null, 404);
}
return $this->redirectToRoute('sulu_website.paginated_sitemap', ['alias' => $alias, 'page' => 1], 301);
} | [
"public",
"function",
"sitemapAction",
"(",
"$",
"alias",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"get",
"(",
"'sulu_website.sitemap.pool'",
")",
"->",
"hasProvider",
"(",
"$",
"alias",
")",
")",
"{",
"return",
"new",
"Response",
"(",
"null",
",",
"404",
")",
";",
"}",
"return",
"$",
"this",
"->",
"redirectToRoute",
"(",
"'sulu_website.paginated_sitemap'",
",",
"[",
"'alias'",
"=>",
"$",
"alias",
",",
"'page'",
"=>",
"1",
"]",
",",
"301",
")",
";",
"}"
] | Redirect to the first page of a single sitemap provider.
@param string $alias
@return Response | [
"Redirect",
"to",
"the",
"first",
"page",
"of",
"a",
"single",
"sitemap",
"provider",
"."
] | 6766a36cc2f0c807c59202bf7540a08c4ef31192 | https://github.com/sulu/sulu/blob/6766a36cc2f0c807c59202bf7540a08c4ef31192/src/Sulu/Bundle/WebsiteBundle/Controller/SitemapController.php#L86-L93 | train |
sulu/sulu | src/Sulu/Bundle/WebsiteBundle/Controller/SitemapController.php | SitemapController.sitemapPaginatedAction | public function sitemapPaginatedAction(Request $request, $alias, $page)
{
if (null !== ($response = $this->getDumpedSitemapResponse($request, $alias, $page))) {
return $response;
}
$portal = $request->get('_sulu')->getAttribute('portal');
$localization = $request->get('_sulu')->getAttribute('localization');
if (!$localization) {
$localization = $portal->getXDefaultLocalization();
}
$sitemap = $this->get('sulu_website.sitemap.xml_renderer')->renderSitemap(
$alias,
$page,
$localization->getLocale(),
$portal,
$request->getHttpHost(),
$request->getScheme()
);
if (!$sitemap) {
return new Response(null, 404);
}
return $this->setCacheLifetime(new Response($sitemap));
} | php | public function sitemapPaginatedAction(Request $request, $alias, $page)
{
if (null !== ($response = $this->getDumpedSitemapResponse($request, $alias, $page))) {
return $response;
}
$portal = $request->get('_sulu')->getAttribute('portal');
$localization = $request->get('_sulu')->getAttribute('localization');
if (!$localization) {
$localization = $portal->getXDefaultLocalization();
}
$sitemap = $this->get('sulu_website.sitemap.xml_renderer')->renderSitemap(
$alias,
$page,
$localization->getLocale(),
$portal,
$request->getHttpHost(),
$request->getScheme()
);
if (!$sitemap) {
return new Response(null, 404);
}
return $this->setCacheLifetime(new Response($sitemap));
} | [
"public",
"function",
"sitemapPaginatedAction",
"(",
"Request",
"$",
"request",
",",
"$",
"alias",
",",
"$",
"page",
")",
"{",
"if",
"(",
"null",
"!==",
"(",
"$",
"response",
"=",
"$",
"this",
"->",
"getDumpedSitemapResponse",
"(",
"$",
"request",
",",
"$",
"alias",
",",
"$",
"page",
")",
")",
")",
"{",
"return",
"$",
"response",
";",
"}",
"$",
"portal",
"=",
"$",
"request",
"->",
"get",
"(",
"'_sulu'",
")",
"->",
"getAttribute",
"(",
"'portal'",
")",
";",
"$",
"localization",
"=",
"$",
"request",
"->",
"get",
"(",
"'_sulu'",
")",
"->",
"getAttribute",
"(",
"'localization'",
")",
";",
"if",
"(",
"!",
"$",
"localization",
")",
"{",
"$",
"localization",
"=",
"$",
"portal",
"->",
"getXDefaultLocalization",
"(",
")",
";",
"}",
"$",
"sitemap",
"=",
"$",
"this",
"->",
"get",
"(",
"'sulu_website.sitemap.xml_renderer'",
")",
"->",
"renderSitemap",
"(",
"$",
"alias",
",",
"$",
"page",
",",
"$",
"localization",
"->",
"getLocale",
"(",
")",
",",
"$",
"portal",
",",
"$",
"request",
"->",
"getHttpHost",
"(",
")",
",",
"$",
"request",
"->",
"getScheme",
"(",
")",
")",
";",
"if",
"(",
"!",
"$",
"sitemap",
")",
"{",
"return",
"new",
"Response",
"(",
"null",
",",
"404",
")",
";",
"}",
"return",
"$",
"this",
"->",
"setCacheLifetime",
"(",
"new",
"Response",
"(",
"$",
"sitemap",
")",
")",
";",
"}"
] | Render a single page for a single sitemap.xml provider.
@param Request $request
@param string $alias
@param int $page
@return Response | [
"Render",
"a",
"single",
"page",
"for",
"a",
"single",
"sitemap",
".",
"xml",
"provider",
"."
] | 6766a36cc2f0c807c59202bf7540a08c4ef31192 | https://github.com/sulu/sulu/blob/6766a36cc2f0c807c59202bf7540a08c4ef31192/src/Sulu/Bundle/WebsiteBundle/Controller/SitemapController.php#L104-L130 | train |
sulu/sulu | src/Sulu/Bundle/WebsiteBundle/Controller/SitemapController.php | SitemapController.setCacheLifetime | private function setCacheLifetime(Response $response)
{
$response->headers->set(
SuluHttpCache::HEADER_REVERSE_PROXY_TTL,
$response->getAge() + $this->container->getParameter('sulu_website.sitemap.cache.lifetime')
);
return $response->setMaxAge(240)
->setSharedMaxAge(960);
} | php | private function setCacheLifetime(Response $response)
{
$response->headers->set(
SuluHttpCache::HEADER_REVERSE_PROXY_TTL,
$response->getAge() + $this->container->getParameter('sulu_website.sitemap.cache.lifetime')
);
return $response->setMaxAge(240)
->setSharedMaxAge(960);
} | [
"private",
"function",
"setCacheLifetime",
"(",
"Response",
"$",
"response",
")",
"{",
"$",
"response",
"->",
"headers",
"->",
"set",
"(",
"SuluHttpCache",
"::",
"HEADER_REVERSE_PROXY_TTL",
",",
"$",
"response",
"->",
"getAge",
"(",
")",
"+",
"$",
"this",
"->",
"container",
"->",
"getParameter",
"(",
"'sulu_website.sitemap.cache.lifetime'",
")",
")",
";",
"return",
"$",
"response",
"->",
"setMaxAge",
"(",
"240",
")",
"->",
"setSharedMaxAge",
"(",
"960",
")",
";",
"}"
] | Set cache headers.
@param Response $response
@return Response | [
"Set",
"cache",
"headers",
"."
] | 6766a36cc2f0c807c59202bf7540a08c4ef31192 | https://github.com/sulu/sulu/blob/6766a36cc2f0c807c59202bf7540a08c4ef31192/src/Sulu/Bundle/WebsiteBundle/Controller/SitemapController.php#L173-L182 | train |
sulu/sulu | src/Sulu/Bundle/WebsiteBundle/Controller/SitemapController.php | SitemapController.createBinaryFileResponse | private function createBinaryFileResponse($file)
{
$response = new BinaryFileResponse($file);
$response->headers->addCacheControlDirective('no-store', true);
return $response;
} | php | private function createBinaryFileResponse($file)
{
$response = new BinaryFileResponse($file);
$response->headers->addCacheControlDirective('no-store', true);
return $response;
} | [
"private",
"function",
"createBinaryFileResponse",
"(",
"$",
"file",
")",
"{",
"$",
"response",
"=",
"new",
"BinaryFileResponse",
"(",
"$",
"file",
")",
";",
"$",
"response",
"->",
"headers",
"->",
"addCacheControlDirective",
"(",
"'no-store'",
",",
"true",
")",
";",
"return",
"$",
"response",
";",
"}"
] | Create a binary file response.
@param string $file
@return BinaryFileResponse | [
"Create",
"a",
"binary",
"file",
"response",
"."
] | 6766a36cc2f0c807c59202bf7540a08c4ef31192 | https://github.com/sulu/sulu/blob/6766a36cc2f0c807c59202bf7540a08c4ef31192/src/Sulu/Bundle/WebsiteBundle/Controller/SitemapController.php#L191-L197 | train |
sulu/sulu | src/Sulu/Component/Security/Authorization/AccessControl/DoctrineAccessControlProvider.php | DoctrineAccessControlProvider.setPermissions | public function setPermissions($type, $identifier, $permissions)
{
foreach ($permissions as $roleId => $rolePermissions) {
$accessControl = $this->accessControlRepository->findByTypeAndIdAndRole($type, $identifier, $roleId);
if ($accessControl) {
$accessControl->setPermissions($this->maskConverter->convertPermissionsToNumber($rolePermissions));
} else {
$role = $this->roleRepository->findRoleById($roleId);
$accessControl = new AccessControl();
$accessControl->setPermissions($this->maskConverter->convertPermissionsToNumber($rolePermissions));
$accessControl->setRole($role);
$accessControl->setEntityId($identifier);
$accessControl->setEntityClass($type);
$this->objectManager->persist($accessControl);
}
}
$this->objectManager->flush();
} | php | public function setPermissions($type, $identifier, $permissions)
{
foreach ($permissions as $roleId => $rolePermissions) {
$accessControl = $this->accessControlRepository->findByTypeAndIdAndRole($type, $identifier, $roleId);
if ($accessControl) {
$accessControl->setPermissions($this->maskConverter->convertPermissionsToNumber($rolePermissions));
} else {
$role = $this->roleRepository->findRoleById($roleId);
$accessControl = new AccessControl();
$accessControl->setPermissions($this->maskConverter->convertPermissionsToNumber($rolePermissions));
$accessControl->setRole($role);
$accessControl->setEntityId($identifier);
$accessControl->setEntityClass($type);
$this->objectManager->persist($accessControl);
}
}
$this->objectManager->flush();
} | [
"public",
"function",
"setPermissions",
"(",
"$",
"type",
",",
"$",
"identifier",
",",
"$",
"permissions",
")",
"{",
"foreach",
"(",
"$",
"permissions",
"as",
"$",
"roleId",
"=>",
"$",
"rolePermissions",
")",
"{",
"$",
"accessControl",
"=",
"$",
"this",
"->",
"accessControlRepository",
"->",
"findByTypeAndIdAndRole",
"(",
"$",
"type",
",",
"$",
"identifier",
",",
"$",
"roleId",
")",
";",
"if",
"(",
"$",
"accessControl",
")",
"{",
"$",
"accessControl",
"->",
"setPermissions",
"(",
"$",
"this",
"->",
"maskConverter",
"->",
"convertPermissionsToNumber",
"(",
"$",
"rolePermissions",
")",
")",
";",
"}",
"else",
"{",
"$",
"role",
"=",
"$",
"this",
"->",
"roleRepository",
"->",
"findRoleById",
"(",
"$",
"roleId",
")",
";",
"$",
"accessControl",
"=",
"new",
"AccessControl",
"(",
")",
";",
"$",
"accessControl",
"->",
"setPermissions",
"(",
"$",
"this",
"->",
"maskConverter",
"->",
"convertPermissionsToNumber",
"(",
"$",
"rolePermissions",
")",
")",
";",
"$",
"accessControl",
"->",
"setRole",
"(",
"$",
"role",
")",
";",
"$",
"accessControl",
"->",
"setEntityId",
"(",
"$",
"identifier",
")",
";",
"$",
"accessControl",
"->",
"setEntityClass",
"(",
"$",
"type",
")",
";",
"$",
"this",
"->",
"objectManager",
"->",
"persist",
"(",
"$",
"accessControl",
")",
";",
"}",
"}",
"$",
"this",
"->",
"objectManager",
"->",
"flush",
"(",
")",
";",
"}"
] | Sets the permissions for the object with the given class and id for the given security identity.
@param string $type The name of the class to protect
@param string $identifier
@param $permissions | [
"Sets",
"the",
"permissions",
"for",
"the",
"object",
"with",
"the",
"given",
"class",
"and",
"id",
"for",
"the",
"given",
"security",
"identity",
"."
] | 6766a36cc2f0c807c59202bf7540a08c4ef31192 | https://github.com/sulu/sulu/blob/6766a36cc2f0c807c59202bf7540a08c4ef31192/src/Sulu/Component/Security/Authorization/AccessControl/DoctrineAccessControlProvider.php#L71-L91 | train |
sulu/sulu | src/Sulu/Component/Security/Authorization/AccessControl/DoctrineAccessControlProvider.php | DoctrineAccessControlProvider.getPermissions | public function getPermissions($type, $identifier)
{
$accessControls = $this->accessControlRepository->findByTypeAndId($type, $identifier);
$permissions = [];
foreach ($accessControls as $accessControl) {
$permissions[$accessControl->getRole()->getId()] = $this->maskConverter->convertPermissionsToArray(
$accessControl->getPermissions()
);
}
return $permissions;
} | php | public function getPermissions($type, $identifier)
{
$accessControls = $this->accessControlRepository->findByTypeAndId($type, $identifier);
$permissions = [];
foreach ($accessControls as $accessControl) {
$permissions[$accessControl->getRole()->getId()] = $this->maskConverter->convertPermissionsToArray(
$accessControl->getPermissions()
);
}
return $permissions;
} | [
"public",
"function",
"getPermissions",
"(",
"$",
"type",
",",
"$",
"identifier",
")",
"{",
"$",
"accessControls",
"=",
"$",
"this",
"->",
"accessControlRepository",
"->",
"findByTypeAndId",
"(",
"$",
"type",
",",
"$",
"identifier",
")",
";",
"$",
"permissions",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"accessControls",
"as",
"$",
"accessControl",
")",
"{",
"$",
"permissions",
"[",
"$",
"accessControl",
"->",
"getRole",
"(",
")",
"->",
"getId",
"(",
")",
"]",
"=",
"$",
"this",
"->",
"maskConverter",
"->",
"convertPermissionsToArray",
"(",
"$",
"accessControl",
"->",
"getPermissions",
"(",
")",
")",
";",
"}",
"return",
"$",
"permissions",
";",
"}"
] | Returns the permissions for all security identities.
@param string $type The type of the protected object
@param string $identifier The identifier of the protected object
@return array | [
"Returns",
"the",
"permissions",
"for",
"all",
"security",
"identities",
"."
] | 6766a36cc2f0c807c59202bf7540a08c4ef31192 | https://github.com/sulu/sulu/blob/6766a36cc2f0c807c59202bf7540a08c4ef31192/src/Sulu/Component/Security/Authorization/AccessControl/DoctrineAccessControlProvider.php#L101-L113 | train |
sulu/sulu | src/Sulu/Bundle/SecurityBundle/Controller/RoleSettingController.php | RoleSettingController.getAction | public function getAction($roleId, $key)
{
$settingValue = $this->get('sulu.repository.role_setting')->findSettingValue($roleId, $key);
return $this->handleView($this->view($settingValue));
} | php | public function getAction($roleId, $key)
{
$settingValue = $this->get('sulu.repository.role_setting')->findSettingValue($roleId, $key);
return $this->handleView($this->view($settingValue));
} | [
"public",
"function",
"getAction",
"(",
"$",
"roleId",
",",
"$",
"key",
")",
"{",
"$",
"settingValue",
"=",
"$",
"this",
"->",
"get",
"(",
"'sulu.repository.role_setting'",
")",
"->",
"findSettingValue",
"(",
"$",
"roleId",
",",
"$",
"key",
")",
";",
"return",
"$",
"this",
"->",
"handleView",
"(",
"$",
"this",
"->",
"view",
"(",
"$",
"settingValue",
")",
")",
";",
"}"
] | Returns value for given role-setting.
@param int $roleId
@param string $key
@return Response | [
"Returns",
"value",
"for",
"given",
"role",
"-",
"setting",
"."
] | 6766a36cc2f0c807c59202bf7540a08c4ef31192 | https://github.com/sulu/sulu/blob/6766a36cc2f0c807c59202bf7540a08c4ef31192/src/Sulu/Bundle/SecurityBundle/Controller/RoleSettingController.php#L38-L43 | train |
sulu/sulu | src/Sulu/Bundle/SecurityBundle/Controller/RoleSettingController.php | RoleSettingController.putAction | public function putAction(Request $request, $roleId, $key)
{
/** @var EntityManagerInterface $entityManager */
$entityManager = $this->get('doctrine.orm.entity_manager');
/** @var RoleSettingRepository $repository */
$repository = $this->get('sulu.repository.role_setting');
$setting = $repository->findSetting($roleId, $key);
if (!$setting) {
$setting = $repository->createNew();
}
$setting->setKey($key);
$setting->setValue($request->get('value', []));
$setting->setRole($entityManager->getReference(Role::class, $roleId));
$entityManager->persist($setting);
$entityManager->flush();
return $this->handleView($this->view($setting->getValue()));
} | php | public function putAction(Request $request, $roleId, $key)
{
/** @var EntityManagerInterface $entityManager */
$entityManager = $this->get('doctrine.orm.entity_manager');
/** @var RoleSettingRepository $repository */
$repository = $this->get('sulu.repository.role_setting');
$setting = $repository->findSetting($roleId, $key);
if (!$setting) {
$setting = $repository->createNew();
}
$setting->setKey($key);
$setting->setValue($request->get('value', []));
$setting->setRole($entityManager->getReference(Role::class, $roleId));
$entityManager->persist($setting);
$entityManager->flush();
return $this->handleView($this->view($setting->getValue()));
} | [
"public",
"function",
"putAction",
"(",
"Request",
"$",
"request",
",",
"$",
"roleId",
",",
"$",
"key",
")",
"{",
"/** @var EntityManagerInterface $entityManager */",
"$",
"entityManager",
"=",
"$",
"this",
"->",
"get",
"(",
"'doctrine.orm.entity_manager'",
")",
";",
"/** @var RoleSettingRepository $repository */",
"$",
"repository",
"=",
"$",
"this",
"->",
"get",
"(",
"'sulu.repository.role_setting'",
")",
";",
"$",
"setting",
"=",
"$",
"repository",
"->",
"findSetting",
"(",
"$",
"roleId",
",",
"$",
"key",
")",
";",
"if",
"(",
"!",
"$",
"setting",
")",
"{",
"$",
"setting",
"=",
"$",
"repository",
"->",
"createNew",
"(",
")",
";",
"}",
"$",
"setting",
"->",
"setKey",
"(",
"$",
"key",
")",
";",
"$",
"setting",
"->",
"setValue",
"(",
"$",
"request",
"->",
"get",
"(",
"'value'",
",",
"[",
"]",
")",
")",
";",
"$",
"setting",
"->",
"setRole",
"(",
"$",
"entityManager",
"->",
"getReference",
"(",
"Role",
"::",
"class",
",",
"$",
"roleId",
")",
")",
";",
"$",
"entityManager",
"->",
"persist",
"(",
"$",
"setting",
")",
";",
"$",
"entityManager",
"->",
"flush",
"(",
")",
";",
"return",
"$",
"this",
"->",
"handleView",
"(",
"$",
"this",
"->",
"view",
"(",
"$",
"setting",
"->",
"getValue",
"(",
")",
")",
")",
";",
"}"
] | Save role-setting with value from request body.
@param Request $request
@param int $roleId
@param string $key
@return Response | [
"Save",
"role",
"-",
"setting",
"with",
"value",
"from",
"request",
"body",
"."
] | 6766a36cc2f0c807c59202bf7540a08c4ef31192 | https://github.com/sulu/sulu/blob/6766a36cc2f0c807c59202bf7540a08c4ef31192/src/Sulu/Bundle/SecurityBundle/Controller/RoleSettingController.php#L54-L74 | train |
sulu/sulu | src/Sulu/Bundle/RouteBundle/Generator/ChainRouteGenerator.php | ChainRouteGenerator.getClassMappingConfiguration | protected function getClassMappingConfiguration($className)
{
if (array_key_exists($className, $this->mappings)) {
return [
'className' => $className,
'mapping' => $this->mappings[$className],
];
}
$reflection = new \ReflectionClass($className);
while ($reflection = $reflection->getParentClass()) {
if (array_key_exists($reflection->getName(), $this->mappings)) {
return [
'className' => $reflection->getName(),
'mapping' => $this->mappings[$reflection->getName()],
];
}
}
throw new MissingClassMappingConfigurationException($className, array_keys($this->mappings));
} | php | protected function getClassMappingConfiguration($className)
{
if (array_key_exists($className, $this->mappings)) {
return [
'className' => $className,
'mapping' => $this->mappings[$className],
];
}
$reflection = new \ReflectionClass($className);
while ($reflection = $reflection->getParentClass()) {
if (array_key_exists($reflection->getName(), $this->mappings)) {
return [
'className' => $reflection->getName(),
'mapping' => $this->mappings[$reflection->getName()],
];
}
}
throw new MissingClassMappingConfigurationException($className, array_keys($this->mappings));
} | [
"protected",
"function",
"getClassMappingConfiguration",
"(",
"$",
"className",
")",
"{",
"if",
"(",
"array_key_exists",
"(",
"$",
"className",
",",
"$",
"this",
"->",
"mappings",
")",
")",
"{",
"return",
"[",
"'className'",
"=>",
"$",
"className",
",",
"'mapping'",
"=>",
"$",
"this",
"->",
"mappings",
"[",
"$",
"className",
"]",
",",
"]",
";",
"}",
"$",
"reflection",
"=",
"new",
"\\",
"ReflectionClass",
"(",
"$",
"className",
")",
";",
"while",
"(",
"$",
"reflection",
"=",
"$",
"reflection",
"->",
"getParentClass",
"(",
")",
")",
"{",
"if",
"(",
"array_key_exists",
"(",
"$",
"reflection",
"->",
"getName",
"(",
")",
",",
"$",
"this",
"->",
"mappings",
")",
")",
"{",
"return",
"[",
"'className'",
"=>",
"$",
"reflection",
"->",
"getName",
"(",
")",
",",
"'mapping'",
"=>",
"$",
"this",
"->",
"mappings",
"[",
"$",
"reflection",
"->",
"getName",
"(",
")",
"]",
",",
"]",
";",
"}",
"}",
"throw",
"new",
"MissingClassMappingConfigurationException",
"(",
"$",
"className",
",",
"array_keys",
"(",
"$",
"this",
"->",
"mappings",
")",
")",
";",
"}"
] | Get class mapping configuration by class name or inheritance chain.
@param string $className
@return array
@throws MissingClassMappingConfigurationException | [
"Get",
"class",
"mapping",
"configuration",
"by",
"class",
"name",
"or",
"inheritance",
"chain",
"."
] | 6766a36cc2f0c807c59202bf7540a08c4ef31192 | https://github.com/sulu/sulu/blob/6766a36cc2f0c807c59202bf7540a08c4ef31192/src/Sulu/Bundle/RouteBundle/Generator/ChainRouteGenerator.php#L78-L98 | train |
sulu/sulu | src/Sulu/Bundle/SecurityBundle/Controller/RoleController.php | RoleController.cgetAction | public function cgetAction(Request $request)
{
if ('true' == $request->get('flat')) {
/** @var RestHelperInterface $restHelper */
$restHelper = $this->get('sulu_core.doctrine_rest_helper');
/** @var DoctrineListBuilderFactory $factory */
$factory = $this->get('sulu_core.doctrine_list_builder_factory');
$listBuilder = $factory->create($this->container->getParameter('sulu.model.role.class'));
$restHelper->initializeListBuilder($listBuilder, $this->getFieldDescriptors());
$list = new ListRepresentation(
$listBuilder->execute(),
static::$entityKey,
'get_roles',
$request->query->all(),
$listBuilder->getCurrentPage(),
$listBuilder->getLimit(),
$listBuilder->count()
);
} else {
$roles = $this->getRoleRepository()->findAllRoles();
$convertedRoles = [];
if (null != $roles) {
foreach ($roles as $role) {
array_push($convertedRoles, $this->convertRole($role));
}
}
$list = new CollectionRepresentation($convertedRoles, static::$entityKey);
}
$view = $this->view($list, 200);
return $this->handleView($view);
} | php | public function cgetAction(Request $request)
{
if ('true' == $request->get('flat')) {
/** @var RestHelperInterface $restHelper */
$restHelper = $this->get('sulu_core.doctrine_rest_helper');
/** @var DoctrineListBuilderFactory $factory */
$factory = $this->get('sulu_core.doctrine_list_builder_factory');
$listBuilder = $factory->create($this->container->getParameter('sulu.model.role.class'));
$restHelper->initializeListBuilder($listBuilder, $this->getFieldDescriptors());
$list = new ListRepresentation(
$listBuilder->execute(),
static::$entityKey,
'get_roles',
$request->query->all(),
$listBuilder->getCurrentPage(),
$listBuilder->getLimit(),
$listBuilder->count()
);
} else {
$roles = $this->getRoleRepository()->findAllRoles();
$convertedRoles = [];
if (null != $roles) {
foreach ($roles as $role) {
array_push($convertedRoles, $this->convertRole($role));
}
}
$list = new CollectionRepresentation($convertedRoles, static::$entityKey);
}
$view = $this->view($list, 200);
return $this->handleView($view);
} | [
"public",
"function",
"cgetAction",
"(",
"Request",
"$",
"request",
")",
"{",
"if",
"(",
"'true'",
"==",
"$",
"request",
"->",
"get",
"(",
"'flat'",
")",
")",
"{",
"/** @var RestHelperInterface $restHelper */",
"$",
"restHelper",
"=",
"$",
"this",
"->",
"get",
"(",
"'sulu_core.doctrine_rest_helper'",
")",
";",
"/** @var DoctrineListBuilderFactory $factory */",
"$",
"factory",
"=",
"$",
"this",
"->",
"get",
"(",
"'sulu_core.doctrine_list_builder_factory'",
")",
";",
"$",
"listBuilder",
"=",
"$",
"factory",
"->",
"create",
"(",
"$",
"this",
"->",
"container",
"->",
"getParameter",
"(",
"'sulu.model.role.class'",
")",
")",
";",
"$",
"restHelper",
"->",
"initializeListBuilder",
"(",
"$",
"listBuilder",
",",
"$",
"this",
"->",
"getFieldDescriptors",
"(",
")",
")",
";",
"$",
"list",
"=",
"new",
"ListRepresentation",
"(",
"$",
"listBuilder",
"->",
"execute",
"(",
")",
",",
"static",
"::",
"$",
"entityKey",
",",
"'get_roles'",
",",
"$",
"request",
"->",
"query",
"->",
"all",
"(",
")",
",",
"$",
"listBuilder",
"->",
"getCurrentPage",
"(",
")",
",",
"$",
"listBuilder",
"->",
"getLimit",
"(",
")",
",",
"$",
"listBuilder",
"->",
"count",
"(",
")",
")",
";",
"}",
"else",
"{",
"$",
"roles",
"=",
"$",
"this",
"->",
"getRoleRepository",
"(",
")",
"->",
"findAllRoles",
"(",
")",
";",
"$",
"convertedRoles",
"=",
"[",
"]",
";",
"if",
"(",
"null",
"!=",
"$",
"roles",
")",
"{",
"foreach",
"(",
"$",
"roles",
"as",
"$",
"role",
")",
"{",
"array_push",
"(",
"$",
"convertedRoles",
",",
"$",
"this",
"->",
"convertRole",
"(",
"$",
"role",
")",
")",
";",
"}",
"}",
"$",
"list",
"=",
"new",
"CollectionRepresentation",
"(",
"$",
"convertedRoles",
",",
"static",
"::",
"$",
"entityKey",
")",
";",
"}",
"$",
"view",
"=",
"$",
"this",
"->",
"view",
"(",
"$",
"list",
",",
"200",
")",
";",
"return",
"$",
"this",
"->",
"handleView",
"(",
"$",
"view",
")",
";",
"}"
] | returns all roles.
@param \Symfony\Component\HttpFoundation\Request $request
@return \Symfony\Component\HttpFoundation\Response | [
"returns",
"all",
"roles",
"."
] | 6766a36cc2f0c807c59202bf7540a08c4ef31192 | https://github.com/sulu/sulu/blob/6766a36cc2f0c807c59202bf7540a08c4ef31192/src/Sulu/Bundle/SecurityBundle/Controller/RoleController.php#L70-L105 | train |
sulu/sulu | src/Sulu/Bundle/SecurityBundle/Controller/RoleController.php | RoleController.getAction | public function getAction($id)
{
$find = function($id) {
/** @var RoleInterface $role */
$role = $this->getRoleRepository()->findRoleById($id);
return $this->convertRole($role);
};
$view = $this->responseGetById($id, $find);
return $this->handleView($view);
} | php | public function getAction($id)
{
$find = function($id) {
/** @var RoleInterface $role */
$role = $this->getRoleRepository()->findRoleById($id);
return $this->convertRole($role);
};
$view = $this->responseGetById($id, $find);
return $this->handleView($view);
} | [
"public",
"function",
"getAction",
"(",
"$",
"id",
")",
"{",
"$",
"find",
"=",
"function",
"(",
"$",
"id",
")",
"{",
"/** @var RoleInterface $role */",
"$",
"role",
"=",
"$",
"this",
"->",
"getRoleRepository",
"(",
")",
"->",
"findRoleById",
"(",
"$",
"id",
")",
";",
"return",
"$",
"this",
"->",
"convertRole",
"(",
"$",
"role",
")",
";",
"}",
";",
"$",
"view",
"=",
"$",
"this",
"->",
"responseGetById",
"(",
"$",
"id",
",",
"$",
"find",
")",
";",
"return",
"$",
"this",
"->",
"handleView",
"(",
"$",
"view",
")",
";",
"}"
] | Returns the role with the given id.
@param $id
@return \Symfony\Component\HttpFoundation\Response | [
"Returns",
"the",
"role",
"with",
"the",
"given",
"id",
"."
] | 6766a36cc2f0c807c59202bf7540a08c4ef31192 | https://github.com/sulu/sulu/blob/6766a36cc2f0c807c59202bf7540a08c4ef31192/src/Sulu/Bundle/SecurityBundle/Controller/RoleController.php#L114-L126 | train |
sulu/sulu | src/Sulu/Bundle/SecurityBundle/Controller/RoleController.php | RoleController.postAction | public function postAction(Request $request)
{
$name = $request->get('name');
$system = $request->get('system');
try {
if (null === $name) {
throw new InvalidArgumentException('Role', 'name');
}
if (null === $system) {
throw new InvalidArgumentException('Role', 'name');
}
$em = $this->getDoctrine()->getManager();
/** @var RoleInterface $role */
$role = $this->getRoleRepository()->createNew();
$role->setName($name);
$role->setSystem($system);
$permissions = $request->get('permissions');
if (!empty($permissions)) {
foreach ($permissions as $permissionData) {
$this->addPermission($role, $permissionData);
}
}
$securityTypeData = $request->get('securityType');
if ($this->checkSecurityTypeData($securityTypeData)) {
$this->setSecurityType($role, $securityTypeData);
}
try {
$em->persist($role);
$em->flush();
$view = $this->view($this->convertRole($role), 200);
} catch (DoctrineUniqueConstraintViolationException $ex) {
throw new SuluUniqueConstraintViolationException('name', 'SuluSecurityBudle:Role');
}
} catch (RestException $ex) {
$view = $this->view($ex->toArray(), 400);
}
return $this->handleView($view);
} | php | public function postAction(Request $request)
{
$name = $request->get('name');
$system = $request->get('system');
try {
if (null === $name) {
throw new InvalidArgumentException('Role', 'name');
}
if (null === $system) {
throw new InvalidArgumentException('Role', 'name');
}
$em = $this->getDoctrine()->getManager();
/** @var RoleInterface $role */
$role = $this->getRoleRepository()->createNew();
$role->setName($name);
$role->setSystem($system);
$permissions = $request->get('permissions');
if (!empty($permissions)) {
foreach ($permissions as $permissionData) {
$this->addPermission($role, $permissionData);
}
}
$securityTypeData = $request->get('securityType');
if ($this->checkSecurityTypeData($securityTypeData)) {
$this->setSecurityType($role, $securityTypeData);
}
try {
$em->persist($role);
$em->flush();
$view = $this->view($this->convertRole($role), 200);
} catch (DoctrineUniqueConstraintViolationException $ex) {
throw new SuluUniqueConstraintViolationException('name', 'SuluSecurityBudle:Role');
}
} catch (RestException $ex) {
$view = $this->view($ex->toArray(), 400);
}
return $this->handleView($view);
} | [
"public",
"function",
"postAction",
"(",
"Request",
"$",
"request",
")",
"{",
"$",
"name",
"=",
"$",
"request",
"->",
"get",
"(",
"'name'",
")",
";",
"$",
"system",
"=",
"$",
"request",
"->",
"get",
"(",
"'system'",
")",
";",
"try",
"{",
"if",
"(",
"null",
"===",
"$",
"name",
")",
"{",
"throw",
"new",
"InvalidArgumentException",
"(",
"'Role'",
",",
"'name'",
")",
";",
"}",
"if",
"(",
"null",
"===",
"$",
"system",
")",
"{",
"throw",
"new",
"InvalidArgumentException",
"(",
"'Role'",
",",
"'name'",
")",
";",
"}",
"$",
"em",
"=",
"$",
"this",
"->",
"getDoctrine",
"(",
")",
"->",
"getManager",
"(",
")",
";",
"/** @var RoleInterface $role */",
"$",
"role",
"=",
"$",
"this",
"->",
"getRoleRepository",
"(",
")",
"->",
"createNew",
"(",
")",
";",
"$",
"role",
"->",
"setName",
"(",
"$",
"name",
")",
";",
"$",
"role",
"->",
"setSystem",
"(",
"$",
"system",
")",
";",
"$",
"permissions",
"=",
"$",
"request",
"->",
"get",
"(",
"'permissions'",
")",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"permissions",
")",
")",
"{",
"foreach",
"(",
"$",
"permissions",
"as",
"$",
"permissionData",
")",
"{",
"$",
"this",
"->",
"addPermission",
"(",
"$",
"role",
",",
"$",
"permissionData",
")",
";",
"}",
"}",
"$",
"securityTypeData",
"=",
"$",
"request",
"->",
"get",
"(",
"'securityType'",
")",
";",
"if",
"(",
"$",
"this",
"->",
"checkSecurityTypeData",
"(",
"$",
"securityTypeData",
")",
")",
"{",
"$",
"this",
"->",
"setSecurityType",
"(",
"$",
"role",
",",
"$",
"securityTypeData",
")",
";",
"}",
"try",
"{",
"$",
"em",
"->",
"persist",
"(",
"$",
"role",
")",
";",
"$",
"em",
"->",
"flush",
"(",
")",
";",
"$",
"view",
"=",
"$",
"this",
"->",
"view",
"(",
"$",
"this",
"->",
"convertRole",
"(",
"$",
"role",
")",
",",
"200",
")",
";",
"}",
"catch",
"(",
"DoctrineUniqueConstraintViolationException",
"$",
"ex",
")",
"{",
"throw",
"new",
"SuluUniqueConstraintViolationException",
"(",
"'name'",
",",
"'SuluSecurityBudle:Role'",
")",
";",
"}",
"}",
"catch",
"(",
"RestException",
"$",
"ex",
")",
"{",
"$",
"view",
"=",
"$",
"this",
"->",
"view",
"(",
"$",
"ex",
"->",
"toArray",
"(",
")",
",",
"400",
")",
";",
"}",
"return",
"$",
"this",
"->",
"handleView",
"(",
"$",
"view",
")",
";",
"}"
] | Creates a new role with the given data.
@param \Symfony\Component\HttpFoundation\Request $request
@throws \Sulu\Component\Rest\Exception\EntityIdAlreadySetException
@throws \Sulu\Component\Rest\Exception\EntityNotFoundException
@return \Symfony\Component\HttpFoundation\Response | [
"Creates",
"a",
"new",
"role",
"with",
"the",
"given",
"data",
"."
] | 6766a36cc2f0c807c59202bf7540a08c4ef31192 | https://github.com/sulu/sulu/blob/6766a36cc2f0c807c59202bf7540a08c4ef31192/src/Sulu/Bundle/SecurityBundle/Controller/RoleController.php#L138-L183 | train |
sulu/sulu | src/Sulu/Bundle/SecurityBundle/Controller/RoleController.php | RoleController.putAction | public function putAction(Request $request, $id)
{
/** @var RoleInterface $role */
$role = $this->getRoleRepository()->findRoleById($id);
try {
if (!$role) {
throw new EntityNotFoundException($this->getRoleRepository()->getClassName(), $id);
} else {
$em = $this->getDoctrine()->getManager();
$name = $request->get('name');
$role->setName($name);
$role->setSystem($request->get('system'));
if (!$this->processPermissions($role, $request->get('permissions', []))) {
throw new RestException('Could not update dependencies!');
}
$securityTypeData = $request->get('securityType');
if ($this->checkSecurityTypeData($securityTypeData)) {
$this->setSecurityType($role, $securityTypeData);
} else {
$role->setSecurityType(null);
}
$em->flush();
$view = $this->view($this->convertRole($role), 200);
}
} catch (EntityNotFoundException $enfe) {
$view = $this->view($enfe->toArray(), 404);
} catch (DoctrineUniqueConstraintViolationException $e) {
throw new RoleNameAlreadyExistsException($name);
} catch (RestException $re) {
$view = $this->view($re->toArray(), 400);
}
return $this->handleView($view);
} | php | public function putAction(Request $request, $id)
{
/** @var RoleInterface $role */
$role = $this->getRoleRepository()->findRoleById($id);
try {
if (!$role) {
throw new EntityNotFoundException($this->getRoleRepository()->getClassName(), $id);
} else {
$em = $this->getDoctrine()->getManager();
$name = $request->get('name');
$role->setName($name);
$role->setSystem($request->get('system'));
if (!$this->processPermissions($role, $request->get('permissions', []))) {
throw new RestException('Could not update dependencies!');
}
$securityTypeData = $request->get('securityType');
if ($this->checkSecurityTypeData($securityTypeData)) {
$this->setSecurityType($role, $securityTypeData);
} else {
$role->setSecurityType(null);
}
$em->flush();
$view = $this->view($this->convertRole($role), 200);
}
} catch (EntityNotFoundException $enfe) {
$view = $this->view($enfe->toArray(), 404);
} catch (DoctrineUniqueConstraintViolationException $e) {
throw new RoleNameAlreadyExistsException($name);
} catch (RestException $re) {
$view = $this->view($re->toArray(), 400);
}
return $this->handleView($view);
} | [
"public",
"function",
"putAction",
"(",
"Request",
"$",
"request",
",",
"$",
"id",
")",
"{",
"/** @var RoleInterface $role */",
"$",
"role",
"=",
"$",
"this",
"->",
"getRoleRepository",
"(",
")",
"->",
"findRoleById",
"(",
"$",
"id",
")",
";",
"try",
"{",
"if",
"(",
"!",
"$",
"role",
")",
"{",
"throw",
"new",
"EntityNotFoundException",
"(",
"$",
"this",
"->",
"getRoleRepository",
"(",
")",
"->",
"getClassName",
"(",
")",
",",
"$",
"id",
")",
";",
"}",
"else",
"{",
"$",
"em",
"=",
"$",
"this",
"->",
"getDoctrine",
"(",
")",
"->",
"getManager",
"(",
")",
";",
"$",
"name",
"=",
"$",
"request",
"->",
"get",
"(",
"'name'",
")",
";",
"$",
"role",
"->",
"setName",
"(",
"$",
"name",
")",
";",
"$",
"role",
"->",
"setSystem",
"(",
"$",
"request",
"->",
"get",
"(",
"'system'",
")",
")",
";",
"if",
"(",
"!",
"$",
"this",
"->",
"processPermissions",
"(",
"$",
"role",
",",
"$",
"request",
"->",
"get",
"(",
"'permissions'",
",",
"[",
"]",
")",
")",
")",
"{",
"throw",
"new",
"RestException",
"(",
"'Could not update dependencies!'",
")",
";",
"}",
"$",
"securityTypeData",
"=",
"$",
"request",
"->",
"get",
"(",
"'securityType'",
")",
";",
"if",
"(",
"$",
"this",
"->",
"checkSecurityTypeData",
"(",
"$",
"securityTypeData",
")",
")",
"{",
"$",
"this",
"->",
"setSecurityType",
"(",
"$",
"role",
",",
"$",
"securityTypeData",
")",
";",
"}",
"else",
"{",
"$",
"role",
"->",
"setSecurityType",
"(",
"null",
")",
";",
"}",
"$",
"em",
"->",
"flush",
"(",
")",
";",
"$",
"view",
"=",
"$",
"this",
"->",
"view",
"(",
"$",
"this",
"->",
"convertRole",
"(",
"$",
"role",
")",
",",
"200",
")",
";",
"}",
"}",
"catch",
"(",
"EntityNotFoundException",
"$",
"enfe",
")",
"{",
"$",
"view",
"=",
"$",
"this",
"->",
"view",
"(",
"$",
"enfe",
"->",
"toArray",
"(",
")",
",",
"404",
")",
";",
"}",
"catch",
"(",
"DoctrineUniqueConstraintViolationException",
"$",
"e",
")",
"{",
"throw",
"new",
"RoleNameAlreadyExistsException",
"(",
"$",
"name",
")",
";",
"}",
"catch",
"(",
"RestException",
"$",
"re",
")",
"{",
"$",
"view",
"=",
"$",
"this",
"->",
"view",
"(",
"$",
"re",
"->",
"toArray",
"(",
")",
",",
"400",
")",
";",
"}",
"return",
"$",
"this",
"->",
"handleView",
"(",
"$",
"view",
")",
";",
"}"
] | Updates the role with the given id and the data given by the request.
@param \Symfony\Component\HttpFoundation\Request $request
@param $id
@return \Symfony\Component\HttpFoundation\Response | [
"Updates",
"the",
"role",
"with",
"the",
"given",
"id",
"and",
"the",
"data",
"given",
"by",
"the",
"request",
"."
] | 6766a36cc2f0c807c59202bf7540a08c4ef31192 | https://github.com/sulu/sulu/blob/6766a36cc2f0c807c59202bf7540a08c4ef31192/src/Sulu/Bundle/SecurityBundle/Controller/RoleController.php#L193-L232 | train |
sulu/sulu | src/Sulu/Bundle/SecurityBundle/Controller/RoleController.php | RoleController.deleteAction | public function deleteAction($id)
{
$delete = function($id) {
$role = $this->getRoleRepository()->findRoleById($id);
if (!$role) {
throw new EntityNotFoundException($this->getRoleRepository()->getClassName(), $id);
}
$em = $this->getDoctrine()->getManager();
$em->remove($role);
$em->flush();
};
$view = $this->responseDelete($id, $delete);
return $this->handleView($view);
} | php | public function deleteAction($id)
{
$delete = function($id) {
$role = $this->getRoleRepository()->findRoleById($id);
if (!$role) {
throw new EntityNotFoundException($this->getRoleRepository()->getClassName(), $id);
}
$em = $this->getDoctrine()->getManager();
$em->remove($role);
$em->flush();
};
$view = $this->responseDelete($id, $delete);
return $this->handleView($view);
} | [
"public",
"function",
"deleteAction",
"(",
"$",
"id",
")",
"{",
"$",
"delete",
"=",
"function",
"(",
"$",
"id",
")",
"{",
"$",
"role",
"=",
"$",
"this",
"->",
"getRoleRepository",
"(",
")",
"->",
"findRoleById",
"(",
"$",
"id",
")",
";",
"if",
"(",
"!",
"$",
"role",
")",
"{",
"throw",
"new",
"EntityNotFoundException",
"(",
"$",
"this",
"->",
"getRoleRepository",
"(",
")",
"->",
"getClassName",
"(",
")",
",",
"$",
"id",
")",
";",
"}",
"$",
"em",
"=",
"$",
"this",
"->",
"getDoctrine",
"(",
")",
"->",
"getManager",
"(",
")",
";",
"$",
"em",
"->",
"remove",
"(",
"$",
"role",
")",
";",
"$",
"em",
"->",
"flush",
"(",
")",
";",
"}",
";",
"$",
"view",
"=",
"$",
"this",
"->",
"responseDelete",
"(",
"$",
"id",
",",
"$",
"delete",
")",
";",
"return",
"$",
"this",
"->",
"handleView",
"(",
"$",
"view",
")",
";",
"}"
] | Deletes the role with the given id.
@param $id
@return \Symfony\Component\HttpFoundation\Response | [
"Deletes",
"the",
"role",
"with",
"the",
"given",
"id",
"."
] | 6766a36cc2f0c807c59202bf7540a08c4ef31192 | https://github.com/sulu/sulu/blob/6766a36cc2f0c807c59202bf7540a08c4ef31192/src/Sulu/Bundle/SecurityBundle/Controller/RoleController.php#L241-L258 | train |
sulu/sulu | src/Sulu/Bundle/SecurityBundle/Controller/RoleController.php | RoleController.processPermissions | protected function processPermissions(RoleInterface $role, $permissions)
{
/** @var RestHelperInterface $restHelper */
$restHelper = $this->get('sulu_core.doctrine_rest_helper');
$get = function($entity) {
/* @var Permission $entity */
return $entity->getId();
};
$delete = function($permission) {
$this->getDoctrine()->getManager()->remove($permission);
};
$update = function($permission, $permissionData) {
return $this->updatePermission($permission, $permissionData);
};
$add = function($permission) use ($role) {
return $this->addPermission($role, $permission);
};
return $restHelper->processSubEntities($role->getPermissions(), $permissions, $get, $add, $update, $delete);
} | php | protected function processPermissions(RoleInterface $role, $permissions)
{
/** @var RestHelperInterface $restHelper */
$restHelper = $this->get('sulu_core.doctrine_rest_helper');
$get = function($entity) {
/* @var Permission $entity */
return $entity->getId();
};
$delete = function($permission) {
$this->getDoctrine()->getManager()->remove($permission);
};
$update = function($permission, $permissionData) {
return $this->updatePermission($permission, $permissionData);
};
$add = function($permission) use ($role) {
return $this->addPermission($role, $permission);
};
return $restHelper->processSubEntities($role->getPermissions(), $permissions, $get, $add, $update, $delete);
} | [
"protected",
"function",
"processPermissions",
"(",
"RoleInterface",
"$",
"role",
",",
"$",
"permissions",
")",
"{",
"/** @var RestHelperInterface $restHelper */",
"$",
"restHelper",
"=",
"$",
"this",
"->",
"get",
"(",
"'sulu_core.doctrine_rest_helper'",
")",
";",
"$",
"get",
"=",
"function",
"(",
"$",
"entity",
")",
"{",
"/* @var Permission $entity */",
"return",
"$",
"entity",
"->",
"getId",
"(",
")",
";",
"}",
";",
"$",
"delete",
"=",
"function",
"(",
"$",
"permission",
")",
"{",
"$",
"this",
"->",
"getDoctrine",
"(",
")",
"->",
"getManager",
"(",
")",
"->",
"remove",
"(",
"$",
"permission",
")",
";",
"}",
";",
"$",
"update",
"=",
"function",
"(",
"$",
"permission",
",",
"$",
"permissionData",
")",
"{",
"return",
"$",
"this",
"->",
"updatePermission",
"(",
"$",
"permission",
",",
"$",
"permissionData",
")",
";",
"}",
";",
"$",
"add",
"=",
"function",
"(",
"$",
"permission",
")",
"use",
"(",
"$",
"role",
")",
"{",
"return",
"$",
"this",
"->",
"addPermission",
"(",
"$",
"role",
",",
"$",
"permission",
")",
";",
"}",
";",
"return",
"$",
"restHelper",
"->",
"processSubEntities",
"(",
"$",
"role",
"->",
"getPermissions",
"(",
")",
",",
"$",
"permissions",
",",
"$",
"get",
",",
"$",
"add",
",",
"$",
"update",
",",
"$",
"delete",
")",
";",
"}"
] | Process all permissions from request.
@param RoleInterface $role The contact on which is worked
@param $permissions
@return bool True if the processing was successful, otherwise false | [
"Process",
"all",
"permissions",
"from",
"request",
"."
] | 6766a36cc2f0c807c59202bf7540a08c4ef31192 | https://github.com/sulu/sulu/blob/6766a36cc2f0c807c59202bf7540a08c4ef31192/src/Sulu/Bundle/SecurityBundle/Controller/RoleController.php#L268-L292 | train |
sulu/sulu | src/Sulu/Bundle/SecurityBundle/Controller/RoleController.php | RoleController.addPermission | protected function addPermission(RoleInterface $role, $permissionData)
{
$em = $this->getDoctrine()->getManager();
$alreadyContains = false;
if (isset($permissionData['id'])) {
$permission = $em->getRepository(static::ENTITY_NAME_PERMISSION)->find($permissionData['id']);
if (!$permission) {
throw new EntityNotFoundException(static::ENTITY_NAME_PERMISSION, $permissionData['id']);
}
// only add if not already contains
$alreadyContains = $role->getPermissions()->contains($permission);
} else {
$permission = new Permission();
$permission->setContext($permissionData['context']);
$permission->setPermissions(
$this->get('sulu_security.mask_converter')
->convertPermissionsToNumber($permissionData['permissions'])
);
}
if (false === $alreadyContains) {
$permission->setRole($role);
$em->persist($permission);
$role->addPermission($permission);
}
return true;
} | php | protected function addPermission(RoleInterface $role, $permissionData)
{
$em = $this->getDoctrine()->getManager();
$alreadyContains = false;
if (isset($permissionData['id'])) {
$permission = $em->getRepository(static::ENTITY_NAME_PERMISSION)->find($permissionData['id']);
if (!$permission) {
throw new EntityNotFoundException(static::ENTITY_NAME_PERMISSION, $permissionData['id']);
}
// only add if not already contains
$alreadyContains = $role->getPermissions()->contains($permission);
} else {
$permission = new Permission();
$permission->setContext($permissionData['context']);
$permission->setPermissions(
$this->get('sulu_security.mask_converter')
->convertPermissionsToNumber($permissionData['permissions'])
);
}
if (false === $alreadyContains) {
$permission->setRole($role);
$em->persist($permission);
$role->addPermission($permission);
}
return true;
} | [
"protected",
"function",
"addPermission",
"(",
"RoleInterface",
"$",
"role",
",",
"$",
"permissionData",
")",
"{",
"$",
"em",
"=",
"$",
"this",
"->",
"getDoctrine",
"(",
")",
"->",
"getManager",
"(",
")",
";",
"$",
"alreadyContains",
"=",
"false",
";",
"if",
"(",
"isset",
"(",
"$",
"permissionData",
"[",
"'id'",
"]",
")",
")",
"{",
"$",
"permission",
"=",
"$",
"em",
"->",
"getRepository",
"(",
"static",
"::",
"ENTITY_NAME_PERMISSION",
")",
"->",
"find",
"(",
"$",
"permissionData",
"[",
"'id'",
"]",
")",
";",
"if",
"(",
"!",
"$",
"permission",
")",
"{",
"throw",
"new",
"EntityNotFoundException",
"(",
"static",
"::",
"ENTITY_NAME_PERMISSION",
",",
"$",
"permissionData",
"[",
"'id'",
"]",
")",
";",
"}",
"// only add if not already contains",
"$",
"alreadyContains",
"=",
"$",
"role",
"->",
"getPermissions",
"(",
")",
"->",
"contains",
"(",
"$",
"permission",
")",
";",
"}",
"else",
"{",
"$",
"permission",
"=",
"new",
"Permission",
"(",
")",
";",
"$",
"permission",
"->",
"setContext",
"(",
"$",
"permissionData",
"[",
"'context'",
"]",
")",
";",
"$",
"permission",
"->",
"setPermissions",
"(",
"$",
"this",
"->",
"get",
"(",
"'sulu_security.mask_converter'",
")",
"->",
"convertPermissionsToNumber",
"(",
"$",
"permissionData",
"[",
"'permissions'",
"]",
")",
")",
";",
"}",
"if",
"(",
"false",
"===",
"$",
"alreadyContains",
")",
"{",
"$",
"permission",
"->",
"setRole",
"(",
"$",
"role",
")",
";",
"$",
"em",
"->",
"persist",
"(",
"$",
"permission",
")",
";",
"$",
"role",
"->",
"addPermission",
"(",
"$",
"permission",
")",
";",
"}",
"return",
"true",
";",
"}"
] | Adds a permission to the given role.
@param RoleInterface $role
@param $permissionData
@return bool
@throws EntityNotFoundException | [
"Adds",
"a",
"permission",
"to",
"the",
"given",
"role",
"."
] | 6766a36cc2f0c807c59202bf7540a08c4ef31192 | https://github.com/sulu/sulu/blob/6766a36cc2f0c807c59202bf7540a08c4ef31192/src/Sulu/Bundle/SecurityBundle/Controller/RoleController.php#L304-L331 | train |
sulu/sulu | src/Sulu/Bundle/SecurityBundle/Controller/RoleController.php | RoleController.updatePermission | private function updatePermission(Permission $permission, $permissionData)
{
$permission->setContext($permissionData['context']);
$permission->setPermissions(
$this->get('sulu_security.mask_converter')
->convertPermissionsToNumber($permissionData['permissions'])
);
return true;
} | php | private function updatePermission(Permission $permission, $permissionData)
{
$permission->setContext($permissionData['context']);
$permission->setPermissions(
$this->get('sulu_security.mask_converter')
->convertPermissionsToNumber($permissionData['permissions'])
);
return true;
} | [
"private",
"function",
"updatePermission",
"(",
"Permission",
"$",
"permission",
",",
"$",
"permissionData",
")",
"{",
"$",
"permission",
"->",
"setContext",
"(",
"$",
"permissionData",
"[",
"'context'",
"]",
")",
";",
"$",
"permission",
"->",
"setPermissions",
"(",
"$",
"this",
"->",
"get",
"(",
"'sulu_security.mask_converter'",
")",
"->",
"convertPermissionsToNumber",
"(",
"$",
"permissionData",
"[",
"'permissions'",
"]",
")",
")",
";",
"return",
"true",
";",
"}"
] | Updates an already existing permission.
@param Permission $permission
@param $permissionData
@return bool | [
"Updates",
"an",
"already",
"existing",
"permission",
"."
] | 6766a36cc2f0c807c59202bf7540a08c4ef31192 | https://github.com/sulu/sulu/blob/6766a36cc2f0c807c59202bf7540a08c4ef31192/src/Sulu/Bundle/SecurityBundle/Controller/RoleController.php#L341-L351 | train |
sulu/sulu | src/Sulu/Bundle/SecurityBundle/Controller/RoleController.php | RoleController.convertRole | protected function convertRole(RoleInterface $role)
{
$roleData['id'] = $role->getId();
$roleData['name'] = $role->getName();
$roleData['identifier'] = $role->getIdentifier();
$roleData['system'] = $role->getSystem();
$roleData['permissions'] = [];
$permissions = $role->getPermissions();
if (!empty($permissions)) {
foreach ($permissions as $permission) {
/* @var Permission $permission */
$roleData['permissions'][] = [
'id' => $permission->getId(),
'context' => $permission->getContext(),
'module' => $permission->getModule(),
'permissions' => $this->get('sulu_security.mask_converter')
->convertPermissionsToArray($permission->getPermissions()),
];
}
}
$securityType = $role->getSecurityType();
if ($securityType) {
$roleData['securityType'] = [
'id' => $securityType->getId(),
'name' => $securityType->getName(),
];
}
return $roleData;
} | php | protected function convertRole(RoleInterface $role)
{
$roleData['id'] = $role->getId();
$roleData['name'] = $role->getName();
$roleData['identifier'] = $role->getIdentifier();
$roleData['system'] = $role->getSystem();
$roleData['permissions'] = [];
$permissions = $role->getPermissions();
if (!empty($permissions)) {
foreach ($permissions as $permission) {
/* @var Permission $permission */
$roleData['permissions'][] = [
'id' => $permission->getId(),
'context' => $permission->getContext(),
'module' => $permission->getModule(),
'permissions' => $this->get('sulu_security.mask_converter')
->convertPermissionsToArray($permission->getPermissions()),
];
}
}
$securityType = $role->getSecurityType();
if ($securityType) {
$roleData['securityType'] = [
'id' => $securityType->getId(),
'name' => $securityType->getName(),
];
}
return $roleData;
} | [
"protected",
"function",
"convertRole",
"(",
"RoleInterface",
"$",
"role",
")",
"{",
"$",
"roleData",
"[",
"'id'",
"]",
"=",
"$",
"role",
"->",
"getId",
"(",
")",
";",
"$",
"roleData",
"[",
"'name'",
"]",
"=",
"$",
"role",
"->",
"getName",
"(",
")",
";",
"$",
"roleData",
"[",
"'identifier'",
"]",
"=",
"$",
"role",
"->",
"getIdentifier",
"(",
")",
";",
"$",
"roleData",
"[",
"'system'",
"]",
"=",
"$",
"role",
"->",
"getSystem",
"(",
")",
";",
"$",
"roleData",
"[",
"'permissions'",
"]",
"=",
"[",
"]",
";",
"$",
"permissions",
"=",
"$",
"role",
"->",
"getPermissions",
"(",
")",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"permissions",
")",
")",
"{",
"foreach",
"(",
"$",
"permissions",
"as",
"$",
"permission",
")",
"{",
"/* @var Permission $permission */",
"$",
"roleData",
"[",
"'permissions'",
"]",
"[",
"]",
"=",
"[",
"'id'",
"=>",
"$",
"permission",
"->",
"getId",
"(",
")",
",",
"'context'",
"=>",
"$",
"permission",
"->",
"getContext",
"(",
")",
",",
"'module'",
"=>",
"$",
"permission",
"->",
"getModule",
"(",
")",
",",
"'permissions'",
"=>",
"$",
"this",
"->",
"get",
"(",
"'sulu_security.mask_converter'",
")",
"->",
"convertPermissionsToArray",
"(",
"$",
"permission",
"->",
"getPermissions",
"(",
")",
")",
",",
"]",
";",
"}",
"}",
"$",
"securityType",
"=",
"$",
"role",
"->",
"getSecurityType",
"(",
")",
";",
"if",
"(",
"$",
"securityType",
")",
"{",
"$",
"roleData",
"[",
"'securityType'",
"]",
"=",
"[",
"'id'",
"=>",
"$",
"securityType",
"->",
"getId",
"(",
")",
",",
"'name'",
"=>",
"$",
"securityType",
"->",
"getName",
"(",
")",
",",
"]",
";",
"}",
"return",
"$",
"roleData",
";",
"}"
] | Converts a role object into an array for the rest service.
@param RoleInterface $role
@return array | [
"Converts",
"a",
"role",
"object",
"into",
"an",
"array",
"for",
"the",
"rest",
"service",
"."
] | 6766a36cc2f0c807c59202bf7540a08c4ef31192 | https://github.com/sulu/sulu/blob/6766a36cc2f0c807c59202bf7540a08c4ef31192/src/Sulu/Bundle/SecurityBundle/Controller/RoleController.php#L360-L391 | train |
sulu/sulu | src/Sulu/Bundle/SecurityBundle/Controller/RoleController.php | RoleController.setSecurityType | private function setSecurityType($role, $securityTypeData)
{
$securityType = $this->getDoctrine()
->getRepository('SuluSecurityBundle:SecurityType')
->findSecurityTypeById($securityTypeData['id']);
if (!$securityType) {
throw new EntityNotFoundException('SuluSecurityBundle:SecurityType', $securityTypeData['id']);
}
$role->setSecurityType($securityType);
} | php | private function setSecurityType($role, $securityTypeData)
{
$securityType = $this->getDoctrine()
->getRepository('SuluSecurityBundle:SecurityType')
->findSecurityTypeById($securityTypeData['id']);
if (!$securityType) {
throw new EntityNotFoundException('SuluSecurityBundle:SecurityType', $securityTypeData['id']);
}
$role->setSecurityType($securityType);
} | [
"private",
"function",
"setSecurityType",
"(",
"$",
"role",
",",
"$",
"securityTypeData",
")",
"{",
"$",
"securityType",
"=",
"$",
"this",
"->",
"getDoctrine",
"(",
")",
"->",
"getRepository",
"(",
"'SuluSecurityBundle:SecurityType'",
")",
"->",
"findSecurityTypeById",
"(",
"$",
"securityTypeData",
"[",
"'id'",
"]",
")",
";",
"if",
"(",
"!",
"$",
"securityType",
")",
"{",
"throw",
"new",
"EntityNotFoundException",
"(",
"'SuluSecurityBundle:SecurityType'",
",",
"$",
"securityTypeData",
"[",
"'id'",
"]",
")",
";",
"}",
"$",
"role",
"->",
"setSecurityType",
"(",
"$",
"securityType",
")",
";",
"}"
] | Sets the securityType from the given data to the role.
@param RoleInterface $role
@param $securityTypeData
@throws \Sulu\Component\Rest\Exception\EntityNotFoundException | [
"Sets",
"the",
"securityType",
"from",
"the",
"given",
"data",
"to",
"the",
"role",
"."
] | 6766a36cc2f0c807c59202bf7540a08c4ef31192 | https://github.com/sulu/sulu/blob/6766a36cc2f0c807c59202bf7540a08c4ef31192/src/Sulu/Bundle/SecurityBundle/Controller/RoleController.php#L413-L423 | train |
sulu/sulu | src/Sulu/Component/Content/Query/ContentQueryBuilder.php | ContentQueryBuilder.buildSelectForStructures | private function buildSelectForStructures($locale, $structures, &$names)
{
$result = '';
// add node name and url to selector
/** @var StructureInterface $structure */
foreach ($structures as $structure) {
$result .= $this->buildSelectForStructure($locale, $structure, $names);
}
return $result;
} | php | private function buildSelectForStructures($locale, $structures, &$names)
{
$result = '';
// add node name and url to selector
/** @var StructureInterface $structure */
foreach ($structures as $structure) {
$result .= $this->buildSelectForStructure($locale, $structure, $names);
}
return $result;
} | [
"private",
"function",
"buildSelectForStructures",
"(",
"$",
"locale",
",",
"$",
"structures",
",",
"&",
"$",
"names",
")",
"{",
"$",
"result",
"=",
"''",
";",
"// add node name and url to selector",
"/** @var StructureInterface $structure */",
"foreach",
"(",
"$",
"structures",
"as",
"$",
"structure",
")",
"{",
"$",
"result",
".=",
"$",
"this",
"->",
"buildSelectForStructure",
"(",
"$",
"locale",
",",
"$",
"structure",
",",
"$",
"names",
")",
";",
"}",
"return",
"$",
"result",
";",
"}"
] | Returns select statement with all url and title properties. | [
"Returns",
"select",
"statement",
"with",
"all",
"url",
"and",
"title",
"properties",
"."
] | 6766a36cc2f0c807c59202bf7540a08c4ef31192 | https://github.com/sulu/sulu/blob/6766a36cc2f0c807c59202bf7540a08c4ef31192/src/Sulu/Component/Content/Query/ContentQueryBuilder.php#L214-L224 | train |
sulu/sulu | src/Sulu/Component/Content/Query/ContentQueryBuilder.php | ContentQueryBuilder.buildSelectForStructure | private function buildSelectForStructure($locale, StructureInterface $structure, &$names)
{
$nodeNameProperty = $structure->getProperty('title');
$result = '';
$name = $this->getTranslatedProperty($nodeNameProperty, $locale)->getName();
if (!in_array($name, $names)) {
$names[] = $name;
$result .= ', ' . $this->buildSelector($name);
}
if ($structure->hasTag('sulu.rlp')) {
$urlProperty = $structure->getPropertyByTagName('sulu.rlp');
$name = $this->getTranslatedProperty($urlProperty, $locale)->getName();
if ('resource_locator' !== $urlProperty->getContentTypeName() && !in_array($name, $names)) {
$names[] = $name;
$result .= ', ' . $this->buildSelector($name);
}
}
return $result;
} | php | private function buildSelectForStructure($locale, StructureInterface $structure, &$names)
{
$nodeNameProperty = $structure->getProperty('title');
$result = '';
$name = $this->getTranslatedProperty($nodeNameProperty, $locale)->getName();
if (!in_array($name, $names)) {
$names[] = $name;
$result .= ', ' . $this->buildSelector($name);
}
if ($structure->hasTag('sulu.rlp')) {
$urlProperty = $structure->getPropertyByTagName('sulu.rlp');
$name = $this->getTranslatedProperty($urlProperty, $locale)->getName();
if ('resource_locator' !== $urlProperty->getContentTypeName() && !in_array($name, $names)) {
$names[] = $name;
$result .= ', ' . $this->buildSelector($name);
}
}
return $result;
} | [
"private",
"function",
"buildSelectForStructure",
"(",
"$",
"locale",
",",
"StructureInterface",
"$",
"structure",
",",
"&",
"$",
"names",
")",
"{",
"$",
"nodeNameProperty",
"=",
"$",
"structure",
"->",
"getProperty",
"(",
"'title'",
")",
";",
"$",
"result",
"=",
"''",
";",
"$",
"name",
"=",
"$",
"this",
"->",
"getTranslatedProperty",
"(",
"$",
"nodeNameProperty",
",",
"$",
"locale",
")",
"->",
"getName",
"(",
")",
";",
"if",
"(",
"!",
"in_array",
"(",
"$",
"name",
",",
"$",
"names",
")",
")",
"{",
"$",
"names",
"[",
"]",
"=",
"$",
"name",
";",
"$",
"result",
".=",
"', '",
".",
"$",
"this",
"->",
"buildSelector",
"(",
"$",
"name",
")",
";",
"}",
"if",
"(",
"$",
"structure",
"->",
"hasTag",
"(",
"'sulu.rlp'",
")",
")",
"{",
"$",
"urlProperty",
"=",
"$",
"structure",
"->",
"getPropertyByTagName",
"(",
"'sulu.rlp'",
")",
";",
"$",
"name",
"=",
"$",
"this",
"->",
"getTranslatedProperty",
"(",
"$",
"urlProperty",
",",
"$",
"locale",
")",
"->",
"getName",
"(",
")",
";",
"if",
"(",
"'resource_locator'",
"!==",
"$",
"urlProperty",
"->",
"getContentTypeName",
"(",
")",
"&&",
"!",
"in_array",
"(",
"$",
"name",
",",
"$",
"names",
")",
")",
"{",
"$",
"names",
"[",
"]",
"=",
"$",
"name",
";",
"$",
"result",
".=",
"', '",
".",
"$",
"this",
"->",
"buildSelector",
"(",
"$",
"name",
")",
";",
"}",
"}",
"return",
"$",
"result",
";",
"}"
] | Returns select of a single structure with title and url selector. | [
"Returns",
"select",
"of",
"a",
"single",
"structure",
"with",
"title",
"and",
"url",
"selector",
"."
] | 6766a36cc2f0c807c59202bf7540a08c4ef31192 | https://github.com/sulu/sulu/blob/6766a36cc2f0c807c59202bf7540a08c4ef31192/src/Sulu/Component/Content/Query/ContentQueryBuilder.php#L229-L251 | train |
sulu/sulu | src/Sulu/Component/Content/Query/ContentQueryBuilder.php | ContentQueryBuilder.buildSelectorForExcerpt | private function buildSelectorForExcerpt($locale, &$additionalFields)
{
$excerptStructure = $this->structureManager->getStructure('excerpt');
$extension = $this->extensionManager->getExtension('', 'excerpt');
foreach ($excerptStructure->getProperties(true) as $property) {
$additionalFields[$locale][] = [
'extension' => $extension,
'target' => 'excerpt',
'property' => $property->getName(),
'name' => $property->getName(),
];
}
} | php | private function buildSelectorForExcerpt($locale, &$additionalFields)
{
$excerptStructure = $this->structureManager->getStructure('excerpt');
$extension = $this->extensionManager->getExtension('', 'excerpt');
foreach ($excerptStructure->getProperties(true) as $property) {
$additionalFields[$locale][] = [
'extension' => $extension,
'target' => 'excerpt',
'property' => $property->getName(),
'name' => $property->getName(),
];
}
} | [
"private",
"function",
"buildSelectorForExcerpt",
"(",
"$",
"locale",
",",
"&",
"$",
"additionalFields",
")",
"{",
"$",
"excerptStructure",
"=",
"$",
"this",
"->",
"structureManager",
"->",
"getStructure",
"(",
"'excerpt'",
")",
";",
"$",
"extension",
"=",
"$",
"this",
"->",
"extensionManager",
"->",
"getExtension",
"(",
"''",
",",
"'excerpt'",
")",
";",
"foreach",
"(",
"$",
"excerptStructure",
"->",
"getProperties",
"(",
"true",
")",
"as",
"$",
"property",
")",
"{",
"$",
"additionalFields",
"[",
"$",
"locale",
"]",
"[",
"]",
"=",
"[",
"'extension'",
"=>",
"$",
"extension",
",",
"'target'",
"=>",
"'excerpt'",
",",
"'property'",
"=>",
"$",
"property",
"->",
"getName",
"(",
")",
",",
"'name'",
"=>",
"$",
"property",
"->",
"getName",
"(",
")",
",",
"]",
";",
"}",
"}"
] | Returns a select statement for excerpt data. | [
"Returns",
"a",
"select",
"statement",
"for",
"excerpt",
"data",
"."
] | 6766a36cc2f0c807c59202bf7540a08c4ef31192 | https://github.com/sulu/sulu/blob/6766a36cc2f0c807c59202bf7540a08c4ef31192/src/Sulu/Component/Content/Query/ContentQueryBuilder.php#L256-L269 | train |
sulu/sulu | src/Sulu/Bundle/ContactBundle/Contact/AbstractContactManager.php | AbstractContactManager.unsetMain | public function unsetMain($arrayCollection)
{
if ($arrayCollection && !$arrayCollection->isEmpty()) {
return $arrayCollection->forAll(
function($index, $entry) {
if (true === $entry->getMain()) {
$entry->setMain(false);
return false;
}
return true;
}
);
}
} | php | public function unsetMain($arrayCollection)
{
if ($arrayCollection && !$arrayCollection->isEmpty()) {
return $arrayCollection->forAll(
function($index, $entry) {
if (true === $entry->getMain()) {
$entry->setMain(false);
return false;
}
return true;
}
);
}
} | [
"public",
"function",
"unsetMain",
"(",
"$",
"arrayCollection",
")",
"{",
"if",
"(",
"$",
"arrayCollection",
"&&",
"!",
"$",
"arrayCollection",
"->",
"isEmpty",
"(",
")",
")",
"{",
"return",
"$",
"arrayCollection",
"->",
"forAll",
"(",
"function",
"(",
"$",
"index",
",",
"$",
"entry",
")",
"{",
"if",
"(",
"true",
"===",
"$",
"entry",
"->",
"getMain",
"(",
")",
")",
"{",
"$",
"entry",
"->",
"setMain",
"(",
"false",
")",
";",
"return",
"false",
";",
"}",
"return",
"true",
";",
"}",
")",
";",
"}",
"}"
] | unsets main of all elements of an ArrayCollection | PersistanceCollection.
@param $arrayCollection
@return bool returns true if a element was unset | [
"unsets",
"main",
"of",
"all",
"elements",
"of",
"an",
"ArrayCollection",
"|",
"PersistanceCollection",
"."
] | 6766a36cc2f0c807c59202bf7540a08c4ef31192 | https://github.com/sulu/sulu/blob/6766a36cc2f0c807c59202bf7540a08c4ef31192/src/Sulu/Bundle/ContactBundle/Contact/AbstractContactManager.php#L114-L129 | train |
sulu/sulu | src/Sulu/Bundle/ContactBundle/Contact/AbstractContactManager.php | AbstractContactManager.setMainForCollection | public function setMainForCollection($arrayCollection)
{
if ($arrayCollection && !$arrayCollection->isEmpty() && !$this->hasMain($arrayCollection)) {
$arrayCollection->first()->setMain(true);
}
} | php | public function setMainForCollection($arrayCollection)
{
if ($arrayCollection && !$arrayCollection->isEmpty() && !$this->hasMain($arrayCollection)) {
$arrayCollection->first()->setMain(true);
}
} | [
"public",
"function",
"setMainForCollection",
"(",
"$",
"arrayCollection",
")",
"{",
"if",
"(",
"$",
"arrayCollection",
"&&",
"!",
"$",
"arrayCollection",
"->",
"isEmpty",
"(",
")",
"&&",
"!",
"$",
"this",
"->",
"hasMain",
"(",
"$",
"arrayCollection",
")",
")",
"{",
"$",
"arrayCollection",
"->",
"first",
"(",
")",
"->",
"setMain",
"(",
"true",
")",
";",
"}",
"}"
] | sets the first element to main, if none is set.
@param $arrayCollection | [
"sets",
"the",
"first",
"element",
"to",
"main",
"if",
"none",
"is",
"set",
"."
] | 6766a36cc2f0c807c59202bf7540a08c4ef31192 | https://github.com/sulu/sulu/blob/6766a36cc2f0c807c59202bf7540a08c4ef31192/src/Sulu/Bundle/ContactBundle/Contact/AbstractContactManager.php#L136-L141 | train |
sulu/sulu | src/Sulu/Bundle/ContactBundle/Contact/AbstractContactManager.php | AbstractContactManager.hasMain | private function hasMain($arrayCollection, &$mainEntity = null)
{
if ($arrayCollection && !$arrayCollection->isEmpty()) {
return $arrayCollection->exists(
function($index, $entity) {
$mainEntity = $entity;
return true === $entity->getMain();
}
);
}
return false;
} | php | private function hasMain($arrayCollection, &$mainEntity = null)
{
if ($arrayCollection && !$arrayCollection->isEmpty()) {
return $arrayCollection->exists(
function($index, $entity) {
$mainEntity = $entity;
return true === $entity->getMain();
}
);
}
return false;
} | [
"private",
"function",
"hasMain",
"(",
"$",
"arrayCollection",
",",
"&",
"$",
"mainEntity",
"=",
"null",
")",
"{",
"if",
"(",
"$",
"arrayCollection",
"&&",
"!",
"$",
"arrayCollection",
"->",
"isEmpty",
"(",
")",
")",
"{",
"return",
"$",
"arrayCollection",
"->",
"exists",
"(",
"function",
"(",
"$",
"index",
",",
"$",
"entity",
")",
"{",
"$",
"mainEntity",
"=",
"$",
"entity",
";",
"return",
"true",
"===",
"$",
"entity",
"->",
"getMain",
"(",
")",
";",
"}",
")",
";",
"}",
"return",
"false",
";",
"}"
] | checks if a collection for main attribute.
@param $arrayCollection
@param $mainEntity will be set, if found
@return mixed | [
"checks",
"if",
"a",
"collection",
"for",
"main",
"attribute",
"."
] | 6766a36cc2f0c807c59202bf7540a08c4ef31192 | https://github.com/sulu/sulu/blob/6766a36cc2f0c807c59202bf7540a08c4ef31192/src/Sulu/Bundle/ContactBundle/Contact/AbstractContactManager.php#L151-L164 | train |
sulu/sulu | src/Sulu/Bundle/ContactBundle/Contact/AbstractContactManager.php | AbstractContactManager.setMainEmail | public function setMainEmail($entity)
{
// set main to first entry or to null
if ($entity->getEmails()->isEmpty()) {
$entity->setMainEmail(null);
} else {
$entity->setMainEmail($entity->getEmails()->first()->getEmail());
}
} | php | public function setMainEmail($entity)
{
// set main to first entry or to null
if ($entity->getEmails()->isEmpty()) {
$entity->setMainEmail(null);
} else {
$entity->setMainEmail($entity->getEmails()->first()->getEmail());
}
} | [
"public",
"function",
"setMainEmail",
"(",
"$",
"entity",
")",
"{",
"// set main to first entry or to null",
"if",
"(",
"$",
"entity",
"->",
"getEmails",
"(",
")",
"->",
"isEmpty",
"(",
")",
")",
"{",
"$",
"entity",
"->",
"setMainEmail",
"(",
"null",
")",
";",
"}",
"else",
"{",
"$",
"entity",
"->",
"setMainEmail",
"(",
"$",
"entity",
"->",
"getEmails",
"(",
")",
"->",
"first",
"(",
")",
"->",
"getEmail",
"(",
")",
")",
";",
"}",
"}"
] | sets Entity's Main-Email.
@param Contact|AccountInterface $entity | [
"sets",
"Entity",
"s",
"Main",
"-",
"Email",
"."
] | 6766a36cc2f0c807c59202bf7540a08c4ef31192 | https://github.com/sulu/sulu/blob/6766a36cc2f0c807c59202bf7540a08c4ef31192/src/Sulu/Bundle/ContactBundle/Contact/AbstractContactManager.php#L171-L179 | train |
sulu/sulu | src/Sulu/Bundle/ContactBundle/Contact/AbstractContactManager.php | AbstractContactManager.setMainPhone | public function setMainPhone($entity)
{
// set main to first entry or to null
if ($entity->getPhones()->isEmpty()) {
$entity->setMainPhone(null);
} else {
$entity->setMainPhone($entity->getPhones()->first()->getPhone());
}
} | php | public function setMainPhone($entity)
{
// set main to first entry or to null
if ($entity->getPhones()->isEmpty()) {
$entity->setMainPhone(null);
} else {
$entity->setMainPhone($entity->getPhones()->first()->getPhone());
}
} | [
"public",
"function",
"setMainPhone",
"(",
"$",
"entity",
")",
"{",
"// set main to first entry or to null",
"if",
"(",
"$",
"entity",
"->",
"getPhones",
"(",
")",
"->",
"isEmpty",
"(",
")",
")",
"{",
"$",
"entity",
"->",
"setMainPhone",
"(",
"null",
")",
";",
"}",
"else",
"{",
"$",
"entity",
"->",
"setMainPhone",
"(",
"$",
"entity",
"->",
"getPhones",
"(",
")",
"->",
"first",
"(",
")",
"->",
"getPhone",
"(",
")",
")",
";",
"}",
"}"
] | sets Entity's Main-Phone.
@param Contact|AccountInterface $entity | [
"sets",
"Entity",
"s",
"Main",
"-",
"Phone",
"."
] | 6766a36cc2f0c807c59202bf7540a08c4ef31192 | https://github.com/sulu/sulu/blob/6766a36cc2f0c807c59202bf7540a08c4ef31192/src/Sulu/Bundle/ContactBundle/Contact/AbstractContactManager.php#L186-L194 | train |
sulu/sulu | src/Sulu/Bundle/ContactBundle/Contact/AbstractContactManager.php | AbstractContactManager.setMainFax | public function setMainFax($entity)
{
// set main to first entry or to null
if ($entity->getFaxes()->isEmpty()) {
$entity->setMainFax(null);
} else {
$entity->setMainFax($entity->getFaxes()->first()->getFax());
}
} | php | public function setMainFax($entity)
{
// set main to first entry or to null
if ($entity->getFaxes()->isEmpty()) {
$entity->setMainFax(null);
} else {
$entity->setMainFax($entity->getFaxes()->first()->getFax());
}
} | [
"public",
"function",
"setMainFax",
"(",
"$",
"entity",
")",
"{",
"// set main to first entry or to null",
"if",
"(",
"$",
"entity",
"->",
"getFaxes",
"(",
")",
"->",
"isEmpty",
"(",
")",
")",
"{",
"$",
"entity",
"->",
"setMainFax",
"(",
"null",
")",
";",
"}",
"else",
"{",
"$",
"entity",
"->",
"setMainFax",
"(",
"$",
"entity",
"->",
"getFaxes",
"(",
")",
"->",
"first",
"(",
")",
"->",
"getFax",
"(",
")",
")",
";",
"}",
"}"
] | sets Entity's Main-Fax.
@param Contact|AccountInterface $entity | [
"sets",
"Entity",
"s",
"Main",
"-",
"Fax",
"."
] | 6766a36cc2f0c807c59202bf7540a08c4ef31192 | https://github.com/sulu/sulu/blob/6766a36cc2f0c807c59202bf7540a08c4ef31192/src/Sulu/Bundle/ContactBundle/Contact/AbstractContactManager.php#L201-L209 | train |
sulu/sulu | src/Sulu/Bundle/ContactBundle/Contact/AbstractContactManager.php | AbstractContactManager.setMainUrl | public function setMainUrl($entity)
{
// set main to first entry or to null
if ($entity->getUrls()->isEmpty()) {
$entity->setMainUrl(null);
} else {
$entity->setMainUrl($entity->getUrls()->first()->getUrl());
}
} | php | public function setMainUrl($entity)
{
// set main to first entry or to null
if ($entity->getUrls()->isEmpty()) {
$entity->setMainUrl(null);
} else {
$entity->setMainUrl($entity->getUrls()->first()->getUrl());
}
} | [
"public",
"function",
"setMainUrl",
"(",
"$",
"entity",
")",
"{",
"// set main to first entry or to null",
"if",
"(",
"$",
"entity",
"->",
"getUrls",
"(",
")",
"->",
"isEmpty",
"(",
")",
")",
"{",
"$",
"entity",
"->",
"setMainUrl",
"(",
"null",
")",
";",
"}",
"else",
"{",
"$",
"entity",
"->",
"setMainUrl",
"(",
"$",
"entity",
"->",
"getUrls",
"(",
")",
"->",
"first",
"(",
")",
"->",
"getUrl",
"(",
")",
")",
";",
"}",
"}"
] | sets Entity's Main-Url.
@param Contact|AccountInterface $entity | [
"sets",
"Entity",
"s",
"Main",
"-",
"Url",
"."
] | 6766a36cc2f0c807c59202bf7540a08c4ef31192 | https://github.com/sulu/sulu/blob/6766a36cc2f0c807c59202bf7540a08c4ef31192/src/Sulu/Bundle/ContactBundle/Contact/AbstractContactManager.php#L216-L224 | train |
sulu/sulu | src/Sulu/Bundle/ContactBundle/Contact/AbstractContactManager.php | AbstractContactManager.getAccounContact | public function getAccounContact(AccountInterface $account, Contact $contact)
{
foreach ($contact->getAccountContacts() as $accountContact) {
/** @var AccountContact $accountContact */
if ($accountContact->getAccount() === $account) {
return $accountContact;
}
}
return;
} | php | public function getAccounContact(AccountInterface $account, Contact $contact)
{
foreach ($contact->getAccountContacts() as $accountContact) {
/** @var AccountContact $accountContact */
if ($accountContact->getAccount() === $account) {
return $accountContact;
}
}
return;
} | [
"public",
"function",
"getAccounContact",
"(",
"AccountInterface",
"$",
"account",
",",
"Contact",
"$",
"contact",
")",
"{",
"foreach",
"(",
"$",
"contact",
"->",
"getAccountContacts",
"(",
")",
"as",
"$",
"accountContact",
")",
"{",
"/** @var AccountContact $accountContact */",
"if",
"(",
"$",
"accountContact",
"->",
"getAccount",
"(",
")",
"===",
"$",
"account",
")",
"{",
"return",
"$",
"accountContact",
";",
"}",
"}",
"return",
";",
"}"
] | Returns AccountContact relation if exists.
@param AccountInterface $account
@param Contact $contact
@return null|AccountContact | [
"Returns",
"AccountContact",
"relation",
"if",
"exists",
"."
] | 6766a36cc2f0c807c59202bf7540a08c4ef31192 | https://github.com/sulu/sulu/blob/6766a36cc2f0c807c59202bf7540a08c4ef31192/src/Sulu/Bundle/ContactBundle/Contact/AbstractContactManager.php#L234-L244 | train |
sulu/sulu | src/Sulu/Bundle/ContactBundle/Contact/AbstractContactManager.php | AbstractContactManager.getMainAccountContact | public function getMainAccountContact($contact)
{
foreach ($contact->getAccountContacts() as $accountContact) {
/** @var AccountContact $accountContact */
if ($accountContact->getMain()) {
return $accountContact;
}
}
return false;
} | php | public function getMainAccountContact($contact)
{
foreach ($contact->getAccountContacts() as $accountContact) {
/** @var AccountContact $accountContact */
if ($accountContact->getMain()) {
return $accountContact;
}
}
return false;
} | [
"public",
"function",
"getMainAccountContact",
"(",
"$",
"contact",
")",
"{",
"foreach",
"(",
"$",
"contact",
"->",
"getAccountContacts",
"(",
")",
"as",
"$",
"accountContact",
")",
"{",
"/** @var AccountContact $accountContact */",
"if",
"(",
"$",
"accountContact",
"->",
"getMain",
"(",
")",
")",
"{",
"return",
"$",
"accountContact",
";",
"}",
"}",
"return",
"false",
";",
"}"
] | returns the main account-contact relation.
@param Contact|AccountInterface $contact
@return AccountContact|bool | [
"returns",
"the",
"main",
"account",
"-",
"contact",
"relation",
"."
] | 6766a36cc2f0c807c59202bf7540a08c4ef31192 | https://github.com/sulu/sulu/blob/6766a36cc2f0c807c59202bf7540a08c4ef31192/src/Sulu/Bundle/ContactBundle/Contact/AbstractContactManager.php#L253-L263 | train |
sulu/sulu | src/Sulu/Bundle/ContactBundle/Contact/AbstractContactManager.php | AbstractContactManager.createMainAccountContact | public function createMainAccountContact(Contact $contact, AccountInterface $account, $position = null)
{
$accountContact = new AccountContact();
$accountContact->setAccount($account);
$accountContact->setContact($contact);
$accountContact->setMain(true);
$this->em->persist($accountContact);
$contact->addAccountContact($accountContact);
$accountContact->setPosition($position);
return $accountContact;
} | php | public function createMainAccountContact(Contact $contact, AccountInterface $account, $position = null)
{
$accountContact = new AccountContact();
$accountContact->setAccount($account);
$accountContact->setContact($contact);
$accountContact->setMain(true);
$this->em->persist($accountContact);
$contact->addAccountContact($accountContact);
$accountContact->setPosition($position);
return $accountContact;
} | [
"public",
"function",
"createMainAccountContact",
"(",
"Contact",
"$",
"contact",
",",
"AccountInterface",
"$",
"account",
",",
"$",
"position",
"=",
"null",
")",
"{",
"$",
"accountContact",
"=",
"new",
"AccountContact",
"(",
")",
";",
"$",
"accountContact",
"->",
"setAccount",
"(",
"$",
"account",
")",
";",
"$",
"accountContact",
"->",
"setContact",
"(",
"$",
"contact",
")",
";",
"$",
"accountContact",
"->",
"setMain",
"(",
"true",
")",
";",
"$",
"this",
"->",
"em",
"->",
"persist",
"(",
"$",
"accountContact",
")",
";",
"$",
"contact",
"->",
"addAccountContact",
"(",
"$",
"accountContact",
")",
";",
"$",
"accountContact",
"->",
"setPosition",
"(",
"$",
"position",
")",
";",
"return",
"$",
"accountContact",
";",
"}"
] | creates a new main Account Contacts relation.
@param Contact $contact
@param AccountInterface $account
@param $position
@return AccountContact | [
"creates",
"a",
"new",
"main",
"Account",
"Contacts",
"relation",
"."
] | 6766a36cc2f0c807c59202bf7540a08c4ef31192 | https://github.com/sulu/sulu/blob/6766a36cc2f0c807c59202bf7540a08c4ef31192/src/Sulu/Bundle/ContactBundle/Contact/AbstractContactManager.php#L274-L285 | train |
sulu/sulu | src/Sulu/Bundle/ContactBundle/Contact/AbstractContactManager.php | AbstractContactManager.deleteAllRelations | public function deleteAllRelations($entity)
{
$this->deleteNotes($entity);
$this->deleteAddresses($entity);
$this->deleteEmails($entity);
$this->deleteFaxes($entity);
$this->deleteSocialMediaProfiles($entity);
$this->deletePhones($entity);
$this->deleteUrls($entity);
} | php | public function deleteAllRelations($entity)
{
$this->deleteNotes($entity);
$this->deleteAddresses($entity);
$this->deleteEmails($entity);
$this->deleteFaxes($entity);
$this->deleteSocialMediaProfiles($entity);
$this->deletePhones($entity);
$this->deleteUrls($entity);
} | [
"public",
"function",
"deleteAllRelations",
"(",
"$",
"entity",
")",
"{",
"$",
"this",
"->",
"deleteNotes",
"(",
"$",
"entity",
")",
";",
"$",
"this",
"->",
"deleteAddresses",
"(",
"$",
"entity",
")",
";",
"$",
"this",
"->",
"deleteEmails",
"(",
"$",
"entity",
")",
";",
"$",
"this",
"->",
"deleteFaxes",
"(",
"$",
"entity",
")",
";",
"$",
"this",
"->",
"deleteSocialMediaProfiles",
"(",
"$",
"entity",
")",
";",
"$",
"this",
"->",
"deletePhones",
"(",
"$",
"entity",
")",
";",
"$",
"this",
"->",
"deleteUrls",
"(",
"$",
"entity",
")",
";",
"}"
] | clears all relational data from entity and deletes it.
@param ContactInterface $entity | [
"clears",
"all",
"relational",
"data",
"from",
"entity",
"and",
"deletes",
"it",
"."
] | 6766a36cc2f0c807c59202bf7540a08c4ef31192 | https://github.com/sulu/sulu/blob/6766a36cc2f0c807c59202bf7540a08c4ef31192/src/Sulu/Bundle/ContactBundle/Contact/AbstractContactManager.php#L364-L373 | train |
sulu/sulu | src/Sulu/Bundle/ContactBundle/Contact/AbstractContactManager.php | AbstractContactManager.deleteAddresses | public function deleteAddresses($entity)
{
// clear addresses
if ($entity->getAccountAddresses()) {
foreach ($entity->getAccountAddresses() as $accountAddresses) {
$this->em->remove($accountAddresses->getAddress());
$this->em->remove($accountAddresses);
}
}
} | php | public function deleteAddresses($entity)
{
// clear addresses
if ($entity->getAccountAddresses()) {
foreach ($entity->getAccountAddresses() as $accountAddresses) {
$this->em->remove($accountAddresses->getAddress());
$this->em->remove($accountAddresses);
}
}
} | [
"public",
"function",
"deleteAddresses",
"(",
"$",
"entity",
")",
"{",
"// clear addresses",
"if",
"(",
"$",
"entity",
"->",
"getAccountAddresses",
"(",
")",
")",
"{",
"foreach",
"(",
"$",
"entity",
"->",
"getAccountAddresses",
"(",
")",
"as",
"$",
"accountAddresses",
")",
"{",
"$",
"this",
"->",
"em",
"->",
"remove",
"(",
"$",
"accountAddresses",
"->",
"getAddress",
"(",
")",
")",
";",
"$",
"this",
"->",
"em",
"->",
"remove",
"(",
"$",
"accountAddresses",
")",
";",
"}",
"}",
"}"
] | deletes all addresses that are assigned to entity.
@param $entity | [
"deletes",
"all",
"addresses",
"that",
"are",
"assigned",
"to",
"entity",
"."
] | 6766a36cc2f0c807c59202bf7540a08c4ef31192 | https://github.com/sulu/sulu/blob/6766a36cc2f0c807c59202bf7540a08c4ef31192/src/Sulu/Bundle/ContactBundle/Contact/AbstractContactManager.php#L440-L449 | train |
sulu/sulu | src/Sulu/Bundle/ContactBundle/Contact/AbstractContactManager.php | AbstractContactManager.getDeliveryAddress | public function getDeliveryAddress($entity, $force = false)
{
/* @var Address $address */
$conditionCallback = function($address) {
return $address->getDeliveryAddress();
};
return $this->getAddressByCondition($entity, $conditionCallback, $force);
} | php | public function getDeliveryAddress($entity, $force = false)
{
/* @var Address $address */
$conditionCallback = function($address) {
return $address->getDeliveryAddress();
};
return $this->getAddressByCondition($entity, $conditionCallback, $force);
} | [
"public",
"function",
"getDeliveryAddress",
"(",
"$",
"entity",
",",
"$",
"force",
"=",
"false",
")",
"{",
"/* @var Address $address */",
"$",
"conditionCallback",
"=",
"function",
"(",
"$",
"address",
")",
"{",
"return",
"$",
"address",
"->",
"getDeliveryAddress",
"(",
")",
";",
"}",
";",
"return",
"$",
"this",
"->",
"getAddressByCondition",
"(",
"$",
"entity",
",",
"$",
"conditionCallback",
",",
"$",
"force",
")",
";",
"}"
] | Returns the delivery address.
@param AccountInterface|Contact $entity
@param bool $force Forces function to return an address if any address is defined
if no delivery address is defined it will first return the main address then any
@return mixed | [
"Returns",
"the",
"delivery",
"address",
"."
] | 6766a36cc2f0c807c59202bf7540a08c4ef31192 | https://github.com/sulu/sulu/blob/6766a36cc2f0c807c59202bf7540a08c4ef31192/src/Sulu/Bundle/ContactBundle/Contact/AbstractContactManager.php#L501-L509 | train |
sulu/sulu | src/Sulu/Bundle/ContactBundle/Contact/AbstractContactManager.php | AbstractContactManager.contactIsEmployeeOfAccount | public function contactIsEmployeeOfAccount($contact, $account)
{
if ($contact->getAccountContacts() && !$contact->getAccountContacts()->isEmpty()) {
foreach ($contact->getAccountContacts() as $accountContact) {
if ($accountContact->getAccount()->getId() === $account->getId()) {
return true;
}
}
}
return false;
} | php | public function contactIsEmployeeOfAccount($contact, $account)
{
if ($contact->getAccountContacts() && !$contact->getAccountContacts()->isEmpty()) {
foreach ($contact->getAccountContacts() as $accountContact) {
if ($accountContact->getAccount()->getId() === $account->getId()) {
return true;
}
}
}
return false;
} | [
"public",
"function",
"contactIsEmployeeOfAccount",
"(",
"$",
"contact",
",",
"$",
"account",
")",
"{",
"if",
"(",
"$",
"contact",
"->",
"getAccountContacts",
"(",
")",
"&&",
"!",
"$",
"contact",
"->",
"getAccountContacts",
"(",
")",
"->",
"isEmpty",
"(",
")",
")",
"{",
"foreach",
"(",
"$",
"contact",
"->",
"getAccountContacts",
"(",
")",
"as",
"$",
"accountContact",
")",
"{",
"if",
"(",
"$",
"accountContact",
"->",
"getAccount",
"(",
")",
"->",
"getId",
"(",
")",
"===",
"$",
"account",
"->",
"getId",
"(",
")",
")",
"{",
"return",
"true",
";",
"}",
"}",
"}",
"return",
"false",
";",
"}"
] | checks if an account is employee of a company.
@param $contact
@param $account
@return bool | [
"checks",
"if",
"an",
"account",
"is",
"employee",
"of",
"a",
"company",
"."
] | 6766a36cc2f0c807c59202bf7540a08c4ef31192 | https://github.com/sulu/sulu/blob/6766a36cc2f0c807c59202bf7540a08c4ef31192/src/Sulu/Bundle/ContactBundle/Contact/AbstractContactManager.php#L519-L530 | train |
sulu/sulu | src/Sulu/Bundle/ContactBundle/Contact/AbstractContactManager.php | AbstractContactManager.getAddresses | private function getAddresses($entity)
{
if ($entity instanceof AccountInterface) {
return $entity->getAccountAddresses();
} elseif ($entity instanceof Contact) {
return $entity->getContactAddresses();
}
return;
} | php | private function getAddresses($entity)
{
if ($entity instanceof AccountInterface) {
return $entity->getAccountAddresses();
} elseif ($entity instanceof Contact) {
return $entity->getContactAddresses();
}
return;
} | [
"private",
"function",
"getAddresses",
"(",
"$",
"entity",
")",
"{",
"if",
"(",
"$",
"entity",
"instanceof",
"AccountInterface",
")",
"{",
"return",
"$",
"entity",
"->",
"getAccountAddresses",
"(",
")",
";",
"}",
"elseif",
"(",
"$",
"entity",
"instanceof",
"Contact",
")",
"{",
"return",
"$",
"entity",
"->",
"getContactAddresses",
"(",
")",
";",
"}",
"return",
";",
"}"
] | returns addresses from account or contact.
@param AccountInterface|Contact $entity
@return \Doctrine\Common\Collections\Collection|null | [
"returns",
"addresses",
"from",
"account",
"or",
"contact",
"."
] | 6766a36cc2f0c807c59202bf7540a08c4ef31192 | https://github.com/sulu/sulu/blob/6766a36cc2f0c807c59202bf7540a08c4ef31192/src/Sulu/Bundle/ContactBundle/Contact/AbstractContactManager.php#L539-L548 | train |
sulu/sulu | src/Sulu/Bundle/ContactBundle/Contact/AbstractContactManager.php | AbstractContactManager.getAddressByCondition | public function getAddressByCondition($entity, callable $conditionCallback, $force = false)
{
$addresses = $this->getAddresses($entity);
$address = null;
$main = null;
if (!is_null($addresses)) {
/* @var AccountAddress $accountAddress */
foreach ($addresses as $address) {
if ($conditionCallback($address->getAddress())) {
return $address->getAddress();
}
if ($address->getMain()) {
$main = $address->getAddress();
}
}
if ($force) {
// return main or first address
if (null === $main && $addresses->first()) {
return $addresses->first()->getAddress();
}
}
}
return $main;
} | php | public function getAddressByCondition($entity, callable $conditionCallback, $force = false)
{
$addresses = $this->getAddresses($entity);
$address = null;
$main = null;
if (!is_null($addresses)) {
/* @var AccountAddress $accountAddress */
foreach ($addresses as $address) {
if ($conditionCallback($address->getAddress())) {
return $address->getAddress();
}
if ($address->getMain()) {
$main = $address->getAddress();
}
}
if ($force) {
// return main or first address
if (null === $main && $addresses->first()) {
return $addresses->first()->getAddress();
}
}
}
return $main;
} | [
"public",
"function",
"getAddressByCondition",
"(",
"$",
"entity",
",",
"callable",
"$",
"conditionCallback",
",",
"$",
"force",
"=",
"false",
")",
"{",
"$",
"addresses",
"=",
"$",
"this",
"->",
"getAddresses",
"(",
"$",
"entity",
")",
";",
"$",
"address",
"=",
"null",
";",
"$",
"main",
"=",
"null",
";",
"if",
"(",
"!",
"is_null",
"(",
"$",
"addresses",
")",
")",
"{",
"/* @var AccountAddress $accountAddress */",
"foreach",
"(",
"$",
"addresses",
"as",
"$",
"address",
")",
"{",
"if",
"(",
"$",
"conditionCallback",
"(",
"$",
"address",
"->",
"getAddress",
"(",
")",
")",
")",
"{",
"return",
"$",
"address",
"->",
"getAddress",
"(",
")",
";",
"}",
"if",
"(",
"$",
"address",
"->",
"getMain",
"(",
")",
")",
"{",
"$",
"main",
"=",
"$",
"address",
"->",
"getAddress",
"(",
")",
";",
"}",
"}",
"if",
"(",
"$",
"force",
")",
"{",
"// return main or first address",
"if",
"(",
"null",
"===",
"$",
"main",
"&&",
"$",
"addresses",
"->",
"first",
"(",
")",
")",
"{",
"return",
"$",
"addresses",
"->",
"first",
"(",
")",
"->",
"getAddress",
"(",
")",
";",
"}",
"}",
"}",
"return",
"$",
"main",
";",
"}"
] | Returns an address by callback-condition.
@param AccountInterface|Contact $entity
@param callable $conditionCallback
@param bool $force Forces function to return an address if any address is defined
if no delivery address is defined it will first return the main address then any
@return mixed | [
"Returns",
"an",
"address",
"by",
"callback",
"-",
"condition",
"."
] | 6766a36cc2f0c807c59202bf7540a08c4ef31192 | https://github.com/sulu/sulu/blob/6766a36cc2f0c807c59202bf7540a08c4ef31192/src/Sulu/Bundle/ContactBundle/Contact/AbstractContactManager.php#L560-L585 | train |
sulu/sulu | src/Sulu/Bundle/ContactBundle/Contact/AbstractContactManager.php | AbstractContactManager.addNewContactRelations | public function addNewContactRelations($contact, $data)
{
// urls
$urls = $this->getProperty($data, 'urls');
if (!empty($urls)) {
foreach ($urls as $urlData) {
$this->addUrl($contact, $urlData);
}
$this->setMainUrl($contact);
}
//faxes
$faxes = $this->getProperty($data, 'faxes');
if (!empty($faxes)) {
foreach ($faxes as $faxData) {
$this->addFax($contact, $faxData);
}
$this->setMainFax($contact);
}
// Social media profiles.
$socialMediaProfiles = $this->getProperty($data, 'socialMediaProfiles');
if (!empty($socialMediaProfiles)) {
foreach ($socialMediaProfiles as $socialMediaProfileData) {
$this->addSocialMediaProfile($contact, $socialMediaProfileData);
}
}
// emails
$emails = $this->getProperty($data, 'emails');
if (!empty($emails)) {
foreach ($emails as $emailData) {
$this->addEmail($contact, $emailData);
}
$this->setMainEmail($contact);
}
// phones
$phones = $this->getProperty($data, 'phones');
if (!empty($phones)) {
foreach ($phones as $phoneData) {
$this->addPhone($contact, $phoneData);
}
$this->setMainPhone($contact);
}
// addresses
$addresses = $this->getProperty($data, 'addresses');
if (!empty($addresses)) {
foreach ($addresses as $addressData) {
$address = $this->createAddress($addressData, $isMain);
$this->addAddress($contact, $address, $isMain);
}
}
// set main address (if it was not set yet)
$this->setMainForCollection($this->getAddressRelations($contact));
// notes
$notes = $this->getProperty($data, 'notes');
if (!empty($notes)) {
foreach ($notes as $noteData) {
$this->addNote($contact, $noteData);
}
}
// handle tags
$tags = $this->getProperty($data, 'tags');
if (!empty($tags)) {
foreach ($tags as $tag) {
$this->addTag($contact, $tag);
}
}
// process details
if (null !== $this->getProperty($data, 'bankAccounts')) {
$this->processBankAccounts($contact, $this->getProperty($data, 'bankAccounts', []));
}
} | php | public function addNewContactRelations($contact, $data)
{
// urls
$urls = $this->getProperty($data, 'urls');
if (!empty($urls)) {
foreach ($urls as $urlData) {
$this->addUrl($contact, $urlData);
}
$this->setMainUrl($contact);
}
//faxes
$faxes = $this->getProperty($data, 'faxes');
if (!empty($faxes)) {
foreach ($faxes as $faxData) {
$this->addFax($contact, $faxData);
}
$this->setMainFax($contact);
}
// Social media profiles.
$socialMediaProfiles = $this->getProperty($data, 'socialMediaProfiles');
if (!empty($socialMediaProfiles)) {
foreach ($socialMediaProfiles as $socialMediaProfileData) {
$this->addSocialMediaProfile($contact, $socialMediaProfileData);
}
}
// emails
$emails = $this->getProperty($data, 'emails');
if (!empty($emails)) {
foreach ($emails as $emailData) {
$this->addEmail($contact, $emailData);
}
$this->setMainEmail($contact);
}
// phones
$phones = $this->getProperty($data, 'phones');
if (!empty($phones)) {
foreach ($phones as $phoneData) {
$this->addPhone($contact, $phoneData);
}
$this->setMainPhone($contact);
}
// addresses
$addresses = $this->getProperty($data, 'addresses');
if (!empty($addresses)) {
foreach ($addresses as $addressData) {
$address = $this->createAddress($addressData, $isMain);
$this->addAddress($contact, $address, $isMain);
}
}
// set main address (if it was not set yet)
$this->setMainForCollection($this->getAddressRelations($contact));
// notes
$notes = $this->getProperty($data, 'notes');
if (!empty($notes)) {
foreach ($notes as $noteData) {
$this->addNote($contact, $noteData);
}
}
// handle tags
$tags = $this->getProperty($data, 'tags');
if (!empty($tags)) {
foreach ($tags as $tag) {
$this->addTag($contact, $tag);
}
}
// process details
if (null !== $this->getProperty($data, 'bankAccounts')) {
$this->processBankAccounts($contact, $this->getProperty($data, 'bankAccounts', []));
}
} | [
"public",
"function",
"addNewContactRelations",
"(",
"$",
"contact",
",",
"$",
"data",
")",
"{",
"// urls",
"$",
"urls",
"=",
"$",
"this",
"->",
"getProperty",
"(",
"$",
"data",
",",
"'urls'",
")",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"urls",
")",
")",
"{",
"foreach",
"(",
"$",
"urls",
"as",
"$",
"urlData",
")",
"{",
"$",
"this",
"->",
"addUrl",
"(",
"$",
"contact",
",",
"$",
"urlData",
")",
";",
"}",
"$",
"this",
"->",
"setMainUrl",
"(",
"$",
"contact",
")",
";",
"}",
"//faxes",
"$",
"faxes",
"=",
"$",
"this",
"->",
"getProperty",
"(",
"$",
"data",
",",
"'faxes'",
")",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"faxes",
")",
")",
"{",
"foreach",
"(",
"$",
"faxes",
"as",
"$",
"faxData",
")",
"{",
"$",
"this",
"->",
"addFax",
"(",
"$",
"contact",
",",
"$",
"faxData",
")",
";",
"}",
"$",
"this",
"->",
"setMainFax",
"(",
"$",
"contact",
")",
";",
"}",
"// Social media profiles.",
"$",
"socialMediaProfiles",
"=",
"$",
"this",
"->",
"getProperty",
"(",
"$",
"data",
",",
"'socialMediaProfiles'",
")",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"socialMediaProfiles",
")",
")",
"{",
"foreach",
"(",
"$",
"socialMediaProfiles",
"as",
"$",
"socialMediaProfileData",
")",
"{",
"$",
"this",
"->",
"addSocialMediaProfile",
"(",
"$",
"contact",
",",
"$",
"socialMediaProfileData",
")",
";",
"}",
"}",
"// emails",
"$",
"emails",
"=",
"$",
"this",
"->",
"getProperty",
"(",
"$",
"data",
",",
"'emails'",
")",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"emails",
")",
")",
"{",
"foreach",
"(",
"$",
"emails",
"as",
"$",
"emailData",
")",
"{",
"$",
"this",
"->",
"addEmail",
"(",
"$",
"contact",
",",
"$",
"emailData",
")",
";",
"}",
"$",
"this",
"->",
"setMainEmail",
"(",
"$",
"contact",
")",
";",
"}",
"// phones",
"$",
"phones",
"=",
"$",
"this",
"->",
"getProperty",
"(",
"$",
"data",
",",
"'phones'",
")",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"phones",
")",
")",
"{",
"foreach",
"(",
"$",
"phones",
"as",
"$",
"phoneData",
")",
"{",
"$",
"this",
"->",
"addPhone",
"(",
"$",
"contact",
",",
"$",
"phoneData",
")",
";",
"}",
"$",
"this",
"->",
"setMainPhone",
"(",
"$",
"contact",
")",
";",
"}",
"// addresses",
"$",
"addresses",
"=",
"$",
"this",
"->",
"getProperty",
"(",
"$",
"data",
",",
"'addresses'",
")",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"addresses",
")",
")",
"{",
"foreach",
"(",
"$",
"addresses",
"as",
"$",
"addressData",
")",
"{",
"$",
"address",
"=",
"$",
"this",
"->",
"createAddress",
"(",
"$",
"addressData",
",",
"$",
"isMain",
")",
";",
"$",
"this",
"->",
"addAddress",
"(",
"$",
"contact",
",",
"$",
"address",
",",
"$",
"isMain",
")",
";",
"}",
"}",
"// set main address (if it was not set yet)",
"$",
"this",
"->",
"setMainForCollection",
"(",
"$",
"this",
"->",
"getAddressRelations",
"(",
"$",
"contact",
")",
")",
";",
"// notes",
"$",
"notes",
"=",
"$",
"this",
"->",
"getProperty",
"(",
"$",
"data",
",",
"'notes'",
")",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"notes",
")",
")",
"{",
"foreach",
"(",
"$",
"notes",
"as",
"$",
"noteData",
")",
"{",
"$",
"this",
"->",
"addNote",
"(",
"$",
"contact",
",",
"$",
"noteData",
")",
";",
"}",
"}",
"// handle tags",
"$",
"tags",
"=",
"$",
"this",
"->",
"getProperty",
"(",
"$",
"data",
",",
"'tags'",
")",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"tags",
")",
")",
"{",
"foreach",
"(",
"$",
"tags",
"as",
"$",
"tag",
")",
"{",
"$",
"this",
"->",
"addTag",
"(",
"$",
"contact",
",",
"$",
"tag",
")",
";",
"}",
"}",
"// process details",
"if",
"(",
"null",
"!==",
"$",
"this",
"->",
"getProperty",
"(",
"$",
"data",
",",
"'bankAccounts'",
")",
")",
"{",
"$",
"this",
"->",
"processBankAccounts",
"(",
"$",
"contact",
",",
"$",
"this",
"->",
"getProperty",
"(",
"$",
"data",
",",
"'bankAccounts'",
",",
"[",
"]",
")",
")",
";",
"}",
"}"
] | adds new relations.
@param Contact $contact
@param array $data | [
"adds",
"new",
"relations",
"."
] | 6766a36cc2f0c807c59202bf7540a08c4ef31192 | https://github.com/sulu/sulu/blob/6766a36cc2f0c807c59202bf7540a08c4ef31192/src/Sulu/Bundle/ContactBundle/Contact/AbstractContactManager.php#L593-L670 | train |
sulu/sulu | src/Sulu/Bundle/ContactBundle/Contact/AbstractContactManager.php | AbstractContactManager.processEmails | public function processEmails($contact, $emails)
{
$get = function($email) {
/* @var Email $email */
return $email->getId();
};
$delete = function($email) use ($contact) {
return $contact->removeEmail($email);
};
$update = function($email, $matchedEntry) {
return $this->updateEmail($email, $matchedEntry);
};
$add = function($email) use ($contact) {
return $this->addEmail($contact, $email);
};
$entities = $contact->getEmails();
$result = $this->processSubEntities(
$entities,
$emails,
$get,
$add,
$update,
$delete
);
$this->resetIndexOfSubentites($entities);
// check main
$this->setMainEmail($contact);
return $result;
} | php | public function processEmails($contact, $emails)
{
$get = function($email) {
/* @var Email $email */
return $email->getId();
};
$delete = function($email) use ($contact) {
return $contact->removeEmail($email);
};
$update = function($email, $matchedEntry) {
return $this->updateEmail($email, $matchedEntry);
};
$add = function($email) use ($contact) {
return $this->addEmail($contact, $email);
};
$entities = $contact->getEmails();
$result = $this->processSubEntities(
$entities,
$emails,
$get,
$add,
$update,
$delete
);
$this->resetIndexOfSubentites($entities);
// check main
$this->setMainEmail($contact);
return $result;
} | [
"public",
"function",
"processEmails",
"(",
"$",
"contact",
",",
"$",
"emails",
")",
"{",
"$",
"get",
"=",
"function",
"(",
"$",
"email",
")",
"{",
"/* @var Email $email */",
"return",
"$",
"email",
"->",
"getId",
"(",
")",
";",
"}",
";",
"$",
"delete",
"=",
"function",
"(",
"$",
"email",
")",
"use",
"(",
"$",
"contact",
")",
"{",
"return",
"$",
"contact",
"->",
"removeEmail",
"(",
"$",
"email",
")",
";",
"}",
";",
"$",
"update",
"=",
"function",
"(",
"$",
"email",
",",
"$",
"matchedEntry",
")",
"{",
"return",
"$",
"this",
"->",
"updateEmail",
"(",
"$",
"email",
",",
"$",
"matchedEntry",
")",
";",
"}",
";",
"$",
"add",
"=",
"function",
"(",
"$",
"email",
")",
"use",
"(",
"$",
"contact",
")",
"{",
"return",
"$",
"this",
"->",
"addEmail",
"(",
"$",
"contact",
",",
"$",
"email",
")",
";",
"}",
";",
"$",
"entities",
"=",
"$",
"contact",
"->",
"getEmails",
"(",
")",
";",
"$",
"result",
"=",
"$",
"this",
"->",
"processSubEntities",
"(",
"$",
"entities",
",",
"$",
"emails",
",",
"$",
"get",
",",
"$",
"add",
",",
"$",
"update",
",",
"$",
"delete",
")",
";",
"$",
"this",
"->",
"resetIndexOfSubentites",
"(",
"$",
"entities",
")",
";",
"// check main",
"$",
"this",
"->",
"setMainEmail",
"(",
"$",
"contact",
")",
";",
"return",
"$",
"result",
";",
"}"
] | Process all emails from request.
@param $contact The contact on which is worked
@param $emails
@return bool True if the processing was successful, otherwise false | [
"Process",
"all",
"emails",
"from",
"request",
"."
] | 6766a36cc2f0c807c59202bf7540a08c4ef31192 | https://github.com/sulu/sulu/blob/6766a36cc2f0c807c59202bf7540a08c4ef31192/src/Sulu/Bundle/ContactBundle/Contact/AbstractContactManager.php#L680-L717 | train |
sulu/sulu | src/Sulu/Bundle/ContactBundle/Contact/AbstractContactManager.php | AbstractContactManager.addEmail | protected function addEmail($contact, $emailData)
{
$success = true;
$emailType = $this->em
->getRepository(self::$emailTypeEntityName)
->find($emailData['emailType']['id']);
if (isset($emailData['id'])) {
throw new EntityIdAlreadySetException(self::$emailEntityName, $emailData['id']);
} elseif (!$emailType) {
throw new EntityNotFoundException(self::$emailTypeEntityName, $emailData['emailType']['id']);
} else {
$email = new Email();
$email->setEmail($emailData['email']);
$email->setEmailType($emailType);
$this->em->persist($email);
$contact->addEmail($email);
}
return $success;
} | php | protected function addEmail($contact, $emailData)
{
$success = true;
$emailType = $this->em
->getRepository(self::$emailTypeEntityName)
->find($emailData['emailType']['id']);
if (isset($emailData['id'])) {
throw new EntityIdAlreadySetException(self::$emailEntityName, $emailData['id']);
} elseif (!$emailType) {
throw new EntityNotFoundException(self::$emailTypeEntityName, $emailData['emailType']['id']);
} else {
$email = new Email();
$email->setEmail($emailData['email']);
$email->setEmailType($emailType);
$this->em->persist($email);
$contact->addEmail($email);
}
return $success;
} | [
"protected",
"function",
"addEmail",
"(",
"$",
"contact",
",",
"$",
"emailData",
")",
"{",
"$",
"success",
"=",
"true",
";",
"$",
"emailType",
"=",
"$",
"this",
"->",
"em",
"->",
"getRepository",
"(",
"self",
"::",
"$",
"emailTypeEntityName",
")",
"->",
"find",
"(",
"$",
"emailData",
"[",
"'emailType'",
"]",
"[",
"'id'",
"]",
")",
";",
"if",
"(",
"isset",
"(",
"$",
"emailData",
"[",
"'id'",
"]",
")",
")",
"{",
"throw",
"new",
"EntityIdAlreadySetException",
"(",
"self",
"::",
"$",
"emailEntityName",
",",
"$",
"emailData",
"[",
"'id'",
"]",
")",
";",
"}",
"elseif",
"(",
"!",
"$",
"emailType",
")",
"{",
"throw",
"new",
"EntityNotFoundException",
"(",
"self",
"::",
"$",
"emailTypeEntityName",
",",
"$",
"emailData",
"[",
"'emailType'",
"]",
"[",
"'id'",
"]",
")",
";",
"}",
"else",
"{",
"$",
"email",
"=",
"new",
"Email",
"(",
")",
";",
"$",
"email",
"->",
"setEmail",
"(",
"$",
"emailData",
"[",
"'email'",
"]",
")",
";",
"$",
"email",
"->",
"setEmailType",
"(",
"$",
"emailType",
")",
";",
"$",
"this",
"->",
"em",
"->",
"persist",
"(",
"$",
"email",
")",
";",
"$",
"contact",
"->",
"addEmail",
"(",
"$",
"email",
")",
";",
"}",
"return",
"$",
"success",
";",
"}"
] | Adds a new email to the given contact and persist it with the given object manager.
@param Contact $contact
@param array $emailData
@return bool
@throws EntityNotFoundException
@throws EntityIdAlreadySetException | [
"Adds",
"a",
"new",
"email",
"to",
"the",
"given",
"contact",
"and",
"persist",
"it",
"with",
"the",
"given",
"object",
"manager",
"."
] | 6766a36cc2f0c807c59202bf7540a08c4ef31192 | https://github.com/sulu/sulu/blob/6766a36cc2f0c807c59202bf7540a08c4ef31192/src/Sulu/Bundle/ContactBundle/Contact/AbstractContactManager.php#L730-L751 | train |
sulu/sulu | src/Sulu/Bundle/ContactBundle/Contact/AbstractContactManager.php | AbstractContactManager.updateEmail | protected function updateEmail(Email $email, $entry)
{
$success = true;
$emailType = $this->em
->getRepository(self::$emailTypeEntityName)
->find($entry['emailType']['id']);
if (!$emailType) {
throw new EntityNotFoundException(self::$emailTypeEntityName, $entry['emailType']['id']);
} else {
$email->setEmail($entry['email']);
$email->setEmailType($emailType);
}
return $success;
} | php | protected function updateEmail(Email $email, $entry)
{
$success = true;
$emailType = $this->em
->getRepository(self::$emailTypeEntityName)
->find($entry['emailType']['id']);
if (!$emailType) {
throw new EntityNotFoundException(self::$emailTypeEntityName, $entry['emailType']['id']);
} else {
$email->setEmail($entry['email']);
$email->setEmailType($emailType);
}
return $success;
} | [
"protected",
"function",
"updateEmail",
"(",
"Email",
"$",
"email",
",",
"$",
"entry",
")",
"{",
"$",
"success",
"=",
"true",
";",
"$",
"emailType",
"=",
"$",
"this",
"->",
"em",
"->",
"getRepository",
"(",
"self",
"::",
"$",
"emailTypeEntityName",
")",
"->",
"find",
"(",
"$",
"entry",
"[",
"'emailType'",
"]",
"[",
"'id'",
"]",
")",
";",
"if",
"(",
"!",
"$",
"emailType",
")",
"{",
"throw",
"new",
"EntityNotFoundException",
"(",
"self",
"::",
"$",
"emailTypeEntityName",
",",
"$",
"entry",
"[",
"'emailType'",
"]",
"[",
"'id'",
"]",
")",
";",
"}",
"else",
"{",
"$",
"email",
"->",
"setEmail",
"(",
"$",
"entry",
"[",
"'email'",
"]",
")",
";",
"$",
"email",
"->",
"setEmailType",
"(",
"$",
"emailType",
")",
";",
"}",
"return",
"$",
"success",
";",
"}"
] | Updates the given email address.
@param Email $email The email object to update
@param array $entry The entry with the new data
@return bool True if successful, otherwise false
@throws EntityNotFoundException | [
"Updates",
"the",
"given",
"email",
"address",
"."
] | 6766a36cc2f0c807c59202bf7540a08c4ef31192 | https://github.com/sulu/sulu/blob/6766a36cc2f0c807c59202bf7540a08c4ef31192/src/Sulu/Bundle/ContactBundle/Contact/AbstractContactManager.php#L763-L779 | train |
sulu/sulu | src/Sulu/Bundle/ContactBundle/Contact/AbstractContactManager.php | AbstractContactManager.processUrls | public function processUrls($contact, $urls)
{
$get = function($url) {
return $url->getId();
};
$delete = function($url) use ($contact) {
return $contact->removeUrl($url);
};
$update = function($url, $matchedEntry) {
return $this->updateUrl($url, $matchedEntry);
};
$add = function($url) use ($contact) {
return $this->addUrl($contact, $url);
};
$entities = $contact->getUrls();
$result = $this->processSubEntities(
$entities,
$urls,
$get,
$add,
$update,
$delete
);
$this->resetIndexOfSubentites($entities);
// check main
$this->setMainUrl($contact);
return $result;
} | php | public function processUrls($contact, $urls)
{
$get = function($url) {
return $url->getId();
};
$delete = function($url) use ($contact) {
return $contact->removeUrl($url);
};
$update = function($url, $matchedEntry) {
return $this->updateUrl($url, $matchedEntry);
};
$add = function($url) use ($contact) {
return $this->addUrl($contact, $url);
};
$entities = $contact->getUrls();
$result = $this->processSubEntities(
$entities,
$urls,
$get,
$add,
$update,
$delete
);
$this->resetIndexOfSubentites($entities);
// check main
$this->setMainUrl($contact);
return $result;
} | [
"public",
"function",
"processUrls",
"(",
"$",
"contact",
",",
"$",
"urls",
")",
"{",
"$",
"get",
"=",
"function",
"(",
"$",
"url",
")",
"{",
"return",
"$",
"url",
"->",
"getId",
"(",
")",
";",
"}",
";",
"$",
"delete",
"=",
"function",
"(",
"$",
"url",
")",
"use",
"(",
"$",
"contact",
")",
"{",
"return",
"$",
"contact",
"->",
"removeUrl",
"(",
"$",
"url",
")",
";",
"}",
";",
"$",
"update",
"=",
"function",
"(",
"$",
"url",
",",
"$",
"matchedEntry",
")",
"{",
"return",
"$",
"this",
"->",
"updateUrl",
"(",
"$",
"url",
",",
"$",
"matchedEntry",
")",
";",
"}",
";",
"$",
"add",
"=",
"function",
"(",
"$",
"url",
")",
"use",
"(",
"$",
"contact",
")",
"{",
"return",
"$",
"this",
"->",
"addUrl",
"(",
"$",
"contact",
",",
"$",
"url",
")",
";",
"}",
";",
"$",
"entities",
"=",
"$",
"contact",
"->",
"getUrls",
"(",
")",
";",
"$",
"result",
"=",
"$",
"this",
"->",
"processSubEntities",
"(",
"$",
"entities",
",",
"$",
"urls",
",",
"$",
"get",
",",
"$",
"add",
",",
"$",
"update",
",",
"$",
"delete",
")",
";",
"$",
"this",
"->",
"resetIndexOfSubentites",
"(",
"$",
"entities",
")",
";",
"// check main",
"$",
"this",
"->",
"setMainUrl",
"(",
"$",
"contact",
")",
";",
"return",
"$",
"result",
";",
"}"
] | Process all urls of request.
@param $contact The contact to be processed
@param array $urls
@return bool True if the processing was successful, otherwise false | [
"Process",
"all",
"urls",
"of",
"request",
"."
] | 6766a36cc2f0c807c59202bf7540a08c4ef31192 | https://github.com/sulu/sulu/blob/6766a36cc2f0c807c59202bf7540a08c4ef31192/src/Sulu/Bundle/ContactBundle/Contact/AbstractContactManager.php#L789-L824 | train |
sulu/sulu | src/Sulu/Bundle/ContactBundle/Contact/AbstractContactManager.php | AbstractContactManager.processCategories | public function processCategories($contact, $categoryIds)
{
$contact->getCategories()->clear();
if (!$categoryIds) {
return true;
}
foreach ($categoryIds as $categoryId) {
$category = $this->em->getRepository(self::$categoryEntityName)->find($categoryId);
if (!$category) {
throw new EntityNotFoundException(self::$categoryEntityName, $categoryId);
}
$contact->addCategory($category);
}
return true;
} | php | public function processCategories($contact, $categoryIds)
{
$contact->getCategories()->clear();
if (!$categoryIds) {
return true;
}
foreach ($categoryIds as $categoryId) {
$category = $this->em->getRepository(self::$categoryEntityName)->find($categoryId);
if (!$category) {
throw new EntityNotFoundException(self::$categoryEntityName, $categoryId);
}
$contact->addCategory($category);
}
return true;
} | [
"public",
"function",
"processCategories",
"(",
"$",
"contact",
",",
"$",
"categoryIds",
")",
"{",
"$",
"contact",
"->",
"getCategories",
"(",
")",
"->",
"clear",
"(",
")",
";",
"if",
"(",
"!",
"$",
"categoryIds",
")",
"{",
"return",
"true",
";",
"}",
"foreach",
"(",
"$",
"categoryIds",
"as",
"$",
"categoryId",
")",
"{",
"$",
"category",
"=",
"$",
"this",
"->",
"em",
"->",
"getRepository",
"(",
"self",
"::",
"$",
"categoryEntityName",
")",
"->",
"find",
"(",
"$",
"categoryId",
")",
";",
"if",
"(",
"!",
"$",
"category",
")",
"{",
"throw",
"new",
"EntityNotFoundException",
"(",
"self",
"::",
"$",
"categoryEntityName",
",",
"$",
"categoryId",
")",
";",
"}",
"$",
"contact",
"->",
"addCategory",
"(",
"$",
"category",
")",
";",
"}",
"return",
"true",
";",
"}"
] | Process all categories of request.
@param $contact - the contact which is processed
@param $categories
@return bool True if the processing was successful, otherwise false | [
"Process",
"all",
"categories",
"of",
"request",
"."
] | 6766a36cc2f0c807c59202bf7540a08c4ef31192 | https://github.com/sulu/sulu/blob/6766a36cc2f0c807c59202bf7540a08c4ef31192/src/Sulu/Bundle/ContactBundle/Contact/AbstractContactManager.php#L834-L853 | train |
sulu/sulu | src/Sulu/Bundle/ContactBundle/Contact/AbstractContactManager.php | AbstractContactManager.addUrl | protected function addUrl($contact, $data)
{
$success = true;
$urlType = $this->em->getRepository(
self::$urlTypeEntityName
)->find($data['urlType']['id']);
if (isset($data['id'])) {
throw new EntityIdAlreadySetException(self::$urlEntityName, $data['id']);
} elseif (!$urlType) {
throw new EntityNotFoundException(self::$urlTypeEntityName, $data['urlType']['id']);
} else {
$url = new Url();
$url->setUrl($data['url']);
$url->setUrlType($urlType);
$this->em->persist($url);
$contact->addUrl($url);
}
return $success;
} | php | protected function addUrl($contact, $data)
{
$success = true;
$urlType = $this->em->getRepository(
self::$urlTypeEntityName
)->find($data['urlType']['id']);
if (isset($data['id'])) {
throw new EntityIdAlreadySetException(self::$urlEntityName, $data['id']);
} elseif (!$urlType) {
throw new EntityNotFoundException(self::$urlTypeEntityName, $data['urlType']['id']);
} else {
$url = new Url();
$url->setUrl($data['url']);
$url->setUrlType($urlType);
$this->em->persist($url);
$contact->addUrl($url);
}
return $success;
} | [
"protected",
"function",
"addUrl",
"(",
"$",
"contact",
",",
"$",
"data",
")",
"{",
"$",
"success",
"=",
"true",
";",
"$",
"urlType",
"=",
"$",
"this",
"->",
"em",
"->",
"getRepository",
"(",
"self",
"::",
"$",
"urlTypeEntityName",
")",
"->",
"find",
"(",
"$",
"data",
"[",
"'urlType'",
"]",
"[",
"'id'",
"]",
")",
";",
"if",
"(",
"isset",
"(",
"$",
"data",
"[",
"'id'",
"]",
")",
")",
"{",
"throw",
"new",
"EntityIdAlreadySetException",
"(",
"self",
"::",
"$",
"urlEntityName",
",",
"$",
"data",
"[",
"'id'",
"]",
")",
";",
"}",
"elseif",
"(",
"!",
"$",
"urlType",
")",
"{",
"throw",
"new",
"EntityNotFoundException",
"(",
"self",
"::",
"$",
"urlTypeEntityName",
",",
"$",
"data",
"[",
"'urlType'",
"]",
"[",
"'id'",
"]",
")",
";",
"}",
"else",
"{",
"$",
"url",
"=",
"new",
"Url",
"(",
")",
";",
"$",
"url",
"->",
"setUrl",
"(",
"$",
"data",
"[",
"'url'",
"]",
")",
";",
"$",
"url",
"->",
"setUrlType",
"(",
"$",
"urlType",
")",
";",
"$",
"this",
"->",
"em",
"->",
"persist",
"(",
"$",
"url",
")",
";",
"$",
"contact",
"->",
"addUrl",
"(",
"$",
"url",
")",
";",
"}",
"return",
"$",
"success",
";",
"}"
] | Adds a new tag to the given contact.
@param $contact
@param $data
@return bool
@throws EntityNotFoundException
@throws EntityIdAlreadySetException | [
"Adds",
"a",
"new",
"tag",
"to",
"the",
"given",
"contact",
"."
] | 6766a36cc2f0c807c59202bf7540a08c4ef31192 | https://github.com/sulu/sulu/blob/6766a36cc2f0c807c59202bf7540a08c4ef31192/src/Sulu/Bundle/ContactBundle/Contact/AbstractContactManager.php#L893-L914 | train |
sulu/sulu | src/Sulu/Bundle/ContactBundle/Contact/AbstractContactManager.php | AbstractContactManager.processPhones | public function processPhones($contact, $phones)
{
$get = function($phone) {
return $phone->getId();
};
$delete = function($phone) use ($contact) {
return $contact->removePhone($phone);
};
$update = function($phone, $matchedEntry) {
return $this->updatePhone($phone, $matchedEntry);
};
$add = function($phone) use ($contact) {
return $this->addPhone($contact, $phone);
};
$entities = $contact->getPhones();
$result = $this->processSubEntities(
$entities,
$phones,
$get,
$add,
$update,
$delete
);
$this->resetIndexOfSubentites($entities);
// check main
$this->setMainPhone($contact);
return $result;
} | php | public function processPhones($contact, $phones)
{
$get = function($phone) {
return $phone->getId();
};
$delete = function($phone) use ($contact) {
return $contact->removePhone($phone);
};
$update = function($phone, $matchedEntry) {
return $this->updatePhone($phone, $matchedEntry);
};
$add = function($phone) use ($contact) {
return $this->addPhone($contact, $phone);
};
$entities = $contact->getPhones();
$result = $this->processSubEntities(
$entities,
$phones,
$get,
$add,
$update,
$delete
);
$this->resetIndexOfSubentites($entities);
// check main
$this->setMainPhone($contact);
return $result;
} | [
"public",
"function",
"processPhones",
"(",
"$",
"contact",
",",
"$",
"phones",
")",
"{",
"$",
"get",
"=",
"function",
"(",
"$",
"phone",
")",
"{",
"return",
"$",
"phone",
"->",
"getId",
"(",
")",
";",
"}",
";",
"$",
"delete",
"=",
"function",
"(",
"$",
"phone",
")",
"use",
"(",
"$",
"contact",
")",
"{",
"return",
"$",
"contact",
"->",
"removePhone",
"(",
"$",
"phone",
")",
";",
"}",
";",
"$",
"update",
"=",
"function",
"(",
"$",
"phone",
",",
"$",
"matchedEntry",
")",
"{",
"return",
"$",
"this",
"->",
"updatePhone",
"(",
"$",
"phone",
",",
"$",
"matchedEntry",
")",
";",
"}",
";",
"$",
"add",
"=",
"function",
"(",
"$",
"phone",
")",
"use",
"(",
"$",
"contact",
")",
"{",
"return",
"$",
"this",
"->",
"addPhone",
"(",
"$",
"contact",
",",
"$",
"phone",
")",
";",
"}",
";",
"$",
"entities",
"=",
"$",
"contact",
"->",
"getPhones",
"(",
")",
";",
"$",
"result",
"=",
"$",
"this",
"->",
"processSubEntities",
"(",
"$",
"entities",
",",
"$",
"phones",
",",
"$",
"get",
",",
"$",
"add",
",",
"$",
"update",
",",
"$",
"delete",
")",
";",
"$",
"this",
"->",
"resetIndexOfSubentites",
"(",
"$",
"entities",
")",
";",
"// check main",
"$",
"this",
"->",
"setMainPhone",
"(",
"$",
"contact",
")",
";",
"return",
"$",
"result",
";",
"}"
] | Process all phones from request.
@param $contact The contact on which is processed
@param $phones
@return bool True if the processing was successful, otherwise false | [
"Process",
"all",
"phones",
"from",
"request",
"."
] | 6766a36cc2f0c807c59202bf7540a08c4ef31192 | https://github.com/sulu/sulu/blob/6766a36cc2f0c807c59202bf7540a08c4ef31192/src/Sulu/Bundle/ContactBundle/Contact/AbstractContactManager.php#L924-L959 | train |
sulu/sulu | src/Sulu/Bundle/ContactBundle/Contact/AbstractContactManager.php | AbstractContactManager.addPhone | protected function addPhone($contact, $phoneData)
{
$success = true;
$phoneType = $this->em->getRepository(
self::$phoneTypeEntityName
)->find($phoneData['phoneType']['id']);
if (isset($phoneData['id'])) {
throw new EntityIdAlreadySetException(self::$phoneEntityName, $phoneData['id']);
} elseif (!$phoneType) {
throw new EntityNotFoundException(self::$phoneTypeEntityName, $phoneData['phoneType']['id']);
} else {
$phone = new Phone();
$phone->setPhone($phoneData['phone']);
$phone->setPhoneType($phoneType);
$this->em->persist($phone);
$contact->addPhone($phone);
}
return $success;
} | php | protected function addPhone($contact, $phoneData)
{
$success = true;
$phoneType = $this->em->getRepository(
self::$phoneTypeEntityName
)->find($phoneData['phoneType']['id']);
if (isset($phoneData['id'])) {
throw new EntityIdAlreadySetException(self::$phoneEntityName, $phoneData['id']);
} elseif (!$phoneType) {
throw new EntityNotFoundException(self::$phoneTypeEntityName, $phoneData['phoneType']['id']);
} else {
$phone = new Phone();
$phone->setPhone($phoneData['phone']);
$phone->setPhoneType($phoneType);
$this->em->persist($phone);
$contact->addPhone($phone);
}
return $success;
} | [
"protected",
"function",
"addPhone",
"(",
"$",
"contact",
",",
"$",
"phoneData",
")",
"{",
"$",
"success",
"=",
"true",
";",
"$",
"phoneType",
"=",
"$",
"this",
"->",
"em",
"->",
"getRepository",
"(",
"self",
"::",
"$",
"phoneTypeEntityName",
")",
"->",
"find",
"(",
"$",
"phoneData",
"[",
"'phoneType'",
"]",
"[",
"'id'",
"]",
")",
";",
"if",
"(",
"isset",
"(",
"$",
"phoneData",
"[",
"'id'",
"]",
")",
")",
"{",
"throw",
"new",
"EntityIdAlreadySetException",
"(",
"self",
"::",
"$",
"phoneEntityName",
",",
"$",
"phoneData",
"[",
"'id'",
"]",
")",
";",
"}",
"elseif",
"(",
"!",
"$",
"phoneType",
")",
"{",
"throw",
"new",
"EntityNotFoundException",
"(",
"self",
"::",
"$",
"phoneTypeEntityName",
",",
"$",
"phoneData",
"[",
"'phoneType'",
"]",
"[",
"'id'",
"]",
")",
";",
"}",
"else",
"{",
"$",
"phone",
"=",
"new",
"Phone",
"(",
")",
";",
"$",
"phone",
"->",
"setPhone",
"(",
"$",
"phoneData",
"[",
"'phone'",
"]",
")",
";",
"$",
"phone",
"->",
"setPhoneType",
"(",
"$",
"phoneType",
")",
";",
"$",
"this",
"->",
"em",
"->",
"persist",
"(",
"$",
"phone",
")",
";",
"$",
"contact",
"->",
"addPhone",
"(",
"$",
"phone",
")",
";",
"}",
"return",
"$",
"success",
";",
"}"
] | Add a new phone to the given contact and persist it with the given object manager.
@param $contact
@param array $phoneData
@throws EntityNotFoundException
@throws EntityIdAlreadySetException
@return bool True if there was no error, otherwise false | [
"Add",
"a",
"new",
"phone",
"to",
"the",
"given",
"contact",
"and",
"persist",
"it",
"with",
"the",
"given",
"object",
"manager",
"."
] | 6766a36cc2f0c807c59202bf7540a08c4ef31192 | https://github.com/sulu/sulu/blob/6766a36cc2f0c807c59202bf7540a08c4ef31192/src/Sulu/Bundle/ContactBundle/Contact/AbstractContactManager.php#L972-L993 | train |
sulu/sulu | src/Sulu/Bundle/ContactBundle/Contact/AbstractContactManager.php | AbstractContactManager.updatePhone | protected function updatePhone(Phone $phone, $entry)
{
$success = true;
$phoneType = $this->em->getRepository(
self::$phoneTypeEntityName
)->find($entry['phoneType']['id']);
if (!$phoneType) {
throw new EntityNotFoundException(self::$phoneTypeEntityName, $entry['phoneType']['id']);
} else {
$phone->setPhone($entry['phone']);
$phone->setPhoneType($phoneType);
}
return $success;
} | php | protected function updatePhone(Phone $phone, $entry)
{
$success = true;
$phoneType = $this->em->getRepository(
self::$phoneTypeEntityName
)->find($entry['phoneType']['id']);
if (!$phoneType) {
throw new EntityNotFoundException(self::$phoneTypeEntityName, $entry['phoneType']['id']);
} else {
$phone->setPhone($entry['phone']);
$phone->setPhoneType($phoneType);
}
return $success;
} | [
"protected",
"function",
"updatePhone",
"(",
"Phone",
"$",
"phone",
",",
"$",
"entry",
")",
"{",
"$",
"success",
"=",
"true",
";",
"$",
"phoneType",
"=",
"$",
"this",
"->",
"em",
"->",
"getRepository",
"(",
"self",
"::",
"$",
"phoneTypeEntityName",
")",
"->",
"find",
"(",
"$",
"entry",
"[",
"'phoneType'",
"]",
"[",
"'id'",
"]",
")",
";",
"if",
"(",
"!",
"$",
"phoneType",
")",
"{",
"throw",
"new",
"EntityNotFoundException",
"(",
"self",
"::",
"$",
"phoneTypeEntityName",
",",
"$",
"entry",
"[",
"'phoneType'",
"]",
"[",
"'id'",
"]",
")",
";",
"}",
"else",
"{",
"$",
"phone",
"->",
"setPhone",
"(",
"$",
"entry",
"[",
"'phone'",
"]",
")",
";",
"$",
"phone",
"->",
"setPhoneType",
"(",
"$",
"phoneType",
")",
";",
"}",
"return",
"$",
"success",
";",
"}"
] | Updates the given phone.
@param Phone $phone The phone object to update
@param $entry The entry with the new data
@throws EntityNotFoundException
@return bool True if successful, otherwise false | [
"Updates",
"the",
"given",
"phone",
"."
] | 6766a36cc2f0c807c59202bf7540a08c4ef31192 | https://github.com/sulu/sulu/blob/6766a36cc2f0c807c59202bf7540a08c4ef31192/src/Sulu/Bundle/ContactBundle/Contact/AbstractContactManager.php#L1005-L1021 | train |
sulu/sulu | src/Sulu/Bundle/ContactBundle/Contact/AbstractContactManager.php | AbstractContactManager.getBooleanValue | protected function getBooleanValue($value)
{
if (is_string($value)) {
return 'true' === $value ? true : false;
} elseif (is_bool($value)) {
return $value;
} elseif (is_numeric($value)) {
return 1 === $value ? true : false;
}
} | php | protected function getBooleanValue($value)
{
if (is_string($value)) {
return 'true' === $value ? true : false;
} elseif (is_bool($value)) {
return $value;
} elseif (is_numeric($value)) {
return 1 === $value ? true : false;
}
} | [
"protected",
"function",
"getBooleanValue",
"(",
"$",
"value",
")",
"{",
"if",
"(",
"is_string",
"(",
"$",
"value",
")",
")",
"{",
"return",
"'true'",
"===",
"$",
"value",
"?",
"true",
":",
"false",
";",
"}",
"elseif",
"(",
"is_bool",
"(",
"$",
"value",
")",
")",
"{",
"return",
"$",
"value",
";",
"}",
"elseif",
"(",
"is_numeric",
"(",
"$",
"value",
")",
")",
"{",
"return",
"1",
"===",
"$",
"value",
"?",
"true",
":",
"false",
";",
"}",
"}"
] | Checks if a value is a boolean and converts it if necessary and returns it.
@param $value
@return bool | [
"Checks",
"if",
"a",
"value",
"is",
"a",
"boolean",
"and",
"converts",
"it",
"if",
"necessary",
"and",
"returns",
"it",
"."
] | 6766a36cc2f0c807c59202bf7540a08c4ef31192 | https://github.com/sulu/sulu/blob/6766a36cc2f0c807c59202bf7540a08c4ef31192/src/Sulu/Bundle/ContactBundle/Contact/AbstractContactManager.php#L1424-L1433 | train |
sulu/sulu | src/Sulu/Bundle/ContactBundle/Contact/AbstractContactManager.php | AbstractContactManager.processNotes | public function processNotes($contact, $notes)
{
$get = function($note) {
return $note->getId();
};
$delete = function($note) use ($contact) {
$contact->removeNote($note);
return true;
};
$update = function($note, $matchedEntry) {
return $this->updateNote($note, $matchedEntry);
};
$add = function($note) use ($contact) {
return $this->addNote($contact, $note);
};
$entities = $contact->getNotes();
$result = $this->processSubEntities(
$entities,
$notes,
$get,
$add,
$update,
$delete
);
$this->resetIndexOfSubentites($entities);
return $result;
} | php | public function processNotes($contact, $notes)
{
$get = function($note) {
return $note->getId();
};
$delete = function($note) use ($contact) {
$contact->removeNote($note);
return true;
};
$update = function($note, $matchedEntry) {
return $this->updateNote($note, $matchedEntry);
};
$add = function($note) use ($contact) {
return $this->addNote($contact, $note);
};
$entities = $contact->getNotes();
$result = $this->processSubEntities(
$entities,
$notes,
$get,
$add,
$update,
$delete
);
$this->resetIndexOfSubentites($entities);
return $result;
} | [
"public",
"function",
"processNotes",
"(",
"$",
"contact",
",",
"$",
"notes",
")",
"{",
"$",
"get",
"=",
"function",
"(",
"$",
"note",
")",
"{",
"return",
"$",
"note",
"->",
"getId",
"(",
")",
";",
"}",
";",
"$",
"delete",
"=",
"function",
"(",
"$",
"note",
")",
"use",
"(",
"$",
"contact",
")",
"{",
"$",
"contact",
"->",
"removeNote",
"(",
"$",
"note",
")",
";",
"return",
"true",
";",
"}",
";",
"$",
"update",
"=",
"function",
"(",
"$",
"note",
",",
"$",
"matchedEntry",
")",
"{",
"return",
"$",
"this",
"->",
"updateNote",
"(",
"$",
"note",
",",
"$",
"matchedEntry",
")",
";",
"}",
";",
"$",
"add",
"=",
"function",
"(",
"$",
"note",
")",
"use",
"(",
"$",
"contact",
")",
"{",
"return",
"$",
"this",
"->",
"addNote",
"(",
"$",
"contact",
",",
"$",
"note",
")",
";",
"}",
";",
"$",
"entities",
"=",
"$",
"contact",
"->",
"getNotes",
"(",
")",
";",
"$",
"result",
"=",
"$",
"this",
"->",
"processSubEntities",
"(",
"$",
"entities",
",",
"$",
"notes",
",",
"$",
"get",
",",
"$",
"add",
",",
"$",
"update",
",",
"$",
"delete",
")",
";",
"$",
"this",
"->",
"resetIndexOfSubentites",
"(",
"$",
"entities",
")",
";",
"return",
"$",
"result",
";",
"}"
] | Process all notes from request.
@param Contact $contact The contact on which is worked
@param $notes
@return bool True if the processing was successful, otherwise false | [
"Process",
"all",
"notes",
"from",
"request",
"."
] | 6766a36cc2f0c807c59202bf7540a08c4ef31192 | https://github.com/sulu/sulu/blob/6766a36cc2f0c807c59202bf7540a08c4ef31192/src/Sulu/Bundle/ContactBundle/Contact/AbstractContactManager.php#L1443-L1477 | train |
sulu/sulu | src/Sulu/Bundle/ContactBundle/Contact/AbstractContactManager.php | AbstractContactManager.processTags | public function processTags($contact, $tags)
{
$get = function($tag) {
return $tag->getId();
};
$delete = function($tag) use ($contact) {
return $contact->removeTag($tag);
};
$update = function() {
return true;
};
$add = function($tag) use ($contact) {
return $this->addTag($contact, $tag);
};
$entities = $contact->getTags();
$result = $this->processSubEntities(
$entities,
$tags,
$get,
$add,
$update,
$delete
);
$this->resetIndexOfSubentites($entities);
return $result;
} | php | public function processTags($contact, $tags)
{
$get = function($tag) {
return $tag->getId();
};
$delete = function($tag) use ($contact) {
return $contact->removeTag($tag);
};
$update = function() {
return true;
};
$add = function($tag) use ($contact) {
return $this->addTag($contact, $tag);
};
$entities = $contact->getTags();
$result = $this->processSubEntities(
$entities,
$tags,
$get,
$add,
$update,
$delete
);
$this->resetIndexOfSubentites($entities);
return $result;
} | [
"public",
"function",
"processTags",
"(",
"$",
"contact",
",",
"$",
"tags",
")",
"{",
"$",
"get",
"=",
"function",
"(",
"$",
"tag",
")",
"{",
"return",
"$",
"tag",
"->",
"getId",
"(",
")",
";",
"}",
";",
"$",
"delete",
"=",
"function",
"(",
"$",
"tag",
")",
"use",
"(",
"$",
"contact",
")",
"{",
"return",
"$",
"contact",
"->",
"removeTag",
"(",
"$",
"tag",
")",
";",
"}",
";",
"$",
"update",
"=",
"function",
"(",
")",
"{",
"return",
"true",
";",
"}",
";",
"$",
"add",
"=",
"function",
"(",
"$",
"tag",
")",
"use",
"(",
"$",
"contact",
")",
"{",
"return",
"$",
"this",
"->",
"addTag",
"(",
"$",
"contact",
",",
"$",
"tag",
")",
";",
"}",
";",
"$",
"entities",
"=",
"$",
"contact",
"->",
"getTags",
"(",
")",
";",
"$",
"result",
"=",
"$",
"this",
"->",
"processSubEntities",
"(",
"$",
"entities",
",",
"$",
"tags",
",",
"$",
"get",
",",
"$",
"add",
",",
"$",
"update",
",",
"$",
"delete",
")",
";",
"$",
"this",
"->",
"resetIndexOfSubentites",
"(",
"$",
"entities",
")",
";",
"return",
"$",
"result",
";",
"}"
] | Process all tags of request.
@param $contact The contact on which is worked
@param array $tags
@return bool True if the processing was successful, otherwise false | [
"Process",
"all",
"tags",
"of",
"request",
"."
] | 6766a36cc2f0c807c59202bf7540a08c4ef31192 | https://github.com/sulu/sulu/blob/6766a36cc2f0c807c59202bf7540a08c4ef31192/src/Sulu/Bundle/ContactBundle/Contact/AbstractContactManager.php#L1531-L1563 | train |
sulu/sulu | src/Sulu/Bundle/ContactBundle/Contact/AbstractContactManager.php | AbstractContactManager.addTag | protected function addTag($contact, $data)
{
$success = true;
$resolvedTag = $this->getTagManager()->findByName($data);
$contact->addTag($resolvedTag);
return $success;
} | php | protected function addTag($contact, $data)
{
$success = true;
$resolvedTag = $this->getTagManager()->findByName($data);
$contact->addTag($resolvedTag);
return $success;
} | [
"protected",
"function",
"addTag",
"(",
"$",
"contact",
",",
"$",
"data",
")",
"{",
"$",
"success",
"=",
"true",
";",
"$",
"resolvedTag",
"=",
"$",
"this",
"->",
"getTagManager",
"(",
")",
"->",
"findByName",
"(",
"$",
"data",
")",
";",
"$",
"contact",
"->",
"addTag",
"(",
"$",
"resolvedTag",
")",
";",
"return",
"$",
"success",
";",
"}"
] | Adds a new tag to the given contact and persist it with the given object manager.
@param $contact
@param $data
@return bool True if there was no error, otherwise false | [
"Adds",
"a",
"new",
"tag",
"to",
"the",
"given",
"contact",
"and",
"persist",
"it",
"with",
"the",
"given",
"object",
"manager",
"."
] | 6766a36cc2f0c807c59202bf7540a08c4ef31192 | https://github.com/sulu/sulu/blob/6766a36cc2f0c807c59202bf7540a08c4ef31192/src/Sulu/Bundle/ContactBundle/Contact/AbstractContactManager.php#L1573-L1580 | train |
sulu/sulu | src/Sulu/Bundle/ContactBundle/Contact/AbstractContactManager.php | AbstractContactManager.processBankAccounts | public function processBankAccounts($contact, $bankAccounts)
{
$get = function($bankAccount) {
return $bankAccount->getId();
};
$delete = function($bankAccounts) use ($contact) {
$contact->removeBankAccount($bankAccounts);
return true;
};
$update = function($bankAccounts, $matchedEntry) {
return $this->updateBankAccount($bankAccounts, $matchedEntry);
};
$add = function($bankAccounts) use ($contact) {
return $this->addBankAccount($contact, $bankAccounts);
};
$entities = $contact->getBankAccounts();
$result = $this->processSubEntities(
$entities,
$bankAccounts,
$get,
$add,
$update,
$delete
);
$this->resetIndexOfSubentites($entities);
return $result;
} | php | public function processBankAccounts($contact, $bankAccounts)
{
$get = function($bankAccount) {
return $bankAccount->getId();
};
$delete = function($bankAccounts) use ($contact) {
$contact->removeBankAccount($bankAccounts);
return true;
};
$update = function($bankAccounts, $matchedEntry) {
return $this->updateBankAccount($bankAccounts, $matchedEntry);
};
$add = function($bankAccounts) use ($contact) {
return $this->addBankAccount($contact, $bankAccounts);
};
$entities = $contact->getBankAccounts();
$result = $this->processSubEntities(
$entities,
$bankAccounts,
$get,
$add,
$update,
$delete
);
$this->resetIndexOfSubentites($entities);
return $result;
} | [
"public",
"function",
"processBankAccounts",
"(",
"$",
"contact",
",",
"$",
"bankAccounts",
")",
"{",
"$",
"get",
"=",
"function",
"(",
"$",
"bankAccount",
")",
"{",
"return",
"$",
"bankAccount",
"->",
"getId",
"(",
")",
";",
"}",
";",
"$",
"delete",
"=",
"function",
"(",
"$",
"bankAccounts",
")",
"use",
"(",
"$",
"contact",
")",
"{",
"$",
"contact",
"->",
"removeBankAccount",
"(",
"$",
"bankAccounts",
")",
";",
"return",
"true",
";",
"}",
";",
"$",
"update",
"=",
"function",
"(",
"$",
"bankAccounts",
",",
"$",
"matchedEntry",
")",
"{",
"return",
"$",
"this",
"->",
"updateBankAccount",
"(",
"$",
"bankAccounts",
",",
"$",
"matchedEntry",
")",
";",
"}",
";",
"$",
"add",
"=",
"function",
"(",
"$",
"bankAccounts",
")",
"use",
"(",
"$",
"contact",
")",
"{",
"return",
"$",
"this",
"->",
"addBankAccount",
"(",
"$",
"contact",
",",
"$",
"bankAccounts",
")",
";",
"}",
";",
"$",
"entities",
"=",
"$",
"contact",
"->",
"getBankAccounts",
"(",
")",
";",
"$",
"result",
"=",
"$",
"this",
"->",
"processSubEntities",
"(",
"$",
"entities",
",",
"$",
"bankAccounts",
",",
"$",
"get",
",",
"$",
"add",
",",
"$",
"update",
",",
"$",
"delete",
")",
";",
"$",
"this",
"->",
"resetIndexOfSubentites",
"(",
"$",
"entities",
")",
";",
"return",
"$",
"result",
";",
"}"
] | Process all bankAccounts of a request.
@param $contact
@param $bankAccounts
@return bool True if the processing was sucessful, otherwise false | [
"Process",
"all",
"bankAccounts",
"of",
"a",
"request",
"."
] | 6766a36cc2f0c807c59202bf7540a08c4ef31192 | https://github.com/sulu/sulu/blob/6766a36cc2f0c807c59202bf7540a08c4ef31192/src/Sulu/Bundle/ContactBundle/Contact/AbstractContactManager.php#L1590-L1624 | train |
sulu/sulu | src/Sulu/Bundle/ContactBundle/Contact/AbstractContactManager.php | AbstractContactManager.processAddresses | public function processAddresses($contact, $addresses)
{
$getAddressId = function($addressRelation) {
return $addressRelation->getAddress()->getId();
};
$delete = function($addressRelation) use ($contact) {
$this->removeAddressRelation($contact, $addressRelation);
return true;
};
$update = function($addressRelation, $matchedEntry) use ($contact) {
$address = $addressRelation->getAddress();
$result = $this->updateAddress($address, $matchedEntry, $isMain);
if ($isMain) {
$this->unsetMain($this->getAddressRelations($contact));
}
$addressRelation->setMain($isMain);
return $result;
};
$add = function($addressData) use ($contact) {
$address = $this->createAddress($addressData, $isMain);
$this->addAddress($contact, $address, $isMain);
return true;
};
$entities = $this->getAddressRelations($contact);
$result = $this->processSubEntities(
$entities,
$addresses,
$getAddressId,
$add,
$update,
$delete
);
$this->resetIndexOfSubentites($entities);
// check if main exists, else take first address
$this->checkAndSetMainAddress($this->getAddressRelations($contact));
return $result;
} | php | public function processAddresses($contact, $addresses)
{
$getAddressId = function($addressRelation) {
return $addressRelation->getAddress()->getId();
};
$delete = function($addressRelation) use ($contact) {
$this->removeAddressRelation($contact, $addressRelation);
return true;
};
$update = function($addressRelation, $matchedEntry) use ($contact) {
$address = $addressRelation->getAddress();
$result = $this->updateAddress($address, $matchedEntry, $isMain);
if ($isMain) {
$this->unsetMain($this->getAddressRelations($contact));
}
$addressRelation->setMain($isMain);
return $result;
};
$add = function($addressData) use ($contact) {
$address = $this->createAddress($addressData, $isMain);
$this->addAddress($contact, $address, $isMain);
return true;
};
$entities = $this->getAddressRelations($contact);
$result = $this->processSubEntities(
$entities,
$addresses,
$getAddressId,
$add,
$update,
$delete
);
$this->resetIndexOfSubentites($entities);
// check if main exists, else take first address
$this->checkAndSetMainAddress($this->getAddressRelations($contact));
return $result;
} | [
"public",
"function",
"processAddresses",
"(",
"$",
"contact",
",",
"$",
"addresses",
")",
"{",
"$",
"getAddressId",
"=",
"function",
"(",
"$",
"addressRelation",
")",
"{",
"return",
"$",
"addressRelation",
"->",
"getAddress",
"(",
")",
"->",
"getId",
"(",
")",
";",
"}",
";",
"$",
"delete",
"=",
"function",
"(",
"$",
"addressRelation",
")",
"use",
"(",
"$",
"contact",
")",
"{",
"$",
"this",
"->",
"removeAddressRelation",
"(",
"$",
"contact",
",",
"$",
"addressRelation",
")",
";",
"return",
"true",
";",
"}",
";",
"$",
"update",
"=",
"function",
"(",
"$",
"addressRelation",
",",
"$",
"matchedEntry",
")",
"use",
"(",
"$",
"contact",
")",
"{",
"$",
"address",
"=",
"$",
"addressRelation",
"->",
"getAddress",
"(",
")",
";",
"$",
"result",
"=",
"$",
"this",
"->",
"updateAddress",
"(",
"$",
"address",
",",
"$",
"matchedEntry",
",",
"$",
"isMain",
")",
";",
"if",
"(",
"$",
"isMain",
")",
"{",
"$",
"this",
"->",
"unsetMain",
"(",
"$",
"this",
"->",
"getAddressRelations",
"(",
"$",
"contact",
")",
")",
";",
"}",
"$",
"addressRelation",
"->",
"setMain",
"(",
"$",
"isMain",
")",
";",
"return",
"$",
"result",
";",
"}",
";",
"$",
"add",
"=",
"function",
"(",
"$",
"addressData",
")",
"use",
"(",
"$",
"contact",
")",
"{",
"$",
"address",
"=",
"$",
"this",
"->",
"createAddress",
"(",
"$",
"addressData",
",",
"$",
"isMain",
")",
";",
"$",
"this",
"->",
"addAddress",
"(",
"$",
"contact",
",",
"$",
"address",
",",
"$",
"isMain",
")",
";",
"return",
"true",
";",
"}",
";",
"$",
"entities",
"=",
"$",
"this",
"->",
"getAddressRelations",
"(",
"$",
"contact",
")",
";",
"$",
"result",
"=",
"$",
"this",
"->",
"processSubEntities",
"(",
"$",
"entities",
",",
"$",
"addresses",
",",
"$",
"getAddressId",
",",
"$",
"add",
",",
"$",
"update",
",",
"$",
"delete",
")",
";",
"$",
"this",
"->",
"resetIndexOfSubentites",
"(",
"$",
"entities",
")",
";",
"// check if main exists, else take first address",
"$",
"this",
"->",
"checkAndSetMainAddress",
"(",
"$",
"this",
"->",
"getAddressRelations",
"(",
"$",
"contact",
")",
")",
";",
"return",
"$",
"result",
";",
"}"
] | Process all addresses from request.
@param $contact The contact on which is worked
@param array $addresses
@return bool True if the processing was sucessful, otherwise false | [
"Process",
"all",
"addresses",
"from",
"request",
"."
] | 6766a36cc2f0c807c59202bf7540a08c4ef31192 | https://github.com/sulu/sulu/blob/6766a36cc2f0c807c59202bf7540a08c4ef31192/src/Sulu/Bundle/ContactBundle/Contact/AbstractContactManager.php#L1692-L1739 | train |
sulu/sulu | src/Sulu/Component/Content/Document/Subscriber/RouteSubscriber.php | RouteSubscriber.handleHydrate | public function handleHydrate(HydrateEvent $event)
{
$document = $event->getDocument();
if (!$document instanceof RouteBehavior) {
return;
}
$document->setHistory($event->getNode()->getPropertyValue(self::NODE_HISTORY_FIELD));
} | php | public function handleHydrate(HydrateEvent $event)
{
$document = $event->getDocument();
if (!$document instanceof RouteBehavior) {
return;
}
$document->setHistory($event->getNode()->getPropertyValue(self::NODE_HISTORY_FIELD));
} | [
"public",
"function",
"handleHydrate",
"(",
"HydrateEvent",
"$",
"event",
")",
"{",
"$",
"document",
"=",
"$",
"event",
"->",
"getDocument",
"(",
")",
";",
"if",
"(",
"!",
"$",
"document",
"instanceof",
"RouteBehavior",
")",
"{",
"return",
";",
"}",
"$",
"document",
"->",
"setHistory",
"(",
"$",
"event",
"->",
"getNode",
"(",
")",
"->",
"getPropertyValue",
"(",
"self",
"::",
"NODE_HISTORY_FIELD",
")",
")",
";",
"}"
] | Writes the history status of the node to the document.
@param HydrateEvent $event | [
"Writes",
"the",
"history",
"status",
"of",
"the",
"node",
"to",
"the",
"document",
"."
] | 6766a36cc2f0c807c59202bf7540a08c4ef31192 | https://github.com/sulu/sulu/blob/6766a36cc2f0c807c59202bf7540a08c4ef31192/src/Sulu/Component/Content/Document/Subscriber/RouteSubscriber.php#L94-L103 | train |
sulu/sulu | src/Sulu/Component/Content/Document/Subscriber/RouteSubscriber.php | RouteSubscriber.handleSetNodeOnPersist | public function handleSetNodeOnPersist(PersistEvent $event)
{
$document = $event->getDocument();
$options = $event->getOptions();
if (!$document instanceof RouteBehavior || !array_key_exists('path', $options)) {
return;
}
$parentPath = PathHelper::getParentPath($options['path']);
$parentNode = $this->nodeManager->createPath($parentPath);
$nodeName = PathHelper::getNodeName($options['path']);
if (!$parentNode->hasNode($nodeName)) {
return;
}
$node = $parentNode->getNode($nodeName);
if ($node->hasProperty(self::NODE_HISTORY_FIELD)) {
return;
}
$event->setNode($node);
$event->setParentNode($parentNode);
} | php | public function handleSetNodeOnPersist(PersistEvent $event)
{
$document = $event->getDocument();
$options = $event->getOptions();
if (!$document instanceof RouteBehavior || !array_key_exists('path', $options)) {
return;
}
$parentPath = PathHelper::getParentPath($options['path']);
$parentNode = $this->nodeManager->createPath($parentPath);
$nodeName = PathHelper::getNodeName($options['path']);
if (!$parentNode->hasNode($nodeName)) {
return;
}
$node = $parentNode->getNode($nodeName);
if ($node->hasProperty(self::NODE_HISTORY_FIELD)) {
return;
}
$event->setNode($node);
$event->setParentNode($parentNode);
} | [
"public",
"function",
"handleSetNodeOnPersist",
"(",
"PersistEvent",
"$",
"event",
")",
"{",
"$",
"document",
"=",
"$",
"event",
"->",
"getDocument",
"(",
")",
";",
"$",
"options",
"=",
"$",
"event",
"->",
"getOptions",
"(",
")",
";",
"if",
"(",
"!",
"$",
"document",
"instanceof",
"RouteBehavior",
"||",
"!",
"array_key_exists",
"(",
"'path'",
",",
"$",
"options",
")",
")",
"{",
"return",
";",
"}",
"$",
"parentPath",
"=",
"PathHelper",
"::",
"getParentPath",
"(",
"$",
"options",
"[",
"'path'",
"]",
")",
";",
"$",
"parentNode",
"=",
"$",
"this",
"->",
"nodeManager",
"->",
"createPath",
"(",
"$",
"parentPath",
")",
";",
"$",
"nodeName",
"=",
"PathHelper",
"::",
"getNodeName",
"(",
"$",
"options",
"[",
"'path'",
"]",
")",
";",
"if",
"(",
"!",
"$",
"parentNode",
"->",
"hasNode",
"(",
"$",
"nodeName",
")",
")",
"{",
"return",
";",
"}",
"$",
"node",
"=",
"$",
"parentNode",
"->",
"getNode",
"(",
"$",
"nodeName",
")",
";",
"if",
"(",
"$",
"node",
"->",
"hasProperty",
"(",
"self",
"::",
"NODE_HISTORY_FIELD",
")",
")",
"{",
"return",
";",
"}",
"$",
"event",
"->",
"setNode",
"(",
"$",
"node",
")",
";",
"$",
"event",
"->",
"setParentNode",
"(",
"$",
"parentNode",
")",
";",
"}"
] | Receives node for route and overwrite when the node is empty.
@param PersistEvent $event | [
"Receives",
"node",
"for",
"route",
"and",
"overwrite",
"when",
"the",
"node",
"is",
"empty",
"."
] | 6766a36cc2f0c807c59202bf7540a08c4ef31192 | https://github.com/sulu/sulu/blob/6766a36cc2f0c807c59202bf7540a08c4ef31192/src/Sulu/Component/Content/Document/Subscriber/RouteSubscriber.php#L110-L133 | train |
sulu/sulu | src/Sulu/Component/Content/Document/Subscriber/RouteSubscriber.php | RouteSubscriber.handlePersist | public function handlePersist(PersistEvent $event)
{
$document = $event->getDocument();
if (!$document instanceof RouteBehavior) {
return;
}
$node = $event->getNode();
$node->setProperty(self::NODE_HISTORY_FIELD, $document->isHistory());
$targetDocument = $document->getTargetDocument();
if ($targetDocument instanceof HomeDocument
|| !$targetDocument instanceof WebspaceBehavior
|| !$targetDocument instanceof ResourceSegmentBehavior
) {
return;
}
// copy new route to old position
$webspaceKey = $targetDocument->getWebspaceName();
$locale = $this->documentInspector->getLocale($document);
$routePath = $this->sessionManager->getRoutePath($webspaceKey, $locale, null)
. $targetDocument->getResourceSegment();
// create a route node if it is not a new document and the path changed
$documentPath = $this->documentInspector->getPath($document);
if ($documentPath && $documentPath != $routePath) {
/** @var RouteDocument $newRouteDocument */
$newRouteDocument = $this->documentManager->create('route');
$newRouteDocument->setTargetDocument($targetDocument);
$this->documentManager->persist(
$newRouteDocument,
$locale,
[
'path' => $routePath,
'auto_create' => true,
]
);
$this->documentManager->publish($newRouteDocument, $locale);
// change routes in old position to history
$this->changeOldPathToHistoryRoutes($document, $newRouteDocument);
}
} | php | public function handlePersist(PersistEvent $event)
{
$document = $event->getDocument();
if (!$document instanceof RouteBehavior) {
return;
}
$node = $event->getNode();
$node->setProperty(self::NODE_HISTORY_FIELD, $document->isHistory());
$targetDocument = $document->getTargetDocument();
if ($targetDocument instanceof HomeDocument
|| !$targetDocument instanceof WebspaceBehavior
|| !$targetDocument instanceof ResourceSegmentBehavior
) {
return;
}
// copy new route to old position
$webspaceKey = $targetDocument->getWebspaceName();
$locale = $this->documentInspector->getLocale($document);
$routePath = $this->sessionManager->getRoutePath($webspaceKey, $locale, null)
. $targetDocument->getResourceSegment();
// create a route node if it is not a new document and the path changed
$documentPath = $this->documentInspector->getPath($document);
if ($documentPath && $documentPath != $routePath) {
/** @var RouteDocument $newRouteDocument */
$newRouteDocument = $this->documentManager->create('route');
$newRouteDocument->setTargetDocument($targetDocument);
$this->documentManager->persist(
$newRouteDocument,
$locale,
[
'path' => $routePath,
'auto_create' => true,
]
);
$this->documentManager->publish($newRouteDocument, $locale);
// change routes in old position to history
$this->changeOldPathToHistoryRoutes($document, $newRouteDocument);
}
} | [
"public",
"function",
"handlePersist",
"(",
"PersistEvent",
"$",
"event",
")",
"{",
"$",
"document",
"=",
"$",
"event",
"->",
"getDocument",
"(",
")",
";",
"if",
"(",
"!",
"$",
"document",
"instanceof",
"RouteBehavior",
")",
"{",
"return",
";",
"}",
"$",
"node",
"=",
"$",
"event",
"->",
"getNode",
"(",
")",
";",
"$",
"node",
"->",
"setProperty",
"(",
"self",
"::",
"NODE_HISTORY_FIELD",
",",
"$",
"document",
"->",
"isHistory",
"(",
")",
")",
";",
"$",
"targetDocument",
"=",
"$",
"document",
"->",
"getTargetDocument",
"(",
")",
";",
"if",
"(",
"$",
"targetDocument",
"instanceof",
"HomeDocument",
"||",
"!",
"$",
"targetDocument",
"instanceof",
"WebspaceBehavior",
"||",
"!",
"$",
"targetDocument",
"instanceof",
"ResourceSegmentBehavior",
")",
"{",
"return",
";",
"}",
"// copy new route to old position",
"$",
"webspaceKey",
"=",
"$",
"targetDocument",
"->",
"getWebspaceName",
"(",
")",
";",
"$",
"locale",
"=",
"$",
"this",
"->",
"documentInspector",
"->",
"getLocale",
"(",
"$",
"document",
")",
";",
"$",
"routePath",
"=",
"$",
"this",
"->",
"sessionManager",
"->",
"getRoutePath",
"(",
"$",
"webspaceKey",
",",
"$",
"locale",
",",
"null",
")",
".",
"$",
"targetDocument",
"->",
"getResourceSegment",
"(",
")",
";",
"// create a route node if it is not a new document and the path changed",
"$",
"documentPath",
"=",
"$",
"this",
"->",
"documentInspector",
"->",
"getPath",
"(",
"$",
"document",
")",
";",
"if",
"(",
"$",
"documentPath",
"&&",
"$",
"documentPath",
"!=",
"$",
"routePath",
")",
"{",
"/** @var RouteDocument $newRouteDocument */",
"$",
"newRouteDocument",
"=",
"$",
"this",
"->",
"documentManager",
"->",
"create",
"(",
"'route'",
")",
";",
"$",
"newRouteDocument",
"->",
"setTargetDocument",
"(",
"$",
"targetDocument",
")",
";",
"$",
"this",
"->",
"documentManager",
"->",
"persist",
"(",
"$",
"newRouteDocument",
",",
"$",
"locale",
",",
"[",
"'path'",
"=>",
"$",
"routePath",
",",
"'auto_create'",
"=>",
"true",
",",
"]",
")",
";",
"$",
"this",
"->",
"documentManager",
"->",
"publish",
"(",
"$",
"newRouteDocument",
",",
"$",
"locale",
")",
";",
"// change routes in old position to history",
"$",
"this",
"->",
"changeOldPathToHistoryRoutes",
"(",
"$",
"document",
",",
"$",
"newRouteDocument",
")",
";",
"}",
"}"
] | Updates the route for the given document and creates history routes if necessary.
@param PersistEvent $event | [
"Updates",
"the",
"route",
"for",
"the",
"given",
"document",
"and",
"creates",
"history",
"routes",
"if",
"necessary",
"."
] | 6766a36cc2f0c807c59202bf7540a08c4ef31192 | https://github.com/sulu/sulu/blob/6766a36cc2f0c807c59202bf7540a08c4ef31192/src/Sulu/Component/Content/Document/Subscriber/RouteSubscriber.php#L140-L186 | train |
sulu/sulu | src/Sulu/Component/Content/Document/Subscriber/RouteSubscriber.php | RouteSubscriber.handleRemove | public function handleRemove(RemoveEvent $event)
{
$document = $event->getDocument();
if (!$document instanceof RouteBehavior) {
return;
}
$this->recursivelyRemoveRoutes($document);
} | php | public function handleRemove(RemoveEvent $event)
{
$document = $event->getDocument();
if (!$document instanceof RouteBehavior) {
return;
}
$this->recursivelyRemoveRoutes($document);
} | [
"public",
"function",
"handleRemove",
"(",
"RemoveEvent",
"$",
"event",
")",
"{",
"$",
"document",
"=",
"$",
"event",
"->",
"getDocument",
"(",
")",
";",
"if",
"(",
"!",
"$",
"document",
"instanceof",
"RouteBehavior",
")",
"{",
"return",
";",
"}",
"$",
"this",
"->",
"recursivelyRemoveRoutes",
"(",
"$",
"document",
")",
";",
"}"
] | Removes the routes for the given document and removes history routes if necessary.
@param RemoveEvent $event | [
"Removes",
"the",
"routes",
"for",
"the",
"given",
"document",
"and",
"removes",
"history",
"routes",
"if",
"necessary",
"."
] | 6766a36cc2f0c807c59202bf7540a08c4ef31192 | https://github.com/sulu/sulu/blob/6766a36cc2f0c807c59202bf7540a08c4ef31192/src/Sulu/Component/Content/Document/Subscriber/RouteSubscriber.php#L193-L202 | train |
sulu/sulu | src/Sulu/Component/Content/Document/Subscriber/RouteSubscriber.php | RouteSubscriber.handlePublish | public function handlePublish(PublishEvent $event)
{
$document = $event->getDocument();
if (!$document instanceof RouteBehavior) {
return;
}
$event->getNode()->setProperty(self::NODE_HISTORY_FIELD, $document->isHistory());
} | php | public function handlePublish(PublishEvent $event)
{
$document = $event->getDocument();
if (!$document instanceof RouteBehavior) {
return;
}
$event->getNode()->setProperty(self::NODE_HISTORY_FIELD, $document->isHistory());
} | [
"public",
"function",
"handlePublish",
"(",
"PublishEvent",
"$",
"event",
")",
"{",
"$",
"document",
"=",
"$",
"event",
"->",
"getDocument",
"(",
")",
";",
"if",
"(",
"!",
"$",
"document",
"instanceof",
"RouteBehavior",
")",
"{",
"return",
";",
"}",
"$",
"event",
"->",
"getNode",
"(",
")",
"->",
"setProperty",
"(",
"self",
"::",
"NODE_HISTORY_FIELD",
",",
"$",
"document",
"->",
"isHistory",
"(",
")",
")",
";",
"}"
] | Handles the history field for the route on publish.
@param PublishEvent $event | [
"Handles",
"the",
"history",
"field",
"for",
"the",
"route",
"on",
"publish",
"."
] | 6766a36cc2f0c807c59202bf7540a08c4ef31192 | https://github.com/sulu/sulu/blob/6766a36cc2f0c807c59202bf7540a08c4ef31192/src/Sulu/Component/Content/Document/Subscriber/RouteSubscriber.php#L209-L218 | train |
sulu/sulu | src/Sulu/Component/Content/Document/Subscriber/RouteSubscriber.php | RouteSubscriber.recursivelyRemoveRoutes | private function recursivelyRemoveRoutes(RouteBehavior $document)
{
$referrers = $this->documentInspector->getReferrers($document);
foreach ($referrers as $referrer) {
if (!$referrer instanceof RouteBehavior) {
continue;
}
$this->recursivelyRemoveRoutes($referrer);
$this->documentManager->remove($referrer);
}
} | php | private function recursivelyRemoveRoutes(RouteBehavior $document)
{
$referrers = $this->documentInspector->getReferrers($document);
foreach ($referrers as $referrer) {
if (!$referrer instanceof RouteBehavior) {
continue;
}
$this->recursivelyRemoveRoutes($referrer);
$this->documentManager->remove($referrer);
}
} | [
"private",
"function",
"recursivelyRemoveRoutes",
"(",
"RouteBehavior",
"$",
"document",
")",
"{",
"$",
"referrers",
"=",
"$",
"this",
"->",
"documentInspector",
"->",
"getReferrers",
"(",
"$",
"document",
")",
";",
"foreach",
"(",
"$",
"referrers",
"as",
"$",
"referrer",
")",
"{",
"if",
"(",
"!",
"$",
"referrer",
"instanceof",
"RouteBehavior",
")",
"{",
"continue",
";",
"}",
"$",
"this",
"->",
"recursivelyRemoveRoutes",
"(",
"$",
"referrer",
")",
";",
"$",
"this",
"->",
"documentManager",
"->",
"remove",
"(",
"$",
"referrer",
")",
";",
"}",
"}"
] | Remove given Route and his history.
@param $document | [
"Remove",
"given",
"Route",
"and",
"his",
"history",
"."
] | 6766a36cc2f0c807c59202bf7540a08c4ef31192 | https://github.com/sulu/sulu/blob/6766a36cc2f0c807c59202bf7540a08c4ef31192/src/Sulu/Component/Content/Document/Subscriber/RouteSubscriber.php#L225-L237 | train |
sulu/sulu | src/Sulu/Component/Content/Document/Subscriber/RouteSubscriber.php | RouteSubscriber.changeOldPathToHistoryRoutes | private function changeOldPathToHistoryRoutes(RouteBehavior $oldDocument, RouteBehavior $newDocument)
{
$oldDocument->setTargetDocument($newDocument);
$oldDocument->setHistory(true);
$oldRouteNode = $this->documentInspector->getNode($oldDocument);
$oldRouteNode->setProperty(self::NODE_HISTORY_FIELD, true);
foreach ($this->documentInspector->getReferrers($oldDocument) as $referrer) {
if ($referrer instanceof RouteBehavior) {
$referrer->setTargetDocument($newDocument);
$referrer->setHistory(true);
$this->documentManager->persist(
$referrer,
null,
[
'path' => $this->documentInspector->getPath($referrer),
]
);
$this->documentManager->publish($referrer, null);
}
}
} | php | private function changeOldPathToHistoryRoutes(RouteBehavior $oldDocument, RouteBehavior $newDocument)
{
$oldDocument->setTargetDocument($newDocument);
$oldDocument->setHistory(true);
$oldRouteNode = $this->documentInspector->getNode($oldDocument);
$oldRouteNode->setProperty(self::NODE_HISTORY_FIELD, true);
foreach ($this->documentInspector->getReferrers($oldDocument) as $referrer) {
if ($referrer instanceof RouteBehavior) {
$referrer->setTargetDocument($newDocument);
$referrer->setHistory(true);
$this->documentManager->persist(
$referrer,
null,
[
'path' => $this->documentInspector->getPath($referrer),
]
);
$this->documentManager->publish($referrer, null);
}
}
} | [
"private",
"function",
"changeOldPathToHistoryRoutes",
"(",
"RouteBehavior",
"$",
"oldDocument",
",",
"RouteBehavior",
"$",
"newDocument",
")",
"{",
"$",
"oldDocument",
"->",
"setTargetDocument",
"(",
"$",
"newDocument",
")",
";",
"$",
"oldDocument",
"->",
"setHistory",
"(",
"true",
")",
";",
"$",
"oldRouteNode",
"=",
"$",
"this",
"->",
"documentInspector",
"->",
"getNode",
"(",
"$",
"oldDocument",
")",
";",
"$",
"oldRouteNode",
"->",
"setProperty",
"(",
"self",
"::",
"NODE_HISTORY_FIELD",
",",
"true",
")",
";",
"foreach",
"(",
"$",
"this",
"->",
"documentInspector",
"->",
"getReferrers",
"(",
"$",
"oldDocument",
")",
"as",
"$",
"referrer",
")",
"{",
"if",
"(",
"$",
"referrer",
"instanceof",
"RouteBehavior",
")",
"{",
"$",
"referrer",
"->",
"setTargetDocument",
"(",
"$",
"newDocument",
")",
";",
"$",
"referrer",
"->",
"setHistory",
"(",
"true",
")",
";",
"$",
"this",
"->",
"documentManager",
"->",
"persist",
"(",
"$",
"referrer",
",",
"null",
",",
"[",
"'path'",
"=>",
"$",
"this",
"->",
"documentInspector",
"->",
"getPath",
"(",
"$",
"referrer",
")",
",",
"]",
")",
";",
"$",
"this",
"->",
"documentManager",
"->",
"publish",
"(",
"$",
"referrer",
",",
"null",
")",
";",
"}",
"}",
"}"
] | Changes the old route to a history route and redirect to the new route.
@param RouteBehavior $oldDocument
@param RouteBehavior $newDocument | [
"Changes",
"the",
"old",
"route",
"to",
"a",
"history",
"route",
"and",
"redirect",
"to",
"the",
"new",
"route",
"."
] | 6766a36cc2f0c807c59202bf7540a08c4ef31192 | https://github.com/sulu/sulu/blob/6766a36cc2f0c807c59202bf7540a08c4ef31192/src/Sulu/Component/Content/Document/Subscriber/RouteSubscriber.php#L245-L266 | train |
sulu/sulu | src/Sulu/Bundle/PageBundle/Content/PageSelectionContainer.php | PageSelectionContainer.getData | public function getData()
{
if (null === $this->data) {
$this->data = $this->loadData();
}
return $this->data;
} | php | public function getData()
{
if (null === $this->data) {
$this->data = $this->loadData();
}
return $this->data;
} | [
"public",
"function",
"getData",
"(",
")",
"{",
"if",
"(",
"null",
"===",
"$",
"this",
"->",
"data",
")",
"{",
"$",
"this",
"->",
"data",
"=",
"$",
"this",
"->",
"loadData",
"(",
")",
";",
"}",
"return",
"$",
"this",
"->",
"data",
";",
"}"
] | Lazy loads the data based on the filter criteria from the config.
@return StructureInterface[] | [
"Lazy",
"loads",
"the",
"data",
"based",
"on",
"the",
"filter",
"criteria",
"from",
"the",
"config",
"."
] | 6766a36cc2f0c807c59202bf7540a08c4ef31192 | https://github.com/sulu/sulu/blob/6766a36cc2f0c807c59202bf7540a08c4ef31192/src/Sulu/Bundle/PageBundle/Content/PageSelectionContainer.php#L110-L117 | train |
sulu/sulu | src/Sulu/Bundle/PageBundle/Content/PageSelectionContainer.php | PageSelectionContainer.loadData | private function loadData()
{
$result = [];
if (null !== $this->ids && count($this->ids) > 0) {
$this->contentQueryBuilder->init(
[
'ids' => $this->ids,
'properties' => (isset($this->params['properties']) ? $this->params['properties']->getValue() : []),
'published' => !$this->showDrafts,
]
);
$pages = $this->contentQueryExecutor->execute(
$this->webspaceKey,
[$this->languageCode],
$this->contentQueryBuilder
);
// init vars
$map = [];
// map pages
foreach ($pages as $page) {
$map[$page['uuid']] = $page;
}
foreach ($this->ids as $id) {
if (isset($map[$id])) {
$result[] = $map[$id];
}
}
}
return $result;
} | php | private function loadData()
{
$result = [];
if (null !== $this->ids && count($this->ids) > 0) {
$this->contentQueryBuilder->init(
[
'ids' => $this->ids,
'properties' => (isset($this->params['properties']) ? $this->params['properties']->getValue() : []),
'published' => !$this->showDrafts,
]
);
$pages = $this->contentQueryExecutor->execute(
$this->webspaceKey,
[$this->languageCode],
$this->contentQueryBuilder
);
// init vars
$map = [];
// map pages
foreach ($pages as $page) {
$map[$page['uuid']] = $page;
}
foreach ($this->ids as $id) {
if (isset($map[$id])) {
$result[] = $map[$id];
}
}
}
return $result;
} | [
"private",
"function",
"loadData",
"(",
")",
"{",
"$",
"result",
"=",
"[",
"]",
";",
"if",
"(",
"null",
"!==",
"$",
"this",
"->",
"ids",
"&&",
"count",
"(",
"$",
"this",
"->",
"ids",
")",
">",
"0",
")",
"{",
"$",
"this",
"->",
"contentQueryBuilder",
"->",
"init",
"(",
"[",
"'ids'",
"=>",
"$",
"this",
"->",
"ids",
",",
"'properties'",
"=>",
"(",
"isset",
"(",
"$",
"this",
"->",
"params",
"[",
"'properties'",
"]",
")",
"?",
"$",
"this",
"->",
"params",
"[",
"'properties'",
"]",
"->",
"getValue",
"(",
")",
":",
"[",
"]",
")",
",",
"'published'",
"=>",
"!",
"$",
"this",
"->",
"showDrafts",
",",
"]",
")",
";",
"$",
"pages",
"=",
"$",
"this",
"->",
"contentQueryExecutor",
"->",
"execute",
"(",
"$",
"this",
"->",
"webspaceKey",
",",
"[",
"$",
"this",
"->",
"languageCode",
"]",
",",
"$",
"this",
"->",
"contentQueryBuilder",
")",
";",
"// init vars",
"$",
"map",
"=",
"[",
"]",
";",
"// map pages",
"foreach",
"(",
"$",
"pages",
"as",
"$",
"page",
")",
"{",
"$",
"map",
"[",
"$",
"page",
"[",
"'uuid'",
"]",
"]",
"=",
"$",
"page",
";",
"}",
"foreach",
"(",
"$",
"this",
"->",
"ids",
"as",
"$",
"id",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"map",
"[",
"$",
"id",
"]",
")",
")",
"{",
"$",
"result",
"[",
"]",
"=",
"$",
"map",
"[",
"$",
"id",
"]",
";",
"}",
"}",
"}",
"return",
"$",
"result",
";",
"}"
] | lazy load data. | [
"lazy",
"load",
"data",
"."
] | 6766a36cc2f0c807c59202bf7540a08c4ef31192 | https://github.com/sulu/sulu/blob/6766a36cc2f0c807c59202bf7540a08c4ef31192/src/Sulu/Bundle/PageBundle/Content/PageSelectionContainer.php#L122-L155 | train |
sulu/sulu | src/Sulu/Component/Util/SuluVersionPass.php | SuluVersionPass.getSuluVersion | private function getSuluVersion($dir)
{
$version = '_._._';
/** @var SplFileInfo $composerFile */
$composerFile = new SplFileInfo($dir . '/composer.lock', '', '');
if (!$composerFile->isFile()) {
return $version;
}
$composer = json_decode($composerFile->getContents(), true);
foreach ($composer['packages'] as $package) {
if ('sulu/sulu' === $package['name']) {
return $package['version'];
}
}
return $version;
} | php | private function getSuluVersion($dir)
{
$version = '_._._';
/** @var SplFileInfo $composerFile */
$composerFile = new SplFileInfo($dir . '/composer.lock', '', '');
if (!$composerFile->isFile()) {
return $version;
}
$composer = json_decode($composerFile->getContents(), true);
foreach ($composer['packages'] as $package) {
if ('sulu/sulu' === $package['name']) {
return $package['version'];
}
}
return $version;
} | [
"private",
"function",
"getSuluVersion",
"(",
"$",
"dir",
")",
"{",
"$",
"version",
"=",
"'_._._'",
";",
"/** @var SplFileInfo $composerFile */",
"$",
"composerFile",
"=",
"new",
"SplFileInfo",
"(",
"$",
"dir",
".",
"'/composer.lock'",
",",
"''",
",",
"''",
")",
";",
"if",
"(",
"!",
"$",
"composerFile",
"->",
"isFile",
"(",
")",
")",
"{",
"return",
"$",
"version",
";",
"}",
"$",
"composer",
"=",
"json_decode",
"(",
"$",
"composerFile",
"->",
"getContents",
"(",
")",
",",
"true",
")",
";",
"foreach",
"(",
"$",
"composer",
"[",
"'packages'",
"]",
"as",
"$",
"package",
")",
"{",
"if",
"(",
"'sulu/sulu'",
"===",
"$",
"package",
"[",
"'name'",
"]",
")",
"{",
"return",
"$",
"package",
"[",
"'version'",
"]",
";",
"}",
"}",
"return",
"$",
"version",
";",
"}"
] | Read composer.lock file and return version of sulu.
@param string $dir
@return string | [
"Read",
"composer",
".",
"lock",
"file",
"and",
"return",
"version",
"of",
"sulu",
"."
] | 6766a36cc2f0c807c59202bf7540a08c4ef31192 | https://github.com/sulu/sulu/blob/6766a36cc2f0c807c59202bf7540a08c4ef31192/src/Sulu/Component/Util/SuluVersionPass.php#L41-L59 | train |
sulu/sulu | src/Sulu/Component/Util/SuluVersionPass.php | SuluVersionPass.getAppVersion | private function getAppVersion($dir)
{
$version = null;
/** @var SplFileInfo $composerFile */
$composerFile = new SplFileInfo($dir . '/composer.json', '', '');
if (!$composerFile->isFile()) {
return $version;
}
$composerJson = json_decode($composerFile->getContents(), true);
if (!array_key_exists('version', $composerJson)) {
return $version;
}
return $composerJson['version'];
} | php | private function getAppVersion($dir)
{
$version = null;
/** @var SplFileInfo $composerFile */
$composerFile = new SplFileInfo($dir . '/composer.json', '', '');
if (!$composerFile->isFile()) {
return $version;
}
$composerJson = json_decode($composerFile->getContents(), true);
if (!array_key_exists('version', $composerJson)) {
return $version;
}
return $composerJson['version'];
} | [
"private",
"function",
"getAppVersion",
"(",
"$",
"dir",
")",
"{",
"$",
"version",
"=",
"null",
";",
"/** @var SplFileInfo $composerFile */",
"$",
"composerFile",
"=",
"new",
"SplFileInfo",
"(",
"$",
"dir",
".",
"'/composer.json'",
",",
"''",
",",
"''",
")",
";",
"if",
"(",
"!",
"$",
"composerFile",
"->",
"isFile",
"(",
")",
")",
"{",
"return",
"$",
"version",
";",
"}",
"$",
"composerJson",
"=",
"json_decode",
"(",
"$",
"composerFile",
"->",
"getContents",
"(",
")",
",",
"true",
")",
";",
"if",
"(",
"!",
"array_key_exists",
"(",
"'version'",
",",
"$",
"composerJson",
")",
")",
"{",
"return",
"$",
"version",
";",
"}",
"return",
"$",
"composerJson",
"[",
"'version'",
"]",
";",
"}"
] | Read composer.json file and return version of app.
@param string $dir
@return string | [
"Read",
"composer",
".",
"json",
"file",
"and",
"return",
"version",
"of",
"app",
"."
] | 6766a36cc2f0c807c59202bf7540a08c4ef31192 | https://github.com/sulu/sulu/blob/6766a36cc2f0c807c59202bf7540a08c4ef31192/src/Sulu/Component/Util/SuluVersionPass.php#L68-L84 | train |
sulu/sulu | src/Sulu/Component/Rest/ListBuilder/Metadata/FieldDescriptorFactory.php | FieldDescriptorFactory.resolveOptions | private function resolveOptions($string, array $options)
{
foreach ($options as $key => $value) {
$string = str_replace(':' . $key, $value, $string);
}
return $string;
} | php | private function resolveOptions($string, array $options)
{
foreach ($options as $key => $value) {
$string = str_replace(':' . $key, $value, $string);
}
return $string;
} | [
"private",
"function",
"resolveOptions",
"(",
"$",
"string",
",",
"array",
"$",
"options",
")",
"{",
"foreach",
"(",
"$",
"options",
"as",
"$",
"key",
"=>",
"$",
"value",
")",
"{",
"$",
"string",
"=",
"str_replace",
"(",
"':'",
".",
"$",
"key",
",",
"$",
"value",
",",
"$",
"string",
")",
";",
"}",
"return",
"$",
"string",
";",
"}"
] | Resolves options for string.
@param string $string
@param array $options
@return string | [
"Resolves",
"options",
"for",
"string",
"."
] | 6766a36cc2f0c807c59202bf7540a08c4ef31192 | https://github.com/sulu/sulu/blob/6766a36cc2f0c807c59202bf7540a08c4ef31192/src/Sulu/Component/Rest/ListBuilder/Metadata/FieldDescriptorFactory.php#L331-L338 | train |
sulu/sulu | src/Sulu/Bundle/MediaBundle/Controller/MediaPreviewController.php | MediaPreviewController.postAction | public function postAction($id, Request $request)
{
try {
$mediaManager = $this->getMediaManager();
$systemCollectionManager = $this->get('sulu_media.system_collections.manager');
$locale = $this->getLocale($request);
$media = $mediaManager->getById($id, $locale);
/** @var MediaInterface $mediaEntity */
$mediaEntity = $media->getEntity();
$data = $this->getData($request, false);
// Unset id to not overwrite original file
unset($data['id']);
if (null !== $mediaEntity->getPreviewImage()) {
$data['id'] = $mediaEntity->getPreviewImage()->getId();
}
$data['collection'] = $systemCollectionManager->getSystemCollection('sulu_media.preview_image');
$data['locale'] = $locale;
$data['title'] = $media->getTitle();
$uploadedFile = $this->getUploadedFile($request, 'previewImage');
$previewImage = $mediaManager->save($uploadedFile, $data, $this->getUser()->getId());
$mediaEntity->setPreviewImage($previewImage->getEntity());
$this->getDoctrine()->getManager()->flush();
$view = $this->view($previewImage, 200);
} catch (MediaNotFoundException $e) {
$view = $this->view($e->toArray(), 404);
} catch (MediaException $e) {
$view = $this->view($e->toArray(), 400);
}
return $this->handleView($view);
} | php | public function postAction($id, Request $request)
{
try {
$mediaManager = $this->getMediaManager();
$systemCollectionManager = $this->get('sulu_media.system_collections.manager');
$locale = $this->getLocale($request);
$media = $mediaManager->getById($id, $locale);
/** @var MediaInterface $mediaEntity */
$mediaEntity = $media->getEntity();
$data = $this->getData($request, false);
// Unset id to not overwrite original file
unset($data['id']);
if (null !== $mediaEntity->getPreviewImage()) {
$data['id'] = $mediaEntity->getPreviewImage()->getId();
}
$data['collection'] = $systemCollectionManager->getSystemCollection('sulu_media.preview_image');
$data['locale'] = $locale;
$data['title'] = $media->getTitle();
$uploadedFile = $this->getUploadedFile($request, 'previewImage');
$previewImage = $mediaManager->save($uploadedFile, $data, $this->getUser()->getId());
$mediaEntity->setPreviewImage($previewImage->getEntity());
$this->getDoctrine()->getManager()->flush();
$view = $this->view($previewImage, 200);
} catch (MediaNotFoundException $e) {
$view = $this->view($e->toArray(), 404);
} catch (MediaException $e) {
$view = $this->view($e->toArray(), 400);
}
return $this->handleView($view);
} | [
"public",
"function",
"postAction",
"(",
"$",
"id",
",",
"Request",
"$",
"request",
")",
"{",
"try",
"{",
"$",
"mediaManager",
"=",
"$",
"this",
"->",
"getMediaManager",
"(",
")",
";",
"$",
"systemCollectionManager",
"=",
"$",
"this",
"->",
"get",
"(",
"'sulu_media.system_collections.manager'",
")",
";",
"$",
"locale",
"=",
"$",
"this",
"->",
"getLocale",
"(",
"$",
"request",
")",
";",
"$",
"media",
"=",
"$",
"mediaManager",
"->",
"getById",
"(",
"$",
"id",
",",
"$",
"locale",
")",
";",
"/** @var MediaInterface $mediaEntity */",
"$",
"mediaEntity",
"=",
"$",
"media",
"->",
"getEntity",
"(",
")",
";",
"$",
"data",
"=",
"$",
"this",
"->",
"getData",
"(",
"$",
"request",
",",
"false",
")",
";",
"// Unset id to not overwrite original file",
"unset",
"(",
"$",
"data",
"[",
"'id'",
"]",
")",
";",
"if",
"(",
"null",
"!==",
"$",
"mediaEntity",
"->",
"getPreviewImage",
"(",
")",
")",
"{",
"$",
"data",
"[",
"'id'",
"]",
"=",
"$",
"mediaEntity",
"->",
"getPreviewImage",
"(",
")",
"->",
"getId",
"(",
")",
";",
"}",
"$",
"data",
"[",
"'collection'",
"]",
"=",
"$",
"systemCollectionManager",
"->",
"getSystemCollection",
"(",
"'sulu_media.preview_image'",
")",
";",
"$",
"data",
"[",
"'locale'",
"]",
"=",
"$",
"locale",
";",
"$",
"data",
"[",
"'title'",
"]",
"=",
"$",
"media",
"->",
"getTitle",
"(",
")",
";",
"$",
"uploadedFile",
"=",
"$",
"this",
"->",
"getUploadedFile",
"(",
"$",
"request",
",",
"'previewImage'",
")",
";",
"$",
"previewImage",
"=",
"$",
"mediaManager",
"->",
"save",
"(",
"$",
"uploadedFile",
",",
"$",
"data",
",",
"$",
"this",
"->",
"getUser",
"(",
")",
"->",
"getId",
"(",
")",
")",
";",
"$",
"mediaEntity",
"->",
"setPreviewImage",
"(",
"$",
"previewImage",
"->",
"getEntity",
"(",
")",
")",
";",
"$",
"this",
"->",
"getDoctrine",
"(",
")",
"->",
"getManager",
"(",
")",
"->",
"flush",
"(",
")",
";",
"$",
"view",
"=",
"$",
"this",
"->",
"view",
"(",
"$",
"previewImage",
",",
"200",
")",
";",
"}",
"catch",
"(",
"MediaNotFoundException",
"$",
"e",
")",
"{",
"$",
"view",
"=",
"$",
"this",
"->",
"view",
"(",
"$",
"e",
"->",
"toArray",
"(",
")",
",",
"404",
")",
";",
"}",
"catch",
"(",
"MediaException",
"$",
"e",
")",
"{",
"$",
"view",
"=",
"$",
"this",
"->",
"view",
"(",
"$",
"e",
"->",
"toArray",
"(",
")",
",",
"400",
")",
";",
"}",
"return",
"$",
"this",
"->",
"handleView",
"(",
"$",
"view",
")",
";",
"}"
] | Creates a new preview image and saves it to the provided media.
@Post("media/{id}/preview")
@param int $id
@param Request $request
@return \Symfony\Component\HttpFoundation\Response
@throws \Sulu\Bundle\MediaBundle\Media\Exception\CollectionNotFoundException | [
"Creates",
"a",
"new",
"preview",
"image",
"and",
"saves",
"it",
"to",
"the",
"provided",
"media",
"."
] | 6766a36cc2f0c807c59202bf7540a08c4ef31192 | https://github.com/sulu/sulu/blob/6766a36cc2f0c807c59202bf7540a08c4ef31192/src/Sulu/Bundle/MediaBundle/Controller/MediaPreviewController.php#L42-L81 | train |
sulu/sulu | src/Sulu/Bundle/MediaBundle/Controller/MediaPreviewController.php | MediaPreviewController.deleteAction | public function deleteAction($id, Request $request)
{
try {
$mediaManager = $this->getMediaManager();
$locale = $this->getLocale($request);
$media = $mediaManager->getById($id, $locale);
/** @var MediaInterface $mediaEntity */
$mediaEntity = $media->getEntity();
if (null !== $mediaEntity->getPreviewImage()) {
$oldPreviewImageId = $mediaEntity->getPreviewImage()->getId();
$mediaEntity->setPreviewImage(null);
$mediaManager->delete($oldPreviewImageId);
}
$view = $this->view(null, 204);
} catch (MediaNotFoundException $e) {
$view = $this->view($e->toArray(), 404);
} catch (MediaException $e) {
$view = $this->view($e->toArray(), 400);
}
return $this->handleView($view);
} | php | public function deleteAction($id, Request $request)
{
try {
$mediaManager = $this->getMediaManager();
$locale = $this->getLocale($request);
$media = $mediaManager->getById($id, $locale);
/** @var MediaInterface $mediaEntity */
$mediaEntity = $media->getEntity();
if (null !== $mediaEntity->getPreviewImage()) {
$oldPreviewImageId = $mediaEntity->getPreviewImage()->getId();
$mediaEntity->setPreviewImage(null);
$mediaManager->delete($oldPreviewImageId);
}
$view = $this->view(null, 204);
} catch (MediaNotFoundException $e) {
$view = $this->view($e->toArray(), 404);
} catch (MediaException $e) {
$view = $this->view($e->toArray(), 400);
}
return $this->handleView($view);
} | [
"public",
"function",
"deleteAction",
"(",
"$",
"id",
",",
"Request",
"$",
"request",
")",
"{",
"try",
"{",
"$",
"mediaManager",
"=",
"$",
"this",
"->",
"getMediaManager",
"(",
")",
";",
"$",
"locale",
"=",
"$",
"this",
"->",
"getLocale",
"(",
"$",
"request",
")",
";",
"$",
"media",
"=",
"$",
"mediaManager",
"->",
"getById",
"(",
"$",
"id",
",",
"$",
"locale",
")",
";",
"/** @var MediaInterface $mediaEntity */",
"$",
"mediaEntity",
"=",
"$",
"media",
"->",
"getEntity",
"(",
")",
";",
"if",
"(",
"null",
"!==",
"$",
"mediaEntity",
"->",
"getPreviewImage",
"(",
")",
")",
"{",
"$",
"oldPreviewImageId",
"=",
"$",
"mediaEntity",
"->",
"getPreviewImage",
"(",
")",
"->",
"getId",
"(",
")",
";",
"$",
"mediaEntity",
"->",
"setPreviewImage",
"(",
"null",
")",
";",
"$",
"mediaManager",
"->",
"delete",
"(",
"$",
"oldPreviewImageId",
")",
";",
"}",
"$",
"view",
"=",
"$",
"this",
"->",
"view",
"(",
"null",
",",
"204",
")",
";",
"}",
"catch",
"(",
"MediaNotFoundException",
"$",
"e",
")",
"{",
"$",
"view",
"=",
"$",
"this",
"->",
"view",
"(",
"$",
"e",
"->",
"toArray",
"(",
")",
",",
"404",
")",
";",
"}",
"catch",
"(",
"MediaException",
"$",
"e",
")",
"{",
"$",
"view",
"=",
"$",
"this",
"->",
"view",
"(",
"$",
"e",
"->",
"toArray",
"(",
")",
",",
"400",
")",
";",
"}",
"return",
"$",
"this",
"->",
"handleView",
"(",
"$",
"view",
")",
";",
"}"
] | Removes current preview image and sets default video thumbnail.
@Delete("media/{id}/preview")
@param $id
@param Request $request
@return \Symfony\Component\HttpFoundation\Response | [
"Removes",
"current",
"preview",
"image",
"and",
"sets",
"default",
"video",
"thumbnail",
"."
] | 6766a36cc2f0c807c59202bf7540a08c4ef31192 | https://github.com/sulu/sulu/blob/6766a36cc2f0c807c59202bf7540a08c4ef31192/src/Sulu/Bundle/MediaBundle/Controller/MediaPreviewController.php#L93-L120 | train |
sulu/sulu | src/Sulu/Component/Rest/Listing/ListQueryBuilder.php | ListQueryBuilder.find | public function find($prefix = 'u')
{
$selectFromDQL = $this->getSelectFrom($prefix);
$whereDQL = $this->getWhere($prefix);
if (true != $this->countQuery) {
$orderDQL = $this->getOrderBy($prefix);
} else {
$orderDQL = '';
}
$dql = sprintf('%s %s %s', $selectFromDQL, $whereDQL, $orderDQL);
return $dql;
} | php | public function find($prefix = 'u')
{
$selectFromDQL = $this->getSelectFrom($prefix);
$whereDQL = $this->getWhere($prefix);
if (true != $this->countQuery) {
$orderDQL = $this->getOrderBy($prefix);
} else {
$orderDQL = '';
}
$dql = sprintf('%s %s %s', $selectFromDQL, $whereDQL, $orderDQL);
return $dql;
} | [
"public",
"function",
"find",
"(",
"$",
"prefix",
"=",
"'u'",
")",
"{",
"$",
"selectFromDQL",
"=",
"$",
"this",
"->",
"getSelectFrom",
"(",
"$",
"prefix",
")",
";",
"$",
"whereDQL",
"=",
"$",
"this",
"->",
"getWhere",
"(",
"$",
"prefix",
")",
";",
"if",
"(",
"true",
"!=",
"$",
"this",
"->",
"countQuery",
")",
"{",
"$",
"orderDQL",
"=",
"$",
"this",
"->",
"getOrderBy",
"(",
"$",
"prefix",
")",
";",
"}",
"else",
"{",
"$",
"orderDQL",
"=",
"''",
";",
"}",
"$",
"dql",
"=",
"sprintf",
"(",
"'%s %s %s'",
",",
"$",
"selectFromDQL",
",",
"$",
"whereDQL",
",",
"$",
"orderDQL",
")",
";",
"return",
"$",
"dql",
";",
"}"
] | Searches Entity by filter for fields, pagination and sorted by a column.
@param string $prefix Prefix for starting Table
@return string | [
"Searches",
"Entity",
"by",
"filter",
"for",
"fields",
"pagination",
"and",
"sorted",
"by",
"a",
"column",
"."
] | 6766a36cc2f0c807c59202bf7540a08c4ef31192 | https://github.com/sulu/sulu/blob/6766a36cc2f0c807c59202bf7540a08c4ef31192/src/Sulu/Component/Rest/Listing/ListQueryBuilder.php#L175-L187 | train |
sulu/sulu | src/Sulu/Component/Rest/Listing/ListQueryBuilder.php | ListQueryBuilder.justCount | public function justCount($countAttribute = 'u.id', $alias = 'totalcount')
{
$this->countQuery = true;
$this->replaceSelect = 'COUNT(' . $countAttribute . ') as ' . $alias;
} | php | public function justCount($countAttribute = 'u.id', $alias = 'totalcount')
{
$this->countQuery = true;
$this->replaceSelect = 'COUNT(' . $countAttribute . ') as ' . $alias;
} | [
"public",
"function",
"justCount",
"(",
"$",
"countAttribute",
"=",
"'u.id'",
",",
"$",
"alias",
"=",
"'totalcount'",
")",
"{",
"$",
"this",
"->",
"countQuery",
"=",
"true",
";",
"$",
"this",
"->",
"replaceSelect",
"=",
"'COUNT('",
".",
"$",
"countAttribute",
".",
"') as '",
".",
"$",
"alias",
";",
"}"
] | just return count. | [
"just",
"return",
"count",
"."
] | 6766a36cc2f0c807c59202bf7540a08c4ef31192 | https://github.com/sulu/sulu/blob/6766a36cc2f0c807c59202bf7540a08c4ef31192/src/Sulu/Component/Rest/Listing/ListQueryBuilder.php#L192-L196 | train |
sulu/sulu | src/Sulu/Component/Rest/Listing/ListQueryBuilder.php | ListQueryBuilder.getSelectFrom | private function getSelectFrom($prefix = 'u')
{
$this->joins = '';
$this->prefixes = [$prefix];
// select and where fields
$fieldsWhere = array_merge(
(null != $this->fields) ? $this->fields : [],
array_keys($this->where)
);
$fieldsWhere = array_merge($fieldsWhere, $this->searchTextFields, $this->searchNumberFields);
if (null != $fieldsWhere && count($fieldsWhere) >= 0) {
foreach ($fieldsWhere as $field) {
$this->performSelectFromField($field, $prefix);
}
}
// if no field is selected take prefix
if (true === $this->countQuery) {
$this->select = $this->replaceSelect;
} elseif (0 == strlen($this->select)) {
$this->select = $prefix;
}
$dql = 'SELECT %s
FROM %s %s
%s';
return sprintf($dql, $this->select, $this->entityName, $prefix, $this->joins);
} | php | private function getSelectFrom($prefix = 'u')
{
$this->joins = '';
$this->prefixes = [$prefix];
// select and where fields
$fieldsWhere = array_merge(
(null != $this->fields) ? $this->fields : [],
array_keys($this->where)
);
$fieldsWhere = array_merge($fieldsWhere, $this->searchTextFields, $this->searchNumberFields);
if (null != $fieldsWhere && count($fieldsWhere) >= 0) {
foreach ($fieldsWhere as $field) {
$this->performSelectFromField($field, $prefix);
}
}
// if no field is selected take prefix
if (true === $this->countQuery) {
$this->select = $this->replaceSelect;
} elseif (0 == strlen($this->select)) {
$this->select = $prefix;
}
$dql = 'SELECT %s
FROM %s %s
%s';
return sprintf($dql, $this->select, $this->entityName, $prefix, $this->joins);
} | [
"private",
"function",
"getSelectFrom",
"(",
"$",
"prefix",
"=",
"'u'",
")",
"{",
"$",
"this",
"->",
"joins",
"=",
"''",
";",
"$",
"this",
"->",
"prefixes",
"=",
"[",
"$",
"prefix",
"]",
";",
"// select and where fields",
"$",
"fieldsWhere",
"=",
"array_merge",
"(",
"(",
"null",
"!=",
"$",
"this",
"->",
"fields",
")",
"?",
"$",
"this",
"->",
"fields",
":",
"[",
"]",
",",
"array_keys",
"(",
"$",
"this",
"->",
"where",
")",
")",
";",
"$",
"fieldsWhere",
"=",
"array_merge",
"(",
"$",
"fieldsWhere",
",",
"$",
"this",
"->",
"searchTextFields",
",",
"$",
"this",
"->",
"searchNumberFields",
")",
";",
"if",
"(",
"null",
"!=",
"$",
"fieldsWhere",
"&&",
"count",
"(",
"$",
"fieldsWhere",
")",
">=",
"0",
")",
"{",
"foreach",
"(",
"$",
"fieldsWhere",
"as",
"$",
"field",
")",
"{",
"$",
"this",
"->",
"performSelectFromField",
"(",
"$",
"field",
",",
"$",
"prefix",
")",
";",
"}",
"}",
"// if no field is selected take prefix",
"if",
"(",
"true",
"===",
"$",
"this",
"->",
"countQuery",
")",
"{",
"$",
"this",
"->",
"select",
"=",
"$",
"this",
"->",
"replaceSelect",
";",
"}",
"elseif",
"(",
"0",
"==",
"strlen",
"(",
"$",
"this",
"->",
"select",
")",
")",
"{",
"$",
"this",
"->",
"select",
"=",
"$",
"prefix",
";",
"}",
"$",
"dql",
"=",
"'SELECT %s\n FROM %s %s\n %s'",
";",
"return",
"sprintf",
"(",
"$",
"dql",
",",
"$",
"this",
"->",
"select",
",",
"$",
"this",
"->",
"entityName",
",",
"$",
"prefix",
",",
"$",
"this",
"->",
"joins",
")",
";",
"}"
] | Create a Select ... From ... Statement for given fields with joins.
@param string $prefix
@return string | [
"Create",
"a",
"Select",
"...",
"From",
"...",
"Statement",
"for",
"given",
"fields",
"with",
"joins",
"."
] | 6766a36cc2f0c807c59202bf7540a08c4ef31192 | https://github.com/sulu/sulu/blob/6766a36cc2f0c807c59202bf7540a08c4ef31192/src/Sulu/Component/Rest/Listing/ListQueryBuilder.php#L205-L235 | train |
sulu/sulu | src/Sulu/Component/Rest/Listing/ListQueryBuilder.php | ListQueryBuilder.performSelectFromField | private function performSelectFromField($field, $prefix = 'u')
{
// Relation name and field delimited by underscore
$fieldParts = explode('_', $field);
// temporary variable for saving field name (needed for array results like [0])
$realFieldName = $field;
// check if a certain field number is searched
if (preg_match('/^(.*)\[(\d+)\]$/', $fieldParts[0], $regresult)) {
$fieldParts[0] = $regresult[1];
$realFieldName = implode('_', $fieldParts);
$this->relationalFilters[$realFieldName] = $regresult[2];
}
// If field is delimited and is a Relation
if (count($fieldParts) >= 2 && $this->isRelation($fieldParts[0])) {
$this->joins .= $this->generateJoins($fieldParts, $prefix);
if (in_array($field, $this->fields)) {
// last element is column name and next-to-last is the associationPrefix
$i = count($fieldParts) - 1;
// {associationPrefix}.{columnName} {alias}
$parent = $fieldParts[$i - 1];
$tempField = $fieldParts[$i];
$alias = $realFieldName;
$this->addToSelect($parent, $tempField, $alias);
}
} elseif (in_array($field, $this->fields) && in_array($field, $this->fieldNames)) {
$this->addToSelect($prefix, $field);
}
} | php | private function performSelectFromField($field, $prefix = 'u')
{
// Relation name and field delimited by underscore
$fieldParts = explode('_', $field);
// temporary variable for saving field name (needed for array results like [0])
$realFieldName = $field;
// check if a certain field number is searched
if (preg_match('/^(.*)\[(\d+)\]$/', $fieldParts[0], $regresult)) {
$fieldParts[0] = $regresult[1];
$realFieldName = implode('_', $fieldParts);
$this->relationalFilters[$realFieldName] = $regresult[2];
}
// If field is delimited and is a Relation
if (count($fieldParts) >= 2 && $this->isRelation($fieldParts[0])) {
$this->joins .= $this->generateJoins($fieldParts, $prefix);
if (in_array($field, $this->fields)) {
// last element is column name and next-to-last is the associationPrefix
$i = count($fieldParts) - 1;
// {associationPrefix}.{columnName} {alias}
$parent = $fieldParts[$i - 1];
$tempField = $fieldParts[$i];
$alias = $realFieldName;
$this->addToSelect($parent, $tempField, $alias);
}
} elseif (in_array($field, $this->fields) && in_array($field, $this->fieldNames)) {
$this->addToSelect($prefix, $field);
}
} | [
"private",
"function",
"performSelectFromField",
"(",
"$",
"field",
",",
"$",
"prefix",
"=",
"'u'",
")",
"{",
"// Relation name and field delimited by underscore",
"$",
"fieldParts",
"=",
"explode",
"(",
"'_'",
",",
"$",
"field",
")",
";",
"// temporary variable for saving field name (needed for array results like [0])",
"$",
"realFieldName",
"=",
"$",
"field",
";",
"// check if a certain field number is searched",
"if",
"(",
"preg_match",
"(",
"'/^(.*)\\[(\\d+)\\]$/'",
",",
"$",
"fieldParts",
"[",
"0",
"]",
",",
"$",
"regresult",
")",
")",
"{",
"$",
"fieldParts",
"[",
"0",
"]",
"=",
"$",
"regresult",
"[",
"1",
"]",
";",
"$",
"realFieldName",
"=",
"implode",
"(",
"'_'",
",",
"$",
"fieldParts",
")",
";",
"$",
"this",
"->",
"relationalFilters",
"[",
"$",
"realFieldName",
"]",
"=",
"$",
"regresult",
"[",
"2",
"]",
";",
"}",
"// If field is delimited and is a Relation",
"if",
"(",
"count",
"(",
"$",
"fieldParts",
")",
">=",
"2",
"&&",
"$",
"this",
"->",
"isRelation",
"(",
"$",
"fieldParts",
"[",
"0",
"]",
")",
")",
"{",
"$",
"this",
"->",
"joins",
".=",
"$",
"this",
"->",
"generateJoins",
"(",
"$",
"fieldParts",
",",
"$",
"prefix",
")",
";",
"if",
"(",
"in_array",
"(",
"$",
"field",
",",
"$",
"this",
"->",
"fields",
")",
")",
"{",
"// last element is column name and next-to-last is the associationPrefix",
"$",
"i",
"=",
"count",
"(",
"$",
"fieldParts",
")",
"-",
"1",
";",
"// {associationPrefix}.{columnName} {alias}",
"$",
"parent",
"=",
"$",
"fieldParts",
"[",
"$",
"i",
"-",
"1",
"]",
";",
"$",
"tempField",
"=",
"$",
"fieldParts",
"[",
"$",
"i",
"]",
";",
"$",
"alias",
"=",
"$",
"realFieldName",
";",
"$",
"this",
"->",
"addToSelect",
"(",
"$",
"parent",
",",
"$",
"tempField",
",",
"$",
"alias",
")",
";",
"}",
"}",
"elseif",
"(",
"in_array",
"(",
"$",
"field",
",",
"$",
"this",
"->",
"fields",
")",
"&&",
"in_array",
"(",
"$",
"field",
",",
"$",
"this",
"->",
"fieldNames",
")",
")",
"{",
"$",
"this",
"->",
"addToSelect",
"(",
"$",
"prefix",
",",
"$",
"field",
")",
";",
"}",
"}"
] | solves the relations for a single field and generate dql for select and joins.
@param string $field
@param string $prefix | [
"solves",
"the",
"relations",
"for",
"a",
"single",
"field",
"and",
"generate",
"dql",
"for",
"select",
"and",
"joins",
"."
] | 6766a36cc2f0c807c59202bf7540a08c4ef31192 | https://github.com/sulu/sulu/blob/6766a36cc2f0c807c59202bf7540a08c4ef31192/src/Sulu/Component/Rest/Listing/ListQueryBuilder.php#L243-L274 | train |
sulu/sulu | src/Sulu/Component/Rest/Listing/ListQueryBuilder.php | ListQueryBuilder.generateJoinCondition | private function generateJoinCondition($field)
{
if (!array_key_exists($field, $this->joinConditions)) {
return '';
}
// ON {joinConditino}
$format = ' WITH %s';
return sprintf($format, $this->joinConditions[$field]);
} | php | private function generateJoinCondition($field)
{
if (!array_key_exists($field, $this->joinConditions)) {
return '';
}
// ON {joinConditino}
$format = ' WITH %s';
return sprintf($format, $this->joinConditions[$field]);
} | [
"private",
"function",
"generateJoinCondition",
"(",
"$",
"field",
")",
"{",
"if",
"(",
"!",
"array_key_exists",
"(",
"$",
"field",
",",
"$",
"this",
"->",
"joinConditions",
")",
")",
"{",
"return",
"''",
";",
"}",
"// ON {joinConditino}",
"$",
"format",
"=",
"' WITH %s'",
";",
"return",
"sprintf",
"(",
"$",
"format",
",",
"$",
"this",
"->",
"joinConditions",
"[",
"$",
"field",
"]",
")",
";",
"}"
] | generates the join condition.
@param $field
@return string | [
"generates",
"the",
"join",
"condition",
"."
] | 6766a36cc2f0c807c59202bf7540a08c4ef31192 | https://github.com/sulu/sulu/blob/6766a36cc2f0c807c59202bf7540a08c4ef31192/src/Sulu/Component/Rest/Listing/ListQueryBuilder.php#L359-L369 | train |
sulu/sulu | src/Sulu/Component/Rest/Listing/ListQueryBuilder.php | ListQueryBuilder.getWhere | private function getWhere($prefix)
{
$result = '';
// Only return where clause if there actually is some data
if (count($this->where) > 0 || count($this->searchFields) > 0) {
$wheres = [];
$searches = [];
$whereKeys = array_keys($this->where);
// Get all fields which will appear in the where clause
// The search fields already have the right format, and we have to use only the keys of where, because its
// values contain the filter expression
$fields = array_unique(array_merge($whereKeys, $this->searchFields));
foreach ($fields as $key) {
$keys = explode('_', $key);
$prefixActual = $prefix;
if (1 == count($keys)) {
$col = $keys[0];
} else {
$i = count($keys);
$prefixActual = $keys[$i - 2];
$col = $keys[$i - 1];
}
// Add where clause y.z for x_y_z
// FIXME DQL injection?
if (in_array($key, $whereKeys)) {
$wheres[] = $prefixActual . '.' . $col . ' = ' . $this->where[$key];
}
if (in_array($key, $this->searchFields)) {
$comparator = '=';
$search = ':strictSearch';
// search by like
if (in_array($key, $this->searchTextFields)) {
$comparator = 'LIKE';
$search = ':search';
}
$searches[] = $prefixActual . '.' . $col . ' ' . $comparator . ' ' . $search;
}
}
// concatenate the query
if (!empty($wheres)) {
$result .= implode(' AND ', $wheres);
}
if (!empty($searches)) {
if ('' != $result) {
$result .= ' AND ';
}
$result .= '(' . implode(' OR ', $searches) . ')';
}
$result = 'WHERE ' . $result;
}
return $result;
} | php | private function getWhere($prefix)
{
$result = '';
// Only return where clause if there actually is some data
if (count($this->where) > 0 || count($this->searchFields) > 0) {
$wheres = [];
$searches = [];
$whereKeys = array_keys($this->where);
// Get all fields which will appear in the where clause
// The search fields already have the right format, and we have to use only the keys of where, because its
// values contain the filter expression
$fields = array_unique(array_merge($whereKeys, $this->searchFields));
foreach ($fields as $key) {
$keys = explode('_', $key);
$prefixActual = $prefix;
if (1 == count($keys)) {
$col = $keys[0];
} else {
$i = count($keys);
$prefixActual = $keys[$i - 2];
$col = $keys[$i - 1];
}
// Add where clause y.z for x_y_z
// FIXME DQL injection?
if (in_array($key, $whereKeys)) {
$wheres[] = $prefixActual . '.' . $col . ' = ' . $this->where[$key];
}
if (in_array($key, $this->searchFields)) {
$comparator = '=';
$search = ':strictSearch';
// search by like
if (in_array($key, $this->searchTextFields)) {
$comparator = 'LIKE';
$search = ':search';
}
$searches[] = $prefixActual . '.' . $col . ' ' . $comparator . ' ' . $search;
}
}
// concatenate the query
if (!empty($wheres)) {
$result .= implode(' AND ', $wheres);
}
if (!empty($searches)) {
if ('' != $result) {
$result .= ' AND ';
}
$result .= '(' . implode(' OR ', $searches) . ')';
}
$result = 'WHERE ' . $result;
}
return $result;
} | [
"private",
"function",
"getWhere",
"(",
"$",
"prefix",
")",
"{",
"$",
"result",
"=",
"''",
";",
"// Only return where clause if there actually is some data",
"if",
"(",
"count",
"(",
"$",
"this",
"->",
"where",
")",
">",
"0",
"||",
"count",
"(",
"$",
"this",
"->",
"searchFields",
")",
">",
"0",
")",
"{",
"$",
"wheres",
"=",
"[",
"]",
";",
"$",
"searches",
"=",
"[",
"]",
";",
"$",
"whereKeys",
"=",
"array_keys",
"(",
"$",
"this",
"->",
"where",
")",
";",
"// Get all fields which will appear in the where clause",
"// The search fields already have the right format, and we have to use only the keys of where, because its",
"// values contain the filter expression",
"$",
"fields",
"=",
"array_unique",
"(",
"array_merge",
"(",
"$",
"whereKeys",
",",
"$",
"this",
"->",
"searchFields",
")",
")",
";",
"foreach",
"(",
"$",
"fields",
"as",
"$",
"key",
")",
"{",
"$",
"keys",
"=",
"explode",
"(",
"'_'",
",",
"$",
"key",
")",
";",
"$",
"prefixActual",
"=",
"$",
"prefix",
";",
"if",
"(",
"1",
"==",
"count",
"(",
"$",
"keys",
")",
")",
"{",
"$",
"col",
"=",
"$",
"keys",
"[",
"0",
"]",
";",
"}",
"else",
"{",
"$",
"i",
"=",
"count",
"(",
"$",
"keys",
")",
";",
"$",
"prefixActual",
"=",
"$",
"keys",
"[",
"$",
"i",
"-",
"2",
"]",
";",
"$",
"col",
"=",
"$",
"keys",
"[",
"$",
"i",
"-",
"1",
"]",
";",
"}",
"// Add where clause y.z for x_y_z",
"// FIXME DQL injection?",
"if",
"(",
"in_array",
"(",
"$",
"key",
",",
"$",
"whereKeys",
")",
")",
"{",
"$",
"wheres",
"[",
"]",
"=",
"$",
"prefixActual",
".",
"'.'",
".",
"$",
"col",
".",
"' = '",
".",
"$",
"this",
"->",
"where",
"[",
"$",
"key",
"]",
";",
"}",
"if",
"(",
"in_array",
"(",
"$",
"key",
",",
"$",
"this",
"->",
"searchFields",
")",
")",
"{",
"$",
"comparator",
"=",
"'='",
";",
"$",
"search",
"=",
"':strictSearch'",
";",
"// search by like",
"if",
"(",
"in_array",
"(",
"$",
"key",
",",
"$",
"this",
"->",
"searchTextFields",
")",
")",
"{",
"$",
"comparator",
"=",
"'LIKE'",
";",
"$",
"search",
"=",
"':search'",
";",
"}",
"$",
"searches",
"[",
"]",
"=",
"$",
"prefixActual",
".",
"'.'",
".",
"$",
"col",
".",
"' '",
".",
"$",
"comparator",
".",
"' '",
".",
"$",
"search",
";",
"}",
"}",
"// concatenate the query",
"if",
"(",
"!",
"empty",
"(",
"$",
"wheres",
")",
")",
"{",
"$",
"result",
".=",
"implode",
"(",
"' AND '",
",",
"$",
"wheres",
")",
";",
"}",
"if",
"(",
"!",
"empty",
"(",
"$",
"searches",
")",
")",
"{",
"if",
"(",
"''",
"!=",
"$",
"result",
")",
"{",
"$",
"result",
".=",
"' AND '",
";",
"}",
"$",
"result",
".=",
"'('",
".",
"implode",
"(",
"' OR '",
",",
"$",
"searches",
")",
".",
"')'",
";",
"}",
"$",
"result",
"=",
"'WHERE '",
".",
"$",
"result",
";",
"}",
"return",
"$",
"result",
";",
"}"
] | Get DQL for Where clause.
@param string $prefix
@return string | [
"Get",
"DQL",
"for",
"Where",
"clause",
"."
] | 6766a36cc2f0c807c59202bf7540a08c4ef31192 | https://github.com/sulu/sulu/blob/6766a36cc2f0c807c59202bf7540a08c4ef31192/src/Sulu/Component/Rest/Listing/ListQueryBuilder.php#L390-L449 | train |
sulu/sulu | src/Sulu/Component/Rest/Listing/ListQueryBuilder.php | ListQueryBuilder.getOrderBy | private function getOrderBy($prefix)
{
$result = '';
// If sorting is defined
if (null != $this->sorting && count($this->sorting) > 0) {
$orderBy = '';
// TODO OrderBy relations translations_value
foreach ($this->sorting as $col => $dir) {
if (strlen($orderBy) > 0) {
$orderBy .= ', ';
}
$orderBy .= $prefix . '.' . $col . ' ' . $dir;
}
$result .= '
ORDER BY ' . $orderBy;
}
return $result;
} | php | private function getOrderBy($prefix)
{
$result = '';
// If sorting is defined
if (null != $this->sorting && count($this->sorting) > 0) {
$orderBy = '';
// TODO OrderBy relations translations_value
foreach ($this->sorting as $col => $dir) {
if (strlen($orderBy) > 0) {
$orderBy .= ', ';
}
$orderBy .= $prefix . '.' . $col . ' ' . $dir;
}
$result .= '
ORDER BY ' . $orderBy;
}
return $result;
} | [
"private",
"function",
"getOrderBy",
"(",
"$",
"prefix",
")",
"{",
"$",
"result",
"=",
"''",
";",
"// If sorting is defined",
"if",
"(",
"null",
"!=",
"$",
"this",
"->",
"sorting",
"&&",
"count",
"(",
"$",
"this",
"->",
"sorting",
")",
">",
"0",
")",
"{",
"$",
"orderBy",
"=",
"''",
";",
"// TODO OrderBy relations translations_value",
"foreach",
"(",
"$",
"this",
"->",
"sorting",
"as",
"$",
"col",
"=>",
"$",
"dir",
")",
"{",
"if",
"(",
"strlen",
"(",
"$",
"orderBy",
")",
">",
"0",
")",
"{",
"$",
"orderBy",
".=",
"', '",
";",
"}",
"$",
"orderBy",
".=",
"$",
"prefix",
".",
"'.'",
".",
"$",
"col",
".",
"' '",
".",
"$",
"dir",
";",
"}",
"$",
"result",
".=",
"'\n ORDER BY '",
".",
"$",
"orderBy",
";",
"}",
"return",
"$",
"result",
";",
"}"
] | Get DQL for Sorting.
@param string $prefix
@return string | [
"Get",
"DQL",
"for",
"Sorting",
"."
] | 6766a36cc2f0c807c59202bf7540a08c4ef31192 | https://github.com/sulu/sulu/blob/6766a36cc2f0c807c59202bf7540a08c4ef31192/src/Sulu/Component/Rest/Listing/ListQueryBuilder.php#L458-L476 | train |
sulu/sulu | src/Sulu/Bundle/ContactBundle/Entity/Phone.php | Phone.setPhoneType | public function setPhoneType(\Sulu\Bundle\ContactBundle\Entity\PhoneType $phoneType)
{
$this->phoneType = $phoneType;
return $this;
} | php | public function setPhoneType(\Sulu\Bundle\ContactBundle\Entity\PhoneType $phoneType)
{
$this->phoneType = $phoneType;
return $this;
} | [
"public",
"function",
"setPhoneType",
"(",
"\\",
"Sulu",
"\\",
"Bundle",
"\\",
"ContactBundle",
"\\",
"Entity",
"\\",
"PhoneType",
"$",
"phoneType",
")",
"{",
"$",
"this",
"->",
"phoneType",
"=",
"$",
"phoneType",
";",
"return",
"$",
"this",
";",
"}"
] | Set phoneType.
@param \Sulu\Bundle\ContactBundle\Entity\PhoneType $phoneType
@return Phone | [
"Set",
"phoneType",
"."
] | 6766a36cc2f0c807c59202bf7540a08c4ef31192 | https://github.com/sulu/sulu/blob/6766a36cc2f0c807c59202bf7540a08c4ef31192/src/Sulu/Bundle/ContactBundle/Entity/Phone.php#L102-L107 | train |
sulu/sulu | src/Sulu/Component/Snippet/Import/SnippetImport.php | SnippetImport.import | public function import($locale, $filePath, OutputInterface $output = null, $format = '1.2.xliff')
{
$parsedDataList = $this->getParser($format)->parse($filePath, $locale);
$failedImports = [];
$importedCounter = 0;
$successCounter = 0;
if (null === $output) {
$output = new NullOutput();
}
$progress = new ProgressBar($output, count($parsedDataList));
$progress->setFormat(' %current%/%max% [%bar%] %percent:3s%% %elapsed:6s%/%estimated:-6s% %memory:6s%');
$progress->start();
foreach ($parsedDataList as $parsedData) {
++$importedCounter;
if (!$this->importDocument($parsedData, $locale, $format)) {
$failedImports[] = $parsedData;
} else {
++$successCounter;
}
$this->logger->info(sprintf('Document %s/%s', $importedCounter, count($parsedDataList)));
$progress->advance();
}
$progress->finish();
$return = new \stdClass();
$return->count = $importedCounter;
$return->fails = count($failedImports);
$return->successes = $successCounter;
$return->failed = $failedImports;
$return->exceptionStore = $this->exceptionStore;
return $return;
} | php | public function import($locale, $filePath, OutputInterface $output = null, $format = '1.2.xliff')
{
$parsedDataList = $this->getParser($format)->parse($filePath, $locale);
$failedImports = [];
$importedCounter = 0;
$successCounter = 0;
if (null === $output) {
$output = new NullOutput();
}
$progress = new ProgressBar($output, count($parsedDataList));
$progress->setFormat(' %current%/%max% [%bar%] %percent:3s%% %elapsed:6s%/%estimated:-6s% %memory:6s%');
$progress->start();
foreach ($parsedDataList as $parsedData) {
++$importedCounter;
if (!$this->importDocument($parsedData, $locale, $format)) {
$failedImports[] = $parsedData;
} else {
++$successCounter;
}
$this->logger->info(sprintf('Document %s/%s', $importedCounter, count($parsedDataList)));
$progress->advance();
}
$progress->finish();
$return = new \stdClass();
$return->count = $importedCounter;
$return->fails = count($failedImports);
$return->successes = $successCounter;
$return->failed = $failedImports;
$return->exceptionStore = $this->exceptionStore;
return $return;
} | [
"public",
"function",
"import",
"(",
"$",
"locale",
",",
"$",
"filePath",
",",
"OutputInterface",
"$",
"output",
"=",
"null",
",",
"$",
"format",
"=",
"'1.2.xliff'",
")",
"{",
"$",
"parsedDataList",
"=",
"$",
"this",
"->",
"getParser",
"(",
"$",
"format",
")",
"->",
"parse",
"(",
"$",
"filePath",
",",
"$",
"locale",
")",
";",
"$",
"failedImports",
"=",
"[",
"]",
";",
"$",
"importedCounter",
"=",
"0",
";",
"$",
"successCounter",
"=",
"0",
";",
"if",
"(",
"null",
"===",
"$",
"output",
")",
"{",
"$",
"output",
"=",
"new",
"NullOutput",
"(",
")",
";",
"}",
"$",
"progress",
"=",
"new",
"ProgressBar",
"(",
"$",
"output",
",",
"count",
"(",
"$",
"parsedDataList",
")",
")",
";",
"$",
"progress",
"->",
"setFormat",
"(",
"' %current%/%max% [%bar%] %percent:3s%% %elapsed:6s%/%estimated:-6s% %memory:6s%'",
")",
";",
"$",
"progress",
"->",
"start",
"(",
")",
";",
"foreach",
"(",
"$",
"parsedDataList",
"as",
"$",
"parsedData",
")",
"{",
"++",
"$",
"importedCounter",
";",
"if",
"(",
"!",
"$",
"this",
"->",
"importDocument",
"(",
"$",
"parsedData",
",",
"$",
"locale",
",",
"$",
"format",
")",
")",
"{",
"$",
"failedImports",
"[",
"]",
"=",
"$",
"parsedData",
";",
"}",
"else",
"{",
"++",
"$",
"successCounter",
";",
"}",
"$",
"this",
"->",
"logger",
"->",
"info",
"(",
"sprintf",
"(",
"'Document %s/%s'",
",",
"$",
"importedCounter",
",",
"count",
"(",
"$",
"parsedDataList",
")",
")",
")",
";",
"$",
"progress",
"->",
"advance",
"(",
")",
";",
"}",
"$",
"progress",
"->",
"finish",
"(",
")",
";",
"$",
"return",
"=",
"new",
"\\",
"stdClass",
"(",
")",
";",
"$",
"return",
"->",
"count",
"=",
"$",
"importedCounter",
";",
"$",
"return",
"->",
"fails",
"=",
"count",
"(",
"$",
"failedImports",
")",
";",
"$",
"return",
"->",
"successes",
"=",
"$",
"successCounter",
";",
"$",
"return",
"->",
"failed",
"=",
"$",
"failedImports",
";",
"$",
"return",
"->",
"exceptionStore",
"=",
"$",
"this",
"->",
"exceptionStore",
";",
"return",
"$",
"return",
";",
"}"
] | Import Snippet by given XLIFF-File.
@param string $locale
@param string $filePath
@param OutputInterface $output
@param string $format
@return \stdClass
@throws FormatImporterNotFoundException | [
"Import",
"Snippet",
"by",
"given",
"XLIFF",
"-",
"File",
"."
] | 6766a36cc2f0c807c59202bf7540a08c4ef31192 | https://github.com/sulu/sulu/blob/6766a36cc2f0c807c59202bf7540a08c4ef31192/src/Sulu/Component/Snippet/Import/SnippetImport.php#L86-L125 | train |
sulu/sulu | src/Sulu/Bundle/LocationBundle/Content/Types/LocationContentType.php | LocationContentType.getCountries | private function getCountries()
{
$countries = [];
foreach (Intl::getRegionBundle()->getCountryNames() as $countryCode => $countryName) {
$countries[strtolower($countryCode)] = new PropertyParameter(strtolower($countryCode), $countryName);
}
return $countries;
} | php | private function getCountries()
{
$countries = [];
foreach (Intl::getRegionBundle()->getCountryNames() as $countryCode => $countryName) {
$countries[strtolower($countryCode)] = new PropertyParameter(strtolower($countryCode), $countryName);
}
return $countries;
} | [
"private",
"function",
"getCountries",
"(",
")",
"{",
"$",
"countries",
"=",
"[",
"]",
";",
"foreach",
"(",
"Intl",
"::",
"getRegionBundle",
"(",
")",
"->",
"getCountryNames",
"(",
")",
"as",
"$",
"countryCode",
"=>",
"$",
"countryName",
")",
"{",
"$",
"countries",
"[",
"strtolower",
"(",
"$",
"countryCode",
")",
"]",
"=",
"new",
"PropertyParameter",
"(",
"strtolower",
"(",
"$",
"countryCode",
")",
",",
"$",
"countryName",
")",
";",
"}",
"return",
"$",
"countries",
";",
"}"
] | Returns array of countries with the country-code as array key.
@return array | [
"Returns",
"array",
"of",
"countries",
"with",
"the",
"country",
"-",
"code",
"as",
"array",
"key",
"."
] | 6766a36cc2f0c807c59202bf7540a08c4ef31192 | https://github.com/sulu/sulu/blob/6766a36cc2f0c807c59202bf7540a08c4ef31192/src/Sulu/Bundle/LocationBundle/Content/Types/LocationContentType.php#L109-L117 | train |
sulu/sulu | src/Sulu/Bundle/ResourceBundle/Entity/Operator.php | Operator.addValue | public function addValue(\Sulu\Bundle\ResourceBundle\Entity\OperatorValue $values)
{
$this->values[] = $values;
return $this;
} | php | public function addValue(\Sulu\Bundle\ResourceBundle\Entity\OperatorValue $values)
{
$this->values[] = $values;
return $this;
} | [
"public",
"function",
"addValue",
"(",
"\\",
"Sulu",
"\\",
"Bundle",
"\\",
"ResourceBundle",
"\\",
"Entity",
"\\",
"OperatorValue",
"$",
"values",
")",
"{",
"$",
"this",
"->",
"values",
"[",
"]",
"=",
"$",
"values",
";",
"return",
"$",
"this",
";",
"}"
] | Add values.
@param \Sulu\Bundle\ResourceBundle\Entity\OperatorValue $values
@return Operator | [
"Add",
"values",
"."
] | 6766a36cc2f0c807c59202bf7540a08c4ef31192 | https://github.com/sulu/sulu/blob/6766a36cc2f0c807c59202bf7540a08c4ef31192/src/Sulu/Bundle/ResourceBundle/Entity/Operator.php#L191-L196 | train |
sulu/sulu | src/Sulu/Bundle/ResourceBundle/Entity/Operator.php | Operator.removeValue | public function removeValue(\Sulu\Bundle\ResourceBundle\Entity\OperatorValue $values)
{
$this->values->removeElement($values);
} | php | public function removeValue(\Sulu\Bundle\ResourceBundle\Entity\OperatorValue $values)
{
$this->values->removeElement($values);
} | [
"public",
"function",
"removeValue",
"(",
"\\",
"Sulu",
"\\",
"Bundle",
"\\",
"ResourceBundle",
"\\",
"Entity",
"\\",
"OperatorValue",
"$",
"values",
")",
"{",
"$",
"this",
"->",
"values",
"->",
"removeElement",
"(",
"$",
"values",
")",
";",
"}"
] | Remove values.
@param \Sulu\Bundle\ResourceBundle\Entity\OperatorValue $values | [
"Remove",
"values",
"."
] | 6766a36cc2f0c807c59202bf7540a08c4ef31192 | https://github.com/sulu/sulu/blob/6766a36cc2f0c807c59202bf7540a08c4ef31192/src/Sulu/Bundle/ResourceBundle/Entity/Operator.php#L203-L206 | train |
sulu/sulu | src/Sulu/Bundle/SecurityBundle/Command/CreateUserCommand.php | CreateUserCommand.encodePassword | private function encodePassword($user, $password, $salt)
{
/** @var PasswordEncoderInterface $encoder */
$encoder = $this->encoderFactory->getEncoder($user);
return $encoder->encodePassword($password, $salt);
} | php | private function encodePassword($user, $password, $salt)
{
/** @var PasswordEncoderInterface $encoder */
$encoder = $this->encoderFactory->getEncoder($user);
return $encoder->encodePassword($password, $salt);
} | [
"private",
"function",
"encodePassword",
"(",
"$",
"user",
",",
"$",
"password",
",",
"$",
"salt",
")",
"{",
"/** @var PasswordEncoderInterface $encoder */",
"$",
"encoder",
"=",
"$",
"this",
"->",
"encoderFactory",
"->",
"getEncoder",
"(",
"$",
"user",
")",
";",
"return",
"$",
"encoder",
"->",
"encodePassword",
"(",
"$",
"password",
",",
"$",
"salt",
")",
";",
"}"
] | Encodes the given password, for the given password, with he given salt and returns the result.
@param $user
@param $password
@param $salt
@return mixed | [
"Encodes",
"the",
"given",
"password",
"for",
"the",
"given",
"password",
"with",
"he",
"given",
"salt",
"and",
"returns",
"the",
"result",
"."
] | 6766a36cc2f0c807c59202bf7540a08c4ef31192 | https://github.com/sulu/sulu/blob/6766a36cc2f0c807c59202bf7540a08c4ef31192/src/Sulu/Bundle/SecurityBundle/Command/CreateUserCommand.php#L348-L354 | train |
sulu/sulu | src/Sulu/Bundle/SecurityBundle/Command/CreateUserCommand.php | CreateUserCommand.getRoleNames | private function getRoleNames()
{
$roleNames = $this->roleRepository->getRoleNames();
if (empty($roleNames)) {
throw new \RuntimeException(sprintf(
'The system currently has no roles. Use the "sulu:security:role:create" command to create roles.'
));
}
return $roleNames;
} | php | private function getRoleNames()
{
$roleNames = $this->roleRepository->getRoleNames();
if (empty($roleNames)) {
throw new \RuntimeException(sprintf(
'The system currently has no roles. Use the "sulu:security:role:create" command to create roles.'
));
}
return $roleNames;
} | [
"private",
"function",
"getRoleNames",
"(",
")",
"{",
"$",
"roleNames",
"=",
"$",
"this",
"->",
"roleRepository",
"->",
"getRoleNames",
"(",
")",
";",
"if",
"(",
"empty",
"(",
"$",
"roleNames",
")",
")",
"{",
"throw",
"new",
"\\",
"RuntimeException",
"(",
"sprintf",
"(",
"'The system currently has no roles. Use the \"sulu:security:role:create\" command to create roles.'",
")",
")",
";",
"}",
"return",
"$",
"roleNames",
";",
"}"
] | Return the names of all the roles.
@return array
@throws \RuntimeException If no roles exist | [
"Return",
"the",
"names",
"of",
"all",
"the",
"roles",
"."
] | 6766a36cc2f0c807c59202bf7540a08c4ef31192 | https://github.com/sulu/sulu/blob/6766a36cc2f0c807c59202bf7540a08c4ef31192/src/Sulu/Bundle/SecurityBundle/Command/CreateUserCommand.php#L363-L374 | train |
sulu/sulu | src/Sulu/Bundle/MediaBundle/Controller/CollectionController.php | CollectionController.getAction | public function getAction($id, Request $request)
{
if ($this->getBooleanRequestParameter($request, 'tree', false, false)) {
$collections = $this->getCollectionManager()->getTreeById(
$id,
$this->getRequestParameter($request, 'locale', true)
);
return $this->handleView(
$this->view(
new CollectionRepresentation($collections, 'collections')
)
);
}
try {
$locale = $this->getRequestParameter($request, 'locale', true);
$depth = intval($request->get('depth', 0));
$breadcrumb = $this->getBooleanRequestParameter($request, 'breadcrumb', false, false);
$children = $this->getBooleanRequestParameter($request, 'children', false, false);
$collectionManager = $this->getCollectionManager();
// filter children
$listRestHelper = $this->get('sulu_core.list_rest_helper');
$limit = $request->get('limit', null);
$offset = $this->getOffset($request, $limit);
$search = $listRestHelper->getSearchPattern();
$sortBy = $request->get('sortBy');
$sortOrder = $request->get('sortOrder', 'ASC');
$filter = [
'limit' => $limit,
'offset' => $offset,
'search' => $search,
];
$view = $this->responseGetById(
$id,
function($id) use ($locale, $collectionManager, $depth, $breadcrumb, $filter, $sortBy, $sortOrder, $children) {
$collection = $collectionManager->getById(
$id,
$locale,
$depth,
$breadcrumb,
$filter,
null !== $sortBy ? [$sortBy => $sortOrder] : [],
$children
);
if (SystemCollectionManagerInterface::COLLECTION_TYPE === $collection->getType()->getKey()) {
$this->get('sulu_security.security_checker')->checkPermission(
'sulu.media.system_collections',
PermissionTypes::VIEW
);
}
return $collection;
}
);
} catch (CollectionNotFoundException $cnf) {
$view = $this->view($cnf->toArray(), 404);
} catch (MediaException $e) {
$view = $this->view($e->toArray(), 400);
}
return $this->handleView($view);
} | php | public function getAction($id, Request $request)
{
if ($this->getBooleanRequestParameter($request, 'tree', false, false)) {
$collections = $this->getCollectionManager()->getTreeById(
$id,
$this->getRequestParameter($request, 'locale', true)
);
return $this->handleView(
$this->view(
new CollectionRepresentation($collections, 'collections')
)
);
}
try {
$locale = $this->getRequestParameter($request, 'locale', true);
$depth = intval($request->get('depth', 0));
$breadcrumb = $this->getBooleanRequestParameter($request, 'breadcrumb', false, false);
$children = $this->getBooleanRequestParameter($request, 'children', false, false);
$collectionManager = $this->getCollectionManager();
// filter children
$listRestHelper = $this->get('sulu_core.list_rest_helper');
$limit = $request->get('limit', null);
$offset = $this->getOffset($request, $limit);
$search = $listRestHelper->getSearchPattern();
$sortBy = $request->get('sortBy');
$sortOrder = $request->get('sortOrder', 'ASC');
$filter = [
'limit' => $limit,
'offset' => $offset,
'search' => $search,
];
$view = $this->responseGetById(
$id,
function($id) use ($locale, $collectionManager, $depth, $breadcrumb, $filter, $sortBy, $sortOrder, $children) {
$collection = $collectionManager->getById(
$id,
$locale,
$depth,
$breadcrumb,
$filter,
null !== $sortBy ? [$sortBy => $sortOrder] : [],
$children
);
if (SystemCollectionManagerInterface::COLLECTION_TYPE === $collection->getType()->getKey()) {
$this->get('sulu_security.security_checker')->checkPermission(
'sulu.media.system_collections',
PermissionTypes::VIEW
);
}
return $collection;
}
);
} catch (CollectionNotFoundException $cnf) {
$view = $this->view($cnf->toArray(), 404);
} catch (MediaException $e) {
$view = $this->view($e->toArray(), 400);
}
return $this->handleView($view);
} | [
"public",
"function",
"getAction",
"(",
"$",
"id",
",",
"Request",
"$",
"request",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"getBooleanRequestParameter",
"(",
"$",
"request",
",",
"'tree'",
",",
"false",
",",
"false",
")",
")",
"{",
"$",
"collections",
"=",
"$",
"this",
"->",
"getCollectionManager",
"(",
")",
"->",
"getTreeById",
"(",
"$",
"id",
",",
"$",
"this",
"->",
"getRequestParameter",
"(",
"$",
"request",
",",
"'locale'",
",",
"true",
")",
")",
";",
"return",
"$",
"this",
"->",
"handleView",
"(",
"$",
"this",
"->",
"view",
"(",
"new",
"CollectionRepresentation",
"(",
"$",
"collections",
",",
"'collections'",
")",
")",
")",
";",
"}",
"try",
"{",
"$",
"locale",
"=",
"$",
"this",
"->",
"getRequestParameter",
"(",
"$",
"request",
",",
"'locale'",
",",
"true",
")",
";",
"$",
"depth",
"=",
"intval",
"(",
"$",
"request",
"->",
"get",
"(",
"'depth'",
",",
"0",
")",
")",
";",
"$",
"breadcrumb",
"=",
"$",
"this",
"->",
"getBooleanRequestParameter",
"(",
"$",
"request",
",",
"'breadcrumb'",
",",
"false",
",",
"false",
")",
";",
"$",
"children",
"=",
"$",
"this",
"->",
"getBooleanRequestParameter",
"(",
"$",
"request",
",",
"'children'",
",",
"false",
",",
"false",
")",
";",
"$",
"collectionManager",
"=",
"$",
"this",
"->",
"getCollectionManager",
"(",
")",
";",
"// filter children",
"$",
"listRestHelper",
"=",
"$",
"this",
"->",
"get",
"(",
"'sulu_core.list_rest_helper'",
")",
";",
"$",
"limit",
"=",
"$",
"request",
"->",
"get",
"(",
"'limit'",
",",
"null",
")",
";",
"$",
"offset",
"=",
"$",
"this",
"->",
"getOffset",
"(",
"$",
"request",
",",
"$",
"limit",
")",
";",
"$",
"search",
"=",
"$",
"listRestHelper",
"->",
"getSearchPattern",
"(",
")",
";",
"$",
"sortBy",
"=",
"$",
"request",
"->",
"get",
"(",
"'sortBy'",
")",
";",
"$",
"sortOrder",
"=",
"$",
"request",
"->",
"get",
"(",
"'sortOrder'",
",",
"'ASC'",
")",
";",
"$",
"filter",
"=",
"[",
"'limit'",
"=>",
"$",
"limit",
",",
"'offset'",
"=>",
"$",
"offset",
",",
"'search'",
"=>",
"$",
"search",
",",
"]",
";",
"$",
"view",
"=",
"$",
"this",
"->",
"responseGetById",
"(",
"$",
"id",
",",
"function",
"(",
"$",
"id",
")",
"use",
"(",
"$",
"locale",
",",
"$",
"collectionManager",
",",
"$",
"depth",
",",
"$",
"breadcrumb",
",",
"$",
"filter",
",",
"$",
"sortBy",
",",
"$",
"sortOrder",
",",
"$",
"children",
")",
"{",
"$",
"collection",
"=",
"$",
"collectionManager",
"->",
"getById",
"(",
"$",
"id",
",",
"$",
"locale",
",",
"$",
"depth",
",",
"$",
"breadcrumb",
",",
"$",
"filter",
",",
"null",
"!==",
"$",
"sortBy",
"?",
"[",
"$",
"sortBy",
"=>",
"$",
"sortOrder",
"]",
":",
"[",
"]",
",",
"$",
"children",
")",
";",
"if",
"(",
"SystemCollectionManagerInterface",
"::",
"COLLECTION_TYPE",
"===",
"$",
"collection",
"->",
"getType",
"(",
")",
"->",
"getKey",
"(",
")",
")",
"{",
"$",
"this",
"->",
"get",
"(",
"'sulu_security.security_checker'",
")",
"->",
"checkPermission",
"(",
"'sulu.media.system_collections'",
",",
"PermissionTypes",
"::",
"VIEW",
")",
";",
"}",
"return",
"$",
"collection",
";",
"}",
")",
";",
"}",
"catch",
"(",
"CollectionNotFoundException",
"$",
"cnf",
")",
"{",
"$",
"view",
"=",
"$",
"this",
"->",
"view",
"(",
"$",
"cnf",
"->",
"toArray",
"(",
")",
",",
"404",
")",
";",
"}",
"catch",
"(",
"MediaException",
"$",
"e",
")",
"{",
"$",
"view",
"=",
"$",
"this",
"->",
"view",
"(",
"$",
"e",
"->",
"toArray",
"(",
")",
",",
"400",
")",
";",
"}",
"return",
"$",
"this",
"->",
"handleView",
"(",
"$",
"view",
")",
";",
"}"
] | Shows a single collection with the given id.
@param $id
@param Request $request
@return \Symfony\Component\HttpFoundation\Response | [
"Shows",
"a",
"single",
"collection",
"with",
"the",
"given",
"id",
"."
] | 6766a36cc2f0c807c59202bf7540a08c4ef31192 | https://github.com/sulu/sulu/blob/6766a36cc2f0c807c59202bf7540a08c4ef31192/src/Sulu/Bundle/MediaBundle/Controller/CollectionController.php#L63-L129 | train |
sulu/sulu | src/Sulu/Bundle/MediaBundle/Controller/CollectionController.php | CollectionController.cgetAction | public function cgetAction(Request $request)
{
try {
/** @var ListRestHelperInterface $listRestHelper */
$listRestHelper = $this->get('sulu_core.list_rest_helper');
$securityChecker = $this->get('sulu_security.security_checker');
$flat = $this->getBooleanRequestParameter($request, 'flat', false);
$depth = $request->get('depth', 0);
$parentId = $request->get('parentId', null);
$limit = $request->get('limit', null);
$offset = $this->getOffset($request, $limit);
$search = $listRestHelper->getSearchPattern();
$sortBy = $request->get('sortBy');
$sortOrder = $request->get('sortOrder', 'ASC');
$includeRoot = $this->getBooleanRequestParameter($request, 'includeRoot', false, false);
$collectionManager = $this->getCollectionManager();
if ('root' === $parentId) {
$includeRoot = false;
$parentId = null;
}
if ($flat) {
$collections = $collectionManager->get(
$this->getRequestParameter($request, 'locale', true),
[
'depth' => $depth,
'parent' => $parentId,
],
$limit,
$offset,
null !== $sortBy ? [$sortBy => $sortOrder] : []
);
} else {
$collections = $collectionManager->getTree(
$this->getRequestParameter($request, 'locale', true),
$offset,
$limit,
$search,
$depth,
null !== $sortBy ? [$sortBy => $sortOrder] : [],
$securityChecker->hasPermission('sulu.media.system_collections', 'view')
);
}
if ($includeRoot && !$parentId) {
$collections = [
new RootCollection(
$this->get('translator')->trans('sulu_media.all_collections', [], 'admin'),
$collections
),
];
}
$all = $collectionManager->getCount();
$list = new ListRepresentation(
$collections,
self::$entityKey,
'get_collections',
$request->query->all(),
$listRestHelper->getPage(),
$listRestHelper->getLimit(),
$all
);
$view = $this->view($list, 200);
} catch (CollectionNotFoundException $cnf) {
$view = $this->view($cnf->toArray(), 404);
} catch (MediaException $me) {
$view = $this->view($me->toArray(), 400);
}
return $this->handleView($view);
} | php | public function cgetAction(Request $request)
{
try {
/** @var ListRestHelperInterface $listRestHelper */
$listRestHelper = $this->get('sulu_core.list_rest_helper');
$securityChecker = $this->get('sulu_security.security_checker');
$flat = $this->getBooleanRequestParameter($request, 'flat', false);
$depth = $request->get('depth', 0);
$parentId = $request->get('parentId', null);
$limit = $request->get('limit', null);
$offset = $this->getOffset($request, $limit);
$search = $listRestHelper->getSearchPattern();
$sortBy = $request->get('sortBy');
$sortOrder = $request->get('sortOrder', 'ASC');
$includeRoot = $this->getBooleanRequestParameter($request, 'includeRoot', false, false);
$collectionManager = $this->getCollectionManager();
if ('root' === $parentId) {
$includeRoot = false;
$parentId = null;
}
if ($flat) {
$collections = $collectionManager->get(
$this->getRequestParameter($request, 'locale', true),
[
'depth' => $depth,
'parent' => $parentId,
],
$limit,
$offset,
null !== $sortBy ? [$sortBy => $sortOrder] : []
);
} else {
$collections = $collectionManager->getTree(
$this->getRequestParameter($request, 'locale', true),
$offset,
$limit,
$search,
$depth,
null !== $sortBy ? [$sortBy => $sortOrder] : [],
$securityChecker->hasPermission('sulu.media.system_collections', 'view')
);
}
if ($includeRoot && !$parentId) {
$collections = [
new RootCollection(
$this->get('translator')->trans('sulu_media.all_collections', [], 'admin'),
$collections
),
];
}
$all = $collectionManager->getCount();
$list = new ListRepresentation(
$collections,
self::$entityKey,
'get_collections',
$request->query->all(),
$listRestHelper->getPage(),
$listRestHelper->getLimit(),
$all
);
$view = $this->view($list, 200);
} catch (CollectionNotFoundException $cnf) {
$view = $this->view($cnf->toArray(), 404);
} catch (MediaException $me) {
$view = $this->view($me->toArray(), 400);
}
return $this->handleView($view);
} | [
"public",
"function",
"cgetAction",
"(",
"Request",
"$",
"request",
")",
"{",
"try",
"{",
"/** @var ListRestHelperInterface $listRestHelper */",
"$",
"listRestHelper",
"=",
"$",
"this",
"->",
"get",
"(",
"'sulu_core.list_rest_helper'",
")",
";",
"$",
"securityChecker",
"=",
"$",
"this",
"->",
"get",
"(",
"'sulu_security.security_checker'",
")",
";",
"$",
"flat",
"=",
"$",
"this",
"->",
"getBooleanRequestParameter",
"(",
"$",
"request",
",",
"'flat'",
",",
"false",
")",
";",
"$",
"depth",
"=",
"$",
"request",
"->",
"get",
"(",
"'depth'",
",",
"0",
")",
";",
"$",
"parentId",
"=",
"$",
"request",
"->",
"get",
"(",
"'parentId'",
",",
"null",
")",
";",
"$",
"limit",
"=",
"$",
"request",
"->",
"get",
"(",
"'limit'",
",",
"null",
")",
";",
"$",
"offset",
"=",
"$",
"this",
"->",
"getOffset",
"(",
"$",
"request",
",",
"$",
"limit",
")",
";",
"$",
"search",
"=",
"$",
"listRestHelper",
"->",
"getSearchPattern",
"(",
")",
";",
"$",
"sortBy",
"=",
"$",
"request",
"->",
"get",
"(",
"'sortBy'",
")",
";",
"$",
"sortOrder",
"=",
"$",
"request",
"->",
"get",
"(",
"'sortOrder'",
",",
"'ASC'",
")",
";",
"$",
"includeRoot",
"=",
"$",
"this",
"->",
"getBooleanRequestParameter",
"(",
"$",
"request",
",",
"'includeRoot'",
",",
"false",
",",
"false",
")",
";",
"$",
"collectionManager",
"=",
"$",
"this",
"->",
"getCollectionManager",
"(",
")",
";",
"if",
"(",
"'root'",
"===",
"$",
"parentId",
")",
"{",
"$",
"includeRoot",
"=",
"false",
";",
"$",
"parentId",
"=",
"null",
";",
"}",
"if",
"(",
"$",
"flat",
")",
"{",
"$",
"collections",
"=",
"$",
"collectionManager",
"->",
"get",
"(",
"$",
"this",
"->",
"getRequestParameter",
"(",
"$",
"request",
",",
"'locale'",
",",
"true",
")",
",",
"[",
"'depth'",
"=>",
"$",
"depth",
",",
"'parent'",
"=>",
"$",
"parentId",
",",
"]",
",",
"$",
"limit",
",",
"$",
"offset",
",",
"null",
"!==",
"$",
"sortBy",
"?",
"[",
"$",
"sortBy",
"=>",
"$",
"sortOrder",
"]",
":",
"[",
"]",
")",
";",
"}",
"else",
"{",
"$",
"collections",
"=",
"$",
"collectionManager",
"->",
"getTree",
"(",
"$",
"this",
"->",
"getRequestParameter",
"(",
"$",
"request",
",",
"'locale'",
",",
"true",
")",
",",
"$",
"offset",
",",
"$",
"limit",
",",
"$",
"search",
",",
"$",
"depth",
",",
"null",
"!==",
"$",
"sortBy",
"?",
"[",
"$",
"sortBy",
"=>",
"$",
"sortOrder",
"]",
":",
"[",
"]",
",",
"$",
"securityChecker",
"->",
"hasPermission",
"(",
"'sulu.media.system_collections'",
",",
"'view'",
")",
")",
";",
"}",
"if",
"(",
"$",
"includeRoot",
"&&",
"!",
"$",
"parentId",
")",
"{",
"$",
"collections",
"=",
"[",
"new",
"RootCollection",
"(",
"$",
"this",
"->",
"get",
"(",
"'translator'",
")",
"->",
"trans",
"(",
"'sulu_media.all_collections'",
",",
"[",
"]",
",",
"'admin'",
")",
",",
"$",
"collections",
")",
",",
"]",
";",
"}",
"$",
"all",
"=",
"$",
"collectionManager",
"->",
"getCount",
"(",
")",
";",
"$",
"list",
"=",
"new",
"ListRepresentation",
"(",
"$",
"collections",
",",
"self",
"::",
"$",
"entityKey",
",",
"'get_collections'",
",",
"$",
"request",
"->",
"query",
"->",
"all",
"(",
")",
",",
"$",
"listRestHelper",
"->",
"getPage",
"(",
")",
",",
"$",
"listRestHelper",
"->",
"getLimit",
"(",
")",
",",
"$",
"all",
")",
";",
"$",
"view",
"=",
"$",
"this",
"->",
"view",
"(",
"$",
"list",
",",
"200",
")",
";",
"}",
"catch",
"(",
"CollectionNotFoundException",
"$",
"cnf",
")",
"{",
"$",
"view",
"=",
"$",
"this",
"->",
"view",
"(",
"$",
"cnf",
"->",
"toArray",
"(",
")",
",",
"404",
")",
";",
"}",
"catch",
"(",
"MediaException",
"$",
"me",
")",
"{",
"$",
"view",
"=",
"$",
"this",
"->",
"view",
"(",
"$",
"me",
"->",
"toArray",
"(",
")",
",",
"400",
")",
";",
"}",
"return",
"$",
"this",
"->",
"handleView",
"(",
"$",
"view",
")",
";",
"}"
] | lists all collections.
@param Request $request
@return \Symfony\Component\HttpFoundation\Response | [
"lists",
"all",
"collections",
"."
] | 6766a36cc2f0c807c59202bf7540a08c4ef31192 | https://github.com/sulu/sulu/blob/6766a36cc2f0c807c59202bf7540a08c4ef31192/src/Sulu/Bundle/MediaBundle/Controller/CollectionController.php#L138-L213 | train |
sulu/sulu | src/Sulu/Bundle/MediaBundle/Controller/CollectionController.php | CollectionController.deleteAction | public function deleteAction($id)
{
$delete = function($id) {
try {
$collectionManager = $this->getCollectionManager();
$collectionManager->delete($id);
} catch (CollectionNotFoundException $cnf) {
throw new EntityNotFoundException(self::$entityName, $id); // will throw 404 Entity not found
} catch (MediaException $me) {
throw new RestException($me->getMessage(), $me->getCode()); // will throw 400 Bad Request
}
};
$view = $this->responseDelete($id, $delete);
return $this->handleView($view);
} | php | public function deleteAction($id)
{
$delete = function($id) {
try {
$collectionManager = $this->getCollectionManager();
$collectionManager->delete($id);
} catch (CollectionNotFoundException $cnf) {
throw new EntityNotFoundException(self::$entityName, $id); // will throw 404 Entity not found
} catch (MediaException $me) {
throw new RestException($me->getMessage(), $me->getCode()); // will throw 400 Bad Request
}
};
$view = $this->responseDelete($id, $delete);
return $this->handleView($view);
} | [
"public",
"function",
"deleteAction",
"(",
"$",
"id",
")",
"{",
"$",
"delete",
"=",
"function",
"(",
"$",
"id",
")",
"{",
"try",
"{",
"$",
"collectionManager",
"=",
"$",
"this",
"->",
"getCollectionManager",
"(",
")",
";",
"$",
"collectionManager",
"->",
"delete",
"(",
"$",
"id",
")",
";",
"}",
"catch",
"(",
"CollectionNotFoundException",
"$",
"cnf",
")",
"{",
"throw",
"new",
"EntityNotFoundException",
"(",
"self",
"::",
"$",
"entityName",
",",
"$",
"id",
")",
";",
"// will throw 404 Entity not found",
"}",
"catch",
"(",
"MediaException",
"$",
"me",
")",
"{",
"throw",
"new",
"RestException",
"(",
"$",
"me",
"->",
"getMessage",
"(",
")",
",",
"$",
"me",
"->",
"getCode",
"(",
")",
")",
";",
"// will throw 400 Bad Request",
"}",
"}",
";",
"$",
"view",
"=",
"$",
"this",
"->",
"responseDelete",
"(",
"$",
"id",
",",
"$",
"delete",
")",
";",
"return",
"$",
"this",
"->",
"handleView",
"(",
"$",
"view",
")",
";",
"}"
] | Delete a collection with the given id.
@param $id
@return \Symfony\Component\HttpFoundation\Response | [
"Delete",
"a",
"collection",
"with",
"the",
"given",
"id",
"."
] | 6766a36cc2f0c807c59202bf7540a08c4ef31192 | https://github.com/sulu/sulu/blob/6766a36cc2f0c807c59202bf7540a08c4ef31192/src/Sulu/Bundle/MediaBundle/Controller/CollectionController.php#L249-L265 | train |
sulu/sulu | src/Sulu/Bundle/MediaBundle/Controller/CollectionController.php | CollectionController.moveEntity | protected function moveEntity($id, Request $request)
{
$destinationId = $this->getRequestParameter($request, 'destination');
$locale = $this->getRequestParameter($request, 'locale', true);
$collection = $this->getCollectionManager()->move($id, $locale, $destinationId);
$view = $this->view($collection);
return $this->handleView($view);
} | php | protected function moveEntity($id, Request $request)
{
$destinationId = $this->getRequestParameter($request, 'destination');
$locale = $this->getRequestParameter($request, 'locale', true);
$collection = $this->getCollectionManager()->move($id, $locale, $destinationId);
$view = $this->view($collection);
return $this->handleView($view);
} | [
"protected",
"function",
"moveEntity",
"(",
"$",
"id",
",",
"Request",
"$",
"request",
")",
"{",
"$",
"destinationId",
"=",
"$",
"this",
"->",
"getRequestParameter",
"(",
"$",
"request",
",",
"'destination'",
")",
";",
"$",
"locale",
"=",
"$",
"this",
"->",
"getRequestParameter",
"(",
"$",
"request",
",",
"'locale'",
",",
"true",
")",
";",
"$",
"collection",
"=",
"$",
"this",
"->",
"getCollectionManager",
"(",
")",
"->",
"move",
"(",
"$",
"id",
",",
"$",
"locale",
",",
"$",
"destinationId",
")",
";",
"$",
"view",
"=",
"$",
"this",
"->",
"view",
"(",
"$",
"collection",
")",
";",
"return",
"$",
"this",
"->",
"handleView",
"(",
"$",
"view",
")",
";",
"}"
] | Moves an entity into another one.
@param int $id
@param Request $request
@return Response | [
"Moves",
"an",
"entity",
"into",
"another",
"one",
"."
] | 6766a36cc2f0c807c59202bf7540a08c4ef31192 | https://github.com/sulu/sulu/blob/6766a36cc2f0c807c59202bf7540a08c4ef31192/src/Sulu/Bundle/MediaBundle/Controller/CollectionController.php#L304-L312 | train |
sulu/sulu | src/Sulu/Component/Content/Metadata/Factory/StructureMetadataFactory.php | StructureMetadataFactory.assertExists | private function assertExists($type)
{
if (!isset($this->typePaths[$type])) {
throw new Exception\DocumentTypeNotFoundException(
sprintf(
'Structure path for document type "%s" is not mapped. Mapped structure types: "%s"',
$type,
implode('", "', array_keys($this->typePaths))
)
);
}
} | php | private function assertExists($type)
{
if (!isset($this->typePaths[$type])) {
throw new Exception\DocumentTypeNotFoundException(
sprintf(
'Structure path for document type "%s" is not mapped. Mapped structure types: "%s"',
$type,
implode('", "', array_keys($this->typePaths))
)
);
}
} | [
"private",
"function",
"assertExists",
"(",
"$",
"type",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"this",
"->",
"typePaths",
"[",
"$",
"type",
"]",
")",
")",
"{",
"throw",
"new",
"Exception",
"\\",
"DocumentTypeNotFoundException",
"(",
"sprintf",
"(",
"'Structure path for document type \"%s\" is not mapped. Mapped structure types: \"%s\"'",
",",
"$",
"type",
",",
"implode",
"(",
"'\", \"'",
",",
"array_keys",
"(",
"$",
"this",
"->",
"typePaths",
")",
")",
")",
")",
";",
"}",
"}"
] | Assert type exists.
@param string $type | [
"Assert",
"type",
"exists",
"."
] | 6766a36cc2f0c807c59202bf7540a08c4ef31192 | https://github.com/sulu/sulu/blob/6766a36cc2f0c807c59202bf7540a08c4ef31192/src/Sulu/Component/Content/Metadata/Factory/StructureMetadataFactory.php#L211-L222 | train |
sulu/sulu | src/Sulu/Component/Content/Metadata/Factory/StructureMetadataFactory.php | StructureMetadataFactory.getPaths | private function getPaths($type)
{
$typeConfigs = $this->typePaths[$type];
$paths = [];
foreach ($typeConfigs as $typeConfig) {
$paths[] = $typeConfig['path'];
}
return $paths;
} | php | private function getPaths($type)
{
$typeConfigs = $this->typePaths[$type];
$paths = [];
foreach ($typeConfigs as $typeConfig) {
$paths[] = $typeConfig['path'];
}
return $paths;
} | [
"private",
"function",
"getPaths",
"(",
"$",
"type",
")",
"{",
"$",
"typeConfigs",
"=",
"$",
"this",
"->",
"typePaths",
"[",
"$",
"type",
"]",
";",
"$",
"paths",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"typeConfigs",
"as",
"$",
"typeConfig",
")",
"{",
"$",
"paths",
"[",
"]",
"=",
"$",
"typeConfig",
"[",
"'path'",
"]",
";",
"}",
"return",
"$",
"paths",
";",
"}"
] | Get the paths from the type path configuration.
@param string $type
@return array | [
"Get",
"the",
"paths",
"from",
"the",
"type",
"path",
"configuration",
"."
] | 6766a36cc2f0c807c59202bf7540a08c4ef31192 | https://github.com/sulu/sulu/blob/6766a36cc2f0c807c59202bf7540a08c4ef31192/src/Sulu/Component/Content/Metadata/Factory/StructureMetadataFactory.php#L231-L241 | train |
sulu/sulu | src/Sulu/Bundle/CategoryBundle/Entity/CategoryRepository.php | CategoryRepository.getCategoryQuery | private function getCategoryQuery()
{
return $this->createQueryBuilder('category')
->leftJoin('category.meta', 'categoryMeta')
->leftJoin('category.translations', 'categoryTranslations')
->leftJoin('categoryTranslations.keywords', 'categoryKeywords')
->leftJoin('category.parent', 'categoryParent')
->leftJoin('category.children', 'categoryChildren')
->addSelect('categoryMeta')
->addSelect('categoryTranslations')
->addSelect('categoryKeywords')
->addSelect('categoryParent')
->addSelect('categoryChildren');
} | php | private function getCategoryQuery()
{
return $this->createQueryBuilder('category')
->leftJoin('category.meta', 'categoryMeta')
->leftJoin('category.translations', 'categoryTranslations')
->leftJoin('categoryTranslations.keywords', 'categoryKeywords')
->leftJoin('category.parent', 'categoryParent')
->leftJoin('category.children', 'categoryChildren')
->addSelect('categoryMeta')
->addSelect('categoryTranslations')
->addSelect('categoryKeywords')
->addSelect('categoryParent')
->addSelect('categoryChildren');
} | [
"private",
"function",
"getCategoryQuery",
"(",
")",
"{",
"return",
"$",
"this",
"->",
"createQueryBuilder",
"(",
"'category'",
")",
"->",
"leftJoin",
"(",
"'category.meta'",
",",
"'categoryMeta'",
")",
"->",
"leftJoin",
"(",
"'category.translations'",
",",
"'categoryTranslations'",
")",
"->",
"leftJoin",
"(",
"'categoryTranslations.keywords'",
",",
"'categoryKeywords'",
")",
"->",
"leftJoin",
"(",
"'category.parent'",
",",
"'categoryParent'",
")",
"->",
"leftJoin",
"(",
"'category.children'",
",",
"'categoryChildren'",
")",
"->",
"addSelect",
"(",
"'categoryMeta'",
")",
"->",
"addSelect",
"(",
"'categoryTranslations'",
")",
"->",
"addSelect",
"(",
"'categoryKeywords'",
")",
"->",
"addSelect",
"(",
"'categoryParent'",
")",
"->",
"addSelect",
"(",
"'categoryChildren'",
")",
";",
"}"
] | Returns the general part of the query.
@return \Doctrine\ORM\QueryBuilder | [
"Returns",
"the",
"general",
"part",
"of",
"the",
"query",
"."
] | 6766a36cc2f0c807c59202bf7540a08c4ef31192 | https://github.com/sulu/sulu/blob/6766a36cc2f0c807c59202bf7540a08c4ef31192/src/Sulu/Bundle/CategoryBundle/Entity/CategoryRepository.php#L190-L203 | train |
sulu/sulu | src/Sulu/Bundle/ResourceBundle/Entity/OperatorRepository.php | OperatorRepository.getOperatorQuery | protected function getOperatorQuery($locale)
{
$qb = $this->createQueryBuilder('operator')
->addSelect('operatorValues')
->addSelect('translations')
->addSelect('operatorValueTranslations')
->leftJoin('operator.translations', 'translations', 'WITH', 'translations.locale = :locale')
->leftJoin('operator.values', 'operatorValues')
->leftJoin(
'operatorValues.translations',
'operatorValueTranslations',
'WITH',
'operatorValueTranslations.locale = :locale'
)
->setParameter('locale', $locale);
return $qb;
} | php | protected function getOperatorQuery($locale)
{
$qb = $this->createQueryBuilder('operator')
->addSelect('operatorValues')
->addSelect('translations')
->addSelect('operatorValueTranslations')
->leftJoin('operator.translations', 'translations', 'WITH', 'translations.locale = :locale')
->leftJoin('operator.values', 'operatorValues')
->leftJoin(
'operatorValues.translations',
'operatorValueTranslations',
'WITH',
'operatorValueTranslations.locale = :locale'
)
->setParameter('locale', $locale);
return $qb;
} | [
"protected",
"function",
"getOperatorQuery",
"(",
"$",
"locale",
")",
"{",
"$",
"qb",
"=",
"$",
"this",
"->",
"createQueryBuilder",
"(",
"'operator'",
")",
"->",
"addSelect",
"(",
"'operatorValues'",
")",
"->",
"addSelect",
"(",
"'translations'",
")",
"->",
"addSelect",
"(",
"'operatorValueTranslations'",
")",
"->",
"leftJoin",
"(",
"'operator.translations'",
",",
"'translations'",
",",
"'WITH'",
",",
"'translations.locale = :locale'",
")",
"->",
"leftJoin",
"(",
"'operator.values'",
",",
"'operatorValues'",
")",
"->",
"leftJoin",
"(",
"'operatorValues.translations'",
",",
"'operatorValueTranslations'",
",",
"'WITH'",
",",
"'operatorValueTranslations.locale = :locale'",
")",
"->",
"setParameter",
"(",
"'locale'",
",",
"$",
"locale",
")",
";",
"return",
"$",
"qb",
";",
"}"
] | Returns the query for operators.
@param string $locale The locale to load
@return \Doctrine\ORM\QueryBuilder | [
"Returns",
"the",
"query",
"for",
"operators",
"."
] | 6766a36cc2f0c807c59202bf7540a08c4ef31192 | https://github.com/sulu/sulu/blob/6766a36cc2f0c807c59202bf7540a08c4ef31192/src/Sulu/Bundle/ResourceBundle/Entity/OperatorRepository.php#L46-L63 | train |
sulu/sulu | src/Sulu/Component/Doctrine/ReferencesOption.php | ReferencesOption.postGenerateSchemaTable | public function postGenerateSchemaTable(GenerateSchemaTableEventArgs $args)
{
$classMetadata = $args->getClassMetadata();
$table = $args->getClassTable();
foreach ($classMetadata->getFieldNames() as $fieldName) {
$mapping = $classMetadata->getFieldMapping($fieldName);
if (!isset($mapping['options']['references'])) {
continue;
}
$referencesOptions = $mapping['options']['references'];
$unknownOptions = array_diff_key($referencesOptions, array_flip(self::$knownOptions));
if (count($unknownOptions) > 0) {
throw new RuntimeException(
sprintf(
'Unknown options "%s" in the "references" option in the Doctrine schema of %s::%s.',
implode('", "', array_keys($unknownOptions)),
$classMetadata->getReflectionClass()->getName(),
$fieldName
)
);
}
if (!isset($referencesOptions['entity'])) {
throw new RuntimeException(
sprintf(
'Missing option "entity" in the "references" option in the Doctrine schema of %s::%s.',
$classMetadata->getReflectionClass()->getName(),
$fieldName
)
);
}
if (!isset($referencesOptions['field'])) {
throw new RuntimeException(
sprintf(
'Missing option "field" in the "references" option in the Doctrine schema of %s::%s.',
$classMetadata->getReflectionClass()->getName(),
$fieldName
)
);
}
$localColumnName = $classMetadata->getColumnName($fieldName);
/** @var ClassMetadata $foreignClassMetadata */
$foreignClassMetadata = $this->managerRegistry->getManagerForClass($referencesOptions['entity'])
->getClassMetadata($referencesOptions['entity']);
$foreignTable = $foreignClassMetadata->getTableName();
$foreignColumnName = $foreignClassMetadata->getColumnName($referencesOptions['field']);
$options = [];
if (isset($referencesOptions['onDelete'])) {
$options['onDelete'] = $referencesOptions['onDelete'];
}
if (isset($referencesOptions['onUpdate'])) {
$options['onUpdate'] = $referencesOptions['onUpdate'];
}
$table->addForeignKeyConstraint(
$foreignTable,
[$localColumnName],
[$foreignColumnName],
$options
);
}
} | php | public function postGenerateSchemaTable(GenerateSchemaTableEventArgs $args)
{
$classMetadata = $args->getClassMetadata();
$table = $args->getClassTable();
foreach ($classMetadata->getFieldNames() as $fieldName) {
$mapping = $classMetadata->getFieldMapping($fieldName);
if (!isset($mapping['options']['references'])) {
continue;
}
$referencesOptions = $mapping['options']['references'];
$unknownOptions = array_diff_key($referencesOptions, array_flip(self::$knownOptions));
if (count($unknownOptions) > 0) {
throw new RuntimeException(
sprintf(
'Unknown options "%s" in the "references" option in the Doctrine schema of %s::%s.',
implode('", "', array_keys($unknownOptions)),
$classMetadata->getReflectionClass()->getName(),
$fieldName
)
);
}
if (!isset($referencesOptions['entity'])) {
throw new RuntimeException(
sprintf(
'Missing option "entity" in the "references" option in the Doctrine schema of %s::%s.',
$classMetadata->getReflectionClass()->getName(),
$fieldName
)
);
}
if (!isset($referencesOptions['field'])) {
throw new RuntimeException(
sprintf(
'Missing option "field" in the "references" option in the Doctrine schema of %s::%s.',
$classMetadata->getReflectionClass()->getName(),
$fieldName
)
);
}
$localColumnName = $classMetadata->getColumnName($fieldName);
/** @var ClassMetadata $foreignClassMetadata */
$foreignClassMetadata = $this->managerRegistry->getManagerForClass($referencesOptions['entity'])
->getClassMetadata($referencesOptions['entity']);
$foreignTable = $foreignClassMetadata->getTableName();
$foreignColumnName = $foreignClassMetadata->getColumnName($referencesOptions['field']);
$options = [];
if (isset($referencesOptions['onDelete'])) {
$options['onDelete'] = $referencesOptions['onDelete'];
}
if (isset($referencesOptions['onUpdate'])) {
$options['onUpdate'] = $referencesOptions['onUpdate'];
}
$table->addForeignKeyConstraint(
$foreignTable,
[$localColumnName],
[$foreignColumnName],
$options
);
}
} | [
"public",
"function",
"postGenerateSchemaTable",
"(",
"GenerateSchemaTableEventArgs",
"$",
"args",
")",
"{",
"$",
"classMetadata",
"=",
"$",
"args",
"->",
"getClassMetadata",
"(",
")",
";",
"$",
"table",
"=",
"$",
"args",
"->",
"getClassTable",
"(",
")",
";",
"foreach",
"(",
"$",
"classMetadata",
"->",
"getFieldNames",
"(",
")",
"as",
"$",
"fieldName",
")",
"{",
"$",
"mapping",
"=",
"$",
"classMetadata",
"->",
"getFieldMapping",
"(",
"$",
"fieldName",
")",
";",
"if",
"(",
"!",
"isset",
"(",
"$",
"mapping",
"[",
"'options'",
"]",
"[",
"'references'",
"]",
")",
")",
"{",
"continue",
";",
"}",
"$",
"referencesOptions",
"=",
"$",
"mapping",
"[",
"'options'",
"]",
"[",
"'references'",
"]",
";",
"$",
"unknownOptions",
"=",
"array_diff_key",
"(",
"$",
"referencesOptions",
",",
"array_flip",
"(",
"self",
"::",
"$",
"knownOptions",
")",
")",
";",
"if",
"(",
"count",
"(",
"$",
"unknownOptions",
")",
">",
"0",
")",
"{",
"throw",
"new",
"RuntimeException",
"(",
"sprintf",
"(",
"'Unknown options \"%s\" in the \"references\" option in the Doctrine schema of %s::%s.'",
",",
"implode",
"(",
"'\", \"'",
",",
"array_keys",
"(",
"$",
"unknownOptions",
")",
")",
",",
"$",
"classMetadata",
"->",
"getReflectionClass",
"(",
")",
"->",
"getName",
"(",
")",
",",
"$",
"fieldName",
")",
")",
";",
"}",
"if",
"(",
"!",
"isset",
"(",
"$",
"referencesOptions",
"[",
"'entity'",
"]",
")",
")",
"{",
"throw",
"new",
"RuntimeException",
"(",
"sprintf",
"(",
"'Missing option \"entity\" in the \"references\" option in the Doctrine schema of %s::%s.'",
",",
"$",
"classMetadata",
"->",
"getReflectionClass",
"(",
")",
"->",
"getName",
"(",
")",
",",
"$",
"fieldName",
")",
")",
";",
"}",
"if",
"(",
"!",
"isset",
"(",
"$",
"referencesOptions",
"[",
"'field'",
"]",
")",
")",
"{",
"throw",
"new",
"RuntimeException",
"(",
"sprintf",
"(",
"'Missing option \"field\" in the \"references\" option in the Doctrine schema of %s::%s.'",
",",
"$",
"classMetadata",
"->",
"getReflectionClass",
"(",
")",
"->",
"getName",
"(",
")",
",",
"$",
"fieldName",
")",
")",
";",
"}",
"$",
"localColumnName",
"=",
"$",
"classMetadata",
"->",
"getColumnName",
"(",
"$",
"fieldName",
")",
";",
"/** @var ClassMetadata $foreignClassMetadata */",
"$",
"foreignClassMetadata",
"=",
"$",
"this",
"->",
"managerRegistry",
"->",
"getManagerForClass",
"(",
"$",
"referencesOptions",
"[",
"'entity'",
"]",
")",
"->",
"getClassMetadata",
"(",
"$",
"referencesOptions",
"[",
"'entity'",
"]",
")",
";",
"$",
"foreignTable",
"=",
"$",
"foreignClassMetadata",
"->",
"getTableName",
"(",
")",
";",
"$",
"foreignColumnName",
"=",
"$",
"foreignClassMetadata",
"->",
"getColumnName",
"(",
"$",
"referencesOptions",
"[",
"'field'",
"]",
")",
";",
"$",
"options",
"=",
"[",
"]",
";",
"if",
"(",
"isset",
"(",
"$",
"referencesOptions",
"[",
"'onDelete'",
"]",
")",
")",
"{",
"$",
"options",
"[",
"'onDelete'",
"]",
"=",
"$",
"referencesOptions",
"[",
"'onDelete'",
"]",
";",
"}",
"if",
"(",
"isset",
"(",
"$",
"referencesOptions",
"[",
"'onUpdate'",
"]",
")",
")",
"{",
"$",
"options",
"[",
"'onUpdate'",
"]",
"=",
"$",
"referencesOptions",
"[",
"'onUpdate'",
"]",
";",
"}",
"$",
"table",
"->",
"addForeignKeyConstraint",
"(",
"$",
"foreignTable",
",",
"[",
"$",
"localColumnName",
"]",
",",
"[",
"$",
"foreignColumnName",
"]",
",",
"$",
"options",
")",
";",
"}",
"}"
] | Parses the mapping and adds foreign-key constraints for each
"references" option found.
@param GenerateSchemaTableEventArgs $args The arguments of the
ToolEvents::postGenerateSchemaTable
event | [
"Parses",
"the",
"mapping",
"and",
"adds",
"foreign",
"-",
"key",
"constraints",
"for",
"each",
"references",
"option",
"found",
"."
] | 6766a36cc2f0c807c59202bf7540a08c4ef31192 | https://github.com/sulu/sulu/blob/6766a36cc2f0c807c59202bf7540a08c4ef31192/src/Sulu/Component/Doctrine/ReferencesOption.php#L87-L159 | train |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.