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/Model.php';
00026
00027
00028
00029
00042
00043 class FF_Model_OverrideCode extends FF_Model {
00044
00045
00050 var $code;
00051
00056 var $creatorId;
00057
00062 var $startDate;
00063
00068 var $endDate;
00069
00074 var $useDate;
00075
00080 var $transactionId;
00081
00086 var $borrowerId;
00087
00092 var $o_borrowerDataAccess;
00093
00098 var $multiUse;
00099
00100
00101
00102
00109 function reset()
00110 {
00111 $this->id = null;
00112 $this->code = null;
00113 $this->creatorId = null;
00114 $this->startDate = null;
00115 $this->endDate = null;
00116 $this->useDate = null;
00117 $this->transactionId = null;
00118 $this->borrowerId = null;
00119 }
00120
00121
00122
00123
00132 function importFromArray($in_data)
00133 {
00134 $this->setId($in_data['id']);
00135 $this->setCode($in_data['code']);
00136 $this->setCreatorId($in_data['creator_id']);
00137 $this->setStartDate($in_data['start_date']);
00138 $this->setEndDate($in_data['end_date']);
00139 $this->setUseDate($in_data['use_date']);
00140 $this->setTransactionId($in_data['transaction_id']);
00141 $this->setBorrowerId($in_data['borrower_id']);
00142 $this->setMultiUse($in_data['multi_use']);
00143 }
00144
00145
00146
00147
00156 function exportToArray()
00157 {
00158 $a_data = array();
00159 $a_data['id'] = $this->getId();
00160 $a_data['code'] = $this->getCode();
00161 $a_data['creator_id'] = $this->getCreatorId();
00162 $a_data['start_date'] = $this->getStartDate();
00163 $a_data['end_date'] = $this->getEndDate();
00164 $a_data['use_date'] = $this->getUseDate();
00165 $a_data['transaction_id'] = $this->getTransactionId();
00166 $a_data['borrower_id'] = $this->getBorrowerId();
00167 $a_data['multi_use'] = $this->getMultiUse();
00168 return $a_data;
00169 }
00170
00171
00172
00173
00182 function getLogEntryDescription($in_id)
00183 {
00184 if ($this->fillById($in_id)) {
00185 return $this->getCode() . '(' . $this->getFormattedStartDate() .
00186 ' - ' . $this->getFormattedEndDate() . ')';
00187 }
00188 else {
00189 return false;
00190 }
00191 }
00192
00193
00194
00195
00205 function isCodeValid($in_code, $in_borrowerId)
00206 {
00207 return $this->o_dataAccess->isCodeValid($in_code, $in_borrowerId);
00208 }
00209
00210
00211
00212
00222 function useCode($in_code, $in_transactionId)
00223 {
00224 return $this->o_dataAccess->useCode($in_code, $in_transactionId);
00225 }
00226
00227
00228
00229
00236 function getNewCode()
00237 {
00238 require_once FASTFRAME_ROOT . 'lib/FastFrame/Util.php';
00239 $o_registry =& FF_Registry::singleton();
00240 $s_length = $o_registry->getConfigParam('override_code/length');
00241 $s_chars = $o_registry->getConfigParam('override_code/characters');
00242 while (true) {
00243 $s_code = strtolower(FF_Util::getRandomString($s_length, $s_chars));
00244 if ($this->o_dataAccess->isDataUnique('code', $s_code, null, false)) {
00245 break;
00246 }
00247 }
00248
00249 return $s_code;
00250 }
00251
00252
00253
00254
00255 function getCode()
00256 {
00257 return $this->code;
00258 }
00259
00260
00261
00262
00263 function setCode($in_value)
00264 {
00265 $this->code = $in_value;
00266 }
00267
00268
00269
00270
00271 function getFormattedMultiUse()
00272 {
00273 return $this->getMultiUse() ? _('Yes') : _('No');
00274 }
00275
00276
00277
00278
00279 function setMultiUse($in_value)
00280 {
00281 $this->multiUse = $this->_scalarToBool($in_value);
00282 }
00283
00284
00285
00286
00287 function getMultiUse()
00288 {
00289 return $this->multiUse;
00290 }
00291
00292
00293
00294
00301 function getCreatorName()
00302 {
00303 $o_profileDataAccess =& FF_DataAccess::factory('Profile', 'profile');
00304 return $o_profileDataAccess->getFullNameById($this->getCreatorId());
00305 }
00306
00307
00308
00309
00310 function getCreatorId()
00311 {
00312 return $this->creatorId;
00313 }
00314
00315
00316
00317
00318 function setCreatorId($in_value)
00319 {
00320 $this->creatorId = $in_value;
00321 }
00322
00323
00324
00325
00332 function getFormattedStartDate()
00333 {
00334 return $this->formatTimestamp($this->getStartDate());
00335 }
00336
00337
00338
00339
00340 function getStartDate()
00341 {
00342 return is_null($this->startDate) ? time() : $this->startDate;
00343 }
00344
00345
00346
00347
00348 function setStartDate($in_value)
00349 {
00350 $this->startDate = $in_value;
00351 }
00352
00353
00354
00355
00362 function getFormattedEndDate()
00363 {
00364 return $this->formatTimestamp($this->getEndDate());
00365 }
00366
00367
00368
00369
00370 function getEndDate()
00371 {
00372 $o_registry =& FF_Registry::singleton();
00373 if (is_null($this->endDate)) {
00374 return mktime(date('H'), date('i'),
00375 date('s') + $o_registry->getConfigParam('override_code/default_duration'),
00376 date('m'), date('d'), date('Y'));
00377 }
00378 else {
00379 return $this->endDate;
00380 }
00381 }
00382
00383
00384
00385
00386 function setEndDate($in_value)
00387 {
00388 $this->endDate = $in_value;
00389 }
00390
00391
00392
00393
00400 function getFormattedUseDate()
00401 {
00402 return $this->formatTimestamp($this->getUseDate());
00403 }
00404
00405
00406
00407
00408 function getUseDate()
00409 {
00410 return $this->useDate;
00411 }
00412
00413
00414
00415
00416 function setUseDate($in_value)
00417 {
00418 $this->useDate = $in_value;
00419 }
00420
00421
00422
00423
00424 function getTransactionId()
00425 {
00426 return $this->transactionId;
00427 }
00428
00429
00430
00431
00432 function setTransactionId($in_value)
00433 {
00434 $this->transactionId = $in_value;
00435 }
00436
00437
00438
00439
00448 function setBorrowerIdByBarcode($in_barcode)
00449 {
00450 $o_borrowerDataAccess =& FF_DataAccess::factory('Borrower');
00451 $s_id = $o_borrowerDataAccess->getBorrowerIdByBarcode($in_barcode);
00452
00453 $s_id = is_null($s_id) ? -1 : $s_id;
00454 $this->setBorrowerId($s_id);
00455 }
00456
00457
00458
00459
00466 function getBorrowerName()
00467 {
00468 $this->_initBorrowerDataAccess();
00469 $s_name = $this->o_borrowerDataAccess->getBorrowerName($this->getBorrowerId());
00470 return empty($s_name) ? false : $s_name ;
00471 }
00472
00473
00474
00475
00476 function getBorrowerId()
00477 {
00478 return $this->borrowerId;
00479 }
00480
00481
00482
00483
00484 function setBorrowerId($in_value)
00485 {
00486 $this->borrowerId = $in_value;
00487 }
00488
00489
00490
00491
00500 function formatTimestamp($in_timestamp)
00501 {
00502 if ($in_timestamp == 0) {
00503 return _('N/A');
00504 }
00505 else {
00506 return date('m/d/Y h:i a', $in_timestamp);
00507 }
00508 }
00509
00510
00511
00512
00520 function _initBorrowerDataAccess()
00521 {
00522 if (!is_object($this->o_borrowerDataAccess)) {
00523 $this->o_borrowerDataAccess =& FF_DataAccess::factory('Borrower');
00524 }
00525 }
00526
00527
00528
00529
00536 function _initDataAccess()
00537 {
00538 $this->o_dataAccess =& FF_DataAccess::factory('OverrideCode');
00539 }
00540
00541
00542 }
00543 ?>