mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-09-18 07:26:40 +02:00
26b8f7dffe
Inform-merge: from the changeset: r32477: Merge 2.0-inform from trunk previously r32478: Merge 2.0-inform from trunk previously r32481: merge 2.0infom with lastes chunk r32483: merge 2.0infom with lastes chunk r33526: Final styling of all forms and combined communication form add/alter javascript for height adjustment of First / Second block r33580: styling for combined form communication in myinfom pages r33706: styling of combined form (communication) in Email r33881: made compatible to $extraClass r33885: added defaultVal r33887: fixed typo r34728: modified SmallFieldHolder?() r34729: added "validationError"-class r34914: WIP3866: Factfinder: Hide "self emplyed" block r34964: Change current plan upto TraumaInsurance? r35038: disabled friggin field focus r35230: #1032 Fixed hash-link insertion r35887: conditionally setting parameters in sourceID() - to avoid empty overrides r35892: Saving value in SQL-compatible format (YYYY-MM-DD instead of DD/MM/YYYY), with fallback for non-sql values (just passed through without conversion) r35928: Removed "create a" from PageType?-dropdown, sorting alphabetically, falling back to $singular_name r35990: branched off for membertablefield r35994: fix for membertablefield r36024: added array-condition needed for DMYDateField r36083: fix bug for compositeField -> dropDatalessField r36394: removed debug code r36826: change wrong indent format r36828: WIP 4262: Logging out of My Inform goes to blank page r36858: Fixed error caused in r12472 while merging to Session-class r37132: Merged partial changesets from branches/2.0-nzct, only adding childID to detailform when not in add-mode r40815: add an unsubscribe record when a member subscribe a newslettertype r41113: fix the bug described in http://support.silverstripe.com/info/ticket/31: CRM not showing search results r43226: fixed search (partial merge from trunk) r43268: merged createNewPassword() from trunk, was referencing a non-existinent global function randomString() git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/sapphire/trunk@45473 467b73ca-7a2a-4603-9d3b-597d59a354a9
113 lines
2.3 KiB
PHP
113 lines
2.3 KiB
PHP
<?php
|
|
|
|
/**
|
|
* Single field in the database.
|
|
* Every field from the database is represented as a sub-class of DBField. In addition to supporting
|
|
* the creation of the field in the database,
|
|
*/
|
|
abstract class DBField extends ViewableData {
|
|
|
|
protected $value;
|
|
|
|
protected $tableName;
|
|
|
|
protected $name;
|
|
|
|
/**
|
|
* @var $default mixed Default-value in the database.
|
|
* Might be overridden on DataObject-level, but still useful for setting defaults on
|
|
* already existing records after a db-build.
|
|
*/
|
|
protected $defaultVal;
|
|
|
|
function __construct($name) {
|
|
$this->name = $name;
|
|
|
|
parent::__construct();
|
|
}
|
|
|
|
/**
|
|
* Create a DBField object that's not bound to any particular field.
|
|
* Useful for accessing the classes behaviour for other parts of your code.
|
|
*/
|
|
static function create($className, $value, $name = null) {
|
|
$dbField = Object::create($className, $name);
|
|
$dbField->setValue($value);
|
|
return $dbField;
|
|
}
|
|
|
|
function setVal($value) {
|
|
return $this->setValue($value);
|
|
}
|
|
|
|
function setValue($value) {
|
|
$this->value = $value;
|
|
}
|
|
|
|
function setTable($tableName) {
|
|
$this->tableName = $tableName;
|
|
}
|
|
|
|
function forTemplate() {
|
|
return $this->value;
|
|
}
|
|
|
|
function HTMLATT() {
|
|
return Convert::raw2htmlatt($this->value);
|
|
}
|
|
function ATT() {
|
|
return Convert::raw2att($this->value);
|
|
}
|
|
|
|
function RAW() {
|
|
return $this->value;
|
|
}
|
|
|
|
function JS() {
|
|
return Convert::raw2js($this->value);
|
|
}
|
|
|
|
function HTML(){
|
|
return Convert::raw2xml($this->value);
|
|
}
|
|
|
|
function XML(){
|
|
return Convert::raw2xml($this->value);
|
|
}
|
|
|
|
/**
|
|
* Returns the value to be set in the database to blank this field.
|
|
* Usually it's a choice between null, 0, and ''
|
|
*/
|
|
function nullValue() {
|
|
return "null";
|
|
}
|
|
|
|
/**
|
|
* Saves this field to the given data object.
|
|
*/
|
|
function saveInto($dataObject) {
|
|
$fieldName = $this->name;
|
|
if($fieldName) {
|
|
$dataObject->$fieldName = $this->value;
|
|
} else {
|
|
user_error("DBField::saveInto() Called on a nameless '" . get_class($this) . "' object", E_USER_ERROR);
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Add the field to the underlying database.
|
|
*/
|
|
abstract function requireField();
|
|
|
|
function debug() {
|
|
return <<<DBG
|
|
<ul>
|
|
<li><b>Name:</b>{$this->name}</li>
|
|
<li><b>Table:</b>{$this->tableName}</li>
|
|
<li><b>Value:</b>{$this->value}</li>
|
|
</ul>
|
|
DBG;
|
|
}
|
|
}
|
|
?>
|