コード例 #1
0
ファイル: Eav.php プロジェクト: hettema/Stages
 /**
  * Load the eav data into the object
  * If attributes is passed (array of attribute_code) the data values will be loaded only for the specified attributes
  *
  * @param Core_Model_Abstract $object
  * @param array $attributes
  * @return Core_Model_Abstract 
  */
 public function loadEavData(Core_Model_Abstract $object, $attributes = array())
 {
     $entityId = $object->getId();
     $entityTypeId = $object->getEntityTypeId();
     if (empty($entityId) || empty($entityTypeId)) {
         return false;
     }
     $sql = "SELECT\n                        tbl_attr.attribute_code,\n                        tbl_attr.attribute_id,\n                        tbl_attr.frontend_input,\n                        tbl_value.value\n                    FROM\n                        valueTable  AS tbl_value\n                        LEFT JOIN " . $this->tbl_eav_entity_attribute . " AS tbl_entity_attr ON tbl_entity_attr.attribute_id = tbl_value.attribute_id\n                        LEFT JOIN " . $this->tbl_eav_attribute . " AS tbl_attr ON tbl_attr.attribute_id = tbl_entity_attr.attribute_id\n                    WHERE\n                        tbl_value.entity_id = " . $entityId . "\n                        AND tbl_entity_attr.entity_type_id = " . $entityTypeId . "";
     //load the data only for the specific attributes if given
     if (!empty($attributes) && is_array($attributes)) {
         $sql .= " AND tbl_attr.attribute_code IN ('" . implode("','", $attributes) . "')";
     }
     $eavOptionValues = array();
     foreach ($this->tbl_set_eav as $table) {
         $result = $this->_getReadAdapter()->fetchAll(str_replace('valueTable', $table, $sql));
         if (empty($result)) {
             continue;
         }
         foreach ($result as $row) {
             $object->setData($row['attribute_code'], $row['value']);
             if ($row['frontend_input'] == 'select' || $row['frontend_input'] == 'multiselect') {
                 $valueId = intval($row['value']);
                 if (empty($valueId)) {
                     continue;
                 }
                 $optionValue = $this->_getReadAdapter()->fetchColumn("SELECT value FROM " . $this->tbl_eav_attr_option_value . " WHERE value_id IN (" . $valueId . ")", 'value');
                 $eavOptionValues[$row['attribute_code']] = implode(',', $optionValue);
             }
         }
     }
     //set the origianl data prior to adding the display data
     $object->setOrigData();
     //set the attribute option values
     foreach ($eavOptionValues as $attributeCode => $value) {
         $object->setData($attributeCode, $value);
     }
     return $object;
 }