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; }
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; }
/** * 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)); }
public function _initCustomFields() { // register types of vars available $varTypes = array(); $varTypes[] = new Ot_CustomAttribute_FieldType('date', 'Date selector', 'Ot_Var_Type_Date'); $varTypes[] = new Ot_CustomAttribute_FieldType('multiselect', 'Multi-Select Box', 'Ot_Var_Type_Multiselect', true); $varTypes[] = new Ot_CustomAttribute_FieldType('multicheckbox', 'Multi Checkbox', 'Ot_Var_Type_Multicheckbox', true); $varTypes[] = new Ot_CustomAttribute_FieldType('select', 'Dropdown Box', 'Ot_Var_Type_Select', true); $varTypes[] = new Ot_CustomAttribute_FieldType('text', 'Short Text Box', 'Ot_Var_Type_Text'); $varTypes[] = new Ot_CustomAttribute_FieldType('textarea', 'Textarea', 'Ot_Var_Type_Textarea'); $varTypes[] = new Ot_CustomAttribute_FieldType('checkbox', 'Checkbox', 'Ot_Var_Type_Checkbox'); $varTypes[] = new Ot_CustomAttribute_FieldType('radio', 'Radio Buttons', 'Ot_Var_Type_Radio', true); $varTypes[] = new Ot_CustomAttribute_FieldType('description', 'Description', 'Ot_Var_Type_Description'); $varTypes[] = new Ot_CustomAttribute_FieldType('ranking', 'Ranking', 'Ot_Var_Type_Ranking'); $ftr = new Ot_CustomAttribute_FieldTypeRegister(); $ftr->registerFieldTypes($varTypes); // Register host objects that these vars can be attached to $hosts = array(); $hosts[] = new Ot_CustomAttribute_Host('Ot_Profile', 'User Account', 'Central OT Framework user account object'); $cfor = new Ot_CustomAttribute_HostRegister(); $cfor->registerHosts($hosts); }