From 8397351641b5aa56bdb9403740c6b43075c54176 Mon Sep 17 00:00:00 2001 From: Richard Klees Date: Wed, 12 Sep 2018 11:40:12 +0200 Subject: [PATCH 1/7] SP: switched settings form to ui-framework --- .../class.ilObjStudyProgrammeSettingsGUI.php | 195 ++++++++++-------- .../model/class.ilStudyProgrammeType.php | 7 +- 2 files changed, 106 insertions(+), 96 deletions(-) diff --git a/Modules/StudyProgramme/classes/class.ilObjStudyProgrammeSettingsGUI.php b/Modules/StudyProgramme/classes/class.ilObjStudyProgrammeSettingsGUI.php index 68bec2ccfe3d..ab782e47d730 100644 --- a/Modules/StudyProgramme/classes/class.ilObjStudyProgrammeSettingsGUI.php +++ b/Modules/StudyProgramme/classes/class.ilObjStudyProgrammeSettingsGUI.php @@ -61,6 +61,26 @@ class ilObjStudyProgrammeSettingsGUI { */ protected $tmp_heading; + /** + * @var ILIAS\UI\Component\Input\Factory + */ + protected $input_factory; + + /** + * @var ILIAS\UI\Renderer + */ + protected $renderer; + + /** + * @var Psr\Http\Message\ServerRequestInterface + */ + protected $request; + + /** + * @var ILIAS\Transformation\Factory + */ + protected $trafo_factory; + public function __construct($a_parent_gui, $a_ref_id) { global $DIC; $tpl = $DIC['tpl']; @@ -86,6 +106,10 @@ public function __construct($a_parent_gui, $a_ref_id) { $this->ilLog = $ilLog; $this->ilias = $ilias; $this->lng = $lng; + $this->input_factory = $DIC->ui()->factory()->input(); + $this->renderer = $DIC->ui()->renderer(); + $this->request = $DIC->http()->request(); + $this->trafo_factory = new \ILIAS\Transformation\Factory(); // TODO: replace this with the version from the DIC once available $this->object = null; @@ -128,27 +152,22 @@ public function executeCommand() { protected function view() { $this->buildModalHeading($this->lng->txt('prg_async_settings'),isset($_GET["currentNode"])); - $form = $this->buildForm(); - $this->fillForm($form); - return $form->getHTML(); + $form = $this->buildForm($this->getObject(), $this->ctrl->getFormAction($this, "update")); + return $this->renderer->render($form); } - /*protected function cancel() { - $this->ctrl->redirect($this->parent_gui); - }*/ - protected function update() { + $form = $this + ->buildForm($this->getObject(), $this->ctrl->getFormAction($this, "update")) + ->withRequest($this->request); + $content = $form->getData(); + $prg = $this->getObject(); - $form = $this->buildForm(); - $form->setValuesByPost(); - $update_possible = $this->checkForm($form); - - if ($update_possible) { - $this->updateFromFrom($form); + if (!is_null($content)) { + $this->updateWith($prg, $content); ilUtil::sendSuccess($this->lng->txt("msg_obj_modified"),true); $response = ilAsyncOutputHandler::encodeAsyncResponse(array("success"=>true, "message"=>$this->lng->txt("msg_obj_modified"))); } else { - // TODO: ilUtil::sendFailure($this->lng->txt("msg_form_save_error")); $response = ilAsyncOutputHandler::encodeAsyncResponse(array("success"=>false, "errors"=>$form->getErrors())); } @@ -159,7 +178,7 @@ protected function update() { if($update_possible) { $this->ctrl->redirect($this); } else { - return $form->getHTML(); + return $this->renderer->render($form); } } } @@ -191,50 +210,79 @@ protected function buildModalHeading($label, $current_node) { const PROP_POINTS = "points"; const PROP_STATUS = "status"; - protected function buildForm() { - $form = new ilAsyncPropertyFormGUI(); + protected function buildForm(\ilObjStudyProgramme $prg, string $submit_action) : ILIAS\UI\Component\Input\Container\Form\Standard { + $ff = $this->input_factory->field(); + $tf = $this->trafo_factory; + $txt = function($id) { return $this->lng->txt($id); }; + $sp_types = ilStudyProgrammeType::getAllTypesArray(); + $status_options = self::getStatusOptions(); + return $this->input_factory->container()->form()->standard( + $submit_action, + [ + $ff->section( + [ + self::PROP_TITLE => + $ff->text($txt("title")) + ->withValue($prg->getTitle()) + ->withRequired(true), + self::PROP_DESC => + $ff->text($txt("description")) // TODO: change this to textarea once available + ->withValue($prg->getDescription()) + ], + $txt("prg_edit"), + "" + ), + $ff->section( + [ + self::PROP_TYPE => + $ff->select($txt("type"), $sp_types) + ->withValue((string)$prg->getSubtypeId()) + ->withAdditionalTransformation($tf->custom(function($v) { + if ($v == "") { + return 0; + } + return $v; + })) + ], + $txt("prg_type"), + "" + ), + $ff->section( + [ + self::PROP_POINTS => + $ff->numeric($txt("prg_points")) + ->withValue((string)$prg->getPoints()), + self::PROP_STATUS => + $ff->select($txt("prg_status"), $status_options) + ->withValue((string)$prg->getStatus()) + ], + $txt("prg_assessment"), + "" + ) + ] + ) + ->withAdditionalTransformation($tf->custom(function($values) { + // values now contains the results of the single sections, + // i.e. a list of arrays according that each contains keys + // according to the section they originated from. + return call_user_func_array("array_merge", $values); + })); + } - if(!$this->ctrl->isAsynch()) { - $form->setAsync(false); + protected function updateWith(\ilObjStudyProgramme $prg, array $data) { + $prg->setTitle($data[self::PROP_TITLE]); + $prg->setDescription($data[self::PROP_DESC]); + + if($prg->getSubtypeId() != $data[self::PROP_TYPE]) { + $prg->setSubtypeId($data[self::PROP_TYPE]); + $prg->updateCustomIcon(); + $this->parent_gui->setTitleAndDescription(); } - $form->setFormAction($this->ctrl->getFormAction($this)); - - $header = new ilFormSectionHeaderGUI(); - $header->setTitle($this->lng->txt("prg_edit")); - $form->addItem($header); - - $item = new ilTextInputGUI($this->lng->txt("title"), self::PROP_TITLE); - $item->setRequired(true); - $form->addItem($item); - - $item = new ilTextAreaInputGUI($this->lng->txt("description"), self::PROP_DESC); - $form->addItem($item); - - $header = new ilFormSectionHeaderGUI(); - $header->setTitle($this->lng->txt("prg_type")); - $form->addItem($header); - - $item = new ilSelectInputGUI($this->lng->txt("type"), self::PROP_TYPE); - $item->setOptions(ilStudyProgrammeType::getAllTypesArray()); - $form->addItem($item); - - $header = new ilFormSectionHeaderGUI(); - $header->setTitle($this->lng->txt("prg_assessment")); - $form->addItem($header); - - $item = new ilNumberInputGUI($this->lng->txt("prg_points"), self::PROP_POINTS); - $item->setMinValue(0); - $form->addItem($item); - - $item = new ilSelectInputGUI($this->lng->txt("prg_status"), self::PROP_STATUS); - $item->setOptions(self::getStatusOptions()); - $form->addItem($item); - - $form->addCommandButton("update", $this->lng->txt("save")); - $form->addCommandButton("cancel", $this->lng->txt("cancel")); - - return $form; + $prg->setPoints($data[self::PROP_POINTS]); + $prg->setStatus($data[self::PROP_STATUS]); + + $prg->update(); } protected function getObject() { @@ -244,41 +292,6 @@ protected function getObject() { return $this->object; } - protected function fillForm($a_form) { - $obj = $this->getObject(); - - $a_form->setValuesByArray(array - ( self::PROP_TITLE => $obj->getTitle() - , self::PROP_DESC => $obj->getDescription() - , self::PROP_TYPE => $obj->getSubtypeId() - , self::PROP_POINTS => $obj->getPoints() - , self::PROP_STATUS => $obj->getStatus() - )); - } - - protected function checkForm($a_form) { - if (!$a_form->checkInput()) { - return false; - } - return true; - } - - protected function updateFromFrom($a_form) { - $obj = $this->getObject(); - - $obj->setTitle($a_form->getItemByPostVar(self::PROP_TITLE)->getValue()); - $obj->setDescription($a_form->getItemByPostVar(self::PROP_DESC)->getValue()); - - if($obj->getSubtypeId() != $a_form->getItemByPostVar(self::PROP_TYPE)->getValue()) { - $obj->setSubtypeId($a_form->getItemByPostVar(self::PROP_TYPE)->getValue()); - $obj->updateCustomIcon(); - $this->parent_gui->setTitleAndDescription(); - } - - $obj->setPoints($a_form->getItemByPostVar(self::PROP_POINTS)->getValue()); - $obj->setStatus($a_form->getItemByPostVar(self::PROP_STATUS)->getValue()); - } - static protected function getStatusOptions() { global $DIC; $lng = $DIC['lng']; diff --git a/Modules/StudyProgramme/classes/model/class.ilStudyProgrammeType.php b/Modules/StudyProgramme/classes/model/class.ilStudyProgrammeType.php index caeda79c20cb..e6a985951c03 100644 --- a/Modules/StudyProgramme/classes/model/class.ilStudyProgrammeType.php +++ b/Modules/StudyProgramme/classes/model/class.ilStudyProgrammeType.php @@ -167,16 +167,13 @@ public static function getAllTypes() { return self::get(); } - public static function getAllTypesArray($add_empty_on_begin = true) { + public static function getAllTypesArray() { $out = array(); foreach(self::getAllTypes() as $type) { $out[$type->getId()] = $type->getTitle(); } - if($add_empty_on_begin) - $out = array('-'=>'-') + $out; - return $out; } @@ -987,4 +984,4 @@ public function getCreateDate() { return $this->create_date; } -} \ No newline at end of file +} From 1917a548ad0f33b19ae43efc9ea828cbe74dac25 Mon Sep 17 00:00:00 2001 From: Richard Klees Date: Tue, 18 Sep 2018 12:36:34 +0200 Subject: [PATCH 2/7] SP: correction in form-handling --- .../classes/class.ilObjStudyProgrammeSettingsGUI.php | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/Modules/StudyProgramme/classes/class.ilObjStudyProgrammeSettingsGUI.php b/Modules/StudyProgramme/classes/class.ilObjStudyProgrammeSettingsGUI.php index ab782e47d730..9573e7c5799d 100644 --- a/Modules/StudyProgramme/classes/class.ilObjStudyProgrammeSettingsGUI.php +++ b/Modules/StudyProgramme/classes/class.ilObjStudyProgrammeSettingsGUI.php @@ -163,7 +163,10 @@ protected function update() { $content = $form->getData(); $prg = $this->getObject(); - if (!is_null($content)) { + // This could further improved by providing a new container for asynch-forms in the + // UI-Framework. + $update_possible = !is_null($content); + if (!$update_possible) { $this->updateWith($prg, $content); ilUtil::sendSuccess($this->lng->txt("msg_obj_modified"),true); $response = ilAsyncOutputHandler::encodeAsyncResponse(array("success"=>true, "message"=>$this->lng->txt("msg_obj_modified"))); From e7b7a643034dde72f350eab89ed7e999d3d670c9 Mon Sep 17 00:00:00 2001 From: Richard Klees Date: Tue, 18 Sep 2018 12:50:43 +0200 Subject: [PATCH 3/7] SP: minor wording in comment --- .../classes/class.ilObjStudyProgrammeSettingsGUI.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Modules/StudyProgramme/classes/class.ilObjStudyProgrammeSettingsGUI.php b/Modules/StudyProgramme/classes/class.ilObjStudyProgrammeSettingsGUI.php index 9573e7c5799d..46bab7b83141 100644 --- a/Modules/StudyProgramme/classes/class.ilObjStudyProgrammeSettingsGUI.php +++ b/Modules/StudyProgramme/classes/class.ilObjStudyProgrammeSettingsGUI.php @@ -266,8 +266,8 @@ protected function buildForm(\ilObjStudyProgramme $prg, string $submit_action) : ) ->withAdditionalTransformation($tf->custom(function($values) { // values now contains the results of the single sections, - // i.e. a list of arrays according that each contains keys - // according to the section they originated from. + // i.e. a list of arrays that each contains keys according + // to the section they originated from. return call_user_func_array("array_merge", $values); })); } From 1dc3cae4bd5d92eb3237d86eb997be5a48f1382b Mon Sep 17 00:00:00 2001 From: Richard Klees Date: Thu, 4 Oct 2018 14:25:05 +0200 Subject: [PATCH 4/7] SP: use text-area for description in settings --- .../classes/class.ilObjStudyProgrammeSettingsGUI.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Modules/StudyProgramme/classes/class.ilObjStudyProgrammeSettingsGUI.php b/Modules/StudyProgramme/classes/class.ilObjStudyProgrammeSettingsGUI.php index 46bab7b83141..df35eedc0853 100644 --- a/Modules/StudyProgramme/classes/class.ilObjStudyProgrammeSettingsGUI.php +++ b/Modules/StudyProgramme/classes/class.ilObjStudyProgrammeSettingsGUI.php @@ -229,7 +229,7 @@ protected function buildForm(\ilObjStudyProgramme $prg, string $submit_action) : ->withValue($prg->getTitle()) ->withRequired(true), self::PROP_DESC => - $ff->text($txt("description")) // TODO: change this to textarea once available + $ff->textarea($txt("description")) ->withValue($prg->getDescription()) ], $txt("prg_edit"), From 7b47574d5220e2a98e259f51814525f51830e6ff Mon Sep 17 00:00:00 2001 From: Richard Klees Date: Thu, 4 Oct 2018 15:06:38 +0200 Subject: [PATCH 5/7] SP: Status is a required setting --- .../classes/class.ilObjStudyProgrammeSettingsGUI.php | 1 + 1 file changed, 1 insertion(+) diff --git a/Modules/StudyProgramme/classes/class.ilObjStudyProgrammeSettingsGUI.php b/Modules/StudyProgramme/classes/class.ilObjStudyProgrammeSettingsGUI.php index df35eedc0853..ff15f5b59c09 100644 --- a/Modules/StudyProgramme/classes/class.ilObjStudyProgrammeSettingsGUI.php +++ b/Modules/StudyProgramme/classes/class.ilObjStudyProgrammeSettingsGUI.php @@ -258,6 +258,7 @@ protected function buildForm(\ilObjStudyProgramme $prg, string $submit_action) : self::PROP_STATUS => $ff->select($txt("prg_status"), $status_options) ->withValue((string)$prg->getStatus()) + ->withRequired(true) ], $txt("prg_assessment"), "" From 3c7b2c19f123fc750532c9c8ac576ded1bdf9f69 Mon Sep 17 00:00:00 2001 From: Richard Klees Date: Tue, 23 Oct 2018 13:45:48 +0200 Subject: [PATCH 6/7] SP: consider 'no_type' in new form implementation --- .../classes/class.ilObjStudyProgrammeSettingsGUI.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Modules/StudyProgramme/classes/class.ilObjStudyProgrammeSettingsGUI.php b/Modules/StudyProgramme/classes/class.ilObjStudyProgrammeSettingsGUI.php index ff15f5b59c09..9c87fffae09a 100644 --- a/Modules/StudyProgramme/classes/class.ilObjStudyProgrammeSettingsGUI.php +++ b/Modules/StudyProgramme/classes/class.ilObjStudyProgrammeSettingsGUI.php @@ -239,7 +239,7 @@ protected function buildForm(\ilObjStudyProgramme $prg, string $submit_action) : [ self::PROP_TYPE => $ff->select($txt("type"), $sp_types) - ->withValue((string)$prg->getSubtypeId()) + ->withValue($prg->getSubtypeId() == 0 ? "" : $prg->getSubtypeId()) ->withAdditionalTransformation($tf->custom(function($v) { if ($v == "") { return 0; From 8122dcb9377e532c80933e0f5a16c6664342c4fb Mon Sep 17 00:00:00 2001 From: Richard Klees Date: Tue, 23 Oct 2018 13:55:57 +0200 Subject: [PATCH 7/7] SP: fixed update after new form implementation --- .../classes/class.ilObjStudyProgrammeSettingsGUI.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Modules/StudyProgramme/classes/class.ilObjStudyProgrammeSettingsGUI.php b/Modules/StudyProgramme/classes/class.ilObjStudyProgrammeSettingsGUI.php index 9c87fffae09a..6452640b1f71 100644 --- a/Modules/StudyProgramme/classes/class.ilObjStudyProgrammeSettingsGUI.php +++ b/Modules/StudyProgramme/classes/class.ilObjStudyProgrammeSettingsGUI.php @@ -166,7 +166,7 @@ protected function update() { // This could further improved by providing a new container for asynch-forms in the // UI-Framework. $update_possible = !is_null($content); - if (!$update_possible) { + if ($update_possible) { $this->updateWith($prg, $content); ilUtil::sendSuccess($this->lng->txt("msg_obj_modified"),true); $response = ilAsyncOutputHandler::encodeAsyncResponse(array("success"=>true, "message"=>$this->lng->txt("msg_obj_modified")));