Source for file datetimefield.php

Documentation is available at datetimefield.php

  1. <?php
  2. /**
  3. * a textfield designed for date-time data
  4. *
  5. @author    Stuart Prescott
  6. @copyright  Copyright Stuart Prescott
  7. @license    http://opensource.org/licenses/gpl-license.php GNU Public License
  8. @version    $Id$
  9. @package    Bumblebee
  10. @subpackage FormsLibrary
  11. */
  12.  
  13. /** Load ancillary functions */
  14. require_once 'inc/typeinfo.php';
  15.  
  16. /** parent object */
  17. require_once 'field.php';
  18. /** type checking and data manipulation */
  19. require_once 'inc/typeinfo.php';
  20. /** contains a timefield object */
  21. require_once 'timefield.php';
  22. /** contains a timefield object */
  23. require_once 'datefield.php';
  24. /** date storage types */
  25. require_once 'inc/date.php';
  26. /** timeslot manipulation and validation object */
  27. require_once 'inc/bookings/timeslotrule.php';
  28.  
  29. /**
  30. * a textfield designed for date-time data
  31. *
  32. @package    Bumblebee
  33. @subpackage FormsLibrary
  34. */
  35. class DateTimeField extends Field {
  36.   /** @var SimpleTime time part of the field  */
  37.   var $time;
  38.   /** @var boolean   time part is editable  */
  39.   var $timeeditable;
  40.   /** @var SimpleDate date part of the field  */
  41.   var $date;
  42.   /** @var boolean   date part is editable  */
  43.   var $dateeditable;
  44.   /** @var array     list of possible choices for the day  */
  45.   var $list;
  46.  
  47.   /** @var integer   current representation of the time part (TF_* defines in TimeField class  */
  48.   var $representation;
  49.   /** @var integer   manually specified representation of the time part (TF_* defines in TimeField class  */
  50.   var $_manualRepresentation = TF_AUTO;
  51.  
  52.     /**
  53.   *  Create a new datetimefield object
  54.   *
  55.   * @param string $name   the name of the field (db name, and html field name
  56.   * @param string $longname  long name to be used in the label of the field in display
  57.   * @param string $description  used in the html title or longdesc for the field
  58.   */
  59. function DateTimeField($name$longname=''$description=''{
  60.     parent::Field($name$longname$description);
  61.     //$this->DEBUG=10;
  62.     $this->time = new TimeField($name.'-time'$longname$description);
  63.     $this->time->isStart true;
  64.     $this->date = new DateField($name.'-date'$longname$description);
  65.   }
  66.  
  67.   function displayInTable($cols=3{
  68.     $errorclass ($this->isValid ? '' "class='inputerror'");
  69.     $t "<tr $errorclass><td>$this->longname</td>\n"
  70.         ."<td title='$this->description'>";
  71.     if ($this->editable && $this->hidden{
  72.       $t .= $this->selectable();
  73.     else {
  74.       if (!$this->hidden$t .= xssqw($this->getValue());
  75.       $t .= $this->hidden();
  76.     }
  77.     if ($this->duplicateName{
  78.       $t .= "<input type='hiddenname='$this->duplicateName"
  79.              ."value='".xssqw($this->value)."' />";
  80.     }
  81.     $t .= "</td>\n";
  82.     for ($i=0$i<$cols-2$i++{
  83.       $t .= '<td></td>';
  84.     }
  85.     $t .= '</tr>';
  86.     return $t;
  87.   }
  88.  
  89.   function selectable({
  90.     //preDump($this->time);
  91.     //echo "Assembling date-time field\ndate";
  92.     $t  $this->date->getdisplay();
  93.     $t .= ' ';
  94.     //echo "Assembling date-time field\ntime";
  95.     $t .= $this->time->getdisplay();
  96.     return $t;
  97.   }
  98.  
  99.   function hidden({
  100.     return $this->date->hidden(.' '$this->time->hidden();
  101.   }
  102.  
  103.   /**
  104.   * calculate the correct values for the separate (and possibly not editable!) parts of the field
  105.   */
  106.   function calcDateTimeParts({
  107.     $val ($this->getValue(== ''$this->getValue();
  108.     #echo "datetime=$val\n";
  109.     $this->time->setDateTime($val);
  110.     $this->date->setDate($val);
  111.     $this->value = $this->date->value .' '$this->time->value;
  112.   }
  113.  
  114.   /**
  115.   * overload the parent's value as we need to do some magic in here
  116.   */
  117.   function set($value{
  118.     #echo "V=$value\n";
  119.     parent::set($value);
  120.     $this->calcDateTimeParts();
  121.   }
  122.  
  123.   /**
  124.   * overload the parent's update method so that local calculations can be performed
  125.   *
  126.   * @param array $data html_name => value pairs
  127.   *
  128.   * @return boolean the value was updated
  129.   */
  130.   function update($data{
  131.     $datechanged $this->date->update($data);
  132.     $timechanged $this->time->update($data);
  133.     if ($datechanged || $timechanged{
  134.       $this->log('DateTimeField::update');
  135.       $data[$this->namebase.$this->name$this->date->value .' '$this->time->value;
  136.       parent::update($data);
  137. //       $this->calcDateTimeParts();
  138.     }
  139.     return $this->changed;
  140.   }
  141.  
  142.   /**
  143.   * associate a TimeSlotRule for validation of the times that we are using
  144.   *
  145.   * @param TimeSlotRule $list a TimeSlotRule
  146.   */
  147.   function setSlots($list{
  148.     $this->list = $list;
  149.     $this->time->setSlots($list);
  150.     $this->calcDateTimeParts();
  151.   }
  152.  
  153.   /**
  154.   * set the appropriate date that we are refering to for the timeslot rule validation
  155.   *
  156.   * @param string $date passed to the TimeSlotRule
  157.    */
  158.   function setSlotStart($date{
  159.     $this->time->setSlotStart($date);
  160.   }
  161.  
  162.   /**
  163.   * pass on any flags about the representation that we should use to our members
  164.   *
  165.   * @param integer $flag (TF_* types from class TimeField constants)
  166.   */
  167.   function setManualRepresentation($flag{
  168.     $this->_manualRepresentation = $flag;
  169.     $this->time->setManualRepresentation($flag);
  170.   }
  171.  
  172.   /**
  173.   *  isValid test (extend Field::isValid), looking at the individual parts of the field
  174.   */
  175.   function isValid({
  176.     parent::isValid();
  177.     $this->isValid = $this->isValid && $this->date->isValid(&& $this->time->isValid();
  178.     return $this->isValid;
  179.   }
  180.  
  181.   /**
  182.   * Set the date and time parts of the field and mark them as editable
  183.   *
  184.   * @param SimpleDate  $date  new date part of the field
  185.   * @param SimpleTime  $time  new time part of the field
  186.   */
  187.   function setEditableOutput($date$time{
  188.     $this->dateeditable = $date;
  189.     $this->date->editableOutput $date;
  190.     $this->timeeditable = $time;
  191.     $this->time->editableOutput $time;
  192.   }
  193.  
  194.   /**
  195.   * return a SQL-injection-cleansed string that can be used in an SQL
  196.   * UPDATE or INSERT statement. i.e. "name='Stuart'".
  197.   *
  198.   * @return string  in SQL assignable form
  199.   */
  200.   function sqlSetStr($name=''$force=false{
  201.     if (empty($name)) {
  202.       $name $this->name;
  203.     }
  204.     if ($this->sqlHidden{
  205.       $date new SimpleDate($this->getValue());
  206.       return $name .'='qw($date->dateTimeString());
  207.     else {
  208.       return '';
  209.     }
  210.   }
  211.  
  212.  
  213.  
  214. // class DateTimeField
  215.  
  216.  
  217. ?>

Documentation generated on Tue, 06 Mar 2007 10:01:15 +0000 by phpDocumentor 1.3.0