| [ PHPXref.com ] | [ Generated: Sun Jul 20 16:45:19 2008 ] | [ Bumblebee 1.0.4 ] |
| [ Index ] [ Variables ] [ Functions ] [ Classes ] [ Constants ] [ Statistics ] | ||
[Summary view] [Print] [Text view]
1 <?php 2 /** 3 * Instrument object (extends dbo), with extra customisations for other links 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: instrument.php,v 1.23 2006-01-06 10:07:21 stuart Exp $ 9 * @package Bumblebee 10 * @subpackage DBObjects 11 */ 12 13 /** parent object */ 14 require_once 'inc/formslib/dbrow.php'; 15 require_once 'inc/formslib/idfield.php'; 16 require_once 'inc/formslib/textfield.php'; 17 require_once 'inc/formslib/textarea.php'; 18 require_once 'inc/formslib/commentfield.php'; 19 require_once 'inc/formslib/checkbox.php'; 20 require_once 'inc/formslib/radiolist.php'; 21 require_once 'inc/formslib/exampleentries.php'; 22 require_once 'inc/bookings/timeslotrule.php'; 23 24 /** 25 * Instrument object (extends dbo), with extra customisations for other links 26 * 27 * @package Bumblebee 28 * @subpackage DBObjects 29 */ 30 class Instrument extends DBRow { 31 32 var $_slotrule; 33 34 function Instrument($id) { 35 global $CONFIG; 36 //$this->DEBUG=10; 37 $this->DBRow('instruments', $id); 38 $this->editable = 1; 39 $this->deleteFromTable = 0; 40 $f = new IdField('id', 'Instrument ID'); 41 $f->editable = 0; 42 $this->addElement($f); 43 $f = new TextField('name', 'Name'); 44 $attrs = array('size' => '48'); 45 $f->required = 1; 46 $f->isValidTest = 'is_nonempty_string'; 47 $f->setAttr($attrs); 48 $this->addElement($f); 49 $f = new TextField('longname', 'Description'); 50 $f->required = 1; 51 $f->isValidTest = 'is_nonempty_string'; 52 $f->setAttr($attrs); 53 $this->addElement($f); 54 $f = new TextField('location', 'Location'); 55 $f->required = 1; 56 $f->isValidTest = 'is_nonempty_string'; 57 $f->setAttr($attrs); 58 $this->addElement($f); 59 $f = new TextField('usualopen', 'Calendar start time (HH:MM)'); 60 $f->required = 1; 61 $f->defaultValue = $CONFIG['instruments']['usualopen']; 62 $f->isValidTest = 'is_valid_time'; 63 $f->setAttr($attrs); 64 $this->addElement($f); 65 $f = new TextField('usualclose', 'Calendar end time (HH:MM)'); 66 $f->required = 1; 67 $f->defaultValue = $CONFIG['instruments']['usualclose']; 68 $f->isValidTest = 'is_valid_time'; 69 $f->setAttr($attrs); 70 $this->addElement($f); 71 $f = new TextField('calprecision', 'Precision of calendar display (seconds)'); 72 $f->required = 1; 73 $f->defaultValue = $CONFIG['instruments']['usualprecision']; 74 $f->isValidTest = 'is_number'; 75 $f->setAttr($attrs); 76 $this->addElement($f); 77 $f = new TextField('caltimemarks', 'Time-periods per HH:MM displayed'); 78 $f->required = 1; 79 $f->defaultValue = $CONFIG['instruments']['usualtimemarks']; 80 $f->isValidTest = 'is_number'; 81 $f->setAttr($attrs); 82 $this->addElement($f); 83 $f = new TextField('callength', 'Number of weeks displayed in calendar'); 84 $f->required = 1; 85 $f->defaultValue = $CONFIG['instruments']['usualcallength']; 86 $f->isValidTest = 'is_number'; 87 $f->setAttr($attrs); 88 $this->addElement($f); 89 $f = new TextField('calhistory', 'Number of weeks history shown'); 90 $f->required = 1; 91 $f->defaultValue = $CONFIG['instruments']['usualcalhistory']; 92 $f->isValidTest = 'is_number'; 93 $f->setAttr($attrs); 94 $this->addElement($f); 95 $f = new TextField('calfuture', 'Number of days into the future'); 96 $f->required = 1; 97 $f->defaultValue = $CONFIG['instruments']['usualcalfuture']; 98 $f->isValidTest = 'is_number'; 99 $f->setAttr($attrs); 100 $this->addElement($f); 101 $f = new TextArea('calendarcomment', 'Advisory text', 'Displayed at the bottom of instrument calendar and on booking form. HTML permitted.'); 102 $f->setAttr(array('rows' =>5, 'cols' => 30)); 103 $f->required = 0; 104 $this->addElement($f); 105 106 // associate with a charging class 107 $f = new RadioList('class', 'Charging class'); 108 $f->connectDB('instrumentclass', array('id', 'name')); 109 $classexample = new ExampleEntries('id','instruments','class','name',3); 110 $classexample->separator = '; '; 111 $f->setFormat('id', '%s', array('name'), ' (%40.40s)', $classexample); 112 $newclassname = new TextField('name',''); 113 $newclassname->namebase = 'newclass-'; 114 $newclassname->setAttr(array('size' => 24)); 115 $newclassname->isValidTest = 'is_nonempty_string'; 116 $newclassname->suppressValidation = 0; 117 $f->list->append(array('-1','Create new: '), $newclassname); 118 $f->setAttr($attrs); 119 $f->extendable = 1; 120 $f->required = 1; 121 $f->isValidTest = 'is_valid_radiochoice'; 122 $this->addElement($f); 123 $f = new TextField('halfdaylength', 'Hours in a half-day'); 124 $f->required = 1; 125 $f->defaultValue = $CONFIG['instruments']['usualhalfdaylength']; 126 $f->isValidTest = 'is_number'; 127 $f->setAttr($attrs); 128 $this->addElement($f); 129 $f = new TextField('fulldaylength', 'Hours in a full-day'); 130 $f->required = 1; 131 $f->defaultValue = $CONFIG['instruments']['usualfulldaylength']; 132 $f->isValidTest = 'is_number'; 133 $f->setAttr($attrs); 134 $this->addElement($f); 135 136 // create the timeslot rule information required 137 $f = new CommentField('timeslotpicturecomment', 'Instrument timeslots', 138 'These fields describe when the instrument is available. '); 139 $f->value = 'Format: HH:MM-HH:MM/n-x%,comment'; 140 $this->addElement($f); 141 $f = new TextField('timeslotpicture', 'Time slot picture'); 142 $f->required = 1; 143 $f->hidden = 1; 144 $f->defaultValue = $CONFIG['instruments']['usualtimeslotpicture']; 145 $f->isValidTest = 'is_set'; 146 $f->setAttr($attrs); 147 $this->addElement($f); 148 $weekstart = new SimpleDate(time()); 149 $weekstart->weekRound(); 150 for ($day=0; $day<7; $day++) { 151 $today = $weekstart; 152 $today->addDays($day); 153 $f = new TextArea('tsr-'.$day, $today->dowStr(), 'Slots in day, one per line'); 154 $f->sqlHidden = 1; 155 $f->setAttr(array('rows' =>3, 'cols' => 30)); 156 $f->required = 1; 157 $this->addElement($f); 158 } 159 160 $f = new TextField('mindatechange', 'Minimum notice for booking change (hours)'); 161 $f->required = 1; 162 $f->defaultValue = $CONFIG['instruments']['usualmindatechange']; 163 $f->isValidTest = 'is_number'; 164 $f->setAttr($attrs); 165 $this->addElement($f); 166 $f = new TextField('supervisors', 'Instrument supervisors', 'comma separated list of usernames'); 167 $f->required = 0; 168 $f->setAttr($attrs); 169 $this->addElement($f); 170 $f = new CheckBox('emailonbooking', 'Email supervisors when booking'); 171 $f->defaultValue = 0; 172 $f->setAttr($attrs); 173 $this->addElement($f); 174 175 $this->fill(); 176 $this->dumpheader = 'Instrument object'; 177 } 178 179 function fill() { 180 parent::fill(); 181 //now edit the time slot representation fields 182 $this->_calcSlotRepresentation(); 183 } 184 185 function sync() { 186 //first construct a timeslot field from the submitted data, then do the sync 187 $newslotrule = $this->_calcNewSlotRule(); 188 if ($this->fields['timeslotpicture']->value != $newslotrule /*&& $this->id > -1*/) { 189 $this->log('Instrument::sync(): indulging in timeslotrule munging: <br />'. 190 $newslotrule .'<br/>'.$this->fields['timeslotpicture']->value); 191 $this->fields['timeslotpicture']->set($newslotrule); 192 $this->fields['timeslotpicture']->changed = 1; 193 $this->changed = $this->changed || ($this->id > -1); 194 // reflect back the data, this is good for checking that it's right, as TimeSlotRule 195 // will drop bits it doesn't understand or doesn't like. 196 //$this->_calcSlotRepresentation(); 197 } else { 198 //? 199 } 200 //$this->DEBUG=10; 201 return parent::sync(); 202 } 203 204 function _calcSlotRepresentation() { 205 $this->_slotrule = new TimeSlotRule($this->fields['timeslotpicture']->getValue()); 206 for ($day=0; $day<7; $day++) { 207 $this->fields['tsr-'.$day]->value = ''; 208 //preDump($this->_slotrule->slots[$day]); 209 $prevpicture = ''; 210 foreach ($this->_slotrule->slots[$day] as $key => $slot) { 211 if (is_numeric($key) && $slot->picture != $prevpicture) { 212 $prevpicture = $slot->picture; 213 //preDump($slot); 214 $this->log('Added picture '. $slot->picture); 215 $this->fields['tsr-'.$day]->value .= $slot->picture."\n"; 216 } 217 } 218 } 219 } 220 221 function _calcNewSlotRule() { 222 $newslot = ''; 223 for ($day=0; $day<7; $day++) { 224 //preDump($this->fields['tsr-'.$day]->value); 225 $lines = preg_split('/[\n\r]+/', $this->fields['tsr-'.$day]->value); 226 // get rid of blanks 227 $lines = preg_grep('/^\s*$/', $lines,PREG_GREP_INVERT); 228 $rejects = preg_grep('{^\d\d:\d\d\-\d\d:\d\d/(\d+|\*)(\-\d+%)?(,.+)?$}', $lines,PREG_GREP_INVERT); 229 if (count($rejects) > 0) { 230 //then this input is invalid 231 $this->fields['tsr-'.$day]->isValid = 0; 232 $this->isValid = 0; 233 //preDump($rejects); 234 } 235 $newslot .= '['.$day.']<'.join($lines,';').'>'; 236 $this->log('Calculated picture '. $newslot); 237 } 238 return $newslot; 239 } 240 241 function display() { 242 return $this->displayAsTable(); 243 } 244 245 } //class Instrument
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
| [ Powered by PHPXref - Served by Debian GNU/Linux ] |