Source for file timefield.php
Documentation is available at timefield.php
* a textfield widget designed to handle time date
* @author Stuart Prescott
* @copyright Copyright Stuart Prescott
* @license http://opensource.org/licenses/gpl-license.php GNU Public License
* @subpackage FormsLibrary
/** Load ancillary functions */
require_once 'inc/typeinfo.php';
require_once 'field.php';
/** Time field is in "FIXED" (uneditable) format */
/** Time field is in "DROP" (dropdown list) format */
/** Time field is in "FREE" (type-in text box) format */
/** Time field is in "FREE" (type-in text box) format always */
/** Time field is in "AUTO" (any of the above as appropriate) format */
* a textfield widget designed to handle time date
* @subpackage FormsLibrary
/** @var SimpleTime time object for this field */
/** @var TimeSlotRule rules for the times that are permitted */
/** @var boolean field is the start time of a slot object */
/** @var SimpleDate the date on which this time is located */
/** @var TimeSlot the actual time slot to which this time is associated */
/** @var integer how this field is to be rendered (see TF_* options) */
/** @var integer force this field to be rendered in a particular way (see TF_* options) */
/** @var DropList DropList object for dropdown list representation of the field */
/** @var boolean is the time *really* editable ... ?? FIXME */
/** @var integer maximum number of booking slots to include in the dropdown */
/** @var boolean go beyond the end of the slots that are part of a group for booking */
/** @var integer max period to be included in the dropdown in seconds */
/** @var SimpleDate max date for the dropdown to go to */
* Create a new field object, designed to be superclasses
* @param string $name the name of the field (db name, and html field name
* @param string $longname long name to be used in the label of the field in display
* @param string $description used in the html title or longdesc for the field
function TimeField($name, $longname=
'', $description=
'') {
parent::Field($name, $longname, $description);
$errorclass =
($this->isValid ?
'' :
"class='inputerror'");
$t =
"<tr $errorclass><td>$this->longname</td>\n"
$t .=
$this->getdisplay();
for ($i=
0; $i<
$cols-
2; $i++
) {
* render the HTML version of the widget
#echo "TIME=".$this->time->timeString()."\n";
$t .=
"<span id='$fixedname'>";
$t .=
"<span id='$varname' style='display: none'>";
* set the representation of this field
* @param integer $flag (TF_* types from class TimeField constants)
$this->log("Manual representation set to $flag",10);
* Determine what sort of representation is appropriate
if (! isset
($this->slot) &&
$this->slot !=
0) {
$this->log('No slot found, TF_FIXED');
$this->log('Slot manually set');
} elseif ($this->slot->isFreeForm) {
/* } elseif ($this->isStart || $this->slot->numslotsFollowing < 1) {
$this->log('Starting slot or none following, TF_FIXED');
$this->representation = TF_FIXED;*/
//$this->log($this->slot->start->ticks.' + '.$duration->ticks.' != '.$this->slot->stop->ticks);
$this->log('Not exactly following slots, TF_FIXED');
* Calculate data for the dropdown list of permissible times
$ends =
$this->slot->allSlotEnds();
$nextStart =
$ends[count($ends)-
1];
#echo "Looking for next start. ";
#echo $nextStart->dateTimeString()." ";
#echo "Limit is ". $this->maxDateDropDown->dateTimeString()."<br />";
// this should never really happen....
$nextStart =
$nextSlot->stop;
if (! $nextSlot->isAvailable) {
#echo "Not available <br />";
#echo "Past max allowable ".$nextSlot->stop->dateTimeString()."<br />";
#echo "Conflicting with booking ".$nextSlot->stop->dateTimeString()."<br />";
$ends[] =
$nextSlot->stop;
#echo "Got an end: ". $nextSlot->stop->dateTimeString() ." ";
#echo $d->datetimeString() . " -- ".$duration->timestring()."<br />";
$dropVals[$duration->timeString()] =
sprintf(T_("%s (until %s)"), $duration->timeString(), $d->datetimeString());
$this->droplist->setValuesArray($dropVals, 'id', 'iv');
$this->droplist->setFormat('id', '%s', array('iv'));
//for ($j = count($durations)-1; $j >=0 && $durations[$j] != $this->value; $j--) {
//$this->droplist->setDefault($j);
* @param string $append append this to the name of the input (optional)
* @param string $hidden show this as hidden by default
* @return string html for field
$t =
"<input type='text' name='{$this->namebase}{
$this->name}$append'
"
$t .=
(isset
($this->attr['size']) ?
"size='".
$this->attr['size'].
"' " :
"");
$t .=
(isset
($this->attr['maxlength']) ?
"maxlength='".
$this->attr['maxlength'].
"' " :
"");
$t .=
($hidden) ?
"style='display: none;' " :
"";
* Convert a string into a js link that controls the behaviour of another div
* @param string $id1 default shown element
* @param string $id2 default hidden element
* @return string html for js link
function _makeHiddenSwitch($id1, $id2) {
$func = preg_replace('/[^\w]/', '_', "hideunhide$id1");
<input type='hidden' id='{
$this->namebase}{
$this->name}-
switch'
name='{
$this->namebase}{
$this->name}-
switch'
value='' />
<
script type='
text/
javascript'>
var switchfield = document.getElementById('{
$this->namebase}{
$this->name}-
switch');
switchfield.
value = '
varfield';
<a href='javascript:$func();'>".T_('edit times')."</a>
* determine if a dropdown list appropriate here?
function _fixedTimeSlots() {
$this->fixedTimeSlots =
false;
$this->fixedTimeSlots =
$this->slot->numslotsFollowing;
.
', numFollowing: '.
$this->fixedTimeSlots, 8);
return $this->fixedTimeSlots;
* overload the parent's set() method as we need to do some extra processing
if (strpos($value, '-') === false) {
* overload the parent's update method so that local calculations can be performed
* @param array $data html_name => value pairs
* @return boolean the value was updated
if (parent::update($data)) {
* Set the time (and value) from a Date-Time string
* @param string $time a date-time string (YYYY-MM-DD HH:MM:SS)
function setDateTime($time) {
#echo "SETDATETIME = $time\n";
$date = new SimpleDate($time);
* Set the time (and value)
* @param string $time a time string (HH:MM)
function setTime($time) {
#echo "SETTIME = $time\n";
$this->time =
new SimpleTime($time);
* associate a TimeSlotRule for validation of the times that we are using
* @param TimeSlotRule $list a valid TimeSlotRule
function setSlots($list) {
* set the appropriate date that we are refering to for the timeslot rule validation
* @param string $date passed to the TimeSlotRule
function setSlotStart($date) {
$this->slotStart =
new SimpleDate($date);
function _findExactSlot() {
$this->log('Found slot start '.
$this->slot->start->dateTimeString(), 10);
$this->log('Found slot stop '.
$this->slot->stop->dateTimeString(), 10);
/* if ($this->slot == '0') {
$this->slot = $this->list->findSlotFromWithin($this->slotStart);
* isValid test (extend Field::isValid), looking at whether the string parsed OK
* return a SQL-injection-cleansed string that can be used in an SQL
* UPDATE or INSERT statement. i.e. "name='Stuart'".
* @return string in SQL assignable form
function sqlSetStr($name='', $force=false) {
Documentation generated on Tue, 06 Mar 2007 10:02:02 +0000 by phpDocumentor 1.3.0