repo stringlengths 6 63 | path stringlengths 5 140 | func_name stringlengths 3 151 | original_string stringlengths 84 13k | language stringclasses 1 value | code stringlengths 84 13k | code_tokens list | docstring stringlengths 3 47.2k | docstring_tokens list | sha stringlengths 40 40 | url stringlengths 91 247 | partition stringclasses 1 value |
|---|---|---|---|---|---|---|---|---|---|---|---|
sulu/sulu | src/Sulu/Component/Rest/ListBuilder/Doctrine/DoctrineListBuilder.php | DoctrineListBuilder.assignSortFields | protected function assignSortFields($queryBuilder)
{
// if no sort has been assigned add order by id ASC as default
if (0 === count($this->sortFields)) {
$queryBuilder->addOrderBy($this->idField->getSelect(), 'ASC');
}
foreach ($this->sortFields as $index => $sortField) {
$statement = $this->getSelectAs($sortField);
if (!$this->hasSelectStatement($queryBuilder, $statement)) {
$queryBuilder->addSelect($this->getSelectAs($sortField, true));
}
$queryBuilder->addOrderBy($sortField->getName(), $this->sortOrders[$index]);
}
} | php | protected function assignSortFields($queryBuilder)
{
// if no sort has been assigned add order by id ASC as default
if (0 === count($this->sortFields)) {
$queryBuilder->addOrderBy($this->idField->getSelect(), 'ASC');
}
foreach ($this->sortFields as $index => $sortField) {
$statement = $this->getSelectAs($sortField);
if (!$this->hasSelectStatement($queryBuilder, $statement)) {
$queryBuilder->addSelect($this->getSelectAs($sortField, true));
}
$queryBuilder->addOrderBy($sortField->getName(), $this->sortOrders[$index]);
}
} | [
"protected",
"function",
"assignSortFields",
"(",
"$",
"queryBuilder",
")",
"{",
"// if no sort has been assigned add order by id ASC as default",
"if",
"(",
"0",
"===",
"count",
"(",
"$",
"this",
"->",
"sortFields",
")",
")",
"{",
"$",
"queryBuilder",
"->",
"addOrderBy",
"(",
"$",
"this",
"->",
"idField",
"->",
"getSelect",
"(",
")",
",",
"'ASC'",
")",
";",
"}",
"foreach",
"(",
"$",
"this",
"->",
"sortFields",
"as",
"$",
"index",
"=>",
"$",
"sortField",
")",
"{",
"$",
"statement",
"=",
"$",
"this",
"->",
"getSelectAs",
"(",
"$",
"sortField",
")",
";",
"if",
"(",
"!",
"$",
"this",
"->",
"hasSelectStatement",
"(",
"$",
"queryBuilder",
",",
"$",
"statement",
")",
")",
"{",
"$",
"queryBuilder",
"->",
"addSelect",
"(",
"$",
"this",
"->",
"getSelectAs",
"(",
"$",
"sortField",
",",
"true",
")",
")",
";",
"}",
"$",
"queryBuilder",
"->",
"addOrderBy",
"(",
"$",
"sortField",
"->",
"getName",
"(",
")",
",",
"$",
"this",
"->",
"sortOrders",
"[",
"$",
"index",
"]",
")",
";",
"}",
"}"
] | Assigns ORDER BY clauses to querybuilder.
@param QueryBuilder $queryBuilder | [
"Assigns",
"ORDER",
"BY",
"clauses",
"to",
"querybuilder",
"."
] | 6766a36cc2f0c807c59202bf7540a08c4ef31192 | https://github.com/sulu/sulu/blob/6766a36cc2f0c807c59202bf7540a08c4ef31192/src/Sulu/Component/Rest/ListBuilder/Doctrine/DoctrineListBuilder.php#L315-L330 | train |
sulu/sulu | src/Sulu/Component/Rest/ListBuilder/Doctrine/DoctrineListBuilder.php | DoctrineListBuilder.assignGroupBy | protected function assignGroupBy($queryBuilder)
{
if (!empty($this->groupByFields)) {
foreach ($this->groupByFields as $fields) {
$queryBuilder->groupBy($fields->getSelect());
}
}
} | php | protected function assignGroupBy($queryBuilder)
{
if (!empty($this->groupByFields)) {
foreach ($this->groupByFields as $fields) {
$queryBuilder->groupBy($fields->getSelect());
}
}
} | [
"protected",
"function",
"assignGroupBy",
"(",
"$",
"queryBuilder",
")",
"{",
"if",
"(",
"!",
"empty",
"(",
"$",
"this",
"->",
"groupByFields",
")",
")",
"{",
"foreach",
"(",
"$",
"this",
"->",
"groupByFields",
"as",
"$",
"fields",
")",
"{",
"$",
"queryBuilder",
"->",
"groupBy",
"(",
"$",
"fields",
"->",
"getSelect",
"(",
")",
")",
";",
"}",
"}",
"}"
] | Sets group by fields to querybuilder.
@param QueryBuilder $queryBuilder | [
"Sets",
"group",
"by",
"fields",
"to",
"querybuilder",
"."
] | 6766a36cc2f0c807c59202bf7540a08c4ef31192 | https://github.com/sulu/sulu/blob/6766a36cc2f0c807c59202bf7540a08c4ef31192/src/Sulu/Component/Rest/ListBuilder/Doctrine/DoctrineListBuilder.php#L350-L357 | train |
sulu/sulu | src/Sulu/Component/Rest/ListBuilder/Doctrine/DoctrineListBuilder.php | DoctrineListBuilder.getJoins | protected function getJoins()
{
$joins = [];
$fields = array_merge($this->sortFields, $this->selectFields, $this->searchFields, $this->expressionFields);
foreach ($fields as $field) {
$joins = array_merge($joins, $field->getJoins());
}
return $joins;
} | php | protected function getJoins()
{
$joins = [];
$fields = array_merge($this->sortFields, $this->selectFields, $this->searchFields, $this->expressionFields);
foreach ($fields as $field) {
$joins = array_merge($joins, $field->getJoins());
}
return $joins;
} | [
"protected",
"function",
"getJoins",
"(",
")",
"{",
"$",
"joins",
"=",
"[",
"]",
";",
"$",
"fields",
"=",
"array_merge",
"(",
"$",
"this",
"->",
"sortFields",
",",
"$",
"this",
"->",
"selectFields",
",",
"$",
"this",
"->",
"searchFields",
",",
"$",
"this",
"->",
"expressionFields",
")",
";",
"foreach",
"(",
"$",
"fields",
"as",
"$",
"field",
")",
"{",
"$",
"joins",
"=",
"array_merge",
"(",
"$",
"joins",
",",
"$",
"field",
"->",
"getJoins",
"(",
")",
")",
";",
"}",
"return",
"$",
"joins",
";",
"}"
] | Returns all the joins required for the query.
@return DoctrineJoinDescriptor[] | [
"Returns",
"all",
"the",
"joins",
"required",
"for",
"the",
"query",
"."
] | 6766a36cc2f0c807c59202bf7540a08c4ef31192 | https://github.com/sulu/sulu/blob/6766a36cc2f0c807c59202bf7540a08c4ef31192/src/Sulu/Component/Rest/ListBuilder/Doctrine/DoctrineListBuilder.php#L364-L374 | train |
sulu/sulu | src/Sulu/Component/Rest/ListBuilder/Doctrine/DoctrineListBuilder.php | DoctrineListBuilder.getAllFields | protected function getAllFields($onlyReturnFilterFields = false)
{
$fields = array_merge(
$this->searchFields,
$this->sortFields,
$this->getUniqueExpressionFieldDescriptors($this->expressions)
);
if (true !== $onlyReturnFilterFields) {
$fields = array_merge($fields, $this->selectFields);
}
return array_filter($fields, function(FieldDescriptorInterface $fieldDescriptor) {
return $fieldDescriptor instanceof DoctrineFieldDescriptorInterface;
});
} | php | protected function getAllFields($onlyReturnFilterFields = false)
{
$fields = array_merge(
$this->searchFields,
$this->sortFields,
$this->getUniqueExpressionFieldDescriptors($this->expressions)
);
if (true !== $onlyReturnFilterFields) {
$fields = array_merge($fields, $this->selectFields);
}
return array_filter($fields, function(FieldDescriptorInterface $fieldDescriptor) {
return $fieldDescriptor instanceof DoctrineFieldDescriptorInterface;
});
} | [
"protected",
"function",
"getAllFields",
"(",
"$",
"onlyReturnFilterFields",
"=",
"false",
")",
"{",
"$",
"fields",
"=",
"array_merge",
"(",
"$",
"this",
"->",
"searchFields",
",",
"$",
"this",
"->",
"sortFields",
",",
"$",
"this",
"->",
"getUniqueExpressionFieldDescriptors",
"(",
"$",
"this",
"->",
"expressions",
")",
")",
";",
"if",
"(",
"true",
"!==",
"$",
"onlyReturnFilterFields",
")",
"{",
"$",
"fields",
"=",
"array_merge",
"(",
"$",
"fields",
",",
"$",
"this",
"->",
"selectFields",
")",
";",
"}",
"return",
"array_filter",
"(",
"$",
"fields",
",",
"function",
"(",
"FieldDescriptorInterface",
"$",
"fieldDescriptor",
")",
"{",
"return",
"$",
"fieldDescriptor",
"instanceof",
"DoctrineFieldDescriptorInterface",
";",
"}",
")",
";",
"}"
] | Returns all DoctrineFieldDescriptors that were passed to list builder.
@param bool $onlyReturnFilterFields Define if only filtering FieldDescriptors should be returned
@return DoctrineFieldDescriptorInterface[] | [
"Returns",
"all",
"DoctrineFieldDescriptors",
"that",
"were",
"passed",
"to",
"list",
"builder",
"."
] | 6766a36cc2f0c807c59202bf7540a08c4ef31192 | https://github.com/sulu/sulu/blob/6766a36cc2f0c807c59202bf7540a08c4ef31192/src/Sulu/Component/Rest/ListBuilder/Doctrine/DoctrineListBuilder.php#L383-L398 | train |
sulu/sulu | src/Sulu/Component/Rest/ListBuilder/Doctrine/DoctrineListBuilder.php | DoctrineListBuilder.createSubQueryBuilder | protected function createSubQueryBuilder($select = null)
{
if (!$select) {
$select = $this->getSelectAs($this->idField);
}
// get all filter-fields
$filterFields = $this->getAllFields(true);
// get entity names
$entityNames = $this->getEntityNamesOfFieldDescriptors($filterFields);
// get necessary joins to achieve filtering
$addJoins = $this->getNecessaryJoins($entityNames);
// create querybuilder and add select
$queryBuilder = $this->createQueryBuilder($addJoins)->select($select);
if ($this->user && $this->permission && array_key_exists($this->permission, $this->permissions)) {
$this->addAccessControl(
$queryBuilder,
$this->user,
$this->permissions[$this->permission],
$this->securedEntityName,
$this->encodeAlias($this->securedEntityName)
);
}
return $queryBuilder;
} | php | protected function createSubQueryBuilder($select = null)
{
if (!$select) {
$select = $this->getSelectAs($this->idField);
}
// get all filter-fields
$filterFields = $this->getAllFields(true);
// get entity names
$entityNames = $this->getEntityNamesOfFieldDescriptors($filterFields);
// get necessary joins to achieve filtering
$addJoins = $this->getNecessaryJoins($entityNames);
// create querybuilder and add select
$queryBuilder = $this->createQueryBuilder($addJoins)->select($select);
if ($this->user && $this->permission && array_key_exists($this->permission, $this->permissions)) {
$this->addAccessControl(
$queryBuilder,
$this->user,
$this->permissions[$this->permission],
$this->securedEntityName,
$this->encodeAlias($this->securedEntityName)
);
}
return $queryBuilder;
} | [
"protected",
"function",
"createSubQueryBuilder",
"(",
"$",
"select",
"=",
"null",
")",
"{",
"if",
"(",
"!",
"$",
"select",
")",
"{",
"$",
"select",
"=",
"$",
"this",
"->",
"getSelectAs",
"(",
"$",
"this",
"->",
"idField",
")",
";",
"}",
"// get all filter-fields",
"$",
"filterFields",
"=",
"$",
"this",
"->",
"getAllFields",
"(",
"true",
")",
";",
"// get entity names",
"$",
"entityNames",
"=",
"$",
"this",
"->",
"getEntityNamesOfFieldDescriptors",
"(",
"$",
"filterFields",
")",
";",
"// get necessary joins to achieve filtering",
"$",
"addJoins",
"=",
"$",
"this",
"->",
"getNecessaryJoins",
"(",
"$",
"entityNames",
")",
";",
"// create querybuilder and add select",
"$",
"queryBuilder",
"=",
"$",
"this",
"->",
"createQueryBuilder",
"(",
"$",
"addJoins",
")",
"->",
"select",
"(",
"$",
"select",
")",
";",
"if",
"(",
"$",
"this",
"->",
"user",
"&&",
"$",
"this",
"->",
"permission",
"&&",
"array_key_exists",
"(",
"$",
"this",
"->",
"permission",
",",
"$",
"this",
"->",
"permissions",
")",
")",
"{",
"$",
"this",
"->",
"addAccessControl",
"(",
"$",
"queryBuilder",
",",
"$",
"this",
"->",
"user",
",",
"$",
"this",
"->",
"permissions",
"[",
"$",
"this",
"->",
"permission",
"]",
",",
"$",
"this",
"->",
"securedEntityName",
",",
"$",
"this",
"->",
"encodeAlias",
"(",
"$",
"this",
"->",
"securedEntityName",
")",
")",
";",
"}",
"return",
"$",
"queryBuilder",
";",
"}"
] | Creates a query-builder for sub-selecting ID's.
@param null|string $select
@return QueryBuilder | [
"Creates",
"a",
"query",
"-",
"builder",
"for",
"sub",
"-",
"selecting",
"ID",
"s",
"."
] | 6766a36cc2f0c807c59202bf7540a08c4ef31192 | https://github.com/sulu/sulu/blob/6766a36cc2f0c807c59202bf7540a08c4ef31192/src/Sulu/Component/Rest/ListBuilder/Doctrine/DoctrineListBuilder.php#L407-L436 | train |
sulu/sulu | src/Sulu/Component/Rest/ListBuilder/Doctrine/DoctrineListBuilder.php | DoctrineListBuilder.getNecessaryJoins | protected function getNecessaryJoins($necessaryEntityNames)
{
$addJoins = [];
// iterate through all field descriptors to find necessary joins
foreach ($this->getAllFields() as $key => $field) {
// if field is in any conditional clause -> add join
if (($field instanceof DoctrineFieldDescriptor || $field instanceof DoctrineJoinDescriptor) &&
false !== array_search($field->getEntityName(), $necessaryEntityNames)
&& $field->getEntityName() !== $this->entityName
) {
$addJoins = array_merge($addJoins, $field->getJoins());
} else {
// include inner joins
foreach ($field->getJoins() as $entityName => $join) {
if (DoctrineJoinDescriptor::JOIN_METHOD_INNER !== $join->getJoinMethod() &&
false === array_search($entityName, $necessaryEntityNames)
) {
break;
}
$addJoins = array_merge($addJoins, [$entityName => $join]);
}
}
}
if ($this->user && $this->permission && array_key_exists($this->permission, $this->permissions)) {
foreach ($this->permissionCheckFields as $permissionCheckField) {
$addJoins = array_merge($addJoins, $permissionCheckField->getJoins());
}
}
return $addJoins;
} | php | protected function getNecessaryJoins($necessaryEntityNames)
{
$addJoins = [];
// iterate through all field descriptors to find necessary joins
foreach ($this->getAllFields() as $key => $field) {
// if field is in any conditional clause -> add join
if (($field instanceof DoctrineFieldDescriptor || $field instanceof DoctrineJoinDescriptor) &&
false !== array_search($field->getEntityName(), $necessaryEntityNames)
&& $field->getEntityName() !== $this->entityName
) {
$addJoins = array_merge($addJoins, $field->getJoins());
} else {
// include inner joins
foreach ($field->getJoins() as $entityName => $join) {
if (DoctrineJoinDescriptor::JOIN_METHOD_INNER !== $join->getJoinMethod() &&
false === array_search($entityName, $necessaryEntityNames)
) {
break;
}
$addJoins = array_merge($addJoins, [$entityName => $join]);
}
}
}
if ($this->user && $this->permission && array_key_exists($this->permission, $this->permissions)) {
foreach ($this->permissionCheckFields as $permissionCheckField) {
$addJoins = array_merge($addJoins, $permissionCheckField->getJoins());
}
}
return $addJoins;
} | [
"protected",
"function",
"getNecessaryJoins",
"(",
"$",
"necessaryEntityNames",
")",
"{",
"$",
"addJoins",
"=",
"[",
"]",
";",
"// iterate through all field descriptors to find necessary joins",
"foreach",
"(",
"$",
"this",
"->",
"getAllFields",
"(",
")",
"as",
"$",
"key",
"=>",
"$",
"field",
")",
"{",
"// if field is in any conditional clause -> add join",
"if",
"(",
"(",
"$",
"field",
"instanceof",
"DoctrineFieldDescriptor",
"||",
"$",
"field",
"instanceof",
"DoctrineJoinDescriptor",
")",
"&&",
"false",
"!==",
"array_search",
"(",
"$",
"field",
"->",
"getEntityName",
"(",
")",
",",
"$",
"necessaryEntityNames",
")",
"&&",
"$",
"field",
"->",
"getEntityName",
"(",
")",
"!==",
"$",
"this",
"->",
"entityName",
")",
"{",
"$",
"addJoins",
"=",
"array_merge",
"(",
"$",
"addJoins",
",",
"$",
"field",
"->",
"getJoins",
"(",
")",
")",
";",
"}",
"else",
"{",
"// include inner joins",
"foreach",
"(",
"$",
"field",
"->",
"getJoins",
"(",
")",
"as",
"$",
"entityName",
"=>",
"$",
"join",
")",
"{",
"if",
"(",
"DoctrineJoinDescriptor",
"::",
"JOIN_METHOD_INNER",
"!==",
"$",
"join",
"->",
"getJoinMethod",
"(",
")",
"&&",
"false",
"===",
"array_search",
"(",
"$",
"entityName",
",",
"$",
"necessaryEntityNames",
")",
")",
"{",
"break",
";",
"}",
"$",
"addJoins",
"=",
"array_merge",
"(",
"$",
"addJoins",
",",
"[",
"$",
"entityName",
"=>",
"$",
"join",
"]",
")",
";",
"}",
"}",
"}",
"if",
"(",
"$",
"this",
"->",
"user",
"&&",
"$",
"this",
"->",
"permission",
"&&",
"array_key_exists",
"(",
"$",
"this",
"->",
"permission",
",",
"$",
"this",
"->",
"permissions",
")",
")",
"{",
"foreach",
"(",
"$",
"this",
"->",
"permissionCheckFields",
"as",
"$",
"permissionCheckField",
")",
"{",
"$",
"addJoins",
"=",
"array_merge",
"(",
"$",
"addJoins",
",",
"$",
"permissionCheckField",
"->",
"getJoins",
"(",
")",
")",
";",
"}",
"}",
"return",
"$",
"addJoins",
";",
"}"
] | Function returns all necessary joins for filtering result.
@param string[] $necessaryEntityNames
@return DoctrineFieldDescriptorInterface[] | [
"Function",
"returns",
"all",
"necessary",
"joins",
"for",
"filtering",
"result",
"."
] | 6766a36cc2f0c807c59202bf7540a08c4ef31192 | https://github.com/sulu/sulu/blob/6766a36cc2f0c807c59202bf7540a08c4ef31192/src/Sulu/Component/Rest/ListBuilder/Doctrine/DoctrineListBuilder.php#L445-L477 | train |
sulu/sulu | src/Sulu/Component/Rest/ListBuilder/Doctrine/DoctrineListBuilder.php | DoctrineListBuilder.getEntityNamesOfFieldDescriptors | protected function getEntityNamesOfFieldDescriptors($filterFields)
{
$fields = [];
// filter array for DoctrineFieldDescriptors
foreach ($filterFields as $field) {
// add joins of field
$fields = array_merge($fields, $field->getJoins());
if ($field instanceof DoctrineFieldDescriptor
|| $field instanceof DoctrineJoinDescriptor
) {
$fields[] = $field;
}
}
$fieldEntityNames = [];
foreach ($fields as $key => $field) {
// special treatment for join descriptors
if ($field instanceof DoctrineJoinDescriptor) {
$fieldEntityNames[] = $key;
}
$fieldEntityNames[] = $field->getEntityName();
}
// unify result
return array_unique($fieldEntityNames);
} | php | protected function getEntityNamesOfFieldDescriptors($filterFields)
{
$fields = [];
// filter array for DoctrineFieldDescriptors
foreach ($filterFields as $field) {
// add joins of field
$fields = array_merge($fields, $field->getJoins());
if ($field instanceof DoctrineFieldDescriptor
|| $field instanceof DoctrineJoinDescriptor
) {
$fields[] = $field;
}
}
$fieldEntityNames = [];
foreach ($fields as $key => $field) {
// special treatment for join descriptors
if ($field instanceof DoctrineJoinDescriptor) {
$fieldEntityNames[] = $key;
}
$fieldEntityNames[] = $field->getEntityName();
}
// unify result
return array_unique($fieldEntityNames);
} | [
"protected",
"function",
"getEntityNamesOfFieldDescriptors",
"(",
"$",
"filterFields",
")",
"{",
"$",
"fields",
"=",
"[",
"]",
";",
"// filter array for DoctrineFieldDescriptors",
"foreach",
"(",
"$",
"filterFields",
"as",
"$",
"field",
")",
"{",
"// add joins of field",
"$",
"fields",
"=",
"array_merge",
"(",
"$",
"fields",
",",
"$",
"field",
"->",
"getJoins",
"(",
")",
")",
";",
"if",
"(",
"$",
"field",
"instanceof",
"DoctrineFieldDescriptor",
"||",
"$",
"field",
"instanceof",
"DoctrineJoinDescriptor",
")",
"{",
"$",
"fields",
"[",
"]",
"=",
"$",
"field",
";",
"}",
"}",
"$",
"fieldEntityNames",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"fields",
"as",
"$",
"key",
"=>",
"$",
"field",
")",
"{",
"// special treatment for join descriptors",
"if",
"(",
"$",
"field",
"instanceof",
"DoctrineJoinDescriptor",
")",
"{",
"$",
"fieldEntityNames",
"[",
"]",
"=",
"$",
"key",
";",
"}",
"$",
"fieldEntityNames",
"[",
"]",
"=",
"$",
"field",
"->",
"getEntityName",
"(",
")",
";",
"}",
"// unify result",
"return",
"array_unique",
"(",
"$",
"fieldEntityNames",
")",
";",
"}"
] | Returns array of field-descriptor aliases.
@param array $filterFields
@return string[] | [
"Returns",
"array",
"of",
"field",
"-",
"descriptor",
"aliases",
"."
] | 6766a36cc2f0c807c59202bf7540a08c4ef31192 | https://github.com/sulu/sulu/blob/6766a36cc2f0c807c59202bf7540a08c4ef31192/src/Sulu/Component/Rest/ListBuilder/Doctrine/DoctrineListBuilder.php#L486-L513 | train |
sulu/sulu | src/Sulu/Component/Rest/ListBuilder/Doctrine/DoctrineListBuilder.php | DoctrineListBuilder.createQueryBuilder | protected function createQueryBuilder($joins = null)
{
$this->queryBuilder = $this->em->createQueryBuilder()
->from($this->entityName, $this->encodeAlias($this->entityName));
$this->assignJoins($this->queryBuilder, $joins);
if (null !== $this->ids) {
$this->in($this->idField, !empty($this->ids) ? $this->ids : [null]);
}
if (null !== $this->excludedIds && !empty($this->excludedIds)) {
$this->notIn($this->idField, $this->excludedIds);
}
// set expressions
if (!empty($this->expressions)) {
foreach ($this->expressions as $expression) {
$this->queryBuilder->andWhere('(' . $expression->getStatement($this->queryBuilder) . ')');
}
}
$this->assignGroupBy($this->queryBuilder);
if (null !== $this->search) {
$searchParts = [];
foreach ($this->searchFields as $searchField) {
$searchParts[] = $searchField->getSearch();
}
$this->queryBuilder->andWhere('(' . implode(' OR ', $searchParts) . ')');
$this->queryBuilder->setParameter('search', '%' . str_replace('*', '%', $this->search) . '%');
}
return $this->queryBuilder;
} | php | protected function createQueryBuilder($joins = null)
{
$this->queryBuilder = $this->em->createQueryBuilder()
->from($this->entityName, $this->encodeAlias($this->entityName));
$this->assignJoins($this->queryBuilder, $joins);
if (null !== $this->ids) {
$this->in($this->idField, !empty($this->ids) ? $this->ids : [null]);
}
if (null !== $this->excludedIds && !empty($this->excludedIds)) {
$this->notIn($this->idField, $this->excludedIds);
}
// set expressions
if (!empty($this->expressions)) {
foreach ($this->expressions as $expression) {
$this->queryBuilder->andWhere('(' . $expression->getStatement($this->queryBuilder) . ')');
}
}
$this->assignGroupBy($this->queryBuilder);
if (null !== $this->search) {
$searchParts = [];
foreach ($this->searchFields as $searchField) {
$searchParts[] = $searchField->getSearch();
}
$this->queryBuilder->andWhere('(' . implode(' OR ', $searchParts) . ')');
$this->queryBuilder->setParameter('search', '%' . str_replace('*', '%', $this->search) . '%');
}
return $this->queryBuilder;
} | [
"protected",
"function",
"createQueryBuilder",
"(",
"$",
"joins",
"=",
"null",
")",
"{",
"$",
"this",
"->",
"queryBuilder",
"=",
"$",
"this",
"->",
"em",
"->",
"createQueryBuilder",
"(",
")",
"->",
"from",
"(",
"$",
"this",
"->",
"entityName",
",",
"$",
"this",
"->",
"encodeAlias",
"(",
"$",
"this",
"->",
"entityName",
")",
")",
";",
"$",
"this",
"->",
"assignJoins",
"(",
"$",
"this",
"->",
"queryBuilder",
",",
"$",
"joins",
")",
";",
"if",
"(",
"null",
"!==",
"$",
"this",
"->",
"ids",
")",
"{",
"$",
"this",
"->",
"in",
"(",
"$",
"this",
"->",
"idField",
",",
"!",
"empty",
"(",
"$",
"this",
"->",
"ids",
")",
"?",
"$",
"this",
"->",
"ids",
":",
"[",
"null",
"]",
")",
";",
"}",
"if",
"(",
"null",
"!==",
"$",
"this",
"->",
"excludedIds",
"&&",
"!",
"empty",
"(",
"$",
"this",
"->",
"excludedIds",
")",
")",
"{",
"$",
"this",
"->",
"notIn",
"(",
"$",
"this",
"->",
"idField",
",",
"$",
"this",
"->",
"excludedIds",
")",
";",
"}",
"// set expressions",
"if",
"(",
"!",
"empty",
"(",
"$",
"this",
"->",
"expressions",
")",
")",
"{",
"foreach",
"(",
"$",
"this",
"->",
"expressions",
"as",
"$",
"expression",
")",
"{",
"$",
"this",
"->",
"queryBuilder",
"->",
"andWhere",
"(",
"'('",
".",
"$",
"expression",
"->",
"getStatement",
"(",
"$",
"this",
"->",
"queryBuilder",
")",
".",
"')'",
")",
";",
"}",
"}",
"$",
"this",
"->",
"assignGroupBy",
"(",
"$",
"this",
"->",
"queryBuilder",
")",
";",
"if",
"(",
"null",
"!==",
"$",
"this",
"->",
"search",
")",
"{",
"$",
"searchParts",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"this",
"->",
"searchFields",
"as",
"$",
"searchField",
")",
"{",
"$",
"searchParts",
"[",
"]",
"=",
"$",
"searchField",
"->",
"getSearch",
"(",
")",
";",
"}",
"$",
"this",
"->",
"queryBuilder",
"->",
"andWhere",
"(",
"'('",
".",
"implode",
"(",
"' OR '",
",",
"$",
"searchParts",
")",
".",
"')'",
")",
";",
"$",
"this",
"->",
"queryBuilder",
"->",
"setParameter",
"(",
"'search'",
",",
"'%'",
".",
"str_replace",
"(",
"'*'",
",",
"'%'",
",",
"$",
"this",
"->",
"search",
")",
".",
"'%'",
")",
";",
"}",
"return",
"$",
"this",
"->",
"queryBuilder",
";",
"}"
] | Creates Querybuilder.
@param array|null $joins Define which joins should be made
@return \Doctrine\ORM\QueryBuilder | [
"Creates",
"Querybuilder",
"."
] | 6766a36cc2f0c807c59202bf7540a08c4ef31192 | https://github.com/sulu/sulu/blob/6766a36cc2f0c807c59202bf7540a08c4ef31192/src/Sulu/Component/Rest/ListBuilder/Doctrine/DoctrineListBuilder.php#L522-L557 | train |
sulu/sulu | src/Sulu/Component/Rest/ListBuilder/Doctrine/DoctrineListBuilder.php | DoctrineListBuilder.assignJoins | protected function assignJoins(QueryBuilder $queryBuilder, array $joins = null)
{
if (null === $joins) {
$joins = $this->getJoins();
}
foreach ($joins as $entity => $join) {
switch ($join->getJoinMethod()) {
case DoctrineJoinDescriptor::JOIN_METHOD_LEFT:
$queryBuilder->leftJoin(
$join->getJoin() ?: $entity,
$this->encodeAlias($entity),
$join->getJoinConditionMethod(),
$join->getJoinCondition()
);
break;
case DoctrineJoinDescriptor::JOIN_METHOD_INNER:
$queryBuilder->innerJoin(
$join->getJoin() ?: $entity,
$this->encodeAlias($entity),
$join->getJoinConditionMethod(),
$join->getJoinCondition()
);
break;
}
}
} | php | protected function assignJoins(QueryBuilder $queryBuilder, array $joins = null)
{
if (null === $joins) {
$joins = $this->getJoins();
}
foreach ($joins as $entity => $join) {
switch ($join->getJoinMethod()) {
case DoctrineJoinDescriptor::JOIN_METHOD_LEFT:
$queryBuilder->leftJoin(
$join->getJoin() ?: $entity,
$this->encodeAlias($entity),
$join->getJoinConditionMethod(),
$join->getJoinCondition()
);
break;
case DoctrineJoinDescriptor::JOIN_METHOD_INNER:
$queryBuilder->innerJoin(
$join->getJoin() ?: $entity,
$this->encodeAlias($entity),
$join->getJoinConditionMethod(),
$join->getJoinCondition()
);
break;
}
}
} | [
"protected",
"function",
"assignJoins",
"(",
"QueryBuilder",
"$",
"queryBuilder",
",",
"array",
"$",
"joins",
"=",
"null",
")",
"{",
"if",
"(",
"null",
"===",
"$",
"joins",
")",
"{",
"$",
"joins",
"=",
"$",
"this",
"->",
"getJoins",
"(",
")",
";",
"}",
"foreach",
"(",
"$",
"joins",
"as",
"$",
"entity",
"=>",
"$",
"join",
")",
"{",
"switch",
"(",
"$",
"join",
"->",
"getJoinMethod",
"(",
")",
")",
"{",
"case",
"DoctrineJoinDescriptor",
"::",
"JOIN_METHOD_LEFT",
":",
"$",
"queryBuilder",
"->",
"leftJoin",
"(",
"$",
"join",
"->",
"getJoin",
"(",
")",
"?",
":",
"$",
"entity",
",",
"$",
"this",
"->",
"encodeAlias",
"(",
"$",
"entity",
")",
",",
"$",
"join",
"->",
"getJoinConditionMethod",
"(",
")",
",",
"$",
"join",
"->",
"getJoinCondition",
"(",
")",
")",
";",
"break",
";",
"case",
"DoctrineJoinDescriptor",
"::",
"JOIN_METHOD_INNER",
":",
"$",
"queryBuilder",
"->",
"innerJoin",
"(",
"$",
"join",
"->",
"getJoin",
"(",
")",
"?",
":",
"$",
"entity",
",",
"$",
"this",
"->",
"encodeAlias",
"(",
"$",
"entity",
")",
",",
"$",
"join",
"->",
"getJoinConditionMethod",
"(",
")",
",",
"$",
"join",
"->",
"getJoinCondition",
"(",
")",
")",
";",
"break",
";",
"}",
"}",
"}"
] | Adds joins to querybuilder.
@param QueryBuilder $queryBuilder
@param array $joins | [
"Adds",
"joins",
"to",
"querybuilder",
"."
] | 6766a36cc2f0c807c59202bf7540a08c4ef31192 | https://github.com/sulu/sulu/blob/6766a36cc2f0c807c59202bf7540a08c4ef31192/src/Sulu/Component/Rest/ListBuilder/Doctrine/DoctrineListBuilder.php#L565-L591 | train |
sulu/sulu | src/Sulu/Component/Rest/ListBuilder/Doctrine/DoctrineListBuilder.php | DoctrineListBuilder.getUniqueExpressionFieldDescriptors | protected function getUniqueExpressionFieldDescriptors(array $expressions)
{
if (0 === count($this->expressionFields)) {
$descriptors = [];
$uniqueNames = array_unique($this->getAllFieldNames($expressions));
foreach ($uniqueNames as $uniqueName) {
$descriptors[] = $this->fieldDescriptors[$uniqueName];
}
$this->expressionFields = $descriptors;
return $descriptors;
}
return $this->expressionFields;
} | php | protected function getUniqueExpressionFieldDescriptors(array $expressions)
{
if (0 === count($this->expressionFields)) {
$descriptors = [];
$uniqueNames = array_unique($this->getAllFieldNames($expressions));
foreach ($uniqueNames as $uniqueName) {
$descriptors[] = $this->fieldDescriptors[$uniqueName];
}
$this->expressionFields = $descriptors;
return $descriptors;
}
return $this->expressionFields;
} | [
"protected",
"function",
"getUniqueExpressionFieldDescriptors",
"(",
"array",
"$",
"expressions",
")",
"{",
"if",
"(",
"0",
"===",
"count",
"(",
"$",
"this",
"->",
"expressionFields",
")",
")",
"{",
"$",
"descriptors",
"=",
"[",
"]",
";",
"$",
"uniqueNames",
"=",
"array_unique",
"(",
"$",
"this",
"->",
"getAllFieldNames",
"(",
"$",
"expressions",
")",
")",
";",
"foreach",
"(",
"$",
"uniqueNames",
"as",
"$",
"uniqueName",
")",
"{",
"$",
"descriptors",
"[",
"]",
"=",
"$",
"this",
"->",
"fieldDescriptors",
"[",
"$",
"uniqueName",
"]",
";",
"}",
"$",
"this",
"->",
"expressionFields",
"=",
"$",
"descriptors",
";",
"return",
"$",
"descriptors",
";",
"}",
"return",
"$",
"this",
"->",
"expressionFields",
";",
"}"
] | Returns an array of unique expression field descriptors.
@param AbstractDoctrineExpression[] $expressions
@return array | [
"Returns",
"an",
"array",
"of",
"unique",
"expression",
"field",
"descriptors",
"."
] | 6766a36cc2f0c807c59202bf7540a08c4ef31192 | https://github.com/sulu/sulu/blob/6766a36cc2f0c807c59202bf7540a08c4ef31192/src/Sulu/Component/Rest/ListBuilder/Doctrine/DoctrineListBuilder.php#L668-L683 | train |
sulu/sulu | src/Sulu/Component/Rest/ListBuilder/Doctrine/DoctrineListBuilder.php | DoctrineListBuilder.getAllFieldNames | protected function getAllFieldNames($expressions)
{
$fieldNames = [];
foreach ($expressions as $expression) {
if ($expression instanceof ConjunctionExpressionInterface) {
$fieldNames = array_merge($fieldNames, $expression->getFieldNames());
} elseif ($expression instanceof BasicExpressionInterface) {
$fieldNames[] = $expression->getFieldName();
}
}
return $fieldNames;
} | php | protected function getAllFieldNames($expressions)
{
$fieldNames = [];
foreach ($expressions as $expression) {
if ($expression instanceof ConjunctionExpressionInterface) {
$fieldNames = array_merge($fieldNames, $expression->getFieldNames());
} elseif ($expression instanceof BasicExpressionInterface) {
$fieldNames[] = $expression->getFieldName();
}
}
return $fieldNames;
} | [
"protected",
"function",
"getAllFieldNames",
"(",
"$",
"expressions",
")",
"{",
"$",
"fieldNames",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"expressions",
"as",
"$",
"expression",
")",
"{",
"if",
"(",
"$",
"expression",
"instanceof",
"ConjunctionExpressionInterface",
")",
"{",
"$",
"fieldNames",
"=",
"array_merge",
"(",
"$",
"fieldNames",
",",
"$",
"expression",
"->",
"getFieldNames",
"(",
")",
")",
";",
"}",
"elseif",
"(",
"$",
"expression",
"instanceof",
"BasicExpressionInterface",
")",
"{",
"$",
"fieldNames",
"[",
"]",
"=",
"$",
"expression",
"->",
"getFieldName",
"(",
")",
";",
"}",
"}",
"return",
"$",
"fieldNames",
";",
"}"
] | Returns all fieldnames used in the expressions.
@param AbstractDoctrineExpression[] $expressions
@return array | [
"Returns",
"all",
"fieldnames",
"used",
"in",
"the",
"expressions",
"."
] | 6766a36cc2f0c807c59202bf7540a08c4ef31192 | https://github.com/sulu/sulu/blob/6766a36cc2f0c807c59202bf7540a08c4ef31192/src/Sulu/Component/Rest/ListBuilder/Doctrine/DoctrineListBuilder.php#L692-L704 | train |
sulu/sulu | src/Sulu/Component/Rest/ListBuilder/Doctrine/DoctrineListBuilder.php | DoctrineListBuilder.getSelectAs | private function getSelectAs(DoctrineFieldDescriptorInterface $field, $hidden = false)
{
$select = $field->getSelect() . ' AS ';
if ($hidden) {
$select .= 'HIDDEN ';
}
return $select . $field->getName();
} | php | private function getSelectAs(DoctrineFieldDescriptorInterface $field, $hidden = false)
{
$select = $field->getSelect() . ' AS ';
if ($hidden) {
$select .= 'HIDDEN ';
}
return $select . $field->getName();
} | [
"private",
"function",
"getSelectAs",
"(",
"DoctrineFieldDescriptorInterface",
"$",
"field",
",",
"$",
"hidden",
"=",
"false",
")",
"{",
"$",
"select",
"=",
"$",
"field",
"->",
"getSelect",
"(",
")",
".",
"' AS '",
";",
"if",
"(",
"$",
"hidden",
")",
"{",
"$",
"select",
".=",
"'HIDDEN '",
";",
"}",
"return",
"$",
"select",
".",
"$",
"field",
"->",
"getName",
"(",
")",
";",
"}"
] | Get select as from doctrine field descriptor.
@param DoctrineFieldDescriptorInterface $field
@param bool $hidden
@return string | [
"Get",
"select",
"as",
"from",
"doctrine",
"field",
"descriptor",
"."
] | 6766a36cc2f0c807c59202bf7540a08c4ef31192 | https://github.com/sulu/sulu/blob/6766a36cc2f0c807c59202bf7540a08c4ef31192/src/Sulu/Component/Rest/ListBuilder/Doctrine/DoctrineListBuilder.php#L738-L747 | train |
sulu/sulu | src/Sulu/Component/DocumentManager/Subscriber/Phpcr/ReorderSubscriber.php | ReorderSubscriber.handleReorder | public function handleReorder(ReorderEvent $event)
{
$this->nodeHelper->reorder($event->getNode(), $event->getDestId());
} | php | public function handleReorder(ReorderEvent $event)
{
$this->nodeHelper->reorder($event->getNode(), $event->getDestId());
} | [
"public",
"function",
"handleReorder",
"(",
"ReorderEvent",
"$",
"event",
")",
"{",
"$",
"this",
"->",
"nodeHelper",
"->",
"reorder",
"(",
"$",
"event",
"->",
"getNode",
"(",
")",
",",
"$",
"event",
"->",
"getDestId",
"(",
")",
")",
";",
"}"
] | Handle the reorder operation.
@param ReorderEvent $event
@throws DocumentManagerException | [
"Handle",
"the",
"reorder",
"operation",
"."
] | 6766a36cc2f0c807c59202bf7540a08c4ef31192 | https://github.com/sulu/sulu/blob/6766a36cc2f0c807c59202bf7540a08c4ef31192/src/Sulu/Component/DocumentManager/Subscriber/Phpcr/ReorderSubscriber.php#L52-L55 | train |
sulu/sulu | src/Sulu/Bundle/AudienceTargetingBundle/Controller/TargetGroupController.php | TargetGroupController.cgetAction | public function cgetAction(Request $request)
{
$restHelper = $this->get('sulu_core.doctrine_rest_helper');
$factory = $this->get('sulu_core.doctrine_list_builder_factory');
$listBuilder = $factory->create($this->getTargetGroupRepository()->getClassName());
$fieldDescriptors = $this->getFieldDescriptors();
$restHelper->initializeListBuilder($listBuilder, $fieldDescriptors);
// If webspaces are concatinated we need to group by id. This happens
// when no fields are supplied at all OR webspaces are requested as field.
$fieldsParam = $request->get('fields');
$fields = explode(',', $fieldsParam);
if (null === $fieldsParam || false !== array_search('webspaceKeys', $fields)) {
$listBuilder->addGroupBy($fieldDescriptors['id']);
}
$results = $listBuilder->execute();
$list = new ListRepresentation(
$results,
'target-groups',
'get_target-groups',
$request->query->all(),
$listBuilder->getCurrentPage(),
$listBuilder->getLimit(),
$listBuilder->count()
);
return $this->handleView($this->view($list, 200));
} | php | public function cgetAction(Request $request)
{
$restHelper = $this->get('sulu_core.doctrine_rest_helper');
$factory = $this->get('sulu_core.doctrine_list_builder_factory');
$listBuilder = $factory->create($this->getTargetGroupRepository()->getClassName());
$fieldDescriptors = $this->getFieldDescriptors();
$restHelper->initializeListBuilder($listBuilder, $fieldDescriptors);
// If webspaces are concatinated we need to group by id. This happens
// when no fields are supplied at all OR webspaces are requested as field.
$fieldsParam = $request->get('fields');
$fields = explode(',', $fieldsParam);
if (null === $fieldsParam || false !== array_search('webspaceKeys', $fields)) {
$listBuilder->addGroupBy($fieldDescriptors['id']);
}
$results = $listBuilder->execute();
$list = new ListRepresentation(
$results,
'target-groups',
'get_target-groups',
$request->query->all(),
$listBuilder->getCurrentPage(),
$listBuilder->getLimit(),
$listBuilder->count()
);
return $this->handleView($this->view($list, 200));
} | [
"public",
"function",
"cgetAction",
"(",
"Request",
"$",
"request",
")",
"{",
"$",
"restHelper",
"=",
"$",
"this",
"->",
"get",
"(",
"'sulu_core.doctrine_rest_helper'",
")",
";",
"$",
"factory",
"=",
"$",
"this",
"->",
"get",
"(",
"'sulu_core.doctrine_list_builder_factory'",
")",
";",
"$",
"listBuilder",
"=",
"$",
"factory",
"->",
"create",
"(",
"$",
"this",
"->",
"getTargetGroupRepository",
"(",
")",
"->",
"getClassName",
"(",
")",
")",
";",
"$",
"fieldDescriptors",
"=",
"$",
"this",
"->",
"getFieldDescriptors",
"(",
")",
";",
"$",
"restHelper",
"->",
"initializeListBuilder",
"(",
"$",
"listBuilder",
",",
"$",
"fieldDescriptors",
")",
";",
"// If webspaces are concatinated we need to group by id. This happens",
"// when no fields are supplied at all OR webspaces are requested as field.",
"$",
"fieldsParam",
"=",
"$",
"request",
"->",
"get",
"(",
"'fields'",
")",
";",
"$",
"fields",
"=",
"explode",
"(",
"','",
",",
"$",
"fieldsParam",
")",
";",
"if",
"(",
"null",
"===",
"$",
"fieldsParam",
"||",
"false",
"!==",
"array_search",
"(",
"'webspaceKeys'",
",",
"$",
"fields",
")",
")",
"{",
"$",
"listBuilder",
"->",
"addGroupBy",
"(",
"$",
"fieldDescriptors",
"[",
"'id'",
"]",
")",
";",
"}",
"$",
"results",
"=",
"$",
"listBuilder",
"->",
"execute",
"(",
")",
";",
"$",
"list",
"=",
"new",
"ListRepresentation",
"(",
"$",
"results",
",",
"'target-groups'",
",",
"'get_target-groups'",
",",
"$",
"request",
"->",
"query",
"->",
"all",
"(",
")",
",",
"$",
"listBuilder",
"->",
"getCurrentPage",
"(",
")",
",",
"$",
"listBuilder",
"->",
"getLimit",
"(",
")",
",",
"$",
"listBuilder",
"->",
"count",
"(",
")",
")",
";",
"return",
"$",
"this",
"->",
"handleView",
"(",
"$",
"this",
"->",
"view",
"(",
"$",
"list",
",",
"200",
")",
")",
";",
"}"
] | Returns list of target-groups.
@param Request $request
@return Response | [
"Returns",
"list",
"of",
"target",
"-",
"groups",
"."
] | 6766a36cc2f0c807c59202bf7540a08c4ef31192 | https://github.com/sulu/sulu/blob/6766a36cc2f0c807c59202bf7540a08c4ef31192/src/Sulu/Bundle/AudienceTargetingBundle/Controller/TargetGroupController.php#L82-L111 | train |
sulu/sulu | src/Sulu/Bundle/AudienceTargetingBundle/Controller/TargetGroupController.php | TargetGroupController.getAction | public function getAction($id)
{
$findCallback = function($id) {
$targetGroup = $this->getTargetGroupRepository()->find($id);
return $targetGroup;
};
$view = $this->responseGetById($id, $findCallback);
return $this->handleView($view);
} | php | public function getAction($id)
{
$findCallback = function($id) {
$targetGroup = $this->getTargetGroupRepository()->find($id);
return $targetGroup;
};
$view = $this->responseGetById($id, $findCallback);
return $this->handleView($view);
} | [
"public",
"function",
"getAction",
"(",
"$",
"id",
")",
"{",
"$",
"findCallback",
"=",
"function",
"(",
"$",
"id",
")",
"{",
"$",
"targetGroup",
"=",
"$",
"this",
"->",
"getTargetGroupRepository",
"(",
")",
"->",
"find",
"(",
"$",
"id",
")",
";",
"return",
"$",
"targetGroup",
";",
"}",
";",
"$",
"view",
"=",
"$",
"this",
"->",
"responseGetById",
"(",
"$",
"id",
",",
"$",
"findCallback",
")",
";",
"return",
"$",
"this",
"->",
"handleView",
"(",
"$",
"view",
")",
";",
"}"
] | Returns a target group by id.
@param int $id
@return Response | [
"Returns",
"a",
"target",
"group",
"by",
"id",
"."
] | 6766a36cc2f0c807c59202bf7540a08c4ef31192 | https://github.com/sulu/sulu/blob/6766a36cc2f0c807c59202bf7540a08c4ef31192/src/Sulu/Bundle/AudienceTargetingBundle/Controller/TargetGroupController.php#L120-L131 | train |
sulu/sulu | src/Sulu/Bundle/AudienceTargetingBundle/Controller/TargetGroupController.php | TargetGroupController.postAction | public function postAction(Request $request)
{
$targetGroup = $this->deserializeData($request->getContent());
$targetGroup = $this->getTargetGroupRepository()->save($targetGroup);
$this->getEntityManager()->flush();
return $this->handleView($this->view($targetGroup));
} | php | public function postAction(Request $request)
{
$targetGroup = $this->deserializeData($request->getContent());
$targetGroup = $this->getTargetGroupRepository()->save($targetGroup);
$this->getEntityManager()->flush();
return $this->handleView($this->view($targetGroup));
} | [
"public",
"function",
"postAction",
"(",
"Request",
"$",
"request",
")",
"{",
"$",
"targetGroup",
"=",
"$",
"this",
"->",
"deserializeData",
"(",
"$",
"request",
"->",
"getContent",
"(",
")",
")",
";",
"$",
"targetGroup",
"=",
"$",
"this",
"->",
"getTargetGroupRepository",
"(",
")",
"->",
"save",
"(",
"$",
"targetGroup",
")",
";",
"$",
"this",
"->",
"getEntityManager",
"(",
")",
"->",
"flush",
"(",
")",
";",
"return",
"$",
"this",
"->",
"handleView",
"(",
"$",
"this",
"->",
"view",
"(",
"$",
"targetGroup",
")",
")",
";",
"}"
] | Handle post request for target group.
@param Request $request
@return Response | [
"Handle",
"post",
"request",
"for",
"target",
"group",
"."
] | 6766a36cc2f0c807c59202bf7540a08c4ef31192 | https://github.com/sulu/sulu/blob/6766a36cc2f0c807c59202bf7540a08c4ef31192/src/Sulu/Bundle/AudienceTargetingBundle/Controller/TargetGroupController.php#L140-L148 | train |
sulu/sulu | src/Sulu/Bundle/AudienceTargetingBundle/Controller/TargetGroupController.php | TargetGroupController.putAction | public function putAction(Request $request, $id)
{
$jsonData = $request->getContent();
$data = json_decode($jsonData, true);
// Id should be taken of request uri.
$data['id'] = $id;
$targetGroup = $this->deserializeData(json_encode($data));
$targetGroup = $this->getTargetGroupRepository()->save($targetGroup);
$this->getEntityManager()->flush();
return $this->handleView($this->view($targetGroup));
} | php | public function putAction(Request $request, $id)
{
$jsonData = $request->getContent();
$data = json_decode($jsonData, true);
// Id should be taken of request uri.
$data['id'] = $id;
$targetGroup = $this->deserializeData(json_encode($data));
$targetGroup = $this->getTargetGroupRepository()->save($targetGroup);
$this->getEntityManager()->flush();
return $this->handleView($this->view($targetGroup));
} | [
"public",
"function",
"putAction",
"(",
"Request",
"$",
"request",
",",
"$",
"id",
")",
"{",
"$",
"jsonData",
"=",
"$",
"request",
"->",
"getContent",
"(",
")",
";",
"$",
"data",
"=",
"json_decode",
"(",
"$",
"jsonData",
",",
"true",
")",
";",
"// Id should be taken of request uri.",
"$",
"data",
"[",
"'id'",
"]",
"=",
"$",
"id",
";",
"$",
"targetGroup",
"=",
"$",
"this",
"->",
"deserializeData",
"(",
"json_encode",
"(",
"$",
"data",
")",
")",
";",
"$",
"targetGroup",
"=",
"$",
"this",
"->",
"getTargetGroupRepository",
"(",
")",
"->",
"save",
"(",
"$",
"targetGroup",
")",
";",
"$",
"this",
"->",
"getEntityManager",
"(",
")",
"->",
"flush",
"(",
")",
";",
"return",
"$",
"this",
"->",
"handleView",
"(",
"$",
"this",
"->",
"view",
"(",
"$",
"targetGroup",
")",
")",
";",
"}"
] | Handle put request for target group.
@param Request $request
@param int $id
@return Response | [
"Handle",
"put",
"request",
"for",
"target",
"group",
"."
] | 6766a36cc2f0c807c59202bf7540a08c4ef31192 | https://github.com/sulu/sulu/blob/6766a36cc2f0c807c59202bf7540a08c4ef31192/src/Sulu/Bundle/AudienceTargetingBundle/Controller/TargetGroupController.php#L158-L171 | train |
sulu/sulu | src/Sulu/Bundle/AudienceTargetingBundle/Controller/TargetGroupController.php | TargetGroupController.deleteAction | public function deleteAction($id)
{
$targetGroup = $this->retrieveTargetGroupById($id);
$this->getEntityManager()->remove($targetGroup);
$this->getEntityManager()->flush();
return $this->handleView($this->view(null, 204));
} | php | public function deleteAction($id)
{
$targetGroup = $this->retrieveTargetGroupById($id);
$this->getEntityManager()->remove($targetGroup);
$this->getEntityManager()->flush();
return $this->handleView($this->view(null, 204));
} | [
"public",
"function",
"deleteAction",
"(",
"$",
"id",
")",
"{",
"$",
"targetGroup",
"=",
"$",
"this",
"->",
"retrieveTargetGroupById",
"(",
"$",
"id",
")",
";",
"$",
"this",
"->",
"getEntityManager",
"(",
")",
"->",
"remove",
"(",
"$",
"targetGroup",
")",
";",
"$",
"this",
"->",
"getEntityManager",
"(",
")",
"->",
"flush",
"(",
")",
";",
"return",
"$",
"this",
"->",
"handleView",
"(",
"$",
"this",
"->",
"view",
"(",
"null",
",",
"204",
")",
")",
";",
"}"
] | Handle delete request for target group.
@param int $id
@return Response | [
"Handle",
"delete",
"request",
"for",
"target",
"group",
"."
] | 6766a36cc2f0c807c59202bf7540a08c4ef31192 | https://github.com/sulu/sulu/blob/6766a36cc2f0c807c59202bf7540a08c4ef31192/src/Sulu/Bundle/AudienceTargetingBundle/Controller/TargetGroupController.php#L180-L188 | train |
sulu/sulu | src/Sulu/Bundle/AudienceTargetingBundle/Controller/TargetGroupController.php | TargetGroupController.cdeleteAction | public function cdeleteAction(Request $request)
{
$idsData = $request->get('ids');
$ids = explode(',', $idsData);
if (!count($ids)) {
throw new MissingParameterException('TargetGroupController', 'ids');
}
$targetGroups = $this->getTargetGroupRepository()->findById($ids);
foreach ($targetGroups as $targetGroup) {
$this->getEntityManager()->remove($targetGroup);
}
$this->getEntityManager()->flush();
return $this->handleView($this->view(null, 204));
} | php | public function cdeleteAction(Request $request)
{
$idsData = $request->get('ids');
$ids = explode(',', $idsData);
if (!count($ids)) {
throw new MissingParameterException('TargetGroupController', 'ids');
}
$targetGroups = $this->getTargetGroupRepository()->findById($ids);
foreach ($targetGroups as $targetGroup) {
$this->getEntityManager()->remove($targetGroup);
}
$this->getEntityManager()->flush();
return $this->handleView($this->view(null, 204));
} | [
"public",
"function",
"cdeleteAction",
"(",
"Request",
"$",
"request",
")",
"{",
"$",
"idsData",
"=",
"$",
"request",
"->",
"get",
"(",
"'ids'",
")",
";",
"$",
"ids",
"=",
"explode",
"(",
"','",
",",
"$",
"idsData",
")",
";",
"if",
"(",
"!",
"count",
"(",
"$",
"ids",
")",
")",
"{",
"throw",
"new",
"MissingParameterException",
"(",
"'TargetGroupController'",
",",
"'ids'",
")",
";",
"}",
"$",
"targetGroups",
"=",
"$",
"this",
"->",
"getTargetGroupRepository",
"(",
")",
"->",
"findById",
"(",
"$",
"ids",
")",
";",
"foreach",
"(",
"$",
"targetGroups",
"as",
"$",
"targetGroup",
")",
"{",
"$",
"this",
"->",
"getEntityManager",
"(",
")",
"->",
"remove",
"(",
"$",
"targetGroup",
")",
";",
"}",
"$",
"this",
"->",
"getEntityManager",
"(",
")",
"->",
"flush",
"(",
")",
";",
"return",
"$",
"this",
"->",
"handleView",
"(",
"$",
"this",
"->",
"view",
"(",
"null",
",",
"204",
")",
")",
";",
"}"
] | Handle multiple delete requests for target groups.
@param Request $request
@throws MissingParameterException
@return Response | [
"Handle",
"multiple",
"delete",
"requests",
"for",
"target",
"groups",
"."
] | 6766a36cc2f0c807c59202bf7540a08c4ef31192 | https://github.com/sulu/sulu/blob/6766a36cc2f0c807c59202bf7540a08c4ef31192/src/Sulu/Bundle/AudienceTargetingBundle/Controller/TargetGroupController.php#L199-L217 | train |
sulu/sulu | src/Sulu/Bundle/AudienceTargetingBundle/Controller/TargetGroupController.php | TargetGroupController.deserializeData | private function deserializeData($data)
{
$result = $this->get('jms_serializer')->deserialize(
$data,
$this->getTargetGroupRepository()->getClassName(),
'json',
DeserializationContext::create()
->setSerializeNull(true)
);
return $result;
} | php | private function deserializeData($data)
{
$result = $this->get('jms_serializer')->deserialize(
$data,
$this->getTargetGroupRepository()->getClassName(),
'json',
DeserializationContext::create()
->setSerializeNull(true)
);
return $result;
} | [
"private",
"function",
"deserializeData",
"(",
"$",
"data",
")",
"{",
"$",
"result",
"=",
"$",
"this",
"->",
"get",
"(",
"'jms_serializer'",
")",
"->",
"deserialize",
"(",
"$",
"data",
",",
"$",
"this",
"->",
"getTargetGroupRepository",
"(",
")",
"->",
"getClassName",
"(",
")",
",",
"'json'",
",",
"DeserializationContext",
"::",
"create",
"(",
")",
"->",
"setSerializeNull",
"(",
"true",
")",
")",
";",
"return",
"$",
"result",
";",
"}"
] | Deserializes string into TargetGroup object.
@param string $data
@return TargetGroupInterface | [
"Deserializes",
"string",
"into",
"TargetGroup",
"object",
"."
] | 6766a36cc2f0c807c59202bf7540a08c4ef31192 | https://github.com/sulu/sulu/blob/6766a36cc2f0c807c59202bf7540a08c4ef31192/src/Sulu/Bundle/AudienceTargetingBundle/Controller/TargetGroupController.php#L226-L237 | train |
sulu/sulu | src/Sulu/Bundle/AudienceTargetingBundle/Controller/TargetGroupController.php | TargetGroupController.retrieveTargetGroupById | private function retrieveTargetGroupById($id)
{
/** @var TargetGroupInterface $targetGroup */
$targetGroup = $this->getTargetGroupRepository()->find($id);
if (!$targetGroup) {
throw new EntityNotFoundException($this->getTargetGroupRepository()->getClassName(), $id);
}
return $targetGroup;
} | php | private function retrieveTargetGroupById($id)
{
/** @var TargetGroupInterface $targetGroup */
$targetGroup = $this->getTargetGroupRepository()->find($id);
if (!$targetGroup) {
throw new EntityNotFoundException($this->getTargetGroupRepository()->getClassName(), $id);
}
return $targetGroup;
} | [
"private",
"function",
"retrieveTargetGroupById",
"(",
"$",
"id",
")",
"{",
"/** @var TargetGroupInterface $targetGroup */",
"$",
"targetGroup",
"=",
"$",
"this",
"->",
"getTargetGroupRepository",
"(",
")",
"->",
"find",
"(",
"$",
"id",
")",
";",
"if",
"(",
"!",
"$",
"targetGroup",
")",
"{",
"throw",
"new",
"EntityNotFoundException",
"(",
"$",
"this",
"->",
"getTargetGroupRepository",
"(",
")",
"->",
"getClassName",
"(",
")",
",",
"$",
"id",
")",
";",
"}",
"return",
"$",
"targetGroup",
";",
"}"
] | Returns target group by id. Throws an exception if not found.
@param int $id
@throws EntityNotFoundException
@return TargetGroupInterface | [
"Returns",
"target",
"group",
"by",
"id",
".",
"Throws",
"an",
"exception",
"if",
"not",
"found",
"."
] | 6766a36cc2f0c807c59202bf7540a08c4ef31192 | https://github.com/sulu/sulu/blob/6766a36cc2f0c807c59202bf7540a08c4ef31192/src/Sulu/Bundle/AudienceTargetingBundle/Controller/TargetGroupController.php#L271-L281 | train |
sulu/sulu | src/Sulu/Bundle/MediaBundle/Controller/MediaStreamController.php | MediaStreamController.cleanUpFileName | private function cleanUpFileName($fileName, $locale, $extension)
{
$pathInfo = pathinfo($fileName);
$cleanedFileName = $this->get('sulu.content.path_cleaner')->cleanup($pathInfo['filename'], $locale);
if ($extension) {
$cleanedFileName .= '.' . $extension;
}
return $cleanedFileName;
} | php | private function cleanUpFileName($fileName, $locale, $extension)
{
$pathInfo = pathinfo($fileName);
$cleanedFileName = $this->get('sulu.content.path_cleaner')->cleanup($pathInfo['filename'], $locale);
if ($extension) {
$cleanedFileName .= '.' . $extension;
}
return $cleanedFileName;
} | [
"private",
"function",
"cleanUpFileName",
"(",
"$",
"fileName",
",",
"$",
"locale",
",",
"$",
"extension",
")",
"{",
"$",
"pathInfo",
"=",
"pathinfo",
"(",
"$",
"fileName",
")",
";",
"$",
"cleanedFileName",
"=",
"$",
"this",
"->",
"get",
"(",
"'sulu.content.path_cleaner'",
")",
"->",
"cleanup",
"(",
"$",
"pathInfo",
"[",
"'filename'",
"]",
",",
"$",
"locale",
")",
";",
"if",
"(",
"$",
"extension",
")",
"{",
"$",
"cleanedFileName",
".=",
"'.'",
".",
"$",
"extension",
";",
"}",
"return",
"$",
"cleanedFileName",
";",
"}"
] | Cleaned up filename.
@param string $fileName
@param string $locale
@param string $extension
@return string | [
"Cleaned",
"up",
"filename",
"."
] | 6766a36cc2f0c807c59202bf7540a08c4ef31192 | https://github.com/sulu/sulu/blob/6766a36cc2f0c807c59202bf7540a08c4ef31192/src/Sulu/Bundle/MediaBundle/Controller/MediaStreamController.php#L225-L234 | train |
sulu/sulu | src/Sulu/Component/Persistence/EventSubscriber/ORM/TimestampableSubscriber.php | TimestampableSubscriber.loadClassMetadata | public function loadClassMetadata(LoadClassMetadataEventArgs $event)
{
$metadata = $event->getClassMetadata();
$reflection = $metadata->getReflectionClass();
if (null !== $reflection && $reflection->implementsInterface('Sulu\Component\Persistence\Model\TimestampableInterface')) {
if (!$metadata->hasField(self::CREATED_FIELD)) {
$metadata->mapField([
'fieldName' => self::CREATED_FIELD,
'type' => 'datetime',
'notnull' => true,
]);
}
if (!$metadata->hasField(self::CHANGED_FIELD)) {
$metadata->mapField([
'fieldName' => self::CHANGED_FIELD,
'type' => 'datetime',
'notnull' => true,
]);
}
}
} | php | public function loadClassMetadata(LoadClassMetadataEventArgs $event)
{
$metadata = $event->getClassMetadata();
$reflection = $metadata->getReflectionClass();
if (null !== $reflection && $reflection->implementsInterface('Sulu\Component\Persistence\Model\TimestampableInterface')) {
if (!$metadata->hasField(self::CREATED_FIELD)) {
$metadata->mapField([
'fieldName' => self::CREATED_FIELD,
'type' => 'datetime',
'notnull' => true,
]);
}
if (!$metadata->hasField(self::CHANGED_FIELD)) {
$metadata->mapField([
'fieldName' => self::CHANGED_FIELD,
'type' => 'datetime',
'notnull' => true,
]);
}
}
} | [
"public",
"function",
"loadClassMetadata",
"(",
"LoadClassMetadataEventArgs",
"$",
"event",
")",
"{",
"$",
"metadata",
"=",
"$",
"event",
"->",
"getClassMetadata",
"(",
")",
";",
"$",
"reflection",
"=",
"$",
"metadata",
"->",
"getReflectionClass",
"(",
")",
";",
"if",
"(",
"null",
"!==",
"$",
"reflection",
"&&",
"$",
"reflection",
"->",
"implementsInterface",
"(",
"'Sulu\\Component\\Persistence\\Model\\TimestampableInterface'",
")",
")",
"{",
"if",
"(",
"!",
"$",
"metadata",
"->",
"hasField",
"(",
"self",
"::",
"CREATED_FIELD",
")",
")",
"{",
"$",
"metadata",
"->",
"mapField",
"(",
"[",
"'fieldName'",
"=>",
"self",
"::",
"CREATED_FIELD",
",",
"'type'",
"=>",
"'datetime'",
",",
"'notnull'",
"=>",
"true",
",",
"]",
")",
";",
"}",
"if",
"(",
"!",
"$",
"metadata",
"->",
"hasField",
"(",
"self",
"::",
"CHANGED_FIELD",
")",
")",
"{",
"$",
"metadata",
"->",
"mapField",
"(",
"[",
"'fieldName'",
"=>",
"self",
"::",
"CHANGED_FIELD",
",",
"'type'",
"=>",
"'datetime'",
",",
"'notnull'",
"=>",
"true",
",",
"]",
")",
";",
"}",
"}",
"}"
] | Load the class data, mapping the created and changed fields
to datetime fields.
@param LoadClassMetadataEventArgs $event | [
"Load",
"the",
"class",
"data",
"mapping",
"the",
"created",
"and",
"changed",
"fields",
"to",
"datetime",
"fields",
"."
] | 6766a36cc2f0c807c59202bf7540a08c4ef31192 | https://github.com/sulu/sulu/blob/6766a36cc2f0c807c59202bf7540a08c4ef31192/src/Sulu/Component/Persistence/EventSubscriber/ORM/TimestampableSubscriber.php#L48-L70 | train |
sulu/sulu | src/Sulu/Component/Persistence/EventSubscriber/ORM/TimestampableSubscriber.php | TimestampableSubscriber.handleTimestamp | private function handleTimestamp(LifecycleEventArgs $event)
{
$entity = $event->getObject();
if (!$entity instanceof TimestampableInterface) {
return;
}
$meta = $event->getObjectManager()->getClassMetadata(get_class($entity));
$created = $meta->getFieldValue($entity, self::CREATED_FIELD);
if (null === $created) {
$meta->setFieldValue($entity, self::CREATED_FIELD, new \DateTime());
}
$meta->setFieldValue($entity, self::CHANGED_FIELD, new \DateTime());
} | php | private function handleTimestamp(LifecycleEventArgs $event)
{
$entity = $event->getObject();
if (!$entity instanceof TimestampableInterface) {
return;
}
$meta = $event->getObjectManager()->getClassMetadata(get_class($entity));
$created = $meta->getFieldValue($entity, self::CREATED_FIELD);
if (null === $created) {
$meta->setFieldValue($entity, self::CREATED_FIELD, new \DateTime());
}
$meta->setFieldValue($entity, self::CHANGED_FIELD, new \DateTime());
} | [
"private",
"function",
"handleTimestamp",
"(",
"LifecycleEventArgs",
"$",
"event",
")",
"{",
"$",
"entity",
"=",
"$",
"event",
"->",
"getObject",
"(",
")",
";",
"if",
"(",
"!",
"$",
"entity",
"instanceof",
"TimestampableInterface",
")",
"{",
"return",
";",
"}",
"$",
"meta",
"=",
"$",
"event",
"->",
"getObjectManager",
"(",
")",
"->",
"getClassMetadata",
"(",
"get_class",
"(",
"$",
"entity",
")",
")",
";",
"$",
"created",
"=",
"$",
"meta",
"->",
"getFieldValue",
"(",
"$",
"entity",
",",
"self",
"::",
"CREATED_FIELD",
")",
";",
"if",
"(",
"null",
"===",
"$",
"created",
")",
"{",
"$",
"meta",
"->",
"setFieldValue",
"(",
"$",
"entity",
",",
"self",
"::",
"CREATED_FIELD",
",",
"new",
"\\",
"DateTime",
"(",
")",
")",
";",
"}",
"$",
"meta",
"->",
"setFieldValue",
"(",
"$",
"entity",
",",
"self",
"::",
"CHANGED_FIELD",
",",
"new",
"\\",
"DateTime",
"(",
")",
")",
";",
"}"
] | Set the timestamps. If created is NULL then set it. Always
set the changed field.
@param LifecycleEventArgs $event | [
"Set",
"the",
"timestamps",
".",
"If",
"created",
"is",
"NULL",
"then",
"set",
"it",
".",
"Always",
"set",
"the",
"changed",
"field",
"."
] | 6766a36cc2f0c807c59202bf7540a08c4ef31192 | https://github.com/sulu/sulu/blob/6766a36cc2f0c807c59202bf7540a08c4ef31192/src/Sulu/Component/Persistence/EventSubscriber/ORM/TimestampableSubscriber.php#L98-L114 | train |
sulu/sulu | src/Sulu/Bundle/SnippetBundle/Controller/LanguageController.php | LanguageController.cgetAction | public function cgetAction()
{
/** @var WebspaceManagerInterface $webspaceManager */
$webspaceManager = $this->get('sulu_core.webspace.webspace_manager');
$localizations = [];
$locales = [];
/** @var Webspace $webspace */
foreach ($webspaceManager->getWebspaceCollection() as $webspace) {
$i = 0;
foreach ($webspace->getAllLocalizations() as $localization) {
if (!in_array($localization->getLocale(), $locales)) {
$locales[] = $localization->getLocale();
$localizations[] = [
'localization' => $localization->getLocale(),
'name' => $localization->getLocale(Localization::DASH),
'id' => $i++,
];
}
}
}
$data = [
'_embedded' => $localizations,
'total' => count($localizations),
];
return new JsonResponse($data);
} | php | public function cgetAction()
{
/** @var WebspaceManagerInterface $webspaceManager */
$webspaceManager = $this->get('sulu_core.webspace.webspace_manager');
$localizations = [];
$locales = [];
/** @var Webspace $webspace */
foreach ($webspaceManager->getWebspaceCollection() as $webspace) {
$i = 0;
foreach ($webspace->getAllLocalizations() as $localization) {
if (!in_array($localization->getLocale(), $locales)) {
$locales[] = $localization->getLocale();
$localizations[] = [
'localization' => $localization->getLocale(),
'name' => $localization->getLocale(Localization::DASH),
'id' => $i++,
];
}
}
}
$data = [
'_embedded' => $localizations,
'total' => count($localizations),
];
return new JsonResponse($data);
} | [
"public",
"function",
"cgetAction",
"(",
")",
"{",
"/** @var WebspaceManagerInterface $webspaceManager */",
"$",
"webspaceManager",
"=",
"$",
"this",
"->",
"get",
"(",
"'sulu_core.webspace.webspace_manager'",
")",
";",
"$",
"localizations",
"=",
"[",
"]",
";",
"$",
"locales",
"=",
"[",
"]",
";",
"/** @var Webspace $webspace */",
"foreach",
"(",
"$",
"webspaceManager",
"->",
"getWebspaceCollection",
"(",
")",
"as",
"$",
"webspace",
")",
"{",
"$",
"i",
"=",
"0",
";",
"foreach",
"(",
"$",
"webspace",
"->",
"getAllLocalizations",
"(",
")",
"as",
"$",
"localization",
")",
"{",
"if",
"(",
"!",
"in_array",
"(",
"$",
"localization",
"->",
"getLocale",
"(",
")",
",",
"$",
"locales",
")",
")",
"{",
"$",
"locales",
"[",
"]",
"=",
"$",
"localization",
"->",
"getLocale",
"(",
")",
";",
"$",
"localizations",
"[",
"]",
"=",
"[",
"'localization'",
"=>",
"$",
"localization",
"->",
"getLocale",
"(",
")",
",",
"'name'",
"=>",
"$",
"localization",
"->",
"getLocale",
"(",
"Localization",
"::",
"DASH",
")",
",",
"'id'",
"=>",
"$",
"i",
"++",
",",
"]",
";",
"}",
"}",
"}",
"$",
"data",
"=",
"[",
"'_embedded'",
"=>",
"$",
"localizations",
",",
"'total'",
"=>",
"count",
"(",
"$",
"localizations",
")",
",",
"]",
";",
"return",
"new",
"JsonResponse",
"(",
"$",
"data",
")",
";",
"}"
] | Returns all languages in admin.
@return JsonResponse | [
"Returns",
"all",
"languages",
"in",
"admin",
"."
] | 6766a36cc2f0c807c59202bf7540a08c4ef31192 | https://github.com/sulu/sulu/blob/6766a36cc2f0c807c59202bf7540a08c4ef31192/src/Sulu/Bundle/SnippetBundle/Controller/LanguageController.php#L31-L60 | train |
sulu/sulu | src/Sulu/Bundle/PageBundle/Content/Structure/ExcerptStructureExtension.php | ExcerptStructureExtension.getExcerptStructure | private function getExcerptStructure($locale = null)
{
if (null === $locale) {
$locale = $this->languageCode;
}
$excerptStructure = $this->structureManager->getStructure(self::EXCERPT_EXTENSION_NAME);
$excerptStructure->setLanguageCode($locale);
return $excerptStructure;
} | php | private function getExcerptStructure($locale = null)
{
if (null === $locale) {
$locale = $this->languageCode;
}
$excerptStructure = $this->structureManager->getStructure(self::EXCERPT_EXTENSION_NAME);
$excerptStructure->setLanguageCode($locale);
return $excerptStructure;
} | [
"private",
"function",
"getExcerptStructure",
"(",
"$",
"locale",
"=",
"null",
")",
"{",
"if",
"(",
"null",
"===",
"$",
"locale",
")",
"{",
"$",
"locale",
"=",
"$",
"this",
"->",
"languageCode",
";",
"}",
"$",
"excerptStructure",
"=",
"$",
"this",
"->",
"structureManager",
"->",
"getStructure",
"(",
"self",
"::",
"EXCERPT_EXTENSION_NAME",
")",
";",
"$",
"excerptStructure",
"->",
"setLanguageCode",
"(",
"$",
"locale",
")",
";",
"return",
"$",
"excerptStructure",
";",
"}"
] | Returns and caches excerpt-structure.
@param string $locale
@return StructureInterface | [
"Returns",
"and",
"caches",
"excerpt",
"-",
"structure",
"."
] | 6766a36cc2f0c807c59202bf7540a08c4ef31192 | https://github.com/sulu/sulu/blob/6766a36cc2f0c807c59202bf7540a08c4ef31192/src/Sulu/Bundle/PageBundle/Content/Structure/ExcerptStructureExtension.php#L233-L243 | train |
sulu/sulu | src/Sulu/Bundle/PageBundle/Content/Structure/ExcerptStructureExtension.php | ExcerptStructureExtension.initProperties | private function initProperties($locale)
{
// Reset the properties before new initialization.
$this->properties = [];
/** @var PropertyInterface $property */
foreach ($this->getExcerptStructure($locale)->getProperties() as $property) {
$this->properties[] = $property->getName();
}
} | php | private function initProperties($locale)
{
// Reset the properties before new initialization.
$this->properties = [];
/** @var PropertyInterface $property */
foreach ($this->getExcerptStructure($locale)->getProperties() as $property) {
$this->properties[] = $property->getName();
}
} | [
"private",
"function",
"initProperties",
"(",
"$",
"locale",
")",
"{",
"// Reset the properties before new initialization.",
"$",
"this",
"->",
"properties",
"=",
"[",
"]",
";",
"/** @var PropertyInterface $property */",
"foreach",
"(",
"$",
"this",
"->",
"getExcerptStructure",
"(",
"$",
"locale",
")",
"->",
"getProperties",
"(",
")",
"as",
"$",
"property",
")",
"{",
"$",
"this",
"->",
"properties",
"[",
"]",
"=",
"$",
"property",
"->",
"getName",
"(",
")",
";",
"}",
"}"
] | Initiates structure and properties.
@param string $locale | [
"Initiates",
"structure",
"and",
"properties",
"."
] | 6766a36cc2f0c807c59202bf7540a08c4ef31192 | https://github.com/sulu/sulu/blob/6766a36cc2f0c807c59202bf7540a08c4ef31192/src/Sulu/Bundle/PageBundle/Content/Structure/ExcerptStructureExtension.php#L250-L259 | train |
sulu/sulu | src/Sulu/Component/Content/Import/WebspaceImport.php | WebspaceImport.setDocumentSettings | protected function setDocumentSettings(
BasePageDocument $document,
$format,
$data,
$overrideSettings
) {
if ('true' !== $overrideSettings) {
return;
}
foreach ($data as $key => $property) {
$setter = 'set' . ucfirst($key);
if (in_array($key, self::$excludedSettings) || !method_exists($document, $setter)) {
continue;
}
$value = $this->getParser($format)->getPropertyData(
$key,
$data
);
$document->$setter($this->getSetterValue($key, $value));
}
} | php | protected function setDocumentSettings(
BasePageDocument $document,
$format,
$data,
$overrideSettings
) {
if ('true' !== $overrideSettings) {
return;
}
foreach ($data as $key => $property) {
$setter = 'set' . ucfirst($key);
if (in_array($key, self::$excludedSettings) || !method_exists($document, $setter)) {
continue;
}
$value = $this->getParser($format)->getPropertyData(
$key,
$data
);
$document->$setter($this->getSetterValue($key, $value));
}
} | [
"protected",
"function",
"setDocumentSettings",
"(",
"BasePageDocument",
"$",
"document",
",",
"$",
"format",
",",
"$",
"data",
",",
"$",
"overrideSettings",
")",
"{",
"if",
"(",
"'true'",
"!==",
"$",
"overrideSettings",
")",
"{",
"return",
";",
"}",
"foreach",
"(",
"$",
"data",
"as",
"$",
"key",
"=>",
"$",
"property",
")",
"{",
"$",
"setter",
"=",
"'set'",
".",
"ucfirst",
"(",
"$",
"key",
")",
";",
"if",
"(",
"in_array",
"(",
"$",
"key",
",",
"self",
"::",
"$",
"excludedSettings",
")",
"||",
"!",
"method_exists",
"(",
"$",
"document",
",",
"$",
"setter",
")",
")",
"{",
"continue",
";",
"}",
"$",
"value",
"=",
"$",
"this",
"->",
"getParser",
"(",
"$",
"format",
")",
"->",
"getPropertyData",
"(",
"$",
"key",
",",
"$",
"data",
")",
";",
"$",
"document",
"->",
"$",
"setter",
"(",
"$",
"this",
"->",
"getSetterValue",
"(",
"$",
"key",
",",
"$",
"value",
")",
")",
";",
"}",
"}"
] | Set all Settings for the given documents and import them.
Import property -o must be set to true.
@param BasePageDocument $document
@param string $format
@param array $data
@param $overrideSettings
@throws DocumentManagerException
@throws FormatImporterNotFoundException | [
"Set",
"all",
"Settings",
"for",
"the",
"given",
"documents",
"and",
"import",
"them",
".",
"Import",
"property",
"-",
"o",
"must",
"be",
"set",
"to",
"true",
"."
] | 6766a36cc2f0c807c59202bf7540a08c4ef31192 | https://github.com/sulu/sulu/blob/6766a36cc2f0c807c59202bf7540a08c4ef31192/src/Sulu/Component/Content/Import/WebspaceImport.php#L384-L408 | train |
sulu/sulu | src/Sulu/Component/Content/Import/WebspaceImport.php | WebspaceImport.getSetterValue | protected function getSetterValue($key, $value)
{
if (empty($value)) {
return;
}
switch ($key) {
case 'redirectTarget':
$value = $this->documentManager->find($value);
break;
case 'permissions':
$value = json_decode($value, true);
break;
case 'navigationContexts':
$value = json_decode($value);
break;
}
return $value;
} | php | protected function getSetterValue($key, $value)
{
if (empty($value)) {
return;
}
switch ($key) {
case 'redirectTarget':
$value = $this->documentManager->find($value);
break;
case 'permissions':
$value = json_decode($value, true);
break;
case 'navigationContexts':
$value = json_decode($value);
break;
}
return $value;
} | [
"protected",
"function",
"getSetterValue",
"(",
"$",
"key",
",",
"$",
"value",
")",
"{",
"if",
"(",
"empty",
"(",
"$",
"value",
")",
")",
"{",
"return",
";",
"}",
"switch",
"(",
"$",
"key",
")",
"{",
"case",
"'redirectTarget'",
":",
"$",
"value",
"=",
"$",
"this",
"->",
"documentManager",
"->",
"find",
"(",
"$",
"value",
")",
";",
"break",
";",
"case",
"'permissions'",
":",
"$",
"value",
"=",
"json_decode",
"(",
"$",
"value",
",",
"true",
")",
";",
"break",
";",
"case",
"'navigationContexts'",
":",
"$",
"value",
"=",
"json_decode",
"(",
"$",
"value",
")",
";",
"break",
";",
"}",
"return",
"$",
"value",
";",
"}"
] | Prepare the settings value for the respective setter.
@param $key
@param $value
@return mixed|object
@throws DocumentManagerException | [
"Prepare",
"the",
"settings",
"value",
"for",
"the",
"respective",
"setter",
"."
] | 6766a36cc2f0c807c59202bf7540a08c4ef31192 | https://github.com/sulu/sulu/blob/6766a36cc2f0c807c59202bf7540a08c4ef31192/src/Sulu/Component/Content/Import/WebspaceImport.php#L420-L439 | train |
sulu/sulu | src/Sulu/Component/Content/Import/WebspaceImport.php | WebspaceImport.importExtension | protected function importExtension(
ExportExtensionInterface $extension,
$extensionKey,
NodeInterface $node,
$data,
$webspaceKey,
$locale,
$format
) {
$extensionData = [];
foreach ($extension->getImportPropertyNames() as $propertyName) {
$value = $this->getParser($format)->getPropertyData(
$propertyName,
$data,
null,
$extensionKey
);
$extensionData[$propertyName] = $value;
}
$extension->import($node, $extensionData, $webspaceKey, $locale, $format);
} | php | protected function importExtension(
ExportExtensionInterface $extension,
$extensionKey,
NodeInterface $node,
$data,
$webspaceKey,
$locale,
$format
) {
$extensionData = [];
foreach ($extension->getImportPropertyNames() as $propertyName) {
$value = $this->getParser($format)->getPropertyData(
$propertyName,
$data,
null,
$extensionKey
);
$extensionData[$propertyName] = $value;
}
$extension->import($node, $extensionData, $webspaceKey, $locale, $format);
} | [
"protected",
"function",
"importExtension",
"(",
"ExportExtensionInterface",
"$",
"extension",
",",
"$",
"extensionKey",
",",
"NodeInterface",
"$",
"node",
",",
"$",
"data",
",",
"$",
"webspaceKey",
",",
"$",
"locale",
",",
"$",
"format",
")",
"{",
"$",
"extensionData",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"extension",
"->",
"getImportPropertyNames",
"(",
")",
"as",
"$",
"propertyName",
")",
"{",
"$",
"value",
"=",
"$",
"this",
"->",
"getParser",
"(",
"$",
"format",
")",
"->",
"getPropertyData",
"(",
"$",
"propertyName",
",",
"$",
"data",
",",
"null",
",",
"$",
"extensionKey",
")",
";",
"$",
"extensionData",
"[",
"$",
"propertyName",
"]",
"=",
"$",
"value",
";",
"}",
"$",
"extension",
"->",
"import",
"(",
"$",
"node",
",",
"$",
"extensionData",
",",
"$",
"webspaceKey",
",",
"$",
"locale",
",",
"$",
"format",
")",
";",
"}"
] | Importing the Extensions like SEO- and Excerption-Tab.
@param ExportExtensionInterface $extension
@param string $extensionKey
@param NodeInterface $node
@param array $data
@param string $webspaceKey
@param string $locale
@param string $format
@throws FormatImporterNotFoundException | [
"Importing",
"the",
"Extensions",
"like",
"SEO",
"-",
"and",
"Excerption",
"-",
"Tab",
"."
] | 6766a36cc2f0c807c59202bf7540a08c4ef31192 | https://github.com/sulu/sulu/blob/6766a36cc2f0c807c59202bf7540a08c4ef31192/src/Sulu/Component/Content/Import/WebspaceImport.php#L454-L477 | train |
sulu/sulu | src/Sulu/Component/Content/Import/WebspaceImport.php | WebspaceImport.generateUrl | private function generateUrl($properties, $parentUuid, $webspaceKey, $locale, $format, $data)
{
$rlpParts = [];
foreach ($properties as $property) {
$rlpParts[] = $this->getParser($format)->getPropertyData(
$property->getName(),
$data,
$property->getContentTypeName()
);
}
$title = trim(implode(' ', $rlpParts));
return $this->rlpStrategy->generate($title, $parentUuid, $webspaceKey, $locale);
} | php | private function generateUrl($properties, $parentUuid, $webspaceKey, $locale, $format, $data)
{
$rlpParts = [];
foreach ($properties as $property) {
$rlpParts[] = $this->getParser($format)->getPropertyData(
$property->getName(),
$data,
$property->getContentTypeName()
);
}
$title = trim(implode(' ', $rlpParts));
return $this->rlpStrategy->generate($title, $parentUuid, $webspaceKey, $locale);
} | [
"private",
"function",
"generateUrl",
"(",
"$",
"properties",
",",
"$",
"parentUuid",
",",
"$",
"webspaceKey",
",",
"$",
"locale",
",",
"$",
"format",
",",
"$",
"data",
")",
"{",
"$",
"rlpParts",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"properties",
"as",
"$",
"property",
")",
"{",
"$",
"rlpParts",
"[",
"]",
"=",
"$",
"this",
"->",
"getParser",
"(",
"$",
"format",
")",
"->",
"getPropertyData",
"(",
"$",
"property",
"->",
"getName",
"(",
")",
",",
"$",
"data",
",",
"$",
"property",
"->",
"getContentTypeName",
"(",
")",
")",
";",
"}",
"$",
"title",
"=",
"trim",
"(",
"implode",
"(",
"' '",
",",
"$",
"rlpParts",
")",
")",
";",
"return",
"$",
"this",
"->",
"rlpStrategy",
"->",
"generate",
"(",
"$",
"title",
",",
"$",
"parentUuid",
",",
"$",
"webspaceKey",
",",
"$",
"locale",
")",
";",
"}"
] | Generates a url by given strategy and property.
@param PropertyInterface[] $properties
@param string $parentUuid
@param string $webspaceKey
@param string $locale
@param string $format
@param array $data
@return string
@throws FormatImporterNotFoundException | [
"Generates",
"a",
"url",
"by",
"given",
"strategy",
"and",
"property",
"."
] | 6766a36cc2f0c807c59202bf7540a08c4ef31192 | https://github.com/sulu/sulu/blob/6766a36cc2f0c807c59202bf7540a08c4ef31192/src/Sulu/Component/Content/Import/WebspaceImport.php#L493-L508 | train |
sulu/sulu | src/Sulu/Bundle/MarkupBundle/Markup/HtmlTagExtractor.php | HtmlTagExtractor.getAttributes | private function getAttributes($tag)
{
if (!preg_match_all(self::ATTRIBUTE_REGEX, $tag, $matches)) {
return [];
}
$attributes = [];
for ($i = 0, $length = count($matches['name']); $i < $length; ++$i) {
$value = $matches['value'][$i];
if ('true' === $value || 'false' === $value) {
$value = filter_var($value, FILTER_VALIDATE_BOOLEAN);
}
$attributes[$matches['name'][$i]] = $value;
}
return $attributes;
} | php | private function getAttributes($tag)
{
if (!preg_match_all(self::ATTRIBUTE_REGEX, $tag, $matches)) {
return [];
}
$attributes = [];
for ($i = 0, $length = count($matches['name']); $i < $length; ++$i) {
$value = $matches['value'][$i];
if ('true' === $value || 'false' === $value) {
$value = filter_var($value, FILTER_VALIDATE_BOOLEAN);
}
$attributes[$matches['name'][$i]] = $value;
}
return $attributes;
} | [
"private",
"function",
"getAttributes",
"(",
"$",
"tag",
")",
"{",
"if",
"(",
"!",
"preg_match_all",
"(",
"self",
"::",
"ATTRIBUTE_REGEX",
",",
"$",
"tag",
",",
"$",
"matches",
")",
")",
"{",
"return",
"[",
"]",
";",
"}",
"$",
"attributes",
"=",
"[",
"]",
";",
"for",
"(",
"$",
"i",
"=",
"0",
",",
"$",
"length",
"=",
"count",
"(",
"$",
"matches",
"[",
"'name'",
"]",
")",
";",
"$",
"i",
"<",
"$",
"length",
";",
"++",
"$",
"i",
")",
"{",
"$",
"value",
"=",
"$",
"matches",
"[",
"'value'",
"]",
"[",
"$",
"i",
"]",
";",
"if",
"(",
"'true'",
"===",
"$",
"value",
"||",
"'false'",
"===",
"$",
"value",
")",
"{",
"$",
"value",
"=",
"filter_var",
"(",
"$",
"value",
",",
"FILTER_VALIDATE_BOOLEAN",
")",
";",
"}",
"$",
"attributes",
"[",
"$",
"matches",
"[",
"'name'",
"]",
"[",
"$",
"i",
"]",
"]",
"=",
"$",
"value",
";",
"}",
"return",
"$",
"attributes",
";",
"}"
] | Returns attributes of given html-tag.
@param string $tag
@return array | [
"Returns",
"attributes",
"of",
"given",
"html",
"-",
"tag",
"."
] | 6766a36cc2f0c807c59202bf7540a08c4ef31192 | https://github.com/sulu/sulu/blob/6766a36cc2f0c807c59202bf7540a08c4ef31192/src/Sulu/Bundle/MarkupBundle/Markup/HtmlTagExtractor.php#L79-L97 | train |
sulu/sulu | src/Sulu/Bundle/CoreBundle/Composer/ScriptHandler.php | ScriptHandler.removeComposerLockFromGitIgnore | public static function removeComposerLockFromGitIgnore()
{
if (!file_exists(static::GIT_IGNORE_FILE)) {
return;
}
$gitignore = file_get_contents(static::GIT_IGNORE_FILE);
$gitignore = str_replace("composer.lock\n", '', $gitignore);
file_put_contents(static::GIT_IGNORE_FILE, $gitignore);
} | php | public static function removeComposerLockFromGitIgnore()
{
if (!file_exists(static::GIT_IGNORE_FILE)) {
return;
}
$gitignore = file_get_contents(static::GIT_IGNORE_FILE);
$gitignore = str_replace("composer.lock\n", '', $gitignore);
file_put_contents(static::GIT_IGNORE_FILE, $gitignore);
} | [
"public",
"static",
"function",
"removeComposerLockFromGitIgnore",
"(",
")",
"{",
"if",
"(",
"!",
"file_exists",
"(",
"static",
"::",
"GIT_IGNORE_FILE",
")",
")",
"{",
"return",
";",
"}",
"$",
"gitignore",
"=",
"file_get_contents",
"(",
"static",
"::",
"GIT_IGNORE_FILE",
")",
";",
"$",
"gitignore",
"=",
"str_replace",
"(",
"\"composer.lock\\n\"",
",",
"''",
",",
"$",
"gitignore",
")",
";",
"file_put_contents",
"(",
"static",
"::",
"GIT_IGNORE_FILE",
",",
"$",
"gitignore",
")",
";",
"}"
] | Removes the composer.lock file from .gitignore, because we don't want the composer.lock to be included in our
repositories, but they should be included when developing specific project. | [
"Removes",
"the",
"composer",
".",
"lock",
"file",
"from",
".",
"gitignore",
"because",
"we",
"don",
"t",
"want",
"the",
"composer",
".",
"lock",
"to",
"be",
"included",
"in",
"our",
"repositories",
"but",
"they",
"should",
"be",
"included",
"when",
"developing",
"specific",
"project",
"."
] | 6766a36cc2f0c807c59202bf7540a08c4ef31192 | https://github.com/sulu/sulu/blob/6766a36cc2f0c807c59202bf7540a08c4ef31192/src/Sulu/Bundle/CoreBundle/Composer/ScriptHandler.php#L25-L34 | train |
sulu/sulu | src/Sulu/Bundle/CoreBundle/Composer/ScriptHandler.php | ScriptHandler.removePackageLockJsonFromGitIgnore | public static function removePackageLockJsonFromGitIgnore()
{
if (!file_exists(static::GIT_IGNORE_FILE)) {
return;
}
$gitignore = file_get_contents(static::GIT_IGNORE_FILE);
$gitignore = str_replace("package-lock.json\n", '', $gitignore);
file_put_contents(static::GIT_IGNORE_FILE, $gitignore);
} | php | public static function removePackageLockJsonFromGitIgnore()
{
if (!file_exists(static::GIT_IGNORE_FILE)) {
return;
}
$gitignore = file_get_contents(static::GIT_IGNORE_FILE);
$gitignore = str_replace("package-lock.json\n", '', $gitignore);
file_put_contents(static::GIT_IGNORE_FILE, $gitignore);
} | [
"public",
"static",
"function",
"removePackageLockJsonFromGitIgnore",
"(",
")",
"{",
"if",
"(",
"!",
"file_exists",
"(",
"static",
"::",
"GIT_IGNORE_FILE",
")",
")",
"{",
"return",
";",
"}",
"$",
"gitignore",
"=",
"file_get_contents",
"(",
"static",
"::",
"GIT_IGNORE_FILE",
")",
";",
"$",
"gitignore",
"=",
"str_replace",
"(",
"\"package-lock.json\\n\"",
",",
"''",
",",
"$",
"gitignore",
")",
";",
"file_put_contents",
"(",
"static",
"::",
"GIT_IGNORE_FILE",
",",
"$",
"gitignore",
")",
";",
"}"
] | Removes the package-lock.json file from .gitignore, because we don't want the package-lock.json to be included in
our repositories, but they should be included when developing specific project. | [
"Removes",
"the",
"package",
"-",
"lock",
".",
"json",
"file",
"from",
".",
"gitignore",
"because",
"we",
"don",
"t",
"want",
"the",
"package",
"-",
"lock",
".",
"json",
"to",
"be",
"included",
"in",
"our",
"repositories",
"but",
"they",
"should",
"be",
"included",
"when",
"developing",
"specific",
"project",
"."
] | 6766a36cc2f0c807c59202bf7540a08c4ef31192 | https://github.com/sulu/sulu/blob/6766a36cc2f0c807c59202bf7540a08c4ef31192/src/Sulu/Bundle/CoreBundle/Composer/ScriptHandler.php#L40-L49 | train |
sulu/sulu | src/Sulu/Bundle/PageBundle/Resources/phpcr-migrations/Version201507231648.php | Version201507231648.upgradeWebspace | private function upgradeWebspace(Webspace $webspace)
{
$sessionManager = $this->container->get('sulu.phpcr.session');
$node = $sessionManager->getContentNode($webspace->getKey());
foreach ($webspace->getAllLocalizations() as $localization) {
$locale = $localization->getLocale();
$propertyName = $this->getPropertyName(self::SHADOW_ON_PROPERTY, $locale);
$this->upgradeNode($node, $propertyName, $locale);
}
} | php | private function upgradeWebspace(Webspace $webspace)
{
$sessionManager = $this->container->get('sulu.phpcr.session');
$node = $sessionManager->getContentNode($webspace->getKey());
foreach ($webspace->getAllLocalizations() as $localization) {
$locale = $localization->getLocale();
$propertyName = $this->getPropertyName(self::SHADOW_ON_PROPERTY, $locale);
$this->upgradeNode($node, $propertyName, $locale);
}
} | [
"private",
"function",
"upgradeWebspace",
"(",
"Webspace",
"$",
"webspace",
")",
"{",
"$",
"sessionManager",
"=",
"$",
"this",
"->",
"container",
"->",
"get",
"(",
"'sulu.phpcr.session'",
")",
";",
"$",
"node",
"=",
"$",
"sessionManager",
"->",
"getContentNode",
"(",
"$",
"webspace",
"->",
"getKey",
"(",
")",
")",
";",
"foreach",
"(",
"$",
"webspace",
"->",
"getAllLocalizations",
"(",
")",
"as",
"$",
"localization",
")",
"{",
"$",
"locale",
"=",
"$",
"localization",
"->",
"getLocale",
"(",
")",
";",
"$",
"propertyName",
"=",
"$",
"this",
"->",
"getPropertyName",
"(",
"self",
"::",
"SHADOW_ON_PROPERTY",
",",
"$",
"locale",
")",
";",
"$",
"this",
"->",
"upgradeNode",
"(",
"$",
"node",
",",
"$",
"propertyName",
",",
"$",
"locale",
")",
";",
"}",
"}"
] | Upgrade a single webspace.
@param Webspace $webspace | [
"Upgrade",
"a",
"single",
"webspace",
"."
] | 6766a36cc2f0c807c59202bf7540a08c4ef31192 | https://github.com/sulu/sulu/blob/6766a36cc2f0c807c59202bf7540a08c4ef31192/src/Sulu/Bundle/PageBundle/Resources/phpcr-migrations/Version201507231648.php#L69-L80 | train |
sulu/sulu | src/Sulu/Bundle/PageBundle/Resources/phpcr-migrations/Version201507231648.php | Version201507231648.upgradeNode | private function upgradeNode(NodeInterface $node, $propertyName, $locale)
{
foreach ($node->getNodes() as $child) {
$this->upgradeNode($child, $propertyName, $locale);
}
if (false === $node->getPropertyValueWithDefault($propertyName, false)) {
return;
}
$shadowLocale = $node->getPropertyValue($this->getPropertyName(self::SHADOW_BASE_PROPERTY, $locale));
$tags = $this->getTags($node, $shadowLocale);
$categories = $this->getCategories($node, $shadowLocale);
$navigationContext = $this->getNavigationContext($node, $shadowLocale);
$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 | private function upgradeNode(NodeInterface $node, $propertyName, $locale)
{
foreach ($node->getNodes() as $child) {
$this->upgradeNode($child, $propertyName, $locale);
}
if (false === $node->getPropertyValueWithDefault($propertyName, false)) {
return;
}
$shadowLocale = $node->getPropertyValue($this->getPropertyName(self::SHADOW_BASE_PROPERTY, $locale));
$tags = $this->getTags($node, $shadowLocale);
$categories = $this->getCategories($node, $shadowLocale);
$navigationContext = $this->getNavigationContext($node, $shadowLocale);
$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);
} | [
"private",
"function",
"upgradeNode",
"(",
"NodeInterface",
"$",
"node",
",",
"$",
"propertyName",
",",
"$",
"locale",
")",
"{",
"foreach",
"(",
"$",
"node",
"->",
"getNodes",
"(",
")",
"as",
"$",
"child",
")",
"{",
"$",
"this",
"->",
"upgradeNode",
"(",
"$",
"child",
",",
"$",
"propertyName",
",",
"$",
"locale",
")",
";",
"}",
"if",
"(",
"false",
"===",
"$",
"node",
"->",
"getPropertyValueWithDefault",
"(",
"$",
"propertyName",
",",
"false",
")",
")",
"{",
"return",
";",
"}",
"$",
"shadowLocale",
"=",
"$",
"node",
"->",
"getPropertyValue",
"(",
"$",
"this",
"->",
"getPropertyName",
"(",
"self",
"::",
"SHADOW_BASE_PROPERTY",
",",
"$",
"locale",
")",
")",
";",
"$",
"tags",
"=",
"$",
"this",
"->",
"getTags",
"(",
"$",
"node",
",",
"$",
"shadowLocale",
")",
";",
"$",
"categories",
"=",
"$",
"this",
"->",
"getCategories",
"(",
"$",
"node",
",",
"$",
"shadowLocale",
")",
";",
"$",
"navigationContext",
"=",
"$",
"this",
"->",
"getNavigationContext",
"(",
"$",
"node",
",",
"$",
"shadowLocale",
")",
";",
"$",
"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",
")",
";",
"}"
] | Upgrade a single node.
@param NodeInterface $node
@param string $propertyName
@param string $locale | [
"Upgrade",
"a",
"single",
"node",
"."
] | 6766a36cc2f0c807c59202bf7540a08c4ef31192 | https://github.com/sulu/sulu/blob/6766a36cc2f0c807c59202bf7540a08c4ef31192/src/Sulu/Bundle/PageBundle/Resources/phpcr-migrations/Version201507231648.php#L89-L108 | train |
sulu/sulu | src/Sulu/Bundle/PageBundle/Resources/phpcr-migrations/Version201507231648.php | Version201507231648.getTags | private function getTags(NodeInterface $node, $locale)
{
return $node->getPropertyValueWithDefault(
sprintf(self::TAGS_PROPERTY, $locale),
[]
);
} | php | private function getTags(NodeInterface $node, $locale)
{
return $node->getPropertyValueWithDefault(
sprintf(self::TAGS_PROPERTY, $locale),
[]
);
} | [
"private",
"function",
"getTags",
"(",
"NodeInterface",
"$",
"node",
",",
"$",
"locale",
")",
"{",
"return",
"$",
"node",
"->",
"getPropertyValueWithDefault",
"(",
"sprintf",
"(",
"self",
"::",
"TAGS_PROPERTY",
",",
"$",
"locale",
")",
",",
"[",
"]",
")",
";",
"}"
] | Returns tags of given node and locale.
@param NodeInterface $node
@param $locale
@return array | [
"Returns",
"tags",
"of",
"given",
"node",
"and",
"locale",
"."
] | 6766a36cc2f0c807c59202bf7540a08c4ef31192 | https://github.com/sulu/sulu/blob/6766a36cc2f0c807c59202bf7540a08c4ef31192/src/Sulu/Bundle/PageBundle/Resources/phpcr-migrations/Version201507231648.php#L131-L137 | train |
sulu/sulu | src/Sulu/Bundle/PageBundle/Resources/phpcr-migrations/Version201507231648.php | Version201507231648.getCategories | private function getCategories(NodeInterface $node, $locale)
{
return $node->getPropertyValueWithDefault(
sprintf(self::CATEGORIES_PROPERTY, $locale),
[]
);
} | php | private function getCategories(NodeInterface $node, $locale)
{
return $node->getPropertyValueWithDefault(
sprintf(self::CATEGORIES_PROPERTY, $locale),
[]
);
} | [
"private",
"function",
"getCategories",
"(",
"NodeInterface",
"$",
"node",
",",
"$",
"locale",
")",
"{",
"return",
"$",
"node",
"->",
"getPropertyValueWithDefault",
"(",
"sprintf",
"(",
"self",
"::",
"CATEGORIES_PROPERTY",
",",
"$",
"locale",
")",
",",
"[",
"]",
")",
";",
"}"
] | Returns categories of given node and locale.
@param NodeInterface $node
@param $locale
@return array | [
"Returns",
"categories",
"of",
"given",
"node",
"and",
"locale",
"."
] | 6766a36cc2f0c807c59202bf7540a08c4ef31192 | https://github.com/sulu/sulu/blob/6766a36cc2f0c807c59202bf7540a08c4ef31192/src/Sulu/Bundle/PageBundle/Resources/phpcr-migrations/Version201507231648.php#L147-L153 | train |
sulu/sulu | src/Sulu/Bundle/PageBundle/Resources/phpcr-migrations/Version201507231648.php | Version201507231648.getNavigationContext | private function getNavigationContext(NodeInterface $node, $locale)
{
return $node->getPropertyValueWithDefault(
sprintf(self::NAVIGATION_CONTEXT_PROPERTY, $locale),
[]
);
} | php | private function getNavigationContext(NodeInterface $node, $locale)
{
return $node->getPropertyValueWithDefault(
sprintf(self::NAVIGATION_CONTEXT_PROPERTY, $locale),
[]
);
} | [
"private",
"function",
"getNavigationContext",
"(",
"NodeInterface",
"$",
"node",
",",
"$",
"locale",
")",
"{",
"return",
"$",
"node",
"->",
"getPropertyValueWithDefault",
"(",
"sprintf",
"(",
"self",
"::",
"NAVIGATION_CONTEXT_PROPERTY",
",",
"$",
"locale",
")",
",",
"[",
"]",
")",
";",
"}"
] | Returns navigation context of given node and locale.
@param NodeInterface $node
@param $locale
@return array | [
"Returns",
"navigation",
"context",
"of",
"given",
"node",
"and",
"locale",
"."
] | 6766a36cc2f0c807c59202bf7540a08c4ef31192 | https://github.com/sulu/sulu/blob/6766a36cc2f0c807c59202bf7540a08c4ef31192/src/Sulu/Bundle/PageBundle/Resources/phpcr-migrations/Version201507231648.php#L163-L169 | train |
sulu/sulu | src/Sulu/Bundle/AdminBundle/Controller/AdminController.php | AdminController.configAction | public function configAction(): Response
{
$user = $this->tokenStorage->getToken()->getUser();
$contact = $this->contactManager->getById($user->getContact()->getId(), $user->getLocale());
$view = View::create([
'sulu_admin' => [
'endpoints' => [
'metadata' => $this->urlGenerator->generate(
'sulu_admin.metadata',
['type' => ':type', 'key' => ':key']
),
],
'fieldTypeOptions' => $this->fieldTypeOptionRegistry->toArray(),
'internalLinkTypes' => $this->linkProviderPool->getConfiguration(),
'navigation' => $this->navigationRegistry->getNavigation()->getChildrenAsArray(),
'routes' => $this->routeRegistry->getRoutes(),
'resources' => $this->resources,
'smartContent' => array_map(function(DataProviderInterface $dataProvider) {
return $dataProvider->getConfiguration();
}, $this->dataProviderPool->getAll()),
'user' => $user,
'contact' => $contact,
],
'sulu_contact' => [
'addressTypes' => $this->managerRegistry->getRepository('SuluContactBundle:AddressType')->findAll(),
'countries' => $this->managerRegistry->getRepository('SuluContactBundle:Country')->findAll(),
],
'sulu_media' => [
'endpoints' => [
'image_format' => $this->urlGenerator->generate(
'sulu_media.redirect',
['id' => ':id']
),
],
],
'sulu_preview' => [
'endpoints' => [
'start' => $this->urlGenerator->generate('sulu_preview.start'),
'render' => $this->urlGenerator->generate('sulu_preview.render'),
'update' => $this->urlGenerator->generate('sulu_preview.update'),
'update-context' => $this->urlGenerator->generate('sulu_preview.update-context'),
'stop' => $this->urlGenerator->generate('sulu_preview.stop'),
],
'debounceDelay' => $this->previewDelay,
'mode' => $this->previewMode,
],
'sulu_security' => [
'endpoints' => [
'contexts' => $this->urlGenerator->generate('cget_contexts'),
],
],
'sulu_website' => [
'endpoints' => [
'clearCache' => $this->urlGenerator->generate('sulu_website.cache.remove'),
],
],
]);
$context = new Context();
$context->setGroups(['frontend', 'partialContact', 'fullRoute']);
$view->setContext($context);
$view->setFormat('json');
return $this->viewHandler->handle($view);
} | php | public function configAction(): Response
{
$user = $this->tokenStorage->getToken()->getUser();
$contact = $this->contactManager->getById($user->getContact()->getId(), $user->getLocale());
$view = View::create([
'sulu_admin' => [
'endpoints' => [
'metadata' => $this->urlGenerator->generate(
'sulu_admin.metadata',
['type' => ':type', 'key' => ':key']
),
],
'fieldTypeOptions' => $this->fieldTypeOptionRegistry->toArray(),
'internalLinkTypes' => $this->linkProviderPool->getConfiguration(),
'navigation' => $this->navigationRegistry->getNavigation()->getChildrenAsArray(),
'routes' => $this->routeRegistry->getRoutes(),
'resources' => $this->resources,
'smartContent' => array_map(function(DataProviderInterface $dataProvider) {
return $dataProvider->getConfiguration();
}, $this->dataProviderPool->getAll()),
'user' => $user,
'contact' => $contact,
],
'sulu_contact' => [
'addressTypes' => $this->managerRegistry->getRepository('SuluContactBundle:AddressType')->findAll(),
'countries' => $this->managerRegistry->getRepository('SuluContactBundle:Country')->findAll(),
],
'sulu_media' => [
'endpoints' => [
'image_format' => $this->urlGenerator->generate(
'sulu_media.redirect',
['id' => ':id']
),
],
],
'sulu_preview' => [
'endpoints' => [
'start' => $this->urlGenerator->generate('sulu_preview.start'),
'render' => $this->urlGenerator->generate('sulu_preview.render'),
'update' => $this->urlGenerator->generate('sulu_preview.update'),
'update-context' => $this->urlGenerator->generate('sulu_preview.update-context'),
'stop' => $this->urlGenerator->generate('sulu_preview.stop'),
],
'debounceDelay' => $this->previewDelay,
'mode' => $this->previewMode,
],
'sulu_security' => [
'endpoints' => [
'contexts' => $this->urlGenerator->generate('cget_contexts'),
],
],
'sulu_website' => [
'endpoints' => [
'clearCache' => $this->urlGenerator->generate('sulu_website.cache.remove'),
],
],
]);
$context = new Context();
$context->setGroups(['frontend', 'partialContact', 'fullRoute']);
$view->setContext($context);
$view->setFormat('json');
return $this->viewHandler->handle($view);
} | [
"public",
"function",
"configAction",
"(",
")",
":",
"Response",
"{",
"$",
"user",
"=",
"$",
"this",
"->",
"tokenStorage",
"->",
"getToken",
"(",
")",
"->",
"getUser",
"(",
")",
";",
"$",
"contact",
"=",
"$",
"this",
"->",
"contactManager",
"->",
"getById",
"(",
"$",
"user",
"->",
"getContact",
"(",
")",
"->",
"getId",
"(",
")",
",",
"$",
"user",
"->",
"getLocale",
"(",
")",
")",
";",
"$",
"view",
"=",
"View",
"::",
"create",
"(",
"[",
"'sulu_admin'",
"=>",
"[",
"'endpoints'",
"=>",
"[",
"'metadata'",
"=>",
"$",
"this",
"->",
"urlGenerator",
"->",
"generate",
"(",
"'sulu_admin.metadata'",
",",
"[",
"'type'",
"=>",
"':type'",
",",
"'key'",
"=>",
"':key'",
"]",
")",
",",
"]",
",",
"'fieldTypeOptions'",
"=>",
"$",
"this",
"->",
"fieldTypeOptionRegistry",
"->",
"toArray",
"(",
")",
",",
"'internalLinkTypes'",
"=>",
"$",
"this",
"->",
"linkProviderPool",
"->",
"getConfiguration",
"(",
")",
",",
"'navigation'",
"=>",
"$",
"this",
"->",
"navigationRegistry",
"->",
"getNavigation",
"(",
")",
"->",
"getChildrenAsArray",
"(",
")",
",",
"'routes'",
"=>",
"$",
"this",
"->",
"routeRegistry",
"->",
"getRoutes",
"(",
")",
",",
"'resources'",
"=>",
"$",
"this",
"->",
"resources",
",",
"'smartContent'",
"=>",
"array_map",
"(",
"function",
"(",
"DataProviderInterface",
"$",
"dataProvider",
")",
"{",
"return",
"$",
"dataProvider",
"->",
"getConfiguration",
"(",
")",
";",
"}",
",",
"$",
"this",
"->",
"dataProviderPool",
"->",
"getAll",
"(",
")",
")",
",",
"'user'",
"=>",
"$",
"user",
",",
"'contact'",
"=>",
"$",
"contact",
",",
"]",
",",
"'sulu_contact'",
"=>",
"[",
"'addressTypes'",
"=>",
"$",
"this",
"->",
"managerRegistry",
"->",
"getRepository",
"(",
"'SuluContactBundle:AddressType'",
")",
"->",
"findAll",
"(",
")",
",",
"'countries'",
"=>",
"$",
"this",
"->",
"managerRegistry",
"->",
"getRepository",
"(",
"'SuluContactBundle:Country'",
")",
"->",
"findAll",
"(",
")",
",",
"]",
",",
"'sulu_media'",
"=>",
"[",
"'endpoints'",
"=>",
"[",
"'image_format'",
"=>",
"$",
"this",
"->",
"urlGenerator",
"->",
"generate",
"(",
"'sulu_media.redirect'",
",",
"[",
"'id'",
"=>",
"':id'",
"]",
")",
",",
"]",
",",
"]",
",",
"'sulu_preview'",
"=>",
"[",
"'endpoints'",
"=>",
"[",
"'start'",
"=>",
"$",
"this",
"->",
"urlGenerator",
"->",
"generate",
"(",
"'sulu_preview.start'",
")",
",",
"'render'",
"=>",
"$",
"this",
"->",
"urlGenerator",
"->",
"generate",
"(",
"'sulu_preview.render'",
")",
",",
"'update'",
"=>",
"$",
"this",
"->",
"urlGenerator",
"->",
"generate",
"(",
"'sulu_preview.update'",
")",
",",
"'update-context'",
"=>",
"$",
"this",
"->",
"urlGenerator",
"->",
"generate",
"(",
"'sulu_preview.update-context'",
")",
",",
"'stop'",
"=>",
"$",
"this",
"->",
"urlGenerator",
"->",
"generate",
"(",
"'sulu_preview.stop'",
")",
",",
"]",
",",
"'debounceDelay'",
"=>",
"$",
"this",
"->",
"previewDelay",
",",
"'mode'",
"=>",
"$",
"this",
"->",
"previewMode",
",",
"]",
",",
"'sulu_security'",
"=>",
"[",
"'endpoints'",
"=>",
"[",
"'contexts'",
"=>",
"$",
"this",
"->",
"urlGenerator",
"->",
"generate",
"(",
"'cget_contexts'",
")",
",",
"]",
",",
"]",
",",
"'sulu_website'",
"=>",
"[",
"'endpoints'",
"=>",
"[",
"'clearCache'",
"=>",
"$",
"this",
"->",
"urlGenerator",
"->",
"generate",
"(",
"'sulu_website.cache.remove'",
")",
",",
"]",
",",
"]",
",",
"]",
")",
";",
"$",
"context",
"=",
"new",
"Context",
"(",
")",
";",
"$",
"context",
"->",
"setGroups",
"(",
"[",
"'frontend'",
",",
"'partialContact'",
",",
"'fullRoute'",
"]",
")",
";",
"$",
"view",
"->",
"setContext",
"(",
"$",
"context",
")",
";",
"$",
"view",
"->",
"setFormat",
"(",
"'json'",
")",
";",
"return",
"$",
"this",
"->",
"viewHandler",
"->",
"handle",
"(",
"$",
"view",
")",
";",
"}"
] | Returns all the configuration for the admin interface. | [
"Returns",
"all",
"the",
"configuration",
"for",
"the",
"admin",
"interface",
"."
] | 6766a36cc2f0c807c59202bf7540a08c4ef31192 | https://github.com/sulu/sulu/blob/6766a36cc2f0c807c59202bf7540a08c4ef31192/src/Sulu/Bundle/AdminBundle/Controller/AdminController.php#L242-L308 | train |
sulu/sulu | src/Sulu/Component/Webspace/Manager/WebspaceCollectionBuilder.php | WebspaceCollectionBuilder.buildUrls | private function buildUrls(
Portal $portal,
Environment $environment,
Url $url,
$segments,
$urlAddress
) {
if ($url->getLanguage()) {
$language = $url->getLanguage();
$country = $url->getCountry();
$locale = $language . ($country ? '_' . $country : '');
$this->buildUrlFullMatch(
$portal,
$environment,
$segments,
[],
$urlAddress,
$portal->getLocalization($locale),
$url
);
} else {
// create all the urls for every localization/segment combination
foreach ($portal->getLocalizations() as $localization) {
$language = $url->getLanguage() ? $url->getLanguage() : $localization->getLanguage();
$country = $url->getCountry() ? $url->getCountry() : $localization->getCountry();
$replacers = [
ReplacerInterface::REPLACER_LANGUAGE => $language,
ReplacerInterface::REPLACER_COUNTRY => $country,
ReplacerInterface::REPLACER_LOCALIZATION => $localization->getLocale(Localization::DASH),
];
$this->buildUrlFullMatch(
$portal,
$environment,
$segments,
$replacers,
$urlAddress,
$localization,
$url
);
}
$this->buildUrlPartialMatch(
$portal,
$environment,
$urlAddress,
$url
);
}
} | php | private function buildUrls(
Portal $portal,
Environment $environment,
Url $url,
$segments,
$urlAddress
) {
if ($url->getLanguage()) {
$language = $url->getLanguage();
$country = $url->getCountry();
$locale = $language . ($country ? '_' . $country : '');
$this->buildUrlFullMatch(
$portal,
$environment,
$segments,
[],
$urlAddress,
$portal->getLocalization($locale),
$url
);
} else {
// create all the urls for every localization/segment combination
foreach ($portal->getLocalizations() as $localization) {
$language = $url->getLanguage() ? $url->getLanguage() : $localization->getLanguage();
$country = $url->getCountry() ? $url->getCountry() : $localization->getCountry();
$replacers = [
ReplacerInterface::REPLACER_LANGUAGE => $language,
ReplacerInterface::REPLACER_COUNTRY => $country,
ReplacerInterface::REPLACER_LOCALIZATION => $localization->getLocale(Localization::DASH),
];
$this->buildUrlFullMatch(
$portal,
$environment,
$segments,
$replacers,
$urlAddress,
$localization,
$url
);
}
$this->buildUrlPartialMatch(
$portal,
$environment,
$urlAddress,
$url
);
}
} | [
"private",
"function",
"buildUrls",
"(",
"Portal",
"$",
"portal",
",",
"Environment",
"$",
"environment",
",",
"Url",
"$",
"url",
",",
"$",
"segments",
",",
"$",
"urlAddress",
")",
"{",
"if",
"(",
"$",
"url",
"->",
"getLanguage",
"(",
")",
")",
"{",
"$",
"language",
"=",
"$",
"url",
"->",
"getLanguage",
"(",
")",
";",
"$",
"country",
"=",
"$",
"url",
"->",
"getCountry",
"(",
")",
";",
"$",
"locale",
"=",
"$",
"language",
".",
"(",
"$",
"country",
"?",
"'_'",
".",
"$",
"country",
":",
"''",
")",
";",
"$",
"this",
"->",
"buildUrlFullMatch",
"(",
"$",
"portal",
",",
"$",
"environment",
",",
"$",
"segments",
",",
"[",
"]",
",",
"$",
"urlAddress",
",",
"$",
"portal",
"->",
"getLocalization",
"(",
"$",
"locale",
")",
",",
"$",
"url",
")",
";",
"}",
"else",
"{",
"// create all the urls for every localization/segment combination",
"foreach",
"(",
"$",
"portal",
"->",
"getLocalizations",
"(",
")",
"as",
"$",
"localization",
")",
"{",
"$",
"language",
"=",
"$",
"url",
"->",
"getLanguage",
"(",
")",
"?",
"$",
"url",
"->",
"getLanguage",
"(",
")",
":",
"$",
"localization",
"->",
"getLanguage",
"(",
")",
";",
"$",
"country",
"=",
"$",
"url",
"->",
"getCountry",
"(",
")",
"?",
"$",
"url",
"->",
"getCountry",
"(",
")",
":",
"$",
"localization",
"->",
"getCountry",
"(",
")",
";",
"$",
"replacers",
"=",
"[",
"ReplacerInterface",
"::",
"REPLACER_LANGUAGE",
"=>",
"$",
"language",
",",
"ReplacerInterface",
"::",
"REPLACER_COUNTRY",
"=>",
"$",
"country",
",",
"ReplacerInterface",
"::",
"REPLACER_LOCALIZATION",
"=>",
"$",
"localization",
"->",
"getLocale",
"(",
"Localization",
"::",
"DASH",
")",
",",
"]",
";",
"$",
"this",
"->",
"buildUrlFullMatch",
"(",
"$",
"portal",
",",
"$",
"environment",
",",
"$",
"segments",
",",
"$",
"replacers",
",",
"$",
"urlAddress",
",",
"$",
"localization",
",",
"$",
"url",
")",
";",
"}",
"$",
"this",
"->",
"buildUrlPartialMatch",
"(",
"$",
"portal",
",",
"$",
"environment",
",",
"$",
"urlAddress",
",",
"$",
"url",
")",
";",
"}",
"}"
] | Builds the URLs for the portal, which are not a redirect.
@param Portal $portal
@param Environment $environment
@param $url
@param $segments
@param $urlAddress | [
"Builds",
"the",
"URLs",
"for",
"the",
"portal",
"which",
"are",
"not",
"a",
"redirect",
"."
] | 6766a36cc2f0c807c59202bf7540a08c4ef31192 | https://github.com/sulu/sulu/blob/6766a36cc2f0c807c59202bf7540a08c4ef31192/src/Sulu/Component/Webspace/Manager/WebspaceCollectionBuilder.php#L322-L372 | train |
sulu/sulu | src/Sulu/Component/Webspace/Manager/WebspaceCollectionBuilder.php | WebspaceCollectionBuilder.generateUrlAddress | private function generateUrlAddress($pattern, $replacers)
{
foreach ($replacers as $replacer => $value) {
$pattern = $this->urlReplacer->replace($pattern, $replacer, $value);
}
return $pattern;
} | php | private function generateUrlAddress($pattern, $replacers)
{
foreach ($replacers as $replacer => $value) {
$pattern = $this->urlReplacer->replace($pattern, $replacer, $value);
}
return $pattern;
} | [
"private",
"function",
"generateUrlAddress",
"(",
"$",
"pattern",
",",
"$",
"replacers",
")",
"{",
"foreach",
"(",
"$",
"replacers",
"as",
"$",
"replacer",
"=>",
"$",
"value",
")",
"{",
"$",
"pattern",
"=",
"$",
"this",
"->",
"urlReplacer",
"->",
"replace",
"(",
"$",
"pattern",
",",
"$",
"replacer",
",",
"$",
"value",
")",
";",
"}",
"return",
"$",
"pattern",
";",
"}"
] | Replaces the given values in the pattern.
@param string $pattern
@param array $replacers
@return string | [
"Replaces",
"the",
"given",
"values",
"in",
"the",
"pattern",
"."
] | 6766a36cc2f0c807c59202bf7540a08c4ef31192 | https://github.com/sulu/sulu/blob/6766a36cc2f0c807c59202bf7540a08c4ef31192/src/Sulu/Component/Webspace/Manager/WebspaceCollectionBuilder.php#L397-L404 | train |
sulu/sulu | src/Sulu/Bundle/SecurityBundle/Entity/GroupRepository.php | GroupRepository.findAllGroups | public function findAllGroups()
{
try {
$qb = $this->createQueryBuilder('grp');
$query = $qb->getQuery();
$result = $query->getResult();
return $result;
} catch (NoResultException $ex) {
return;
}
} | php | public function findAllGroups()
{
try {
$qb = $this->createQueryBuilder('grp');
$query = $qb->getQuery();
$result = $query->getResult();
return $result;
} catch (NoResultException $ex) {
return;
}
} | [
"public",
"function",
"findAllGroups",
"(",
")",
"{",
"try",
"{",
"$",
"qb",
"=",
"$",
"this",
"->",
"createQueryBuilder",
"(",
"'grp'",
")",
";",
"$",
"query",
"=",
"$",
"qb",
"->",
"getQuery",
"(",
")",
";",
"$",
"result",
"=",
"$",
"query",
"->",
"getResult",
"(",
")",
";",
"return",
"$",
"result",
";",
"}",
"catch",
"(",
"NoResultException",
"$",
"ex",
")",
"{",
"return",
";",
"}",
"}"
] | Searches for all roles.
@return array | [
"Searches",
"for",
"all",
"roles",
"."
] | 6766a36cc2f0c807c59202bf7540a08c4ef31192 | https://github.com/sulu/sulu/blob/6766a36cc2f0c807c59202bf7540a08c4ef31192/src/Sulu/Bundle/SecurityBundle/Entity/GroupRepository.php#L54-L66 | train |
sulu/sulu | src/Sulu/Bundle/MediaBundle/Search/Subscriber/StructureMediaSearchSubscriber.php | StructureMediaSearchSubscriber.getImageUrl | private function getImageUrl($data, $locale)
{
// new structures will container an instance of MediaSelectionContainer
if ($data instanceof MediaSelectionContainer) {
$medias = $data->getData('de');
// old ones an array ...
} else {
if (!isset($data['ids'])) {
throw new \RuntimeException(
sprintf('Was expecting media value to contain array key "ids", got: "%s"', print_r($data, true))
);
}
$medias = $this->mediaManager->get($locale, [
'ids' => $data['ids'],
]);
}
// no media, no thumbnail URL
if (!$medias) {
return;
}
$media = current($medias);
if (!$media) {
return;
}
$formats = $media->getThumbnails();
if (!isset($formats[$this->searchImageFormat])) {
throw new \InvalidArgumentException(
sprintf('Search image format "%s" is not known', $this->searchImageFormat)
);
}
return $formats[$this->searchImageFormat];
} | php | private function getImageUrl($data, $locale)
{
// new structures will container an instance of MediaSelectionContainer
if ($data instanceof MediaSelectionContainer) {
$medias = $data->getData('de');
// old ones an array ...
} else {
if (!isset($data['ids'])) {
throw new \RuntimeException(
sprintf('Was expecting media value to contain array key "ids", got: "%s"', print_r($data, true))
);
}
$medias = $this->mediaManager->get($locale, [
'ids' => $data['ids'],
]);
}
// no media, no thumbnail URL
if (!$medias) {
return;
}
$media = current($medias);
if (!$media) {
return;
}
$formats = $media->getThumbnails();
if (!isset($formats[$this->searchImageFormat])) {
throw new \InvalidArgumentException(
sprintf('Search image format "%s" is not known', $this->searchImageFormat)
);
}
return $formats[$this->searchImageFormat];
} | [
"private",
"function",
"getImageUrl",
"(",
"$",
"data",
",",
"$",
"locale",
")",
"{",
"// new structures will container an instance of MediaSelectionContainer",
"if",
"(",
"$",
"data",
"instanceof",
"MediaSelectionContainer",
")",
"{",
"$",
"medias",
"=",
"$",
"data",
"->",
"getData",
"(",
"'de'",
")",
";",
"// old ones an array ...",
"}",
"else",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"data",
"[",
"'ids'",
"]",
")",
")",
"{",
"throw",
"new",
"\\",
"RuntimeException",
"(",
"sprintf",
"(",
"'Was expecting media value to contain array key \"ids\", got: \"%s\"'",
",",
"print_r",
"(",
"$",
"data",
",",
"true",
")",
")",
")",
";",
"}",
"$",
"medias",
"=",
"$",
"this",
"->",
"mediaManager",
"->",
"get",
"(",
"$",
"locale",
",",
"[",
"'ids'",
"=>",
"$",
"data",
"[",
"'ids'",
"]",
",",
"]",
")",
";",
"}",
"// no media, no thumbnail URL",
"if",
"(",
"!",
"$",
"medias",
")",
"{",
"return",
";",
"}",
"$",
"media",
"=",
"current",
"(",
"$",
"medias",
")",
";",
"if",
"(",
"!",
"$",
"media",
")",
"{",
"return",
";",
"}",
"$",
"formats",
"=",
"$",
"media",
"->",
"getThumbnails",
"(",
")",
";",
"if",
"(",
"!",
"isset",
"(",
"$",
"formats",
"[",
"$",
"this",
"->",
"searchImageFormat",
"]",
")",
")",
"{",
"throw",
"new",
"\\",
"InvalidArgumentException",
"(",
"sprintf",
"(",
"'Search image format \"%s\" is not known'",
",",
"$",
"this",
"->",
"searchImageFormat",
")",
")",
";",
"}",
"return",
"$",
"formats",
"[",
"$",
"this",
"->",
"searchImageFormat",
"]",
";",
"}"
] | Returns the url for the image.
@param $data
@param $locale
@throws \RuntimeException
@throws \InvalidArgumentException | [
"Returns",
"the",
"url",
"for",
"the",
"image",
"."
] | 6766a36cc2f0c807c59202bf7540a08c4ef31192 | https://github.com/sulu/sulu/blob/6766a36cc2f0c807c59202bf7540a08c4ef31192/src/Sulu/Bundle/MediaBundle/Search/Subscriber/StructureMediaSearchSubscriber.php#L114-L152 | train |
sulu/sulu | src/Sulu/Bundle/PageBundle/Preview/PageRouteDefaultsProvider.php | PageRouteDefaultsProvider.documentToStructure | protected function documentToStructure(BasePageDocument $document)
{
$structure = $this->inspector->getStructureMetadata($document);
$documentAlias = $this->inspector->getMetadata($document)->getAlias();
$structureBridge = $this->structureManager->wrapStructure($documentAlias, $structure);
$structureBridge->setDocument($document);
return $structureBridge;
} | php | protected function documentToStructure(BasePageDocument $document)
{
$structure = $this->inspector->getStructureMetadata($document);
$documentAlias = $this->inspector->getMetadata($document)->getAlias();
$structureBridge = $this->structureManager->wrapStructure($documentAlias, $structure);
$structureBridge->setDocument($document);
return $structureBridge;
} | [
"protected",
"function",
"documentToStructure",
"(",
"BasePageDocument",
"$",
"document",
")",
"{",
"$",
"structure",
"=",
"$",
"this",
"->",
"inspector",
"->",
"getStructureMetadata",
"(",
"$",
"document",
")",
";",
"$",
"documentAlias",
"=",
"$",
"this",
"->",
"inspector",
"->",
"getMetadata",
"(",
"$",
"document",
")",
"->",
"getAlias",
"(",
")",
";",
"$",
"structureBridge",
"=",
"$",
"this",
"->",
"structureManager",
"->",
"wrapStructure",
"(",
"$",
"documentAlias",
",",
"$",
"structure",
")",
";",
"$",
"structureBridge",
"->",
"setDocument",
"(",
"$",
"document",
")",
";",
"return",
"$",
"structureBridge",
";",
"}"
] | Return a structure bridge corresponding to the given document.
@param BasePageDocument $document
@return PageBridge | [
"Return",
"a",
"structure",
"bridge",
"corresponding",
"to",
"the",
"given",
"document",
"."
] | 6766a36cc2f0c807c59202bf7540a08c4ef31192 | https://github.com/sulu/sulu/blob/6766a36cc2f0c807c59202bf7540a08c4ef31192/src/Sulu/Bundle/PageBundle/Preview/PageRouteDefaultsProvider.php#L104-L113 | train |
sulu/sulu | src/Sulu/Bundle/MediaBundle/Controller/MediaRedirectController.php | MediaRedirectController.redirectAction | public function redirectAction(Request $request, $id)
{
$locale = $this->getRequestParameter($request, 'locale', true);
$format = $this->getRequestParameter($request, 'format');
/** @var Media $media */
$media = $this->container->get('sulu_media.media_manager')->getById($id, $locale);
if (null === $format) {
return $this->redirect($media->getUrl());
}
if (!array_key_exists($format, $media->getFormats())) {
throw $this->createNotFoundException();
}
return $this->redirect($media->getFormats()[$format]);
} | php | public function redirectAction(Request $request, $id)
{
$locale = $this->getRequestParameter($request, 'locale', true);
$format = $this->getRequestParameter($request, 'format');
/** @var Media $media */
$media = $this->container->get('sulu_media.media_manager')->getById($id, $locale);
if (null === $format) {
return $this->redirect($media->getUrl());
}
if (!array_key_exists($format, $media->getFormats())) {
throw $this->createNotFoundException();
}
return $this->redirect($media->getFormats()[$format]);
} | [
"public",
"function",
"redirectAction",
"(",
"Request",
"$",
"request",
",",
"$",
"id",
")",
"{",
"$",
"locale",
"=",
"$",
"this",
"->",
"getRequestParameter",
"(",
"$",
"request",
",",
"'locale'",
",",
"true",
")",
";",
"$",
"format",
"=",
"$",
"this",
"->",
"getRequestParameter",
"(",
"$",
"request",
",",
"'format'",
")",
";",
"/** @var Media $media */",
"$",
"media",
"=",
"$",
"this",
"->",
"container",
"->",
"get",
"(",
"'sulu_media.media_manager'",
")",
"->",
"getById",
"(",
"$",
"id",
",",
"$",
"locale",
")",
";",
"if",
"(",
"null",
"===",
"$",
"format",
")",
"{",
"return",
"$",
"this",
"->",
"redirect",
"(",
"$",
"media",
"->",
"getUrl",
"(",
")",
")",
";",
"}",
"if",
"(",
"!",
"array_key_exists",
"(",
"$",
"format",
",",
"$",
"media",
"->",
"getFormats",
"(",
")",
")",
")",
"{",
"throw",
"$",
"this",
"->",
"createNotFoundException",
"(",
")",
";",
"}",
"return",
"$",
"this",
"->",
"redirect",
"(",
"$",
"media",
"->",
"getFormats",
"(",
")",
"[",
"$",
"format",
"]",
")",
";",
"}"
] | Redirects to format or original url.
@param Request $request
@param int $id
@return RedirectResponse | [
"Redirects",
"to",
"format",
"or",
"original",
"url",
"."
] | 6766a36cc2f0c807c59202bf7540a08c4ef31192 | https://github.com/sulu/sulu/blob/6766a36cc2f0c807c59202bf7540a08c4ef31192/src/Sulu/Bundle/MediaBundle/Controller/MediaRedirectController.php#L35-L52 | train |
sulu/sulu | src/Sulu/Bundle/SnippetBundle/Controller/SnippetAreaController.php | SnippetAreaController.putAction | public function putAction(Request $request, $key)
{
$webspaceKey = $this->getRequestParameter($request, 'webspace', true);
$this->get('sulu_security.security_checker')->checkPermission(
new SecurityCondition(SnippetAdmin::getDefaultSnippetsSecurityContext($webspaceKey)),
PermissionTypes::EDIT
);
$default = $request->get('defaultUuid');
$areas = $this->getLocalizedAreas();
$area = $areas[$key];
$defaultSnippet = $this->get('sulu_snippet.default_snippet.manager')->save(
$webspaceKey,
$key,
$default,
$this->getUser()->getLocale()
);
return new JsonResponse(
[
'key' => $key,
'template' => $area['template'],
'title' => $area['title'],
'defaultUuid' => $defaultSnippet ? $defaultSnippet->getUuid() : null,
'defaultTitle' => $defaultSnippet ? $defaultSnippet->getTitle() : null,
'valid' => true,
]
);
} | php | public function putAction(Request $request, $key)
{
$webspaceKey = $this->getRequestParameter($request, 'webspace', true);
$this->get('sulu_security.security_checker')->checkPermission(
new SecurityCondition(SnippetAdmin::getDefaultSnippetsSecurityContext($webspaceKey)),
PermissionTypes::EDIT
);
$default = $request->get('defaultUuid');
$areas = $this->getLocalizedAreas();
$area = $areas[$key];
$defaultSnippet = $this->get('sulu_snippet.default_snippet.manager')->save(
$webspaceKey,
$key,
$default,
$this->getUser()->getLocale()
);
return new JsonResponse(
[
'key' => $key,
'template' => $area['template'],
'title' => $area['title'],
'defaultUuid' => $defaultSnippet ? $defaultSnippet->getUuid() : null,
'defaultTitle' => $defaultSnippet ? $defaultSnippet->getTitle() : null,
'valid' => true,
]
);
} | [
"public",
"function",
"putAction",
"(",
"Request",
"$",
"request",
",",
"$",
"key",
")",
"{",
"$",
"webspaceKey",
"=",
"$",
"this",
"->",
"getRequestParameter",
"(",
"$",
"request",
",",
"'webspace'",
",",
"true",
")",
";",
"$",
"this",
"->",
"get",
"(",
"'sulu_security.security_checker'",
")",
"->",
"checkPermission",
"(",
"new",
"SecurityCondition",
"(",
"SnippetAdmin",
"::",
"getDefaultSnippetsSecurityContext",
"(",
"$",
"webspaceKey",
")",
")",
",",
"PermissionTypes",
"::",
"EDIT",
")",
";",
"$",
"default",
"=",
"$",
"request",
"->",
"get",
"(",
"'defaultUuid'",
")",
";",
"$",
"areas",
"=",
"$",
"this",
"->",
"getLocalizedAreas",
"(",
")",
";",
"$",
"area",
"=",
"$",
"areas",
"[",
"$",
"key",
"]",
";",
"$",
"defaultSnippet",
"=",
"$",
"this",
"->",
"get",
"(",
"'sulu_snippet.default_snippet.manager'",
")",
"->",
"save",
"(",
"$",
"webspaceKey",
",",
"$",
"key",
",",
"$",
"default",
",",
"$",
"this",
"->",
"getUser",
"(",
")",
"->",
"getLocale",
"(",
")",
")",
";",
"return",
"new",
"JsonResponse",
"(",
"[",
"'key'",
"=>",
"$",
"key",
",",
"'template'",
"=>",
"$",
"area",
"[",
"'template'",
"]",
",",
"'title'",
"=>",
"$",
"area",
"[",
"'title'",
"]",
",",
"'defaultUuid'",
"=>",
"$",
"defaultSnippet",
"?",
"$",
"defaultSnippet",
"->",
"getUuid",
"(",
")",
":",
"null",
",",
"'defaultTitle'",
"=>",
"$",
"defaultSnippet",
"?",
"$",
"defaultSnippet",
"->",
"getTitle",
"(",
")",
":",
"null",
",",
"'valid'",
"=>",
"true",
",",
"]",
")",
";",
"}"
] | Put default action.
@param Request $request
@param string $key
@return JsonResponse | [
"Put",
"default",
"action",
"."
] | 6766a36cc2f0c807c59202bf7540a08c4ef31192 | https://github.com/sulu/sulu/blob/6766a36cc2f0c807c59202bf7540a08c4ef31192/src/Sulu/Bundle/SnippetBundle/Controller/SnippetAreaController.php#L101-L131 | train |
sulu/sulu | src/Sulu/Bundle/SnippetBundle/Controller/SnippetAreaController.php | SnippetAreaController.deleteAction | public function deleteAction(Request $request, $key)
{
$webspaceKey = $this->getRequestParameter($request, 'webspace', true);
$this->get('sulu_security.security_checker')->checkPermission(
new SecurityCondition(SnippetAdmin::getDefaultSnippetsSecurityContext($webspaceKey)),
PermissionTypes::EDIT
);
$areas = $this->getLocalizedAreas();
$area = $areas[$key];
$this->get('sulu_snippet.default_snippet.manager')->remove($webspaceKey, $key);
return new JsonResponse(
[
'key' => $key,
'template' => $area['template'],
'title' => $area['title'],
'defaultUuid' => null,
'defaultTitle' => null,
'valid' => true,
]
);
} | php | public function deleteAction(Request $request, $key)
{
$webspaceKey = $this->getRequestParameter($request, 'webspace', true);
$this->get('sulu_security.security_checker')->checkPermission(
new SecurityCondition(SnippetAdmin::getDefaultSnippetsSecurityContext($webspaceKey)),
PermissionTypes::EDIT
);
$areas = $this->getLocalizedAreas();
$area = $areas[$key];
$this->get('sulu_snippet.default_snippet.manager')->remove($webspaceKey, $key);
return new JsonResponse(
[
'key' => $key,
'template' => $area['template'],
'title' => $area['title'],
'defaultUuid' => null,
'defaultTitle' => null,
'valid' => true,
]
);
} | [
"public",
"function",
"deleteAction",
"(",
"Request",
"$",
"request",
",",
"$",
"key",
")",
"{",
"$",
"webspaceKey",
"=",
"$",
"this",
"->",
"getRequestParameter",
"(",
"$",
"request",
",",
"'webspace'",
",",
"true",
")",
";",
"$",
"this",
"->",
"get",
"(",
"'sulu_security.security_checker'",
")",
"->",
"checkPermission",
"(",
"new",
"SecurityCondition",
"(",
"SnippetAdmin",
"::",
"getDefaultSnippetsSecurityContext",
"(",
"$",
"webspaceKey",
")",
")",
",",
"PermissionTypes",
"::",
"EDIT",
")",
";",
"$",
"areas",
"=",
"$",
"this",
"->",
"getLocalizedAreas",
"(",
")",
";",
"$",
"area",
"=",
"$",
"areas",
"[",
"$",
"key",
"]",
";",
"$",
"this",
"->",
"get",
"(",
"'sulu_snippet.default_snippet.manager'",
")",
"->",
"remove",
"(",
"$",
"webspaceKey",
",",
"$",
"key",
")",
";",
"return",
"new",
"JsonResponse",
"(",
"[",
"'key'",
"=>",
"$",
"key",
",",
"'template'",
"=>",
"$",
"area",
"[",
"'template'",
"]",
",",
"'title'",
"=>",
"$",
"area",
"[",
"'title'",
"]",
",",
"'defaultUuid'",
"=>",
"null",
",",
"'defaultTitle'",
"=>",
"null",
",",
"'valid'",
"=>",
"true",
",",
"]",
")",
";",
"}"
] | Delete default action.
@param Request $request
@param string $key
@return JsonResponse | [
"Delete",
"default",
"action",
"."
] | 6766a36cc2f0c807c59202bf7540a08c4ef31192 | https://github.com/sulu/sulu/blob/6766a36cc2f0c807c59202bf7540a08c4ef31192/src/Sulu/Bundle/SnippetBundle/Controller/SnippetAreaController.php#L141-L164 | train |
sulu/sulu | src/Sulu/Bundle/SecurityBundle/UserManager/UserManager.php | UserManager.delete | public function delete()
{
$delete = function($id) {
$user = $this->userRepository->findUserById($id);
if (!$user) {
throw new EntityNotFoundException($this->userRepository->getClassName(), $id);
}
$this->em->remove($user);
$this->em->flush();
};
return $delete;
} | php | public function delete()
{
$delete = function($id) {
$user = $this->userRepository->findUserById($id);
if (!$user) {
throw new EntityNotFoundException($this->userRepository->getClassName(), $id);
}
$this->em->remove($user);
$this->em->flush();
};
return $delete;
} | [
"public",
"function",
"delete",
"(",
")",
"{",
"$",
"delete",
"=",
"function",
"(",
"$",
"id",
")",
"{",
"$",
"user",
"=",
"$",
"this",
"->",
"userRepository",
"->",
"findUserById",
"(",
"$",
"id",
")",
";",
"if",
"(",
"!",
"$",
"user",
")",
"{",
"throw",
"new",
"EntityNotFoundException",
"(",
"$",
"this",
"->",
"userRepository",
"->",
"getClassName",
"(",
")",
",",
"$",
"id",
")",
";",
"}",
"$",
"this",
"->",
"em",
"->",
"remove",
"(",
"$",
"user",
")",
";",
"$",
"this",
"->",
"em",
"->",
"flush",
"(",
")",
";",
"}",
";",
"return",
"$",
"delete",
";",
"}"
] | Deletes a user with the given id.
@return \Closure | [
"Deletes",
"a",
"user",
"with",
"the",
"given",
"id",
"."
] | 6766a36cc2f0c807c59202bf7540a08c4ef31192 | https://github.com/sulu/sulu/blob/6766a36cc2f0c807c59202bf7540a08c4ef31192/src/Sulu/Bundle/SecurityBundle/UserManager/UserManager.php#L107-L120 | train |
sulu/sulu | src/Sulu/Bundle/SecurityBundle/UserManager/UserManager.php | UserManager.isUsernameUnique | public function isUsernameUnique($username)
{
if ($username) {
try {
$this->userRepository->findUserByUsername($username);
} catch (NoResultException $exc) {
return true;
}
}
return false;
} | php | public function isUsernameUnique($username)
{
if ($username) {
try {
$this->userRepository->findUserByUsername($username);
} catch (NoResultException $exc) {
return true;
}
}
return false;
} | [
"public",
"function",
"isUsernameUnique",
"(",
"$",
"username",
")",
"{",
"if",
"(",
"$",
"username",
")",
"{",
"try",
"{",
"$",
"this",
"->",
"userRepository",
"->",
"findUserByUsername",
"(",
"$",
"username",
")",
";",
"}",
"catch",
"(",
"NoResultException",
"$",
"exc",
")",
"{",
"return",
"true",
";",
"}",
"}",
"return",
"false",
";",
"}"
] | Checks if a username is unique
Null and empty will always return false.
@param string $username
@return bool | [
"Checks",
"if",
"a",
"username",
"is",
"unique",
"Null",
"and",
"empty",
"will",
"always",
"return",
"false",
"."
] | 6766a36cc2f0c807c59202bf7540a08c4ef31192 | https://github.com/sulu/sulu/blob/6766a36cc2f0c807c59202bf7540a08c4ef31192/src/Sulu/Bundle/SecurityBundle/UserManager/UserManager.php#L281-L292 | train |
sulu/sulu | src/Sulu/Bundle/SecurityBundle/UserManager/UserManager.php | UserManager.isEmailUnique | public function isEmailUnique($email)
{
if ($email) {
try {
$this->userRepository->findUserByEmail($email);
} catch (NoResultException $exc) {
return true;
}
}
return false;
} | php | public function isEmailUnique($email)
{
if ($email) {
try {
$this->userRepository->findUserByEmail($email);
} catch (NoResultException $exc) {
return true;
}
}
return false;
} | [
"public",
"function",
"isEmailUnique",
"(",
"$",
"email",
")",
"{",
"if",
"(",
"$",
"email",
")",
"{",
"try",
"{",
"$",
"this",
"->",
"userRepository",
"->",
"findUserByEmail",
"(",
"$",
"email",
")",
";",
"}",
"catch",
"(",
"NoResultException",
"$",
"exc",
")",
"{",
"return",
"true",
";",
"}",
"}",
"return",
"false",
";",
"}"
] | Checks if an email-adress is unique
Null and empty will always return false.
@param string $email
@return bool | [
"Checks",
"if",
"an",
"email",
"-",
"adress",
"is",
"unique",
"Null",
"and",
"empty",
"will",
"always",
"return",
"false",
"."
] | 6766a36cc2f0c807c59202bf7540a08c4ef31192 | https://github.com/sulu/sulu/blob/6766a36cc2f0c807c59202bf7540a08c4ef31192/src/Sulu/Bundle/SecurityBundle/UserManager/UserManager.php#L302-L313 | train |
sulu/sulu | src/Sulu/Bundle/SecurityBundle/UserManager/UserManager.php | UserManager.processUserRoles | public function processUserRoles(UserInterface $user, $userRoles)
{
$get = function($entity) {
/* @var UserInterface $entity */
return $entity->getId();
};
$delete = function($userRole) use ($user) {
$user->removeUserRole($userRole);
$this->em->remove($userRole);
};
$update = function($userRole, $userRoleData) {
return $this->updateUserRole($userRole, $userRoleData);
};
$add = function($userRole) use ($user) {
return $this->addUserRole($user, $userRole);
};
$entities = $user->getUserRoles();
$result = $this->processSubEntities(
$entities,
$userRoles,
$get,
$add,
$update,
$delete
);
$this->resetIndexOfSubentites($entities);
return $result;
} | php | public function processUserRoles(UserInterface $user, $userRoles)
{
$get = function($entity) {
/* @var UserInterface $entity */
return $entity->getId();
};
$delete = function($userRole) use ($user) {
$user->removeUserRole($userRole);
$this->em->remove($userRole);
};
$update = function($userRole, $userRoleData) {
return $this->updateUserRole($userRole, $userRoleData);
};
$add = function($userRole) use ($user) {
return $this->addUserRole($user, $userRole);
};
$entities = $user->getUserRoles();
$result = $this->processSubEntities(
$entities,
$userRoles,
$get,
$add,
$update,
$delete
);
$this->resetIndexOfSubentites($entities);
return $result;
} | [
"public",
"function",
"processUserRoles",
"(",
"UserInterface",
"$",
"user",
",",
"$",
"userRoles",
")",
"{",
"$",
"get",
"=",
"function",
"(",
"$",
"entity",
")",
"{",
"/* @var UserInterface $entity */",
"return",
"$",
"entity",
"->",
"getId",
"(",
")",
";",
"}",
";",
"$",
"delete",
"=",
"function",
"(",
"$",
"userRole",
")",
"use",
"(",
"$",
"user",
")",
"{",
"$",
"user",
"->",
"removeUserRole",
"(",
"$",
"userRole",
")",
";",
"$",
"this",
"->",
"em",
"->",
"remove",
"(",
"$",
"userRole",
")",
";",
"}",
";",
"$",
"update",
"=",
"function",
"(",
"$",
"userRole",
",",
"$",
"userRoleData",
")",
"{",
"return",
"$",
"this",
"->",
"updateUserRole",
"(",
"$",
"userRole",
",",
"$",
"userRoleData",
")",
";",
"}",
";",
"$",
"add",
"=",
"function",
"(",
"$",
"userRole",
")",
"use",
"(",
"$",
"user",
")",
"{",
"return",
"$",
"this",
"->",
"addUserRole",
"(",
"$",
"user",
",",
"$",
"userRole",
")",
";",
"}",
";",
"$",
"entities",
"=",
"$",
"user",
"->",
"getUserRoles",
"(",
")",
";",
"$",
"result",
"=",
"$",
"this",
"->",
"processSubEntities",
"(",
"$",
"entities",
",",
"$",
"userRoles",
",",
"$",
"get",
",",
"$",
"add",
",",
"$",
"update",
",",
"$",
"delete",
")",
";",
"$",
"this",
"->",
"resetIndexOfSubentites",
"(",
"$",
"entities",
")",
";",
"return",
"$",
"result",
";",
"}"
] | Process all user roles from request.
@param UserInterface $user
@param array $userRoles
@return bool True if the processing was successful, otherwise false | [
"Process",
"all",
"user",
"roles",
"from",
"request",
"."
] | 6766a36cc2f0c807c59202bf7540a08c4ef31192 | https://github.com/sulu/sulu/blob/6766a36cc2f0c807c59202bf7540a08c4ef31192/src/Sulu/Bundle/SecurityBundle/UserManager/UserManager.php#L351-L385 | train |
sulu/sulu | src/Sulu/Bundle/SecurityBundle/UserManager/UserManager.php | UserManager.processUserGroups | protected function processUserGroups(UserInterface $user, $userGroups)
{
$get = function($entity) {
/* @var UserInterface $entity */
return $entity->getId();
};
$delete = function($userGroup) use ($user) {
$user->removeUserGroup($userGroup);
$this->em->remove($userGroup);
};
$update = function($userGroup, $userGroupData) {
return $this->updateUserGroup($userGroup, $userGroupData);
};
$add = function($userGroup) use ($user) {
return $this->addUserGroup($user, $userGroup);
};
$entities = $user->getUserGroups();
$result = $this->processSubEntities(
$entities,
$userGroups,
$get,
$add,
$update,
$delete
);
$this->resetIndexOfSubentites($entities);
return $result;
} | php | protected function processUserGroups(UserInterface $user, $userGroups)
{
$get = function($entity) {
/* @var UserInterface $entity */
return $entity->getId();
};
$delete = function($userGroup) use ($user) {
$user->removeUserGroup($userGroup);
$this->em->remove($userGroup);
};
$update = function($userGroup, $userGroupData) {
return $this->updateUserGroup($userGroup, $userGroupData);
};
$add = function($userGroup) use ($user) {
return $this->addUserGroup($user, $userGroup);
};
$entities = $user->getUserGroups();
$result = $this->processSubEntities(
$entities,
$userGroups,
$get,
$add,
$update,
$delete
);
$this->resetIndexOfSubentites($entities);
return $result;
} | [
"protected",
"function",
"processUserGroups",
"(",
"UserInterface",
"$",
"user",
",",
"$",
"userGroups",
")",
"{",
"$",
"get",
"=",
"function",
"(",
"$",
"entity",
")",
"{",
"/* @var UserInterface $entity */",
"return",
"$",
"entity",
"->",
"getId",
"(",
")",
";",
"}",
";",
"$",
"delete",
"=",
"function",
"(",
"$",
"userGroup",
")",
"use",
"(",
"$",
"user",
")",
"{",
"$",
"user",
"->",
"removeUserGroup",
"(",
"$",
"userGroup",
")",
";",
"$",
"this",
"->",
"em",
"->",
"remove",
"(",
"$",
"userGroup",
")",
";",
"}",
";",
"$",
"update",
"=",
"function",
"(",
"$",
"userGroup",
",",
"$",
"userGroupData",
")",
"{",
"return",
"$",
"this",
"->",
"updateUserGroup",
"(",
"$",
"userGroup",
",",
"$",
"userGroupData",
")",
";",
"}",
";",
"$",
"add",
"=",
"function",
"(",
"$",
"userGroup",
")",
"use",
"(",
"$",
"user",
")",
"{",
"return",
"$",
"this",
"->",
"addUserGroup",
"(",
"$",
"user",
",",
"$",
"userGroup",
")",
";",
"}",
";",
"$",
"entities",
"=",
"$",
"user",
"->",
"getUserGroups",
"(",
")",
";",
"$",
"result",
"=",
"$",
"this",
"->",
"processSubEntities",
"(",
"$",
"entities",
",",
"$",
"userGroups",
",",
"$",
"get",
",",
"$",
"add",
",",
"$",
"update",
",",
"$",
"delete",
")",
";",
"$",
"this",
"->",
"resetIndexOfSubentites",
"(",
"$",
"entities",
")",
";",
"return",
"$",
"result",
";",
"}"
] | Process all user groups from request.
@param UserInterface $user
@param $userGroups
@return bool True if the processing was successful, otherwise false | [
"Process",
"all",
"user",
"groups",
"from",
"request",
"."
] | 6766a36cc2f0c807c59202bf7540a08c4ef31192 | https://github.com/sulu/sulu/blob/6766a36cc2f0c807c59202bf7540a08c4ef31192/src/Sulu/Bundle/SecurityBundle/UserManager/UserManager.php#L395-L429 | train |
sulu/sulu | src/Sulu/Bundle/SecurityBundle/UserManager/UserManager.php | UserManager.updateUserRole | private function updateUserRole(UserRole $userRole, $userRoleData)
{
$role = $this->roleRepository->findRoleById($userRoleData['role']['id']);
if (!$role) {
throw new EntityNotFoundException($this->roleRepository->getClassName(), $userRole['role']['id']);
}
$userRole->setRole($role);
if (array_key_exists('locales', $userRoleData)) {
$userRole->setLocale(json_encode($userRoleData['locales']));
} else {
$userRole->setLocale($userRoleData['locale']);
}
return true;
} | php | private function updateUserRole(UserRole $userRole, $userRoleData)
{
$role = $this->roleRepository->findRoleById($userRoleData['role']['id']);
if (!$role) {
throw new EntityNotFoundException($this->roleRepository->getClassName(), $userRole['role']['id']);
}
$userRole->setRole($role);
if (array_key_exists('locales', $userRoleData)) {
$userRole->setLocale(json_encode($userRoleData['locales']));
} else {
$userRole->setLocale($userRoleData['locale']);
}
return true;
} | [
"private",
"function",
"updateUserRole",
"(",
"UserRole",
"$",
"userRole",
",",
"$",
"userRoleData",
")",
"{",
"$",
"role",
"=",
"$",
"this",
"->",
"roleRepository",
"->",
"findRoleById",
"(",
"$",
"userRoleData",
"[",
"'role'",
"]",
"[",
"'id'",
"]",
")",
";",
"if",
"(",
"!",
"$",
"role",
")",
"{",
"throw",
"new",
"EntityNotFoundException",
"(",
"$",
"this",
"->",
"roleRepository",
"->",
"getClassName",
"(",
")",
",",
"$",
"userRole",
"[",
"'role'",
"]",
"[",
"'id'",
"]",
")",
";",
"}",
"$",
"userRole",
"->",
"setRole",
"(",
"$",
"role",
")",
";",
"if",
"(",
"array_key_exists",
"(",
"'locales'",
",",
"$",
"userRoleData",
")",
")",
"{",
"$",
"userRole",
"->",
"setLocale",
"(",
"json_encode",
"(",
"$",
"userRoleData",
"[",
"'locales'",
"]",
")",
")",
";",
"}",
"else",
"{",
"$",
"userRole",
"->",
"setLocale",
"(",
"$",
"userRoleData",
"[",
"'locale'",
"]",
")",
";",
"}",
"return",
"true",
";",
"}"
] | Updates an existing UserRole with the given data.
@param UserRole $userRole
@param $userRoleData
@throws \Sulu\Component\Rest\Exception\EntityNotFoundException
@return bool | [
"Updates",
"an",
"existing",
"UserRole",
"with",
"the",
"given",
"data",
"."
] | 6766a36cc2f0c807c59202bf7540a08c4ef31192 | https://github.com/sulu/sulu/blob/6766a36cc2f0c807c59202bf7540a08c4ef31192/src/Sulu/Bundle/SecurityBundle/UserManager/UserManager.php#L441-L457 | train |
sulu/sulu | src/Sulu/Bundle/SecurityBundle/UserManager/UserManager.php | UserManager.addUserRole | private function addUserRole(UserInterface $user, $userRoleData)
{
$alreadyContains = false;
$role = $this->roleRepository->findRoleById($userRoleData['role']['id']);
if (!$role) {
throw new EntityNotFoundException($this->roleRepository->getClassName(), $userRoleData['role']['id']);
}
if ($user->getUserRoles()) {
foreach ($user->getUserRoles() as $containedRole) {
if ($containedRole->getRole()->getId() === $role->getId()) {
$alreadyContains = true;
}
}
}
if (false === $alreadyContains) {
$userRole = new UserRole();
$userRole->setUser($user);
$userRole->setRole($role);
$userRole->setLocale(json_encode($userRoleData['locales']));
$this->em->persist($userRole);
$user->addUserRole($userRole);
}
return true;
} | php | private function addUserRole(UserInterface $user, $userRoleData)
{
$alreadyContains = false;
$role = $this->roleRepository->findRoleById($userRoleData['role']['id']);
if (!$role) {
throw new EntityNotFoundException($this->roleRepository->getClassName(), $userRoleData['role']['id']);
}
if ($user->getUserRoles()) {
foreach ($user->getUserRoles() as $containedRole) {
if ($containedRole->getRole()->getId() === $role->getId()) {
$alreadyContains = true;
}
}
}
if (false === $alreadyContains) {
$userRole = new UserRole();
$userRole->setUser($user);
$userRole->setRole($role);
$userRole->setLocale(json_encode($userRoleData['locales']));
$this->em->persist($userRole);
$user->addUserRole($userRole);
}
return true;
} | [
"private",
"function",
"addUserRole",
"(",
"UserInterface",
"$",
"user",
",",
"$",
"userRoleData",
")",
"{",
"$",
"alreadyContains",
"=",
"false",
";",
"$",
"role",
"=",
"$",
"this",
"->",
"roleRepository",
"->",
"findRoleById",
"(",
"$",
"userRoleData",
"[",
"'role'",
"]",
"[",
"'id'",
"]",
")",
";",
"if",
"(",
"!",
"$",
"role",
")",
"{",
"throw",
"new",
"EntityNotFoundException",
"(",
"$",
"this",
"->",
"roleRepository",
"->",
"getClassName",
"(",
")",
",",
"$",
"userRoleData",
"[",
"'role'",
"]",
"[",
"'id'",
"]",
")",
";",
"}",
"if",
"(",
"$",
"user",
"->",
"getUserRoles",
"(",
")",
")",
"{",
"foreach",
"(",
"$",
"user",
"->",
"getUserRoles",
"(",
")",
"as",
"$",
"containedRole",
")",
"{",
"if",
"(",
"$",
"containedRole",
"->",
"getRole",
"(",
")",
"->",
"getId",
"(",
")",
"===",
"$",
"role",
"->",
"getId",
"(",
")",
")",
"{",
"$",
"alreadyContains",
"=",
"true",
";",
"}",
"}",
"}",
"if",
"(",
"false",
"===",
"$",
"alreadyContains",
")",
"{",
"$",
"userRole",
"=",
"new",
"UserRole",
"(",
")",
";",
"$",
"userRole",
"->",
"setUser",
"(",
"$",
"user",
")",
";",
"$",
"userRole",
"->",
"setRole",
"(",
"$",
"role",
")",
";",
"$",
"userRole",
"->",
"setLocale",
"(",
"json_encode",
"(",
"$",
"userRoleData",
"[",
"'locales'",
"]",
")",
")",
";",
"$",
"this",
"->",
"em",
"->",
"persist",
"(",
"$",
"userRole",
")",
";",
"$",
"user",
"->",
"addUserRole",
"(",
"$",
"userRole",
")",
";",
"}",
"return",
"true",
";",
"}"
] | Adds a new UserRole to the given user.
@param UserInterface $user
@param $userRoleData
@throws \Sulu\Component\Rest\Exception\EntityNotFoundException
@return bool | [
"Adds",
"a",
"new",
"UserRole",
"to",
"the",
"given",
"user",
"."
] | 6766a36cc2f0c807c59202bf7540a08c4ef31192 | https://github.com/sulu/sulu/blob/6766a36cc2f0c807c59202bf7540a08c4ef31192/src/Sulu/Bundle/SecurityBundle/UserManager/UserManager.php#L469-L498 | train |
sulu/sulu | src/Sulu/Bundle/SecurityBundle/UserManager/UserManager.php | UserManager.addUserGroup | private function addUserGroup(UserInterface $user, $userGroupData)
{
$group = $this->groupRepository->findGroupById($userGroupData['group']['id']);
if (!$group) {
throw new EntityNotFoundException($this->groupRepository->getClassName(), $userGroupData['group']['id']);
}
$userGroup = new UserGroup();
$userGroup->setUser($user);
$userGroup->setGroup($group);
$userGroup->setLocale(json_encode($userGroupData['locales']));
$this->em->persist($userGroup);
$user->addUserGroup($userGroup);
return true;
} | php | private function addUserGroup(UserInterface $user, $userGroupData)
{
$group = $this->groupRepository->findGroupById($userGroupData['group']['id']);
if (!$group) {
throw new EntityNotFoundException($this->groupRepository->getClassName(), $userGroupData['group']['id']);
}
$userGroup = new UserGroup();
$userGroup->setUser($user);
$userGroup->setGroup($group);
$userGroup->setLocale(json_encode($userGroupData['locales']));
$this->em->persist($userGroup);
$user->addUserGroup($userGroup);
return true;
} | [
"private",
"function",
"addUserGroup",
"(",
"UserInterface",
"$",
"user",
",",
"$",
"userGroupData",
")",
"{",
"$",
"group",
"=",
"$",
"this",
"->",
"groupRepository",
"->",
"findGroupById",
"(",
"$",
"userGroupData",
"[",
"'group'",
"]",
"[",
"'id'",
"]",
")",
";",
"if",
"(",
"!",
"$",
"group",
")",
"{",
"throw",
"new",
"EntityNotFoundException",
"(",
"$",
"this",
"->",
"groupRepository",
"->",
"getClassName",
"(",
")",
",",
"$",
"userGroupData",
"[",
"'group'",
"]",
"[",
"'id'",
"]",
")",
";",
"}",
"$",
"userGroup",
"=",
"new",
"UserGroup",
"(",
")",
";",
"$",
"userGroup",
"->",
"setUser",
"(",
"$",
"user",
")",
";",
"$",
"userGroup",
"->",
"setGroup",
"(",
"$",
"group",
")",
";",
"$",
"userGroup",
"->",
"setLocale",
"(",
"json_encode",
"(",
"$",
"userGroupData",
"[",
"'locales'",
"]",
")",
")",
";",
"$",
"this",
"->",
"em",
"->",
"persist",
"(",
"$",
"userGroup",
")",
";",
"$",
"user",
"->",
"addUserGroup",
"(",
"$",
"userGroup",
")",
";",
"return",
"true",
";",
"}"
] | Adds a new UserGroup to the given user.
@param UserInterface $user
@param $userGroupData
@throws \Sulu\Component\Rest\Exception\EntityNotFoundException
@return bool | [
"Adds",
"a",
"new",
"UserGroup",
"to",
"the",
"given",
"user",
"."
] | 6766a36cc2f0c807c59202bf7540a08c4ef31192 | https://github.com/sulu/sulu/blob/6766a36cc2f0c807c59202bf7540a08c4ef31192/src/Sulu/Bundle/SecurityBundle/UserManager/UserManager.php#L510-L527 | train |
sulu/sulu | src/Sulu/Bundle/SecurityBundle/UserManager/UserManager.php | UserManager.updateUserGroup | private function updateUserGroup(UserGroup $userGroup, $userGroupData)
{
$group = $this->groupRepository->findGroupById($userGroupData['group']['id']);
if (!$group) {
throw new EntityNotFoundException($this->groupRepository->getClassName(), $userGroup['group']['id']);
}
$userGroup->setGroup($group);
if (array_key_exists('locales', $userGroupData)) {
$userGroup->setLocale(json_encode($userGroupData['locales']));
} else {
$userGroup->setLocale($userGroupData['locale']);
}
return true;
} | php | private function updateUserGroup(UserGroup $userGroup, $userGroupData)
{
$group = $this->groupRepository->findGroupById($userGroupData['group']['id']);
if (!$group) {
throw new EntityNotFoundException($this->groupRepository->getClassName(), $userGroup['group']['id']);
}
$userGroup->setGroup($group);
if (array_key_exists('locales', $userGroupData)) {
$userGroup->setLocale(json_encode($userGroupData['locales']));
} else {
$userGroup->setLocale($userGroupData['locale']);
}
return true;
} | [
"private",
"function",
"updateUserGroup",
"(",
"UserGroup",
"$",
"userGroup",
",",
"$",
"userGroupData",
")",
"{",
"$",
"group",
"=",
"$",
"this",
"->",
"groupRepository",
"->",
"findGroupById",
"(",
"$",
"userGroupData",
"[",
"'group'",
"]",
"[",
"'id'",
"]",
")",
";",
"if",
"(",
"!",
"$",
"group",
")",
"{",
"throw",
"new",
"EntityNotFoundException",
"(",
"$",
"this",
"->",
"groupRepository",
"->",
"getClassName",
"(",
")",
",",
"$",
"userGroup",
"[",
"'group'",
"]",
"[",
"'id'",
"]",
")",
";",
"}",
"$",
"userGroup",
"->",
"setGroup",
"(",
"$",
"group",
")",
";",
"if",
"(",
"array_key_exists",
"(",
"'locales'",
",",
"$",
"userGroupData",
")",
")",
"{",
"$",
"userGroup",
"->",
"setLocale",
"(",
"json_encode",
"(",
"$",
"userGroupData",
"[",
"'locales'",
"]",
")",
")",
";",
"}",
"else",
"{",
"$",
"userGroup",
"->",
"setLocale",
"(",
"$",
"userGroupData",
"[",
"'locale'",
"]",
")",
";",
"}",
"return",
"true",
";",
"}"
] | Updates an existing UserGroup with the given data.
@param \Sulu\Bundle\SecurityBundle\Entity\UserGroup $userGroup
@param $userGroupData
@throws \Sulu\Component\Rest\Exception\EntityNotFoundException
@return bool | [
"Updates",
"an",
"existing",
"UserGroup",
"with",
"the",
"given",
"data",
"."
] | 6766a36cc2f0c807c59202bf7540a08c4ef31192 | https://github.com/sulu/sulu/blob/6766a36cc2f0c807c59202bf7540a08c4ef31192/src/Sulu/Bundle/SecurityBundle/UserManager/UserManager.php#L539-L555 | train |
sulu/sulu | src/Sulu/Bundle/SecurityBundle/UserManager/UserManager.php | UserManager.getContact | private function getContact($id)
{
$contact = $this->contactManager->findById($id);
if (!$contact) {
throw new EntityNotFoundException($this->contactManager->getContactEntityName(), $id);
}
return $contact;
} | php | private function getContact($id)
{
$contact = $this->contactManager->findById($id);
if (!$contact) {
throw new EntityNotFoundException($this->contactManager->getContactEntityName(), $id);
}
return $contact;
} | [
"private",
"function",
"getContact",
"(",
"$",
"id",
")",
"{",
"$",
"contact",
"=",
"$",
"this",
"->",
"contactManager",
"->",
"findById",
"(",
"$",
"id",
")",
";",
"if",
"(",
"!",
"$",
"contact",
")",
"{",
"throw",
"new",
"EntityNotFoundException",
"(",
"$",
"this",
"->",
"contactManager",
"->",
"getContactEntityName",
"(",
")",
",",
"$",
"id",
")",
";",
"}",
"return",
"$",
"contact",
";",
"}"
] | Returns the contact with the given id.
@param int $id
@throws \Sulu\Component\Rest\Exception\EntityNotFoundException
@return Contact | [
"Returns",
"the",
"contact",
"with",
"the",
"given",
"id",
"."
] | 6766a36cc2f0c807c59202bf7540a08c4ef31192 | https://github.com/sulu/sulu/blob/6766a36cc2f0c807c59202bf7540a08c4ef31192/src/Sulu/Bundle/SecurityBundle/UserManager/UserManager.php#L566-L575 | train |
sulu/sulu | src/Sulu/Bundle/SecurityBundle/UserManager/UserManager.php | UserManager.processEmail | private function processEmail(UserInterface $user, $email, $contact = null)
{
if ($contact) {
// if no email passed try to use the contact's first email
if (null === $email &&
array_key_exists('emails', $contact) && count($contact['emails']) > 0 &&
$this->isEmailUnique($contact['emails'][0]['email'])
) {
$email = $contact['emails'][0]['email'];
}
if (null !== $email) {
if (!$this->isEmailUnique($email)) {
throw new EmailNotUniqueException($email);
}
$user->setEmail($email);
}
} else {
if (null !== $email) {
if ($email !== $user->getEmail() &&
!$this->isEmailUnique($email)
) {
throw new EmailNotUniqueException($email);
}
$user->setEmail($email);
} else {
$user->setEmail(null);
}
}
} | php | private function processEmail(UserInterface $user, $email, $contact = null)
{
if ($contact) {
// if no email passed try to use the contact's first email
if (null === $email &&
array_key_exists('emails', $contact) && count($contact['emails']) > 0 &&
$this->isEmailUnique($contact['emails'][0]['email'])
) {
$email = $contact['emails'][0]['email'];
}
if (null !== $email) {
if (!$this->isEmailUnique($email)) {
throw new EmailNotUniqueException($email);
}
$user->setEmail($email);
}
} else {
if (null !== $email) {
if ($email !== $user->getEmail() &&
!$this->isEmailUnique($email)
) {
throw new EmailNotUniqueException($email);
}
$user->setEmail($email);
} else {
$user->setEmail(null);
}
}
} | [
"private",
"function",
"processEmail",
"(",
"UserInterface",
"$",
"user",
",",
"$",
"email",
",",
"$",
"contact",
"=",
"null",
")",
"{",
"if",
"(",
"$",
"contact",
")",
"{",
"// if no email passed try to use the contact's first email",
"if",
"(",
"null",
"===",
"$",
"email",
"&&",
"array_key_exists",
"(",
"'emails'",
",",
"$",
"contact",
")",
"&&",
"count",
"(",
"$",
"contact",
"[",
"'emails'",
"]",
")",
">",
"0",
"&&",
"$",
"this",
"->",
"isEmailUnique",
"(",
"$",
"contact",
"[",
"'emails'",
"]",
"[",
"0",
"]",
"[",
"'email'",
"]",
")",
")",
"{",
"$",
"email",
"=",
"$",
"contact",
"[",
"'emails'",
"]",
"[",
"0",
"]",
"[",
"'email'",
"]",
";",
"}",
"if",
"(",
"null",
"!==",
"$",
"email",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"isEmailUnique",
"(",
"$",
"email",
")",
")",
"{",
"throw",
"new",
"EmailNotUniqueException",
"(",
"$",
"email",
")",
";",
"}",
"$",
"user",
"->",
"setEmail",
"(",
"$",
"email",
")",
";",
"}",
"}",
"else",
"{",
"if",
"(",
"null",
"!==",
"$",
"email",
")",
"{",
"if",
"(",
"$",
"email",
"!==",
"$",
"user",
"->",
"getEmail",
"(",
")",
"&&",
"!",
"$",
"this",
"->",
"isEmailUnique",
"(",
"$",
"email",
")",
")",
"{",
"throw",
"new",
"EmailNotUniqueException",
"(",
"$",
"email",
")",
";",
"}",
"$",
"user",
"->",
"setEmail",
"(",
"$",
"email",
")",
";",
"}",
"else",
"{",
"$",
"user",
"->",
"setEmail",
"(",
"null",
")",
";",
"}",
"}",
"}"
] | Processes the email and adds it to the user.
@param UserInterface $user
@param string $email
@param null|array $contact
@throws EmailNotUniqueException | [
"Processes",
"the",
"email",
"and",
"adds",
"it",
"to",
"the",
"user",
"."
] | 6766a36cc2f0c807c59202bf7540a08c4ef31192 | https://github.com/sulu/sulu/blob/6766a36cc2f0c807c59202bf7540a08c4ef31192/src/Sulu/Bundle/SecurityBundle/UserManager/UserManager.php#L636-L664 | train |
sulu/sulu | src/Sulu/Bundle/SecurityBundle/EventListener/UserLocaleListener.php | UserLocaleListener.copyUserLocaleToRequest | public function copyUserLocaleToRequest(GetResponseEvent $event)
{
$token = $this->tokenStorage->getToken();
if (!$token) {
return;
}
$user = $token->getUser();
if (!$user instanceof UserInterface) {
return;
}
$locale = $user->getLocale();
$event->getRequest()->setLocale($locale);
$this->translator->setLocale($locale);
} | php | public function copyUserLocaleToRequest(GetResponseEvent $event)
{
$token = $this->tokenStorage->getToken();
if (!$token) {
return;
}
$user = $token->getUser();
if (!$user instanceof UserInterface) {
return;
}
$locale = $user->getLocale();
$event->getRequest()->setLocale($locale);
$this->translator->setLocale($locale);
} | [
"public",
"function",
"copyUserLocaleToRequest",
"(",
"GetResponseEvent",
"$",
"event",
")",
"{",
"$",
"token",
"=",
"$",
"this",
"->",
"tokenStorage",
"->",
"getToken",
"(",
")",
";",
"if",
"(",
"!",
"$",
"token",
")",
"{",
"return",
";",
"}",
"$",
"user",
"=",
"$",
"token",
"->",
"getUser",
"(",
")",
";",
"if",
"(",
"!",
"$",
"user",
"instanceof",
"UserInterface",
")",
"{",
"return",
";",
"}",
"$",
"locale",
"=",
"$",
"user",
"->",
"getLocale",
"(",
")",
";",
"$",
"event",
"->",
"getRequest",
"(",
")",
"->",
"setLocale",
"(",
"$",
"locale",
")",
";",
"$",
"this",
"->",
"translator",
"->",
"setLocale",
"(",
"$",
"locale",
")",
";",
"}"
] | Sets the locale of the current User to the request, if a User is logged in.
@param GetResponseEvent $event | [
"Sets",
"the",
"locale",
"of",
"the",
"current",
"User",
"to",
"the",
"request",
"if",
"a",
"User",
"is",
"logged",
"in",
"."
] | 6766a36cc2f0c807c59202bf7540a08c4ef31192 | https://github.com/sulu/sulu/blob/6766a36cc2f0c807c59202bf7540a08c4ef31192/src/Sulu/Bundle/SecurityBundle/EventListener/UserLocaleListener.php#L45-L60 | train |
sulu/sulu | src/Sulu/Component/Content/Compat/Structure.php | Structure.addChild | protected function addChild(PropertyInterface $property)
{
if ($property instanceof SectionPropertyInterface) {
foreach ($property->getChildProperties() as $childProperty) {
$this->addPropertyTags($childProperty);
}
} else {
$this->addPropertyTags($property);
}
$this->properties[$property->getName()] = $property;
} | php | protected function addChild(PropertyInterface $property)
{
if ($property instanceof SectionPropertyInterface) {
foreach ($property->getChildProperties() as $childProperty) {
$this->addPropertyTags($childProperty);
}
} else {
$this->addPropertyTags($property);
}
$this->properties[$property->getName()] = $property;
} | [
"protected",
"function",
"addChild",
"(",
"PropertyInterface",
"$",
"property",
")",
"{",
"if",
"(",
"$",
"property",
"instanceof",
"SectionPropertyInterface",
")",
"{",
"foreach",
"(",
"$",
"property",
"->",
"getChildProperties",
"(",
")",
"as",
"$",
"childProperty",
")",
"{",
"$",
"this",
"->",
"addPropertyTags",
"(",
"$",
"childProperty",
")",
";",
"}",
"}",
"else",
"{",
"$",
"this",
"->",
"addPropertyTags",
"(",
"$",
"property",
")",
";",
"}",
"$",
"this",
"->",
"properties",
"[",
"$",
"property",
"->",
"getName",
"(",
")",
"]",
"=",
"$",
"property",
";",
"}"
] | adds a property to structure.
@param PropertyInterface $property | [
"adds",
"a",
"property",
"to",
"structure",
"."
] | 6766a36cc2f0c807c59202bf7540a08c4ef31192 | https://github.com/sulu/sulu/blob/6766a36cc2f0c807c59202bf7540a08c4ef31192/src/Sulu/Component/Content/Compat/Structure.php#L255-L266 | train |
sulu/sulu | src/Sulu/Component/Content/Compat/Structure.php | Structure.addPropertyTags | protected function addPropertyTags(PropertyInterface $property)
{
foreach ($property->getTags() as $tag) {
if (!array_key_exists($tag->getName(), $this->tags)) {
$this->tags[$tag->getName()] = [
'tag' => $tag,
'properties' => [$tag->getPriority() => $property],
'highest' => $property,
'lowest' => $property,
];
} else {
$this->tags[$tag->getName()]['properties'][$tag->getPriority()] = $property;
// replace highest priority property
$highestProperty = $this->tags[$tag->getName()]['highest'];
if ($highestProperty->getTag($tag->getName())->getPriority() < $tag->getPriority()) {
$this->tags[$tag->getName()]['highest'] = $property;
}
// replace lowest priority property
$lowestProperty = $this->tags[$tag->getName()]['lowest'];
if ($lowestProperty->getTag($tag->getName())->getPriority() > $tag->getPriority()) {
$this->tags[$tag->getName()]['lowest'] = $property;
}
}
}
} | php | protected function addPropertyTags(PropertyInterface $property)
{
foreach ($property->getTags() as $tag) {
if (!array_key_exists($tag->getName(), $this->tags)) {
$this->tags[$tag->getName()] = [
'tag' => $tag,
'properties' => [$tag->getPriority() => $property],
'highest' => $property,
'lowest' => $property,
];
} else {
$this->tags[$tag->getName()]['properties'][$tag->getPriority()] = $property;
// replace highest priority property
$highestProperty = $this->tags[$tag->getName()]['highest'];
if ($highestProperty->getTag($tag->getName())->getPriority() < $tag->getPriority()) {
$this->tags[$tag->getName()]['highest'] = $property;
}
// replace lowest priority property
$lowestProperty = $this->tags[$tag->getName()]['lowest'];
if ($lowestProperty->getTag($tag->getName())->getPriority() > $tag->getPriority()) {
$this->tags[$tag->getName()]['lowest'] = $property;
}
}
}
} | [
"protected",
"function",
"addPropertyTags",
"(",
"PropertyInterface",
"$",
"property",
")",
"{",
"foreach",
"(",
"$",
"property",
"->",
"getTags",
"(",
")",
"as",
"$",
"tag",
")",
"{",
"if",
"(",
"!",
"array_key_exists",
"(",
"$",
"tag",
"->",
"getName",
"(",
")",
",",
"$",
"this",
"->",
"tags",
")",
")",
"{",
"$",
"this",
"->",
"tags",
"[",
"$",
"tag",
"->",
"getName",
"(",
")",
"]",
"=",
"[",
"'tag'",
"=>",
"$",
"tag",
",",
"'properties'",
"=>",
"[",
"$",
"tag",
"->",
"getPriority",
"(",
")",
"=>",
"$",
"property",
"]",
",",
"'highest'",
"=>",
"$",
"property",
",",
"'lowest'",
"=>",
"$",
"property",
",",
"]",
";",
"}",
"else",
"{",
"$",
"this",
"->",
"tags",
"[",
"$",
"tag",
"->",
"getName",
"(",
")",
"]",
"[",
"'properties'",
"]",
"[",
"$",
"tag",
"->",
"getPriority",
"(",
")",
"]",
"=",
"$",
"property",
";",
"// replace highest priority property",
"$",
"highestProperty",
"=",
"$",
"this",
"->",
"tags",
"[",
"$",
"tag",
"->",
"getName",
"(",
")",
"]",
"[",
"'highest'",
"]",
";",
"if",
"(",
"$",
"highestProperty",
"->",
"getTag",
"(",
"$",
"tag",
"->",
"getName",
"(",
")",
")",
"->",
"getPriority",
"(",
")",
"<",
"$",
"tag",
"->",
"getPriority",
"(",
")",
")",
"{",
"$",
"this",
"->",
"tags",
"[",
"$",
"tag",
"->",
"getName",
"(",
")",
"]",
"[",
"'highest'",
"]",
"=",
"$",
"property",
";",
"}",
"// replace lowest priority property",
"$",
"lowestProperty",
"=",
"$",
"this",
"->",
"tags",
"[",
"$",
"tag",
"->",
"getName",
"(",
")",
"]",
"[",
"'lowest'",
"]",
";",
"if",
"(",
"$",
"lowestProperty",
"->",
"getTag",
"(",
"$",
"tag",
"->",
"getName",
"(",
")",
")",
"->",
"getPriority",
"(",
")",
">",
"$",
"tag",
"->",
"getPriority",
"(",
")",
")",
"{",
"$",
"this",
"->",
"tags",
"[",
"$",
"tag",
"->",
"getName",
"(",
")",
"]",
"[",
"'lowest'",
"]",
"=",
"$",
"property",
";",
"}",
"}",
"}",
"}"
] | add tags of properties. | [
"add",
"tags",
"of",
"properties",
"."
] | 6766a36cc2f0c807c59202bf7540a08c4ef31192 | https://github.com/sulu/sulu/blob/6766a36cc2f0c807c59202bf7540a08c4ef31192/src/Sulu/Component/Content/Compat/Structure.php#L271-L297 | train |
sulu/sulu | src/Sulu/Component/Content/Compat/Structure.php | Structure.getProperty | public function getProperty($name)
{
$result = $this->findProperty($name);
if (null !== $result) {
return $result;
} elseif (isset($this->properties[$name])) {
return $this->properties[$name];
} else {
throw new NoSuchPropertyException($name);
}
} | php | public function getProperty($name)
{
$result = $this->findProperty($name);
if (null !== $result) {
return $result;
} elseif (isset($this->properties[$name])) {
return $this->properties[$name];
} else {
throw new NoSuchPropertyException($name);
}
} | [
"public",
"function",
"getProperty",
"(",
"$",
"name",
")",
"{",
"$",
"result",
"=",
"$",
"this",
"->",
"findProperty",
"(",
"$",
"name",
")",
";",
"if",
"(",
"null",
"!==",
"$",
"result",
")",
"{",
"return",
"$",
"result",
";",
"}",
"elseif",
"(",
"isset",
"(",
"$",
"this",
"->",
"properties",
"[",
"$",
"name",
"]",
")",
")",
"{",
"return",
"$",
"this",
"->",
"properties",
"[",
"$",
"name",
"]",
";",
"}",
"else",
"{",
"throw",
"new",
"NoSuchPropertyException",
"(",
"$",
"name",
")",
";",
"}",
"}"
] | returns a property instance with given name.
@param $name string name of property
@return PropertyInterface
@throws NoSuchPropertyException | [
"returns",
"a",
"property",
"instance",
"with",
"given",
"name",
"."
] | 6766a36cc2f0c807c59202bf7540a08c4ef31192 | https://github.com/sulu/sulu/blob/6766a36cc2f0c807c59202bf7540a08c4ef31192/src/Sulu/Component/Content/Compat/Structure.php#L456-L467 | train |
sulu/sulu | src/Sulu/Component/Content/Compat/Structure.php | Structure.getPropertyByTagName | public function getPropertyByTagName($tagName, $highest = true)
{
if (array_key_exists($tagName, $this->tags)) {
return $this->tags[$tagName][true === $highest ? 'highest' : 'lowest'];
} else {
throw new NoSuchPropertyException($tagName);
}
} | php | public function getPropertyByTagName($tagName, $highest = true)
{
if (array_key_exists($tagName, $this->tags)) {
return $this->tags[$tagName][true === $highest ? 'highest' : 'lowest'];
} else {
throw new NoSuchPropertyException($tagName);
}
} | [
"public",
"function",
"getPropertyByTagName",
"(",
"$",
"tagName",
",",
"$",
"highest",
"=",
"true",
")",
"{",
"if",
"(",
"array_key_exists",
"(",
"$",
"tagName",
",",
"$",
"this",
"->",
"tags",
")",
")",
"{",
"return",
"$",
"this",
"->",
"tags",
"[",
"$",
"tagName",
"]",
"[",
"true",
"===",
"$",
"highest",
"?",
"'highest'",
":",
"'lowest'",
"]",
";",
"}",
"else",
"{",
"throw",
"new",
"NoSuchPropertyException",
"(",
"$",
"tagName",
")",
";",
"}",
"}"
] | returns a property instance with given tag name.
@param string $tagName
@param bool $highest
@return PropertyInterface
@throws NoSuchPropertyException | [
"returns",
"a",
"property",
"instance",
"with",
"given",
"tag",
"name",
"."
] | 6766a36cc2f0c807c59202bf7540a08c4ef31192 | https://github.com/sulu/sulu/blob/6766a36cc2f0c807c59202bf7540a08c4ef31192/src/Sulu/Component/Content/Compat/Structure.php#L479-L486 | train |
sulu/sulu | src/Sulu/Component/Content/Compat/Structure.php | Structure.getPropertiesByTagName | public function getPropertiesByTagName($tagName)
{
if (array_key_exists($tagName, $this->tags)) {
return $this->tags[$tagName]['properties'];
} else {
throw new NoSuchPropertyException($tagName);
}
} | php | public function getPropertiesByTagName($tagName)
{
if (array_key_exists($tagName, $this->tags)) {
return $this->tags[$tagName]['properties'];
} else {
throw new NoSuchPropertyException($tagName);
}
} | [
"public",
"function",
"getPropertiesByTagName",
"(",
"$",
"tagName",
")",
"{",
"if",
"(",
"array_key_exists",
"(",
"$",
"tagName",
",",
"$",
"this",
"->",
"tags",
")",
")",
"{",
"return",
"$",
"this",
"->",
"tags",
"[",
"$",
"tagName",
"]",
"[",
"'properties'",
"]",
";",
"}",
"else",
"{",
"throw",
"new",
"NoSuchPropertyException",
"(",
"$",
"tagName",
")",
";",
"}",
"}"
] | returns properties with given tag name sorted by priority.
@param string $tagName
@return PropertyInterface
@throws NoSuchPropertyException | [
"returns",
"properties",
"with",
"given",
"tag",
"name",
"sorted",
"by",
"priority",
"."
] | 6766a36cc2f0c807c59202bf7540a08c4ef31192 | https://github.com/sulu/sulu/blob/6766a36cc2f0c807c59202bf7540a08c4ef31192/src/Sulu/Component/Content/Compat/Structure.php#L497-L504 | train |
sulu/sulu | src/Sulu/Component/Content/Compat/Structure.php | Structure.findProperty | private function findProperty($name)
{
foreach ($this->getProperties(true) as $property) {
if ($property->getName() === $name) {
return $property;
}
}
return;
} | php | private function findProperty($name)
{
foreach ($this->getProperties(true) as $property) {
if ($property->getName() === $name) {
return $property;
}
}
return;
} | [
"private",
"function",
"findProperty",
"(",
"$",
"name",
")",
"{",
"foreach",
"(",
"$",
"this",
"->",
"getProperties",
"(",
"true",
")",
"as",
"$",
"property",
")",
"{",
"if",
"(",
"$",
"property",
"->",
"getName",
"(",
")",
"===",
"$",
"name",
")",
"{",
"return",
"$",
"property",
";",
"}",
"}",
"return",
";",
"}"
] | find property in flatten properties.
@param string $name
@return null|PropertyInterface | [
"find",
"property",
"in",
"flatten",
"properties",
"."
] | 6766a36cc2f0c807c59202bf7540a08c4ef31192 | https://github.com/sulu/sulu/blob/6766a36cc2f0c807c59202bf7540a08c4ef31192/src/Sulu/Component/Content/Compat/Structure.php#L549-L558 | train |
sulu/sulu | src/Sulu/Component/Content/Compat/Structure.php | Structure.getProperties | public function getProperties($flatten = false)
{
if (false === $flatten) {
return $this->properties;
} else {
$result = [];
foreach ($this->properties as $property) {
if ($property instanceof SectionPropertyInterface) {
$result = array_merge($result, $property->getChildProperties());
} else {
$result[] = $property;
}
}
return $result;
}
} | php | public function getProperties($flatten = false)
{
if (false === $flatten) {
return $this->properties;
} else {
$result = [];
foreach ($this->properties as $property) {
if ($property instanceof SectionPropertyInterface) {
$result = array_merge($result, $property->getChildProperties());
} else {
$result[] = $property;
}
}
return $result;
}
} | [
"public",
"function",
"getProperties",
"(",
"$",
"flatten",
"=",
"false",
")",
"{",
"if",
"(",
"false",
"===",
"$",
"flatten",
")",
"{",
"return",
"$",
"this",
"->",
"properties",
";",
"}",
"else",
"{",
"$",
"result",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"this",
"->",
"properties",
"as",
"$",
"property",
")",
"{",
"if",
"(",
"$",
"property",
"instanceof",
"SectionPropertyInterface",
")",
"{",
"$",
"result",
"=",
"array_merge",
"(",
"$",
"result",
",",
"$",
"property",
"->",
"getChildProperties",
"(",
")",
")",
";",
"}",
"else",
"{",
"$",
"result",
"[",
"]",
"=",
"$",
"property",
";",
"}",
"}",
"return",
"$",
"result",
";",
"}",
"}"
] | returns an array of properties.
@param bool $flatten
@return PropertyInterface[] | [
"returns",
"an",
"array",
"of",
"properties",
"."
] | 6766a36cc2f0c807c59202bf7540a08c4ef31192 | https://github.com/sulu/sulu/blob/6766a36cc2f0c807c59202bf7540a08c4ef31192/src/Sulu/Component/Content/Compat/Structure.php#L685-L701 | train |
sulu/sulu | src/Sulu/Component/Content/Compat/Structure.php | Structure.__isset | public function __isset($property)
{
if (null !== $this->findProperty($property)) {
return true;
} else {
return isset($this->$property);
}
} | php | public function __isset($property)
{
if (null !== $this->findProperty($property)) {
return true;
} else {
return isset($this->$property);
}
} | [
"public",
"function",
"__isset",
"(",
"$",
"property",
")",
"{",
"if",
"(",
"null",
"!==",
"$",
"this",
"->",
"findProperty",
"(",
"$",
"property",
")",
")",
"{",
"return",
"true",
";",
"}",
"else",
"{",
"return",
"isset",
"(",
"$",
"this",
"->",
"$",
"property",
")",
";",
"}",
"}"
] | magic isset.
@param $property
@return bool | [
"magic",
"isset",
"."
] | 6766a36cc2f0c807c59202bf7540a08c4ef31192 | https://github.com/sulu/sulu/blob/6766a36cc2f0c807c59202bf7540a08c4ef31192/src/Sulu/Component/Content/Compat/Structure.php#L838-L845 | train |
sulu/sulu | src/Sulu/Component/Content/Compat/Structure.php | Structure.toArray | public function toArray($complete = true)
{
if ($complete) {
$result = [
'id' => $this->uuid,
'nodeType' => $this->nodeType,
'internal' => $this->internal,
'shadowLocales' => $this->getShadowLocales(),
'contentLocales' => $this->getContentLocales(),
'shadowOn' => $this->getIsShadow(),
'shadowBaseLanguage' => $this->getShadowBaseLanguage() ?: false,
'template' => $this->getKey(),
'hasSub' => $this->hasChildren,
'creator' => $this->creator,
'changer' => $this->changer,
'created' => $this->created,
'changed' => $this->changed,
];
if (null !== $this->type) {
$result['type'] = $this->getType()->toArray();
}
if (self::NODE_TYPE_INTERNAL_LINK === $this->nodeType) {
$result['linked'] = 'internal';
} elseif (self::NODE_TYPE_EXTERNAL_LINK === $this->nodeType) {
$result['linked'] = 'external';
}
$this->appendProperties($this->getProperties(), $result);
return $result;
} else {
$result = [
'id' => $this->uuid,
'path' => $this->path,
'nodeType' => $this->nodeType,
'internal' => $this->internal,
'getContentLocales' => $this->getContentLocales(),
'hasSub' => $this->hasChildren,
'title' => $this->getProperty('title')->toArray(),
];
if (null !== $this->type) {
$result['type'] = $this->getType()->toArray();
}
if (self::NODE_TYPE_INTERNAL_LINK === $this->nodeType) {
$result['linked'] = 'internal';
} elseif (self::NODE_TYPE_EXTERNAL_LINK === $this->nodeType) {
$result['linked'] = 'external';
}
return $result;
}
} | php | public function toArray($complete = true)
{
if ($complete) {
$result = [
'id' => $this->uuid,
'nodeType' => $this->nodeType,
'internal' => $this->internal,
'shadowLocales' => $this->getShadowLocales(),
'contentLocales' => $this->getContentLocales(),
'shadowOn' => $this->getIsShadow(),
'shadowBaseLanguage' => $this->getShadowBaseLanguage() ?: false,
'template' => $this->getKey(),
'hasSub' => $this->hasChildren,
'creator' => $this->creator,
'changer' => $this->changer,
'created' => $this->created,
'changed' => $this->changed,
];
if (null !== $this->type) {
$result['type'] = $this->getType()->toArray();
}
if (self::NODE_TYPE_INTERNAL_LINK === $this->nodeType) {
$result['linked'] = 'internal';
} elseif (self::NODE_TYPE_EXTERNAL_LINK === $this->nodeType) {
$result['linked'] = 'external';
}
$this->appendProperties($this->getProperties(), $result);
return $result;
} else {
$result = [
'id' => $this->uuid,
'path' => $this->path,
'nodeType' => $this->nodeType,
'internal' => $this->internal,
'getContentLocales' => $this->getContentLocales(),
'hasSub' => $this->hasChildren,
'title' => $this->getProperty('title')->toArray(),
];
if (null !== $this->type) {
$result['type'] = $this->getType()->toArray();
}
if (self::NODE_TYPE_INTERNAL_LINK === $this->nodeType) {
$result['linked'] = 'internal';
} elseif (self::NODE_TYPE_EXTERNAL_LINK === $this->nodeType) {
$result['linked'] = 'external';
}
return $result;
}
} | [
"public",
"function",
"toArray",
"(",
"$",
"complete",
"=",
"true",
")",
"{",
"if",
"(",
"$",
"complete",
")",
"{",
"$",
"result",
"=",
"[",
"'id'",
"=>",
"$",
"this",
"->",
"uuid",
",",
"'nodeType'",
"=>",
"$",
"this",
"->",
"nodeType",
",",
"'internal'",
"=>",
"$",
"this",
"->",
"internal",
",",
"'shadowLocales'",
"=>",
"$",
"this",
"->",
"getShadowLocales",
"(",
")",
",",
"'contentLocales'",
"=>",
"$",
"this",
"->",
"getContentLocales",
"(",
")",
",",
"'shadowOn'",
"=>",
"$",
"this",
"->",
"getIsShadow",
"(",
")",
",",
"'shadowBaseLanguage'",
"=>",
"$",
"this",
"->",
"getShadowBaseLanguage",
"(",
")",
"?",
":",
"false",
",",
"'template'",
"=>",
"$",
"this",
"->",
"getKey",
"(",
")",
",",
"'hasSub'",
"=>",
"$",
"this",
"->",
"hasChildren",
",",
"'creator'",
"=>",
"$",
"this",
"->",
"creator",
",",
"'changer'",
"=>",
"$",
"this",
"->",
"changer",
",",
"'created'",
"=>",
"$",
"this",
"->",
"created",
",",
"'changed'",
"=>",
"$",
"this",
"->",
"changed",
",",
"]",
";",
"if",
"(",
"null",
"!==",
"$",
"this",
"->",
"type",
")",
"{",
"$",
"result",
"[",
"'type'",
"]",
"=",
"$",
"this",
"->",
"getType",
"(",
")",
"->",
"toArray",
"(",
")",
";",
"}",
"if",
"(",
"self",
"::",
"NODE_TYPE_INTERNAL_LINK",
"===",
"$",
"this",
"->",
"nodeType",
")",
"{",
"$",
"result",
"[",
"'linked'",
"]",
"=",
"'internal'",
";",
"}",
"elseif",
"(",
"self",
"::",
"NODE_TYPE_EXTERNAL_LINK",
"===",
"$",
"this",
"->",
"nodeType",
")",
"{",
"$",
"result",
"[",
"'linked'",
"]",
"=",
"'external'",
";",
"}",
"$",
"this",
"->",
"appendProperties",
"(",
"$",
"this",
"->",
"getProperties",
"(",
")",
",",
"$",
"result",
")",
";",
"return",
"$",
"result",
";",
"}",
"else",
"{",
"$",
"result",
"=",
"[",
"'id'",
"=>",
"$",
"this",
"->",
"uuid",
",",
"'path'",
"=>",
"$",
"this",
"->",
"path",
",",
"'nodeType'",
"=>",
"$",
"this",
"->",
"nodeType",
",",
"'internal'",
"=>",
"$",
"this",
"->",
"internal",
",",
"'getContentLocales'",
"=>",
"$",
"this",
"->",
"getContentLocales",
"(",
")",
",",
"'hasSub'",
"=>",
"$",
"this",
"->",
"hasChildren",
",",
"'title'",
"=>",
"$",
"this",
"->",
"getProperty",
"(",
"'title'",
")",
"->",
"toArray",
"(",
")",
",",
"]",
";",
"if",
"(",
"null",
"!==",
"$",
"this",
"->",
"type",
")",
"{",
"$",
"result",
"[",
"'type'",
"]",
"=",
"$",
"this",
"->",
"getType",
"(",
")",
"->",
"toArray",
"(",
")",
";",
"}",
"if",
"(",
"self",
"::",
"NODE_TYPE_INTERNAL_LINK",
"===",
"$",
"this",
"->",
"nodeType",
")",
"{",
"$",
"result",
"[",
"'linked'",
"]",
"=",
"'internal'",
";",
"}",
"elseif",
"(",
"self",
"::",
"NODE_TYPE_EXTERNAL_LINK",
"===",
"$",
"this",
"->",
"nodeType",
")",
"{",
"$",
"result",
"[",
"'linked'",
"]",
"=",
"'external'",
";",
"}",
"return",
"$",
"result",
";",
"}",
"}"
] | returns an array of property value pairs.
@param bool $complete True if result should be representation of full node
@return array | [
"returns",
"an",
"array",
"of",
"property",
"value",
"pairs",
"."
] | 6766a36cc2f0c807c59202bf7540a08c4ef31192 | https://github.com/sulu/sulu/blob/6766a36cc2f0c807c59202bf7540a08c4ef31192/src/Sulu/Component/Content/Compat/Structure.php#L854-L909 | train |
sulu/sulu | src/Sulu/Component/Content/Compat/Structure.php | Structure.getStructureTag | public function getStructureTag($name)
{
if (!isset($this->structureTags[$name])) {
throw new \InvalidArgumentException(sprintf('Trying to get undefined structure StructureTag "%s"', $name));
}
return $this->structureTags[$name];
} | php | public function getStructureTag($name)
{
if (!isset($this->structureTags[$name])) {
throw new \InvalidArgumentException(sprintf('Trying to get undefined structure StructureTag "%s"', $name));
}
return $this->structureTags[$name];
} | [
"public",
"function",
"getStructureTag",
"(",
"$",
"name",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"this",
"->",
"structureTags",
"[",
"$",
"name",
"]",
")",
")",
"{",
"throw",
"new",
"\\",
"InvalidArgumentException",
"(",
"sprintf",
"(",
"'Trying to get undefined structure StructureTag \"%s\"'",
",",
"$",
"name",
")",
")",
";",
"}",
"return",
"$",
"this",
"->",
"structureTags",
"[",
"$",
"name",
"]",
";",
"}"
] | Return the tag with the given name.
@param string $name
@return StructureTag
@throws \InvalidArgumentException | [
"Return",
"the",
"tag",
"with",
"the",
"given",
"name",
"."
] | 6766a36cc2f0c807c59202bf7540a08c4ef31192 | https://github.com/sulu/sulu/blob/6766a36cc2f0c807c59202bf7540a08c4ef31192/src/Sulu/Component/Content/Compat/Structure.php#L1006-L1013 | train |
sulu/sulu | src/Sulu/Component/Webspace/Loader/XmlFileLoader11.php | XmlFileLoader11.generateTemplates | protected function generateTemplates(Webspace $webspace)
{
foreach ($this->xpath->query('/x:webspace/x:templates/x:template') as $templateNode) {
/* @var \DOMNode $templateNode */
$template = $templateNode->nodeValue;
$type = $templateNode->attributes->getNamedItem('type')->nodeValue;
$webspace->addTemplate($type, $template);
}
return $webspace;
} | php | protected function generateTemplates(Webspace $webspace)
{
foreach ($this->xpath->query('/x:webspace/x:templates/x:template') as $templateNode) {
/* @var \DOMNode $templateNode */
$template = $templateNode->nodeValue;
$type = $templateNode->attributes->getNamedItem('type')->nodeValue;
$webspace->addTemplate($type, $template);
}
return $webspace;
} | [
"protected",
"function",
"generateTemplates",
"(",
"Webspace",
"$",
"webspace",
")",
"{",
"foreach",
"(",
"$",
"this",
"->",
"xpath",
"->",
"query",
"(",
"'/x:webspace/x:templates/x:template'",
")",
"as",
"$",
"templateNode",
")",
"{",
"/* @var \\DOMNode $templateNode */",
"$",
"template",
"=",
"$",
"templateNode",
"->",
"nodeValue",
";",
"$",
"type",
"=",
"$",
"templateNode",
"->",
"attributes",
"->",
"getNamedItem",
"(",
"'type'",
")",
"->",
"nodeValue",
";",
"$",
"webspace",
"->",
"addTemplate",
"(",
"$",
"type",
",",
"$",
"template",
")",
";",
"}",
"return",
"$",
"webspace",
";",
"}"
] | Adds the template for the given types as described in the XML document.
The types can be arbitrary, so that another bundle can easily add a new type and use the information from the
webspace.
@param Webspace $webspace
@return Webspace | [
"Adds",
"the",
"template",
"for",
"the",
"given",
"types",
"as",
"described",
"in",
"the",
"XML",
"document",
"."
] | 6766a36cc2f0c807c59202bf7540a08c4ef31192 | https://github.com/sulu/sulu/blob/6766a36cc2f0c807c59202bf7540a08c4ef31192/src/Sulu/Component/Webspace/Loader/XmlFileLoader11.php#L82-L92 | train |
sulu/sulu | src/Sulu/Bundle/SecurityBundle/Controller/ResettingController.php | ResettingController.sendEmailAction | public function sendEmailAction(Request $request, $generateNewKey = true)
{
try {
/** @var UserInterface $user */
$user = $this->findUser($request->get('user'));
if (true === $generateNewKey) {
$this->generateTokenForUser($user);
}
$email = $this->getEmail($user);
$this->sendTokenEmail($user, $this->getSenderAddress($request), $email);
$response = new JsonResponse(['email' => $email]);
} catch (EntityNotFoundException $ex) {
$response = new JsonResponse($ex->toArray(), 400);
} catch (TokenAlreadyRequestedException $ex) {
$response = new JsonResponse($ex->toArray(), 400);
} catch (NoTokenFoundException $ex) {
$response = new JsonResponse($ex->toArray(), 400);
} catch (TokenEmailsLimitReachedException $ex) {
$response = new JsonResponse($ex->toArray(), 400);
} catch (EmailTemplateException $ex) {
$response = new JsonResponse($ex->toArray(), 400);
} catch (UserNotInSystemException $ex) {
$response = new JsonResponse($ex->toArray(), 400);
}
return $response;
} | php | public function sendEmailAction(Request $request, $generateNewKey = true)
{
try {
/** @var UserInterface $user */
$user = $this->findUser($request->get('user'));
if (true === $generateNewKey) {
$this->generateTokenForUser($user);
}
$email = $this->getEmail($user);
$this->sendTokenEmail($user, $this->getSenderAddress($request), $email);
$response = new JsonResponse(['email' => $email]);
} catch (EntityNotFoundException $ex) {
$response = new JsonResponse($ex->toArray(), 400);
} catch (TokenAlreadyRequestedException $ex) {
$response = new JsonResponse($ex->toArray(), 400);
} catch (NoTokenFoundException $ex) {
$response = new JsonResponse($ex->toArray(), 400);
} catch (TokenEmailsLimitReachedException $ex) {
$response = new JsonResponse($ex->toArray(), 400);
} catch (EmailTemplateException $ex) {
$response = new JsonResponse($ex->toArray(), 400);
} catch (UserNotInSystemException $ex) {
$response = new JsonResponse($ex->toArray(), 400);
}
return $response;
} | [
"public",
"function",
"sendEmailAction",
"(",
"Request",
"$",
"request",
",",
"$",
"generateNewKey",
"=",
"true",
")",
"{",
"try",
"{",
"/** @var UserInterface $user */",
"$",
"user",
"=",
"$",
"this",
"->",
"findUser",
"(",
"$",
"request",
"->",
"get",
"(",
"'user'",
")",
")",
";",
"if",
"(",
"true",
"===",
"$",
"generateNewKey",
")",
"{",
"$",
"this",
"->",
"generateTokenForUser",
"(",
"$",
"user",
")",
";",
"}",
"$",
"email",
"=",
"$",
"this",
"->",
"getEmail",
"(",
"$",
"user",
")",
";",
"$",
"this",
"->",
"sendTokenEmail",
"(",
"$",
"user",
",",
"$",
"this",
"->",
"getSenderAddress",
"(",
"$",
"request",
")",
",",
"$",
"email",
")",
";",
"$",
"response",
"=",
"new",
"JsonResponse",
"(",
"[",
"'email'",
"=>",
"$",
"email",
"]",
")",
";",
"}",
"catch",
"(",
"EntityNotFoundException",
"$",
"ex",
")",
"{",
"$",
"response",
"=",
"new",
"JsonResponse",
"(",
"$",
"ex",
"->",
"toArray",
"(",
")",
",",
"400",
")",
";",
"}",
"catch",
"(",
"TokenAlreadyRequestedException",
"$",
"ex",
")",
"{",
"$",
"response",
"=",
"new",
"JsonResponse",
"(",
"$",
"ex",
"->",
"toArray",
"(",
")",
",",
"400",
")",
";",
"}",
"catch",
"(",
"NoTokenFoundException",
"$",
"ex",
")",
"{",
"$",
"response",
"=",
"new",
"JsonResponse",
"(",
"$",
"ex",
"->",
"toArray",
"(",
")",
",",
"400",
")",
";",
"}",
"catch",
"(",
"TokenEmailsLimitReachedException",
"$",
"ex",
")",
"{",
"$",
"response",
"=",
"new",
"JsonResponse",
"(",
"$",
"ex",
"->",
"toArray",
"(",
")",
",",
"400",
")",
";",
"}",
"catch",
"(",
"EmailTemplateException",
"$",
"ex",
")",
"{",
"$",
"response",
"=",
"new",
"JsonResponse",
"(",
"$",
"ex",
"->",
"toArray",
"(",
")",
",",
"400",
")",
";",
"}",
"catch",
"(",
"UserNotInSystemException",
"$",
"ex",
")",
"{",
"$",
"response",
"=",
"new",
"JsonResponse",
"(",
"$",
"ex",
"->",
"toArray",
"(",
")",
",",
"400",
")",
";",
"}",
"return",
"$",
"response",
";",
"}"
] | Generates a token for a user and sends an email with
a link to the resetting route.
@param Request $request
@param bool $generateNewKey If true a new token will be generated before sending the mail
@return JsonResponse | [
"Generates",
"a",
"token",
"for",
"a",
"user",
"and",
"sends",
"an",
"email",
"with",
"a",
"link",
"to",
"the",
"resetting",
"route",
"."
] | 6766a36cc2f0c807c59202bf7540a08c4ef31192 | https://github.com/sulu/sulu/blob/6766a36cc2f0c807c59202bf7540a08c4ef31192/src/Sulu/Bundle/SecurityBundle/Controller/ResettingController.php#L71-L97 | train |
sulu/sulu | src/Sulu/Bundle/SecurityBundle/Controller/ResettingController.php | ResettingController.resetAction | public function resetAction(Request $request)
{
try {
$token = $request->get('token');
/** @var UserInterface $user */
$user = $this->findUserByValidToken($token);
$this->changePassword($user, $request->get('password', ''));
$this->deleteToken($user);
$this->loginUser($user, $request);
$response = new JsonResponse(['url' => $this->get('router')->generate('sulu_admin')]);
} catch (InvalidTokenException $ex) {
$response = new JsonResponse($ex->toArray(), 400);
} catch (MissingPasswordException $ex) {
$response = new JsonResponse($ex->toArray(), 400);
}
return $response;
} | php | public function resetAction(Request $request)
{
try {
$token = $request->get('token');
/** @var UserInterface $user */
$user = $this->findUserByValidToken($token);
$this->changePassword($user, $request->get('password', ''));
$this->deleteToken($user);
$this->loginUser($user, $request);
$response = new JsonResponse(['url' => $this->get('router')->generate('sulu_admin')]);
} catch (InvalidTokenException $ex) {
$response = new JsonResponse($ex->toArray(), 400);
} catch (MissingPasswordException $ex) {
$response = new JsonResponse($ex->toArray(), 400);
}
return $response;
} | [
"public",
"function",
"resetAction",
"(",
"Request",
"$",
"request",
")",
"{",
"try",
"{",
"$",
"token",
"=",
"$",
"request",
"->",
"get",
"(",
"'token'",
")",
";",
"/** @var UserInterface $user */",
"$",
"user",
"=",
"$",
"this",
"->",
"findUserByValidToken",
"(",
"$",
"token",
")",
";",
"$",
"this",
"->",
"changePassword",
"(",
"$",
"user",
",",
"$",
"request",
"->",
"get",
"(",
"'password'",
",",
"''",
")",
")",
";",
"$",
"this",
"->",
"deleteToken",
"(",
"$",
"user",
")",
";",
"$",
"this",
"->",
"loginUser",
"(",
"$",
"user",
",",
"$",
"request",
")",
";",
"$",
"response",
"=",
"new",
"JsonResponse",
"(",
"[",
"'url'",
"=>",
"$",
"this",
"->",
"get",
"(",
"'router'",
")",
"->",
"generate",
"(",
"'sulu_admin'",
")",
"]",
")",
";",
"}",
"catch",
"(",
"InvalidTokenException",
"$",
"ex",
")",
"{",
"$",
"response",
"=",
"new",
"JsonResponse",
"(",
"$",
"ex",
"->",
"toArray",
"(",
")",
",",
"400",
")",
";",
"}",
"catch",
"(",
"MissingPasswordException",
"$",
"ex",
")",
"{",
"$",
"response",
"=",
"new",
"JsonResponse",
"(",
"$",
"ex",
"->",
"toArray",
"(",
")",
",",
"400",
")",
";",
"}",
"return",
"$",
"response",
";",
"}"
] | Resets a users password.
@param Request $request
@return JsonResponse | [
"Resets",
"a",
"users",
"password",
"."
] | 6766a36cc2f0c807c59202bf7540a08c4ef31192 | https://github.com/sulu/sulu/blob/6766a36cc2f0c807c59202bf7540a08c4ef31192/src/Sulu/Bundle/SecurityBundle/Controller/ResettingController.php#L106-L123 | train |
sulu/sulu | src/Sulu/Bundle/SecurityBundle/Controller/ResettingController.php | ResettingController.getSenderAddress | protected function getSenderAddress(Request $request)
{
$sender = $this->getParameter('sulu_security.reset_password.mail.sender');
if (!$sender || !$this->isEmailValid($sender)) {
$sender = 'no-reply@' . $request->getHost();
}
return $sender;
} | php | protected function getSenderAddress(Request $request)
{
$sender = $this->getParameter('sulu_security.reset_password.mail.sender');
if (!$sender || !$this->isEmailValid($sender)) {
$sender = 'no-reply@' . $request->getHost();
}
return $sender;
} | [
"protected",
"function",
"getSenderAddress",
"(",
"Request",
"$",
"request",
")",
"{",
"$",
"sender",
"=",
"$",
"this",
"->",
"getParameter",
"(",
"'sulu_security.reset_password.mail.sender'",
")",
";",
"if",
"(",
"!",
"$",
"sender",
"||",
"!",
"$",
"this",
"->",
"isEmailValid",
"(",
"$",
"sender",
")",
")",
"{",
"$",
"sender",
"=",
"'no-reply@'",
".",
"$",
"request",
"->",
"getHost",
"(",
")",
";",
"}",
"return",
"$",
"sender",
";",
"}"
] | Returns the sender's email address.
@param Request $request
@return string | [
"Returns",
"the",
"sender",
"s",
"email",
"address",
"."
] | 6766a36cc2f0c807c59202bf7540a08c4ef31192 | https://github.com/sulu/sulu/blob/6766a36cc2f0c807c59202bf7540a08c4ef31192/src/Sulu/Bundle/SecurityBundle/Controller/ResettingController.php#L132-L141 | train |
sulu/sulu | src/Sulu/Bundle/SecurityBundle/Controller/ResettingController.php | ResettingController.getEmail | private function getEmail(UserInterface $user)
{
if (null !== $user->getEmail()) {
return $user->getEmail();
}
return $this->container->getParameter('sulu_admin.email');
} | php | private function getEmail(UserInterface $user)
{
if (null !== $user->getEmail()) {
return $user->getEmail();
}
return $this->container->getParameter('sulu_admin.email');
} | [
"private",
"function",
"getEmail",
"(",
"UserInterface",
"$",
"user",
")",
"{",
"if",
"(",
"null",
"!==",
"$",
"user",
"->",
"getEmail",
"(",
")",
")",
"{",
"return",
"$",
"user",
"->",
"getEmail",
"(",
")",
";",
"}",
"return",
"$",
"this",
"->",
"container",
"->",
"getParameter",
"(",
"'sulu_admin.email'",
")",
";",
"}"
] | Returns the users email or as a fallback the installation-email-adress.
@param UserInterface $user
@return string | [
"Returns",
"the",
"users",
"email",
"or",
"as",
"a",
"fallback",
"the",
"installation",
"-",
"email",
"-",
"adress",
"."
] | 6766a36cc2f0c807c59202bf7540a08c4ef31192 | https://github.com/sulu/sulu/blob/6766a36cc2f0c807c59202bf7540a08c4ef31192/src/Sulu/Bundle/SecurityBundle/Controller/ResettingController.php#L216-L223 | train |
sulu/sulu | src/Sulu/Bundle/SecurityBundle/Controller/ResettingController.php | ResettingController.findUserByValidToken | private function findUserByValidToken($token)
{
try {
/** @var UserInterface $user */
$user = $this->getUserRepository()->findUserByToken($token);
if (new \DateTime() > $user->getPasswordResetTokenExpiresAt()) {
throw new InvalidTokenException($token);
}
return $user;
} catch (NoResultException $exc) {
throw new InvalidTokenException($token);
}
} | php | private function findUserByValidToken($token)
{
try {
/** @var UserInterface $user */
$user = $this->getUserRepository()->findUserByToken($token);
if (new \DateTime() > $user->getPasswordResetTokenExpiresAt()) {
throw new InvalidTokenException($token);
}
return $user;
} catch (NoResultException $exc) {
throw new InvalidTokenException($token);
}
} | [
"private",
"function",
"findUserByValidToken",
"(",
"$",
"token",
")",
"{",
"try",
"{",
"/** @var UserInterface $user */",
"$",
"user",
"=",
"$",
"this",
"->",
"getUserRepository",
"(",
")",
"->",
"findUserByToken",
"(",
"$",
"token",
")",
";",
"if",
"(",
"new",
"\\",
"DateTime",
"(",
")",
">",
"$",
"user",
"->",
"getPasswordResetTokenExpiresAt",
"(",
")",
")",
"{",
"throw",
"new",
"InvalidTokenException",
"(",
"$",
"token",
")",
";",
"}",
"return",
"$",
"user",
";",
"}",
"catch",
"(",
"NoResultException",
"$",
"exc",
")",
"{",
"throw",
"new",
"InvalidTokenException",
"(",
"$",
"token",
")",
";",
"}",
"}"
] | Returns a user for a given token and checks if the token is still valid.
@param string $token
@return \Symfony\Component\Security\Core\User\UserInterface
@throws InvalidTokenException | [
"Returns",
"a",
"user",
"for",
"a",
"given",
"token",
"and",
"checks",
"if",
"the",
"token",
"is",
"still",
"valid",
"."
] | 6766a36cc2f0c807c59202bf7540a08c4ef31192 | https://github.com/sulu/sulu/blob/6766a36cc2f0c807c59202bf7540a08c4ef31192/src/Sulu/Bundle/SecurityBundle/Controller/ResettingController.php#L259-L272 | train |
sulu/sulu | src/Sulu/Bundle/SecurityBundle/Controller/ResettingController.php | ResettingController.loginUser | private function loginUser(UserInterface $user, $request)
{
$token = new UsernamePasswordToken($user, null, 'admin', $user->getRoles());
$this->get('security.token_storage')->setToken($token); //now the user is logged in
//now dispatch the login event
$event = new InteractiveLoginEvent($request, $token);
$this->get('event_dispatcher')->dispatch('security.interactive_login', $event);
} | php | private function loginUser(UserInterface $user, $request)
{
$token = new UsernamePasswordToken($user, null, 'admin', $user->getRoles());
$this->get('security.token_storage')->setToken($token); //now the user is logged in
//now dispatch the login event
$event = new InteractiveLoginEvent($request, $token);
$this->get('event_dispatcher')->dispatch('security.interactive_login', $event);
} | [
"private",
"function",
"loginUser",
"(",
"UserInterface",
"$",
"user",
",",
"$",
"request",
")",
"{",
"$",
"token",
"=",
"new",
"UsernamePasswordToken",
"(",
"$",
"user",
",",
"null",
",",
"'admin'",
",",
"$",
"user",
"->",
"getRoles",
"(",
")",
")",
";",
"$",
"this",
"->",
"get",
"(",
"'security.token_storage'",
")",
"->",
"setToken",
"(",
"$",
"token",
")",
";",
"//now the user is logged in",
"//now dispatch the login event",
"$",
"event",
"=",
"new",
"InteractiveLoginEvent",
"(",
"$",
"request",
",",
"$",
"token",
")",
";",
"$",
"this",
"->",
"get",
"(",
"'event_dispatcher'",
")",
"->",
"dispatch",
"(",
"'security.interactive_login'",
",",
"$",
"event",
")",
";",
"}"
] | Gives a user a token, so she's logged in.
@param UserInterface $user
@param $request | [
"Gives",
"a",
"user",
"a",
"token",
"so",
"she",
"s",
"logged",
"in",
"."
] | 6766a36cc2f0c807c59202bf7540a08c4ef31192 | https://github.com/sulu/sulu/blob/6766a36cc2f0c807c59202bf7540a08c4ef31192/src/Sulu/Bundle/SecurityBundle/Controller/ResettingController.php#L288-L296 | train |
sulu/sulu | src/Sulu/Bundle/SecurityBundle/Controller/ResettingController.php | ResettingController.deleteToken | private function deleteToken(UserInterface $user)
{
$em = $this->getDoctrine()->getManager();
$user->setPasswordResetToken(null);
$user->setPasswordResetTokenExpiresAt(null);
$user->setPasswordResetTokenEmailsSent(null);
$em->persist($user);
$em->flush();
} | php | private function deleteToken(UserInterface $user)
{
$em = $this->getDoctrine()->getManager();
$user->setPasswordResetToken(null);
$user->setPasswordResetTokenExpiresAt(null);
$user->setPasswordResetTokenEmailsSent(null);
$em->persist($user);
$em->flush();
} | [
"private",
"function",
"deleteToken",
"(",
"UserInterface",
"$",
"user",
")",
"{",
"$",
"em",
"=",
"$",
"this",
"->",
"getDoctrine",
"(",
")",
"->",
"getManager",
"(",
")",
";",
"$",
"user",
"->",
"setPasswordResetToken",
"(",
"null",
")",
";",
"$",
"user",
"->",
"setPasswordResetTokenExpiresAt",
"(",
"null",
")",
";",
"$",
"user",
"->",
"setPasswordResetTokenEmailsSent",
"(",
"null",
")",
";",
"$",
"em",
"->",
"persist",
"(",
"$",
"user",
")",
";",
"$",
"em",
"->",
"flush",
"(",
")",
";",
"}"
] | Deletes the user's reset-password-token.
@param UserInterface $user | [
"Deletes",
"the",
"user",
"s",
"reset",
"-",
"password",
"-",
"token",
"."
] | 6766a36cc2f0c807c59202bf7540a08c4ef31192 | https://github.com/sulu/sulu/blob/6766a36cc2f0c807c59202bf7540a08c4ef31192/src/Sulu/Bundle/SecurityBundle/Controller/ResettingController.php#L303-L311 | train |
sulu/sulu | src/Sulu/Bundle/SecurityBundle/Controller/ResettingController.php | ResettingController.sendTokenEmail | private function sendTokenEmail(UserInterface $user, $from, $to)
{
if (null === $user->getPasswordResetToken()) {
throw new NoTokenFoundException($user);
}
$maxNumberEmails = $this->getParameter('sulu_security.reset_password.mail.token_send_limit');
if ($user->getPasswordResetTokenEmailsSent() === $maxNumberEmails) {
throw new TokenEmailsLimitReachedException($maxNumberEmails, $user);
}
$mailer = $this->get('mailer');
$em = $this->getDoctrine()->getManager();
$message = $mailer->createMessage()->setSubject(
$this->getSubject()
)->setFrom($from)->setTo($to)->setBody(
$this->getMessage($user)
);
$mailer->send($message);
$user->setPasswordResetTokenEmailsSent($user->getPasswordResetTokenEmailsSent() + 1);
$em->persist($user);
$em->flush();
} | php | private function sendTokenEmail(UserInterface $user, $from, $to)
{
if (null === $user->getPasswordResetToken()) {
throw new NoTokenFoundException($user);
}
$maxNumberEmails = $this->getParameter('sulu_security.reset_password.mail.token_send_limit');
if ($user->getPasswordResetTokenEmailsSent() === $maxNumberEmails) {
throw new TokenEmailsLimitReachedException($maxNumberEmails, $user);
}
$mailer = $this->get('mailer');
$em = $this->getDoctrine()->getManager();
$message = $mailer->createMessage()->setSubject(
$this->getSubject()
)->setFrom($from)->setTo($to)->setBody(
$this->getMessage($user)
);
$mailer->send($message);
$user->setPasswordResetTokenEmailsSent($user->getPasswordResetTokenEmailsSent() + 1);
$em->persist($user);
$em->flush();
} | [
"private",
"function",
"sendTokenEmail",
"(",
"UserInterface",
"$",
"user",
",",
"$",
"from",
",",
"$",
"to",
")",
"{",
"if",
"(",
"null",
"===",
"$",
"user",
"->",
"getPasswordResetToken",
"(",
")",
")",
"{",
"throw",
"new",
"NoTokenFoundException",
"(",
"$",
"user",
")",
";",
"}",
"$",
"maxNumberEmails",
"=",
"$",
"this",
"->",
"getParameter",
"(",
"'sulu_security.reset_password.mail.token_send_limit'",
")",
";",
"if",
"(",
"$",
"user",
"->",
"getPasswordResetTokenEmailsSent",
"(",
")",
"===",
"$",
"maxNumberEmails",
")",
"{",
"throw",
"new",
"TokenEmailsLimitReachedException",
"(",
"$",
"maxNumberEmails",
",",
"$",
"user",
")",
";",
"}",
"$",
"mailer",
"=",
"$",
"this",
"->",
"get",
"(",
"'mailer'",
")",
";",
"$",
"em",
"=",
"$",
"this",
"->",
"getDoctrine",
"(",
")",
"->",
"getManager",
"(",
")",
";",
"$",
"message",
"=",
"$",
"mailer",
"->",
"createMessage",
"(",
")",
"->",
"setSubject",
"(",
"$",
"this",
"->",
"getSubject",
"(",
")",
")",
"->",
"setFrom",
"(",
"$",
"from",
")",
"->",
"setTo",
"(",
"$",
"to",
")",
"->",
"setBody",
"(",
"$",
"this",
"->",
"getMessage",
"(",
"$",
"user",
")",
")",
";",
"$",
"mailer",
"->",
"send",
"(",
"$",
"message",
")",
";",
"$",
"user",
"->",
"setPasswordResetTokenEmailsSent",
"(",
"$",
"user",
"->",
"getPasswordResetTokenEmailsSent",
"(",
")",
"+",
"1",
")",
";",
"$",
"em",
"->",
"persist",
"(",
"$",
"user",
")",
";",
"$",
"em",
"->",
"flush",
"(",
")",
";",
"}"
] | Sends the password-reset-token of a user to an email-adress.
@param UserInterface $user
@param string $from From-Email-Address
@param string $to To-Email-Address
@throws NoTokenFoundException
@throws TokenEmailsLimitReachedException | [
"Sends",
"the",
"password",
"-",
"reset",
"-",
"token",
"of",
"a",
"user",
"to",
"an",
"email",
"-",
"adress",
"."
] | 6766a36cc2f0c807c59202bf7540a08c4ef31192 | https://github.com/sulu/sulu/blob/6766a36cc2f0c807c59202bf7540a08c4ef31192/src/Sulu/Bundle/SecurityBundle/Controller/ResettingController.php#L323-L345 | train |
sulu/sulu | src/Sulu/Bundle/SecurityBundle/Controller/ResettingController.php | ResettingController.changePassword | private function changePassword(UserInterface $user, $password)
{
if ('' === $password) {
throw new MissingPasswordException();
}
$em = $this->getDoctrine()->getManager();
$user->setPassword($this->encodePassword($user, $password, $user->getSalt()));
$em->persist($user);
$em->flush();
} | php | private function changePassword(UserInterface $user, $password)
{
if ('' === $password) {
throw new MissingPasswordException();
}
$em = $this->getDoctrine()->getManager();
$user->setPassword($this->encodePassword($user, $password, $user->getSalt()));
$em->persist($user);
$em->flush();
} | [
"private",
"function",
"changePassword",
"(",
"UserInterface",
"$",
"user",
",",
"$",
"password",
")",
"{",
"if",
"(",
"''",
"===",
"$",
"password",
")",
"{",
"throw",
"new",
"MissingPasswordException",
"(",
")",
";",
"}",
"$",
"em",
"=",
"$",
"this",
"->",
"getDoctrine",
"(",
")",
"->",
"getManager",
"(",
")",
";",
"$",
"user",
"->",
"setPassword",
"(",
"$",
"this",
"->",
"encodePassword",
"(",
"$",
"user",
",",
"$",
"password",
",",
"$",
"user",
"->",
"getSalt",
"(",
")",
")",
")",
";",
"$",
"em",
"->",
"persist",
"(",
"$",
"user",
")",
";",
"$",
"em",
"->",
"flush",
"(",
")",
";",
"}"
] | Changes the password of a user.
@param UserInterface $user
@param string $password
@throws MissingPasswordException | [
"Changes",
"the",
"password",
"of",
"a",
"user",
"."
] | 6766a36cc2f0c807c59202bf7540a08c4ef31192 | https://github.com/sulu/sulu/blob/6766a36cc2f0c807c59202bf7540a08c4ef31192/src/Sulu/Bundle/SecurityBundle/Controller/ResettingController.php#L355-L364 | train |
sulu/sulu | src/Sulu/Bundle/SecurityBundle/Controller/ResettingController.php | ResettingController.generateTokenForUser | private function generateTokenForUser(UserInterface $user)
{
// if a token was already requested within the request interval time frame
if (null !== $user->getPasswordResetToken()
&& $this->dateIsInRequestFrame($user->getPasswordResetTokenExpiresAt())) {
throw new TokenAlreadyRequestedException(self::getRequestInterval());
}
$em = $this->getDoctrine()->getManager();
$user->setPasswordResetToken($this->getToken());
$expireDateTime = (new \DateTime())->add(self::getResetInterval());
$user->setPasswordResetTokenExpiresAt($expireDateTime);
$user->setPasswordResetTokenEmailsSent(0);
$em->persist($user);
$em->flush();
} | php | private function generateTokenForUser(UserInterface $user)
{
// if a token was already requested within the request interval time frame
if (null !== $user->getPasswordResetToken()
&& $this->dateIsInRequestFrame($user->getPasswordResetTokenExpiresAt())) {
throw new TokenAlreadyRequestedException(self::getRequestInterval());
}
$em = $this->getDoctrine()->getManager();
$user->setPasswordResetToken($this->getToken());
$expireDateTime = (new \DateTime())->add(self::getResetInterval());
$user->setPasswordResetTokenExpiresAt($expireDateTime);
$user->setPasswordResetTokenEmailsSent(0);
$em->persist($user);
$em->flush();
} | [
"private",
"function",
"generateTokenForUser",
"(",
"UserInterface",
"$",
"user",
")",
"{",
"// if a token was already requested within the request interval time frame",
"if",
"(",
"null",
"!==",
"$",
"user",
"->",
"getPasswordResetToken",
"(",
")",
"&&",
"$",
"this",
"->",
"dateIsInRequestFrame",
"(",
"$",
"user",
"->",
"getPasswordResetTokenExpiresAt",
"(",
")",
")",
")",
"{",
"throw",
"new",
"TokenAlreadyRequestedException",
"(",
"self",
"::",
"getRequestInterval",
"(",
")",
")",
";",
"}",
"$",
"em",
"=",
"$",
"this",
"->",
"getDoctrine",
"(",
")",
"->",
"getManager",
"(",
")",
";",
"$",
"user",
"->",
"setPasswordResetToken",
"(",
"$",
"this",
"->",
"getToken",
"(",
")",
")",
";",
"$",
"expireDateTime",
"=",
"(",
"new",
"\\",
"DateTime",
"(",
")",
")",
"->",
"add",
"(",
"self",
"::",
"getResetInterval",
"(",
")",
")",
";",
"$",
"user",
"->",
"setPasswordResetTokenExpiresAt",
"(",
"$",
"expireDateTime",
")",
";",
"$",
"user",
"->",
"setPasswordResetTokenEmailsSent",
"(",
"0",
")",
";",
"$",
"em",
"->",
"persist",
"(",
"$",
"user",
")",
";",
"$",
"em",
"->",
"flush",
"(",
")",
";",
"}"
] | Generates a new token for a new user.
@param UserInterface $user
@throws TokenAlreadyRequestedException | [
"Generates",
"a",
"new",
"token",
"for",
"a",
"new",
"user",
"."
] | 6766a36cc2f0c807c59202bf7540a08c4ef31192 | https://github.com/sulu/sulu/blob/6766a36cc2f0c807c59202bf7540a08c4ef31192/src/Sulu/Bundle/SecurityBundle/Controller/ResettingController.php#L373-L389 | train |
sulu/sulu | src/Sulu/Bundle/SecurityBundle/Controller/ResettingController.php | ResettingController.getUniqueToken | private function getUniqueToken($startToken)
{
try {
$this->getUserRepository()->findUserByToken($startToken);
} catch (NoResultException $ex) {
return $startToken;
}
return $this->getUniqueToken($this->getTokenGenerator()->generateToken());
} | php | private function getUniqueToken($startToken)
{
try {
$this->getUserRepository()->findUserByToken($startToken);
} catch (NoResultException $ex) {
return $startToken;
}
return $this->getUniqueToken($this->getTokenGenerator()->generateToken());
} | [
"private",
"function",
"getUniqueToken",
"(",
"$",
"startToken",
")",
"{",
"try",
"{",
"$",
"this",
"->",
"getUserRepository",
"(",
")",
"->",
"findUserByToken",
"(",
"$",
"startToken",
")",
";",
"}",
"catch",
"(",
"NoResultException",
"$",
"ex",
")",
"{",
"return",
"$",
"startToken",
";",
"}",
"return",
"$",
"this",
"->",
"getUniqueToken",
"(",
"$",
"this",
"->",
"getTokenGenerator",
"(",
")",
"->",
"generateToken",
"(",
")",
")",
";",
"}"
] | If the passed token is unique returns it back otherwise returns a unique token.
@param string $startToken The token to start width
@return string a unique token | [
"If",
"the",
"passed",
"token",
"is",
"unique",
"returns",
"it",
"back",
"otherwise",
"returns",
"a",
"unique",
"token",
"."
] | 6766a36cc2f0c807c59202bf7540a08c4ef31192 | https://github.com/sulu/sulu/blob/6766a36cc2f0c807c59202bf7540a08c4ef31192/src/Sulu/Bundle/SecurityBundle/Controller/ResettingController.php#L425-L434 | train |
sulu/sulu | src/Sulu/Bundle/SecurityBundle/Controller/ResettingController.php | ResettingController.encodePassword | private function encodePassword(UserInterface $user, $password, $salt)
{
$encoder = $this->get('sulu_security.encoder_factory')->getEncoder($user);
return $encoder->encodePassword($password, $salt);
} | php | private function encodePassword(UserInterface $user, $password, $salt)
{
$encoder = $this->get('sulu_security.encoder_factory')->getEncoder($user);
return $encoder->encodePassword($password, $salt);
} | [
"private",
"function",
"encodePassword",
"(",
"UserInterface",
"$",
"user",
",",
"$",
"password",
",",
"$",
"salt",
")",
"{",
"$",
"encoder",
"=",
"$",
"this",
"->",
"get",
"(",
"'sulu_security.encoder_factory'",
")",
"->",
"getEncoder",
"(",
"$",
"user",
")",
";",
"return",
"$",
"encoder",
"->",
"encodePassword",
"(",
"$",
"password",
",",
"$",
"salt",
")",
";",
"}"
] | Returns an encoded password gor a given one.
@param UserInterface $user
@param string $password
@param string $salt
@return mixed | [
"Returns",
"an",
"encoded",
"password",
"gor",
"a",
"given",
"one",
"."
] | 6766a36cc2f0c807c59202bf7540a08c4ef31192 | https://github.com/sulu/sulu/blob/6766a36cc2f0c807c59202bf7540a08c4ef31192/src/Sulu/Bundle/SecurityBundle/Controller/ResettingController.php#L445-L450 | train |
sulu/sulu | src/Sulu/Bundle/SecurityBundle/Controller/ResettingController.php | ResettingController.hasSystem | private function hasSystem(SuluUserInterface $user)
{
$system = $this->getSystem();
foreach ($user->getRoleObjects() as $role) {
if ($role->getSystem() === $system) {
return true;
}
}
return false;
} | php | private function hasSystem(SuluUserInterface $user)
{
$system = $this->getSystem();
foreach ($user->getRoleObjects() as $role) {
if ($role->getSystem() === $system) {
return true;
}
}
return false;
} | [
"private",
"function",
"hasSystem",
"(",
"SuluUserInterface",
"$",
"user",
")",
"{",
"$",
"system",
"=",
"$",
"this",
"->",
"getSystem",
"(",
")",
";",
"foreach",
"(",
"$",
"user",
"->",
"getRoleObjects",
"(",
")",
"as",
"$",
"role",
")",
"{",
"if",
"(",
"$",
"role",
"->",
"getSystem",
"(",
")",
"===",
"$",
"system",
")",
"{",
"return",
"true",
";",
"}",
"}",
"return",
"false",
";",
"}"
] | Check if given user has sulu-system.
@param SuluUserInterface $user
@return bool | [
"Check",
"if",
"given",
"user",
"has",
"sulu",
"-",
"system",
"."
] | 6766a36cc2f0c807c59202bf7540a08c4ef31192 | https://github.com/sulu/sulu/blob/6766a36cc2f0c807c59202bf7540a08c4ef31192/src/Sulu/Bundle/SecurityBundle/Controller/ResettingController.php#L467-L477 | train |
sulu/sulu | src/Sulu/Bundle/MediaBundle/Media/ImageConverter/Cropper/Cropper.php | Cropper.isInsideImage | private function isInsideImage(ImageInterface $image, $x, $y, $width, $height)
{
if ($x < 0 || $y < 0) {
return false;
}
if ($x + $width > $image->getSize()->getWidth()) {
return false;
}
if ($y + $height > $image->getSize()->getHeight()) {
return false;
}
return true;
} | php | private function isInsideImage(ImageInterface $image, $x, $y, $width, $height)
{
if ($x < 0 || $y < 0) {
return false;
}
if ($x + $width > $image->getSize()->getWidth()) {
return false;
}
if ($y + $height > $image->getSize()->getHeight()) {
return false;
}
return true;
} | [
"private",
"function",
"isInsideImage",
"(",
"ImageInterface",
"$",
"image",
",",
"$",
"x",
",",
"$",
"y",
",",
"$",
"width",
",",
"$",
"height",
")",
"{",
"if",
"(",
"$",
"x",
"<",
"0",
"||",
"$",
"y",
"<",
"0",
")",
"{",
"return",
"false",
";",
"}",
"if",
"(",
"$",
"x",
"+",
"$",
"width",
">",
"$",
"image",
"->",
"getSize",
"(",
")",
"->",
"getWidth",
"(",
")",
")",
"{",
"return",
"false",
";",
"}",
"if",
"(",
"$",
"y",
"+",
"$",
"height",
">",
"$",
"image",
"->",
"getSize",
"(",
")",
"->",
"getHeight",
"(",
")",
")",
"{",
"return",
"false",
";",
"}",
"return",
"true",
";",
"}"
] | Returns true iff the cropping does not exceed the image borders.
@param ImageInterface $image
@param $x
@param $y
@param $width
@param $height
@return bool | [
"Returns",
"true",
"iff",
"the",
"cropping",
"does",
"not",
"exceed",
"the",
"image",
"borders",
"."
] | 6766a36cc2f0c807c59202bf7540a08c4ef31192 | https://github.com/sulu/sulu/blob/6766a36cc2f0c807c59202bf7540a08c4ef31192/src/Sulu/Bundle/MediaBundle/Media/ImageConverter/Cropper/Cropper.php#L56-L69 | train |
sulu/sulu | src/Sulu/Bundle/MediaBundle/Media/ImageConverter/Cropper/Cropper.php | Cropper.isNotSmallerThanFormat | private function isNotSmallerThanFormat($width, $height, array $format)
{
if (isset($format['scale']['x']) && $width < $format['scale']['x']) {
return false;
}
if (isset($format['scale']['y']) && $height < $format['scale']['y']) {
return false;
}
return true;
} | php | private function isNotSmallerThanFormat($width, $height, array $format)
{
if (isset($format['scale']['x']) && $width < $format['scale']['x']) {
return false;
}
if (isset($format['scale']['y']) && $height < $format['scale']['y']) {
return false;
}
return true;
} | [
"private",
"function",
"isNotSmallerThanFormat",
"(",
"$",
"width",
",",
"$",
"height",
",",
"array",
"$",
"format",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"format",
"[",
"'scale'",
"]",
"[",
"'x'",
"]",
")",
"&&",
"$",
"width",
"<",
"$",
"format",
"[",
"'scale'",
"]",
"[",
"'x'",
"]",
")",
"{",
"return",
"false",
";",
"}",
"if",
"(",
"isset",
"(",
"$",
"format",
"[",
"'scale'",
"]",
"[",
"'y'",
"]",
")",
"&&",
"$",
"height",
"<",
"$",
"format",
"[",
"'scale'",
"]",
"[",
"'y'",
"]",
")",
"{",
"return",
"false",
";",
"}",
"return",
"true",
";",
"}"
] | Returns true iff the crop is greater or equal to the size of a given format.
@param $width
@param $height
@param array $format
@return bool | [
"Returns",
"true",
"iff",
"the",
"crop",
"is",
"greater",
"or",
"equal",
"to",
"the",
"size",
"of",
"a",
"given",
"format",
"."
] | 6766a36cc2f0c807c59202bf7540a08c4ef31192 | https://github.com/sulu/sulu/blob/6766a36cc2f0c807c59202bf7540a08c4ef31192/src/Sulu/Bundle/MediaBundle/Media/ImageConverter/Cropper/Cropper.php#L80-L90 | train |
sulu/sulu | src/Sulu/Bundle/DocumentManagerBundle/Document/Subscriber/SecuritySubscriber.php | SecuritySubscriber.setDefaultUser | public function setDefaultUser(ConfigureOptionsEvent $event)
{
$optionsResolver = $event->getOptions();
$optionsResolver->setDefault(static::USER_OPTION, null);
if (null === $this->tokenStorage) {
return;
}
$token = $this->tokenStorage->getToken();
if (null === $token || $token instanceof AnonymousToken) {
return;
}
$user = $token->getUser();
if (!$user instanceof UserInterface) {
return;
}
$optionsResolver->setDefault(static::USER_OPTION, $user->getId());
} | php | public function setDefaultUser(ConfigureOptionsEvent $event)
{
$optionsResolver = $event->getOptions();
$optionsResolver->setDefault(static::USER_OPTION, null);
if (null === $this->tokenStorage) {
return;
}
$token = $this->tokenStorage->getToken();
if (null === $token || $token instanceof AnonymousToken) {
return;
}
$user = $token->getUser();
if (!$user instanceof UserInterface) {
return;
}
$optionsResolver->setDefault(static::USER_OPTION, $user->getId());
} | [
"public",
"function",
"setDefaultUser",
"(",
"ConfigureOptionsEvent",
"$",
"event",
")",
"{",
"$",
"optionsResolver",
"=",
"$",
"event",
"->",
"getOptions",
"(",
")",
";",
"$",
"optionsResolver",
"->",
"setDefault",
"(",
"static",
"::",
"USER_OPTION",
",",
"null",
")",
";",
"if",
"(",
"null",
"===",
"$",
"this",
"->",
"tokenStorage",
")",
"{",
"return",
";",
"}",
"$",
"token",
"=",
"$",
"this",
"->",
"tokenStorage",
"->",
"getToken",
"(",
")",
";",
"if",
"(",
"null",
"===",
"$",
"token",
"||",
"$",
"token",
"instanceof",
"AnonymousToken",
")",
"{",
"return",
";",
"}",
"$",
"user",
"=",
"$",
"token",
"->",
"getUser",
"(",
")",
";",
"if",
"(",
"!",
"$",
"user",
"instanceof",
"UserInterface",
")",
"{",
"return",
";",
"}",
"$",
"optionsResolver",
"->",
"setDefault",
"(",
"static",
"::",
"USER_OPTION",
",",
"$",
"user",
"->",
"getId",
"(",
")",
")",
";",
"}"
] | Sets the default user from the session.
@param ConfigureOptionsEvent $event | [
"Sets",
"the",
"default",
"user",
"from",
"the",
"session",
"."
] | 6766a36cc2f0c807c59202bf7540a08c4ef31192 | https://github.com/sulu/sulu/blob/6766a36cc2f0c807c59202bf7540a08c4ef31192/src/Sulu/Bundle/DocumentManagerBundle/Document/Subscriber/SecuritySubscriber.php#L53-L76 | train |
sulu/sulu | src/Sulu/Bundle/ContactBundle/Entity/PhoneType.php | PhoneType.addPhone | public function addPhone(\Sulu\Bundle\ContactBundle\Entity\Phone $phones)
{
$this->phones[] = $phones;
return $this;
} | php | public function addPhone(\Sulu\Bundle\ContactBundle\Entity\Phone $phones)
{
$this->phones[] = $phones;
return $this;
} | [
"public",
"function",
"addPhone",
"(",
"\\",
"Sulu",
"\\",
"Bundle",
"\\",
"ContactBundle",
"\\",
"Entity",
"\\",
"Phone",
"$",
"phones",
")",
"{",
"$",
"this",
"->",
"phones",
"[",
"]",
"=",
"$",
"phones",
";",
"return",
"$",
"this",
";",
"}"
] | Add phones.
@param \Sulu\Bundle\ContactBundle\Entity\Phone $phones
@return PhoneType | [
"Add",
"phones",
"."
] | 6766a36cc2f0c807c59202bf7540a08c4ef31192 | https://github.com/sulu/sulu/blob/6766a36cc2f0c807c59202bf7540a08c4ef31192/src/Sulu/Bundle/ContactBundle/Entity/PhoneType.php#L99-L104 | train |
sulu/sulu | src/Sulu/Bundle/ContactBundle/Entity/PhoneType.php | PhoneType.removePhone | public function removePhone(\Sulu\Bundle\ContactBundle\Entity\Phone $phones)
{
$this->phones->removeElement($phones);
} | php | public function removePhone(\Sulu\Bundle\ContactBundle\Entity\Phone $phones)
{
$this->phones->removeElement($phones);
} | [
"public",
"function",
"removePhone",
"(",
"\\",
"Sulu",
"\\",
"Bundle",
"\\",
"ContactBundle",
"\\",
"Entity",
"\\",
"Phone",
"$",
"phones",
")",
"{",
"$",
"this",
"->",
"phones",
"->",
"removeElement",
"(",
"$",
"phones",
")",
";",
"}"
] | Remove phones.
@param \Sulu\Bundle\ContactBundle\Entity\Phone $phones | [
"Remove",
"phones",
"."
] | 6766a36cc2f0c807c59202bf7540a08c4ef31192 | https://github.com/sulu/sulu/blob/6766a36cc2f0c807c59202bf7540a08c4ef31192/src/Sulu/Bundle/ContactBundle/Entity/PhoneType.php#L111-L114 | train |
sulu/sulu | src/Sulu/Component/Webspace/Manager/WebspaceCollection.php | WebspaceCollection.getPortal | public function getPortal($key)
{
return array_key_exists($key, $this->portals) ? $this->portals[$key] : null;
} | php | public function getPortal($key)
{
return array_key_exists($key, $this->portals) ? $this->portals[$key] : null;
} | [
"public",
"function",
"getPortal",
"(",
"$",
"key",
")",
"{",
"return",
"array_key_exists",
"(",
"$",
"key",
",",
"$",
"this",
"->",
"portals",
")",
"?",
"$",
"this",
"->",
"portals",
"[",
"$",
"key",
"]",
":",
"null",
";",
"}"
] | Returns the portal with the given index.
@param $key string The index of the portal
@return Portal | [
"Returns",
"the",
"portal",
"with",
"the",
"given",
"index",
"."
] | 6766a36cc2f0c807c59202bf7540a08c4ef31192 | https://github.com/sulu/sulu/blob/6766a36cc2f0c807c59202bf7540a08c4ef31192/src/Sulu/Component/Webspace/Manager/WebspaceCollection.php#L81-L84 | train |
sulu/sulu | src/Sulu/Component/Webspace/Manager/WebspaceCollection.php | WebspaceCollection.getPortalInformations | public function getPortalInformations($environment, $types = null)
{
if (!isset($this->portalInformations[$environment])) {
throw new \InvalidArgumentException(sprintf(
'Unknown portal environment "%s"', $environment
));
}
if (null === $types) {
return $this->portalInformations[$environment];
}
return array_filter(
$this->portalInformations[$environment],
function(PortalInformation $portalInformation) use ($types) {
return in_array($portalInformation->getType(), $types);
}
);
} | php | public function getPortalInformations($environment, $types = null)
{
if (!isset($this->portalInformations[$environment])) {
throw new \InvalidArgumentException(sprintf(
'Unknown portal environment "%s"', $environment
));
}
if (null === $types) {
return $this->portalInformations[$environment];
}
return array_filter(
$this->portalInformations[$environment],
function(PortalInformation $portalInformation) use ($types) {
return in_array($portalInformation->getType(), $types);
}
);
} | [
"public",
"function",
"getPortalInformations",
"(",
"$",
"environment",
",",
"$",
"types",
"=",
"null",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"this",
"->",
"portalInformations",
"[",
"$",
"environment",
"]",
")",
")",
"{",
"throw",
"new",
"\\",
"InvalidArgumentException",
"(",
"sprintf",
"(",
"'Unknown portal environment \"%s\"'",
",",
"$",
"environment",
")",
")",
";",
"}",
"if",
"(",
"null",
"===",
"$",
"types",
")",
"{",
"return",
"$",
"this",
"->",
"portalInformations",
"[",
"$",
"environment",
"]",
";",
"}",
"return",
"array_filter",
"(",
"$",
"this",
"->",
"portalInformations",
"[",
"$",
"environment",
"]",
",",
"function",
"(",
"PortalInformation",
"$",
"portalInformation",
")",
"use",
"(",
"$",
"types",
")",
"{",
"return",
"in_array",
"(",
"$",
"portalInformation",
"->",
"getType",
"(",
")",
",",
"$",
"types",
")",
";",
"}",
")",
";",
"}"
] | Returns the portal informations for the given environment.
@param $environment string The environment to deliver
@param array|null $types Defines which typr of portals are requested (null for all)
@return \Sulu\Component\Webspace\PortalInformation[] | [
"Returns",
"the",
"portal",
"informations",
"for",
"the",
"given",
"environment",
"."
] | 6766a36cc2f0c807c59202bf7540a08c4ef31192 | https://github.com/sulu/sulu/blob/6766a36cc2f0c807c59202bf7540a08c4ef31192/src/Sulu/Component/Webspace/Manager/WebspaceCollection.php#L94-L111 | train |
sulu/sulu | src/Sulu/Component/Webspace/Manager/WebspaceCollection.php | WebspaceCollection.getWebspace | public function getWebspace($key)
{
return array_key_exists($key, $this->webspaces) ? $this->webspaces[$key] : null;
} | php | public function getWebspace($key)
{
return array_key_exists($key, $this->webspaces) ? $this->webspaces[$key] : null;
} | [
"public",
"function",
"getWebspace",
"(",
"$",
"key",
")",
"{",
"return",
"array_key_exists",
"(",
"$",
"key",
",",
"$",
"this",
"->",
"webspaces",
")",
"?",
"$",
"this",
"->",
"webspaces",
"[",
"$",
"key",
"]",
":",
"null",
";",
"}"
] | Returns the webspace with the given key.
@param $key string The key of the webspace
@return Webspace | [
"Returns",
"the",
"webspace",
"with",
"the",
"given",
"key",
"."
] | 6766a36cc2f0c807c59202bf7540a08c4ef31192 | https://github.com/sulu/sulu/blob/6766a36cc2f0c807c59202bf7540a08c4ef31192/src/Sulu/Component/Webspace/Manager/WebspaceCollection.php#L120-L123 | train |
sulu/sulu | src/Sulu/Component/Webspace/Manager/WebspaceCollection.php | WebspaceCollection.toArray | public function toArray()
{
$collection = [];
$webspaces = [];
foreach ($this->webspaces as $webspace) {
$webspaces[] = $webspace->toArray();
}
$portalInformations = [];
foreach ($this->portalInformations as $environment => $environmentPortalInformations) {
$portalInformations[$environment] = [];
foreach ($environmentPortalInformations as $environmentPortalInformation) {
$portalInformations[$environment][$environmentPortalInformation->getUrl()] = $environmentPortalInformation->toArray();
}
}
$collection['webspaces'] = $webspaces;
$collection['portalInformations'] = $portalInformations;
return $collection;
} | php | public function toArray()
{
$collection = [];
$webspaces = [];
foreach ($this->webspaces as $webspace) {
$webspaces[] = $webspace->toArray();
}
$portalInformations = [];
foreach ($this->portalInformations as $environment => $environmentPortalInformations) {
$portalInformations[$environment] = [];
foreach ($environmentPortalInformations as $environmentPortalInformation) {
$portalInformations[$environment][$environmentPortalInformation->getUrl()] = $environmentPortalInformation->toArray();
}
}
$collection['webspaces'] = $webspaces;
$collection['portalInformations'] = $portalInformations;
return $collection;
} | [
"public",
"function",
"toArray",
"(",
")",
"{",
"$",
"collection",
"=",
"[",
"]",
";",
"$",
"webspaces",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"this",
"->",
"webspaces",
"as",
"$",
"webspace",
")",
"{",
"$",
"webspaces",
"[",
"]",
"=",
"$",
"webspace",
"->",
"toArray",
"(",
")",
";",
"}",
"$",
"portalInformations",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"this",
"->",
"portalInformations",
"as",
"$",
"environment",
"=>",
"$",
"environmentPortalInformations",
")",
"{",
"$",
"portalInformations",
"[",
"$",
"environment",
"]",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"environmentPortalInformations",
"as",
"$",
"environmentPortalInformation",
")",
"{",
"$",
"portalInformations",
"[",
"$",
"environment",
"]",
"[",
"$",
"environmentPortalInformation",
"->",
"getUrl",
"(",
")",
"]",
"=",
"$",
"environmentPortalInformation",
"->",
"toArray",
"(",
")",
";",
"}",
"}",
"$",
"collection",
"[",
"'webspaces'",
"]",
"=",
"$",
"webspaces",
";",
"$",
"collection",
"[",
"'portalInformations'",
"]",
"=",
"$",
"portalInformations",
";",
"return",
"$",
"collection",
";",
"}"
] | Returns the content of these portals as array.
@return array | [
"Returns",
"the",
"content",
"of",
"these",
"portals",
"as",
"array",
"."
] | 6766a36cc2f0c807c59202bf7540a08c4ef31192 | https://github.com/sulu/sulu/blob/6766a36cc2f0c807c59202bf7540a08c4ef31192/src/Sulu/Component/Webspace/Manager/WebspaceCollection.php#L154-L176 | train |
sulu/sulu | src/Sulu/Component/Rest/ListBuilder/AbstractListBuilder.php | AbstractListBuilder.retrieveIndexOfFieldDescriptor | protected function retrieveIndexOfFieldDescriptor(
FieldDescriptorInterface $fieldDescriptor,
array $fieldDescriptors
) {
foreach ($fieldDescriptors as $index => $other) {
if ($fieldDescriptor->compare($other)) {
return $index;
}
}
return false;
} | php | protected function retrieveIndexOfFieldDescriptor(
FieldDescriptorInterface $fieldDescriptor,
array $fieldDescriptors
) {
foreach ($fieldDescriptors as $index => $other) {
if ($fieldDescriptor->compare($other)) {
return $index;
}
}
return false;
} | [
"protected",
"function",
"retrieveIndexOfFieldDescriptor",
"(",
"FieldDescriptorInterface",
"$",
"fieldDescriptor",
",",
"array",
"$",
"fieldDescriptors",
")",
"{",
"foreach",
"(",
"$",
"fieldDescriptors",
"as",
"$",
"index",
"=>",
"$",
"other",
")",
"{",
"if",
"(",
"$",
"fieldDescriptor",
"->",
"compare",
"(",
"$",
"other",
")",
")",
"{",
"return",
"$",
"index",
";",
"}",
"}",
"return",
"false",
";",
"}"
] | Returns index of given FieldDescriptor in given array of descriptors.
If no match is found, false will be returned.
@param FieldDescriptorInterface $fieldDescriptor
@param FieldDescriptorInterface[] $fieldDescriptors
@return bool|int|string | [
"Returns",
"index",
"of",
"given",
"FieldDescriptor",
"in",
"given",
"array",
"of",
"descriptors",
".",
"If",
"no",
"match",
"is",
"found",
"false",
"will",
"be",
"returned",
"."
] | 6766a36cc2f0c807c59202bf7540a08c4ef31192 | https://github.com/sulu/sulu/blob/6766a36cc2f0c807c59202bf7540a08c4ef31192/src/Sulu/Component/Rest/ListBuilder/AbstractListBuilder.php#L419-L430 | train |
sulu/sulu | src/Sulu/Bundle/HttpCacheBundle/EventSubscriber/TagsSubscriber.php | TagsSubscriber.addTags | public function addTags(): void
{
$tags = $this->getTags();
$currentStructureUuid = $this->getCurrentStructureUuid();
if ($currentStructureUuid && !in_array($currentStructureUuid, $tags)) {
$tags[] = $currentStructureUuid;
}
if (count($tags) <= 0) {
return;
}
$this->symfonyResponseTagger->addTags($tags);
} | php | public function addTags(): void
{
$tags = $this->getTags();
$currentStructureUuid = $this->getCurrentStructureUuid();
if ($currentStructureUuid && !in_array($currentStructureUuid, $tags)) {
$tags[] = $currentStructureUuid;
}
if (count($tags) <= 0) {
return;
}
$this->symfonyResponseTagger->addTags($tags);
} | [
"public",
"function",
"addTags",
"(",
")",
":",
"void",
"{",
"$",
"tags",
"=",
"$",
"this",
"->",
"getTags",
"(",
")",
";",
"$",
"currentStructureUuid",
"=",
"$",
"this",
"->",
"getCurrentStructureUuid",
"(",
")",
";",
"if",
"(",
"$",
"currentStructureUuid",
"&&",
"!",
"in_array",
"(",
"$",
"currentStructureUuid",
",",
"$",
"tags",
")",
")",
"{",
"$",
"tags",
"[",
"]",
"=",
"$",
"currentStructureUuid",
";",
"}",
"if",
"(",
"count",
"(",
"$",
"tags",
")",
"<=",
"0",
")",
"{",
"return",
";",
"}",
"$",
"this",
"->",
"symfonyResponseTagger",
"->",
"addTags",
"(",
"$",
"tags",
")",
";",
"}"
] | Adds tags from the reference store to the response tagger. | [
"Adds",
"tags",
"from",
"the",
"reference",
"store",
"to",
"the",
"response",
"tagger",
"."
] | 6766a36cc2f0c807c59202bf7540a08c4ef31192 | https://github.com/sulu/sulu/blob/6766a36cc2f0c807c59202bf7540a08c4ef31192/src/Sulu/Bundle/HttpCacheBundle/EventSubscriber/TagsSubscriber.php#L66-L79 | train |
sulu/sulu | src/Sulu/Bundle/HttpCacheBundle/EventSubscriber/TagsSubscriber.php | TagsSubscriber.getTags | private function getTags(): array
{
$tags = [];
foreach ($this->referenceStorePool->getStores() as $alias => $referenceStore) {
$tags = array_merge($tags, $this->getTagsFromStore($alias, $referenceStore));
}
return $tags;
} | php | private function getTags(): array
{
$tags = [];
foreach ($this->referenceStorePool->getStores() as $alias => $referenceStore) {
$tags = array_merge($tags, $this->getTagsFromStore($alias, $referenceStore));
}
return $tags;
} | [
"private",
"function",
"getTags",
"(",
")",
":",
"array",
"{",
"$",
"tags",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"this",
"->",
"referenceStorePool",
"->",
"getStores",
"(",
")",
"as",
"$",
"alias",
"=>",
"$",
"referenceStore",
")",
"{",
"$",
"tags",
"=",
"array_merge",
"(",
"$",
"tags",
",",
"$",
"this",
"->",
"getTagsFromStore",
"(",
"$",
"alias",
",",
"$",
"referenceStore",
")",
")",
";",
"}",
"return",
"$",
"tags",
";",
"}"
] | Merges tags from all registered stores. | [
"Merges",
"tags",
"from",
"all",
"registered",
"stores",
"."
] | 6766a36cc2f0c807c59202bf7540a08c4ef31192 | https://github.com/sulu/sulu/blob/6766a36cc2f0c807c59202bf7540a08c4ef31192/src/Sulu/Bundle/HttpCacheBundle/EventSubscriber/TagsSubscriber.php#L84-L92 | train |
sulu/sulu | src/Sulu/Bundle/HttpCacheBundle/EventSubscriber/TagsSubscriber.php | TagsSubscriber.getTagsFromStore | private function getTagsFromStore($alias, ReferenceStoreInterface $referenceStore): array
{
$tags = [];
foreach ($referenceStore->getAll() as $reference) {
$tag = $reference;
if (!Uuid::isValid($reference)) {
$tag = $alias . '-' . $reference;
}
$tags[] = $tag;
}
return $tags;
} | php | private function getTagsFromStore($alias, ReferenceStoreInterface $referenceStore): array
{
$tags = [];
foreach ($referenceStore->getAll() as $reference) {
$tag = $reference;
if (!Uuid::isValid($reference)) {
$tag = $alias . '-' . $reference;
}
$tags[] = $tag;
}
return $tags;
} | [
"private",
"function",
"getTagsFromStore",
"(",
"$",
"alias",
",",
"ReferenceStoreInterface",
"$",
"referenceStore",
")",
":",
"array",
"{",
"$",
"tags",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"referenceStore",
"->",
"getAll",
"(",
")",
"as",
"$",
"reference",
")",
"{",
"$",
"tag",
"=",
"$",
"reference",
";",
"if",
"(",
"!",
"Uuid",
"::",
"isValid",
"(",
"$",
"reference",
")",
")",
"{",
"$",
"tag",
"=",
"$",
"alias",
".",
"'-'",
".",
"$",
"reference",
";",
"}",
"$",
"tags",
"[",
"]",
"=",
"$",
"tag",
";",
"}",
"return",
"$",
"tags",
";",
"}"
] | Returns tags from given store. | [
"Returns",
"tags",
"from",
"given",
"store",
"."
] | 6766a36cc2f0c807c59202bf7540a08c4ef31192 | https://github.com/sulu/sulu/blob/6766a36cc2f0c807c59202bf7540a08c4ef31192/src/Sulu/Bundle/HttpCacheBundle/EventSubscriber/TagsSubscriber.php#L97-L110 | train |
sulu/sulu | src/Sulu/Bundle/HttpCacheBundle/EventSubscriber/TagsSubscriber.php | TagsSubscriber.getCurrentStructureUuid | private function getCurrentStructureUuid(): ?string
{
$request = $this->requestStack->getCurrentRequest();
if (!$request) {
return null;
}
$structure = $request->get('structure');
if (!$structure || !$structure instanceof StructureInterface) {
return null;
}
return $structure->getUuid();
} | php | private function getCurrentStructureUuid(): ?string
{
$request = $this->requestStack->getCurrentRequest();
if (!$request) {
return null;
}
$structure = $request->get('structure');
if (!$structure || !$structure instanceof StructureInterface) {
return null;
}
return $structure->getUuid();
} | [
"private",
"function",
"getCurrentStructureUuid",
"(",
")",
":",
"?",
"string",
"{",
"$",
"request",
"=",
"$",
"this",
"->",
"requestStack",
"->",
"getCurrentRequest",
"(",
")",
";",
"if",
"(",
"!",
"$",
"request",
")",
"{",
"return",
"null",
";",
"}",
"$",
"structure",
"=",
"$",
"request",
"->",
"get",
"(",
"'structure'",
")",
";",
"if",
"(",
"!",
"$",
"structure",
"||",
"!",
"$",
"structure",
"instanceof",
"StructureInterface",
")",
"{",
"return",
"null",
";",
"}",
"return",
"$",
"structure",
"->",
"getUuid",
"(",
")",
";",
"}"
] | Returns uuid of current structure. | [
"Returns",
"uuid",
"of",
"current",
"structure",
"."
] | 6766a36cc2f0c807c59202bf7540a08c4ef31192 | https://github.com/sulu/sulu/blob/6766a36cc2f0c807c59202bf7540a08c4ef31192/src/Sulu/Bundle/HttpCacheBundle/EventSubscriber/TagsSubscriber.php#L115-L128 | train |
sulu/sulu | src/Sulu/Component/CustomUrl/Manager/CustomUrlManager.php | CustomUrlManager.findRoute | protected function findRoute($uuid)
{
$document = $this->documentManager->find($uuid);
if (!$document instanceof RouteDocument) {
return;
}
return $document;
} | php | protected function findRoute($uuid)
{
$document = $this->documentManager->find($uuid);
if (!$document instanceof RouteDocument) {
return;
}
return $document;
} | [
"protected",
"function",
"findRoute",
"(",
"$",
"uuid",
")",
"{",
"$",
"document",
"=",
"$",
"this",
"->",
"documentManager",
"->",
"find",
"(",
"$",
"uuid",
")",
";",
"if",
"(",
"!",
"$",
"document",
"instanceof",
"RouteDocument",
")",
"{",
"return",
";",
"}",
"return",
"$",
"document",
";",
"}"
] | Read route of custom-url identified by uuid.
@param string $uuid
@return RouteDocument | [
"Read",
"route",
"of",
"custom",
"-",
"url",
"identified",
"by",
"uuid",
"."
] | 6766a36cc2f0c807c59202bf7540a08c4ef31192 | https://github.com/sulu/sulu/blob/6766a36cc2f0c807c59202bf7540a08c4ef31192/src/Sulu/Component/CustomUrl/Manager/CustomUrlManager.php#L241-L250 | train |
sulu/sulu | src/Sulu/Component/CustomUrl/Manager/CustomUrlManager.php | CustomUrlManager.bind | private function bind(CustomUrlDocument $document, $data)
{
$document->setTitle($data['title']);
unset($data['title']);
$metadata = $this->metadataFactory->getMetadataForAlias('custom_url');
$accessor = PropertyAccess::createPropertyAccessor();
foreach ($metadata->getFieldMappings() as $fieldName => $mapping) {
if (!array_key_exists($fieldName, $data)) {
continue;
}
$value = $data[$fieldName];
if (array_key_exists('type', $mapping) && 'reference' === $mapping['type']) {
$value = $this->documentManager->find($value, LOCALE, ['load_ghost_content' => true]);
}
$accessor->setValue($document, $fieldName, $value);
}
} | php | private function bind(CustomUrlDocument $document, $data)
{
$document->setTitle($data['title']);
unset($data['title']);
$metadata = $this->metadataFactory->getMetadataForAlias('custom_url');
$accessor = PropertyAccess::createPropertyAccessor();
foreach ($metadata->getFieldMappings() as $fieldName => $mapping) {
if (!array_key_exists($fieldName, $data)) {
continue;
}
$value = $data[$fieldName];
if (array_key_exists('type', $mapping) && 'reference' === $mapping['type']) {
$value = $this->documentManager->find($value, LOCALE, ['load_ghost_content' => true]);
}
$accessor->setValue($document, $fieldName, $value);
}
} | [
"private",
"function",
"bind",
"(",
"CustomUrlDocument",
"$",
"document",
",",
"$",
"data",
")",
"{",
"$",
"document",
"->",
"setTitle",
"(",
"$",
"data",
"[",
"'title'",
"]",
")",
";",
"unset",
"(",
"$",
"data",
"[",
"'title'",
"]",
")",
";",
"$",
"metadata",
"=",
"$",
"this",
"->",
"metadataFactory",
"->",
"getMetadataForAlias",
"(",
"'custom_url'",
")",
";",
"$",
"accessor",
"=",
"PropertyAccess",
"::",
"createPropertyAccessor",
"(",
")",
";",
"foreach",
"(",
"$",
"metadata",
"->",
"getFieldMappings",
"(",
")",
"as",
"$",
"fieldName",
"=>",
"$",
"mapping",
")",
"{",
"if",
"(",
"!",
"array_key_exists",
"(",
"$",
"fieldName",
",",
"$",
"data",
")",
")",
"{",
"continue",
";",
"}",
"$",
"value",
"=",
"$",
"data",
"[",
"$",
"fieldName",
"]",
";",
"if",
"(",
"array_key_exists",
"(",
"'type'",
",",
"$",
"mapping",
")",
"&&",
"'reference'",
"===",
"$",
"mapping",
"[",
"'type'",
"]",
")",
"{",
"$",
"value",
"=",
"$",
"this",
"->",
"documentManager",
"->",
"find",
"(",
"$",
"value",
",",
"LOCALE",
",",
"[",
"'load_ghost_content'",
"=>",
"true",
"]",
")",
";",
"}",
"$",
"accessor",
"->",
"setValue",
"(",
"$",
"document",
",",
"$",
"fieldName",
",",
"$",
"value",
")",
";",
"}",
"}"
] | Bind data array to given document.
TODO this logic have to be extracted in a proper way.
@param CustomUrlDocument $document
@param array $data | [
"Bind",
"data",
"array",
"to",
"given",
"document",
"."
] | 6766a36cc2f0c807c59202bf7540a08c4ef31192 | https://github.com/sulu/sulu/blob/6766a36cc2f0c807c59202bf7540a08c4ef31192/src/Sulu/Component/CustomUrl/Manager/CustomUrlManager.php#L324-L345 | train |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.