2007-07-19 12:40:28 +02:00
|
|
|
<?php
|
2008-02-25 03:10:37 +01:00
|
|
|
/**
|
|
|
|
* Represents a short text field.
|
|
|
|
* @package sapphire
|
|
|
|
* @subpackage model
|
|
|
|
*/
|
2007-07-19 12:40:28 +02:00
|
|
|
class Varchar extends DBField {
|
2008-08-09 04:00:40 +02:00
|
|
|
|
2007-07-19 12:40:28 +02:00
|
|
|
protected $size;
|
|
|
|
|
|
|
|
function __construct($name, $size = 50) {
|
2007-09-09 06:02:54 +02:00
|
|
|
$this->size = $size ? $size : 50;
|
2007-07-19 12:40:28 +02:00
|
|
|
parent::__construct($name);
|
|
|
|
}
|
2008-08-09 08:29:50 +02:00
|
|
|
|
2007-07-19 12:40:28 +02:00
|
|
|
function requireField() {
|
2008-11-23 02:01:03 +01:00
|
|
|
$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);
|
2007-07-19 12:40:28 +02:00
|
|
|
}
|
2008-08-09 04:00:40 +02:00
|
|
|
|
|
|
|
function hasValue() {
|
|
|
|
return ($this->value || $this->value == '0');
|
|
|
|
}
|
|
|
|
|
2007-07-19 12:40:28 +02:00
|
|
|
/**
|
|
|
|
* Return the first letter of the string followed by a .
|
|
|
|
*/
|
|
|
|
function Initial() {
|
|
|
|
if($this->value) return $this->value[0] . '.';
|
|
|
|
}
|
|
|
|
|
2008-09-28 15:13:16 +02:00
|
|
|
/**
|
|
|
|
* @deprecated 2.3 Use ATT_val()
|
|
|
|
*/
|
2007-07-19 12:40:28 +02:00
|
|
|
function Attr() {
|
2008-10-08 23:33:43 +02:00
|
|
|
user_error("Varchar::Attr() is deprecated. Use ATT_val() instead.", E_USER_NOTICE);
|
2007-07-19 12:40:28 +02:00
|
|
|
return Convert::raw2att($this->value);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-02-02 00:49:53 +01:00
|
|
|
?>
|