00001 <?php
00002
00003
00004
00005
00006
00007
00008
00009
00010 class DBFieldText extends DBField {
00011 const BLOB_LENGTH_LARGE = 4294967295;
00012 const BLOB_LENGTH_MEDIUM = 16777215;
00013 const BLOB_LENGTH_SMALL = 65535;
00014
00015
00016
00017
00018
00019 protected $length = 255;
00020
00021 public function __construct($name, $length = 255, $default_value = null, $policy = self::NONE) {
00022 parent::__construct($name, $default_value, $policy);
00023 $this->length = $length;
00024 }
00025
00026
00027
00028
00029
00030
00031
00032 public function validate($value) {
00033 $ret = new Status();
00034 $l = String::length(Cast::string($value));
00035 if ($l > $this->length) {
00036 $ret->append(tr(
00037 '%field may have no more than %num character',
00038 'core',
00039 array(
00040 '%field' => $this->get_field_name_translation(),
00041 '%num' => $this->length
00042 )
00043 ));
00044 }
00045 else if ($l == 0 && !$this->get_null_allowed()) {
00046 $ret->append(tr(
00047 '%field may not be empty',
00048 'core',
00049 array(
00050 '%field' => $this->get_field_name_translation(),
00051 )
00052 ));
00053 }
00054 return $ret;
00055 }
00056
00057 public function get_length() {
00058 return $this->length;
00059 }
00060 }