code
stringlengths 17
247k
| docstring
stringlengths 30
30.3k
| func_name
stringlengths 1
89
| language
stringclasses 1
value | repo
stringlengths 7
63
| path
stringlengths 7
153
| url
stringlengths 51
209
| license
stringclasses 4
values |
---|---|---|---|---|---|---|---|
protected function checkRelationClass($class, $component, $relationClass, $type)
{
if (!is_string($component) || is_numeric($component)) {
throw new InvalidArgumentException(
"{$class} has invalid {$type} relation name"
);
}
if (!is_string($relationClass)) {
throw new InvalidArgumentException(
"{$type} relation {$class}.{$component} is not a class name"
);
}
if (!class_exists($relationClass ?? '')) {
throw new InvalidArgumentException(
"{$type} relation {$class}.{$component} references class {$relationClass} which doesn't exist"
);
}
// Support polymorphic has_one
if ($type === 'has_one') {
$valid = is_a($relationClass, DataObject::class, true);
} else {
$valid = is_subclass_of($relationClass, DataObject::class, true);
}
if (!$valid) {
throw new InvalidArgumentException(
"{$type} relation {$class}.{$component} references class {$relationClass} "
. " which is not a subclass of " . DataObject::class
);
}
} | Validate a given class is valid for a relation
@param string $class Parent class
@param string $component Component name
@param string $relationClass Candidate class to check
@param string $type Relation type (e.g. has_one) | checkRelationClass | php | silverstripe/silverstripe-framework | src/ORM/DataObjectSchema.php | https://github.com/silverstripe/silverstripe-framework/blob/master/src/ORM/DataObjectSchema.php | BSD-3-Clause |
protected function linkJoinTable()
{
// Join to the many-many join table
$dataClassIDColumn = DataObject::getSchema()->sqlColumnForField($this->dataClass(), 'ID');
$this->dataQuery->innerJoin(
$this->joinTable,
"\"{$this->joinTable}\".\"{$this->localKey}\" = {$dataClassIDColumn}"
);
// Add the extra fields to the query
if ($this->extraFields) {
$this->appendExtraFieldsToQuery();
}
} | Setup the join between this dataobject and the necessary mapping table | linkJoinTable | php | silverstripe/silverstripe-framework | src/ORM/ManyManyList.php | https://github.com/silverstripe/silverstripe-framework/blob/master/src/ORM/ManyManyList.php | BSD-3-Clause |
protected function foreignIDFilter($id = null)
{
if ($id === null) {
$id = $this->getForeignID();
}
// Apply relation filter
$key = "\"{$this->joinTable}\".\"{$this->foreignKey}\"";
if (is_array($id)) {
$in = $this->prepareForeignIDsForWhereInClause($id);
$vals = str_contains($in, '?') ? $id : [];
return ["$key IN ($in)" => $vals];
}
if ($id !== null) {
return [$key => $id];
}
return null;
} | Return a filter expression for when getting the contents of the
relationship for some foreign ID
@param int|null|string|array $id | foreignIDFilter | php | silverstripe/silverstripe-framework | src/ORM/ManyManyList.php | https://github.com/silverstripe/silverstripe-framework/blob/master/src/ORM/ManyManyList.php | BSD-3-Clause |
protected function foreignIDWriteFilter($id = null)
{
return $this->foreignIDFilter($id);
} | Return a filter expression for the join table when writing to the join table
When writing (add, remove, removeByID), we need to filter the join table to just the relevant
entries. However some subclasses of ManyManyList (Member_GroupSet) modify foreignIDFilter to
include additional calculated entries, so we need different filters when reading and when writing
@param array|int|null $id (optional) An ID or an array of IDs - if not provided, will use the current ids
as per getForeignID
@return array Condition In array(SQL => parameters format) | foreignIDWriteFilter | php | silverstripe/silverstripe-framework | src/ORM/ManyManyList.php | https://github.com/silverstripe/silverstripe-framework/blob/master/src/ORM/ManyManyList.php | BSD-3-Clause |
public function remove($item)
{
if (!($item instanceof $this->dataClass)) {
throw new InvalidArgumentException("ManyManyList::remove() expecting a $this->dataClass object");
}
$result = $this->removeByID($item->ID);
return $result;
} | Remove the given item from this list.
Note that for a ManyManyList, the item is never actually deleted, only
the join table is affected.
@param DataObject $item | remove | php | silverstripe/silverstripe-framework | src/ORM/ManyManyList.php | https://github.com/silverstripe/silverstripe-framework/blob/master/src/ORM/ManyManyList.php | BSD-3-Clause |
public function removeByID($itemID)
{
if (!is_numeric($itemID)) {
throw new InvalidArgumentException("ManyManyList::removeById() expecting an ID");
}
$query = SQLDelete::create("\"{$this->joinTable}\"");
if ($filter = $this->foreignIDWriteFilter($this->getForeignID())) {
$query->setWhere($filter);
} else {
user_error("Can't call ManyManyList::remove() until a foreign ID is set");
}
$query->addWhere([
"\"{$this->joinTable}\".\"{$this->localKey}\"" => $itemID
]);
// Perform the deletion
$query->execute();
if ($this->removeCallbacks) {
$this->removeCallbacks->call($this, [$itemID]);
}
} | Remove the given item from this list.
Note that for a ManyManyList, the item is never actually deleted, only
the join table is affected
@param int $itemID The item ID | removeByID | php | silverstripe/silverstripe-framework | src/ORM/ManyManyList.php | https://github.com/silverstripe/silverstripe-framework/blob/master/src/ORM/ManyManyList.php | BSD-3-Clause |
public function removeAll()
{
// Remove the join to the join table to avoid MySQL row locking issues.
$query = $this->dataQuery();
$foreignFilter = $query->getQueryParam('Foreign.Filter');
$query->removeFilterOn($foreignFilter);
// Select ID column
$selectQuery = $query->query();
$dataClassIDColumn = DataObject::getSchema()->sqlColumnForField($this->dataClass(), 'ID');
$selectQuery->setSelect($dataClassIDColumn);
$from = $selectQuery->getFrom();
unset($from[$this->joinTable]);
$selectQuery->setFrom($from);
$selectQuery->setOrderBy(); // ORDER BY in subselects breaks MS SQL Server and is not necessary here
$selectQuery->setLimit(null); // LIMIT in subselects breaks MariaDB (https://mariadb.com/kb/en/subquery-limitations/#limit) and is not necessary here
$selectQuery->setDistinct(false);
// Use a sub-query as SQLite does not support setting delete targets in
// joined queries.
$delete = SQLDelete::create();
$delete->setFrom("\"{$this->joinTable}\"");
$delete->addWhere($this->foreignIDFilter());
$subSelect = $selectQuery->sql($parameters);
$delete->addWhere([
"\"{$this->joinTable}\".\"{$this->localKey}\" IN ($subSelect)" => $parameters
]);
$affectedIds = [];
if ($this->removeCallbacks) {
$affectedIds = $delete
->toSelect()
->setSelect("\"{$this->joinTable}\".\"{$this->localKey}\"")
->execute()
->column();
}
// Perform the deletion
$delete->execute();
if ($this->removeCallbacks && $affectedIds) {
$this->removeCallbacks->call($this, $affectedIds);
}
} | Remove all items from this many-many join. To remove a subset of items,
filter it first.
@return void | removeAll | php | silverstripe/silverstripe-framework | src/ORM/ManyManyList.php | https://github.com/silverstripe/silverstripe-framework/blob/master/src/ORM/ManyManyList.php | BSD-3-Clause |
public function getExtraData($componentName, $itemID)
{
$result = [];
// Skip if no extrafields or unsaved record
if (empty($this->extraFields) || empty($itemID)) {
return $result;
}
if (!is_numeric($itemID)) {
throw new InvalidArgumentException('ManyManyList::getExtraData() passed a non-numeric child ID');
}
$cleanExtraFields = [];
foreach ($this->extraFields as $fieldName => $dbFieldSpec) {
$cleanExtraFields[] = "\"{$fieldName}\"";
}
$query = SQLSelect::create($cleanExtraFields, "\"{$this->joinTable}\"");
$filter = $this->foreignIDWriteFilter($this->getForeignID());
if ($filter) {
$query->setWhere($filter);
} else {
throw new BadMethodCallException("Can't call ManyManyList::getExtraData() until a foreign ID is set");
}
$query->addWhere([
"\"{$this->joinTable}\".\"{$this->localKey}\"" => $itemID
]);
$queryResult = $query->execute()->record();
if ($queryResult) {
foreach ($queryResult as $fieldName => $value) {
$result[$fieldName] = $value;
}
}
return $result;
} | Find the extra field data for a single row of the relationship join
table, given the known child ID.
@param string $componentName The name of the component
@param int $itemID The ID of the child for the relationship
@return array Map of fieldName => fieldValue | getExtraData | php | silverstripe/silverstripe-framework | src/ORM/ManyManyList.php | https://github.com/silverstripe/silverstripe-framework/blob/master/src/ORM/ManyManyList.php | BSD-3-Clause |
public function getJoinTable()
{
return $this->joinTable;
} | Gets the join table used for the relationship.
@return string the name of the table | getJoinTable | php | silverstripe/silverstripe-framework | src/ORM/ManyManyList.php | https://github.com/silverstripe/silverstripe-framework/blob/master/src/ORM/ManyManyList.php | BSD-3-Clause |
public function getLocalKey()
{
return $this->localKey;
} | Gets the key used to store the ID of the local/parent object.
@return string the field name | getLocalKey | php | silverstripe/silverstripe-framework | src/ORM/ManyManyList.php | https://github.com/silverstripe/silverstripe-framework/blob/master/src/ORM/ManyManyList.php | BSD-3-Clause |
public function getExtraFields()
{
return $this->extraFields;
} | Gets the extra fields included in the relationship.
@return array a map of field names to types | getExtraFields | php | silverstripe/silverstripe-framework | src/ORM/ManyManyList.php | https://github.com/silverstripe/silverstripe-framework/blob/master/src/ORM/ManyManyList.php | BSD-3-Clause |
public function __construct(SS_List $list, $keyField = "ID", $valueField = "Title")
{
Deprecation::withSuppressedNotice(function () {
Deprecation::notice('5.4.0', 'Will be renamed to SilverStripe\Model\List\Map', Deprecation::SCOPE_CLASS);
});
$this->list = $list;
$this->keyField = $keyField;
$this->valueField = $valueField;
} | Construct a new map around an SS_list.
@param SS_List $list The list to build a map from
@param string $keyField The field to use as the key of each map entry
@param string $valueField The field to use as the value of each map entry | __construct | php | silverstripe/silverstripe-framework | src/ORM/Map.php | https://github.com/silverstripe/silverstripe-framework/blob/master/src/ORM/Map.php | BSD-3-Clause |
public function setKeyField($keyField)
{
$this->keyField = $keyField;
} | Set the key field for this map.
@var string $keyField | setKeyField | php | silverstripe/silverstripe-framework | src/ORM/Map.php | https://github.com/silverstripe/silverstripe-framework/blob/master/src/ORM/Map.php | BSD-3-Clause |
public function setValueField($valueField)
{
$this->valueField = $valueField;
} | Set the value field for this map.
@var string $valueField | setValueField | php | silverstripe/silverstripe-framework | src/ORM/Map.php | https://github.com/silverstripe/silverstripe-framework/blob/master/src/ORM/Map.php | BSD-3-Clause |
public function toArray()
{
$array = [];
foreach ($this as $k => $v) {
$array[$k] = $v;
}
return $array;
} | Return an array equivalent to this map.
@return array | toArray | php | silverstripe/silverstripe-framework | src/ORM/Map.php | https://github.com/silverstripe/silverstripe-framework/blob/master/src/ORM/Map.php | BSD-3-Clause |
public function keys()
{
return array_keys($this->toArray() ?? []);
} | Return all the keys of this map.
@return array | keys | php | silverstripe/silverstripe-framework | src/ORM/Map.php | https://github.com/silverstripe/silverstripe-framework/blob/master/src/ORM/Map.php | BSD-3-Clause |
public function values()
{
return array_values($this->toArray() ?? []);
} | Return all the values of this map.
@return array | values | php | silverstripe/silverstripe-framework | src/ORM/Map.php | https://github.com/silverstripe/silverstripe-framework/blob/master/src/ORM/Map.php | BSD-3-Clause |
public function unshift($key, $value)
{
$oldItems = $this->firstItems;
$this->firstItems = [
$key => $value
];
if ($oldItems) {
$this->firstItems = $this->firstItems + $oldItems;
}
return $this;
} | Unshift an item onto the start of the map.
Stores the value in addition to the {@link DataQuery} for the map.
@var string $key
@var mixed $value
@return $this | unshift | php | silverstripe/silverstripe-framework | src/ORM/Map.php | https://github.com/silverstripe/silverstripe-framework/blob/master/src/ORM/Map.php | BSD-3-Clause |
public function push($key, $value)
{
$oldItems = $this->lastItems;
$this->lastItems = [
$key => $value
];
if ($oldItems) {
$this->lastItems = $this->lastItems + $oldItems;
}
return $this;
} | Pushes an item onto the end of the map.
@var string $key
@var mixed $value
@return $this | push | php | silverstripe/silverstripe-framework | src/ORM/Map.php | https://github.com/silverstripe/silverstripe-framework/blob/master/src/ORM/Map.php | BSD-3-Clause |
protected function extractValue($item, $key)
{
if (is_object($item)) {
if (method_exists($item, 'hasMethod') && $item->hasMethod($key)) {
return $item->{$key}();
}
return $item->{$key};
} else {
if (array_key_exists($key, $item)) {
return $item[$key];
}
}
} | Extracts a value from an item in the list, where the item is either an
object or array.
@param array|object $item
@param string $key
@return mixed | extractValue | php | silverstripe/silverstripe-framework | src/ORM/Map.php | https://github.com/silverstripe/silverstripe-framework/blob/master/src/ORM/Map.php | BSD-3-Clause |
protected function foreignIDFilter($id = null)
{
// foreignIDFilter is applied to the HasManyList via ManyManyThroughQueryManipulator, not here
return [];
} | Don't apply foreign ID filter until getFinalisedQuery() | foreignIDFilter | php | silverstripe/silverstripe-framework | src/ORM/ManyManyThroughList.php | https://github.com/silverstripe/silverstripe-framework/blob/master/src/ORM/ManyManyThroughList.php | BSD-3-Clause |
public function getExtraFields()
{
// Inherit config from join table
$joinClass = $this->manipulator->getJoinClass();
return Config::inst()->get($joinClass, 'db');
} | Get extra fields used by this list
@return array a map of field names to types | getExtraFields | php | silverstripe/silverstripe-framework | src/ORM/ManyManyThroughList.php | https://github.com/silverstripe/silverstripe-framework/blob/master/src/ORM/ManyManyThroughList.php | BSD-3-Clause |
public function __construct($baseClass, $relationName, $dataClass)
{
$this->baseClass = $baseClass;
$this->relationName = $relationName;
$this->dataClass = $dataClass;
parent::__construct();
} | Create a new UnsavedRelationList
@param string $baseClass
@param string $relationName
@param class-string<T> $dataClass The DataObject class used in the relation | __construct | php | silverstripe/silverstripe-framework | src/ORM/UnsavedRelationList.php | https://github.com/silverstripe/silverstripe-framework/blob/master/src/ORM/UnsavedRelationList.php | BSD-3-Clause |
public function add($item, $extraFields = null)
{
$this->push($item, $extraFields);
} | Add an item to this relationship
@param mixed $item
@param array $extraFields A map of additional columns to insert into the joinTable in the case of a many_many relation | add | php | silverstripe/silverstripe-framework | src/ORM/UnsavedRelationList.php | https://github.com/silverstripe/silverstripe-framework/blob/master/src/ORM/UnsavedRelationList.php | BSD-3-Clause |
public function push($item, $extraFields = null)
{
if ((is_object($item) && !$item instanceof $this->dataClass)
|| (!is_object($item) && !is_numeric($item))
) {
throw new InvalidArgumentException(
"UnsavedRelationList::add() expecting a $this->dataClass object, or ID value"
);
}
if (is_object($item) && $item->ID) {
$item = $item->ID;
}
$this->extraFields[] = $extraFields;
parent::push($item);
} | Pushes an item onto the end of this list.
@param array|object $item
@param array $extraFields | push | php | silverstripe/silverstripe-framework | src/ORM/UnsavedRelationList.php | https://github.com/silverstripe/silverstripe-framework/blob/master/src/ORM/UnsavedRelationList.php | BSD-3-Clause |
public function dataClass()
{
return $this->dataClass;
} | Get the dataClass name for this relation, ie the DataObject ClassName
@return class-string<T> | dataClass | php | silverstripe/silverstripe-framework | src/ORM/UnsavedRelationList.php | https://github.com/silverstripe/silverstripe-framework/blob/master/src/ORM/UnsavedRelationList.php | BSD-3-Clause |
public function toArray()
{
$items = [];
foreach ($this->items as $key => $item) {
if (is_numeric($item)) {
$item = DataObject::get_by_id($this->dataClass, $item);
}
if (!empty($this->extraFields[$key])) {
$item->update($this->extraFields[$key]);
}
$items[] = $item;
}
return $items;
} | Return an array of the actual items that this relation contains at this stage.
This is when the query is actually executed. | toArray | php | silverstripe/silverstripe-framework | src/ORM/UnsavedRelationList.php | https://github.com/silverstripe/silverstripe-framework/blob/master/src/ORM/UnsavedRelationList.php | BSD-3-Clause |
public function removeAll()
{
$this->items = [];
$this->extraFields = [];
} | Remove all items from this relation. | removeAll | php | silverstripe/silverstripe-framework | src/ORM/UnsavedRelationList.php | https://github.com/silverstripe/silverstripe-framework/blob/master/src/ORM/UnsavedRelationList.php | BSD-3-Clause |
public function removeMany($items)
{
$this->items = array_diff($this->items ?? [], $items);
return $this;
} | Remove the items from this list with the given IDs
@param array $items
@return $this | removeMany | php | silverstripe/silverstripe-framework | src/ORM/UnsavedRelationList.php | https://github.com/silverstripe/silverstripe-framework/blob/master/src/ORM/UnsavedRelationList.php | BSD-3-Clause |
public function removeDuplicates($field = 'ID')
{
$this->items = array_unique($this->items ?? []);
} | Removes items from this list which are equal.
@param string $field unused | removeDuplicates | php | silverstripe/silverstripe-framework | src/ORM/UnsavedRelationList.php | https://github.com/silverstripe/silverstripe-framework/blob/master/src/ORM/UnsavedRelationList.php | BSD-3-Clause |
public function setByIDList($idList)
{
$this->removeAll();
$this->addMany($idList);
} | Sets the Relation to be the given ID list.
Records will be added and deleted as appropriate.
@param array $idList List of IDs. | setByIDList | php | silverstripe/silverstripe-framework | src/ORM/UnsavedRelationList.php | https://github.com/silverstripe/silverstripe-framework/blob/master/src/ORM/UnsavedRelationList.php | BSD-3-Clause |
public function getIDList()
{
// Get a list of IDs of our current items - if it's not a number then object then assume it's a DO.
$ids = array_map(function ($obj) {
return is_numeric($obj) ? $obj : $obj->ID;
}, $this->items ?? []);
// Strip out duplicates and anything resolving to False.
$ids = array_filter(array_unique($ids ?? []));
// Change the array from (1, 2, 3) to (1 => 1, 2 => 2, 3 => 3)
if ($ids) {
$ids = array_combine($ids ?? [], $ids ?? []);
}
return $ids;
} | Returns an array with both the keys and values set to the IDs of the records in this list.
Does not respect sort order. Use ->column("ID") to get an ID list with the current sort.
Does not return the IDs for unsaved DataObjects. | getIDList | php | silverstripe/silverstripe-framework | src/ORM/UnsavedRelationList.php | https://github.com/silverstripe/silverstripe-framework/blob/master/src/ORM/UnsavedRelationList.php | BSD-3-Clause |
public function column($colName = 'ID')
{
$list = new ArrayList($this->toArray());
return $list->column($colName);
} | Returns an array of a single field value for all items in the list.
@param string $colName
@return array | column | php | silverstripe/silverstripe-framework | src/ORM/UnsavedRelationList.php | https://github.com/silverstripe/silverstripe-framework/blob/master/src/ORM/UnsavedRelationList.php | BSD-3-Clause |
public function columnUnique($colName = "ID")
{
$list = new ArrayList($this->toArray());
return $list->columnUnique($colName);
} | Returns a unique array of a single field value for all items in the list.
@param string $colName
@return array | columnUnique | php | silverstripe/silverstripe-framework | src/ORM/UnsavedRelationList.php | https://github.com/silverstripe/silverstripe-framework/blob/master/src/ORM/UnsavedRelationList.php | BSD-3-Clause |
public function forForeignID($id)
{
$singleton = DataObject::singleton($this->baseClass);
/** @var Relation $relation */
$relation = $singleton->{$this->relationName}($id);
return $relation;
} | Returns a copy of this list with the relationship linked to the given foreign ID.
@param int|array $id An ID or an array of IDs.
@return Relation<T> | forForeignID | php | silverstripe/silverstripe-framework | src/ORM/UnsavedRelationList.php | https://github.com/silverstripe/silverstripe-framework/blob/master/src/ORM/UnsavedRelationList.php | BSD-3-Clause |
public function dbObject($fieldName)
{
return DataObject::singleton($this->dataClass)->dbObject($fieldName);
} | Return the DBField object that represents the given field on the related class.
@param string $fieldName Name of the field
@return DBField The field as a DBField object | dbObject | php | silverstripe/silverstripe-framework | src/ORM/UnsavedRelationList.php | https://github.com/silverstripe/silverstripe-framework/blob/master/src/ORM/UnsavedRelationList.php | BSD-3-Clause |
public function query()
{
return $this->getFinalisedQuery();
} | Return the {@link SQLSelect} object that represents the current query; note that it will
be a clone of the object.
@return SQLSelect | query | php | silverstripe/silverstripe-framework | src/ORM/DataQuery.php | https://github.com/silverstripe/silverstripe-framework/blob/master/src/ORM/DataQuery.php | BSD-3-Clause |
protected function initialiseQuery()
{
// Join on base table and let lazy loading join subtables
$baseClass = DataObject::getSchema()->baseDataClass($this->dataClass());
if (!$baseClass) {
throw new InvalidArgumentException("DataQuery::create() Can't find data classes for '{$this->dataClass}'");
}
// Build our initial query
$this->query = new SQLSelect([]);
$this->query->setDistinct(true);
if ($sort = singleton($this->dataClass)->config()->get('default_sort')) {
$this->sort($sort);
}
$baseTable = DataObject::getSchema()->tableName($baseClass);
$this->query->setFrom("\"{$baseTable}\"");
$obj = Injector::inst()->get($baseClass);
$obj->extend('augmentDataQueryCreation', $this->query, $this);
} | Set up the simplest initial query | initialiseQuery | php | silverstripe/silverstripe-framework | src/ORM/DataQuery.php | https://github.com/silverstripe/silverstripe-framework/blob/master/src/ORM/DataQuery.php | BSD-3-Clause |
public function count()
{
$quotedColumn = DataObject::getSchema()->sqlColumnForField($this->dataClass(), 'ID');
return $this->getFinalisedQuery()->count("DISTINCT {$quotedColumn}");
} | Return the number of records in this query.
Note that this will issue a separate SELECT COUNT() query.
@return int | count | php | silverstripe/silverstripe-framework | src/ORM/DataQuery.php | https://github.com/silverstripe/silverstripe-framework/blob/master/src/ORM/DataQuery.php | BSD-3-Clause |
public function max($field)
{
$table = DataObject::getSchema()->tableForField($this->dataClass, $field);
if (!$table) {
return $this->aggregate("MAX(\"$field\")");
}
return $this->aggregate("MAX(\"$table\".\"$field\")");
} | Return the maximum value of the given field in this DataList
@param string $field Unquoted database column name. Will be ANSI quoted
automatically so must not contain double quotes.
@return string | max | php | silverstripe/silverstripe-framework | src/ORM/DataQuery.php | https://github.com/silverstripe/silverstripe-framework/blob/master/src/ORM/DataQuery.php | BSD-3-Clause |
public function min($field)
{
$table = DataObject::getSchema()->tableForField($this->dataClass, $field);
if (!$table) {
return $this->aggregate("MIN(\"$field\")");
}
return $this->aggregate("MIN(\"$table\".\"$field\")");
} | Return the minimum value of the given field in this DataList
@param string $field Unquoted database column name. Will be ANSI quoted
automatically so must not contain double quotes.
@return string | min | php | silverstripe/silverstripe-framework | src/ORM/DataQuery.php | https://github.com/silverstripe/silverstripe-framework/blob/master/src/ORM/DataQuery.php | BSD-3-Clause |
public function avg($field)
{
$table = DataObject::getSchema()->tableForField($this->dataClass, $field);
if (!$table) {
return $this->aggregate("AVG(\"$field\")");
}
return $this->aggregate("AVG(\"$table\".\"$field\")");
} | Return the average value of the given field in this DataList
@param string $field Unquoted database column name. Will be ANSI quoted
automatically so must not contain double quotes.
@return string | avg | php | silverstripe/silverstripe-framework | src/ORM/DataQuery.php | https://github.com/silverstripe/silverstripe-framework/blob/master/src/ORM/DataQuery.php | BSD-3-Clause |
public function sum($field)
{
$table = DataObject::getSchema()->tableForField($this->dataClass, $field);
if (!$table) {
return $this->aggregate("SUM(\"$field\")");
}
return $this->aggregate("SUM(\"$table\".\"$field\")");
} | Return the sum of the values of the given field in this DataList
@param string $field Unquoted database column name. Will be ANSI quoted
automatically so must not contain double quotes.
@return string | sum | php | silverstripe/silverstripe-framework | src/ORM/DataQuery.php | https://github.com/silverstripe/silverstripe-framework/blob/master/src/ORM/DataQuery.php | BSD-3-Clause |
public function aggregate($expression)
{
return $this->getFinalisedQuery()->aggregate($expression)->execute()->value();
} | Runs a raw aggregate expression. Please handle escaping yourself
@param string $expression An aggregate expression, such as 'MAX("Balance")', or a set of them
(as an escaped SQL statement)
@return string | aggregate | php | silverstripe/silverstripe-framework | src/ORM/DataQuery.php | https://github.com/silverstripe/silverstripe-framework/blob/master/src/ORM/DataQuery.php | BSD-3-Clause |
public function firstRow()
{
return $this->getFinalisedQuery()->firstRow();
} | Return the first row that would be returned by this full DataQuery
Note that this will issue a separate SELECT ... LIMIT 1 query.
@return SQLSelect | firstRow | php | silverstripe/silverstripe-framework | src/ORM/DataQuery.php | https://github.com/silverstripe/silverstripe-framework/blob/master/src/ORM/DataQuery.php | BSD-3-Clause |
public function lastRow()
{
return $this->getFinalisedQuery()->lastRow();
} | Return the last row that would be returned by this full DataQuery
Note that this will issue a separate SELECT ... LIMIT query.
@return SQLSelect | lastRow | php | silverstripe/silverstripe-framework | src/ORM/DataQuery.php | https://github.com/silverstripe/silverstripe-framework/blob/master/src/ORM/DataQuery.php | BSD-3-Clause |
protected function selectColumnsFromTable(SQLSelect &$query, $tableClass, $columns = null)
{
// Add SQL for multi-value fields
$schema = DataObject::getSchema();
$databaseFields = $schema->databaseFields($tableClass, false);
$compositeFields = $schema->compositeFields($tableClass, false);
$tableName = $schema->tableName($tableClass);
unset($databaseFields['ID']);
foreach ($databaseFields as $k => $v) {
if ((is_null($columns) || in_array($k, $columns ?? [])) && !isset($compositeFields[$k])) {
// Update $collidingFields if necessary
$expressionForField = $query->expressionForField($k);
$quotedField = $schema->sqlColumnForField($tableClass, $k);
if ($expressionForField) {
if (!isset($this->collidingFields[$k])) {
$this->collidingFields[$k] = [$expressionForField];
}
$this->collidingFields[$k][] = $quotedField;
} else {
$query->selectField($quotedField, $k);
}
$dbO = Injector::inst()->create($v, $k);
$dbO->setTable($tableName);
$dbO->addToQuery($query);
}
}
foreach ($compositeFields as $k => $v) {
if ((is_null($columns) || in_array($k, $columns ?? [])) && $v) {
$dbO = Injector::inst()->create($v, $k);
$dbO->setTable($tableName);
$dbO->addToQuery($query);
}
}
} | Update the SELECT clause of the query with the columns from the given table
@param SQLSelect $query
@param string $tableClass Class to select from
@param array $columns | selectColumnsFromTable | php | silverstripe/silverstripe-framework | src/ORM/DataQuery.php | https://github.com/silverstripe/silverstripe-framework/blob/master/src/ORM/DataQuery.php | BSD-3-Clause |
public function groupby($groupby)
{
$this->query->addGroupBy($groupby);
return $this;
} | Append a GROUP BY clause to this query.
@param string $groupby Escaped SQL statement
@return $this | groupby | php | silverstripe/silverstripe-framework | src/ORM/DataQuery.php | https://github.com/silverstripe/silverstripe-framework/blob/master/src/ORM/DataQuery.php | BSD-3-Clause |
public function having($having)
{
$this->query->addHaving($having);
return $this;
} | Append a HAVING clause to this query.
@param mixed $having Predicate(s) to set, as escaped SQL statements or parameterised queries
@return $this | having | php | silverstripe/silverstripe-framework | src/ORM/DataQuery.php | https://github.com/silverstripe/silverstripe-framework/blob/master/src/ORM/DataQuery.php | BSD-3-Clause |
public function disjunctiveGroup()
{
// using func_get_args to add a new param while retaining BC
// @deprecated - add a new param for CMS 6 - string $clause = 'WHERE'
$clause = 'WHERE';
$args = func_get_args();
if (count($args) > 0) {
$clause = $args[0];
}
return new DataQuery_SubGroup($this, 'OR', $clause);
} | Create a disjunctive subgroup.
That is a subgroup joined by OR
@param string $clause
@return DataQuery_SubGroup | disjunctiveGroup | php | silverstripe/silverstripe-framework | src/ORM/DataQuery.php | https://github.com/silverstripe/silverstripe-framework/blob/master/src/ORM/DataQuery.php | BSD-3-Clause |
public function conjunctiveGroup()
{
// using func_get_args to add a new param while retaining BC
// @deprecated - add a new param for CMS 6 - string $clause = 'WHERE'
$clause = 'WHERE';
$args = func_get_args();
if (count($args) > 0) {
$clause = $args[0];
}
return new DataQuery_SubGroup($this, 'AND', $clause);
} | Create a conjunctive subgroup
That is a subgroup joined by AND
@param string $clause
@return DataQuery_SubGroup | conjunctiveGroup | php | silverstripe/silverstripe-framework | src/ORM/DataQuery.php | https://github.com/silverstripe/silverstripe-framework/blob/master/src/ORM/DataQuery.php | BSD-3-Clause |
public function where($filter)
{
if ($filter) {
$this->query->addWhere($filter);
}
return $this;
} | Adds a WHERE clause.
@see SQLSelect::addWhere() for syntax examples, although DataQuery
won't expand multiple arguments as SQLSelect does.
@param string|array|SQLConditionGroup $filter Predicate(s) to set, as escaped SQL statements or
paramaterised queries
@return $this | where | php | silverstripe/silverstripe-framework | src/ORM/DataQuery.php | https://github.com/silverstripe/silverstripe-framework/blob/master/src/ORM/DataQuery.php | BSD-3-Clause |
public function whereAny($filter)
{
if ($filter) {
$this->query->addWhereAny($filter);
}
return $this;
} | Append a WHERE with OR.
@see SQLSelect::addWhere() for syntax examples, although DataQuery
won't expand multiple method arguments as SQLSelect does.
@param string|array|SQLConditionGroup $filter Predicate(s) to set, as escaped SQL statements or
paramaterised queries
@return $this | whereAny | php | silverstripe/silverstripe-framework | src/ORM/DataQuery.php | https://github.com/silverstripe/silverstripe-framework/blob/master/src/ORM/DataQuery.php | BSD-3-Clause |
public function sort($sort = null, $direction = null, $clear = true)
{
if ($clear) {
$this->query->setOrderBy($sort, $direction);
} else {
$this->query->addOrderBy($sort, $direction);
}
return $this;
} | Set the ORDER BY clause of this query
Note: while the similarly named DataList::sort() does not allow raw SQL, DataQuery::sort() does allow it
Raw SQL can be vulnerable to SQL injection attacks if used incorrectly, so it's preferable not to use it
@see SQLSelect::orderby()
@param string $sort Column to sort on (escaped SQL statement)
@param string $direction Direction ("ASC" or "DESC", escaped SQL statement)
@param bool $clear Clear existing values
@return $this | sort | php | silverstripe/silverstripe-framework | src/ORM/DataQuery.php | https://github.com/silverstripe/silverstripe-framework/blob/master/src/ORM/DataQuery.php | BSD-3-Clause |
public function distinct($value)
{
$this->query->setDistinct($value);
return $this;
} | Set whether this query should be distinct or not.
@param bool $value
@return $this | distinct | php | silverstripe/silverstripe-framework | src/ORM/DataQuery.php | https://github.com/silverstripe/silverstripe-framework/blob/master/src/ORM/DataQuery.php | BSD-3-Clause |
public function innerJoin($table, $onClause, $alias = null, $order = 20, $parameters = [])
{
if ($table) {
$this->query->addInnerJoin($table, $onClause, $alias, $order, $parameters);
}
return $this;
} | Add an INNER JOIN clause to this query.
@param string $table The unquoted table name to join to.
@param string $onClause The filter for the join (escaped SQL statement)
@param string $alias An optional alias name (unquoted)
@param int $order A numerical index to control the order that joins are added to the query; lower order values
will cause the query to appear first. The default is 20, and joins created automatically by the
ORM have a value of 10.
@param array $parameters Any additional parameters if the join is a parameterised subquery
@return $this | innerJoin | php | silverstripe/silverstripe-framework | src/ORM/DataQuery.php | https://github.com/silverstripe/silverstripe-framework/blob/master/src/ORM/DataQuery.php | BSD-3-Clause |
public function leftJoin($table, $onClause, $alias = null, $order = 20, $parameters = [])
{
if ($table) {
$this->query->addLeftJoin($table, $onClause, $alias, $order, $parameters);
}
return $this;
} | Add a LEFT JOIN clause to this query.
@param string $table The unquoted table to join to.
@param string $onClause The filter for the join (escaped SQL statement).
@param string $alias An optional alias name (unquoted)
@param int $order A numerical index to control the order that joins are added to the query; lower order values
will cause the query to appear first. The default is 20, and joins created automatically by the
ORM have a value of 10.
@param array $parameters Any additional parameters if the join is a parameterised subquery
@return $this | leftJoin | php | silverstripe/silverstripe-framework | src/ORM/DataQuery.php | https://github.com/silverstripe/silverstripe-framework/blob/master/src/ORM/DataQuery.php | BSD-3-Clause |
public function rightJoin($table, $onClause, $alias = null, $order = 20, $parameters = [])
{
if ($table) {
$this->query->addRightJoin($table, $onClause, $alias, $order, $parameters);
}
return $this;
} | Add a RIGHT JOIN clause to this query.
@param string $table The unquoted table to join to.
@param string $onClause The filter for the join (escaped SQL statement).
@param string $alias An optional alias name (unquoted)
@param int $order A numerical index to control the order that joins are added to the query; lower order values
will cause the query to appear first. The default is 20, and joins created automatically by the
ORM have a value of 10.
@param array $parameters Any additional parameters if the join is a parameterised subquery
@return $this | rightJoin | php | silverstripe/silverstripe-framework | src/ORM/DataQuery.php | https://github.com/silverstripe/silverstripe-framework/blob/master/src/ORM/DataQuery.php | BSD-3-Clause |
public static function applyRelationPrefix($relation)
{
if (!$relation) {
return null;
}
if (is_string($relation)) {
$relation = explode(".", $relation ?? '');
}
return strtolower(implode('_', $relation)) . '_';
} | Prefix of all joined table aliases. E.g. ->filter('Banner.Image.Title)'
Will join the Banner, and then Image relations
`$relationPrefx` will be `banner_image_`
Each table in the Image chain will be suffixed to this prefix. E.g.
`banner_image_File` and `banner_image_Image`
This will be null if no relation is joined.
E.g. `->filter('Title')`
@param string|array $relation Relation in '.' delimited string, or array of parts
@return string Table prefix | applyRelationPrefix | php | silverstripe/silverstripe-framework | src/ORM/DataQuery.php | https://github.com/silverstripe/silverstripe-framework/blob/master/src/ORM/DataQuery.php | BSD-3-Clause |
public function subtract(DataQuery $subtractQuery, $field = 'ID')
{
$fieldExpression = $subtractQuery->expressionForField($field);
$subSelect = $subtractQuery->getFinalisedQuery();
$subSelect->setSelect([]);
$subSelect->selectField($fieldExpression, $field);
$subSelect->setOrderBy(null);
$subSelectSQL = $subSelect->sql($subSelectParameters);
$this->where([$this->expressionForField($field) . " NOT IN ($subSelectSQL)" => $subSelectParameters]);
return $this;
} | Removes the result of query from this query.
@param DataQuery $subtractQuery
@param string $field
@return $this | subtract | php | silverstripe/silverstripe-framework | src/ORM/DataQuery.php | https://github.com/silverstripe/silverstripe-framework/blob/master/src/ORM/DataQuery.php | BSD-3-Clause |
public function selectField($fieldExpression, $alias = null)
{
$this->query->selectField($fieldExpression, $alias);
} | Select the given field expressions.
@param string $fieldExpression String The field to select (escaped SQL statement)
@param string $alias String The alias of that field (escaped SQL statement) | selectField | php | silverstripe/silverstripe-framework | src/ORM/DataQuery.php | https://github.com/silverstripe/silverstripe-framework/blob/master/src/ORM/DataQuery.php | BSD-3-Clause |
public function setQueryParam($key, $value)
{
$this->queryParams[$key] = $value;
return $this;
} | Set an arbitrary query parameter, that can be used by decorators to add additional meta-data to the query.
It's expected that the $key will be namespaced, e.g, 'Versioned.stage' instead of just 'stage'.
@param string $key
@param string|array $value
@return $this | setQueryParam | php | silverstripe/silverstripe-framework | src/ORM/DataQuery.php | https://github.com/silverstripe/silverstripe-framework/blob/master/src/ORM/DataQuery.php | BSD-3-Clause |
public function getQueryParam($key)
{
if (isset($this->queryParams[$key])) {
return $this->queryParams[$key];
}
return null;
} | Set an arbitrary query parameter, that can be used by decorators to add additional meta-data to the query.
@param string $key
@return string | getQueryParam | php | silverstripe/silverstripe-framework | src/ORM/DataQuery.php | https://github.com/silverstripe/silverstripe-framework/blob/master/src/ORM/DataQuery.php | BSD-3-Clause |
public function pushQueryManipulator(DataQueryManipulator $manipulator)
{
$this->dataQueryManipulators[] = $manipulator;
return $this;
} | Assign callback to be invoked in getFinalisedQuery()
@param DataQueryManipulator $manipulator
@return $this | pushQueryManipulator | php | silverstripe/silverstripe-framework | src/ORM/DataQuery.php | https://github.com/silverstripe/silverstripe-framework/blob/master/src/ORM/DataQuery.php | BSD-3-Clause |
private function getJoinTableName($class, $table)
{
$updated = $table;
$this->invokeWithExtensions('updateJoinTableName', $class, $table, $updated);
return $updated;
} | Use this extension point to alter the table name
useful for versioning for example
@param $class
@param $table
@return mixed | getJoinTableName | php | silverstripe/silverstripe-framework | src/ORM/DataQuery.php | https://github.com/silverstripe/silverstripe-framework/blob/master/src/ORM/DataQuery.php | BSD-3-Clause |
public function validate(ValidationResult $validationResult)
{
} | Hook for extension-specific validation.
@param ValidationResult $validationResult Local validation result
@throws ValidationException | validate | php | silverstripe/silverstripe-framework | src/ORM/DataExtension.php | https://github.com/silverstripe/silverstripe-framework/blob/master/src/ORM/DataExtension.php | BSD-3-Clause |
public function augmentSQL(SQLSelect $query, DataQuery $dataQuery = null)
{
} | Edit the given query object to support queries for this extension
@param SQLSelect $query Query to augment.
@param DataQuery $dataQuery Container DataQuery for this SQLSelect | augmentSQL | php | silverstripe/silverstripe-framework | src/ORM/DataExtension.php | https://github.com/silverstripe/silverstripe-framework/blob/master/src/ORM/DataExtension.php | BSD-3-Clause |
public function augmentDatabase()
{
} | Update the database schema as required by this extension.
When duplicating a table's structure, remember to duplicate the create options
as well. See {@link Versioned->augmentDatabase} for an example. | augmentDatabase | php | silverstripe/silverstripe-framework | src/ORM/DataExtension.php | https://github.com/silverstripe/silverstripe-framework/blob/master/src/ORM/DataExtension.php | BSD-3-Clause |
public function augmentWrite(&$manipulation)
{
} | Augment a write-record request.
@param array $manipulation Array of operations to augment. | augmentWrite | php | silverstripe/silverstripe-framework | src/ORM/DataExtension.php | https://github.com/silverstripe/silverstripe-framework/blob/master/src/ORM/DataExtension.php | BSD-3-Clause |
public function onBeforeWrite()
{
} | Extend the owner's onBeforeWrite() logic
See {@link DataObject::onBeforeWrite()} for context. | onBeforeWrite | php | silverstripe/silverstripe-framework | src/ORM/DataExtension.php | https://github.com/silverstripe/silverstripe-framework/blob/master/src/ORM/DataExtension.php | BSD-3-Clause |
public function onAfterWrite()
{
} | Extend the owner's onAfterWrite() logic
See {@link DataObject::onAfterWrite()} for context. | onAfterWrite | php | silverstripe/silverstripe-framework | src/ORM/DataExtension.php | https://github.com/silverstripe/silverstripe-framework/blob/master/src/ORM/DataExtension.php | BSD-3-Clause |
public function onBeforeDelete()
{
} | Extend the owner's onBeforeDelete() logic
See {@link DataObject::onBeforeDelete()} for context. | onBeforeDelete | php | silverstripe/silverstripe-framework | src/ORM/DataExtension.php | https://github.com/silverstripe/silverstripe-framework/blob/master/src/ORM/DataExtension.php | BSD-3-Clause |
public function onAfterDelete()
{
} | Extend the owner's onAfterDelete() logic
See {@link DataObject::onAfterDelete()} for context. | onAfterDelete | php | silverstripe/silverstripe-framework | src/ORM/DataExtension.php | https://github.com/silverstripe/silverstripe-framework/blob/master/src/ORM/DataExtension.php | BSD-3-Clause |
public function requireDefaultRecords()
{
} | Extend the owner's requireDefaultRecords() logic
See {@link DataObject::requireDefaultRecords()} for context. | requireDefaultRecords | php | silverstripe/silverstripe-framework | src/ORM/DataExtension.php | https://github.com/silverstripe/silverstripe-framework/blob/master/src/ORM/DataExtension.php | BSD-3-Clause |
public function populateDefaults()
{
} | Extend the owner's populateDefaults() logic
See {@link DataObject::populateDefaults()} for context. | populateDefaults | php | silverstripe/silverstripe-framework | src/ORM/DataExtension.php | https://github.com/silverstripe/silverstripe-framework/blob/master/src/ORM/DataExtension.php | BSD-3-Clause |
public function onAfterBuild()
{
} | Extend the owner's onAfterBuild() logic
See {@link DataObject::onAfterBuild()} for context. | onAfterBuild | php | silverstripe/silverstripe-framework | src/ORM/DataExtension.php | https://github.com/silverstripe/silverstripe-framework/blob/master/src/ORM/DataExtension.php | BSD-3-Clause |
public function can($member)
{
} | Influence the owner's can() permission check value to be disallowed (false),
allowed (true) if no other processed results are to disallow, or open (null) to not
affect the outcome.
See {@link DataObject::can()} and {@link DataObject::extendedCan()} for context.
@param Member $member
@return bool|null | can | php | silverstripe/silverstripe-framework | src/ORM/DataExtension.php | https://github.com/silverstripe/silverstripe-framework/blob/master/src/ORM/DataExtension.php | BSD-3-Clause |
public function canEdit($member)
{
} | Influence the owner's canEdit() permission check value to be disallowed (false),
allowed (true) if no other processed results are to disallow, or open (null) to not
affect the outcome.
See {@link DataObject::canEdit()} and {@link DataObject::extendedCan()} for context.
@param Member $member
@return bool|null | canEdit | php | silverstripe/silverstripe-framework | src/ORM/DataExtension.php | https://github.com/silverstripe/silverstripe-framework/blob/master/src/ORM/DataExtension.php | BSD-3-Clause |
public function canDelete($member)
{
} | Influence the owner's canDelete() permission check value to be disallowed (false),
allowed (true) if no other processed results are to disallow, or open (null) to not
affect the outcome.
See {@link DataObject::canDelete()} and {@link DataObject::extendedCan()} for context.
@param Member $member
@return bool|null | canDelete | php | silverstripe/silverstripe-framework | src/ORM/DataExtension.php | https://github.com/silverstripe/silverstripe-framework/blob/master/src/ORM/DataExtension.php | BSD-3-Clause |
public function canCreate($member)
{
} | Influence the owner's canCreate() permission check value to be disallowed (false),
allowed (true) if no other processed results are to disallow, or open (null) to not
affect the outcome.
See {@link DataObject::canCreate()} and {@link DataObject::extendedCan()} for context.
@param Member $member
@return bool|null | canCreate | php | silverstripe/silverstripe-framework | src/ORM/DataExtension.php | https://github.com/silverstripe/silverstripe-framework/blob/master/src/ORM/DataExtension.php | BSD-3-Clause |
public function extraStatics($class = null, $extension = null)
{
return [];
} | Define extra database fields
Return a map where the keys are db, has_one, etc, and the values are
additional fields/relations to be defined.
@param string $class since this method might be called on the class directly
@param string $extension since this can help to extract parameters to help set indexes
@return array Returns a map where the keys are db, has_one, etc, and
the values are additional fields/relations to be defined. | extraStatics | php | silverstripe/silverstripe-framework | src/ORM/DataExtension.php | https://github.com/silverstripe/silverstripe-framework/blob/master/src/ORM/DataExtension.php | BSD-3-Clause |
public function updateCMSActions(FieldList $actions)
{
} | This is used to provide modifications to the form actions
used in the CMS. {@link DataObject->getCMSActions()}.
@param FieldList $actions FieldList | updateCMSActions | php | silverstripe/silverstripe-framework | src/ORM/DataExtension.php | https://github.com/silverstripe/silverstripe-framework/blob/master/src/ORM/DataExtension.php | BSD-3-Clause |
public function updateSummaryFields(&$fields)
{
$summary_fields = Config::inst()->get(static::class, 'summary_fields');
if ($summary_fields) {
// if summary_fields were passed in numeric array,
// convert to an associative array
if ($summary_fields && array_key_exists(0, $summary_fields ?? [])) {
$summary_fields = array_combine(array_values($summary_fields ?? []), array_values($summary_fields ?? []));
}
if ($summary_fields) {
$fields = array_merge($fields, $summary_fields);
}
}
} | this function is used to provide modifications to the summary fields in CMS
by the extension
By default, the summaryField() of its owner will merge more fields defined in the extension's
$extra_fields['summary_fields']
@param array $fields Array of field names | updateSummaryFields | php | silverstripe/silverstripe-framework | src/ORM/DataExtension.php | https://github.com/silverstripe/silverstripe-framework/blob/master/src/ORM/DataExtension.php | BSD-3-Clause |
public function updateFieldLabels(&$labels)
{
$field_labels = Config::inst()->get(static::class, 'field_labels');
if ($field_labels) {
$labels = array_merge($labels, $field_labels);
}
} | this function is used to provide modifications to the fields labels in CMS
by the extension
By default, the fieldLabels() of its owner will merge more fields defined in the extension's
$extra_fields['field_labels']
@param array $labels Array of field labels | updateFieldLabels | php | silverstripe/silverstripe-framework | src/ORM/DataExtension.php | https://github.com/silverstripe/silverstripe-framework/blob/master/src/ORM/DataExtension.php | BSD-3-Clause |
public static function invert($arr)
{
Deprecation::withSuppressedNotice(function () {
Deprecation::notice('5.4.0', 'Will be renamed to SilverStripe\Core\ArrayLib::invert()');
});
if (!$arr) {
return [];
}
$result = [];
foreach ($arr as $columnName => $column) {
foreach ($column as $rowName => $cell) {
$result[$rowName][$columnName] = $cell;
}
}
return $result;
} | Inverses the first and second level keys of an associative
array, keying the result by the second level, and combines
all first level entries within them.
Before:
<example>
array(
'row1' => array(
'col1' =>'val1',
'col2' => 'val2'
),
'row2' => array(
'col1' => 'val3',
'col2' => 'val4'
)
)
</example>
After:
<example>
array(
'col1' => array(
'row1' => 'val1',
'row2' => 'val3',
),
'col2' => array(
'row1' => 'val2',
'row2' => 'val4',
),
)
</example>
@param array $arr
@return array
@deprecated 5.4.0 Will be renamed to SilverStripe\Core\ArrayLib::invert() | invert | php | silverstripe/silverstripe-framework | src/ORM/ArrayLib.php | https://github.com/silverstripe/silverstripe-framework/blob/master/src/ORM/ArrayLib.php | BSD-3-Clause |
public static function valuekey($arr)
{
Deprecation::withSuppressedNotice(function () {
Deprecation::notice('5.4.0', 'Will be renamed to SilverStripe\Core\ArrayLib::valuekey()');
});
return array_combine($arr ?? [], $arr ?? []);
} | Return an array where the keys are all equal to the values.
@param $arr array
@return array
@deprecated 5.4.0 Will be renamed to SilverStripe\Core\ArrayLib::valuekey() | valuekey | php | silverstripe/silverstripe-framework | src/ORM/ArrayLib.php | https://github.com/silverstripe/silverstripe-framework/blob/master/src/ORM/ArrayLib.php | BSD-3-Clause |
public static function array_values_recursive($array)
{
Deprecation::withSuppressedNotice(function () {
Deprecation::notice('5.4.0', 'Will be renamed to SilverStripe\Core\ArrayLib::invearray_values_recursivert()');
});
return ArrayLib::flatten($array, false);
} | Flattens a multi-dimensional array to a one level array without preserving the keys
@param array $array
@return array
@deprecated 5.4.0 Will be renamed to SilverStripe\Core\ArrayLib::array_values_recursive() | array_values_recursive | php | silverstripe/silverstripe-framework | src/ORM/ArrayLib.php | https://github.com/silverstripe/silverstripe-framework/blob/master/src/ORM/ArrayLib.php | BSD-3-Clause |
public static function filter_keys($arr, $keys)
{
Deprecation::withSuppressedNotice(function () {
Deprecation::notice('5.4.0', 'Will be renamed to SilverStripe\Core\ArrayLib::filter_keys()');
});
foreach ($arr as $key => $v) {
if (!in_array($key, $keys ?? [])) {
unset($arr[$key]);
}
}
return $arr;
} | Filter an array by keys (useful for only allowing certain form-input to
be saved).
@param $arr array
@param $keys array
@return array
@deprecated 5.4.0 Will be renamed to SilverStripe\Core\ArrayLib::filter_keys() | filter_keys | php | silverstripe/silverstripe-framework | src/ORM/ArrayLib.php | https://github.com/silverstripe/silverstripe-framework/blob/master/src/ORM/ArrayLib.php | BSD-3-Clause |
public static function is_associative($array)
{
Deprecation::withSuppressedNotice(function () {
Deprecation::notice('5.4.0', 'Will be renamed to SilverStripe\Core\ArrayLib::is_associative()');
});
$isAssociative = !empty($array)
&& is_array($array)
&& ($array !== array_values($array ?? []));
return $isAssociative;
} | Determines if an array is associative by checking for existing keys via
array_key_exists().
@see http://nz.php.net/manual/en/function.is-array.php#121692
@param array $array
@return boolean
@deprecated 5.4.0 Will be renamed to SilverStripe\Core\ArrayLib::is_associative() | is_associative | php | silverstripe/silverstripe-framework | src/ORM/ArrayLib.php | https://github.com/silverstripe/silverstripe-framework/blob/master/src/ORM/ArrayLib.php | BSD-3-Clause |
public static function in_array_recursive($needle, $haystack, $strict = false)
{
Deprecation::withSuppressedNotice(function () {
Deprecation::notice('5.4.0', 'Will be renamed to SilverStripe\Core\ArrayLib::in_array_recursive()');
});
if (!is_array($haystack)) {
return false;
}
if (in_array($needle, $haystack ?? [], $strict ?? false)) {
return true;
} else {
foreach ($haystack as $obj) {
if (ArrayLib::in_array_recursive($needle, $obj, $strict)) {
return true;
}
}
}
return false;
} | Recursively searches an array $haystack for the value(s) $needle.
Assumes that all values in $needle (if $needle is an array) are at
the SAME level, not spread across multiple dimensions of the $haystack.
@param mixed $needle
@param array $haystack
@param boolean $strict
@return boolean
@deprecated 5.4.0 Will be renamed to SilverStripe\Core\ArrayLib::in_array_recursive() | in_array_recursive | php | silverstripe/silverstripe-framework | src/ORM/ArrayLib.php | https://github.com/silverstripe/silverstripe-framework/blob/master/src/ORM/ArrayLib.php | BSD-3-Clause |
public static function array_merge_recursive($array)
{
Deprecation::withSuppressedNotice(function () {
Deprecation::notice('5.4.0', 'Will be renamed to SilverStripe\Core\ArrayLib::array_merge_recursive()');
});
$arrays = func_get_args();
$merged = [];
if (count($arrays ?? []) == 1) {
return $array;
}
while ($arrays) {
$array = array_shift($arrays);
if (!is_array($array)) {
trigger_error(
'SilverStripe\ORM\ArrayLib::array_merge_recursive() encountered a non array argument',
E_USER_WARNING
);
return [];
}
if (!$array) {
continue;
}
foreach ($array as $key => $value) {
if (is_array($value) && array_key_exists($key, $merged ?? []) && is_array($merged[$key])) {
$merged[$key] = ArrayLib::array_merge_recursive($merged[$key], $value);
} else {
$merged[$key] = $value;
}
}
}
return $merged;
} | Recursively merges two or more arrays.
Behaves similar to array_merge_recursive(), however it only merges
values when both are arrays rather than creating a new array with
both values, as the PHP version does. The same behaviour also occurs
with numeric keys, to match that of what PHP does to generate $_REQUEST.
@param array $array
@return array
@deprecated 5.4.0 Will be renamed to SilverStripe\Core\ArrayLib::array_merge_recursive() | array_merge_recursive | php | silverstripe/silverstripe-framework | src/ORM/ArrayLib.php | https://github.com/silverstripe/silverstripe-framework/blob/master/src/ORM/ArrayLib.php | BSD-3-Clause |
public static function iterateVolatile(array &$list)
{
Deprecation::withSuppressedNotice(function () {
Deprecation::notice('5.4.0', 'Will be renamed to SilverStripe\Core\ArrayLib::iterateVolatile()');
});
// Keyed by already-iterated items
$iterated = [];
// Get all items not yet iterated
while ($items = array_diff_key($list ?? [], $iterated)) {
// Yield all results
foreach ($items as $key => $value) {
// Skip items removed by a prior step
if (array_key_exists($key, $list ?? [])) {
// Ensure we yield from the source list
$iterated[$key] = true;
yield $key => $list[$key];
}
}
}
} | Iterate list, but allowing for modifications to the underlying list.
Items in $list will only be iterated exactly once for each key, and supports
items being removed or deleted.
List must be associative.
@param array $list
@return Generator
@deprecated 5.4.0 Will be renamed to SilverStripe\Core\ArrayLib::iterateVolatile() | iterateVolatile | php | silverstripe/silverstripe-framework | src/ORM/ArrayLib.php | https://github.com/silverstripe/silverstripe-framework/blob/master/src/ORM/ArrayLib.php | BSD-3-Clause |
public function addError($message, $messageType = ValidationResult::TYPE_ERROR, $code = null, $cast = ValidationResult::CAST_TEXT)
{
if ($code === null) {
Deprecation::notice(
'5.4.0',
'Passing $code as null is deprecated. Pass a blank string instead.',
Deprecation::SCOPE_GLOBAL
);
$code = '';
}
if ($cast === null) {
Deprecation::notice(
'5.4.0',
'Passing $cast as null is deprecated. Pass a ValidationResult::CAST_* constant instead.',
Deprecation::SCOPE_GLOBAL
);
$cast = ValidationResult::CAST_TEXT;
}
return $this->addFieldError('', $message, $messageType, $code, $cast);
} | Record an error against this validation result,
@param string $message The message string.
@param string $messageType Passed as a CSS class to the form, so other values can be used if desired.
Standard types are defined by the TYPE_ constant definitions.
@param string $code A codename for this error. Only one message per codename will be added.
This can be usedful for ensuring no duplicate messages
@param string|bool $cast Cast type; One of the CAST_ constant definitions.
Bool values will be treated as plain text flag.
@return $this | addError | php | silverstripe/silverstripe-framework | src/ORM/ValidationResult.php | https://github.com/silverstripe/silverstripe-framework/blob/master/src/ORM/ValidationResult.php | BSD-3-Clause |
public function addFieldError(
$fieldName,
$message,
$messageType = ValidationResult::TYPE_ERROR,
$code = null,
$cast = ValidationResult::CAST_TEXT
) {
if ($code === null) {
Deprecation::notice(
'5.4.0',
'Passing $code as null is deprecated. Pass a blank string instead.',
Deprecation::SCOPE_GLOBAL
);
$code = '';
}
if ($cast === null) {
Deprecation::notice(
'5.4.0',
'Passing $cast as null is deprecated. Pass a ValidationResult::CAST_* constant instead.',
Deprecation::SCOPE_GLOBAL
);
$cast = ValidationResult::CAST_TEXT;
}
$this->isValid = false;
return $this->addFieldMessage($fieldName, $message, $messageType, $code, $cast);
} | Record an error against this validation result,
@param string $fieldName The field to link the message to. If omitted; a form-wide message is assumed.
@param string $message The message string.
@param string $messageType The type of message: e.g. "bad", "warning", "good", or "required". Passed as a CSS
class to the form, so other values can be used if desired.
@param string $code A codename for this error. Only one message per codename will be added.
This can be usedful for ensuring no duplicate messages
@param string|bool $cast Cast type; One of the CAST_ constant definitions.
Bool values will be treated as plain text flag.
@return $this | addFieldError | php | silverstripe/silverstripe-framework | src/ORM/ValidationResult.php | https://github.com/silverstripe/silverstripe-framework/blob/master/src/ORM/ValidationResult.php | BSD-3-Clause |
public function addMessage($message, $messageType = ValidationResult::TYPE_ERROR, $code = null, $cast = ValidationResult::CAST_TEXT)
{
if ($code === null) {
Deprecation::notice(
'5.4.0',
'Passing $code as null is deprecated. Pass a blank string instead.',
Deprecation::SCOPE_GLOBAL
);
$code = '';
}
if ($cast === null) {
Deprecation::notice(
'5.4.0',
'Passing $cast as null is deprecated. Pass a ValidationResult::CAST_* constant instead.',
Deprecation::SCOPE_GLOBAL
);
$cast = ValidationResult::CAST_TEXT;
}
return $this->addFieldMessage(null, $message, $messageType, $code, $cast);
} | Add a message to this ValidationResult without necessarily marking it as an error
@param string $message The message string.
@param string $messageType The type of message: e.g. "bad", "warning", "good", or "required". Passed as a CSS
class to the form, so other values can be used if desired.
@param string $code A codename for this error. Only one message per codename will be added.
This can be usedful for ensuring no duplicate messages
@param string|bool $cast Cast type; One of the CAST_ constant definitions.
Bool values will be treated as plain text flag.
@return $this | addMessage | php | silverstripe/silverstripe-framework | src/ORM/ValidationResult.php | https://github.com/silverstripe/silverstripe-framework/blob/master/src/ORM/ValidationResult.php | BSD-3-Clause |
public function addFieldMessage(
$fieldName,
$message,
$messageType = ValidationResult::TYPE_ERROR,
$code = null,
$cast = ValidationResult::CAST_TEXT
) {
if ($code === null) {
Deprecation::notice(
'5.4.0',
'Passing $code as null is deprecated. Pass a blank string instead.',
Deprecation::SCOPE_GLOBAL
);
$code = '';
}
if ($cast === null) {
Deprecation::notice(
'5.4.0',
'Passing $cast as null is deprecated. Pass a ValidationResult::CAST_* constant instead.',
Deprecation::SCOPE_GLOBAL
);
$cast = ValidationResult::CAST_TEXT;
}
if ($code && is_numeric($code)) {
throw new InvalidArgumentException("Don't use a numeric code '$code'. Use a string.");
}
if (is_bool($cast)) {
$cast = $cast ? ValidationResult::CAST_TEXT : ValidationResult::CAST_HTML;
}
$metadata = [
'message' => $message,
'fieldName' => $fieldName,
'messageType' => $messageType,
'messageCast' => $cast,
];
if ($code) {
$this->messages[$code] = $metadata;
} else {
$this->messages[] = $metadata;
}
return $this;
} | Add a message to this ValidationResult without necessarily marking it as an error
@param string $fieldName The field to link the message to. If omitted; a form-wide message is assumed.
@param string $message The message string.
@param string $messageType The type of message: e.g. "bad", "warning", "good", or "required". Passed as a CSS
class to the form, so other values can be used if desired.
@param string $code A codename for this error. Only one message per codename will be added.
This can be usedful for ensuring no duplicate messages
@param string|bool $cast Cast type; One of the CAST_ constant definitions.
Bool values will be treated as plain text flag.
@return $this | addFieldMessage | php | silverstripe/silverstripe-framework | src/ORM/ValidationResult.php | https://github.com/silverstripe/silverstripe-framework/blob/master/src/ORM/ValidationResult.php | BSD-3-Clause |
public function isValid()
{
return $this->isValid;
} | Returns true if the result is valid.
@return boolean | isValid | php | silverstripe/silverstripe-framework | src/ORM/ValidationResult.php | https://github.com/silverstripe/silverstripe-framework/blob/master/src/ORM/ValidationResult.php | BSD-3-Clause |
public function combineAnd(ValidationResult $other)
{
$this->isValid = $this->isValid && $other->isValid();
$this->messages = array_merge($this->messages, $other->getMessages());
return $this;
} | Combine this Validation Result with the ValidationResult given in other.
It will be valid if both this and the other result are valid.
This object will be modified to contain the new validation information.
@param ValidationResult $other the validation result object to combine
@return $this | combineAnd | php | silverstripe/silverstripe-framework | src/ORM/ValidationResult.php | https://github.com/silverstripe/silverstripe-framework/blob/master/src/ORM/ValidationResult.php | BSD-3-Clause |
public function getForeignID()
{
return $this->dataQuery->getQueryParam('Foreign.ID');
} | Any number of foreign keys to apply to this list
@return string|array|null | getForeignID | php | silverstripe/silverstripe-framework | src/ORM/RelationList.php | https://github.com/silverstripe/silverstripe-framework/blob/master/src/ORM/RelationList.php | BSD-3-Clause |
public function __construct(SS_List $list, $request = [])
{
Deprecation::withSuppressedNotice(function () {
Deprecation::notice('5.4.0', 'Will be renamed to SilverStripe\Model\List\PaginatedList', Deprecation::SCOPE_CLASS);
});
if (!is_array($request) && !$request instanceof ArrayAccess) {
throw new Exception('The request must be readable as an array.');
}
$this->setRequest($request);
parent::__construct($list);
} | Constructs a new paginated list instance around a list.
@param TList<T> $list The list to paginate. The getRange method will
be used to get the subset of objects to show.
@param array|ArrayAccess $request Either a map of request parameters or
request object that the pagination offset is read from.
@throws Exception | __construct | php | silverstripe/silverstripe-framework | src/ORM/PaginatedList.php | https://github.com/silverstripe/silverstripe-framework/blob/master/src/ORM/PaginatedList.php | BSD-3-Clause |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.