.

DBFieldInt Class Reference
[Model]

A integer field in DB. More...

Inheritance diagram for DBFieldInt:
DBField IDBField IPolicyHolder

List of all members.

Public Member Functions

  __construct ($name, $default_value=0, $policy=self::NOT_NULL)
  get_field_default ()
  Returns the default value for this field.
  has_default_value ()
  Returns true, if field has default value.
  validate ($value)
  Returns true, if the value passed fits the fields restrictions.

Public Attributes

const  AUTOINCREMENT = 4
  This field is autoincremented.
const  FOREIGN_KEY = 3
  Convenience declaration: Combines UNSIGNED, and NOT_NULL.
const  PRIMARY_KEY = 7
  Convenience declaration: Combines AUTOINCREMENT, UNSIGNED, and NOT_NULL.
const  UNSIGNED = 2
  This field is unsigned.

Protected Member Functions

  do_format_not_null ($value)
  Format values that are not NULL.

Detailed Description

A integer field in DB.

Author:
Gerd Riesselmann

Definition at line 8 of file dbfield.int.cls.php.


Constructor & Destructor Documentation

DBFieldInt::__construct ( name,
default_value = 0,
policy = self::NOT_NULL  
)

Definition at line 27 of file dbfield.int.cls.php.

00027                                                                                        {
00028                 parent::__construct($name, $default_value, $policy);
00029         }

Member Function Documentation

DBFieldInt::do_format_not_null ( value  )  [protected]

Format values that are not NULL.

Parameters:
mixed  $value
Returns:
string

Reimplemented from DBField.

Definition at line 95 of file dbfield.int.cls.php.

00095                                                       {
00096                 return Cast::int($value);
00097         }
DBFieldInt::get_field_default (  ) 

Returns the default value for this field.

Returns:
mixed

Reimplemented from DBField.

Definition at line 36 of file dbfield.int.cls.php.

00036                                             {
00037                 if ($this->has_policy(self::AUTOINCREMENT)) {
00038                         return null;
00039                 }
00040                 return parent::get_field_default();
00041         }       
DBFieldInt::has_default_value (  ) 

Returns true, if field has default value.

Reimplemented from DBField.

Definition at line 84 of file dbfield.int.cls.php.

00084                                             {
00085                 $ret = $this->has_policy(self::AUTOINCREMENT) || parent::has_default_value();
00086                 return $ret;
00087         }
DBFieldInt::validate ( value  ) 

Returns true, if the value passed fits the fields restrictions.

Parameters:
string  $value
Returns:
Status

Reimplemented from DBField.

Definition at line 49 of file dbfield.int.cls.php.

00049                                          {
00050                 if ($value === '') {
00051                         $value = null;
00052                 }
00053                 
00054                 $ret = parent::validate($value);
00055                 if ($ret->is_ok() && !is_null($value)) {
00056                         if ($this->has_policy(self::UNSIGNED)) {
00057                                 if (!Validation::is_int($value, 0)) {
00058                                         $ret->append(tr(
00059                                                 '%field must be a positive integer', 
00060                                                 'core', 
00061                                                 array(
00062                                                         '%field' => $this->get_field_name_translation()
00063                                                 )
00064                                         ));
00065                                 }
00066                         }
00067                         else if (!Validation::is_int($value)) {
00068                                 $ret->append(tr(
00069                                         '%field must be an integer', 
00070                                         'core', 
00071                                         array(
00072                                                 '%field' => $this->get_field_name_translation()
00073                                         )
00074                                 ));
00075                         }
00076                 }
00077                 
00078                 return $ret;
00079         }

Member Data Documentation

This field is autoincremented.

Definition at line 12 of file dbfield.int.cls.php.

Convenience declaration: Combines UNSIGNED, and NOT_NULL.

Definition at line 25 of file dbfield.int.cls.php.

Convenience declaration: Combines AUTOINCREMENT, UNSIGNED, and NOT_NULL.

Definition at line 21 of file dbfield.int.cls.php.

This field is unsigned.

Definition at line 16 of file dbfield.int.cls.php.


The documentation for this class was generated from the following file: