DataAccess/mysql/Location.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/DataAccess.php';
00026 
00027 // }}}
00028 // {{{ class FF_DataAccess_Location_mysql 
00029 
00040 // }}}
00041 class FF_DataAccess_Location_mysql extends FF_DataAccess {
00042     // {{{ constructor
00043 
00050     function FF_DataAccess_Location_mysql()
00051     {
00052         FF_DataAccess::FF_DataAccess();
00053         $this->table = $this->o_registry->getConfigParam('data/locations_table');
00054     }
00055 
00056     // }}}
00057     // {{{ update()
00058 
00067     function update($in_data)
00068     {
00069         $o_result =& parent::update($in_data);
00070         if ($o_result->isSuccess()) {
00071             $this->_setIsDefaultToFalse($in_data);
00072         }
00073 
00074         return $o_result;
00075     }
00076 
00077     // }}}
00078     // {{{ add()
00079 
00088     function add($in_data)
00089     {
00090         $o_result =& parent::add($in_data);
00091         if ($o_result->isSuccess()) {
00092             $this->_setIsDefaultToFalse($in_data);
00093         }
00094 
00095         return $o_result;
00096     }
00097 
00098     // }}}
00099     // {{{ getLocationOptions()
00100 
00107     function getLocationOptions()
00108     {
00109         $s_query = "SELECT id, name FROM $this->table ORDER BY name";
00110         return $this->o_data->getAssoc($s_query);
00111     }
00112 
00113     // }}}
00114     // {{{ getNextId()
00115 
00122     function getNextId()
00123     {
00124         // change sequence name since we give it the full table name
00125         $this->o_data->setOption('seqname_format', '%s');
00126         return $this->o_data->nextId($this->o_registry->getConfigParam('data/sequence_table'));
00127     }
00128 
00129     // }}}
00130     // {{{ getDefaultValue()
00131 
00139     function getDefaultValue()
00140     {
00141         $s_query = "SELECT id FROM $this->table WHERE is_default=1 OR 1 ORDER BY is_default DESC LIMIT 1";
00142         return $this->o_data->getOne($s_query);
00143     }
00144 
00145     // }}}
00146     // {{{ getLocationName()
00147 
00156     function getLocationName($in_id)
00157     {
00158         $s_query = "SELECT IFNULL(name, ?) FROM $this->table WHERE id = ?";
00159         return $this->o_data->getOne($s_query, array(_('Unknown'), $in_id));
00160     }
00161 
00162     // }}}
00163     // {{{ _setIsDefaultToFalse()
00164 
00174     function _setIsDefaultToFalse($in_data)
00175     {
00176         if ($in_data['is_default']) {
00177             $this->o_data->autoExecute($this->table, array('is_default' => 0), DB_AUTOQUERY_UPDATE, 'id \!= ' . $this->o_data->quoteSmart($in_data['id']));
00178         }
00179     }
00180 
00181     // }}}
00182 }
00183 ?>

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