Model/Item.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 // | Authors: Greg Gilbert <ggilbert@codejanitor.com>                     |
00021 // +----------------------------------------------------------------------+
00022 
00023 // }}}
00024 // {{{ requires
00025 
00026 require_once FASTFRAME_ROOT . 'lib/FastFrame/Model.php';
00027 
00028 // }}}
00029 // {{{ constants
00030 
00031 // The available item statuses
00032 define('ITEM_STATUS_AVAILABLE', 'AVAILABLE');
00033 define('ITEM_STATUS_ONLOAN', 'ONLOAN');
00034 define('ITEM_STATUS_UNAVAILABLE', 'UNAVAILABLE');
00035 define('ITEM_STATUS_MISSING', 'MISSING');
00036 define('ITEM_STATUS_REPAIR', 'REPAIR');
00037 
00038 // }}}
00039 // {{{ class FF_Model_Item
00040 
00054 // }}}
00055 class FF_Model_Item extends FF_Model {
00056     // {{{ properties
00057 
00062     var $name;
00063 
00068     var $description;
00069 
00074     var $status;
00075 
00080     var $categoryId;
00081     
00086     var $vendorId;
00087     
00092     var $barcode;
00093 
00098     var $serialNum;
00099 
00104     var $storeId;
00105 
00110     var $shopperViewable = true;
00111 
00116     var $isGroup = false;
00117 
00122     var $isDeleted = false;
00123 
00128     var $attributes = array();
00129 
00134     var $newComment;
00135 
00140     var $commentsToRemove = array();
00141 
00146     var $rules = array();
00147 
00148     // }}}
00149     // {{{ save()
00150 
00159     function save($in_isUpdate)
00160     {
00161         $o_result =& parent::save($in_isUpdate);
00162             
00163         // Handle comments and rules
00164         if ($o_result->isSuccess()) {
00165             require_once dirname(__FILE__) . '/Comment.php';
00166             $o_commentModel =& new FF_Model_Comment();
00167             $o_commentModel->processComments($this->getId(), $this->newComment, 
00168                     $this->getCommentsToRemove(), $o_result);
00169 
00170             $o_rulesDataAccess =& FF_DataAccess::factory('Rule');
00171             $tmp_result =& $o_rulesDataAccess->updateRulesForItem($this->getId(), $this->getRules());
00172             if (!$tmp_result->isSuccess()) {
00173                 $o_result->addMessage($tmp_result->getMessages());
00174             }
00175         }
00176 
00177         return $o_result;
00178     }
00179 
00180     // }}}
00181     // {{{ reset()
00182 
00189     function reset()
00190     {
00191         $this->id = null;
00192         $this->name = null;
00193         $this->description = null;
00194         $this->status = null;
00195         $this->categoryId = null;
00196         $this->barcode = null;
00197         $this->serialNum = null;
00198         $this->storeId = null;
00199         $this->shopperViewable = true;
00200         $this->isGroup = false;
00201         $this->attributes = array();
00202         $this->newComment = null; 
00203         $this->commentsToRemove = array();
00204         $this->rules = array();
00205     }
00206 
00207     // }}}
00208     // {{{ importFromArray()
00209 
00218     function importFromArray($in_data)
00219     {
00220         $this->setId($in_data['id']);
00221         $this->setName($in_data['name']);
00222         $this->setDescription($in_data['description']);
00223         $this->setStatus($in_data['status']);
00224         $this->setSerialNum($in_data['serial_num']);
00225         $this->setBarcode($in_data['barcode']);
00226         
00227         if (isset($in_data['deleted'])) {
00228             $this->setIsDeleted($in_data['deleted']);
00229         }
00230 
00231         // Many of these aren't used on the list page
00232         if (isset($in_data['shopper_viewable'])) {
00233             $this->setShopperViewable($in_data['shopper_viewable']);
00234         }
00235 
00236         if (isset($in_data['store_id'])) {
00237             $this->setStoreId($in_data['store_id']);
00238         }
00239 
00240         if (isset($in_data['category_id'])) {
00241             $this->setCategoryId($in_data['category_id']);
00242         }
00243 
00244         if (isset($in_data['vendor_id'])) {
00245             $this->setVendorId($in_data['vendor_id']);
00246         }
00247 
00248         if (isset($in_data['isGroup'])) {
00249             $this->setIsGroup($in_data['isGroup']);
00250         }
00251 
00252         if (isset($in_data['attributes'])) {
00253             $this->attributes = $in_data['attributes'];
00254         }
00255 
00256         if (isset($in_data['newComment'])) {
00257             $this->setNewComment($in_data['newComment']);
00258         }
00259 
00260         if (isset($in_data['commentsToRemove'])) {
00261             $this->commentsToRemove = $in_data['commentsToRemove'];
00262         }
00263 
00264         if (isset($in_data['rules'])) {
00265             $this->rules = $in_data['rules'];
00266         }
00267     }
00268 
00269     // }}}
00270     // {{{ exportToArray()
00271 
00280     function exportToArray()
00281     {
00282         $a_data = array();
00283         $a_data['id'] = $this->getId();
00284         $a_data['name'] = $this->getName();
00285         $a_data['description'] = $this->getDescription();
00286         $a_data['category_id'] = $this->getCategoryId();
00287         $a_data['vendor_id'] = $this->getVendorId();
00288         $a_data['status'] = $this->getStatus();
00289         $a_data['barcode'] = $this->getBarcode();
00290         $a_data['serial_num'] = $this->getSerialNum();
00291         $a_data['store_id'] = $this->getStoreId();
00292         $a_data['shopper_viewable'] = $this->getShopperViewable();
00293         $a_data['isGroup'] = $this->getIsGroup();
00294         $a_data['attributes'] = $this->attributes;
00295         $a_data['newComment'] = $this->getNewComment();
00296         $a_data['commentsToRemove'] = $this->commentsToRemove;
00297         $a_data['rules'] = $this->getRules();
00298         return $a_data;
00299     }
00300 
00301     // }}}
00302     // {{{ isBarcodeUnique()
00303 
00314     function isBarcodeUnique($in_isUpdate)
00315     {
00316         return $this->o_dataAccess->isBarcodeUnique($this->getBarcode(), $this->getId(), $in_isUpdate);
00317     }
00318 
00319     // }}}
00320     // {{{ getItemIdByBarcode()
00321 
00330     function getItemIdByBarcode($in_barcode)
00331     {
00332         return $this->o_dataAccess->getItemIdByBarcode($in_barcode);
00333     }
00334 
00335     // }}}
00336     // {{{ getLogEntryDescription()
00337 
00346     function getLogEntryDescription($in_id)
00347     {
00348         if ($this->fillById($in_id)) {
00349             return $this->name . ' (' . $this->barcode . ')';
00350         }
00351         else {
00352             return false;
00353         }
00354     }
00355 
00356     // }}}
00357     // {{{ getMostRecentBorrower()
00358     
00365     function getMostRecentBorrower()
00366     {
00367         $o_dao =& FF_DataAccess::factory('Transaction');
00368         return $o_dao->getMostRecentBorrower($this->getId());
00369     }
00370 
00371     // }}}
00372     // {{{ setName()
00373 
00374     function setName($in_value)
00375     {
00376         $this->name = $in_value;
00377     }
00378 
00379     // }}}
00380     // {{{ getName()
00381 
00382     function getName()
00383     {
00384         return $this->name;
00385     }
00386 
00387     // }}}
00388     // {{{ getFormattedDescription()
00389 
00396     function getFormattedDescription()
00397     {
00398         return nl2br(htmlspecialchars($this->description));
00399     }
00400 
00401     // }}}
00402     // {{{ setDescription()
00403 
00404     function setDescription($in_value)
00405     {
00406         $this->description = $in_value;
00407     }
00408 
00409     // }}}
00410     // {{{ getDescription()
00411 
00412     function getDescription()
00413     {
00414         return $this->description;
00415     }
00416 
00417     // }}}
00418     // {{{ getVendorName()
00419 
00426     function getVendorName()
00427     {
00428         if (!FastFrame::isEmpty($this->vendorId)) {
00429             require_once dirname(__FILE__) . '/Vendor.php';
00430             $o_vendorModel =& new FF_Model_Vendor();
00431             if ($o_vendorModel->fillById($this->vendorId)) {
00432                 return $o_vendorModel->getName();
00433             }
00434         }
00435 
00436         return _('No Vendor Selected');
00437     }
00438 
00439     // }}}
00440     // {{{ getVendorId()
00441 
00442     function getVendorId()
00443     {
00444         return $this->vendorId;
00445     }
00446 
00447     // }}}
00448     // {{{ setVendorId()
00449 
00450     function setVendorId($in_value)
00451     {
00452         $this->vendorId = $in_value;
00453     }
00454 
00455     // }}}
00456     // {{{ getCategoryName()
00457 
00464     function getCategoryName()
00465     {
00466         if (!FastFrame::isEmpty($this->categoryId)) {
00467             require_once dirname(__FILE__) . '/Category.php';
00468             $o_categoryModel =& new FF_Model_Category();
00469             if ($o_categoryModel->fillById($this->categoryId)) {
00470                 return $o_categoryModel->getName();
00471             }
00472         }
00473 
00474         return _('No Category Selected');
00475     }
00476 
00477     // }}}
00478     // {{{ getCategoryId()
00479 
00480     function getCategoryId()
00481     {
00482         return $this->categoryId;
00483     }
00484 
00485     // }}}
00486     // {{{ setCategoryId()
00487 
00488     function setCategoryId($in_value)
00489     {
00490         $this->categoryId = $in_value;
00491     }
00492 
00493     // }}}
00494     // {{{ getBarcode()
00495 
00496     function getBarcode()
00497     {
00498         return $this->barcode;
00499     }
00500 
00501     // }}}
00502     // {{{ setBarcode()
00503 
00504     function setBarcode($in_value)
00505     {
00506         $this->barcode = $in_value;
00507     }
00508 
00509     // }}}
00510     // {{{ getStatusOptions()
00511 
00518     function getStatusOptions()
00519     {
00520         return array(
00521                 ITEM_STATUS_AVAILABLE => _('Available'),
00522                 ITEM_STATUS_ONLOAN => _('On Loan'), 
00523                 ITEM_STATUS_UNAVAILABLE => _('Unavailable'),
00524                 ITEM_STATUS_MISSING => _('Missing'), 
00525                 ITEM_STATUS_REPAIR=>_('Repair')
00526             );
00527     }
00528 
00529     // }}}
00530     // {{{ getFormattedStatus()
00531 
00538     function getFormattedStatus()
00539     {
00540         if ($this->getIsGroup()) {
00541             return _('N/A');
00542         }
00543         else {
00544             $a_options = $this->getStatusOptions();
00545             return isset($a_options[$this->status]) ? $a_options[$this->status] : _('Invalid Status');
00546         }
00547     }
00548 
00549     // }}}
00550     // {{{ getStatus()
00551 
00552     function getStatus()
00553     {
00554         return $this->status;
00555     }
00556 
00557     // }}}
00558     // {{{ setStatus()
00559 
00560     function setStatus($in_value)
00561     {
00562         $this->status = $in_value;
00563     }
00564 
00565     // }}}
00566     // {{{ getSerialNum()
00567 
00568     function getSerialNum()
00569     {
00570         return $this->serialNum;
00571     }
00572 
00573     // }}}
00574     // {{{ setSerialNum()
00575 
00576     function setSerialNum($in_value)
00577     {
00578         $this->serialNum = $in_value;
00579     }
00580 
00581     // }}}
00582     // {{{ getShopperViewable()
00583 
00584     function getShopperViewable()
00585     {
00586         return $this->shopperViewable;
00587     }
00588 
00589     // }}}
00590     // {{{ setShopperViewable()
00591 
00592     function setShopperViewable($in_value)
00593     {
00594         $this->shopperViewable = $this->_scalarToBool($in_value);
00595     }
00596 
00597     // }}}
00598     // {{{ getStoreId()
00599 
00600     function getStoreId()
00601     {
00602         return $this->storeId;
00603     }
00604 
00605     // }}}
00606     // {{{ setStoreId()
00607 
00608     function setStoreId($in_value)
00609     {
00610         $this->storeId = $in_value;
00611     }
00612 
00613     // }}}
00614     // {{{ getFormattedIsGroup()
00615 
00622     function getFormattedIsGroup()
00623     {
00624         return $this->getIsGroup() ? _('Yes') : _('No');
00625     }
00626 
00627     // }}}
00628     // {{{ getIsGroup()
00629 
00630     function getIsGroup()
00631     {
00632         return $this->isGroup;
00633     }
00634 
00635     // }}}
00636     // {{{ setIsGroup()
00637 
00638     function setIsGroup($in_value)
00639     {
00640         $this->isGroup = $in_value;
00641     }
00642 
00643     // }}}
00644     // {{{ getIsDeleted()
00645 
00646     function getIsDeleted()
00647     {
00648         return $this->isDeleted;
00649     }
00650 
00651     // }}}
00652     // {{{ setIsDeleted()
00653 
00654     function setIsDeleted($in_value)
00655     {
00656         $this->isDeleted = $this->_scalarToBool($in_value);
00657     }
00658 
00659     // }}}
00660     // {{{ getAttribute()
00661 
00670     function getAttribute($in_attr)
00671     {
00672         return isset($this->attributes[$in_attr]) ? $this->attributes[$in_attr] : null;
00673     }
00674 
00675     // }}}
00676     // {{{ setAttribute()
00677 
00687     function setAttribute($in_attr, $in_value)
00688     {
00689         $this->attributes[$in_attr] = $in_value;
00690     }
00691 
00692     // }}}
00693     // {{{ getNewComment()
00694 
00695     function getNewComment()
00696     {
00697         return $this->newComment;
00698     }
00699 
00700     // }}}
00701     // {{{ setNewComment()
00702 
00711     function setNewComment($in_comment)
00712     {
00713         $this->newComment = $in_comment;
00714     }
00715 
00716     // }}}
00717     // {{{ getCommentsToRemove()
00718 
00727     function getCommentsToRemove($in_formize = false)
00728     {
00729         $a_comments = $this->commentsToRemove;
00730         if ($in_formize) {
00731             foreach ($a_comments as $s_key => $s_val) {
00732                 unset($a_comments[$s_key]);
00733                 $a_comments['comments'][$s_val] = 1;
00734             }
00735         }
00736 
00737         return $a_comments;
00738     }
00739 
00740     // }}}
00741     // {{{ setCommentsToRemove()
00742 
00751     function setCommentsToRemove($in_comments)
00752     {
00753         $this->commentsToRemove = array_keys((array) $in_comments);
00754     }
00755 
00756     // }}}
00757     // {{{ getRuleOptions()
00758 
00765     function getRuleOptions()
00766     {
00767         $o_rulesDataAccess =& FF_DataAccess::factory('Rule');
00768         return $o_rulesDataAccess->getRuleOptions($this->getId());
00769     }
00770 
00771     // }}}
00772     // {{{ getRules()
00773 
00774     function getRules()
00775     {
00776         return $this->rules;
00777     }
00778 
00779     // }}}
00780     // {{{ setRules()
00781 
00782     function setRules($in_value)
00783     {
00784         $this->rules = $in_value;
00785     }
00786 
00787     // }}}
00788     // {{{ _initDataAccess()
00789 
00796     function _initDataAccess()
00797     {
00798         $this->o_dataAccess =& FF_DataAccess::factory('Item');
00799     }
00800 
00801     // }}}
00802 }
00803 ?>

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