/** * Load the confgi data into the passed $object * * @param Core_Model_Abstract $object * @param string $scope * @param int $scopeId * @return Core_Model_Abstract */ public function loadConfigData(Core_Model_Abstract $object, $scope = 'default', $scopeId = 0) { $results = $this->_getReadAdapter()->fetchAll("SELECT * FROM " . $this->tbl_config_data . " WHERE scope='" . $scope . "' AND scope_id=" . $scopeId . "\n GROUP BY path ORDER BY scope DESC"); if (!$results) { return $object; } foreach ($results as $result) { $object->setData($result['path'], $result['value']); } return $object; }
/** * Processing data before saving user info * * @return Admin_Model_User */ protected function _beforeSave() { if ($this->userExists()) { $this->_dataSaveAllowed = false; App_Main::getSession()->addError('Username or email already exists'); return false; } return parent::_beforeSave(); }
public function __get($var) { // 我的扩展行为 static $_traits = array('base' => 1); if (isset($_traits[$var])) { $class = 'Model_User_' . ucfirst($var); return $this->{$var} = new $class($this); } parent::__get($var); }
/** * 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; }
public function __construct($data = array()) { parent::__construct($data); }
/** * Additional get data with clear mode * * @param string $key * @param bool $clear * @return mixed */ public function getData($key = '', $clear = false) { $data = parent::getData($key); if ($clear && isset($this->_data[$key])) { unset($this->_data[$key]); } return $data; }
/** * Prepare the object data for saving to the database * If $table is null, the main table is used and the fields are identified * * @param Core_Model_Abstract $object * @param bool $graceful * @param string $table * @return type */ protected function _prepareDataForSave(Core_Model_Abstract $object, $graceful = false, $table = false) { $data = array(); $table = !$table ? $this->getMainTable() : $table; $fields = $this->_getWriteAdapter()->describeTable($table); foreach ($fields as $field => $fieldInfo) { if (!$object->hasData($field) && $fieldInfo['Null'] == 'NO') { if (isset($fieldInfo['Default'])) { continue; } if (isset($fieldInfo['Key']) && $fieldInfo['Key'] == 'PRI') { continue; } //@# ToDO add the check to auto increment here if needed } if ($object->hasData($field)) { $data[$field] = $this->_prepareValueForSave($object->getData($field), $fieldInfo['data_type']); } else { if ($fieldInfo['Null'] == 'NO' && !isset($fieldInfo['Default']) && $graceful) { //set empty string for those field which does not have default value and is nullable $data[$field] = $this->_prepareValueForSave(''); } else { continue; } } } return $data; }
/** * Save url information * * @param Core_Model_Visitor $visitor * @return Core_Model_Resource_Visitor */ protected function _saveUrlInfo(Core_Model_Abstract $visitor) { $this->_getWriteAdapter()->insert($this->tbl_url_info, array('url' => $this->_prepareValueForSave(App_Main::getHelper('core/string')->substr($visitor->getUrl(), 0, 250)), 'referer' => $this->_prepareValueForSave(App_Main::getHelper('core/string')->substr($visitor->getHttpReferer(), 0, 250)))); $visitor->setLastUrlId($this->_getWriteAdapter()->lastInsertId()); return $this; }
/** * 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; }
/** * 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() . "'"); }