protected function _initializeCustomfields() { foreach (TBGCustomDatatype::getAll() as $key => $customdatatype) { $var_name = "_customfield" . $key; $this->{$var_name} = null; } if ($rows = TBGIssueCustomFieldsTable::getTable()->getAllValuesByIssueID($this->getID())) { foreach ($rows as $row) { $datatype = new TBGCustomDatatype($row->get(TBGIssueCustomFieldsTable::CUSTOMFIELDS_ID)); $var_name = "_customfield" . $datatype->getKey(); if ($datatype->hasCustomOptions()) { $option = TBGCustomFieldOptionsTable::getTable()->selectById((int) $row->get(TBGIssueCustomFieldsTable::CUSTOMFIELDOPTION_ID)); if ($option instanceof TBGCustomDatatypeOption) { $this->{$var_name} = $option; } } else { if ($datatype->hasPredefinedOptions()) { $this->{$var_name} = $row->get(TBGIssueCustomFieldsTable::CUSTOMFIELDOPTION_ID); } else { $this->{$var_name} = $row->get(TBGIssueCustomFieldsTable::OPTION_VALUE); } } } } }
/** * Add or delete a custom type * * @param TBGRequest $request */ public function runConfigureIssuefieldsCustomTypeAction(TBGRequest $request) { switch ($request->getParameter('mode')) { case 'add': if ($request->getParameter('name') != '') { try { $customtype = new TBGCustomDatatype(); $customtype->setName($request->getParameter('name')); $customtype->setItemdata($request->getParameter('label')); $customtype->setType($request->getParameter('field_type')); $customtype->save(); return $this->renderJSON(array('failed' => false, 'title' => TBGContext::getI18n()->__('The custom field was added'), 'content' => $this->getComponentHTML('issuefields_customtype', array('type_key' => $customtype->getKey(), 'type' => $customtype)))); } catch (Exception $e) { return $this->renderJSON(array('failed' => true, 'error' => $e->getMessage())); } } return $this->renderJSON(array('failed' => true, 'error' => TBGContext::getI18n()->__('Please provide a valid name'))); break; case 'update': if ($request->getParameter('name') != '') { $customtype = TBGCustomDatatype::getByKey($request->getParameter('type')); if ($customtype instanceof TBGCustomDatatype) { $customtype->setDescription($request->getParameter('description')); $customtype->setInstructions($request->getParameter('instructions')); $customtype->setName($request->getParameter('name')); $customtype->save(); return $this->renderJSON(array('failed' => false, 'title' => TBGContext::getI18n()->__('The custom field was updated'), 'description' => $customtype->getDescription(), 'instructions' => $customtype->getInstructions(), 'name' => $customtype->getName())); } return $this->renderJSON(array('failed' => true, 'error' => TBGContext::getI18n()->__('You need to provide a custom field key that already exists'))); } return $this->renderJSON(array('failed' => true, 'error' => TBGContext::getI18n()->__('Please provide a valid name'))); break; case 'delete': $customtype = TBGCustomDatatype::getByKey($request->getParameter('type')); if ($customtype instanceof TBGCustomDatatype) { $customtype->delete(); return $this->renderJSON(array('failed' => false, 'title' => TBGContext::getI18n()->__('The custom field was deleted'))); } return $this->renderJSON(array('failed' => true, 'error' => TBGContext::getI18n()->__('You need to provide a custom field key that already exists'))); break; } }
/** * Populates all the custom field values */ protected function _populateCustomfields() { if (!$this->_custom_populated) { $this->_custom_populated = true; foreach (TBGCustomDatatype::getAll() as $key => $customdatatype) { $var_name = "_customfield" . $key; $this->{$var_name} = null; } if ($res = TBGIssueCustomFieldsTable::getTable()->getAllValuesByIssueID($this->getID())) { while ($row = $res->getNextRow()) { $datatype = new TBGCustomDatatype($row->get(TBGIssueCustomFieldsTable::CUSTOMFIELDS_ID)); $var_name = "_customfield" . $datatype->getKey(); if ($datatype->hasCustomOptions()) { if ($optionrow = TBGCustomFieldOptionsTable::getTable()->doSelectById($row->get(TBGIssueCustomFieldsTable::OPTION_VALUE))) { $this->{$var_name} = $optionrow->get(TBGCustomFieldOptionsTable::OPTION_VALUE); } } else { $this->{$var_name} = $row->get(TBGIssueCustomFieldsTable::OPTION_VALUE); } } } $this->_mergeChangedProperties(); } }