Validate/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/Validate.php';
00026 
00027 // }}}
00028 // {{{ class FF_Validate_Assignment
00029 
00039 // }}}
00040 class FF_Validate_Assignment extends FF_Validate {
00041     // {{{ validate()
00042 
00052     function validate($in_isBatch)
00053     {
00054         if ($in_isBatch) {
00055             $this->_validateBatchTimes();
00056         }
00057         else {
00058             $this->_validateId();
00059             $this->_validateName();
00060             $this->_validateTimes();
00061         }
00062         
00063         return $this->o_result;
00064     }
00065 
00066     // }}}
00067     // {{{ _validateId()
00068 
00075     function _validateId()
00076     {
00077         if ($this->isUpdate && FastFrame::isEmpty($this->o_model->getId())) {
00078             $this->o_result->addMessage(_('Id cannot be empty'));
00079             $this->o_result->setSuccess(false);
00080         }
00081     }
00082 
00083     // }}}
00084     // {{{ _validateName()
00085 
00092     function _validateName()
00093     {
00094         if (FastFrame::isEmpty($this->o_model->getName())) {
00095             $this->o_result->addMessage(_('Name cannot be empty'));
00096             $this->o_result->setSuccess(false);
00097         }
00098 
00099         if (preg_match('/[\."\/\\\\*?<>|:]/', $this->o_model->getName())) {
00100             $this->o_result->addMessage(_('The name cannot contain the following characters: . " / \ * ? < > | :'));
00101             $this->o_result->setSuccess(false);
00102         }
00103     }
00104 
00105     // }}}
00106     // {{{ _validateTimes()
00107 
00114     function _validateTimes()
00115     {
00116         if ($this->o_model->getOpenTime() === false) {
00117             $this->o_result->addMessage(_('You must set both a date and time for the Open Date'));
00118             $this->o_result->setSuccess(false);
00119         }
00120 
00121         if ($this->o_model->getLateTime() === false) {
00122             $this->o_result->addMessage(_('You must set both a date and time for the Due Date'));
00123             $this->o_result->setSuccess(false);
00124         }
00125 
00126         if ($this->o_model->getCloseTime() === false) {
00127             $this->o_result->addMessage(_('You must set both a date and time for the Close Date'));
00128             $this->o_result->setSuccess(false);
00129         }
00130 
00131         if (FastFrame::isEmpty($this->o_model->getLateTime())) {
00132             $this->o_result->addMessage(_('Due Date cannot be empty'));
00133             $this->o_result->setSuccess(false);
00134             return;
00135         }
00136 
00137         if (!FastFrame::isEmpty($this->o_model->getOpenTime()) &&
00138             $this->o_model->getOpenTime() >= $this->o_model->getLateTime()) {
00139             $this->o_result->addMessage(_('Open Date must be before the Due Date'));
00140             $this->o_result->setSuccess(false);
00141         }
00142 
00143         if (!FastFrame::isEmpty($this->o_model->getCloseTime()) &&
00144             $this->o_model->getCloseTime() <= $this->o_model->getLateTime()) {
00145             $this->o_result->addMessage(_('Close Date must be after the Due Date'));
00146             $this->o_result->setSuccess(false);
00147         }
00148     }
00149 
00150     // }}}
00151     // {{{ _validateBatchTimes()
00152 
00159     function _validateBatchTimes()
00160     {
00161         if (!FastFrame::isEmpty($this->o_model->getLateTime()) &&
00162             (!is_numeric($this->o_model->getLateTime()) || $this->o_model->getLateTime() < 0)) {
00163             $this->o_result->addMessage(_('Updated Due Date must be a number'));
00164             $this->o_result->setSuccess(false);
00165         }
00166 
00167         if (!FastFrame::isEmpty($this->o_model->getOpenTime()) &&
00168             (!is_numeric($this->o_model->getOpenTime()) || $this->o_model->getOpenTime() < 0)) {
00169             $this->o_result->addMessage(_('Updated Open Date must be a number'));
00170             $this->o_result->setSuccess(false);
00171         }
00172 
00173         if (!FastFrame::isEmpty($this->o_model->getCloseTime()) &&
00174             (!is_numeric($this->o_model->getCloseTime()) || $this->o_model->getCloseTime() < 0)) {
00175             $this->o_result->addMessage(_('Updated Close Date must be a number'));
00176             $this->o_result->setSuccess(false);
00177         }
00178     }
00179 
00180     // }}}
00181 }
00182 ?>

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