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() {
|
|
|
|
DB::requireField($this->tableName, $this->name, "varchar($this->size) character set utf8 collate utf8_general_ci");
|
|
|
|
}
|
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] . '.';
|
|
|
|
}
|
|
|
|
|
|
|
|
function Attr() {
|
|
|
|
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 forTemplate() {
|
|
|
|
return $this->raw2HTML();
|
|
|
|
}*/
|
|
|
|
|
|
|
|
function LowerCase() {
|
|
|
|
return Convert::raw2xml(strtolower($this->value));
|
|
|
|
}
|
|
|
|
|
|
|
|
function LimitCharacters($limit = 20, $add = "...") {
|
|
|
|
$value = trim($this->value);
|
|
|
|
return (strlen($value) > $limit) ? substr($value, 0, $limit) . $add : $value;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
?>
|