classes/scheduler/TimeBlockDAO.inc.php

Go to the documentation of this file.
00001 <?php
00002 
00018 import('scheduler.TimeBlock');
00019 
00020 class TimeBlockDAO extends DAO {
00026    function &getTimeBlock($timeBlockId) {
00027       $result =& $this->retrieve(
00028          'SELECT * FROM time_blocks WHERE time_block_id = ?', $timeBlockId
00029       );
00030 
00031       $returner = null;
00032       if ($result->RecordCount() != 0) {
00033          $returner =& $this->_returnTimeBlockFromRow($result->GetRowAssoc(false));
00034       }
00035       $result->Close();
00036       return $returner;
00037    }
00038 
00044    function getTimeBlockSchedConfId($timeBlockId) {
00045       $result =& $this->retrieve(
00046          'SELECT sched_conf_id FROM time_blocks WHERE time_block_id = ?', $timeBlockId
00047       );
00048 
00049       return isset($result->fields[0]) ? $result->fields[0] : 0;
00050    }
00051 
00058    function timeBlockExistsForSchedConf($timeBlockId, $schedConfId) {
00059       $result =& $this->retrieve(
00060          'SELECT  COUNT(*)
00061          FROM  time_blocks
00062          WHERE time_block_id = ?
00063          AND   sched_conf_id = ?',
00064          array(
00065             $timeBlockId,
00066             $schedConfId
00067          )
00068       );
00069       $returner = isset($result->fields[0]) && $result->fields[0] != 0 ? true : false;
00070 
00071       $result->Close();
00072       unset($result);
00073 
00074       return $returner;
00075    }
00076 
00082    function timeBlocksExistForSchedConf($schedConfId) {
00083       $result =& $this->retrieve(
00084          'SELECT  COUNT(*)
00085          FROM  time_blocks
00086          WHERE sched_conf_id = ?',
00087          array($schedConfId)
00088       );
00089       $returner = isset($result->fields[0]) && $result->fields[0] != 0 ? true : false;
00090 
00091       $result->Close();
00092       unset($result);
00093 
00094       return $returner;
00095    }
00096 
00101    function getLocaleFieldNames() {
00102       return array('name', 'description');
00103    }
00104 
00110    function &_returnTimeBlockFromRow(&$row) {
00111       $timeBlock = new TimeBlock();
00112       $timeBlock->setId($row['time_block_id']);
00113       $timeBlock->setSchedConfId($row['sched_conf_id']);
00114       $timeBlock->setStartTime($this->datetimeFromDB($row['start_time']));
00115       $timeBlock->setEndTime($this->datetimeFromDB($row['end_time']));
00116       $timeBlock->setAssignedColour($row['assigned_colour']);
00117       $timeBlock->setUnassignedColour($row['unassigned_colour']);
00118       $this->getDataObjectSettings('time_block_settings', 'time_block_id', $row['time_block_id'], $timeBlock);
00119       return $timeBlock;
00120    }
00121 
00126    function updateLocaleFields(&$timeBlock) {
00127       $this->updateDataObjectSettings('time_block_settings', $timeBlock, array(
00128          'time_block_id' => $timeBlock->getId()
00129       ));
00130    }
00131 
00137    function insertTimeBlock(&$timeBlock) {
00138       $this->update(
00139          sprintf('INSERT INTO time_blocks (
00140                sched_conf_id,
00141                start_time,
00142                end_time, assigned_colour,
00143                unassigned_colour
00144             ) VALUES (?, %s, %s, ?, ?)',
00145             $this->datetimeToDB($timeBlock->getStartTime()),
00146             $this->datetimeToDB($timeBlock->getEndTime())
00147          ), array(
00148             $timeBlock->getSchedConfId(),
00149             $timeBlock->getAssignedColour(),
00150             $timeBlock->getUnassignedColour()
00151          )
00152       );
00153       $timeBlock->setId($this->getInsertTimeBlockId());
00154       $this->updateLocaleFields($timeBlock);
00155       return $timeBlock->getId();
00156    }
00157 
00163    function updateTimeBlock(&$timeBlock) {
00164       $returner = $this->update(
00165          sprintf('UPDATE   time_blocks
00166             SET   sched_conf_id = ?,
00167                start_time = %s,
00168                end_time = %s,
00169                assigned_colour = ?,
00170                unassigned_colour = ?
00171             WHERE time_block_id = ?',
00172             $this->datetimeToDB($timeBlock->getStartTime()),
00173             $this->datetimeToDB($timeBlock->getEndTime())
00174          ), array(
00175             $timeBlock->getSchedConfId(),
00176             $timeBlock->getAssignedColour(),
00177             $timeBlock->getUnassignedColour(),
00178             $timeBlock->getId()
00179          )
00180       );
00181       $this->updateLocaleFields($timeBlock);
00182       return $returner;
00183    }
00184 
00190    function deleteTimeBlock($timeBlock) {
00191       return $this->deleteTimeBlockById($timeBlock->getId());
00192    }
00193 
00199    function deleteTimeBlockById($timeBlockId) {
00200       $this->update('DELETE FROM time_block_settings WHERE time_block_id = ?', $timeBlockId);
00201       $this->update('DELETE FROM time_block_settings WHERE time_block_id = ?', $timeBlockId);
00202       return $this->update('DELETE FROM time_blocks WHERE time_block_id = ?', $timeBlockId);
00203    }
00204 
00209    function deleteTimeBlocksBySchedConfId($schedConfId) {
00210       $timeBlocks =& $this->getTimeBlocksBySchedConfId($schedConfId);
00211       while (($timeBlock =& $timeBlocks->next())) {
00212          $this->deleteTimeBlock($timeBlock);
00213          unset($timeBlock);
00214       }
00215    }
00216 
00222    function &getTimeBlocksBySchedConfId($schedConfId, $rangeInfo = null) {
00223       $result =& $this->retrieveRange(
00224          'SELECT * FROM time_blocks WHERE sched_conf_id = ? ORDER BY start_time',
00225          $schedConfId,
00226          $rangeInfo
00227       );
00228 
00229       $returner = new DAOResultFactory($result, $this, '_returnTimeBlockFromRow');
00230       return $returner;
00231    }
00232 
00237    function getInsertTimeBlockId() {
00238       return $this->getInsertId('time_blocks', 'time_block_id');
00239    }
00240 }
00241 
00242 ?>

Generated on 25 Jul 2013 for Open Conference Systems by  doxygen 1.4.7