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_Borrower extends FF_Model {
00044
00045
00050 var $firstName;
00051
00056 var $lastName;
00057
00062 var $barcode;
00063
00068 var $type;
00069
00074 var $email;
00075
00080 var $profileId;
00081
00086 var $attributes = array();
00087
00092 var $demos = array();
00093
00098 var $demosToRemove = array();
00099
00106 var $newComment;
00107
00112 var $commentsToRemove = array();
00113
00118 var $o_demoDataAccess;
00119
00120
00121
00122
00131 function save($in_isUpdate)
00132 {
00133 $o_result =& parent::save($in_isUpdate);
00134
00135
00136 if ($o_result->isSuccess()) {
00137 require_once dirname(__FILE__) . '/Comment.php';
00138 $o_commentModel =& new FF_Model_Comment();
00139 $o_commentModel->processComments($this->getId(), $this->newComment,
00140 $this->getCommentsToRemove(), $o_result);
00141 }
00142
00143 return $o_result;
00144 }
00145
00146
00147
00148
00155 function reset()
00156 {
00157 $this->id = null;
00158 $this->firstName = null;
00159 $this->lastName = null;
00160 $this->barcode = null;
00161 $this->type = null;
00162 $this->email = null;
00163 $this->attributes = array();
00164 $this->newComment = null;
00165 $this->commentsToRemove = array();
00166 $this->demos = array();
00167 $this->demosToRemove = array();
00168 }
00169
00170
00171
00172
00181 function importFromArray($in_data)
00182 {
00183 $this->setId($in_data['id']);
00184 $this->setFirstName($in_data['first_name']);
00185 $this->setLastName($in_data['last_name']);
00186 $this->setBarcode($in_data['barcode']);
00187 $this->setType($in_data['type']);
00188 $this->setEmail($in_data['email']);
00189 $this->setProfileId($in_data['profile_id']);
00190 if (isset($in_data['attributes'])) {
00191 $this->attributes = $in_data['attributes'];
00192 }
00193
00194 if (isset($in_data['demos'])) {
00195 $this->demos = $in_data['demos'];
00196 }
00197
00198 if (isset($in_data['demosToRemove'])) {
00199 $this->demosToRemove = $in_data['demosToRemove'];
00200 }
00201
00202 if (isset($in_data['newComment'])) {
00203 $this->setNewComment($in_data['newComment']);
00204 }
00205
00206 if (isset($in_data['commentsToRemove'])) {
00207 $this->commentsToRemove = $in_data['commentsToRemove'];
00208 }
00209 }
00210
00211
00212
00213
00222 function exportToArray()
00223 {
00224 $a_data = array();
00225 $a_data['id'] = $this->getId();
00226 $a_data['first_name'] = $this->getFirstName();
00227 $a_data['last_name'] = $this->getLastName();
00228 $a_data['barcode'] = $this->getBarcode();
00229 $a_data['type'] = $this->getType();
00230 $a_data['email'] = $this->getEmail();
00231 $a_data['profile_id'] = $this->getProfileId();
00232 $a_data['attributes'] = $this->attributes;
00233 $a_data['demos'] = $this->demos;
00234 $a_data['newComment'] = $this->getNewComment();
00235 $a_data['commentsToRemove'] = $this->commentsToRemove;
00236 return $a_data;
00237 }
00238
00239
00240
00241
00253 function &getDataToExport($in_fields, $in_limited, $in_file, $in_fieldNum)
00254 {
00255 $o_result = new FF_Result();
00256
00257 if ($in_limited) {
00258 if (!preg_match('/csv$/i', $in_file['name']) || $in_file['size'] == 0) {
00259 $o_result->setSuccess(false);
00260 $o_result->addMessage(_('You did not upload a valid CSV file'));
00261 return $o_result;
00262 }
00263
00264 $handle = fopen($in_file['tmp_name'], 'r');
00265 $a_borrowers = array();
00266 while (($a_data = fgetcsv($handle, 1000, ',')) !== false) {
00267 $a_borrowers[] = $a_data[$in_fieldNum];
00268 }
00269 }
00270 else {
00271 $a_borrowers = array();
00272 }
00273
00274 $o_result =& $this->o_dataAccess->getDataToExport($in_fields, $a_borrowers);
00275 return $o_result;
00276 }
00277
00278
00279
00280
00287 function getFields()
00288 {
00289 $a_fields = array(
00290 'id' => 'Id',
00291 'first_name' => 'First Name',
00292 'last_name' => 'Last Name',
00293 'barcode' => 'Barcode',
00294 'email' => 'Email',
00295 'type' => 'Type');
00296
00297 $o_registry = FF_Registry::singleton();
00298 $o_perms = FF_Perms::factory();
00299 foreach ($o_registry->getConfigParam('borrower/attributes') as $s_key => $s_desc) {
00300 $s_perm = "can_view_borrower_attrib_$s_key";
00301 if ($o_perms->hasPerm($s_perm)) {
00302 $a_fields["attrib.$s_key"] = $s_desc;
00303 }
00304 }
00305
00306 return $a_fields;
00307 }
00308
00309
00310
00311
00318 function getNumComments()
00319 {
00320 $o_commentDataAccess =& FF_DataAccess::factory('Comment');
00321 return $o_commentDataAccess->getCommentCount($this->getId());
00322 }
00323
00324
00325
00326
00327 function getBorrowerIdByBarcode( $in_barcode)
00328 {
00329 return $this->o_dataAccess->getBorrowerIdByBarcode($in_barcode);
00330 }
00331
00332
00333
00334
00341 function getBorrowerName()
00342 {
00343 $s_name = $this->o_dataAccess->getBorrowerName($this->getId());
00344 return empty($s_name) ? false : $s_name;
00345 }
00346
00347
00348
00349
00350 function getFirstName()
00351 {
00352 return $this->firstName;
00353 }
00354
00355
00356
00357
00358 function setFirstName($in_value)
00359 {
00360 $this->firstName = $in_value;
00361 }
00362
00363
00364
00365
00366 function getLastName()
00367 {
00368 return $this->lastName;
00369 }
00370
00371
00372
00373
00374 function setLastName($in_value)
00375 {
00376 $this->lastName = $in_value;
00377 }
00378
00379
00380
00381
00382 function getBarcode()
00383 {
00384 return $this->barcode;
00385 }
00386
00387
00388
00389
00390 function setBarcode($in_value)
00391 {
00392 $this->barcode = $in_value;
00393 }
00394
00395
00396
00397
00404 function getFormattedType()
00405 {
00406 $o_registry =& FF_Registry::singleton();
00407 $a_types = $o_registry->getConfigParam('borrower/types', array());
00408 if (isset($a_types[$this->getType()])) {
00409 return $a_types[$this->getType()];
00410 }
00411 else {
00412 return _('Unknown Type');
00413 }
00414 }
00415
00416
00417
00418
00419 function getType()
00420 {
00421 return $this->type;
00422 }
00423
00424
00425
00426
00427 function setType($in_value)
00428 {
00429 $this->type = $in_value;
00430 }
00431
00432
00433
00434
00435 function getEmail()
00436 {
00437 return $this->email;
00438 }
00439
00440
00441
00442
00443 function setEmail($in_value)
00444 {
00445 $this->email = $in_value;
00446 }
00447
00448
00449
00450
00457 function getProfileUsername()
00458 {
00459 $o_profileDataAccess =& FF_DataAccess::factory('Profile', 'profile');
00460 if ($this->getProfileId() == 0) {
00461 return _('No Profile Associated');
00462 }
00463 else {
00464 return $o_profileDataAccess->getUsernameById($this->getProfileId());
00465 }
00466 }
00467
00468
00469
00470
00480 function isProfileIdUnique($in_isUpdate)
00481 {
00482 return $this->o_dataAccess->isProfileIdUnique($this->getProfileId(), $this->getId(), $in_isUpdate);
00483 }
00484
00485
00486
00487
00496 function getIdByProfileId($in_profileId)
00497 {
00498 $s_id = $this->o_dataAccess->getIdByProfileId($in_profileId);
00499 return empty($s_id) ? false : $s_id;
00500 }
00501
00502
00503
00504
00505 function getProfileId()
00506 {
00507 return $this->profileId;
00508 }
00509
00510
00511
00512
00513 function setProfileId($in_value)
00514 {
00515 $this->profileId = $in_value;
00516 }
00517
00518
00519
00520
00529 function getAttribute($in_attr)
00530 {
00531 return isset($this->attributes[$in_attr]) ? $this->attributes[$in_attr] : null;
00532 }
00533
00534
00535
00536
00546 function setAttribute($in_attr, $in_value)
00547 {
00548 $this->attributes[$in_attr] = $in_value;
00549 }
00550
00551
00552
00553
00560 function getAllDemos()
00561 {
00562 if (!$this->getId()) {
00563 return array();
00564 }
00565
00566 return $this->o_demoDataAccess->getDemosByBorrowerId($this->getId());
00567 }
00568
00569
00570
00571
00580 function addDemo($in_demoId)
00581 {
00582 if (!FastFrame::isEmpty($in_demoId, false)) {
00583 $this->comments[$s_id] = $in_comment;
00584 }
00585 }
00586
00587
00588
00589
00598 function removeDemo($in_demoId)
00599 {
00600 if (!FastFrame::isEmpty($in_demoId, false)) {
00601 $this->commentsToRemove[] = $in_demoId;
00602 }
00603 }
00604
00605
00606
00607
00614 function removeDemos()
00615 {
00616 $o_result = new FF_Result();
00617 foreach ($this->demosToRemove as $s_id) {
00618 $tmp_result =& $this->o_dataAccess->removeDemo($this->getId(),$s_id);
00619 if (!$tmp_result->isSuccess()) {
00620 $o_result->addMessage($tmp_result->getMessages());
00621 $o_result->setSuccess(false);
00622 }
00623 }
00624
00625 return $o_result;
00626 }
00627
00628
00629
00630
00631 function getNewComment()
00632 {
00633 return $this->newComment;
00634 }
00635
00636
00637
00638
00647 function setNewComment($in_comment)
00648 {
00649 $this->newComment = $in_comment;
00650 }
00651
00652
00653
00654
00663 function getCommentsToRemove($in_formize = false)
00664 {
00665 $a_comments = $this->commentsToRemove;
00666 if ($in_formize) {
00667 foreach ($a_comments as $s_key => $s_val) {
00668 unset($a_comments[$s_key]);
00669 $a_comments['comments'][$s_val] = 1;
00670 }
00671 }
00672
00673 return $a_comments;
00674 }
00675
00676
00677
00678
00687 function setCommentsToRemove($in_comments)
00688 {
00689 $this->commentsToRemove = array_keys((array) $in_comments);
00690 }
00691
00692
00693
00694
00701 function _initDataAccess()
00702 {
00703 $this->o_dataAccess =& FF_DataAccess::factory('Borrower');
00704 $this->o_demoDataAccess =& FF_DataAccess::factory('Demo');
00705 }
00706
00707
00708 }
00709 ?>