public function get($attributeId) { $thisAttribute = $this->find($attributeId); if (is_null($thisAttribute)) { throw new Ot_Exception_Data('msg-error-noAttribute'); } $thisAttribute = $thisAttribute->toArray(); $ftr = new Ot_CustomAttribute_FieldTypeRegister(); $thisAttribute['fieldType'] = $ftr->getFieldType($thisAttribute['fieldTypeKey']); if (is_null($thisAttribute['fieldType'])) { throw new Ot_Exception_Data('Field type (' . $thisAttribute['fieldTypeKey'] . ' not registered'); } $cahr = new Ot_CustomAttribute_HostRegister(); $thisAttribute['host'] = $cahr->getHost($thisAttribute['hostKey']); if (is_null($thisAttribute['host'])) { throw new Ot_Exception_Data('Host (' . $thisAttribute['hostKey'] . ') not registered'); } $options = unserialize($thisAttribute['options']); $thisAttribute['options'] = array(); if (is_array($options)) { foreach ($options as $a) { $thisAttribute['options'][]['option'] = $a; } } return $thisAttribute; }
/** * Adds a new attribute to a node * */ public function addAction() { $key = $this->_getParam('key', null); $fieldTypeKey = $this->_getParam('fieldTypeKey', null); if (is_null($key)) { throw new Ot_Exception_Input('msg-error-objectNotFound'); } $cahr = new Ot_CustomAttribute_HostRegister(); $thisHost = $cahr->getHost($key); if (is_null($thisHost)) { throw new Ot_Exception_Input('msg-error-objectNotSetup'); } $caft = new Ot_CustomAttribute_FieldTypeRegister(); $thisFieldType = $caft->getFieldType($fieldTypeKey); if (is_null($thisFieldType)) { throw new Ot_Exception_Input('Field type not setup in bootstrap'); } $numberOfOptions = $this->_request->isPost() ? $this->_getParam('rowCt', 0) : ($thisFieldType->hasOptions() ? 1 : 0); $form = new Ot_Form_CustomAttribute(array('numberOfOptions' => $numberOfOptions)); if ($this->_request->isPost()) { if ($form->isValid($_POST)) { $data = array('hostKey' => $key, 'fieldTypeKey' => $fieldTypeKey, 'label' => $form->getValue('label'), 'description' => $form->getValue('description'), 'required' => $form->getValue('required')); if ($thisFieldType->hasOptions()) { $options = array(); foreach ($form->getValue('options') as $o) { if ($o['option'] != '') { $options[] = $o['option']; } } $data['options'] = serialize($options); } $attr = new Ot_Model_DbTable_CustomAttribute(); $attributeId = $attr->insert($data); $logOptions = array('attributeName' => 'hostKey', 'attributeId' => $data['hostKey']); $this->_helper->log(Zend_Log::INFO, 'Attribute ' . $data['label'] . ' added', $logOptions); $logOptions = array('attributeName' => 'attributeId', 'attributeId' => $attributeId); $this->_helper->log(Zend_Log::INFO, $data['label'] . ' added', $logOptions); $this->_helper->messenger->addSuccess($this->view->translate('msg-info-attributeAdded', array($data['label'], $thisHost->getName()))); $this->_helper->redirector->gotoRoute(array('controller' => 'custom', 'action' => 'details', 'key' => $key), 'ot', true); } } $this->_helper->pageTitle('ot-custom-add:title', array($thisFieldType->getName(), $thisHost->getName())); $this->view->assign(array('fieldType' => $thisFieldType, 'host' => $thisHost, 'form' => $form)); }