00001 <?php
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025 require_once FASTFRAME_ROOT . 'lib/FastFrame/DataAccess.php';
00026
00027
00028
00029
00040
00041 class FF_DataAccess_Location_mysql extends FF_DataAccess {
00042
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
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
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
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
00115
00122 function getNextId()
00123 {
00124
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
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
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
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 ?>