/** * @param assFormulaQuestionUnitCategory $cat * @return ilPropertyFormGUI */ protected function initUnitCategoryForm(assFormulaQuestionUnitCategory $cat = null) { if ($this->unit_cat_form instanceof ilPropertyFormGUI) { return $this->unit_cat_form; } $this->unit_cat_form = new ilPropertyFormGUI(); $title = new ilTextInputGUI($this->lng->txt('title'), 'category_name'); $title->setRequired(true); $this->unit_cat_form->addItem($title); if (null === $cat) { $this->unit_cat_form->setTitle($this->lng->txt('new_category')); $this->unit_cat_form->setFormAction($this->ctrl->getFormAction($this, 'addCategory')); $this->unit_cat_form->addCommandButton('addCategory', $this->lng->txt('save')); } else { $this->ctrl->setParameter($this, 'category_id', $cat->getId()); $this->unit_cat_form->addCommandButton('saveCategory', $this->lng->txt('save')); $this->unit_cat_form->setFormAction($this->ctrl->getFormAction($this, 'saveCategory')); $this->unit_cat_form->setTitle(sprintf($this->lng->txt('selected_category'), $cat->getDisplayString())); } $this->unit_cat_form->addCommandButton($this->getUnitCategoryOverviewCommand(), $this->lng->txt('cancel')); return $this->unit_cat_form; }
/** * @param assFormulaQuestionUnitCategory $category * @throws ilException */ public function saveCategory(assFormulaQuestionUnitCategory $category) { /** * @var $ilDB ilDB */ global $ilDB; $res = $ilDB->queryF('SELECT * FROM il_qpl_qst_fq_ucat WHERE category = %s AND question_fi = %s AND category_id != %s', array('text', 'integer', 'integer'), array($category->getCategory(), $this->getConsumerId(), $category->getId())); if ($ilDB->numRows($res)) { throw new ilException('err_wrong_categoryname'); } $ilDB->manipulateF('UPDATE il_qpl_qst_fq_ucat SET category = %s WHERE question_fi = %s AND category_id = %s', array('text', 'integer', 'integer'), array($category->getCategory(), $this->getConsumerId(), $category->getId())); }