forked from ILIAS-eLearning/ILIAS
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Terms of Service: Refactored GUI classes (intermediate state)
- Loading branch information
1 parent
3388e2c
commit 99edea0
Showing
27 changed files
with
1,648 additions
and
1,453 deletions.
There are no files selected for viewing
98 changes: 98 additions & 0 deletions
98
Services/TermsOfService/classes/Document/class.ilTermsOfServiceDocument.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
<?php | ||
/* Copyright (c) 1998-2018 ILIAS open source, Extended GPL, see docs/LICENSE */ | ||
|
||
/** | ||
* Class ilTermsOfServiceDocument | ||
* @author Michael Jansen <[email protected]> | ||
*/ | ||
class ilTermsOfServiceDocument extends ActiveRecord | ||
{ | ||
const TABLE_NAME = 'tos_documents'; | ||
|
||
/** | ||
* @var string | ||
* @db_has_field true | ||
* @db_fieldtype integer | ||
* @db_length 4 | ||
* @db_is_primary true | ||
* @con_sequence true | ||
*/ | ||
protected $id; | ||
|
||
/** | ||
* @var int | ||
* @con_has_field true | ||
* @con_fieldtype integer | ||
* @con_length 4 | ||
*/ | ||
protected $creation_ts = 0; | ||
|
||
/** | ||
* @var int | ||
* @con_has_field true | ||
* @con_fieldtype integer | ||
* @con_length 4 | ||
*/ | ||
protected $modification_ts = 0; | ||
|
||
/** | ||
* @var int | ||
* @con_has_field true | ||
* @con_fieldtype integer | ||
* @con_length 4 | ||
*/ | ||
protected $owner_usr_id = 0; | ||
|
||
/** | ||
* @var int | ||
* @con_has_field true | ||
* @con_fieldtype integer | ||
* @con_length 4 | ||
*/ | ||
protected $sorting = 0; | ||
|
||
/** | ||
* @var string | ||
* @db_has_field true | ||
* @db_fieldtype text | ||
* @db_length 255 | ||
*/ | ||
protected $title = ''; | ||
|
||
/** | ||
* @var string | ||
* @db_has_field true | ||
* @db_fieldtype text | ||
* @db_length 255 | ||
*/ | ||
protected $last_modified_usr_id = ''; | ||
|
||
/** | ||
* @inheritdoc | ||
*/ | ||
static function returnDbTableName() | ||
{ | ||
return self::TABLE_NAME; | ||
} | ||
|
||
/** | ||
* @inheritdoc | ||
*/ | ||
public function create() | ||
{ | ||
$this->setCreationTs(time()); | ||
$this->setModificationTs(time()); | ||
|
||
parent::create(); | ||
} | ||
|
||
/** | ||
* @inheritdoc | ||
*/ | ||
public function update() | ||
{ | ||
$this->setModificationTs(time()); | ||
|
||
parent::update(); | ||
} | ||
} |
153 changes: 153 additions & 0 deletions
153
Services/TermsOfService/classes/Document/class.ilTermsOfServiceDocumentFormGUI.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,153 @@ | ||
<?php | ||
/* Copyright (c) 1998-2018 ILIAS open source, Extended GPL, see docs/LICENSE */ | ||
|
||
/** | ||
* Class ilTermsOfServiceDocumentFormGUI | ||
* @author Michael Jansen <[email protected]> | ||
*/ | ||
class ilTermsOfServiceDocumentFormGUI extends \ilPropertyFormGUI | ||
{ | ||
/** @var \ilTermsOfServiceDocument */ | ||
protected $document; | ||
|
||
/** @var \ilObjUser */ | ||
protected $user; | ||
|
||
/** @var \\ILIAS\FileUpload\FileUpload */ | ||
protected $fileUpload; | ||
|
||
/** @var string */ | ||
protected $formAction; | ||
|
||
/** @var string */ | ||
protected $saveCommand; | ||
|
||
/** @var string */ | ||
protected $cancelCommand; | ||
|
||
/** @var $bool */ | ||
protected $isEditable = false; | ||
|
||
/** @var string */ | ||
protected $translatedError = ''; | ||
|
||
/** | ||
* ilTermsOfServiceDocumentFormGUI constructor. | ||
* @param \ilTermsOfServiceDocument $document | ||
* @param \ilObjUser $user | ||
* @param \ILIAS\FileUpload\FileUpload $fileUpload | ||
* @param ilLanguage $lng | ||
* @param string $formAction | ||
* @param string $saveCommand | ||
* @param string $cancelCommand | ||
* @param bool $isEditable | ||
*/ | ||
public function __construct( | ||
\ilTermsOfServiceDocument $document, | ||
\ilObjUser $user, | ||
\ILIAS\FileUpload\FileUpload $fileUpload, | ||
string $formAction = '', | ||
string $saveCommand = 'saveDocument', | ||
string $cancelCommand = 'showDocuments', | ||
bool $isEditable = false | ||
) { | ||
$this->document = $document; | ||
$this->user = $user; | ||
$this->fileUpload = $fileUpload; | ||
$this->formAction = $formAction; | ||
$this->saveCommand = $saveCommand; | ||
$this->cancelCommand = $cancelCommand; | ||
$this->isEditable = $isEditable; | ||
|
||
parent::__construct(); | ||
|
||
$this->initForm(); | ||
} | ||
|
||
/** | ||
* | ||
*/ | ||
protected function initForm() | ||
{ | ||
$this->setTitle($this->lng->txt('tos_form_new_doc_head')); | ||
$this->setFormAction($this->formAction); | ||
|
||
$title = new \ilTextInputGUI($this->lng->txt('tos_form_document_title'), 'title'); | ||
$title->setInfo($this->lng->txt('tos_form_document_title_info')); | ||
$title->setRequired(true); | ||
$title->setDisabled(!$this->isEditable); | ||
$title->setValue($this->document->getText()); | ||
$title->setMaxLength(255); | ||
$this->addItem($title); | ||
|
||
$document = new \ilFileInputGUI($this->lng->txt('tos_form_document'), 'document'); | ||
$document->setInfo($this->lng->txt('tos_form_document_info')); | ||
if (!$this->document->getId()) { | ||
$document->setRequired(true); | ||
} | ||
$document->setDisabled(!$this->isEditable); | ||
$document->setSuffixes(['html']); | ||
$this->addItem($document); | ||
|
||
if ($this->isEditable) { | ||
$this->addCommandButton($this->saveCommand, $this->lng->txt('save')); | ||
} | ||
|
||
$this->addCommandButton($this->cancelCommand, $this->lng->txt('cancel')); | ||
} | ||
|
||
/** | ||
* @return bool | ||
*/ | ||
public function hasTranslatedError(): bool | ||
{ | ||
return strlen($this->translatedError); | ||
} | ||
|
||
/** | ||
* @return string | ||
*/ | ||
public function getTranslatedError(): string | ||
{ | ||
return $this->translatedError; | ||
} | ||
|
||
/** | ||
* @return bool | ||
*/ | ||
public function saveObject() :bool | ||
{ | ||
if (!$this->fillObject()) { | ||
$this->setValuesByPost(); | ||
return false; | ||
} | ||
|
||
$this->document->save(); | ||
|
||
return true; | ||
} | ||
|
||
/** | ||
* | ||
*/ | ||
protected function fillObject(): bool | ||
{ | ||
if (!$this->checkInput()) { | ||
return false; | ||
} | ||
|
||
if (!$this->fileUpload->hasUploads()) { | ||
return false; | ||
} | ||
|
||
$this->document->setTitle($this->getInput('title')); | ||
|
||
if ($this->document->getId() > 0) { | ||
$this->document->setLastModifiedUsrId($this->user->getId()); | ||
} else { | ||
$this->document->setOwnerUsrId($this->user->getId()); | ||
} | ||
|
||
return true; | ||
} | ||
} |
Oops, something went wrong.