Skip to content

Commit

Permalink
GET to constr: according to change reqs
Browse files Browse the repository at this point in the history
  • Loading branch information
ferishili committed Nov 7, 2023
1 parent 87ae4d9 commit 92cd27b
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 18 deletions.
61 changes: 43 additions & 18 deletions classes/Conf/PublicationUsage/class.xoctPublicationUsageGUI.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,19 +50,37 @@ class xoctPublicationUsageGUI extends xoctGUI
* @var \ilTabs
*/
private $tabs;

/**
* @var HTTPServices
*/
private $http;
/**
* @var string
*/
protected $identifier;
/**
* @var int
*/
protected $get_id;
/**
* xoctPublicationUsageGUI constructor.
*/
public function __construct()
{
global $DIC;
parent::__construct();
$this->http = $DIC->http();
$this->toolbar = $DIC->toolbar();
$this->main_tpl = $DIC->ui()->mainTemplate();
$this->tabs = $DIC->tabs();
// Getting Query Parameters
$this->pub_subtab_active =
$this->http->request()->getQueryParams()['pub_subtab_active'] ?? xoctMainGUI::SUBTAB_PUBLICATION_USAGE;
$this->identifier = $this->http->request()->getQueryParams()[self::IDENTIFIER] ?? '';
$this->get_id = (int) $this->http->request()->getQueryParams()['id'] ?? null;
$this->repository = new PublicationUsageRepository();
$this->setTab();

}

