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_Priority_mysql extends FF_DataAccess {
00042
00043
00050 function FF_DataAccess_Priority_mysql()
00051 {
00052 FF_DataAccess::FF_DataAccess();
00053 $this->table = $this->o_registry->getConfigParam('data/priorities_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
00110 function getPriorityOptions($in_options = array())
00111 {
00112 $s_query = "SELECT points, name FROM $this->table ORDER BY points";
00113 $a_points = $this->o_data->getAssoc($s_query);
00114 if (!empty($in_options['asRange'])) {
00115 $a_newPoints = array();
00116 $tmp_points = array_keys($a_points);
00117 $s_last = count($tmp_points) - 1;
00118 for ($i = $s_last; $i >= 0; $i--) {
00119 $s_points = $tmp_points[$i];
00120 $s_prevPoints = $i == 0 ? 0 : $tmp_points[$i - 1] + 1;
00121 if ($i == $s_last) {
00122
00123 $a_newPoints["$s_prevPoints-10000"] = $a_points[$s_points];
00124 }
00125 else {
00126 $a_newPoints["$s_prevPoints-$s_points"] = $a_points[$s_points];
00127 }
00128 }
00129
00130 $a_points = $a_newPoints;
00131 }
00132
00133 return $a_points;
00134 }
00135
00136
00137
00138
00145 function getNextId()
00146 {
00147
00148 $this->o_data->setOption('seqname_format', '%s');
00149 return $this->o_data->nextId($this->o_registry->getConfigParam('data/sequence_table'));
00150 }
00151
00152
00153
00154
00162 function getDefaultValue()
00163 {
00164 $s_query = "SELECT points FROM $this->table WHERE is_default=1 OR 1 ORDER BY is_default DESC LIMIT 1";
00165 return $this->o_data->getOne($s_query);
00166 }
00167
00168
00169
00170
00180 function getClosestPriority($in_points)
00181 {
00182 $s_query = "SELECT points,name FROM $this->table ORDER BY ABS(points - ?) LIMIT 1";
00183 $a_data = $this->o_data->getAll($s_query, array($in_points));
00184 return $a_data[0];
00185 }
00186
00187
00188
00189
00198 function getNextPriority($in_points, $in_dir)
00199 {
00200 if ($in_dir) {
00201 $s_query = "SELECT points, name FROM $this->table WHERE points > ? ORDER BY points ASC LIMIT 1";
00202 }
00203 else {
00204 $s_query = "SELECT points, name FROM $this->table WHERE points < ? ORDER BY points DESC LIMIT 1";
00205 }
00206
00207 $a_data = $this->o_data->getAll($s_query, array($in_points));
00208 return @$a_data[0];
00209 }
00210
00211
00212
00213
00220 function getPriorityAlerts()
00221 {
00222 $s_query = "SELECT points, alert_message FROM $this->table WHERE alert_message != ''";
00223 return $this->o_data->getAssoc($s_query);
00224 }
00225
00226
00227
00228
00238 function _setIsDefaultToFalse($in_data)
00239 {
00240 if ($in_data['is_default']) {
00241 $this->o_data->autoExecute($this->table, array('is_default' => 0), DB_AUTOQUERY_UPDATE, 'id \!= ' . $this->o_data->quoteSmart($in_data['id']));
00242 }
00243 }
00244
00245
00246 }
00247 ?>