DataAccess/mysql/OverrideCode.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 require_once dirname(__FILE__) . '/../../Model/Log.php';
00027 
00028 // }}}
00029 // {{{ class FF_DataAccess_OverrideCode_mysql 
00030 
00040 // }}}
00041 class FF_DataAccess_OverrideCode_mysql extends FF_DataAccess {
00042     // {{{ properties
00043 
00048     var $o_log;
00049 
00050     // }}}
00051     // {{{ constructor
00052 
00059     function FF_DataAccess_OverrideCode_mysql()
00060     {
00061         FF_DataAccess::FF_DataAccess();
00062         $this->table = $this->o_registry->getConfigParam('data/override_codes_table');
00063         $this->o_log =& new FF_Model_Log();
00064     }
00065 
00066     // }}}
00067     // {{{ update()
00068 
00077     function update($in_data)
00078     {
00079         $in_data['start_date'] = $this->timestampToISODate($in_data['start_date']);
00080         $in_data['end_date'] = $this->timestampToISODate($in_data['end_date']);
00081         unset($in_data['use_date']);
00082         unset($in_data['transaction_id']);
00083         unset($in_data['code']);
00084         $o_result =& parent::update($in_data);
00085         if ($o_result->isSuccess()) {
00086             $tmp_result =& $this->o_log->newLogEntry('UPDATE', $in_data['id'], $this->table);
00087         }
00088 
00089         return $o_result;
00090     }
00091 
00092     // }}}
00093     // {{{ add()
00094 
00103     function add($in_data)
00104     {
00105         $in_data['start_date'] = $this->timestampToISODate($in_data['start_date']);
00106         $in_data['end_date'] = $this->timestampToISODate($in_data['end_date']);
00107         unset($in_data['use_date']);
00108         unset($in_data['transaction_id']);
00109         $o_result =& parent::add($in_data);
00110         if ($o_result->isSuccess()) {
00111             $tmp_result =& $this->o_log->newLogEntry('INSERT', $in_data['id'], $this->table);
00112         }
00113 
00114         return $o_result;
00115     }
00116 
00117     // }}}
00118     // {{{ remove()
00119 
00128     function remove($in_overrideCodeId)
00129     {
00130         $o_result =& parent::remove($in_overrideCodeId);
00131         if ($o_result->isSuccess()) {
00132             $tmp_result =& $this->o_log->newLogEntry('DELETE', $in_overrideCodeId, $this->table);
00133         }
00134 
00135         return $o_result;
00136     }
00137 
00138     // }}}
00139     // {{{ isCodeValid()
00140 
00150     function isCodeValid($in_code, $in_borrowerId)
00151     {
00152         $s_query = "SELECT COUNT(*) FROM $this->table
00153                     WHERE code = ? AND borrower_id = ? AND 
00154                     start_date <= NOW() AND end_date >= NOW() AND (use_date = 0 OR multi_use = 1)";
00155 
00156         return $this->o_data->getOne($s_query, array($in_code, $in_borrowerId)) == 0 ? false : true;
00157     }
00158 
00159     // }}}
00160     // {{{ useCode()
00161 
00171     function useCode($in_code, $in_transactionId)
00172     {
00173         $s_query = "SELECT id FROM $this->table WHERE code = ?";
00174         $s_id = $this->o_data->getOne($s_query, $in_code);
00175         $s_stmt = $this->o_data->prepare("UPDATE $this->table SET use_date=NOW(), transaction_id = ? WHERE id = ?");
00176 
00177         if (DB::isError($this->o_data->execute($s_stmt, array($in_transactionId, $s_id)))) {
00178             return false;
00179         }
00180         else {
00181             $tmp_result =& $this->o_log->newLogEntry('OC_USE', $s_id, $this->table, time(), $in_transactionId);
00182             return true;
00183         }
00184     }
00185 
00186     // }}}
00187     // {{{ getDataByPrimaryKey()
00188 
00198     function getDataByPrimaryKey($in_id, $in_fields = '*')
00199     {
00200         return parent::getDataByPrimaryKey($in_id, $this->_getSelectFields());
00201     }
00202 
00203     // }}}
00204     // {{{ getListData()
00205 
00217     function getListData($in_where, $in_orderByField, $in_orderByDir, $in_fields = '*')
00218     {
00219         return parent::getListData($in_where, $in_orderByField, $in_orderByDir, $this->_getSelectFields());
00220     }
00221 
00222     // }}}
00223     // {{{ getNextId()
00224 
00231     function getNextId()
00232     {
00233         // change sequence name since we give it the full table name
00234         $this->o_data->setOption('seqname_format', '%s');
00235         return $this->o_data->nextId($this->o_registry->getConfigParam('data/sequence_table'));
00236     }
00237 
00238     // }}}
00239     // {{{ _getSelectFields()
00240 
00248     function _getSelectFields()
00249     {
00250         return 'id, code, creator_id, UNIX_TIMESTAMP(start_date) AS start_date, UNIX_TIMESTAMP(end_date) AS end_date, UNIX_TIMESTAMP(use_date) AS use_date, transaction_id, borrower_id, multi_use';
00251     }
00252 
00253     // }}}
00254 }
00255 ?>

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