Exemplo n.º 1
0
 /**
  * Set basic properties for the item, whether in a list or a singleton
  *
  * @param unknown_type $item
  * @param unknown_type $key
  * @param unknown_type $refresh
  */
 protected function prepareItem(&$item, $key = 0, $refresh = false)
 {
     $getEav = $this->_getEav;
     $options = $this->_getEavOptions;
     $eavStates = count($this->getEavState()->getProperties());
     if (!empty($getEav) || $eavStates > 0) {
         $app = JFactory::getApplication();
         $editable_by = method_exists('isAdmin', $app) && $app->isAdmin() ? 1 : 2;
         // CLI fix
         Tienda::load('TiendaModelEavAttributes', 'models.eavattributes');
         Tienda::load("TiendaHelperBase", 'helpers._base');
         $eav_helper = TiendaHelperBase::getInstance('Eav');
         $entity = $this->getTable()->get('_suffix');
         $tbl_key = $this->getTable()->getKeyName();
         $entity_id = $item->{$tbl_key};
         // add the custom fields as properties
         $eavs = $eav_helper->getAttributes($entity, $entity_id, false, $editable_by);
         // Mirrored table?
         if (!count($eavs) && strlen($this->getTable()->getLinkedTable())) {
             $entity = $this->getTable()->getLinkedTable();
             $entity_id = $item->{$this->getTable()->getLinkedTableKeyName()};
             $eavs = $eav_helper->getAttributes($entity, $entity_id, false, $editable_by);
         }
         foreach ($eavs as $eav) {
             $key = $eav->eavattribute_alias;
             $add = true;
             // Include Mode: Fetch only these fields
             if (array_key_exists('include', $options)) {
                 foreach ($options['include'] as $k) {
                     if ($key != $k) {
                         $add = false;
                     }
                 }
             } else {
                 // Exclude Mode: Fetch everything except these fields
                 if (array_key_exists('exclude', $options)) {
                     foreach ($options['exclude'] as $k) {
                         if ($key == $k) {
                             $add = false;
                         }
                     }
                 }
                 // Default Mode: Fetch Everything
             }
             if ($add) {
                 $value = $eav_helper->getAttributeValue($eav, $this->getTable()->get('_suffix'), $item->{$tbl_key}, true, true);
                 // Do NOT ovveride properties
                 if (!property_exists($item, $key)) {
                     $item->{$key} = $value;
                 }
             }
         }
     }
     parent::prepareItem($item, $key, $refresh);
 }
Exemplo n.º 2
0
 /**
  * Set basic properties for the item, whether in a list or a singleton
  *
  * @param unknown_type $item
  * @param unknown_type $key
  * @param unknown_type $refresh
  */
 protected function prepareItem(&$item, $key = 0, $refresh = false)
 {
     $item->link = 'index.php?option=com_tienda&view=addresses&task=edit&id=' . $item->address_id;
     if (!empty($item->extra_fields)) {
         $extra_fields = new DSCParameter(trim($item->extra_fields));
         $extra_fields = $extra_fields->toArray();
         foreach ($extra_fields as $k => $v) {
             $item->{$k} = $v;
         }
     }
     parent::prepareItem($item, $key, $refresh);
 }