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 require_once dirname(__FILE__) . '/../../Model/Log.php';
00027
00028
00029
00030
00040
00041 class FF_DataAccess_OverrideCode_mysql extends FF_DataAccess {
00042
00043
00048 var $o_log;
00049
00050
00051
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
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
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
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
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
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
00188
00198 function getDataByPrimaryKey($in_id, $in_fields = '*')
00199 {
00200 return parent::getDataByPrimaryKey($in_id, $this->_getSelectFields());
00201 }
00202
00203
00204
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
00224
00231 function getNextId()
00232 {
00233
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
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 ?>