.

DBFieldDateTime Class Reference
[Model]

A date and time field in DB. More...

Inheritance diagram for DBFieldDateTime:
DBField IDBField IPolicyHolder DBFieldDate DBFieldTime

List of all members.

Public Member Functions

  convert_result ($value)
  Transform result from SELECT to native.
  format ($value)
  Reformat passed value to DB format.
  format_select ()
  Allow replacements for field in select from clause.
  format_where ($value)
  Format for use in WHERE clause.
  get_field_default ()
  Returns the default value for this field.
  validate ($value)
  Returns true, if the value passed fits the fields restrictions.

Public Attributes

const  NOW = 'now'
const  TIMESTAMP = 32

Protected Member Functions

  format_date_value ($value)
  Formats a value for use in DB.
  get_db_now_constant ()
  Returns fucntion or constant to set current time in DB (like NOW() or CURRENT_TIMESTAMP).

Detailed Description

A date and time field in DB.

Author:
Gerd Riesselmann

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


Member Function Documentation

DBFieldDateTime::convert_result ( value  ) 

Transform result from SELECT to native.

Parameters:
mixed  $value
Returns:
mixed

Reimplemented from DBField.

Definition at line 121 of file dbfield.datetime.cls.php.

00121                                                {
00122                 return is_null($value) ? null : GyroDate::datetime($value);
00123         }       
DBFieldDateTime::format ( value  ) 

Reformat passed value to DB format.

Parameters:
mixed  $value
Returns:
string

Reimplemented from DBField.

Definition at line 34 of file dbfield.datetime.cls.php.

00034                                        {
00035                 if ($this->has_policy(self::TIMESTAMP)) {
00036                         return 'DEFAULT';        
00037                 }
00038                 
00039                 // Treat '', false and 0 as NULL in updates and inserts
00040                 if (empty($value)) {
00041                         return $this->do_format_null(null);
00042                 }
00043                 else {
00044                         return $this->format_where($value);
00045                 }
00046         }
DBFieldDateTime::format_date_value ( value  )  [protected]

Formats a value for use in DB.

Parameters:
datetime  $value
Returns:
string

Reimplemented in DBFieldDate, and DBFieldTime.

Definition at line 104 of file dbfield.datetime.cls.php.

00104                                                      {
00105                 return $this->quote(GyroDate::mysql_date($value));      
00106         }
DBFieldDateTime::format_select (  ) 

Allow replacements for field in select from clause.

Reimplemented from DBField.

Reimplemented in DBFieldTime.

Definition at line 111 of file dbfield.datetime.cls.php.

00111                                         {
00112                 return 'UNIX_TIMESTAMP(' . parent::format_select() . ')';       
00113         }
DBFieldDateTime::format_where ( value  ) 

Format for use in WHERE clause.

Parameters:
mixed  $value
Returns:
string

Reimplemented from DBField.

Definition at line 54 of file dbfield.datetime.cls.php.

00054                                              {
00055                 if ($this->is_null($value)) {
00056                         return parent::format($value);
00057                 }
00058                 else if ($value == self::NOW) {
00059                         return $this->get_db_now_constant();
00060                 } 
00061                 else {
00062                         return $this->format_date_value(GyroDate::datetime($value));;
00063                 }
00064         }       
DBFieldDateTime::get_db_now_constant (  )  [protected]

Returns fucntion or constant to set current time in DB (like NOW() or CURRENT_TIMESTAMP).

Returns:
string

Reimplemented in DBFieldDate, and DBFieldTime.

Definition at line 94 of file dbfield.datetime.cls.php.

00094                                                  {
00095                 return 'CURRENT_TIMESTAMP';
00096         }
DBFieldDateTime::get_field_default (  ) 

Returns the default value for this field.

Returns:
mixed

Reimplemented from DBField.

Definition at line 17 of file dbfield.datetime.cls.php.

00017                                             {
00018                 if ($this->has_policy(self::TIMESTAMP)) {
00019                         return null; // Timestamps are managed entirely by DB
00020                 }
00021                 $ret = parent::get_field_default();
00022                 if ($ret == self::NOW) {
00023                         $ret = time();
00024                 }
00025                 return $ret;            
00026         }
DBFieldDateTime::validate ( value  ) 

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

Parameters:
mixed  $value
Returns:
Status

Reimplemented from DBField.

Definition at line 72 of file dbfield.datetime.cls.php.

00072                                          {
00073                 $ret = parent::validate($value);
00074                 if ($ret->is_ok()) {
00075                         $test = GyroDate::datetime($value);
00076                         if ($test === false) {
00077                                 $ret->append(tr(
00078                                         '%field must be a date and time value', 
00079                                         'core', 
00080                                         array(
00081                                                 '%field' => $this->get_field_name_translation()
00082                                         )
00083                                 ));
00084                         }
00085                 }
00086                 return $ret;
00087         }       

Member Data Documentation

const DBFieldDateTime::NOW = 'now'

Definition at line 9 of file dbfield.datetime.cls.php.

Definition at line 10 of file dbfield.datetime.cls.php.


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