Model/Assignment.php

Go to the documentation of this file.
00001 <?php
00003 // {{{ license
00004 
00005 // +----------------------------------------------------------------------+
00006 // | FastFrame Application Framework                                      |
00007 // +----------------------------------------------------------------------+
00008 // | Copyright (c) 2002-2006 The Codejanitor Group                        |
00009 // +----------------------------------------------------------------------+
00010 // | This source file is subject to the GNU Lesser Public License (LGPL), |
00011 // | that is bundled with this package in the file LICENSE, and is        |
00012 // | available at through the world-wide-web at                           |
00013 // | http://www.fsf.org/copyleft/lesser.html                              |
00014 // | If you did not receive a copy of the LGPL and are unable to          |
00015 // | obtain it through the world-wide-web, you can get it by writing the  |
00016 // | Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, |
00017 // | MA 02111-1307, USA.                                                  |
00018 // +----------------------------------------------------------------------+
00019 // | Authors: Jason Rust <jrust@codejanitor.com>                          |
00020 // +----------------------------------------------------------------------+
00021 
00022 // }}}
00023 // {{{ requires
00024 
00025 require_once FASTFRAME_ROOT . 'lib/FastFrame/Model.php';
00026 
00027 // }}}
00028 // {{{ class FF_Model_Assignment
00029 
00042 // }}}
00043 class FF_Model_Assignment extends FF_Model {
00044     // {{{ properties
00045 
00050     var $name;
00051 
00056     var $openTime;
00057 
00062     var $lateTime;
00063 
00068     var $closeTime;
00069 
00074     var $session;
00075 
00080     var $ownerId;
00081 
00086     var $courseCode;
00087 
00092     var $batchIds = array();
00093 
00094     // }}}
00095     // {{{ reset()
00096 
00103     function reset()
00104     {
00105         $this->id = null;
00106         $this->name = null;
00107         $this->openTime = null;
00108         $this->lateTime = null;
00109         $this->closeTime = null;
00110         $this->session = null;
00111         $this->ownerId = null;
00112         $this->courseCode = null;
00113         $this->batchIds = array();
00114     }
00115 
00116     // }}}
00117     // {{{ importFromArray()
00118 
00127     function importFromArray($in_data)
00128     {
00129         $this->setId($in_data['id']);
00130         $this->setName($in_data['name']);
00131         $this->setOpenTime($in_data['open_time']);
00132         $this->setLateTime($in_data['late_time']);
00133         $this->setCloseTime($in_data['close_time']);
00134         $this->setSession($in_data['session']);
00135         $this->setOwnerId($in_data['owner_id']);
00136         $this->setCourseCode($in_data['course_code']);
00137     }
00138 
00139     // }}}
00140     // {{{ exportToArray()
00141 
00150     function exportToArray()
00151     {
00152         $a_data = array();
00153         $a_data['id'] = $this->getId();
00154         $a_data['name'] = $this->getName();
00155         $a_data['open_time'] = $this->getOpenTime();
00156         $a_data['late_time'] = $this->getLateTime();
00157         $a_data['close_time'] = $this->getCloseTime();
00158         $a_data['session'] = $this->getSession();
00159         $a_data['owner_id'] = $this->getOwnerId();
00160         $a_data['course_code'] = $this->getCourseCode();
00161         return $a_data;
00162     }
00163 
00164     // }}}
00165     // {{{ remove()
00166 
00176     function remove($in_id = null)
00177     {
00178         $s_id = is_null($in_id) ? $this->getId() : $in_id;
00179         $o_result =& $this->o_dataAccess->remove($s_id);
00180         // Remove the associated ftp files
00181         $o_registry =& FF_Registry::singleton();
00182         $s_path = $o_registry->getConfigParam('ftp/data_dir');
00183         if ($o_result->isSuccess() && !empty($s_path)) {
00184             require_once 'System.php';
00185             $s_path .= '/' . $s_id;
00186             @System::rm("-r $s_path");
00187         }
00188 
00189         return $o_result;
00190     }
00191 
00192     // }}}
00193     // {{{ batchEdit()
00194 
00203     function &batchEdit($in_action)
00204     {
00205         $o_result = new FF_Result();
00206         if ($in_action == 'copy') {
00207             $o_model =& new FF_Model_Assignment();
00208             foreach ($this->batchIds as $s_id) {
00209                 $o_model->reset();
00210                 if (!$o_model->fillById($s_id)) {
00211                     $o_result->setSuccess(false);
00212                     $o_result->addMessage(_('Was unable to copy one of the selected assignments'));
00213                     continue;
00214                 }
00215 
00216                 if ($o_model->getCourseCode() == $this->getCourseCode() ||
00217                     FastFrame::isEmpty($this->getCourseCode())) {
00218                     $o_model->setName($o_model->getName() . ' ' . _('[copy]'));
00219                 }
00220 
00221                 if (!FastFrame::isEmpty($this->getCourseCode())) {
00222                     $o_model->setCourseCode($this->getCourseCode());
00223                 }
00224 
00225                 if (!FastFrame::isEmpty($this->getSession())) {
00226                     $o_model->setSession($this->getSession());
00227                 }
00228 
00229                 if ($this->getLateTime() > 0) {
00230                     $o_model->setLateTime($o_model->getLateTime() + $this->getLateTime() * 86400);
00231                 }
00232 
00233                 if ($this->getOpenTime() > 0 && $o_model->getOpenTime() != 0) {
00234                     $o_model->setOpenTime($o_model->getOpenTime() + $this->getOpenTime() * 86400);
00235                 }
00236                 
00237                 if ($this->getCloseTime() > 0 && $o_model->getCloseTime() != 0) {
00238                     $o_model->setCloseTime($o_model->getCloseTime() + $this->getCloseTime() * 86400);
00239                 }
00240 
00241                 $tmp_result =& $o_model->save(false);
00242                 if (!$tmp_result->isSuccess()) {
00243                     $o_result->setSuccess(false);
00244                     $o_result->addMessage($tmp_result->getMessages());
00245                 }
00246             }
00247         }
00248         else {
00249             if (!FastFrame::isEmpty($this->getCourseCode())) {
00250                 if (!$this->o_dataAccess->updateCourseCodes($this->batchIds, $this->getCourseCode(), $this->getOwnerId())) {
00251                     $o_result->setSuccess(false);
00252                     $o_result->addMessage(_('Unable to update the course codes'));
00253                 }
00254             }
00255 
00256             if (!FastFrame::isEmpty($this->getSession())) {
00257                 if (!$this->o_dataAccess->updateSession($this->batchIds, $this->getSession(), $this->getOwnerId())) {
00258                     $o_result->setSuccess(false);
00259                     $o_result->addMessage(_('Unable to update the session'));
00260                 }
00261             }
00262 
00263             if ($this->getLateTime() > 0) {
00264                 if (!$this->o_dataAccess->updateTimes($this->batchIds, $this->getLateTime() * 86400, $this->getOwnerId(), 'late')) {
00265                     $o_result->setSuccess(false);
00266                     $o_result->addMessage(_('Unable to update the late times'));
00267                 }
00268             }
00269 
00270             if ($this->getOpenTime() > 0) {
00271                 if (!$this->o_dataAccess->updateTimes($this->batchIds, $this->getOpenTime() * 86400, $this->getOwnerId(), 'open')) {
00272                     $o_result->setSuccess(false);
00273                     $o_result->addMessage(_('Unable to update the open times'));
00274                 }
00275             }
00276 
00277             if ($this->getCloseTime() > 0) {
00278                 if (!$this->o_dataAccess->updateTimes($this->batchIds, $this->getCloseTime() * 86400, $this->getOwnerId(), 'close')) {
00279                     $o_result->setSuccess(false);
00280                     $o_result->addMessage(_('Unable to update the close times'));
00281                 }
00282             }
00283         }
00284 
00285         return $o_result;
00286     }
00287 
00288     // }}}
00289     // {{{ setBatchIds()
00290 
00291     function setBatchIds($in_ids)
00292     {
00293         $this->batchIds = (array) $in_ids;
00294     }
00295 
00296     // }}}
00297     // {{{ getDescriptionsById()
00298 
00307     function getDescriptionsById($in_ids) {
00308         return $this->o_dataAccess->getDescriptionsById($in_ids);
00309     }
00310 
00311     // }}}
00312     // {{{ getName()
00313 
00314     function getName()
00315     {
00316         return $this->name;
00317     }
00318 
00319     // }}}
00320     // {{{ setName()
00321 
00322     function setName($in_value)
00323     {
00324         $this->name = $in_value;
00325     }
00326 
00327     // }}}
00328     // {{{ getFormattedOpenTime()
00329 
00330     function getFormattedOpenTime()
00331     {
00332         return empty($this->openTime) ? _('N/A') : date('m/d/Y H:i', $this->openTime);
00333     }
00334 
00335     // }}}
00336     // {{{ getOpenTime()
00337 
00338     function getOpenTime()
00339     {
00340         return $this->openTime;
00341     }
00342 
00343     // }}}
00344     // {{{ setOpenTime()
00345 
00346     function setOpenTime($in_value)
00347     {
00348         $this->openTime = $in_value;
00349     }
00350 
00351     // }}}
00352     // {{{ getFormattedLateTime()
00353 
00354     function getFormattedLateTime()
00355     {
00356         return date('m/d/Y H:i', $this->lateTime);
00357     }
00358 
00359     // }}}
00360     // {{{ getLateTime()
00361 
00362     function getLateTime()
00363     {
00364         return is_null($this->lateTime) ? time() : $this->lateTime;
00365     }
00366 
00367     // }}}
00368     // {{{ setLateTime()
00369 
00370     function setLateTime($in_value)
00371     {
00372         $this->lateTime = $in_value;
00373     }
00374 
00375     // }}}
00376     // {{{ getFormattedCloseTime()
00377 
00378     function getFormattedCloseTime()
00379     {
00380         return empty($this->closeTime) ? _('N/A') : date('m/d/Y H:i', $this->closeTime);
00381     }
00382 
00383     // }}}
00384     // {{{ getCloseTime()
00385 
00386     function getCloseTime()
00387     {
00388         return $this->closeTime;
00389     }
00390 
00391     // }}}
00392     // {{{ setCloseTime()
00393 
00394     function setCloseTime($in_value)
00395     {
00396         $this->closeTime = $in_value;
00397     }
00398 
00399     // }}}
00400     // {{{ getSessionOptions()
00401 
00410     function getSessionOptions($in_addEmpty = false)
00411     {
00412         $a_options = $this->o_dataAccess->getSessionOptions();
00413         if ($in_addEmpty) {
00414             $a_options = array_merge(array('' => ''), $a_options);
00415         }
00416         
00417         return $a_options;
00418     }
00419 
00420     // }}}
00421     // {{{ getSession()
00422 
00423     function getSession()
00424     {
00425         return $this->session;
00426     }
00427 
00428     // }}}
00429     // {{{ setSession()
00430 
00431     function setSession($in_value)
00432     {
00433         $this->session = $in_value;
00434     }
00435 
00436     // }}}
00437     // {{{ getOwnerId()
00438 
00439     function getOwnerId()
00440     {
00441         return $this->ownerId;
00442     }
00443 
00444     // }}}
00445     // {{{ setOwnerId()
00446 
00447     function setOwnerId($in_value)
00448     {
00449         $this->ownerId = $in_value;
00450     }
00451 
00452     // }}}
00453     // {{{ getClassOptions()
00454 
00463     function getClassOptions($in_addEmpty = false)
00464     {
00465         $a_options = $this->o_dataAccess->getClassOptions();
00466         if ($in_addEmpty) {
00467             $a_options = array_merge(array('' => ''), $a_options);
00468         }
00469         
00470         return $a_options;
00471     }
00472 
00473     // }}}
00474     // {{{ getCourseCode()
00475 
00476     function getCourseCode()
00477     {
00478         return $this->courseCode;
00479     }
00480 
00481     // }}}
00482     // {{{ setCourseCode()
00483 
00484     function setCourseCode($in_value)
00485     {
00486         $this->courseCode = $in_value;
00487     }
00488 
00489     // }}}
00490     // {{{ _initDataAccess()
00491 
00498     function _initDataAccess()
00499     {
00500         $this->o_dataAccess =& FF_DataAccess::factory('Assignment');
00501     }
00502 
00503     // }}}
00504 }
00505 ?>

Generated on Fri Jun 23 11:38:14 2006 for FastFrame by  doxygen 1.4.4