/** * Return the singleton instance of box object * * @param string $block * @param array $config * @return Axis_Core_Box_Abstract * @throws Axis_Exception */ public function box($block, $config = array()) { $block = Axis::getClass($block, 'Box'); if (Zend_Registry::isRegistered($block)) { return Zend_Registry::get($block)->refresh()->setFromArray($config); } return Axis::single($block, $config); }
public function loadAction() { $id = $this->_getParam('id'); $data = Axis::model('core/template_box')->find($id)->current()->toArray(); list($namespace, $module, $name) = explode('_', $data['class']); $boxClass = Axis::getClass($namespace . '_' . $module . '/' . $name, 'Box'); $boxObject = Axis::model($boxClass, array('supress_init' => true)); $data['configuration_fields'] = $boxObject->getConfigurationFields(); $data['configuration_values'] = $boxObject->getConfigurationValues(); $select = Axis::model('core/template_box_page')->select('*')->where('box_id = ?', $id); $data['assignments'] = array(); foreach ($select->fetchAll() as $assignment) { $data['assignments'][] = $assignment; } return $this->_helper->json->setData($data)->sendSuccess(); }
public function saveAction() { $path = $this->_getParam('path'); $siteId = $this->_getParam('siteId'); $value = $this->_getParam('value'); $rowField = Axis::single('core/config_field')->select()->where('path = ?', $path)->fetchRow(); $model = Axis::model('core/config_value'); $row = $model->select()->where('path = ?', $path)->where('site_id = ?', $siteId)->fetchRow(); /* * if such row not founded then create new record * It possible when we redeclare global config_value for site */ if (!$row) { $row = $model->createRow(array('config_field_id' => $rowField->id, 'path' => $path, 'site_id' => $siteId)); } if (!empty($rowField->model)) { $class = Axis::getClass($rowField->model); if (class_exists($class) && in_array('Axis_Config_Option_Encodable_Interface', class_implements($class))) { $value = Axis::model($rowField->model)->encode($value); } } $row->value = $value; $row->save(); Axis::message()->addSuccess(Axis::translate('admin')->__('Configuration option was saved successfully')); return $this->_helper->json->sendSuccess(); }
protected function _savePrevious() { $rowData = $this->_rowField; $this->_rowField = array(); if (empty($rowData)) { return; } $modelField = Axis::single('core/config_field'); $rowField = $modelField->select()->where('path = ?', $rowData['path'])->fetchRow(); if (!$rowField) { $rowData = array_merge($this->_defaultsRowField, $rowData); $rowField = $modelField->createRow(); } if ($this->_isContainer) { $rowData = array_merge($rowData, array('type' => '', 'model' => '')); } $rowField->setFromArray($rowData); $rowField->save(); if ($this->_isContainer) { return; } $modelValue = Axis::single('core/config_value'); $rowValue = $modelValue->select()->where('path = ?', $rowData['path'])->where('config_field_id = ?', $rowField->id)->where('site_id = ?', 0)->fetchRow(); if (!$rowValue) { $rowValue = $modelValue->createRow(array('config_field_id' => $rowField->id, 'path' => $rowData['path'], 'site_id' => 0)); } if (null !== $this->_rawValue) { $value = $this->_rawValue; if (!empty($rowData['model'])) { $class = Axis::getClass($rowData['model']); if (class_exists($class) && in_array('Axis_Config_Option_Encodable_Interface', class_implements($class))) { $value = Axis::model($rowData['model'])->encode($value); } } $rowValue->value = $value; } $rowValue->save(); }
private function _load($key, $siteId, $default) { if (null === $siteId) { $siteId = Axis::getSiteId(); } $hasCache = (bool) Zend_Registry::isRegistered('cache') ? Axis::cache() instanceof Zend_Cache_Core : false; if (!$hasCache || !($dataset = Axis::cache()->load("config_{$key}_site_{$siteId}"))) { $dataset = Axis::single('core/config_field')->select(array('path', 'model'))->joinInner('core_config_value', 'ccv.config_field_id = ccf.id', 'value')->where('ccf.path LIKE ?', $key . '/%')->where('ccv.site_id IN(?)', array(0, $siteId))->fetchAssoc(); if ($hasCache) { Axis::cache()->save($dataset, "config_{$key}_site_{$siteId}", array('config')); } } if (!sizeof($dataset)) { $this->_data[$key] = $default; return; } $values = array(); foreach ($dataset as $path => $data) { $parts = explode('/', $path); $value = $data['value']; if (!empty($data['model'])) { $class = Axis::getClass($data['model']); if (class_exists($class) && in_array('Axis_Config_Option_Encodable_Interface', class_implements($class))) { $value = Axis::single($data['model'])->decode($value); } } $values[$parts[0]][$parts[1]][$parts[2]] = $value; } foreach ($values as $key => $value) { if (is_array($value)) { $this->_data[$key] = new self($value, $this->_allowModifications); } else { $this->_data[$key] = $value; } } }
/** * Retrieve the box object * * @param string $block * @param array $config * @return Axis_Core_Box_Abstract * @throws Axis_Exception */ public function box($block, $config = array()) { return Axis::model(Axis::getClass($block, 'Box'), $config); }