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
public function getPaginationGetVar() { return $this->getVar; }
Returns the GET var that is used to set the page start. This defaults to "start". If there is more than one paginated list on a page, it is necessary to set a different get var for each using {@link setPaginationGetVar()}. @return string
getPaginationGetVar
php
silverstripe/silverstripe-framework
src/ORM/PaginatedList.php
https://github.com/silverstripe/silverstripe-framework/blob/master/src/ORM/PaginatedList.php
BSD-3-Clause
public function setPaginationGetVar($var) { $this->getVar = $var; return $this; }
Sets the GET var used to set the page start. @param string $var @return $this
setPaginationGetVar
php
silverstripe/silverstripe-framework
src/ORM/PaginatedList.php
https://github.com/silverstripe/silverstripe-framework/blob/master/src/ORM/PaginatedList.php
BSD-3-Clause
public function getPageLength() { return $this->pageLength; }
Returns the number of items displayed per page. This defaults to 10. @return int
getPageLength
php
silverstripe/silverstripe-framework
src/ORM/PaginatedList.php
https://github.com/silverstripe/silverstripe-framework/blob/master/src/ORM/PaginatedList.php
BSD-3-Clause
public function setPageLength($length) { $this->pageLength = (int)$length; return $this; }
Set the number of items displayed per page. Set to zero to disable paging. @param int $length @return $this
setPageLength
php
silverstripe/silverstripe-framework
src/ORM/PaginatedList.php
https://github.com/silverstripe/silverstripe-framework/blob/master/src/ORM/PaginatedList.php
BSD-3-Clause
public function getPageStart() { $request = $this->getRequest(); if ($this->pageStart === null) { if ($request && isset($request[$this->getPaginationGetVar()]) && $request[$this->getPaginationGetVar()] > 0 ) { $this->pageStart = (int)$request[$this->getPaginationGetVar()]; } else { $this->pageStart = 0; } } return $this->pageStart; }
Returns the offset of the item the current page starts at. @return int
getPageStart
php
silverstripe/silverstripe-framework
src/ORM/PaginatedList.php
https://github.com/silverstripe/silverstripe-framework/blob/master/src/ORM/PaginatedList.php
BSD-3-Clause
public function setPageStart($start) { $this->pageStart = (int)$start; return $this; }
Sets the offset of the item that current page starts at. This should be a multiple of the page length. @param int $start @return $this
setPageStart
php
silverstripe/silverstripe-framework
src/ORM/PaginatedList.php
https://github.com/silverstripe/silverstripe-framework/blob/master/src/ORM/PaginatedList.php
BSD-3-Clause
public function getTotalItems() { if ($this->totalItems === null) { $this->totalItems = count($this->list ?? []); } return $this->totalItems; }
Returns the total number of items in the unpaginated list. @return int
getTotalItems
php
silverstripe/silverstripe-framework
src/ORM/PaginatedList.php
https://github.com/silverstripe/silverstripe-framework/blob/master/src/ORM/PaginatedList.php
BSD-3-Clause
public function setTotalItems($items) { $this->totalItems = (int)$items; return $this; }
Sets the total number of items in the list. This is useful when doing custom pagination. @param int $items @return $this
setTotalItems
php
silverstripe/silverstripe-framework
src/ORM/PaginatedList.php
https://github.com/silverstripe/silverstripe-framework/blob/master/src/ORM/PaginatedList.php
BSD-3-Clause
public function setPaginationFromQuery(SQLSelect $query) { if ($limit = $query->getLimit()) { $this->setPageLength($limit['limit']); $this->setPageStart($limit['start']); $this->setTotalItems($query->unlimitedRowCount()); } return $this; }
Sets the page length, page start and total items from a query object's limit, offset and unlimited count. The query MUST have a limit clause. @param SQLSelect $query @return $this
setPaginationFromQuery
php
silverstripe/silverstripe-framework
src/ORM/PaginatedList.php
https://github.com/silverstripe/silverstripe-framework/blob/master/src/ORM/PaginatedList.php
BSD-3-Clause
public function getLimitItems() { return $this->limitItems; }
Returns whether or not the underlying list is limited to the current pagination range when iterating. By default the limit method will be called on the underlying list to extract the subset for the current page. In some situations, if the list is custom generated and already paginated you don't want to additionally limit the list. You can use {@link setLimitItems} to control this. @return bool
getLimitItems
php
silverstripe/silverstripe-framework
src/ORM/PaginatedList.php
https://github.com/silverstripe/silverstripe-framework/blob/master/src/ORM/PaginatedList.php
BSD-3-Clause
public function Pages($max = null) { $result = new ArrayList(); if ($max) { $start = ($this->CurrentPage() - floor($max / 2)) - 1; $end = $this->CurrentPage() + floor($max / 2); if ($start < 0) { $start = 0; $end = $max; } if ($end > $this->TotalPages()) { $end = $this->TotalPages(); $start = max(0, $end - $max); } } else { $start = 0; $end = $this->TotalPages(); } for ($i = $start; $i < $end; $i++) { $result->push(new ArrayData([ 'PageNum' => $i + 1, 'Link' => HTTP::setGetVar( $this->getPaginationGetVar(), $i * $this->getPageLength(), ($this->request instanceof HTTPRequest) ? $this->request->getURL(true) : null ), 'CurrentBool' => $this->CurrentPage() == ($i + 1) ])); } return $result; }
Returns a set of links to all the pages in the list. This is useful for basic pagination. By default it returns links to every page, but if you pass the $max parameter the number of pages will be limited to that number, centered around the current page. @param int $max @return SS_List
Pages
php
silverstripe/silverstripe-framework
src/ORM/PaginatedList.php
https://github.com/silverstripe/silverstripe-framework/blob/master/src/ORM/PaginatedList.php
BSD-3-Clause
public function FirstItem() { return ($start = $this->getPageStart()) ? $start + 1 : 1; }
Returns the number of the first item being displayed on the current page. This is useful for things like "displaying 10-20". @return int
FirstItem
php
silverstripe/silverstripe-framework
src/ORM/PaginatedList.php
https://github.com/silverstripe/silverstripe-framework/blob/master/src/ORM/PaginatedList.php
BSD-3-Clause
public function FirstLink() { return HTTP::setGetVar( $this->getPaginationGetVar(), 0, ($this->request instanceof HTTPRequest) ? $this->request->getURL(true) : null ); }
Returns a link to the first page. @return string
FirstLink
php
silverstripe/silverstripe-framework
src/ORM/PaginatedList.php
https://github.com/silverstripe/silverstripe-framework/blob/master/src/ORM/PaginatedList.php
BSD-3-Clause
public function LastLink() { return HTTP::setGetVar( $this->getPaginationGetVar(), ($this->TotalPages() - 1) * $this->getPageLength(), ($this->request instanceof HTTPRequest) ? $this->request->getURL(true) : null ); }
Returns a link to the last page. @return string
LastLink
php
silverstripe/silverstripe-framework
src/ORM/PaginatedList.php
https://github.com/silverstripe/silverstripe-framework/blob/master/src/ORM/PaginatedList.php
BSD-3-Clause
public function NextLink() { if ($this->NotLastPage()) { return HTTP::setGetVar( $this->getPaginationGetVar(), $this->getPageStart() + $this->getPageLength(), ($this->request instanceof HTTPRequest) ? $this->request->getURL(true) : null ); } }
Returns a link to the next page, if there is another page after the current one. @return string
NextLink
php
silverstripe/silverstripe-framework
src/ORM/PaginatedList.php
https://github.com/silverstripe/silverstripe-framework/blob/master/src/ORM/PaginatedList.php
BSD-3-Clause
public function PrevLink() { if ($this->NotFirstPage()) { return HTTP::setGetVar( $this->getPaginationGetVar(), $this->getPageStart() - $this->getPageLength(), ($this->request instanceof HTTPRequest) ? $this->request->getURL(true) : null ); } }
Returns a link to the previous page, if the first page is not currently active. @return string
PrevLink
php
silverstripe/silverstripe-framework
src/ORM/PaginatedList.php
https://github.com/silverstripe/silverstripe-framework/blob/master/src/ORM/PaginatedList.php
BSD-3-Clause
public function TotalItems() { Deprecation::notice('5.4.0', 'Use getTotalItems() instead.'); return $this->getTotalItems(); }
Returns the total number of items in the list @depreated 5.4.0 Use getTotalItems() instead.
TotalItems
php
silverstripe/silverstripe-framework
src/ORM/PaginatedList.php
https://github.com/silverstripe/silverstripe-framework/blob/master/src/ORM/PaginatedList.php
BSD-3-Clause
public function setRequest($request) { $this->request = $request; }
Set the request object for this list @param HTTPRequest|ArrayAccess $request
setRequest
php
silverstripe/silverstripe-framework
src/ORM/PaginatedList.php
https://github.com/silverstripe/silverstripe-framework/blob/master/src/ORM/PaginatedList.php
BSD-3-Clause
public function groupedDataClasses() { // Get all root data objects $allClasses = get_declared_classes(); $rootClasses = []; foreach ($allClasses as $class) { if (get_parent_class($class ?? '') == DataObject::class) { $rootClasses[$class] = []; } } // Assign every other data object one of those foreach ($allClasses as $class) { if (!isset($rootClasses[$class]) && is_subclass_of($class, DataObject::class)) { foreach ($rootClasses as $rootClass => $dummy) { if (is_subclass_of($class, $rootClass ?? '')) { $rootClasses[$rootClass][] = $class; break; } } } } return $rootClasses; }
Get the data classes, grouped by their root class @return array Array of data classes, grouped by their root class
groupedDataClasses
php
silverstripe/silverstripe-framework
src/ORM/DatabaseAdmin.php
https://github.com/silverstripe/silverstripe-framework/blob/master/src/ORM/DatabaseAdmin.php
BSD-3-Clause
public function index() { return $this->build(); }
When we're called as /dev/build, that's actually the index. Do the same as /dev/build/build.
index
php
silverstripe/silverstripe-framework
src/ORM/DatabaseAdmin.php
https://github.com/silverstripe/silverstripe-framework/blob/master/src/ORM/DatabaseAdmin.php
BSD-3-Clause
public function build() { // The default time limit of 30 seconds is normally not enough Environment::increaseTimeLimitTo(600); // If this code is being run outside of a dev/build or without a ?flush query string param, // the class manifest hasn't been flushed, so do it here $request = $this->getRequest(); if (!array_key_exists('flush', $request->getVars() ?? []) && strpos($request->getURL() ?? '', 'dev/build') !== 0) { ClassLoader::inst()->getManifest()->regenerate(false); } $url = $this->getReturnURL(); if ($url) { echo "<p>Setting up the database; you will be returned to your site shortly....</p>"; $this->doBuild(true); echo "<p>Done!</p>"; $this->redirect($url); } else { $quiet = $this->request->requestVar('quiet') !== null; $fromInstaller = $this->request->requestVar('from_installer') !== null; $populate = $this->request->requestVar('dont_populate') === null; $this->doBuild($quiet || $fromInstaller, $populate); } }
Updates the database schema, creating tables & fields as necessary.
build
php
silverstripe/silverstripe-framework
src/ORM/DatabaseAdmin.php
https://github.com/silverstripe/silverstripe-framework/blob/master/src/ORM/DatabaseAdmin.php
BSD-3-Clause
protected function getReturnURL() { $url = $this->request->getVar('returnURL'); // Check that this url is a site url if (empty($url) || !Director::is_site_url($url)) { return null; } // Convert to absolute URL return Director::absoluteURL((string) $url, true); }
Gets the url to return to after build @return string|null
getReturnURL
php
silverstripe/silverstripe-framework
src/ORM/DatabaseAdmin.php
https://github.com/silverstripe/silverstripe-framework/blob/master/src/ORM/DatabaseAdmin.php
BSD-3-Clause
public static function lastBuilt() { Deprecation::withSuppressedNotice(function () { Deprecation::notice( '5.4.0', 'Will be replaced with SilverStripe\Dev\Command\DbBuild::lastBuilt()' ); }); $file = TEMP_PATH . DIRECTORY_SEPARATOR . 'database-last-generated-' . str_replace(['\\', '/', ':'], '.', Director::baseFolder() ?? ''); if (file_exists($file ?? '')) { return filemtime($file ?? ''); } return null; }
Returns the timestamp of the time that the database was last built @return string Returns the timestamp of the time that the database was last built @deprecated 5.4.0 Will be replaced with SilverStripe\Dev\Command\DbBuild::lastBuilt()
lastBuilt
php
silverstripe/silverstripe-framework
src/ORM/DatabaseAdmin.php
https://github.com/silverstripe/silverstripe-framework/blob/master/src/ORM/DatabaseAdmin.php
BSD-3-Clause
protected function getClassTables($dataClass) { $schema = DataObject::getSchema(); $table = $schema->tableName($dataClass); // Base table yield $table; // Remap versioned table class name values as well /** @var Versioned|DataObject $dataClass */ $dataClass = DataObject::singleton($dataClass); if ($dataClass->hasExtension(Versioned::class)) { if ($dataClass->hasStages()) { yield "{$table}_Live"; } yield "{$table}_Versions"; } }
Get tables to update for this class @param string $dataClass @return Generator|string[]
getClassTables
php
silverstripe/silverstripe-framework
src/ORM/DatabaseAdmin.php
https://github.com/silverstripe/silverstripe-framework/blob/master/src/ORM/DatabaseAdmin.php
BSD-3-Clause
public static function get_conn($name = 'default') { if (isset(DB::$connections[$name])) { return DB::$connections[$name]; } // lazy connect $config = static::getConfig($name); if ($config) { return static::connect($config, $name); } return null; }
Get the global database connection. @param string $name An optional name given to a connection in the DB::setConn() call. If omitted, the default connection is returned. @return Database
get_conn
php
silverstripe/silverstripe-framework
src/ORM/DB.php
https://github.com/silverstripe/silverstripe-framework/blob/master/src/ORM/DB.php
BSD-3-Clause
public static function get_schema($name = 'default') { $connection = DB::get_conn($name); if ($connection) { return $connection->getSchemaManager(); } return null; }
Retrieves the schema manager for the current database @param string $name An optional name given to a connection in the DB::setConn() call. If omitted, the default connection is returned. @return DBSchemaManager
get_schema
php
silverstripe/silverstripe-framework
src/ORM/DB.php
https://github.com/silverstripe/silverstripe-framework/blob/master/src/ORM/DB.php
BSD-3-Clause
public static function build_sql(SQLExpression $expression, &$parameters, $name = 'default') { $connection = DB::get_conn($name); if ($connection) { return $connection->getQueryBuilder()->buildSQL($expression, $parameters); } else { $parameters = []; return null; } }
Builds a sql query with the specified connection @param SQLExpression $expression The expression object to build from @param array $parameters Out parameter for the resulting query parameters @param string $name An optional name given to a connection in the DB::setConn() call. If omitted, the default connection is returned. @return string The resulting SQL as a string
build_sql
php
silverstripe/silverstripe-framework
src/ORM/DB.php
https://github.com/silverstripe/silverstripe-framework/blob/master/src/ORM/DB.php
BSD-3-Clause
public static function get_connector($name = 'default') { $connection = DB::get_conn($name); if ($connection) { return $connection->getConnector(); } return null; }
Retrieves the connector object for the current database @param string $name An optional name given to a connection in the DB::setConn() call. If omitted, the default connection is returned. @return DBConnector
get_connector
php
silverstripe/silverstripe-framework
src/ORM/DB.php
https://github.com/silverstripe/silverstripe-framework/blob/master/src/ORM/DB.php
BSD-3-Clause
public static function set_alternative_database_name($name = null) { // Ignore if disabled if (!Config::inst()->get(static::class, 'alternative_database_enabled')) { return; } // Skip if CLI if (Director::is_cli()) { return; } // Validate name if ($name && !DB::valid_alternative_database_name($name)) { throw new InvalidArgumentException(sprintf( 'Invalid alternative database name: "%s"', $name )); } // Set against session if (!Injector::inst()->has(HTTPRequest::class)) { return; } $request = Injector::inst()->get(HTTPRequest::class); if ($name) { $request->getSession()->set(DB::ALT_DB_KEY, $name); } else { $request->getSession()->clear(DB::ALT_DB_KEY); } }
Set an alternative database in a browser cookie, with the cookie lifetime set to the browser session. This is useful for integration testing on temporary databases. There is a strict naming convention for temporary databases to avoid abuse: <prefix> (default: 'ss_') + tmpdb + <7 digits> As an additional security measure, temporary databases will be ignored in "live" mode. Note that the database will be set on the next request. Set it to null to revert to the main database. @param string $name
set_alternative_database_name
php
silverstripe/silverstripe-framework
src/ORM/DB.php
https://github.com/silverstripe/silverstripe-framework/blob/master/src/ORM/DB.php
BSD-3-Clause
public static function get_alternative_database_name() { // Ignore if disabled if (!Config::inst()->get(static::class, 'alternative_database_enabled')) { return false; } // Skip if CLI if (Director::is_cli()) { return false; } // Skip if there's no request object yet if (!Injector::inst()->has(HTTPRequest::class)) { return null; } $request = Injector::inst()->get(HTTPRequest::class); // Skip if the session hasn't been started if (!$request->getSession()->isStarted()) { return null; } $name = $request->getSession()->get(DB::ALT_DB_KEY); if (DB::valid_alternative_database_name($name)) { return $name; } return false; }
Get the name of the database in use @return string|false Name of temp database, or false if not set
get_alternative_database_name
php
silverstripe/silverstripe-framework
src/ORM/DB.php
https://github.com/silverstripe/silverstripe-framework/blob/master/src/ORM/DB.php
BSD-3-Clause
public static function valid_alternative_database_name($name) { if (Director::isLive() || empty($name)) { return false; } $prefix = Environment::getEnv('SS_DATABASE_PREFIX') ?: 'ss_'; $pattern = strtolower(sprintf('/^%stmpdb\d{7}$/', $prefix)); return (bool)preg_match($pattern ?? '', $name ?? ''); }
Determines if the name is valid, as a security measure against setting arbitrary databases. @param string $name @return bool
valid_alternative_database_name
php
silverstripe/silverstripe-framework
src/ORM/DB.php
https://github.com/silverstripe/silverstripe-framework/blob/master/src/ORM/DB.php
BSD-3-Clause
public static function connect($databaseConfig, $label = 'default') { // This is used by the "testsession" module to test up a test session using an alternative name if ($name = DB::get_alternative_database_name()) { $databaseConfig['database'] = $name; } if (!isset($databaseConfig['type']) || empty($databaseConfig['type'])) { throw new InvalidArgumentException("DB::connect: Not passed a valid database config"); } DB::$connection_attempted = true; $dbClass = $databaseConfig['type']; // Using Injector->create allows us to use registered configurations // which may or may not map to explicit objects $conn = Injector::inst()->create($dbClass); DB::set_conn($conn, $label); $conn->connect($databaseConfig); return $conn; }
Specify connection to a database Given the database configuration, this method will create the correct subclass of {@link SS_Database}. @param array $databaseConfig A map of options. The 'type' is the name of the subclass of SS_Database to use. For the rest of the options, see the specific class. @param string $label identifier for the connection @return Database
connect
php
silverstripe/silverstripe-framework
src/ORM/DB.php
https://github.com/silverstripe/silverstripe-framework/blob/master/src/ORM/DB.php
BSD-3-Clause
public static function setConfig($databaseConfig, $name = 'default') { static::$configs[$name] = $databaseConfig; }
Set config for a lazy-connected database @param array $databaseConfig @param string $name
setConfig
php
silverstripe/silverstripe-framework
src/ORM/DB.php
https://github.com/silverstripe/silverstripe-framework/blob/master/src/ORM/DB.php
BSD-3-Clause
public static function getConfig($name = 'default') { if (isset(static::$configs[$name])) { return static::$configs[$name]; } }
Get the named connection config @param string $name @return mixed
getConfig
php
silverstripe/silverstripe-framework
src/ORM/DB.php
https://github.com/silverstripe/silverstripe-framework/blob/master/src/ORM/DB.php
BSD-3-Clause
public static function connection_attempted() { return DB::$connection_attempted; }
Returns true if a database connection has been attempted. In particular, it lets the caller know if we're still so early in the execution pipeline that we haven't even tried to connect to the database yet.
connection_attempted
php
silverstripe/silverstripe-framework
src/ORM/DB.php
https://github.com/silverstripe/silverstripe-framework/blob/master/src/ORM/DB.php
BSD-3-Clause
public static function prepared_query($sql, $parameters, $errorLevel = E_USER_ERROR) { DB::$lastQuery = $sql; return DB::get_conn()->preparedQuery($sql, $parameters, $errorLevel); }
Execute the given SQL parameterised query with the specified arguments @param string $sql The SQL query to execute. The ? character will denote parameters. @param array $parameters An ordered list of arguments. @param int $errorLevel The level of error reporting to enable for the query @return Query
prepared_query
php
silverstripe/silverstripe-framework
src/ORM/DB.php
https://github.com/silverstripe/silverstripe-framework/blob/master/src/ORM/DB.php
BSD-3-Clause
public static function manipulate($manipulation) { DB::$lastQuery = $manipulation; DB::get_conn()->manipulate($manipulation); }
Execute a complex manipulation on the database. A manipulation is an array of insert / or update sequences. The keys of the array are table names, and the values are map containing 'command' and 'fields'. Command should be 'insert' or 'update', and fields should be a map of field names to field values, including quotes. The field value can also be a SQL function or similar. Example: <code> array( // Command: insert "table name" => array( "command" => "insert", "fields" => array( "ClassName" => "'MyClass'", // if you're setting a literal, you need to escape and provide quotes "Created" => "now()", // alternatively, you can call DB functions "ID" => 234, ), "id" => 234 // an alternative to providing ID in the fields list ), // Command: update "other table" => array( "command" => "update", "fields" => array( "ClassName" => "'MyClass'", "LastEdited" => "now()", ), "where" => "ID = 234", "id" => 234 // an alternative to providing a where clause ), ) </code> You'll note that only one command on a given table can be called. That's a limitation of the system that's due to it being written for {@link DataObject::write()}, which needs to do a single write on a number of different tables. @param array $manipulation
manipulate
php
silverstripe/silverstripe-framework
src/ORM/DB.php
https://github.com/silverstripe/silverstripe-framework/blob/master/src/ORM/DB.php
BSD-3-Clause
public static function get_generated_id($table) { return DB::get_conn()->getGeneratedID($table); }
Get the autogenerated ID from the previous INSERT query. @param string $table @return int
get_generated_id
php
silverstripe/silverstripe-framework
src/ORM/DB.php
https://github.com/silverstripe/silverstripe-framework/blob/master/src/ORM/DB.php
BSD-3-Clause
public static function is_active() { return ($conn = DB::get_conn()) && $conn->isActive(); }
Check if the connection to the database is active. @return boolean
is_active
php
silverstripe/silverstripe-framework
src/ORM/DB.php
https://github.com/silverstripe/silverstripe-framework/blob/master/src/ORM/DB.php
BSD-3-Clause
public static function create_database($database) { return DB::get_conn()->selectDatabase($database, true); }
Create the database and connect to it. This can be called if the initial database connection is not successful because the database does not exist. @param string $database Name of database to create @return boolean Returns true if successful
create_database
php
silverstripe/silverstripe-framework
src/ORM/DB.php
https://github.com/silverstripe/silverstripe-framework/blob/master/src/ORM/DB.php
BSD-3-Clause
public static function create_table( $table, $fields = null, $indexes = null, $options = null, $advancedOptions = null ) { return DB::get_schema()->createTable($table, $fields, $indexes, $options, $advancedOptions); }
Create a new table. @param string $table The name of the table @param array $fields A map of field names to field types @param array $indexes A map of indexes @param array $options An map of additional options. The available keys are as follows: - 'MSSQLDatabase'/'MySQLDatabase'/'PostgreSQLDatabase' - database-specific options such as "engine" for MySQL. - 'temporary' - If true, then a temporary table will be created @param array $advancedOptions Advanced creation options @return string The table name generated. This may be different from the table name, for example with temporary tables.
create_table
php
silverstripe/silverstripe-framework
src/ORM/DB.php
https://github.com/silverstripe/silverstripe-framework/blob/master/src/ORM/DB.php
BSD-3-Clause
public static function create_field($table, $field, $spec) { return DB::get_schema()->createField($table, $field, $spec); }
Create a new field on a table. @param string $table Name of the table. @param string $field Name of the field to add. @param string $spec The field specification, eg 'INTEGER NOT NULL'
create_field
php
silverstripe/silverstripe-framework
src/ORM/DB.php
https://github.com/silverstripe/silverstripe-framework/blob/master/src/ORM/DB.php
BSD-3-Clause
public static function require_table( $table, $fieldSchema = null, $indexSchema = null, $hasAutoIncPK = true, $options = null, $extensions = null ) { DB::get_schema()->requireTable($table, $fieldSchema, $indexSchema, $hasAutoIncPK, $options, $extensions); }
Generate the following table in the database, modifying whatever already exists as necessary. @param string $table The name of the table @param string $fieldSchema A list of the fields to create, in the same form as DataObject::$db @param string $indexSchema A list of indexes to create. The keys of the array are the names of the index. The values of the array can be one of: - true: Create a single column index on the field named the same as the index. - array('fields' => array('A','B','C'), 'type' => 'index/unique/fulltext'): This gives you full control over the index. @param boolean $hasAutoIncPK A flag indicating that the primary key on this table is an autoincrement type @param string $options SQL statement to append to the CREATE TABLE call. @param array $extensions List of extensions
require_table
php
silverstripe/silverstripe-framework
src/ORM/DB.php
https://github.com/silverstripe/silverstripe-framework/blob/master/src/ORM/DB.php
BSD-3-Clause
public static function require_field($table, $field, $spec) { DB::get_schema()->requireField($table, $field, $spec); }
Generate the given field on the table, modifying whatever already exists as necessary. @param string $table The table name. @param string $field The field name. @param string $spec The field specification.
require_field
php
silverstripe/silverstripe-framework
src/ORM/DB.php
https://github.com/silverstripe/silverstripe-framework/blob/master/src/ORM/DB.php
BSD-3-Clause
public static function require_index($table, $index, $spec) { DB::get_schema()->requireIndex($table, $index, $spec); }
Generate the given index in the database, modifying whatever already exists as necessary. @param string $table The table name. @param string $index The index name. @param string|boolean $spec The specification of the index. See requireTable() for more information.
require_index
php
silverstripe/silverstripe-framework
src/ORM/DB.php
https://github.com/silverstripe/silverstripe-framework/blob/master/src/ORM/DB.php
BSD-3-Clause
public static function dont_require_table($table) { DB::get_schema()->dontRequireTable($table); }
If the given table exists, move it out of the way by renaming it to _obsolete_(tablename). @param string $table The table name.
dont_require_table
php
silverstripe/silverstripe-framework
src/ORM/DB.php
https://github.com/silverstripe/silverstripe-framework/blob/master/src/ORM/DB.php
BSD-3-Clause
public static function check_and_repair_table($table) { return DB::get_schema()->checkAndRepairTable($table); }
Checks a table's integrity and repairs it if necessary. @param string $table The name of the table. @return boolean Return true if the table has integrity after the method is complete.
check_and_repair_table
php
silverstripe/silverstripe-framework
src/ORM/DB.php
https://github.com/silverstripe/silverstripe-framework/blob/master/src/ORM/DB.php
BSD-3-Clause
public static function affected_rows() { return DB::get_conn()->affectedRows(); }
Return the number of rows affected by the previous operation. @return integer The number of affected rows
affected_rows
php
silverstripe/silverstripe-framework
src/ORM/DB.php
https://github.com/silverstripe/silverstripe-framework/blob/master/src/ORM/DB.php
BSD-3-Clause
public static function table_list() { return DB::get_schema()->tableList(); }
Returns a list of all tables in the database. The table names will be in lower case. @return array The list of tables
table_list
php
silverstripe/silverstripe-framework
src/ORM/DB.php
https://github.com/silverstripe/silverstripe-framework/blob/master/src/ORM/DB.php
BSD-3-Clause
public static function field_list($table) { return DB::get_schema()->fieldList($table); }
Get a list of all the fields for the given table. Returns a map of field name => field spec. @param string $table The table name. @return array The list of fields
field_list
php
silverstripe/silverstripe-framework
src/ORM/DB.php
https://github.com/silverstripe/silverstripe-framework/blob/master/src/ORM/DB.php
BSD-3-Clause
public static function quiet($quiet = true) { DB::get_schema()->quiet($quiet); }
Enable suppression of database messages. @param bool $quiet
quiet
php
silverstripe/silverstripe-framework
src/ORM/DB.php
https://github.com/silverstripe/silverstripe-framework/blob/master/src/ORM/DB.php
BSD-3-Clause
public static function alteration_message($message, $type = "") { DB::get_schema()->alterationMessage($message, $type); }
Show a message about database alteration @param string $message to display @param string $type one of [created|changed|repaired|obsolete|deleted|error]
alteration_message
php
silverstripe/silverstripe-framework
src/ORM/DB.php
https://github.com/silverstripe/silverstripe-framework/blob/master/src/ORM/DB.php
BSD-3-Clause
public function __construct(string $joinClass, string $localKey, string $foreignKey, string $foreignClass, string $parentClass) { $this->setJoinClass($joinClass); $this->setLocalKey($localKey); $this->setForeignKey($foreignKey); if ($foreignClass) { $this->setForeignClass($foreignClass); } if ($parentClass) { $this->setParentClass($parentClass); } }
Build query manipulator for a given join table. Additional parameters (foreign key, etc) will be inferred at evaluation from query parameters set via the ManyManyThroughList @param class-string<TJoin> $joinClass @param string $foreignClass @param string $parentClass
__construct
php
silverstripe/silverstripe-framework
src/ORM/ManyManyThroughQueryManipulator.php
https://github.com/silverstripe/silverstripe-framework/blob/master/src/ORM/ManyManyThroughQueryManipulator.php
BSD-3-Clause
public function getForeignIDKey() { $key = $this->getForeignKey(); if ($this->getForeignClass() === DataObject::class) { return $key . 'ID'; } return $key; }
Gets ID key name for foreign key component @return string
getForeignIDKey
php
silverstripe/silverstripe-framework
src/ORM/ManyManyThroughQueryManipulator.php
https://github.com/silverstripe/silverstripe-framework/blob/master/src/ORM/ManyManyThroughQueryManipulator.php
BSD-3-Clause
public function getForeignClassKey() { if ($this->getForeignClass() === DataObject::class) { return $this->getForeignKey() . 'Class'; } return null; }
Gets Class key name for foreign key component (or null if none) @return string|null
getForeignClassKey
php
silverstripe/silverstripe-framework
src/ORM/ManyManyThroughQueryManipulator.php
https://github.com/silverstripe/silverstripe-framework/blob/master/src/ORM/ManyManyThroughQueryManipulator.php
BSD-3-Clause
public function getParentRelationship(DataQuery $query) { // Create has_many if ($this->getForeignClass() === DataObject::class) { /** @internal Polymorphic many_many is experimental */ $list = PolymorphicHasManyList::create( $this->getJoinClass(), $this->getForeignKey(), $this->getParentClass() ); } else { $list = HasManyList::create($this->getJoinClass(), $this->getForeignKey()); } $list = $list->setDataQueryParam($this->extractInheritableQueryParameters($query)); // Limit to given foreign key $foreignID = $query->getQueryParam('Foreign.ID'); if ($foreignID) { $list = $list->forForeignID($foreignID); } return $list; }
Get has_many relationship between parent and join table (for a given DataQuery) @param DataQuery $query @return HasManyList<TJoin>
getParentRelationship
php
silverstripe/silverstripe-framework
src/ORM/ManyManyThroughQueryManipulator.php
https://github.com/silverstripe/silverstripe-framework/blob/master/src/ORM/ManyManyThroughQueryManipulator.php
BSD-3-Clause
public function extractInheritableQueryParameters(DataQuery $query) { $params = $query->getQueryParams(); // Remove `Foreign.` query parameters for created objects, // as this would interfere with relations on those objects. foreach (array_keys($params ?? []) as $key) { if (stripos($key ?? '', 'Foreign.') === 0) { unset($params[$key]); } } // Get inheritable parameters from an instance of the base query dataclass $inst = Injector::inst()->create($query->dataClass()); $inst->setSourceQueryParams($params); return $inst->getInheritableQueryParams(); }
Calculate the query parameters that should be inherited from the base many_many to the nested has_many list. @param DataQuery $query @return mixed
extractInheritableQueryParameters
php
silverstripe/silverstripe-framework
src/ORM/ManyManyThroughQueryManipulator.php
https://github.com/silverstripe/silverstripe-framework/blob/master/src/ORM/ManyManyThroughQueryManipulator.php
BSD-3-Clause
public function getJoinAlias() { return DataObject::getSchema()->tableName($this->getJoinClass()); }
Get name of join table alias for use in queries. @return string
getJoinAlias
php
silverstripe/silverstripe-framework
src/ORM/ManyManyThroughQueryManipulator.php
https://github.com/silverstripe/silverstripe-framework/blob/master/src/ORM/ManyManyThroughQueryManipulator.php
BSD-3-Clause
public function afterGetFinalisedQuery(DataQuery $dataQuery, $queriedColumns, SQLSelect $sqlQuery) { // Inject final replacement after manipulation has been performed on the base dataquery $joinTableSQL = $dataQuery->getQueryParam('Foreign.JoinTableSQL'); if ($joinTableSQL) { $sqlQuery->replaceText('SELECT $$_SUBQUERY_$$', $joinTableSQL); $dataQuery->setQueryParam('Foreign.JoinTableSQL', null); } }
Invoked after getFinalisedQuery() @param DataQuery $dataQuery @param array $queriedColumns @param SQLSelect $sqlQuery
afterGetFinalisedQuery
php
silverstripe/silverstripe-framework
src/ORM/ManyManyThroughQueryManipulator.php
https://github.com/silverstripe/silverstripe-framework/blob/master/src/ORM/ManyManyThroughQueryManipulator.php
BSD-3-Clause
public function add($item) { throw new BadMethodCallException('Cannot add a DataObject record to EagerLoadedList. Use addRow() to add database rows.'); }
Not implemented - use addRow instead.
add
php
silverstripe/silverstripe-framework
src/ORM/EagerLoadedList.php
https://github.com/silverstripe/silverstripe-framework/blob/master/src/ORM/EagerLoadedList.php
BSD-3-Clause
public function dataClass() { if ($this->dataClass) { return $this->dataClass; } if (count($this->items ?? []) > 0) { return get_class($this->items[0]); } return null; }
Return the class of items in this list, by looking at the first item inside it. @return class-string<T>|null
dataClass
php
silverstripe/silverstripe-framework
src/ORM/ArrayList.php
https://github.com/silverstripe/silverstripe-framework/blob/master/src/ORM/ArrayList.php
BSD-3-Clause
public function setDataClass($class) { $this->dataClass = $class; return $this; }
Hint this list to a specific type @param class-string<T> $class @return $this
setDataClass
php
silverstripe/silverstripe-framework
src/ORM/ArrayList.php
https://github.com/silverstripe/silverstripe-framework/blob/master/src/ORM/ArrayList.php
BSD-3-Clause
public function exists() { return !empty($this->items); }
Returns true if this list has items @return bool
exists
php
silverstripe/silverstripe-framework
src/ORM/ArrayList.php
https://github.com/silverstripe/silverstripe-framework/blob/master/src/ORM/ArrayList.php
BSD-3-Clause
public function toNestedArray() { $result = []; foreach ($this->items as $item) { if (is_object($item)) { if (method_exists($item, 'toMap')) { $result[] = $item->toMap(); } else { $result[] = (array) $item; } } else { $result[] = $item; } } return $result; }
Return this list as an array and every object it as an sub array as well
toNestedArray
php
silverstripe/silverstripe-framework
src/ORM/ArrayList.php
https://github.com/silverstripe/silverstripe-framework/blob/master/src/ORM/ArrayList.php
BSD-3-Clause
public function remove($item) { $renumberKeys = false; foreach ($this->items as $key => $value) { if ($item === $value) { $renumberKeys = true; unset($this->items[$key]); } } if ($renumberKeys) { $this->items = array_values($this->items ?? []); } }
Remove this item from this list @param mixed $item
remove
php
silverstripe/silverstripe-framework
src/ORM/ArrayList.php
https://github.com/silverstripe/silverstripe-framework/blob/master/src/ORM/ArrayList.php
BSD-3-Clause
public function replace($item, $with) { foreach ($this->items as $key => $candidate) { if ($candidate === $item) { $this->items[$key] = $with; return; } } }
Replaces an item in this list with another item. @param array|object $item @param array|object $with @return void
replace
php
silverstripe/silverstripe-framework
src/ORM/ArrayList.php
https://github.com/silverstripe/silverstripe-framework/blob/master/src/ORM/ArrayList.php
BSD-3-Clause
public function push($item) { $this->items[] = $item; }
Pushes an item onto the end of this list. @param array|object $item
push
php
silverstripe/silverstripe-framework
src/ORM/ArrayList.php
https://github.com/silverstripe/silverstripe-framework/blob/master/src/ORM/ArrayList.php
BSD-3-Clause
public function unshift($item) { array_unshift($this->items, $item); }
Add an item onto the beginning of the list. @param array|object $item
unshift
php
silverstripe/silverstripe-framework
src/ORM/ArrayList.php
https://github.com/silverstripe/silverstripe-framework/blob/master/src/ORM/ArrayList.php
BSD-3-Clause
public function columnUnique($colName = 'ID') { return array_unique($this->column($colName) ?? []); }
Returns a unique array of a single field value for all the items in the list @param string $colName @return array
columnUnique
php
silverstripe/silverstripe-framework
src/ORM/ArrayList.php
https://github.com/silverstripe/silverstripe-framework/blob/master/src/ORM/ArrayList.php
BSD-3-Clause
public function canSortBy($by) { return true; }
You can always sort a ArrayList @param string $by @return bool
canSortBy
php
silverstripe/silverstripe-framework
src/ORM/ArrayList.php
https://github.com/silverstripe/silverstripe-framework/blob/master/src/ORM/ArrayList.php
BSD-3-Clause
protected function parseSortColumn($column, $direction = null) { // Substitute the direction for the column if column is a numeric index if ($direction && (empty($column) || is_numeric($column))) { $column = $direction; $direction = null; } // Parse column specification, considering possible ansi sql quoting // Note that table prefix is allowed, but discarded if (preg_match('/^("?(?<table>[^"\s]+)"?\\.)?"?(?<column>[^"\s]+)"?(\s+(?<direction>((asc)|(desc))(ending)?))?$/i', $column ?? '', $match)) { $column = $match['column']; if (empty($direction) && !empty($match['direction'])) { $direction = $match['direction']; } } else { throw new InvalidArgumentException("Invalid sort() column"); } // Parse sort direction specification if (empty($direction) || preg_match('/^asc(ending)?$/i', $direction ?? '')) { $direction = SORT_ASC; } elseif (preg_match('/^desc(ending)?$/i', $direction ?? '')) { $direction = SORT_DESC; } else { throw new InvalidArgumentException("Invalid sort() direction"); } return [$column, $direction]; }
Parses a specified column into a sort field and direction @param string $column String to parse containing the column name @param mixed $direction Optional Additional argument which may contain the direction @return array Sort specification in the form array("Column", SORT_ASC).
parseSortColumn
php
silverstripe/silverstripe-framework
src/ORM/ArrayList.php
https://github.com/silverstripe/silverstripe-framework/blob/master/src/ORM/ArrayList.php
BSD-3-Clause
public function shuffle() { shuffle($this->items); return $this; }
Shuffle the items in this array list @return $this
shuffle
php
silverstripe/silverstripe-framework
src/ORM/ArrayList.php
https://github.com/silverstripe/silverstripe-framework/blob/master/src/ORM/ArrayList.php
BSD-3-Clause
public function canFilterBy($by) { if (empty($this->items)) { return false; } $firstRecord = $this->first(); if (is_array($firstRecord)) { return array_key_exists($by, $firstRecord); } if ($firstRecord instanceof ViewableData) { return $firstRecord->hasField($by); } return property_exists($firstRecord, $by ?? ''); }
Returns true if the given column can be used to filter the records. It works by checking the fields available in the first record of the list. @param string $by @return bool
canFilterBy
php
silverstripe/silverstripe-framework
src/ORM/ArrayList.php
https://github.com/silverstripe/silverstripe-framework/blob/master/src/ORM/ArrayList.php
BSD-3-Clause
public function find($key, $value) { return $this->filter($key, $value)->first(); }
Find the first item of this list where the given key = value @param string $key @param mixed $value @return T|null
find
php
silverstripe/silverstripe-framework
src/ORM/ArrayList.php
https://github.com/silverstripe/silverstripe-framework/blob/master/src/ORM/ArrayList.php
BSD-3-Clause
protected function normaliseFilterArgs($column, $value = null) { $args = func_get_args(); if (count($args ?? []) > 2) { throw new InvalidArgumentException('filter takes one array or two arguments'); } if (count($args ?? []) === 1 && !is_array($args[0])) { throw new InvalidArgumentException('filter takes one array or two arguments'); } $keepUs = []; if (count($args ?? []) === 2) { $keepUs[$args[0]] = $args[1]; } if (count($args ?? []) === 1 && is_array($args[0])) { foreach ($args[0] as $key => $val) { $keepUs[$key] = $val; } } return $keepUs; }
Take the "standard" arguments that the filter/exclude functions take and return a single array with 'colum' => 'value' @param $column array|string The column name to filter OR an assosicative array of column => value @param $value array|string|null The values to filter the $column against @return array The normalised keyed array
normaliseFilterArgs
php
silverstripe/silverstripe-framework
src/ORM/ArrayList.php
https://github.com/silverstripe/silverstripe-framework/blob/master/src/ORM/ArrayList.php
BSD-3-Clause
public function byIDs($ids) { $ids = array_map('intval', $ids ?? []); // sanitize return $this->filter('ID', $ids); }
Filter this list to only contain the given Primary IDs @param array $ids Array of integers, will be automatically cast/escaped. @return static<T>
byIDs
php
silverstripe/silverstripe-framework
src/ORM/ArrayList.php
https://github.com/silverstripe/silverstripe-framework/blob/master/src/ORM/ArrayList.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}; } if (array_key_exists($key, $item ?? [])) { return $item[$key]; } return null; }
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/ArrayList.php
https://github.com/silverstripe/silverstripe-framework/blob/master/src/ORM/ArrayList.php
BSD-3-Clause
public function filter() { return $this->list->filter(...func_get_args()); }
Filter the list to include items with these characteristics @example $list->filter('Name', 'bob'); // only bob in list @example $list->filter('Name', array('aziz', 'bob'); // aziz and bob in list @example $list->filter(array('Name'=>'bob, 'Age'=>21)); // bob or someone with Age 21 @example $list->filter(array('Name'=>'bob, 'Age'=>array(21, 43))); // bob or anyone with Age 21 or 43 @return TList<T>
filter
php
silverstripe/silverstripe-framework
src/ORM/ListDecorator.php
https://github.com/silverstripe/silverstripe-framework/blob/master/src/ORM/ListDecorator.php
BSD-3-Clause
public function filterByCallback($callback) { if (!is_callable($callback)) { throw new LogicException(sprintf( "SS_Filterable::filterByCallback() passed callback must be callable, '%s' given", gettype($callback) )); } $output = ArrayList::create(); foreach ($this->list as $item) { if ($callback($item, $this->list)) { $output->push($item); } } return $output; }
Note that, in the current implementation, the filtered list will be an ArrayList, but this may change in a future implementation. @see Filterable::filterByCallback() @example $list = $list->filterByCallback(function($item, $list) { return $item->Age == 9; }) @param callable $callback @return ArrayList<T>
filterByCallback
php
silverstripe/silverstripe-framework
src/ORM/ListDecorator.php
https://github.com/silverstripe/silverstripe-framework/blob/master/src/ORM/ListDecorator.php
BSD-3-Clause
public function byIDs($ids) { return $this->list->byIDs($ids); }
Filter this list to only contain the given Primary IDs @param array $ids Array of integers @return TList<T>
byIDs
php
silverstripe/silverstripe-framework
src/ORM/ListDecorator.php
https://github.com/silverstripe/silverstripe-framework/blob/master/src/ORM/ListDecorator.php
BSD-3-Clause
public function exclude() { return $this->list->exclude(...func_get_args()); }
Exclude the list to not contain items with these characteristics @example $list->exclude('Name', 'bob'); // exclude bob from list @example $list->exclude('Name', array('aziz', 'bob'); // exclude aziz and bob from list @example $list->exclude(array('Name'=>'bob, 'Age'=>21)); // exclude bob or someone with Age 21 @example $list->exclude(array('Name'=>'bob, 'Age'=>array(21, 43))); // exclude bob or anyone with Age 21 or 43 @return TList<T>
exclude
php
silverstripe/silverstripe-framework
src/ORM/ListDecorator.php
https://github.com/silverstripe/silverstripe-framework/blob/master/src/ORM/ListDecorator.php
BSD-3-Clause
public function __construct($dataClass) { $this->dataClass = $dataClass; $this->dataQuery = new DataQuery($this->dataClass); parent::__construct(); }
Create a new DataList. No querying is done on construction, but the initial query schema is set up. @param class-string<T> $dataClass - The DataObject class to query.
__construct
php
silverstripe/silverstripe-framework
src/ORM/DataList.php
https://github.com/silverstripe/silverstripe-framework/blob/master/src/ORM/DataList.php
BSD-3-Clause
public function __clone() { $this->dataQuery = clone $this->dataQuery; $this->finalisedQuery = null; $this->eagerLoadedData = []; }
When cloning this object, clone the dataQuery object as well
__clone
php
silverstripe/silverstripe-framework
src/ORM/DataList.php
https://github.com/silverstripe/silverstripe-framework/blob/master/src/ORM/DataList.php
BSD-3-Clause
public function dataQuery() { return clone $this->dataQuery; }
Return a copy of the internal {@link DataQuery} object Because the returned value is a copy, modifying it won't affect this list's contents. If you want to alter the data query directly, use the alterDataQuery method @return DataQuery
dataQuery
php
silverstripe/silverstripe-framework
src/ORM/DataList.php
https://github.com/silverstripe/silverstripe-framework/blob/master/src/ORM/DataList.php
BSD-3-Clause
public function alterDataQuery($callback) { if ($this->inAlterDataQueryCall) { $list = $this; $res = call_user_func($callback, $list->dataQuery, $list); if ($res) { $list->dataQuery = $res; } return $list; } $list = clone $this; $list->inAlterDataQueryCall = true; try { $res = $callback($list->dataQuery, $list); if ($res) { $list->dataQuery = $res; } } catch (Exception $e) { $list->inAlterDataQueryCall = false; throw $e; } $list->inAlterDataQueryCall = false; return $list; }
Return a new DataList instance with the underlying {@link DataQuery} object altered If you want to alter the underlying dataQuery for this list, this wrapper method will ensure that you can do so without mutating the existing List object. It clones this list, calls the passed callback function with the dataQuery of the new list as it's first parameter (and the list as it's second), then returns the list Note that this function is re-entrant - it's safe to call this inside a callback passed to alterDataQuery @param callable $callback @return static<T> @throws Exception
alterDataQuery
php
silverstripe/silverstripe-framework
src/ORM/DataList.php
https://github.com/silverstripe/silverstripe-framework/blob/master/src/ORM/DataList.php
BSD-3-Clause
public function sql(&$parameters = []) { return $this->dataQuery->query()->sql($parameters); }
Returns the SQL query that will be used to get this DataList's records. Good for debugging. :-) @param array $parameters Out variable for parameters required for this query @return string The resulting SQL query (may be parameterised)
sql
php
silverstripe/silverstripe-framework
src/ORM/DataList.php
https://github.com/silverstripe/silverstripe-framework/blob/master/src/ORM/DataList.php
BSD-3-Clause
public function canSortBy($fieldName) { return $this->dataQuery()->query()->canSortBy($fieldName); }
Returns true if this DataList can be sorted by the given field. @param string $fieldName @return boolean
canSortBy
php
silverstripe/silverstripe-framework
src/ORM/DataList.php
https://github.com/silverstripe/silverstripe-framework/blob/master/src/ORM/DataList.php
BSD-3-Clause
protected function isValidRelationName($field) { return preg_match('/^[A-Z0-9\._]+$/i', $field ?? ''); }
Check if the given field specification could be interpreted as an unquoted relation name @param string $field @return bool
isValidRelationName
php
silverstripe/silverstripe-framework
src/ORM/DataList.php
https://github.com/silverstripe/silverstripe-framework/blob/master/src/ORM/DataList.php
BSD-3-Clause
public function toArray() { $results = []; foreach ($this as $item) { $results[] = $item; } return $results; }
Return an array of the actual items that this DataList contains at this stage. This is when the query is actually executed. @return array<T>
toArray
php
silverstripe/silverstripe-framework
src/ORM/DataList.php
https://github.com/silverstripe/silverstripe-framework/blob/master/src/ORM/DataList.php
BSD-3-Clause
public function createDataObject($row) { $class = $this->dataClass; if (empty($row['ClassName'])) { $row['ClassName'] = $class; } // Failover from RecordClassName to ClassName if (empty($row['RecordClassName'])) { $row['RecordClassName'] = $row['ClassName']; } // Instantiate the class mentioned in RecordClassName only if it exists, otherwise default to $this->dataClass if (class_exists($row['RecordClassName'] ?? '')) { $class = $row['RecordClassName']; } $creationType = empty($row['ID']) ? DataObject::CREATE_OBJECT : DataObject::CREATE_HYDRATED; $item = Injector::inst()->create($class, $row, $creationType, $this->getQueryParams()); $this->setDataObjectEagerLoadedData($item); return $item; }
Create a DataObject from the given SQL row If called without $row['ID'] set, then a new object will be created rather than rehydrated. @param array $row @return T
createDataObject
php
silverstripe/silverstripe-framework
src/ORM/DataList.php
https://github.com/silverstripe/silverstripe-framework/blob/master/src/ORM/DataList.php
BSD-3-Clause
public function getQueryParams() { return $this->dataQuery()->getQueryParams(); }
Get query parameters for this list. These values will be assigned as query parameters to newly created objects from this list. @return array
getQueryParams
php
silverstripe/silverstripe-framework
src/ORM/DataList.php
https://github.com/silverstripe/silverstripe-framework/blob/master/src/ORM/DataList.php
BSD-3-Clause
protected function getFinalisedQuery() { if (!$this->finalisedQuery) { $this->finalisedQuery = $this->executeQuery(); } return $this->finalisedQuery; }
Returns the Query result for this DataList. Repeated calls will return a cached result, unless the DataQuery underlying this list has been modified @return Query @internal This API may change in minor releases
getFinalisedQuery
php
silverstripe/silverstripe-framework
src/ORM/DataList.php
https://github.com/silverstripe/silverstripe-framework/blob/master/src/ORM/DataList.php
BSD-3-Clause
public function max($fieldName) { return $this->dataQuery->max($fieldName); }
Return the maximum value of the given field in this DataList @param string $fieldName @return mixed
max
php
silverstripe/silverstripe-framework
src/ORM/DataList.php
https://github.com/silverstripe/silverstripe-framework/blob/master/src/ORM/DataList.php
BSD-3-Clause
public function min($fieldName) { return $this->dataQuery->min($fieldName); }
Return the minimum value of the given field in this DataList @param string $fieldName @return mixed
min
php
silverstripe/silverstripe-framework
src/ORM/DataList.php
https://github.com/silverstripe/silverstripe-framework/blob/master/src/ORM/DataList.php
BSD-3-Clause
public function avg($fieldName) { return $this->dataQuery->avg($fieldName); }
Return the average value of the given field in this DataList @param string $fieldName @return mixed
avg
php
silverstripe/silverstripe-framework
src/ORM/DataList.php
https://github.com/silverstripe/silverstripe-framework/blob/master/src/ORM/DataList.php
BSD-3-Clause
public function sum($fieldName) { return $this->dataQuery->sum($fieldName); }
Return the sum of the values of the given field in this DataList @param string $fieldName @return mixed
sum
php
silverstripe/silverstripe-framework
src/ORM/DataList.php
https://github.com/silverstripe/silverstripe-framework/blob/master/src/ORM/DataList.php
BSD-3-Clause
public function exists() { return $this->dataQuery->exists(); }
Returns true if this DataList has items @return bool
exists
php
silverstripe/silverstripe-framework
src/ORM/DataList.php
https://github.com/silverstripe/silverstripe-framework/blob/master/src/ORM/DataList.php
BSD-3-Clause
public function columnUnique($colName = "ID") { return $this->dataQuery->distinct(true)->column($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/DataList.php
https://github.com/silverstripe/silverstripe-framework/blob/master/src/ORM/DataList.php
BSD-3-Clause
public function getIDList() { $ids = $this->column("ID"); return $ids ? array_combine($ids, $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. @return array<int>
getIDList
php
silverstripe/silverstripe-framework
src/ORM/DataList.php
https://github.com/silverstripe/silverstripe-framework/blob/master/src/ORM/DataList.php
BSD-3-Clause
public function relation($relationName) { $ids = $this->column('ID'); $singleton = DataObject::singleton($this->dataClass); /** @var RelationList $relation */ $relation = $singleton->$relationName($ids); return $relation; }
Returns a HasManyList or ManyMany list representing the querying of a relation across all objects in this data list. For it to work, the relation must be defined on the data class that you used to create this DataList. Example: Get members from all Groups: DataList::Create(\SilverStripe\Security\Group::class)->relation("Members") @param string $relationName @return RelationList
relation
php
silverstripe/silverstripe-framework
src/ORM/DataList.php
https://github.com/silverstripe/silverstripe-framework/blob/master/src/ORM/DataList.php
BSD-3-Clause