Skip to content

Commit

Permalink
Terms of Service: Refactored GUI classes (intermediate state)
Browse files Browse the repository at this point in the history
  • Loading branch information
mjansenDatabay committed Aug 8, 2018
1 parent 3388e2c commit 99edea0
Show file tree
Hide file tree
Showing 27 changed files with 1,648 additions and 1,453 deletions.
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();
}
}
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;
}
}
Loading

0 comments on commit 99edea0

Please sign in to comment.