/** * Adds a new unit */ protected function addUnit() { if (!$this->isCRUDContext()) { $this->showUnitsOfCategory(); return; } $category = $this->getCategoryById((int) $_GET['category_id']); $this->initUnitForm($category); if ($this->unit_form->checkInput()) { $unit = new assFormulaQuestionUnit(); $unit->setUnit($this->unit_form->getInput('unit_title')); $unit->setCategory($category->getId()); $this->repository->createNewUnit($unit); $unit->setBaseUnit((int) $this->unit_form->getInput('base_unit')); $unit->setFactor((double) $this->unit_form->getInput('factor')); $this->repository->saveUnit($unit); ilUtil::sendSuccess($this->lng->txt('saved_successfully')); $this->showUnitsOfCategory(); return; } $this->unit_form->setValuesByPost(); $this->tpl->setContent($this->unit_form->getHtml()); }