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
contao-community-alliance/dc-general
src/Data/DefaultDataProvider.php
DefaultDataProvider.enableDefaultUuidGenerator
public function enableDefaultUuidGenerator() { if ($this->idGenerator) { throw new DcGeneralRuntimeException('Error: already an id generator set on database provider.'); } $this->setIdGenerator(new DatabaseUuidIdGenerator($this->connection)); return $this; }
php
public function enableDefaultUuidGenerator() { if ($this->idGenerator) { throw new DcGeneralRuntimeException('Error: already an id generator set on database provider.'); } $this->setIdGenerator(new DatabaseUuidIdGenerator($this->connection)); return $this; }
[ "public", "function", "enableDefaultUuidGenerator", "(", ")", "{", "if", "(", "$", "this", "->", "idGenerator", ")", "{", "throw", "new", "DcGeneralRuntimeException", "(", "'Error: already an id generator set on database provider.'", ")", ";", "}", "$", "this", "->", "setIdGenerator", "(", "new", "DatabaseUuidIdGenerator", "(", "$", "this", "->", "connection", ")", ")", ";", "return", "$", "this", ";", "}" ]
Create an instance of the default database driven uuid generator. @return DefaultDataProvider @throws DcGeneralRuntimeException When already an id generator has been set on the instance.
[ "Create", "an", "instance", "of", "the", "default", "database", "driven", "uuid", "generator", "." ]
bf59fc2085cc848c564e40324dee14ef2897faa6
https://github.com/contao-community-alliance/dc-general/blob/bf59fc2085cc848c564e40324dee14ef2897faa6/src/Data/DefaultDataProvider.php#L165-L174
train
contao-community-alliance/dc-general
src/Data/DefaultDataProvider.php
DefaultDataProvider.createModelFromDatabaseResult
protected function createModelFromDatabaseResult(array $result) { $model = $this->getEmptyModel(); foreach ($result as $key => $value) { if ($key === $this->idProperty) { $model->setIdRaw($value); } $model->setPropertyRaw($key, StringUtil::deserialize($value)); } return $model; }
php
protected function createModelFromDatabaseResult(array $result) { $model = $this->getEmptyModel(); foreach ($result as $key => $value) { if ($key === $this->idProperty) { $model->setIdRaw($value); } $model->setPropertyRaw($key, StringUtil::deserialize($value)); } return $model; }
[ "protected", "function", "createModelFromDatabaseResult", "(", "array", "$", "result", ")", "{", "$", "model", "=", "$", "this", "->", "getEmptyModel", "(", ")", ";", "foreach", "(", "$", "result", "as", "$", "key", "=>", "$", "value", ")", "{", "if", "(", "$", "key", "===", "$", "this", "->", "idProperty", ")", "{", "$", "model", "->", "setIdRaw", "(", "$", "value", ")", ";", "}", "$", "model", "->", "setPropertyRaw", "(", "$", "key", ",", "StringUtil", "::", "deserialize", "(", "$", "value", ")", ")", ";", "}", "return", "$", "model", ";", "}" ]
Create a model from a database result. @param array $result The database result to create a model from. @return ModelInterface
[ "Create", "a", "model", "from", "a", "database", "result", "." ]
bf59fc2085cc848c564e40324dee14ef2897faa6
https://github.com/contao-community-alliance/dc-general/blob/bf59fc2085cc848c564e40324dee14ef2897faa6/src/Data/DefaultDataProvider.php#L316-L329
train
contao-community-alliance/dc-general
src/Data/DefaultDataProvider.php
DefaultDataProvider.prefixDataProviderProperties
private function prefixDataProviderProperties(ConfigInterface $config) { $internalConfig = clone $config; $this->sortingPrefixer($internalConfig); if (null !== ($filter = $internalConfig->getFilter())) { $this->filterPrefixer($filter); $internalConfig->setFilter($filter); } if (null !== ($fields = $internalConfig->getFields())) { $this->fieldPrefixer($fields); $internalConfig->setFields($fields); } return $internalConfig; }
php
private function prefixDataProviderProperties(ConfigInterface $config) { $internalConfig = clone $config; $this->sortingPrefixer($internalConfig); if (null !== ($filter = $internalConfig->getFilter())) { $this->filterPrefixer($filter); $internalConfig->setFilter($filter); } if (null !== ($fields = $internalConfig->getFields())) { $this->fieldPrefixer($fields); $internalConfig->setFields($fields); } return $internalConfig; }
[ "private", "function", "prefixDataProviderProperties", "(", "ConfigInterface", "$", "config", ")", "{", "$", "internalConfig", "=", "clone", "$", "config", ";", "$", "this", "->", "sortingPrefixer", "(", "$", "internalConfig", ")", ";", "if", "(", "null", "!==", "(", "$", "filter", "=", "$", "internalConfig", "->", "getFilter", "(", ")", ")", ")", "{", "$", "this", "->", "filterPrefixer", "(", "$", "filter", ")", ";", "$", "internalConfig", "->", "setFilter", "(", "$", "filter", ")", ";", "}", "if", "(", "null", "!==", "(", "$", "fields", "=", "$", "internalConfig", "->", "getFields", "(", ")", ")", ")", "{", "$", "this", "->", "fieldPrefixer", "(", "$", "fields", ")", ";", "$", "internalConfig", "->", "setFields", "(", "$", "fields", ")", ";", "}", "return", "$", "internalConfig", ";", "}" ]
Prefix the data provider properties. @param ConfigInterface $config The config. @return ConfigInterface
[ "Prefix", "the", "data", "provider", "properties", "." ]
bf59fc2085cc848c564e40324dee14ef2897faa6
https://github.com/contao-community-alliance/dc-general/blob/bf59fc2085cc848c564e40324dee14ef2897faa6/src/Data/DefaultDataProvider.php#L494-L510
train
contao-community-alliance/dc-general
src/Data/DefaultDataProvider.php
DefaultDataProvider.sortingPrefixer
private function sortingPrefixer(ConfigInterface $config) { $sorting = []; foreach ($config->getSorting() as $property => $value) { if (0 === \strpos($property, $this->source . '.')) { $sorting[$property] = $value; continue; } if (!$this->fieldExists($property)) { continue; } $sorting[$this->source . '.' . $property] = $value; } $config->setSorting($sorting); }
php
private function sortingPrefixer(ConfigInterface $config) { $sorting = []; foreach ($config->getSorting() as $property => $value) { if (0 === \strpos($property, $this->source . '.')) { $sorting[$property] = $value; continue; } if (!$this->fieldExists($property)) { continue; } $sorting[$this->source . '.' . $property] = $value; } $config->setSorting($sorting); }
[ "private", "function", "sortingPrefixer", "(", "ConfigInterface", "$", "config", ")", "{", "$", "sorting", "=", "[", "]", ";", "foreach", "(", "$", "config", "->", "getSorting", "(", ")", "as", "$", "property", "=>", "$", "value", ")", "{", "if", "(", "0", "===", "\\", "strpos", "(", "$", "property", ",", "$", "this", "->", "source", ".", "'.'", ")", ")", "{", "$", "sorting", "[", "$", "property", "]", "=", "$", "value", ";", "continue", ";", "}", "if", "(", "!", "$", "this", "->", "fieldExists", "(", "$", "property", ")", ")", "{", "continue", ";", "}", "$", "sorting", "[", "$", "this", "->", "source", ".", "'.'", ".", "$", "property", "]", "=", "$", "value", ";", "}", "$", "config", "->", "setSorting", "(", "$", "sorting", ")", ";", "}" ]
The config sorting prefixer. @param ConfigInterface $config The config. @return void
[ "The", "config", "sorting", "prefixer", "." ]
bf59fc2085cc848c564e40324dee14ef2897faa6
https://github.com/contao-community-alliance/dc-general/blob/bf59fc2085cc848c564e40324dee14ef2897faa6/src/Data/DefaultDataProvider.php#L519-L536
train
contao-community-alliance/dc-general
src/Data/DefaultDataProvider.php
DefaultDataProvider.filterPrefixer
private function filterPrefixer(array &$filter) { foreach ($filter as &$child) { if (\array_key_exists('property', $child) && (false === \strpos($child['property'], $this->source . '.')) && $this->fieldExists($child['property']) ) { $child['property'] = $this->source . '.' . $child['property']; } if (\array_key_exists('children', $child)) { $this->filterPrefixer($child['children']); } } }
php
private function filterPrefixer(array &$filter) { foreach ($filter as &$child) { if (\array_key_exists('property', $child) && (false === \strpos($child['property'], $this->source . '.')) && $this->fieldExists($child['property']) ) { $child['property'] = $this->source . '.' . $child['property']; } if (\array_key_exists('children', $child)) { $this->filterPrefixer($child['children']); } } }
[ "private", "function", "filterPrefixer", "(", "array", "&", "$", "filter", ")", "{", "foreach", "(", "$", "filter", "as", "&", "$", "child", ")", "{", "if", "(", "\\", "array_key_exists", "(", "'property'", ",", "$", "child", ")", "&&", "(", "false", "===", "\\", "strpos", "(", "$", "child", "[", "'property'", "]", ",", "$", "this", "->", "source", ".", "'.'", ")", ")", "&&", "$", "this", "->", "fieldExists", "(", "$", "child", "[", "'property'", "]", ")", ")", "{", "$", "child", "[", "'property'", "]", "=", "$", "this", "->", "source", ".", "'.'", ".", "$", "child", "[", "'property'", "]", ";", "}", "if", "(", "\\", "array_key_exists", "(", "'children'", ",", "$", "child", ")", ")", "{", "$", "this", "->", "filterPrefixer", "(", "$", "child", "[", "'children'", "]", ")", ";", "}", "}", "}" ]
The filter prefixer. @param array $filter The filter setting. @return void
[ "The", "filter", "prefixer", "." ]
bf59fc2085cc848c564e40324dee14ef2897faa6
https://github.com/contao-community-alliance/dc-general/blob/bf59fc2085cc848c564e40324dee14ef2897faa6/src/Data/DefaultDataProvider.php#L545-L559
train
contao-community-alliance/dc-general
src/Data/DefaultDataProvider.php
DefaultDataProvider.fieldPrefixer
private function fieldPrefixer(array &$fields) { foreach ($fields as $index => $property) { if (0 === \strpos($property, $this->source . '.') || !$this->fieldExists($property) ) { continue; } $fields[$index] = $this->source . '.' . $property; } }
php
private function fieldPrefixer(array &$fields) { foreach ($fields as $index => $property) { if (0 === \strpos($property, $this->source . '.') || !$this->fieldExists($property) ) { continue; } $fields[$index] = $this->source . '.' . $property; } }
[ "private", "function", "fieldPrefixer", "(", "array", "&", "$", "fields", ")", "{", "foreach", "(", "$", "fields", "as", "$", "index", "=>", "$", "property", ")", "{", "if", "(", "0", "===", "\\", "strpos", "(", "$", "property", ",", "$", "this", "->", "source", ".", "'.'", ")", "||", "!", "$", "this", "->", "fieldExists", "(", "$", "property", ")", ")", "{", "continue", ";", "}", "$", "fields", "[", "$", "index", "]", "=", "$", "this", "->", "source", ".", "'.'", ".", "$", "property", ";", "}", "}" ]
The field prefixer. @param array $fields The fields. @return void
[ "The", "field", "prefixer", "." ]
bf59fc2085cc848c564e40324dee14ef2897faa6
https://github.com/contao-community-alliance/dc-general/blob/bf59fc2085cc848c564e40324dee14ef2897faa6/src/Data/DefaultDataProvider.php#L568-L579
train
contao-community-alliance/dc-general
src/Data/DefaultDataProvider.php
DefaultDataProvider.convertModelToDataPropertyArray
private function convertModelToDataPropertyArray(ModelInterface $model, $timestamp = 0) { $data = []; foreach ($model as $key => $value) { if ($key === $this->idProperty) { continue; } if (\is_array($value)) { $data[$this->source . '.' . $key] = \serialize($value); } else { $data[$this->source . '.' . $key] = $value; } } if ($this->timeStampProperty) { $data[$this->source . '.' . $this->getTimeStampProperty()] = $timestamp ?: \time(); } return $data; }
php
private function convertModelToDataPropertyArray(ModelInterface $model, $timestamp = 0) { $data = []; foreach ($model as $key => $value) { if ($key === $this->idProperty) { continue; } if (\is_array($value)) { $data[$this->source . '.' . $key] = \serialize($value); } else { $data[$this->source . '.' . $key] = $value; } } if ($this->timeStampProperty) { $data[$this->source . '.' . $this->getTimeStampProperty()] = $timestamp ?: \time(); } return $data; }
[ "private", "function", "convertModelToDataPropertyArray", "(", "ModelInterface", "$", "model", ",", "$", "timestamp", "=", "0", ")", "{", "$", "data", "=", "[", "]", ";", "foreach", "(", "$", "model", "as", "$", "key", "=>", "$", "value", ")", "{", "if", "(", "$", "key", "===", "$", "this", "->", "idProperty", ")", "{", "continue", ";", "}", "if", "(", "\\", "is_array", "(", "$", "value", ")", ")", "{", "$", "data", "[", "$", "this", "->", "source", ".", "'.'", ".", "$", "key", "]", "=", "\\", "serialize", "(", "$", "value", ")", ";", "}", "else", "{", "$", "data", "[", "$", "this", "->", "source", ".", "'.'", ".", "$", "key", "]", "=", "$", "value", ";", "}", "}", "if", "(", "$", "this", "->", "timeStampProperty", ")", "{", "$", "data", "[", "$", "this", "->", "source", ".", "'.'", ".", "$", "this", "->", "getTimeStampProperty", "(", ")", "]", "=", "$", "timestamp", "?", ":", "\\", "time", "(", ")", ";", "}", "return", "$", "data", ";", "}" ]
Convert a model into a property array to be used in insert and update queries. @param ModelInterface $model The model to convert into an property array. @param int $timestamp Optional the timestamp. @return array @SuppressWarnings(PHPMD.Superglobals)
[ "Convert", "a", "model", "into", "a", "property", "array", "to", "be", "used", "in", "insert", "and", "update", "queries", "." ]
bf59fc2085cc848c564e40324dee14ef2897faa6
https://github.com/contao-community-alliance/dc-general/blob/bf59fc2085cc848c564e40324dee14ef2897faa6/src/Data/DefaultDataProvider.php#L591-L611
train
contao-community-alliance/dc-general
src/Data/DefaultDataProvider.php
DefaultDataProvider.insertModelIntoDatabase
private function insertModelIntoDatabase(ModelInterface $model, $timestamp = 0) { $data = $this->convertModelToDataPropertyArray($model, $timestamp); if ($this->getIdGenerator()) { $model->setId($this->getIdGenerator()->generate()); $data[$this->idProperty] = $model->getId(); } $this->connection->insert($this->source, $data); $insertId = $this->connection->lastInsertId($this->source); if (('' !== $insertId) && !isset($data[$this->idProperty])) { $model->setId($insertId); } }
php
private function insertModelIntoDatabase(ModelInterface $model, $timestamp = 0) { $data = $this->convertModelToDataPropertyArray($model, $timestamp); if ($this->getIdGenerator()) { $model->setId($this->getIdGenerator()->generate()); $data[$this->idProperty] = $model->getId(); } $this->connection->insert($this->source, $data); $insertId = $this->connection->lastInsertId($this->source); if (('' !== $insertId) && !isset($data[$this->idProperty])) { $model->setId($insertId); } }
[ "private", "function", "insertModelIntoDatabase", "(", "ModelInterface", "$", "model", ",", "$", "timestamp", "=", "0", ")", "{", "$", "data", "=", "$", "this", "->", "convertModelToDataPropertyArray", "(", "$", "model", ",", "$", "timestamp", ")", ";", "if", "(", "$", "this", "->", "getIdGenerator", "(", ")", ")", "{", "$", "model", "->", "setId", "(", "$", "this", "->", "getIdGenerator", "(", ")", "->", "generate", "(", ")", ")", ";", "$", "data", "[", "$", "this", "->", "idProperty", "]", "=", "$", "model", "->", "getId", "(", ")", ";", "}", "$", "this", "->", "connection", "->", "insert", "(", "$", "this", "->", "source", ",", "$", "data", ")", ";", "$", "insertId", "=", "$", "this", "->", "connection", "->", "lastInsertId", "(", "$", "this", "->", "source", ")", ";", "if", "(", "(", "''", "!==", "$", "insertId", ")", "&&", "!", "isset", "(", "$", "data", "[", "$", "this", "->", "idProperty", "]", ")", ")", "{", "$", "model", "->", "setId", "(", "$", "insertId", ")", ";", "}", "}" ]
Insert the model into the database. @param ModelInterface $model The model to insert into the database. @param int $timestamp Optional the timestamp. @return void
[ "Insert", "the", "model", "into", "the", "database", "." ]
bf59fc2085cc848c564e40324dee14ef2897faa6
https://github.com/contao-community-alliance/dc-general/blob/bf59fc2085cc848c564e40324dee14ef2897faa6/src/Data/DefaultDataProvider.php#L621-L636
train
contao-community-alliance/dc-general
src/Data/DefaultDataProvider.php
DefaultDataProvider.getVersions
public function getVersions($mixID, $onlyActive = false) { $queryBuilder = $this->connection->createQueryBuilder(); $queryBuilder->select(['tstamp', 'version', 'username', 'active']); $queryBuilder->from('tl_version'); $queryBuilder->andWhere($queryBuilder->expr()->eq('tl_version.formTable', ':formTable')); $queryBuilder->setParameter(':formTable', $this->source); $queryBuilder->andWhere($queryBuilder->expr()->eq('tl_version.pid', ':pid')); $queryBuilder->setParameter(':pid', $mixID); if ($onlyActive) { $queryBuilder->andWhere($queryBuilder->expr()->eq('tl_version.active', ':active')); $queryBuilder->setParameter(':active', '1'); } else { $queryBuilder->orderBy('tl_version.version', 'DESC'); } $statement = $queryBuilder->execute(); if (0 === $statement->rowCount()) { return null; } $versions = $statement->fetch(\PDO::FETCH_ASSOC); $collection = $this->getEmptyCollection(); foreach ($versions as $versionValue) { $model = $this->getEmptyModel(); $model->setId($mixID); foreach ($versionValue as $key => $value) { if ($key === $this->idProperty) { continue; } $model->setProperty($key, $value); } $collection->push($model); } return $collection; }
php
public function getVersions($mixID, $onlyActive = false) { $queryBuilder = $this->connection->createQueryBuilder(); $queryBuilder->select(['tstamp', 'version', 'username', 'active']); $queryBuilder->from('tl_version'); $queryBuilder->andWhere($queryBuilder->expr()->eq('tl_version.formTable', ':formTable')); $queryBuilder->setParameter(':formTable', $this->source); $queryBuilder->andWhere($queryBuilder->expr()->eq('tl_version.pid', ':pid')); $queryBuilder->setParameter(':pid', $mixID); if ($onlyActive) { $queryBuilder->andWhere($queryBuilder->expr()->eq('tl_version.active', ':active')); $queryBuilder->setParameter(':active', '1'); } else { $queryBuilder->orderBy('tl_version.version', 'DESC'); } $statement = $queryBuilder->execute(); if (0 === $statement->rowCount()) { return null; } $versions = $statement->fetch(\PDO::FETCH_ASSOC); $collection = $this->getEmptyCollection(); foreach ($versions as $versionValue) { $model = $this->getEmptyModel(); $model->setId($mixID); foreach ($versionValue as $key => $value) { if ($key === $this->idProperty) { continue; } $model->setProperty($key, $value); } $collection->push($model); } return $collection; }
[ "public", "function", "getVersions", "(", "$", "mixID", ",", "$", "onlyActive", "=", "false", ")", "{", "$", "queryBuilder", "=", "$", "this", "->", "connection", "->", "createQueryBuilder", "(", ")", ";", "$", "queryBuilder", "->", "select", "(", "[", "'tstamp'", ",", "'version'", ",", "'username'", ",", "'active'", "]", ")", ";", "$", "queryBuilder", "->", "from", "(", "'tl_version'", ")", ";", "$", "queryBuilder", "->", "andWhere", "(", "$", "queryBuilder", "->", "expr", "(", ")", "->", "eq", "(", "'tl_version.formTable'", ",", "':formTable'", ")", ")", ";", "$", "queryBuilder", "->", "setParameter", "(", "':formTable'", ",", "$", "this", "->", "source", ")", ";", "$", "queryBuilder", "->", "andWhere", "(", "$", "queryBuilder", "->", "expr", "(", ")", "->", "eq", "(", "'tl_version.pid'", ",", "':pid'", ")", ")", ";", "$", "queryBuilder", "->", "setParameter", "(", "':pid'", ",", "$", "mixID", ")", ";", "if", "(", "$", "onlyActive", ")", "{", "$", "queryBuilder", "->", "andWhere", "(", "$", "queryBuilder", "->", "expr", "(", ")", "->", "eq", "(", "'tl_version.active'", ",", "':active'", ")", ")", ";", "$", "queryBuilder", "->", "setParameter", "(", "':active'", ",", "'1'", ")", ";", "}", "else", "{", "$", "queryBuilder", "->", "orderBy", "(", "'tl_version.version'", ",", "'DESC'", ")", ";", "}", "$", "statement", "=", "$", "queryBuilder", "->", "execute", "(", ")", ";", "if", "(", "0", "===", "$", "statement", "->", "rowCount", "(", ")", ")", "{", "return", "null", ";", "}", "$", "versions", "=", "$", "statement", "->", "fetch", "(", "\\", "PDO", "::", "FETCH_ASSOC", ")", ";", "$", "collection", "=", "$", "this", "->", "getEmptyCollection", "(", ")", ";", "foreach", "(", "$", "versions", "as", "$", "versionValue", ")", "{", "$", "model", "=", "$", "this", "->", "getEmptyModel", "(", ")", ";", "$", "model", "->", "setId", "(", "$", "mixID", ")", ";", "foreach", "(", "$", "versionValue", "as", "$", "key", "=>", "$", "value", ")", "{", "if", "(", "$", "key", "===", "$", "this", "->", "idProperty", ")", "{", "continue", ";", "}", "$", "model", "->", "setProperty", "(", "$", "key", ",", "$", "value", ")", ";", "}", "$", "collection", "->", "push", "(", "$", "model", ")", ";", "}", "return", "$", "collection", ";", "}" ]
Return a list with all versions for the row with the given Id. @param mixed $mixID The ID of the row. @param boolean $onlyActive If true, only active versions will get returned, if false all version will get returned. @return CollectionInterface
[ "Return", "a", "list", "with", "all", "versions", "for", "the", "row", "with", "the", "given", "Id", "." ]
bf59fc2085cc848c564e40324dee14ef2897faa6
https://github.com/contao-community-alliance/dc-general/blob/bf59fc2085cc848c564e40324dee14ef2897faa6/src/Data/DefaultDataProvider.php#L736-L778
train
contao-community-alliance/dc-general
src/Data/DefaultDataProvider.php
DefaultDataProvider.saveVersion
public function saveVersion(ModelInterface $model, $username) { $queryBuilder = $this->connection->createQueryBuilder(); $queryBuilder->select('COUNT(*) AS count'); $queryBuilder->from('tl_version'); $queryBuilder->andWhere($queryBuilder->expr()->eq('tl_version.pid', ':pid')); $queryBuilder->setParameter(':pid', $model->getId()); $queryBuilder->andWhere($queryBuilder->expr()->eq('tl_version.fromTable', ':fromTable')); $queryBuilder->setParameter(':fromTable', $this->source); $statement = $queryBuilder->execute(); $count = $statement->fetch(\PDO::FETCH_COLUMN); $mixNewVersion = ((int) $count + 1); $mixData = $model->getPropertiesAsArray(); $mixData[$this->idProperty] = $model->getId(); $insert = [ 'tl_version.pid' => $model->getId(), 'tl_version.tstamp' => \time(), 'tl_version.version' => $mixNewVersion, 'tl_version.fromTable' => $this->source, 'tl_version.username' => $username, 'tl_version.data' => \serialize($mixData) ]; $this->connection->insert('tl_version', $insert); $this->setVersionActive($model->getId(), $mixNewVersion); }
php
public function saveVersion(ModelInterface $model, $username) { $queryBuilder = $this->connection->createQueryBuilder(); $queryBuilder->select('COUNT(*) AS count'); $queryBuilder->from('tl_version'); $queryBuilder->andWhere($queryBuilder->expr()->eq('tl_version.pid', ':pid')); $queryBuilder->setParameter(':pid', $model->getId()); $queryBuilder->andWhere($queryBuilder->expr()->eq('tl_version.fromTable', ':fromTable')); $queryBuilder->setParameter(':fromTable', $this->source); $statement = $queryBuilder->execute(); $count = $statement->fetch(\PDO::FETCH_COLUMN); $mixNewVersion = ((int) $count + 1); $mixData = $model->getPropertiesAsArray(); $mixData[$this->idProperty] = $model->getId(); $insert = [ 'tl_version.pid' => $model->getId(), 'tl_version.tstamp' => \time(), 'tl_version.version' => $mixNewVersion, 'tl_version.fromTable' => $this->source, 'tl_version.username' => $username, 'tl_version.data' => \serialize($mixData) ]; $this->connection->insert('tl_version', $insert); $this->setVersionActive($model->getId(), $mixNewVersion); }
[ "public", "function", "saveVersion", "(", "ModelInterface", "$", "model", ",", "$", "username", ")", "{", "$", "queryBuilder", "=", "$", "this", "->", "connection", "->", "createQueryBuilder", "(", ")", ";", "$", "queryBuilder", "->", "select", "(", "'COUNT(*) AS count'", ")", ";", "$", "queryBuilder", "->", "from", "(", "'tl_version'", ")", ";", "$", "queryBuilder", "->", "andWhere", "(", "$", "queryBuilder", "->", "expr", "(", ")", "->", "eq", "(", "'tl_version.pid'", ",", "':pid'", ")", ")", ";", "$", "queryBuilder", "->", "setParameter", "(", "':pid'", ",", "$", "model", "->", "getId", "(", ")", ")", ";", "$", "queryBuilder", "->", "andWhere", "(", "$", "queryBuilder", "->", "expr", "(", ")", "->", "eq", "(", "'tl_version.fromTable'", ",", "':fromTable'", ")", ")", ";", "$", "queryBuilder", "->", "setParameter", "(", "':fromTable'", ",", "$", "this", "->", "source", ")", ";", "$", "statement", "=", "$", "queryBuilder", "->", "execute", "(", ")", ";", "$", "count", "=", "$", "statement", "->", "fetch", "(", "\\", "PDO", "::", "FETCH_COLUMN", ")", ";", "$", "mixNewVersion", "=", "(", "(", "int", ")", "$", "count", "+", "1", ")", ";", "$", "mixData", "=", "$", "model", "->", "getPropertiesAsArray", "(", ")", ";", "$", "mixData", "[", "$", "this", "->", "idProperty", "]", "=", "$", "model", "->", "getId", "(", ")", ";", "$", "insert", "=", "[", "'tl_version.pid'", "=>", "$", "model", "->", "getId", "(", ")", ",", "'tl_version.tstamp'", "=>", "\\", "time", "(", ")", ",", "'tl_version.version'", "=>", "$", "mixNewVersion", ",", "'tl_version.fromTable'", "=>", "$", "this", "->", "source", ",", "'tl_version.username'", "=>", "$", "username", ",", "'tl_version.data'", "=>", "\\", "serialize", "(", "$", "mixData", ")", "]", ";", "$", "this", "->", "connection", "->", "insert", "(", "'tl_version'", ",", "$", "insert", ")", ";", "$", "this", "->", "setVersionActive", "(", "$", "model", "->", "getId", "(", ")", ",", "$", "mixNewVersion", ")", ";", "}" ]
Save a new version of a row. @param ModelInterface $model The model for which a new version shall be created. @param string $username The username to attach to the version as creator. @return void
[ "Save", "a", "new", "version", "of", "a", "row", "." ]
bf59fc2085cc848c564e40324dee14ef2897faa6
https://github.com/contao-community-alliance/dc-general/blob/bf59fc2085cc848c564e40324dee14ef2897faa6/src/Data/DefaultDataProvider.php#L788-L818
train
contao-community-alliance/dc-general
src/Data/DefaultDataProvider.php
DefaultDataProvider.setVersionActive
public function setVersionActive($mixID, $mixVersion) { $updateValues = ['tl_version.pid' => $mixID, 'tl_version.fromTable' => $this->source]; // Set version inactive. $this->connection->update('tl_version', ['tl_version.active' => ''], $updateValues); // Set version active. $updateValues['version'] = $mixVersion; $this->connection->update('tl_version', ['tl_version.active' => 1], $updateValues); }
php
public function setVersionActive($mixID, $mixVersion) { $updateValues = ['tl_version.pid' => $mixID, 'tl_version.fromTable' => $this->source]; // Set version inactive. $this->connection->update('tl_version', ['tl_version.active' => ''], $updateValues); // Set version active. $updateValues['version'] = $mixVersion; $this->connection->update('tl_version', ['tl_version.active' => 1], $updateValues); }
[ "public", "function", "setVersionActive", "(", "$", "mixID", ",", "$", "mixVersion", ")", "{", "$", "updateValues", "=", "[", "'tl_version.pid'", "=>", "$", "mixID", ",", "'tl_version.fromTable'", "=>", "$", "this", "->", "source", "]", ";", "// Set version inactive.", "$", "this", "->", "connection", "->", "update", "(", "'tl_version'", ",", "[", "'tl_version.active'", "=>", "''", "]", ",", "$", "updateValues", ")", ";", "// Set version active.", "$", "updateValues", "[", "'version'", "]", "=", "$", "mixVersion", ";", "$", "this", "->", "connection", "->", "update", "(", "'tl_version'", ",", "[", "'tl_version.active'", "=>", "1", "]", ",", "$", "updateValues", ")", ";", "}" ]
Set a version as active. @param mixed $mixID The ID of the row. @param mixed $mixVersion The version number to set active. @return void
[ "Set", "a", "version", "as", "active", "." ]
bf59fc2085cc848c564e40324dee14ef2897faa6
https://github.com/contao-community-alliance/dc-general/blob/bf59fc2085cc848c564e40324dee14ef2897faa6/src/Data/DefaultDataProvider.php#L828-L838
train
contao-community-alliance/dc-general
src/Data/DefaultDataProvider.php
DefaultDataProvider.getActiveVersion
public function getActiveVersion($mixID) { $queryBuilder = $this->connection->createQueryBuilder(); $queryBuilder->select(['select']); $queryBuilder->from('tl_version'); $queryBuilder->andWhere($queryBuilder->expr()->eq('tl_version.pid', ':pid')); $queryBuilder->setParameter(':pid', $mixID); $queryBuilder->andWhere($queryBuilder->expr()->eq('tl_version.fromTable', ':fromTable')); $queryBuilder->setParameter(':fromTable', $this->source); $queryBuilder->andWhere($queryBuilder->expr()->eq('tl_version.active', ':active')); $queryBuilder->setParameter(':active', 1); $statement = $queryBuilder->execute(); if (0 === $statement->rowCount()) { return null; } return $statement->fetch(\PDO::FETCH_OBJ)->version; }
php
public function getActiveVersion($mixID) { $queryBuilder = $this->connection->createQueryBuilder(); $queryBuilder->select(['select']); $queryBuilder->from('tl_version'); $queryBuilder->andWhere($queryBuilder->expr()->eq('tl_version.pid', ':pid')); $queryBuilder->setParameter(':pid', $mixID); $queryBuilder->andWhere($queryBuilder->expr()->eq('tl_version.fromTable', ':fromTable')); $queryBuilder->setParameter(':fromTable', $this->source); $queryBuilder->andWhere($queryBuilder->expr()->eq('tl_version.active', ':active')); $queryBuilder->setParameter(':active', 1); $statement = $queryBuilder->execute(); if (0 === $statement->rowCount()) { return null; } return $statement->fetch(\PDO::FETCH_OBJ)->version; }
[ "public", "function", "getActiveVersion", "(", "$", "mixID", ")", "{", "$", "queryBuilder", "=", "$", "this", "->", "connection", "->", "createQueryBuilder", "(", ")", ";", "$", "queryBuilder", "->", "select", "(", "[", "'select'", "]", ")", ";", "$", "queryBuilder", "->", "from", "(", "'tl_version'", ")", ";", "$", "queryBuilder", "->", "andWhere", "(", "$", "queryBuilder", "->", "expr", "(", ")", "->", "eq", "(", "'tl_version.pid'", ",", "':pid'", ")", ")", ";", "$", "queryBuilder", "->", "setParameter", "(", "':pid'", ",", "$", "mixID", ")", ";", "$", "queryBuilder", "->", "andWhere", "(", "$", "queryBuilder", "->", "expr", "(", ")", "->", "eq", "(", "'tl_version.fromTable'", ",", "':fromTable'", ")", ")", ";", "$", "queryBuilder", "->", "setParameter", "(", "':fromTable'", ",", "$", "this", "->", "source", ")", ";", "$", "queryBuilder", "->", "andWhere", "(", "$", "queryBuilder", "->", "expr", "(", ")", "->", "eq", "(", "'tl_version.active'", ",", "':active'", ")", ")", ";", "$", "queryBuilder", "->", "setParameter", "(", "':active'", ",", "1", ")", ";", "$", "statement", "=", "$", "queryBuilder", "->", "execute", "(", ")", ";", "if", "(", "0", "===", "$", "statement", "->", "rowCount", "(", ")", ")", "{", "return", "null", ";", "}", "return", "$", "statement", "->", "fetch", "(", "\\", "PDO", "::", "FETCH_OBJ", ")", "->", "version", ";", "}" ]
Retrieve the current active version for a row. @param mixed $mixID The ID of the row. @return mixed The current version number of the requested row.
[ "Retrieve", "the", "current", "active", "version", "for", "a", "row", "." ]
bf59fc2085cc848c564e40324dee14ef2897faa6
https://github.com/contao-community-alliance/dc-general/blob/bf59fc2085cc848c564e40324dee14ef2897faa6/src/Data/DefaultDataProvider.php#L847-L865
train
contao-community-alliance/dc-general
src/Data/DefaultDataProvider.php
DefaultDataProvider.sameModels
public function sameModels($firstModel, $secondModel) { foreach ($firstModel as $key => $value) { if ($key === $this->idProperty) { continue; } if (\is_array($value)) { if (!\is_array($secondModel->getProperty($key))) { return false; } if (\serialize($value) !== \serialize($secondModel->getProperty($key))) { return false; } } elseif ($value !== $secondModel->getProperty($key)) { return false; } } return true; }
php
public function sameModels($firstModel, $secondModel) { foreach ($firstModel as $key => $value) { if ($key === $this->idProperty) { continue; } if (\is_array($value)) { if (!\is_array($secondModel->getProperty($key))) { return false; } if (\serialize($value) !== \serialize($secondModel->getProperty($key))) { return false; } } elseif ($value !== $secondModel->getProperty($key)) { return false; } } return true; }
[ "public", "function", "sameModels", "(", "$", "firstModel", ",", "$", "secondModel", ")", "{", "foreach", "(", "$", "firstModel", "as", "$", "key", "=>", "$", "value", ")", "{", "if", "(", "$", "key", "===", "$", "this", "->", "idProperty", ")", "{", "continue", ";", "}", "if", "(", "\\", "is_array", "(", "$", "value", ")", ")", "{", "if", "(", "!", "\\", "is_array", "(", "$", "secondModel", "->", "getProperty", "(", "$", "key", ")", ")", ")", "{", "return", "false", ";", "}", "if", "(", "\\", "serialize", "(", "$", "value", ")", "!==", "\\", "serialize", "(", "$", "secondModel", "->", "getProperty", "(", "$", "key", ")", ")", ")", "{", "return", "false", ";", "}", "}", "elseif", "(", "$", "value", "!==", "$", "secondModel", "->", "getProperty", "(", "$", "key", ")", ")", "{", "return", "false", ";", "}", "}", "return", "true", ";", "}" ]
Check if two models have the same values in all properties. @param ModelInterface $firstModel The first model to compare. @param ModelInterface $secondModel The second model to compare. @return boolean True - If both models are same, false if not.
[ "Check", "if", "two", "models", "have", "the", "same", "values", "in", "all", "properties", "." ]
bf59fc2085cc848c564e40324dee14ef2897faa6
https://github.com/contao-community-alliance/dc-general/blob/bf59fc2085cc848c564e40324dee14ef2897faa6/src/Data/DefaultDataProvider.php#L875-L896
train
contao-community-alliance/dc-general
src/Data/DefaultDataProvider.php
DefaultDataProvider.insertUndo
protected function insertUndo($sourceSQL, $saveSQL, $table) { // Load row. $statement = $this->connection->query($saveSQL); // Check if we have a result. if (0 === $statement->rowCount()) { return; } $result = $statement->fetch(\PDO::FETCH_ASSOC); // Save information in array. $parameters = []; foreach ($result as $value) { $parameters[$table][] = $value; } $prefix = '<span style="color:#b3b3b3; padding-right:3px;">(DC General)</span>'; $user = BackendUser::getInstance(); // Write into undo. $this->connection->insert( 'tl_undo', [ 'tl_undo.pid' => $user->id, 'tl_undo.tstamp' => \time(), 'tl_undo.fromTable' => $table, 'tl_undo.query' => $prefix . $sourceSQL, 'tl_undo.affectedRows' => \count($parameters[$table]), 'tl_undo.data' => \serialize($parameters) ] ); }
php
protected function insertUndo($sourceSQL, $saveSQL, $table) { // Load row. $statement = $this->connection->query($saveSQL); // Check if we have a result. if (0 === $statement->rowCount()) { return; } $result = $statement->fetch(\PDO::FETCH_ASSOC); // Save information in array. $parameters = []; foreach ($result as $value) { $parameters[$table][] = $value; } $prefix = '<span style="color:#b3b3b3; padding-right:3px;">(DC General)</span>'; $user = BackendUser::getInstance(); // Write into undo. $this->connection->insert( 'tl_undo', [ 'tl_undo.pid' => $user->id, 'tl_undo.tstamp' => \time(), 'tl_undo.fromTable' => $table, 'tl_undo.query' => $prefix . $sourceSQL, 'tl_undo.affectedRows' => \count($parameters[$table]), 'tl_undo.data' => \serialize($parameters) ] ); }
[ "protected", "function", "insertUndo", "(", "$", "sourceSQL", ",", "$", "saveSQL", ",", "$", "table", ")", "{", "// Load row.", "$", "statement", "=", "$", "this", "->", "connection", "->", "query", "(", "$", "saveSQL", ")", ";", "// Check if we have a result.", "if", "(", "0", "===", "$", "statement", "->", "rowCount", "(", ")", ")", "{", "return", ";", "}", "$", "result", "=", "$", "statement", "->", "fetch", "(", "\\", "PDO", "::", "FETCH_ASSOC", ")", ";", "// Save information in array.", "$", "parameters", "=", "[", "]", ";", "foreach", "(", "$", "result", "as", "$", "value", ")", "{", "$", "parameters", "[", "$", "table", "]", "[", "]", "=", "$", "value", ";", "}", "$", "prefix", "=", "'<span style=\"color:#b3b3b3; padding-right:3px;\">(DC General)</span>'", ";", "$", "user", "=", "BackendUser", "::", "getInstance", "(", ")", ";", "// Write into undo.", "$", "this", "->", "connection", "->", "insert", "(", "'tl_undo'", ",", "[", "'tl_undo.pid'", "=>", "$", "user", "->", "id", ",", "'tl_undo.tstamp'", "=>", "\\", "time", "(", ")", ",", "'tl_undo.fromTable'", "=>", "$", "table", ",", "'tl_undo.query'", "=>", "$", "prefix", ".", "$", "sourceSQL", ",", "'tl_undo.affectedRows'", "=>", "\\", "count", "(", "$", "parameters", "[", "$", "table", "]", ")", ",", "'tl_undo.data'", "=>", "\\", "serialize", "(", "$", "parameters", ")", "]", ")", ";", "}" ]
Store an undo entry in the table tl_undo. Currently this only supports delete queries. @param string $sourceSQL The SQL used to perform the action to be undone. @param string $saveSQL The SQL query to retrieve the current entries. @param string $table The table to be affected by the action. @return void
[ "Store", "an", "undo", "entry", "in", "the", "table", "tl_undo", "." ]
bf59fc2085cc848c564e40324dee14ef2897faa6
https://github.com/contao-community-alliance/dc-general/blob/bf59fc2085cc848c564e40324dee14ef2897faa6/src/Data/DefaultDataProvider.php#L909-L942
train
contao-community-alliance/dc-general
src/Data/DefaultDataProvider.php
DefaultDataProvider.fallbackFromDatabaseToConnection
private function fallbackFromDatabaseToConnection(array &$config) { if (isset($config['database'])) { // @codingStandardsIgnoreStart @\trigger_error( 'Config key database is deprecated use instead connection. Fallback will be dropped.', E_USER_DEPRECATED ); // @codingStandardsIgnoreEnd if (!isset($config['connection'])) { $config['connection'] = $config['database']; } unset($config['database']); } if (isset($config['connection']) && $config['connection'] instanceof Database) { // @codingStandardsIgnoreStart @\trigger_error( '"' . __METHOD__ . '" now accepts doctrine instances - ' . 'passing Contao database instances is deprecated.', E_USER_DEPRECATED ); // @codingStandardsIgnoreEnd $reflection = new \ReflectionProperty(Database::class, 'resConnection'); $reflection->setAccessible(true); $config['connection'] = $reflection->getValue($config['connection']); } }
php
private function fallbackFromDatabaseToConnection(array &$config) { if (isset($config['database'])) { // @codingStandardsIgnoreStart @\trigger_error( 'Config key database is deprecated use instead connection. Fallback will be dropped.', E_USER_DEPRECATED ); // @codingStandardsIgnoreEnd if (!isset($config['connection'])) { $config['connection'] = $config['database']; } unset($config['database']); } if (isset($config['connection']) && $config['connection'] instanceof Database) { // @codingStandardsIgnoreStart @\trigger_error( '"' . __METHOD__ . '" now accepts doctrine instances - ' . 'passing Contao database instances is deprecated.', E_USER_DEPRECATED ); // @codingStandardsIgnoreEnd $reflection = new \ReflectionProperty(Database::class, 'resConnection'); $reflection->setAccessible(true); $config['connection'] = $reflection->getValue($config['connection']); } }
[ "private", "function", "fallbackFromDatabaseToConnection", "(", "array", "&", "$", "config", ")", "{", "if", "(", "isset", "(", "$", "config", "[", "'database'", "]", ")", ")", "{", "// @codingStandardsIgnoreStart", "@", "\\", "trigger_error", "(", "'Config key database is deprecated use instead connection. Fallback will be dropped.'", ",", "E_USER_DEPRECATED", ")", ";", "// @codingStandardsIgnoreEnd", "if", "(", "!", "isset", "(", "$", "config", "[", "'connection'", "]", ")", ")", "{", "$", "config", "[", "'connection'", "]", "=", "$", "config", "[", "'database'", "]", ";", "}", "unset", "(", "$", "config", "[", "'database'", "]", ")", ";", "}", "if", "(", "isset", "(", "$", "config", "[", "'connection'", "]", ")", "&&", "$", "config", "[", "'connection'", "]", "instanceof", "Database", ")", "{", "// @codingStandardsIgnoreStart", "@", "\\", "trigger_error", "(", "'\"'", ".", "__METHOD__", ".", "'\" now accepts doctrine instances - '", ".", "'passing Contao database instances is deprecated.'", ",", "E_USER_DEPRECATED", ")", ";", "// @codingStandardsIgnoreEnd", "$", "reflection", "=", "new", "\\", "ReflectionProperty", "(", "Database", "::", "class", ",", "'resConnection'", ")", ";", "$", "reflection", "->", "setAccessible", "(", "true", ")", ";", "$", "config", "[", "'connection'", "]", "=", "$", "reflection", "->", "getValue", "(", "$", "config", "[", "'connection'", "]", ")", ";", "}", "}" ]
This is a fallback for get the connection instead of the old database. @param array $config The configuration. @return void @deprecated This method is deprecated sinde 2.1 and where removed in 3.0. The old database never used in future.
[ "This", "is", "a", "fallback", "for", "get", "the", "connection", "instead", "of", "the", "old", "database", "." ]
bf59fc2085cc848c564e40324dee14ef2897faa6
https://github.com/contao-community-alliance/dc-general/blob/bf59fc2085cc848c564e40324dee14ef2897faa6/src/Data/DefaultDataProvider.php#L963-L993
train
contao-community-alliance/dc-general
src/BaseConfigRegistry.php
BaseConfigRegistry.addParentFilter
private function addParentFilter($idParent, $config) { $environment = $this->getEnvironment(); $definition = $environment->getDataDefinition(); $providerName = $definition->getBasicDefinition()->getDataProvider(); $parentProviderName = $idParent->getDataProviderName(); $parentProvider = $environment->getDataProvider($parentProviderName); if ($definition->getBasicDefinition()->getParentDataProvider() !== $parentProviderName) { throw new DcGeneralRuntimeException( 'Unexpected parent provider ' . $parentProviderName . ' (expected ' . $definition->getBasicDefinition()->getParentDataProvider() . ')' ); } if ($parentProvider) { $parent = $parentProvider->fetch($parentProvider->getEmptyConfig()->setId($idParent->getId())); if (!$parent) { throw new DcGeneralRuntimeException( 'Parent item ' . $idParent->getSerialized() . ' not found in ' . $parentProviderName ); } $condition = $definition->getModelRelationshipDefinition()->getChildCondition( $parentProviderName, $providerName ); if ($condition) { $baseFilter = $config->getFilter(); $filter = $condition->getFilter($parent); if ($baseFilter) { $filter = \array_merge($baseFilter, $filter); } $config->setFilter([['operation' => 'AND', 'children' => $filter]]); } } return $config; }
php
private function addParentFilter($idParent, $config) { $environment = $this->getEnvironment(); $definition = $environment->getDataDefinition(); $providerName = $definition->getBasicDefinition()->getDataProvider(); $parentProviderName = $idParent->getDataProviderName(); $parentProvider = $environment->getDataProvider($parentProviderName); if ($definition->getBasicDefinition()->getParentDataProvider() !== $parentProviderName) { throw new DcGeneralRuntimeException( 'Unexpected parent provider ' . $parentProviderName . ' (expected ' . $definition->getBasicDefinition()->getParentDataProvider() . ')' ); } if ($parentProvider) { $parent = $parentProvider->fetch($parentProvider->getEmptyConfig()->setId($idParent->getId())); if (!$parent) { throw new DcGeneralRuntimeException( 'Parent item ' . $idParent->getSerialized() . ' not found in ' . $parentProviderName ); } $condition = $definition->getModelRelationshipDefinition()->getChildCondition( $parentProviderName, $providerName ); if ($condition) { $baseFilter = $config->getFilter(); $filter = $condition->getFilter($parent); if ($baseFilter) { $filter = \array_merge($baseFilter, $filter); } $config->setFilter([['operation' => 'AND', 'children' => $filter]]); } } return $config; }
[ "private", "function", "addParentFilter", "(", "$", "idParent", ",", "$", "config", ")", "{", "$", "environment", "=", "$", "this", "->", "getEnvironment", "(", ")", ";", "$", "definition", "=", "$", "environment", "->", "getDataDefinition", "(", ")", ";", "$", "providerName", "=", "$", "definition", "->", "getBasicDefinition", "(", ")", "->", "getDataProvider", "(", ")", ";", "$", "parentProviderName", "=", "$", "idParent", "->", "getDataProviderName", "(", ")", ";", "$", "parentProvider", "=", "$", "environment", "->", "getDataProvider", "(", "$", "parentProviderName", ")", ";", "if", "(", "$", "definition", "->", "getBasicDefinition", "(", ")", "->", "getParentDataProvider", "(", ")", "!==", "$", "parentProviderName", ")", "{", "throw", "new", "DcGeneralRuntimeException", "(", "'Unexpected parent provider '", ".", "$", "parentProviderName", ".", "' (expected '", ".", "$", "definition", "->", "getBasicDefinition", "(", ")", "->", "getParentDataProvider", "(", ")", ".", "')'", ")", ";", "}", "if", "(", "$", "parentProvider", ")", "{", "$", "parent", "=", "$", "parentProvider", "->", "fetch", "(", "$", "parentProvider", "->", "getEmptyConfig", "(", ")", "->", "setId", "(", "$", "idParent", "->", "getId", "(", ")", ")", ")", ";", "if", "(", "!", "$", "parent", ")", "{", "throw", "new", "DcGeneralRuntimeException", "(", "'Parent item '", ".", "$", "idParent", "->", "getSerialized", "(", ")", ".", "' not found in '", ".", "$", "parentProviderName", ")", ";", "}", "$", "condition", "=", "$", "definition", "->", "getModelRelationshipDefinition", "(", ")", "->", "getChildCondition", "(", "$", "parentProviderName", ",", "$", "providerName", ")", ";", "if", "(", "$", "condition", ")", "{", "$", "baseFilter", "=", "$", "config", "->", "getFilter", "(", ")", ";", "$", "filter", "=", "$", "condition", "->", "getFilter", "(", "$", "parent", ")", ";", "if", "(", "$", "baseFilter", ")", "{", "$", "filter", "=", "\\", "array_merge", "(", "$", "baseFilter", ",", "$", "filter", ")", ";", "}", "$", "config", "->", "setFilter", "(", "[", "[", "'operation'", "=>", "'AND'", ",", "'children'", "=>", "$", "filter", "]", "]", ")", ";", "}", "}", "return", "$", "config", ";", "}" ]
Add the filter for the item with the given id from the parent data provider to the given config. @param ModelIdInterface $idParent The id of the parent item. @param ConfigInterface $config The config to add the filter to. @return ConfigInterface @throws DcGeneralRuntimeException When the parent item is not found.
[ "Add", "the", "filter", "for", "the", "item", "with", "the", "given", "id", "from", "the", "parent", "data", "provider", "to", "the", "given", "config", "." ]
bf59fc2085cc848c564e40324dee14ef2897faa6
https://github.com/contao-community-alliance/dc-general/blob/bf59fc2085cc848c564e40324dee14ef2897faa6/src/BaseConfigRegistry.php#L81-L122
train
contao-community-alliance/dc-general
src/Controller/Ajax.php
Ajax.getGet
protected function getGet($key, $decodeEntities = false) { return $this->getEnvironment()->getInputProvider()->getParameter($key, $decodeEntities); }
php
protected function getGet($key, $decodeEntities = false) { return $this->getEnvironment()->getInputProvider()->getParameter($key, $decodeEntities); }
[ "protected", "function", "getGet", "(", "$", "key", ",", "$", "decodeEntities", "=", "false", ")", "{", "return", "$", "this", "->", "getEnvironment", "(", ")", "->", "getInputProvider", "(", ")", "->", "getParameter", "(", "$", "key", ",", "$", "decodeEntities", ")", ";", "}" ]
Compat wrapper for contao 2.X and 3.X - delegates to the relevant input handler. @param string $key The key to retrieve. @param bool $decodeEntities Decode the entities. @return mixed
[ "Compat", "wrapper", "for", "contao", "2", ".", "X", "and", "3", ".", "X", "-", "delegates", "to", "the", "relevant", "input", "handler", "." ]
bf59fc2085cc848c564e40324dee14ef2897faa6
https://github.com/contao-community-alliance/dc-general/blob/bf59fc2085cc848c564e40324dee14ef2897faa6/src/Controller/Ajax.php#L84-L87
train
contao-community-alliance/dc-general
src/Controller/Ajax.php
Ajax.getPost
protected function getPost($key, $decodeEntities = false) { return $this->getEnvironment()->getInputProvider()->getValue($key, $decodeEntities); }
php
protected function getPost($key, $decodeEntities = false) { return $this->getEnvironment()->getInputProvider()->getValue($key, $decodeEntities); }
[ "protected", "function", "getPost", "(", "$", "key", ",", "$", "decodeEntities", "=", "false", ")", "{", "return", "$", "this", "->", "getEnvironment", "(", ")", "->", "getInputProvider", "(", ")", "->", "getValue", "(", "$", "key", ",", "$", "decodeEntities", ")", ";", "}" ]
Compatibility wrapper for contao 2.X and 3.X - delegates to the relevant input handler. @param string $key The key to retrieve. @param bool $decodeEntities Decode the entities. @return mixed
[ "Compatibility", "wrapper", "for", "contao", "2", ".", "X", "and", "3", ".", "X", "-", "delegates", "to", "the", "relevant", "input", "handler", "." ]
bf59fc2085cc848c564e40324dee14ef2897faa6
https://github.com/contao-community-alliance/dc-general/blob/bf59fc2085cc848c564e40324dee14ef2897faa6/src/Controller/Ajax.php#L97-L100
train
contao-community-alliance/dc-general
src/Controller/Ajax.php
Ajax.loadStructure
protected function loadStructure() { // Method ajaxTreeView is in TreeView.php - watch out! $response = new Response( $this->getDataContainer()->ajaxTreeView($this->getAjaxId(), (int) $this->getPost('level')) ); throw new ResponseException($response); }
php
protected function loadStructure() { // Method ajaxTreeView is in TreeView.php - watch out! $response = new Response( $this->getDataContainer()->ajaxTreeView($this->getAjaxId(), (int) $this->getPost('level')) ); throw new ResponseException($response); }
[ "protected", "function", "loadStructure", "(", ")", "{", "// Method ajaxTreeView is in TreeView.php - watch out!", "$", "response", "=", "new", "Response", "(", "$", "this", "->", "getDataContainer", "(", ")", "->", "ajaxTreeView", "(", "$", "this", "->", "getAjaxId", "(", ")", ",", "(", "int", ")", "$", "this", "->", "getPost", "(", "'level'", ")", ")", ")", ";", "throw", "new", "ResponseException", "(", "$", "response", ")", ";", "}" ]
Load a tree structure. This method exits the script! @return void @throws ResponseException Throws a response exception.
[ "Load", "a", "tree", "structure", "." ]
bf59fc2085cc848c564e40324dee14ef2897faa6
https://github.com/contao-community-alliance/dc-general/blob/bf59fc2085cc848c564e40324dee14ef2897faa6/src/Controller/Ajax.php#L123-L131
train
contao-community-alliance/dc-general
src/Controller/Ajax.php
Ajax.loadFileManager
protected function loadFileManager() { // Method ajaxTreeView is in TreeView.php - watch out! $response = new Response( $this->getDataContainer()->ajaxTreeView($this->getPost('folder', true), (int) $this->getPost('level')) ); throw new ResponseException($response); }
php
protected function loadFileManager() { // Method ajaxTreeView is in TreeView.php - watch out! $response = new Response( $this->getDataContainer()->ajaxTreeView($this->getPost('folder', true), (int) $this->getPost('level')) ); throw new ResponseException($response); }
[ "protected", "function", "loadFileManager", "(", ")", "{", "// Method ajaxTreeView is in TreeView.php - watch out!", "$", "response", "=", "new", "Response", "(", "$", "this", "->", "getDataContainer", "(", ")", "->", "ajaxTreeView", "(", "$", "this", "->", "getPost", "(", "'folder'", ",", "true", ")", ",", "(", "int", ")", "$", "this", "->", "getPost", "(", "'level'", ")", ")", ")", ";", "throw", "new", "ResponseException", "(", "$", "response", ")", ";", "}" ]
Load a file manager tree structure. This method exits the script! @return void @throws ResponseException Throws a response exception.
[ "Load", "a", "file", "manager", "tree", "structure", "." ]
bf59fc2085cc848c564e40324dee14ef2897faa6
https://github.com/contao-community-alliance/dc-general/blob/bf59fc2085cc848c564e40324dee14ef2897faa6/src/Controller/Ajax.php#L142-L150
train
contao-community-alliance/dc-general
src/Controller/Ajax.php
Ajax.executePostActions
public function executePostActions(DataContainerInterface $container) { \header('Content-Type: text/html; charset=' . $GLOBALS['TL_CONFIG']['characterSet']); $this->objDc = $container; $action = $this->getEnvironment()->getInputProvider()->getValue('action'); if (\in_array( $action, [ // This is impossible to handle generically in DcGeneral. 'toggleFeatured', // DcGeneral handles sub palettes differently. 'toggleSubpalette' ] )) { return; } if (\in_array( $action, [ // Load nodes of the page structure tree. Compatible between 2.X and 3.X. 'loadStructure', // Load nodes of the file manager tree. 'loadFileManager', // Load nodes of the page tree. 'loadPagetree', // Load nodes of the file tree. 'loadFiletree', // Reload the page/file picker. 'reloadPagetree', 'reloadFiletree', 'setLegendState' ] )) { $this->{$action}(); return; } $ajax = new ContaoAjax($action); $ajax->executePreActions(); $ajax->executePostActions(new DcCompat($this->getEnvironment(), $this->getActiveModel())); }
php
public function executePostActions(DataContainerInterface $container) { \header('Content-Type: text/html; charset=' . $GLOBALS['TL_CONFIG']['characterSet']); $this->objDc = $container; $action = $this->getEnvironment()->getInputProvider()->getValue('action'); if (\in_array( $action, [ // This is impossible to handle generically in DcGeneral. 'toggleFeatured', // DcGeneral handles sub palettes differently. 'toggleSubpalette' ] )) { return; } if (\in_array( $action, [ // Load nodes of the page structure tree. Compatible between 2.X and 3.X. 'loadStructure', // Load nodes of the file manager tree. 'loadFileManager', // Load nodes of the page tree. 'loadPagetree', // Load nodes of the file tree. 'loadFiletree', // Reload the page/file picker. 'reloadPagetree', 'reloadFiletree', 'setLegendState' ] )) { $this->{$action}(); return; } $ajax = new ContaoAjax($action); $ajax->executePreActions(); $ajax->executePostActions(new DcCompat($this->getEnvironment(), $this->getActiveModel())); }
[ "public", "function", "executePostActions", "(", "DataContainerInterface", "$", "container", ")", "{", "\\", "header", "(", "'Content-Type: text/html; charset='", ".", "$", "GLOBALS", "[", "'TL_CONFIG'", "]", "[", "'characterSet'", "]", ")", ";", "$", "this", "->", "objDc", "=", "$", "container", ";", "$", "action", "=", "$", "this", "->", "getEnvironment", "(", ")", "->", "getInputProvider", "(", ")", "->", "getValue", "(", "'action'", ")", ";", "if", "(", "\\", "in_array", "(", "$", "action", ",", "[", "// This is impossible to handle generically in DcGeneral.", "'toggleFeatured'", ",", "// DcGeneral handles sub palettes differently.", "'toggleSubpalette'", "]", ")", ")", "{", "return", ";", "}", "if", "(", "\\", "in_array", "(", "$", "action", ",", "[", "// Load nodes of the page structure tree. Compatible between 2.X and 3.X.", "'loadStructure'", ",", "// Load nodes of the file manager tree.", "'loadFileManager'", ",", "// Load nodes of the page tree.", "'loadPagetree'", ",", "// Load nodes of the file tree.", "'loadFiletree'", ",", "// Reload the page/file picker.", "'reloadPagetree'", ",", "'reloadFiletree'", ",", "'setLegendState'", "]", ")", ")", "{", "$", "this", "->", "{", "$", "action", "}", "(", ")", ";", "return", ";", "}", "$", "ajax", "=", "new", "ContaoAjax", "(", "$", "action", ")", ";", "$", "ajax", "->", "executePreActions", "(", ")", ";", "$", "ajax", "->", "executePostActions", "(", "new", "DcCompat", "(", "$", "this", "->", "getEnvironment", "(", ")", ",", "$", "this", "->", "getActiveModel", "(", ")", ")", ")", ";", "}" ]
Handle the post actions from DcGeneral. @param DataContainerInterface $container The data container. @return void @SuppressWarnings(PHPMD.Superglobals) @SuppressWarnings(PHPMD.CamelCaseVariableName)
[ "Handle", "the", "post", "actions", "from", "DcGeneral", "." ]
bf59fc2085cc848c564e40324dee14ef2897faa6
https://github.com/contao-community-alliance/dc-general/blob/bf59fc2085cc848c564e40324dee14ef2897faa6/src/Controller/Ajax.php#L203-L247
train
contao-community-alliance/dc-general
src/Controller/Ajax.php
Ajax.exitScript
protected function exitScript() { // @codingStandardsIgnoreStart @\trigger_error('Use own response exit!', E_USER_DEPRECATED); // @codingStandardsIgnoreEnd $session = System::getContainer()->get('session'); $sessionBag = $session->getBag('contao_backend')->all(); $user = BackendUser::getInstance(); Database::getInstance()->prepare('UPDATE tl_user SET tl_user.session=? WHERE tl_user.id=?') ->execute(\serialize($sessionBag), $user->id); exit; }
php
protected function exitScript() { // @codingStandardsIgnoreStart @\trigger_error('Use own response exit!', E_USER_DEPRECATED); // @codingStandardsIgnoreEnd $session = System::getContainer()->get('session'); $sessionBag = $session->getBag('contao_backend')->all(); $user = BackendUser::getInstance(); Database::getInstance()->prepare('UPDATE tl_user SET tl_user.session=? WHERE tl_user.id=?') ->execute(\serialize($sessionBag), $user->id); exit; }
[ "protected", "function", "exitScript", "(", ")", "{", "// @codingStandardsIgnoreStart", "@", "\\", "trigger_error", "(", "'Use own response exit!'", ",", "E_USER_DEPRECATED", ")", ";", "// @codingStandardsIgnoreEnd", "$", "session", "=", "System", "::", "getContainer", "(", ")", "->", "get", "(", "'session'", ")", ";", "$", "sessionBag", "=", "$", "session", "->", "getBag", "(", "'contao_backend'", ")", "->", "all", "(", ")", ";", "$", "user", "=", "BackendUser", "::", "getInstance", "(", ")", ";", "Database", "::", "getInstance", "(", ")", "->", "prepare", "(", "'UPDATE tl_user SET tl_user.session=? WHERE tl_user.id=?'", ")", "->", "execute", "(", "\\", "serialize", "(", "$", "sessionBag", ")", ",", "$", "user", "->", "id", ")", ";", "exit", ";", "}" ]
Convenience method to exit the script. Will get called from subclasses to have a central endpoint to exit the script. @return void @deprecated Deperecated since 2.1 and where remove in 3.0. Use own response exit. @SuppressWarnings(PHPMD.ExitExpression) - The whole purpose of the method is the exit expression.
[ "Convenience", "method", "to", "exit", "the", "script", "." ]
bf59fc2085cc848c564e40324dee14ef2897faa6
https://github.com/contao-community-alliance/dc-general/blob/bf59fc2085cc848c564e40324dee14ef2897faa6/src/Controller/Ajax.php#L280-L295
train
yiisoft/cache
src/MemCached.php
MemCached.addServers
protected function addServers($cache, $servers) { $existingServers = []; if ($this->persistentId !== null) { foreach ($cache->getServerList() as $s) { $existingServers[$s['host'] . ':' . $s['port']] = true; } } foreach ($servers as $server) { if (empty($existingServers) || !isset($existingServers[$server->getHost() . ':' . $server->getPort()])) { $cache->addServer($server->getHost(), $server->getPort(), $server->getWeight()); } } }
php
protected function addServers($cache, $servers) { $existingServers = []; if ($this->persistentId !== null) { foreach ($cache->getServerList() as $s) { $existingServers[$s['host'] . ':' . $s['port']] = true; } } foreach ($servers as $server) { if (empty($existingServers) || !isset($existingServers[$server->getHost() . ':' . $server->getPort()])) { $cache->addServer($server->getHost(), $server->getPort(), $server->getWeight()); } } }
[ "protected", "function", "addServers", "(", "$", "cache", ",", "$", "servers", ")", "{", "$", "existingServers", "=", "[", "]", ";", "if", "(", "$", "this", "->", "persistentId", "!==", "null", ")", "{", "foreach", "(", "$", "cache", "->", "getServerList", "(", ")", "as", "$", "s", ")", "{", "$", "existingServers", "[", "$", "s", "[", "'host'", "]", ".", "':'", ".", "$", "s", "[", "'port'", "]", "]", "=", "true", ";", "}", "}", "foreach", "(", "$", "servers", "as", "$", "server", ")", "{", "if", "(", "empty", "(", "$", "existingServers", ")", "||", "!", "isset", "(", "$", "existingServers", "[", "$", "server", "->", "getHost", "(", ")", ".", "':'", ".", "$", "server", "->", "getPort", "(", ")", "]", ")", ")", "{", "$", "cache", "->", "addServer", "(", "$", "server", "->", "getHost", "(", ")", ",", "$", "server", "->", "getPort", "(", ")", ",", "$", "server", "->", "getWeight", "(", ")", ")", ";", "}", "}", "}" ]
Add servers to the server pool of the cache specified @param \Memcached $cache @param MemCachedServer[] $servers
[ "Add", "servers", "to", "the", "server", "pool", "of", "the", "cache", "specified" ]
d3ffe8436270481e34842705817a5cf8025d947f
https://github.com/yiisoft/cache/blob/d3ffe8436270481e34842705817a5cf8025d947f/src/MemCached.php#L122-L135
train
yiisoft/cache
src/MemCached.php
MemCached.getMemcached
public function getMemcached() { if ($this->_cache === null) { if (!extension_loaded('memcached')) { throw new InvalidConfigException('MemCached requires PHP memcached extension to be loaded.'); } $this->_cache = $this->persistentId !== null ? new \Memcached($this->persistentId) : new \Memcached; if ($this->username !== null || $this->password !== null) { $this->_cache->setOption(\Memcached::OPT_BINARY_PROTOCOL, true); $this->_cache->setSaslAuthData($this->username, $this->password); } if (!empty($this->options)) { $this->_cache->setOptions($this->options); } } return $this->_cache; }
php
public function getMemcached() { if ($this->_cache === null) { if (!extension_loaded('memcached')) { throw new InvalidConfigException('MemCached requires PHP memcached extension to be loaded.'); } $this->_cache = $this->persistentId !== null ? new \Memcached($this->persistentId) : new \Memcached; if ($this->username !== null || $this->password !== null) { $this->_cache->setOption(\Memcached::OPT_BINARY_PROTOCOL, true); $this->_cache->setSaslAuthData($this->username, $this->password); } if (!empty($this->options)) { $this->_cache->setOptions($this->options); } } return $this->_cache; }
[ "public", "function", "getMemcached", "(", ")", "{", "if", "(", "$", "this", "->", "_cache", "===", "null", ")", "{", "if", "(", "!", "extension_loaded", "(", "'memcached'", ")", ")", "{", "throw", "new", "InvalidConfigException", "(", "'MemCached requires PHP memcached extension to be loaded.'", ")", ";", "}", "$", "this", "->", "_cache", "=", "$", "this", "->", "persistentId", "!==", "null", "?", "new", "\\", "Memcached", "(", "$", "this", "->", "persistentId", ")", ":", "new", "\\", "Memcached", ";", "if", "(", "$", "this", "->", "username", "!==", "null", "||", "$", "this", "->", "password", "!==", "null", ")", "{", "$", "this", "->", "_cache", "->", "setOption", "(", "\\", "Memcached", "::", "OPT_BINARY_PROTOCOL", ",", "true", ")", ";", "$", "this", "->", "_cache", "->", "setSaslAuthData", "(", "$", "this", "->", "username", ",", "$", "this", "->", "password", ")", ";", "}", "if", "(", "!", "empty", "(", "$", "this", "->", "options", ")", ")", "{", "$", "this", "->", "_cache", "->", "setOptions", "(", "$", "this", "->", "options", ")", ";", "}", "}", "return", "$", "this", "->", "_cache", ";", "}" ]
Returns the underlying memcached object. @return \Memcached the memcached object used by this cache component. @throws InvalidConfigException if memcached extension is not loaded
[ "Returns", "the", "underlying", "memcached", "object", "." ]
d3ffe8436270481e34842705817a5cf8025d947f
https://github.com/yiisoft/cache/blob/d3ffe8436270481e34842705817a5cf8025d947f/src/MemCached.php#L142-L160
train
contao-community-alliance/dc-general
src/DC/General.php
General.getTablenameCallback
protected function getTablenameCallback($tableName) { if (isset($GLOBALS['TL_DCA'][$tableName]['config']['tablename_callback']) && \is_array($GLOBALS['TL_DCA'][$tableName]['config']['tablename_callback']) ) { foreach ($GLOBALS['TL_DCA'][$tableName]['config']['tablename_callback'] as $callback) { $tableName = Callbacks::call($callback, $tableName, $this) ?: $tableName; } } return $tableName; }
php
protected function getTablenameCallback($tableName) { if (isset($GLOBALS['TL_DCA'][$tableName]['config']['tablename_callback']) && \is_array($GLOBALS['TL_DCA'][$tableName]['config']['tablename_callback']) ) { foreach ($GLOBALS['TL_DCA'][$tableName]['config']['tablename_callback'] as $callback) { $tableName = Callbacks::call($callback, $tableName, $this) ?: $tableName; } } return $tableName; }
[ "protected", "function", "getTablenameCallback", "(", "$", "tableName", ")", "{", "if", "(", "isset", "(", "$", "GLOBALS", "[", "'TL_DCA'", "]", "[", "$", "tableName", "]", "[", "'config'", "]", "[", "'tablename_callback'", "]", ")", "&&", "\\", "is_array", "(", "$", "GLOBALS", "[", "'TL_DCA'", "]", "[", "$", "tableName", "]", "[", "'config'", "]", "[", "'tablename_callback'", "]", ")", ")", "{", "foreach", "(", "$", "GLOBALS", "[", "'TL_DCA'", "]", "[", "$", "tableName", "]", "[", "'config'", "]", "[", "'tablename_callback'", "]", "as", "$", "callback", ")", "{", "$", "tableName", "=", "Callbacks", "::", "call", "(", "$", "callback", ",", "$", "tableName", ",", "$", "this", ")", "?", ":", "$", "tableName", ";", "}", "}", "return", "$", "tableName", ";", "}" ]
Call the table name callback. @param string $tableName The current table name. @return string New name of current table. @SuppressWarnings(PHPMD.CamelCaseVariableName) @SuppressWarnings(PHPMD.Superglobals)
[ "Call", "the", "table", "name", "callback", "." ]
bf59fc2085cc848c564e40324dee14ef2897faa6
https://github.com/contao-community-alliance/dc-general/blob/bf59fc2085cc848c564e40324dee14ef2897faa6/src/DC/General.php#L155-L166
train
contao-community-alliance/dc-general
src/DC/General.php
General.callAction
protected function callAction() { $environment = $this->getEnvironment(); $action = new Action($environment->getInputProvider()->getParameter('act') ?: 'showAll'); return $environment->getController()->handle($action); }
php
protected function callAction() { $environment = $this->getEnvironment(); $action = new Action($environment->getInputProvider()->getParameter('act') ?: 'showAll'); return $environment->getController()->handle($action); }
[ "protected", "function", "callAction", "(", ")", "{", "$", "environment", "=", "$", "this", "->", "getEnvironment", "(", ")", ";", "$", "action", "=", "new", "Action", "(", "$", "environment", "->", "getInputProvider", "(", ")", "->", "getParameter", "(", "'act'", ")", "?", ":", "'showAll'", ")", ";", "return", "$", "environment", "->", "getController", "(", ")", "->", "handle", "(", "$", "action", ")", ";", "}" ]
Call the desired user action with an implicit fallback to the "showAll" action when none has been requested. @return string
[ "Call", "the", "desired", "user", "action", "with", "an", "implicit", "fallback", "to", "the", "showAll", "action", "when", "none", "has", "been", "requested", "." ]
bf59fc2085cc848c564e40324dee14ef2897faa6
https://github.com/contao-community-alliance/dc-general/blob/bf59fc2085cc848c564e40324dee14ef2897faa6/src/DC/General.php#L267-L273
train
contao-community-alliance/dc-general
src/Contao/Subscriber/FallbackResetSubscriber.php
FallbackResetSubscriber.determineFilterConfig
private function determineFilterConfig(AbstractModelAwareEvent $event) { $environment = $event->getEnvironment(); $model = $event->getModel(); $dataProvider = $environment->getDataProvider($model->getProviderName()); $definition = $environment->getDataDefinition(); $relationship = $definition->getModelRelationshipDefinition(); $root = $relationship->getRootCondition(); if (null !== $root && $root->matches($model)) { return $dataProvider->getEmptyConfig()->setFilter($root->getFilterArray()); } $parentFilter = $relationship->getChildCondition( $definition->getBasicDefinition()->getParentDataProvider(), $model->getProviderName() ); if (null !== $parentFilter) { $parentConfig = $dataProvider->getEmptyConfig()->setFilter($parentFilter->getInverseFilterFor($model)); $parentProvider = $environment->getDataProvider($parentFilter->getSourceName()); $parent = $parentProvider->fetchAll($parentConfig)->get(0); return $dataProvider->getEmptyConfig()->setFilter($parentFilter->getFilter($parent)); } // Trigger BC layer in handleFallback(). if ((null === $root) && (0 === \count($relationship->getChildConditions()))) { return null; } return $dataProvider->getEmptyConfig(); }
php
private function determineFilterConfig(AbstractModelAwareEvent $event) { $environment = $event->getEnvironment(); $model = $event->getModel(); $dataProvider = $environment->getDataProvider($model->getProviderName()); $definition = $environment->getDataDefinition(); $relationship = $definition->getModelRelationshipDefinition(); $root = $relationship->getRootCondition(); if (null !== $root && $root->matches($model)) { return $dataProvider->getEmptyConfig()->setFilter($root->getFilterArray()); } $parentFilter = $relationship->getChildCondition( $definition->getBasicDefinition()->getParentDataProvider(), $model->getProviderName() ); if (null !== $parentFilter) { $parentConfig = $dataProvider->getEmptyConfig()->setFilter($parentFilter->getInverseFilterFor($model)); $parentProvider = $environment->getDataProvider($parentFilter->getSourceName()); $parent = $parentProvider->fetchAll($parentConfig)->get(0); return $dataProvider->getEmptyConfig()->setFilter($parentFilter->getFilter($parent)); } // Trigger BC layer in handleFallback(). if ((null === $root) && (0 === \count($relationship->getChildConditions()))) { return null; } return $dataProvider->getEmptyConfig(); }
[ "private", "function", "determineFilterConfig", "(", "AbstractModelAwareEvent", "$", "event", ")", "{", "$", "environment", "=", "$", "event", "->", "getEnvironment", "(", ")", ";", "$", "model", "=", "$", "event", "->", "getModel", "(", ")", ";", "$", "dataProvider", "=", "$", "environment", "->", "getDataProvider", "(", "$", "model", "->", "getProviderName", "(", ")", ")", ";", "$", "definition", "=", "$", "environment", "->", "getDataDefinition", "(", ")", ";", "$", "relationship", "=", "$", "definition", "->", "getModelRelationshipDefinition", "(", ")", ";", "$", "root", "=", "$", "relationship", "->", "getRootCondition", "(", ")", ";", "if", "(", "null", "!==", "$", "root", "&&", "$", "root", "->", "matches", "(", "$", "model", ")", ")", "{", "return", "$", "dataProvider", "->", "getEmptyConfig", "(", ")", "->", "setFilter", "(", "$", "root", "->", "getFilterArray", "(", ")", ")", ";", "}", "$", "parentFilter", "=", "$", "relationship", "->", "getChildCondition", "(", "$", "definition", "->", "getBasicDefinition", "(", ")", "->", "getParentDataProvider", "(", ")", ",", "$", "model", "->", "getProviderName", "(", ")", ")", ";", "if", "(", "null", "!==", "$", "parentFilter", ")", "{", "$", "parentConfig", "=", "$", "dataProvider", "->", "getEmptyConfig", "(", ")", "->", "setFilter", "(", "$", "parentFilter", "->", "getInverseFilterFor", "(", "$", "model", ")", ")", ";", "$", "parentProvider", "=", "$", "environment", "->", "getDataProvider", "(", "$", "parentFilter", "->", "getSourceName", "(", ")", ")", ";", "$", "parent", "=", "$", "parentProvider", "->", "fetchAll", "(", "$", "parentConfig", ")", "->", "get", "(", "0", ")", ";", "return", "$", "dataProvider", "->", "getEmptyConfig", "(", ")", "->", "setFilter", "(", "$", "parentFilter", "->", "getFilter", "(", "$", "parent", ")", ")", ";", "}", "// Trigger BC layer in handleFallback().", "if", "(", "(", "null", "===", "$", "root", ")", "&&", "(", "0", "===", "\\", "count", "(", "$", "relationship", "->", "getChildConditions", "(", ")", ")", ")", ")", "{", "return", "null", ";", "}", "return", "$", "dataProvider", "->", "getEmptyConfig", "(", ")", ";", "}" ]
Determine the filter config to use. @param AbstractModelAwareEvent $event The event. @return ConfigInterface|null
[ "Determine", "the", "filter", "config", "to", "use", "." ]
bf59fc2085cc848c564e40324dee14ef2897faa6
https://github.com/contao-community-alliance/dc-general/blob/bf59fc2085cc848c564e40324dee14ef2897faa6/src/Contao/Subscriber/FallbackResetSubscriber.php#L144-L175
train
contao-community-alliance/dc-general
src/DataDefinition/Definition/DefaultDataProviderDefinition.php
DefaultDataProviderDefinition.makeName
protected function makeName($information) { if ($information instanceof DataProviderInformationInterface) { $information = $information->getName(); } if (!\is_string($information)) { throw new DcGeneralInvalidArgumentException('Invalid value passed.'); } return $information; }
php
protected function makeName($information) { if ($information instanceof DataProviderInformationInterface) { $information = $information->getName(); } if (!\is_string($information)) { throw new DcGeneralInvalidArgumentException('Invalid value passed.'); } return $information; }
[ "protected", "function", "makeName", "(", "$", "information", ")", "{", "if", "(", "$", "information", "instanceof", "DataProviderInformationInterface", ")", "{", "$", "information", "=", "$", "information", "->", "getName", "(", ")", ";", "}", "if", "(", "!", "\\", "is_string", "(", "$", "information", ")", ")", "{", "throw", "new", "DcGeneralInvalidArgumentException", "(", "'Invalid value passed.'", ")", ";", "}", "return", "$", "information", ";", "}" ]
Convert a value into a data definition name. Convenience method to ensure we have a data provider name. @param DataProviderInformationInterface|string $information The information or name of a data provider. @return string @throws DcGeneralInvalidArgumentException If neither a string nor an instance of DataProviderInformationInterface has been passed. @internal
[ "Convert", "a", "value", "into", "a", "data", "definition", "name", "." ]
bf59fc2085cc848c564e40324dee14ef2897faa6
https://github.com/contao-community-alliance/dc-general/blob/bf59fc2085cc848c564e40324dee14ef2897faa6/src/DataDefinition/Definition/DefaultDataProviderDefinition.php#L76-L87
train
contao-community-alliance/dc-general
src/Contao/Subscriber/FormatModelLabelSubscriber.php
FormatModelLabelSubscriber.handleFormatModelLabel
public function handleFormatModelLabel(FormatModelLabelEvent $event) { if (!$this->scopeDeterminator->currentScopeIsBackend()) { return; } $environment = $event->getEnvironment(); $model = $event->getModel(); $dataDefinition = $environment->getDataDefinition(); /** @var Contao2BackendViewDefinitionInterface $viewSection */ $viewSection = $dataDefinition->getDefinition(Contao2BackendViewDefinitionInterface::NAME); $listing = $viewSection->getListingConfig(); $properties = $dataDefinition->getPropertiesDefinition(); $formatter = $listing->getLabelFormatter($model->getProviderName()); $sorting = ViewHelpers::getGroupingMode($environment); $firstSorting = $this->getFirstSorting($sorting['sorting']); $propertyNames = $formatter->getPropertyNames(); $modelToLabelEvent = new ModelToLabelEvent($environment, $model); $modelToLabelEvent ->setArgs($this->prepareLabelArguments($propertyNames, $properties, $environment, $model)) ->setLabel($formatter->getFormat()) ->setFormatter($formatter); $environment->getEventDispatcher()->dispatch(ModelToLabelEvent::NAME, $modelToLabelEvent); // Add columns. if ($listing->getShowColumns()) { $event->setLabel($this->renderWithColumns($propertyNames, $modelToLabelEvent->getArgs(), $firstSorting)); return; } $event->setLabel( [ [ 'colspan' => null, 'class' => 'tl_file_list', 'content' => $this->renderSingleValue( $modelToLabelEvent->getLabel(), $modelToLabelEvent->getArgs(), $formatter->getMaxLength() ) ] ] ); }
php
public function handleFormatModelLabel(FormatModelLabelEvent $event) { if (!$this->scopeDeterminator->currentScopeIsBackend()) { return; } $environment = $event->getEnvironment(); $model = $event->getModel(); $dataDefinition = $environment->getDataDefinition(); /** @var Contao2BackendViewDefinitionInterface $viewSection */ $viewSection = $dataDefinition->getDefinition(Contao2BackendViewDefinitionInterface::NAME); $listing = $viewSection->getListingConfig(); $properties = $dataDefinition->getPropertiesDefinition(); $formatter = $listing->getLabelFormatter($model->getProviderName()); $sorting = ViewHelpers::getGroupingMode($environment); $firstSorting = $this->getFirstSorting($sorting['sorting']); $propertyNames = $formatter->getPropertyNames(); $modelToLabelEvent = new ModelToLabelEvent($environment, $model); $modelToLabelEvent ->setArgs($this->prepareLabelArguments($propertyNames, $properties, $environment, $model)) ->setLabel($formatter->getFormat()) ->setFormatter($formatter); $environment->getEventDispatcher()->dispatch(ModelToLabelEvent::NAME, $modelToLabelEvent); // Add columns. if ($listing->getShowColumns()) { $event->setLabel($this->renderWithColumns($propertyNames, $modelToLabelEvent->getArgs(), $firstSorting)); return; } $event->setLabel( [ [ 'colspan' => null, 'class' => 'tl_file_list', 'content' => $this->renderSingleValue( $modelToLabelEvent->getLabel(), $modelToLabelEvent->getArgs(), $formatter->getMaxLength() ) ] ] ); }
[ "public", "function", "handleFormatModelLabel", "(", "FormatModelLabelEvent", "$", "event", ")", "{", "if", "(", "!", "$", "this", "->", "scopeDeterminator", "->", "currentScopeIsBackend", "(", ")", ")", "{", "return", ";", "}", "$", "environment", "=", "$", "event", "->", "getEnvironment", "(", ")", ";", "$", "model", "=", "$", "event", "->", "getModel", "(", ")", ";", "$", "dataDefinition", "=", "$", "environment", "->", "getDataDefinition", "(", ")", ";", "/** @var Contao2BackendViewDefinitionInterface $viewSection */", "$", "viewSection", "=", "$", "dataDefinition", "->", "getDefinition", "(", "Contao2BackendViewDefinitionInterface", "::", "NAME", ")", ";", "$", "listing", "=", "$", "viewSection", "->", "getListingConfig", "(", ")", ";", "$", "properties", "=", "$", "dataDefinition", "->", "getPropertiesDefinition", "(", ")", ";", "$", "formatter", "=", "$", "listing", "->", "getLabelFormatter", "(", "$", "model", "->", "getProviderName", "(", ")", ")", ";", "$", "sorting", "=", "ViewHelpers", "::", "getGroupingMode", "(", "$", "environment", ")", ";", "$", "firstSorting", "=", "$", "this", "->", "getFirstSorting", "(", "$", "sorting", "[", "'sorting'", "]", ")", ";", "$", "propertyNames", "=", "$", "formatter", "->", "getPropertyNames", "(", ")", ";", "$", "modelToLabelEvent", "=", "new", "ModelToLabelEvent", "(", "$", "environment", ",", "$", "model", ")", ";", "$", "modelToLabelEvent", "->", "setArgs", "(", "$", "this", "->", "prepareLabelArguments", "(", "$", "propertyNames", ",", "$", "properties", ",", "$", "environment", ",", "$", "model", ")", ")", "->", "setLabel", "(", "$", "formatter", "->", "getFormat", "(", ")", ")", "->", "setFormatter", "(", "$", "formatter", ")", ";", "$", "environment", "->", "getEventDispatcher", "(", ")", "->", "dispatch", "(", "ModelToLabelEvent", "::", "NAME", ",", "$", "modelToLabelEvent", ")", ";", "// Add columns.", "if", "(", "$", "listing", "->", "getShowColumns", "(", ")", ")", "{", "$", "event", "->", "setLabel", "(", "$", "this", "->", "renderWithColumns", "(", "$", "propertyNames", ",", "$", "modelToLabelEvent", "->", "getArgs", "(", ")", ",", "$", "firstSorting", ")", ")", ";", "return", ";", "}", "$", "event", "->", "setLabel", "(", "[", "[", "'colspan'", "=>", "null", ",", "'class'", "=>", "'tl_file_list'", ",", "'content'", "=>", "$", "this", "->", "renderSingleValue", "(", "$", "modelToLabelEvent", "->", "getLabel", "(", ")", ",", "$", "modelToLabelEvent", "->", "getArgs", "(", ")", ",", "$", "formatter", "->", "getMaxLength", "(", ")", ")", "]", "]", ")", ";", "}" ]
Default handler for formatting a model. @param FormatModelLabelEvent $event The event. @return void
[ "Default", "handler", "for", "formatting", "a", "model", "." ]
bf59fc2085cc848c564e40324dee14ef2897faa6
https://github.com/contao-community-alliance/dc-general/blob/bf59fc2085cc848c564e40324dee14ef2897faa6/src/Contao/Subscriber/FormatModelLabelSubscriber.php#L49-L95
train
contao-community-alliance/dc-general
src/Contao/Subscriber/FormatModelLabelSubscriber.php
FormatModelLabelSubscriber.getFirstSorting
private function getFirstSorting(GroupAndSortingDefinitionInterface $sortingDefinition = null) { if (null === $sortingDefinition) { return ''; } foreach ($sortingDefinition as $information) { /** @var GroupAndSortingInformationInterface $information */ if ($information->getProperty()) { return $information->getProperty(); } } return ''; }
php
private function getFirstSorting(GroupAndSortingDefinitionInterface $sortingDefinition = null) { if (null === $sortingDefinition) { return ''; } foreach ($sortingDefinition as $information) { /** @var GroupAndSortingInformationInterface $information */ if ($information->getProperty()) { return $information->getProperty(); } } return ''; }
[ "private", "function", "getFirstSorting", "(", "GroupAndSortingDefinitionInterface", "$", "sortingDefinition", "=", "null", ")", "{", "if", "(", "null", "===", "$", "sortingDefinition", ")", "{", "return", "''", ";", "}", "foreach", "(", "$", "sortingDefinition", "as", "$", "information", ")", "{", "/** @var GroupAndSortingInformationInterface $information */", "if", "(", "$", "information", "->", "getProperty", "(", ")", ")", "{", "return", "$", "information", "->", "getProperty", "(", ")", ";", "}", "}", "return", "''", ";", "}" ]
Retrieve the first sorting value. @param GroupAndSortingDefinitionInterface|null $sortingDefinition The sorting definition. @return string
[ "Retrieve", "the", "first", "sorting", "value", "." ]
bf59fc2085cc848c564e40324dee14ef2897faa6
https://github.com/contao-community-alliance/dc-general/blob/bf59fc2085cc848c564e40324dee14ef2897faa6/src/Contao/Subscriber/FormatModelLabelSubscriber.php#L104-L118
train
contao-community-alliance/dc-general
src/Contao/Subscriber/FormatModelLabelSubscriber.php
FormatModelLabelSubscriber.prepareLabelArguments
private function prepareLabelArguments( $propertyNames, PropertiesDefinitionInterface $properties, EnvironmentInterface $environment, ModelInterface $model ) { $args = []; foreach ($propertyNames as $propertyName) { if (!$properties->hasProperty($propertyName)) { $args[$propertyName] = '-'; continue; } $args[$propertyName] = (string) ViewHelpers::getReadableFieldValue( $environment, $properties->getProperty($propertyName), $model ); } return $args; }
php
private function prepareLabelArguments( $propertyNames, PropertiesDefinitionInterface $properties, EnvironmentInterface $environment, ModelInterface $model ) { $args = []; foreach ($propertyNames as $propertyName) { if (!$properties->hasProperty($propertyName)) { $args[$propertyName] = '-'; continue; } $args[$propertyName] = (string) ViewHelpers::getReadableFieldValue( $environment, $properties->getProperty($propertyName), $model ); } return $args; }
[ "private", "function", "prepareLabelArguments", "(", "$", "propertyNames", ",", "PropertiesDefinitionInterface", "$", "properties", ",", "EnvironmentInterface", "$", "environment", ",", "ModelInterface", "$", "model", ")", "{", "$", "args", "=", "[", "]", ";", "foreach", "(", "$", "propertyNames", "as", "$", "propertyName", ")", "{", "if", "(", "!", "$", "properties", "->", "hasProperty", "(", "$", "propertyName", ")", ")", "{", "$", "args", "[", "$", "propertyName", "]", "=", "'-'", ";", "continue", ";", "}", "$", "args", "[", "$", "propertyName", "]", "=", "(", "string", ")", "ViewHelpers", "::", "getReadableFieldValue", "(", "$", "environment", ",", "$", "properties", "->", "getProperty", "(", "$", "propertyName", ")", ",", "$", "model", ")", ";", "}", "return", "$", "args", ";", "}" ]
Prepare the arguments for the label formatter. @param string[] $propertyNames The properties. @param PropertiesDefinitionInterface $properties The property definition. @param EnvironmentInterface $environment The environment. @param ModelInterface $model The model. @return array
[ "Prepare", "the", "arguments", "for", "the", "label", "formatter", "." ]
bf59fc2085cc848c564e40324dee14ef2897faa6
https://github.com/contao-community-alliance/dc-general/blob/bf59fc2085cc848c564e40324dee14ef2897faa6/src/Contao/Subscriber/FormatModelLabelSubscriber.php#L130-L152
train
contao-community-alliance/dc-general
src/Contao/Subscriber/FormatModelLabelSubscriber.php
FormatModelLabelSubscriber.renderWithColumns
private function renderWithColumns($propertyNames, $args, $firstSorting) { $label = []; if (!\is_array($args)) { // @codingStandardsIgnoreStart @\trigger_error('Warning, column layout without arguments will not be supported.', E_USER_DEPRECATED); // @codingStandardsIgnoreEnd $label[] = [ 'colspan' => \count($propertyNames), 'class' => 'tl_file_list col_all', 'content' => $args ]; } else { foreach ($propertyNames as $propertyName) { $class = 'tl_file_list col_' . $propertyName; if ($firstSorting === $propertyName) { $class .= ' ordered_by'; } $label[] = [ 'colspan' => 1, 'class' => $class, 'content' => $args[$propertyName] ?: '-' ]; } } return $label; }
php
private function renderWithColumns($propertyNames, $args, $firstSorting) { $label = []; if (!\is_array($args)) { // @codingStandardsIgnoreStart @\trigger_error('Warning, column layout without arguments will not be supported.', E_USER_DEPRECATED); // @codingStandardsIgnoreEnd $label[] = [ 'colspan' => \count($propertyNames), 'class' => 'tl_file_list col_all', 'content' => $args ]; } else { foreach ($propertyNames as $propertyName) { $class = 'tl_file_list col_' . $propertyName; if ($firstSorting === $propertyName) { $class .= ' ordered_by'; } $label[] = [ 'colspan' => 1, 'class' => $class, 'content' => $args[$propertyName] ?: '-' ]; } } return $label; }
[ "private", "function", "renderWithColumns", "(", "$", "propertyNames", ",", "$", "args", ",", "$", "firstSorting", ")", "{", "$", "label", "=", "[", "]", ";", "if", "(", "!", "\\", "is_array", "(", "$", "args", ")", ")", "{", "// @codingStandardsIgnoreStart", "@", "\\", "trigger_error", "(", "'Warning, column layout without arguments will not be supported.'", ",", "E_USER_DEPRECATED", ")", ";", "// @codingStandardsIgnoreEnd", "$", "label", "[", "]", "=", "[", "'colspan'", "=>", "\\", "count", "(", "$", "propertyNames", ")", ",", "'class'", "=>", "'tl_file_list col_all'", ",", "'content'", "=>", "$", "args", "]", ";", "}", "else", "{", "foreach", "(", "$", "propertyNames", "as", "$", "propertyName", ")", "{", "$", "class", "=", "'tl_file_list col_'", ".", "$", "propertyName", ";", "if", "(", "$", "firstSorting", "===", "$", "propertyName", ")", "{", "$", "class", ".=", "' ordered_by'", ";", "}", "$", "label", "[", "]", "=", "[", "'colspan'", "=>", "1", ",", "'class'", "=>", "$", "class", ",", "'content'", "=>", "$", "args", "[", "$", "propertyName", "]", "?", ":", "'-'", "]", ";", "}", "}", "return", "$", "label", ";", "}" ]
Render for column layout. @param string[] $propertyNames The properties. @param string[] $args The rendered arguments. @param string $firstSorting The sorting column. @return array
[ "Render", "for", "column", "layout", "." ]
bf59fc2085cc848c564e40324dee14ef2897faa6
https://github.com/contao-community-alliance/dc-general/blob/bf59fc2085cc848c564e40324dee14ef2897faa6/src/Contao/Subscriber/FormatModelLabelSubscriber.php#L163-L191
train
contao-community-alliance/dc-general
src/Contao/Subscriber/FormatModelLabelSubscriber.php
FormatModelLabelSubscriber.renderSingleValue
private function renderSingleValue($label, $args, $maxLength = null) { // BC: sometimes the label was returned as string in the arguments instead of an array. $string = !\is_array($args) ? $args : \vsprintf($label, $args); if ((null !== $maxLength) && \strlen($string) > $maxLength) { $string = \substr($string, 0, $maxLength); } return $string; }
php
private function renderSingleValue($label, $args, $maxLength = null) { // BC: sometimes the label was returned as string in the arguments instead of an array. $string = !\is_array($args) ? $args : \vsprintf($label, $args); if ((null !== $maxLength) && \strlen($string) > $maxLength) { $string = \substr($string, 0, $maxLength); } return $string; }
[ "private", "function", "renderSingleValue", "(", "$", "label", ",", "$", "args", ",", "$", "maxLength", "=", "null", ")", "{", "// BC: sometimes the label was returned as string in the arguments instead of an array.", "$", "string", "=", "!", "\\", "is_array", "(", "$", "args", ")", "?", "$", "args", ":", "\\", "vsprintf", "(", "$", "label", ",", "$", "args", ")", ";", "if", "(", "(", "null", "!==", "$", "maxLength", ")", "&&", "\\", "strlen", "(", "$", "string", ")", ">", "$", "maxLength", ")", "{", "$", "string", "=", "\\", "substr", "(", "$", "string", ",", "0", ",", "$", "maxLength", ")", ";", "}", "return", "$", "string", ";", "}" ]
Render as single value. @param string $label The label string. @param string[] $args The rendered arguments. @param null $maxLength The maximum length for the label or null to allow unlimited. @return string
[ "Render", "as", "single", "value", "." ]
bf59fc2085cc848c564e40324dee14ef2897faa6
https://github.com/contao-community-alliance/dc-general/blob/bf59fc2085cc848c564e40324dee14ef2897faa6/src/Contao/Subscriber/FormatModelLabelSubscriber.php#L202-L212
train
contao-community-alliance/dc-general
src/Contao/Dca/Populator/BackendViewPopulator.php
BackendViewPopulator.populatePanel
protected function populatePanel(EnvironmentInterface $environment) { /** @var BackendViewInterface $view */ $view = $environment->getView(); // Already populated or not in Backend? Get out then. if (!(($view instanceof BaseView))) { return; } if (!$environment->getDataDefinition()->hasDefinition(Contao2BackendViewDefinitionInterface::NAME)) { return; } // Already populated. if ($view->getPanel()) { return; } $view->setPanel((new PanelBuilder($environment))->build()); }
php
protected function populatePanel(EnvironmentInterface $environment) { /** @var BackendViewInterface $view */ $view = $environment->getView(); // Already populated or not in Backend? Get out then. if (!(($view instanceof BaseView))) { return; } if (!$environment->getDataDefinition()->hasDefinition(Contao2BackendViewDefinitionInterface::NAME)) { return; } // Already populated. if ($view->getPanel()) { return; } $view->setPanel((new PanelBuilder($environment))->build()); }
[ "protected", "function", "populatePanel", "(", "EnvironmentInterface", "$", "environment", ")", "{", "/** @var BackendViewInterface $view */", "$", "view", "=", "$", "environment", "->", "getView", "(", ")", ";", "// Already populated or not in Backend? Get out then.", "if", "(", "!", "(", "(", "$", "view", "instanceof", "BaseView", ")", ")", ")", "{", "return", ";", "}", "if", "(", "!", "$", "environment", "->", "getDataDefinition", "(", ")", "->", "hasDefinition", "(", "Contao2BackendViewDefinitionInterface", "::", "NAME", ")", ")", "{", "return", ";", "}", "// Already populated.", "if", "(", "$", "view", "->", "getPanel", "(", ")", ")", "{", "return", ";", "}", "$", "view", "->", "setPanel", "(", "(", "new", "PanelBuilder", "(", "$", "environment", ")", ")", "->", "build", "(", ")", ")", ";", "}" ]
Create a panel instance in the view if none has been defined yet. @param EnvironmentInterface $environment The environment to populate. @return void @internal
[ "Create", "a", "panel", "instance", "in", "the", "view", "if", "none", "has", "been", "defined", "yet", "." ]
bf59fc2085cc848c564e40324dee14ef2897faa6
https://github.com/contao-community-alliance/dc-general/blob/bf59fc2085cc848c564e40324dee14ef2897faa6/src/Contao/Dca/Populator/BackendViewPopulator.php#L107-L127
train
contao-community-alliance/dc-general
src/Contao/View/Contao2BackendView/Controller/ClipboardController.php
ClipboardController.handleAction
public function handleAction(ActionEvent $event) { if (!$this->scopeDeterminator->currentScopeIsBackend()) { return; } if ('clear-clipboard' === ($actionName = $event->getAction()->getName())) { $this->clearClipboard($event); } if (false === $this->checkPermission($event)) { $this->clearClipboard($event, false); $event->stopPropagation(); return; } if ('create' === $actionName || 'cut' === $actionName || 'copy' === $actionName || 'deepcopy' === $actionName ) { $this->addToClipboard($event); } }
php
public function handleAction(ActionEvent $event) { if (!$this->scopeDeterminator->currentScopeIsBackend()) { return; } if ('clear-clipboard' === ($actionName = $event->getAction()->getName())) { $this->clearClipboard($event); } if (false === $this->checkPermission($event)) { $this->clearClipboard($event, false); $event->stopPropagation(); return; } if ('create' === $actionName || 'cut' === $actionName || 'copy' === $actionName || 'deepcopy' === $actionName ) { $this->addToClipboard($event); } }
[ "public", "function", "handleAction", "(", "ActionEvent", "$", "event", ")", "{", "if", "(", "!", "$", "this", "->", "scopeDeterminator", "->", "currentScopeIsBackend", "(", ")", ")", "{", "return", ";", "}", "if", "(", "'clear-clipboard'", "===", "(", "$", "actionName", "=", "$", "event", "->", "getAction", "(", ")", "->", "getName", "(", ")", ")", ")", "{", "$", "this", "->", "clearClipboard", "(", "$", "event", ")", ";", "}", "if", "(", "false", "===", "$", "this", "->", "checkPermission", "(", "$", "event", ")", ")", "{", "$", "this", "->", "clearClipboard", "(", "$", "event", ",", "false", ")", ";", "$", "event", "->", "stopPropagation", "(", ")", ";", "return", ";", "}", "if", "(", "'create'", "===", "$", "actionName", "||", "'cut'", "===", "$", "actionName", "||", "'copy'", "===", "$", "actionName", "||", "'deepcopy'", "===", "$", "actionName", ")", "{", "$", "this", "->", "addToClipboard", "(", "$", "event", ")", ";", "}", "}" ]
Handle action. @param ActionEvent $event The action event. @return void
[ "Handle", "action", "." ]
bf59fc2085cc848c564e40324dee14ef2897faa6
https://github.com/contao-community-alliance/dc-general/blob/bf59fc2085cc848c564e40324dee14ef2897faa6/src/Contao/View/Contao2BackendView/Controller/ClipboardController.php#L85-L110
train
contao-community-alliance/dc-general
src/Contao/View/Contao2BackendView/Controller/ClipboardController.php
ClipboardController.checkPermission
private function checkPermission(ActionEvent $event) { $actionName = $event->getAction()->getName(); $environment = $event->getEnvironment(); $basicDefinition = $environment->getDataDefinition()->getBasicDefinition(); if ((('create' === $actionName) && (true === $basicDefinition->isCreatable())) || (('cut' === $actionName) && (true === $basicDefinition->isEditable())) || (false === \in_array($actionName, ['create', 'cut'])) ) { return true; } $permissionMessage = 'You have no permission for model ' . $actionName .' '; switch ($actionName) { case 'create': $permissionMessage .= 'in ' . $environment->getDataDefinition()->getName(); break; case 'cut': $permissionMessage .= $environment->getInputProvider()->getParameter('source'); break; default: } $event->setResponse( \sprintf( '<div style="text-align:center; font-weight:bold; padding:40px;">%s.</div>', $permissionMessage ) ); return false; }
php
private function checkPermission(ActionEvent $event) { $actionName = $event->getAction()->getName(); $environment = $event->getEnvironment(); $basicDefinition = $environment->getDataDefinition()->getBasicDefinition(); if ((('create' === $actionName) && (true === $basicDefinition->isCreatable())) || (('cut' === $actionName) && (true === $basicDefinition->isEditable())) || (false === \in_array($actionName, ['create', 'cut'])) ) { return true; } $permissionMessage = 'You have no permission for model ' . $actionName .' '; switch ($actionName) { case 'create': $permissionMessage .= 'in ' . $environment->getDataDefinition()->getName(); break; case 'cut': $permissionMessage .= $environment->getInputProvider()->getParameter('source'); break; default: } $event->setResponse( \sprintf( '<div style="text-align:center; font-weight:bold; padding:40px;">%s.</div>', $permissionMessage ) ); return false; }
[ "private", "function", "checkPermission", "(", "ActionEvent", "$", "event", ")", "{", "$", "actionName", "=", "$", "event", "->", "getAction", "(", ")", "->", "getName", "(", ")", ";", "$", "environment", "=", "$", "event", "->", "getEnvironment", "(", ")", ";", "$", "basicDefinition", "=", "$", "environment", "->", "getDataDefinition", "(", ")", "->", "getBasicDefinition", "(", ")", ";", "if", "(", "(", "(", "'create'", "===", "$", "actionName", ")", "&&", "(", "true", "===", "$", "basicDefinition", "->", "isCreatable", "(", ")", ")", ")", "||", "(", "(", "'cut'", "===", "$", "actionName", ")", "&&", "(", "true", "===", "$", "basicDefinition", "->", "isEditable", "(", ")", ")", ")", "||", "(", "false", "===", "\\", "in_array", "(", "$", "actionName", ",", "[", "'create'", ",", "'cut'", "]", ")", ")", ")", "{", "return", "true", ";", "}", "$", "permissionMessage", "=", "'You have no permission for model '", ".", "$", "actionName", ".", "' '", ";", "switch", "(", "$", "actionName", ")", "{", "case", "'create'", ":", "$", "permissionMessage", ".=", "'in '", ".", "$", "environment", "->", "getDataDefinition", "(", ")", "->", "getName", "(", ")", ";", "break", ";", "case", "'cut'", ":", "$", "permissionMessage", ".=", "$", "environment", "->", "getInputProvider", "(", ")", "->", "getParameter", "(", "'source'", ")", ";", "break", ";", "default", ":", "}", "$", "event", "->", "setResponse", "(", "\\", "sprintf", "(", "'<div style=\"text-align:center; font-weight:bold; padding:40px;\">%s.</div>'", ",", "$", "permissionMessage", ")", ")", ";", "return", "false", ";", "}" ]
Check if permission for action. @param ActionEvent $event The event. @return bool
[ "Check", "if", "permission", "for", "action", "." ]
bf59fc2085cc848c564e40324dee14ef2897faa6
https://github.com/contao-community-alliance/dc-general/blob/bf59fc2085cc848c564e40324dee14ef2897faa6/src/Contao/View/Contao2BackendView/Controller/ClipboardController.php#L119-L154
train
contao-community-alliance/dc-general
src/Contao/View/Contao2BackendView/Controller/ClipboardController.php
ClipboardController.clearClipboard
private function clearClipboard(ActionEvent $event, $redirect = true) { $environment = $event->getEnvironment(); $eventDispatcher = $environment->getEventDispatcher(); $clipboard = $environment->getClipboard(); $input = $environment->getInputProvider(); if ($clipboardId = $input->getParameter('clipboard-item')) { $clipboard->removeByClipboardId($clipboardId); } else { $clipboard->clear(); } $clipboard->saveTo($environment); if (false === $redirect) { return; } $addToUrlEvent = new AddToUrlEvent('clipboard-item=&original-act=&act=' . $input->getParameter('original-act')); $eventDispatcher->dispatch(ContaoEvents::BACKEND_ADD_TO_URL, $addToUrlEvent); $redirectEvent = new RedirectEvent($addToUrlEvent->getUrl()); $eventDispatcher->dispatch(ContaoEvents::CONTROLLER_REDIRECT, $redirectEvent); }
php
private function clearClipboard(ActionEvent $event, $redirect = true) { $environment = $event->getEnvironment(); $eventDispatcher = $environment->getEventDispatcher(); $clipboard = $environment->getClipboard(); $input = $environment->getInputProvider(); if ($clipboardId = $input->getParameter('clipboard-item')) { $clipboard->removeByClipboardId($clipboardId); } else { $clipboard->clear(); } $clipboard->saveTo($environment); if (false === $redirect) { return; } $addToUrlEvent = new AddToUrlEvent('clipboard-item=&original-act=&act=' . $input->getParameter('original-act')); $eventDispatcher->dispatch(ContaoEvents::BACKEND_ADD_TO_URL, $addToUrlEvent); $redirectEvent = new RedirectEvent($addToUrlEvent->getUrl()); $eventDispatcher->dispatch(ContaoEvents::CONTROLLER_REDIRECT, $redirectEvent); }
[ "private", "function", "clearClipboard", "(", "ActionEvent", "$", "event", ",", "$", "redirect", "=", "true", ")", "{", "$", "environment", "=", "$", "event", "->", "getEnvironment", "(", ")", ";", "$", "eventDispatcher", "=", "$", "environment", "->", "getEventDispatcher", "(", ")", ";", "$", "clipboard", "=", "$", "environment", "->", "getClipboard", "(", ")", ";", "$", "input", "=", "$", "environment", "->", "getInputProvider", "(", ")", ";", "if", "(", "$", "clipboardId", "=", "$", "input", "->", "getParameter", "(", "'clipboard-item'", ")", ")", "{", "$", "clipboard", "->", "removeByClipboardId", "(", "$", "clipboardId", ")", ";", "}", "else", "{", "$", "clipboard", "->", "clear", "(", ")", ";", "}", "$", "clipboard", "->", "saveTo", "(", "$", "environment", ")", ";", "if", "(", "false", "===", "$", "redirect", ")", "{", "return", ";", "}", "$", "addToUrlEvent", "=", "new", "AddToUrlEvent", "(", "'clipboard-item=&original-act=&act='", ".", "$", "input", "->", "getParameter", "(", "'original-act'", ")", ")", ";", "$", "eventDispatcher", "->", "dispatch", "(", "ContaoEvents", "::", "BACKEND_ADD_TO_URL", ",", "$", "addToUrlEvent", ")", ";", "$", "redirectEvent", "=", "new", "RedirectEvent", "(", "$", "addToUrlEvent", "->", "getUrl", "(", ")", ")", ";", "$", "eventDispatcher", "->", "dispatch", "(", "ContaoEvents", "::", "CONTROLLER_REDIRECT", ",", "$", "redirectEvent", ")", ";", "}" ]
Handle clear clipboard action. @param ActionEvent $event The action event. @param bool $redirect Redirect after clear the clipboard. @return void
[ "Handle", "clear", "clipboard", "action", "." ]
bf59fc2085cc848c564e40324dee14ef2897faa6
https://github.com/contao-community-alliance/dc-general/blob/bf59fc2085cc848c564e40324dee14ef2897faa6/src/Contao/View/Contao2BackendView/Controller/ClipboardController.php#L164-L187
train
contao-community-alliance/dc-general
src/Contao/View/Contao2BackendView/Controller/ClipboardController.php
ClipboardController.translateActionName
private function translateActionName($actionName) { switch ($actionName) { case 'create': return Item::CREATE; case 'cut': return Item::CUT; case 'copy': return Item::COPY; case 'deepcopy': return Item::DEEP_COPY; default: } return null; }
php
private function translateActionName($actionName) { switch ($actionName) { case 'create': return Item::CREATE; case 'cut': return Item::CUT; case 'copy': return Item::COPY; case 'deepcopy': return Item::DEEP_COPY; default: } return null; }
[ "private", "function", "translateActionName", "(", "$", "actionName", ")", "{", "switch", "(", "$", "actionName", ")", "{", "case", "'create'", ":", "return", "Item", "::", "CREATE", ";", "case", "'cut'", ":", "return", "Item", "::", "CUT", ";", "case", "'copy'", ":", "return", "Item", "::", "COPY", ";", "case", "'deepcopy'", ":", "return", "Item", "::", "DEEP_COPY", ";", "default", ":", "}", "return", "null", ";", "}" ]
Translate an action name to a clipboard action name. @param string $actionName The action name to translate. @return null|string
[ "Translate", "an", "action", "name", "to", "a", "clipboard", "action", "name", "." ]
bf59fc2085cc848c564e40324dee14ef2897faa6
https://github.com/contao-community-alliance/dc-general/blob/bf59fc2085cc848c564e40324dee14ef2897faa6/src/Contao/View/Contao2BackendView/Controller/ClipboardController.php#L196-L210
train
contao-community-alliance/dc-general
src/Contao/View/Contao2BackendView/Controller/ClipboardController.php
ClipboardController.addToClipboard
private function addToClipboard(ActionEvent $event) { $actionName = $event->getAction()->getName(); $environment = $event->getEnvironment(); $input = $environment->getInputProvider(); $clipboard = $environment->getClipboard(); $parentIdRaw = $input->getParameter('pid'); if ($parentIdRaw) { $parentId = ModelId::fromSerialized($parentIdRaw); } else { $parentId = null; } if (!($clipboardActionName = $this->translateActionName($actionName))) { return; } if ('create' === $actionName) { if ($this->isAddingAllowed($environment)) { return; } $providerName = $environment->getDataDefinition()->getBasicDefinition()->getDataProvider(); $item = new UnsavedItem($clipboardActionName, $parentId, $providerName); // Remove other create items, there can only be one create item in the clipboard or many others $clipboard->clear(); } else { $modelIdRaw = $input->getParameter('source'); $modelId = ModelId::fromSerialized($modelIdRaw); // If edit several don´t remove items from the clipboard. $this->removeItemsFromClipboard($event); // Only push item to clipboard if manual sorting is used. if (Item::COPY === $clipboardActionName && !ViewHelpers::getManualSortingProperty($environment)) { return; } // create the new item $item = new Item($clipboardActionName, $parentId, $modelId); } // If edit several don´t redirect do home and push item to the clipboard. if ('select' === $input->getParameter('act')) { $clipboard->push($item)->saveTo($environment); return; } // Let the clipboard save it's values persistent. $clipboard->clear()->push($item)->saveTo($environment); ViewHelpers::redirectHome($environment); }
php
private function addToClipboard(ActionEvent $event) { $actionName = $event->getAction()->getName(); $environment = $event->getEnvironment(); $input = $environment->getInputProvider(); $clipboard = $environment->getClipboard(); $parentIdRaw = $input->getParameter('pid'); if ($parentIdRaw) { $parentId = ModelId::fromSerialized($parentIdRaw); } else { $parentId = null; } if (!($clipboardActionName = $this->translateActionName($actionName))) { return; } if ('create' === $actionName) { if ($this->isAddingAllowed($environment)) { return; } $providerName = $environment->getDataDefinition()->getBasicDefinition()->getDataProvider(); $item = new UnsavedItem($clipboardActionName, $parentId, $providerName); // Remove other create items, there can only be one create item in the clipboard or many others $clipboard->clear(); } else { $modelIdRaw = $input->getParameter('source'); $modelId = ModelId::fromSerialized($modelIdRaw); // If edit several don´t remove items from the clipboard. $this->removeItemsFromClipboard($event); // Only push item to clipboard if manual sorting is used. if (Item::COPY === $clipboardActionName && !ViewHelpers::getManualSortingProperty($environment)) { return; } // create the new item $item = new Item($clipboardActionName, $parentId, $modelId); } // If edit several don´t redirect do home and push item to the clipboard. if ('select' === $input->getParameter('act')) { $clipboard->push($item)->saveTo($environment); return; } // Let the clipboard save it's values persistent. $clipboard->clear()->push($item)->saveTo($environment); ViewHelpers::redirectHome($environment); }
[ "private", "function", "addToClipboard", "(", "ActionEvent", "$", "event", ")", "{", "$", "actionName", "=", "$", "event", "->", "getAction", "(", ")", "->", "getName", "(", ")", ";", "$", "environment", "=", "$", "event", "->", "getEnvironment", "(", ")", ";", "$", "input", "=", "$", "environment", "->", "getInputProvider", "(", ")", ";", "$", "clipboard", "=", "$", "environment", "->", "getClipboard", "(", ")", ";", "$", "parentIdRaw", "=", "$", "input", "->", "getParameter", "(", "'pid'", ")", ";", "if", "(", "$", "parentIdRaw", ")", "{", "$", "parentId", "=", "ModelId", "::", "fromSerialized", "(", "$", "parentIdRaw", ")", ";", "}", "else", "{", "$", "parentId", "=", "null", ";", "}", "if", "(", "!", "(", "$", "clipboardActionName", "=", "$", "this", "->", "translateActionName", "(", "$", "actionName", ")", ")", ")", "{", "return", ";", "}", "if", "(", "'create'", "===", "$", "actionName", ")", "{", "if", "(", "$", "this", "->", "isAddingAllowed", "(", "$", "environment", ")", ")", "{", "return", ";", "}", "$", "providerName", "=", "$", "environment", "->", "getDataDefinition", "(", ")", "->", "getBasicDefinition", "(", ")", "->", "getDataProvider", "(", ")", ";", "$", "item", "=", "new", "UnsavedItem", "(", "$", "clipboardActionName", ",", "$", "parentId", ",", "$", "providerName", ")", ";", "// Remove other create items, there can only be one create item in the clipboard or many others", "$", "clipboard", "->", "clear", "(", ")", ";", "}", "else", "{", "$", "modelIdRaw", "=", "$", "input", "->", "getParameter", "(", "'source'", ")", ";", "$", "modelId", "=", "ModelId", "::", "fromSerialized", "(", "$", "modelIdRaw", ")", ";", "// If edit several don´t remove items from the clipboard.", "$", "this", "->", "removeItemsFromClipboard", "(", "$", "event", ")", ";", "// Only push item to clipboard if manual sorting is used.", "if", "(", "Item", "::", "COPY", "===", "$", "clipboardActionName", "&&", "!", "ViewHelpers", "::", "getManualSortingProperty", "(", "$", "environment", ")", ")", "{", "return", ";", "}", "// create the new item", "$", "item", "=", "new", "Item", "(", "$", "clipboardActionName", ",", "$", "parentId", ",", "$", "modelId", ")", ";", "}", "// If edit several don´t redirect do home and push item to the clipboard.", "if", "(", "'select'", "===", "$", "input", "->", "getParameter", "(", "'act'", ")", ")", "{", "$", "clipboard", "->", "push", "(", "$", "item", ")", "->", "saveTo", "(", "$", "environment", ")", ";", "return", ";", "}", "// Let the clipboard save it's values persistent.", "$", "clipboard", "->", "clear", "(", ")", "->", "push", "(", "$", "item", ")", "->", "saveTo", "(", "$", "environment", ")", ";", "ViewHelpers", "::", "redirectHome", "(", "$", "environment", ")", ";", "}" ]
Handle "old" add to clipboard actions. @param ActionEvent $event The action event. @return void
[ "Handle", "old", "add", "to", "clipboard", "actions", "." ]
bf59fc2085cc848c564e40324dee14ef2897faa6
https://github.com/contao-community-alliance/dc-general/blob/bf59fc2085cc848c564e40324dee14ef2897faa6/src/Contao/View/Contao2BackendView/Controller/ClipboardController.php#L219-L274
train
contao-community-alliance/dc-general
src/Contao/View/Contao2BackendView/Controller/ClipboardController.php
ClipboardController.isAddingAllowed
protected function isAddingAllowed(EnvironmentInterface $environment) { $inputProvider = $environment->getInputProvider(); // No manual sorting property defined, no need to add it to the clipboard. // Or we already have an after or into attribute, a handler can pick it up. return (!ViewHelpers::getManualSortingProperty($environment) || $inputProvider->hasParameter('after') || $inputProvider->hasParameter('into') ); }
php
protected function isAddingAllowed(EnvironmentInterface $environment) { $inputProvider = $environment->getInputProvider(); // No manual sorting property defined, no need to add it to the clipboard. // Or we already have an after or into attribute, a handler can pick it up. return (!ViewHelpers::getManualSortingProperty($environment) || $inputProvider->hasParameter('after') || $inputProvider->hasParameter('into') ); }
[ "protected", "function", "isAddingAllowed", "(", "EnvironmentInterface", "$", "environment", ")", "{", "$", "inputProvider", "=", "$", "environment", "->", "getInputProvider", "(", ")", ";", "// No manual sorting property defined, no need to add it to the clipboard.", "// Or we already have an after or into attribute, a handler can pick it up.", "return", "(", "!", "ViewHelpers", "::", "getManualSortingProperty", "(", "$", "environment", ")", "||", "$", "inputProvider", "->", "hasParameter", "(", "'after'", ")", "||", "$", "inputProvider", "->", "hasParameter", "(", "'into'", ")", ")", ";", "}" ]
Is adding to the clipboard allowed. @param EnvironmentInterface $environment The environment. @return bool
[ "Is", "adding", "to", "the", "clipboard", "allowed", "." ]
bf59fc2085cc848c564e40324dee14ef2897faa6
https://github.com/contao-community-alliance/dc-general/blob/bf59fc2085cc848c564e40324dee14ef2897faa6/src/Contao/View/Contao2BackendView/Controller/ClipboardController.php#L283-L293
train
contao-community-alliance/dc-general
src/Contao/View/Contao2BackendView/Controller/ClipboardController.php
ClipboardController.handleView
public function handleView(ViewEvent $event) { if (!$this->scopeDeterminator->currentScopeIsBackend()) { return; } if (DcGeneralViews::CLIPBOARD !== $event->getViewName()) { return; } $environment = $event->getEnvironment(); $input = $environment->getInputProvider(); $eventDispatcher = $environment->getEventDispatcher(); $basicDefinition = $environment->getDataDefinition()->getBasicDefinition(); $filter = new Filter(); $filter->andModelIsFromProvider($basicDefinition->getDataProvider()); if ($parentProviderName = $basicDefinition->getParentDataProvider()) { $filter->andParentIsFromProvider($parentProviderName); } else { $filter->andHasNoParent(); } $options = []; foreach ($environment->getClipboard()->fetch($filter) as $item) { $modelId = $item->getModelId(); $dataProvider = $environment->getDataProvider($item->getDataProviderName()); if ($modelId) { $config = $dataProvider->getEmptyConfig(); $config->setId($modelId->getId()); $model = $dataProvider->fetch($config); // The model might have been deleted meanwhile. if (!$model) { continue; } $formatModelLabelEvent = new FormatModelLabelEvent($environment, $model); $eventDispatcher->dispatch(DcGeneralEvents::FORMAT_MODEL_LABEL, $formatModelLabelEvent); $label = $formatModelLabelEvent->getLabel(); $label = \array_shift($label); $label = $label['content']; } else { $model = $dataProvider->getEmptyModel(); $label = $environment->getTranslator()->translate('new.0', $item->getDataProviderName()); } $options[$item->getClipboardId()] = ['item' => $item, 'model' => $model, 'label' => $label]; } $inputAction = $input->getParameter('act'); $addToUrlEvent = new AddToUrlEvent('act=clear-clipboard&original-act=' . $inputAction); $eventDispatcher->dispatch(ContaoEvents::BACKEND_ADD_TO_URL, $addToUrlEvent); $clearUrl = $addToUrlEvent->getUrl(); $addToUrlEvent = new AddToUrlEvent( 'clipboard-item=%id%&act=clear-clipboard&original-act=' . $inputAction ); $eventDispatcher->dispatch(ContaoEvents::BACKEND_ADD_TO_URL, $addToUrlEvent); $clearItemUrl = $addToUrlEvent->getUrl(); $template = new ContaoBackendViewTemplate('dcbe_general_clipboard'); $template ->set('environment', $environment) ->set('options', $options) ->set('clearUrl', $clearUrl) ->set('clearItemUrl', $clearItemUrl); $event->setResponse($template->parse()); }
php
public function handleView(ViewEvent $event) { if (!$this->scopeDeterminator->currentScopeIsBackend()) { return; } if (DcGeneralViews::CLIPBOARD !== $event->getViewName()) { return; } $environment = $event->getEnvironment(); $input = $environment->getInputProvider(); $eventDispatcher = $environment->getEventDispatcher(); $basicDefinition = $environment->getDataDefinition()->getBasicDefinition(); $filter = new Filter(); $filter->andModelIsFromProvider($basicDefinition->getDataProvider()); if ($parentProviderName = $basicDefinition->getParentDataProvider()) { $filter->andParentIsFromProvider($parentProviderName); } else { $filter->andHasNoParent(); } $options = []; foreach ($environment->getClipboard()->fetch($filter) as $item) { $modelId = $item->getModelId(); $dataProvider = $environment->getDataProvider($item->getDataProviderName()); if ($modelId) { $config = $dataProvider->getEmptyConfig(); $config->setId($modelId->getId()); $model = $dataProvider->fetch($config); // The model might have been deleted meanwhile. if (!$model) { continue; } $formatModelLabelEvent = new FormatModelLabelEvent($environment, $model); $eventDispatcher->dispatch(DcGeneralEvents::FORMAT_MODEL_LABEL, $formatModelLabelEvent); $label = $formatModelLabelEvent->getLabel(); $label = \array_shift($label); $label = $label['content']; } else { $model = $dataProvider->getEmptyModel(); $label = $environment->getTranslator()->translate('new.0', $item->getDataProviderName()); } $options[$item->getClipboardId()] = ['item' => $item, 'model' => $model, 'label' => $label]; } $inputAction = $input->getParameter('act'); $addToUrlEvent = new AddToUrlEvent('act=clear-clipboard&original-act=' . $inputAction); $eventDispatcher->dispatch(ContaoEvents::BACKEND_ADD_TO_URL, $addToUrlEvent); $clearUrl = $addToUrlEvent->getUrl(); $addToUrlEvent = new AddToUrlEvent( 'clipboard-item=%id%&act=clear-clipboard&original-act=' . $inputAction ); $eventDispatcher->dispatch(ContaoEvents::BACKEND_ADD_TO_URL, $addToUrlEvent); $clearItemUrl = $addToUrlEvent->getUrl(); $template = new ContaoBackendViewTemplate('dcbe_general_clipboard'); $template ->set('environment', $environment) ->set('options', $options) ->set('clearUrl', $clearUrl) ->set('clearItemUrl', $clearItemUrl); $event->setResponse($template->parse()); }
[ "public", "function", "handleView", "(", "ViewEvent", "$", "event", ")", "{", "if", "(", "!", "$", "this", "->", "scopeDeterminator", "->", "currentScopeIsBackend", "(", ")", ")", "{", "return", ";", "}", "if", "(", "DcGeneralViews", "::", "CLIPBOARD", "!==", "$", "event", "->", "getViewName", "(", ")", ")", "{", "return", ";", "}", "$", "environment", "=", "$", "event", "->", "getEnvironment", "(", ")", ";", "$", "input", "=", "$", "environment", "->", "getInputProvider", "(", ")", ";", "$", "eventDispatcher", "=", "$", "environment", "->", "getEventDispatcher", "(", ")", ";", "$", "basicDefinition", "=", "$", "environment", "->", "getDataDefinition", "(", ")", "->", "getBasicDefinition", "(", ")", ";", "$", "filter", "=", "new", "Filter", "(", ")", ";", "$", "filter", "->", "andModelIsFromProvider", "(", "$", "basicDefinition", "->", "getDataProvider", "(", ")", ")", ";", "if", "(", "$", "parentProviderName", "=", "$", "basicDefinition", "->", "getParentDataProvider", "(", ")", ")", "{", "$", "filter", "->", "andParentIsFromProvider", "(", "$", "parentProviderName", ")", ";", "}", "else", "{", "$", "filter", "->", "andHasNoParent", "(", ")", ";", "}", "$", "options", "=", "[", "]", ";", "foreach", "(", "$", "environment", "->", "getClipboard", "(", ")", "->", "fetch", "(", "$", "filter", ")", "as", "$", "item", ")", "{", "$", "modelId", "=", "$", "item", "->", "getModelId", "(", ")", ";", "$", "dataProvider", "=", "$", "environment", "->", "getDataProvider", "(", "$", "item", "->", "getDataProviderName", "(", ")", ")", ";", "if", "(", "$", "modelId", ")", "{", "$", "config", "=", "$", "dataProvider", "->", "getEmptyConfig", "(", ")", ";", "$", "config", "->", "setId", "(", "$", "modelId", "->", "getId", "(", ")", ")", ";", "$", "model", "=", "$", "dataProvider", "->", "fetch", "(", "$", "config", ")", ";", "// The model might have been deleted meanwhile.", "if", "(", "!", "$", "model", ")", "{", "continue", ";", "}", "$", "formatModelLabelEvent", "=", "new", "FormatModelLabelEvent", "(", "$", "environment", ",", "$", "model", ")", ";", "$", "eventDispatcher", "->", "dispatch", "(", "DcGeneralEvents", "::", "FORMAT_MODEL_LABEL", ",", "$", "formatModelLabelEvent", ")", ";", "$", "label", "=", "$", "formatModelLabelEvent", "->", "getLabel", "(", ")", ";", "$", "label", "=", "\\", "array_shift", "(", "$", "label", ")", ";", "$", "label", "=", "$", "label", "[", "'content'", "]", ";", "}", "else", "{", "$", "model", "=", "$", "dataProvider", "->", "getEmptyModel", "(", ")", ";", "$", "label", "=", "$", "environment", "->", "getTranslator", "(", ")", "->", "translate", "(", "'new.0'", ",", "$", "item", "->", "getDataProviderName", "(", ")", ")", ";", "}", "$", "options", "[", "$", "item", "->", "getClipboardId", "(", ")", "]", "=", "[", "'item'", "=>", "$", "item", ",", "'model'", "=>", "$", "model", ",", "'label'", "=>", "$", "label", "]", ";", "}", "$", "inputAction", "=", "$", "input", "->", "getParameter", "(", "'act'", ")", ";", "$", "addToUrlEvent", "=", "new", "AddToUrlEvent", "(", "'act=clear-clipboard&original-act='", ".", "$", "inputAction", ")", ";", "$", "eventDispatcher", "->", "dispatch", "(", "ContaoEvents", "::", "BACKEND_ADD_TO_URL", ",", "$", "addToUrlEvent", ")", ";", "$", "clearUrl", "=", "$", "addToUrlEvent", "->", "getUrl", "(", ")", ";", "$", "addToUrlEvent", "=", "new", "AddToUrlEvent", "(", "'clipboard-item=%id%&act=clear-clipboard&original-act='", ".", "$", "inputAction", ")", ";", "$", "eventDispatcher", "->", "dispatch", "(", "ContaoEvents", "::", "BACKEND_ADD_TO_URL", ",", "$", "addToUrlEvent", ")", ";", "$", "clearItemUrl", "=", "$", "addToUrlEvent", "->", "getUrl", "(", ")", ";", "$", "template", "=", "new", "ContaoBackendViewTemplate", "(", "'dcbe_general_clipboard'", ")", ";", "$", "template", "->", "set", "(", "'environment'", ",", "$", "environment", ")", "->", "set", "(", "'options'", ",", "$", "options", ")", "->", "set", "(", "'clearUrl'", ",", "$", "clearUrl", ")", "->", "set", "(", "'clearItemUrl'", ",", "$", "clearItemUrl", ")", ";", "$", "event", "->", "setResponse", "(", "$", "template", "->", "parse", "(", ")", ")", ";", "}" ]
Handle view. @param ViewEvent $event The view event. @return void
[ "Handle", "view", "." ]
bf59fc2085cc848c564e40324dee14ef2897faa6
https://github.com/contao-community-alliance/dc-general/blob/bf59fc2085cc848c564e40324dee14ef2897faa6/src/Contao/View/Contao2BackendView/Controller/ClipboardController.php#L302-L372
train
contao-community-alliance/dc-general
src/Contao/Callback/Callbacks.php
Callbacks.evaluateCallback
protected static function evaluateCallback($callback) { if (\is_array($callback) && (2 === \count($callback)) && \is_string($callback[0]) && \is_string($callback[1])) { $serviceCallback = static::evaluateServiceCallback($callback); if ($serviceCallback[0] !== $callback[0]) { return $serviceCallback; } $class = new \ReflectionClass($callback[0]); // Ff the method is static, do not create an instance. if ($class->hasMethod($callback[1]) && $class->getMethod($callback[1])->isStatic()) { return $callback; } // Fetch singleton instance. if ($class->hasMethod('getInstance')) { $getInstanceMethod = $class->getMethod('getInstance'); if ($getInstanceMethod->isStatic()) { $callback[0] = $getInstanceMethod->invoke(null); return $callback; } } // Create a new instance. $constructor = $class->getConstructor(); if (!$constructor || $constructor->isPublic()) { $callback[0] = $class->newInstance(); } else { // Graceful fallback, to prevent access violation to non-public \Backend::__construct(). $callback[0] = $class->newInstanceWithoutConstructor(); $constructor->setAccessible(true); $constructor->invoke($callback[0]); } } return $callback; }
php
protected static function evaluateCallback($callback) { if (\is_array($callback) && (2 === \count($callback)) && \is_string($callback[0]) && \is_string($callback[1])) { $serviceCallback = static::evaluateServiceCallback($callback); if ($serviceCallback[0] !== $callback[0]) { return $serviceCallback; } $class = new \ReflectionClass($callback[0]); // Ff the method is static, do not create an instance. if ($class->hasMethod($callback[1]) && $class->getMethod($callback[1])->isStatic()) { return $callback; } // Fetch singleton instance. if ($class->hasMethod('getInstance')) { $getInstanceMethod = $class->getMethod('getInstance'); if ($getInstanceMethod->isStatic()) { $callback[0] = $getInstanceMethod->invoke(null); return $callback; } } // Create a new instance. $constructor = $class->getConstructor(); if (!$constructor || $constructor->isPublic()) { $callback[0] = $class->newInstance(); } else { // Graceful fallback, to prevent access violation to non-public \Backend::__construct(). $callback[0] = $class->newInstanceWithoutConstructor(); $constructor->setAccessible(true); $constructor->invoke($callback[0]); } } return $callback; }
[ "protected", "static", "function", "evaluateCallback", "(", "$", "callback", ")", "{", "if", "(", "\\", "is_array", "(", "$", "callback", ")", "&&", "(", "2", "===", "\\", "count", "(", "$", "callback", ")", ")", "&&", "\\", "is_string", "(", "$", "callback", "[", "0", "]", ")", "&&", "\\", "is_string", "(", "$", "callback", "[", "1", "]", ")", ")", "{", "$", "serviceCallback", "=", "static", "::", "evaluateServiceCallback", "(", "$", "callback", ")", ";", "if", "(", "$", "serviceCallback", "[", "0", "]", "!==", "$", "callback", "[", "0", "]", ")", "{", "return", "$", "serviceCallback", ";", "}", "$", "class", "=", "new", "\\", "ReflectionClass", "(", "$", "callback", "[", "0", "]", ")", ";", "// Ff the method is static, do not create an instance.", "if", "(", "$", "class", "->", "hasMethod", "(", "$", "callback", "[", "1", "]", ")", "&&", "$", "class", "->", "getMethod", "(", "$", "callback", "[", "1", "]", ")", "->", "isStatic", "(", ")", ")", "{", "return", "$", "callback", ";", "}", "// Fetch singleton instance.", "if", "(", "$", "class", "->", "hasMethod", "(", "'getInstance'", ")", ")", "{", "$", "getInstanceMethod", "=", "$", "class", "->", "getMethod", "(", "'getInstance'", ")", ";", "if", "(", "$", "getInstanceMethod", "->", "isStatic", "(", ")", ")", "{", "$", "callback", "[", "0", "]", "=", "$", "getInstanceMethod", "->", "invoke", "(", "null", ")", ";", "return", "$", "callback", ";", "}", "}", "// Create a new instance.", "$", "constructor", "=", "$", "class", "->", "getConstructor", "(", ")", ";", "if", "(", "!", "$", "constructor", "||", "$", "constructor", "->", "isPublic", "(", ")", ")", "{", "$", "callback", "[", "0", "]", "=", "$", "class", "->", "newInstance", "(", ")", ";", "}", "else", "{", "// Graceful fallback, to prevent access violation to non-public \\Backend::__construct().", "$", "callback", "[", "0", "]", "=", "$", "class", "->", "newInstanceWithoutConstructor", "(", ")", ";", "$", "constructor", "->", "setAccessible", "(", "true", ")", ";", "$", "constructor", "->", "invoke", "(", "$", "callback", "[", "0", "]", ")", ";", "}", "}", "return", "$", "callback", ";", "}" ]
Evaluate the callback and create an object instance if required and possible. @param array|callable $callback The callback to invoke. @return array|callable @SuppressWarnings(PHPMD.CyclomaticComplexity)
[ "Evaluate", "the", "callback", "and", "create", "an", "object", "instance", "if", "required", "and", "possible", "." ]
bf59fc2085cc848c564e40324dee14ef2897faa6
https://github.com/contao-community-alliance/dc-general/blob/bf59fc2085cc848c564e40324dee14ef2897faa6/src/Contao/Callback/Callbacks.php#L108-L147
train
contao-community-alliance/dc-general
src/Contao/Callback/Callbacks.php
Callbacks.evaluateServiceCallback
private static function evaluateServiceCallback($callback) { $container = System::getContainer(); if ($container->has($callback[0]) && ((false !== \strpos($callback[0], '\\')) || !\class_exists($callback[0])) ) { $callback[0] = $container->get($callback[0]); return $callback; } if ($container instanceof Container && isset($container->getRemovedIds()[$callback[0]])) { throw new ServiceNotFoundException( $callback[0], null, null, [], sprintf( 'The "%s" service or alias has been removed or inlined when the container was compiled. ' . 'You should either make it public, ' . 'or stop using the container directly and use dependency injection instead.', $callback[0] ) ); } return $callback; }
php
private static function evaluateServiceCallback($callback) { $container = System::getContainer(); if ($container->has($callback[0]) && ((false !== \strpos($callback[0], '\\')) || !\class_exists($callback[0])) ) { $callback[0] = $container->get($callback[0]); return $callback; } if ($container instanceof Container && isset($container->getRemovedIds()[$callback[0]])) { throw new ServiceNotFoundException( $callback[0], null, null, [], sprintf( 'The "%s" service or alias has been removed or inlined when the container was compiled. ' . 'You should either make it public, ' . 'or stop using the container directly and use dependency injection instead.', $callback[0] ) ); } return $callback; }
[ "private", "static", "function", "evaluateServiceCallback", "(", "$", "callback", ")", "{", "$", "container", "=", "System", "::", "getContainer", "(", ")", ";", "if", "(", "$", "container", "->", "has", "(", "$", "callback", "[", "0", "]", ")", "&&", "(", "(", "false", "!==", "\\", "strpos", "(", "$", "callback", "[", "0", "]", ",", "'\\\\'", ")", ")", "||", "!", "\\", "class_exists", "(", "$", "callback", "[", "0", "]", ")", ")", ")", "{", "$", "callback", "[", "0", "]", "=", "$", "container", "->", "get", "(", "$", "callback", "[", "0", "]", ")", ";", "return", "$", "callback", ";", "}", "if", "(", "$", "container", "instanceof", "Container", "&&", "isset", "(", "$", "container", "->", "getRemovedIds", "(", ")", "[", "$", "callback", "[", "0", "]", "]", ")", ")", "{", "throw", "new", "ServiceNotFoundException", "(", "$", "callback", "[", "0", "]", ",", "null", ",", "null", ",", "[", "]", ",", "sprintf", "(", "'The \"%s\" service or alias has been removed or inlined when the container was compiled. '", ".", "'You should either make it public, '", ".", "'or stop using the container directly and use dependency injection instead.'", ",", "$", "callback", "[", "0", "]", ")", ")", ";", "}", "return", "$", "callback", ";", "}" ]
Evaluate the callback from the service container. @param array $callback The callback. @return array @throws ServiceNotFoundException When service is not public or removed.
[ "Evaluate", "the", "callback", "from", "the", "service", "container", "." ]
bf59fc2085cc848c564e40324dee14ef2897faa6
https://github.com/contao-community-alliance/dc-general/blob/bf59fc2085cc848c564e40324dee14ef2897faa6/src/Contao/Callback/Callbacks.php#L158-L186
train
contao-community-alliance/dc-general
src/Contao/Dca/Palette/LegacyPalettesParser.php
LegacyPalettesParser.parse
public function parse(array $palettes, array $subPalettes = [], PaletteCollectionInterface $collection = null) { if (isset($palettes['__selector__'])) { $selectorFieldNames = $palettes['__selector__']; unset($palettes['__selector__']); } else { $selectorFieldNames = []; } return $this->parsePalettes( $palettes, $this->parseSubpalettes($subPalettes, $selectorFieldNames), $selectorFieldNames, $collection ); }
php
public function parse(array $palettes, array $subPalettes = [], PaletteCollectionInterface $collection = null) { if (isset($palettes['__selector__'])) { $selectorFieldNames = $palettes['__selector__']; unset($palettes['__selector__']); } else { $selectorFieldNames = []; } return $this->parsePalettes( $palettes, $this->parseSubpalettes($subPalettes, $selectorFieldNames), $selectorFieldNames, $collection ); }
[ "public", "function", "parse", "(", "array", "$", "palettes", ",", "array", "$", "subPalettes", "=", "[", "]", ",", "PaletteCollectionInterface", "$", "collection", "=", "null", ")", "{", "if", "(", "isset", "(", "$", "palettes", "[", "'__selector__'", "]", ")", ")", "{", "$", "selectorFieldNames", "=", "$", "palettes", "[", "'__selector__'", "]", ";", "unset", "(", "$", "palettes", "[", "'__selector__'", "]", ")", ";", "}", "else", "{", "$", "selectorFieldNames", "=", "[", "]", ";", "}", "return", "$", "this", "->", "parsePalettes", "(", "$", "palettes", ",", "$", "this", "->", "parseSubpalettes", "(", "$", "subPalettes", ",", "$", "selectorFieldNames", ")", ",", "$", "selectorFieldNames", ",", "$", "collection", ")", ";", "}" ]
Parse the palette and sub palette array and create a complete palette collection. @param array(string => string) $palettes The palettes from the DCA. @param array(string => string) $subPalettes The sub palettes from the DCA [optional]. @param PaletteCollectionInterface|null $collection The palette collection to populate [optional]. @return PaletteCollectionInterface
[ "Parse", "the", "palette", "and", "sub", "palette", "array", "and", "create", "a", "complete", "palette", "collection", "." ]
bf59fc2085cc848c564e40324dee14ef2897faa6
https://github.com/contao-community-alliance/dc-general/blob/bf59fc2085cc848c564e40324dee14ef2897faa6/src/Contao/Dca/Palette/LegacyPalettesParser.php#L58-L73
train
contao-community-alliance/dc-general
src/Contao/Dca/Palette/LegacyPalettesParser.php
LegacyPalettesParser.parsePalettes
public function parsePalettes( array $palettes, array $subPaletteProperties = [], array $selectorFieldNames = [], PaletteCollectionInterface $collection = null ) { if (!$collection) { $collection = new PaletteCollection(); } if (isset($palettes['__selector__'])) { $selectorFieldNames = \array_merge($selectorFieldNames, $palettes['__selector__']); $selectorFieldNames = \array_unique($selectorFieldNames); unset($palettes['__selector__']); } foreach ($palettes as $selector => $fields) { // Fields list must be a string. if (!\is_string($fields)) { continue; } if ($collection->hasPaletteByName($selector)) { $palette = $collection->getPaletteByName($selector); $this->parsePalette( $selector, $fields, $subPaletteProperties, $selectorFieldNames, $palette ); continue; } $palette = $this->parsePalette( $selector, $fields, $subPaletteProperties, $selectorFieldNames ); $collection->addPalette($palette); } return $collection; }
php
public function parsePalettes( array $palettes, array $subPaletteProperties = [], array $selectorFieldNames = [], PaletteCollectionInterface $collection = null ) { if (!$collection) { $collection = new PaletteCollection(); } if (isset($palettes['__selector__'])) { $selectorFieldNames = \array_merge($selectorFieldNames, $palettes['__selector__']); $selectorFieldNames = \array_unique($selectorFieldNames); unset($palettes['__selector__']); } foreach ($palettes as $selector => $fields) { // Fields list must be a string. if (!\is_string($fields)) { continue; } if ($collection->hasPaletteByName($selector)) { $palette = $collection->getPaletteByName($selector); $this->parsePalette( $selector, $fields, $subPaletteProperties, $selectorFieldNames, $palette ); continue; } $palette = $this->parsePalette( $selector, $fields, $subPaletteProperties, $selectorFieldNames ); $collection->addPalette($palette); } return $collection; }
[ "public", "function", "parsePalettes", "(", "array", "$", "palettes", ",", "array", "$", "subPaletteProperties", "=", "[", "]", ",", "array", "$", "selectorFieldNames", "=", "[", "]", ",", "PaletteCollectionInterface", "$", "collection", "=", "null", ")", "{", "if", "(", "!", "$", "collection", ")", "{", "$", "collection", "=", "new", "PaletteCollection", "(", ")", ";", "}", "if", "(", "isset", "(", "$", "palettes", "[", "'__selector__'", "]", ")", ")", "{", "$", "selectorFieldNames", "=", "\\", "array_merge", "(", "$", "selectorFieldNames", ",", "$", "palettes", "[", "'__selector__'", "]", ")", ";", "$", "selectorFieldNames", "=", "\\", "array_unique", "(", "$", "selectorFieldNames", ")", ";", "unset", "(", "$", "palettes", "[", "'__selector__'", "]", ")", ";", "}", "foreach", "(", "$", "palettes", "as", "$", "selector", "=>", "$", "fields", ")", "{", "// Fields list must be a string.", "if", "(", "!", "\\", "is_string", "(", "$", "fields", ")", ")", "{", "continue", ";", "}", "if", "(", "$", "collection", "->", "hasPaletteByName", "(", "$", "selector", ")", ")", "{", "$", "palette", "=", "$", "collection", "->", "getPaletteByName", "(", "$", "selector", ")", ";", "$", "this", "->", "parsePalette", "(", "$", "selector", ",", "$", "fields", ",", "$", "subPaletteProperties", ",", "$", "selectorFieldNames", ",", "$", "palette", ")", ";", "continue", ";", "}", "$", "palette", "=", "$", "this", "->", "parsePalette", "(", "$", "selector", ",", "$", "fields", ",", "$", "subPaletteProperties", ",", "$", "selectorFieldNames", ")", ";", "$", "collection", "->", "addPalette", "(", "$", "palette", ")", ";", "}", "return", "$", "collection", ";", "}" ]
Parse the given palettes. @param array(string => string) $palettes The array of palettes, e.g. <code>array('default' => '{title_legend},title')</code>. @param array(string => string) $subPaletteProperties Mapped array from subpalette [optional]. @param array $selectorFieldNames List of names of the properties to be used as selector [optional]. @param PaletteCollectionInterface $collection The palette collection to populate [optional]. @return PaletteCollectionInterface
[ "Parse", "the", "given", "palettes", "." ]
bf59fc2085cc848c564e40324dee14ef2897faa6
https://github.com/contao-community-alliance/dc-general/blob/bf59fc2085cc848c564e40324dee14ef2897faa6/src/Contao/Dca/Palette/LegacyPalettesParser.php#L87-L132
train
contao-community-alliance/dc-general
src/Contao/Dca/Palette/LegacyPalettesParser.php
LegacyPalettesParser.parsePalette
public function parsePalette( $paletteSelector, $fields, array $subPaletteProperties = [], array $selectorFieldNames = [], PaletteInterface $palette = null ) { if (!$palette) { $palette = new Palette(); $palette->setName($paletteSelector); } $palette->setCondition($this->createPaletteCondition($paletteSelector, $selectorFieldNames)); // We ignore the difference between field set (separated by ";") and fields (separated by ","). $fields = preg_split('~[;,]~', $fields); $fields = \array_map('trim', $fields); $fields = \array_filter($fields); $legend = null; foreach ($fields as $field) { if (preg_match('~^\{(.*?)(_legend)?(:hide)?\}$~', $field, $matches)) { $name = $matches[1]; if ($palette->hasLegend($name)) { $legend = $palette->getLegend($name); } else { $legend = new Legend($matches[1]); $palette->addLegend($legend); } if (\array_key_exists(3, $matches)) { $legend->setInitialVisibility(false); } continue; } // Fallback for incomplete palettes without legend, // Create an empty legend. if (!$legend) { $name = 'unnamed'; if ($palette->hasLegend($name)) { $legend = $palette->getLegend($name); } else { $legend = new Legend($matches[1]); $palette->addLegend($legend); } } // Add the current field to the legend. $property = new Property($field); $legend->addProperty($property); // Add sub palette fields to the legend. if (isset($subPaletteProperties[$field])) { foreach ($subPaletteProperties[$field] as $property) { $legend->addProperty(clone $property); } } } return $palette; }
php
public function parsePalette( $paletteSelector, $fields, array $subPaletteProperties = [], array $selectorFieldNames = [], PaletteInterface $palette = null ) { if (!$palette) { $palette = new Palette(); $palette->setName($paletteSelector); } $palette->setCondition($this->createPaletteCondition($paletteSelector, $selectorFieldNames)); // We ignore the difference between field set (separated by ";") and fields (separated by ","). $fields = preg_split('~[;,]~', $fields); $fields = \array_map('trim', $fields); $fields = \array_filter($fields); $legend = null; foreach ($fields as $field) { if (preg_match('~^\{(.*?)(_legend)?(:hide)?\}$~', $field, $matches)) { $name = $matches[1]; if ($palette->hasLegend($name)) { $legend = $palette->getLegend($name); } else { $legend = new Legend($matches[1]); $palette->addLegend($legend); } if (\array_key_exists(3, $matches)) { $legend->setInitialVisibility(false); } continue; } // Fallback for incomplete palettes without legend, // Create an empty legend. if (!$legend) { $name = 'unnamed'; if ($palette->hasLegend($name)) { $legend = $palette->getLegend($name); } else { $legend = new Legend($matches[1]); $palette->addLegend($legend); } } // Add the current field to the legend. $property = new Property($field); $legend->addProperty($property); // Add sub palette fields to the legend. if (isset($subPaletteProperties[$field])) { foreach ($subPaletteProperties[$field] as $property) { $legend->addProperty(clone $property); } } } return $palette; }
[ "public", "function", "parsePalette", "(", "$", "paletteSelector", ",", "$", "fields", ",", "array", "$", "subPaletteProperties", "=", "[", "]", ",", "array", "$", "selectorFieldNames", "=", "[", "]", ",", "PaletteInterface", "$", "palette", "=", "null", ")", "{", "if", "(", "!", "$", "palette", ")", "{", "$", "palette", "=", "new", "Palette", "(", ")", ";", "$", "palette", "->", "setName", "(", "$", "paletteSelector", ")", ";", "}", "$", "palette", "->", "setCondition", "(", "$", "this", "->", "createPaletteCondition", "(", "$", "paletteSelector", ",", "$", "selectorFieldNames", ")", ")", ";", "// We ignore the difference between field set (separated by \";\") and fields (separated by \",\").", "$", "fields", "=", "preg_split", "(", "'~[;,]~'", ",", "$", "fields", ")", ";", "$", "fields", "=", "\\", "array_map", "(", "'trim'", ",", "$", "fields", ")", ";", "$", "fields", "=", "\\", "array_filter", "(", "$", "fields", ")", ";", "$", "legend", "=", "null", ";", "foreach", "(", "$", "fields", "as", "$", "field", ")", "{", "if", "(", "preg_match", "(", "'~^\\{(.*?)(_legend)?(:hide)?\\}$~'", ",", "$", "field", ",", "$", "matches", ")", ")", "{", "$", "name", "=", "$", "matches", "[", "1", "]", ";", "if", "(", "$", "palette", "->", "hasLegend", "(", "$", "name", ")", ")", "{", "$", "legend", "=", "$", "palette", "->", "getLegend", "(", "$", "name", ")", ";", "}", "else", "{", "$", "legend", "=", "new", "Legend", "(", "$", "matches", "[", "1", "]", ")", ";", "$", "palette", "->", "addLegend", "(", "$", "legend", ")", ";", "}", "if", "(", "\\", "array_key_exists", "(", "3", ",", "$", "matches", ")", ")", "{", "$", "legend", "->", "setInitialVisibility", "(", "false", ")", ";", "}", "continue", ";", "}", "// Fallback for incomplete palettes without legend,", "// Create an empty legend.", "if", "(", "!", "$", "legend", ")", "{", "$", "name", "=", "'unnamed'", ";", "if", "(", "$", "palette", "->", "hasLegend", "(", "$", "name", ")", ")", "{", "$", "legend", "=", "$", "palette", "->", "getLegend", "(", "$", "name", ")", ";", "}", "else", "{", "$", "legend", "=", "new", "Legend", "(", "$", "matches", "[", "1", "]", ")", ";", "$", "palette", "->", "addLegend", "(", "$", "legend", ")", ";", "}", "}", "// Add the current field to the legend.", "$", "property", "=", "new", "Property", "(", "$", "field", ")", ";", "$", "legend", "->", "addProperty", "(", "$", "property", ")", ";", "// Add sub palette fields to the legend.", "if", "(", "isset", "(", "$", "subPaletteProperties", "[", "$", "field", "]", ")", ")", "{", "foreach", "(", "$", "subPaletteProperties", "[", "$", "field", "]", "as", "$", "property", ")", "{", "$", "legend", "->", "addProperty", "(", "clone", "$", "property", ")", ";", "}", "}", "}", "return", "$", "palette", ";", "}" ]
Parse a single palette. @param string $paletteSelector The selector for the palette. @param string $fields The fields contained within the palette. @param array(string => PropertyInterface) $subPaletteProperties The sub palette properties [optional]. @param array(string) $selectorFieldNames The names of all properties being used as selectors [optional]. @param PaletteInterface $palette The palette to be populated [optional]. @return Palette
[ "Parse", "a", "single", "palette", "." ]
bf59fc2085cc848c564e40324dee14ef2897faa6
https://github.com/contao-community-alliance/dc-general/blob/bf59fc2085cc848c564e40324dee14ef2897faa6/src/Contao/Dca/Palette/LegacyPalettesParser.php#L146-L208
train
contao-community-alliance/dc-general
src/Contao/Dca/Palette/LegacyPalettesParser.php
LegacyPalettesParser.createPaletteCondition
public function createPaletteCondition($paletteSelector, array $selectorFieldNames) { if ('default' === $paletteSelector) { return new DefaultPaletteCondition(); } // Legacy fallback, try to split on $selectors with optimistic suggestion of values. if (false === \strpos($paletteSelector, '|')) { foreach ($selectorFieldNames as $selectorFieldName) { $paletteSelector = \str_replace( $selectorFieldName, '|' . $selectorFieldName . '|', $paletteSelector ); } } // Extended mode, split selectors and values with "|". $paletteSelectorParts = \explode('|', $paletteSelector); $paletteSelectorParts = \array_map('trim', $paletteSelectorParts); $paletteSelectorParts = \array_filter($paletteSelectorParts); $condition = new PaletteConditionChain(); foreach ($paletteSelectorParts as $paletteSelectorPart) { // The part is a property name (checkbox like selector). if (\in_array($paletteSelectorPart, $selectorFieldNames)) { $condition->addCondition( new PalettePropertyTrueCondition($paletteSelectorPart) ); continue; } // The part is a value (but which?) (select box like selector). $orCondition = new PaletteConditionChain([], PaletteConditionChain::OR_CONJUNCTION); foreach ($selectorFieldNames as $selectorFieldName) { $orCondition->addCondition( new PalettePropertyValueCondition( $selectorFieldName, $paletteSelectorPart, true ) ); } $condition->addCondition($orCondition); } return $condition; }
php
public function createPaletteCondition($paletteSelector, array $selectorFieldNames) { if ('default' === $paletteSelector) { return new DefaultPaletteCondition(); } // Legacy fallback, try to split on $selectors with optimistic suggestion of values. if (false === \strpos($paletteSelector, '|')) { foreach ($selectorFieldNames as $selectorFieldName) { $paletteSelector = \str_replace( $selectorFieldName, '|' . $selectorFieldName . '|', $paletteSelector ); } } // Extended mode, split selectors and values with "|". $paletteSelectorParts = \explode('|', $paletteSelector); $paletteSelectorParts = \array_map('trim', $paletteSelectorParts); $paletteSelectorParts = \array_filter($paletteSelectorParts); $condition = new PaletteConditionChain(); foreach ($paletteSelectorParts as $paletteSelectorPart) { // The part is a property name (checkbox like selector). if (\in_array($paletteSelectorPart, $selectorFieldNames)) { $condition->addCondition( new PalettePropertyTrueCondition($paletteSelectorPart) ); continue; } // The part is a value (but which?) (select box like selector). $orCondition = new PaletteConditionChain([], PaletteConditionChain::OR_CONJUNCTION); foreach ($selectorFieldNames as $selectorFieldName) { $orCondition->addCondition( new PalettePropertyValueCondition( $selectorFieldName, $paletteSelectorPart, true ) ); } $condition->addCondition($orCondition); } return $condition; }
[ "public", "function", "createPaletteCondition", "(", "$", "paletteSelector", ",", "array", "$", "selectorFieldNames", ")", "{", "if", "(", "'default'", "===", "$", "paletteSelector", ")", "{", "return", "new", "DefaultPaletteCondition", "(", ")", ";", "}", "// Legacy fallback, try to split on $selectors with optimistic suggestion of values.", "if", "(", "false", "===", "\\", "strpos", "(", "$", "paletteSelector", ",", "'|'", ")", ")", "{", "foreach", "(", "$", "selectorFieldNames", "as", "$", "selectorFieldName", ")", "{", "$", "paletteSelector", "=", "\\", "str_replace", "(", "$", "selectorFieldName", ",", "'|'", ".", "$", "selectorFieldName", ".", "'|'", ",", "$", "paletteSelector", ")", ";", "}", "}", "// Extended mode, split selectors and values with \"|\".", "$", "paletteSelectorParts", "=", "\\", "explode", "(", "'|'", ",", "$", "paletteSelector", ")", ";", "$", "paletteSelectorParts", "=", "\\", "array_map", "(", "'trim'", ",", "$", "paletteSelectorParts", ")", ";", "$", "paletteSelectorParts", "=", "\\", "array_filter", "(", "$", "paletteSelectorParts", ")", ";", "$", "condition", "=", "new", "PaletteConditionChain", "(", ")", ";", "foreach", "(", "$", "paletteSelectorParts", "as", "$", "paletteSelectorPart", ")", "{", "// The part is a property name (checkbox like selector).", "if", "(", "\\", "in_array", "(", "$", "paletteSelectorPart", ",", "$", "selectorFieldNames", ")", ")", "{", "$", "condition", "->", "addCondition", "(", "new", "PalettePropertyTrueCondition", "(", "$", "paletteSelectorPart", ")", ")", ";", "continue", ";", "}", "// The part is a value (but which?) (select box like selector).", "$", "orCondition", "=", "new", "PaletteConditionChain", "(", "[", "]", ",", "PaletteConditionChain", "::", "OR_CONJUNCTION", ")", ";", "foreach", "(", "$", "selectorFieldNames", "as", "$", "selectorFieldName", ")", "{", "$", "orCondition", "->", "addCondition", "(", "new", "PalettePropertyValueCondition", "(", "$", "selectorFieldName", ",", "$", "paletteSelectorPart", ",", "true", ")", ")", ";", "}", "$", "condition", "->", "addCondition", "(", "$", "orCondition", ")", ";", "}", "return", "$", "condition", ";", "}" ]
Parse the palette selector and create the corresponding condition. @param string $paletteSelector Create the condition for the selector. @param array $selectorFieldNames The property names to be used as selectors. @return null|PaletteConditionInterface
[ "Parse", "the", "palette", "selector", "and", "create", "the", "corresponding", "condition", "." ]
bf59fc2085cc848c564e40324dee14ef2897faa6
https://github.com/contao-community-alliance/dc-general/blob/bf59fc2085cc848c564e40324dee14ef2897faa6/src/Contao/Dca/Palette/LegacyPalettesParser.php#L218-L268
train
contao-community-alliance/dc-general
src/Contao/Dca/Palette/LegacyPalettesParser.php
LegacyPalettesParser.parseSubpalettes
public function parseSubpalettes(array $subpalettes, array $selectorFieldNames = []) { $properties = []; foreach ($subpalettes as $subPaletteSelector => $childFields) { // Child fields list must be a string. if (!\is_string($childFields)) { continue; } $selectorFieldName = $this->createSubpaletteSelectorFieldName($subPaletteSelector, $selectorFieldNames); $selectorProperty = []; // For selectable sub selector. if (isset($properties[$selectorFieldName]) && (0 < \substr_count($subPaletteSelector, '_')) ) { $selectorProperty = $properties[$selectorFieldName]; } $properties[$selectorFieldName] = $this->parseSubpalette( $subPaletteSelector, $childFields, $selectorFieldNames, $selectorProperty ); } return $properties; }
php
public function parseSubpalettes(array $subpalettes, array $selectorFieldNames = []) { $properties = []; foreach ($subpalettes as $subPaletteSelector => $childFields) { // Child fields list must be a string. if (!\is_string($childFields)) { continue; } $selectorFieldName = $this->createSubpaletteSelectorFieldName($subPaletteSelector, $selectorFieldNames); $selectorProperty = []; // For selectable sub selector. if (isset($properties[$selectorFieldName]) && (0 < \substr_count($subPaletteSelector, '_')) ) { $selectorProperty = $properties[$selectorFieldName]; } $properties[$selectorFieldName] = $this->parseSubpalette( $subPaletteSelector, $childFields, $selectorFieldNames, $selectorProperty ); } return $properties; }
[ "public", "function", "parseSubpalettes", "(", "array", "$", "subpalettes", ",", "array", "$", "selectorFieldNames", "=", "[", "]", ")", "{", "$", "properties", "=", "[", "]", ";", "foreach", "(", "$", "subpalettes", "as", "$", "subPaletteSelector", "=>", "$", "childFields", ")", "{", "// Child fields list must be a string.", "if", "(", "!", "\\", "is_string", "(", "$", "childFields", ")", ")", "{", "continue", ";", "}", "$", "selectorFieldName", "=", "$", "this", "->", "createSubpaletteSelectorFieldName", "(", "$", "subPaletteSelector", ",", "$", "selectorFieldNames", ")", ";", "$", "selectorProperty", "=", "[", "]", ";", "// For selectable sub selector.", "if", "(", "isset", "(", "$", "properties", "[", "$", "selectorFieldName", "]", ")", "&&", "(", "0", "<", "\\", "substr_count", "(", "$", "subPaletteSelector", ",", "'_'", ")", ")", ")", "{", "$", "selectorProperty", "=", "$", "properties", "[", "$", "selectorFieldName", "]", ";", "}", "$", "properties", "[", "$", "selectorFieldName", "]", "=", "$", "this", "->", "parseSubpalette", "(", "$", "subPaletteSelector", ",", "$", "childFields", ",", "$", "selectorFieldNames", ",", "$", "selectorProperty", ")", ";", "}", "return", "$", "properties", ";", "}" ]
Parse the sub palettes and return the properties for each selector property. @param array $subpalettes The sub palettes to parse. @param array $selectorFieldNames Names of the selector properties [optional]. @return array(string => PropertyInterface[])
[ "Parse", "the", "sub", "palettes", "and", "return", "the", "properties", "for", "each", "selector", "property", "." ]
bf59fc2085cc848c564e40324dee14ef2897faa6
https://github.com/contao-community-alliance/dc-general/blob/bf59fc2085cc848c564e40324dee14ef2897faa6/src/Contao/Dca/Palette/LegacyPalettesParser.php#L278-L306
train
contao-community-alliance/dc-general
src/Contao/Dca/Palette/LegacyPalettesParser.php
LegacyPalettesParser.parseSubpalette
public function parseSubpalette( $subPaletteSelector, $childFields, array $selectorFieldNames = [], array $properties = [] ) { $childFields = \explode(',', $childFields); $childFields = \array_map('trim', $childFields); $condition = $this->createSubpaletteCondition($subPaletteSelector, $selectorFieldNames); foreach ($childFields as $childField) { $property = new Property($childField); $property->setVisibleCondition(clone $condition); $properties[] = $property; } return $properties; }
php
public function parseSubpalette( $subPaletteSelector, $childFields, array $selectorFieldNames = [], array $properties = [] ) { $childFields = \explode(',', $childFields); $childFields = \array_map('trim', $childFields); $condition = $this->createSubpaletteCondition($subPaletteSelector, $selectorFieldNames); foreach ($childFields as $childField) { $property = new Property($childField); $property->setVisibleCondition(clone $condition); $properties[] = $property; } return $properties; }
[ "public", "function", "parseSubpalette", "(", "$", "subPaletteSelector", ",", "$", "childFields", ",", "array", "$", "selectorFieldNames", "=", "[", "]", ",", "array", "$", "properties", "=", "[", "]", ")", "{", "$", "childFields", "=", "\\", "explode", "(", "','", ",", "$", "childFields", ")", ";", "$", "childFields", "=", "\\", "array_map", "(", "'trim'", ",", "$", "childFields", ")", ";", "$", "condition", "=", "$", "this", "->", "createSubpaletteCondition", "(", "$", "subPaletteSelector", ",", "$", "selectorFieldNames", ")", ";", "foreach", "(", "$", "childFields", "as", "$", "childField", ")", "{", "$", "property", "=", "new", "Property", "(", "$", "childField", ")", ";", "$", "property", "->", "setVisibleCondition", "(", "clone", "$", "condition", ")", ";", "$", "properties", "[", "]", "=", "$", "property", ";", "}", "return", "$", "properties", ";", "}" ]
Parse the list of sub palette fields into an array of properties. @param string $subPaletteSelector The selector in use. @param string $childFields List of the properties for the sub palette. @param array $selectorFieldNames List of the selector properties [optional]. @param array $properties List of the selector visible properties [optional]. @return PropertyInterface[]
[ "Parse", "the", "list", "of", "sub", "palette", "fields", "into", "an", "array", "of", "properties", "." ]
bf59fc2085cc848c564e40324dee14ef2897faa6
https://github.com/contao-community-alliance/dc-general/blob/bf59fc2085cc848c564e40324dee14ef2897faa6/src/Contao/Dca/Palette/LegacyPalettesParser.php#L318-L336
train
contao-community-alliance/dc-general
src/Contao/Dca/Palette/LegacyPalettesParser.php
LegacyPalettesParser.createSubpaletteSelectorFieldName
public function createSubpaletteSelectorFieldName($subPaletteSelector, array $selectorFieldNames = []) { $selectorValues = \explode('_', $subPaletteSelector); $selectorFieldName = \array_shift($selectorValues); $selectorValueCount = \count($selectorValues); while ($selectorValueCount) { if (\in_array($selectorFieldName, $selectorFieldNames)) { break; } $selectorFieldName .= '_' . \array_shift($selectorValues); $selectorValueCount = \count($selectorValues); } return $selectorFieldName; }
php
public function createSubpaletteSelectorFieldName($subPaletteSelector, array $selectorFieldNames = []) { $selectorValues = \explode('_', $subPaletteSelector); $selectorFieldName = \array_shift($selectorValues); $selectorValueCount = \count($selectorValues); while ($selectorValueCount) { if (\in_array($selectorFieldName, $selectorFieldNames)) { break; } $selectorFieldName .= '_' . \array_shift($selectorValues); $selectorValueCount = \count($selectorValues); } return $selectorFieldName; }
[ "public", "function", "createSubpaletteSelectorFieldName", "(", "$", "subPaletteSelector", ",", "array", "$", "selectorFieldNames", "=", "[", "]", ")", "{", "$", "selectorValues", "=", "\\", "explode", "(", "'_'", ",", "$", "subPaletteSelector", ")", ";", "$", "selectorFieldName", "=", "\\", "array_shift", "(", "$", "selectorValues", ")", ";", "$", "selectorValueCount", "=", "\\", "count", "(", "$", "selectorValues", ")", ";", "while", "(", "$", "selectorValueCount", ")", "{", "if", "(", "\\", "in_array", "(", "$", "selectorFieldName", ",", "$", "selectorFieldNames", ")", ")", "{", "break", ";", "}", "$", "selectorFieldName", ".=", "'_'", ".", "\\", "array_shift", "(", "$", "selectorValues", ")", ";", "$", "selectorValueCount", "=", "\\", "count", "(", "$", "selectorValues", ")", ";", "}", "return", "$", "selectorFieldName", ";", "}" ]
Translate a sub palette selector into the real name of a property. This method supports the following cases for the sub palette selector: Case 1: the sub palette selector contain a combination of "property name" + '_' + value in which we require that the "property name" is contained within $selectorFieldNames. In this cases a select/radio sub palette is in place. Case 2: the sub palette selector is only a "property name", the value is then implicated to be true. In this cases a checkbox sub palette is in place. @param string $subPaletteSelector The selector being evaluated. @param array $selectorFieldNames The names of the properties to be used as selectors [optional]. @return string
[ "Translate", "a", "sub", "palette", "selector", "into", "the", "real", "name", "of", "a", "property", "." ]
bf59fc2085cc848c564e40324dee14ef2897faa6
https://github.com/contao-community-alliance/dc-general/blob/bf59fc2085cc848c564e40324dee14ef2897faa6/src/Contao/Dca/Palette/LegacyPalettesParser.php#L355-L369
train
contao-community-alliance/dc-general
src/Contao/Dca/Palette/LegacyPalettesParser.php
LegacyPalettesParser.createSubpaletteCondition
public function createSubpaletteCondition($subPaletteSelector, array $selectorFieldNames = []) { $condition = null; // Try to find a select value first (case 1). $selectorValues = \explode('_', $subPaletteSelector); $selectorFieldName = \array_shift($selectorValues); $selectorValueCount = \count($selectorValues); while ($selectorValueCount) { if (empty($selectorValues)) { break; } if (\in_array($selectorFieldName, $selectorFieldNames)) { $condition = new PropertyValueCondition($selectorFieldName, \implode('_', $selectorValues)); break; } $selectorFieldName .= '_' . \array_shift($selectorValues); } // If case 1 was not successful, try implicitly case 2 must apply. if (!$condition) { $condition = new PropertyTrueCondition($subPaletteSelector); } return $condition; }
php
public function createSubpaletteCondition($subPaletteSelector, array $selectorFieldNames = []) { $condition = null; // Try to find a select value first (case 1). $selectorValues = \explode('_', $subPaletteSelector); $selectorFieldName = \array_shift($selectorValues); $selectorValueCount = \count($selectorValues); while ($selectorValueCount) { if (empty($selectorValues)) { break; } if (\in_array($selectorFieldName, $selectorFieldNames)) { $condition = new PropertyValueCondition($selectorFieldName, \implode('_', $selectorValues)); break; } $selectorFieldName .= '_' . \array_shift($selectorValues); } // If case 1 was not successful, try implicitly case 2 must apply. if (!$condition) { $condition = new PropertyTrueCondition($subPaletteSelector); } return $condition; }
[ "public", "function", "createSubpaletteCondition", "(", "$", "subPaletteSelector", ",", "array", "$", "selectorFieldNames", "=", "[", "]", ")", "{", "$", "condition", "=", "null", ";", "// Try to find a select value first (case 1).", "$", "selectorValues", "=", "\\", "explode", "(", "'_'", ",", "$", "subPaletteSelector", ")", ";", "$", "selectorFieldName", "=", "\\", "array_shift", "(", "$", "selectorValues", ")", ";", "$", "selectorValueCount", "=", "\\", "count", "(", "$", "selectorValues", ")", ";", "while", "(", "$", "selectorValueCount", ")", "{", "if", "(", "empty", "(", "$", "selectorValues", ")", ")", "{", "break", ";", "}", "if", "(", "\\", "in_array", "(", "$", "selectorFieldName", ",", "$", "selectorFieldNames", ")", ")", "{", "$", "condition", "=", "new", "PropertyValueCondition", "(", "$", "selectorFieldName", ",", "\\", "implode", "(", "'_'", ",", "$", "selectorValues", ")", ")", ";", "break", ";", "}", "$", "selectorFieldName", ".=", "'_'", ".", "\\", "array_shift", "(", "$", "selectorValues", ")", ";", "}", "// If case 1 was not successful, try implicitly case 2 must apply.", "if", "(", "!", "$", "condition", ")", "{", "$", "condition", "=", "new", "PropertyTrueCondition", "(", "$", "subPaletteSelector", ")", ";", "}", "return", "$", "condition", ";", "}" ]
Parse the sub palette selector and create the corresponding condition. This method supports the following cases for the sub palette selector: Case 1: the sub palette selector contain a combination of "property name" + '_' + value in which we require that the "property name" is contained within $selectorFieldNames. In this cases a select/radio sub palette is in place. Case 2: the sub palette selector is only a "property name", the value is then implicated to be true. In this cases a checkbox sub palette is in place. @param string $subPaletteSelector The selector being evaluated. @param array $selectorFieldNames The names of the properties to be used as selectors [optional]. @return PropertyTrueCondition|PropertyValueCondition|null
[ "Parse", "the", "sub", "palette", "selector", "and", "create", "the", "corresponding", "condition", "." ]
bf59fc2085cc848c564e40324dee14ef2897faa6
https://github.com/contao-community-alliance/dc-general/blob/bf59fc2085cc848c564e40324dee14ef2897faa6/src/Contao/Dca/Palette/LegacyPalettesParser.php#L388-L415
train
contao-community-alliance/dc-general
src/Data/ModelManipulator.php
ModelManipulator.updateModelFromPropertyBag
public static function updateModelFromPropertyBag( PropertiesDefinitionInterface $properties, ModelInterface $model, PropertyValueBagInterface $values ) { foreach ($values as $propertyName => $value) { try { if (!$properties->hasProperty($propertyName)) { continue; } $property = $properties->getProperty($propertyName); $extra = $property->getExtra(); // Don´t save value if isset property readonly. if (empty($extra['readonly'])) { $model->setProperty($propertyName, static::sanitizeValue($property, $value)); } if (empty($extra)) { continue; } // If always save is true, we need to mark the model as changed. if (!empty($extra['alwaysSave'])) { // Set property to generate alias or combined values. if (!empty($extra['readonly'])) { $model->setProperty($propertyName, static::sanitizeValue($property, null)); } $model->setMeta($model::IS_CHANGED, true); } } catch (\Exception $exception) { $values->markPropertyValueAsInvalid($propertyName, $exception->getMessage()); } } }
php
public static function updateModelFromPropertyBag( PropertiesDefinitionInterface $properties, ModelInterface $model, PropertyValueBagInterface $values ) { foreach ($values as $propertyName => $value) { try { if (!$properties->hasProperty($propertyName)) { continue; } $property = $properties->getProperty($propertyName); $extra = $property->getExtra(); // Don´t save value if isset property readonly. if (empty($extra['readonly'])) { $model->setProperty($propertyName, static::sanitizeValue($property, $value)); } if (empty($extra)) { continue; } // If always save is true, we need to mark the model as changed. if (!empty($extra['alwaysSave'])) { // Set property to generate alias or combined values. if (!empty($extra['readonly'])) { $model->setProperty($propertyName, static::sanitizeValue($property, null)); } $model->setMeta($model::IS_CHANGED, true); } } catch (\Exception $exception) { $values->markPropertyValueAsInvalid($propertyName, $exception->getMessage()); } } }
[ "public", "static", "function", "updateModelFromPropertyBag", "(", "PropertiesDefinitionInterface", "$", "properties", ",", "ModelInterface", "$", "model", ",", "PropertyValueBagInterface", "$", "values", ")", "{", "foreach", "(", "$", "values", "as", "$", "propertyName", "=>", "$", "value", ")", "{", "try", "{", "if", "(", "!", "$", "properties", "->", "hasProperty", "(", "$", "propertyName", ")", ")", "{", "continue", ";", "}", "$", "property", "=", "$", "properties", "->", "getProperty", "(", "$", "propertyName", ")", ";", "$", "extra", "=", "$", "property", "->", "getExtra", "(", ")", ";", "// Don´t save value if isset property readonly.", "if", "(", "empty", "(", "$", "extra", "[", "'readonly'", "]", ")", ")", "{", "$", "model", "->", "setProperty", "(", "$", "propertyName", ",", "static", "::", "sanitizeValue", "(", "$", "property", ",", "$", "value", ")", ")", ";", "}", "if", "(", "empty", "(", "$", "extra", ")", ")", "{", "continue", ";", "}", "// If always save is true, we need to mark the model as changed.", "if", "(", "!", "empty", "(", "$", "extra", "[", "'alwaysSave'", "]", ")", ")", "{", "// Set property to generate alias or combined values.", "if", "(", "!", "empty", "(", "$", "extra", "[", "'readonly'", "]", ")", ")", "{", "$", "model", "->", "setProperty", "(", "$", "propertyName", ",", "static", "::", "sanitizeValue", "(", "$", "property", ",", "null", ")", ")", ";", "}", "$", "model", "->", "setMeta", "(", "$", "model", "::", "IS_CHANGED", ",", "true", ")", ";", "}", "}", "catch", "(", "\\", "Exception", "$", "exception", ")", "{", "$", "values", "->", "markPropertyValueAsInvalid", "(", "$", "propertyName", ",", "$", "exception", "->", "getMessage", "(", ")", ")", ";", "}", "}", "}" ]
Update the model with the values from the value bag. @param PropertiesDefinitionInterface $properties The property information store. @param ModelInterface $model The model to update. @param PropertyValueBagInterface $values The value bag to retrieve the values from. @return void
[ "Update", "the", "model", "with", "the", "values", "from", "the", "value", "bag", "." ]
bf59fc2085cc848c564e40324dee14ef2897faa6
https://github.com/contao-community-alliance/dc-general/blob/bf59fc2085cc848c564e40324dee14ef2897faa6/src/Data/ModelManipulator.php#L41-L76
train
contao-community-alliance/dc-general
src/Controller/BackendTreeController.php
BackendTreeController.prepareTreeSelector
private function prepareTreeSelector(PickerInterface $picker) { $modelId = ModelId::fromSerialized($picker->getConfig()->getExtra('modelId')); if (Validator::isInsecurePath($table = $modelId->getDataProviderName())) { throw new \InvalidArgumentException('The table name contains invalid characters'); } if (Validator::isInsecurePath($field = $picker->getConfig()->getExtra('propertyName'))) { throw new \InvalidArgumentException('The field name contains invalid characters'); } $sessionBag = $this->container->get('session')->getBag('contao_backend'); // Define the current ID. \define('CURRENT_ID', ($table ? $sessionBag->get('CURRENT_ID') : $modelId->getId())); $this->itemContainer = (new DcGeneralFactory()) ->setContainerName($modelId->getDataProviderName()) ->setTranslator($this->container->get('cca.translator.contao_translator')) ->setEventDispatcher($this->container->get('event_dispatcher')) ->createDcGeneral(); // Merge with the information from the data container. $property = $this ->itemContainer ->getEnvironment() ->getDataDefinition() ->getPropertiesDefinition() ->getProperty($picker->getConfig()->getExtra('propertyName')); $information = (array) $GLOBALS['TL_DCA'][$table]['fields'][$field]; if (!isset($information['eval'])) { $information['eval'] = array(); } $information['eval'] = array_merge($property->getExtra(), $information['eval']); $treeSelector = new $GLOBALS['BE_FFL']['DcGeneralTreePicker']( Widget::getAttributesFromDca( $information, $field, \array_filter(\explode(',', $picker->getConfig()->getValue())), $field, $table, new DcCompat($this->itemContainer->getEnvironment()) ), new DcCompat($this->itemContainer->getEnvironment()) ); $treeSelector->id = 'tl_listing'; return $treeSelector; }
php
private function prepareTreeSelector(PickerInterface $picker) { $modelId = ModelId::fromSerialized($picker->getConfig()->getExtra('modelId')); if (Validator::isInsecurePath($table = $modelId->getDataProviderName())) { throw new \InvalidArgumentException('The table name contains invalid characters'); } if (Validator::isInsecurePath($field = $picker->getConfig()->getExtra('propertyName'))) { throw new \InvalidArgumentException('The field name contains invalid characters'); } $sessionBag = $this->container->get('session')->getBag('contao_backend'); // Define the current ID. \define('CURRENT_ID', ($table ? $sessionBag->get('CURRENT_ID') : $modelId->getId())); $this->itemContainer = (new DcGeneralFactory()) ->setContainerName($modelId->getDataProviderName()) ->setTranslator($this->container->get('cca.translator.contao_translator')) ->setEventDispatcher($this->container->get('event_dispatcher')) ->createDcGeneral(); // Merge with the information from the data container. $property = $this ->itemContainer ->getEnvironment() ->getDataDefinition() ->getPropertiesDefinition() ->getProperty($picker->getConfig()->getExtra('propertyName')); $information = (array) $GLOBALS['TL_DCA'][$table]['fields'][$field]; if (!isset($information['eval'])) { $information['eval'] = array(); } $information['eval'] = array_merge($property->getExtra(), $information['eval']); $treeSelector = new $GLOBALS['BE_FFL']['DcGeneralTreePicker']( Widget::getAttributesFromDca( $information, $field, \array_filter(\explode(',', $picker->getConfig()->getValue())), $field, $table, new DcCompat($this->itemContainer->getEnvironment()) ), new DcCompat($this->itemContainer->getEnvironment()) ); $treeSelector->id = 'tl_listing'; return $treeSelector; }
[ "private", "function", "prepareTreeSelector", "(", "PickerInterface", "$", "picker", ")", "{", "$", "modelId", "=", "ModelId", "::", "fromSerialized", "(", "$", "picker", "->", "getConfig", "(", ")", "->", "getExtra", "(", "'modelId'", ")", ")", ";", "if", "(", "Validator", "::", "isInsecurePath", "(", "$", "table", "=", "$", "modelId", "->", "getDataProviderName", "(", ")", ")", ")", "{", "throw", "new", "\\", "InvalidArgumentException", "(", "'The table name contains invalid characters'", ")", ";", "}", "if", "(", "Validator", "::", "isInsecurePath", "(", "$", "field", "=", "$", "picker", "->", "getConfig", "(", ")", "->", "getExtra", "(", "'propertyName'", ")", ")", ")", "{", "throw", "new", "\\", "InvalidArgumentException", "(", "'The field name contains invalid characters'", ")", ";", "}", "$", "sessionBag", "=", "$", "this", "->", "container", "->", "get", "(", "'session'", ")", "->", "getBag", "(", "'contao_backend'", ")", ";", "// Define the current ID.", "\\", "define", "(", "'CURRENT_ID'", ",", "(", "$", "table", "?", "$", "sessionBag", "->", "get", "(", "'CURRENT_ID'", ")", ":", "$", "modelId", "->", "getId", "(", ")", ")", ")", ";", "$", "this", "->", "itemContainer", "=", "(", "new", "DcGeneralFactory", "(", ")", ")", "->", "setContainerName", "(", "$", "modelId", "->", "getDataProviderName", "(", ")", ")", "->", "setTranslator", "(", "$", "this", "->", "container", "->", "get", "(", "'cca.translator.contao_translator'", ")", ")", "->", "setEventDispatcher", "(", "$", "this", "->", "container", "->", "get", "(", "'event_dispatcher'", ")", ")", "->", "createDcGeneral", "(", ")", ";", "// Merge with the information from the data container.", "$", "property", "=", "$", "this", "->", "itemContainer", "->", "getEnvironment", "(", ")", "->", "getDataDefinition", "(", ")", "->", "getPropertiesDefinition", "(", ")", "->", "getProperty", "(", "$", "picker", "->", "getConfig", "(", ")", "->", "getExtra", "(", "'propertyName'", ")", ")", ";", "$", "information", "=", "(", "array", ")", "$", "GLOBALS", "[", "'TL_DCA'", "]", "[", "$", "table", "]", "[", "'fields'", "]", "[", "$", "field", "]", ";", "if", "(", "!", "isset", "(", "$", "information", "[", "'eval'", "]", ")", ")", "{", "$", "information", "[", "'eval'", "]", "=", "array", "(", ")", ";", "}", "$", "information", "[", "'eval'", "]", "=", "array_merge", "(", "$", "property", "->", "getExtra", "(", ")", ",", "$", "information", "[", "'eval'", "]", ")", ";", "$", "treeSelector", "=", "new", "$", "GLOBALS", "[", "'BE_FFL'", "]", "[", "'DcGeneralTreePicker'", "]", "(", "Widget", "::", "getAttributesFromDca", "(", "$", "information", ",", "$", "field", ",", "\\", "array_filter", "(", "\\", "explode", "(", "','", ",", "$", "picker", "->", "getConfig", "(", ")", "->", "getValue", "(", ")", ")", ")", ",", "$", "field", ",", "$", "table", ",", "new", "DcCompat", "(", "$", "this", "->", "itemContainer", "->", "getEnvironment", "(", ")", ")", ")", ",", "new", "DcCompat", "(", "$", "this", "->", "itemContainer", "->", "getEnvironment", "(", ")", ")", ")", ";", "$", "treeSelector", "->", "id", "=", "'tl_listing'", ";", "return", "$", "treeSelector", ";", "}" ]
Prepare the tree selector. @param PickerInterface $picker The picker. @return TreePicker @throws \InvalidArgumentException If invalid characters in the data provider name or property name. @SuppressWarnings(PHPMD.Superglobals)
[ "Prepare", "the", "tree", "selector", "." ]
bf59fc2085cc848c564e40324dee14ef2897faa6
https://github.com/contao-community-alliance/dc-general/blob/bf59fc2085cc848c564e40324dee14ef2897faa6/src/Controller/BackendTreeController.php#L317-L368
train
contao-community-alliance/dc-general
src/Data/DefaultEditInformation.php
DefaultEditInformation.getFlatModelErrors
public function getFlatModelErrors(ModelInterface $model) { $modelErrors = $this->getModelError($model); if (!$modelErrors) { return $modelErrors; } $errors = [[]]; foreach ($this->getModelError($model) as $modelError) { $errors[] = $modelError; } return \array_merge(...$errors); }
php
public function getFlatModelErrors(ModelInterface $model) { $modelErrors = $this->getModelError($model); if (!$modelErrors) { return $modelErrors; } $errors = [[]]; foreach ($this->getModelError($model) as $modelError) { $errors[] = $modelError; } return \array_merge(...$errors); }
[ "public", "function", "getFlatModelErrors", "(", "ModelInterface", "$", "model", ")", "{", "$", "modelErrors", "=", "$", "this", "->", "getModelError", "(", "$", "model", ")", ";", "if", "(", "!", "$", "modelErrors", ")", "{", "return", "$", "modelErrors", ";", "}", "$", "errors", "=", "[", "[", "]", "]", ";", "foreach", "(", "$", "this", "->", "getModelError", "(", "$", "model", ")", "as", "$", "modelError", ")", "{", "$", "errors", "[", "]", "=", "$", "modelError", ";", "}", "return", "\\", "array_merge", "(", "...", "$", "errors", ")", ";", "}" ]
Get flat model errors. This returns all errors without property names hierarchy. @param ModelInterface $model The model. @return array|null
[ "Get", "flat", "model", "errors", ".", "This", "returns", "all", "errors", "without", "property", "names", "hierarchy", "." ]
bf59fc2085cc848c564e40324dee14ef2897faa6
https://github.com/contao-community-alliance/dc-general/blob/bf59fc2085cc848c564e40324dee14ef2897faa6/src/Data/DefaultEditInformation.php#L116-L129
train
contao-community-alliance/dc-general
src/Contao/View/Contao2BackendView/EventListener/ColorPickerWizardListener.php
ColorPickerWizardListener.getWizard
public static function getWizard($propInfo, EnvironmentInterface $environment) { $wizard = ''; $propExtra = $propInfo->getExtra(); if (\is_array($propExtra) && \array_key_exists('colorpicker', $propExtra) && $propExtra['colorpicker']) { $pickerText = $environment->getTranslator()->translate('colorpicker', 'MSC'); $event = new GenerateHtmlEvent( 'pickcolor.svg', $pickerText, \sprintf( 'style="%s" title="%s" id="moo_%s"', 'vertical-align:top;cursor:pointer', StringUtil::specialchars($pickerText), $propInfo->getName() ) ); $environment->getEventDispatcher()->dispatch(ContaoEvents::IMAGE_GET_HTML, $event); // Support single fields as well (see contao/core#5240) $strKey = $propExtra['multiple'] ? $propInfo->getName() . '_0' : $propInfo->getName(); $wizard .= \sprintf( ' %1$s <script>var cl;window.addEvent("domready", function() { new MooRainbow("moo_%2$s", {' . 'id: "ctrl_%3$s", startColor: ((cl = $("ctrl_%3$s").value.hexToRgb(true)) ? cl : [255, 0, 0]),' . 'imgPath: "%4$s", onComplete: function(color) {$("ctrl_%3$s").value = color.hex.replace("#", "");}});' . '});</script>', $event->getHtml(), $propInfo->getName(), $strKey, 'assets/colorpicker/images/' ); } return $wizard; }
php
public static function getWizard($propInfo, EnvironmentInterface $environment) { $wizard = ''; $propExtra = $propInfo->getExtra(); if (\is_array($propExtra) && \array_key_exists('colorpicker', $propExtra) && $propExtra['colorpicker']) { $pickerText = $environment->getTranslator()->translate('colorpicker', 'MSC'); $event = new GenerateHtmlEvent( 'pickcolor.svg', $pickerText, \sprintf( 'style="%s" title="%s" id="moo_%s"', 'vertical-align:top;cursor:pointer', StringUtil::specialchars($pickerText), $propInfo->getName() ) ); $environment->getEventDispatcher()->dispatch(ContaoEvents::IMAGE_GET_HTML, $event); // Support single fields as well (see contao/core#5240) $strKey = $propExtra['multiple'] ? $propInfo->getName() . '_0' : $propInfo->getName(); $wizard .= \sprintf( ' %1$s <script>var cl;window.addEvent("domready", function() { new MooRainbow("moo_%2$s", {' . 'id: "ctrl_%3$s", startColor: ((cl = $("ctrl_%3$s").value.hexToRgb(true)) ? cl : [255, 0, 0]),' . 'imgPath: "%4$s", onComplete: function(color) {$("ctrl_%3$s").value = color.hex.replace("#", "");}});' . '});</script>', $event->getHtml(), $propInfo->getName(), $strKey, 'assets/colorpicker/images/' ); } return $wizard; }
[ "public", "static", "function", "getWizard", "(", "$", "propInfo", ",", "EnvironmentInterface", "$", "environment", ")", "{", "$", "wizard", "=", "''", ";", "$", "propExtra", "=", "$", "propInfo", "->", "getExtra", "(", ")", ";", "if", "(", "\\", "is_array", "(", "$", "propExtra", ")", "&&", "\\", "array_key_exists", "(", "'colorpicker'", ",", "$", "propExtra", ")", "&&", "$", "propExtra", "[", "'colorpicker'", "]", ")", "{", "$", "pickerText", "=", "$", "environment", "->", "getTranslator", "(", ")", "->", "translate", "(", "'colorpicker'", ",", "'MSC'", ")", ";", "$", "event", "=", "new", "GenerateHtmlEvent", "(", "'pickcolor.svg'", ",", "$", "pickerText", ",", "\\", "sprintf", "(", "'style=\"%s\" title=\"%s\" id=\"moo_%s\"'", ",", "'vertical-align:top;cursor:pointer'", ",", "StringUtil", "::", "specialchars", "(", "$", "pickerText", ")", ",", "$", "propInfo", "->", "getName", "(", ")", ")", ")", ";", "$", "environment", "->", "getEventDispatcher", "(", ")", "->", "dispatch", "(", "ContaoEvents", "::", "IMAGE_GET_HTML", ",", "$", "event", ")", ";", "// Support single fields as well (see contao/core#5240)", "$", "strKey", "=", "$", "propExtra", "[", "'multiple'", "]", "?", "$", "propInfo", "->", "getName", "(", ")", ".", "'_0'", ":", "$", "propInfo", "->", "getName", "(", ")", ";", "$", "wizard", ".=", "\\", "sprintf", "(", "' %1$s <script>var cl;window.addEvent(\"domready\", function() { new MooRainbow(\"moo_%2$s\", {'", ".", "'id: \"ctrl_%3$s\", startColor: ((cl = $(\"ctrl_%3$s\").value.hexToRgb(true)) ? cl : [255, 0, 0]),'", ".", "'imgPath: \"%4$s\", onComplete: function(color) {$(\"ctrl_%3$s\").value = color.hex.replace(\"#\", \"\");}});'", ".", "'});</script>'", ",", "$", "event", "->", "getHtml", "(", ")", ",", "$", "propInfo", "->", "getName", "(", ")", ",", "$", "strKey", ",", "'assets/colorpicker/images/'", ")", ";", "}", "return", "$", "wizard", ";", "}" ]
Append wizard icons. @param PropertyInterface $propInfo The property for which the wizards shall be generated. @param EnvironmentInterface $environment The environment. @return string @SuppressWarnings(PHPMD.Superglobals) @SuppressWarnings(PHPMD.CamelCaseVariableName)
[ "Append", "wizard", "icons", "." ]
bf59fc2085cc848c564e40324dee14ef2897faa6
https://github.com/contao-community-alliance/dc-general/blob/bf59fc2085cc848c564e40324dee14ef2897faa6/src/Contao/View/Contao2BackendView/EventListener/ColorPickerWizardListener.php#L86-L122
train
contao-community-alliance/dc-general
src/Contao/View/Contao2BackendView/Subscriber/GetGroupHeaderSubscriber.php
GetGroupHeaderSubscriber.handle
public function handle(GetGroupHeaderEvent $event) { if ((null !== $event->getValue()) || !$this->scopeDeterminator->currentScopeIsBackend()) { return; } $environment = $event->getEnvironment(); $property = $environment ->getDataDefinition() ->getPropertiesDefinition() ->getProperty($event->getGroupField()); // No property? Get out! if (!$property) { $event->setValue('-'); return; } $value = $this->formatGroupHeader( $environment, $event->getModel(), $property, $event->getGroupingMode(), $event->getGroupingLength() ); if (null !== $value) { $event->setValue($value); } }
php
public function handle(GetGroupHeaderEvent $event) { if ((null !== $event->getValue()) || !$this->scopeDeterminator->currentScopeIsBackend()) { return; } $environment = $event->getEnvironment(); $property = $environment ->getDataDefinition() ->getPropertiesDefinition() ->getProperty($event->getGroupField()); // No property? Get out! if (!$property) { $event->setValue('-'); return; } $value = $this->formatGroupHeader( $environment, $event->getModel(), $property, $event->getGroupingMode(), $event->getGroupingLength() ); if (null !== $value) { $event->setValue($value); } }
[ "public", "function", "handle", "(", "GetGroupHeaderEvent", "$", "event", ")", "{", "if", "(", "(", "null", "!==", "$", "event", "->", "getValue", "(", ")", ")", "||", "!", "$", "this", "->", "scopeDeterminator", "->", "currentScopeIsBackend", "(", ")", ")", "{", "return", ";", "}", "$", "environment", "=", "$", "event", "->", "getEnvironment", "(", ")", ";", "$", "property", "=", "$", "environment", "->", "getDataDefinition", "(", ")", "->", "getPropertiesDefinition", "(", ")", "->", "getProperty", "(", "$", "event", "->", "getGroupField", "(", ")", ")", ";", "// No property? Get out!", "if", "(", "!", "$", "property", ")", "{", "$", "event", "->", "setValue", "(", "'-'", ")", ";", "return", ";", "}", "$", "value", "=", "$", "this", "->", "formatGroupHeader", "(", "$", "environment", ",", "$", "event", "->", "getModel", "(", ")", ",", "$", "property", ",", "$", "event", "->", "getGroupingMode", "(", ")", ",", "$", "event", "->", "getGroupingLength", "(", ")", ")", ";", "if", "(", "null", "!==", "$", "value", ")", "{", "$", "event", "->", "setValue", "(", "$", "value", ")", ";", "}", "}" ]
Handle the subscribed event. @param GetGroupHeaderEvent $event The event. @return void
[ "Handle", "the", "subscribed", "event", "." ]
bf59fc2085cc848c564e40324dee14ef2897faa6
https://github.com/contao-community-alliance/dc-general/blob/bf59fc2085cc848c564e40324dee14ef2897faa6/src/Contao/View/Contao2BackendView/Subscriber/GetGroupHeaderSubscriber.php#L79-L108
train
contao-community-alliance/dc-general
src/Contao/View/Contao2BackendView/Subscriber/GetGroupHeaderSubscriber.php
GetGroupHeaderSubscriber.formatGroupHeader
protected function formatGroupHeader( EnvironmentInterface $environment, ModelInterface $model, PropertyInterface $property, $groupingMode, $groupingLength ) { $evaluation = $property->getExtra(); if (!$evaluation['multiple'] && ('checkbox' === $property->getWidgetType())) { return $this->formatCheckboxOptionLabel($model->getProperty($property->getName())); } if (GroupAndSortingInformationInterface::GROUP_NONE !== $groupingMode) { return $this->formatByGroupingMode($groupingMode, $groupingLength, $environment, $property, $model); } $value = ViewHelpers::getReadableFieldValue($environment, $property, $model); if (isset($evaluation['reference'])) { $remoteNew = $evaluation['reference'][$value]; } elseif (\array_is_assoc($property->getOptions())) { $options = $property->getOptions(); $remoteNew = $options[$value]; } else { $remoteNew = $value; } if (\is_array($remoteNew)) { $remoteNew = $remoteNew[0]; } if (empty($remoteNew)) { $remoteNew = '-'; } return $remoteNew; }
php
protected function formatGroupHeader( EnvironmentInterface $environment, ModelInterface $model, PropertyInterface $property, $groupingMode, $groupingLength ) { $evaluation = $property->getExtra(); if (!$evaluation['multiple'] && ('checkbox' === $property->getWidgetType())) { return $this->formatCheckboxOptionLabel($model->getProperty($property->getName())); } if (GroupAndSortingInformationInterface::GROUP_NONE !== $groupingMode) { return $this->formatByGroupingMode($groupingMode, $groupingLength, $environment, $property, $model); } $value = ViewHelpers::getReadableFieldValue($environment, $property, $model); if (isset($evaluation['reference'])) { $remoteNew = $evaluation['reference'][$value]; } elseif (\array_is_assoc($property->getOptions())) { $options = $property->getOptions(); $remoteNew = $options[$value]; } else { $remoteNew = $value; } if (\is_array($remoteNew)) { $remoteNew = $remoteNew[0]; } if (empty($remoteNew)) { $remoteNew = '-'; } return $remoteNew; }
[ "protected", "function", "formatGroupHeader", "(", "EnvironmentInterface", "$", "environment", ",", "ModelInterface", "$", "model", ",", "PropertyInterface", "$", "property", ",", "$", "groupingMode", ",", "$", "groupingLength", ")", "{", "$", "evaluation", "=", "$", "property", "->", "getExtra", "(", ")", ";", "if", "(", "!", "$", "evaluation", "[", "'multiple'", "]", "&&", "(", "'checkbox'", "===", "$", "property", "->", "getWidgetType", "(", ")", ")", ")", "{", "return", "$", "this", "->", "formatCheckboxOptionLabel", "(", "$", "model", "->", "getProperty", "(", "$", "property", "->", "getName", "(", ")", ")", ")", ";", "}", "if", "(", "GroupAndSortingInformationInterface", "::", "GROUP_NONE", "!==", "$", "groupingMode", ")", "{", "return", "$", "this", "->", "formatByGroupingMode", "(", "$", "groupingMode", ",", "$", "groupingLength", ",", "$", "environment", ",", "$", "property", ",", "$", "model", ")", ";", "}", "$", "value", "=", "ViewHelpers", "::", "getReadableFieldValue", "(", "$", "environment", ",", "$", "property", ",", "$", "model", ")", ";", "if", "(", "isset", "(", "$", "evaluation", "[", "'reference'", "]", ")", ")", "{", "$", "remoteNew", "=", "$", "evaluation", "[", "'reference'", "]", "[", "$", "value", "]", ";", "}", "elseif", "(", "\\", "array_is_assoc", "(", "$", "property", "->", "getOptions", "(", ")", ")", ")", "{", "$", "options", "=", "$", "property", "->", "getOptions", "(", ")", ";", "$", "remoteNew", "=", "$", "options", "[", "$", "value", "]", ";", "}", "else", "{", "$", "remoteNew", "=", "$", "value", ";", "}", "if", "(", "\\", "is_array", "(", "$", "remoteNew", ")", ")", "{", "$", "remoteNew", "=", "$", "remoteNew", "[", "0", "]", ";", "}", "if", "(", "empty", "(", "$", "remoteNew", ")", ")", "{", "$", "remoteNew", "=", "'-'", ";", "}", "return", "$", "remoteNew", ";", "}" ]
Get the group header. @param EnvironmentInterface $environment The environment. @param ModelInterface $model The model. @param PropertyInterface $property The property. @param int $groupingMode The grouping mode. @param int $groupingLength The grouping length. @return string
[ "Get", "the", "group", "header", "." ]
bf59fc2085cc848c564e40324dee14ef2897faa6
https://github.com/contao-community-alliance/dc-general/blob/bf59fc2085cc848c564e40324dee14ef2897faa6/src/Contao/View/Contao2BackendView/Subscriber/GetGroupHeaderSubscriber.php#L121-L157
train
contao-community-alliance/dc-general
src/Contao/View/Contao2BackendView/Subscriber/GetGroupHeaderSubscriber.php
GetGroupHeaderSubscriber.formatCheckboxOptionLabel
private function formatCheckboxOptionLabel($value) { return ('' !== $value) ? \ucfirst($this->translator->translate('MSC.yes')) : \ucfirst($this->translator->translate('MSC.no')); }
php
private function formatCheckboxOptionLabel($value) { return ('' !== $value) ? \ucfirst($this->translator->translate('MSC.yes')) : \ucfirst($this->translator->translate('MSC.no')); }
[ "private", "function", "formatCheckboxOptionLabel", "(", "$", "value", ")", "{", "return", "(", "''", "!==", "$", "value", ")", "?", "\\", "ucfirst", "(", "$", "this", "->", "translator", "->", "translate", "(", "'MSC.yes'", ")", ")", ":", "\\", "ucfirst", "(", "$", "this", "->", "translator", "->", "translate", "(", "'MSC.no'", ")", ")", ";", "}" ]
Format the grouping header for a checkbox option. @param string $value The given value. @return string
[ "Format", "the", "grouping", "header", "for", "a", "checkbox", "option", "." ]
bf59fc2085cc848c564e40324dee14ef2897faa6
https://github.com/contao-community-alliance/dc-general/blob/bf59fc2085cc848c564e40324dee14ef2897faa6/src/Contao/View/Contao2BackendView/Subscriber/GetGroupHeaderSubscriber.php#L166-L171
train
contao-community-alliance/dc-general
src/Contao/View/Contao2BackendView/Subscriber/GetGroupHeaderSubscriber.php
GetGroupHeaderSubscriber.formatByGroupingMode
private function formatByGroupingMode( $groupingMode, $groupingLength, EnvironmentInterface $environment, PropertyInterface $property, ModelInterface $model ) { switch ($groupingMode) { case GroupAndSortingInformationInterface::GROUP_CHAR: return $this->formatByCharGrouping( ViewHelpers::getReadableFieldValue($environment, $property, $model), $groupingLength ); case GroupAndSortingInformationInterface::GROUP_DAY: return $this->formatByDayGrouping((int) $model->getProperty($property->getName())); case GroupAndSortingInformationInterface::GROUP_MONTH: return $this->formatByMonthGrouping((int) $model->getProperty($property->getName())); case GroupAndSortingInformationInterface::GROUP_YEAR: return $this->formatByYearGrouping((int) $model->getProperty($property->getName())); default: return ViewHelpers::getReadableFieldValue($environment, $property, $model); } }
php
private function formatByGroupingMode( $groupingMode, $groupingLength, EnvironmentInterface $environment, PropertyInterface $property, ModelInterface $model ) { switch ($groupingMode) { case GroupAndSortingInformationInterface::GROUP_CHAR: return $this->formatByCharGrouping( ViewHelpers::getReadableFieldValue($environment, $property, $model), $groupingLength ); case GroupAndSortingInformationInterface::GROUP_DAY: return $this->formatByDayGrouping((int) $model->getProperty($property->getName())); case GroupAndSortingInformationInterface::GROUP_MONTH: return $this->formatByMonthGrouping((int) $model->getProperty($property->getName())); case GroupAndSortingInformationInterface::GROUP_YEAR: return $this->formatByYearGrouping((int) $model->getProperty($property->getName())); default: return ViewHelpers::getReadableFieldValue($environment, $property, $model); } }
[ "private", "function", "formatByGroupingMode", "(", "$", "groupingMode", ",", "$", "groupingLength", ",", "EnvironmentInterface", "$", "environment", ",", "PropertyInterface", "$", "property", ",", "ModelInterface", "$", "model", ")", "{", "switch", "(", "$", "groupingMode", ")", "{", "case", "GroupAndSortingInformationInterface", "::", "GROUP_CHAR", ":", "return", "$", "this", "->", "formatByCharGrouping", "(", "ViewHelpers", "::", "getReadableFieldValue", "(", "$", "environment", ",", "$", "property", ",", "$", "model", ")", ",", "$", "groupingLength", ")", ";", "case", "GroupAndSortingInformationInterface", "::", "GROUP_DAY", ":", "return", "$", "this", "->", "formatByDayGrouping", "(", "(", "int", ")", "$", "model", "->", "getProperty", "(", "$", "property", "->", "getName", "(", ")", ")", ")", ";", "case", "GroupAndSortingInformationInterface", "::", "GROUP_MONTH", ":", "return", "$", "this", "->", "formatByMonthGrouping", "(", "(", "int", ")", "$", "model", "->", "getProperty", "(", "$", "property", "->", "getName", "(", ")", ")", ")", ";", "case", "GroupAndSortingInformationInterface", "::", "GROUP_YEAR", ":", "return", "$", "this", "->", "formatByYearGrouping", "(", "(", "int", ")", "$", "model", "->", "getProperty", "(", "$", "property", "->", "getName", "(", ")", ")", ")", ";", "default", ":", "return", "ViewHelpers", "::", "getReadableFieldValue", "(", "$", "environment", ",", "$", "property", ",", "$", "model", ")", ";", "}", "}" ]
Format the group header by the grouping mode. @param int $groupingMode The grouping mode. @param int $groupingLength The grouping length. @param EnvironmentInterface $environment The environment. @param PropertyInterface $property The current property definition. @param ModelInterface $model The current data model. @return string
[ "Format", "the", "group", "header", "by", "the", "grouping", "mode", "." ]
bf59fc2085cc848c564e40324dee14ef2897faa6
https://github.com/contao-community-alliance/dc-general/blob/bf59fc2085cc848c564e40324dee14ef2897faa6/src/Contao/View/Contao2BackendView/Subscriber/GetGroupHeaderSubscriber.php#L184-L210
train
contao-community-alliance/dc-general
src/Contao/View/Contao2BackendView/Subscriber/GetGroupHeaderSubscriber.php
GetGroupHeaderSubscriber.formatByCharGrouping
private function formatByCharGrouping($value, $groupingLength) { if ('' === $value) { return '-'; } return \ucfirst(Utf8::substr($value, 0, $groupingLength ?: null)); }
php
private function formatByCharGrouping($value, $groupingLength) { if ('' === $value) { return '-'; } return \ucfirst(Utf8::substr($value, 0, $groupingLength ?: null)); }
[ "private", "function", "formatByCharGrouping", "(", "$", "value", ",", "$", "groupingLength", ")", "{", "if", "(", "''", "===", "$", "value", ")", "{", "return", "'-'", ";", "}", "return", "\\", "ucfirst", "(", "Utf8", "::", "substr", "(", "$", "value", ",", "0", ",", "$", "groupingLength", "?", ":", "null", ")", ")", ";", "}" ]
Format a value for char grouping. @param string $value The value. @param int $groupingLength The group length. @return string
[ "Format", "a", "value", "for", "char", "grouping", "." ]
bf59fc2085cc848c564e40324dee14ef2897faa6
https://github.com/contao-community-alliance/dc-general/blob/bf59fc2085cc848c564e40324dee14ef2897faa6/src/Contao/View/Contao2BackendView/Subscriber/GetGroupHeaderSubscriber.php#L220-L227
train
contao-community-alliance/dc-general
src/Contao/View/Contao2BackendView/Subscriber/GetGroupHeaderSubscriber.php
GetGroupHeaderSubscriber.formatByDayGrouping
private function formatByDayGrouping($value) { $value = $this->getTimestamp($value); if ('' === $value) { return '-'; } $event = new ParseDateEvent($value, Config::get('dateFormat')); $this->dispatcher->dispatch(ContaoEvents::DATE_PARSE, $event); return $event->getResult(); }
php
private function formatByDayGrouping($value) { $value = $this->getTimestamp($value); if ('' === $value) { return '-'; } $event = new ParseDateEvent($value, Config::get('dateFormat')); $this->dispatcher->dispatch(ContaoEvents::DATE_PARSE, $event); return $event->getResult(); }
[ "private", "function", "formatByDayGrouping", "(", "$", "value", ")", "{", "$", "value", "=", "$", "this", "->", "getTimestamp", "(", "$", "value", ")", ";", "if", "(", "''", "===", "$", "value", ")", "{", "return", "'-'", ";", "}", "$", "event", "=", "new", "ParseDateEvent", "(", "$", "value", ",", "Config", "::", "get", "(", "'dateFormat'", ")", ")", ";", "$", "this", "->", "dispatcher", "->", "dispatch", "(", "ContaoEvents", "::", "DATE_PARSE", ",", "$", "event", ")", ";", "return", "$", "event", "->", "getResult", "(", ")", ";", "}" ]
Render a grouping header for day. @param int $value The value. @return string
[ "Render", "a", "grouping", "header", "for", "day", "." ]
bf59fc2085cc848c564e40324dee14ef2897faa6
https://github.com/contao-community-alliance/dc-general/blob/bf59fc2085cc848c564e40324dee14ef2897faa6/src/Contao/View/Contao2BackendView/Subscriber/GetGroupHeaderSubscriber.php#L236-L246
train
contao-community-alliance/dc-general
src/Contao/View/Contao2BackendView/Subscriber/GetGroupHeaderSubscriber.php
GetGroupHeaderSubscriber.formatByMonthGrouping
private function formatByMonthGrouping($value) { $value = $this->getTimestamp($value); if ('' === $value) { return '-'; } $event = new ParseDateEvent($value, 'F Y'); $this->dispatcher->dispatch(ContaoEvents::DATE_PARSE, $event); return $event->getResult(); }
php
private function formatByMonthGrouping($value) { $value = $this->getTimestamp($value); if ('' === $value) { return '-'; } $event = new ParseDateEvent($value, 'F Y'); $this->dispatcher->dispatch(ContaoEvents::DATE_PARSE, $event); return $event->getResult(); }
[ "private", "function", "formatByMonthGrouping", "(", "$", "value", ")", "{", "$", "value", "=", "$", "this", "->", "getTimestamp", "(", "$", "value", ")", ";", "if", "(", "''", "===", "$", "value", ")", "{", "return", "'-'", ";", "}", "$", "event", "=", "new", "ParseDateEvent", "(", "$", "value", ",", "'F Y'", ")", ";", "$", "this", "->", "dispatcher", "->", "dispatch", "(", "ContaoEvents", "::", "DATE_PARSE", ",", "$", "event", ")", ";", "return", "$", "event", "->", "getResult", "(", ")", ";", "}" ]
Render a grouping header for month. @param int $value The value. @return string
[ "Render", "a", "grouping", "header", "for", "month", "." ]
bf59fc2085cc848c564e40324dee14ef2897faa6
https://github.com/contao-community-alliance/dc-general/blob/bf59fc2085cc848c564e40324dee14ef2897faa6/src/Contao/View/Contao2BackendView/Subscriber/GetGroupHeaderSubscriber.php#L255-L265
train
contao-community-alliance/dc-general
src/Contao/SessionStorage.php
SessionStorage.load
private function load() { if (\count($this->attributes)) { return; } $sessionBag = $this->session->getBag($this->getSessionBagKey()); $databaseSessionBag = $this->session->getBag($this->getDatabaseSessionBagKey()); $this->attributes = \array_merge( (array) $sessionBag->get($this->getScope()), (array) $databaseSessionBag->get($this->getScope()) ); }
php
private function load() { if (\count($this->attributes)) { return; } $sessionBag = $this->session->getBag($this->getSessionBagKey()); $databaseSessionBag = $this->session->getBag($this->getDatabaseSessionBagKey()); $this->attributes = \array_merge( (array) $sessionBag->get($this->getScope()), (array) $databaseSessionBag->get($this->getScope()) ); }
[ "private", "function", "load", "(", ")", "{", "if", "(", "\\", "count", "(", "$", "this", "->", "attributes", ")", ")", "{", "return", ";", "}", "$", "sessionBag", "=", "$", "this", "->", "session", "->", "getBag", "(", "$", "this", "->", "getSessionBagKey", "(", ")", ")", ";", "$", "databaseSessionBag", "=", "$", "this", "->", "session", "->", "getBag", "(", "$", "this", "->", "getDatabaseSessionBagKey", "(", ")", ")", ";", "$", "this", "->", "attributes", "=", "\\", "array_merge", "(", "(", "array", ")", "$", "sessionBag", "->", "get", "(", "$", "this", "->", "getScope", "(", ")", ")", ",", "(", "array", ")", "$", "databaseSessionBag", "->", "get", "(", "$", "this", "->", "getScope", "(", ")", ")", ")", ";", "}" ]
Load the data from the session if it has not been loaded yet. @return void
[ "Load", "the", "data", "from", "the", "session", "if", "it", "has", "not", "been", "loaded", "yet", "." ]
bf59fc2085cc848c564e40324dee14ef2897faa6
https://github.com/contao-community-alliance/dc-general/blob/bf59fc2085cc848c564e40324dee14ef2897faa6/src/Contao/SessionStorage.php#L187-L200
train
contao-community-alliance/dc-general
src/Contao/SessionStorage.php
SessionStorage.persist
private function persist() { $sessionBag = $this->session->getBag($this->getSessionBagKey()); $sessionBag->set($this->getScope(), $this->filterAttributes()); $databaseSessionBag = $this->session->getBag($this->getDatabaseSessionBagKey()); $databaseSessionBag->set($this->getScope(), $this->filterAttributes(true)); }
php
private function persist() { $sessionBag = $this->session->getBag($this->getSessionBagKey()); $sessionBag->set($this->getScope(), $this->filterAttributes()); $databaseSessionBag = $this->session->getBag($this->getDatabaseSessionBagKey()); $databaseSessionBag->set($this->getScope(), $this->filterAttributes(true)); }
[ "private", "function", "persist", "(", ")", "{", "$", "sessionBag", "=", "$", "this", "->", "session", "->", "getBag", "(", "$", "this", "->", "getSessionBagKey", "(", ")", ")", ";", "$", "sessionBag", "->", "set", "(", "$", "this", "->", "getScope", "(", ")", ",", "$", "this", "->", "filterAttributes", "(", ")", ")", ";", "$", "databaseSessionBag", "=", "$", "this", "->", "session", "->", "getBag", "(", "$", "this", "->", "getDatabaseSessionBagKey", "(", ")", ")", ";", "$", "databaseSessionBag", "->", "set", "(", "$", "this", "->", "getScope", "(", ")", ",", "$", "this", "->", "filterAttributes", "(", "true", ")", ")", ";", "}" ]
Save the data to the session. @return void
[ "Save", "the", "data", "to", "the", "session", "." ]
bf59fc2085cc848c564e40324dee14ef2897faa6
https://github.com/contao-community-alliance/dc-general/blob/bf59fc2085cc848c564e40324dee14ef2897faa6/src/Contao/SessionStorage.php#L207-L214
train
contao-community-alliance/dc-general
src/Contao/SessionStorage.php
SessionStorage.filterAttributes
private function filterAttributes($determineDatabase = false) { $databaseAttributes = \array_merge( (array) $this->databaseKeys['common'], (array) $this->databaseKeys[$this->getScope()] ); if ($determineDatabase) { return \array_intersect_key($this->attributes, \array_flip($databaseAttributes)); } return \array_diff_key($this->attributes, \array_flip($databaseAttributes)); }
php
private function filterAttributes($determineDatabase = false) { $databaseAttributes = \array_merge( (array) $this->databaseKeys['common'], (array) $this->databaseKeys[$this->getScope()] ); if ($determineDatabase) { return \array_intersect_key($this->attributes, \array_flip($databaseAttributes)); } return \array_diff_key($this->attributes, \array_flip($databaseAttributes)); }
[ "private", "function", "filterAttributes", "(", "$", "determineDatabase", "=", "false", ")", "{", "$", "databaseAttributes", "=", "\\", "array_merge", "(", "(", "array", ")", "$", "this", "->", "databaseKeys", "[", "'common'", "]", ",", "(", "array", ")", "$", "this", "->", "databaseKeys", "[", "$", "this", "->", "getScope", "(", ")", "]", ")", ";", "if", "(", "$", "determineDatabase", ")", "{", "return", "\\", "array_intersect_key", "(", "$", "this", "->", "attributes", ",", "\\", "array_flip", "(", "$", "databaseAttributes", ")", ")", ";", "}", "return", "\\", "array_diff_key", "(", "$", "this", "->", "attributes", ",", "\\", "array_flip", "(", "$", "databaseAttributes", ")", ")", ";", "}" ]
Filter the attributes. @param bool $determineDatabase Determine for filter database session attributes. If is false, this filter non database attributes. @return array
[ "Filter", "the", "attributes", "." ]
bf59fc2085cc848c564e40324dee14ef2897faa6
https://github.com/contao-community-alliance/dc-general/blob/bf59fc2085cc848c564e40324dee14ef2897faa6/src/Contao/SessionStorage.php#L224-L236
train
yiisoft/cache
src/Dependencies/TagDependency.php
TagDependency.touchKeys
protected static function touchKeys($cache, $keys): array { $items = []; $time = microtime(); foreach ($keys as $key) { $items[$key] = $time; } $cache->setMultiple($items); return $items; }
php
protected static function touchKeys($cache, $keys): array { $items = []; $time = microtime(); foreach ($keys as $key) { $items[$key] = $time; } $cache->setMultiple($items); return $items; }
[ "protected", "static", "function", "touchKeys", "(", "$", "cache", ",", "$", "keys", ")", ":", "array", "{", "$", "items", "=", "[", "]", ";", "$", "time", "=", "microtime", "(", ")", ";", "foreach", "(", "$", "keys", "as", "$", "key", ")", "{", "$", "items", "[", "$", "key", "]", "=", "$", "time", ";", "}", "$", "cache", "->", "setMultiple", "(", "$", "items", ")", ";", "return", "$", "items", ";", "}" ]
Generates the timestamp for the specified cache keys. @param \Psr\SimpleCache\CacheInterface $cache @param string[] $keys @return array the timestamp indexed by cache keys @throws \Psr\SimpleCache\InvalidArgumentException
[ "Generates", "the", "timestamp", "for", "the", "specified", "cache", "keys", "." ]
d3ffe8436270481e34842705817a5cf8025d947f
https://github.com/yiisoft/cache/blob/d3ffe8436270481e34842705817a5cf8025d947f/src/Dependencies/TagDependency.php#L95-L104
train
contao-community-alliance/dc-general
src/Data/TableRowsAsRecordsDataProvider.php
TableRowsAsRecordsDataProvider.setBaseConfig
public function setBaseConfig(array $config) { parent::setBaseConfig($config); if (!$config['group_column']) { throw new DcGeneralException(__CLASS__ . ' needs a grouping column.', 1); } $this->strGroupCol = $config['group_column']; if ($config['sort_column']) { $this->strSortCol = $config['sort_column']; } }
php
public function setBaseConfig(array $config) { parent::setBaseConfig($config); if (!$config['group_column']) { throw new DcGeneralException(__CLASS__ . ' needs a grouping column.', 1); } $this->strGroupCol = $config['group_column']; if ($config['sort_column']) { $this->strSortCol = $config['sort_column']; } }
[ "public", "function", "setBaseConfig", "(", "array", "$", "config", ")", "{", "parent", "::", "setBaseConfig", "(", "$", "config", ")", ";", "if", "(", "!", "$", "config", "[", "'group_column'", "]", ")", "{", "throw", "new", "DcGeneralException", "(", "__CLASS__", ".", "' needs a grouping column.'", ",", "1", ")", ";", "}", "$", "this", "->", "strGroupCol", "=", "$", "config", "[", "'group_column'", "]", ";", "if", "(", "$", "config", "[", "'sort_column'", "]", ")", "{", "$", "this", "->", "strSortCol", "=", "$", "config", "[", "'sort_column'", "]", ";", "}", "}" ]
Set base config with source and other necessary parameter. @param array $config The configuration to use. @return void @throws DcGeneralException When no source has been defined.
[ "Set", "base", "config", "with", "source", "and", "other", "necessary", "parameter", "." ]
bf59fc2085cc848c564e40324dee14ef2897faa6
https://github.com/contao-community-alliance/dc-general/blob/bf59fc2085cc848c564e40324dee14ef2897faa6/src/Data/TableRowsAsRecordsDataProvider.php#L59-L71
train
contao-community-alliance/dc-general
src/Data/TableRowsAsRecordsDataProvider.php
TableRowsAsRecordsDataProvider.fetch
public function fetch(ConfigInterface $config) { if (!$config->getId()) { throw new DcGeneralException( 'Error, no id passed, TableRowsAsRecordsDriver is only intended for edit mode.', 1 ); } $queryBuilder = $this->connection->createQueryBuilder(); DefaultDataProviderDBalUtils::addField($config, $this->idProperty, $queryBuilder); $queryBuilder->from($this->source); $queryBuilder->where($queryBuilder->expr()->eq($this->strGroupCol, ':' . $this->strGroupCol)); $queryBuilder->setParameter($this->strGroupCol, $config->getId()); if ($this->strSortCol) { $queryBuilder->orderBy($this->strSortCol, 'ASC'); } $statement = $queryBuilder->execute(); $model = $this->getEmptyModel(); $model->setID($config->getId()); if (0 < $statement->rowCount()) { $model->setPropertyRaw('rows', $statement->fetchAll(\PDO::FETCH_ASSOC)); } return $model; }
php
public function fetch(ConfigInterface $config) { if (!$config->getId()) { throw new DcGeneralException( 'Error, no id passed, TableRowsAsRecordsDriver is only intended for edit mode.', 1 ); } $queryBuilder = $this->connection->createQueryBuilder(); DefaultDataProviderDBalUtils::addField($config, $this->idProperty, $queryBuilder); $queryBuilder->from($this->source); $queryBuilder->where($queryBuilder->expr()->eq($this->strGroupCol, ':' . $this->strGroupCol)); $queryBuilder->setParameter($this->strGroupCol, $config->getId()); if ($this->strSortCol) { $queryBuilder->orderBy($this->strSortCol, 'ASC'); } $statement = $queryBuilder->execute(); $model = $this->getEmptyModel(); $model->setID($config->getId()); if (0 < $statement->rowCount()) { $model->setPropertyRaw('rows', $statement->fetchAll(\PDO::FETCH_ASSOC)); } return $model; }
[ "public", "function", "fetch", "(", "ConfigInterface", "$", "config", ")", "{", "if", "(", "!", "$", "config", "->", "getId", "(", ")", ")", "{", "throw", "new", "DcGeneralException", "(", "'Error, no id passed, TableRowsAsRecordsDriver is only intended for edit mode.'", ",", "1", ")", ";", "}", "$", "queryBuilder", "=", "$", "this", "->", "connection", "->", "createQueryBuilder", "(", ")", ";", "DefaultDataProviderDBalUtils", "::", "addField", "(", "$", "config", ",", "$", "this", "->", "idProperty", ",", "$", "queryBuilder", ")", ";", "$", "queryBuilder", "->", "from", "(", "$", "this", "->", "source", ")", ";", "$", "queryBuilder", "->", "where", "(", "$", "queryBuilder", "->", "expr", "(", ")", "->", "eq", "(", "$", "this", "->", "strGroupCol", ",", "':'", ".", "$", "this", "->", "strGroupCol", ")", ")", ";", "$", "queryBuilder", "->", "setParameter", "(", "$", "this", "->", "strGroupCol", ",", "$", "config", "->", "getId", "(", ")", ")", ";", "if", "(", "$", "this", "->", "strSortCol", ")", "{", "$", "queryBuilder", "->", "orderBy", "(", "$", "this", "->", "strSortCol", ",", "'ASC'", ")", ";", "}", "$", "statement", "=", "$", "queryBuilder", "->", "execute", "(", ")", ";", "$", "model", "=", "$", "this", "->", "getEmptyModel", "(", ")", ";", "$", "model", "->", "setID", "(", "$", "config", "->", "getId", "(", ")", ")", ";", "if", "(", "0", "<", "$", "statement", "->", "rowCount", "(", ")", ")", "{", "$", "model", "->", "setPropertyRaw", "(", "'rows'", ",", "$", "statement", "->", "fetchAll", "(", "\\", "PDO", "::", "FETCH_ASSOC", ")", ")", ";", "}", "return", "$", "model", ";", "}" ]
Fetch a single record by id. This data provider only supports retrieving by id so use $objConfig->setId() to populate the config with an Id. @param ConfigInterface $config The configuration to use. @return ModelInterface @throws DcGeneralException If config object does not contain an Id.
[ "Fetch", "a", "single", "record", "by", "id", "." ]
bf59fc2085cc848c564e40324dee14ef2897faa6
https://github.com/contao-community-alliance/dc-general/blob/bf59fc2085cc848c564e40324dee14ef2897faa6/src/Data/TableRowsAsRecordsDataProvider.php#L144-L172
train
contao-community-alliance/dc-general
src/Data/TableRowsAsRecordsDataProvider.php
TableRowsAsRecordsDataProvider.save
public function save(ModelInterface $item, $timestamp = 0, $recursive = false) { if (!\is_int($timestamp)) { throw new DcGeneralException('The parameter for this method has been change!'); } $data = $item->getProperty('rows'); if (!($data && $item->getId())) { throw new DcGeneralException('invalid input data in model.', 1); } $keep = []; foreach ($data as $row) { $sqlData = $row; // Update all. $intId = (int) $row['id']; // Always unset id. unset($sqlData['id']); // Work around the fact that multicolumnwizard does not clear any hidden fields when copying a dataset. // therefore we do consider any dupe as new dataset and save it accordingly. if (\in_array($intId, $keep)) { $intId = 0; } if ($intId > 0) { $this->connection->update( $this->source, $sqlData, ['id' => $intId, $this->strGroupCol => $item->getId()] ); $keep[] = $intId; continue; } // Force group col value. $sqlData[$this->strGroupCol] = $item->getId(); $this->connection->insert($this->source, $sqlData); $keep[] = $this->connection->lastInsertId($this->source); } // House keeping, kill the rest. $queryBuilder = $this->connection->createQueryBuilder(); $queryBuilder->delete($this->source); $queryBuilder->andWhere($queryBuilder->expr()->eq($this->strGroupCol, ':' . $this->strGroupCol)); $queryBuilder->setParameter(':' . $this->strGroupCol, $item->getId()); $queryBuilder->andWhere($queryBuilder->expr()->notIn('id', $keep)); $queryBuilder->execute(); return $item; }
php
public function save(ModelInterface $item, $timestamp = 0, $recursive = false) { if (!\is_int($timestamp)) { throw new DcGeneralException('The parameter for this method has been change!'); } $data = $item->getProperty('rows'); if (!($data && $item->getId())) { throw new DcGeneralException('invalid input data in model.', 1); } $keep = []; foreach ($data as $row) { $sqlData = $row; // Update all. $intId = (int) $row['id']; // Always unset id. unset($sqlData['id']); // Work around the fact that multicolumnwizard does not clear any hidden fields when copying a dataset. // therefore we do consider any dupe as new dataset and save it accordingly. if (\in_array($intId, $keep)) { $intId = 0; } if ($intId > 0) { $this->connection->update( $this->source, $sqlData, ['id' => $intId, $this->strGroupCol => $item->getId()] ); $keep[] = $intId; continue; } // Force group col value. $sqlData[$this->strGroupCol] = $item->getId(); $this->connection->insert($this->source, $sqlData); $keep[] = $this->connection->lastInsertId($this->source); } // House keeping, kill the rest. $queryBuilder = $this->connection->createQueryBuilder(); $queryBuilder->delete($this->source); $queryBuilder->andWhere($queryBuilder->expr()->eq($this->strGroupCol, ':' . $this->strGroupCol)); $queryBuilder->setParameter(':' . $this->strGroupCol, $item->getId()); $queryBuilder->andWhere($queryBuilder->expr()->notIn('id', $keep)); $queryBuilder->execute(); return $item; }
[ "public", "function", "save", "(", "ModelInterface", "$", "item", ",", "$", "timestamp", "=", "0", ",", "$", "recursive", "=", "false", ")", "{", "if", "(", "!", "\\", "is_int", "(", "$", "timestamp", ")", ")", "{", "throw", "new", "DcGeneralException", "(", "'The parameter for this method has been change!'", ")", ";", "}", "$", "data", "=", "$", "item", "->", "getProperty", "(", "'rows'", ")", ";", "if", "(", "!", "(", "$", "data", "&&", "$", "item", "->", "getId", "(", ")", ")", ")", "{", "throw", "new", "DcGeneralException", "(", "'invalid input data in model.'", ",", "1", ")", ";", "}", "$", "keep", "=", "[", "]", ";", "foreach", "(", "$", "data", "as", "$", "row", ")", "{", "$", "sqlData", "=", "$", "row", ";", "// Update all.", "$", "intId", "=", "(", "int", ")", "$", "row", "[", "'id'", "]", ";", "// Always unset id.", "unset", "(", "$", "sqlData", "[", "'id'", "]", ")", ";", "// Work around the fact that multicolumnwizard does not clear any hidden fields when copying a dataset.", "// therefore we do consider any dupe as new dataset and save it accordingly.", "if", "(", "\\", "in_array", "(", "$", "intId", ",", "$", "keep", ")", ")", "{", "$", "intId", "=", "0", ";", "}", "if", "(", "$", "intId", ">", "0", ")", "{", "$", "this", "->", "connection", "->", "update", "(", "$", "this", "->", "source", ",", "$", "sqlData", ",", "[", "'id'", "=>", "$", "intId", ",", "$", "this", "->", "strGroupCol", "=>", "$", "item", "->", "getId", "(", ")", "]", ")", ";", "$", "keep", "[", "]", "=", "$", "intId", ";", "continue", ";", "}", "// Force group col value.", "$", "sqlData", "[", "$", "this", "->", "strGroupCol", "]", "=", "$", "item", "->", "getId", "(", ")", ";", "$", "this", "->", "connection", "->", "insert", "(", "$", "this", "->", "source", ",", "$", "sqlData", ")", ";", "$", "keep", "[", "]", "=", "$", "this", "->", "connection", "->", "lastInsertId", "(", "$", "this", "->", "source", ")", ";", "}", "// House keeping, kill the rest.", "$", "queryBuilder", "=", "$", "this", "->", "connection", "->", "createQueryBuilder", "(", ")", ";", "$", "queryBuilder", "->", "delete", "(", "$", "this", "->", "source", ")", ";", "$", "queryBuilder", "->", "andWhere", "(", "$", "queryBuilder", "->", "expr", "(", ")", "->", "eq", "(", "$", "this", "->", "strGroupCol", ",", "':'", ".", "$", "this", "->", "strGroupCol", ")", ")", ";", "$", "queryBuilder", "->", "setParameter", "(", "':'", ".", "$", "this", "->", "strGroupCol", ",", "$", "item", "->", "getId", "(", ")", ")", ";", "$", "queryBuilder", "->", "andWhere", "(", "$", "queryBuilder", "->", "expr", "(", ")", "->", "notIn", "(", "'id'", ",", "$", "keep", ")", ")", ";", "$", "queryBuilder", "->", "execute", "(", ")", ";", "return", "$", "item", ";", "}" ]
Save a model to the database. In general, this method fetches the solely property "rows" from the model and updates the local table against these contents. The parent id (id of the model) will get checked and reflected also for new items. When rows with duplicate ids are encountered (like from MCW for example), the dupes are inserted as new rows. @param ModelInterface $item The model to save. @param int $timestamp Optional the timestamp. @param bool $recursive Ignored as not relevant in this data provider. @return ModelInterface The passed Model. @throws DcGeneralException When the passed model does not contain a property named "rows", an Exception is thrown. @SuppressWarnings(PHPMD.UnusedFormalParameter)
[ "Save", "a", "model", "to", "the", "database", "." ]
bf59fc2085cc848c564e40324dee14ef2897faa6
https://github.com/contao-community-alliance/dc-general/blob/bf59fc2085cc848c564e40324dee14ef2897faa6/src/Data/TableRowsAsRecordsDataProvider.php#L261-L316
train
contao-community-alliance/dc-general
src/DataDefinition/ModelRelationship/AbstractCondition.php
AbstractCondition.checkAndFilter
protected static function checkAndFilter($model, $filter) { foreach ($filter as $child) { // AND => first false means false. if (!self::checkCondition($model, $child)) { return false; } } return true; }
php
protected static function checkAndFilter($model, $filter) { foreach ($filter as $child) { // AND => first false means false. if (!self::checkCondition($model, $child)) { return false; } } return true; }
[ "protected", "static", "function", "checkAndFilter", "(", "$", "model", ",", "$", "filter", ")", "{", "foreach", "(", "$", "filter", "as", "$", "child", ")", "{", "// AND => first false means false.", "if", "(", "!", "self", "::", "checkCondition", "(", "$", "model", ",", "$", "child", ")", ")", "{", "return", "false", ";", "}", "}", "return", "true", ";", "}" ]
Check if an AND condition filter matches. @param ModelInterface $model The model to check the condition against. @param array $filter The filter rules to be applied. @return bool
[ "Check", "if", "an", "AND", "condition", "filter", "matches", "." ]
bf59fc2085cc848c564e40324dee14ef2897faa6
https://github.com/contao-community-alliance/dc-general/blob/bf59fc2085cc848c564e40324dee14ef2897faa6/src/DataDefinition/ModelRelationship/AbstractCondition.php#L42-L51
train
contao-community-alliance/dc-general
src/DataDefinition/ModelRelationship/AbstractCondition.php
AbstractCondition.checkCondition
public static function checkCondition(ModelInterface $objParentModel, $arrFilter) { switch ($arrFilter['operation']) { case 'AND': return self::checkAndFilter($objParentModel, $arrFilter['children']); case 'OR': return self::checkOrFilter($objParentModel, $arrFilter['children']); case '=': return (self::getConditionValue($arrFilter, $objParentModel) == $arrFilter['value']); case '>': return (self::getConditionValue($arrFilter, $objParentModel) > $arrFilter['value']); case '<': return (self::getConditionValue($arrFilter, $objParentModel) < $arrFilter['value']); case 'IN': return \in_array($objParentModel->getProperty($arrFilter['property']), $arrFilter['values']); case 'LIKE': throw new DcGeneralRuntimeException('LIKE unsupported as of now.'); default: } throw new DcGeneralRuntimeException( 'Error processing filter array - unknown operation ' . \var_export($arrFilter, true), 1 ); }
php
public static function checkCondition(ModelInterface $objParentModel, $arrFilter) { switch ($arrFilter['operation']) { case 'AND': return self::checkAndFilter($objParentModel, $arrFilter['children']); case 'OR': return self::checkOrFilter($objParentModel, $arrFilter['children']); case '=': return (self::getConditionValue($arrFilter, $objParentModel) == $arrFilter['value']); case '>': return (self::getConditionValue($arrFilter, $objParentModel) > $arrFilter['value']); case '<': return (self::getConditionValue($arrFilter, $objParentModel) < $arrFilter['value']); case 'IN': return \in_array($objParentModel->getProperty($arrFilter['property']), $arrFilter['values']); case 'LIKE': throw new DcGeneralRuntimeException('LIKE unsupported as of now.'); default: } throw new DcGeneralRuntimeException( 'Error processing filter array - unknown operation ' . \var_export($arrFilter, true), 1 ); }
[ "public", "static", "function", "checkCondition", "(", "ModelInterface", "$", "objParentModel", ",", "$", "arrFilter", ")", "{", "switch", "(", "$", "arrFilter", "[", "'operation'", "]", ")", "{", "case", "'AND'", ":", "return", "self", "::", "checkAndFilter", "(", "$", "objParentModel", ",", "$", "arrFilter", "[", "'children'", "]", ")", ";", "case", "'OR'", ":", "return", "self", "::", "checkOrFilter", "(", "$", "objParentModel", ",", "$", "arrFilter", "[", "'children'", "]", ")", ";", "case", "'='", ":", "return", "(", "self", "::", "getConditionValue", "(", "$", "arrFilter", ",", "$", "objParentModel", ")", "==", "$", "arrFilter", "[", "'value'", "]", ")", ";", "case", "'>'", ":", "return", "(", "self", "::", "getConditionValue", "(", "$", "arrFilter", ",", "$", "objParentModel", ")", ">", "$", "arrFilter", "[", "'value'", "]", ")", ";", "case", "'<'", ":", "return", "(", "self", "::", "getConditionValue", "(", "$", "arrFilter", ",", "$", "objParentModel", ")", "<", "$", "arrFilter", "[", "'value'", "]", ")", ";", "case", "'IN'", ":", "return", "\\", "in_array", "(", "$", "objParentModel", "->", "getProperty", "(", "$", "arrFilter", "[", "'property'", "]", ")", ",", "$", "arrFilter", "[", "'values'", "]", ")", ";", "case", "'LIKE'", ":", "throw", "new", "DcGeneralRuntimeException", "(", "'LIKE unsupported as of now.'", ")", ";", "default", ":", "}", "throw", "new", "DcGeneralRuntimeException", "(", "'Error processing filter array - unknown operation '", ".", "\\", "var_export", "(", "$", "arrFilter", ",", "true", ")", ",", "1", ")", ";", "}" ]
Check if the passed filter rules apply to the given model. @param ModelInterface $objParentModel The model to check the condition against. @param array $arrFilter The condition filter to be applied. @return bool @throws DcGeneralRuntimeException When an unknown filter operation is encountered.
[ "Check", "if", "the", "passed", "filter", "rules", "apply", "to", "the", "given", "model", "." ]
bf59fc2085cc848c564e40324dee14ef2897faa6
https://github.com/contao-community-alliance/dc-general/blob/bf59fc2085cc848c564e40324dee14ef2897faa6/src/DataDefinition/ModelRelationship/AbstractCondition.php#L95-L126
train
contao-community-alliance/dc-general
src/Contao/View/Contao2BackendView/Subscriber/CheckPermission.php
CheckPermission.checkPermissionForProperties
public function checkPermissionForProperties(BuildDataDefinitionEvent $event) { if (!$this->scopeDeterminator->currentScopeIsBackend()) { return; } $container = $event->getContainer(); $properties = $container->getPropertiesDefinition(); $palettesDefinition = $container->getPalettesDefinition(); foreach ($palettesDefinition->getPalettes() as $palette) { foreach ($palette->getProperties() as $property) { if (!$properties->hasProperty($name = $property->getName())) { // @codingStandardsIgnoreStart @\trigger_error( \sprintf( 'Warning: unknown property "%s" in palette: %s', $name, $palette->getName() ), E_USER_WARNING ); // @codingStandardsIgnoreEnd continue; } $this ->getVisibilityConditionChain($property) ->addCondition(new BooleanCondition(!$properties->getProperty($name)->isExcluded())); } } }
php
public function checkPermissionForProperties(BuildDataDefinitionEvent $event) { if (!$this->scopeDeterminator->currentScopeIsBackend()) { return; } $container = $event->getContainer(); $properties = $container->getPropertiesDefinition(); $palettesDefinition = $container->getPalettesDefinition(); foreach ($palettesDefinition->getPalettes() as $palette) { foreach ($palette->getProperties() as $property) { if (!$properties->hasProperty($name = $property->getName())) { // @codingStandardsIgnoreStart @\trigger_error( \sprintf( 'Warning: unknown property "%s" in palette: %s', $name, $palette->getName() ), E_USER_WARNING ); // @codingStandardsIgnoreEnd continue; } $this ->getVisibilityConditionChain($property) ->addCondition(new BooleanCondition(!$properties->getProperty($name)->isExcluded())); } } }
[ "public", "function", "checkPermissionForProperties", "(", "BuildDataDefinitionEvent", "$", "event", ")", "{", "if", "(", "!", "$", "this", "->", "scopeDeterminator", "->", "currentScopeIsBackend", "(", ")", ")", "{", "return", ";", "}", "$", "container", "=", "$", "event", "->", "getContainer", "(", ")", ";", "$", "properties", "=", "$", "container", "->", "getPropertiesDefinition", "(", ")", ";", "$", "palettesDefinition", "=", "$", "container", "->", "getPalettesDefinition", "(", ")", ";", "foreach", "(", "$", "palettesDefinition", "->", "getPalettes", "(", ")", "as", "$", "palette", ")", "{", "foreach", "(", "$", "palette", "->", "getProperties", "(", ")", "as", "$", "property", ")", "{", "if", "(", "!", "$", "properties", "->", "hasProperty", "(", "$", "name", "=", "$", "property", "->", "getName", "(", ")", ")", ")", "{", "// @codingStandardsIgnoreStart", "@", "\\", "trigger_error", "(", "\\", "sprintf", "(", "'Warning: unknown property \"%s\" in palette: %s'", ",", "$", "name", ",", "$", "palette", "->", "getName", "(", ")", ")", ",", "E_USER_WARNING", ")", ";", "// @codingStandardsIgnoreEnd", "continue", ";", "}", "$", "this", "->", "getVisibilityConditionChain", "(", "$", "property", ")", "->", "addCondition", "(", "new", "BooleanCondition", "(", "!", "$", "properties", "->", "getProperty", "(", "$", "name", ")", "->", "isExcluded", "(", ")", ")", ")", ";", "}", "}", "}" ]
Check permission for properties by user alexf. @param BuildDataDefinitionEvent $event The event. @return void
[ "Check", "permission", "for", "properties", "by", "user", "alexf", "." ]
bf59fc2085cc848c564e40324dee14ef2897faa6
https://github.com/contao-community-alliance/dc-general/blob/bf59fc2085cc848c564e40324dee14ef2897faa6/src/Contao/View/Contao2BackendView/Subscriber/CheckPermission.php#L77-L108
train
contao-community-alliance/dc-general
src/Contao/View/Contao2BackendView/Subscriber/CheckPermission.php
CheckPermission.checkPermissionIsEditable
public function checkPermissionIsEditable(BuildDataDefinitionEvent $event) { if (!$this->scopeDeterminator->currentScopeIsBackend()) { return; } $container = $event->getContainer(); if ($container->getBasicDefinition()->isEditable()) { return; } $view = $container->getDefinition(Contao2BackendViewDefinitionInterface::NAME); $modelCommands = $view->getModelCommands(); $this->disableCommandByActionName($modelCommands, 'edit'); $this->disableCommandByActionName($modelCommands, 'cut'); $this->disableToggleCommand($modelCommands); }
php
public function checkPermissionIsEditable(BuildDataDefinitionEvent $event) { if (!$this->scopeDeterminator->currentScopeIsBackend()) { return; } $container = $event->getContainer(); if ($container->getBasicDefinition()->isEditable()) { return; } $view = $container->getDefinition(Contao2BackendViewDefinitionInterface::NAME); $modelCommands = $view->getModelCommands(); $this->disableCommandByActionName($modelCommands, 'edit'); $this->disableCommandByActionName($modelCommands, 'cut'); $this->disableToggleCommand($modelCommands); }
[ "public", "function", "checkPermissionIsEditable", "(", "BuildDataDefinitionEvent", "$", "event", ")", "{", "if", "(", "!", "$", "this", "->", "scopeDeterminator", "->", "currentScopeIsBackend", "(", ")", ")", "{", "return", ";", "}", "$", "container", "=", "$", "event", "->", "getContainer", "(", ")", ";", "if", "(", "$", "container", "->", "getBasicDefinition", "(", ")", "->", "isEditable", "(", ")", ")", "{", "return", ";", "}", "$", "view", "=", "$", "container", "->", "getDefinition", "(", "Contao2BackendViewDefinitionInterface", "::", "NAME", ")", ";", "$", "modelCommands", "=", "$", "view", "->", "getModelCommands", "(", ")", ";", "$", "this", "->", "disableCommandByActionName", "(", "$", "modelCommands", ",", "'edit'", ")", ";", "$", "this", "->", "disableCommandByActionName", "(", "$", "modelCommands", ",", "'cut'", ")", ";", "$", "this", "->", "disableToggleCommand", "(", "$", "modelCommands", ")", ";", "}" ]
Check permission is editable. @param BuildDataDefinitionEvent $event The event. @return void
[ "Check", "permission", "is", "editable", "." ]
bf59fc2085cc848c564e40324dee14ef2897faa6
https://github.com/contao-community-alliance/dc-general/blob/bf59fc2085cc848c564e40324dee14ef2897faa6/src/Contao/View/Contao2BackendView/Subscriber/CheckPermission.php#L117-L135
train
contao-community-alliance/dc-general
src/Contao/View/Contao2BackendView/Subscriber/CheckPermission.php
CheckPermission.checkPermissionIsDeletable
public function checkPermissionIsDeletable(BuildDataDefinitionEvent $event) { if (!$this->scopeDeterminator->currentScopeIsBackend()) { return; } $container = $event->getContainer(); if ($container->getBasicDefinition()->isDeletable()) { return; } $view = $container->getDefinition(Contao2BackendViewDefinitionInterface::NAME); $modelCommands = $view->getModelCommands(); $this->disableCommandByActionName($modelCommands, 'delete'); }
php
public function checkPermissionIsDeletable(BuildDataDefinitionEvent $event) { if (!$this->scopeDeterminator->currentScopeIsBackend()) { return; } $container = $event->getContainer(); if ($container->getBasicDefinition()->isDeletable()) { return; } $view = $container->getDefinition(Contao2BackendViewDefinitionInterface::NAME); $modelCommands = $view->getModelCommands(); $this->disableCommandByActionName($modelCommands, 'delete'); }
[ "public", "function", "checkPermissionIsDeletable", "(", "BuildDataDefinitionEvent", "$", "event", ")", "{", "if", "(", "!", "$", "this", "->", "scopeDeterminator", "->", "currentScopeIsBackend", "(", ")", ")", "{", "return", ";", "}", "$", "container", "=", "$", "event", "->", "getContainer", "(", ")", ";", "if", "(", "$", "container", "->", "getBasicDefinition", "(", ")", "->", "isDeletable", "(", ")", ")", "{", "return", ";", "}", "$", "view", "=", "$", "container", "->", "getDefinition", "(", "Contao2BackendViewDefinitionInterface", "::", "NAME", ")", ";", "$", "modelCommands", "=", "$", "view", "->", "getModelCommands", "(", ")", ";", "$", "this", "->", "disableCommandByActionName", "(", "$", "modelCommands", ",", "'delete'", ")", ";", "}" ]
Check permission is deletable. @param BuildDataDefinitionEvent $event The event. @return void
[ "Check", "permission", "is", "deletable", "." ]
bf59fc2085cc848c564e40324dee14ef2897faa6
https://github.com/contao-community-alliance/dc-general/blob/bf59fc2085cc848c564e40324dee14ef2897faa6/src/Contao/View/Contao2BackendView/Subscriber/CheckPermission.php#L144-L160
train
contao-community-alliance/dc-general
src/Contao/View/Contao2BackendView/Subscriber/CheckPermission.php
CheckPermission.checkPermissionIsCreatable
public function checkPermissionIsCreatable(BuildDataDefinitionEvent $event) { if (!$this->scopeDeterminator->currentScopeIsBackend()) { return; } $container = $event->getContainer(); if ($container->getBasicDefinition()->isCreatable()) { return; } $view = $container->getDefinition(Contao2BackendViewDefinitionInterface::NAME); $modelCommands = $view->getModelCommands(); $this->disableCommandByActionName($modelCommands, 'copy'); }
php
public function checkPermissionIsCreatable(BuildDataDefinitionEvent $event) { if (!$this->scopeDeterminator->currentScopeIsBackend()) { return; } $container = $event->getContainer(); if ($container->getBasicDefinition()->isCreatable()) { return; } $view = $container->getDefinition(Contao2BackendViewDefinitionInterface::NAME); $modelCommands = $view->getModelCommands(); $this->disableCommandByActionName($modelCommands, 'copy'); }
[ "public", "function", "checkPermissionIsCreatable", "(", "BuildDataDefinitionEvent", "$", "event", ")", "{", "if", "(", "!", "$", "this", "->", "scopeDeterminator", "->", "currentScopeIsBackend", "(", ")", ")", "{", "return", ";", "}", "$", "container", "=", "$", "event", "->", "getContainer", "(", ")", ";", "if", "(", "$", "container", "->", "getBasicDefinition", "(", ")", "->", "isCreatable", "(", ")", ")", "{", "return", ";", "}", "$", "view", "=", "$", "container", "->", "getDefinition", "(", "Contao2BackendViewDefinitionInterface", "::", "NAME", ")", ";", "$", "modelCommands", "=", "$", "view", "->", "getModelCommands", "(", ")", ";", "$", "this", "->", "disableCommandByActionName", "(", "$", "modelCommands", ",", "'copy'", ")", ";", "}" ]
Check permission is creatable. @param BuildDataDefinitionEvent $event The event. @return void
[ "Check", "permission", "is", "creatable", "." ]
bf59fc2085cc848c564e40324dee14ef2897faa6
https://github.com/contao-community-alliance/dc-general/blob/bf59fc2085cc848c564e40324dee14ef2897faa6/src/Contao/View/Contao2BackendView/Subscriber/CheckPermission.php#L169-L185
train
contao-community-alliance/dc-general
src/Contao/View/Contao2BackendView/Subscriber/CheckPermission.php
CheckPermission.getVisibilityConditionChain
private function getVisibilityConditionChain($property) { if (($chain = $property->getVisibleCondition()) && ($chain instanceof PropertyConditionChain) && $chain->getConjunction() === PropertyConditionChain::AND_CONJUNCTION ) { return $chain; } $newChain = new PropertyConditionChain($chain ? [$chain] : []); $property->setVisibleCondition($newChain); return $newChain; }
php
private function getVisibilityConditionChain($property) { if (($chain = $property->getVisibleCondition()) && ($chain instanceof PropertyConditionChain) && $chain->getConjunction() === PropertyConditionChain::AND_CONJUNCTION ) { return $chain; } $newChain = new PropertyConditionChain($chain ? [$chain] : []); $property->setVisibleCondition($newChain); return $newChain; }
[ "private", "function", "getVisibilityConditionChain", "(", "$", "property", ")", "{", "if", "(", "(", "$", "chain", "=", "$", "property", "->", "getVisibleCondition", "(", ")", ")", "&&", "(", "$", "chain", "instanceof", "PropertyConditionChain", ")", "&&", "$", "chain", "->", "getConjunction", "(", ")", "===", "PropertyConditionChain", "::", "AND_CONJUNCTION", ")", "{", "return", "$", "chain", ";", "}", "$", "newChain", "=", "new", "PropertyConditionChain", "(", "$", "chain", "?", "[", "$", "chain", "]", ":", "[", "]", ")", ";", "$", "property", "->", "setVisibleCondition", "(", "$", "newChain", ")", ";", "return", "$", "newChain", ";", "}" ]
Retrieve the visibility condition chain or create an empty one if none exists. @param PropertyInterface $property The property. @return PropertyConditionChain
[ "Retrieve", "the", "visibility", "condition", "chain", "or", "create", "an", "empty", "one", "if", "none", "exists", "." ]
bf59fc2085cc848c564e40324dee14ef2897faa6
https://github.com/contao-community-alliance/dc-general/blob/bf59fc2085cc848c564e40324dee14ef2897faa6/src/Contao/View/Contao2BackendView/Subscriber/CheckPermission.php#L194-L207
train
contao-community-alliance/dc-general
src/Contao/View/Contao2BackendView/Subscriber/CheckPermission.php
CheckPermission.disableCommandByActionName
private function disableCommandByActionName(CommandCollectionInterface $commands, $actionName) { foreach ($commands->getCommands() as $command) { $parameters = $command->getParameters()->getArrayCopy(); $disableCommand = false; if (\array_key_exists('act', $parameters) && ($parameters['act'] === $actionName) ) { $disableCommand = true; } if (!$disableCommand && ($command->getName() === $actionName)) { $disableCommand = true; } if (!$disableCommand) { continue; } $command->setDisabled(); } }
php
private function disableCommandByActionName(CommandCollectionInterface $commands, $actionName) { foreach ($commands->getCommands() as $command) { $parameters = $command->getParameters()->getArrayCopy(); $disableCommand = false; if (\array_key_exists('act', $parameters) && ($parameters['act'] === $actionName) ) { $disableCommand = true; } if (!$disableCommand && ($command->getName() === $actionName)) { $disableCommand = true; } if (!$disableCommand) { continue; } $command->setDisabled(); } }
[ "private", "function", "disableCommandByActionName", "(", "CommandCollectionInterface", "$", "commands", ",", "$", "actionName", ")", "{", "foreach", "(", "$", "commands", "->", "getCommands", "(", ")", "as", "$", "command", ")", "{", "$", "parameters", "=", "$", "command", "->", "getParameters", "(", ")", "->", "getArrayCopy", "(", ")", ";", "$", "disableCommand", "=", "false", ";", "if", "(", "\\", "array_key_exists", "(", "'act'", ",", "$", "parameters", ")", "&&", "(", "$", "parameters", "[", "'act'", "]", "===", "$", "actionName", ")", ")", "{", "$", "disableCommand", "=", "true", ";", "}", "if", "(", "!", "$", "disableCommand", "&&", "(", "$", "command", "->", "getName", "(", ")", "===", "$", "actionName", ")", ")", "{", "$", "disableCommand", "=", "true", ";", "}", "if", "(", "!", "$", "disableCommand", ")", "{", "continue", ";", "}", "$", "command", "->", "setDisabled", "(", ")", ";", "}", "}" ]
Disable command by action name. @param CommandCollectionInterface $commands The commands collection. @param string $actionName The action name. @return void
[ "Disable", "command", "by", "action", "name", "." ]
bf59fc2085cc848c564e40324dee14ef2897faa6
https://github.com/contao-community-alliance/dc-general/blob/bf59fc2085cc848c564e40324dee14ef2897faa6/src/Contao/View/Contao2BackendView/Subscriber/CheckPermission.php#L217-L240
train
contao-community-alliance/dc-general
src/Contao/View/Contao2BackendView/Subscriber/CheckPermission.php
CheckPermission.disableToggleCommand
private function disableToggleCommand(CommandCollectionInterface $commands) { foreach ($commands->getCommands() as $command) { if (!($command instanceof ToggleCommandInterface)) { continue; } $this->disableCommandByActionName($commands, $command->getName()); } }
php
private function disableToggleCommand(CommandCollectionInterface $commands) { foreach ($commands->getCommands() as $command) { if (!($command instanceof ToggleCommandInterface)) { continue; } $this->disableCommandByActionName($commands, $command->getName()); } }
[ "private", "function", "disableToggleCommand", "(", "CommandCollectionInterface", "$", "commands", ")", "{", "foreach", "(", "$", "commands", "->", "getCommands", "(", ")", "as", "$", "command", ")", "{", "if", "(", "!", "(", "$", "command", "instanceof", "ToggleCommandInterface", ")", ")", "{", "continue", ";", "}", "$", "this", "->", "disableCommandByActionName", "(", "$", "commands", ",", "$", "command", "->", "getName", "(", ")", ")", ";", "}", "}" ]
Disable the toggle command. @param CommandCollectionInterface $commands The commands collection. @return void
[ "Disable", "the", "toggle", "command", "." ]
bf59fc2085cc848c564e40324dee14ef2897faa6
https://github.com/contao-community-alliance/dc-general/blob/bf59fc2085cc848c564e40324dee14ef2897faa6/src/Contao/View/Contao2BackendView/Subscriber/CheckPermission.php#L249-L258
train
contao-community-alliance/dc-general
src/Controller/ModelCollector.php
ModelCollector.getModel
public function getModel($modelId, $providerName = null) { if (\is_string($modelId)) { try { $modelId = ModelId::fromValues($providerName, $modelId); } catch (\Exception $swallow) { $modelId = ModelId::fromSerialized($modelId); } } if (!($modelId instanceof ModelIdInterface)) { throw new \InvalidArgumentException('Invalid model id passed: ' . \var_export($modelId, true)); } $definition = $this->environment->getDataDefinition(); $parentDefinition = $this->environment->getParentDataDefinition(); $dataProvider = $this->environment->getDataProvider($modelId->getDataProviderName()); $config = $dataProvider->getEmptyConfig(); if ($definition->getName() === $modelId->getDataProviderName()) { $propertyDefinition = $definition->getPropertiesDefinition(); } elseif ($parentDefinition->getName() === $modelId->getDataProviderName()) { $propertyDefinition = $parentDefinition->getPropertiesDefinition(); } else { throw new \InvalidArgumentException('Invalid provider name ' . $modelId->getDataProviderName()); } $properties = []; // Filter real properties from the property definition. foreach ($propertyDefinition->getPropertyNames() as $propertyName) { if ($dataProvider->fieldExists($propertyName)) { $properties[] = $propertyName; continue; } // @codingStandardsIgnoreStart @\trigger_error( 'Only real property is allowed in the property definition.' . 'This will no longer be supported in the future.', E_DEPRECATED ); // @codingStandardsIgnoreEnd } $config->setId($modelId->getId())->setFields($properties); return $dataProvider->fetch($config); }
php
public function getModel($modelId, $providerName = null) { if (\is_string($modelId)) { try { $modelId = ModelId::fromValues($providerName, $modelId); } catch (\Exception $swallow) { $modelId = ModelId::fromSerialized($modelId); } } if (!($modelId instanceof ModelIdInterface)) { throw new \InvalidArgumentException('Invalid model id passed: ' . \var_export($modelId, true)); } $definition = $this->environment->getDataDefinition(); $parentDefinition = $this->environment->getParentDataDefinition(); $dataProvider = $this->environment->getDataProvider($modelId->getDataProviderName()); $config = $dataProvider->getEmptyConfig(); if ($definition->getName() === $modelId->getDataProviderName()) { $propertyDefinition = $definition->getPropertiesDefinition(); } elseif ($parentDefinition->getName() === $modelId->getDataProviderName()) { $propertyDefinition = $parentDefinition->getPropertiesDefinition(); } else { throw new \InvalidArgumentException('Invalid provider name ' . $modelId->getDataProviderName()); } $properties = []; // Filter real properties from the property definition. foreach ($propertyDefinition->getPropertyNames() as $propertyName) { if ($dataProvider->fieldExists($propertyName)) { $properties[] = $propertyName; continue; } // @codingStandardsIgnoreStart @\trigger_error( 'Only real property is allowed in the property definition.' . 'This will no longer be supported in the future.', E_DEPRECATED ); // @codingStandardsIgnoreEnd } $config->setId($modelId->getId())->setFields($properties); return $dataProvider->fetch($config); }
[ "public", "function", "getModel", "(", "$", "modelId", ",", "$", "providerName", "=", "null", ")", "{", "if", "(", "\\", "is_string", "(", "$", "modelId", ")", ")", "{", "try", "{", "$", "modelId", "=", "ModelId", "::", "fromValues", "(", "$", "providerName", ",", "$", "modelId", ")", ";", "}", "catch", "(", "\\", "Exception", "$", "swallow", ")", "{", "$", "modelId", "=", "ModelId", "::", "fromSerialized", "(", "$", "modelId", ")", ";", "}", "}", "if", "(", "!", "(", "$", "modelId", "instanceof", "ModelIdInterface", ")", ")", "{", "throw", "new", "\\", "InvalidArgumentException", "(", "'Invalid model id passed: '", ".", "\\", "var_export", "(", "$", "modelId", ",", "true", ")", ")", ";", "}", "$", "definition", "=", "$", "this", "->", "environment", "->", "getDataDefinition", "(", ")", ";", "$", "parentDefinition", "=", "$", "this", "->", "environment", "->", "getParentDataDefinition", "(", ")", ";", "$", "dataProvider", "=", "$", "this", "->", "environment", "->", "getDataProvider", "(", "$", "modelId", "->", "getDataProviderName", "(", ")", ")", ";", "$", "config", "=", "$", "dataProvider", "->", "getEmptyConfig", "(", ")", ";", "if", "(", "$", "definition", "->", "getName", "(", ")", "===", "$", "modelId", "->", "getDataProviderName", "(", ")", ")", "{", "$", "propertyDefinition", "=", "$", "definition", "->", "getPropertiesDefinition", "(", ")", ";", "}", "elseif", "(", "$", "parentDefinition", "->", "getName", "(", ")", "===", "$", "modelId", "->", "getDataProviderName", "(", ")", ")", "{", "$", "propertyDefinition", "=", "$", "parentDefinition", "->", "getPropertiesDefinition", "(", ")", ";", "}", "else", "{", "throw", "new", "\\", "InvalidArgumentException", "(", "'Invalid provider name '", ".", "$", "modelId", "->", "getDataProviderName", "(", ")", ")", ";", "}", "$", "properties", "=", "[", "]", ";", "// Filter real properties from the property definition.", "foreach", "(", "$", "propertyDefinition", "->", "getPropertyNames", "(", ")", "as", "$", "propertyName", ")", "{", "if", "(", "$", "dataProvider", "->", "fieldExists", "(", "$", "propertyName", ")", ")", "{", "$", "properties", "[", "]", "=", "$", "propertyName", ";", "continue", ";", "}", "// @codingStandardsIgnoreStart", "@", "\\", "trigger_error", "(", "'Only real property is allowed in the property definition.'", ".", "'This will no longer be supported in the future.'", ",", "E_DEPRECATED", ")", ";", "// @codingStandardsIgnoreEnd", "}", "$", "config", "->", "setId", "(", "$", "modelId", "->", "getId", "(", ")", ")", "->", "setFields", "(", "$", "properties", ")", ";", "return", "$", "dataProvider", "->", "fetch", "(", "$", "config", ")", ";", "}" ]
Fetch a certain model from its provider. @param string|ModelIdInterface $modelId This is either the id of the model or a serialized id. @param string|null $providerName The name of the provider, if this is empty, the id will be deserialized and the provider name will get extracted from there. @return ModelInterface @throws \InvalidArgumentException When the model id is invalid.
[ "Fetch", "a", "certain", "model", "from", "its", "provider", "." ]
bf59fc2085cc848c564e40324dee14ef2897faa6
https://github.com/contao-community-alliance/dc-general/blob/bf59fc2085cc848c564e40324dee14ef2897faa6/src/Controller/ModelCollector.php#L140-L188
train
contao-community-alliance/dc-general
src/Controller/ModelCollector.php
ModelCollector.searchParentOfIn
public function searchParentOfIn(ModelInterface $model, CollectionInterface $models) { foreach ($models as $candidate) { /** @var ModelInterface $candidate */ foreach ($this->relationships->getChildConditions($candidate->getProviderName()) as $condition) { if ($condition->matches($candidate, $model)) { return $candidate; } $provider = $this->environment->getDataProvider($condition->getDestinationName()); $config = $provider->getEmptyConfig()->setFilter($condition->getFilter($candidate)); $result = $this->searchParentOfIn($model, $provider->fetchAll($config)); if (null !== $result) { return $result; } } } return null; }
php
public function searchParentOfIn(ModelInterface $model, CollectionInterface $models) { foreach ($models as $candidate) { /** @var ModelInterface $candidate */ foreach ($this->relationships->getChildConditions($candidate->getProviderName()) as $condition) { if ($condition->matches($candidate, $model)) { return $candidate; } $provider = $this->environment->getDataProvider($condition->getDestinationName()); $config = $provider->getEmptyConfig()->setFilter($condition->getFilter($candidate)); $result = $this->searchParentOfIn($model, $provider->fetchAll($config)); if (null !== $result) { return $result; } } } return null; }
[ "public", "function", "searchParentOfIn", "(", "ModelInterface", "$", "model", ",", "CollectionInterface", "$", "models", ")", "{", "foreach", "(", "$", "models", "as", "$", "candidate", ")", "{", "/** @var ModelInterface $candidate */", "foreach", "(", "$", "this", "->", "relationships", "->", "getChildConditions", "(", "$", "candidate", "->", "getProviderName", "(", ")", ")", "as", "$", "condition", ")", "{", "if", "(", "$", "condition", "->", "matches", "(", "$", "candidate", ",", "$", "model", ")", ")", "{", "return", "$", "candidate", ";", "}", "$", "provider", "=", "$", "this", "->", "environment", "->", "getDataProvider", "(", "$", "condition", "->", "getDestinationName", "(", ")", ")", ";", "$", "config", "=", "$", "provider", "->", "getEmptyConfig", "(", ")", "->", "setFilter", "(", "$", "condition", "->", "getFilter", "(", "$", "candidate", ")", ")", ";", "$", "result", "=", "$", "this", "->", "searchParentOfIn", "(", "$", "model", ",", "$", "provider", "->", "fetchAll", "(", "$", "config", ")", ")", ";", "if", "(", "null", "!==", "$", "result", ")", "{", "return", "$", "result", ";", "}", "}", "}", "return", "null", ";", "}" ]
Search the parent of the passed model in the passed collection. This recursively tries to load the parent from sub collections in sub providers. @param ModelInterface $model The model to search the parent for. @param CollectionInterface $models The collection to search in. @return ModelInterface
[ "Search", "the", "parent", "of", "the", "passed", "model", "in", "the", "passed", "collection", "." ]
bf59fc2085cc848c564e40324dee14ef2897faa6
https://github.com/contao-community-alliance/dc-general/blob/bf59fc2085cc848c564e40324dee14ef2897faa6/src/Controller/ModelCollector.php#L200-L219
train
contao-community-alliance/dc-general
src/Controller/ModelCollector.php
ModelCollector.searchParentOf
public function searchParentOf(ModelInterface $model) { switch ($this->definitionMode) { case BasicDefinitionInterface::MODE_HIERARCHICAL: return $this->searchParentOfInHierarchical($model); case BasicDefinitionInterface::MODE_PARENTEDLIST: return $this->searchParentOfInParentedMode($model); default: } throw new DcGeneralInvalidArgumentException('Invalid condition, not in hierarchical mode!'); }
php
public function searchParentOf(ModelInterface $model) { switch ($this->definitionMode) { case BasicDefinitionInterface::MODE_HIERARCHICAL: return $this->searchParentOfInHierarchical($model); case BasicDefinitionInterface::MODE_PARENTEDLIST: return $this->searchParentOfInParentedMode($model); default: } throw new DcGeneralInvalidArgumentException('Invalid condition, not in hierarchical mode!'); }
[ "public", "function", "searchParentOf", "(", "ModelInterface", "$", "model", ")", "{", "switch", "(", "$", "this", "->", "definitionMode", ")", "{", "case", "BasicDefinitionInterface", "::", "MODE_HIERARCHICAL", ":", "return", "$", "this", "->", "searchParentOfInHierarchical", "(", "$", "model", ")", ";", "case", "BasicDefinitionInterface", "::", "MODE_PARENTEDLIST", ":", "return", "$", "this", "->", "searchParentOfInParentedMode", "(", "$", "model", ")", ";", "default", ":", "}", "throw", "new", "DcGeneralInvalidArgumentException", "(", "'Invalid condition, not in hierarchical mode!'", ")", ";", "}" ]
Search the parent model for the given model. @param ModelInterface $model The model for which the parent shall be retrieved. @return ModelInterface|null @throws DcGeneralInvalidArgumentException When a root model has been passed or not in hierarchical mode.
[ "Search", "the", "parent", "model", "for", "the", "given", "model", "." ]
bf59fc2085cc848c564e40324dee14ef2897faa6
https://github.com/contao-community-alliance/dc-general/blob/bf59fc2085cc848c564e40324dee14ef2897faa6/src/Controller/ModelCollector.php#L230-L241
train
contao-community-alliance/dc-general
src/Controller/ModelCollector.php
ModelCollector.internalCollectChildrenOf
private function internalCollectChildrenOf(ModelInterface $model, $providerName = '', $recursive = false) { if ('' === $providerName) { $providerName = $model->getProviderName(); } $ids = ($model->getProviderName() === $providerName) ? [$model->getId()] : []; // Check all data providers for children of the given element. $childIds = []; foreach ($this->relationships->getChildConditions($model->getProviderName()) as $condition) { $provider = $this->environment->getDataProvider($condition->getDestinationName()); $config = $provider->getEmptyConfig(); $config->setFilter($condition->getFilter($model)); foreach ($provider->fetchAll($config) as $child) { /** @var ModelInterface $child */ if (!$recursive && $child->getProviderName() === $providerName) { $ids[] = $child->getId(); } if (false === $recursive) { continue; } // Head into recursion. $childIds[] = $this->collectChildrenOf($child, $providerName); } } return \array_merge($ids, ...$childIds); }
php
private function internalCollectChildrenOf(ModelInterface $model, $providerName = '', $recursive = false) { if ('' === $providerName) { $providerName = $model->getProviderName(); } $ids = ($model->getProviderName() === $providerName) ? [$model->getId()] : []; // Check all data providers for children of the given element. $childIds = []; foreach ($this->relationships->getChildConditions($model->getProviderName()) as $condition) { $provider = $this->environment->getDataProvider($condition->getDestinationName()); $config = $provider->getEmptyConfig(); $config->setFilter($condition->getFilter($model)); foreach ($provider->fetchAll($config) as $child) { /** @var ModelInterface $child */ if (!$recursive && $child->getProviderName() === $providerName) { $ids[] = $child->getId(); } if (false === $recursive) { continue; } // Head into recursion. $childIds[] = $this->collectChildrenOf($child, $providerName); } } return \array_merge($ids, ...$childIds); }
[ "private", "function", "internalCollectChildrenOf", "(", "ModelInterface", "$", "model", ",", "$", "providerName", "=", "''", ",", "$", "recursive", "=", "false", ")", "{", "if", "(", "''", "===", "$", "providerName", ")", "{", "$", "providerName", "=", "$", "model", "->", "getProviderName", "(", ")", ";", "}", "$", "ids", "=", "(", "$", "model", "->", "getProviderName", "(", ")", "===", "$", "providerName", ")", "?", "[", "$", "model", "->", "getId", "(", ")", "]", ":", "[", "]", ";", "// Check all data providers for children of the given element.", "$", "childIds", "=", "[", "]", ";", "foreach", "(", "$", "this", "->", "relationships", "->", "getChildConditions", "(", "$", "model", "->", "getProviderName", "(", ")", ")", "as", "$", "condition", ")", "{", "$", "provider", "=", "$", "this", "->", "environment", "->", "getDataProvider", "(", "$", "condition", "->", "getDestinationName", "(", ")", ")", ";", "$", "config", "=", "$", "provider", "->", "getEmptyConfig", "(", ")", ";", "$", "config", "->", "setFilter", "(", "$", "condition", "->", "getFilter", "(", "$", "model", ")", ")", ";", "foreach", "(", "$", "provider", "->", "fetchAll", "(", "$", "config", ")", "as", "$", "child", ")", "{", "/** @var ModelInterface $child */", "if", "(", "!", "$", "recursive", "&&", "$", "child", "->", "getProviderName", "(", ")", "===", "$", "providerName", ")", "{", "$", "ids", "[", "]", "=", "$", "child", "->", "getId", "(", ")", ";", "}", "if", "(", "false", "===", "$", "recursive", ")", "{", "continue", ";", "}", "// Head into recursion.", "$", "childIds", "[", "]", "=", "$", "this", "->", "collectChildrenOf", "(", "$", "child", ",", "$", "providerName", ")", ";", "}", "}", "return", "\\", "array_merge", "(", "$", "ids", ",", "...", "$", "childIds", ")", ";", "}" ]
Scan for children of a given model. This method is ready for mixed hierarchy and will return all children and grandchildren for the given table (or originating table of the model, if no provider name has been given) for all levels and parent child conditions. @param ModelInterface $model The model to assemble children from. @param string $providerName The name of the data provider to fetch children from. @param bool $recursive Determine for recursive sampling. For models with included child models. @return array
[ "Scan", "for", "children", "of", "a", "given", "model", "." ]
bf59fc2085cc848c564e40324dee14ef2897faa6
https://github.com/contao-community-alliance/dc-general/blob/bf59fc2085cc848c564e40324dee14ef2897faa6/src/Controller/ModelCollector.php#L338-L369
train
contao-community-alliance/dc-general
src/Controller/ModelCollector.php
ModelCollector.searchParentOfInParentedMode
private function searchParentOfInParentedMode(ModelInterface $model) { if ($this->defaultProviderName !== $model->getProviderName()) { throw new DcGeneralInvalidArgumentException( 'Model originates from ' . $model->getProviderName() . ' but is expected to be from ' . $this->defaultProviderName . ' can not determine parent.' ); } $condition = $this->relationships->getChildCondition($this->parentProviderName, $this->defaultProviderName); // This is pretty expensive, we fetch all models from the parent provider here. // This can be much faster by using the inverse condition if present. foreach ($this->parentProvider->fetchAll($this->parentProvider->getEmptyConfig()) as $candidate) { if ($condition->matches($candidate, $model)) { return $candidate; } } return null; }
php
private function searchParentOfInParentedMode(ModelInterface $model) { if ($this->defaultProviderName !== $model->getProviderName()) { throw new DcGeneralInvalidArgumentException( 'Model originates from ' . $model->getProviderName() . ' but is expected to be from ' . $this->defaultProviderName . ' can not determine parent.' ); } $condition = $this->relationships->getChildCondition($this->parentProviderName, $this->defaultProviderName); // This is pretty expensive, we fetch all models from the parent provider here. // This can be much faster by using the inverse condition if present. foreach ($this->parentProvider->fetchAll($this->parentProvider->getEmptyConfig()) as $candidate) { if ($condition->matches($candidate, $model)) { return $candidate; } } return null; }
[ "private", "function", "searchParentOfInParentedMode", "(", "ModelInterface", "$", "model", ")", "{", "if", "(", "$", "this", "->", "defaultProviderName", "!==", "$", "model", "->", "getProviderName", "(", ")", ")", "{", "throw", "new", "DcGeneralInvalidArgumentException", "(", "'Model originates from '", ".", "$", "model", "->", "getProviderName", "(", ")", ".", "' but is expected to be from '", ".", "$", "this", "->", "defaultProviderName", ".", "' can not determine parent.'", ")", ";", "}", "$", "condition", "=", "$", "this", "->", "relationships", "->", "getChildCondition", "(", "$", "this", "->", "parentProviderName", ",", "$", "this", "->", "defaultProviderName", ")", ";", "// This is pretty expensive, we fetch all models from the parent provider here.", "// This can be much faster by using the inverse condition if present.", "foreach", "(", "$", "this", "->", "parentProvider", "->", "fetchAll", "(", "$", "this", "->", "parentProvider", "->", "getEmptyConfig", "(", ")", ")", "as", "$", "candidate", ")", "{", "if", "(", "$", "condition", "->", "matches", "(", "$", "candidate", ",", "$", "model", ")", ")", "{", "return", "$", "candidate", ";", "}", "}", "return", "null", ";", "}" ]
Search the parent of a model in parented mode. @param ModelInterface $model The model to search the parent of. @return ModelInterface|null @throws DcGeneralInvalidArgumentException When the model does not originate from the child provider.
[ "Search", "the", "parent", "of", "a", "model", "in", "parented", "mode", "." ]
bf59fc2085cc848c564e40324dee14ef2897faa6
https://github.com/contao-community-alliance/dc-general/blob/bf59fc2085cc848c564e40324dee14ef2897faa6/src/Controller/ModelCollector.php#L380-L400
train
contao-community-alliance/dc-general
src/Controller/ModelCollector.php
ModelCollector.searchParentOfInHierarchical
private function searchParentOfInHierarchical(ModelInterface $model) { if ($this->isRootModel($model)) { throw new DcGeneralInvalidArgumentException('Invalid condition, root models can not have parents!'); } // Start from the root data provider and walk through the whole tree. // To speed up, some conditions have an inverse filter - we should use them! $config = $this->rootProvider->getEmptyConfig()->setFilter($this->rootCondition->getFilterArray()); return $this->searchParentOfIn($model, $this->rootProvider->fetchAll($config)); }
php
private function searchParentOfInHierarchical(ModelInterface $model) { if ($this->isRootModel($model)) { throw new DcGeneralInvalidArgumentException('Invalid condition, root models can not have parents!'); } // Start from the root data provider and walk through the whole tree. // To speed up, some conditions have an inverse filter - we should use them! $config = $this->rootProvider->getEmptyConfig()->setFilter($this->rootCondition->getFilterArray()); return $this->searchParentOfIn($model, $this->rootProvider->fetchAll($config)); }
[ "private", "function", "searchParentOfInHierarchical", "(", "ModelInterface", "$", "model", ")", "{", "if", "(", "$", "this", "->", "isRootModel", "(", "$", "model", ")", ")", "{", "throw", "new", "DcGeneralInvalidArgumentException", "(", "'Invalid condition, root models can not have parents!'", ")", ";", "}", "// Start from the root data provider and walk through the whole tree.", "// To speed up, some conditions have an inverse filter - we should use them!", "$", "config", "=", "$", "this", "->", "rootProvider", "->", "getEmptyConfig", "(", ")", "->", "setFilter", "(", "$", "this", "->", "rootCondition", "->", "getFilterArray", "(", ")", ")", ";", "return", "$", "this", "->", "searchParentOfIn", "(", "$", "model", ",", "$", "this", "->", "rootProvider", "->", "fetchAll", "(", "$", "config", ")", ")", ";", "}" ]
Search the parent of a model in hierarchical mode. @param ModelInterface $model The model to search the parent of. @return ModelInterface|null @throws DcGeneralInvalidArgumentException When a root model has been passed.
[ "Search", "the", "parent", "of", "a", "model", "in", "hierarchical", "mode", "." ]
bf59fc2085cc848c564e40324dee14ef2897faa6
https://github.com/contao-community-alliance/dc-general/blob/bf59fc2085cc848c564e40324dee14ef2897faa6/src/Controller/ModelCollector.php#L411-L421
train
contao-community-alliance/dc-general
src/Controller/ModelCollector.php
ModelCollector.addParentFilter
private function addParentFilter(ModelInterface $model, $config) { // Not hierarchical, nothing to do. if (BasicDefinitionInterface::MODE_HIERARCHICAL !== $this->definitionMode) { return; } // Root model? if ($this->isRootModel($model)) { $config->setFilter($this->rootCondition->getFilterArray()); return; } // Determine the hard way now. $parent = $this->searchParentOf($model); if (!$parent instanceof ModelInterface) { throw new DcGeneralRuntimeException( 'Parent could not be found, are the parent child conditions correct?' ); } $condition = $this->relationships->getChildCondition($parent->getProviderName(), $model->getProviderName()); $config->setFilter($condition->getFilter($parent)); }
php
private function addParentFilter(ModelInterface $model, $config) { // Not hierarchical, nothing to do. if (BasicDefinitionInterface::MODE_HIERARCHICAL !== $this->definitionMode) { return; } // Root model? if ($this->isRootModel($model)) { $config->setFilter($this->rootCondition->getFilterArray()); return; } // Determine the hard way now. $parent = $this->searchParentOf($model); if (!$parent instanceof ModelInterface) { throw new DcGeneralRuntimeException( 'Parent could not be found, are the parent child conditions correct?' ); } $condition = $this->relationships->getChildCondition($parent->getProviderName(), $model->getProviderName()); $config->setFilter($condition->getFilter($parent)); }
[ "private", "function", "addParentFilter", "(", "ModelInterface", "$", "model", ",", "$", "config", ")", "{", "// Not hierarchical, nothing to do.", "if", "(", "BasicDefinitionInterface", "::", "MODE_HIERARCHICAL", "!==", "$", "this", "->", "definitionMode", ")", "{", "return", ";", "}", "// Root model?", "if", "(", "$", "this", "->", "isRootModel", "(", "$", "model", ")", ")", "{", "$", "config", "->", "setFilter", "(", "$", "this", "->", "rootCondition", "->", "getFilterArray", "(", ")", ")", ";", "return", ";", "}", "// Determine the hard way now.", "$", "parent", "=", "$", "this", "->", "searchParentOf", "(", "$", "model", ")", ";", "if", "(", "!", "$", "parent", "instanceof", "ModelInterface", ")", "{", "throw", "new", "DcGeneralRuntimeException", "(", "'Parent could not be found, are the parent child conditions correct?'", ")", ";", "}", "$", "condition", "=", "$", "this", "->", "relationships", "->", "getChildCondition", "(", "$", "parent", "->", "getProviderName", "(", ")", ",", "$", "model", "->", "getProviderName", "(", ")", ")", ";", "$", "config", "->", "setFilter", "(", "$", "condition", "->", "getFilter", "(", "$", "parent", ")", ")", ";", "}" ]
Add the parent filter matching the parent of a model. @param ModelInterface $model The model to search the parent for. @param ConfigInterface $config The configuration to add the parent filter to. @return void @throws DcGeneralRuntimeException When parent could not be found.
[ "Add", "the", "parent", "filter", "matching", "the", "parent", "of", "a", "model", "." ]
bf59fc2085cc848c564e40324dee14ef2897faa6
https://github.com/contao-community-alliance/dc-general/blob/bf59fc2085cc848c564e40324dee14ef2897faa6/src/Controller/ModelCollector.php#L433-L457
train
contao-community-alliance/dc-general
src/Controller/ModelCollector.php
ModelCollector.isRootModel
private function isRootModel(ModelInterface $model) { return (null !== $this->rootCondition) && $this->rootCondition->matches($model); }
php
private function isRootModel(ModelInterface $model) { return (null !== $this->rootCondition) && $this->rootCondition->matches($model); }
[ "private", "function", "isRootModel", "(", "ModelInterface", "$", "model", ")", "{", "return", "(", "null", "!==", "$", "this", "->", "rootCondition", ")", "&&", "$", "this", "->", "rootCondition", "->", "matches", "(", "$", "model", ")", ";", "}" ]
Check if the passed model is a root model. @param ModelInterface $model The model to check. @return bool
[ "Check", "if", "the", "passed", "model", "is", "a", "root", "model", "." ]
bf59fc2085cc848c564e40324dee14ef2897faa6
https://github.com/contao-community-alliance/dc-general/blob/bf59fc2085cc848c564e40324dee14ef2897faa6/src/Controller/ModelCollector.php#L467-L470
train
contao-community-alliance/dc-general
src/Controller/SortingManager.php
SortingManager.getModelIds
protected function getModelIds() { $ids = []; foreach ($this->models as $model) { /** @var ModelInterface $model */ $ids[] = $model->getId(); } return $ids; }
php
protected function getModelIds() { $ids = []; foreach ($this->models as $model) { /** @var ModelInterface $model */ $ids[] = $model->getId(); } return $ids; }
[ "protected", "function", "getModelIds", "(", ")", "{", "$", "ids", "=", "[", "]", ";", "foreach", "(", "$", "this", "->", "models", "as", "$", "model", ")", "{", "/** @var ModelInterface $model */", "$", "ids", "[", "]", "=", "$", "model", "->", "getId", "(", ")", ";", "}", "return", "$", "ids", ";", "}" ]
Retrieve the ids of the models. @return array
[ "Retrieve", "the", "ids", "of", "the", "models", "." ]
bf59fc2085cc848c564e40324dee14ef2897faa6
https://github.com/contao-community-alliance/dc-general/blob/bf59fc2085cc848c564e40324dee14ef2897faa6/src/Controller/SortingManager.php#L228-L238
train
contao-community-alliance/dc-general
src/Controller/SortingManager.php
SortingManager.scanToDesiredPosition
protected function scanToDesiredPosition() { // Enforce proper sorting now. $this->marker = null; $this->position = 0; $ids = $this->getModelIds(); // If no previous model, insert at beginning. if (null === $this->previousModel) { if ($this->siblingsCopy->length()) { $this->marker = $this->siblingsCopy->shift(); } return; } if ($this->siblingsCopy->length()) { // Search for "previous" sibling. do { $this->marker = $this->siblingsCopy->shift(); if (\in_array($this->marker->getId(), $ids)) { continue; } if ($this->marker) { $this->position = $this->marker->getProperty($this->getSortingProperty()); } } while ($this->marker && $this->marker->getId() !== $this->getPreviousModel()->getId()); // Remember the "next" sibling. if ($this->marker) { $this->marker = $this->siblingsCopy->shift(); } } }
php
protected function scanToDesiredPosition() { // Enforce proper sorting now. $this->marker = null; $this->position = 0; $ids = $this->getModelIds(); // If no previous model, insert at beginning. if (null === $this->previousModel) { if ($this->siblingsCopy->length()) { $this->marker = $this->siblingsCopy->shift(); } return; } if ($this->siblingsCopy->length()) { // Search for "previous" sibling. do { $this->marker = $this->siblingsCopy->shift(); if (\in_array($this->marker->getId(), $ids)) { continue; } if ($this->marker) { $this->position = $this->marker->getProperty($this->getSortingProperty()); } } while ($this->marker && $this->marker->getId() !== $this->getPreviousModel()->getId()); // Remember the "next" sibling. if ($this->marker) { $this->marker = $this->siblingsCopy->shift(); } } }
[ "protected", "function", "scanToDesiredPosition", "(", ")", "{", "// Enforce proper sorting now.", "$", "this", "->", "marker", "=", "null", ";", "$", "this", "->", "position", "=", "0", ";", "$", "ids", "=", "$", "this", "->", "getModelIds", "(", ")", ";", "// If no previous model, insert at beginning.", "if", "(", "null", "===", "$", "this", "->", "previousModel", ")", "{", "if", "(", "$", "this", "->", "siblingsCopy", "->", "length", "(", ")", ")", "{", "$", "this", "->", "marker", "=", "$", "this", "->", "siblingsCopy", "->", "shift", "(", ")", ";", "}", "return", ";", "}", "if", "(", "$", "this", "->", "siblingsCopy", "->", "length", "(", ")", ")", "{", "// Search for \"previous\" sibling.", "do", "{", "$", "this", "->", "marker", "=", "$", "this", "->", "siblingsCopy", "->", "shift", "(", ")", ";", "if", "(", "\\", "in_array", "(", "$", "this", "->", "marker", "->", "getId", "(", ")", ",", "$", "ids", ")", ")", "{", "continue", ";", "}", "if", "(", "$", "this", "->", "marker", ")", "{", "$", "this", "->", "position", "=", "$", "this", "->", "marker", "->", "getProperty", "(", "$", "this", "->", "getSortingProperty", "(", ")", ")", ";", "}", "}", "while", "(", "$", "this", "->", "marker", "&&", "$", "this", "->", "marker", "->", "getId", "(", ")", "!==", "$", "this", "->", "getPreviousModel", "(", ")", "->", "getId", "(", ")", ")", ";", "// Remember the \"next\" sibling.", "if", "(", "$", "this", "->", "marker", ")", "{", "$", "this", "->", "marker", "=", "$", "this", "->", "siblingsCopy", "->", "shift", "(", ")", ";", "}", "}", "}" ]
Scan through the sibling list to the position we want to insert at. @return void
[ "Scan", "through", "the", "sibling", "list", "to", "the", "position", "we", "want", "to", "insert", "at", "." ]
bf59fc2085cc848c564e40324dee14ef2897faa6
https://github.com/contao-community-alliance/dc-general/blob/bf59fc2085cc848c564e40324dee14ef2897faa6/src/Controller/SortingManager.php#L245-L279
train
contao-community-alliance/dc-general
src/Controller/SortingManager.php
SortingManager.determineDelta
private function determineDelta() { $delta = ( ($this->marker->getProperty($this->getSortingProperty()) - $this->position) / $this->results->length() ); // If delta too narrow, we need to make room. // Prevent delta to exceed, also. Use minimum delta which is calculated as multiple of 128. if (($delta < 2) || ($delta > 128)) { return (\ceil($this->results->length() / 128) * 128); } return $delta; }
php
private function determineDelta() { $delta = ( ($this->marker->getProperty($this->getSortingProperty()) - $this->position) / $this->results->length() ); // If delta too narrow, we need to make room. // Prevent delta to exceed, also. Use minimum delta which is calculated as multiple of 128. if (($delta < 2) || ($delta > 128)) { return (\ceil($this->results->length() / 128) * 128); } return $delta; }
[ "private", "function", "determineDelta", "(", ")", "{", "$", "delta", "=", "(", "(", "$", "this", "->", "marker", "->", "getProperty", "(", "$", "this", "->", "getSortingProperty", "(", ")", ")", "-", "$", "this", "->", "position", ")", "/", "$", "this", "->", "results", "->", "length", "(", ")", ")", ";", "// If delta too narrow, we need to make room.", "// Prevent delta to exceed, also. Use minimum delta which is calculated as multiple of 128.", "if", "(", "(", "$", "delta", "<", "2", ")", "||", "(", "$", "delta", ">", "128", ")", ")", "{", "return", "(", "\\", "ceil", "(", "$", "this", "->", "results", "->", "length", "(", ")", "/", "128", ")", "*", "128", ")", ";", "}", "return", "$", "delta", ";", "}" ]
Determine delta value. Delta value will be between 2 and a multiple 128 which is large enough to contain all models being moved. @return float|int
[ "Determine", "delta", "value", "." ]
bf59fc2085cc848c564e40324dee14ef2897faa6
https://github.com/contao-community-alliance/dc-general/blob/bf59fc2085cc848c564e40324dee14ef2897faa6/src/Controller/SortingManager.php#L288-L301
train
contao-community-alliance/dc-general
src/Controller/SortingManager.php
SortingManager.updateSorting
private function updateSorting() { $ids = $this->getModelIds(); // If no "next" sibling, simply increment the sorting as we are at the end of the list. if (!$this->marker) { foreach ($this->results as $model) { $this->position += 128; /** @var ModelInterface $model */ $model->setProperty($this->getSortingProperty(), $this->position); } return; } $delta = $this->determineDelta(); // Loop over all models and increment sorting value. foreach ($this->results as $model) { $this->position += $delta; /** @var ModelInterface $model */ $model->setProperty($this->getSortingProperty(), $this->position); } // When the sorting exceeds the sorting of the "next" sibling, we need to push the remaining siblings to the // end of the list. if ($this->marker->getProperty($this->getSortingProperty()) <= $this->position) { do { // Skip models about to be pasted. if (\in_array($this->marker->getId(), $ids)) { $this->marker = $this->siblingsCopy->shift(); continue; } $this->position += $delta; $this->marker->setProperty($this->getSortingProperty(), $this->position); $this->results->push($this->marker); $this->marker = $this->siblingsCopy->shift(); } while ($this->marker); } }
php
private function updateSorting() { $ids = $this->getModelIds(); // If no "next" sibling, simply increment the sorting as we are at the end of the list. if (!$this->marker) { foreach ($this->results as $model) { $this->position += 128; /** @var ModelInterface $model */ $model->setProperty($this->getSortingProperty(), $this->position); } return; } $delta = $this->determineDelta(); // Loop over all models and increment sorting value. foreach ($this->results as $model) { $this->position += $delta; /** @var ModelInterface $model */ $model->setProperty($this->getSortingProperty(), $this->position); } // When the sorting exceeds the sorting of the "next" sibling, we need to push the remaining siblings to the // end of the list. if ($this->marker->getProperty($this->getSortingProperty()) <= $this->position) { do { // Skip models about to be pasted. if (\in_array($this->marker->getId(), $ids)) { $this->marker = $this->siblingsCopy->shift(); continue; } $this->position += $delta; $this->marker->setProperty($this->getSortingProperty(), $this->position); $this->results->push($this->marker); $this->marker = $this->siblingsCopy->shift(); } while ($this->marker); } }
[ "private", "function", "updateSorting", "(", ")", "{", "$", "ids", "=", "$", "this", "->", "getModelIds", "(", ")", ";", "// If no \"next\" sibling, simply increment the sorting as we are at the end of the list.", "if", "(", "!", "$", "this", "->", "marker", ")", "{", "foreach", "(", "$", "this", "->", "results", "as", "$", "model", ")", "{", "$", "this", "->", "position", "+=", "128", ";", "/** @var ModelInterface $model */", "$", "model", "->", "setProperty", "(", "$", "this", "->", "getSortingProperty", "(", ")", ",", "$", "this", "->", "position", ")", ";", "}", "return", ";", "}", "$", "delta", "=", "$", "this", "->", "determineDelta", "(", ")", ";", "// Loop over all models and increment sorting value.", "foreach", "(", "$", "this", "->", "results", "as", "$", "model", ")", "{", "$", "this", "->", "position", "+=", "$", "delta", ";", "/** @var ModelInterface $model */", "$", "model", "->", "setProperty", "(", "$", "this", "->", "getSortingProperty", "(", ")", ",", "$", "this", "->", "position", ")", ";", "}", "// When the sorting exceeds the sorting of the \"next\" sibling, we need to push the remaining siblings to the", "// end of the list.", "if", "(", "$", "this", "->", "marker", "->", "getProperty", "(", "$", "this", "->", "getSortingProperty", "(", ")", ")", "<=", "$", "this", "->", "position", ")", "{", "do", "{", "// Skip models about to be pasted.", "if", "(", "\\", "in_array", "(", "$", "this", "->", "marker", "->", "getId", "(", ")", ",", "$", "ids", ")", ")", "{", "$", "this", "->", "marker", "=", "$", "this", "->", "siblingsCopy", "->", "shift", "(", ")", ";", "continue", ";", "}", "$", "this", "->", "position", "+=", "$", "delta", ";", "$", "this", "->", "marker", "->", "setProperty", "(", "$", "this", "->", "getSortingProperty", "(", ")", ",", "$", "this", "->", "position", ")", ";", "$", "this", "->", "results", "->", "push", "(", "$", "this", "->", "marker", ")", ";", "$", "this", "->", "marker", "=", "$", "this", "->", "siblingsCopy", "->", "shift", "(", ")", ";", "}", "while", "(", "$", "this", "->", "marker", ")", ";", "}", "}" ]
Update the sorting property values of all models. @return void
[ "Update", "the", "sorting", "property", "values", "of", "all", "models", "." ]
bf59fc2085cc848c564e40324dee14ef2897faa6
https://github.com/contao-community-alliance/dc-general/blob/bf59fc2085cc848c564e40324dee14ef2897faa6/src/Controller/SortingManager.php#L308-L348
train
contao-community-alliance/dc-general
src/Controller/SortingManager.php
SortingManager.calculate
protected function calculate() { if (isset($this->results) || (0 === $this->models->length())) { return; } if (!$this->getSortingProperty()) { throw new \RuntimeException('No sorting property defined for ' . $this->models->get(0)->getProviderName()); } $this->results = clone $this->models; $this->siblingsCopy = clone $this->siblings; $this->scanToDesiredPosition(); $this->updateSorting(); }
php
protected function calculate() { if (isset($this->results) || (0 === $this->models->length())) { return; } if (!$this->getSortingProperty()) { throw new \RuntimeException('No sorting property defined for ' . $this->models->get(0)->getProviderName()); } $this->results = clone $this->models; $this->siblingsCopy = clone $this->siblings; $this->scanToDesiredPosition(); $this->updateSorting(); }
[ "protected", "function", "calculate", "(", ")", "{", "if", "(", "isset", "(", "$", "this", "->", "results", ")", "||", "(", "0", "===", "$", "this", "->", "models", "->", "length", "(", ")", ")", ")", "{", "return", ";", "}", "if", "(", "!", "$", "this", "->", "getSortingProperty", "(", ")", ")", "{", "throw", "new", "\\", "RuntimeException", "(", "'No sorting property defined for '", ".", "$", "this", "->", "models", "->", "get", "(", "0", ")", "->", "getProviderName", "(", ")", ")", ";", "}", "$", "this", "->", "results", "=", "clone", "$", "this", "->", "models", ";", "$", "this", "->", "siblingsCopy", "=", "clone", "$", "this", "->", "siblings", ";", "$", "this", "->", "scanToDesiredPosition", "(", ")", ";", "$", "this", "->", "updateSorting", "(", ")", ";", "}" ]
Calculate the resulting list. @return void @throws \RuntimeException When no sorting property has been defined.
[ "Calculate", "the", "resulting", "list", "." ]
bf59fc2085cc848c564e40324dee14ef2897faa6
https://github.com/contao-community-alliance/dc-general/blob/bf59fc2085cc848c564e40324dee14ef2897faa6/src/Controller/SortingManager.php#L357-L372
train
contao-community-alliance/dc-general
src/Contao/View/Contao2BackendView/ActionHandler/EditHandler.php
EditHandler.checkPermission
private function checkPermission(ActionEvent $event) { $environment = $event->getEnvironment(); if (true === $environment->getDataDefinition()->getBasicDefinition()->isEditable()) { return true; } $inputProvider = $environment->getInputProvider(); $event->setResponse( \sprintf( '<div style="text-align:center; font-weight:bold; padding:40px;"> You have no permission for edit model %s. </div>', ModelId::fromSerialized($inputProvider->getParameter('id'))->getSerialized() ) ); return false; }
php
private function checkPermission(ActionEvent $event) { $environment = $event->getEnvironment(); if (true === $environment->getDataDefinition()->getBasicDefinition()->isEditable()) { return true; } $inputProvider = $environment->getInputProvider(); $event->setResponse( \sprintf( '<div style="text-align:center; font-weight:bold; padding:40px;"> You have no permission for edit model %s. </div>', ModelId::fromSerialized($inputProvider->getParameter('id'))->getSerialized() ) ); return false; }
[ "private", "function", "checkPermission", "(", "ActionEvent", "$", "event", ")", "{", "$", "environment", "=", "$", "event", "->", "getEnvironment", "(", ")", ";", "if", "(", "true", "===", "$", "environment", "->", "getDataDefinition", "(", ")", "->", "getBasicDefinition", "(", ")", "->", "isEditable", "(", ")", ")", "{", "return", "true", ";", "}", "$", "inputProvider", "=", "$", "environment", "->", "getInputProvider", "(", ")", ";", "$", "event", "->", "setResponse", "(", "\\", "sprintf", "(", "'<div style=\"text-align:center; font-weight:bold; padding:40px;\">\n You have no permission for edit model %s.\n </div>'", ",", "ModelId", "::", "fromSerialized", "(", "$", "inputProvider", "->", "getParameter", "(", "'id'", ")", ")", "->", "getSerialized", "(", ")", ")", ")", ";", "return", "false", ";", "}" ]
Check permission for edit a model. @param ActionEvent $event The action event. @return bool
[ "Check", "permission", "for", "edit", "a", "model", "." ]
bf59fc2085cc848c564e40324dee14ef2897faa6
https://github.com/contao-community-alliance/dc-general/blob/bf59fc2085cc848c564e40324dee14ef2897faa6/src/Contao/View/Contao2BackendView/ActionHandler/EditHandler.php#L130-L150
train
contao-community-alliance/dc-general
src/Contao/View/Contao2BackendView/ActionHandler/EditHandler.php
EditHandler.checkRestoreVersion
private function checkRestoreVersion(EnvironmentInterface $environment, ModelId $modelId) { $inputProvider = $environment->getInputProvider(); $dataProviderDefinition = $environment->getDataDefinition()->getDataProviderDefinition(); $dataProvider = $environment->getDataProvider($modelId->getDataProviderName()); if (!((null !== ($modelVersion = $inputProvider->getValue('version'))) && ('tl_version' === $inputProvider->getValue('FORM_SUBMIT')) && $dataProviderDefinition->getInformation($modelId->getDataProviderName())->isVersioningEnabled()) ) { return; } if (null === ($model = $dataProvider->getVersion($modelId->getId(), $modelVersion))) { $message = \sprintf( 'Could not load version %s of record ID %s from %s', $modelVersion, $modelId->getId(), $modelId->getDataProviderName() ); $environment->getEventDispatcher()->dispatch( ContaoEvents::SYSTEM_LOG, new LogEvent($message, TL_ERROR, 'DC_General - checkRestoreVersion()') ); throw new DcGeneralRuntimeException($message); } $dataProvider->save($model); $dataProvider->setVersionActive($modelId->getId(), $modelVersion); $environment->getEventDispatcher()->dispatch(ContaoEvents::CONTROLLER_RELOAD, new ReloadEvent()); }
php
private function checkRestoreVersion(EnvironmentInterface $environment, ModelId $modelId) { $inputProvider = $environment->getInputProvider(); $dataProviderDefinition = $environment->getDataDefinition()->getDataProviderDefinition(); $dataProvider = $environment->getDataProvider($modelId->getDataProviderName()); if (!((null !== ($modelVersion = $inputProvider->getValue('version'))) && ('tl_version' === $inputProvider->getValue('FORM_SUBMIT')) && $dataProviderDefinition->getInformation($modelId->getDataProviderName())->isVersioningEnabled()) ) { return; } if (null === ($model = $dataProvider->getVersion($modelId->getId(), $modelVersion))) { $message = \sprintf( 'Could not load version %s of record ID %s from %s', $modelVersion, $modelId->getId(), $modelId->getDataProviderName() ); $environment->getEventDispatcher()->dispatch( ContaoEvents::SYSTEM_LOG, new LogEvent($message, TL_ERROR, 'DC_General - checkRestoreVersion()') ); throw new DcGeneralRuntimeException($message); } $dataProvider->save($model); $dataProvider->setVersionActive($modelId->getId(), $modelVersion); $environment->getEventDispatcher()->dispatch(ContaoEvents::CONTROLLER_RELOAD, new ReloadEvent()); }
[ "private", "function", "checkRestoreVersion", "(", "EnvironmentInterface", "$", "environment", ",", "ModelId", "$", "modelId", ")", "{", "$", "inputProvider", "=", "$", "environment", "->", "getInputProvider", "(", ")", ";", "$", "dataProviderDefinition", "=", "$", "environment", "->", "getDataDefinition", "(", ")", "->", "getDataProviderDefinition", "(", ")", ";", "$", "dataProvider", "=", "$", "environment", "->", "getDataProvider", "(", "$", "modelId", "->", "getDataProviderName", "(", ")", ")", ";", "if", "(", "!", "(", "(", "null", "!==", "(", "$", "modelVersion", "=", "$", "inputProvider", "->", "getValue", "(", "'version'", ")", ")", ")", "&&", "(", "'tl_version'", "===", "$", "inputProvider", "->", "getValue", "(", "'FORM_SUBMIT'", ")", ")", "&&", "$", "dataProviderDefinition", "->", "getInformation", "(", "$", "modelId", "->", "getDataProviderName", "(", ")", ")", "->", "isVersioningEnabled", "(", ")", ")", ")", "{", "return", ";", "}", "if", "(", "null", "===", "(", "$", "model", "=", "$", "dataProvider", "->", "getVersion", "(", "$", "modelId", "->", "getId", "(", ")", ",", "$", "modelVersion", ")", ")", ")", "{", "$", "message", "=", "\\", "sprintf", "(", "'Could not load version %s of record ID %s from %s'", ",", "$", "modelVersion", ",", "$", "modelId", "->", "getId", "(", ")", ",", "$", "modelId", "->", "getDataProviderName", "(", ")", ")", ";", "$", "environment", "->", "getEventDispatcher", "(", ")", "->", "dispatch", "(", "ContaoEvents", "::", "SYSTEM_LOG", ",", "new", "LogEvent", "(", "$", "message", ",", "TL_ERROR", ",", "'DC_General - checkRestoreVersion()'", ")", ")", ";", "throw", "new", "DcGeneralRuntimeException", "(", "$", "message", ")", ";", "}", "$", "dataProvider", "->", "save", "(", "$", "model", ")", ";", "$", "dataProvider", "->", "setVersionActive", "(", "$", "modelId", "->", "getId", "(", ")", ",", "$", "modelVersion", ")", ";", "$", "environment", "->", "getEventDispatcher", "(", ")", "->", "dispatch", "(", "ContaoEvents", "::", "CONTROLLER_RELOAD", ",", "new", "ReloadEvent", "(", ")", ")", ";", "}" ]
Check the submitted data if we want to restore a previous version of a model. If so, the model will get loaded and marked as active version in the data provider and the client will perform a reload of the page. @param EnvironmentInterface $environment The environment. @param ModelId $modelId The model id. @return void @throws DcGeneralRuntimeException When the requested version could not be located in the database. @SuppressWarnings(PHPMD.LongVariable)
[ "Check", "the", "submitted", "data", "if", "we", "want", "to", "restore", "a", "previous", "version", "of", "a", "model", "." ]
bf59fc2085cc848c564e40324dee14ef2897faa6
https://github.com/contao-community-alliance/dc-general/blob/bf59fc2085cc848c564e40324dee14ef2897faa6/src/Contao/View/Contao2BackendView/ActionHandler/EditHandler.php#L167-L200
train
contao-community-alliance/dc-general
src/Contao/View/Contao2BackendView/ActionHandler/SelectHandler.php
SelectHandler.getSubmitAction
private function getSubmitAction(EnvironmentInterface $environment, $regardSelectMode = false) { if (!$regardSelectMode && $environment->getInputProvider()->hasParameter('select') && !$environment->getInputProvider()->hasValue('properties') ) { return 'select' . \ucfirst($environment->getInputProvider()->getParameter('select')); } if (null !== ($action = $this->determineAction($environment))) { return $action; } if ($regardSelectMode) { return $environment->getInputProvider()->getParameter('mode') ?: null; } return $environment->getInputProvider()->getParameter('select') ? 'select' . \ucfirst($environment->getInputProvider()->getParameter('select')) : null; }
php
private function getSubmitAction(EnvironmentInterface $environment, $regardSelectMode = false) { if (!$regardSelectMode && $environment->getInputProvider()->hasParameter('select') && !$environment->getInputProvider()->hasValue('properties') ) { return 'select' . \ucfirst($environment->getInputProvider()->getParameter('select')); } if (null !== ($action = $this->determineAction($environment))) { return $action; } if ($regardSelectMode) { return $environment->getInputProvider()->getParameter('mode') ?: null; } return $environment->getInputProvider()->getParameter('select') ? 'select' . \ucfirst($environment->getInputProvider()->getParameter('select')) : null; }
[ "private", "function", "getSubmitAction", "(", "EnvironmentInterface", "$", "environment", ",", "$", "regardSelectMode", "=", "false", ")", "{", "if", "(", "!", "$", "regardSelectMode", "&&", "$", "environment", "->", "getInputProvider", "(", ")", "->", "hasParameter", "(", "'select'", ")", "&&", "!", "$", "environment", "->", "getInputProvider", "(", ")", "->", "hasValue", "(", "'properties'", ")", ")", "{", "return", "'select'", ".", "\\", "ucfirst", "(", "$", "environment", "->", "getInputProvider", "(", ")", "->", "getParameter", "(", "'select'", ")", ")", ";", "}", "if", "(", "null", "!==", "(", "$", "action", "=", "$", "this", "->", "determineAction", "(", "$", "environment", ")", ")", ")", "{", "return", "$", "action", ";", "}", "if", "(", "$", "regardSelectMode", ")", "{", "return", "$", "environment", "->", "getInputProvider", "(", ")", "->", "getParameter", "(", "'mode'", ")", "?", ":", "null", ";", "}", "return", "$", "environment", "->", "getInputProvider", "(", ")", "->", "getParameter", "(", "'select'", ")", "?", "'select'", ".", "\\", "ucfirst", "(", "$", "environment", "->", "getInputProvider", "(", ")", "->", "getParameter", "(", "'select'", ")", ")", ":", "null", ";", "}" ]
Get the submit action name. @param EnvironmentInterface $environment The environment. @param boolean $regardSelectMode Determine regard the select mode parameter. @return string
[ "Get", "the", "submit", "action", "name", "." ]
bf59fc2085cc848c564e40324dee14ef2897faa6
https://github.com/contao-community-alliance/dc-general/blob/bf59fc2085cc848c564e40324dee14ef2897faa6/src/Contao/View/Contao2BackendView/ActionHandler/SelectHandler.php#L125-L144
train
contao-community-alliance/dc-general
src/Contao/View/Contao2BackendView/ActionHandler/SelectHandler.php
SelectHandler.determineAction
private function determineAction(EnvironmentInterface $environment) { foreach (['delete', 'cut', 'copy', 'override', 'edit'] as $action) { if ($environment->getInputProvider()->hasValue($action) || $environment->getInputProvider()->hasValue($action . '_save') || $environment->getInputProvider()->hasValue($action . '_saveNback') ) { $environment->getInputProvider()->setParameter('mode', $action); return $action; } } return null; }
php
private function determineAction(EnvironmentInterface $environment) { foreach (['delete', 'cut', 'copy', 'override', 'edit'] as $action) { if ($environment->getInputProvider()->hasValue($action) || $environment->getInputProvider()->hasValue($action . '_save') || $environment->getInputProvider()->hasValue($action . '_saveNback') ) { $environment->getInputProvider()->setParameter('mode', $action); return $action; } } return null; }
[ "private", "function", "determineAction", "(", "EnvironmentInterface", "$", "environment", ")", "{", "foreach", "(", "[", "'delete'", ",", "'cut'", ",", "'copy'", ",", "'override'", ",", "'edit'", "]", "as", "$", "action", ")", "{", "if", "(", "$", "environment", "->", "getInputProvider", "(", ")", "->", "hasValue", "(", "$", "action", ")", "||", "$", "environment", "->", "getInputProvider", "(", ")", "->", "hasValue", "(", "$", "action", ".", "'_save'", ")", "||", "$", "environment", "->", "getInputProvider", "(", ")", "->", "hasValue", "(", "$", "action", ".", "'_saveNback'", ")", ")", "{", "$", "environment", "->", "getInputProvider", "(", ")", "->", "setParameter", "(", "'mode'", ",", "$", "action", ")", ";", "return", "$", "action", ";", "}", "}", "return", "null", ";", "}" ]
Determine the action. @param EnvironmentInterface $environment The environment. @return string|null
[ "Determine", "the", "action", "." ]
bf59fc2085cc848c564e40324dee14ef2897faa6
https://github.com/contao-community-alliance/dc-general/blob/bf59fc2085cc848c564e40324dee14ef2897faa6/src/Contao/View/Contao2BackendView/ActionHandler/SelectHandler.php#L153-L167
train
contao-community-alliance/dc-general
src/Contao/View/Contao2BackendView/ActionHandler/SelectHandler.php
SelectHandler.regardSelectMode
private function regardSelectMode(EnvironmentInterface $environment) { $inputProvider = $environment->getInputProvider(); $regardSelectMode = false; \array_map( function ($value) use ($inputProvider, &$regardSelectMode) { if (!$inputProvider->hasValue($value)) { return false; } $regardSelectMode = true; return true; }, ['edit_save', 'edit_saveNback', 'override_save', 'override_saveNback', 'delete', 'copy', 'cut'] ); if (('auto' === $inputProvider->getValue('SUBMIT_TYPE')) && ('edit' === $inputProvider->getParameter('select')) ) { return true; } return $regardSelectMode; }
php
private function regardSelectMode(EnvironmentInterface $environment) { $inputProvider = $environment->getInputProvider(); $regardSelectMode = false; \array_map( function ($value) use ($inputProvider, &$regardSelectMode) { if (!$inputProvider->hasValue($value)) { return false; } $regardSelectMode = true; return true; }, ['edit_save', 'edit_saveNback', 'override_save', 'override_saveNback', 'delete', 'copy', 'cut'] ); if (('auto' === $inputProvider->getValue('SUBMIT_TYPE')) && ('edit' === $inputProvider->getParameter('select')) ) { return true; } return $regardSelectMode; }
[ "private", "function", "regardSelectMode", "(", "EnvironmentInterface", "$", "environment", ")", "{", "$", "inputProvider", "=", "$", "environment", "->", "getInputProvider", "(", ")", ";", "$", "regardSelectMode", "=", "false", ";", "\\", "array_map", "(", "function", "(", "$", "value", ")", "use", "(", "$", "inputProvider", ",", "&", "$", "regardSelectMode", ")", "{", "if", "(", "!", "$", "inputProvider", "->", "hasValue", "(", "$", "value", ")", ")", "{", "return", "false", ";", "}", "$", "regardSelectMode", "=", "true", ";", "return", "true", ";", "}", ",", "[", "'edit_save'", ",", "'edit_saveNback'", ",", "'override_save'", ",", "'override_saveNback'", ",", "'delete'", ",", "'copy'", ",", "'cut'", "]", ")", ";", "if", "(", "(", "'auto'", "===", "$", "inputProvider", "->", "getValue", "(", "'SUBMIT_TYPE'", ")", ")", "&&", "(", "'edit'", "===", "$", "inputProvider", "->", "getParameter", "(", "'select'", ")", ")", ")", "{", "return", "true", ";", "}", "return", "$", "regardSelectMode", ";", "}" ]
Determine regard select mode. @param EnvironmentInterface $environment The environment. @return bool
[ "Determine", "regard", "select", "mode", "." ]
bf59fc2085cc848c564e40324dee14ef2897faa6
https://github.com/contao-community-alliance/dc-general/blob/bf59fc2085cc848c564e40324dee14ef2897faa6/src/Contao/View/Contao2BackendView/ActionHandler/SelectHandler.php#L176-L200
train
contao-community-alliance/dc-general
src/Contao/View/Contao2BackendView/ActionHandler/SelectHandler.php
SelectHandler.getModelIds
private function getModelIds(EnvironmentInterface $environment, Action $action, $submitAction) { $valueKey = \in_array($submitAction, ['edit', 'override']) ? 'properties' : 'models'; $modelIds = (array) $environment->getInputProvider()->getValue($valueKey); if (!empty($modelIds)) { $modelIds = \array_map( function ($modelId) { return ModelId::fromSerialized($modelId); }, $modelIds ); $event = new PrepareMultipleModelsActionEvent($environment, $action, $modelIds, $submitAction); $environment->getEventDispatcher()->dispatch($event::NAME, $event); $modelIds = $event->getModelIds(); } return $modelIds; }
php
private function getModelIds(EnvironmentInterface $environment, Action $action, $submitAction) { $valueKey = \in_array($submitAction, ['edit', 'override']) ? 'properties' : 'models'; $modelIds = (array) $environment->getInputProvider()->getValue($valueKey); if (!empty($modelIds)) { $modelIds = \array_map( function ($modelId) { return ModelId::fromSerialized($modelId); }, $modelIds ); $event = new PrepareMultipleModelsActionEvent($environment, $action, $modelIds, $submitAction); $environment->getEventDispatcher()->dispatch($event::NAME, $event); $modelIds = $event->getModelIds(); } return $modelIds; }
[ "private", "function", "getModelIds", "(", "EnvironmentInterface", "$", "environment", ",", "Action", "$", "action", ",", "$", "submitAction", ")", "{", "$", "valueKey", "=", "\\", "in_array", "(", "$", "submitAction", ",", "[", "'edit'", ",", "'override'", "]", ")", "?", "'properties'", ":", "'models'", ";", "$", "modelIds", "=", "(", "array", ")", "$", "environment", "->", "getInputProvider", "(", ")", "->", "getValue", "(", "$", "valueKey", ")", ";", "if", "(", "!", "empty", "(", "$", "modelIds", ")", ")", "{", "$", "modelIds", "=", "\\", "array_map", "(", "function", "(", "$", "modelId", ")", "{", "return", "ModelId", "::", "fromSerialized", "(", "$", "modelId", ")", ";", "}", ",", "$", "modelIds", ")", ";", "$", "event", "=", "new", "PrepareMultipleModelsActionEvent", "(", "$", "environment", ",", "$", "action", ",", "$", "modelIds", ",", "$", "submitAction", ")", ";", "$", "environment", "->", "getEventDispatcher", "(", ")", "->", "dispatch", "(", "$", "event", "::", "NAME", ",", "$", "event", ")", ";", "$", "modelIds", "=", "$", "event", "->", "getModelIds", "(", ")", ";", "}", "return", "$", "modelIds", ";", "}" ]
Get The model ids from the environment. @param EnvironmentInterface $environment The environment. @param Action $action The dcg action. @param string $submitAction The submit action name. @return ModelId[]
[ "Get", "The", "model", "ids", "from", "the", "environment", "." ]
bf59fc2085cc848c564e40324dee14ef2897faa6
https://github.com/contao-community-alliance/dc-general/blob/bf59fc2085cc848c564e40324dee14ef2897faa6/src/Contao/View/Contao2BackendView/ActionHandler/SelectHandler.php#L211-L231
train
contao-community-alliance/dc-general
src/Contao/View/Contao2BackendView/ActionHandler/SelectHandler.php
SelectHandler.handleSelectModelsAllAction
private function handleSelectModelsAllAction(EnvironmentInterface $environment, Action $action) { $this->clearClipboard($environment); $this->handleGlobalCommands($environment); if ($response = $this->callAction($environment, 'selectModelAll')) { return $response; } return null; }
php
private function handleSelectModelsAllAction(EnvironmentInterface $environment, Action $action) { $this->clearClipboard($environment); $this->handleGlobalCommands($environment); if ($response = $this->callAction($environment, 'selectModelAll')) { return $response; } return null; }
[ "private", "function", "handleSelectModelsAllAction", "(", "EnvironmentInterface", "$", "environment", ",", "Action", "$", "action", ")", "{", "$", "this", "->", "clearClipboard", "(", "$", "environment", ")", ";", "$", "this", "->", "handleGlobalCommands", "(", "$", "environment", ")", ";", "if", "(", "$", "response", "=", "$", "this", "->", "callAction", "(", "$", "environment", ",", "'selectModelAll'", ")", ")", "{", "return", "$", "response", ";", "}", "return", "null", ";", "}" ]
Handel select model all action. @param EnvironmentInterface $environment The environment. @param Action $action The action. @return null|string @SuppressWarnings(PHPMD.UnusedFormalParameter) @SuppressWarnings(PHPMD.UnusedPrivateMethod)
[ "Handel", "select", "model", "all", "action", "." ]
bf59fc2085cc848c564e40324dee14ef2897faa6
https://github.com/contao-community-alliance/dc-general/blob/bf59fc2085cc848c564e40324dee14ef2897faa6/src/Contao/View/Contao2BackendView/ActionHandler/SelectHandler.php#L244-L254
train
contao-community-alliance/dc-general
src/Contao/View/Contao2BackendView/ActionHandler/SelectHandler.php
SelectHandler.handleSelectPropertiesAllAction
private function handleSelectPropertiesAllAction(EnvironmentInterface $environment, Action $action) { $this->clearClipboard($environment); $this->handleGlobalCommands($environment); $this->handleSessionOverrideEditAll( $this->getModelIds($environment, $action, $this->getSubmitAction($environment)), 'models', $environment ); $collection = $this->getSelectCollection($environment); $this->setIntersectProperties($collection, $environment); $this->setIntersectValues($collection, $environment); if ($response = $this->callAction($environment, 'selectPropertyAll')) { return $response; } return null; }
php
private function handleSelectPropertiesAllAction(EnvironmentInterface $environment, Action $action) { $this->clearClipboard($environment); $this->handleGlobalCommands($environment); $this->handleSessionOverrideEditAll( $this->getModelIds($environment, $action, $this->getSubmitAction($environment)), 'models', $environment ); $collection = $this->getSelectCollection($environment); $this->setIntersectProperties($collection, $environment); $this->setIntersectValues($collection, $environment); if ($response = $this->callAction($environment, 'selectPropertyAll')) { return $response; } return null; }
[ "private", "function", "handleSelectPropertiesAllAction", "(", "EnvironmentInterface", "$", "environment", ",", "Action", "$", "action", ")", "{", "$", "this", "->", "clearClipboard", "(", "$", "environment", ")", ";", "$", "this", "->", "handleGlobalCommands", "(", "$", "environment", ")", ";", "$", "this", "->", "handleSessionOverrideEditAll", "(", "$", "this", "->", "getModelIds", "(", "$", "environment", ",", "$", "action", ",", "$", "this", "->", "getSubmitAction", "(", "$", "environment", ")", ")", ",", "'models'", ",", "$", "environment", ")", ";", "$", "collection", "=", "$", "this", "->", "getSelectCollection", "(", "$", "environment", ")", ";", "$", "this", "->", "setIntersectProperties", "(", "$", "collection", ",", "$", "environment", ")", ";", "$", "this", "->", "setIntersectValues", "(", "$", "collection", ",", "$", "environment", ")", ";", "if", "(", "$", "response", "=", "$", "this", "->", "callAction", "(", "$", "environment", ",", "'selectPropertyAll'", ")", ")", "{", "return", "$", "response", ";", "}", "return", "null", ";", "}" ]
Handle the select property all action. @param EnvironmentInterface $environment The environment. @param Action $action The action. @return null|string @SuppressWarnings(PHPMD.UnusedPrivateMethod)
[ "Handle", "the", "select", "property", "all", "action", "." ]
bf59fc2085cc848c564e40324dee14ef2897faa6
https://github.com/contao-community-alliance/dc-general/blob/bf59fc2085cc848c564e40324dee14ef2897faa6/src/Contao/View/Contao2BackendView/ActionHandler/SelectHandler.php#L266-L285
train
contao-community-alliance/dc-general
src/Contao/View/Contao2BackendView/ActionHandler/SelectHandler.php
SelectHandler.handleCutAllAction
private function handleCutAllAction(EnvironmentInterface $environment, Action $action) { $inputProvider = $environment->getInputProvider(); foreach ($this->getModelIds($environment, $action, $this->getSubmitAction($environment)) as $modelId) { $inputProvider->setParameter('source', $modelId->getSerialized()); $this->callAction($environment, 'cut'); $inputProvider->unsetParameter('source'); } ViewHelpers::redirectHome($environment); return null; }
php
private function handleCutAllAction(EnvironmentInterface $environment, Action $action) { $inputProvider = $environment->getInputProvider(); foreach ($this->getModelIds($environment, $action, $this->getSubmitAction($environment)) as $modelId) { $inputProvider->setParameter('source', $modelId->getSerialized()); $this->callAction($environment, 'cut'); $inputProvider->unsetParameter('source'); } ViewHelpers::redirectHome($environment); return null; }
[ "private", "function", "handleCutAllAction", "(", "EnvironmentInterface", "$", "environment", ",", "Action", "$", "action", ")", "{", "$", "inputProvider", "=", "$", "environment", "->", "getInputProvider", "(", ")", ";", "foreach", "(", "$", "this", "->", "getModelIds", "(", "$", "environment", ",", "$", "action", ",", "$", "this", "->", "getSubmitAction", "(", "$", "environment", ")", ")", "as", "$", "modelId", ")", "{", "$", "inputProvider", "->", "setParameter", "(", "'source'", ",", "$", "modelId", "->", "getSerialized", "(", ")", ")", ";", "$", "this", "->", "callAction", "(", "$", "environment", ",", "'cut'", ")", ";", "$", "inputProvider", "->", "unsetParameter", "(", "'source'", ")", ";", "}", "ViewHelpers", "::", "redirectHome", "(", "$", "environment", ")", ";", "return", "null", ";", "}" ]
Handle the cut all action. @param EnvironmentInterface $environment The environment. @param Action $action The action. @return null @SuppressWarnings(PHPMD.UnusedPrivateMethod)
[ "Handle", "the", "cut", "all", "action", "." ]
bf59fc2085cc848c564e40324dee14ef2897faa6
https://github.com/contao-community-alliance/dc-general/blob/bf59fc2085cc848c564e40324dee14ef2897faa6/src/Contao/View/Contao2BackendView/ActionHandler/SelectHandler.php#L326-L340
train