repo stringlengths 6 63 | path stringlengths 5 140 | func_name stringlengths 3 151 | original_string stringlengths 84 13k | language stringclasses 1 value | code stringlengths 84 13k | code_tokens list | docstring stringlengths 3 47.2k | docstring_tokens list | sha stringlengths 40 40 | url stringlengths 91 247 | partition stringclasses 1 value |
|---|---|---|---|---|---|---|---|---|---|---|---|
sulu/sulu | src/Sulu/Component/Security/Authorization/AccessControl/SecuredEntityRepositoryTrait.php | SecuredEntityRepositoryTrait.addAccessControl | protected function addAccessControl(
QueryBuilder $queryBuilder,
UserInterface $user,
$permission,
$entityClass,
$entityAlias
) {
$queryBuilder->leftJoin(
AccessControl::class,
'accessControl',
'WITH',
'accessControl.entityClass = :entityClass AND accessControl.entityId = ' . $entityAlias . '.id'
);
$queryBuilder->leftJoin('accessControl.role', 'role');
$queryBuilder->andWhere(
'BIT_AND(accessControl.permissions, :permission) = :permission OR accessControl.permissions IS NULL'
);
$roleIds = [];
foreach ($user->getRoleObjects() as $role) {
$roleIds[] = $role->getId();
}
$queryBuilder->andWhere('role.id IN(:roleIds) OR role.id IS NULL');
$queryBuilder->setParameter('roleIds', $roleIds);
$queryBuilder->setParameter('entityClass', $entityClass);
$queryBuilder->setParameter('permission', $permission);
} | php | protected function addAccessControl(
QueryBuilder $queryBuilder,
UserInterface $user,
$permission,
$entityClass,
$entityAlias
) {
$queryBuilder->leftJoin(
AccessControl::class,
'accessControl',
'WITH',
'accessControl.entityClass = :entityClass AND accessControl.entityId = ' . $entityAlias . '.id'
);
$queryBuilder->leftJoin('accessControl.role', 'role');
$queryBuilder->andWhere(
'BIT_AND(accessControl.permissions, :permission) = :permission OR accessControl.permissions IS NULL'
);
$roleIds = [];
foreach ($user->getRoleObjects() as $role) {
$roleIds[] = $role->getId();
}
$queryBuilder->andWhere('role.id IN(:roleIds) OR role.id IS NULL');
$queryBuilder->setParameter('roleIds', $roleIds);
$queryBuilder->setParameter('entityClass', $entityClass);
$queryBuilder->setParameter('permission', $permission);
} | [
"protected",
"function",
"addAccessControl",
"(",
"QueryBuilder",
"$",
"queryBuilder",
",",
"UserInterface",
"$",
"user",
",",
"$",
"permission",
",",
"$",
"entityClass",
",",
"$",
"entityAlias",
")",
"{",
"$",
"queryBuilder",
"->",
"leftJoin",
"(",
"AccessControl",
"::",
"class",
",",
"'accessControl'",
",",
"'WITH'",
",",
"'accessControl.entityClass = :entityClass AND accessControl.entityId = '",
".",
"$",
"entityAlias",
".",
"'.id'",
")",
";",
"$",
"queryBuilder",
"->",
"leftJoin",
"(",
"'accessControl.role'",
",",
"'role'",
")",
";",
"$",
"queryBuilder",
"->",
"andWhere",
"(",
"'BIT_AND(accessControl.permissions, :permission) = :permission OR accessControl.permissions IS NULL'",
")",
";",
"$",
"roleIds",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"user",
"->",
"getRoleObjects",
"(",
")",
"as",
"$",
"role",
")",
"{",
"$",
"roleIds",
"[",
"]",
"=",
"$",
"role",
"->",
"getId",
"(",
")",
";",
"}",
"$",
"queryBuilder",
"->",
"andWhere",
"(",
"'role.id IN(:roleIds) OR role.id IS NULL'",
")",
";",
"$",
"queryBuilder",
"->",
"setParameter",
"(",
"'roleIds'",
",",
"$",
"roleIds",
")",
";",
"$",
"queryBuilder",
"->",
"setParameter",
"(",
"'entityClass'",
",",
"$",
"entityClass",
")",
";",
"$",
"queryBuilder",
"->",
"setParameter",
"(",
"'permission'",
",",
"$",
"permission",
")",
";",
"}"
] | Adds joins and conditions to the QueryBuilder in order to only return entities the given user is allowed to see.
@param QueryBuilder $queryBuilder The instance of the QueryBuilder to adjust
@param UserInterface $user The user for which the access control is checked
@param int $permission The permission mask for which is checked
@param string $entityClass The class of the entity of which the access control is checked
@param string $entityAlias The alias of the entity used in the query builder | [
"Adds",
"joins",
"and",
"conditions",
"to",
"the",
"QueryBuilder",
"in",
"order",
"to",
"only",
"return",
"entities",
"the",
"given",
"user",
"is",
"allowed",
"to",
"see",
"."
] | 6766a36cc2f0c807c59202bf7540a08c4ef31192 | https://github.com/sulu/sulu/blob/6766a36cc2f0c807c59202bf7540a08c4ef31192/src/Sulu/Component/Security/Authorization/AccessControl/SecuredEntityRepositoryTrait.php#L32-L59 | train |
sulu/sulu | src/Sulu/Bundle/CoreBundle/DependencyInjection/SuluCoreExtension.php | SuluCoreExtension.initListBuilder | private function initListBuilder(ContainerBuilder $container, Loader\XmlFileLoader $loader)
{
if (SuluKernel::CONTEXT_ADMIN === $container->getParameter('sulu.context')) {
$loader->load('list_builder.xml');
}
} | php | private function initListBuilder(ContainerBuilder $container, Loader\XmlFileLoader $loader)
{
if (SuluKernel::CONTEXT_ADMIN === $container->getParameter('sulu.context')) {
$loader->load('list_builder.xml');
}
} | [
"private",
"function",
"initListBuilder",
"(",
"ContainerBuilder",
"$",
"container",
",",
"Loader",
"\\",
"XmlFileLoader",
"$",
"loader",
")",
"{",
"if",
"(",
"SuluKernel",
"::",
"CONTEXT_ADMIN",
"===",
"$",
"container",
"->",
"getParameter",
"(",
"'sulu.context'",
")",
")",
"{",
"$",
"loader",
"->",
"load",
"(",
"'list_builder.xml'",
")",
";",
"}",
"}"
] | Initializes list builder.
@param ContainerBuilder $container
@param Loader\XmlFileLoader $loader | [
"Initializes",
"list",
"builder",
"."
] | 6766a36cc2f0c807c59202bf7540a08c4ef31192 | https://github.com/sulu/sulu/blob/6766a36cc2f0c807c59202bf7540a08c4ef31192/src/Sulu/Bundle/CoreBundle/DependencyInjection/SuluCoreExtension.php#L397-L402 | train |
sulu/sulu | src/Sulu/Component/Content/Export/WebspaceExport.php | WebspaceExport.getExtensionData | protected function getExtensionData(BasePageDocument $document)
{
$extensionData = [];
foreach ($document->getExtensionsData()->toArray() as $extensionName => $extensionProperties) {
/** @var \Sulu\Bundle\PageBundle\Content\Structure\ExcerptStructureExtension $extension */
$extension = $this->extensionManager->getExtension($document->getStructureType(), $extensionName);
if ($extension instanceof ExportExtensionInterface) {
$extensionData[$extensionName] = $extension->export($extensionProperties, $this->format);
}
}
return $extensionData;
} | php | protected function getExtensionData(BasePageDocument $document)
{
$extensionData = [];
foreach ($document->getExtensionsData()->toArray() as $extensionName => $extensionProperties) {
/** @var \Sulu\Bundle\PageBundle\Content\Structure\ExcerptStructureExtension $extension */
$extension = $this->extensionManager->getExtension($document->getStructureType(), $extensionName);
if ($extension instanceof ExportExtensionInterface) {
$extensionData[$extensionName] = $extension->export($extensionProperties, $this->format);
}
}
return $extensionData;
} | [
"protected",
"function",
"getExtensionData",
"(",
"BasePageDocument",
"$",
"document",
")",
"{",
"$",
"extensionData",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"document",
"->",
"getExtensionsData",
"(",
")",
"->",
"toArray",
"(",
")",
"as",
"$",
"extensionName",
"=>",
"$",
"extensionProperties",
")",
"{",
"/** @var \\Sulu\\Bundle\\PageBundle\\Content\\Structure\\ExcerptStructureExtension $extension */",
"$",
"extension",
"=",
"$",
"this",
"->",
"extensionManager",
"->",
"getExtension",
"(",
"$",
"document",
"->",
"getStructureType",
"(",
")",
",",
"$",
"extensionName",
")",
";",
"if",
"(",
"$",
"extension",
"instanceof",
"ExportExtensionInterface",
")",
"{",
"$",
"extensionData",
"[",
"$",
"extensionName",
"]",
"=",
"$",
"extension",
"->",
"export",
"(",
"$",
"extensionProperties",
",",
"$",
"this",
"->",
"format",
")",
";",
"}",
"}",
"return",
"$",
"extensionData",
";",
"}"
] | Returns a flat array with the extensions of the given document.
@param BasePageDocument $document
@return array | [
"Returns",
"a",
"flat",
"array",
"with",
"the",
"extensions",
"of",
"the",
"given",
"document",
"."
] | 6766a36cc2f0c807c59202bf7540a08c4ef31192 | https://github.com/sulu/sulu/blob/6766a36cc2f0c807c59202bf7540a08c4ef31192/src/Sulu/Component/Content/Export/WebspaceExport.php#L148-L162 | train |
sulu/sulu | src/Sulu/Component/Content/Export/WebspaceExport.php | WebspaceExport.getSettingData | protected function getSettingData(BasePageDocument $document)
{
if ($created = $document->getCreated()) {
$created = $created->format('c');
}
if ($changed = $document->getChanged()) {
$changed = $changed->format('c');
}
if ($published = $document->getPublished()) {
$published = $published->format('c');
}
$settingOptions = [];
if ('1.2.xliff' === $this->format) {
$settingOptions = ['translate' => false];
}
return [
'structureType' => $this->createProperty('structureType', $document->getStructureType(), $settingOptions),
'published' => $this->createProperty('published', $published, $settingOptions),
'created' => $this->createProperty('created', $created, $settingOptions),
'changed' => $this->createProperty('changed', $changed, $settingOptions),
'creator' => $this->createProperty('creator', $document->getCreator(), $settingOptions),
'changer' => $this->createProperty('changer', $document->getChanger(), $settingOptions),
'locale' => $this->createProperty('locale', $document->getLocale(), $settingOptions),
'navigationContexts' => $this->createProperty(
'navigationContexts',
json_encode($document->getNavigationContexts()),
$settingOptions
),
'permissions' => $this->createProperty(
'permissions',
json_encode($document->getPermissions()),
$settingOptions
),
'shadowLocale' => $this->createProperty('shadowLocale', $document->getShadowLocale(), $settingOptions),
'originalLocale' => $this->createProperty(
'originalLocale',
$document->getOriginalLocale(),
$settingOptions
),
'resourceSegment' => $this->createProperty(
'resourceSegment',
$document->getResourceSegment(),
$settingOptions
),
'webspaceName' => $this->createProperty('webspaceName', $document->getWebspaceName(), $settingOptions),
'redirectExternal' => $this->createProperty(
'redirectExternal',
$document->getRedirectExternal(),
$settingOptions
),
'redirectType' => $this->createProperty('redirectType', $document->getRedirectType(), $settingOptions),
'redirectTarget' => $this->createProperty(
'redirectTarget',
$document->getRedirectTarget(),
$settingOptions
),
'workflowStage' => $this->createProperty('workflowStage', $document->getWorkflowStage(), $settingOptions),
'path' => $this->createProperty('path', $document->getPath(), $settingOptions),
];
} | php | protected function getSettingData(BasePageDocument $document)
{
if ($created = $document->getCreated()) {
$created = $created->format('c');
}
if ($changed = $document->getChanged()) {
$changed = $changed->format('c');
}
if ($published = $document->getPublished()) {
$published = $published->format('c');
}
$settingOptions = [];
if ('1.2.xliff' === $this->format) {
$settingOptions = ['translate' => false];
}
return [
'structureType' => $this->createProperty('structureType', $document->getStructureType(), $settingOptions),
'published' => $this->createProperty('published', $published, $settingOptions),
'created' => $this->createProperty('created', $created, $settingOptions),
'changed' => $this->createProperty('changed', $changed, $settingOptions),
'creator' => $this->createProperty('creator', $document->getCreator(), $settingOptions),
'changer' => $this->createProperty('changer', $document->getChanger(), $settingOptions),
'locale' => $this->createProperty('locale', $document->getLocale(), $settingOptions),
'navigationContexts' => $this->createProperty(
'navigationContexts',
json_encode($document->getNavigationContexts()),
$settingOptions
),
'permissions' => $this->createProperty(
'permissions',
json_encode($document->getPermissions()),
$settingOptions
),
'shadowLocale' => $this->createProperty('shadowLocale', $document->getShadowLocale(), $settingOptions),
'originalLocale' => $this->createProperty(
'originalLocale',
$document->getOriginalLocale(),
$settingOptions
),
'resourceSegment' => $this->createProperty(
'resourceSegment',
$document->getResourceSegment(),
$settingOptions
),
'webspaceName' => $this->createProperty('webspaceName', $document->getWebspaceName(), $settingOptions),
'redirectExternal' => $this->createProperty(
'redirectExternal',
$document->getRedirectExternal(),
$settingOptions
),
'redirectType' => $this->createProperty('redirectType', $document->getRedirectType(), $settingOptions),
'redirectTarget' => $this->createProperty(
'redirectTarget',
$document->getRedirectTarget(),
$settingOptions
),
'workflowStage' => $this->createProperty('workflowStage', $document->getWorkflowStage(), $settingOptions),
'path' => $this->createProperty('path', $document->getPath(), $settingOptions),
];
} | [
"protected",
"function",
"getSettingData",
"(",
"BasePageDocument",
"$",
"document",
")",
"{",
"if",
"(",
"$",
"created",
"=",
"$",
"document",
"->",
"getCreated",
"(",
")",
")",
"{",
"$",
"created",
"=",
"$",
"created",
"->",
"format",
"(",
"'c'",
")",
";",
"}",
"if",
"(",
"$",
"changed",
"=",
"$",
"document",
"->",
"getChanged",
"(",
")",
")",
"{",
"$",
"changed",
"=",
"$",
"changed",
"->",
"format",
"(",
"'c'",
")",
";",
"}",
"if",
"(",
"$",
"published",
"=",
"$",
"document",
"->",
"getPublished",
"(",
")",
")",
"{",
"$",
"published",
"=",
"$",
"published",
"->",
"format",
"(",
"'c'",
")",
";",
"}",
"$",
"settingOptions",
"=",
"[",
"]",
";",
"if",
"(",
"'1.2.xliff'",
"===",
"$",
"this",
"->",
"format",
")",
"{",
"$",
"settingOptions",
"=",
"[",
"'translate'",
"=>",
"false",
"]",
";",
"}",
"return",
"[",
"'structureType'",
"=>",
"$",
"this",
"->",
"createProperty",
"(",
"'structureType'",
",",
"$",
"document",
"->",
"getStructureType",
"(",
")",
",",
"$",
"settingOptions",
")",
",",
"'published'",
"=>",
"$",
"this",
"->",
"createProperty",
"(",
"'published'",
",",
"$",
"published",
",",
"$",
"settingOptions",
")",
",",
"'created'",
"=>",
"$",
"this",
"->",
"createProperty",
"(",
"'created'",
",",
"$",
"created",
",",
"$",
"settingOptions",
")",
",",
"'changed'",
"=>",
"$",
"this",
"->",
"createProperty",
"(",
"'changed'",
",",
"$",
"changed",
",",
"$",
"settingOptions",
")",
",",
"'creator'",
"=>",
"$",
"this",
"->",
"createProperty",
"(",
"'creator'",
",",
"$",
"document",
"->",
"getCreator",
"(",
")",
",",
"$",
"settingOptions",
")",
",",
"'changer'",
"=>",
"$",
"this",
"->",
"createProperty",
"(",
"'changer'",
",",
"$",
"document",
"->",
"getChanger",
"(",
")",
",",
"$",
"settingOptions",
")",
",",
"'locale'",
"=>",
"$",
"this",
"->",
"createProperty",
"(",
"'locale'",
",",
"$",
"document",
"->",
"getLocale",
"(",
")",
",",
"$",
"settingOptions",
")",
",",
"'navigationContexts'",
"=>",
"$",
"this",
"->",
"createProperty",
"(",
"'navigationContexts'",
",",
"json_encode",
"(",
"$",
"document",
"->",
"getNavigationContexts",
"(",
")",
")",
",",
"$",
"settingOptions",
")",
",",
"'permissions'",
"=>",
"$",
"this",
"->",
"createProperty",
"(",
"'permissions'",
",",
"json_encode",
"(",
"$",
"document",
"->",
"getPermissions",
"(",
")",
")",
",",
"$",
"settingOptions",
")",
",",
"'shadowLocale'",
"=>",
"$",
"this",
"->",
"createProperty",
"(",
"'shadowLocale'",
",",
"$",
"document",
"->",
"getShadowLocale",
"(",
")",
",",
"$",
"settingOptions",
")",
",",
"'originalLocale'",
"=>",
"$",
"this",
"->",
"createProperty",
"(",
"'originalLocale'",
",",
"$",
"document",
"->",
"getOriginalLocale",
"(",
")",
",",
"$",
"settingOptions",
")",
",",
"'resourceSegment'",
"=>",
"$",
"this",
"->",
"createProperty",
"(",
"'resourceSegment'",
",",
"$",
"document",
"->",
"getResourceSegment",
"(",
")",
",",
"$",
"settingOptions",
")",
",",
"'webspaceName'",
"=>",
"$",
"this",
"->",
"createProperty",
"(",
"'webspaceName'",
",",
"$",
"document",
"->",
"getWebspaceName",
"(",
")",
",",
"$",
"settingOptions",
")",
",",
"'redirectExternal'",
"=>",
"$",
"this",
"->",
"createProperty",
"(",
"'redirectExternal'",
",",
"$",
"document",
"->",
"getRedirectExternal",
"(",
")",
",",
"$",
"settingOptions",
")",
",",
"'redirectType'",
"=>",
"$",
"this",
"->",
"createProperty",
"(",
"'redirectType'",
",",
"$",
"document",
"->",
"getRedirectType",
"(",
")",
",",
"$",
"settingOptions",
")",
",",
"'redirectTarget'",
"=>",
"$",
"this",
"->",
"createProperty",
"(",
"'redirectTarget'",
",",
"$",
"document",
"->",
"getRedirectTarget",
"(",
")",
",",
"$",
"settingOptions",
")",
",",
"'workflowStage'",
"=>",
"$",
"this",
"->",
"createProperty",
"(",
"'workflowStage'",
",",
"$",
"document",
"->",
"getWorkflowStage",
"(",
")",
",",
"$",
"settingOptions",
")",
",",
"'path'",
"=>",
"$",
"this",
"->",
"createProperty",
"(",
"'path'",
",",
"$",
"document",
"->",
"getPath",
"(",
")",
",",
"$",
"settingOptions",
")",
",",
"]",
";",
"}"
] | Returns a flat array with the settings of the given document.
@param BasePageDocument $document
@return array | [
"Returns",
"a",
"flat",
"array",
"with",
"the",
"settings",
"of",
"the",
"given",
"document",
"."
] | 6766a36cc2f0c807c59202bf7540a08c4ef31192 | https://github.com/sulu/sulu/blob/6766a36cc2f0c807c59202bf7540a08c4ef31192/src/Sulu/Component/Content/Export/WebspaceExport.php#L171-L234 | train |
sulu/sulu | src/Sulu/Component/Content/Export/WebspaceExport.php | WebspaceExport.getDocuments | protected function getDocuments($webspaceKey, $uuid = null, $nodes = null, $ignoredNodes = null)
{
$queryString = $this->getDocumentsQueryString($webspaceKey, $uuid, $nodes, $ignoredNodes);
$query = $this->documentManager->createQuery($queryString, $this->exportLocale);
return $query->execute();
} | php | protected function getDocuments($webspaceKey, $uuid = null, $nodes = null, $ignoredNodes = null)
{
$queryString = $this->getDocumentsQueryString($webspaceKey, $uuid, $nodes, $ignoredNodes);
$query = $this->documentManager->createQuery($queryString, $this->exportLocale);
return $query->execute();
} | [
"protected",
"function",
"getDocuments",
"(",
"$",
"webspaceKey",
",",
"$",
"uuid",
"=",
"null",
",",
"$",
"nodes",
"=",
"null",
",",
"$",
"ignoredNodes",
"=",
"null",
")",
"{",
"$",
"queryString",
"=",
"$",
"this",
"->",
"getDocumentsQueryString",
"(",
"$",
"webspaceKey",
",",
"$",
"uuid",
",",
"$",
"nodes",
",",
"$",
"ignoredNodes",
")",
";",
"$",
"query",
"=",
"$",
"this",
"->",
"documentManager",
"->",
"createQuery",
"(",
"$",
"queryString",
",",
"$",
"this",
"->",
"exportLocale",
")",
";",
"return",
"$",
"query",
"->",
"execute",
"(",
")",
";",
"}"
] | Returns all Documents from given webspace.
@param string $webspaceKey
@param string $uuid
@param array $nodes
@param array $ignoredNodes
@return array
@throws DocumentManagerException | [
"Returns",
"all",
"Documents",
"from",
"given",
"webspace",
"."
] | 6766a36cc2f0c807c59202bf7540a08c4ef31192 | https://github.com/sulu/sulu/blob/6766a36cc2f0c807c59202bf7540a08c4ef31192/src/Sulu/Component/Content/Export/WebspaceExport.php#L248-L255 | train |
sulu/sulu | src/Sulu/Component/Content/Export/WebspaceExport.php | WebspaceExport.getDocumentsQueryString | protected function getDocumentsQueryString($webspaceKey, $uuid = null, $nodes = null, $ignoredNodes = null)
{
$where = [];
// only pages
$where[] = '([jcr:mixinTypes] = "sulu:page" OR [jcr:mixinTypes] = "sulu:home")';
// filter by webspace key
$where[] = sprintf(
'(ISDESCENDANTNODE("/cmf/%s/contents") OR ISSAMENODE("/cmf/%s/contents"))',
$webspaceKey,
$webspaceKey
);
// filter by locale
$where[] = sprintf(
'[i18n:%s-template] IS NOT NULL',
$this->exportLocale
);
// filter by uuid
if ($uuid) {
$where[] = sprintf('[jcr:uuid] = "%s"', $uuid);
}
$nodeWhere = $this->buildNodeUuidToPathWhere($nodes, false);
if ($nodeWhere) {
$where[] = $nodeWhere;
}
$ignoreWhere = $this->buildNodeUuidToPathWhere($ignoredNodes, true);
if ($ignoreWhere) {
$where[] = $ignoreWhere;
}
$queryString = 'SELECT * FROM [nt:unstructured] AS a WHERE ' . implode(' AND ', $where);
return $queryString;
} | php | protected function getDocumentsQueryString($webspaceKey, $uuid = null, $nodes = null, $ignoredNodes = null)
{
$where = [];
// only pages
$where[] = '([jcr:mixinTypes] = "sulu:page" OR [jcr:mixinTypes] = "sulu:home")';
// filter by webspace key
$where[] = sprintf(
'(ISDESCENDANTNODE("/cmf/%s/contents") OR ISSAMENODE("/cmf/%s/contents"))',
$webspaceKey,
$webspaceKey
);
// filter by locale
$where[] = sprintf(
'[i18n:%s-template] IS NOT NULL',
$this->exportLocale
);
// filter by uuid
if ($uuid) {
$where[] = sprintf('[jcr:uuid] = "%s"', $uuid);
}
$nodeWhere = $this->buildNodeUuidToPathWhere($nodes, false);
if ($nodeWhere) {
$where[] = $nodeWhere;
}
$ignoreWhere = $this->buildNodeUuidToPathWhere($ignoredNodes, true);
if ($ignoreWhere) {
$where[] = $ignoreWhere;
}
$queryString = 'SELECT * FROM [nt:unstructured] AS a WHERE ' . implode(' AND ', $where);
return $queryString;
} | [
"protected",
"function",
"getDocumentsQueryString",
"(",
"$",
"webspaceKey",
",",
"$",
"uuid",
"=",
"null",
",",
"$",
"nodes",
"=",
"null",
",",
"$",
"ignoredNodes",
"=",
"null",
")",
"{",
"$",
"where",
"=",
"[",
"]",
";",
"// only pages",
"$",
"where",
"[",
"]",
"=",
"'([jcr:mixinTypes] = \"sulu:page\" OR [jcr:mixinTypes] = \"sulu:home\")'",
";",
"// filter by webspace key",
"$",
"where",
"[",
"]",
"=",
"sprintf",
"(",
"'(ISDESCENDANTNODE(\"/cmf/%s/contents\") OR ISSAMENODE(\"/cmf/%s/contents\"))'",
",",
"$",
"webspaceKey",
",",
"$",
"webspaceKey",
")",
";",
"// filter by locale",
"$",
"where",
"[",
"]",
"=",
"sprintf",
"(",
"'[i18n:%s-template] IS NOT NULL'",
",",
"$",
"this",
"->",
"exportLocale",
")",
";",
"// filter by uuid",
"if",
"(",
"$",
"uuid",
")",
"{",
"$",
"where",
"[",
"]",
"=",
"sprintf",
"(",
"'[jcr:uuid] = \"%s\"'",
",",
"$",
"uuid",
")",
";",
"}",
"$",
"nodeWhere",
"=",
"$",
"this",
"->",
"buildNodeUuidToPathWhere",
"(",
"$",
"nodes",
",",
"false",
")",
";",
"if",
"(",
"$",
"nodeWhere",
")",
"{",
"$",
"where",
"[",
"]",
"=",
"$",
"nodeWhere",
";",
"}",
"$",
"ignoreWhere",
"=",
"$",
"this",
"->",
"buildNodeUuidToPathWhere",
"(",
"$",
"ignoredNodes",
",",
"true",
")",
";",
"if",
"(",
"$",
"ignoreWhere",
")",
"{",
"$",
"where",
"[",
"]",
"=",
"$",
"ignoreWhere",
";",
"}",
"$",
"queryString",
"=",
"'SELECT * FROM [nt:unstructured] AS a WHERE '",
".",
"implode",
"(",
"' AND '",
",",
"$",
"where",
")",
";",
"return",
"$",
"queryString",
";",
"}"
] | Create the query to get all documents from given webspace and language.
@param string $webspaceKey
@param string $uuid
@param array $nodes
@param array $ignoredNodes
@return string
@throws DocumentManagerException | [
"Create",
"the",
"query",
"to",
"get",
"all",
"documents",
"from",
"given",
"webspace",
"and",
"language",
"."
] | 6766a36cc2f0c807c59202bf7540a08c4ef31192 | https://github.com/sulu/sulu/blob/6766a36cc2f0c807c59202bf7540a08c4ef31192/src/Sulu/Component/Content/Export/WebspaceExport.php#L269-L308 | train |
sulu/sulu | src/Sulu/Component/Content/Export/WebspaceExport.php | WebspaceExport.buildNodeUuidToPathWhere | protected function buildNodeUuidToPathWhere($nodes, $not = false)
{
if ($nodes) {
$paths = $this->getPathsByUuids($nodes);
$wheres = [];
foreach ($nodes as $key => $uuid) {
if (isset($paths[$uuid])) {
$wheres[] = sprintf('ISDESCENDANTNODE("%s")', $paths[$uuid]);
}
}
if (!empty($wheres)) {
return ($not ? 'NOT ' : '') . '(' . implode(' OR ', $wheres) . ')';
}
}
} | php | protected function buildNodeUuidToPathWhere($nodes, $not = false)
{
if ($nodes) {
$paths = $this->getPathsByUuids($nodes);
$wheres = [];
foreach ($nodes as $key => $uuid) {
if (isset($paths[$uuid])) {
$wheres[] = sprintf('ISDESCENDANTNODE("%s")', $paths[$uuid]);
}
}
if (!empty($wheres)) {
return ($not ? 'NOT ' : '') . '(' . implode(' OR ', $wheres) . ')';
}
}
} | [
"protected",
"function",
"buildNodeUuidToPathWhere",
"(",
"$",
"nodes",
",",
"$",
"not",
"=",
"false",
")",
"{",
"if",
"(",
"$",
"nodes",
")",
"{",
"$",
"paths",
"=",
"$",
"this",
"->",
"getPathsByUuids",
"(",
"$",
"nodes",
")",
";",
"$",
"wheres",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"nodes",
"as",
"$",
"key",
"=>",
"$",
"uuid",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"paths",
"[",
"$",
"uuid",
"]",
")",
")",
"{",
"$",
"wheres",
"[",
"]",
"=",
"sprintf",
"(",
"'ISDESCENDANTNODE(\"%s\")'",
",",
"$",
"paths",
"[",
"$",
"uuid",
"]",
")",
";",
"}",
"}",
"if",
"(",
"!",
"empty",
"(",
"$",
"wheres",
")",
")",
"{",
"return",
"(",
"$",
"not",
"?",
"'NOT '",
":",
"''",
")",
".",
"'('",
".",
"implode",
"(",
"' OR '",
",",
"$",
"wheres",
")",
".",
"')'",
";",
"}",
"}",
"}"
] | Build query to return only specific nodes.
@param $nodes
@param bool|false $not
@return string
@throws DocumentManagerException | [
"Build",
"query",
"to",
"return",
"only",
"specific",
"nodes",
"."
] | 6766a36cc2f0c807c59202bf7540a08c4ef31192 | https://github.com/sulu/sulu/blob/6766a36cc2f0c807c59202bf7540a08c4ef31192/src/Sulu/Component/Content/Export/WebspaceExport.php#L320-L336 | train |
sulu/sulu | src/Sulu/Component/Content/Export/WebspaceExport.php | WebspaceExport.getPathsByUuids | protected function getPathsByUuids($uuids)
{
$paths = [];
$where = [];
foreach ($uuids as $uuid) {
$where[] = sprintf('[jcr:uuid] = "%s"', $uuid);
}
$queryString = 'SELECT * FROM [nt:unstructured] AS a WHERE ' . implode(' OR ', $where);
$query = $this->documentManager->createQuery($queryString);
$result = $query->execute();
/** @var BasePageDocument $page */
foreach ($result as $page) {
$paths[$page->getUuid()] = $page->getPath();
}
return $paths;
} | php | protected function getPathsByUuids($uuids)
{
$paths = [];
$where = [];
foreach ($uuids as $uuid) {
$where[] = sprintf('[jcr:uuid] = "%s"', $uuid);
}
$queryString = 'SELECT * FROM [nt:unstructured] AS a WHERE ' . implode(' OR ', $where);
$query = $this->documentManager->createQuery($queryString);
$result = $query->execute();
/** @var BasePageDocument $page */
foreach ($result as $page) {
$paths[$page->getUuid()] = $page->getPath();
}
return $paths;
} | [
"protected",
"function",
"getPathsByUuids",
"(",
"$",
"uuids",
")",
"{",
"$",
"paths",
"=",
"[",
"]",
";",
"$",
"where",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"uuids",
"as",
"$",
"uuid",
")",
"{",
"$",
"where",
"[",
"]",
"=",
"sprintf",
"(",
"'[jcr:uuid] = \"%s\"'",
",",
"$",
"uuid",
")",
";",
"}",
"$",
"queryString",
"=",
"'SELECT * FROM [nt:unstructured] AS a WHERE '",
".",
"implode",
"(",
"' OR '",
",",
"$",
"where",
")",
";",
"$",
"query",
"=",
"$",
"this",
"->",
"documentManager",
"->",
"createQuery",
"(",
"$",
"queryString",
")",
";",
"$",
"result",
"=",
"$",
"query",
"->",
"execute",
"(",
")",
";",
"/** @var BasePageDocument $page */",
"foreach",
"(",
"$",
"result",
"as",
"$",
"page",
")",
"{",
"$",
"paths",
"[",
"$",
"page",
"->",
"getUuid",
"(",
")",
"]",
"=",
"$",
"page",
"->",
"getPath",
"(",
")",
";",
"}",
"return",
"$",
"paths",
";",
"}"
] | Returns node path from given uuid.
@param $uuids
@return string[]
@throws DocumentManagerException | [
"Returns",
"node",
"path",
"from",
"given",
"uuid",
"."
] | 6766a36cc2f0c807c59202bf7540a08c4ef31192 | https://github.com/sulu/sulu/blob/6766a36cc2f0c807c59202bf7540a08c4ef31192/src/Sulu/Component/Content/Export/WebspaceExport.php#L347-L368 | train |
sulu/sulu | src/Sulu/Bundle/PageBundle/EventListener/TeaserSerializeEventSubscriber.php | TeaserSerializeEventSubscriber.onPostSerialize | public function onPostSerialize(ObjectEvent $event)
{
$teaser = $event->getObject();
$visitor = $event->getVisitor();
$context = $event->getContext();
if (!($teaser instanceof Teaser)) {
return;
}
$visitor->addData('teaserId', $context->accept(sprintf('%s;%s', $teaser->getType(), $teaser->getId())));
} | php | public function onPostSerialize(ObjectEvent $event)
{
$teaser = $event->getObject();
$visitor = $event->getVisitor();
$context = $event->getContext();
if (!($teaser instanceof Teaser)) {
return;
}
$visitor->addData('teaserId', $context->accept(sprintf('%s;%s', $teaser->getType(), $teaser->getId())));
} | [
"public",
"function",
"onPostSerialize",
"(",
"ObjectEvent",
"$",
"event",
")",
"{",
"$",
"teaser",
"=",
"$",
"event",
"->",
"getObject",
"(",
")",
";",
"$",
"visitor",
"=",
"$",
"event",
"->",
"getVisitor",
"(",
")",
";",
"$",
"context",
"=",
"$",
"event",
"->",
"getContext",
"(",
")",
";",
"if",
"(",
"!",
"(",
"$",
"teaser",
"instanceof",
"Teaser",
")",
")",
"{",
"return",
";",
"}",
"$",
"visitor",
"->",
"addData",
"(",
"'teaserId'",
",",
"$",
"context",
"->",
"accept",
"(",
"sprintf",
"(",
"'%s;%s'",
",",
"$",
"teaser",
"->",
"getType",
"(",
")",
",",
"$",
"teaser",
"->",
"getId",
"(",
")",
")",
")",
")",
";",
"}"
] | Add uniqueid and media-data to serialized data.
@param ObjectEvent $event | [
"Add",
"uniqueid",
"and",
"media",
"-",
"data",
"to",
"serialized",
"data",
"."
] | 6766a36cc2f0c807c59202bf7540a08c4ef31192 | https://github.com/sulu/sulu/blob/6766a36cc2f0c807c59202bf7540a08c4ef31192/src/Sulu/Bundle/PageBundle/EventListener/TeaserSerializeEventSubscriber.php#L57-L68 | train |
sulu/sulu | src/Sulu/Component/DocumentManager/Subscriber/Behavior/Mapping/NodeNameSubscriber.php | NodeNameSubscriber.setNodeName | private function setNodeName(AbstractMappingEvent $event)
{
$document = $event->getDocument();
if (!$document instanceof NodeNameBehavior) {
return;
}
$node = $event->getNode();
$accessor = $event->getAccessor();
$accessor->set(
'nodeName',
$node->getName()
);
} | php | private function setNodeName(AbstractMappingEvent $event)
{
$document = $event->getDocument();
if (!$document instanceof NodeNameBehavior) {
return;
}
$node = $event->getNode();
$accessor = $event->getAccessor();
$accessor->set(
'nodeName',
$node->getName()
);
} | [
"private",
"function",
"setNodeName",
"(",
"AbstractMappingEvent",
"$",
"event",
")",
"{",
"$",
"document",
"=",
"$",
"event",
"->",
"getDocument",
"(",
")",
";",
"if",
"(",
"!",
"$",
"document",
"instanceof",
"NodeNameBehavior",
")",
"{",
"return",
";",
"}",
"$",
"node",
"=",
"$",
"event",
"->",
"getNode",
"(",
")",
";",
"$",
"accessor",
"=",
"$",
"event",
"->",
"getAccessor",
"(",
")",
";",
"$",
"accessor",
"->",
"set",
"(",
"'nodeName'",
",",
"$",
"node",
"->",
"getName",
"(",
")",
")",
";",
"}"
] | Sets the node name.
@param AbstractMappingEvent $event
@throws DocumentManagerException | [
"Sets",
"the",
"node",
"name",
"."
] | 6766a36cc2f0c807c59202bf7540a08c4ef31192 | https://github.com/sulu/sulu/blob/6766a36cc2f0c807c59202bf7540a08c4ef31192/src/Sulu/Component/DocumentManager/Subscriber/Behavior/Mapping/NodeNameSubscriber.php#L66-L80 | train |
sulu/sulu | src/Sulu/Component/Import/Format/Xliff12.php | Xliff12.getChildPropertyDatas | private function getChildPropertyDatas($child)
{
$childProperties = [];
foreach (array_keys($child) as $childKey) {
$childProperties[$childKey] = $this->getPropertyData($childKey, $child, $contentTypeName = null, $extension = null);
}
return $childProperties;
} | php | private function getChildPropertyDatas($child)
{
$childProperties = [];
foreach (array_keys($child) as $childKey) {
$childProperties[$childKey] = $this->getPropertyData($childKey, $child, $contentTypeName = null, $extension = null);
}
return $childProperties;
} | [
"private",
"function",
"getChildPropertyDatas",
"(",
"$",
"child",
")",
"{",
"$",
"childProperties",
"=",
"[",
"]",
";",
"foreach",
"(",
"array_keys",
"(",
"$",
"child",
")",
"as",
"$",
"childKey",
")",
"{",
"$",
"childProperties",
"[",
"$",
"childKey",
"]",
"=",
"$",
"this",
"->",
"getPropertyData",
"(",
"$",
"childKey",
",",
"$",
"child",
",",
"$",
"contentTypeName",
"=",
"null",
",",
"$",
"extension",
"=",
"null",
")",
";",
"}",
"return",
"$",
"childProperties",
";",
"}"
] | Prepare data for structure.
@param $child
@return array | [
"Prepare",
"data",
"for",
"structure",
"."
] | 6766a36cc2f0c807c59202bf7540a08c4ef31192 | https://github.com/sulu/sulu/blob/6766a36cc2f0c807c59202bf7540a08c4ef31192/src/Sulu/Component/Import/Format/Xliff12.php#L84-L92 | train |
sulu/sulu | src/Sulu/Component/Import/Format/Xliff12.php | Xliff12.utf8ToCharset | private function utf8ToCharset($content, $encoding = null)
{
if ('UTF-8' !== $encoding && !empty($encoding)) {
if (function_exists('mb_convert_encoding')) {
return mb_convert_encoding($content, $encoding, 'UTF-8');
}
if (function_exists('iconv')) {
return iconv('UTF-8', $encoding, $content);
}
throw new \RuntimeException('No suitable convert encoding function (use UTF-8 as your encoding or install the iconv or mbstring extension).');
}
return $content;
} | php | private function utf8ToCharset($content, $encoding = null)
{
if ('UTF-8' !== $encoding && !empty($encoding)) {
if (function_exists('mb_convert_encoding')) {
return mb_convert_encoding($content, $encoding, 'UTF-8');
}
if (function_exists('iconv')) {
return iconv('UTF-8', $encoding, $content);
}
throw new \RuntimeException('No suitable convert encoding function (use UTF-8 as your encoding or install the iconv or mbstring extension).');
}
return $content;
} | [
"private",
"function",
"utf8ToCharset",
"(",
"$",
"content",
",",
"$",
"encoding",
"=",
"null",
")",
"{",
"if",
"(",
"'UTF-8'",
"!==",
"$",
"encoding",
"&&",
"!",
"empty",
"(",
"$",
"encoding",
")",
")",
"{",
"if",
"(",
"function_exists",
"(",
"'mb_convert_encoding'",
")",
")",
"{",
"return",
"mb_convert_encoding",
"(",
"$",
"content",
",",
"$",
"encoding",
",",
"'UTF-8'",
")",
";",
"}",
"if",
"(",
"function_exists",
"(",
"'iconv'",
")",
")",
"{",
"return",
"iconv",
"(",
"'UTF-8'",
",",
"$",
"encoding",
",",
"$",
"content",
")",
";",
"}",
"throw",
"new",
"\\",
"RuntimeException",
"(",
"'No suitable convert encoding function (use UTF-8 as your encoding or install the iconv or mbstring extension).'",
")",
";",
"}",
"return",
"$",
"content",
";",
"}"
] | Part of Symfony XliffFileLoader.
@param string $content String to decode
@param string $encoding Target encoding
@return string | [
"Part",
"of",
"Symfony",
"XliffFileLoader",
"."
] | 6766a36cc2f0c807c59202bf7540a08c4ef31192 | https://github.com/sulu/sulu/blob/6766a36cc2f0c807c59202bf7540a08c4ef31192/src/Sulu/Component/Import/Format/Xliff12.php#L202-L217 | train |
sulu/sulu | src/Sulu/Bundle/SnippetBundle/DependencyInjection/Compiler/SnippetAreaCompilerPass.php | SnippetAreaCompilerPass.getArea | private function getArea($template, $area, $locales, $templateTitles)
{
$key = $area['key'];
$titles = [];
foreach ($locales as $locale) {
$title = $templateTitles[$locale] . ' ' . ucfirst($key);
if (isset($area['title'][$locale])) {
$title = $area['title'][$locale];
}
$titles[$locale] = $title;
}
return [
'key' => $key,
'template' => $template,
'title' => $titles,
];
} | php | private function getArea($template, $area, $locales, $templateTitles)
{
$key = $area['key'];
$titles = [];
foreach ($locales as $locale) {
$title = $templateTitles[$locale] . ' ' . ucfirst($key);
if (isset($area['title'][$locale])) {
$title = $area['title'][$locale];
}
$titles[$locale] = $title;
}
return [
'key' => $key,
'template' => $template,
'title' => $titles,
];
} | [
"private",
"function",
"getArea",
"(",
"$",
"template",
",",
"$",
"area",
",",
"$",
"locales",
",",
"$",
"templateTitles",
")",
"{",
"$",
"key",
"=",
"$",
"area",
"[",
"'key'",
"]",
";",
"$",
"titles",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"locales",
"as",
"$",
"locale",
")",
"{",
"$",
"title",
"=",
"$",
"templateTitles",
"[",
"$",
"locale",
"]",
".",
"' '",
".",
"ucfirst",
"(",
"$",
"key",
")",
";",
"if",
"(",
"isset",
"(",
"$",
"area",
"[",
"'title'",
"]",
"[",
"$",
"locale",
"]",
")",
")",
"{",
"$",
"title",
"=",
"$",
"area",
"[",
"'title'",
"]",
"[",
"$",
"locale",
"]",
";",
"}",
"$",
"titles",
"[",
"$",
"locale",
"]",
"=",
"$",
"title",
";",
"}",
"return",
"[",
"'key'",
"=>",
"$",
"key",
",",
"'template'",
"=>",
"$",
"template",
",",
"'title'",
"=>",
"$",
"titles",
",",
"]",
";",
"}"
] | Get area.
@return array | [
"Get",
"area",
"."
] | 6766a36cc2f0c807c59202bf7540a08c4ef31192 | https://github.com/sulu/sulu/blob/6766a36cc2f0c807c59202bf7540a08c4ef31192/src/Sulu/Bundle/SnippetBundle/DependencyInjection/Compiler/SnippetAreaCompilerPass.php#L82-L102 | train |
sulu/sulu | src/Sulu/Bundle/ResourceBundle/Entity/Condition.php | Condition.setConditionGroup | public function setConditionGroup(\Sulu\Bundle\ResourceBundle\Entity\ConditionGroup $conditionGroup)
{
$this->conditionGroup = $conditionGroup;
return $this;
} | php | public function setConditionGroup(\Sulu\Bundle\ResourceBundle\Entity\ConditionGroup $conditionGroup)
{
$this->conditionGroup = $conditionGroup;
return $this;
} | [
"public",
"function",
"setConditionGroup",
"(",
"\\",
"Sulu",
"\\",
"Bundle",
"\\",
"ResourceBundle",
"\\",
"Entity",
"\\",
"ConditionGroup",
"$",
"conditionGroup",
")",
"{",
"$",
"this",
"->",
"conditionGroup",
"=",
"$",
"conditionGroup",
";",
"return",
"$",
"this",
";",
"}"
] | Set conditionGroup.
@param \Sulu\Bundle\ResourceBundle\Entity\ConditionGroup $conditionGroup
@return Condition | [
"Set",
"conditionGroup",
"."
] | 6766a36cc2f0c807c59202bf7540a08c4ef31192 | https://github.com/sulu/sulu/blob/6766a36cc2f0c807c59202bf7540a08c4ef31192/src/Sulu/Bundle/ResourceBundle/Entity/Condition.php#L168-L173 | train |
sulu/sulu | src/Sulu/Bundle/AudienceTargetingBundle/Serializer/Subscriber/TargetGroupRuleSerializeSubscriber.php | TargetGroupRuleSerializeSubscriber.onPostDeserialize | public function onPostDeserialize(ObjectEvent $event)
{
/** @var TargetGroupRuleInterface $targetGroupRule */
$targetGroupRule = $event->getObject();
if (!$targetGroupRule instanceof TargetGroupRuleInterface) {
return;
}
if ($targetGroupRule->getConditions()) {
foreach ($targetGroupRule->getConditions() as $condition) {
$condition->setRule($targetGroupRule);
}
}
} | php | public function onPostDeserialize(ObjectEvent $event)
{
/** @var TargetGroupRuleInterface $targetGroupRule */
$targetGroupRule = $event->getObject();
if (!$targetGroupRule instanceof TargetGroupRuleInterface) {
return;
}
if ($targetGroupRule->getConditions()) {
foreach ($targetGroupRule->getConditions() as $condition) {
$condition->setRule($targetGroupRule);
}
}
} | [
"public",
"function",
"onPostDeserialize",
"(",
"ObjectEvent",
"$",
"event",
")",
"{",
"/** @var TargetGroupRuleInterface $targetGroupRule */",
"$",
"targetGroupRule",
"=",
"$",
"event",
"->",
"getObject",
"(",
")",
";",
"if",
"(",
"!",
"$",
"targetGroupRule",
"instanceof",
"TargetGroupRuleInterface",
")",
"{",
"return",
";",
"}",
"if",
"(",
"$",
"targetGroupRule",
"->",
"getConditions",
"(",
")",
")",
"{",
"foreach",
"(",
"$",
"targetGroupRule",
"->",
"getConditions",
"(",
")",
"as",
"$",
"condition",
")",
"{",
"$",
"condition",
"->",
"setRule",
"(",
"$",
"targetGroupRule",
")",
";",
"}",
"}",
"}"
] | Called after a target group rule was deserialized.
@param ObjectEvent $event | [
"Called",
"after",
"a",
"target",
"group",
"rule",
"was",
"deserialized",
"."
] | 6766a36cc2f0c807c59202bf7540a08c4ef31192 | https://github.com/sulu/sulu/blob/6766a36cc2f0c807c59202bf7540a08c4ef31192/src/Sulu/Bundle/AudienceTargetingBundle/Serializer/Subscriber/TargetGroupRuleSerializeSubscriber.php#L40-L54 | train |
sulu/sulu | src/Sulu/Bundle/WebsiteBundle/Navigation/NavigationQueryBuilder.php | NavigationQueryBuilder.buildWhere | protected function buildWhere($webspaceKey, $locale)
{
$where = [];
if (null !== $this->context) {
$where[] = sprintf("page.[i18n:%s-navContexts] = '%s'", $locale, $this->context);
}
if (null !== $this->parent) {
$where[] = sprintf("ISDESCENDANTNODE(page, '%s')", $this->parent);
} else {
$where[] = sprintf("ISDESCENDANTNODE(page, '%s')", '/cmf/' . $webspaceKey . '/contents');
}
return implode(' AND ', $where);
} | php | protected function buildWhere($webspaceKey, $locale)
{
$where = [];
if (null !== $this->context) {
$where[] = sprintf("page.[i18n:%s-navContexts] = '%s'", $locale, $this->context);
}
if (null !== $this->parent) {
$where[] = sprintf("ISDESCENDANTNODE(page, '%s')", $this->parent);
} else {
$where[] = sprintf("ISDESCENDANTNODE(page, '%s')", '/cmf/' . $webspaceKey . '/contents');
}
return implode(' AND ', $where);
} | [
"protected",
"function",
"buildWhere",
"(",
"$",
"webspaceKey",
",",
"$",
"locale",
")",
"{",
"$",
"where",
"=",
"[",
"]",
";",
"if",
"(",
"null",
"!==",
"$",
"this",
"->",
"context",
")",
"{",
"$",
"where",
"[",
"]",
"=",
"sprintf",
"(",
"\"page.[i18n:%s-navContexts] = '%s'\"",
",",
"$",
"locale",
",",
"$",
"this",
"->",
"context",
")",
";",
"}",
"if",
"(",
"null",
"!==",
"$",
"this",
"->",
"parent",
")",
"{",
"$",
"where",
"[",
"]",
"=",
"sprintf",
"(",
"\"ISDESCENDANTNODE(page, '%s')\"",
",",
"$",
"this",
"->",
"parent",
")",
";",
"}",
"else",
"{",
"$",
"where",
"[",
"]",
"=",
"sprintf",
"(",
"\"ISDESCENDANTNODE(page, '%s')\"",
",",
"'/cmf/'",
".",
"$",
"webspaceKey",
".",
"'/contents'",
")",
";",
"}",
"return",
"implode",
"(",
"' AND '",
",",
"$",
"where",
")",
";",
"}"
] | Returns custom select statement. | [
"Returns",
"custom",
"select",
"statement",
"."
] | 6766a36cc2f0c807c59202bf7540a08c4ef31192 | https://github.com/sulu/sulu/blob/6766a36cc2f0c807c59202bf7540a08c4ef31192/src/Sulu/Bundle/WebsiteBundle/Navigation/NavigationQueryBuilder.php#L36-L49 | train |
sulu/sulu | src/Sulu/Bundle/MediaBundle/Controller/MediaController.php | MediaController.getAction | public function getAction($id, Request $request)
{
try {
$locale = $this->getRequestParameter($request, 'locale', true);
$mediaManager = $this->getMediaManager();
$view = $this->responseGetById(
$id,
function($id) use ($locale, $mediaManager) {
$media = $mediaManager->getById($id, $locale);
$collection = $media->getEntity()->getCollection();
if (SystemCollectionManagerInterface::COLLECTION_TYPE === $collection->getType()->getKey()) {
$this->getSecurityChecker()->checkPermission(
'sulu.media.system_collections',
PermissionTypes::VIEW
);
}
$this->getSecurityChecker()->checkPermission(
new SecurityCondition(
$this->getSecurityContext(),
$locale,
$this->getSecuredClass(),
$collection->getId()
),
PermissionTypes::VIEW
);
return $media;
}
);
} 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 getAction($id, Request $request)
{
try {
$locale = $this->getRequestParameter($request, 'locale', true);
$mediaManager = $this->getMediaManager();
$view = $this->responseGetById(
$id,
function($id) use ($locale, $mediaManager) {
$media = $mediaManager->getById($id, $locale);
$collection = $media->getEntity()->getCollection();
if (SystemCollectionManagerInterface::COLLECTION_TYPE === $collection->getType()->getKey()) {
$this->getSecurityChecker()->checkPermission(
'sulu.media.system_collections',
PermissionTypes::VIEW
);
}
$this->getSecurityChecker()->checkPermission(
new SecurityCondition(
$this->getSecurityContext(),
$locale,
$this->getSecuredClass(),
$collection->getId()
),
PermissionTypes::VIEW
);
return $media;
}
);
} catch (MediaNotFoundException $e) {
$view = $this->view($e->toArray(), 404);
} catch (MediaException $e) {
$view = $this->view($e->toArray(), 400);
}
return $this->handleView($view);
} | [
"public",
"function",
"getAction",
"(",
"$",
"id",
",",
"Request",
"$",
"request",
")",
"{",
"try",
"{",
"$",
"locale",
"=",
"$",
"this",
"->",
"getRequestParameter",
"(",
"$",
"request",
",",
"'locale'",
",",
"true",
")",
";",
"$",
"mediaManager",
"=",
"$",
"this",
"->",
"getMediaManager",
"(",
")",
";",
"$",
"view",
"=",
"$",
"this",
"->",
"responseGetById",
"(",
"$",
"id",
",",
"function",
"(",
"$",
"id",
")",
"use",
"(",
"$",
"locale",
",",
"$",
"mediaManager",
")",
"{",
"$",
"media",
"=",
"$",
"mediaManager",
"->",
"getById",
"(",
"$",
"id",
",",
"$",
"locale",
")",
";",
"$",
"collection",
"=",
"$",
"media",
"->",
"getEntity",
"(",
")",
"->",
"getCollection",
"(",
")",
";",
"if",
"(",
"SystemCollectionManagerInterface",
"::",
"COLLECTION_TYPE",
"===",
"$",
"collection",
"->",
"getType",
"(",
")",
"->",
"getKey",
"(",
")",
")",
"{",
"$",
"this",
"->",
"getSecurityChecker",
"(",
")",
"->",
"checkPermission",
"(",
"'sulu.media.system_collections'",
",",
"PermissionTypes",
"::",
"VIEW",
")",
";",
"}",
"$",
"this",
"->",
"getSecurityChecker",
"(",
")",
"->",
"checkPermission",
"(",
"new",
"SecurityCondition",
"(",
"$",
"this",
"->",
"getSecurityContext",
"(",
")",
",",
"$",
"locale",
",",
"$",
"this",
"->",
"getSecuredClass",
"(",
")",
",",
"$",
"collection",
"->",
"getId",
"(",
")",
")",
",",
"PermissionTypes",
"::",
"VIEW",
")",
";",
"return",
"$",
"media",
";",
"}",
")",
";",
"}",
"catch",
"(",
"MediaNotFoundException",
"$",
"e",
")",
"{",
"$",
"view",
"=",
"$",
"this",
"->",
"view",
"(",
"$",
"e",
"->",
"toArray",
"(",
")",
",",
"404",
")",
";",
"}",
"catch",
"(",
"MediaException",
"$",
"e",
")",
"{",
"$",
"view",
"=",
"$",
"this",
"->",
"view",
"(",
"$",
"e",
"->",
"toArray",
"(",
")",
",",
"400",
")",
";",
"}",
"return",
"$",
"this",
"->",
"handleView",
"(",
"$",
"view",
")",
";",
"}"
] | Shows a single media with the given id.
@param $id
@param Request $request
@return Response | [
"Shows",
"a",
"single",
"media",
"with",
"the",
"given",
"id",
"."
] | 6766a36cc2f0c807c59202bf7540a08c4ef31192 | https://github.com/sulu/sulu/blob/6766a36cc2f0c807c59202bf7540a08c4ef31192/src/Sulu/Bundle/MediaBundle/Controller/MediaController.php#L64-L102 | train |
sulu/sulu | src/Sulu/Bundle/MediaBundle/Controller/MediaController.php | MediaController.cgetAction | public function cgetAction(Request $request)
{
$locale = $this->getRequestParameter($request, 'locale', true);
$fieldDescriptors = $this->getFieldDescriptors($locale, false);
$types = array_filter(explode(',', $request->get('types')));
$listBuilder = $this->getListBuilder($request, $fieldDescriptors, $types);
$listBuilder->setParameter('locale', $locale);
$listResponse = $listBuilder->execute();
$count = $listBuilder->count();
for ($i = 0, $length = count($listResponse); $i < $length; ++$i) {
$format = $this->getFormatManager()->getFormats(
$listResponse[$i]['id'],
$listResponse[$i]['name'],
$listResponse[$i]['storageOptions'],
$listResponse[$i]['version'],
$listResponse[$i]['subVersion'],
$listResponse[$i]['mimeType']
);
if (0 < count($format)) {
$listResponse[$i]['thumbnails'] = $format;
}
$listResponse[$i]['url'] = $this->getMediaManager()->getUrl(
$listResponse[$i]['id'],
$listResponse[$i]['name'],
$listResponse[$i]['version']
);
}
$ids = $listBuilder->getIds();
if (null != $ids) {
$result = [];
foreach ($listResponse as $item) {
$result[array_search($item['id'], $ids)] = $item;
}
ksort($result);
$listResponse = array_values($result);
}
$list = new ListRepresentation(
$listResponse,
self::$entityKey,
'cget_media',
$request->query->all(),
$listBuilder->getCurrentPage(),
$listBuilder->getLimit(),
$count
);
$view = $this->view($list, 200);
return $this->handleView($view);
} | php | public function cgetAction(Request $request)
{
$locale = $this->getRequestParameter($request, 'locale', true);
$fieldDescriptors = $this->getFieldDescriptors($locale, false);
$types = array_filter(explode(',', $request->get('types')));
$listBuilder = $this->getListBuilder($request, $fieldDescriptors, $types);
$listBuilder->setParameter('locale', $locale);
$listResponse = $listBuilder->execute();
$count = $listBuilder->count();
for ($i = 0, $length = count($listResponse); $i < $length; ++$i) {
$format = $this->getFormatManager()->getFormats(
$listResponse[$i]['id'],
$listResponse[$i]['name'],
$listResponse[$i]['storageOptions'],
$listResponse[$i]['version'],
$listResponse[$i]['subVersion'],
$listResponse[$i]['mimeType']
);
if (0 < count($format)) {
$listResponse[$i]['thumbnails'] = $format;
}
$listResponse[$i]['url'] = $this->getMediaManager()->getUrl(
$listResponse[$i]['id'],
$listResponse[$i]['name'],
$listResponse[$i]['version']
);
}
$ids = $listBuilder->getIds();
if (null != $ids) {
$result = [];
foreach ($listResponse as $item) {
$result[array_search($item['id'], $ids)] = $item;
}
ksort($result);
$listResponse = array_values($result);
}
$list = new ListRepresentation(
$listResponse,
self::$entityKey,
'cget_media',
$request->query->all(),
$listBuilder->getCurrentPage(),
$listBuilder->getLimit(),
$count
);
$view = $this->view($list, 200);
return $this->handleView($view);
} | [
"public",
"function",
"cgetAction",
"(",
"Request",
"$",
"request",
")",
"{",
"$",
"locale",
"=",
"$",
"this",
"->",
"getRequestParameter",
"(",
"$",
"request",
",",
"'locale'",
",",
"true",
")",
";",
"$",
"fieldDescriptors",
"=",
"$",
"this",
"->",
"getFieldDescriptors",
"(",
"$",
"locale",
",",
"false",
")",
";",
"$",
"types",
"=",
"array_filter",
"(",
"explode",
"(",
"','",
",",
"$",
"request",
"->",
"get",
"(",
"'types'",
")",
")",
")",
";",
"$",
"listBuilder",
"=",
"$",
"this",
"->",
"getListBuilder",
"(",
"$",
"request",
",",
"$",
"fieldDescriptors",
",",
"$",
"types",
")",
";",
"$",
"listBuilder",
"->",
"setParameter",
"(",
"'locale'",
",",
"$",
"locale",
")",
";",
"$",
"listResponse",
"=",
"$",
"listBuilder",
"->",
"execute",
"(",
")",
";",
"$",
"count",
"=",
"$",
"listBuilder",
"->",
"count",
"(",
")",
";",
"for",
"(",
"$",
"i",
"=",
"0",
",",
"$",
"length",
"=",
"count",
"(",
"$",
"listResponse",
")",
";",
"$",
"i",
"<",
"$",
"length",
";",
"++",
"$",
"i",
")",
"{",
"$",
"format",
"=",
"$",
"this",
"->",
"getFormatManager",
"(",
")",
"->",
"getFormats",
"(",
"$",
"listResponse",
"[",
"$",
"i",
"]",
"[",
"'id'",
"]",
",",
"$",
"listResponse",
"[",
"$",
"i",
"]",
"[",
"'name'",
"]",
",",
"$",
"listResponse",
"[",
"$",
"i",
"]",
"[",
"'storageOptions'",
"]",
",",
"$",
"listResponse",
"[",
"$",
"i",
"]",
"[",
"'version'",
"]",
",",
"$",
"listResponse",
"[",
"$",
"i",
"]",
"[",
"'subVersion'",
"]",
",",
"$",
"listResponse",
"[",
"$",
"i",
"]",
"[",
"'mimeType'",
"]",
")",
";",
"if",
"(",
"0",
"<",
"count",
"(",
"$",
"format",
")",
")",
"{",
"$",
"listResponse",
"[",
"$",
"i",
"]",
"[",
"'thumbnails'",
"]",
"=",
"$",
"format",
";",
"}",
"$",
"listResponse",
"[",
"$",
"i",
"]",
"[",
"'url'",
"]",
"=",
"$",
"this",
"->",
"getMediaManager",
"(",
")",
"->",
"getUrl",
"(",
"$",
"listResponse",
"[",
"$",
"i",
"]",
"[",
"'id'",
"]",
",",
"$",
"listResponse",
"[",
"$",
"i",
"]",
"[",
"'name'",
"]",
",",
"$",
"listResponse",
"[",
"$",
"i",
"]",
"[",
"'version'",
"]",
")",
";",
"}",
"$",
"ids",
"=",
"$",
"listBuilder",
"->",
"getIds",
"(",
")",
";",
"if",
"(",
"null",
"!=",
"$",
"ids",
")",
"{",
"$",
"result",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"listResponse",
"as",
"$",
"item",
")",
"{",
"$",
"result",
"[",
"array_search",
"(",
"$",
"item",
"[",
"'id'",
"]",
",",
"$",
"ids",
")",
"]",
"=",
"$",
"item",
";",
"}",
"ksort",
"(",
"$",
"result",
")",
";",
"$",
"listResponse",
"=",
"array_values",
"(",
"$",
"result",
")",
";",
"}",
"$",
"list",
"=",
"new",
"ListRepresentation",
"(",
"$",
"listResponse",
",",
"self",
"::",
"$",
"entityKey",
",",
"'cget_media'",
",",
"$",
"request",
"->",
"query",
"->",
"all",
"(",
")",
",",
"$",
"listBuilder",
"->",
"getCurrentPage",
"(",
")",
",",
"$",
"listBuilder",
"->",
"getLimit",
"(",
")",
",",
"$",
"count",
")",
";",
"$",
"view",
"=",
"$",
"this",
"->",
"view",
"(",
"$",
"list",
",",
"200",
")",
";",
"return",
"$",
"this",
"->",
"handleView",
"(",
"$",
"view",
")",
";",
"}"
] | Lists all media.
@param Request $request
@return Response | [
"Lists",
"all",
"media",
"."
] | 6766a36cc2f0c807c59202bf7540a08c4ef31192 | https://github.com/sulu/sulu/blob/6766a36cc2f0c807c59202bf7540a08c4ef31192/src/Sulu/Bundle/MediaBundle/Controller/MediaController.php#L111-L165 | train |
sulu/sulu | src/Sulu/Bundle/MediaBundle/Controller/MediaController.php | MediaController.getListBuilder | private function getListBuilder(Request $request, array $fieldDescriptors, $types)
{
$restHelper = $this->get('sulu_core.doctrine_rest_helper');
$factory = $this->get('sulu_core.doctrine_list_builder_factory');
$listBuilder = $factory->create($this->getParameter('sulu.model.media.class'));
$restHelper->initializeListBuilder($listBuilder, $fieldDescriptors);
// default sort by created
if (!$request->get('sortBy')) {
$listBuilder->sort($fieldDescriptors['created'], 'desc');
}
$collectionId = $request->get('collection');
if ($collectionId) {
$collectionType = $this->getCollectionRepository()->findCollectionTypeById($collectionId);
if (SystemCollectionManagerInterface::COLLECTION_TYPE === $collectionType) {
$this->getSecurityChecker()->checkPermission(
'sulu.media.system_collections',
PermissionTypes::VIEW
);
}
$listBuilder->addSelectField($fieldDescriptors['collection']);
$listBuilder->where($fieldDescriptors['collection'], $collectionId);
} else {
$listBuilder->addPermissionCheckField($fieldDescriptors['collection']);
$listBuilder->setPermissionCheck(
$this->getUser(),
PermissionTypes::VIEW,
$this->getParameter('sulu.model.collection.class')
);
}
// set the types
if (count($types)) {
$listBuilder->in($fieldDescriptors['type'], $types);
}
if (!$this->getSecurityChecker()->hasPermission('sulu.media.system_collections', PermissionTypes::VIEW)) {
$systemCollection = $this->getCollectionRepository()
->findCollectionByKey(SystemCollectionManagerInterface::COLLECTION_KEY);
$lftExpression = $listBuilder->createWhereExpression(
$fieldDescriptors['lft'],
$systemCollection->getLft(),
ListBuilderInterface::WHERE_COMPARATOR_LESS
);
$rgtExpression = $listBuilder->createWhereExpression(
$fieldDescriptors['rgt'],
$systemCollection->getRgt(),
ListBuilderInterface::WHERE_COMPARATOR_GREATER
);
$listBuilder->addExpression(
$listBuilder->createOrExpression([
$lftExpression,
$rgtExpression,
])
);
}
// field which will be needed afterwards to generate route
$listBuilder->addSelectField($fieldDescriptors['version']);
$listBuilder->addSelectField($fieldDescriptors['subVersion']);
$listBuilder->addSelectField($fieldDescriptors['name']);
$listBuilder->addSelectField($fieldDescriptors['locale']);
$listBuilder->addSelectField($fieldDescriptors['mimeType']);
$listBuilder->addSelectField($fieldDescriptors['storageOptions']);
$listBuilder->addSelectField($fieldDescriptors['id']);
$listBuilder->addSelectField($fieldDescriptors['collection']);
return $listBuilder;
} | php | private function getListBuilder(Request $request, array $fieldDescriptors, $types)
{
$restHelper = $this->get('sulu_core.doctrine_rest_helper');
$factory = $this->get('sulu_core.doctrine_list_builder_factory');
$listBuilder = $factory->create($this->getParameter('sulu.model.media.class'));
$restHelper->initializeListBuilder($listBuilder, $fieldDescriptors);
// default sort by created
if (!$request->get('sortBy')) {
$listBuilder->sort($fieldDescriptors['created'], 'desc');
}
$collectionId = $request->get('collection');
if ($collectionId) {
$collectionType = $this->getCollectionRepository()->findCollectionTypeById($collectionId);
if (SystemCollectionManagerInterface::COLLECTION_TYPE === $collectionType) {
$this->getSecurityChecker()->checkPermission(
'sulu.media.system_collections',
PermissionTypes::VIEW
);
}
$listBuilder->addSelectField($fieldDescriptors['collection']);
$listBuilder->where($fieldDescriptors['collection'], $collectionId);
} else {
$listBuilder->addPermissionCheckField($fieldDescriptors['collection']);
$listBuilder->setPermissionCheck(
$this->getUser(),
PermissionTypes::VIEW,
$this->getParameter('sulu.model.collection.class')
);
}
// set the types
if (count($types)) {
$listBuilder->in($fieldDescriptors['type'], $types);
}
if (!$this->getSecurityChecker()->hasPermission('sulu.media.system_collections', PermissionTypes::VIEW)) {
$systemCollection = $this->getCollectionRepository()
->findCollectionByKey(SystemCollectionManagerInterface::COLLECTION_KEY);
$lftExpression = $listBuilder->createWhereExpression(
$fieldDescriptors['lft'],
$systemCollection->getLft(),
ListBuilderInterface::WHERE_COMPARATOR_LESS
);
$rgtExpression = $listBuilder->createWhereExpression(
$fieldDescriptors['rgt'],
$systemCollection->getRgt(),
ListBuilderInterface::WHERE_COMPARATOR_GREATER
);
$listBuilder->addExpression(
$listBuilder->createOrExpression([
$lftExpression,
$rgtExpression,
])
);
}
// field which will be needed afterwards to generate route
$listBuilder->addSelectField($fieldDescriptors['version']);
$listBuilder->addSelectField($fieldDescriptors['subVersion']);
$listBuilder->addSelectField($fieldDescriptors['name']);
$listBuilder->addSelectField($fieldDescriptors['locale']);
$listBuilder->addSelectField($fieldDescriptors['mimeType']);
$listBuilder->addSelectField($fieldDescriptors['storageOptions']);
$listBuilder->addSelectField($fieldDescriptors['id']);
$listBuilder->addSelectField($fieldDescriptors['collection']);
return $listBuilder;
} | [
"private",
"function",
"getListBuilder",
"(",
"Request",
"$",
"request",
",",
"array",
"$",
"fieldDescriptors",
",",
"$",
"types",
")",
"{",
"$",
"restHelper",
"=",
"$",
"this",
"->",
"get",
"(",
"'sulu_core.doctrine_rest_helper'",
")",
";",
"$",
"factory",
"=",
"$",
"this",
"->",
"get",
"(",
"'sulu_core.doctrine_list_builder_factory'",
")",
";",
"$",
"listBuilder",
"=",
"$",
"factory",
"->",
"create",
"(",
"$",
"this",
"->",
"getParameter",
"(",
"'sulu.model.media.class'",
")",
")",
";",
"$",
"restHelper",
"->",
"initializeListBuilder",
"(",
"$",
"listBuilder",
",",
"$",
"fieldDescriptors",
")",
";",
"// default sort by created",
"if",
"(",
"!",
"$",
"request",
"->",
"get",
"(",
"'sortBy'",
")",
")",
"{",
"$",
"listBuilder",
"->",
"sort",
"(",
"$",
"fieldDescriptors",
"[",
"'created'",
"]",
",",
"'desc'",
")",
";",
"}",
"$",
"collectionId",
"=",
"$",
"request",
"->",
"get",
"(",
"'collection'",
")",
";",
"if",
"(",
"$",
"collectionId",
")",
"{",
"$",
"collectionType",
"=",
"$",
"this",
"->",
"getCollectionRepository",
"(",
")",
"->",
"findCollectionTypeById",
"(",
"$",
"collectionId",
")",
";",
"if",
"(",
"SystemCollectionManagerInterface",
"::",
"COLLECTION_TYPE",
"===",
"$",
"collectionType",
")",
"{",
"$",
"this",
"->",
"getSecurityChecker",
"(",
")",
"->",
"checkPermission",
"(",
"'sulu.media.system_collections'",
",",
"PermissionTypes",
"::",
"VIEW",
")",
";",
"}",
"$",
"listBuilder",
"->",
"addSelectField",
"(",
"$",
"fieldDescriptors",
"[",
"'collection'",
"]",
")",
";",
"$",
"listBuilder",
"->",
"where",
"(",
"$",
"fieldDescriptors",
"[",
"'collection'",
"]",
",",
"$",
"collectionId",
")",
";",
"}",
"else",
"{",
"$",
"listBuilder",
"->",
"addPermissionCheckField",
"(",
"$",
"fieldDescriptors",
"[",
"'collection'",
"]",
")",
";",
"$",
"listBuilder",
"->",
"setPermissionCheck",
"(",
"$",
"this",
"->",
"getUser",
"(",
")",
",",
"PermissionTypes",
"::",
"VIEW",
",",
"$",
"this",
"->",
"getParameter",
"(",
"'sulu.model.collection.class'",
")",
")",
";",
"}",
"// set the types",
"if",
"(",
"count",
"(",
"$",
"types",
")",
")",
"{",
"$",
"listBuilder",
"->",
"in",
"(",
"$",
"fieldDescriptors",
"[",
"'type'",
"]",
",",
"$",
"types",
")",
";",
"}",
"if",
"(",
"!",
"$",
"this",
"->",
"getSecurityChecker",
"(",
")",
"->",
"hasPermission",
"(",
"'sulu.media.system_collections'",
",",
"PermissionTypes",
"::",
"VIEW",
")",
")",
"{",
"$",
"systemCollection",
"=",
"$",
"this",
"->",
"getCollectionRepository",
"(",
")",
"->",
"findCollectionByKey",
"(",
"SystemCollectionManagerInterface",
"::",
"COLLECTION_KEY",
")",
";",
"$",
"lftExpression",
"=",
"$",
"listBuilder",
"->",
"createWhereExpression",
"(",
"$",
"fieldDescriptors",
"[",
"'lft'",
"]",
",",
"$",
"systemCollection",
"->",
"getLft",
"(",
")",
",",
"ListBuilderInterface",
"::",
"WHERE_COMPARATOR_LESS",
")",
";",
"$",
"rgtExpression",
"=",
"$",
"listBuilder",
"->",
"createWhereExpression",
"(",
"$",
"fieldDescriptors",
"[",
"'rgt'",
"]",
",",
"$",
"systemCollection",
"->",
"getRgt",
"(",
")",
",",
"ListBuilderInterface",
"::",
"WHERE_COMPARATOR_GREATER",
")",
";",
"$",
"listBuilder",
"->",
"addExpression",
"(",
"$",
"listBuilder",
"->",
"createOrExpression",
"(",
"[",
"$",
"lftExpression",
",",
"$",
"rgtExpression",
",",
"]",
")",
")",
";",
"}",
"// field which will be needed afterwards to generate route",
"$",
"listBuilder",
"->",
"addSelectField",
"(",
"$",
"fieldDescriptors",
"[",
"'version'",
"]",
")",
";",
"$",
"listBuilder",
"->",
"addSelectField",
"(",
"$",
"fieldDescriptors",
"[",
"'subVersion'",
"]",
")",
";",
"$",
"listBuilder",
"->",
"addSelectField",
"(",
"$",
"fieldDescriptors",
"[",
"'name'",
"]",
")",
";",
"$",
"listBuilder",
"->",
"addSelectField",
"(",
"$",
"fieldDescriptors",
"[",
"'locale'",
"]",
")",
";",
"$",
"listBuilder",
"->",
"addSelectField",
"(",
"$",
"fieldDescriptors",
"[",
"'mimeType'",
"]",
")",
";",
"$",
"listBuilder",
"->",
"addSelectField",
"(",
"$",
"fieldDescriptors",
"[",
"'storageOptions'",
"]",
")",
";",
"$",
"listBuilder",
"->",
"addSelectField",
"(",
"$",
"fieldDescriptors",
"[",
"'id'",
"]",
")",
";",
"$",
"listBuilder",
"->",
"addSelectField",
"(",
"$",
"fieldDescriptors",
"[",
"'collection'",
"]",
")",
";",
"return",
"$",
"listBuilder",
";",
"}"
] | Returns a list-builder for media list.
@param Request $request
@param FieldDescriptorInterface[] $fieldDescriptors
@param array $types
@return DoctrineListBuilder | [
"Returns",
"a",
"list",
"-",
"builder",
"for",
"media",
"list",
"."
] | 6766a36cc2f0c807c59202bf7540a08c4ef31192 | https://github.com/sulu/sulu/blob/6766a36cc2f0c807c59202bf7540a08c4ef31192/src/Sulu/Bundle/MediaBundle/Controller/MediaController.php#L176-L247 | train |
sulu/sulu | src/Sulu/Bundle/MediaBundle/Controller/MediaController.php | MediaController.deleteAction | public function deleteAction($id)
{
$delete = function($id) {
try {
$this->getMediaManager()->delete($id, true);
} catch (MediaNotFoundException $e) {
$entityName = $this->getParameter('sulu.model.media.class');
throw new EntityNotFoundException($entityName, $id); // will throw 404 Entity not found
} catch (MediaException $e) {
throw new RestException($e->getMessage(), $e->getCode()); // will throw 400 Bad Request
}
};
$view = $this->responseDelete($id, $delete);
return $this->handleView($view);
} | php | public function deleteAction($id)
{
$delete = function($id) {
try {
$this->getMediaManager()->delete($id, true);
} catch (MediaNotFoundException $e) {
$entityName = $this->getParameter('sulu.model.media.class');
throw new EntityNotFoundException($entityName, $id); // will throw 404 Entity not found
} catch (MediaException $e) {
throw new RestException($e->getMessage(), $e->getCode()); // will throw 400 Bad Request
}
};
$view = $this->responseDelete($id, $delete);
return $this->handleView($view);
} | [
"public",
"function",
"deleteAction",
"(",
"$",
"id",
")",
"{",
"$",
"delete",
"=",
"function",
"(",
"$",
"id",
")",
"{",
"try",
"{",
"$",
"this",
"->",
"getMediaManager",
"(",
")",
"->",
"delete",
"(",
"$",
"id",
",",
"true",
")",
";",
"}",
"catch",
"(",
"MediaNotFoundException",
"$",
"e",
")",
"{",
"$",
"entityName",
"=",
"$",
"this",
"->",
"getParameter",
"(",
"'sulu.model.media.class'",
")",
";",
"throw",
"new",
"EntityNotFoundException",
"(",
"$",
"entityName",
",",
"$",
"id",
")",
";",
"// will throw 404 Entity not found",
"}",
"catch",
"(",
"MediaException",
"$",
"e",
")",
"{",
"throw",
"new",
"RestException",
"(",
"$",
"e",
"->",
"getMessage",
"(",
")",
",",
"$",
"e",
"->",
"getCode",
"(",
")",
")",
";",
"// will throw 400 Bad Request",
"}",
"}",
";",
"$",
"view",
"=",
"$",
"this",
"->",
"responseDelete",
"(",
"$",
"id",
",",
"$",
"delete",
")",
";",
"return",
"$",
"this",
"->",
"handleView",
"(",
"$",
"view",
")",
";",
"}"
] | Delete a media with the given id.
@param $id
@return \Symfony\Component\HttpFoundation\Response | [
"Delete",
"a",
"media",
"with",
"the",
"given",
"id",
"."
] | 6766a36cc2f0c807c59202bf7540a08c4ef31192 | https://github.com/sulu/sulu/blob/6766a36cc2f0c807c59202bf7540a08c4ef31192/src/Sulu/Bundle/MediaBundle/Controller/MediaController.php#L285-L302 | train |
sulu/sulu | src/Sulu/Bundle/MediaBundle/Controller/MediaController.php | MediaController.moveEntity | protected function moveEntity($id, Request $request)
{
try {
$locale = $this->getRequestParameter($request, 'locale', true);
$destination = $this->getRequestParameter($request, 'destination', true);
$mediaManager = $this->getMediaManager();
$media = $mediaManager->move(
$id,
$locale,
$destination
);
$view = $this->view($media, 200);
} catch (MediaNotFoundException $e) {
$view = $this->view($e->toArray(), 404);
} catch (MediaException $e) {
$view = $this->view($e->toArray(), 400);
}
return $this->handleView($view);
} | php | protected function moveEntity($id, Request $request)
{
try {
$locale = $this->getRequestParameter($request, 'locale', true);
$destination = $this->getRequestParameter($request, 'destination', true);
$mediaManager = $this->getMediaManager();
$media = $mediaManager->move(
$id,
$locale,
$destination
);
$view = $this->view($media, 200);
} catch (MediaNotFoundException $e) {
$view = $this->view($e->toArray(), 404);
} catch (MediaException $e) {
$view = $this->view($e->toArray(), 400);
}
return $this->handleView($view);
} | [
"protected",
"function",
"moveEntity",
"(",
"$",
"id",
",",
"Request",
"$",
"request",
")",
"{",
"try",
"{",
"$",
"locale",
"=",
"$",
"this",
"->",
"getRequestParameter",
"(",
"$",
"request",
",",
"'locale'",
",",
"true",
")",
";",
"$",
"destination",
"=",
"$",
"this",
"->",
"getRequestParameter",
"(",
"$",
"request",
",",
"'destination'",
",",
"true",
")",
";",
"$",
"mediaManager",
"=",
"$",
"this",
"->",
"getMediaManager",
"(",
")",
";",
"$",
"media",
"=",
"$",
"mediaManager",
"->",
"move",
"(",
"$",
"id",
",",
"$",
"locale",
",",
"$",
"destination",
")",
";",
"$",
"view",
"=",
"$",
"this",
"->",
"view",
"(",
"$",
"media",
",",
"200",
")",
";",
"}",
"catch",
"(",
"MediaNotFoundException",
"$",
"e",
")",
"{",
"$",
"view",
"=",
"$",
"this",
"->",
"view",
"(",
"$",
"e",
"->",
"toArray",
"(",
")",
",",
"404",
")",
";",
"}",
"catch",
"(",
"MediaException",
"$",
"e",
")",
"{",
"$",
"view",
"=",
"$",
"this",
"->",
"view",
"(",
"$",
"e",
"->",
"toArray",
"(",
")",
",",
"400",
")",
";",
"}",
"return",
"$",
"this",
"->",
"handleView",
"(",
"$",
"view",
")",
";",
"}"
] | Move an entity to another collection.
@param int $id
@param Request $request
@return Response | [
"Move",
"an",
"entity",
"to",
"another",
"collection",
"."
] | 6766a36cc2f0c807c59202bf7540a08c4ef31192 | https://github.com/sulu/sulu/blob/6766a36cc2f0c807c59202bf7540a08c4ef31192/src/Sulu/Bundle/MediaBundle/Controller/MediaController.php#L388-L409 | train |
sulu/sulu | src/Sulu/Bundle/ContactBundle/Controller/AccountController.php | AccountController.getContactsAction | public function getContactsAction($id, Request $request)
{
if ('true' == $request->get('flat')) {
/* @var AccountInterface $account */
$account = $this->getRepository()->findById($id);
/** @var RestHelperInterface $restHelper */
$restHelper = $this->getRestHelper();
/** @var DoctrineListBuilderFactory $factory */
$factory = $this->get('sulu_core.doctrine_list_builder_factory');
$listBuilder = $factory->create(self::$accountContactEntityName);
$fieldDescriptors = $this->getAccountContactFieldDescriptors();
$restHelper->initializeListBuilder($listBuilder, $fieldDescriptors);
$listBuilder->addSelectField($fieldDescriptors['contactId']);
$listBuilder->setIdField($fieldDescriptors['id']);
$listBuilder->where($fieldDescriptors['account'], $id);
$listBuilder->sort($fieldDescriptors['lastName'], $listBuilder::SORTORDER_ASC);
$values = $listBuilder->execute();
foreach ($values as &$value) {
// Substitute id since we are interested in the contact id not the accountContact id.
$value['id'] = $value['contactId'];
unset($value['contactId']);
if (null != $account->getMainContact() && $value['id'] === $account->getMainContact()->getId()) {
$value['isMainContact'] = true;
} else {
$value['isMainContact'] = false;
}
}
$list = new ListRepresentation(
$values,
'contacts',
'get_account_contacts',
array_merge(['id' => $id], $request->query->all()),
$listBuilder->getCurrentPage(),
$listBuilder->getLimit(),
$listBuilder->count()
);
} else {
$contactManager = $this->getAccountManager();
$locale = $this->getUser()->getLocale();
$contacts = $contactManager->findContactsByAccountId($id, $locale, false);
$list = new CollectionRepresentation($contacts, self::$contactEntityKey);
}
$view = $this->view($list, 200);
return $this->handleView($view);
} | php | public function getContactsAction($id, Request $request)
{
if ('true' == $request->get('flat')) {
/* @var AccountInterface $account */
$account = $this->getRepository()->findById($id);
/** @var RestHelperInterface $restHelper */
$restHelper = $this->getRestHelper();
/** @var DoctrineListBuilderFactory $factory */
$factory = $this->get('sulu_core.doctrine_list_builder_factory');
$listBuilder = $factory->create(self::$accountContactEntityName);
$fieldDescriptors = $this->getAccountContactFieldDescriptors();
$restHelper->initializeListBuilder($listBuilder, $fieldDescriptors);
$listBuilder->addSelectField($fieldDescriptors['contactId']);
$listBuilder->setIdField($fieldDescriptors['id']);
$listBuilder->where($fieldDescriptors['account'], $id);
$listBuilder->sort($fieldDescriptors['lastName'], $listBuilder::SORTORDER_ASC);
$values = $listBuilder->execute();
foreach ($values as &$value) {
// Substitute id since we are interested in the contact id not the accountContact id.
$value['id'] = $value['contactId'];
unset($value['contactId']);
if (null != $account->getMainContact() && $value['id'] === $account->getMainContact()->getId()) {
$value['isMainContact'] = true;
} else {
$value['isMainContact'] = false;
}
}
$list = new ListRepresentation(
$values,
'contacts',
'get_account_contacts',
array_merge(['id' => $id], $request->query->all()),
$listBuilder->getCurrentPage(),
$listBuilder->getLimit(),
$listBuilder->count()
);
} else {
$contactManager = $this->getAccountManager();
$locale = $this->getUser()->getLocale();
$contacts = $contactManager->findContactsByAccountId($id, $locale, false);
$list = new CollectionRepresentation($contacts, self::$contactEntityKey);
}
$view = $this->view($list, 200);
return $this->handleView($view);
} | [
"public",
"function",
"getContactsAction",
"(",
"$",
"id",
",",
"Request",
"$",
"request",
")",
"{",
"if",
"(",
"'true'",
"==",
"$",
"request",
"->",
"get",
"(",
"'flat'",
")",
")",
"{",
"/* @var AccountInterface $account */",
"$",
"account",
"=",
"$",
"this",
"->",
"getRepository",
"(",
")",
"->",
"findById",
"(",
"$",
"id",
")",
";",
"/** @var RestHelperInterface $restHelper */",
"$",
"restHelper",
"=",
"$",
"this",
"->",
"getRestHelper",
"(",
")",
";",
"/** @var DoctrineListBuilderFactory $factory */",
"$",
"factory",
"=",
"$",
"this",
"->",
"get",
"(",
"'sulu_core.doctrine_list_builder_factory'",
")",
";",
"$",
"listBuilder",
"=",
"$",
"factory",
"->",
"create",
"(",
"self",
"::",
"$",
"accountContactEntityName",
")",
";",
"$",
"fieldDescriptors",
"=",
"$",
"this",
"->",
"getAccountContactFieldDescriptors",
"(",
")",
";",
"$",
"restHelper",
"->",
"initializeListBuilder",
"(",
"$",
"listBuilder",
",",
"$",
"fieldDescriptors",
")",
";",
"$",
"listBuilder",
"->",
"addSelectField",
"(",
"$",
"fieldDescriptors",
"[",
"'contactId'",
"]",
")",
";",
"$",
"listBuilder",
"->",
"setIdField",
"(",
"$",
"fieldDescriptors",
"[",
"'id'",
"]",
")",
";",
"$",
"listBuilder",
"->",
"where",
"(",
"$",
"fieldDescriptors",
"[",
"'account'",
"]",
",",
"$",
"id",
")",
";",
"$",
"listBuilder",
"->",
"sort",
"(",
"$",
"fieldDescriptors",
"[",
"'lastName'",
"]",
",",
"$",
"listBuilder",
"::",
"SORTORDER_ASC",
")",
";",
"$",
"values",
"=",
"$",
"listBuilder",
"->",
"execute",
"(",
")",
";",
"foreach",
"(",
"$",
"values",
"as",
"&",
"$",
"value",
")",
"{",
"// Substitute id since we are interested in the contact id not the accountContact id.",
"$",
"value",
"[",
"'id'",
"]",
"=",
"$",
"value",
"[",
"'contactId'",
"]",
";",
"unset",
"(",
"$",
"value",
"[",
"'contactId'",
"]",
")",
";",
"if",
"(",
"null",
"!=",
"$",
"account",
"->",
"getMainContact",
"(",
")",
"&&",
"$",
"value",
"[",
"'id'",
"]",
"===",
"$",
"account",
"->",
"getMainContact",
"(",
")",
"->",
"getId",
"(",
")",
")",
"{",
"$",
"value",
"[",
"'isMainContact'",
"]",
"=",
"true",
";",
"}",
"else",
"{",
"$",
"value",
"[",
"'isMainContact'",
"]",
"=",
"false",
";",
"}",
"}",
"$",
"list",
"=",
"new",
"ListRepresentation",
"(",
"$",
"values",
",",
"'contacts'",
",",
"'get_account_contacts'",
",",
"array_merge",
"(",
"[",
"'id'",
"=>",
"$",
"id",
"]",
",",
"$",
"request",
"->",
"query",
"->",
"all",
"(",
")",
")",
",",
"$",
"listBuilder",
"->",
"getCurrentPage",
"(",
")",
",",
"$",
"listBuilder",
"->",
"getLimit",
"(",
")",
",",
"$",
"listBuilder",
"->",
"count",
"(",
")",
")",
";",
"}",
"else",
"{",
"$",
"contactManager",
"=",
"$",
"this",
"->",
"getAccountManager",
"(",
")",
";",
"$",
"locale",
"=",
"$",
"this",
"->",
"getUser",
"(",
")",
"->",
"getLocale",
"(",
")",
";",
"$",
"contacts",
"=",
"$",
"contactManager",
"->",
"findContactsByAccountId",
"(",
"$",
"id",
",",
"$",
"locale",
",",
"false",
")",
";",
"$",
"list",
"=",
"new",
"CollectionRepresentation",
"(",
"$",
"contacts",
",",
"self",
"::",
"$",
"contactEntityKey",
")",
";",
"}",
"$",
"view",
"=",
"$",
"this",
"->",
"view",
"(",
"$",
"list",
",",
"200",
")",
";",
"return",
"$",
"this",
"->",
"handleView",
"(",
"$",
"view",
")",
";",
"}"
] | Lists all contacts of an account.
optional parameter 'flat' calls listAction.
@param int $id
@param Request $request
@return Response | [
"Lists",
"all",
"contacts",
"of",
"an",
"account",
".",
"optional",
"parameter",
"flat",
"calls",
"listAction",
"."
] | 6766a36cc2f0c807c59202bf7540a08c4ef31192 | https://github.com/sulu/sulu/blob/6766a36cc2f0c807c59202bf7540a08c4ef31192/src/Sulu/Bundle/ContactBundle/Controller/AccountController.php#L104-L158 | train |
sulu/sulu | src/Sulu/Bundle/ContactBundle/Controller/AccountController.php | AccountController.getAddressesAction | public function getAddressesAction($id, Request $request)
{
if ('true' == $request->get('flat')) {
/** @var RestHelperInterface $restHelper */
$restHelper = $this->getRestHelper();
/** @var DoctrineListBuilderFactory $factory */
$factory = $this->get('sulu_core.doctrine_list_builder_factory');
$listBuilder = $factory->create($this->getAccountEntityName());
$restHelper->initializeListBuilder($listBuilder, $this->getAccountAddressesFieldDescriptors());
$listBuilder->where($this->getFieldDescriptors()['id'], $id);
$values = $listBuilder->execute();
$list = new ListRepresentation(
$values,
'addresses',
'get_account_addresses',
array_merge(['id' => $id], $request->query->all()),
$listBuilder->getCurrentPage(),
$listBuilder->getLimit(),
$listBuilder->count()
);
} else {
$addresses = $this->getDoctrine()->getRepository(self::$addressEntityName)->findByAccountId($id);
$list = new CollectionRepresentation($addresses, 'addresses');
}
$view = $this->view($list, 200);
return $this->handleView($view);
} | php | public function getAddressesAction($id, Request $request)
{
if ('true' == $request->get('flat')) {
/** @var RestHelperInterface $restHelper */
$restHelper = $this->getRestHelper();
/** @var DoctrineListBuilderFactory $factory */
$factory = $this->get('sulu_core.doctrine_list_builder_factory');
$listBuilder = $factory->create($this->getAccountEntityName());
$restHelper->initializeListBuilder($listBuilder, $this->getAccountAddressesFieldDescriptors());
$listBuilder->where($this->getFieldDescriptors()['id'], $id);
$values = $listBuilder->execute();
$list = new ListRepresentation(
$values,
'addresses',
'get_account_addresses',
array_merge(['id' => $id], $request->query->all()),
$listBuilder->getCurrentPage(),
$listBuilder->getLimit(),
$listBuilder->count()
);
} else {
$addresses = $this->getDoctrine()->getRepository(self::$addressEntityName)->findByAccountId($id);
$list = new CollectionRepresentation($addresses, 'addresses');
}
$view = $this->view($list, 200);
return $this->handleView($view);
} | [
"public",
"function",
"getAddressesAction",
"(",
"$",
"id",
",",
"Request",
"$",
"request",
")",
"{",
"if",
"(",
"'true'",
"==",
"$",
"request",
"->",
"get",
"(",
"'flat'",
")",
")",
"{",
"/** @var RestHelperInterface $restHelper */",
"$",
"restHelper",
"=",
"$",
"this",
"->",
"getRestHelper",
"(",
")",
";",
"/** @var DoctrineListBuilderFactory $factory */",
"$",
"factory",
"=",
"$",
"this",
"->",
"get",
"(",
"'sulu_core.doctrine_list_builder_factory'",
")",
";",
"$",
"listBuilder",
"=",
"$",
"factory",
"->",
"create",
"(",
"$",
"this",
"->",
"getAccountEntityName",
"(",
")",
")",
";",
"$",
"restHelper",
"->",
"initializeListBuilder",
"(",
"$",
"listBuilder",
",",
"$",
"this",
"->",
"getAccountAddressesFieldDescriptors",
"(",
")",
")",
";",
"$",
"listBuilder",
"->",
"where",
"(",
"$",
"this",
"->",
"getFieldDescriptors",
"(",
")",
"[",
"'id'",
"]",
",",
"$",
"id",
")",
";",
"$",
"values",
"=",
"$",
"listBuilder",
"->",
"execute",
"(",
")",
";",
"$",
"list",
"=",
"new",
"ListRepresentation",
"(",
"$",
"values",
",",
"'addresses'",
",",
"'get_account_addresses'",
",",
"array_merge",
"(",
"[",
"'id'",
"=>",
"$",
"id",
"]",
",",
"$",
"request",
"->",
"query",
"->",
"all",
"(",
")",
")",
",",
"$",
"listBuilder",
"->",
"getCurrentPage",
"(",
")",
",",
"$",
"listBuilder",
"->",
"getLimit",
"(",
")",
",",
"$",
"listBuilder",
"->",
"count",
"(",
")",
")",
";",
"}",
"else",
"{",
"$",
"addresses",
"=",
"$",
"this",
"->",
"getDoctrine",
"(",
")",
"->",
"getRepository",
"(",
"self",
"::",
"$",
"addressEntityName",
")",
"->",
"findByAccountId",
"(",
"$",
"id",
")",
";",
"$",
"list",
"=",
"new",
"CollectionRepresentation",
"(",
"$",
"addresses",
",",
"'addresses'",
")",
";",
"}",
"$",
"view",
"=",
"$",
"this",
"->",
"view",
"(",
"$",
"list",
",",
"200",
")",
";",
"return",
"$",
"this",
"->",
"handleView",
"(",
"$",
"view",
")",
";",
"}"
] | Lists all addresses of an account
optional parameter 'flat' calls listAction.
@param int $id
@param Request $request
@return Response | [
"Lists",
"all",
"addresses",
"of",
"an",
"account",
"optional",
"parameter",
"flat",
"calls",
"listAction",
"."
] | 6766a36cc2f0c807c59202bf7540a08c4ef31192 | https://github.com/sulu/sulu/blob/6766a36cc2f0c807c59202bf7540a08c4ef31192/src/Sulu/Bundle/ContactBundle/Controller/AccountController.php#L169-L202 | train |
sulu/sulu | src/Sulu/Bundle/ContactBundle/Controller/AccountController.php | AccountController.deleteContactsAction | public function deleteContactsAction($accountId, $contactId)
{
try {
// Check if relation exists.
/** @var AccountContactEntity $accountContact */
$accountContact = $this->getDoctrine()
->getRepository(self::$accountContactEntityName)
->findByForeignIds($accountId, $contactId);
if (!$accountContact) {
throw new EntityNotFoundException('AccountContact', $accountId . $contactId);
}
$id = $accountContact->getId();
$account = $accountContact->getAccount();
// Remove main contact when relation with main was removed.
if ($account->getMainContact() && strval($account->getMainContact()->getId()) === $contactId) {
$account->setMainContact(null);
}
// Remove accountContact.
$em = $this->getDoctrine()->getManager();
$em->remove($accountContact);
$em->flush();
$view = $this->view($id, 200);
} catch (EntityNotFoundException $enfe) {
$view = $this->view($enfe->toArray(), 404);
}
return $this->handleView($view);
} | php | public function deleteContactsAction($accountId, $contactId)
{
try {
// Check if relation exists.
/** @var AccountContactEntity $accountContact */
$accountContact = $this->getDoctrine()
->getRepository(self::$accountContactEntityName)
->findByForeignIds($accountId, $contactId);
if (!$accountContact) {
throw new EntityNotFoundException('AccountContact', $accountId . $contactId);
}
$id = $accountContact->getId();
$account = $accountContact->getAccount();
// Remove main contact when relation with main was removed.
if ($account->getMainContact() && strval($account->getMainContact()->getId()) === $contactId) {
$account->setMainContact(null);
}
// Remove accountContact.
$em = $this->getDoctrine()->getManager();
$em->remove($accountContact);
$em->flush();
$view = $this->view($id, 200);
} catch (EntityNotFoundException $enfe) {
$view = $this->view($enfe->toArray(), 404);
}
return $this->handleView($view);
} | [
"public",
"function",
"deleteContactsAction",
"(",
"$",
"accountId",
",",
"$",
"contactId",
")",
"{",
"try",
"{",
"// Check if relation exists.",
"/** @var AccountContactEntity $accountContact */",
"$",
"accountContact",
"=",
"$",
"this",
"->",
"getDoctrine",
"(",
")",
"->",
"getRepository",
"(",
"self",
"::",
"$",
"accountContactEntityName",
")",
"->",
"findByForeignIds",
"(",
"$",
"accountId",
",",
"$",
"contactId",
")",
";",
"if",
"(",
"!",
"$",
"accountContact",
")",
"{",
"throw",
"new",
"EntityNotFoundException",
"(",
"'AccountContact'",
",",
"$",
"accountId",
".",
"$",
"contactId",
")",
";",
"}",
"$",
"id",
"=",
"$",
"accountContact",
"->",
"getId",
"(",
")",
";",
"$",
"account",
"=",
"$",
"accountContact",
"->",
"getAccount",
"(",
")",
";",
"// Remove main contact when relation with main was removed.",
"if",
"(",
"$",
"account",
"->",
"getMainContact",
"(",
")",
"&&",
"strval",
"(",
"$",
"account",
"->",
"getMainContact",
"(",
")",
"->",
"getId",
"(",
")",
")",
"===",
"$",
"contactId",
")",
"{",
"$",
"account",
"->",
"setMainContact",
"(",
"null",
")",
";",
"}",
"// Remove accountContact.",
"$",
"em",
"=",
"$",
"this",
"->",
"getDoctrine",
"(",
")",
"->",
"getManager",
"(",
")",
";",
"$",
"em",
"->",
"remove",
"(",
"$",
"accountContact",
")",
";",
"$",
"em",
"->",
"flush",
"(",
")",
";",
"$",
"view",
"=",
"$",
"this",
"->",
"view",
"(",
"$",
"id",
",",
"200",
")",
";",
"}",
"catch",
"(",
"EntityNotFoundException",
"$",
"enfe",
")",
"{",
"$",
"view",
"=",
"$",
"this",
"->",
"view",
"(",
"$",
"enfe",
"->",
"toArray",
"(",
")",
",",
"404",
")",
";",
"}",
"return",
"$",
"this",
"->",
"handleView",
"(",
"$",
"view",
")",
";",
"}"
] | Deleted account contact.
@param int $accountId
@param int $contactId
@throws \Exception
@return Response | [
"Deleted",
"account",
"contact",
"."
] | 6766a36cc2f0c807c59202bf7540a08c4ef31192 | https://github.com/sulu/sulu/blob/6766a36cc2f0c807c59202bf7540a08c4ef31192/src/Sulu/Bundle/ContactBundle/Controller/AccountController.php#L291-L323 | train |
sulu/sulu | src/Sulu/Bundle/ContactBundle/Controller/AccountController.php | AccountController.cgetAction | public function cgetAction(Request $request)
{
$locale = $this->getUser()->getLocale();
if ('true' == $request->get('flat')) {
/** @var RestHelperInterface $restHelper */
$restHelper = $this->get('sulu_core.doctrine_rest_helper');
$fieldDescriptors = $this->getFieldDescriptors();
$listBuilder = $this->generateFlatListBuilder();
$restHelper->initializeListBuilder($listBuilder, $fieldDescriptors);
$this->applyRequestParameters($request, $listBuilder);
$listResponse = $listBuilder->execute();
$listResponse = $this->addLogos($listResponse, $locale);
$list = new ListRepresentation(
$listResponse,
self::$entityKey,
'get_accounts',
$request->query->all(),
$listBuilder->getCurrentPage(),
$listBuilder->getLimit(),
$listBuilder->count()
);
$view = $this->view($list, 200);
} else {
$filter = $this->retrieveFilter($request);
$accountManager = $this->getAccountManager();
$accounts = $accountManager->findAll($locale, $filter);
$list = new CollectionRepresentation($accounts, self::$entityKey);
$view = $this->view($list, 200);
}
$context = new Context();
$context->setGroups(['fullAccount', 'partialContact', 'Default']);
$view->setContext($context);
return $this->handleView($view);
} | php | public function cgetAction(Request $request)
{
$locale = $this->getUser()->getLocale();
if ('true' == $request->get('flat')) {
/** @var RestHelperInterface $restHelper */
$restHelper = $this->get('sulu_core.doctrine_rest_helper');
$fieldDescriptors = $this->getFieldDescriptors();
$listBuilder = $this->generateFlatListBuilder();
$restHelper->initializeListBuilder($listBuilder, $fieldDescriptors);
$this->applyRequestParameters($request, $listBuilder);
$listResponse = $listBuilder->execute();
$listResponse = $this->addLogos($listResponse, $locale);
$list = new ListRepresentation(
$listResponse,
self::$entityKey,
'get_accounts',
$request->query->all(),
$listBuilder->getCurrentPage(),
$listBuilder->getLimit(),
$listBuilder->count()
);
$view = $this->view($list, 200);
} else {
$filter = $this->retrieveFilter($request);
$accountManager = $this->getAccountManager();
$accounts = $accountManager->findAll($locale, $filter);
$list = new CollectionRepresentation($accounts, self::$entityKey);
$view = $this->view($list, 200);
}
$context = new Context();
$context->setGroups(['fullAccount', 'partialContact', 'Default']);
$view->setContext($context);
return $this->handleView($view);
} | [
"public",
"function",
"cgetAction",
"(",
"Request",
"$",
"request",
")",
"{",
"$",
"locale",
"=",
"$",
"this",
"->",
"getUser",
"(",
")",
"->",
"getLocale",
"(",
")",
";",
"if",
"(",
"'true'",
"==",
"$",
"request",
"->",
"get",
"(",
"'flat'",
")",
")",
"{",
"/** @var RestHelperInterface $restHelper */",
"$",
"restHelper",
"=",
"$",
"this",
"->",
"get",
"(",
"'sulu_core.doctrine_rest_helper'",
")",
";",
"$",
"fieldDescriptors",
"=",
"$",
"this",
"->",
"getFieldDescriptors",
"(",
")",
";",
"$",
"listBuilder",
"=",
"$",
"this",
"->",
"generateFlatListBuilder",
"(",
")",
";",
"$",
"restHelper",
"->",
"initializeListBuilder",
"(",
"$",
"listBuilder",
",",
"$",
"fieldDescriptors",
")",
";",
"$",
"this",
"->",
"applyRequestParameters",
"(",
"$",
"request",
",",
"$",
"listBuilder",
")",
";",
"$",
"listResponse",
"=",
"$",
"listBuilder",
"->",
"execute",
"(",
")",
";",
"$",
"listResponse",
"=",
"$",
"this",
"->",
"addLogos",
"(",
"$",
"listResponse",
",",
"$",
"locale",
")",
";",
"$",
"list",
"=",
"new",
"ListRepresentation",
"(",
"$",
"listResponse",
",",
"self",
"::",
"$",
"entityKey",
",",
"'get_accounts'",
",",
"$",
"request",
"->",
"query",
"->",
"all",
"(",
")",
",",
"$",
"listBuilder",
"->",
"getCurrentPage",
"(",
")",
",",
"$",
"listBuilder",
"->",
"getLimit",
"(",
")",
",",
"$",
"listBuilder",
"->",
"count",
"(",
")",
")",
";",
"$",
"view",
"=",
"$",
"this",
"->",
"view",
"(",
"$",
"list",
",",
"200",
")",
";",
"}",
"else",
"{",
"$",
"filter",
"=",
"$",
"this",
"->",
"retrieveFilter",
"(",
"$",
"request",
")",
";",
"$",
"accountManager",
"=",
"$",
"this",
"->",
"getAccountManager",
"(",
")",
";",
"$",
"accounts",
"=",
"$",
"accountManager",
"->",
"findAll",
"(",
"$",
"locale",
",",
"$",
"filter",
")",
";",
"$",
"list",
"=",
"new",
"CollectionRepresentation",
"(",
"$",
"accounts",
",",
"self",
"::",
"$",
"entityKey",
")",
";",
"$",
"view",
"=",
"$",
"this",
"->",
"view",
"(",
"$",
"list",
",",
"200",
")",
";",
"}",
"$",
"context",
"=",
"new",
"Context",
"(",
")",
";",
"$",
"context",
"->",
"setGroups",
"(",
"[",
"'fullAccount'",
",",
"'partialContact'",
",",
"'Default'",
"]",
")",
";",
"$",
"view",
"->",
"setContext",
"(",
"$",
"context",
")",
";",
"return",
"$",
"this",
"->",
"handleView",
"(",
"$",
"view",
")",
";",
"}"
] | Lists all accounts.
Optional parameter 'flat' calls listAction.
@param Request $request
@return Response | [
"Lists",
"all",
"accounts",
".",
"Optional",
"parameter",
"flat",
"calls",
"listAction",
"."
] | 6766a36cc2f0c807c59202bf7540a08c4ef31192 | https://github.com/sulu/sulu/blob/6766a36cc2f0c807c59202bf7540a08c4ef31192/src/Sulu/Bundle/ContactBundle/Controller/AccountController.php#L333-L372 | train |
sulu/sulu | src/Sulu/Bundle/ContactBundle/Controller/AccountController.php | AccountController.generateFlatListBuilder | protected function generateFlatListBuilder()
{
/** @var DoctrineListBuilderFactory $factory */
$factory = $this->get('sulu_core.doctrine_list_builder_factory');
$listBuilder = $factory->create($this->getAccountEntityName());
return $listBuilder;
} | php | protected function generateFlatListBuilder()
{
/** @var DoctrineListBuilderFactory $factory */
$factory = $this->get('sulu_core.doctrine_list_builder_factory');
$listBuilder = $factory->create($this->getAccountEntityName());
return $listBuilder;
} | [
"protected",
"function",
"generateFlatListBuilder",
"(",
")",
"{",
"/** @var DoctrineListBuilderFactory $factory */",
"$",
"factory",
"=",
"$",
"this",
"->",
"get",
"(",
"'sulu_core.doctrine_list_builder_factory'",
")",
";",
"$",
"listBuilder",
"=",
"$",
"factory",
"->",
"create",
"(",
"$",
"this",
"->",
"getAccountEntityName",
"(",
")",
")",
";",
"return",
"$",
"listBuilder",
";",
"}"
] | Creates a listbuilder instance.
@return DoctrineListBuilder | [
"Creates",
"a",
"listbuilder",
"instance",
"."
] | 6766a36cc2f0c807c59202bf7540a08c4ef31192 | https://github.com/sulu/sulu/blob/6766a36cc2f0c807c59202bf7540a08c4ef31192/src/Sulu/Bundle/ContactBundle/Controller/AccountController.php#L379-L386 | train |
sulu/sulu | src/Sulu/Bundle/ContactBundle/Controller/AccountController.php | AccountController.applyRequestParameters | protected function applyRequestParameters(Request $request, $listBuilder)
{
if (json_decode($request->get('hasNoParent', null))) {
$listBuilder->where($this->getFieldDescriptorForNoParent(), null);
}
if (json_decode($request->get('hasEmail', null))) {
$listBuilder->whereNot($this->getFieldDescriptors()['mainEmail'], null);
}
} | php | protected function applyRequestParameters(Request $request, $listBuilder)
{
if (json_decode($request->get('hasNoParent', null))) {
$listBuilder->where($this->getFieldDescriptorForNoParent(), null);
}
if (json_decode($request->get('hasEmail', null))) {
$listBuilder->whereNot($this->getFieldDescriptors()['mainEmail'], null);
}
} | [
"protected",
"function",
"applyRequestParameters",
"(",
"Request",
"$",
"request",
",",
"$",
"listBuilder",
")",
"{",
"if",
"(",
"json_decode",
"(",
"$",
"request",
"->",
"get",
"(",
"'hasNoParent'",
",",
"null",
")",
")",
")",
"{",
"$",
"listBuilder",
"->",
"where",
"(",
"$",
"this",
"->",
"getFieldDescriptorForNoParent",
"(",
")",
",",
"null",
")",
";",
"}",
"if",
"(",
"json_decode",
"(",
"$",
"request",
"->",
"get",
"(",
"'hasEmail'",
",",
"null",
")",
")",
")",
"{",
"$",
"listBuilder",
"->",
"whereNot",
"(",
"$",
"this",
"->",
"getFieldDescriptors",
"(",
")",
"[",
"'mainEmail'",
"]",
",",
"null",
")",
";",
"}",
"}"
] | Applies the filter parameter and hasNoparent parameter for listbuilder.
@param Request $request
@param DoctrineListBuilder $listBuilder | [
"Applies",
"the",
"filter",
"parameter",
"and",
"hasNoparent",
"parameter",
"for",
"listbuilder",
"."
] | 6766a36cc2f0c807c59202bf7540a08c4ef31192 | https://github.com/sulu/sulu/blob/6766a36cc2f0c807c59202bf7540a08c4ef31192/src/Sulu/Bundle/ContactBundle/Controller/AccountController.php#L394-L403 | train |
sulu/sulu | src/Sulu/Bundle/ContactBundle/Controller/AccountController.php | AccountController.postAction | public function postAction(Request $request)
{
$name = $request->get('name');
try {
if (null == $name) {
throw new RestException('There is no name for the account given');
}
$em = $this->getDoctrine()->getManager();
$account = $this->doPost($request);
$em->persist($account);
$em->flush();
$accountManager = $this->getAccountManager();
$locale = $this->getUser()->getLocale();
$acc = $accountManager->getAccount($account, $locale);
$view = $this->view($acc, 200);
$context = new Context();
$context->setGroups(self::$accountSerializationGroups);
$view->setContext($context);
} catch (EntityNotFoundException $enfe) {
$view = $this->view($enfe->toArray(), 404);
} catch (RestException $re) {
$view = $this->view($re->toArray(), 400);
}
return $this->handleView($view);
} | php | public function postAction(Request $request)
{
$name = $request->get('name');
try {
if (null == $name) {
throw new RestException('There is no name for the account given');
}
$em = $this->getDoctrine()->getManager();
$account = $this->doPost($request);
$em->persist($account);
$em->flush();
$accountManager = $this->getAccountManager();
$locale = $this->getUser()->getLocale();
$acc = $accountManager->getAccount($account, $locale);
$view = $this->view($acc, 200);
$context = new Context();
$context->setGroups(self::$accountSerializationGroups);
$view->setContext($context);
} catch (EntityNotFoundException $enfe) {
$view = $this->view($enfe->toArray(), 404);
} catch (RestException $re) {
$view = $this->view($re->toArray(), 400);
}
return $this->handleView($view);
} | [
"public",
"function",
"postAction",
"(",
"Request",
"$",
"request",
")",
"{",
"$",
"name",
"=",
"$",
"request",
"->",
"get",
"(",
"'name'",
")",
";",
"try",
"{",
"if",
"(",
"null",
"==",
"$",
"name",
")",
"{",
"throw",
"new",
"RestException",
"(",
"'There is no name for the account given'",
")",
";",
"}",
"$",
"em",
"=",
"$",
"this",
"->",
"getDoctrine",
"(",
")",
"->",
"getManager",
"(",
")",
";",
"$",
"account",
"=",
"$",
"this",
"->",
"doPost",
"(",
"$",
"request",
")",
";",
"$",
"em",
"->",
"persist",
"(",
"$",
"account",
")",
";",
"$",
"em",
"->",
"flush",
"(",
")",
";",
"$",
"accountManager",
"=",
"$",
"this",
"->",
"getAccountManager",
"(",
")",
";",
"$",
"locale",
"=",
"$",
"this",
"->",
"getUser",
"(",
")",
"->",
"getLocale",
"(",
")",
";",
"$",
"acc",
"=",
"$",
"accountManager",
"->",
"getAccount",
"(",
"$",
"account",
",",
"$",
"locale",
")",
";",
"$",
"view",
"=",
"$",
"this",
"->",
"view",
"(",
"$",
"acc",
",",
"200",
")",
";",
"$",
"context",
"=",
"new",
"Context",
"(",
")",
";",
"$",
"context",
"->",
"setGroups",
"(",
"self",
"::",
"$",
"accountSerializationGroups",
")",
";",
"$",
"view",
"->",
"setContext",
"(",
"$",
"context",
")",
";",
"}",
"catch",
"(",
"EntityNotFoundException",
"$",
"enfe",
")",
"{",
"$",
"view",
"=",
"$",
"this",
"->",
"view",
"(",
"$",
"enfe",
"->",
"toArray",
"(",
")",
",",
"404",
")",
";",
"}",
"catch",
"(",
"RestException",
"$",
"re",
")",
"{",
"$",
"view",
"=",
"$",
"this",
"->",
"view",
"(",
"$",
"re",
"->",
"toArray",
"(",
")",
",",
"400",
")",
";",
"}",
"return",
"$",
"this",
"->",
"handleView",
"(",
"$",
"view",
")",
";",
"}"
] | Creates a new account.
@param Request $request
@return Response | [
"Creates",
"a",
"new",
"account",
"."
] | 6766a36cc2f0c807c59202bf7540a08c4ef31192 | https://github.com/sulu/sulu/blob/6766a36cc2f0c807c59202bf7540a08c4ef31192/src/Sulu/Bundle/ContactBundle/Controller/AccountController.php#L433-L462 | train |
sulu/sulu | src/Sulu/Bundle/ContactBundle/Controller/AccountController.php | AccountController.doPost | protected function doPost(Request $request)
{
$accountManager = $this->getAccountManager();
$account = $this->get('sulu_contact.account_factory')->createEntity();
$account->setName($request->get('name'));
$account->setCorporation($request->get('corporation'));
if (null !== $request->get('uid')) {
$account->setUid($request->get('uid'));
}
if (null !== $request->get('note')) {
$account->setNote($request->get('note'));
}
$logo = $request->get('logo', []);
if ($logo && array_key_exists('id', $logo)) {
$accountManager->setLogo($account, $request->get('logo')['id']);
}
$this->setParent($request->get('parent'), $account);
$accountManager->processCategories($account, $request->get('categories', []));
$account->setCreator($this->getUser());
$account->setChanger($this->getUser());
// Add urls, phones, emails, tags, bankAccounts, notes, addresses,..
$accountManager->addNewContactRelations($account, $request->request->all());
return $account;
} | php | protected function doPost(Request $request)
{
$accountManager = $this->getAccountManager();
$account = $this->get('sulu_contact.account_factory')->createEntity();
$account->setName($request->get('name'));
$account->setCorporation($request->get('corporation'));
if (null !== $request->get('uid')) {
$account->setUid($request->get('uid'));
}
if (null !== $request->get('note')) {
$account->setNote($request->get('note'));
}
$logo = $request->get('logo', []);
if ($logo && array_key_exists('id', $logo)) {
$accountManager->setLogo($account, $request->get('logo')['id']);
}
$this->setParent($request->get('parent'), $account);
$accountManager->processCategories($account, $request->get('categories', []));
$account->setCreator($this->getUser());
$account->setChanger($this->getUser());
// Add urls, phones, emails, tags, bankAccounts, notes, addresses,..
$accountManager->addNewContactRelations($account, $request->request->all());
return $account;
} | [
"protected",
"function",
"doPost",
"(",
"Request",
"$",
"request",
")",
"{",
"$",
"accountManager",
"=",
"$",
"this",
"->",
"getAccountManager",
"(",
")",
";",
"$",
"account",
"=",
"$",
"this",
"->",
"get",
"(",
"'sulu_contact.account_factory'",
")",
"->",
"createEntity",
"(",
")",
";",
"$",
"account",
"->",
"setName",
"(",
"$",
"request",
"->",
"get",
"(",
"'name'",
")",
")",
";",
"$",
"account",
"->",
"setCorporation",
"(",
"$",
"request",
"->",
"get",
"(",
"'corporation'",
")",
")",
";",
"if",
"(",
"null",
"!==",
"$",
"request",
"->",
"get",
"(",
"'uid'",
")",
")",
"{",
"$",
"account",
"->",
"setUid",
"(",
"$",
"request",
"->",
"get",
"(",
"'uid'",
")",
")",
";",
"}",
"if",
"(",
"null",
"!==",
"$",
"request",
"->",
"get",
"(",
"'note'",
")",
")",
"{",
"$",
"account",
"->",
"setNote",
"(",
"$",
"request",
"->",
"get",
"(",
"'note'",
")",
")",
";",
"}",
"$",
"logo",
"=",
"$",
"request",
"->",
"get",
"(",
"'logo'",
",",
"[",
"]",
")",
";",
"if",
"(",
"$",
"logo",
"&&",
"array_key_exists",
"(",
"'id'",
",",
"$",
"logo",
")",
")",
"{",
"$",
"accountManager",
"->",
"setLogo",
"(",
"$",
"account",
",",
"$",
"request",
"->",
"get",
"(",
"'logo'",
")",
"[",
"'id'",
"]",
")",
";",
"}",
"$",
"this",
"->",
"setParent",
"(",
"$",
"request",
"->",
"get",
"(",
"'parent'",
")",
",",
"$",
"account",
")",
";",
"$",
"accountManager",
"->",
"processCategories",
"(",
"$",
"account",
",",
"$",
"request",
"->",
"get",
"(",
"'categories'",
",",
"[",
"]",
")",
")",
";",
"$",
"account",
"->",
"setCreator",
"(",
"$",
"this",
"->",
"getUser",
"(",
")",
")",
";",
"$",
"account",
"->",
"setChanger",
"(",
"$",
"this",
"->",
"getUser",
"(",
")",
")",
";",
"// Add urls, phones, emails, tags, bankAccounts, notes, addresses,..",
"$",
"accountManager",
"->",
"addNewContactRelations",
"(",
"$",
"account",
",",
"$",
"request",
"->",
"request",
"->",
"all",
"(",
")",
")",
";",
"return",
"$",
"account",
";",
"}"
] | Maps data from request to a new account.
@param Request $request
@throws EntityNotFoundException
@return AccountInterface | [
"Maps",
"data",
"from",
"request",
"to",
"a",
"new",
"account",
"."
] | 6766a36cc2f0c807c59202bf7540a08c4ef31192 | https://github.com/sulu/sulu/blob/6766a36cc2f0c807c59202bf7540a08c4ef31192/src/Sulu/Bundle/ContactBundle/Controller/AccountController.php#L473-L504 | train |
sulu/sulu | src/Sulu/Bundle/ContactBundle/Controller/AccountController.php | AccountController.putAction | public function putAction($id, Request $request)
{
try {
$account = $this->getRepository()->findAccountById($id);
if (!$account) {
throw new EntityNotFoundException($this->getAccountEntityName(), $id);
} else {
$em = $this->getDoctrine()->getManager();
$this->doPut($account, $request);
$em->flush();
// get api entity
$accountManager = $this->getAccountManager();
$locale = $this->getUser()->getLocale();
$acc = $accountManager->getAccount($account, $locale);
$context = new Context();
$context->setGroups(self::$accountSerializationGroups);
$view = $this->view($acc, 200);
$view->setContext($context);
}
} catch (EntityNotFoundException $enfe) {
$view = $this->view($enfe->toArray(), 404);
} catch (RestException $exc) {
$view = $this->view($exc->toArray(), 400);
}
return $this->handleView($view);
} | php | public function putAction($id, Request $request)
{
try {
$account = $this->getRepository()->findAccountById($id);
if (!$account) {
throw new EntityNotFoundException($this->getAccountEntityName(), $id);
} else {
$em = $this->getDoctrine()->getManager();
$this->doPut($account, $request);
$em->flush();
// get api entity
$accountManager = $this->getAccountManager();
$locale = $this->getUser()->getLocale();
$acc = $accountManager->getAccount($account, $locale);
$context = new Context();
$context->setGroups(self::$accountSerializationGroups);
$view = $this->view($acc, 200);
$view->setContext($context);
}
} catch (EntityNotFoundException $enfe) {
$view = $this->view($enfe->toArray(), 404);
} catch (RestException $exc) {
$view = $this->view($exc->toArray(), 400);
}
return $this->handleView($view);
} | [
"public",
"function",
"putAction",
"(",
"$",
"id",
",",
"Request",
"$",
"request",
")",
"{",
"try",
"{",
"$",
"account",
"=",
"$",
"this",
"->",
"getRepository",
"(",
")",
"->",
"findAccountById",
"(",
"$",
"id",
")",
";",
"if",
"(",
"!",
"$",
"account",
")",
"{",
"throw",
"new",
"EntityNotFoundException",
"(",
"$",
"this",
"->",
"getAccountEntityName",
"(",
")",
",",
"$",
"id",
")",
";",
"}",
"else",
"{",
"$",
"em",
"=",
"$",
"this",
"->",
"getDoctrine",
"(",
")",
"->",
"getManager",
"(",
")",
";",
"$",
"this",
"->",
"doPut",
"(",
"$",
"account",
",",
"$",
"request",
")",
";",
"$",
"em",
"->",
"flush",
"(",
")",
";",
"// get api entity",
"$",
"accountManager",
"=",
"$",
"this",
"->",
"getAccountManager",
"(",
")",
";",
"$",
"locale",
"=",
"$",
"this",
"->",
"getUser",
"(",
")",
"->",
"getLocale",
"(",
")",
";",
"$",
"acc",
"=",
"$",
"accountManager",
"->",
"getAccount",
"(",
"$",
"account",
",",
"$",
"locale",
")",
";",
"$",
"context",
"=",
"new",
"Context",
"(",
")",
";",
"$",
"context",
"->",
"setGroups",
"(",
"self",
"::",
"$",
"accountSerializationGroups",
")",
";",
"$",
"view",
"=",
"$",
"this",
"->",
"view",
"(",
"$",
"acc",
",",
"200",
")",
";",
"$",
"view",
"->",
"setContext",
"(",
"$",
"context",
")",
";",
"}",
"}",
"catch",
"(",
"EntityNotFoundException",
"$",
"enfe",
")",
"{",
"$",
"view",
"=",
"$",
"this",
"->",
"view",
"(",
"$",
"enfe",
"->",
"toArray",
"(",
")",
",",
"404",
")",
";",
"}",
"catch",
"(",
"RestException",
"$",
"exc",
")",
"{",
"$",
"view",
"=",
"$",
"this",
"->",
"view",
"(",
"$",
"exc",
"->",
"toArray",
"(",
")",
",",
"400",
")",
";",
"}",
"return",
"$",
"this",
"->",
"handleView",
"(",
"$",
"view",
")",
";",
"}"
] | Edits the existing contact with the given id.
@param int $id The id of the contact to update
@param Request $request
@return Response
@throws \Sulu\Component\Rest\Exception\EntityNotFoundException | [
"Edits",
"the",
"existing",
"contact",
"with",
"the",
"given",
"id",
"."
] | 6766a36cc2f0c807c59202bf7540a08c4ef31192 | https://github.com/sulu/sulu/blob/6766a36cc2f0c807c59202bf7540a08c4ef31192/src/Sulu/Bundle/ContactBundle/Controller/AccountController.php#L516-L548 | train |
sulu/sulu | src/Sulu/Bundle/ContactBundle/Controller/AccountController.php | AccountController.doPut | protected function doPut(AccountInterface $account, Request $request)
{
$account->setName($request->get('name'));
$account->setCorporation($request->get('corporation'));
$accountManager = $this->getAccountManager();
if (null !== $request->get('uid')) {
$account->setUid($request->get('uid'));
}
if (null !== $request->get('note')) {
$account->setNote($request->get('note'));
}
$logo = $request->get('logo', []);
if ($logo && array_key_exists('id', $logo)) {
$accountManager->setLogo($account, $request->get('logo')['id']);
}
$this->setParent($request->get('parent'), $account);
$user = $this->getUser();
$account->setChanger($user);
// Process details
if (!($accountManager->processUrls($account, $request->get('urls', []))
&& $accountManager->processEmails($account, $request->get('emails', []))
&& $accountManager->processFaxes($account, $request->get('faxes', []))
&& $accountManager->processSocialMediaProfiles($account, $request->get('socialMediaProfiles', []))
&& $accountManager->processPhones($account, $request->get('phones', []))
&& $accountManager->processAddresses($account, $request->get('addresses', []))
&& $accountManager->processTags($account, $request->get('tags', []))
&& $accountManager->processNotes($account, $request->get('notes', []))
&& $accountManager->processCategories($account, $request->get('categories', []))
&& $accountManager->processBankAccounts($account, $request->get('bankAccounts', [])))
) {
throw new RestException('Updating dependencies is not possible', 0);
}
} | php | protected function doPut(AccountInterface $account, Request $request)
{
$account->setName($request->get('name'));
$account->setCorporation($request->get('corporation'));
$accountManager = $this->getAccountManager();
if (null !== $request->get('uid')) {
$account->setUid($request->get('uid'));
}
if (null !== $request->get('note')) {
$account->setNote($request->get('note'));
}
$logo = $request->get('logo', []);
if ($logo && array_key_exists('id', $logo)) {
$accountManager->setLogo($account, $request->get('logo')['id']);
}
$this->setParent($request->get('parent'), $account);
$user = $this->getUser();
$account->setChanger($user);
// Process details
if (!($accountManager->processUrls($account, $request->get('urls', []))
&& $accountManager->processEmails($account, $request->get('emails', []))
&& $accountManager->processFaxes($account, $request->get('faxes', []))
&& $accountManager->processSocialMediaProfiles($account, $request->get('socialMediaProfiles', []))
&& $accountManager->processPhones($account, $request->get('phones', []))
&& $accountManager->processAddresses($account, $request->get('addresses', []))
&& $accountManager->processTags($account, $request->get('tags', []))
&& $accountManager->processNotes($account, $request->get('notes', []))
&& $accountManager->processCategories($account, $request->get('categories', []))
&& $accountManager->processBankAccounts($account, $request->get('bankAccounts', [])))
) {
throw new RestException('Updating dependencies is not possible', 0);
}
} | [
"protected",
"function",
"doPut",
"(",
"AccountInterface",
"$",
"account",
",",
"Request",
"$",
"request",
")",
"{",
"$",
"account",
"->",
"setName",
"(",
"$",
"request",
"->",
"get",
"(",
"'name'",
")",
")",
";",
"$",
"account",
"->",
"setCorporation",
"(",
"$",
"request",
"->",
"get",
"(",
"'corporation'",
")",
")",
";",
"$",
"accountManager",
"=",
"$",
"this",
"->",
"getAccountManager",
"(",
")",
";",
"if",
"(",
"null",
"!==",
"$",
"request",
"->",
"get",
"(",
"'uid'",
")",
")",
"{",
"$",
"account",
"->",
"setUid",
"(",
"$",
"request",
"->",
"get",
"(",
"'uid'",
")",
")",
";",
"}",
"if",
"(",
"null",
"!==",
"$",
"request",
"->",
"get",
"(",
"'note'",
")",
")",
"{",
"$",
"account",
"->",
"setNote",
"(",
"$",
"request",
"->",
"get",
"(",
"'note'",
")",
")",
";",
"}",
"$",
"logo",
"=",
"$",
"request",
"->",
"get",
"(",
"'logo'",
",",
"[",
"]",
")",
";",
"if",
"(",
"$",
"logo",
"&&",
"array_key_exists",
"(",
"'id'",
",",
"$",
"logo",
")",
")",
"{",
"$",
"accountManager",
"->",
"setLogo",
"(",
"$",
"account",
",",
"$",
"request",
"->",
"get",
"(",
"'logo'",
")",
"[",
"'id'",
"]",
")",
";",
"}",
"$",
"this",
"->",
"setParent",
"(",
"$",
"request",
"->",
"get",
"(",
"'parent'",
")",
",",
"$",
"account",
")",
";",
"$",
"user",
"=",
"$",
"this",
"->",
"getUser",
"(",
")",
";",
"$",
"account",
"->",
"setChanger",
"(",
"$",
"user",
")",
";",
"// Process details",
"if",
"(",
"!",
"(",
"$",
"accountManager",
"->",
"processUrls",
"(",
"$",
"account",
",",
"$",
"request",
"->",
"get",
"(",
"'urls'",
",",
"[",
"]",
")",
")",
"&&",
"$",
"accountManager",
"->",
"processEmails",
"(",
"$",
"account",
",",
"$",
"request",
"->",
"get",
"(",
"'emails'",
",",
"[",
"]",
")",
")",
"&&",
"$",
"accountManager",
"->",
"processFaxes",
"(",
"$",
"account",
",",
"$",
"request",
"->",
"get",
"(",
"'faxes'",
",",
"[",
"]",
")",
")",
"&&",
"$",
"accountManager",
"->",
"processSocialMediaProfiles",
"(",
"$",
"account",
",",
"$",
"request",
"->",
"get",
"(",
"'socialMediaProfiles'",
",",
"[",
"]",
")",
")",
"&&",
"$",
"accountManager",
"->",
"processPhones",
"(",
"$",
"account",
",",
"$",
"request",
"->",
"get",
"(",
"'phones'",
",",
"[",
"]",
")",
")",
"&&",
"$",
"accountManager",
"->",
"processAddresses",
"(",
"$",
"account",
",",
"$",
"request",
"->",
"get",
"(",
"'addresses'",
",",
"[",
"]",
")",
")",
"&&",
"$",
"accountManager",
"->",
"processTags",
"(",
"$",
"account",
",",
"$",
"request",
"->",
"get",
"(",
"'tags'",
",",
"[",
"]",
")",
")",
"&&",
"$",
"accountManager",
"->",
"processNotes",
"(",
"$",
"account",
",",
"$",
"request",
"->",
"get",
"(",
"'notes'",
",",
"[",
"]",
")",
")",
"&&",
"$",
"accountManager",
"->",
"processCategories",
"(",
"$",
"account",
",",
"$",
"request",
"->",
"get",
"(",
"'categories'",
",",
"[",
"]",
")",
")",
"&&",
"$",
"accountManager",
"->",
"processBankAccounts",
"(",
"$",
"account",
",",
"$",
"request",
"->",
"get",
"(",
"'bankAccounts'",
",",
"[",
"]",
")",
")",
")",
")",
"{",
"throw",
"new",
"RestException",
"(",
"'Updating dependencies is not possible'",
",",
"0",
")",
";",
"}",
"}"
] | processes given entity for put.
@param AccountInterface $account
@param Request $request
@throws EntityNotFoundException
@throws RestException | [
"processes",
"given",
"entity",
"for",
"put",
"."
] | 6766a36cc2f0c807c59202bf7540a08c4ef31192 | https://github.com/sulu/sulu/blob/6766a36cc2f0c807c59202bf7540a08c4ef31192/src/Sulu/Bundle/ContactBundle/Controller/AccountController.php#L559-L597 | train |
sulu/sulu | src/Sulu/Bundle/ContactBundle/Controller/AccountController.php | AccountController.setParent | private function setParent($parentData, AccountInterface $account)
{
if (null != $parentData && isset($parentData['id']) && 'null' != $parentData['id'] && '' != $parentData['id']) {
$parent = $this->getRepository()->findAccountById($parentData['id']);
if (!$parent) {
throw new EntityNotFoundException($this->getAccountEntityName(), $parentData['id']);
}
$account->setParent($parent);
} else {
$account->setParent(null);
}
} | php | private function setParent($parentData, AccountInterface $account)
{
if (null != $parentData && isset($parentData['id']) && 'null' != $parentData['id'] && '' != $parentData['id']) {
$parent = $this->getRepository()->findAccountById($parentData['id']);
if (!$parent) {
throw new EntityNotFoundException($this->getAccountEntityName(), $parentData['id']);
}
$account->setParent($parent);
} else {
$account->setParent(null);
}
} | [
"private",
"function",
"setParent",
"(",
"$",
"parentData",
",",
"AccountInterface",
"$",
"account",
")",
"{",
"if",
"(",
"null",
"!=",
"$",
"parentData",
"&&",
"isset",
"(",
"$",
"parentData",
"[",
"'id'",
"]",
")",
"&&",
"'null'",
"!=",
"$",
"parentData",
"[",
"'id'",
"]",
"&&",
"''",
"!=",
"$",
"parentData",
"[",
"'id'",
"]",
")",
"{",
"$",
"parent",
"=",
"$",
"this",
"->",
"getRepository",
"(",
")",
"->",
"findAccountById",
"(",
"$",
"parentData",
"[",
"'id'",
"]",
")",
";",
"if",
"(",
"!",
"$",
"parent",
")",
"{",
"throw",
"new",
"EntityNotFoundException",
"(",
"$",
"this",
"->",
"getAccountEntityName",
"(",
")",
",",
"$",
"parentData",
"[",
"'id'",
"]",
")",
";",
"}",
"$",
"account",
"->",
"setParent",
"(",
"$",
"parent",
")",
";",
"}",
"else",
"{",
"$",
"account",
"->",
"setParent",
"(",
"null",
")",
";",
"}",
"}"
] | Set parent to account.
@param array $parentData
@param AccountInterface $account
@throws \Sulu\Component\Rest\Exception\EntityNotFoundException | [
"Set",
"parent",
"to",
"account",
"."
] | 6766a36cc2f0c807c59202bf7540a08c4ef31192 | https://github.com/sulu/sulu/blob/6766a36cc2f0c807c59202bf7540a08c4ef31192/src/Sulu/Bundle/ContactBundle/Controller/AccountController.php#L607-L618 | train |
sulu/sulu | src/Sulu/Bundle/ContactBundle/Controller/AccountController.php | AccountController.doPatch | protected function doPatch(AccountInterface $account, Request $request, ObjectManager $entityManager)
{
$accountManager = $this->getAccountManager();
if (null !== $request->get('uid')) {
$account->setUid($request->get('uid'));
}
if (null !== $request->get('registerNumber')) {
$account->setRegisterNumber($request->get('registerNumber'));
}
if (null !== $request->get('number')) {
$account->setNumber($request->get('number'));
}
if (null !== $request->get('placeOfJurisdiction')) {
$account->setPlaceOfJurisdiction($request->get('placeOfJurisdiction'));
}
if (array_key_exists('id', $request->get('logo', []))) {
$accountManager->setLogo($account, $request->get('logo')['id']);
}
if (null !== $request->get('medias')) {
$accountManager->setMedias($account, $request->get('medias'));
}
// Check if mainContact is set
if (null !== ($mainContactRequest = $request->get('mainContact'))) {
$mainContact = $entityManager->getRepository(
$this->container->getParameter('sulu.model.contact.class')
)->find($mainContactRequest['id']);
if ($mainContact) {
$account->setMainContact($mainContact);
}
}
// Process details
if (null !== $request->get('bankAccounts')) {
$accountManager->processBankAccounts($account, $request->get('bankAccounts', []));
}
} | php | protected function doPatch(AccountInterface $account, Request $request, ObjectManager $entityManager)
{
$accountManager = $this->getAccountManager();
if (null !== $request->get('uid')) {
$account->setUid($request->get('uid'));
}
if (null !== $request->get('registerNumber')) {
$account->setRegisterNumber($request->get('registerNumber'));
}
if (null !== $request->get('number')) {
$account->setNumber($request->get('number'));
}
if (null !== $request->get('placeOfJurisdiction')) {
$account->setPlaceOfJurisdiction($request->get('placeOfJurisdiction'));
}
if (array_key_exists('id', $request->get('logo', []))) {
$accountManager->setLogo($account, $request->get('logo')['id']);
}
if (null !== $request->get('medias')) {
$accountManager->setMedias($account, $request->get('medias'));
}
// Check if mainContact is set
if (null !== ($mainContactRequest = $request->get('mainContact'))) {
$mainContact = $entityManager->getRepository(
$this->container->getParameter('sulu.model.contact.class')
)->find($mainContactRequest['id']);
if ($mainContact) {
$account->setMainContact($mainContact);
}
}
// Process details
if (null !== $request->get('bankAccounts')) {
$accountManager->processBankAccounts($account, $request->get('bankAccounts', []));
}
} | [
"protected",
"function",
"doPatch",
"(",
"AccountInterface",
"$",
"account",
",",
"Request",
"$",
"request",
",",
"ObjectManager",
"$",
"entityManager",
")",
"{",
"$",
"accountManager",
"=",
"$",
"this",
"->",
"getAccountManager",
"(",
")",
";",
"if",
"(",
"null",
"!==",
"$",
"request",
"->",
"get",
"(",
"'uid'",
")",
")",
"{",
"$",
"account",
"->",
"setUid",
"(",
"$",
"request",
"->",
"get",
"(",
"'uid'",
")",
")",
";",
"}",
"if",
"(",
"null",
"!==",
"$",
"request",
"->",
"get",
"(",
"'registerNumber'",
")",
")",
"{",
"$",
"account",
"->",
"setRegisterNumber",
"(",
"$",
"request",
"->",
"get",
"(",
"'registerNumber'",
")",
")",
";",
"}",
"if",
"(",
"null",
"!==",
"$",
"request",
"->",
"get",
"(",
"'number'",
")",
")",
"{",
"$",
"account",
"->",
"setNumber",
"(",
"$",
"request",
"->",
"get",
"(",
"'number'",
")",
")",
";",
"}",
"if",
"(",
"null",
"!==",
"$",
"request",
"->",
"get",
"(",
"'placeOfJurisdiction'",
")",
")",
"{",
"$",
"account",
"->",
"setPlaceOfJurisdiction",
"(",
"$",
"request",
"->",
"get",
"(",
"'placeOfJurisdiction'",
")",
")",
";",
"}",
"if",
"(",
"array_key_exists",
"(",
"'id'",
",",
"$",
"request",
"->",
"get",
"(",
"'logo'",
",",
"[",
"]",
")",
")",
")",
"{",
"$",
"accountManager",
"->",
"setLogo",
"(",
"$",
"account",
",",
"$",
"request",
"->",
"get",
"(",
"'logo'",
")",
"[",
"'id'",
"]",
")",
";",
"}",
"if",
"(",
"null",
"!==",
"$",
"request",
"->",
"get",
"(",
"'medias'",
")",
")",
"{",
"$",
"accountManager",
"->",
"setMedias",
"(",
"$",
"account",
",",
"$",
"request",
"->",
"get",
"(",
"'medias'",
")",
")",
";",
"}",
"// Check if mainContact is set",
"if",
"(",
"null",
"!==",
"(",
"$",
"mainContactRequest",
"=",
"$",
"request",
"->",
"get",
"(",
"'mainContact'",
")",
")",
")",
"{",
"$",
"mainContact",
"=",
"$",
"entityManager",
"->",
"getRepository",
"(",
"$",
"this",
"->",
"container",
"->",
"getParameter",
"(",
"'sulu.model.contact.class'",
")",
")",
"->",
"find",
"(",
"$",
"mainContactRequest",
"[",
"'id'",
"]",
")",
";",
"if",
"(",
"$",
"mainContact",
")",
"{",
"$",
"account",
"->",
"setMainContact",
"(",
"$",
"mainContact",
")",
";",
"}",
"}",
"// Process details",
"if",
"(",
"null",
"!==",
"$",
"request",
"->",
"get",
"(",
"'bankAccounts'",
")",
")",
"{",
"$",
"accountManager",
"->",
"processBankAccounts",
"(",
"$",
"account",
",",
"$",
"request",
"->",
"get",
"(",
"'bankAccounts'",
",",
"[",
"]",
")",
")",
";",
"}",
"}"
] | Process geiven entity for patch.
@param AccountInterface $account
@param Request $request
@param ObjectManager $entityManager | [
"Process",
"geiven",
"entity",
"for",
"patch",
"."
] | 6766a36cc2f0c807c59202bf7540a08c4ef31192 | https://github.com/sulu/sulu/blob/6766a36cc2f0c807c59202bf7540a08c4ef31192/src/Sulu/Bundle/ContactBundle/Controller/AccountController.php#L669-L705 | train |
sulu/sulu | src/Sulu/Bundle/ContactBundle/Controller/AccountController.php | AccountController.deleteAction | public function deleteAction($id, Request $request)
{
$delete = function($id) use ($request) {
$account = $this->getRepository()->findAccountByIdAndDelete($id);
if (!$account) {
throw new EntityNotFoundException($this->getAccountEntityName(), $id);
}
$em = $this->getDoctrine()->getManager();
$addresses = $account->getAddresses();
/** @var AddressEntity $address */
foreach ($addresses as $address) {
if (!$address->hasRelations()) {
$em->remove($address);
}
}
// Remove related contacts if removeContacts is true.
if (null !== $request->get('removeContacts') &&
'true' == $request->get('removeContacts')
) {
foreach ($account->getAccountContacts() as $accountContact) {
$em->remove($accountContact->getContact());
}
}
$em->remove($account);
$em->flush();
};
$view = $this->responseDelete($id, $delete);
return $this->handleView($view);
} | php | public function deleteAction($id, Request $request)
{
$delete = function($id) use ($request) {
$account = $this->getRepository()->findAccountByIdAndDelete($id);
if (!$account) {
throw new EntityNotFoundException($this->getAccountEntityName(), $id);
}
$em = $this->getDoctrine()->getManager();
$addresses = $account->getAddresses();
/** @var AddressEntity $address */
foreach ($addresses as $address) {
if (!$address->hasRelations()) {
$em->remove($address);
}
}
// Remove related contacts if removeContacts is true.
if (null !== $request->get('removeContacts') &&
'true' == $request->get('removeContacts')
) {
foreach ($account->getAccountContacts() as $accountContact) {
$em->remove($accountContact->getContact());
}
}
$em->remove($account);
$em->flush();
};
$view = $this->responseDelete($id, $delete);
return $this->handleView($view);
} | [
"public",
"function",
"deleteAction",
"(",
"$",
"id",
",",
"Request",
"$",
"request",
")",
"{",
"$",
"delete",
"=",
"function",
"(",
"$",
"id",
")",
"use",
"(",
"$",
"request",
")",
"{",
"$",
"account",
"=",
"$",
"this",
"->",
"getRepository",
"(",
")",
"->",
"findAccountByIdAndDelete",
"(",
"$",
"id",
")",
";",
"if",
"(",
"!",
"$",
"account",
")",
"{",
"throw",
"new",
"EntityNotFoundException",
"(",
"$",
"this",
"->",
"getAccountEntityName",
"(",
")",
",",
"$",
"id",
")",
";",
"}",
"$",
"em",
"=",
"$",
"this",
"->",
"getDoctrine",
"(",
")",
"->",
"getManager",
"(",
")",
";",
"$",
"addresses",
"=",
"$",
"account",
"->",
"getAddresses",
"(",
")",
";",
"/** @var AddressEntity $address */",
"foreach",
"(",
"$",
"addresses",
"as",
"$",
"address",
")",
"{",
"if",
"(",
"!",
"$",
"address",
"->",
"hasRelations",
"(",
")",
")",
"{",
"$",
"em",
"->",
"remove",
"(",
"$",
"address",
")",
";",
"}",
"}",
"// Remove related contacts if removeContacts is true.",
"if",
"(",
"null",
"!==",
"$",
"request",
"->",
"get",
"(",
"'removeContacts'",
")",
"&&",
"'true'",
"==",
"$",
"request",
"->",
"get",
"(",
"'removeContacts'",
")",
")",
"{",
"foreach",
"(",
"$",
"account",
"->",
"getAccountContacts",
"(",
")",
"as",
"$",
"accountContact",
")",
"{",
"$",
"em",
"->",
"remove",
"(",
"$",
"accountContact",
"->",
"getContact",
"(",
")",
")",
";",
"}",
"}",
"$",
"em",
"->",
"remove",
"(",
"$",
"account",
")",
";",
"$",
"em",
"->",
"flush",
"(",
")",
";",
"}",
";",
"$",
"view",
"=",
"$",
"this",
"->",
"responseDelete",
"(",
"$",
"id",
",",
"$",
"delete",
")",
";",
"return",
"$",
"this",
"->",
"handleView",
"(",
"$",
"view",
")",
";",
"}"
] | Delete an account with the given id.
@param $id
@param Request $request
@return Response | [
"Delete",
"an",
"account",
"with",
"the",
"given",
"id",
"."
] | 6766a36cc2f0c807c59202bf7540a08c4ef31192 | https://github.com/sulu/sulu/blob/6766a36cc2f0c807c59202bf7540a08c4ef31192/src/Sulu/Bundle/ContactBundle/Controller/AccountController.php#L715-L750 | train |
sulu/sulu | src/Sulu/Bundle/ContactBundle/Controller/AccountController.php | AccountController.multipledeleteinfoAction | public function multipledeleteinfoAction(Request $request)
{
$ids = $request->get('ids');
$response = [];
$numContacts = 0;
$numChildren = 0;
foreach ($ids as $id) {
$account = $this->getRepository()->countDistinctAccountChildrenAndContacts($id);
// Get number of subaccounts.
$numChildren += $account['numChildren'];
// FIXME: Distinct contacts: (currently the same contacts could be counted multiple times).
// Get full number of contacts.
$numContacts += $account['numContacts'];
}
$response['numContacts'] = $numContacts;
$response['numChildren'] = $numChildren;
$view = $this->view($response, 200);
return $this->handleView($view);
} | php | public function multipledeleteinfoAction(Request $request)
{
$ids = $request->get('ids');
$response = [];
$numContacts = 0;
$numChildren = 0;
foreach ($ids as $id) {
$account = $this->getRepository()->countDistinctAccountChildrenAndContacts($id);
// Get number of subaccounts.
$numChildren += $account['numChildren'];
// FIXME: Distinct contacts: (currently the same contacts could be counted multiple times).
// Get full number of contacts.
$numContacts += $account['numContacts'];
}
$response['numContacts'] = $numContacts;
$response['numChildren'] = $numChildren;
$view = $this->view($response, 200);
return $this->handleView($view);
} | [
"public",
"function",
"multipledeleteinfoAction",
"(",
"Request",
"$",
"request",
")",
"{",
"$",
"ids",
"=",
"$",
"request",
"->",
"get",
"(",
"'ids'",
")",
";",
"$",
"response",
"=",
"[",
"]",
";",
"$",
"numContacts",
"=",
"0",
";",
"$",
"numChildren",
"=",
"0",
";",
"foreach",
"(",
"$",
"ids",
"as",
"$",
"id",
")",
"{",
"$",
"account",
"=",
"$",
"this",
"->",
"getRepository",
"(",
")",
"->",
"countDistinctAccountChildrenAndContacts",
"(",
"$",
"id",
")",
";",
"// Get number of subaccounts.",
"$",
"numChildren",
"+=",
"$",
"account",
"[",
"'numChildren'",
"]",
";",
"// FIXME: Distinct contacts: (currently the same contacts could be counted multiple times).",
"// Get full number of contacts.",
"$",
"numContacts",
"+=",
"$",
"account",
"[",
"'numContacts'",
"]",
";",
"}",
"$",
"response",
"[",
"'numContacts'",
"]",
"=",
"$",
"numContacts",
";",
"$",
"response",
"[",
"'numChildren'",
"]",
"=",
"$",
"numChildren",
";",
"$",
"view",
"=",
"$",
"this",
"->",
"view",
"(",
"$",
"response",
",",
"200",
")",
";",
"return",
"$",
"this",
"->",
"handleView",
"(",
"$",
"view",
")",
";",
"}"
] | Returns delete info for multiple ids.
@param Request $request
@return Response | [
"Returns",
"delete",
"info",
"for",
"multiple",
"ids",
"."
] | 6766a36cc2f0c807c59202bf7540a08c4ef31192 | https://github.com/sulu/sulu/blob/6766a36cc2f0c807c59202bf7540a08c4ef31192/src/Sulu/Bundle/ContactBundle/Controller/AccountController.php#L759-L784 | train |
sulu/sulu | src/Sulu/Bundle/ContactBundle/Controller/AccountController.php | AccountController.getAction | public function getAction($id, Request $request)
{
$includes = explode(',', $request->get('include'));
$accountManager = $this->getAccountManager();
$locale = $this->getUser()->getLocale();
try {
$view = $this->responseGetById(
$id,
function($id) use ($includes, $accountManager, $locale) {
return $accountManager->getByIdAndInclude($id, $locale, $includes);
}
);
$context = new Context();
$context->setGroups(self::$accountSerializationGroups);
$view->setContext($context);
} catch (EntityNotFoundException $enfe) {
$view = $this->view($enfe->toArray(), 404);
}
return $this->handleView($view);
} | php | public function getAction($id, Request $request)
{
$includes = explode(',', $request->get('include'));
$accountManager = $this->getAccountManager();
$locale = $this->getUser()->getLocale();
try {
$view = $this->responseGetById(
$id,
function($id) use ($includes, $accountManager, $locale) {
return $accountManager->getByIdAndInclude($id, $locale, $includes);
}
);
$context = new Context();
$context->setGroups(self::$accountSerializationGroups);
$view->setContext($context);
} catch (EntityNotFoundException $enfe) {
$view = $this->view($enfe->toArray(), 404);
}
return $this->handleView($view);
} | [
"public",
"function",
"getAction",
"(",
"$",
"id",
",",
"Request",
"$",
"request",
")",
"{",
"$",
"includes",
"=",
"explode",
"(",
"','",
",",
"$",
"request",
"->",
"get",
"(",
"'include'",
")",
")",
";",
"$",
"accountManager",
"=",
"$",
"this",
"->",
"getAccountManager",
"(",
")",
";",
"$",
"locale",
"=",
"$",
"this",
"->",
"getUser",
"(",
")",
"->",
"getLocale",
"(",
")",
";",
"try",
"{",
"$",
"view",
"=",
"$",
"this",
"->",
"responseGetById",
"(",
"$",
"id",
",",
"function",
"(",
"$",
"id",
")",
"use",
"(",
"$",
"includes",
",",
"$",
"accountManager",
",",
"$",
"locale",
")",
"{",
"return",
"$",
"accountManager",
"->",
"getByIdAndInclude",
"(",
"$",
"id",
",",
"$",
"locale",
",",
"$",
"includes",
")",
";",
"}",
")",
";",
"$",
"context",
"=",
"new",
"Context",
"(",
")",
";",
"$",
"context",
"->",
"setGroups",
"(",
"self",
"::",
"$",
"accountSerializationGroups",
")",
";",
"$",
"view",
"->",
"setContext",
"(",
"$",
"context",
")",
";",
"}",
"catch",
"(",
"EntityNotFoundException",
"$",
"enfe",
")",
"{",
"$",
"view",
"=",
"$",
"this",
"->",
"view",
"(",
"$",
"enfe",
"->",
"toArray",
"(",
")",
",",
"404",
")",
";",
"}",
"return",
"$",
"this",
"->",
"handleView",
"(",
"$",
"view",
")",
";",
"}"
] | Shows a single account with the given id.
@param int $id
@param Request $request
@return Response | [
"Shows",
"a",
"single",
"account",
"with",
"the",
"given",
"id",
"."
] | 6766a36cc2f0c807c59202bf7540a08c4ef31192 | https://github.com/sulu/sulu/blob/6766a36cc2f0c807c59202bf7540a08c4ef31192/src/Sulu/Bundle/ContactBundle/Controller/AccountController.php#L864-L886 | train |
sulu/sulu | src/Sulu/Bundle/ContactBundle/Controller/AccountController.php | AccountController.addLogos | private function addLogos($accounts, $locale)
{
$ids = array_filter(array_column($accounts, 'logo'));
$logos = $this->get('sulu_media.media_manager')->getFormatUrls($ids, $locale);
foreach ($accounts as $key => $account) {
if (array_key_exists('logo', $account) && $account['logo'] && array_key_exists($account['logo'], $logos)) {
$accounts[$key]['logo'] = $logos[$account['logo']];
}
}
return $accounts;
} | php | private function addLogos($accounts, $locale)
{
$ids = array_filter(array_column($accounts, 'logo'));
$logos = $this->get('sulu_media.media_manager')->getFormatUrls($ids, $locale);
foreach ($accounts as $key => $account) {
if (array_key_exists('logo', $account) && $account['logo'] && array_key_exists($account['logo'], $logos)) {
$accounts[$key]['logo'] = $logos[$account['logo']];
}
}
return $accounts;
} | [
"private",
"function",
"addLogos",
"(",
"$",
"accounts",
",",
"$",
"locale",
")",
"{",
"$",
"ids",
"=",
"array_filter",
"(",
"array_column",
"(",
"$",
"accounts",
",",
"'logo'",
")",
")",
";",
"$",
"logos",
"=",
"$",
"this",
"->",
"get",
"(",
"'sulu_media.media_manager'",
")",
"->",
"getFormatUrls",
"(",
"$",
"ids",
",",
"$",
"locale",
")",
";",
"foreach",
"(",
"$",
"accounts",
"as",
"$",
"key",
"=>",
"$",
"account",
")",
"{",
"if",
"(",
"array_key_exists",
"(",
"'logo'",
",",
"$",
"account",
")",
"&&",
"$",
"account",
"[",
"'logo'",
"]",
"&&",
"array_key_exists",
"(",
"$",
"account",
"[",
"'logo'",
"]",
",",
"$",
"logos",
")",
")",
"{",
"$",
"accounts",
"[",
"$",
"key",
"]",
"[",
"'logo'",
"]",
"=",
"$",
"logos",
"[",
"$",
"account",
"[",
"'logo'",
"]",
"]",
";",
"}",
"}",
"return",
"$",
"accounts",
";",
"}"
] | Takes an array of accounts and resets the logo-property containing the media id with
the actual urls to the logo thumbnails.
@param array $accounts
@param string $locale
@return array | [
"Takes",
"an",
"array",
"of",
"accounts",
"and",
"resets",
"the",
"logo",
"-",
"property",
"containing",
"the",
"media",
"id",
"with",
"the",
"actual",
"urls",
"to",
"the",
"logo",
"thumbnails",
"."
] | 6766a36cc2f0c807c59202bf7540a08c4ef31192 | https://github.com/sulu/sulu/blob/6766a36cc2f0c807c59202bf7540a08c4ef31192/src/Sulu/Bundle/ContactBundle/Controller/AccountController.php#L1219-L1230 | train |
sulu/sulu | src/Sulu/Bundle/ContactBundle/Controller/AccountController.php | AccountController.retrieveFilter | private function retrieveFilter(Request $request)
{
$filter = [];
$ids = $request->get('ids');
if ($ids) {
if (is_string($ids)) {
$ids = explode(',', $ids);
}
$filter['id'] = $ids;
}
return $filter;
} | php | private function retrieveFilter(Request $request)
{
$filter = [];
$ids = $request->get('ids');
if ($ids) {
if (is_string($ids)) {
$ids = explode(',', $ids);
}
$filter['id'] = $ids;
}
return $filter;
} | [
"private",
"function",
"retrieveFilter",
"(",
"Request",
"$",
"request",
")",
"{",
"$",
"filter",
"=",
"[",
"]",
";",
"$",
"ids",
"=",
"$",
"request",
"->",
"get",
"(",
"'ids'",
")",
";",
"if",
"(",
"$",
"ids",
")",
"{",
"if",
"(",
"is_string",
"(",
"$",
"ids",
")",
")",
"{",
"$",
"ids",
"=",
"explode",
"(",
"','",
",",
"$",
"ids",
")",
";",
"}",
"$",
"filter",
"[",
"'id'",
"]",
"=",
"$",
"ids",
";",
"}",
"return",
"$",
"filter",
";",
"}"
] | Retrieves the ids from the request.
@param Request $request
@param int &$count
@return array | [
"Retrieves",
"the",
"ids",
"from",
"the",
"request",
"."
] | 6766a36cc2f0c807c59202bf7540a08c4ef31192 | https://github.com/sulu/sulu/blob/6766a36cc2f0c807c59202bf7540a08c4ef31192/src/Sulu/Bundle/ContactBundle/Controller/AccountController.php#L1240-L1254 | train |
sulu/sulu | src/Sulu/Bundle/SecurityBundle/Entity/SecurityTypeRepository.php | SecurityTypeRepository.findSecurityTypeById | public function findSecurityTypeById($id)
{
try {
$qb = $this->createQueryBuilder('securityType')
->where('securityType.id=:securityTypeId');
$query = $qb->getQuery();
$query->setParameter('securityTypeId', $id);
return $query->getSingleResult();
} catch (NoResultException $ex) {
return;
}
} | php | public function findSecurityTypeById($id)
{
try {
$qb = $this->createQueryBuilder('securityType')
->where('securityType.id=:securityTypeId');
$query = $qb->getQuery();
$query->setParameter('securityTypeId', $id);
return $query->getSingleResult();
} catch (NoResultException $ex) {
return;
}
} | [
"public",
"function",
"findSecurityTypeById",
"(",
"$",
"id",
")",
"{",
"try",
"{",
"$",
"qb",
"=",
"$",
"this",
"->",
"createQueryBuilder",
"(",
"'securityType'",
")",
"->",
"where",
"(",
"'securityType.id=:securityTypeId'",
")",
";",
"$",
"query",
"=",
"$",
"qb",
"->",
"getQuery",
"(",
")",
";",
"$",
"query",
"->",
"setParameter",
"(",
"'securityTypeId'",
",",
"$",
"id",
")",
";",
"return",
"$",
"query",
"->",
"getSingleResult",
"(",
")",
";",
"}",
"catch",
"(",
"NoResultException",
"$",
"ex",
")",
"{",
"return",
";",
"}",
"}"
] | Searches for a role with a specific id.
@param $id
@return RoleInterface | [
"Searches",
"for",
"a",
"role",
"with",
"a",
"specific",
"id",
"."
] | 6766a36cc2f0c807c59202bf7540a08c4ef31192 | https://github.com/sulu/sulu/blob/6766a36cc2f0c807c59202bf7540a08c4ef31192/src/Sulu/Bundle/SecurityBundle/Entity/SecurityTypeRepository.php#L31-L44 | train |
sulu/sulu | src/Sulu/Component/Content/Extension/AbstractExtension.php | AbstractExtension.saveProperty | protected function saveProperty(NodeInterface $node, $data, $name, $default = '')
{
$value = isset($data[$name]) ? $data[$name] : $default;
$node->setProperty($this->getPropertyName($name), $value);
} | php | protected function saveProperty(NodeInterface $node, $data, $name, $default = '')
{
$value = isset($data[$name]) ? $data[$name] : $default;
$node->setProperty($this->getPropertyName($name), $value);
} | [
"protected",
"function",
"saveProperty",
"(",
"NodeInterface",
"$",
"node",
",",
"$",
"data",
",",
"$",
"name",
",",
"$",
"default",
"=",
"''",
")",
"{",
"$",
"value",
"=",
"isset",
"(",
"$",
"data",
"[",
"$",
"name",
"]",
")",
"?",
"$",
"data",
"[",
"$",
"name",
"]",
":",
"$",
"default",
";",
"$",
"node",
"->",
"setProperty",
"(",
"$",
"this",
"->",
"getPropertyName",
"(",
"$",
"name",
")",
",",
"$",
"value",
")",
";",
"}"
] | save a single property value.
@param NodeInterface $node
@param array $data data array
@param string $name name of property in node an data array
@param string $default value if no data exists with given name
@param string $default | [
"save",
"a",
"single",
"property",
"value",
"."
] | 6766a36cc2f0c807c59202bf7540a08c4ef31192 | https://github.com/sulu/sulu/blob/6766a36cc2f0c807c59202bf7540a08c4ef31192/src/Sulu/Component/Content/Extension/AbstractExtension.php#L95-L99 | train |
sulu/sulu | src/Sulu/Bundle/ContactBundle/Entity/Contact.php | Contact.getMainAccountContact | protected function getMainAccountContact()
{
$accountContacts = $this->getAccountContacts();
if (!is_null($accountContacts)) {
/** @var AccountContact $accountContact */
foreach ($accountContacts as $accountContact) {
if ($accountContact->getMain()) {
return $accountContact;
}
}
}
return;
} | php | protected function getMainAccountContact()
{
$accountContacts = $this->getAccountContacts();
if (!is_null($accountContacts)) {
/** @var AccountContact $accountContact */
foreach ($accountContacts as $accountContact) {
if ($accountContact->getMain()) {
return $accountContact;
}
}
}
return;
} | [
"protected",
"function",
"getMainAccountContact",
"(",
")",
"{",
"$",
"accountContacts",
"=",
"$",
"this",
"->",
"getAccountContacts",
"(",
")",
";",
"if",
"(",
"!",
"is_null",
"(",
"$",
"accountContacts",
")",
")",
"{",
"/** @var AccountContact $accountContact */",
"foreach",
"(",
"$",
"accountContacts",
"as",
"$",
"accountContact",
")",
"{",
"if",
"(",
"$",
"accountContact",
"->",
"getMain",
"(",
")",
")",
"{",
"return",
"$",
"accountContact",
";",
"}",
"}",
"}",
"return",
";",
"}"
] | Returns main account contact. | [
"Returns",
"main",
"account",
"contact",
"."
] | 6766a36cc2f0c807c59202bf7540a08c4ef31192 | https://github.com/sulu/sulu/blob/6766a36cc2f0c807c59202bf7540a08c4ef31192/src/Sulu/Bundle/ContactBundle/Entity/Contact.php#L809-L823 | train |
sulu/sulu | src/Sulu/Component/DocumentManager/ProxyFactory.php | ProxyFactory.createProxyForNode | public function createProxyForNode($fromDocument, NodeInterface $targetNode, $options = [])
{
// if node is already registered then just return the registered document
$locale = $this->registry->getOriginalLocaleForDocument($fromDocument);
if ($this->registry->hasNode($targetNode, $locale)) {
$document = $this->registry->getDocumentForNode($targetNode, $locale);
// If the parent is not loaded in the correct locale, reload it in the correct locale.
if ($this->registry->getOriginalLocaleForDocument($document) !== $locale) {
$hydrateEvent = new HydrateEvent($targetNode, $locale);
$hydrateEvent->setDocument($document);
$this->dispatcher->dispatch(Events::HYDRATE, $hydrateEvent);
}
return $document;
}
$initializer = function(LazyLoadingInterface $document, $method, array $parameters, &$initializer) use (
$targetNode,
$options,
$locale
) {
$hydrateEvent = new HydrateEvent($targetNode, $locale, $options);
$hydrateEvent->setDocument($document);
$this->dispatcher->dispatch(Events::HYDRATE, $hydrateEvent);
$initializer = null;
};
$targetMetadata = $this->metadataFactory->getMetadataForPhpcrNode($targetNode);
$proxy = $this->proxyFactory->createProxy($targetMetadata->getClass(), $initializer);
$locale = $this->registry->getOriginalLocaleForDocument($fromDocument);
$this->registry->registerDocument($proxy, $targetNode, $locale);
return $proxy;
} | php | public function createProxyForNode($fromDocument, NodeInterface $targetNode, $options = [])
{
// if node is already registered then just return the registered document
$locale = $this->registry->getOriginalLocaleForDocument($fromDocument);
if ($this->registry->hasNode($targetNode, $locale)) {
$document = $this->registry->getDocumentForNode($targetNode, $locale);
// If the parent is not loaded in the correct locale, reload it in the correct locale.
if ($this->registry->getOriginalLocaleForDocument($document) !== $locale) {
$hydrateEvent = new HydrateEvent($targetNode, $locale);
$hydrateEvent->setDocument($document);
$this->dispatcher->dispatch(Events::HYDRATE, $hydrateEvent);
}
return $document;
}
$initializer = function(LazyLoadingInterface $document, $method, array $parameters, &$initializer) use (
$targetNode,
$options,
$locale
) {
$hydrateEvent = new HydrateEvent($targetNode, $locale, $options);
$hydrateEvent->setDocument($document);
$this->dispatcher->dispatch(Events::HYDRATE, $hydrateEvent);
$initializer = null;
};
$targetMetadata = $this->metadataFactory->getMetadataForPhpcrNode($targetNode);
$proxy = $this->proxyFactory->createProxy($targetMetadata->getClass(), $initializer);
$locale = $this->registry->getOriginalLocaleForDocument($fromDocument);
$this->registry->registerDocument($proxy, $targetNode, $locale);
return $proxy;
} | [
"public",
"function",
"createProxyForNode",
"(",
"$",
"fromDocument",
",",
"NodeInterface",
"$",
"targetNode",
",",
"$",
"options",
"=",
"[",
"]",
")",
"{",
"// if node is already registered then just return the registered document",
"$",
"locale",
"=",
"$",
"this",
"->",
"registry",
"->",
"getOriginalLocaleForDocument",
"(",
"$",
"fromDocument",
")",
";",
"if",
"(",
"$",
"this",
"->",
"registry",
"->",
"hasNode",
"(",
"$",
"targetNode",
",",
"$",
"locale",
")",
")",
"{",
"$",
"document",
"=",
"$",
"this",
"->",
"registry",
"->",
"getDocumentForNode",
"(",
"$",
"targetNode",
",",
"$",
"locale",
")",
";",
"// If the parent is not loaded in the correct locale, reload it in the correct locale.",
"if",
"(",
"$",
"this",
"->",
"registry",
"->",
"getOriginalLocaleForDocument",
"(",
"$",
"document",
")",
"!==",
"$",
"locale",
")",
"{",
"$",
"hydrateEvent",
"=",
"new",
"HydrateEvent",
"(",
"$",
"targetNode",
",",
"$",
"locale",
")",
";",
"$",
"hydrateEvent",
"->",
"setDocument",
"(",
"$",
"document",
")",
";",
"$",
"this",
"->",
"dispatcher",
"->",
"dispatch",
"(",
"Events",
"::",
"HYDRATE",
",",
"$",
"hydrateEvent",
")",
";",
"}",
"return",
"$",
"document",
";",
"}",
"$",
"initializer",
"=",
"function",
"(",
"LazyLoadingInterface",
"$",
"document",
",",
"$",
"method",
",",
"array",
"$",
"parameters",
",",
"&",
"$",
"initializer",
")",
"use",
"(",
"$",
"targetNode",
",",
"$",
"options",
",",
"$",
"locale",
")",
"{",
"$",
"hydrateEvent",
"=",
"new",
"HydrateEvent",
"(",
"$",
"targetNode",
",",
"$",
"locale",
",",
"$",
"options",
")",
";",
"$",
"hydrateEvent",
"->",
"setDocument",
"(",
"$",
"document",
")",
";",
"$",
"this",
"->",
"dispatcher",
"->",
"dispatch",
"(",
"Events",
"::",
"HYDRATE",
",",
"$",
"hydrateEvent",
")",
";",
"$",
"initializer",
"=",
"null",
";",
"}",
";",
"$",
"targetMetadata",
"=",
"$",
"this",
"->",
"metadataFactory",
"->",
"getMetadataForPhpcrNode",
"(",
"$",
"targetNode",
")",
";",
"$",
"proxy",
"=",
"$",
"this",
"->",
"proxyFactory",
"->",
"createProxy",
"(",
"$",
"targetMetadata",
"->",
"getClass",
"(",
")",
",",
"$",
"initializer",
")",
";",
"$",
"locale",
"=",
"$",
"this",
"->",
"registry",
"->",
"getOriginalLocaleForDocument",
"(",
"$",
"fromDocument",
")",
";",
"$",
"this",
"->",
"registry",
"->",
"registerDocument",
"(",
"$",
"proxy",
",",
"$",
"targetNode",
",",
"$",
"locale",
")",
";",
"return",
"$",
"proxy",
";",
"}"
] | Create a new proxy object from the given document for
the given target node.
TODO: We only pass the document here in order to correctly evaluate its locale
later. I wonder if it necessary.
@param object $fromDocument
@param NodeInterface $targetNode
@param array $options
@return \ProxyManager\Proxy\GhostObjectInterface | [
"Create",
"a",
"new",
"proxy",
"object",
"from",
"the",
"given",
"document",
"for",
"the",
"given",
"target",
"node",
"."
] | 6766a36cc2f0c807c59202bf7540a08c4ef31192 | https://github.com/sulu/sulu/blob/6766a36cc2f0c807c59202bf7540a08c4ef31192/src/Sulu/Component/DocumentManager/ProxyFactory.php#L78-L113 | train |
sulu/sulu | src/Sulu/Component/DocumentManager/ProxyFactory.php | ProxyFactory.createChildrenCollection | public function createChildrenCollection($document, array $options = [])
{
$node = $this->registry->getNodeForDocument($document);
$locale = $this->registry->getOriginalLocaleForDocument($document);
return new ChildrenCollection(
$node,
$this->dispatcher,
$locale,
$options
);
} | php | public function createChildrenCollection($document, array $options = [])
{
$node = $this->registry->getNodeForDocument($document);
$locale = $this->registry->getOriginalLocaleForDocument($document);
return new ChildrenCollection(
$node,
$this->dispatcher,
$locale,
$options
);
} | [
"public",
"function",
"createChildrenCollection",
"(",
"$",
"document",
",",
"array",
"$",
"options",
"=",
"[",
"]",
")",
"{",
"$",
"node",
"=",
"$",
"this",
"->",
"registry",
"->",
"getNodeForDocument",
"(",
"$",
"document",
")",
";",
"$",
"locale",
"=",
"$",
"this",
"->",
"registry",
"->",
"getOriginalLocaleForDocument",
"(",
"$",
"document",
")",
";",
"return",
"new",
"ChildrenCollection",
"(",
"$",
"node",
",",
"$",
"this",
"->",
"dispatcher",
",",
"$",
"locale",
",",
"$",
"options",
")",
";",
"}"
] | Create a new children collection for the given document.
@param object $document
@return ChildrenCollection | [
"Create",
"a",
"new",
"children",
"collection",
"for",
"the",
"given",
"document",
"."
] | 6766a36cc2f0c807c59202bf7540a08c4ef31192 | https://github.com/sulu/sulu/blob/6766a36cc2f0c807c59202bf7540a08c4ef31192/src/Sulu/Component/DocumentManager/ProxyFactory.php#L122-L133 | train |
sulu/sulu | src/Sulu/Component/DocumentManager/ProxyFactory.php | ProxyFactory.createReferrerCollection | public function createReferrerCollection($document)
{
$node = $this->registry->getNodeForDocument($document);
$locale = $this->registry->getOriginalLocaleForDocument($document);
return new ReferrerCollection(
$node,
$this->dispatcher,
$locale
);
} | php | public function createReferrerCollection($document)
{
$node = $this->registry->getNodeForDocument($document);
$locale = $this->registry->getOriginalLocaleForDocument($document);
return new ReferrerCollection(
$node,
$this->dispatcher,
$locale
);
} | [
"public",
"function",
"createReferrerCollection",
"(",
"$",
"document",
")",
"{",
"$",
"node",
"=",
"$",
"this",
"->",
"registry",
"->",
"getNodeForDocument",
"(",
"$",
"document",
")",
";",
"$",
"locale",
"=",
"$",
"this",
"->",
"registry",
"->",
"getOriginalLocaleForDocument",
"(",
"$",
"document",
")",
";",
"return",
"new",
"ReferrerCollection",
"(",
"$",
"node",
",",
"$",
"this",
"->",
"dispatcher",
",",
"$",
"locale",
")",
";",
"}"
] | Create a new collection of referrers from a list of referencing items.
@param $document
@return ReferrerCollection | [
"Create",
"a",
"new",
"collection",
"of",
"referrers",
"from",
"a",
"list",
"of",
"referencing",
"items",
"."
] | 6766a36cc2f0c807c59202bf7540a08c4ef31192 | https://github.com/sulu/sulu/blob/6766a36cc2f0c807c59202bf7540a08c4ef31192/src/Sulu/Component/DocumentManager/ProxyFactory.php#L142-L152 | train |
sulu/sulu | src/Sulu/Bundle/DocumentManagerBundle/DataFixtures/DocumentFixtureLoader.php | DocumentFixtureLoader.load | public function load(array $paths)
{
$finder = new Finder();
$finder->in($paths);
$finder->name('*Fixture.php');
foreach ($finder as $file) {
$declaredClasses = get_declared_classes();
require_once $file;
$declaredClassesDiff = array_diff(get_declared_classes(), $declaredClasses);
$fixtureClass = array_pop($declaredClassesDiff);
if (!$fixtureClass) {
throw new \InvalidArgumentException(sprintf(
'Could not determine class from included file "%s". Class detection will only work once per request.',
$file
));
}
$refl = new \ReflectionClass($fixtureClass);
if ($refl->isAbstract()) {
continue;
}
if (false === $refl->isSubclassOf(DocumentFixtureInterface::class)) {
continue;
}
$fixture = new $fixtureClass();
if ($fixture instanceof ContainerAwareInterface) {
$fixture->setContainer($this->container);
}
$fixtures[] = $fixture;
}
usort($fixtures, function(DocumentFixtureInterface $fixture1, DocumentFixtureInterface $fixture2) {
return $fixture1->getOrder() > $fixture2->getOrder();
});
return $fixtures;
} | php | public function load(array $paths)
{
$finder = new Finder();
$finder->in($paths);
$finder->name('*Fixture.php');
foreach ($finder as $file) {
$declaredClasses = get_declared_classes();
require_once $file;
$declaredClassesDiff = array_diff(get_declared_classes(), $declaredClasses);
$fixtureClass = array_pop($declaredClassesDiff);
if (!$fixtureClass) {
throw new \InvalidArgumentException(sprintf(
'Could not determine class from included file "%s". Class detection will only work once per request.',
$file
));
}
$refl = new \ReflectionClass($fixtureClass);
if ($refl->isAbstract()) {
continue;
}
if (false === $refl->isSubclassOf(DocumentFixtureInterface::class)) {
continue;
}
$fixture = new $fixtureClass();
if ($fixture instanceof ContainerAwareInterface) {
$fixture->setContainer($this->container);
}
$fixtures[] = $fixture;
}
usort($fixtures, function(DocumentFixtureInterface $fixture1, DocumentFixtureInterface $fixture2) {
return $fixture1->getOrder() > $fixture2->getOrder();
});
return $fixtures;
} | [
"public",
"function",
"load",
"(",
"array",
"$",
"paths",
")",
"{",
"$",
"finder",
"=",
"new",
"Finder",
"(",
")",
";",
"$",
"finder",
"->",
"in",
"(",
"$",
"paths",
")",
";",
"$",
"finder",
"->",
"name",
"(",
"'*Fixture.php'",
")",
";",
"foreach",
"(",
"$",
"finder",
"as",
"$",
"file",
")",
"{",
"$",
"declaredClasses",
"=",
"get_declared_classes",
"(",
")",
";",
"require_once",
"$",
"file",
";",
"$",
"declaredClassesDiff",
"=",
"array_diff",
"(",
"get_declared_classes",
"(",
")",
",",
"$",
"declaredClasses",
")",
";",
"$",
"fixtureClass",
"=",
"array_pop",
"(",
"$",
"declaredClassesDiff",
")",
";",
"if",
"(",
"!",
"$",
"fixtureClass",
")",
"{",
"throw",
"new",
"\\",
"InvalidArgumentException",
"(",
"sprintf",
"(",
"'Could not determine class from included file \"%s\". Class detection will only work once per request.'",
",",
"$",
"file",
")",
")",
";",
"}",
"$",
"refl",
"=",
"new",
"\\",
"ReflectionClass",
"(",
"$",
"fixtureClass",
")",
";",
"if",
"(",
"$",
"refl",
"->",
"isAbstract",
"(",
")",
")",
"{",
"continue",
";",
"}",
"if",
"(",
"false",
"===",
"$",
"refl",
"->",
"isSubclassOf",
"(",
"DocumentFixtureInterface",
"::",
"class",
")",
")",
"{",
"continue",
";",
"}",
"$",
"fixture",
"=",
"new",
"$",
"fixtureClass",
"(",
")",
";",
"if",
"(",
"$",
"fixture",
"instanceof",
"ContainerAwareInterface",
")",
"{",
"$",
"fixture",
"->",
"setContainer",
"(",
"$",
"this",
"->",
"container",
")",
";",
"}",
"$",
"fixtures",
"[",
"]",
"=",
"$",
"fixture",
";",
"}",
"usort",
"(",
"$",
"fixtures",
",",
"function",
"(",
"DocumentFixtureInterface",
"$",
"fixture1",
",",
"DocumentFixtureInterface",
"$",
"fixture2",
")",
"{",
"return",
"$",
"fixture1",
"->",
"getOrder",
"(",
")",
">",
"$",
"fixture2",
"->",
"getOrder",
"(",
")",
";",
"}",
")",
";",
"return",
"$",
"fixtures",
";",
"}"
] | Load, instantiate and sort all fixture files found
within the given paths.
@param array $paths
@return DocumentFixtureInterface[] | [
"Load",
"instantiate",
"and",
"sort",
"all",
"fixture",
"files",
"found",
"within",
"the",
"given",
"paths",
"."
] | 6766a36cc2f0c807c59202bf7540a08c4ef31192 | https://github.com/sulu/sulu/blob/6766a36cc2f0c807c59202bf7540a08c4ef31192/src/Sulu/Bundle/DocumentManagerBundle/DataFixtures/DocumentFixtureLoader.php#L44-L87 | train |
sulu/sulu | src/Sulu/Component/Content/Document/Subscriber/ShadowCopyPropertiesSubscriber.php | ShadowCopyPropertiesSubscriber.copyShadowProperties | public function copyShadowProperties(AbstractMappingEvent $event)
{
$document = $event->getDocument();
if (!$this->supports($document)) {
return;
}
if (!$event->getDocument()->isShadowLocaleEnabled()) {
$this->copyToShadows($event->getDocument(), $event->getNode());
} else {
$this->copyFromShadow($event->getDocument(), $event->getNode());
}
} | php | public function copyShadowProperties(AbstractMappingEvent $event)
{
$document = $event->getDocument();
if (!$this->supports($document)) {
return;
}
if (!$event->getDocument()->isShadowLocaleEnabled()) {
$this->copyToShadows($event->getDocument(), $event->getNode());
} else {
$this->copyFromShadow($event->getDocument(), $event->getNode());
}
} | [
"public",
"function",
"copyShadowProperties",
"(",
"AbstractMappingEvent",
"$",
"event",
")",
"{",
"$",
"document",
"=",
"$",
"event",
"->",
"getDocument",
"(",
")",
";",
"if",
"(",
"!",
"$",
"this",
"->",
"supports",
"(",
"$",
"document",
")",
")",
"{",
"return",
";",
"}",
"if",
"(",
"!",
"$",
"event",
"->",
"getDocument",
"(",
")",
"->",
"isShadowLocaleEnabled",
"(",
")",
")",
"{",
"$",
"this",
"->",
"copyToShadows",
"(",
"$",
"event",
"->",
"getDocument",
"(",
")",
",",
"$",
"event",
"->",
"getNode",
"(",
")",
")",
";",
"}",
"else",
"{",
"$",
"this",
"->",
"copyFromShadow",
"(",
"$",
"event",
"->",
"getDocument",
"(",
")",
",",
"$",
"event",
"->",
"getNode",
"(",
")",
")",
";",
"}",
"}"
] | Handles persist event of document manager.
@param AbstractMappingEvent $event | [
"Handles",
"persist",
"event",
"of",
"document",
"manager",
"."
] | 6766a36cc2f0c807c59202bf7540a08c4ef31192 | https://github.com/sulu/sulu/blob/6766a36cc2f0c807c59202bf7540a08c4ef31192/src/Sulu/Component/Content/Document/Subscriber/ShadowCopyPropertiesSubscriber.php#L64-L77 | train |
sulu/sulu | src/Sulu/Component/Content/Document/Subscriber/ShadowCopyPropertiesSubscriber.php | ShadowCopyPropertiesSubscriber.copyToShadows | public function copyToShadows($document, NodeInterface $node)
{
$tags = $this->getTags($node, $document->getLocale());
$categories = $this->getCategories($node, $document->getLocale());
$navigationContext = $this->getNavigationContext($node, $document->getLocale());
foreach ($node->getProperties(self::SHADOW_BASE_PROPERTY) as $property) {
if ($property->getValue() === $document->getLocale()) {
$locale = $this->getLocale($property->getName());
$node->setProperty(sprintf(self::TAGS_PROPERTY, $locale), $tags);
$node->setProperty(sprintf(self::CATEGORIES_PROPERTY, $locale), $categories);
$node->setProperty(sprintf(self::NAVIGATION_CONTEXT_PROPERTY, $locale), $navigationContext);
}
}
} | php | public function copyToShadows($document, NodeInterface $node)
{
$tags = $this->getTags($node, $document->getLocale());
$categories = $this->getCategories($node, $document->getLocale());
$navigationContext = $this->getNavigationContext($node, $document->getLocale());
foreach ($node->getProperties(self::SHADOW_BASE_PROPERTY) as $property) {
if ($property->getValue() === $document->getLocale()) {
$locale = $this->getLocale($property->getName());
$node->setProperty(sprintf(self::TAGS_PROPERTY, $locale), $tags);
$node->setProperty(sprintf(self::CATEGORIES_PROPERTY, $locale), $categories);
$node->setProperty(sprintf(self::NAVIGATION_CONTEXT_PROPERTY, $locale), $navigationContext);
}
}
} | [
"public",
"function",
"copyToShadows",
"(",
"$",
"document",
",",
"NodeInterface",
"$",
"node",
")",
"{",
"$",
"tags",
"=",
"$",
"this",
"->",
"getTags",
"(",
"$",
"node",
",",
"$",
"document",
"->",
"getLocale",
"(",
")",
")",
";",
"$",
"categories",
"=",
"$",
"this",
"->",
"getCategories",
"(",
"$",
"node",
",",
"$",
"document",
"->",
"getLocale",
"(",
")",
")",
";",
"$",
"navigationContext",
"=",
"$",
"this",
"->",
"getNavigationContext",
"(",
"$",
"node",
",",
"$",
"document",
"->",
"getLocale",
"(",
")",
")",
";",
"foreach",
"(",
"$",
"node",
"->",
"getProperties",
"(",
"self",
"::",
"SHADOW_BASE_PROPERTY",
")",
"as",
"$",
"property",
")",
"{",
"if",
"(",
"$",
"property",
"->",
"getValue",
"(",
")",
"===",
"$",
"document",
"->",
"getLocale",
"(",
")",
")",
"{",
"$",
"locale",
"=",
"$",
"this",
"->",
"getLocale",
"(",
"$",
"property",
"->",
"getName",
"(",
")",
")",
";",
"$",
"node",
"->",
"setProperty",
"(",
"sprintf",
"(",
"self",
"::",
"TAGS_PROPERTY",
",",
"$",
"locale",
")",
",",
"$",
"tags",
")",
";",
"$",
"node",
"->",
"setProperty",
"(",
"sprintf",
"(",
"self",
"::",
"CATEGORIES_PROPERTY",
",",
"$",
"locale",
")",
",",
"$",
"categories",
")",
";",
"$",
"node",
"->",
"setProperty",
"(",
"sprintf",
"(",
"self",
"::",
"NAVIGATION_CONTEXT_PROPERTY",
",",
"$",
"locale",
")",
",",
"$",
"navigationContext",
")",
";",
"}",
"}",
"}"
] | Copy tags and categories from current locale to all shadowed pages with this locale as base-locale.
@param object $document
@param NodeInterface $node | [
"Copy",
"tags",
"and",
"categories",
"from",
"current",
"locale",
"to",
"all",
"shadowed",
"pages",
"with",
"this",
"locale",
"as",
"base",
"-",
"locale",
"."
] | 6766a36cc2f0c807c59202bf7540a08c4ef31192 | https://github.com/sulu/sulu/blob/6766a36cc2f0c807c59202bf7540a08c4ef31192/src/Sulu/Component/Content/Document/Subscriber/ShadowCopyPropertiesSubscriber.php#L85-L100 | train |
sulu/sulu | src/Sulu/Component/Content/Document/Subscriber/ShadowCopyPropertiesSubscriber.php | ShadowCopyPropertiesSubscriber.copyFromShadow | public function copyFromShadow($document, NodeInterface $node)
{
$shadowLocale = $document->getShadowLocale();
$tags = $this->getTags($node, $shadowLocale);
$categories = $this->getCategories($node, $shadowLocale);
$navigationContext = $this->getNavigationContext($node, $shadowLocale);
$node->setProperty(sprintf(self::TAGS_PROPERTY, $document->getLocale()), $tags);
$node->setProperty(sprintf(self::CATEGORIES_PROPERTY, $document->getLocale()), $categories);
$node->setProperty(sprintf(self::NAVIGATION_CONTEXT_PROPERTY, $document->getLocale()), $navigationContext);
} | php | public function copyFromShadow($document, NodeInterface $node)
{
$shadowLocale = $document->getShadowLocale();
$tags = $this->getTags($node, $shadowLocale);
$categories = $this->getCategories($node, $shadowLocale);
$navigationContext = $this->getNavigationContext($node, $shadowLocale);
$node->setProperty(sprintf(self::TAGS_PROPERTY, $document->getLocale()), $tags);
$node->setProperty(sprintf(self::CATEGORIES_PROPERTY, $document->getLocale()), $categories);
$node->setProperty(sprintf(self::NAVIGATION_CONTEXT_PROPERTY, $document->getLocale()), $navigationContext);
} | [
"public",
"function",
"copyFromShadow",
"(",
"$",
"document",
",",
"NodeInterface",
"$",
"node",
")",
"{",
"$",
"shadowLocale",
"=",
"$",
"document",
"->",
"getShadowLocale",
"(",
")",
";",
"$",
"tags",
"=",
"$",
"this",
"->",
"getTags",
"(",
"$",
"node",
",",
"$",
"shadowLocale",
")",
";",
"$",
"categories",
"=",
"$",
"this",
"->",
"getCategories",
"(",
"$",
"node",
",",
"$",
"shadowLocale",
")",
";",
"$",
"navigationContext",
"=",
"$",
"this",
"->",
"getNavigationContext",
"(",
"$",
"node",
",",
"$",
"shadowLocale",
")",
";",
"$",
"node",
"->",
"setProperty",
"(",
"sprintf",
"(",
"self",
"::",
"TAGS_PROPERTY",
",",
"$",
"document",
"->",
"getLocale",
"(",
")",
")",
",",
"$",
"tags",
")",
";",
"$",
"node",
"->",
"setProperty",
"(",
"sprintf",
"(",
"self",
"::",
"CATEGORIES_PROPERTY",
",",
"$",
"document",
"->",
"getLocale",
"(",
")",
")",
",",
"$",
"categories",
")",
";",
"$",
"node",
"->",
"setProperty",
"(",
"sprintf",
"(",
"self",
"::",
"NAVIGATION_CONTEXT_PROPERTY",
",",
"$",
"document",
"->",
"getLocale",
"(",
")",
")",
",",
"$",
"navigationContext",
")",
";",
"}"
] | Copy tags and categories from base-locale to current locale.
@param object $document
@param NodeInterface $node | [
"Copy",
"tags",
"and",
"categories",
"from",
"base",
"-",
"locale",
"to",
"current",
"locale",
"."
] | 6766a36cc2f0c807c59202bf7540a08c4ef31192 | https://github.com/sulu/sulu/blob/6766a36cc2f0c807c59202bf7540a08c4ef31192/src/Sulu/Component/Content/Document/Subscriber/ShadowCopyPropertiesSubscriber.php#L108-L119 | train |
sulu/sulu | src/Sulu/Bundle/ContactBundle/Controller/AbstractMediaController.php | AbstractMediaController.addMediaToEntity | protected function addMediaToEntity($entityName, $id, $mediaId)
{
try {
$em = $this->getDoctrine()->getManager();
$entity = $em->getRepository($entityName)->find($id);
$media = $this->container->get('sulu.repository.media')->find($mediaId);
if (!$entity) {
throw new EntityNotFoundException($entityName, $id);
}
if (!$media) {
throw new EntityNotFoundException($this->getParameter('sulu.model.media.class'), $mediaId);
}
if ($entity->getMedias()->contains($media)) {
throw new RestException('Relation already exists');
}
$entity->addMedia($media);
$em->flush();
$view = $this->view(
new Media(
$media,
$this->getUser()->getLocale(),
null
),
200
);
} catch (EntityNotFoundException $enfe) {
$view = $this->view($enfe->toArray(), 404);
} catch (RestException $exc) {
$view = $this->view($exc->toArray(), 400);
} catch (\Exception $e) {
$view = $this->view($e->getMessage(), 400);
}
return $this->handleView($view);
} | php | protected function addMediaToEntity($entityName, $id, $mediaId)
{
try {
$em = $this->getDoctrine()->getManager();
$entity = $em->getRepository($entityName)->find($id);
$media = $this->container->get('sulu.repository.media')->find($mediaId);
if (!$entity) {
throw new EntityNotFoundException($entityName, $id);
}
if (!$media) {
throw new EntityNotFoundException($this->getParameter('sulu.model.media.class'), $mediaId);
}
if ($entity->getMedias()->contains($media)) {
throw new RestException('Relation already exists');
}
$entity->addMedia($media);
$em->flush();
$view = $this->view(
new Media(
$media,
$this->getUser()->getLocale(),
null
),
200
);
} catch (EntityNotFoundException $enfe) {
$view = $this->view($enfe->toArray(), 404);
} catch (RestException $exc) {
$view = $this->view($exc->toArray(), 400);
} catch (\Exception $e) {
$view = $this->view($e->getMessage(), 400);
}
return $this->handleView($view);
} | [
"protected",
"function",
"addMediaToEntity",
"(",
"$",
"entityName",
",",
"$",
"id",
",",
"$",
"mediaId",
")",
"{",
"try",
"{",
"$",
"em",
"=",
"$",
"this",
"->",
"getDoctrine",
"(",
")",
"->",
"getManager",
"(",
")",
";",
"$",
"entity",
"=",
"$",
"em",
"->",
"getRepository",
"(",
"$",
"entityName",
")",
"->",
"find",
"(",
"$",
"id",
")",
";",
"$",
"media",
"=",
"$",
"this",
"->",
"container",
"->",
"get",
"(",
"'sulu.repository.media'",
")",
"->",
"find",
"(",
"$",
"mediaId",
")",
";",
"if",
"(",
"!",
"$",
"entity",
")",
"{",
"throw",
"new",
"EntityNotFoundException",
"(",
"$",
"entityName",
",",
"$",
"id",
")",
";",
"}",
"if",
"(",
"!",
"$",
"media",
")",
"{",
"throw",
"new",
"EntityNotFoundException",
"(",
"$",
"this",
"->",
"getParameter",
"(",
"'sulu.model.media.class'",
")",
",",
"$",
"mediaId",
")",
";",
"}",
"if",
"(",
"$",
"entity",
"->",
"getMedias",
"(",
")",
"->",
"contains",
"(",
"$",
"media",
")",
")",
"{",
"throw",
"new",
"RestException",
"(",
"'Relation already exists'",
")",
";",
"}",
"$",
"entity",
"->",
"addMedia",
"(",
"$",
"media",
")",
";",
"$",
"em",
"->",
"flush",
"(",
")",
";",
"$",
"view",
"=",
"$",
"this",
"->",
"view",
"(",
"new",
"Media",
"(",
"$",
"media",
",",
"$",
"this",
"->",
"getUser",
"(",
")",
"->",
"getLocale",
"(",
")",
",",
"null",
")",
",",
"200",
")",
";",
"}",
"catch",
"(",
"EntityNotFoundException",
"$",
"enfe",
")",
"{",
"$",
"view",
"=",
"$",
"this",
"->",
"view",
"(",
"$",
"enfe",
"->",
"toArray",
"(",
")",
",",
"404",
")",
";",
"}",
"catch",
"(",
"RestException",
"$",
"exc",
")",
"{",
"$",
"view",
"=",
"$",
"this",
"->",
"view",
"(",
"$",
"exc",
"->",
"toArray",
"(",
")",
",",
"400",
")",
";",
"}",
"catch",
"(",
"\\",
"Exception",
"$",
"e",
")",
"{",
"$",
"view",
"=",
"$",
"this",
"->",
"view",
"(",
"$",
"e",
"->",
"getMessage",
"(",
")",
",",
"400",
")",
";",
"}",
"return",
"$",
"this",
"->",
"handleView",
"(",
"$",
"view",
")",
";",
"}"
] | Adds a relation between a media and the entity.
@param string $entityName
@param string $id
@param string $mediaId
@return Media | [
"Adds",
"a",
"relation",
"between",
"a",
"media",
"and",
"the",
"entity",
"."
] | 6766a36cc2f0c807c59202bf7540a08c4ef31192 | https://github.com/sulu/sulu/blob/6766a36cc2f0c807c59202bf7540a08c4ef31192/src/Sulu/Bundle/ContactBundle/Controller/AbstractMediaController.php#L56-L95 | train |
sulu/sulu | src/Sulu/Bundle/ContactBundle/Controller/AbstractMediaController.php | AbstractMediaController.removeMediaFromEntity | protected function removeMediaFromEntity($entityName, $id, $mediaId)
{
try {
$delete = function() use ($entityName, $id, $mediaId) {
$em = $this->getDoctrine()->getManager();
$entity = $em->getRepository($entityName)->find($id);
$media = $this->container->get('sulu.repository.media')->find($mediaId);
if (!$entity) {
throw new EntityNotFoundException($entityName, $id);
}
$mediaEntityName = $this->getParameter('sulu.model.media.class');
if (!$media) {
throw new EntityNotFoundException($mediaEntityName, $mediaId);
}
if (!$entity->getMedias()->contains($media)) {
throw new RestException(
'Relation between ' . $entityName .
' and ' . $mediaEntityName . ' with id ' . $mediaId . ' does not exists!'
);
}
$entity->removeMedia($media);
$em->flush();
};
$view = $this->responseDelete($id, $delete);
} catch (EntityNotFoundException $enfe) {
$view = $this->view($enfe->toArray(), 404);
} catch (RestException $exc) {
$view = $this->view($exc->toArray(), 400);
} catch (\Exception $e) {
$view = $this->view($e->getMessage(), 400);
}
return $this->handleView($view);
} | php | protected function removeMediaFromEntity($entityName, $id, $mediaId)
{
try {
$delete = function() use ($entityName, $id, $mediaId) {
$em = $this->getDoctrine()->getManager();
$entity = $em->getRepository($entityName)->find($id);
$media = $this->container->get('sulu.repository.media')->find($mediaId);
if (!$entity) {
throw new EntityNotFoundException($entityName, $id);
}
$mediaEntityName = $this->getParameter('sulu.model.media.class');
if (!$media) {
throw new EntityNotFoundException($mediaEntityName, $mediaId);
}
if (!$entity->getMedias()->contains($media)) {
throw new RestException(
'Relation between ' . $entityName .
' and ' . $mediaEntityName . ' with id ' . $mediaId . ' does not exists!'
);
}
$entity->removeMedia($media);
$em->flush();
};
$view = $this->responseDelete($id, $delete);
} catch (EntityNotFoundException $enfe) {
$view = $this->view($enfe->toArray(), 404);
} catch (RestException $exc) {
$view = $this->view($exc->toArray(), 400);
} catch (\Exception $e) {
$view = $this->view($e->getMessage(), 400);
}
return $this->handleView($view);
} | [
"protected",
"function",
"removeMediaFromEntity",
"(",
"$",
"entityName",
",",
"$",
"id",
",",
"$",
"mediaId",
")",
"{",
"try",
"{",
"$",
"delete",
"=",
"function",
"(",
")",
"use",
"(",
"$",
"entityName",
",",
"$",
"id",
",",
"$",
"mediaId",
")",
"{",
"$",
"em",
"=",
"$",
"this",
"->",
"getDoctrine",
"(",
")",
"->",
"getManager",
"(",
")",
";",
"$",
"entity",
"=",
"$",
"em",
"->",
"getRepository",
"(",
"$",
"entityName",
")",
"->",
"find",
"(",
"$",
"id",
")",
";",
"$",
"media",
"=",
"$",
"this",
"->",
"container",
"->",
"get",
"(",
"'sulu.repository.media'",
")",
"->",
"find",
"(",
"$",
"mediaId",
")",
";",
"if",
"(",
"!",
"$",
"entity",
")",
"{",
"throw",
"new",
"EntityNotFoundException",
"(",
"$",
"entityName",
",",
"$",
"id",
")",
";",
"}",
"$",
"mediaEntityName",
"=",
"$",
"this",
"->",
"getParameter",
"(",
"'sulu.model.media.class'",
")",
";",
"if",
"(",
"!",
"$",
"media",
")",
"{",
"throw",
"new",
"EntityNotFoundException",
"(",
"$",
"mediaEntityName",
",",
"$",
"mediaId",
")",
";",
"}",
"if",
"(",
"!",
"$",
"entity",
"->",
"getMedias",
"(",
")",
"->",
"contains",
"(",
"$",
"media",
")",
")",
"{",
"throw",
"new",
"RestException",
"(",
"'Relation between '",
".",
"$",
"entityName",
".",
"' and '",
".",
"$",
"mediaEntityName",
".",
"' with id '",
".",
"$",
"mediaId",
".",
"' does not exists!'",
")",
";",
"}",
"$",
"entity",
"->",
"removeMedia",
"(",
"$",
"media",
")",
";",
"$",
"em",
"->",
"flush",
"(",
")",
";",
"}",
";",
"$",
"view",
"=",
"$",
"this",
"->",
"responseDelete",
"(",
"$",
"id",
",",
"$",
"delete",
")",
";",
"}",
"catch",
"(",
"EntityNotFoundException",
"$",
"enfe",
")",
"{",
"$",
"view",
"=",
"$",
"this",
"->",
"view",
"(",
"$",
"enfe",
"->",
"toArray",
"(",
")",
",",
"404",
")",
";",
"}",
"catch",
"(",
"RestException",
"$",
"exc",
")",
"{",
"$",
"view",
"=",
"$",
"this",
"->",
"view",
"(",
"$",
"exc",
"->",
"toArray",
"(",
")",
",",
"400",
")",
";",
"}",
"catch",
"(",
"\\",
"Exception",
"$",
"e",
")",
"{",
"$",
"view",
"=",
"$",
"this",
"->",
"view",
"(",
"$",
"e",
"->",
"getMessage",
"(",
")",
",",
"400",
")",
";",
"}",
"return",
"$",
"this",
"->",
"handleView",
"(",
"$",
"view",
")",
";",
"}"
] | Removes a media from the relation with an entity.
@param string $entityName
@param string $id
@param string $mediaId
@return Response | [
"Removes",
"a",
"media",
"from",
"the",
"relation",
"with",
"an",
"entity",
"."
] | 6766a36cc2f0c807c59202bf7540a08c4ef31192 | https://github.com/sulu/sulu/blob/6766a36cc2f0c807c59202bf7540a08c4ef31192/src/Sulu/Bundle/ContactBundle/Controller/AbstractMediaController.php#L106-L145 | train |
sulu/sulu | src/Sulu/Bundle/ContactBundle/Controller/AbstractMediaController.php | AbstractMediaController.getMultipleView | protected function getMultipleView($entityName, $routeName, AbstractContactManager $contactManager, $id, $request)
{
try {
$locale = $this->getUser()->getLocale();
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($entityName);
$fieldDescriptors = $this->getFieldDescriptors($entityName, $id);
$listBuilder->setIdField($fieldDescriptors['id']);
$restHelper->initializeListBuilder($listBuilder, $fieldDescriptors);
$listResponse = $listBuilder->execute();
$listResponse = $this->addThumbnails($listResponse, $locale);
$listResponse = $this->addUrls($listResponse, $locale);
$list = new ListRepresentation(
$listResponse,
self::$mediaEntityKey,
$routeName,
array_merge(['id' => $id], $request->query->all()),
$listBuilder->getCurrentPage(),
$listBuilder->getLimit(),
$listBuilder->count()
);
} else {
$media = $contactManager->getById($id, $locale)->getMedias();
$list = new CollectionRepresentation($media, self::$mediaEntityKey);
}
$view = $this->view($list, 200);
} catch (EntityNotFoundException $e) {
$view = $this->view($e->toArray(), 404);
}
return $this->handleView($view);
} | php | protected function getMultipleView($entityName, $routeName, AbstractContactManager $contactManager, $id, $request)
{
try {
$locale = $this->getUser()->getLocale();
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($entityName);
$fieldDescriptors = $this->getFieldDescriptors($entityName, $id);
$listBuilder->setIdField($fieldDescriptors['id']);
$restHelper->initializeListBuilder($listBuilder, $fieldDescriptors);
$listResponse = $listBuilder->execute();
$listResponse = $this->addThumbnails($listResponse, $locale);
$listResponse = $this->addUrls($listResponse, $locale);
$list = new ListRepresentation(
$listResponse,
self::$mediaEntityKey,
$routeName,
array_merge(['id' => $id], $request->query->all()),
$listBuilder->getCurrentPage(),
$listBuilder->getLimit(),
$listBuilder->count()
);
} else {
$media = $contactManager->getById($id, $locale)->getMedias();
$list = new CollectionRepresentation($media, self::$mediaEntityKey);
}
$view = $this->view($list, 200);
} catch (EntityNotFoundException $e) {
$view = $this->view($e->toArray(), 404);
}
return $this->handleView($view);
} | [
"protected",
"function",
"getMultipleView",
"(",
"$",
"entityName",
",",
"$",
"routeName",
",",
"AbstractContactManager",
"$",
"contactManager",
",",
"$",
"id",
",",
"$",
"request",
")",
"{",
"try",
"{",
"$",
"locale",
"=",
"$",
"this",
"->",
"getUser",
"(",
")",
"->",
"getLocale",
"(",
")",
";",
"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",
"(",
"$",
"entityName",
")",
";",
"$",
"fieldDescriptors",
"=",
"$",
"this",
"->",
"getFieldDescriptors",
"(",
"$",
"entityName",
",",
"$",
"id",
")",
";",
"$",
"listBuilder",
"->",
"setIdField",
"(",
"$",
"fieldDescriptors",
"[",
"'id'",
"]",
")",
";",
"$",
"restHelper",
"->",
"initializeListBuilder",
"(",
"$",
"listBuilder",
",",
"$",
"fieldDescriptors",
")",
";",
"$",
"listResponse",
"=",
"$",
"listBuilder",
"->",
"execute",
"(",
")",
";",
"$",
"listResponse",
"=",
"$",
"this",
"->",
"addThumbnails",
"(",
"$",
"listResponse",
",",
"$",
"locale",
")",
";",
"$",
"listResponse",
"=",
"$",
"this",
"->",
"addUrls",
"(",
"$",
"listResponse",
",",
"$",
"locale",
")",
";",
"$",
"list",
"=",
"new",
"ListRepresentation",
"(",
"$",
"listResponse",
",",
"self",
"::",
"$",
"mediaEntityKey",
",",
"$",
"routeName",
",",
"array_merge",
"(",
"[",
"'id'",
"=>",
"$",
"id",
"]",
",",
"$",
"request",
"->",
"query",
"->",
"all",
"(",
")",
")",
",",
"$",
"listBuilder",
"->",
"getCurrentPage",
"(",
")",
",",
"$",
"listBuilder",
"->",
"getLimit",
"(",
")",
",",
"$",
"listBuilder",
"->",
"count",
"(",
")",
")",
";",
"}",
"else",
"{",
"$",
"media",
"=",
"$",
"contactManager",
"->",
"getById",
"(",
"$",
"id",
",",
"$",
"locale",
")",
"->",
"getMedias",
"(",
")",
";",
"$",
"list",
"=",
"new",
"CollectionRepresentation",
"(",
"$",
"media",
",",
"self",
"::",
"$",
"mediaEntityKey",
")",
";",
"}",
"$",
"view",
"=",
"$",
"this",
"->",
"view",
"(",
"$",
"list",
",",
"200",
")",
";",
"}",
"catch",
"(",
"EntityNotFoundException",
"$",
"e",
")",
"{",
"$",
"view",
"=",
"$",
"this",
"->",
"view",
"(",
"$",
"e",
"->",
"toArray",
"(",
")",
",",
"404",
")",
";",
"}",
"return",
"$",
"this",
"->",
"handleView",
"(",
"$",
"view",
")",
";",
"}"
] | Returns a view containing all media of an entity.
@param string $entityName
@param string $routeName
@param AbstractContactManager $contactManager
@param string $id
@param Request $request
@return Response | [
"Returns",
"a",
"view",
"containing",
"all",
"media",
"of",
"an",
"entity",
"."
] | 6766a36cc2f0c807c59202bf7540a08c4ef31192 | https://github.com/sulu/sulu/blob/6766a36cc2f0c807c59202bf7540a08c4ef31192/src/Sulu/Bundle/ContactBundle/Controller/AbstractMediaController.php#L158-L198 | train |
sulu/sulu | src/Sulu/Bundle/ContactBundle/Controller/AbstractMediaController.php | AbstractMediaController.getFieldsView | protected function getFieldsView($entityName)
{
return $this->handleView($this->view(array_values($this->getFieldDescriptors($entityName, null)), 200));
} | php | protected function getFieldsView($entityName)
{
return $this->handleView($this->view(array_values($this->getFieldDescriptors($entityName, null)), 200));
} | [
"protected",
"function",
"getFieldsView",
"(",
"$",
"entityName",
")",
"{",
"return",
"$",
"this",
"->",
"handleView",
"(",
"$",
"this",
"->",
"view",
"(",
"array_values",
"(",
"$",
"this",
"->",
"getFieldDescriptors",
"(",
"$",
"entityName",
",",
"null",
")",
")",
",",
"200",
")",
")",
";",
"}"
] | Returns the the media fields for the current entity.
@param $entityName
@return Response | [
"Returns",
"the",
"the",
"media",
"fields",
"for",
"the",
"current",
"entity",
"."
] | 6766a36cc2f0c807c59202bf7540a08c4ef31192 | https://github.com/sulu/sulu/blob/6766a36cc2f0c807c59202bf7540a08c4ef31192/src/Sulu/Bundle/ContactBundle/Controller/AbstractMediaController.php#L207-L210 | train |
sulu/sulu | src/Sulu/Bundle/ContactBundle/Controller/AbstractMediaController.php | AbstractMediaController.getFieldDescriptors | private function getFieldDescriptors($entityName, $id)
{
if (null === $this->fieldDescriptors) {
$this->initFieldDescriptors($entityName, $id);
}
return $this->fieldDescriptors;
} | php | private function getFieldDescriptors($entityName, $id)
{
if (null === $this->fieldDescriptors) {
$this->initFieldDescriptors($entityName, $id);
}
return $this->fieldDescriptors;
} | [
"private",
"function",
"getFieldDescriptors",
"(",
"$",
"entityName",
",",
"$",
"id",
")",
"{",
"if",
"(",
"null",
"===",
"$",
"this",
"->",
"fieldDescriptors",
")",
"{",
"$",
"this",
"->",
"initFieldDescriptors",
"(",
"$",
"entityName",
",",
"$",
"id",
")",
";",
"}",
"return",
"$",
"this",
"->",
"fieldDescriptors",
";",
"}"
] | Returns the field-descriptors. Ensures that the descriptors get only instantiated once.
@param $entityName
@return DoctrineFieldDescriptor[] | [
"Returns",
"the",
"field",
"-",
"descriptors",
".",
"Ensures",
"that",
"the",
"descriptors",
"get",
"only",
"instantiated",
"once",
"."
] | 6766a36cc2f0c807c59202bf7540a08c4ef31192 | https://github.com/sulu/sulu/blob/6766a36cc2f0c807c59202bf7540a08c4ef31192/src/Sulu/Bundle/ContactBundle/Controller/AbstractMediaController.php#L219-L226 | train |
sulu/sulu | src/Sulu/Bundle/ContactBundle/Controller/AbstractMediaController.php | AbstractMediaController.addThumbnails | private function addThumbnails($entities, $locale)
{
$ids = array_filter(array_column($entities, 'thumbnails'));
$thumbnails = $this->getMediaManager()->getFormatUrls($ids, $locale);
foreach ($entities as $key => $entity) {
if (array_key_exists('thumbnails', $entity)
&& $entity['thumbnails']
&& array_key_exists($entity['thumbnails'], $thumbnails)
) {
$entities[$key]['thumbnails'] = $thumbnails[$entity['thumbnails']];
}
}
return $entities;
} | php | private function addThumbnails($entities, $locale)
{
$ids = array_filter(array_column($entities, 'thumbnails'));
$thumbnails = $this->getMediaManager()->getFormatUrls($ids, $locale);
foreach ($entities as $key => $entity) {
if (array_key_exists('thumbnails', $entity)
&& $entity['thumbnails']
&& array_key_exists($entity['thumbnails'], $thumbnails)
) {
$entities[$key]['thumbnails'] = $thumbnails[$entity['thumbnails']];
}
}
return $entities;
} | [
"private",
"function",
"addThumbnails",
"(",
"$",
"entities",
",",
"$",
"locale",
")",
"{",
"$",
"ids",
"=",
"array_filter",
"(",
"array_column",
"(",
"$",
"entities",
",",
"'thumbnails'",
")",
")",
";",
"$",
"thumbnails",
"=",
"$",
"this",
"->",
"getMediaManager",
"(",
")",
"->",
"getFormatUrls",
"(",
"$",
"ids",
",",
"$",
"locale",
")",
";",
"foreach",
"(",
"$",
"entities",
"as",
"$",
"key",
"=>",
"$",
"entity",
")",
"{",
"if",
"(",
"array_key_exists",
"(",
"'thumbnails'",
",",
"$",
"entity",
")",
"&&",
"$",
"entity",
"[",
"'thumbnails'",
"]",
"&&",
"array_key_exists",
"(",
"$",
"entity",
"[",
"'thumbnails'",
"]",
",",
"$",
"thumbnails",
")",
")",
"{",
"$",
"entities",
"[",
"$",
"key",
"]",
"[",
"'thumbnails'",
"]",
"=",
"$",
"thumbnails",
"[",
"$",
"entity",
"[",
"'thumbnails'",
"]",
"]",
";",
"}",
"}",
"return",
"$",
"entities",
";",
"}"
] | Takes an array of entities and resets the thumbnails-property containing the media id with
the actual urls to the thumbnails.
@param array $entities
@param string $locale
@return array | [
"Takes",
"an",
"array",
"of",
"entities",
"and",
"resets",
"the",
"thumbnails",
"-",
"property",
"containing",
"the",
"media",
"id",
"with",
"the",
"actual",
"urls",
"to",
"the",
"thumbnails",
"."
] | 6766a36cc2f0c807c59202bf7540a08c4ef31192 | https://github.com/sulu/sulu/blob/6766a36cc2f0c807c59202bf7540a08c4ef31192/src/Sulu/Bundle/ContactBundle/Controller/AbstractMediaController.php#L427-L441 | train |
sulu/sulu | src/Sulu/Bundle/ContactBundle/Controller/AbstractMediaController.php | AbstractMediaController.addUrls | private function addUrls($entities, $locale)
{
$ids = array_filter(array_column($entities, 'id'));
$apiEntities = $this->getMediaManager()->getByIds($ids, $locale);
$i = 0;
foreach ($entities as $key => $entity) {
$entities[$key]['url'] = $apiEntities[$i]->getUrl();
++$i;
}
return $entities;
} | php | private function addUrls($entities, $locale)
{
$ids = array_filter(array_column($entities, 'id'));
$apiEntities = $this->getMediaManager()->getByIds($ids, $locale);
$i = 0;
foreach ($entities as $key => $entity) {
$entities[$key]['url'] = $apiEntities[$i]->getUrl();
++$i;
}
return $entities;
} | [
"private",
"function",
"addUrls",
"(",
"$",
"entities",
",",
"$",
"locale",
")",
"{",
"$",
"ids",
"=",
"array_filter",
"(",
"array_column",
"(",
"$",
"entities",
",",
"'id'",
")",
")",
";",
"$",
"apiEntities",
"=",
"$",
"this",
"->",
"getMediaManager",
"(",
")",
"->",
"getByIds",
"(",
"$",
"ids",
",",
"$",
"locale",
")",
";",
"$",
"i",
"=",
"0",
";",
"foreach",
"(",
"$",
"entities",
"as",
"$",
"key",
"=>",
"$",
"entity",
")",
"{",
"$",
"entities",
"[",
"$",
"key",
"]",
"[",
"'url'",
"]",
"=",
"$",
"apiEntities",
"[",
"$",
"i",
"]",
"->",
"getUrl",
"(",
")",
";",
"++",
"$",
"i",
";",
"}",
"return",
"$",
"entities",
";",
"}"
] | Takes an array of entities and resets the url-property with the actual urls to the original file.
@param array $entities
@param string $locale
@return array | [
"Takes",
"an",
"array",
"of",
"entities",
"and",
"resets",
"the",
"url",
"-",
"property",
"with",
"the",
"actual",
"urls",
"to",
"the",
"original",
"file",
"."
] | 6766a36cc2f0c807c59202bf7540a08c4ef31192 | https://github.com/sulu/sulu/blob/6766a36cc2f0c807c59202bf7540a08c4ef31192/src/Sulu/Bundle/ContactBundle/Controller/AbstractMediaController.php#L451-L462 | train |
sulu/sulu | src/Sulu/Bundle/MediaBundle/Search/EventListener/PermissionListener.php | PermissionListener.onPermissionUpdate | public function onPermissionUpdate(PermissionUpdateEvent $event)
{
if (Collection::class !== $event->getType()) {
return;
}
foreach ($this->fileVersionMetaRepository->findByCollectionId($event->getIdentifier()) as $fileVersionMeta) {
$this->searchManager->deindex($fileVersionMeta);
}
} | php | public function onPermissionUpdate(PermissionUpdateEvent $event)
{
if (Collection::class !== $event->getType()) {
return;
}
foreach ($this->fileVersionMetaRepository->findByCollectionId($event->getIdentifier()) as $fileVersionMeta) {
$this->searchManager->deindex($fileVersionMeta);
}
} | [
"public",
"function",
"onPermissionUpdate",
"(",
"PermissionUpdateEvent",
"$",
"event",
")",
"{",
"if",
"(",
"Collection",
"::",
"class",
"!==",
"$",
"event",
"->",
"getType",
"(",
")",
")",
"{",
"return",
";",
"}",
"foreach",
"(",
"$",
"this",
"->",
"fileVersionMetaRepository",
"->",
"findByCollectionId",
"(",
"$",
"event",
"->",
"getIdentifier",
"(",
")",
")",
"as",
"$",
"fileVersionMeta",
")",
"{",
"$",
"this",
"->",
"searchManager",
"->",
"deindex",
"(",
"$",
"fileVersionMeta",
")",
";",
"}",
"}"
] | Removes all FileVersionMetas belonging to the collection, which just got secured.
@param PermissionUpdateEvent $event | [
"Removes",
"all",
"FileVersionMetas",
"belonging",
"to",
"the",
"collection",
"which",
"just",
"got",
"secured",
"."
] | 6766a36cc2f0c807c59202bf7540a08c4ef31192 | https://github.com/sulu/sulu/blob/6766a36cc2f0c807c59202bf7540a08c4ef31192/src/Sulu/Bundle/MediaBundle/Search/EventListener/PermissionListener.php#L47-L56 | train |
sulu/sulu | src/Sulu/Bundle/SnippetBundle/Snippet/DefaultSnippetManager.php | DefaultSnippetManager.checkTemplate | private function checkTemplate($document, $type)
{
$area = $this->areas->get($type);
return $document->getStructureType() === $area['template'];
} | php | private function checkTemplate($document, $type)
{
$area = $this->areas->get($type);
return $document->getStructureType() === $area['template'];
} | [
"private",
"function",
"checkTemplate",
"(",
"$",
"document",
",",
"$",
"type",
")",
"{",
"$",
"area",
"=",
"$",
"this",
"->",
"areas",
"->",
"get",
"(",
"$",
"type",
")",
";",
"return",
"$",
"document",
"->",
"getStructureType",
"(",
")",
"===",
"$",
"area",
"[",
"'template'",
"]",
";",
"}"
] | Check template.
@param SnippetDocument $document
@param string $type
@return bool | [
"Check",
"template",
"."
] | 6766a36cc2f0c807c59202bf7540a08c4ef31192 | https://github.com/sulu/sulu/blob/6766a36cc2f0c807c59202bf7540a08c4ef31192/src/Sulu/Bundle/SnippetBundle/Snippet/DefaultSnippetManager.php#L174-L179 | train |
sulu/sulu | src/Sulu/Component/Content/Document/Subscriber/StructureSubscriber.php | StructureSubscriber.handlePersistStructureType | public function handlePersistStructureType(PersistEvent $event)
{
$document = $event->getDocument();
if (!$this->supportsBehavior($document)) {
return;
}
$structureMetadata = $this->inspector->getStructureMetadata($document);
$structure = $document->getStructure();
if ($structure instanceof ManagedStructure) {
$structure->setStructureMetadata($structureMetadata);
}
} | php | public function handlePersistStructureType(PersistEvent $event)
{
$document = $event->getDocument();
if (!$this->supportsBehavior($document)) {
return;
}
$structureMetadata = $this->inspector->getStructureMetadata($document);
$structure = $document->getStructure();
if ($structure instanceof ManagedStructure) {
$structure->setStructureMetadata($structureMetadata);
}
} | [
"public",
"function",
"handlePersistStructureType",
"(",
"PersistEvent",
"$",
"event",
")",
"{",
"$",
"document",
"=",
"$",
"event",
"->",
"getDocument",
"(",
")",
";",
"if",
"(",
"!",
"$",
"this",
"->",
"supportsBehavior",
"(",
"$",
"document",
")",
")",
"{",
"return",
";",
"}",
"$",
"structureMetadata",
"=",
"$",
"this",
"->",
"inspector",
"->",
"getStructureMetadata",
"(",
"$",
"document",
")",
";",
"$",
"structure",
"=",
"$",
"document",
"->",
"getStructure",
"(",
")",
";",
"if",
"(",
"$",
"structure",
"instanceof",
"ManagedStructure",
")",
"{",
"$",
"structure",
"->",
"setStructureMetadata",
"(",
"$",
"structureMetadata",
")",
";",
"}",
"}"
] | Set the structure type early so that subsequent subscribers operate
upon the correct structure type.
@param PersistEvent $event | [
"Set",
"the",
"structure",
"type",
"early",
"so",
"that",
"subsequent",
"subscribers",
"operate",
"upon",
"the",
"correct",
"structure",
"type",
"."
] | 6766a36cc2f0c807c59202bf7540a08c4ef31192 | https://github.com/sulu/sulu/blob/6766a36cc2f0c807c59202bf7540a08c4ef31192/src/Sulu/Component/Content/Document/Subscriber/StructureSubscriber.php#L138-L152 | train |
sulu/sulu | src/Sulu/Component/Content/Document/Subscriber/StructureSubscriber.php | StructureSubscriber.handlePersistStagedProperties | public function handlePersistStagedProperties(PersistEvent $event)
{
$document = $event->getDocument();
if (!$this->supportsBehavior($document)) {
return;
}
$document->getStructure()->commitStagedData($event->getOption('clear_missing_content'));
} | php | public function handlePersistStagedProperties(PersistEvent $event)
{
$document = $event->getDocument();
if (!$this->supportsBehavior($document)) {
return;
}
$document->getStructure()->commitStagedData($event->getOption('clear_missing_content'));
} | [
"public",
"function",
"handlePersistStagedProperties",
"(",
"PersistEvent",
"$",
"event",
")",
"{",
"$",
"document",
"=",
"$",
"event",
"->",
"getDocument",
"(",
")",
";",
"if",
"(",
"!",
"$",
"this",
"->",
"supportsBehavior",
"(",
"$",
"document",
")",
")",
"{",
"return",
";",
"}",
"$",
"document",
"->",
"getStructure",
"(",
")",
"->",
"commitStagedData",
"(",
"$",
"event",
"->",
"getOption",
"(",
"'clear_missing_content'",
")",
")",
";",
"}"
] | Commit the properties, which are only staged on the structure yet.
@param PersistEvent $event | [
"Commit",
"the",
"properties",
"which",
"are",
"only",
"staged",
"on",
"the",
"structure",
"yet",
"."
] | 6766a36cc2f0c807c59202bf7540a08c4ef31192 | https://github.com/sulu/sulu/blob/6766a36cc2f0c807c59202bf7540a08c4ef31192/src/Sulu/Component/Content/Document/Subscriber/StructureSubscriber.php#L159-L168 | train |
sulu/sulu | src/Sulu/Component/Content/Document/Subscriber/StructureSubscriber.php | StructureSubscriber.getDefaultStructureType | private function getDefaultStructureType(StructureBehavior $document)
{
$alias = $this->inspector->getMetadata($document)->getAlias();
$webspace = $this->webspaceManager->findWebspaceByKey($this->inspector->getWebspace($document));
if (!$webspace) {
return $this->getDefaultStructureTypeFromConfig($alias);
}
return $webspace->getDefaultTemplate($alias);
} | php | private function getDefaultStructureType(StructureBehavior $document)
{
$alias = $this->inspector->getMetadata($document)->getAlias();
$webspace = $this->webspaceManager->findWebspaceByKey($this->inspector->getWebspace($document));
if (!$webspace) {
return $this->getDefaultStructureTypeFromConfig($alias);
}
return $webspace->getDefaultTemplate($alias);
} | [
"private",
"function",
"getDefaultStructureType",
"(",
"StructureBehavior",
"$",
"document",
")",
"{",
"$",
"alias",
"=",
"$",
"this",
"->",
"inspector",
"->",
"getMetadata",
"(",
"$",
"document",
")",
"->",
"getAlias",
"(",
")",
";",
"$",
"webspace",
"=",
"$",
"this",
"->",
"webspaceManager",
"->",
"findWebspaceByKey",
"(",
"$",
"this",
"->",
"inspector",
"->",
"getWebspace",
"(",
"$",
"document",
")",
")",
";",
"if",
"(",
"!",
"$",
"webspace",
")",
"{",
"return",
"$",
"this",
"->",
"getDefaultStructureTypeFromConfig",
"(",
"$",
"alias",
")",
";",
"}",
"return",
"$",
"webspace",
"->",
"getDefaultTemplate",
"(",
"$",
"alias",
")",
";",
"}"
] | Return the default structure for the given StructureBehavior implementing document.
@param StructureBehavior $document
@return string | [
"Return",
"the",
"default",
"structure",
"for",
"the",
"given",
"StructureBehavior",
"implementing",
"document",
"."
] | 6766a36cc2f0c807c59202bf7540a08c4ef31192 | https://github.com/sulu/sulu/blob/6766a36cc2f0c807c59202bf7540a08c4ef31192/src/Sulu/Component/Content/Document/Subscriber/StructureSubscriber.php#L265-L275 | train |
sulu/sulu | src/Sulu/Component/Content/Document/Subscriber/StructureSubscriber.php | StructureSubscriber.mapContentToNode | private function mapContentToNode($document, NodeInterface $node, $locale, $ignoreRequired)
{
$structure = $document->getStructure();
$webspaceName = $this->inspector->getWebspace($document);
$metadata = $this->inspector->getStructureMetadata($document);
if (!$metadata) {
throw new \RuntimeException(
sprintf(
'Metadata for Structure Type "%s" was not found, does the file "%s.xml" exists?',
$document->getStructureType(),
$document->getStructureType()
)
);
}
foreach ($metadata->getProperties() as $propertyName => $structureProperty) {
if (TitleSubscriber::PROPERTY_NAME === $propertyName) {
continue;
}
$realProperty = $structure->getProperty($propertyName);
$value = $realProperty->getValue();
if (false === $ignoreRequired && $structureProperty->isRequired() && null === $value) {
throw new MandatoryPropertyException(
sprintf(
'Property "%s" in structure "%s" is required but no value was given. Loaded from "%s"',
$propertyName,
$metadata->getName(),
$metadata->getResource()
)
);
}
$contentTypeName = $structureProperty->getType();
$contentType = $this->contentTypeManager->get($contentTypeName);
// TODO: Only write if the property has been modified.
$legacyProperty = $this->legacyPropertyFactory->createTranslatedProperty($structureProperty, $locale);
$legacyProperty->setValue($value);
$contentType->write(
new SuluNode($node),
$legacyProperty,
null,
$webspaceName,
$locale,
null
);
}
} | php | private function mapContentToNode($document, NodeInterface $node, $locale, $ignoreRequired)
{
$structure = $document->getStructure();
$webspaceName = $this->inspector->getWebspace($document);
$metadata = $this->inspector->getStructureMetadata($document);
if (!$metadata) {
throw new \RuntimeException(
sprintf(
'Metadata for Structure Type "%s" was not found, does the file "%s.xml" exists?',
$document->getStructureType(),
$document->getStructureType()
)
);
}
foreach ($metadata->getProperties() as $propertyName => $structureProperty) {
if (TitleSubscriber::PROPERTY_NAME === $propertyName) {
continue;
}
$realProperty = $structure->getProperty($propertyName);
$value = $realProperty->getValue();
if (false === $ignoreRequired && $structureProperty->isRequired() && null === $value) {
throw new MandatoryPropertyException(
sprintf(
'Property "%s" in structure "%s" is required but no value was given. Loaded from "%s"',
$propertyName,
$metadata->getName(),
$metadata->getResource()
)
);
}
$contentTypeName = $structureProperty->getType();
$contentType = $this->contentTypeManager->get($contentTypeName);
// TODO: Only write if the property has been modified.
$legacyProperty = $this->legacyPropertyFactory->createTranslatedProperty($structureProperty, $locale);
$legacyProperty->setValue($value);
$contentType->write(
new SuluNode($node),
$legacyProperty,
null,
$webspaceName,
$locale,
null
);
}
} | [
"private",
"function",
"mapContentToNode",
"(",
"$",
"document",
",",
"NodeInterface",
"$",
"node",
",",
"$",
"locale",
",",
"$",
"ignoreRequired",
")",
"{",
"$",
"structure",
"=",
"$",
"document",
"->",
"getStructure",
"(",
")",
";",
"$",
"webspaceName",
"=",
"$",
"this",
"->",
"inspector",
"->",
"getWebspace",
"(",
"$",
"document",
")",
";",
"$",
"metadata",
"=",
"$",
"this",
"->",
"inspector",
"->",
"getStructureMetadata",
"(",
"$",
"document",
")",
";",
"if",
"(",
"!",
"$",
"metadata",
")",
"{",
"throw",
"new",
"\\",
"RuntimeException",
"(",
"sprintf",
"(",
"'Metadata for Structure Type \"%s\" was not found, does the file \"%s.xml\" exists?'",
",",
"$",
"document",
"->",
"getStructureType",
"(",
")",
",",
"$",
"document",
"->",
"getStructureType",
"(",
")",
")",
")",
";",
"}",
"foreach",
"(",
"$",
"metadata",
"->",
"getProperties",
"(",
")",
"as",
"$",
"propertyName",
"=>",
"$",
"structureProperty",
")",
"{",
"if",
"(",
"TitleSubscriber",
"::",
"PROPERTY_NAME",
"===",
"$",
"propertyName",
")",
"{",
"continue",
";",
"}",
"$",
"realProperty",
"=",
"$",
"structure",
"->",
"getProperty",
"(",
"$",
"propertyName",
")",
";",
"$",
"value",
"=",
"$",
"realProperty",
"->",
"getValue",
"(",
")",
";",
"if",
"(",
"false",
"===",
"$",
"ignoreRequired",
"&&",
"$",
"structureProperty",
"->",
"isRequired",
"(",
")",
"&&",
"null",
"===",
"$",
"value",
")",
"{",
"throw",
"new",
"MandatoryPropertyException",
"(",
"sprintf",
"(",
"'Property \"%s\" in structure \"%s\" is required but no value was given. Loaded from \"%s\"'",
",",
"$",
"propertyName",
",",
"$",
"metadata",
"->",
"getName",
"(",
")",
",",
"$",
"metadata",
"->",
"getResource",
"(",
")",
")",
")",
";",
"}",
"$",
"contentTypeName",
"=",
"$",
"structureProperty",
"->",
"getType",
"(",
")",
";",
"$",
"contentType",
"=",
"$",
"this",
"->",
"contentTypeManager",
"->",
"get",
"(",
"$",
"contentTypeName",
")",
";",
"// TODO: Only write if the property has been modified.",
"$",
"legacyProperty",
"=",
"$",
"this",
"->",
"legacyPropertyFactory",
"->",
"createTranslatedProperty",
"(",
"$",
"structureProperty",
",",
"$",
"locale",
")",
";",
"$",
"legacyProperty",
"->",
"setValue",
"(",
"$",
"value",
")",
";",
"$",
"contentType",
"->",
"write",
"(",
"new",
"SuluNode",
"(",
"$",
"node",
")",
",",
"$",
"legacyProperty",
",",
"null",
",",
"$",
"webspaceName",
",",
"$",
"locale",
",",
"null",
")",
";",
"}",
"}"
] | Map to the content properties to the node using the content types.
@param mixed $document
@param NodeInterface $node
@param string $locale
@param bool $ignoreRequired
@throws MandatoryPropertyException
@throws \RuntimeException | [
"Map",
"to",
"the",
"content",
"properties",
"to",
"the",
"node",
"using",
"the",
"content",
"types",
"."
] | 6766a36cc2f0c807c59202bf7540a08c4ef31192 | https://github.com/sulu/sulu/blob/6766a36cc2f0c807c59202bf7540a08c4ef31192/src/Sulu/Component/Content/Document/Subscriber/StructureSubscriber.php#L334-L386 | train |
sulu/sulu | src/Sulu/Component/Content/Document/Subscriber/StructureSubscriber.php | StructureSubscriber.getStructure | private function getStructure($document, $structureType, $rehydrate)
{
if ($structureType) {
return $this->createStructure($document);
}
if (!$rehydrate && $document->getStructure()) {
return $document->getStructure();
}
return new Structure();
} | php | private function getStructure($document, $structureType, $rehydrate)
{
if ($structureType) {
return $this->createStructure($document);
}
if (!$rehydrate && $document->getStructure()) {
return $document->getStructure();
}
return new Structure();
} | [
"private",
"function",
"getStructure",
"(",
"$",
"document",
",",
"$",
"structureType",
",",
"$",
"rehydrate",
")",
"{",
"if",
"(",
"$",
"structureType",
")",
"{",
"return",
"$",
"this",
"->",
"createStructure",
"(",
"$",
"document",
")",
";",
"}",
"if",
"(",
"!",
"$",
"rehydrate",
"&&",
"$",
"document",
"->",
"getStructure",
"(",
")",
")",
"{",
"return",
"$",
"document",
"->",
"getStructure",
"(",
")",
";",
"}",
"return",
"new",
"Structure",
"(",
")",
";",
"}"
] | Return the a structure for the document.
- If the Structure already exists on the document, use that.
- If the Structure type is given, then create a ManagedStructure - this
means that the structure is already persisted on the node and it has data.
- If none of the above applies then create a new, empty, Structure.
@param object $document
@param string $structureType
@param bool $rehydrate
@return StructureInterface | [
"Return",
"the",
"a",
"structure",
"for",
"the",
"document",
"."
] | 6766a36cc2f0c807c59202bf7540a08c4ef31192 | https://github.com/sulu/sulu/blob/6766a36cc2f0c807c59202bf7540a08c4ef31192/src/Sulu/Component/Content/Document/Subscriber/StructureSubscriber.php#L402-L413 | train |
sulu/sulu | src/Sulu/Component/Webspace/Webspace.php | Webspace.getLocalization | public function getLocalization($localization)
{
$localizations = $this->getLocalizations();
if (!empty($localizations)) {
foreach ($localizations as $webspaceLocalization) {
$result = $webspaceLocalization->findLocalization($localization);
if ($result) {
return $result;
}
}
}
return;
} | php | public function getLocalization($localization)
{
$localizations = $this->getLocalizations();
if (!empty($localizations)) {
foreach ($localizations as $webspaceLocalization) {
$result = $webspaceLocalization->findLocalization($localization);
if ($result) {
return $result;
}
}
}
return;
} | [
"public",
"function",
"getLocalization",
"(",
"$",
"localization",
")",
"{",
"$",
"localizations",
"=",
"$",
"this",
"->",
"getLocalizations",
"(",
")",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"localizations",
")",
")",
"{",
"foreach",
"(",
"$",
"localizations",
"as",
"$",
"webspaceLocalization",
")",
"{",
"$",
"result",
"=",
"$",
"webspaceLocalization",
"->",
"findLocalization",
"(",
"$",
"localization",
")",
";",
"if",
"(",
"$",
"result",
")",
"{",
"return",
"$",
"result",
";",
"}",
"}",
"}",
"return",
";",
"}"
] | Returns the localization object for a given localization string.
@param string $localization
@return Localization|null | [
"Returns",
"the",
"localization",
"object",
"for",
"a",
"given",
"localization",
"string",
"."
] | 6766a36cc2f0c807c59202bf7540a08c4ef31192 | https://github.com/sulu/sulu/blob/6766a36cc2f0c807c59202bf7540a08c4ef31192/src/Sulu/Component/Webspace/Webspace.php#L201-L215 | train |
sulu/sulu | src/Sulu/Component/Webspace/Webspace.php | Webspace.setDefaultLocalization | public function setDefaultLocalization($defaultLocalization)
{
$this->defaultLocalization = $defaultLocalization;
if (!$this->getXDefaultLocalization()) {
$this->xDefaultLocalization = $defaultLocalization;
}
} | php | public function setDefaultLocalization($defaultLocalization)
{
$this->defaultLocalization = $defaultLocalization;
if (!$this->getXDefaultLocalization()) {
$this->xDefaultLocalization = $defaultLocalization;
}
} | [
"public",
"function",
"setDefaultLocalization",
"(",
"$",
"defaultLocalization",
")",
"{",
"$",
"this",
"->",
"defaultLocalization",
"=",
"$",
"defaultLocalization",
";",
"if",
"(",
"!",
"$",
"this",
"->",
"getXDefaultLocalization",
"(",
")",
")",
"{",
"$",
"this",
"->",
"xDefaultLocalization",
"=",
"$",
"defaultLocalization",
";",
"}",
"}"
] | Sets the default localization for this webspace.
@param Localization $defaultLocalization | [
"Sets",
"the",
"default",
"localization",
"for",
"this",
"webspace",
"."
] | 6766a36cc2f0c807c59202bf7540a08c4ef31192 | https://github.com/sulu/sulu/blob/6766a36cc2f0c807c59202bf7540a08c4ef31192/src/Sulu/Component/Webspace/Webspace.php#L222-L229 | train |
sulu/sulu | src/Sulu/Component/Webspace/Webspace.php | Webspace.addSegment | public function addSegment(Segment $segment)
{
$this->segments[] = $segment;
if ($segment->isDefault()) {
$this->setDefaultSegment($segment);
}
} | php | public function addSegment(Segment $segment)
{
$this->segments[] = $segment;
if ($segment->isDefault()) {
$this->setDefaultSegment($segment);
}
} | [
"public",
"function",
"addSegment",
"(",
"Segment",
"$",
"segment",
")",
"{",
"$",
"this",
"->",
"segments",
"[",
"]",
"=",
"$",
"segment",
";",
"if",
"(",
"$",
"segment",
"->",
"isDefault",
"(",
")",
")",
"{",
"$",
"this",
"->",
"setDefaultSegment",
"(",
"$",
"segment",
")",
";",
"}",
"}"
] | Adds a segment to the webspace.
@param Segment $segment | [
"Adds",
"a",
"segment",
"to",
"the",
"webspace",
"."
] | 6766a36cc2f0c807c59202bf7540a08c4ef31192 | https://github.com/sulu/sulu/blob/6766a36cc2f0c807c59202bf7540a08c4ef31192/src/Sulu/Component/Webspace/Webspace.php#L314-L321 | train |
sulu/sulu | src/Sulu/Component/Webspace/Webspace.php | Webspace.hasDomain | public function hasDomain($domain, $environment, $locale = null)
{
$localizationParts = explode('_', $locale);
$language = $localizationParts[0];
$country = isset($localizationParts[1]) ? $localizationParts[1] : '';
foreach ($this->getPortals() as $portal) {
foreach ($portal->getEnvironment($environment)->getUrls() as $url) {
$host = parse_url('//' . $url->getUrl())['host'];
if ((null === $locale || $url->isValidLocale($language, $country))
&& ($host === $domain || '{host}' === $host)
) {
return true;
}
}
}
return false;
} | php | public function hasDomain($domain, $environment, $locale = null)
{
$localizationParts = explode('_', $locale);
$language = $localizationParts[0];
$country = isset($localizationParts[1]) ? $localizationParts[1] : '';
foreach ($this->getPortals() as $portal) {
foreach ($portal->getEnvironment($environment)->getUrls() as $url) {
$host = parse_url('//' . $url->getUrl())['host'];
if ((null === $locale || $url->isValidLocale($language, $country))
&& ($host === $domain || '{host}' === $host)
) {
return true;
}
}
}
return false;
} | [
"public",
"function",
"hasDomain",
"(",
"$",
"domain",
",",
"$",
"environment",
",",
"$",
"locale",
"=",
"null",
")",
"{",
"$",
"localizationParts",
"=",
"explode",
"(",
"'_'",
",",
"$",
"locale",
")",
";",
"$",
"language",
"=",
"$",
"localizationParts",
"[",
"0",
"]",
";",
"$",
"country",
"=",
"isset",
"(",
"$",
"localizationParts",
"[",
"1",
"]",
")",
"?",
"$",
"localizationParts",
"[",
"1",
"]",
":",
"''",
";",
"foreach",
"(",
"$",
"this",
"->",
"getPortals",
"(",
")",
"as",
"$",
"portal",
")",
"{",
"foreach",
"(",
"$",
"portal",
"->",
"getEnvironment",
"(",
"$",
"environment",
")",
"->",
"getUrls",
"(",
")",
"as",
"$",
"url",
")",
"{",
"$",
"host",
"=",
"parse_url",
"(",
"'//'",
".",
"$",
"url",
"->",
"getUrl",
"(",
")",
")",
"[",
"'host'",
"]",
";",
"if",
"(",
"(",
"null",
"===",
"$",
"locale",
"||",
"$",
"url",
"->",
"isValidLocale",
"(",
"$",
"language",
",",
"$",
"country",
")",
")",
"&&",
"(",
"$",
"host",
"===",
"$",
"domain",
"||",
"'{host}'",
"===",
"$",
"host",
")",
")",
"{",
"return",
"true",
";",
"}",
"}",
"}",
"return",
"false",
";",
"}"
] | Returns false if domain not exists in webspace.
@param string $domain
@param string $environment
@param string $locale
@return bool
@throws Exception\EnvironmentNotFoundException | [
"Returns",
"false",
"if",
"domain",
"not",
"exists",
"in",
"webspace",
"."
] | 6766a36cc2f0c807c59202bf7540a08c4ef31192 | https://github.com/sulu/sulu/blob/6766a36cc2f0c807c59202bf7540a08c4ef31192/src/Sulu/Component/Webspace/Webspace.php#L430-L448 | train |
sulu/sulu | src/Sulu/Component/Webspace/Webspace.php | Webspace.getTemplate | public function getTemplate($type, $format = 'html')
{
if (array_key_exists($type, $this->templates)) {
return $this->templates[$type] . '.' . $format . '.twig';
}
return;
} | php | public function getTemplate($type, $format = 'html')
{
if (array_key_exists($type, $this->templates)) {
return $this->templates[$type] . '.' . $format . '.twig';
}
return;
} | [
"public",
"function",
"getTemplate",
"(",
"$",
"type",
",",
"$",
"format",
"=",
"'html'",
")",
"{",
"if",
"(",
"array_key_exists",
"(",
"$",
"type",
",",
"$",
"this",
"->",
"templates",
")",
")",
"{",
"return",
"$",
"this",
"->",
"templates",
"[",
"$",
"type",
"]",
".",
"'.'",
".",
"$",
"format",
".",
"'.twig'",
";",
"}",
"return",
";",
"}"
] | Returns a template for the given type.
@param string $type
@param string $format
@return string|null | [
"Returns",
"a",
"template",
"for",
"the",
"given",
"type",
"."
] | 6766a36cc2f0c807c59202bf7540a08c4ef31192 | https://github.com/sulu/sulu/blob/6766a36cc2f0c807c59202bf7540a08c4ef31192/src/Sulu/Component/Webspace/Webspace.php#L469-L476 | train |
sulu/sulu | src/Sulu/Component/Content/Compat/Property.php | Property.getIsMultiple | public function getIsMultiple()
{
$minOccurs = $this->getMinOccurs();
$maxOccurs = $this->getMaxOccurs();
if (is_null($minOccurs) && is_null($maxOccurs)) {
// if no occurs attributes are set it defaults to false
return false;
}
if (0 === $minOccurs && 1 === $maxOccurs) {
// this one allows to have an optional field
return true;
}
if (1 === $minOccurs && 1 === $maxOccurs) {
// if the occurences have a high and low limit of 1 it should be displayed as single
return false;
}
// if minOccurs is set a value of 1 is enough, because maxOccurs would be considered "unbound" when null
return $minOccurs >= 1 || $maxOccurs > 1;
} | php | public function getIsMultiple()
{
$minOccurs = $this->getMinOccurs();
$maxOccurs = $this->getMaxOccurs();
if (is_null($minOccurs) && is_null($maxOccurs)) {
// if no occurs attributes are set it defaults to false
return false;
}
if (0 === $minOccurs && 1 === $maxOccurs) {
// this one allows to have an optional field
return true;
}
if (1 === $minOccurs && 1 === $maxOccurs) {
// if the occurences have a high and low limit of 1 it should be displayed as single
return false;
}
// if minOccurs is set a value of 1 is enough, because maxOccurs would be considered "unbound" when null
return $minOccurs >= 1 || $maxOccurs > 1;
} | [
"public",
"function",
"getIsMultiple",
"(",
")",
"{",
"$",
"minOccurs",
"=",
"$",
"this",
"->",
"getMinOccurs",
"(",
")",
";",
"$",
"maxOccurs",
"=",
"$",
"this",
"->",
"getMaxOccurs",
"(",
")",
";",
"if",
"(",
"is_null",
"(",
"$",
"minOccurs",
")",
"&&",
"is_null",
"(",
"$",
"maxOccurs",
")",
")",
"{",
"// if no occurs attributes are set it defaults to false",
"return",
"false",
";",
"}",
"if",
"(",
"0",
"===",
"$",
"minOccurs",
"&&",
"1",
"===",
"$",
"maxOccurs",
")",
"{",
"// this one allows to have an optional field",
"return",
"true",
";",
"}",
"if",
"(",
"1",
"===",
"$",
"minOccurs",
"&&",
"1",
"===",
"$",
"maxOccurs",
")",
"{",
"// if the occurences have a high and low limit of 1 it should be displayed as single",
"return",
"false",
";",
"}",
"// if minOccurs is set a value of 1 is enough, because maxOccurs would be considered \"unbound\" when null",
"return",
"$",
"minOccurs",
">=",
"1",
"||",
"$",
"maxOccurs",
">",
"1",
";",
"}"
] | returns TRUE if property is multiple.
@return bool | [
"returns",
"TRUE",
"if",
"property",
"is",
"multiple",
"."
] | 6766a36cc2f0c807c59202bf7540a08c4ef31192 | https://github.com/sulu/sulu/blob/6766a36cc2f0c807c59202bf7540a08c4ef31192/src/Sulu/Component/Content/Compat/Property.php#L367-L389 | train |
sulu/sulu | src/Sulu/Component/Rest/RequestParametersTrait.php | RequestParametersTrait.getRequestParameter | protected function getRequestParameter(Request $request, $name, $force = false, $default = null)
{
$value = $request->get($name, $default);
if ($force && null === $value) {
throw new MissingParameterException(get_class($this), $name);
}
return $value;
} | php | protected function getRequestParameter(Request $request, $name, $force = false, $default = null)
{
$value = $request->get($name, $default);
if ($force && null === $value) {
throw new MissingParameterException(get_class($this), $name);
}
return $value;
} | [
"protected",
"function",
"getRequestParameter",
"(",
"Request",
"$",
"request",
",",
"$",
"name",
",",
"$",
"force",
"=",
"false",
",",
"$",
"default",
"=",
"null",
")",
"{",
"$",
"value",
"=",
"$",
"request",
"->",
"get",
"(",
"$",
"name",
",",
"$",
"default",
")",
";",
"if",
"(",
"$",
"force",
"&&",
"null",
"===",
"$",
"value",
")",
"{",
"throw",
"new",
"MissingParameterException",
"(",
"get_class",
"(",
"$",
"this",
")",
",",
"$",
"name",
")",
";",
"}",
"return",
"$",
"value",
";",
"}"
] | returns request parameter with given name.
@param Request $request
@param string $name
@param bool $force TRUE if value is mandatory
@param mixed $default value if parameter not exists
@throws MissingParameterException parameter is mandatory but does not exists
@return string | [
"returns",
"request",
"parameter",
"with",
"given",
"name",
"."
] | 6766a36cc2f0c807c59202bf7540a08c4ef31192 | https://github.com/sulu/sulu/blob/6766a36cc2f0c807c59202bf7540a08c4ef31192/src/Sulu/Component/Rest/RequestParametersTrait.php#L35-L43 | train |
sulu/sulu | src/Sulu/Component/Rest/RequestParametersTrait.php | RequestParametersTrait.getBooleanRequestParameter | protected function getBooleanRequestParameter($request, $name, $force = false, $default = null)
{
$value = $this->getRequestParameter($request, $name, $force, $default);
if ('true' === $value || true === $value) {
$value = true;
} elseif ('false' === $value || false === $value) {
$value = false;
} elseif ($force && true !== $value && false !== $value) {
throw new ParameterDataTypeException(get_class($this), $name);
} else {
$value = $default;
}
return $value;
} | php | protected function getBooleanRequestParameter($request, $name, $force = false, $default = null)
{
$value = $this->getRequestParameter($request, $name, $force, $default);
if ('true' === $value || true === $value) {
$value = true;
} elseif ('false' === $value || false === $value) {
$value = false;
} elseif ($force && true !== $value && false !== $value) {
throw new ParameterDataTypeException(get_class($this), $name);
} else {
$value = $default;
}
return $value;
} | [
"protected",
"function",
"getBooleanRequestParameter",
"(",
"$",
"request",
",",
"$",
"name",
",",
"$",
"force",
"=",
"false",
",",
"$",
"default",
"=",
"null",
")",
"{",
"$",
"value",
"=",
"$",
"this",
"->",
"getRequestParameter",
"(",
"$",
"request",
",",
"$",
"name",
",",
"$",
"force",
",",
"$",
"default",
")",
";",
"if",
"(",
"'true'",
"===",
"$",
"value",
"||",
"true",
"===",
"$",
"value",
")",
"{",
"$",
"value",
"=",
"true",
";",
"}",
"elseif",
"(",
"'false'",
"===",
"$",
"value",
"||",
"false",
"===",
"$",
"value",
")",
"{",
"$",
"value",
"=",
"false",
";",
"}",
"elseif",
"(",
"$",
"force",
"&&",
"true",
"!==",
"$",
"value",
"&&",
"false",
"!==",
"$",
"value",
")",
"{",
"throw",
"new",
"ParameterDataTypeException",
"(",
"get_class",
"(",
"$",
"this",
")",
",",
"$",
"name",
")",
";",
"}",
"else",
"{",
"$",
"value",
"=",
"$",
"default",
";",
"}",
"return",
"$",
"value",
";",
"}"
] | returns request parameter as boolean 'true' => true , 'false' => false.
@param Request $request
@param string $name
@param bool $force TRUE if value is mandatory
@param bool $default value if parameter not exists
@throws MissingParameterException parameter is mandatory but does not exists
@throws ParameterDataTypeException parameter hast the wrong data type
@return bool | [
"returns",
"request",
"parameter",
"as",
"boolean",
"true",
"=",
">",
"true",
"false",
"=",
">",
"false",
"."
] | 6766a36cc2f0c807c59202bf7540a08c4ef31192 | https://github.com/sulu/sulu/blob/6766a36cc2f0c807c59202bf7540a08c4ef31192/src/Sulu/Component/Rest/RequestParametersTrait.php#L58-L72 | train |
sulu/sulu | src/Sulu/Component/DocumentManager/NodeHelper.php | NodeHelper.normalizePath | private function normalizePath(SessionInterface $session, $identifier)
{
if (!UUIDHelper::isUUID($identifier)) {
return $identifier;
}
return $session->getNodeByIdentifier($identifier)->getPath();
} | php | private function normalizePath(SessionInterface $session, $identifier)
{
if (!UUIDHelper::isUUID($identifier)) {
return $identifier;
}
return $session->getNodeByIdentifier($identifier)->getPath();
} | [
"private",
"function",
"normalizePath",
"(",
"SessionInterface",
"$",
"session",
",",
"$",
"identifier",
")",
"{",
"if",
"(",
"!",
"UUIDHelper",
"::",
"isUUID",
"(",
"$",
"identifier",
")",
")",
"{",
"return",
"$",
"identifier",
";",
"}",
"return",
"$",
"session",
"->",
"getNodeByIdentifier",
"(",
"$",
"identifier",
")",
"->",
"getPath",
"(",
")",
";",
"}"
] | Returns the path based on the given UUID.
@param SessionInterface $session
@param string $identifier
@return string | [
"Returns",
"the",
"path",
"based",
"on",
"the",
"given",
"UUID",
"."
] | 6766a36cc2f0c807c59202bf7540a08c4ef31192 | https://github.com/sulu/sulu/blob/6766a36cc2f0c807c59202bf7540a08c4ef31192/src/Sulu/Component/DocumentManager/NodeHelper.php#L94-L101 | train |
sulu/sulu | src/Sulu/Bundle/PageBundle/Serializer/Subscriber/RedirectTypeSubscriber.php | RedirectTypeSubscriber.onPostSerialize | public function onPostSerialize(ObjectEvent $event)
{
/** @var RedirectTypeBehavior $document */
$document = $event->getObject();
if (!$document instanceof RedirectTypeBehavior) {
return;
}
$visitor = $event->getVisitor();
$redirectType = $document->getRedirectType();
if (RedirectType::INTERNAL == $redirectType && null !== $document->getRedirectTarget()) {
$visitor->addData('linked', 'internal');
$visitor->addData('internal_link', $document->getRedirectTarget()->getUuid());
} elseif (RedirectType::EXTERNAL == $redirectType) {
$visitor->addData('linked', 'external');
$visitor->addData('external', $document->getRedirectExternal());
} else {
$visitor->addData('linked', null);
}
} | php | public function onPostSerialize(ObjectEvent $event)
{
/** @var RedirectTypeBehavior $document */
$document = $event->getObject();
if (!$document instanceof RedirectTypeBehavior) {
return;
}
$visitor = $event->getVisitor();
$redirectType = $document->getRedirectType();
if (RedirectType::INTERNAL == $redirectType && null !== $document->getRedirectTarget()) {
$visitor->addData('linked', 'internal');
$visitor->addData('internal_link', $document->getRedirectTarget()->getUuid());
} elseif (RedirectType::EXTERNAL == $redirectType) {
$visitor->addData('linked', 'external');
$visitor->addData('external', $document->getRedirectExternal());
} else {
$visitor->addData('linked', null);
}
} | [
"public",
"function",
"onPostSerialize",
"(",
"ObjectEvent",
"$",
"event",
")",
"{",
"/** @var RedirectTypeBehavior $document */",
"$",
"document",
"=",
"$",
"event",
"->",
"getObject",
"(",
")",
";",
"if",
"(",
"!",
"$",
"document",
"instanceof",
"RedirectTypeBehavior",
")",
"{",
"return",
";",
"}",
"$",
"visitor",
"=",
"$",
"event",
"->",
"getVisitor",
"(",
")",
";",
"$",
"redirectType",
"=",
"$",
"document",
"->",
"getRedirectType",
"(",
")",
";",
"if",
"(",
"RedirectType",
"::",
"INTERNAL",
"==",
"$",
"redirectType",
"&&",
"null",
"!==",
"$",
"document",
"->",
"getRedirectTarget",
"(",
")",
")",
"{",
"$",
"visitor",
"->",
"addData",
"(",
"'linked'",
",",
"'internal'",
")",
";",
"$",
"visitor",
"->",
"addData",
"(",
"'internal_link'",
",",
"$",
"document",
"->",
"getRedirectTarget",
"(",
")",
"->",
"getUuid",
"(",
")",
")",
";",
"}",
"elseif",
"(",
"RedirectType",
"::",
"EXTERNAL",
"==",
"$",
"redirectType",
")",
"{",
"$",
"visitor",
"->",
"addData",
"(",
"'linked'",
",",
"'external'",
")",
";",
"$",
"visitor",
"->",
"addData",
"(",
"'external'",
",",
"$",
"document",
"->",
"getRedirectExternal",
"(",
")",
")",
";",
"}",
"else",
"{",
"$",
"visitor",
"->",
"addData",
"(",
"'linked'",
",",
"null",
")",
";",
"}",
"}"
] | Adds the type of redirect and the redirect location to the serialization.
@param ObjectEvent $event | [
"Adds",
"the",
"type",
"of",
"redirect",
"and",
"the",
"redirect",
"location",
"to",
"the",
"serialization",
"."
] | 6766a36cc2f0c807c59202bf7540a08c4ef31192 | https://github.com/sulu/sulu/blob/6766a36cc2f0c807c59202bf7540a08c4ef31192/src/Sulu/Bundle/PageBundle/Serializer/Subscriber/RedirectTypeSubscriber.php#L44-L66 | train |
sulu/sulu | src/Sulu/Component/DocumentManager/Subscriber/Core/InstantiatorSubscriber.php | InstantiatorSubscriber.getDocumentFromNode | private function getDocumentFromNode(NodeInterface $node)
{
$metadata = $this->metadataFactory->getMetadataForPhpcrNode($node);
return $this->instantiateFromMetadata($metadata);
} | php | private function getDocumentFromNode(NodeInterface $node)
{
$metadata = $this->metadataFactory->getMetadataForPhpcrNode($node);
return $this->instantiateFromMetadata($metadata);
} | [
"private",
"function",
"getDocumentFromNode",
"(",
"NodeInterface",
"$",
"node",
")",
"{",
"$",
"metadata",
"=",
"$",
"this",
"->",
"metadataFactory",
"->",
"getMetadataForPhpcrNode",
"(",
"$",
"node",
")",
";",
"return",
"$",
"this",
"->",
"instantiateFromMetadata",
"(",
"$",
"metadata",
")",
";",
"}"
] | Instantiate a new document. The class is determined from
the mixins present in the PHPCR node for legacy reasons.
@param NodeInterface $node
@return object | [
"Instantiate",
"a",
"new",
"document",
".",
"The",
"class",
"is",
"determined",
"from",
"the",
"mixins",
"present",
"in",
"the",
"PHPCR",
"node",
"for",
"legacy",
"reasons",
"."
] | 6766a36cc2f0c807c59202bf7540a08c4ef31192 | https://github.com/sulu/sulu/blob/6766a36cc2f0c807c59202bf7540a08c4ef31192/src/Sulu/Component/DocumentManager/Subscriber/Core/InstantiatorSubscriber.php#L90-L95 | train |
sulu/sulu | src/Sulu/Bundle/RouteBundle/Controller/RouteController.php | RouteController.cgetAction | public function cgetAction(Request $request)
{
// required parameter
$locale = $this->getRequestParameter($request, 'locale', true);
$entityClass = $this->getRequestParameter($request, 'entityClass', true);
$entityId = $this->getRequestParameter($request, 'entityId', true);
// optional parameter
$history = $this->getBooleanRequestParameter($request, 'history', false, false);
$routes = $this->findRoutes($history, $entityClass, $entityId, $locale);
return $this->handleView($this->view(new CollectionRepresentation($routes, 'routes')));
} | php | public function cgetAction(Request $request)
{
// required parameter
$locale = $this->getRequestParameter($request, 'locale', true);
$entityClass = $this->getRequestParameter($request, 'entityClass', true);
$entityId = $this->getRequestParameter($request, 'entityId', true);
// optional parameter
$history = $this->getBooleanRequestParameter($request, 'history', false, false);
$routes = $this->findRoutes($history, $entityClass, $entityId, $locale);
return $this->handleView($this->view(new CollectionRepresentation($routes, 'routes')));
} | [
"public",
"function",
"cgetAction",
"(",
"Request",
"$",
"request",
")",
"{",
"// required parameter",
"$",
"locale",
"=",
"$",
"this",
"->",
"getRequestParameter",
"(",
"$",
"request",
",",
"'locale'",
",",
"true",
")",
";",
"$",
"entityClass",
"=",
"$",
"this",
"->",
"getRequestParameter",
"(",
"$",
"request",
",",
"'entityClass'",
",",
"true",
")",
";",
"$",
"entityId",
"=",
"$",
"this",
"->",
"getRequestParameter",
"(",
"$",
"request",
",",
"'entityId'",
",",
"true",
")",
";",
"// optional parameter",
"$",
"history",
"=",
"$",
"this",
"->",
"getBooleanRequestParameter",
"(",
"$",
"request",
",",
"'history'",
",",
"false",
",",
"false",
")",
";",
"$",
"routes",
"=",
"$",
"this",
"->",
"findRoutes",
"(",
"$",
"history",
",",
"$",
"entityClass",
",",
"$",
"entityId",
",",
"$",
"locale",
")",
";",
"return",
"$",
"this",
"->",
"handleView",
"(",
"$",
"this",
"->",
"view",
"(",
"new",
"CollectionRepresentation",
"(",
"$",
"routes",
",",
"'routes'",
")",
")",
")",
";",
"}"
] | Returns list of routes for given entity.
@param Request $request
@return Response | [
"Returns",
"list",
"of",
"routes",
"for",
"given",
"entity",
"."
] | 6766a36cc2f0c807c59202bf7540a08c4ef31192 | https://github.com/sulu/sulu/blob/6766a36cc2f0c807c59202bf7540a08c4ef31192/src/Sulu/Bundle/RouteBundle/Controller/RouteController.php#L38-L51 | train |
sulu/sulu | src/Sulu/Bundle/RouteBundle/Controller/RouteController.php | RouteController.findRoutes | private function findRoutes($history, $entityClass, $entityId, $locale)
{
/** @var RouteRepositoryInterface $routeRespository */
$routeRespository = $this->get('sulu.repository.route');
if ($history) {
return $routeRespository->findHistoryByEntity($entityClass, $entityId, $locale);
}
return [$routeRespository->findByEntity($entityClass, $entityId, $locale)];
} | php | private function findRoutes($history, $entityClass, $entityId, $locale)
{
/** @var RouteRepositoryInterface $routeRespository */
$routeRespository = $this->get('sulu.repository.route');
if ($history) {
return $routeRespository->findHistoryByEntity($entityClass, $entityId, $locale);
}
return [$routeRespository->findByEntity($entityClass, $entityId, $locale)];
} | [
"private",
"function",
"findRoutes",
"(",
"$",
"history",
",",
"$",
"entityClass",
",",
"$",
"entityId",
",",
"$",
"locale",
")",
"{",
"/** @var RouteRepositoryInterface $routeRespository */",
"$",
"routeRespository",
"=",
"$",
"this",
"->",
"get",
"(",
"'sulu.repository.route'",
")",
";",
"if",
"(",
"$",
"history",
")",
"{",
"return",
"$",
"routeRespository",
"->",
"findHistoryByEntity",
"(",
"$",
"entityClass",
",",
"$",
"entityId",
",",
"$",
"locale",
")",
";",
"}",
"return",
"[",
"$",
"routeRespository",
"->",
"findByEntity",
"(",
"$",
"entityClass",
",",
"$",
"entityId",
",",
"$",
"locale",
")",
"]",
";",
"}"
] | Find routes with given parameters.
@param bool $history
@param string $entityClass
@param string $entityId
@param string $locale
@return RouteInterface|RouteInterface[] | [
"Find",
"routes",
"with",
"given",
"parameters",
"."
] | 6766a36cc2f0c807c59202bf7540a08c4ef31192 | https://github.com/sulu/sulu/blob/6766a36cc2f0c807c59202bf7540a08c4ef31192/src/Sulu/Bundle/RouteBundle/Controller/RouteController.php#L63-L73 | train |
sulu/sulu | src/Sulu/Bundle/RouteBundle/Controller/RouteController.php | RouteController.deleteAction | public function deleteAction($id)
{
/** @var RouteRepositoryInterface $routeRespository */
$routeRespository = $this->get('sulu.repository.route');
$route = $routeRespository->find($id);
if (!$route) {
throw new EntityNotFoundException(RouteInterface::class, $id);
}
$entityManager = $this->get('doctrine.orm.entity_manager');
$entityManager->remove($route);
$entityManager->flush();
return $this->handleView($this->view());
} | php | public function deleteAction($id)
{
/** @var RouteRepositoryInterface $routeRespository */
$routeRespository = $this->get('sulu.repository.route');
$route = $routeRespository->find($id);
if (!$route) {
throw new EntityNotFoundException(RouteInterface::class, $id);
}
$entityManager = $this->get('doctrine.orm.entity_manager');
$entityManager->remove($route);
$entityManager->flush();
return $this->handleView($this->view());
} | [
"public",
"function",
"deleteAction",
"(",
"$",
"id",
")",
"{",
"/** @var RouteRepositoryInterface $routeRespository */",
"$",
"routeRespository",
"=",
"$",
"this",
"->",
"get",
"(",
"'sulu.repository.route'",
")",
";",
"$",
"route",
"=",
"$",
"routeRespository",
"->",
"find",
"(",
"$",
"id",
")",
";",
"if",
"(",
"!",
"$",
"route",
")",
"{",
"throw",
"new",
"EntityNotFoundException",
"(",
"RouteInterface",
"::",
"class",
",",
"$",
"id",
")",
";",
"}",
"$",
"entityManager",
"=",
"$",
"this",
"->",
"get",
"(",
"'doctrine.orm.entity_manager'",
")",
";",
"$",
"entityManager",
"->",
"remove",
"(",
"$",
"route",
")",
";",
"$",
"entityManager",
"->",
"flush",
"(",
")",
";",
"return",
"$",
"this",
"->",
"handleView",
"(",
"$",
"this",
"->",
"view",
"(",
")",
")",
";",
"}"
] | Delete given history-route.
@param int $id
@return Response
@throws EntityNotFoundException | [
"Delete",
"given",
"history",
"-",
"route",
"."
] | 6766a36cc2f0c807c59202bf7540a08c4ef31192 | https://github.com/sulu/sulu/blob/6766a36cc2f0c807c59202bf7540a08c4ef31192/src/Sulu/Bundle/RouteBundle/Controller/RouteController.php#L84-L99 | train |
sulu/sulu | src/Sulu/Bundle/LocationBundle/Geolocator/GeolocatorLocation.php | GeolocatorLocation.toArray | public function toArray()
{
$res = [];
foreach ([
'id',
'displayTitle',
'street',
'number',
'code',
'town',
'country',
'longitude',
'latitude',
] as $propertyName) {
$res[$propertyName] = $this->{'get' . ucfirst($propertyName)}();
}
$res['name'] = TextUtils::truncate($this->getDisplayTitle(), 75);
return $res;
} | php | public function toArray()
{
$res = [];
foreach ([
'id',
'displayTitle',
'street',
'number',
'code',
'town',
'country',
'longitude',
'latitude',
] as $propertyName) {
$res[$propertyName] = $this->{'get' . ucfirst($propertyName)}();
}
$res['name'] = TextUtils::truncate($this->getDisplayTitle(), 75);
return $res;
} | [
"public",
"function",
"toArray",
"(",
")",
"{",
"$",
"res",
"=",
"[",
"]",
";",
"foreach",
"(",
"[",
"'id'",
",",
"'displayTitle'",
",",
"'street'",
",",
"'number'",
",",
"'code'",
",",
"'town'",
",",
"'country'",
",",
"'longitude'",
",",
"'latitude'",
",",
"]",
"as",
"$",
"propertyName",
")",
"{",
"$",
"res",
"[",
"$",
"propertyName",
"]",
"=",
"$",
"this",
"->",
"{",
"'get'",
".",
"ucfirst",
"(",
"$",
"propertyName",
")",
"}",
"(",
")",
";",
"}",
"$",
"res",
"[",
"'name'",
"]",
"=",
"TextUtils",
"::",
"truncate",
"(",
"$",
"this",
"->",
"getDisplayTitle",
"(",
")",
",",
"75",
")",
";",
"return",
"$",
"res",
";",
"}"
] | Serialize the location to an array.
@return array | [
"Serialize",
"the",
"location",
"to",
"an",
"array",
"."
] | 6766a36cc2f0c807c59202bf7540a08c4ef31192 | https://github.com/sulu/sulu/blob/6766a36cc2f0c807c59202bf7540a08c4ef31192/src/Sulu/Bundle/LocationBundle/Geolocator/GeolocatorLocation.php#L185-L205 | train |
sulu/sulu | src/Sulu/Bundle/WebsiteBundle/Sitemap/XmlSitemapRenderer.php | XmlSitemapRenderer.needsIndex | private function needsIndex()
{
return 1 < count($this->sitemapProviderPool->getProviders())
|| 1 < array_reduce(
$this->sitemapProviderPool->getIndex(),
function($v1, Sitemap $v2) {
return $v1 + $v2->getMaxPage();
}
);
} | php | private function needsIndex()
{
return 1 < count($this->sitemapProviderPool->getProviders())
|| 1 < array_reduce(
$this->sitemapProviderPool->getIndex(),
function($v1, Sitemap $v2) {
return $v1 + $v2->getMaxPage();
}
);
} | [
"private",
"function",
"needsIndex",
"(",
")",
"{",
"return",
"1",
"<",
"count",
"(",
"$",
"this",
"->",
"sitemapProviderPool",
"->",
"getProviders",
"(",
")",
")",
"||",
"1",
"<",
"array_reduce",
"(",
"$",
"this",
"->",
"sitemapProviderPool",
"->",
"getIndex",
"(",
")",
",",
"function",
"(",
"$",
"v1",
",",
"Sitemap",
"$",
"v2",
")",
"{",
"return",
"$",
"v1",
"+",
"$",
"v2",
"->",
"getMaxPage",
"(",
")",
";",
"}",
")",
";",
"}"
] | Returns true if a index exists.
@return bool | [
"Returns",
"true",
"if",
"a",
"index",
"exists",
"."
] | 6766a36cc2f0c807c59202bf7540a08c4ef31192 | https://github.com/sulu/sulu/blob/6766a36cc2f0c807c59202bf7540a08c4ef31192/src/Sulu/Bundle/WebsiteBundle/Sitemap/XmlSitemapRenderer.php#L106-L115 | train |
sulu/sulu | src/Sulu/Component/Rest/Listing/ListRepository.php | ListRepository.getArrayIndexByKeyValue | private function getArrayIndexByKeyValue($array, $value, $key = 'id')
{
foreach ($array as $index => $result) {
if ($result[$key] === $value) {
return $index;
}
}
return false;
} | php | private function getArrayIndexByKeyValue($array, $value, $key = 'id')
{
foreach ($array as $index => $result) {
if ($result[$key] === $value) {
return $index;
}
}
return false;
} | [
"private",
"function",
"getArrayIndexByKeyValue",
"(",
"$",
"array",
",",
"$",
"value",
",",
"$",
"key",
"=",
"'id'",
")",
"{",
"foreach",
"(",
"$",
"array",
"as",
"$",
"index",
"=>",
"$",
"result",
")",
"{",
"if",
"(",
"$",
"result",
"[",
"$",
"key",
"]",
"===",
"$",
"value",
")",
"{",
"return",
"$",
"index",
";",
"}",
"}",
"return",
"false",
";",
"}"
] | returns array index of by a specified key value.
@param $array
@param $value
@param string $key
@return bool|int|string | [
"returns",
"array",
"index",
"of",
"by",
"a",
"specified",
"key",
"value",
"."
] | 6766a36cc2f0c807c59202bf7540a08c4ef31192 | https://github.com/sulu/sulu/blob/6766a36cc2f0c807c59202bf7540a08c4ef31192/src/Sulu/Component/Rest/Listing/ListRepository.php#L152-L161 | train |
sulu/sulu | src/Sulu/Component/Rest/Listing/ListRepository.php | ListRepository.getCount | public function getCount($where = [], $joinConditions = [], $prefix = 'u')
{
return $this->find($where, $prefix, true, $joinConditions);
} | php | public function getCount($where = [], $joinConditions = [], $prefix = 'u')
{
return $this->find($where, $prefix, true, $joinConditions);
} | [
"public",
"function",
"getCount",
"(",
"$",
"where",
"=",
"[",
"]",
",",
"$",
"joinConditions",
"=",
"[",
"]",
",",
"$",
"prefix",
"=",
"'u'",
")",
"{",
"return",
"$",
"this",
"->",
"find",
"(",
"$",
"where",
",",
"$",
"prefix",
",",
"true",
",",
"$",
"joinConditions",
")",
";",
"}"
] | returns the amount of data.
@param array $where
@param array $joinConditions
@param string $prefix
@return int | [
"returns",
"the",
"amount",
"of",
"data",
"."
] | 6766a36cc2f0c807c59202bf7540a08c4ef31192 | https://github.com/sulu/sulu/blob/6766a36cc2f0c807c59202bf7540a08c4ef31192/src/Sulu/Component/Rest/Listing/ListRepository.php#L172-L175 | train |
sulu/sulu | src/Sulu/Component/Rest/Listing/ListRepository.php | ListRepository.getFieldsWitTypes | public function getFieldsWitTypes(array $types, $intersectArray = null)
{
$result = [];
foreach ($this->getClassMetadata()->getFieldNames() as $field) {
$type = $this->getClassMetadata()->getTypeOfField($field);
if (in_array($type, $types)) {
$result[] = $field;
}
}
// calculate intersection
if (!is_null($intersectArray)) {
$result = array_intersect($result, $intersectArray);
}
return $result;
} | php | public function getFieldsWitTypes(array $types, $intersectArray = null)
{
$result = [];
foreach ($this->getClassMetadata()->getFieldNames() as $field) {
$type = $this->getClassMetadata()->getTypeOfField($field);
if (in_array($type, $types)) {
$result[] = $field;
}
}
// calculate intersection
if (!is_null($intersectArray)) {
$result = array_intersect($result, $intersectArray);
}
return $result;
} | [
"public",
"function",
"getFieldsWitTypes",
"(",
"array",
"$",
"types",
",",
"$",
"intersectArray",
"=",
"null",
")",
"{",
"$",
"result",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"this",
"->",
"getClassMetadata",
"(",
")",
"->",
"getFieldNames",
"(",
")",
"as",
"$",
"field",
")",
"{",
"$",
"type",
"=",
"$",
"this",
"->",
"getClassMetadata",
"(",
")",
"->",
"getTypeOfField",
"(",
"$",
"field",
")",
";",
"if",
"(",
"in_array",
"(",
"$",
"type",
",",
"$",
"types",
")",
")",
"{",
"$",
"result",
"[",
"]",
"=",
"$",
"field",
";",
"}",
"}",
"// calculate intersection",
"if",
"(",
"!",
"is_null",
"(",
"$",
"intersectArray",
")",
")",
"{",
"$",
"result",
"=",
"array_intersect",
"(",
"$",
"result",
",",
"$",
"intersectArray",
")",
";",
"}",
"return",
"$",
"result",
";",
"}"
] | returns all fields with a specified type.
@param array $types
@param null $intersectArray only return fields that are defined in this array
@return array | [
"returns",
"all",
"fields",
"with",
"a",
"specified",
"type",
"."
] | 6766a36cc2f0c807c59202bf7540a08c4ef31192 | https://github.com/sulu/sulu/blob/6766a36cc2f0c807c59202bf7540a08c4ef31192/src/Sulu/Component/Rest/Listing/ListRepository.php#L185-L200 | train |
sulu/sulu | src/Sulu/Bundle/MediaBundle/Entity/FileVersion.php | FileVersion.getExtension | public function getExtension()
{
$pathInfo = pathinfo($this->getName());
$extension = ExtensionGuesser::getInstance()->guess($this->getMimeType());
if ($extension) {
return $extension;
} elseif (isset($pathInfo['extension'])) {
return $pathInfo['extension'];
}
return null;
} | php | public function getExtension()
{
$pathInfo = pathinfo($this->getName());
$extension = ExtensionGuesser::getInstance()->guess($this->getMimeType());
if ($extension) {
return $extension;
} elseif (isset($pathInfo['extension'])) {
return $pathInfo['extension'];
}
return null;
} | [
"public",
"function",
"getExtension",
"(",
")",
"{",
"$",
"pathInfo",
"=",
"pathinfo",
"(",
"$",
"this",
"->",
"getName",
"(",
")",
")",
";",
"$",
"extension",
"=",
"ExtensionGuesser",
"::",
"getInstance",
"(",
")",
"->",
"guess",
"(",
"$",
"this",
"->",
"getMimeType",
"(",
")",
")",
";",
"if",
"(",
"$",
"extension",
")",
"{",
"return",
"$",
"extension",
";",
"}",
"elseif",
"(",
"isset",
"(",
"$",
"pathInfo",
"[",
"'extension'",
"]",
")",
")",
"{",
"return",
"$",
"pathInfo",
"[",
"'extension'",
"]",
";",
"}",
"return",
"null",
";",
"}"
] | Get extension.
@return null|string | [
"Get",
"extension",
"."
] | 6766a36cc2f0c807c59202bf7540a08c4ef31192 | https://github.com/sulu/sulu/blob/6766a36cc2f0c807c59202bf7540a08c4ef31192/src/Sulu/Bundle/MediaBundle/Entity/FileVersion.php#L277-L288 | train |
sulu/sulu | src/Sulu/Bundle/MediaBundle/Entity/FileVersion.php | FileVersion.addPublishLanguage | public function addPublishLanguage(\Sulu\Bundle\MediaBundle\Entity\FileVersionPublishLanguage $publishLanguages)
{
$this->publishLanguages[] = $publishLanguages;
return $this;
} | php | public function addPublishLanguage(\Sulu\Bundle\MediaBundle\Entity\FileVersionPublishLanguage $publishLanguages)
{
$this->publishLanguages[] = $publishLanguages;
return $this;
} | [
"public",
"function",
"addPublishLanguage",
"(",
"\\",
"Sulu",
"\\",
"Bundle",
"\\",
"MediaBundle",
"\\",
"Entity",
"\\",
"FileVersionPublishLanguage",
"$",
"publishLanguages",
")",
"{",
"$",
"this",
"->",
"publishLanguages",
"[",
"]",
"=",
"$",
"publishLanguages",
";",
"return",
"$",
"this",
";",
"}"
] | Add publishLanguages.
@param \Sulu\Bundle\MediaBundle\Entity\FileVersionPublishLanguage $publishLanguages
@return FileVersion | [
"Add",
"publishLanguages",
"."
] | 6766a36cc2f0c807c59202bf7540a08c4ef31192 | https://github.com/sulu/sulu/blob/6766a36cc2f0c807c59202bf7540a08c4ef31192/src/Sulu/Bundle/MediaBundle/Entity/FileVersion.php#L382-L387 | train |
sulu/sulu | src/Sulu/Bundle/MediaBundle/Entity/FileVersion.php | FileVersion.removePublishLanguage | public function removePublishLanguage(\Sulu\Bundle\MediaBundle\Entity\FileVersionPublishLanguage $publishLanguages)
{
$this->publishLanguages->removeElement($publishLanguages);
} | php | public function removePublishLanguage(\Sulu\Bundle\MediaBundle\Entity\FileVersionPublishLanguage $publishLanguages)
{
$this->publishLanguages->removeElement($publishLanguages);
} | [
"public",
"function",
"removePublishLanguage",
"(",
"\\",
"Sulu",
"\\",
"Bundle",
"\\",
"MediaBundle",
"\\",
"Entity",
"\\",
"FileVersionPublishLanguage",
"$",
"publishLanguages",
")",
"{",
"$",
"this",
"->",
"publishLanguages",
"->",
"removeElement",
"(",
"$",
"publishLanguages",
")",
";",
"}"
] | Remove publishLanguages.
@param \Sulu\Bundle\MediaBundle\Entity\FileVersionPublishLanguage $publishLanguages | [
"Remove",
"publishLanguages",
"."
] | 6766a36cc2f0c807c59202bf7540a08c4ef31192 | https://github.com/sulu/sulu/blob/6766a36cc2f0c807c59202bf7540a08c4ef31192/src/Sulu/Bundle/MediaBundle/Entity/FileVersion.php#L394-L397 | train |
sulu/sulu | src/Sulu/Bundle/MediaBundle/Entity/FileVersion.php | FileVersion.addMeta | public function addMeta(\Sulu\Bundle\MediaBundle\Entity\FileVersionMeta $meta)
{
$this->meta[] = $meta;
return $this;
} | php | public function addMeta(\Sulu\Bundle\MediaBundle\Entity\FileVersionMeta $meta)
{
$this->meta[] = $meta;
return $this;
} | [
"public",
"function",
"addMeta",
"(",
"\\",
"Sulu",
"\\",
"Bundle",
"\\",
"MediaBundle",
"\\",
"Entity",
"\\",
"FileVersionMeta",
"$",
"meta",
")",
"{",
"$",
"this",
"->",
"meta",
"[",
"]",
"=",
"$",
"meta",
";",
"return",
"$",
"this",
";",
"}"
] | Add meta.
@param \Sulu\Bundle\MediaBundle\Entity\FileVersionMeta $meta
@return FileVersion | [
"Add",
"meta",
"."
] | 6766a36cc2f0c807c59202bf7540a08c4ef31192 | https://github.com/sulu/sulu/blob/6766a36cc2f0c807c59202bf7540a08c4ef31192/src/Sulu/Bundle/MediaBundle/Entity/FileVersion.php#L416-L421 | train |
sulu/sulu | src/Sulu/Bundle/MediaBundle/Entity/FileVersion.php | FileVersion.removeMeta | public function removeMeta(\Sulu\Bundle\MediaBundle\Entity\FileVersionMeta $meta)
{
$this->meta->removeElement($meta);
} | php | public function removeMeta(\Sulu\Bundle\MediaBundle\Entity\FileVersionMeta $meta)
{
$this->meta->removeElement($meta);
} | [
"public",
"function",
"removeMeta",
"(",
"\\",
"Sulu",
"\\",
"Bundle",
"\\",
"MediaBundle",
"\\",
"Entity",
"\\",
"FileVersionMeta",
"$",
"meta",
")",
"{",
"$",
"this",
"->",
"meta",
"->",
"removeElement",
"(",
"$",
"meta",
")",
";",
"}"
] | Remove meta.
@param \Sulu\Bundle\MediaBundle\Entity\FileVersionMeta $meta | [
"Remove",
"meta",
"."
] | 6766a36cc2f0c807c59202bf7540a08c4ef31192 | https://github.com/sulu/sulu/blob/6766a36cc2f0c807c59202bf7540a08c4ef31192/src/Sulu/Bundle/MediaBundle/Entity/FileVersion.php#L428-L431 | train |
sulu/sulu | src/Sulu/Bundle/MediaBundle/Entity/FileVersion.php | FileVersion.setDefaultMeta | public function setDefaultMeta(\Sulu\Bundle\MediaBundle\Entity\FileVersionMeta $defaultMeta = null)
{
$this->defaultMeta = $defaultMeta;
return $this;
} | php | public function setDefaultMeta(\Sulu\Bundle\MediaBundle\Entity\FileVersionMeta $defaultMeta = null)
{
$this->defaultMeta = $defaultMeta;
return $this;
} | [
"public",
"function",
"setDefaultMeta",
"(",
"\\",
"Sulu",
"\\",
"Bundle",
"\\",
"MediaBundle",
"\\",
"Entity",
"\\",
"FileVersionMeta",
"$",
"defaultMeta",
"=",
"null",
")",
"{",
"$",
"this",
"->",
"defaultMeta",
"=",
"$",
"defaultMeta",
";",
"return",
"$",
"this",
";",
"}"
] | Set defaultMeta.
@param \Sulu\Bundle\MediaBundle\Entity\FileVersionMeta $defaultMeta
@return FileVersion | [
"Set",
"defaultMeta",
"."
] | 6766a36cc2f0c807c59202bf7540a08c4ef31192 | https://github.com/sulu/sulu/blob/6766a36cc2f0c807c59202bf7540a08c4ef31192/src/Sulu/Bundle/MediaBundle/Entity/FileVersion.php#L540-L545 | train |
sulu/sulu | src/Sulu/Bundle/PageBundle/Controller/WebspaceLocalizationController.php | WebspaceLocalizationController.cgetAction | public function cgetAction(Request $request)
{
$webspaceKey = $request->get('webspace');
/** @var WebspaceManagerInterface $webspaceManager */
$webspaceManager = $this->get('sulu_core.webspace.webspace_manager');
$webspace = $webspaceManager->findWebspaceByKey($webspaceKey);
if ($webspace) {
$localizations = new CollectionRepresentation($webspace->getAllLocalizations(), 'localizations');
$view = $this->view($localizations, 200);
} else {
$error = new RestException(sprintf('No webspace found for key \'%s\'', $webspaceKey));
$view = $this->view($error->toArray(), 400);
}
return $this->handleView($view);
} | php | public function cgetAction(Request $request)
{
$webspaceKey = $request->get('webspace');
/** @var WebspaceManagerInterface $webspaceManager */
$webspaceManager = $this->get('sulu_core.webspace.webspace_manager');
$webspace = $webspaceManager->findWebspaceByKey($webspaceKey);
if ($webspace) {
$localizations = new CollectionRepresentation($webspace->getAllLocalizations(), 'localizations');
$view = $this->view($localizations, 200);
} else {
$error = new RestException(sprintf('No webspace found for key \'%s\'', $webspaceKey));
$view = $this->view($error->toArray(), 400);
}
return $this->handleView($view);
} | [
"public",
"function",
"cgetAction",
"(",
"Request",
"$",
"request",
")",
"{",
"$",
"webspaceKey",
"=",
"$",
"request",
"->",
"get",
"(",
"'webspace'",
")",
";",
"/** @var WebspaceManagerInterface $webspaceManager */",
"$",
"webspaceManager",
"=",
"$",
"this",
"->",
"get",
"(",
"'sulu_core.webspace.webspace_manager'",
")",
";",
"$",
"webspace",
"=",
"$",
"webspaceManager",
"->",
"findWebspaceByKey",
"(",
"$",
"webspaceKey",
")",
";",
"if",
"(",
"$",
"webspace",
")",
"{",
"$",
"localizations",
"=",
"new",
"CollectionRepresentation",
"(",
"$",
"webspace",
"->",
"getAllLocalizations",
"(",
")",
",",
"'localizations'",
")",
";",
"$",
"view",
"=",
"$",
"this",
"->",
"view",
"(",
"$",
"localizations",
",",
"200",
")",
";",
"}",
"else",
"{",
"$",
"error",
"=",
"new",
"RestException",
"(",
"sprintf",
"(",
"'No webspace found for key \\'%s\\''",
",",
"$",
"webspaceKey",
")",
")",
";",
"$",
"view",
"=",
"$",
"this",
"->",
"view",
"(",
"$",
"error",
"->",
"toArray",
"(",
")",
",",
"400",
")",
";",
"}",
"return",
"$",
"this",
"->",
"handleView",
"(",
"$",
"view",
")",
";",
"}"
] | Returns the localizations for the given webspace.
@param Request $request
@return \Symfony\Component\HttpFoundation\Response | [
"Returns",
"the",
"localizations",
"for",
"the",
"given",
"webspace",
"."
] | 6766a36cc2f0c807c59202bf7540a08c4ef31192 | https://github.com/sulu/sulu/blob/6766a36cc2f0c807c59202bf7540a08c4ef31192/src/Sulu/Bundle/PageBundle/Controller/WebspaceLocalizationController.php#L33-L51 | train |
sulu/sulu | src/Sulu/Bundle/CategoryBundle/Api/Category.php | Category.getMeta | public function getMeta()
{
$arrReturn = [];
if (null !== $this->entity->getMeta()) {
foreach ($this->entity->getMeta() as $meta) {
if (!$meta->getLocale() || $meta->getLocale() === $this->locale) {
array_push(
$arrReturn,
[
'id' => $meta->getId(),
'key' => $meta->getKey(),
'value' => $meta->getValue(),
]
);
}
}
return $arrReturn;
}
return;
} | php | public function getMeta()
{
$arrReturn = [];
if (null !== $this->entity->getMeta()) {
foreach ($this->entity->getMeta() as $meta) {
if (!$meta->getLocale() || $meta->getLocale() === $this->locale) {
array_push(
$arrReturn,
[
'id' => $meta->getId(),
'key' => $meta->getKey(),
'value' => $meta->getValue(),
]
);
}
}
return $arrReturn;
}
return;
} | [
"public",
"function",
"getMeta",
"(",
")",
"{",
"$",
"arrReturn",
"=",
"[",
"]",
";",
"if",
"(",
"null",
"!==",
"$",
"this",
"->",
"entity",
"->",
"getMeta",
"(",
")",
")",
"{",
"foreach",
"(",
"$",
"this",
"->",
"entity",
"->",
"getMeta",
"(",
")",
"as",
"$",
"meta",
")",
"{",
"if",
"(",
"!",
"$",
"meta",
"->",
"getLocale",
"(",
")",
"||",
"$",
"meta",
"->",
"getLocale",
"(",
")",
"===",
"$",
"this",
"->",
"locale",
")",
"{",
"array_push",
"(",
"$",
"arrReturn",
",",
"[",
"'id'",
"=>",
"$",
"meta",
"->",
"getId",
"(",
")",
",",
"'key'",
"=>",
"$",
"meta",
"->",
"getKey",
"(",
")",
",",
"'value'",
"=>",
"$",
"meta",
"->",
"getValue",
"(",
")",
",",
"]",
")",
";",
"}",
"}",
"return",
"$",
"arrReturn",
";",
"}",
"return",
";",
"}"
] | Returns the name of the Category dependent on the locale.
@VirtualProperty
@SerializedName("meta")
@Groups({"fullCategory","partialCategory"})
@return array | [
"Returns",
"the",
"name",
"of",
"the",
"Category",
"dependent",
"on",
"the",
"locale",
"."
] | 6766a36cc2f0c807c59202bf7540a08c4ef31192 | https://github.com/sulu/sulu/blob/6766a36cc2f0c807c59202bf7540a08c4ef31192/src/Sulu/Bundle/CategoryBundle/Api/Category.php#L179-L200 | train |
sulu/sulu | src/Sulu/Bundle/CategoryBundle/Api/Category.php | Category.getCreator | public function getCreator()
{
$strReturn = '';
$creator = $this->entity->getCreator();
if ($creator) {
return $this->getUserFullName($creator);
}
return $strReturn;
} | php | public function getCreator()
{
$strReturn = '';
$creator = $this->entity->getCreator();
if ($creator) {
return $this->getUserFullName($creator);
}
return $strReturn;
} | [
"public",
"function",
"getCreator",
"(",
")",
"{",
"$",
"strReturn",
"=",
"''",
";",
"$",
"creator",
"=",
"$",
"this",
"->",
"entity",
"->",
"getCreator",
"(",
")",
";",
"if",
"(",
"$",
"creator",
")",
"{",
"return",
"$",
"this",
"->",
"getUserFullName",
"(",
"$",
"creator",
")",
";",
"}",
"return",
"$",
"strReturn",
";",
"}"
] | Returns the creator of the category.
@VirtualProperty
@SerializedName("creator")
@Groups({"fullCategory"})
@return string | [
"Returns",
"the",
"creator",
"of",
"the",
"category",
"."
] | 6766a36cc2f0c807c59202bf7540a08c4ef31192 | https://github.com/sulu/sulu/blob/6766a36cc2f0c807c59202bf7540a08c4ef31192/src/Sulu/Bundle/CategoryBundle/Api/Category.php#L211-L220 | train |
sulu/sulu | src/Sulu/Bundle/CategoryBundle/Api/Category.php | Category.getChanger | public function getChanger()
{
$strReturn = '';
$changer = $this->entity->getChanger();
if ($changer) {
return $this->getUserFullName($changer);
}
return $strReturn;
} | php | public function getChanger()
{
$strReturn = '';
$changer = $this->entity->getChanger();
if ($changer) {
return $this->getUserFullName($changer);
}
return $strReturn;
} | [
"public",
"function",
"getChanger",
"(",
")",
"{",
"$",
"strReturn",
"=",
"''",
";",
"$",
"changer",
"=",
"$",
"this",
"->",
"entity",
"->",
"getChanger",
"(",
")",
";",
"if",
"(",
"$",
"changer",
")",
"{",
"return",
"$",
"this",
"->",
"getUserFullName",
"(",
"$",
"changer",
")",
";",
"}",
"return",
"$",
"strReturn",
";",
"}"
] | Returns the changer of the category.
@VirtualProperty
@SerializedName("changer")
@Groups({"fullCategory"})
@return string | [
"Returns",
"the",
"changer",
"of",
"the",
"category",
"."
] | 6766a36cc2f0c807c59202bf7540a08c4ef31192 | https://github.com/sulu/sulu/blob/6766a36cc2f0c807c59202bf7540a08c4ef31192/src/Sulu/Bundle/CategoryBundle/Api/Category.php#L231-L240 | train |
sulu/sulu | src/Sulu/Bundle/CategoryBundle/Api/Category.php | Category.getChildren | public function getChildren()
{
$children = [];
if ($this->entity->getChildren()) {
foreach ($this->entity->getChildren() as $child) {
$children[] = new self($child, $this->locale);
}
}
return $children;
} | php | public function getChildren()
{
$children = [];
if ($this->entity->getChildren()) {
foreach ($this->entity->getChildren() as $child) {
$children[] = new self($child, $this->locale);
}
}
return $children;
} | [
"public",
"function",
"getChildren",
"(",
")",
"{",
"$",
"children",
"=",
"[",
"]",
";",
"if",
"(",
"$",
"this",
"->",
"entity",
"->",
"getChildren",
"(",
")",
")",
"{",
"foreach",
"(",
"$",
"this",
"->",
"entity",
"->",
"getChildren",
"(",
")",
"as",
"$",
"child",
")",
"{",
"$",
"children",
"[",
"]",
"=",
"new",
"self",
"(",
"$",
"child",
",",
"$",
"this",
"->",
"locale",
")",
";",
"}",
"}",
"return",
"$",
"children",
";",
"}"
] | Returns the children of a category.
@VirtualProperty
@SerializedName("children")
@Groups({"fullCategory"})
@return Category[] | [
"Returns",
"the",
"children",
"of",
"a",
"category",
"."
] | 6766a36cc2f0c807c59202bf7540a08c4ef31192 | https://github.com/sulu/sulu/blob/6766a36cc2f0c807c59202bf7540a08c4ef31192/src/Sulu/Bundle/CategoryBundle/Api/Category.php#L279-L289 | train |
sulu/sulu | src/Sulu/Bundle/CategoryBundle/Api/Category.php | Category.setTranslation | public function setTranslation(CategoryTranslationInterface $translation)
{
$translationEntity = $this->getTranslationByLocale($translation->getLocale());
if (!$translationEntity) {
$translationEntity = $translation;
$this->entity->addTranslation($translationEntity);
}
$translationEntity->setCategory($this->entity);
$translationEntity->setTranslation($translation->getTranslation());
$translationEntity->setLocale($translation->getLocale());
if (null === $this->getId() && null === $this->getDefaultLocale()) {
// new entity and new translation
// save first locale as default
$this->entity->setDefaultLocale($translationEntity->getLocale());
}
} | php | public function setTranslation(CategoryTranslationInterface $translation)
{
$translationEntity = $this->getTranslationByLocale($translation->getLocale());
if (!$translationEntity) {
$translationEntity = $translation;
$this->entity->addTranslation($translationEntity);
}
$translationEntity->setCategory($this->entity);
$translationEntity->setTranslation($translation->getTranslation());
$translationEntity->setLocale($translation->getLocale());
if (null === $this->getId() && null === $this->getDefaultLocale()) {
// new entity and new translation
// save first locale as default
$this->entity->setDefaultLocale($translationEntity->getLocale());
}
} | [
"public",
"function",
"setTranslation",
"(",
"CategoryTranslationInterface",
"$",
"translation",
")",
"{",
"$",
"translationEntity",
"=",
"$",
"this",
"->",
"getTranslationByLocale",
"(",
"$",
"translation",
"->",
"getLocale",
"(",
")",
")",
";",
"if",
"(",
"!",
"$",
"translationEntity",
")",
"{",
"$",
"translationEntity",
"=",
"$",
"translation",
";",
"$",
"this",
"->",
"entity",
"->",
"addTranslation",
"(",
"$",
"translationEntity",
")",
";",
"}",
"$",
"translationEntity",
"->",
"setCategory",
"(",
"$",
"this",
"->",
"entity",
")",
";",
"$",
"translationEntity",
"->",
"setTranslation",
"(",
"$",
"translation",
"->",
"getTranslation",
"(",
")",
")",
";",
"$",
"translationEntity",
"->",
"setLocale",
"(",
"$",
"translation",
"->",
"getLocale",
"(",
")",
")",
";",
"if",
"(",
"null",
"===",
"$",
"this",
"->",
"getId",
"(",
")",
"&&",
"null",
"===",
"$",
"this",
"->",
"getDefaultLocale",
"(",
")",
")",
"{",
"// new entity and new translation",
"// save first locale as default",
"$",
"this",
"->",
"entity",
"->",
"setDefaultLocale",
"(",
"$",
"translationEntity",
"->",
"getLocale",
"(",
")",
")",
";",
"}",
"}"
] | Sets a translation to the entity.
If no other translation was assigned before, the translation is added as default.
@param CategoryTranslationInterface $translation | [
"Sets",
"a",
"translation",
"to",
"the",
"entity",
".",
"If",
"no",
"other",
"translation",
"was",
"assigned",
"before",
"the",
"translation",
"is",
"added",
"as",
"default",
"."
] | 6766a36cc2f0c807c59202bf7540a08c4ef31192 | https://github.com/sulu/sulu/blob/6766a36cc2f0c807c59202bf7540a08c4ef31192/src/Sulu/Bundle/CategoryBundle/Api/Category.php#L297-L315 | train |
sulu/sulu | src/Sulu/Bundle/CategoryBundle/Api/Category.php | Category.setMeta | public function setMeta($metaEntities)
{
$currentMeta = $this->entity->getMeta();
foreach ($metaEntities as $singleMeta) {
$metaEntity = $this->getSingleMetaById($currentMeta, $singleMeta->getId());
if (!$metaEntity) {
$metaEntity = $singleMeta;
$this->entity->addMeta($metaEntity);
}
$metaEntity->setCategory($this->entity);
$metaEntity->setKey($singleMeta->getKey());
$metaEntity->setValue($singleMeta->getValue());
$metaEntity->setLocale($singleMeta->getLocale());
}
return $this;
} | php | public function setMeta($metaEntities)
{
$currentMeta = $this->entity->getMeta();
foreach ($metaEntities as $singleMeta) {
$metaEntity = $this->getSingleMetaById($currentMeta, $singleMeta->getId());
if (!$metaEntity) {
$metaEntity = $singleMeta;
$this->entity->addMeta($metaEntity);
}
$metaEntity->setCategory($this->entity);
$metaEntity->setKey($singleMeta->getKey());
$metaEntity->setValue($singleMeta->getValue());
$metaEntity->setLocale($singleMeta->getLocale());
}
return $this;
} | [
"public",
"function",
"setMeta",
"(",
"$",
"metaEntities",
")",
"{",
"$",
"currentMeta",
"=",
"$",
"this",
"->",
"entity",
"->",
"getMeta",
"(",
")",
";",
"foreach",
"(",
"$",
"metaEntities",
"as",
"$",
"singleMeta",
")",
"{",
"$",
"metaEntity",
"=",
"$",
"this",
"->",
"getSingleMetaById",
"(",
"$",
"currentMeta",
",",
"$",
"singleMeta",
"->",
"getId",
"(",
")",
")",
";",
"if",
"(",
"!",
"$",
"metaEntity",
")",
"{",
"$",
"metaEntity",
"=",
"$",
"singleMeta",
";",
"$",
"this",
"->",
"entity",
"->",
"addMeta",
"(",
"$",
"metaEntity",
")",
";",
"}",
"$",
"metaEntity",
"->",
"setCategory",
"(",
"$",
"this",
"->",
"entity",
")",
";",
"$",
"metaEntity",
"->",
"setKey",
"(",
"$",
"singleMeta",
"->",
"getKey",
"(",
")",
")",
";",
"$",
"metaEntity",
"->",
"setValue",
"(",
"$",
"singleMeta",
"->",
"getValue",
"(",
")",
")",
";",
"$",
"metaEntity",
"->",
"setLocale",
"(",
"$",
"singleMeta",
"->",
"getLocale",
"(",
")",
")",
";",
"}",
"return",
"$",
"this",
";",
"}"
] | Takes meta as array and sets it to the entity.
@param CategoryMetaInterface[] $metaEntities
@return Category | [
"Takes",
"meta",
"as",
"array",
"and",
"sets",
"it",
"to",
"the",
"entity",
"."
] | 6766a36cc2f0c807c59202bf7540a08c4ef31192 | https://github.com/sulu/sulu/blob/6766a36cc2f0c807c59202bf7540a08c4ef31192/src/Sulu/Bundle/CategoryBundle/Api/Category.php#L324-L341 | train |
sulu/sulu | src/Sulu/Bundle/CategoryBundle/Api/Category.php | Category.getParent | public function getParent()
{
$parent = $this->getEntity()->getParent();
if ($parent) {
return new self($parent, $this->locale);
}
return;
} | php | public function getParent()
{
$parent = $this->getEntity()->getParent();
if ($parent) {
return new self($parent, $this->locale);
}
return;
} | [
"public",
"function",
"getParent",
"(",
")",
"{",
"$",
"parent",
"=",
"$",
"this",
"->",
"getEntity",
"(",
")",
"->",
"getParent",
"(",
")",
";",
"if",
"(",
"$",
"parent",
")",
"{",
"return",
"new",
"self",
"(",
"$",
"parent",
",",
"$",
"this",
"->",
"locale",
")",
";",
"}",
"return",
";",
"}"
] | Returns a parent category if one exists.
@return null|Category | [
"Returns",
"a",
"parent",
"category",
"if",
"one",
"exists",
"."
] | 6766a36cc2f0c807c59202bf7540a08c4ef31192 | https://github.com/sulu/sulu/blob/6766a36cc2f0c807c59202bf7540a08c4ef31192/src/Sulu/Bundle/CategoryBundle/Api/Category.php#L348-L356 | train |
sulu/sulu | src/Sulu/Bundle/CategoryBundle/Api/Category.php | Category.getKeywords | public function getKeywords()
{
$keywords = [];
$translation = $this->getTranslation(true);
if (!$translation) {
return $keywords;
}
foreach ($translation->getKeywords() as $keyword) {
$keywords[] = $keyword->getKeyword();
}
return $keywords;
} | php | public function getKeywords()
{
$keywords = [];
$translation = $this->getTranslation(true);
if (!$translation) {
return $keywords;
}
foreach ($translation->getKeywords() as $keyword) {
$keywords[] = $keyword->getKeyword();
}
return $keywords;
} | [
"public",
"function",
"getKeywords",
"(",
")",
"{",
"$",
"keywords",
"=",
"[",
"]",
";",
"$",
"translation",
"=",
"$",
"this",
"->",
"getTranslation",
"(",
"true",
")",
";",
"if",
"(",
"!",
"$",
"translation",
")",
"{",
"return",
"$",
"keywords",
";",
"}",
"foreach",
"(",
"$",
"translation",
"->",
"getKeywords",
"(",
")",
"as",
"$",
"keyword",
")",
"{",
"$",
"keywords",
"[",
"]",
"=",
"$",
"keyword",
"->",
"getKeyword",
"(",
")",
";",
"}",
"return",
"$",
"keywords",
";",
"}"
] | Returns the keywords of the category translations.
@return string[] | [
"Returns",
"the",
"keywords",
"of",
"the",
"category",
"translations",
"."
] | 6766a36cc2f0c807c59202bf7540a08c4ef31192 | https://github.com/sulu/sulu/blob/6766a36cc2f0c807c59202bf7540a08c4ef31192/src/Sulu/Bundle/CategoryBundle/Api/Category.php#L410-L425 | train |
sulu/sulu | src/Sulu/Bundle/CategoryBundle/Api/Category.php | Category.getUserFullName | private function getUserFullName($user)
{
$strReturn = '';
if ($user && method_exists($user, 'getContact')) {
$strReturn = $user->getContact()->getFirstName() . ' ' . $user->getContact()->getLastName();
}
return $strReturn;
} | php | private function getUserFullName($user)
{
$strReturn = '';
if ($user && method_exists($user, 'getContact')) {
$strReturn = $user->getContact()->getFirstName() . ' ' . $user->getContact()->getLastName();
}
return $strReturn;
} | [
"private",
"function",
"getUserFullName",
"(",
"$",
"user",
")",
"{",
"$",
"strReturn",
"=",
"''",
";",
"if",
"(",
"$",
"user",
"&&",
"method_exists",
"(",
"$",
"user",
",",
"'getContact'",
")",
")",
"{",
"$",
"strReturn",
"=",
"$",
"user",
"->",
"getContact",
"(",
")",
"->",
"getFirstName",
"(",
")",
".",
"' '",
".",
"$",
"user",
"->",
"getContact",
"(",
")",
"->",
"getLastName",
"(",
")",
";",
"}",
"return",
"$",
"strReturn",
";",
"}"
] | Takes a user entity and returns the fullname.
@param $user
@return string | [
"Takes",
"a",
"user",
"entity",
"and",
"returns",
"the",
"fullname",
"."
] | 6766a36cc2f0c807c59202bf7540a08c4ef31192 | https://github.com/sulu/sulu/blob/6766a36cc2f0c807c59202bf7540a08c4ef31192/src/Sulu/Bundle/CategoryBundle/Api/Category.php#L434-L442 | train |
sulu/sulu | src/Sulu/Bundle/CategoryBundle/Api/Category.php | Category.getSingleMetaById | private function getSingleMetaById($meta, $id)
{
if (null !== $id) {
foreach ($meta as $singleMeta) {
if ($singleMeta->getId() === $id) {
return $singleMeta;
}
}
}
} | php | private function getSingleMetaById($meta, $id)
{
if (null !== $id) {
foreach ($meta as $singleMeta) {
if ($singleMeta->getId() === $id) {
return $singleMeta;
}
}
}
} | [
"private",
"function",
"getSingleMetaById",
"(",
"$",
"meta",
",",
"$",
"id",
")",
"{",
"if",
"(",
"null",
"!==",
"$",
"id",
")",
"{",
"foreach",
"(",
"$",
"meta",
"as",
"$",
"singleMeta",
")",
"{",
"if",
"(",
"$",
"singleMeta",
"->",
"getId",
"(",
")",
"===",
"$",
"id",
")",
"{",
"return",
"$",
"singleMeta",
";",
"}",
"}",
"}",
"}"
] | Takes an array of CollectionMeta and returns a single meta for a given id.
@param $meta
@param $id
@return CollectionMeta | [
"Takes",
"an",
"array",
"of",
"CollectionMeta",
"and",
"returns",
"a",
"single",
"meta",
"for",
"a",
"given",
"id",
"."
] | 6766a36cc2f0c807c59202bf7540a08c4ef31192 | https://github.com/sulu/sulu/blob/6766a36cc2f0c807c59202bf7540a08c4ef31192/src/Sulu/Bundle/CategoryBundle/Api/Category.php#L452-L461 | train |
sulu/sulu | src/Sulu/Bundle/CategoryBundle/Api/Category.php | Category.toArray | public function toArray()
{
return [
'id' => $this->getId(),
'key' => $this->getKey(),
'name' => $this->getName(),
'meta' => $this->getMeta(),
'keywords' => $this->getKeywords(),
'defaultLocale' => $this->getDefaultLocale(),
'creator' => $this->getCreator(),
'changer' => $this->getChanger(),
'created' => $this->getCreated(),
'changed' => $this->getChanged(),
];
} | php | public function toArray()
{
return [
'id' => $this->getId(),
'key' => $this->getKey(),
'name' => $this->getName(),
'meta' => $this->getMeta(),
'keywords' => $this->getKeywords(),
'defaultLocale' => $this->getDefaultLocale(),
'creator' => $this->getCreator(),
'changer' => $this->getChanger(),
'created' => $this->getCreated(),
'changed' => $this->getChanged(),
];
} | [
"public",
"function",
"toArray",
"(",
")",
"{",
"return",
"[",
"'id'",
"=>",
"$",
"this",
"->",
"getId",
"(",
")",
",",
"'key'",
"=>",
"$",
"this",
"->",
"getKey",
"(",
")",
",",
"'name'",
"=>",
"$",
"this",
"->",
"getName",
"(",
")",
",",
"'meta'",
"=>",
"$",
"this",
"->",
"getMeta",
"(",
")",
",",
"'keywords'",
"=>",
"$",
"this",
"->",
"getKeywords",
"(",
")",
",",
"'defaultLocale'",
"=>",
"$",
"this",
"->",
"getDefaultLocale",
"(",
")",
",",
"'creator'",
"=>",
"$",
"this",
"->",
"getCreator",
"(",
")",
",",
"'changer'",
"=>",
"$",
"this",
"->",
"getChanger",
"(",
")",
",",
"'created'",
"=>",
"$",
"this",
"->",
"getCreated",
"(",
")",
",",
"'changed'",
"=>",
"$",
"this",
"->",
"getChanged",
"(",
")",
",",
"]",
";",
"}"
] | Returns an array representation of the object.
@return array | [
"Returns",
"an",
"array",
"representation",
"of",
"the",
"object",
"."
] | 6766a36cc2f0c807c59202bf7540a08c4ef31192 | https://github.com/sulu/sulu/blob/6766a36cc2f0c807c59202bf7540a08c4ef31192/src/Sulu/Bundle/CategoryBundle/Api/Category.php#L468-L482 | train |
sulu/sulu | src/Sulu/Bundle/CategoryBundle/Api/Category.php | Category.getTranslation | private function getTranslation($withDefault = false)
{
$translation = $this->getTranslationByLocale($this->locale);
if (true === $withDefault && null === $translation && null !== $this->getDefaultLocale()) {
return $this->getTranslationByLocale($this->getDefaultLocale());
}
return $translation;
} | php | private function getTranslation($withDefault = false)
{
$translation = $this->getTranslationByLocale($this->locale);
if (true === $withDefault && null === $translation && null !== $this->getDefaultLocale()) {
return $this->getTranslationByLocale($this->getDefaultLocale());
}
return $translation;
} | [
"private",
"function",
"getTranslation",
"(",
"$",
"withDefault",
"=",
"false",
")",
"{",
"$",
"translation",
"=",
"$",
"this",
"->",
"getTranslationByLocale",
"(",
"$",
"this",
"->",
"locale",
")",
";",
"if",
"(",
"true",
"===",
"$",
"withDefault",
"&&",
"null",
"===",
"$",
"translation",
"&&",
"null",
"!==",
"$",
"this",
"->",
"getDefaultLocale",
"(",
")",
")",
"{",
"return",
"$",
"this",
"->",
"getTranslationByLocale",
"(",
"$",
"this",
"->",
"getDefaultLocale",
"(",
")",
")",
";",
"}",
"return",
"$",
"translation",
";",
"}"
] | Returns the translation with the current locale.
@param $withDefault
@return CategoryTranslationInterface | [
"Returns",
"the",
"translation",
"with",
"the",
"current",
"locale",
"."
] | 6766a36cc2f0c807c59202bf7540a08c4ef31192 | https://github.com/sulu/sulu/blob/6766a36cc2f0c807c59202bf7540a08c4ef31192/src/Sulu/Bundle/CategoryBundle/Api/Category.php#L491-L500 | train |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.