コード例 #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;
 }
コード例 #2
0
ファイル: Abstract.php プロジェクト: hettema/Stages
 /**
  * Load an object model data from db
  *
  * @param   Core_Model_Abstract $object
  * @param   mixed $value
  * @param   string $field field to load by (defaults to model id)
  * @return  Core_Model_Resource_Abstract
  */
 public function load(Core_Model_Abstract $object, $value, $field = null)
 {
     if (is_null($field)) {
         $field = $this->getIdFieldName();
     }
     $read = $this->_getReadAdapter();
     if (!is_null($value)) {
         $data = $this->_getReadAdapter()->fetchRow("SELECT * FROM " . $this->getMainTable() . " WHERE " . $field . "='" . $value . "'");
         if ($data) {
             $object->setData($data);
         }
     }
     if ($object->getId()) {
         $this->_afterLoad($object);
     }
     return $this;
 }
コード例 #3
0
ファイル: Rewrite.php プロジェクト: hettema/Stages
 /**
  * Create a new url rewite information
  *
  * @param Core_Model_Abstract $object
  * @param string $idpath
  * @param string $requestPath
  * @param string $targetPath
  * @return Core_Model_Url_Rewrite 
  */
 public function newUrlRewite(Core_Model_Abstract $object, $idpath = null, $requestPath = null, $targetPath = null)
 {
     if (empty($requestPath)) {
         if (!$object->getRequestPath()) {
             if ($object->getRequestPathPrepend()) {
                 $requestPath .= trim($object->getRequestPathPrepend(), '/') . '/';
             }
             if ($object->getUrlKey()) {
                 $requestPath .= $object->getUrlKey();
             } else {
                 $requestPath .= $object->getId();
             }
         } else {
             $requestPath = $object->getRequestPath();
         }
     }
     $data['request_path'] = mb_strtolower($requestPath, 'UTF-8');
     if (empty($targetPath)) {
         if (!$object->getTargetPath()) {
             if ($object->getTargetPathPrepend()) {
                 $targetPath .= trim($object->getTargetPathPrepend(), '/') . '/';
             }
             $targetPath .= $object->getId();
         } else {
             $targetPath = $object->getTargetPath();
         }
     }
     $data['target_path'] = $targetPath;
     if (empty($idpath)) {
         if (!$object->getIdPath()) {
             if ($object->getIdPathPrepend()) {
                 $idpath .= rtrim($object->getIdPathPrepend(), '/') . '/';
             }
             $idpath .= $object->getId();
         } else {
             $idpath = $object->getIdPath();
         }
     }
     $data['id_path'] = $idpath;
     $this->setData($data);
     $this->loadByIdPath($data['id_path']);
     if (!$this->getId()) {
         $this->loadByRequestPath($data['request_path']);
     }
     $this->save();
     return $this;
 }
コード例 #4
0
ファイル: Visitor.php プロジェクト: hettema/Stages
 /**
  * Save visitor and url relation
  *
  * @param   Core_Model_Visitor $visitor
  * @return  Core_Model_Resource_Visitor
  */
 protected function _saveVisitorUrl(Core_Model_Abstract $visitor)
 {
     $write = $this->_getWriteAdapter();
     $write->insert($this->tbl_url, array('url_id' => $visitor->getLastUrlId(), 'visitor_id' => $visitor->getId(), 'visit_time' => $this->_prepareValueForSave(now())));
     return $this;
 }
コード例 #5
0
ファイル: User.php プロジェクト: hettema/Stages
 /**
  * Check whether the user already exists
  * checks for email  and username
  * 
  * @param Core_Model_Abstract $user
  * @return type 
  */
 public function userExists(Core_Model_Abstract $user)
 {
     return $this->_getReadAdapter()->fetchRow("SELECT * FROM " . $this->tbl_user . " WHERE (username = '******' OR email = '" . $user->getEmail() . "') AND user_id != '" . $user->getId() . "'");
 }