public function getAttributes($hostParentId = null) { $attr = new Ot_Model_DbTable_CustomAttribute(); $where = $attr->getAdapter()->quoteInto('hostKey = ?', $this->getKey()); $results = $attr->fetchAll($where, 'order')->toArray(); $attributes = array(); $ftr = new Ot_CustomAttribute_FieldTypeRegister(); $fieldTypes = $ftr->getFieldTypes(); foreach ($results as $r) { if (!isset($fieldTypes[$r['fieldTypeKey']])) { continue; } $r['fieldType'] = $fieldTypes[$r['fieldTypeKey']]; $r['var'] = $r['fieldType']->getVar(); $r['var']->setLabel($r['label'])->setDescription($r['description'])->setOptions(unserialize($r['options']))->setName($this->getKey() . $r['attributeId'])->setRequired($r['required']); $attributes[$this->getKey() . $r['attributeId']] = $r; } if (!is_null($hostParentId)) { $attrValModel = new Ot_Model_DbTable_CustomAttributeValue(); $where = $attrValModel->getAdapter()->quoteInto('hostKey = ?', $this->getKey()) . ' AND ' . $attrValModel->getAdapter()->quoteInto('hostParentId = ?', $hostParentId); $attrValues = $attrValModel->fetchAll($where); foreach ($attrValues as $a) { if (isset($attributes[$this->getKey() . $a->attributeId])) { $attributes[$this->getKey() . $a->attributeId]['var']->setRawValue($a->value); } } } return $attributes; }
/** * Updates the display order of the attributes from the AJAX request * */ public function saveAttributeOrderAction() { $this->_helper->viewRenderer->setNeverRender(); $this->_helper->layout->disableLayout(); $key = $this->_getParam('key', null); $attributeIds = $this->_getParam('attributeIds', array()); if (is_null($key)) { $ret = array('rc' => 0, 'msg' => $this->view->translate('msg-error-objectIdNotSet')); echo Zend_Json_Encoder::encode($ret); return; } $cahr = new Ot_CustomAttribute_HostRegister(); $thisHost = $cahr->getHost($key); if (is_null($thisHost)) { $ret = array('rc' => 0, 'msg' => $this->view->translate('msg-error-objectIdNotSet')); echo Zend_Json_Encoder::encode($ret); return; } if (count($attributeIds) == 0) { $ret = array('rc' => 0, 'msg' => $this->view->translate('msg-error-attributeIdsNotSet')); echo Zend_Json_Encoder::encode($ret); return; } if ($this->_request->isPost()) { $attr = new Ot_Model_DbTable_CustomAttribute(); $dba = $attr->getAdapter(); $dba->beginTransaction(); $i = 1; foreach ($attributeIds as $id) { $id = (int) substr($id, strpos($id, '_') + 1); $data = array("order" => $i); $where = $dba->quoteInto('attributeId = ?', $id) . " AND " . $dba->quoteInto('hostKey = ?', $key); try { $attr->update($data, $where); } catch (Exception $e) { $dba->rollBack(); $ret = array('rc' => 0, 'msg' => $this->view->translate('msg-error-orderNotSaved', $e->getMessage())); echo Zend_Json_Encoder::encode($ret); return; } $i++; } $dba->commit(); $logOptions = array('attributeName' => 'hostKey', 'attributeId' => $key); $this->_helper->log(Zend_Log::INFO, $thisHost->getName() . ' had attributes reordered', $logOptions); $ret = array('rc' => 1, 'msg' => $this->view->translate('msg-info-newOrderSaved')); echo Zend_Json_Encoder::encode($ret); return; } }