Model/Group.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 // {{{ class FF_Model_Group
00030 
00044 // }}}
00045 class FF_Model_Group extends FF_Model {
00046     // {{{ properties
00047 
00052     var $name;
00053     
00058     var $description;
00059 
00064     var $categoryId;
00065 
00070     var $storeId;
00071 
00076     var $shopperViewable = true;
00077 
00082     var $isKit = false;
00083 
00088     var $items = array();
00089 
00094     var $itemsToRemove = array();
00095 
00100     var $rules = array();
00101 
00102     // }}}
00103     // {{{ save()
00104 
00114     function save($in_isUpdate)
00115     {
00116         $o_result =& parent::save($in_isUpdate);
00117             
00118         // Handle items that were set to be removed and rules
00119         if ($o_result->isSuccess()) {
00120             $tmp_result =& $this->removeItems();
00121             if (!$tmp_result->isSuccess()) {
00122                 $o_result->addMessage($tmp_result->getMessages());
00123             }
00124 
00125             $o_rulesDataAccess =& FF_DataAccess::factory('Rule');
00126             $tmp_result =& $o_rulesDataAccess->updateRulesForItem($this->getId(), $this->getRules());
00127             if (!$tmp_result->isSuccess()) {
00128                 $o_result->addMessage($tmp_result->getMessages());
00129             }
00130 
00131             $this->o_dataAccess->updateRelationships($this->getId(), $this->getAllItems());
00132         }
00133 
00134         return $o_result;
00135     }
00136 
00137     // }}}
00138     // {{{ remove()
00139 
00140     /* Removes the current model or the one specified
00141      *
00142      * @param int $in_id (optional) The id to delete.  If not specified then the
00143      *            current id is used
00144      *
00145      * @access public
00146      * @return object A result object 
00147      */
00148     function remove($in_id = null)
00149     {
00150         $s_id = $in_id ? $in_id : $this->getId();
00151         $o_result =& parent::remove($in_id);
00152         $this->o_dataAccess->updateRelationships($s_id, array());
00153         return $o_result;
00154     }
00155 
00156     // }}}
00157     // {{{ reset()
00158 
00165     function reset()
00166     {
00167         $this->id = null;
00168         $this->name = null;
00169         $this->description = null;
00170         $this->categoryId = null;
00171         $this->shopperViewable = true;
00172         $this->isKit = false;
00173         $this->items = array();
00174         $this->itemsToRemove = array();
00175     }
00176 
00177     // }}}
00178     // {{{ importFromArray()
00179 
00188     function importFromArray($in_data)
00189     {
00190         $this->setId($in_data['id']);
00191         $this->setName($in_data['name']);
00192         $this->setDescription($in_data['description']);
00193         $this->setCategoryId($in_data['category_id']);
00194         $this->setShopperViewable($in_data['shopper_viewable']);
00195         $this->setIsKit($in_data['is_kit']);
00196         $this->setStoreId($in_data['store_id']);
00197         if (isset($in_data['items'])) {
00198             $this->items = $in_data['items'];
00199         }
00200 
00201         if (isset($in_data['itemsToRemove'])) {
00202             $this->itemsToRemove = $in_data['itemsToRemove'];
00203         }
00204 
00205         if (isset($in_data['rules'])) {
00206             $this->rules = $in_data['rules'];
00207         }
00208     }
00209 
00210     // }}}
00211     // {{{ exportToArray()
00212 
00221     function exportToArray()
00222     {
00223         $a_data = array();
00224         $a_data['id'] = $this->getId();
00225         $a_data['name'] = $this->getName();
00226         $a_data['description'] = $this->getDescription();
00227         $a_data['category_id'] = $this->getCategoryId();
00228         $a_data['store_id'] = $this->getStoreId();
00229         $a_data['shopper_viewable'] = $this->getShopperViewable();
00230         $a_data['is_kit'] = $this->getIsKit();
00231         $a_data['items'] = $this->items;
00232         $a_data['itemsToRemove'] = $this->itemsToRemove;
00233         $a_data['rules'] = $this->getRules();
00234         return $a_data;
00235     }
00236 
00237     // }}}
00238     // {{{ getLogEntryDescription()
00239 
00248     function getLogEntryDescription($in_id)
00249     {
00250         if ($this->fillById($in_id)) {
00251             return $this->name;
00252         }
00253         else {
00254             return false;
00255         }
00256     }
00257 
00258     // }}}
00259     // {{{ setName()
00260 
00261     function setName($in_value)
00262     {
00263         $this->name = $in_value;
00264     }
00265 
00266     // }}}
00267     // {{{ getName()
00268 
00269     function getName()
00270     {
00271         return $this->name;
00272     }
00273 
00274     // }}}
00275     // {{{ getFormattedDescription()
00276 
00283     function getFormattedDescription()
00284     {
00285         return nl2br(htmlspecialchars($this->description));
00286     }
00287 
00288     // }}}
00289     // {{{ setDescription()
00290 
00291     function setDescription($in_value)
00292     {
00293         $this->description = $in_value;
00294     }
00295 
00296     // }}}
00297     // {{{ getDescription()
00298 
00299     function getDescription()
00300     {
00301         return $this->description;
00302     }
00303 
00304     // }}}
00305     // {{{ getCategoryName()
00306 
00313     function getCategoryName()
00314     {
00315         if (!FastFrame::isEmpty($this->categoryId)) {
00316             require_once dirname(__FILE__) . '/Category.php';
00317             $o_categoryModel =& new FF_Model_Category();
00318             if ($o_categoryModel->fillById($this->categoryId)) {
00319                 return $o_categoryModel->getName();
00320             }
00321         }
00322 
00323         return _('No Category Selected');
00324     }
00325 
00326     // }}}
00327     // {{{ getCategoryId()
00328 
00329     function getCategoryId()
00330     {
00331         return $this->categoryId;
00332     }
00333 
00334     // }}}
00335     // {{{ setCategoryId()
00336 
00337     function setCategoryId($in_value)
00338     {
00339         $this->categoryId = $in_value;
00340     }
00341 
00342     // }}}
00343     // {{{ getShopperViewable()
00344 
00345     function getShopperViewable()
00346     {
00347         return $this->shopperViewable;
00348     }
00349 
00350     // }}}
00351     // {{{ setShopperViewable()
00352 
00353     function setShopperViewable($in_value)
00354     {
00355         $this->shopperViewable = $this->_scalarToBool($in_value);
00356     }
00357 
00358     // }}}
00359     // {{{ getStoreId()
00360 
00361     function getStoreId()
00362     {
00363         return $this->storeId;
00364     }
00365 
00366     // }}}
00367     // {{{ setStoreId()
00368 
00369     function setStoreId($in_value)
00370     {
00371         $this->storeId = $in_value;
00372     }
00373 
00374     // }}}
00375     // {{{ getIsKit()
00376 
00377     function getIsKit()
00378     {
00379         return $this->isKit;
00380     }
00381 
00382     // }}}
00383     // {{{ setIsKit()
00384 
00385     function setIsKit($in_value)
00386     {
00387         $this->isKit = $this->_scalarToBool($in_value);
00388     }
00389 
00390     // }}}
00391     // {{{ setItemsByBarcode()
00392 
00402     function setItemsByBarcode($in_barcodes)
00403     {
00404         if (!FastFrame::isEmpty($in_barcodes, false)) {
00405             require_once dirname(__FILE__) . '/Item.php';
00406             $o_itemModel =& new FF_Model_Item();
00407             $a_barcodes = preg_split('/\s/', $in_barcodes, -1, PREG_SPLIT_NO_EMPTY);
00408             foreach ($a_barcodes as $s_barcode) {
00409                 $this->setItem($o_itemModel->getItemIdByBarcode($s_barcode), $s_barcode);
00410             }
00411         }
00412     }
00413 
00414     // }}}
00415     // {{{ getBarcodeList()
00416 
00423     function getBarcodeList()
00424     {
00425         $s_items = '';
00426         foreach ($this->getLoadedItems() as $a_item) {
00427             if (!is_null($a_item['barcode'])) {
00428                 $s_items .= $a_item['barcode'] . ' ';
00429             }
00430         }
00431 
00432         return $s_items;
00433     }
00434 
00435     // }}}
00436     // {{{ setItemsToRemove()
00437 
00446     function setItemsToRemove($in_items)
00447     {
00448         $this->itemsToRemove = (array) $in_items;
00449     }
00450 
00451     // }}}
00452     // {{{ getItemsToRemove()
00453 
00460     function getItemsToRemove()
00461     {
00462         return $this->itemsToRemove;
00463     }
00464 
00465     // }}}
00466     // {{{ removeItems()
00467 
00474     function removeItems()
00475     {
00476         $o_result = new FF_Result();
00477         $a_items = $this->getItemsToRemove();
00478         foreach (array_keys($a_items) as $s_key) {
00479             foreach (array_keys($a_items[$s_key]) as $s_itemId) {
00480                 $this->o_dataAccess->removeItem($this->getId(), $s_itemId, $o_result);
00481             }
00482         }
00483 
00484         return $o_result;
00485     }
00486 
00487     // }}}
00488     // {{{ getAllItems()
00489 
00496     function getAllItems()
00497     {
00498         if (!FastFrame::isEmpty($this->id)) {
00499             return $this->o_dataAccess->getGroupItems($this->getId());
00500         }
00501         else {
00502             return array();
00503         }
00504     }
00505 
00506     // }}}
00507     // {{{ getLoadedItems()
00508 
00515     function getLoadedItems()
00516     {
00517         return $this->items;
00518     }
00519 
00520     // }}}
00521     // {{{ getItem()
00522 
00531     function getItem($in_id)
00532     {
00533         return isset($this->items[$in_id]) ? $this->items[$in_id] : '';
00534     }
00535 
00536     // }}}
00537     // {{{ setItem()
00538 
00548     function setItem($in_itemId, $in_barcode = null)
00549     {
00550         $this->items[] = array('itemId' => $in_itemId, 'barcode' => $in_barcode);
00551     }
00552 
00553     // }}}
00554     // {{{ getRuleOptions()
00555 
00562     function getRuleOptions()
00563     {
00564         $o_rulesDataAccess =& FF_DataAccess::factory('Rule');
00565         return $o_rulesDataAccess->getRuleOptions($this->getId());
00566     }
00567 
00568     // }}}
00569     // {{{ getRules()
00570 
00571     function getRules()
00572     {
00573         return $this->rules;
00574     }
00575 
00576     // }}}
00577     // {{{ setRules()
00578 
00579     function setRules($in_value)
00580     {
00581         $this->rules = $in_value;
00582     }
00583 
00584     // }}}
00585     // {{{ _initDataAccess()
00586 
00593     function _initDataAccess()
00594     {
00595         $this->o_dataAccess =& FF_DataAccess::factory('Group');
00596     }
00597 
00598     // }}}
00599 }
00600 ?>

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