/**
Expand All @@ -80,7 +98,6 @@ protected function index()
public function setTab()
{
$this->ctrl->saveParameter($this, 'pub_subtab_active');
$this->pub_subtab_active = $_GET['pub_subtab_active'] ?: xoctMainGUI::SUBTAB_PUBLICATION_USAGE;
$this->tabs->setSubTabActive($this->pub_subtab_active);
}

Expand Down Expand Up @@ -175,9 +192,13 @@ protected function create()
*/
protected function edit()
{
if (empty($this->identifier)) {
ilUtil::sendFailure($this->plugin->txt('publication_usage_no_identifier'), true);
$this->ctrl->redirect($this);
}
$xoctPublicationUsageFormGUI = new xoctPublicationUsageFormGUI(
$this,
$this->repository->getUsage($_GET[self::IDENTIFIER])
$this->repository->getUsage($this->identifier)
);
$xoctPublicationUsageFormGUI->fillForm();
$this->main_tpl->setContent($xoctPublicationUsageFormGUI->getHTML());
Expand All @@ -188,10 +209,10 @@ protected function edit()
*/
protected function update()
{
$usage_id = $_GET[self::IDENTIFIER];
$usage_id = $this->identifier;
$xoctPublicationUsageFormGUI = new xoctPublicationUsageFormGUI(
$this,
$usage_id ? $this->repository->getUsage($_GET[self::IDENTIFIER]) : new PublicationUsage()
$usage_id ? $this->repository->getUsage($usage_id) : new PublicationUsage()
);
$xoctPublicationUsageFormGUI->setValuesByPost();
if ($xoctPublicationUsageFormGUI->saveObject()) {
Expand All @@ -216,10 +237,14 @@ public function txt($key): string
*/
protected function confirmDelete()
{
if (empty($this->identifier)) {
ilUtil::sendFailure($this->plugin->txt('publication_usage_no_identifier'), true);
$this->ctrl->redirect($this);
}
/**
* @var $xoctPublicationUsage PublicationUsage
*/
$xoctPublicationUsage = $this->repository->getUsage($_GET[self::IDENTIFIER]);
$xoctPublicationUsage = $this->repository->getUsage($this->identifier);
$confirm = new ilConfirmationGUI();
$confirm->addItem(self::IDENTIFIER, $xoctPublicationUsage->getUsageId(), $xoctPublicationUsage->getTitle());
$confirm->setFormAction($this->ctrl->getFormAction($this));
Expand Down Expand Up @@ -303,11 +328,11 @@ protected function createSub()
*/
protected function editSub()
{
if (!PublicationSubUsage::find($_GET['id'])) {
if (!PublicationSubUsage::find($this->get_id)) {
ilUtil::sendFailure($this->plugin->txt('publication_usage_sub_not_found'), true);
$this->ctrl->redirect($this);
}
$xoctPublicationSubUsageFormGUI = new xoctPublicationSubUsageFormGUI($this, PublicationSubUsage::find($_GET['id']), false);
$xoctPublicationSubUsageFormGUI = new xoctPublicationSubUsageFormGUI($this, PublicationSubUsage::find($this->get_id), false);
$xoctPublicationSubUsageFormGUI->fillForm();
$this->main_tpl->setContent($xoctPublicationSubUsageFormGUI->getHTML());
}
Expand All @@ -318,7 +343,7 @@ protected function editSub()
*/
protected function updateSub()
{
$sub_usage_id = $_GET['id'];
$sub_usage_id = $this->get_id;
if (!PublicationSubUsage::find($sub_usage_id)) {
ilUtil::sendFailure($this->plugin->txt('publication_usage_sub_not_found'), true);
$this->ctrl->redirect($this);
Expand All @@ -338,14 +363,14 @@ protected function updateSub()

protected function confirmDeleteSub()
{
if (!PublicationSubUsage::find($_GET['id'])) {
if (!PublicationSubUsage::find($this->get_id)) {
ilUtil::sendFailure($this->plugin->txt('publication_usage_sub_not_found'), true);
$this->ctrl->redirect($this);
}
$xoctPublicationSubUsage = PublicationSubUsage::find($_GET['id']);
$xoctPublicationSubUsage = PublicationSubUsage::find($this->get_id);
$confirm = new ilConfirmationGUI();
$confirm->setHeaderText($this->txt('confirm_delete_text_sub'));
$confirm->addItem('id', $_GET['id'], $xoctPublicationSubUsage->getTitle());
$confirm->addItem('id', $this->get_id, $xoctPublicationSubUsage->getTitle());
$confirm->setFormAction($this->ctrl->getFormAction($this));
$confirm->setCancel($this->txt(self::CMD_CANCEL), self::CMD_CANCEL);
$confirm->setConfirm($this->txt(self::CMD_DELETE), self::CMD_DELETE_SUB);
Expand Down Expand Up @@ -391,18 +416,18 @@ protected function createGroup()

protected function editGroup()
{
if (!PublicationUsageGroup::find($_GET['id'])) {
if (!PublicationUsageGroup::find($this->get_id)) {
ilUtil::sendFailure($this->plugin->txt('publication_usage_group_not_found'), true);
$this->ctrl->redirect($this);
}
$xoctPublicationGroupFormGUI = new xoctPublicationGroupFormGUI($this, PublicationUsageGroup::find($_GET['id']), false);
$xoctPublicationGroupFormGUI = new xoctPublicationGroupFormGUI($this, PublicationUsageGroup::find($this->get_id), false);
$xoctPublicationGroupFormGUI->fillForm();
$this->main_tpl->setContent($xoctPublicationGroupFormGUI->getHTML());
}

protected function updateGroup()
{
$xoctPublicationGroupFormGUI = new xoctPublicationGroupFormGUI($this, PublicationUsageGroup::find($_GET['id']), false);
$xoctPublicationGroupFormGUI = new xoctPublicationGroupFormGUI($this, PublicationUsageGroup::find($this->get_id), false);
$xoctPublicationGroupFormGUI->setValuesByPost();
if ($xoctPublicationGroupFormGUI->saveObject()) {
ilUtil::sendSuccess($this->plugin->txt('publication_usage_msg_success'), true);
Expand All @@ -413,14 +438,14 @@ protected function updateGroup()

protected function confirmDeleteGroup()
{
if (!PublicationUsageGroup::find($_GET['id'])) {
if (!PublicationUsageGroup::find($this->get_id)) {
ilUtil::sendFailure($this->plugin->txt('publication_usage_group_not_found'), true);
$this->ctrl->redirect($this);
}
$xoctPublicationUsageGroup = PublicationUsageGroup::find($_GET['id']);
$xoctPublicationUsageGroup = PublicationUsageGroup::find($this->get_id);
$confirm = new ilConfirmationGUI();
$confirm->setHeaderText($this->txt('confirm_delete_text_group'));
$confirm->addItem('id', $_GET['id'], $xoctPublicationUsageGroup->getName());
$confirm->addItem('id', $this->get_id, $xoctPublicationUsageGroup->getName());
$confirm->setFormAction($this->ctrl->getFormAction($this));
$confirm->setCancel($this->txt(self::CMD_CANCEL), self::CMD_CANCEL);
$confirm->setConfirm($this->txt(self::CMD_DELETE), self::CMD_DELETE_GROUP);
Expand Down
1 change: 1 addition & 0 deletions lang/ilias_de.lang
Original file line number Diff line number Diff line change
Expand Up @@ -589,6 +589,7 @@ publication_usage_select_sub_usage_id_desc#:#Wählen Sie aus bereits konfigurier
publication_usage_parent_usage_id#:#Eltern-Verwendungszweck
publication_usage_sub_not_found#:#Ersatz-Verwendungszweck konnte nicht gefunden werden
publication_usage_sub_not_allowed#:#Verwendungszweck konnte nicht ersatzbar werden
publication_usage_no_identifier#:#Keine Veröffentlichungs-Nutzungskennung gefunden!
publication_usage_sub#:#Ersatz
publication_usage_display_name#:#Anzeigename
publication_usage_display_name_info#:#Anzeigename INFO
Expand Down
1 change: 1 addition & 0 deletions lang/ilias_en.lang
Original file line number Diff line number Diff line change
Expand Up @@ -590,6 +590,7 @@ publication_usage_select_sub_usage_id_desc#:#Select from already configured usag
publication_usage_parent_usage_id#:#Parent Usage
publication_usage_sub_not_found#:#Sub-Usage not found
publication_usage_sub_not_allowed#:#Sub-usage is not allowed for this parent usage
publication_usage_no_identifier#:#No publication usage identifier found!
publication_usage_sub#:#Sub
publication_usage_display_name#:#Display Name
publication_usage_display_name_info#:#The display name (max %s chars) to be shown to the users, and it can be localized by adding a string id (pu_display_name_%s) to the plugin languages.
Expand Down

0 comments on commit 92cd27b

Please sign in to comment.