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 getDbName() { // Special handler for "NULL" relations if ($this->name === "NULL") { return $this->name; } // Ensure that we're dealing with a DataObject. if (!is_subclass_of($this->model, DataObject::class)) { throw new InvalidArgumentException( "Model supplied to " . static::class . " should be an instance of DataObject." ); } $tablePrefix = DataQuery::applyRelationPrefix($this->relation); $schema = DataObject::getSchema(); if ($this->aggregate) { $column = $this->aggregate['column']; $function = $this->aggregate['function']; $table = $column ? $schema->tableForField($this->model, $column) : $schema->baseDataTable($this->model); if (!$table) { throw new InvalidArgumentException(sprintf( 'Invalid column %s for aggregate function %s on %s', $column, $function, $this->model )); } return sprintf( '%s("%s%s".%s)', $function, $tablePrefix, $table, $column ? "\"$column\"" : '"ID"' ); } // Check if this column is a table on the current model $table = $schema->tableForField($this->model, $this->name); if ($table) { return $schema->sqlColumnForField($this->model, $this->name, $tablePrefix); } // fallback to the provided name in the event of a joined column // name (as the candidate class doesn't check joined records) $parts = explode('.', $this->fullName ?? ''); return '"' . implode('"."', $parts) . '"'; }
Normalizes the field name to table mapping. @return string
getDbName
php
silverstripe/silverstripe-framework
src/ORM/Filters/SearchFilter.php
https://github.com/silverstripe/silverstripe-framework/blob/master/src/ORM/Filters/SearchFilter.php
BSD-3-Clause
public function getDbFormattedValue() { // SRM: This code finds the table where the field named $this->name lives if ($this->aggregate) { return intval($this->value); } /** @var DBField $dbField */ $dbField = singleton($this->model)->dbObject($this->name); $dbField->setValue($this->value); return $dbField->RAW(); }
Return the value of the field as processed by the DBField class @return string
getDbFormattedValue
php
silverstripe/silverstripe-framework
src/ORM/Filters/SearchFilter.php
https://github.com/silverstripe/silverstripe-framework/blob/master/src/ORM/Filters/SearchFilter.php
BSD-3-Clause
public function applyAggregate(DataQuery $query, $having) { $schema = DataObject::getSchema(); $baseTable = $schema->baseDataTable($query->dataClass()); return $query ->having($having) ->groupby("\"{$baseTable}\".\"ID\""); }
Given an escaped HAVING clause, add it along with the appropriate GROUP BY clause @param DataQuery $query @param string $having @return DataQuery
applyAggregate
php
silverstripe/silverstripe-framework
src/ORM/Filters/SearchFilter.php
https://github.com/silverstripe/silverstripe-framework/blob/master/src/ORM/Filters/SearchFilter.php
BSD-3-Clause
protected function applyMany(DataQuery $query) { throw new InvalidArgumentException(static::class . " can't be used to filter by a list of items."); }
Apply filter criteria to a SQL query with an array of values. @param DataQuery $query @return DataQuery
applyMany
php
silverstripe/silverstripe-framework
src/ORM/Filters/SearchFilter.php
https://github.com/silverstripe/silverstripe-framework/blob/master/src/ORM/Filters/SearchFilter.php
BSD-3-Clause
public function exclude(DataQuery $query) { if (($key = array_search('not', $this->modifiers ?? [])) !== false) { unset($this->modifiers[$key]); return $this->apply($query); } if (is_array($this->value)) { return $this->excludeMany($query); } else { return $this->excludeOne($query); } }
Exclude filter criteria from a SQL query. @param DataQuery $query @return DataQuery
exclude
php
silverstripe/silverstripe-framework
src/ORM/Filters/SearchFilter.php
https://github.com/silverstripe/silverstripe-framework/blob/master/src/ORM/Filters/SearchFilter.php
BSD-3-Clause
protected function excludeMany(DataQuery $query) { throw new InvalidArgumentException(static::class . " can't be used to filter by a list of items."); }
Exclude filter criteria from a SQL query with an array of values. @param DataQuery $query @return DataQuery
excludeMany
php
silverstripe/silverstripe-framework
src/ORM/Filters/SearchFilter.php
https://github.com/silverstripe/silverstripe-framework/blob/master/src/ORM/Filters/SearchFilter.php
BSD-3-Clause
protected function applyOne(DataQuery $query) { return $this->oneFilter($query, true); }
Applies an exact match (equals) on a field value. @param DataQuery $query @return DataQuery
applyOne
php
silverstripe/silverstripe-framework
src/ORM/Filters/ExactMatchFilter.php
https://github.com/silverstripe/silverstripe-framework/blob/master/src/ORM/Filters/ExactMatchFilter.php
BSD-3-Clause
protected function excludeOne(DataQuery $query) { return $this->oneFilter($query, false); }
Excludes an exact match (equals) on a field value. @param DataQuery $query @return DataQuery
excludeOne
php
silverstripe/silverstripe-framework
src/ORM/Filters/ExactMatchFilter.php
https://github.com/silverstripe/silverstripe-framework/blob/master/src/ORM/Filters/ExactMatchFilter.php
BSD-3-Clause
protected function applyMany(DataQuery $query) { return $this->manyFilter($query, true); }
Applies an exact match (equals) on a field value against multiple possible values. @param DataQuery $query @return DataQuery
applyMany
php
silverstripe/silverstripe-framework
src/ORM/Filters/ExactMatchFilter.php
https://github.com/silverstripe/silverstripe-framework/blob/master/src/ORM/Filters/ExactMatchFilter.php
BSD-3-Clause
protected function excludeMany(DataQuery $query) { return $this->manyFilter($query, false); }
Excludes an exact match (equals) on a field value against multiple possible values. @param DataQuery $query @return DataQuery
excludeMany
php
silverstripe/silverstripe-framework
src/ORM/Filters/ExactMatchFilter.php
https://github.com/silverstripe/silverstripe-framework/blob/master/src/ORM/Filters/ExactMatchFilter.php
BSD-3-Clause
public function __construct($name = null, $size = 255, $options = []) { $this->size = $size ? $size : 255; parent::__construct($name, $options); }
Construct a new short text field @param string $name The name of the field @param int $size The maximum size of the field, in terms of characters @param array $options Optional parameters, e.g. array("nullifyEmpty"=>false). See {@link StringField::setOptions()} for information on the available options
__construct
php
silverstripe/silverstripe-framework
src/ORM/FieldType/DBVarchar.php
https://github.com/silverstripe/silverstripe-framework/blob/master/src/ORM/FieldType/DBVarchar.php
BSD-3-Clause
public function Initial() { if ($this->exists()) { $value = $this->RAW(); return $value[0] . '.'; } return null; }
Return the first letter of the string followed by a . @return string
Initial
php
silverstripe/silverstripe-framework
src/ORM/FieldType/DBVarchar.php
https://github.com/silverstripe/silverstripe-framework/blob/master/src/ORM/FieldType/DBVarchar.php
BSD-3-Clause
public function URL() { $value = $this->RAW(); if (preg_match('#^[a-zA-Z]+://#', $value ?? '')) { return $value; } return 'http://' . $value; }
Ensure that the given value is an absolute URL. @return string
URL
php
silverstripe/silverstripe-framework
src/ORM/FieldType/DBVarchar.php
https://github.com/silverstripe/silverstripe-framework/blob/master/src/ORM/FieldType/DBVarchar.php
BSD-3-Clause
public function RTF() { return str_replace("\n", '\par ', $this->RAW() ?? ''); }
Return the value of the field in rich text format @return string
RTF
php
silverstripe/silverstripe-framework
src/ORM/FieldType/DBVarchar.php
https://github.com/silverstripe/silverstripe-framework/blob/master/src/ORM/FieldType/DBVarchar.php
BSD-3-Clause
public function getProcessShortcodes() { return $this->processShortcodes; }
Check if shortcodes are enabled @return bool
getProcessShortcodes
php
silverstripe/silverstripe-framework
src/ORM/FieldType/DBHTMLText.php
https://github.com/silverstripe/silverstripe-framework/blob/master/src/ORM/FieldType/DBHTMLText.php
BSD-3-Clause
public function setProcessShortcodes($process) { $this->processShortcodes = (bool)$process; return $this; }
Set shortcodes on or off by default @param bool $process @return $this
setProcessShortcodes
php
silverstripe/silverstripe-framework
src/ORM/FieldType/DBHTMLText.php
https://github.com/silverstripe/silverstripe-framework/blob/master/src/ORM/FieldType/DBHTMLText.php
BSD-3-Clause
public function getWhitelist() { return $this->whitelist; }
List of html properties to whitelist @return array
getWhitelist
php
silverstripe/silverstripe-framework
src/ORM/FieldType/DBHTMLText.php
https://github.com/silverstripe/silverstripe-framework/blob/master/src/ORM/FieldType/DBHTMLText.php
BSD-3-Clause
public function setWhitelist($whitelist) { if (!is_array($whitelist)) { $whitelist = preg_split('/\s*,\s*/', $whitelist ?? ''); } $this->whitelist = $whitelist; return $this; }
Set list of html properties to whitelist @param array $whitelist @return $this
setWhitelist
php
silverstripe/silverstripe-framework
src/ORM/FieldType/DBHTMLText.php
https://github.com/silverstripe/silverstripe-framework/blob/master/src/ORM/FieldType/DBHTMLText.php
BSD-3-Clause
public function setOptions(array $options = []) { if (array_key_exists("shortcodes", $options ?? [])) { $this->setProcessShortcodes(!!$options["shortcodes"]); } if (array_key_exists("whitelist", $options ?? [])) { $this->setWhitelist($options['whitelist']); } return parent::setOptions($options); }
@param array $options Options accepted in addition to those provided by Text: - shortcodes: If true, shortcodes will be turned into the appropriate HTML. If false, shortcodes will not be processed. - whitelist: If provided, a comma-separated list of elements that will be allowed to be stored (be careful on relying on this for XSS protection - some seemingly-safe elements allow attributes that can be exploited, for instance <img onload="exploiting_code();" src="..." />) Text nodes outside of HTML tags are filtered out by default, but may be included by adding the text() directive. E.g. 'link,meta,text()' will allow only <link /> <meta /> and text at the root level. @return $this
setOptions
php
silverstripe/silverstripe-framework
src/ORM/FieldType/DBHTMLText.php
https://github.com/silverstripe/silverstripe-framework/blob/master/src/ORM/FieldType/DBHTMLText.php
BSD-3-Clause
public function AbsoluteLinks() { return HTTP::absoluteURLs($this->forTemplate()); }
Return the value of the field with relative links converted to absolute urls (with placeholders parsed). @return string
AbsoluteLinks
php
silverstripe/silverstripe-framework
src/ORM/FieldType/DBHTMLText.php
https://github.com/silverstripe/silverstripe-framework/blob/master/src/ORM/FieldType/DBHTMLText.php
BSD-3-Clause
public function whitelistContent($value) { if ($this->whitelist) { $dom = HTMLValue::create($value); $query = []; $textFilter = ' | //body/text()'; foreach ($this->whitelist as $tag) { if ($tag === 'text()') { $textFilter = ''; // Disable text filter if allowed } else { $query[] = 'not(self::' . $tag . ')'; } } foreach ($dom->query('//body//*[' . implode(' and ', $query) . ']' . $textFilter) as $el) { if ($el->parentNode) { $el->parentNode->removeChild($el); } } $value = $dom->getContent(); } return $value; }
Filter the given $value string through the whitelist filter @param string $value Input html content @return string Value with all non-whitelisted content stripped (if applicable)
whitelistContent
php
silverstripe/silverstripe-framework
src/ORM/FieldType/DBHTMLText.php
https://github.com/silverstripe/silverstripe-framework/blob/master/src/ORM/FieldType/DBHTMLText.php
BSD-3-Clause
public function Nice() { return number_format($this->value * 100, $this->decimalSize - 2) . '%'; }
Returns the number, expressed as a percentage. For example, “36.30%”
Nice
php
silverstripe/silverstripe-framework
src/ORM/FieldType/DBPercentage.php
https://github.com/silverstripe/silverstripe-framework/blob/master/src/ORM/FieldType/DBPercentage.php
BSD-3-Clause
private function getDefaultOptions($start = null, $end = null) { if (!$start) { $start = (int)date('Y'); } if (!$end) { $end = 1900; } $years = []; for ($i = $start; $i >= $end; $i--) { $years[$i] = $i; } return $years; }
Returns a list of default options that can be used to populate a select box, or compare against input values. Starts by default at the current year, and counts back to 1900. @param int|bool $start starting date to count down from @param int|bool $end end date to count down to @return array
getDefaultOptions
php
silverstripe/silverstripe-framework
src/ORM/FieldType/DBYear.php
https://github.com/silverstripe/silverstripe-framework/blob/master/src/ORM/FieldType/DBYear.php
BSD-3-Clause
public function Plain() { // Strip out HTML $text = strip_tags($this->RAW() ?? ''); // Convert back to plain text return trim(Convert::xml2raw($text) ?? ''); }
Get plain-text version. Note: unlike DBHTMLText, this doesn't respect line breaks / paragraphs @return string
Plain
php
silverstripe/silverstripe-framework
src/ORM/FieldType/DBHTMLVarchar.php
https://github.com/silverstripe/silverstripe-framework/blob/master/src/ORM/FieldType/DBHTMLVarchar.php
BSD-3-Clause
public function Nice($showNative = false) { if ($showNative) { return $this->getNativeName(); } return $this->getShortName(); }
See {@link getShortName()} and {@link getNativeName()}. @param Boolean $showNative Show a localized version of the name instead, based on the field's locale value. @return String
Nice
php
silverstripe/silverstripe-framework
src/ORM/FieldType/DBLocale.php
https://github.com/silverstripe/silverstripe-framework/blob/master/src/ORM/FieldType/DBLocale.php
BSD-3-Clause
public function getShortName() { return i18n::getData()->languageName($this->value); }
Resolves the locale to a common english-language name through {@link i18n::get_common_locales()}. @return string
getShortName
php
silverstripe/silverstripe-framework
src/ORM/FieldType/DBLocale.php
https://github.com/silverstripe/silverstripe-framework/blob/master/src/ORM/FieldType/DBLocale.php
BSD-3-Clause
public function getNativeName() { $locale = $this->value; return i18n::with_locale($locale, function () { return $this->getShortName(); }); }
Returns the localized name based on the field's value. Example: "de_DE" returns "Deutsch". @return string
getNativeName
php
silverstripe/silverstripe-framework
src/ORM/FieldType/DBLocale.php
https://github.com/silverstripe/silverstripe-framework/blob/master/src/ORM/FieldType/DBLocale.php
BSD-3-Clause
public function formField($title = null, $name = null, $hasEmpty = false, $value = '', $emptyString = null) { if (!$title) { $title = $this->getName(); } if (!$name) { $name = $this->getName(); } $field = DropdownField::create($name, $title, $this->enumValues(false), $value); if ($hasEmpty) { $field->setEmptyString($emptyString); } return $field; }
Return a dropdown field suitable for editing this field. @param string $title @param string $name @param bool $hasEmpty @param string $value @param string $emptyString @return DropdownField
formField
php
silverstripe/silverstripe-framework
src/ORM/FieldType/DBEnum.php
https://github.com/silverstripe/silverstripe-framework/blob/master/src/ORM/FieldType/DBEnum.php
BSD-3-Clause
public function getEnumObsolete() { // Without a table or field specified, we can only retrieve known enum values $table = $this->getTable(); $name = $this->getName(); if (empty($table) || empty($name)) { return $this->getEnum(); } // Ensure the table level cache exists if (empty(DBEnum::$enum_cache[$table])) { DBEnum::$enum_cache[$table] = []; } // Check existing cache if (!empty(DBEnum::$enum_cache[$table][$name])) { return DBEnum::$enum_cache[$table][$name]; } // Get all enum values $enumValues = $this->getEnum(); if (DB::get_schema()->hasField($table, $name)) { $existing = DB::query("SELECT DISTINCT \"{$name}\" FROM \"{$table}\"")->column(); $enumValues = array_unique(array_merge($enumValues, $existing)); } // Cache and return DBEnum::$enum_cache[$table][$name] = $enumValues; return $enumValues; }
Get the list of enum values, including obsolete values still present in the database If table or name are not set, or if it is not a valid field on the given table, then only known enum values are returned. Values cached in this method can be cleared via `DBEnum::reset();` @return array
getEnumObsolete
php
silverstripe/silverstripe-framework
src/ORM/FieldType/DBEnum.php
https://github.com/silverstripe/silverstripe-framework/blob/master/src/ORM/FieldType/DBEnum.php
BSD-3-Clause
public function Date() { $formatter = $this->getFormatter(IntlDateFormatter::MEDIUM, IntlDateFormatter::NONE); return $formatter->format($this->getTimestamp()); }
Returns the standard localised date @return string Formatted date.
Date
php
silverstripe/silverstripe-framework
src/ORM/FieldType/DBDatetime.php
https://github.com/silverstripe/silverstripe-framework/blob/master/src/ORM/FieldType/DBDatetime.php
BSD-3-Clause
public function Time() { $formatter = $this->getFormatter(IntlDateFormatter::NONE, IntlDateFormatter::MEDIUM); return $formatter->format($this->getTimestamp()); }
Returns the standard localised time @return string Formatted time.
Time
php
silverstripe/silverstripe-framework
src/ORM/FieldType/DBDatetime.php
https://github.com/silverstripe/silverstripe-framework/blob/master/src/ORM/FieldType/DBDatetime.php
BSD-3-Clause
public function Time12() { return $this->Format('h:mm a'); }
Returns the time in 12-hour format using the format string 'h:mm a' e.g. '1:32 pm'. @return string Formatted time.
Time12
php
silverstripe/silverstripe-framework
src/ORM/FieldType/DBDatetime.php
https://github.com/silverstripe/silverstripe-framework/blob/master/src/ORM/FieldType/DBDatetime.php
BSD-3-Clause
public function Time24() { return $this->Format('H:mm'); }
Returns the time in 24-hour format using the format string 'H:mm' e.g. '13:32'. @return string Formatted time.
Time24
php
silverstripe/silverstripe-framework
src/ORM/FieldType/DBDatetime.php
https://github.com/silverstripe/silverstripe-framework/blob/master/src/ORM/FieldType/DBDatetime.php
BSD-3-Clause
public function FormatFromSettings($member = null) { if (!$member) { $member = Security::getCurrentUser(); } // Fall back to nice if (!$member) { return $this->Nice(); } $dateFormat = $member->getDateFormat(); $timeFormat = $member->getTimeFormat(); // Get user format return $this->Format($dateFormat . ' ' . $timeFormat, $member->getLocale()); }
Return a date and time formatted as per a CMS user's settings. @param Member $member @return boolean|string A time and date pair formatted as per user-defined settings.
FormatFromSettings
php
silverstripe/silverstripe-framework
src/ORM/FieldType/DBDatetime.php
https://github.com/silverstripe/silverstripe-framework/blob/master/src/ORM/FieldType/DBDatetime.php
BSD-3-Clause
public function URLDatetime() { return rawurlencode($this->Format(DBDatetime::ISO_DATETIME, DBDatetime::ISO_LOCALE) ?? ''); }
Returns the url encoded date and time in ISO 6801 format using format string 'y-MM-dd%20HH:mm:ss' e.g. '2014-02-28%2013:32:22'. @return string Formatted date and time.
URLDatetime
php
silverstripe/silverstripe-framework
src/ORM/FieldType/DBDatetime.php
https://github.com/silverstripe/silverstripe-framework/blob/master/src/ORM/FieldType/DBDatetime.php
BSD-3-Clause
public static function now() { $time = DBDatetime::$mock_now ? DBDatetime::$mock_now->Value : time(); /** @var DBDatetime $now */ $now = DBField::create_field('Datetime', $time); return $now; }
Returns either the current system date as determined by date(), or a mocked date through {@link set_mock_now()}. @return static
now
php
silverstripe/silverstripe-framework
src/ORM/FieldType/DBDatetime.php
https://github.com/silverstripe/silverstripe-framework/blob/master/src/ORM/FieldType/DBDatetime.php
BSD-3-Clause
public static function set_mock_now($datetime) { if (!$datetime instanceof DBDatetime) { $value = $datetime; $datetime = DBField::create_field('Datetime', $datetime); if ($datetime === false) { throw new InvalidArgumentException('DBDatetime::set_mock_now(): Wrong format: ' . $value); } } DBDatetime::$mock_now = $datetime; }
Mock the system date temporarily, which is useful for time-based unit testing. Use {@link clear_mock_now()} to revert to the current system date. Caution: This sets a fixed date that doesn't increment with time. @param DBDatetime|string $datetime Either in object format, or as a DBDatetime compatible string. @throws Exception
set_mock_now
php
silverstripe/silverstripe-framework
src/ORM/FieldType/DBDatetime.php
https://github.com/silverstripe/silverstripe-framework/blob/master/src/ORM/FieldType/DBDatetime.php
BSD-3-Clause
public static function clear_mock_now() { DBDatetime::$mock_now = null; }
Clear any mocked date, which causes {@link Now()} to return the current system date.
clear_mock_now
php
silverstripe/silverstripe-framework
src/ORM/FieldType/DBDatetime.php
https://github.com/silverstripe/silverstripe-framework/blob/master/src/ORM/FieldType/DBDatetime.php
BSD-3-Clause
public static function withFixedNow($time, $callback) { $original = DBDatetime::$mock_now; try { DBDatetime::set_mock_now($time); return $callback(); } finally { DBDatetime::$mock_now = $original; } }
Run a callback with specific time, original mock value is retained after callback @param DBDatetime|string $time @param callable $callback @return mixed @throws Exception
withFixedNow
php
silverstripe/silverstripe-framework
src/ORM/FieldType/DBDatetime.php
https://github.com/silverstripe/silverstripe-framework/blob/master/src/ORM/FieldType/DBDatetime.php
BSD-3-Clause
public function getFormatter($dateLength = IntlDateFormatter::MEDIUM, $timeLength = IntlDateFormatter::SHORT) { return parent::getFormatter($dateLength, $timeLength); }
Get date / time formatter for the current locale @param int $dateLength @param int $timeLength @return IntlDateFormatter
getFormatter
php
silverstripe/silverstripe-framework
src/ORM/FieldType/DBDatetime.php
https://github.com/silverstripe/silverstripe-framework/blob/master/src/ORM/FieldType/DBDatetime.php
BSD-3-Clause
public function getCustomFormatter( $locale = null, $pattern = null, $dateLength = IntlDateFormatter::MEDIUM, $timeLength = IntlDateFormatter::MEDIUM ) { return parent::getCustomFormatter($locale, $pattern, $dateLength, $timeLength); }
Return formatter in a given locale. Useful if localising in a format other than the current locale. @param string|null $locale The current locale, or null to use default @param string|null $pattern Custom pattern to use for this, if required @param int $dateLength @param int $timeLength @return IntlDateFormatter
getCustomFormatter
php
silverstripe/silverstripe-framework
src/ORM/FieldType/DBDatetime.php
https://github.com/silverstripe/silverstripe-framework/blob/master/src/ORM/FieldType/DBDatetime.php
BSD-3-Clause
public function getISOFormat() { return DBDatetime::ISO_DATETIME; }
Get standard ISO date format string @return string
getISOFormat
php
silverstripe/silverstripe-framework
src/ORM/FieldType/DBDatetime.php
https://github.com/silverstripe/silverstripe-framework/blob/master/src/ORM/FieldType/DBDatetime.php
BSD-3-Clause
public function getValue() { return (int) $this->value; }
Ensure int values are always returned. This is for mis-configured databases that return strings.
getValue
php
silverstripe/silverstripe-framework
src/ORM/FieldType/DBInt.php
https://github.com/silverstripe/silverstripe-framework/blob/master/src/ORM/FieldType/DBInt.php
BSD-3-Clause
public function Formatted() { return number_format($this->value ?? 0.0); }
Returns the number, with commas added as appropriate, eg “1,000”.
Formatted
php
silverstripe/silverstripe-framework
src/ORM/FieldType/DBInt.php
https://github.com/silverstripe/silverstripe-framework/blob/master/src/ORM/FieldType/DBInt.php
BSD-3-Clause
public function LimitSentences($maxSentences = 2) { if (!is_numeric($maxSentences)) { throw new InvalidArgumentException("Text::LimitSentence() expects one numeric argument"); } $value = $this->Plain(); if (!$value) { return ''; } // Do a word-search $words = preg_split('/\s+/u', $value ?? '') ?: []; $sentences = 0; foreach ($words as $i => $word) { if (preg_match('/(!|\?|\.)$/', $word ?? '') && !preg_match('/(Dr|Mr|Mrs|Ms|Miss|Sr|Jr|No)\.$/i', $word ?? '')) { $sentences++; if ($sentences >= $maxSentences) { return implode(' ', array_slice($words ?? [], 0, $i + 1)); } } } // Failing to find the number of sentences requested, fallback to a logical default if ($maxSentences > 1) { return $value; } // If searching for a single sentence (and there are none) just do a text summary return $this->Summary(20); }
Limit sentences, can be controlled by passing an integer. @param int $maxSentences The amount of sentences you want. @return string
LimitSentences
php
silverstripe/silverstripe-framework
src/ORM/FieldType/DBText.php
https://github.com/silverstripe/silverstripe-framework/blob/master/src/ORM/FieldType/DBText.php
BSD-3-Clause
public function FirstSentence() { return $this->LimitSentences(1); }
Return the first string that finishes with a period (.) in this text. @return string
FirstSentence
php
silverstripe/silverstripe-framework
src/ORM/FieldType/DBText.php
https://github.com/silverstripe/silverstripe-framework/blob/master/src/ORM/FieldType/DBText.php
BSD-3-Clause
public function ContextSummary( $characters = 500, $keywords = null, $highlight = true, $prefix = false, $suffix = false ) { if (!$keywords) { // Use the default "Search" request variable (from SearchForm) $keywords = isset($_REQUEST['Search']) ? $_REQUEST['Search'] : ''; } if ($prefix === false) { $prefix = $this->defaultEllipsis() . ' '; } if ($suffix === false) { $suffix = $this->defaultEllipsis(); } // Get raw text value, but XML encode it (as we'll be merging with HTML tags soon) $text = Convert::raw2xml($this->Plain()); $keywords = Convert::raw2xml($keywords); // Find the search string $position = empty($keywords) ? 0 : (int) mb_stripos($text ?? '', $keywords ?? ''); // We want to search string to be in the middle of our block to give it some context $position = floor(max(0, $position - ($characters / 2)) ?? 0.0); if ($position > 0) { // We don't want to start mid-word $position = max( (int) mb_strrpos(mb_substr($text ?? '', 0, $position), ' '), (int) mb_strrpos(mb_substr($text ?? '', 0, $position), "\n") ); } $summary = mb_substr($text ?? '', $position ?? 0, $characters); $stringPieces = explode(' ', $keywords ?? ''); if ($highlight) { // Add a span around all key words from the search term as well if ($stringPieces) { foreach ($stringPieces as $stringPiece) { if (mb_strlen($stringPiece ?? '') > 2) { // Maintain case of original string $summary = preg_replace( '/' . preg_quote($stringPiece ?? '', '/') . '/i', '<mark>$0</mark>', $summary ?? '' ); } } } } $summary = trim($summary ?? ''); // Add leading / trailing '...' if trimmed on either end if ($position > 0) { $summary = $prefix . $summary; } if (strlen($text ?? '') > ($characters + $position)) { $summary = $summary . $suffix; } return nl2br($summary ?? ''); }
Perform context searching to give some context to searches, optionally highlighting the search term. @param int $characters Number of characters in the summary @param string $keywords Supplied string ("keywords"). Will fall back to 'Search' querystring arg. @param bool $highlight Add a highlight <mark> element around search query? @param string|false $prefix Prefix text @param string|false $suffix Suffix text @return string HTML string with context
ContextSummary
php
silverstripe/silverstripe-framework
src/ORM/FieldType/DBText.php
https://github.com/silverstripe/silverstripe-framework/blob/master/src/ORM/FieldType/DBText.php
BSD-3-Clause
public function Nice() { $val = $this->config()->currency_symbol . number_format(abs($this->value ?? 0.0) ?? 0.0, 2); if ($this->value < 0) { return "($val)"; } return $val; }
Returns the number as a currency, eg “$1,000.00”.
Nice
php
silverstripe/silverstripe-framework
src/ORM/FieldType/DBCurrency.php
https://github.com/silverstripe/silverstripe-framework/blob/master/src/ORM/FieldType/DBCurrency.php
BSD-3-Clause
public function Whole() { $val = $this->config()->currency_symbol . number_format(abs($this->value ?? 0.0) ?? 0.0, 0); if ($this->value < 0) { return "($val)"; } return $val; }
Returns the number as a whole-number currency, eg “$1,000”.
Whole
php
silverstripe/silverstripe-framework
src/ORM/FieldType/DBCurrency.php
https://github.com/silverstripe/silverstripe-framework/blob/master/src/ORM/FieldType/DBCurrency.php
BSD-3-Clause
protected function parseDate($value) { // Skip empty values if (empty($value) && !is_numeric($value)) { return null; } // Determine value to parse if (is_array($value)) { $source = $value; // parse array } elseif (is_numeric($value)) { $source = $value; // parse timestamp } else { // Convert US date -> iso, fix y2k, etc $value = $this->fixInputDate($value); if (is_null($value)) { return null; } $source = strtotime($value ?? ''); // convert string to timestamp } if ($value === false) { return false; } // Format as iso8601 $formatter = $this->getInternalFormatter(); return $formatter->format($source); }
Parse timestamp or iso8601-ish date into standard iso8601 format @param mixed $value @return string|null|false Formatted date, null if empty but valid, or false if invalid
parseDate
php
silverstripe/silverstripe-framework
src/ORM/FieldType/DBDate.php
https://github.com/silverstripe/silverstripe-framework/blob/master/src/ORM/FieldType/DBDate.php
BSD-3-Clause
public function Nice() { if (!$this->value) { return null; } $formatter = $this->getFormatter(); return $formatter->format($this->getTimestamp()); }
Returns the standard localised medium date @return ?string
Nice
php
silverstripe/silverstripe-framework
src/ORM/FieldType/DBDate.php
https://github.com/silverstripe/silverstripe-framework/blob/master/src/ORM/FieldType/DBDate.php
BSD-3-Clause
public function Year() { return $this->Format('y'); }
Returns the year from the given date @return string
Year
php
silverstripe/silverstripe-framework
src/ORM/FieldType/DBDate.php
https://github.com/silverstripe/silverstripe-framework/blob/master/src/ORM/FieldType/DBDate.php
BSD-3-Clause
public function Month() { return $this->Format('LLLL'); }
Returns a full textual representation of a month, such as January. @return string
Month
php
silverstripe/silverstripe-framework
src/ORM/FieldType/DBDate.php
https://github.com/silverstripe/silverstripe-framework/blob/master/src/ORM/FieldType/DBDate.php
BSD-3-Clause
public function ShortMonth() { return $this->Format('LLL'); }
Returns the short version of the month such as Jan @return string
ShortMonth
php
silverstripe/silverstripe-framework
src/ORM/FieldType/DBDate.php
https://github.com/silverstripe/silverstripe-framework/blob/master/src/ORM/FieldType/DBDate.php
BSD-3-Clause
public function Short() { if (!$this->value) { return null; } $formatter = $this->getFormatter(IntlDateFormatter::SHORT); return $formatter->format($this->getTimestamp()); }
Returns the date in the localised short format @return string
Short
php
silverstripe/silverstripe-framework
src/ORM/FieldType/DBDate.php
https://github.com/silverstripe/silverstripe-framework/blob/master/src/ORM/FieldType/DBDate.php
BSD-3-Clause
public function Long() { if (!$this->value) { return null; } $formatter = $this->getFormatter(IntlDateFormatter::LONG); return $formatter->format($this->getTimestamp()); }
Returns the date in the localised long format @return string
Long
php
silverstripe/silverstripe-framework
src/ORM/FieldType/DBDate.php
https://github.com/silverstripe/silverstripe-framework/blob/master/src/ORM/FieldType/DBDate.php
BSD-3-Clause
public function Full() { if (!$this->value) { return null; } $formatter = $this->getFormatter(IntlDateFormatter::FULL); return $formatter->format($this->getTimestamp()); }
Returns the date in the localised full format @return string
Full
php
silverstripe/silverstripe-framework
src/ORM/FieldType/DBDate.php
https://github.com/silverstripe/silverstripe-framework/blob/master/src/ORM/FieldType/DBDate.php
BSD-3-Clause
public function Format($format) { // Note: soft-arg uses func_get_args() to respect semver. Add to signature in 5.0 $locale = func_num_args() > 1 ? func_get_arg(1) : null; if (!$this->value) { return null; } // Replace {o} with ordinal representation of day of the month if (strpos($format ?? '', '{o}') !== false) { $format = str_replace('{o}', "'{$this->DayOfMonth(true)}'", $format ?? ''); } $formatter = $this->getCustomFormatter($locale, $format); return $formatter->Format($this->getTimestamp()); }
Return the date using a particular formatting string. Use {o} to include an ordinal representation for the day of the month ("1st", "2nd", "3rd" etc) @param string $format Format code string. See https://unicode-org.github.io/icu/userguide/format_parse/datetime @param string $locale Custom locale to use (add to signature in 5.0) @return ?string The date in the requested format
Format
php
silverstripe/silverstripe-framework
src/ORM/FieldType/DBDate.php
https://github.com/silverstripe/silverstripe-framework/blob/master/src/ORM/FieldType/DBDate.php
BSD-3-Clause
public function getTimestamp() { if ($this->value) { return strtotime($this->value ?? ''); } return 0; }
Get unix timestamp for this date @return int
getTimestamp
php
silverstripe/silverstripe-framework
src/ORM/FieldType/DBDate.php
https://github.com/silverstripe/silverstripe-framework/blob/master/src/ORM/FieldType/DBDate.php
BSD-3-Clause
public function FormatFromSettings($member = null) { if (!$member) { $member = Security::getCurrentUser(); } // Fall back to nice if (!$member) { return $this->Nice(); } // Get user format return $this->Format($member->getDateFormat(), $member->getLocale()); }
Return a date formatted as per a CMS user's settings. @param Member $member @return boolean | string A date formatted as per user-defined settings.
FormatFromSettings
php
silverstripe/silverstripe-framework
src/ORM/FieldType/DBDate.php
https://github.com/silverstripe/silverstripe-framework/blob/master/src/ORM/FieldType/DBDate.php
BSD-3-Clause
public function RangeString($otherDateObj, $includeOrdinals = false) { $d1 = $this->DayOfMonth($includeOrdinals); $d2 = $otherDateObj->DayOfMonth($includeOrdinals); $m1 = $this->ShortMonth(); $m2 = $otherDateObj->ShortMonth(); $y1 = $this->Year(); $y2 = $otherDateObj->Year(); if ($y1 != $y2) { return "$d1 $m1 $y1 - $d2 $m2 $y2"; } if ($m1 != $m2) { return "$d1 $m1 - $d2 $m2 $y1"; } return "$d1 - $d2 $m1 $y1"; }
Return a string in the form "12 - 16 Sept" or "12 Aug - 16 Sept" @param DBDate $otherDateObj Another date object specifying the end of the range @param bool $includeOrdinals Include ordinal suffix to day, e.g. "th" or "rd" @return string
RangeString
php
silverstripe/silverstripe-framework
src/ORM/FieldType/DBDate.php
https://github.com/silverstripe/silverstripe-framework/blob/master/src/ORM/FieldType/DBDate.php
BSD-3-Clause
public function Rfc822() { if ($this->value) { return date('r', $this->getTimestamp()); } return null; }
Return string in RFC822 format @return string
Rfc822
php
silverstripe/silverstripe-framework
src/ORM/FieldType/DBDate.php
https://github.com/silverstripe/silverstripe-framework/blob/master/src/ORM/FieldType/DBDate.php
BSD-3-Clause
public function Ago($includeSeconds = true, $significance = 2) { if (!$this->value) { return null; } $timestamp = $this->getTimestamp(); $now = DBDatetime::now()->getTimestamp(); if ($timestamp <= $now) { return _t( __CLASS__ . '.TIMEDIFFAGO', "{difference} ago", 'Natural language time difference, e.g. 2 hours ago', ['difference' => $this->TimeDiff($includeSeconds, $significance)] ); } return _t( __CLASS__ . '.TIMEDIFFIN', "in {difference}", 'Natural language time difference, e.g. in 2 hours', ['difference' => $this->TimeDiff($includeSeconds, $significance)] ); }
Returns the number of seconds/minutes/hours/days or months since the timestamp. @param boolean $includeSeconds Show seconds, or just round to "less than a minute". @param int $significance Minimum significant value of X for "X units ago" to display @return string
Ago
php
silverstripe/silverstripe-framework
src/ORM/FieldType/DBDate.php
https://github.com/silverstripe/silverstripe-framework/blob/master/src/ORM/FieldType/DBDate.php
BSD-3-Clause
public function TimeDiffIn($format) { if (!$this->value) { return null; } $now = DBDatetime::now()->getTimestamp(); $time = $this->getTimestamp(); $ago = abs($time - $now); switch ($format) { case 'seconds': $span = $ago; return _t( __CLASS__ . '.SECONDS_SHORT_PLURALS', '{count} sec|{count} secs', ['count' => $span] ); case 'minutes': $span = round($ago / 60); return _t( __CLASS__ . '.MINUTES_SHORT_PLURALS', '{count} min|{count} mins', ['count' => $span] ); case 'hours': $span = round($ago / 3600); return _t( __CLASS__ . '.HOURS_SHORT_PLURALS', '{count} hour|{count} hours', ['count' => $span] ); case 'days': $span = round($ago / 86400); return _t( __CLASS__ . '.DAYS_SHORT_PLURALS', '{count} day|{count} days', ['count' => $span] ); case 'months': $span = round($ago / 86400 / 30); return _t( __CLASS__ . '.MONTHS_SHORT_PLURALS', '{count} month|{count} months', ['count' => $span] ); case 'years': $span = round($ago / 86400 / 365); return _t( __CLASS__ . '.YEARS_SHORT_PLURALS', '{count} year|{count} years', ['count' => $span] ); default: throw new \InvalidArgumentException("Invalid format $format"); } }
Gets the time difference, but always returns it in a certain format @param string $format The format, could be one of these: 'seconds', 'minutes', 'hours', 'days', 'months', 'years'. @return string The resulting formatted period
TimeDiffIn
php
silverstripe/silverstripe-framework
src/ORM/FieldType/DBDate.php
https://github.com/silverstripe/silverstripe-framework/blob/master/src/ORM/FieldType/DBDate.php
BSD-3-Clause
public function InPast() { return strtotime($this->value ?? '') < DBDatetime::now()->getTimestamp(); }
Returns true if date is in the past. @return boolean
InPast
php
silverstripe/silverstripe-framework
src/ORM/FieldType/DBDate.php
https://github.com/silverstripe/silverstripe-framework/blob/master/src/ORM/FieldType/DBDate.php
BSD-3-Clause
public function InFuture() { return strtotime($this->value ?? '') > DBDatetime::now()->getTimestamp(); }
Returns true if date is in the future. @return boolean
InFuture
php
silverstripe/silverstripe-framework
src/ORM/FieldType/DBDate.php
https://github.com/silverstripe/silverstripe-framework/blob/master/src/ORM/FieldType/DBDate.php
BSD-3-Clause
public function IsToday() { return $this->Format(DBDate::ISO_DATE) === DBDatetime::now()->Format(DBDate::ISO_DATE); }
Returns true if date is today. @return boolean
IsToday
php
silverstripe/silverstripe-framework
src/ORM/FieldType/DBDate.php
https://github.com/silverstripe/silverstripe-framework/blob/master/src/ORM/FieldType/DBDate.php
BSD-3-Clause
public function URLDate() { return rawurlencode($this->Format(DBDate::ISO_DATE, DBDate::ISO_LOCALE) ?? ''); }
Returns a date suitable for insertion into a URL and use by the system. @return string
URLDate
php
silverstripe/silverstripe-framework
src/ORM/FieldType/DBDate.php
https://github.com/silverstripe/silverstripe-framework/blob/master/src/ORM/FieldType/DBDate.php
BSD-3-Clause
protected function explodeDateString($value) { // split on known delimiters (. / -) if (!preg_match( '#^(?<first>\\d+)[-/\\.](?<second>\\d+)[-/\\.](?<third>\\d+)(?<time>.*)$#', $value ?? '', $matches )) { throw new InvalidArgumentException( "Invalid date: '$value'. Use " . DBDate::ISO_DATE . " to prevent this error." ); } $parts = [ $matches['first'], $matches['second'], $matches['third'] ]; // Flip d-m-y to y-m-d if ($parts[0] < 1000 && $parts[2] > 1000) { $parts = array_reverse($parts ?? []); } if ($parts[0] < 1000 && (int)$parts[0] !== 0) { throw new InvalidArgumentException( "Invalid date: '$value'. Use " . DBDate::ISO_DATE . " to prevent this error." ); } $parts[] = $matches['time']; return $parts; }
Attempt to split date string into year, month, day, and timestamp components. @param string $value @return array
explodeDateString
php
silverstripe/silverstripe-framework
src/ORM/FieldType/DBDate.php
https://github.com/silverstripe/silverstripe-framework/blob/master/src/ORM/FieldType/DBDate.php
BSD-3-Clause
public function Nice() { return number_format($this->value ?? 0.0, 2); }
Returns the number, with commas and decimal places as appropriate, eg “1,000.00”. @uses number_format()
Nice
php
silverstripe/silverstripe-framework
src/ORM/FieldType/DBFloat.php
https://github.com/silverstripe/silverstripe-framework/blob/master/src/ORM/FieldType/DBFloat.php
BSD-3-Clause
public function setOptions(array $options = []) { parent::setOptions($options); if (array_key_exists('nullifyEmpty', $options ?? [])) { $this->options['nullifyEmpty'] = (bool) $options['nullifyEmpty']; } if (array_key_exists('default', $options ?? [])) { $this->setDefaultValue($options['default']); } return $this; }
Update the optional parameters for this field. @param array $options Array of options The options allowed are: <ul><li>"nullifyEmpty" This is a boolean flag. True (the default) means that empty strings are automatically converted to nulls to be stored in the database. Set it to false to ensure that nulls and empty strings are kept intact in the database. </li></ul> @return $this
setOptions
php
silverstripe/silverstripe-framework
src/ORM/FieldType/DBString.php
https://github.com/silverstripe/silverstripe-framework/blob/master/src/ORM/FieldType/DBString.php
BSD-3-Clause
public function setNullifyEmpty($value) { $this->options['nullifyEmpty'] = (bool) $value; return $this; }
Set whether this field stores empty strings rather than converting them to null. @param $value boolean True if empty strings are to be converted to null @return $this
setNullifyEmpty
php
silverstripe/silverstripe-framework
src/ORM/FieldType/DBString.php
https://github.com/silverstripe/silverstripe-framework/blob/master/src/ORM/FieldType/DBString.php
BSD-3-Clause
public function getNullifyEmpty() { return !empty($this->options['nullifyEmpty']); }
Get whether this field stores empty strings rather than converting them to null @return boolean True if empty strings are to be converted to null
getNullifyEmpty
php
silverstripe/silverstripe-framework
src/ORM/FieldType/DBString.php
https://github.com/silverstripe/silverstripe-framework/blob/master/src/ORM/FieldType/DBString.php
BSD-3-Clause
public function LimitCharacters($limit = 20, $add = false) { $value = $this->Plain(); if (mb_strlen($value ?? '') <= $limit) { return $value; } return $this->addEllipsis(mb_substr($value ?? '', 0, $limit), $add); }
Limit this field's content by a number of characters. This makes use of strip_tags() to avoid malforming the HTML tags in the string of text. @param int $limit Number of characters to limit by @param string|false $add Ellipsis to add to the end of truncated string @return string
LimitCharacters
php
silverstripe/silverstripe-framework
src/ORM/FieldType/DBString.php
https://github.com/silverstripe/silverstripe-framework/blob/master/src/ORM/FieldType/DBString.php
BSD-3-Clause
public function LimitCharactersToClosestWord($limit = 20, $add = false) { // Safely convert to plain text $value = $this->Plain(); // Determine if value exceeds limit before limiting characters if (mb_strlen($value ?? '') <= $limit) { return $value; } // Limit to character limit $value = mb_substr($value ?? '', 0, $limit); // If value exceeds limit, strip punctuation off the end to the last space and apply ellipsis $value = $this->addEllipsis( preg_replace( '/[^\w_]+$/', '', mb_substr($value ?? '', 0, mb_strrpos($value ?? '', " ")) ), $add ); return $value; }
Limit this field's content by a number of characters and truncate the field to the closest complete word. All HTML tags are stripped from the field. @param int $limit Number of characters to limit by @param string|false $add Ellipsis to add to the end of truncated string @return string Plain text value with limited characters
LimitCharactersToClosestWord
php
silverstripe/silverstripe-framework
src/ORM/FieldType/DBString.php
https://github.com/silverstripe/silverstripe-framework/blob/master/src/ORM/FieldType/DBString.php
BSD-3-Clause
public function LimitWordCount($numWords = 26, $add = false) { $value = $this->Plain(); $words = explode(' ', $value ?? ''); if (count($words ?? []) <= $numWords) { return $value; } // Limit $words = array_slice($words ?? [], 0, $numWords); return $this->addEllipsis(implode(' ', $words), $add); }
Limit this field's content by a number of words. @param int $numWords Number of words to limit by. @param false $add Ellipsis to add to the end of truncated string. @return string
LimitWordCount
php
silverstripe/silverstripe-framework
src/ORM/FieldType/DBString.php
https://github.com/silverstripe/silverstripe-framework/blob/master/src/ORM/FieldType/DBString.php
BSD-3-Clause
public function LowerCase() { return mb_strtolower($this->RAW() ?? ''); }
Converts the current value for this StringField to lowercase. @return string Text with lowercase (HTML for some subclasses)
LowerCase
php
silverstripe/silverstripe-framework
src/ORM/FieldType/DBString.php
https://github.com/silverstripe/silverstripe-framework/blob/master/src/ORM/FieldType/DBString.php
BSD-3-Clause
public function UpperCase() { return mb_strtoupper($this->RAW() ?? ''); }
Converts the current value for this StringField to uppercase. @return string Text with uppercase (HTML for some subclasses)
UpperCase
php
silverstripe/silverstripe-framework
src/ORM/FieldType/DBString.php
https://github.com/silverstripe/silverstripe-framework/blob/master/src/ORM/FieldType/DBString.php
BSD-3-Clause
public function Plain() { return trim($this->RAW() ?? ''); }
Plain text version of this string @return string Plain text
Plain
php
silverstripe/silverstripe-framework
src/ORM/FieldType/DBString.php
https://github.com/silverstripe/silverstripe-framework/blob/master/src/ORM/FieldType/DBString.php
BSD-3-Clause
public function getBaseClass() { // Use explicit base class if ($this->baseClass) { return $this->baseClass; } // Default to the basename of the record $schema = DataObject::getSchema(); if ($this->record) { return $schema->baseDataClass($this->record); } // During dev/build only the table is assigned $tableClass = $schema->tableClass($this->getTable()); if ($tableClass && ($baseClass = $schema->baseDataClass($tableClass))) { return $baseClass; } // Fallback to global default return DataObject::class; }
Get the base dataclass for the list of subclasses @return string
getBaseClass
php
silverstripe/silverstripe-framework
src/ORM/FieldType/DBClassNameTrait.php
https://github.com/silverstripe/silverstripe-framework/blob/master/src/ORM/FieldType/DBClassNameTrait.php
BSD-3-Clause
public function getShortName() { $value = $this->getValue(); if (empty($value) || !ClassInfo::exists($value)) { return null; } return ClassInfo::shortName($value); }
Get the base name of the current class Useful as a non-fully qualified CSS Class name in templates. @return string|null
getShortName
php
silverstripe/silverstripe-framework
src/ORM/FieldType/DBClassNameTrait.php
https://github.com/silverstripe/silverstripe-framework/blob/master/src/ORM/FieldType/DBClassNameTrait.php
BSD-3-Clause
public function getEnum() { $classNames = ClassInfo::subclassesFor($this->getBaseClass()); $dataobject = strtolower(DataObject::class); unset($classNames[$dataobject]); return array_values($classNames ?? []); }
Get list of classnames that should be selectable @return array
getEnum
php
silverstripe/silverstripe-framework
src/ORM/FieldType/DBClassNameTrait.php
https://github.com/silverstripe/silverstripe-framework/blob/master/src/ORM/FieldType/DBClassNameTrait.php
BSD-3-Clause
protected function parseTime($value) { // Skip empty values if (empty($value) && !is_numeric($value)) { return null; } // Determine value to parse if (is_array($value)) { $source = $value; // parse array } elseif (is_numeric($value)) { $source = $value; // parse timestamp } else { // Convert using strtotime $source = strtotime($value ?? ''); } if ($value === false) { return false; } // Format as iso8601 $formatter = $this->getFormatter(); $formatter->setPattern($this->getISOFormat()); return $formatter->format($source); }
Parse timestamp or iso8601-ish date into standard iso8601 format @param mixed $value @return string|null|false Formatted time, null if empty but valid, or false if invalid
parseTime
php
silverstripe/silverstripe-framework
src/ORM/FieldType/DBTime.php
https://github.com/silverstripe/silverstripe-framework/blob/master/src/ORM/FieldType/DBTime.php
BSD-3-Clause
public function getFormatter($timeLength = IntlDateFormatter::MEDIUM) { return IntlDateFormatter::create(i18n::get_locale(), IntlDateFormatter::NONE, $timeLength); }
Get date / time formatter for the current locale @param int $timeLength @return IntlDateFormatter
getFormatter
php
silverstripe/silverstripe-framework
src/ORM/FieldType/DBTime.php
https://github.com/silverstripe/silverstripe-framework/blob/master/src/ORM/FieldType/DBTime.php
BSD-3-Clause
public function Format($format) { if (!$this->value) { return null; } $formatter = $this->getFormatter(); $formatter->setPattern($format); return $formatter->format($this->getTimestamp()); }
Return the time using a particular formatting string. @param string $format Format code string. See https://unicode-org.github.io/icu/userguide/format_parse/datetime @return string The time in the requested format
Format
php
silverstripe/silverstripe-framework
src/ORM/FieldType/DBTime.php
https://github.com/silverstripe/silverstripe-framework/blob/master/src/ORM/FieldType/DBTime.php
BSD-3-Clause
public function FormatFromSettings($member = null) { if (!$member) { $member = Security::getCurrentUser(); } // Fall back to nice if (!$member) { return $this->Nice(); } // Get user format $format = $member->getTimeFormat(); return $this->Format($format); }
Return a time formatted as per a CMS user's settings. @param Member $member @return string A time formatted as per user-defined settings.
FormatFromSettings
php
silverstripe/silverstripe-framework
src/ORM/FieldType/DBTime.php
https://github.com/silverstripe/silverstripe-framework/blob/master/src/ORM/FieldType/DBTime.php
BSD-3-Clause
public function getISOFormat() { return DBTime::ISO_TIME; }
Get standard ISO time format string @return string
getISOFormat
php
silverstripe/silverstripe-framework
src/ORM/FieldType/DBTime.php
https://github.com/silverstripe/silverstripe-framework/blob/master/src/ORM/FieldType/DBTime.php
BSD-3-Clause
public function getClassValue() { return $this->getField('Class'); }
Get the value of the "Class" this key points to @return string Name of a subclass of DataObject
getClassValue
php
silverstripe/silverstripe-framework
src/ORM/FieldType/DBPolymorphicForeignKey.php
https://github.com/silverstripe/silverstripe-framework/blob/master/src/ORM/FieldType/DBPolymorphicForeignKey.php
BSD-3-Clause
public function setClassValue($value, $markChanged = true) { $this->setField('Class', $value, $markChanged); }
Set the value of the "Class" this key points to @param string $value Name of a subclass of DataObject @param boolean $markChanged Mark this field as changed?
setClassValue
php
silverstripe/silverstripe-framework
src/ORM/FieldType/DBPolymorphicForeignKey.php
https://github.com/silverstripe/silverstripe-framework/blob/master/src/ORM/FieldType/DBPolymorphicForeignKey.php
BSD-3-Clause
public function getIDValue() { return $this->getField('ID'); }
Gets the value of the "ID" this key points to @return integer
getIDValue
php
silverstripe/silverstripe-framework
src/ORM/FieldType/DBPolymorphicForeignKey.php
https://github.com/silverstripe/silverstripe-framework/blob/master/src/ORM/FieldType/DBPolymorphicForeignKey.php
BSD-3-Clause
public function setIDValue($value, $markChanged = true) { $this->setField('ID', $value, $markChanged); }
Sets the value of the "ID" this key points to @param integer $value @param boolean $markChanged Mark this field as changed?
setIDValue
php
silverstripe/silverstripe-framework
src/ORM/FieldType/DBPolymorphicForeignKey.php
https://github.com/silverstripe/silverstripe-framework/blob/master/src/ORM/FieldType/DBPolymorphicForeignKey.php
BSD-3-Clause
public function __construct($name = null, $options = []) { $this->name = $name; if ($options) { if (!is_array($options)) { throw new InvalidArgumentException("Invalid options $options"); } $this->setOptions($options); } parent::__construct(); }
Provide the DBField name and an array of options, e.g. ['index' => true], or ['nullifyEmpty' => false] @param string $name @param array $options @throws InvalidArgumentException If $options was passed by not an array
__construct
php
silverstripe/silverstripe-framework
src/ORM/FieldType/DBField.php
https://github.com/silverstripe/silverstripe-framework/blob/master/src/ORM/FieldType/DBField.php
BSD-3-Clause
public static function create_field($spec, $value, $name = null, ...$args) { // Raise warning if inconsistent with DataObject::dbObject() behaviour // This will cause spec args to be shifted down by the number of provided $args if ($args && strpos($spec ?? '', '(') !== false) { trigger_error('Additional args provided in both $spec and $args', E_USER_WARNING); } // Ensure name is always first argument array_unshift($args, $name); /** @var DBField $dbField */ $dbField = Injector::inst()->createWithArgs($spec, $args); $dbField->setValue($value, null, false); return $dbField; }
Create a DBField object that's not bound to any particular field. Useful for accessing the classes behaviour for other parts of your code. @param string $spec Class specification to construct. May include both service name and additional constructor arguments in the same format as DataObject.db config. @param mixed $value value of field @param string $name Name of field @param mixed $args Additional arguments to pass to constructor if not using args in service $spec Note: Will raise a warning if using both @return static
create_field
php
silverstripe/silverstripe-framework
src/ORM/FieldType/DBField.php
https://github.com/silverstripe/silverstripe-framework/blob/master/src/ORM/FieldType/DBField.php
BSD-3-Clause
public function setName($name) { if ($this->name && $this->name !== $name) { user_error("DBField::setName() shouldn't be called once a DBField already has a name." . "It's partially immutable - it shouldn't be altered after it's given a value.", E_USER_WARNING); } $this->name = $name; return $this; }
Set the name of this field. The name should never be altered, but it if was never given a name in the first place you can set a name. If you try an alter the name a warning will be thrown. @param string $name @return $this
setName
php
silverstripe/silverstripe-framework
src/ORM/FieldType/DBField.php
https://github.com/silverstripe/silverstripe-framework/blob/master/src/ORM/FieldType/DBField.php
BSD-3-Clause
public function getDefaultValue() { return $this->defaultVal; }
Get default value assigned at the DB level @return mixed
getDefaultValue
php
silverstripe/silverstripe-framework
src/ORM/FieldType/DBField.php
https://github.com/silverstripe/silverstripe-framework/blob/master/src/ORM/FieldType/DBField.php
BSD-3-Clause
public function setDefaultValue($defaultValue) { $this->defaultVal = $defaultValue; return $this; }
Set default value to use at the DB level @param mixed $defaultValue @return $this
setDefaultValue
php
silverstripe/silverstripe-framework
src/ORM/FieldType/DBField.php
https://github.com/silverstripe/silverstripe-framework/blob/master/src/ORM/FieldType/DBField.php
BSD-3-Clause
public function setOptions(array $options = []) { $this->options = $options; return $this; }
Update the optional parameters for this field @param array $options Array of options @return $this
setOptions
php
silverstripe/silverstripe-framework
src/ORM/FieldType/DBField.php
https://github.com/silverstripe/silverstripe-framework/blob/master/src/ORM/FieldType/DBField.php
BSD-3-Clause
public function exists() { return (bool)$this->value; }
Determines if the field has a value which is not considered to be 'null' in a database context. @return boolean
exists
php
silverstripe/silverstripe-framework
src/ORM/FieldType/DBField.php
https://github.com/silverstripe/silverstripe-framework/blob/master/src/ORM/FieldType/DBField.php
BSD-3-Clause
public function prepValueForDB($value) { if ($value === null || $value === "" || $value === false || ($this->scalarValueOnly() && !is_scalar($value)) ) { return null; } else { return $value; } }
Return the transformed value ready to be sent to the database. This value will be escaped automatically by the prepared query processor, so it should not be escaped or quoted at all. @param mixed $value The value to check @return mixed The raw value, or escaped parameterised details
prepValueForDB
php
silverstripe/silverstripe-framework
src/ORM/FieldType/DBField.php
https://github.com/silverstripe/silverstripe-framework/blob/master/src/ORM/FieldType/DBField.php
BSD-3-Clause
public function addToQuery(&$query) { }
Add custom query parameters for this field, mostly SELECT statements for multi-value fields. By default, the ORM layer does a SELECT <tablename>.* which gets you the default representations of all columns. @param SQLSelect $query
addToQuery
php
silverstripe/silverstripe-framework
src/ORM/FieldType/DBField.php
https://github.com/silverstripe/silverstripe-framework/blob/master/src/ORM/FieldType/DBField.php
BSD-3-Clause