mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-09-19 16:06:32 +02:00
ed39a9e369
git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/sapphire/trunk@77380 467b73ca-7a2a-4603-9d3b-597d59a354a9
51 lines
1.2 KiB
PHP
51 lines
1.2 KiB
PHP
<?php
|
|
/**
|
|
* Represents a short text field.
|
|
* @package sapphire
|
|
* @subpackage model
|
|
*/
|
|
class Varchar extends DBField {
|
|
|
|
protected $size;
|
|
|
|
function __construct($name, $size = 50) {
|
|
$this->size = $size ? $size : 50;
|
|
parent::__construct($name);
|
|
}
|
|
|
|
function requireField() {
|
|
$parts=Array('datatype'=>'varchar', 'precision'=>$this->size, 'character set'=>'utf8', 'collate'=>'utf8_general_ci');
|
|
$values=Array('type'=>'varchar', 'parts'=>$parts);
|
|
DB::requireField($this->tableName, $this->name, $values);
|
|
}
|
|
|
|
function hasValue() {
|
|
return ($this->value || $this->value == '0');
|
|
}
|
|
|
|
/**
|
|
* Return the first letter of the string followed by a .
|
|
*/
|
|
function Initial() {
|
|
if($this->value) return $this->value[0] . '.';
|
|
}
|
|
|
|
/**
|
|
* Ensure that the given value is an absolute URL.
|
|
*/
|
|
function URL() {
|
|
if(ereg('^[a-zA-Z]+://', $this->value)) return $this->value;
|
|
else return "http://" . $this->value;
|
|
}
|
|
|
|
function RTF() {
|
|
return str_replace("\n", '\par ', $this->value);
|
|
}
|
|
|
|
function LimitCharacters($limit = 20, $add = "...") {
|
|
$value = trim($this->value);
|
|
return (strlen($value) > $limit) ? substr($value, 0, $limit) . $add : $value;
|
|
}
|
|
}
|
|
|
|
?>
|