Validate/Alumni.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_Alumni
00029 
00040 // }}}
00041 class FF_Validate_Alumni extends FF_Validate {
00042     // {{{ validate()
00043 
00051     function validate()
00052     {
00053         $this->_validateId();
00054         $this->_validateRequiredFields();
00055         $this->_validateWebSite();
00056         return $this->o_result;
00057     }
00058 
00059     // }}}
00060     // {{{ _validateId()
00061 
00068     function _validateId()
00069     {
00070         if ($this->isUpdate && FastFrame::isEmpty($this->o_model->getId())) {
00071             $this->o_result->addMessage(_('Id cannot be empty'));
00072             $this->o_result->setSuccess(false);
00073         }
00074     }
00075 
00076     // }}}
00077     // {{{ _validateWebSite()
00078 
00085     function _validateWebSite()
00086     {
00087         if (!FastFrame::isEmpty($this->o_model->getWebSite())) {
00088             require_once 'Validate.php';
00089             $a_options = array('allowed_schemes' => array('http', 'https'));
00090             if (!Validate::uri($this->o_model->getWebSite(), $a_options)) {
00091                 $this->o_result->addMessage(_('Invalid web site address.  It must be in the form of http://www.example.com'));
00092                 $this->o_result->setSuccess(false);
00093             }
00094         }
00095     }
00096 
00097     // }}}
00098     // {{{ _validateRequiredFields()
00099 
00106     function _validateRequiredFields()
00107     {
00108         $o_registry =& FF_Registry::singleton();
00109         $a_data = $o_registry->getConfigParam('profile/fields', array(), 'alum_website');
00110         $a_fields = array('title' => 'getTitle', 'company' => 'getCompany', 
00111                 'address' => 'getAddress', 'city' => 'getCity', 
00112                 'state' => 'getState', 'country' => 'getCountry', 
00113                 'fax' => 'getFax', 
00114                 'web_site' => 'getWebSite', 'major' => 'getMajor', 
00115                 'grad_year' => 'getGradYear');
00116         foreach ($a_fields as $s_field => $s_method) {
00117             // Don't check locked fields since the field isn't there for them to fix
00118             if (empty($a_data[$s_field]['locked']) && !empty($a_data[$s_field]['required'])) {
00119                 if (FastFrame::isEmpty($this->o_model->$s_method())) {
00120                     $this->o_result->addMessage(sprintf(_('%s cannot be empty'), $a_data[$s_field]['desc']));
00121                     $this->o_result->setSuccess(false);
00122                 }
00123             }
00124         }
00125     }
00126 
00127     // }}}
00128 }
00129 ?>

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