DataAccess/mysql/Priority.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_Priority_mysql 
00029 
00040 // }}}
00041 class FF_DataAccess_Priority_mysql extends FF_DataAccess {
00042     // {{{ constructor
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     // {{{ 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     // {{{ getPriorityOptions()
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                     // If the last one, then the range is infinite, so just make the end bound a huge number
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     // {{{ getNextId()
00138 
00145     function getNextId()
00146     {
00147         // change sequence name since we give it the full table name
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     // {{{ getDefaultValue()
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     // {{{ getClosestPriority()
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     // {{{ getNextPriority()
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     // {{{ getPriorityAlerts()
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     // {{{ _setIsDefaultToFalse()
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 ?>

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