Orion PHP  0.11.12
The PHP5.3 framework
string.php
Go to the documentation of this file.
00001 <?php
00002 namespace Orion\Core\Model;
00003 
00004 use \Orion\Core;
00005 
00006 class String extends Field
00007 {
00008     protected $length;
00009     protected $regex;
00010 
00011     public function __construct($bind='string', $label='String', $length=255, $regex=null, $required=false, $primary=false)
00012     {
00013         $this->type = 'string';
00014         $this->bind = $bind;
00015         $this->label = $label;
00016         $this->length = $length;
00017         $this->regex = $regex;
00018         $this->required = $required;
00019         $this->primary = $primary;
00020     }
00021 
00022         public function validate($value)
00023         {
00024         if($value == null) return true;
00025         
00026                 if($this->length != null && strlen($value) > $this->length)
00027                         return false;
00028                 elseif($this->regex != null && !Core\Tools::match($value, $this->regex))
00029             return false;
00030         
00031                 return true;
00032         }
00033 
00034     public function prepare($value)
00035     {
00036                 return "'".$value."'";
00037     }
00038 
00039     public function toHtml($XHTML=true)
00040     {
00041         if($XHTML)
00042             $tag = ' /';
00043         else
00044             $tag = '';
00045 
00046         return '<div class="form-row"><label for="'.$this->bind.'">'.$this->label.'</label><div class="form-container"><input name="'.$this->bind.'" type="text" class="form-text" value="'.$this->value.'"'.$tag.'></div></div>';
00047     }
00048 }
00049 
00050 ?>