diff --git a/core/model/fieldtypes/Boolean.php b/core/model/fieldtypes/Boolean.php index b8ff85d3b46..cb4b155e0f0 100644 --- a/core/model/fieldtypes/Boolean.php +++ b/core/model/fieldtypes/Boolean.php @@ -1,6 +1,7 @@ + * static $db = array( + * "Price" => "Currency", + * "Tax" => "Currency(5)", + * ); + * * * @deprecated 2.5 Use Money class * @@ -11,6 +19,9 @@ class Currency extends Decimal { protected static $currencySymbol = '$'; + /** + * Returns the number as a currency, eg “$1,000.00”. + */ function Nice() { // return "value\">$" . number_format($this->value, 2) . ''; $val = self::$currencySymbol . number_format(abs($this->value), 2); @@ -18,6 +29,9 @@ function Nice() { else return $val; } + /** + * Returns the number as a whole-number currency, eg “$1,000”. + */ function Whole() { $val = self::$currencySymbol . number_format(abs($this->value), 0); if($this->value < 0) return "($val)"; diff --git a/core/model/fieldtypes/DBField.php b/core/model/fieldtypes/DBField.php index 316e30c1328..db8e821bd21 100755 --- a/core/model/fieldtypes/DBField.php +++ b/core/model/fieldtypes/DBField.php @@ -3,13 +3,26 @@ * Single field in the database. * Every field from the database is represented as a sub-class of DBField. * - *

Multi-value DBField objects

+ * Multi-value DBField objects + * * Sometimes you will want to make DBField classes that don't have a 1-1 match to database fields. To do this, there are a * number of fields for you to overload. * - Overload {@link writeToManipulation} to add the appropriate references to the INSERT or UPDATE command * - Overload {@link addToQuery} to add the appropriate items to a SELECT query's field list * - Add appropriate accessor methods * + * Subclass Example + * + * The class is easy to overload with custom types, e.g. the MySQL "BLOB" type (http://dev.mysql.com/doc/refman/5.0/en/blob.html). + * + * + * class Blob extends DBField { + * function requireField() { + * DB::requireField($this->tableName, $this->name, "blob"); + * } + * } + * + * * @package sapphire * @subpackage model */ diff --git a/core/model/fieldtypes/Date.php b/core/model/fieldtypes/Date.php index 7b63d836f9f..e7925171fd5 100644 --- a/core/model/fieldtypes/Date.php +++ b/core/model/fieldtypes/Date.php @@ -6,6 +6,13 @@ * Alternatively you can set a timestamp that is evaluated through * PHP's built-in date() function according to your system locale. * + * Example definition via {@link DataObject::$db}: + * + * static $db = array( + * "Expires" => "Date", + * ); + * + * * @todo Add localization support, see http://open.silverstripe.com/ticket/2931 * * @package sapphire @@ -41,6 +48,9 @@ function Nice() { if($this->value) return date('d/m/Y', strtotime($this->value)); } + /** + * Returns the date in US format: “01/18/2006” + */ function NiceUS() { if($this->value) return date('m/d/Y', strtotime($this->value)); } @@ -91,7 +101,7 @@ function Full() { /** * Return the date using a particular formatting string. * - * @param string $format Format code string. e.g. "d M Y" + * @param string $format Format code string. e.g. "d M Y" (see http://php.net/date) * @return string The date in the requested format */ function Format($format) { diff --git a/core/model/fieldtypes/Datetime.php b/core/model/fieldtypes/Datetime.php index 2f63bd8b194..371ce4c4a28 100644 --- a/core/model/fieldtypes/Datetime.php +++ b/core/model/fieldtypes/Datetime.php @@ -11,6 +11,13 @@ * methods. This ensures that all time-based computations are testable with mock dates * through {@link SS_Datetime::set_mock_now()}. * + * Example definition via {@link DataObject::$db}: + * + * static $db = array( + * "Expires" => "SSDatetime", + * ); + * + * * @todo Add localization support, see http://open.silverstripe.com/ticket/2931 * * @package sapphire @@ -31,6 +38,9 @@ function setValue($value) { } } + /** + * Returns the date in the raw SQL-format, e.g. “2006-01-18 16:32:04” + */ function Nice() { return date('d/m/Y g:ia', strtotime($this->value)); } diff --git a/core/model/fieldtypes/Enum.php b/core/model/fieldtypes/Enum.php index f0014cdaf73..591abb095a9 100755 --- a/core/model/fieldtypes/Enum.php +++ b/core/model/fieldtypes/Enum.php @@ -1,6 +1,8 @@ "Enum('Val1, Val2, Val3', 'Val1')" - * or: "MyField" => "Enum(Array('Val1', 'Val2', 'Val3'), 'Val1')" - * but NOT: "MyField" => "Enum('Val1', 'Val2', 'Val3', 'Val1')" + * + * Example usage in {@link DataObject::$db} with comma-separated string notation ('Val1' is default) + * + * "MyField" => "Enum('Val1, Val2, Val3', 'Val1')" + * + * + * Example usage in in {@link DataObject::$db} with array notation ('Val1' is default) + * + * "MyField" => "Enum(array('Val1', 'Val2', 'Val3'), 'Val1')" + * + * * @param enum: A string containing a comma separated list of options or an array of Vals. * @param default The default option, which is either NULL or one of the items in the enumeration. */ diff --git a/core/model/fieldtypes/Float.php b/core/model/fieldtypes/Float.php index e01c981ea58..cf33493c198 100644 --- a/core/model/fieldtypes/Float.php +++ b/core/model/fieldtypes/Float.php @@ -1,6 +1,7 @@ tableName, $this->name, $values); } + /** + * Returns the number, with commas and decimal places as appropriate, eg “1,000.00”. + * + * @uses number_format() + */ function Nice() { return number_format($this->value, 2); } diff --git a/core/model/fieldtypes/HTMLText.php b/core/model/fieldtypes/HTMLText.php index 331e9d17157..47fea31c441 100755 --- a/core/model/fieldtypes/HTMLText.php +++ b/core/model/fieldtypes/HTMLText.php @@ -1,8 +1,12 @@ value); } diff --git a/core/model/fieldtypes/Percentage.php b/core/model/fieldtypes/Percentage.php index f5817f27f30..b6d533bade8 100644 --- a/core/model/fieldtypes/Percentage.php +++ b/core/model/fieldtypes/Percentage.php @@ -1,6 +1,15 @@ + * static $db = array( + * "SuccessRatio" => "Percentage", + * "ReallyAccurate" => "Percentage(6)", + * ); + * + * * @package sapphire * @subpackage model */ @@ -15,6 +24,9 @@ function __construct($name, $precision = 4) { parent::__construct($name, $precision + 1, $precision); } + /** + * Returns the number, expressed as a percentage. For example, “36.30%” + */ function Nice() { return number_format($this->value * 100, $this->decimalSize - 2) . '%'; } diff --git a/core/model/fieldtypes/Text.php b/core/model/fieldtypes/Text.php index 4386f687146..38d42ba7fb1 100644 --- a/core/model/fieldtypes/Text.php +++ b/core/model/fieldtypes/Text.php @@ -1,6 +1,18 @@ + * static $db = array( + * "MyDescription" => "Text", + * ); + * + * + * @see HTMLText + * @see HTMLVarchar + * @see Varchar + * * @package sapphire * @subpackage model */ diff --git a/core/model/fieldtypes/Time.php b/core/model/fieldtypes/Time.php index f484606a23f..c146be5ea5e 100755 --- a/core/model/fieldtypes/Time.php +++ b/core/model/fieldtypes/Time.php @@ -2,6 +2,13 @@ /** * Represents a column in the database with the type 'Time'. * + * Example definition via {@link DataObject::$db}: + * + * static $db = array( + * "StartTime" => "Time", + * ); + * + * * @todo Add localization support, see http://open.silverstripe.com/ticket/2931 * * @package sapphire diff --git a/core/model/fieldtypes/Varchar.php b/core/model/fieldtypes/Varchar.php index 65f77997c35..1d308638c4a 100644 --- a/core/model/fieldtypes/Varchar.php +++ b/core/model/fieldtypes/Varchar.php @@ -1,6 +1,11 @@ false). See {@link StringField::setOptions()} for information on the available options