This commit is contained in:
Dennis Eichhorn 2020-03-05 20:35:58 +01:00
parent 52e9db17cf
commit 80c7d090e9
10 changed files with 218 additions and 49 deletions

38
Models/NullQAAnswer.php Normal file
View File

@ -0,0 +1,38 @@
<?php
/**
* Orange Management
*
* PHP Version 7.4
*
* @package Modules\QA\Models
* @copyright Dennis Eichhorn
* @license OMS License 1.0
* @version 1.0.0
* @link https://orange-management.org
*/
declare(strict_types=1);
namespace Modules\QA\Models;
/**
* Null model
*
* @package Modules\QA\Models
* @license OMS License 1.0
* @link https://orange-management.org
* @since 1.0.0
*/
final class NullQAAnswer extends QAAnswer
{
/**
* Constructor
*
* @param int $id Model id
*
* @since 1.0.0
*/
public function __construct(int $id = 0)
{
$this->id = $id;
}
}

38
Models/NullQACategory.php Normal file
View File

@ -0,0 +1,38 @@
<?php
/**
* Orange Management
*
* PHP Version 7.4
*
* @package Modules\QA\Models
* @copyright Dennis Eichhorn
* @license OMS License 1.0
* @version 1.0.0
* @link https://orange-management.org
*/
declare(strict_types=1);
namespace Modules\QA\Models;
/**
* Null model
*
* @package Modules\QA\Models
* @license OMS License 1.0
* @link https://orange-management.org
* @since 1.0.0
*/
final class NullQACategory extends QACategory
{
/**
* Constructor
*
* @param int $id Model id
*
* @since 1.0.0
*/
public function __construct(int $id = 0)
{
$this->id = $id;
}
}

38
Models/NullQAQuestion.php Normal file
View File

@ -0,0 +1,38 @@
<?php
/**
* Orange Management
*
* PHP Version 7.4
*
* @package Modules\QA\Models
* @copyright Dennis Eichhorn
* @license OMS License 1.0
* @version 1.0.0
* @link https://orange-management.org
*/
declare(strict_types=1);
namespace Modules\QA\Models;
/**
* Null model
*
* @package Modules\QA\Models
* @license OMS License 1.0
* @link https://orange-management.org
* @since 1.0.0
*/
final class NullQAQuestion extends QAQuestion
{
/**
* Constructor
*
* @param int $id Model id
*
* @since 1.0.0
*/
public function __construct(int $id = 0)
{
$this->id = $id;
}
}

View File

@ -14,6 +14,9 @@ declare(strict_types=1);
namespace Modules\QA\Models; namespace Modules\QA\Models;
use Modules\Admin\Models\Account;
use Modules\Admin\Models\NullAccount;
/** /**
* Answer class. * Answer class.
* *
@ -50,7 +53,13 @@ class QAAnswer implements \JsonSerializable
*/ */
private $answerRaw = ''; private $answerRaw = '';
private $question = 0; /**
* Question
*
* @var QAQuestion
* @since 1.0.0
*/
private QAQuestion $question;
/** /**
* Is accepted answer. * Is accepted answer.
@ -60,8 +69,20 @@ class QAAnswer implements \JsonSerializable
*/ */
private bool $isAccepted = false; private bool $isAccepted = false;
private $createdBy = 0; /**
* Created by.
*
* @var Account
* @var 1.0.0
*/
private Account $createdBy;
/**
* Created at.
*
* @var \DateTime
* @var 1.0.0
*/
private \DateTime $createdAt; private \DateTime $createdAt;
/** /**
@ -72,6 +93,8 @@ class QAAnswer implements \JsonSerializable
public function __construct() public function __construct()
{ {
$this->createdAt = new \DateTime('now'); $this->createdAt = new \DateTime('now');
$this->createdBy = new NullAccount();
$this->question = new NullQAQuestion();
} }
/** /**
@ -115,11 +138,11 @@ class QAAnswer implements \JsonSerializable
/** /**
* Get the question * Get the question
* *
* @return int * @return QAQuestion
* *
* @since 1.0.0 * @since 1.0.0
*/ */
public function getQuestion() : int public function getQuestion() : QAQuestion
{ {
return $this->question; return $this->question;
} }
@ -127,13 +150,13 @@ class QAAnswer implements \JsonSerializable
/** /**
* Set the question * Set the question
* *
* @param int $question Question * @param QAQuestion $question Question
* *
* @return void * @return void
* *
* @since 1.0.0 * @since 1.0.0
*/ */
public function setQuestion(int $question) : void public function setQuestion(QAQuestion $question) : void
{ {
$this->question = $question; $this->question = $question;
} }
@ -193,11 +216,11 @@ class QAAnswer implements \JsonSerializable
/** /**
* Get created by * Get created by
* *
* @return int|\phpOMS\Account\Account * @return Account
* *
* @since 1.0.0 * @since 1.0.0
*/ */
public function getCreatedBy() public function getCreatedBy() : Account
{ {
return $this->createdBy; return $this->createdBy;
} }
@ -205,15 +228,15 @@ class QAAnswer implements \JsonSerializable
/** /**
* Set created by * Set created by
* *
* @param mixed $id Creator * @param Account $account Creator
* *
* @return void * @return void
* *
* @since 1.0.0 * @since 1.0.0
*/ */
public function setCreatedBy($id) : void public function setCreatedBy(Account $account) : void
{ {
$this->createdBy = $id; $this->createdBy = $account;
} }
/** /**

View File

@ -14,7 +14,7 @@ declare(strict_types=1);
namespace Modules\QA\Models; namespace Modules\QA\Models;
use Modules\Profile\Models\ProfileMapper; use Modules\Admin\Models\AccountMapper;
use phpOMS\DataStorage\Database\DataMapperAbstract; use phpOMS\DataStorage\Database\DataMapperAbstract;
/** /**
@ -39,10 +39,27 @@ final class QAAnswerMapper extends DataMapperAbstract
'qa_answer_question' => ['name' => 'qa_answer_question', 'type' => 'int', 'internal' => 'question'], 'qa_answer_question' => ['name' => 'qa_answer_question', 'type' => 'int', 'internal' => 'question'],
'qa_answer_status' => ['name' => 'qa_answer_status', 'type' => 'int', 'internal' => 'status'], 'qa_answer_status' => ['name' => 'qa_answer_status', 'type' => 'int', 'internal' => 'status'],
'qa_answer_accepted' => ['name' => 'qa_answer_accepted', 'type' => 'bool', 'internal' => 'isAccepted'], 'qa_answer_accepted' => ['name' => 'qa_answer_accepted', 'type' => 'bool', 'internal' => 'isAccepted'],
'qa_answer_created_by' => ['name' => 'qa_answer_created_by', 'type' => 'int', 'internal' => 'createdBy'], 'qa_answer_created_by' => ['name' => 'qa_answer_created_by', 'type' => 'int', 'internal' => 'createdBy', 'readonly' => true],
'qa_answer_created_at' => ['name' => 'qa_answer_created_at', 'type' => 'DateTime', 'internal' => 'createdAt', 'readonly' => true], 'qa_answer_created_at' => ['name' => 'qa_answer_created_at', 'type' => 'DateTime', 'internal' => 'createdAt', 'readonly' => true],
]; ];
/**
* Belongs to.
*
* @var array<string, array{mapper:string, self:string}>
* @since 1.0.0
*/
protected static array $belongsTo = [
'createdBy' => [
'mapper' => AccountMapper::class,
'self' => 'qa_answer_created_by',
],
'question' => [
'mapper' => QAQuestionMapper::class,
'self' => 'qa_answer_question',
],
];
/** /**
* Primary table. * Primary table.
* *
@ -66,17 +83,4 @@ final class QAAnswerMapper extends DataMapperAbstract
* @since 1.0.0 * @since 1.0.0
*/ */
protected static string $primaryField = 'qa_answer_id'; protected static string $primaryField = 'qa_answer_id';
/**
* Belongs to.
*
* @var array<string, array{mapper:string, self:string}>
* @since 1.0.0
*/
protected static array $belongsTo = [
'createdBy' => [
'mapper' => ProfileMapper::class,
'self' => 'qa_answer_created_by',
],
];
} }

View File

@ -43,10 +43,10 @@ class QACategory implements \JsonSerializable
/** /**
* Parent category. * Parent category.
* *
* @var null|int|QACategory * @var null|QACategory
* @since 1.0.0 * @since 1.0.0
*/ */
private $parent = null; private ?self $parent = null;
/** /**
* Get id. * Get id.
@ -89,11 +89,11 @@ class QACategory implements \JsonSerializable
/** /**
* Get the parent category * Get the parent category
* *
* @return null|int * @return null|self
* *
* @since 1.0.0 * @since 1.0.0
*/ */
public function getParent() : ?int public function getParent() : ?self
{ {
return $this->parent; return $this->parent;
} }
@ -101,13 +101,13 @@ class QACategory implements \JsonSerializable
/** /**
* Set the parent category * Set the parent category
* *
* @param int $parent Parent category * @param null|self $parent Parent category
* *
* @return void * @return void
* *
* @since 1.0.0 * @since 1.0.0
*/ */
public function setParent(int $parent) : void public function setParent(?self $parent) : void
{ {
$this->parent = $parent; $this->parent = $parent;
} }

View File

@ -38,6 +38,19 @@ final class QACategoryMapper extends DataMapperAbstract
'qa_category_parent' => ['name' => 'qa_category_parent', 'type' => 'int', 'internal' => 'parent'], 'qa_category_parent' => ['name' => 'qa_category_parent', 'type' => 'int', 'internal' => 'parent'],
]; ];
/**
* Belongs to.
*
* @var array<string, array{mapper:string, self:string}>
* @since 1.0.0
*/
protected static array $belongsTo = [
'parent' => [
'mapper' => self::class,
'self' => 'qa_category_parent',
],
];
/** /**
* Primary table. * Primary table.
* *

View File

@ -14,6 +14,8 @@ declare(strict_types=1);
namespace Modules\QA\Models; namespace Modules\QA\Models;
use Modules\Admin\Models\Account;
use Modules\Admin\Models\NullAccount;
use Modules\Tag\Models\Tag; use Modules\Tag\Models\Tag;
/** /**
@ -61,16 +63,28 @@ class QAQuestion implements \JsonSerializable
/** /**
* Category. * Category.
* *
* @var int * @var QACategory
* @since 1.0.0 * @since 1.0.0
*/ */
private $category = 0; private ?QACategory $category = null;
private $language = ''; private $language = '';
private $createdBy = 0; /**
* Created by.
*
* @var Account
* @since 1.0.0
*/
private Account $createdBy;
private $createdAt = null; /**
* Created at.
*
* @var \DateTime
* @since 1.0.0
*/
private \DateTime $createdAt;
/** /**
* Badges. * Badges.
@ -96,6 +110,7 @@ class QAQuestion implements \JsonSerializable
public function __construct() public function __construct()
{ {
$this->createdAt = new \DateTime('now'); $this->createdAt = new \DateTime('now');
$this->createdBy = new NullAccount();
} }
/** /**
@ -257,21 +272,21 @@ class QAQuestion implements \JsonSerializable
* *
* @since 1.0.0 * @since 1.0.0
*/ */
public function getCategory() public function getCategory() : QACategory
{ {
return $this->category; return $this->category ?? new NullQACategory();
} }
/** /**
* Set the category * Set the category
* *
* @param int $category Category * @param null|QACategory $category Category
* *
* @return void * @return void
* *
* @since 1.0.0 * @since 1.0.0
*/ */
public function setCategory(int $category) : void public function setCategory(?QACategory $category) : void
{ {
$this->category = $category; $this->category = $category;
} }
@ -279,11 +294,11 @@ class QAQuestion implements \JsonSerializable
/** /**
* Get created by * Get created by
* *
* @return int|\phpOMS\Account\Account * @return Account
* *
* @since 1.0.0 * @since 1.0.0
*/ */
public function getCreatedBy() public function getCreatedBy() : Account
{ {
return $this->createdBy; return $this->createdBy;
} }
@ -291,15 +306,15 @@ class QAQuestion implements \JsonSerializable
/** /**
* Set created by * Set created by
* *
* @param mixed $id Created by * @param Account $account Created by
* *
* @return void * @return void
* *
* @since 1.0.0 * @since 1.0.0
*/ */
public function setCreatedBy($id) : void public function setCreatedBy(Account $account) : void
{ {
$this->createdBy = $id; $this->createdBy = $account;
} }
/** /**

View File

@ -14,7 +14,7 @@ declare(strict_types=1);
namespace Modules\QA\Models; namespace Modules\QA\Models;
use Modules\Profile\Models\ProfileMapper; use Modules\Admin\Models\AccountMapper;
use phpOMS\DataStorage\Database\DataMapperAbstract; use phpOMS\DataStorage\Database\DataMapperAbstract;
/** /**
@ -40,7 +40,7 @@ final class QAQuestionMapper extends DataMapperAbstract
'qa_question_question' => ['name' => 'qa_question_question', 'type' => 'string', 'internal' => 'question'], 'qa_question_question' => ['name' => 'qa_question_question', 'type' => 'string', 'internal' => 'question'],
'qa_question_status' => ['name' => 'qa_question_status', 'type' => 'int', 'internal' => 'status'], 'qa_question_status' => ['name' => 'qa_question_status', 'type' => 'int', 'internal' => 'status'],
'qa_question_category' => ['name' => 'qa_question_category', 'type' => 'int', 'internal' => 'category'], 'qa_question_category' => ['name' => 'qa_question_category', 'type' => 'int', 'internal' => 'category'],
'qa_question_created_by' => ['name' => 'qa_question_created_by', 'type' => 'int', 'internal' => 'createdBy'], 'qa_question_created_by' => ['name' => 'qa_question_created_by', 'type' => 'int', 'internal' => 'createdBy', 'readonly' => true],
'qa_question_created_at' => ['name' => 'qa_question_created_at', 'type' => 'DateTime', 'internal' => 'createdAt', 'readonly' => true], 'qa_question_created_at' => ['name' => 'qa_question_created_at', 'type' => 'DateTime', 'internal' => 'createdAt', 'readonly' => true],
]; ];
@ -80,7 +80,7 @@ final class QAQuestionMapper extends DataMapperAbstract
*/ */
protected static array $belongsTo = [ protected static array $belongsTo = [
'createdBy' => [ 'createdBy' => [
'mapper' => ProfileMapper::class, 'mapper' => AccountMapper::class,
'self' => 'qa_question_created_by', 'self' => 'qa_question_created_by',
], ],
]; ];

View File

@ -43,7 +43,7 @@ echo $this->getData('nav')->render();
<div class="col-xs-12"> <div class="col-xs-12">
<section class="box wf-100"> <section class="box wf-100">
<div class="inner"> <div class="inner">
<?= $this->printHtml($answer->getAnswer()); ?><?= $this->printHtml($answer->getCreatedAt()->format('Y-m-d')); ?><?= $this->printHtml($answer->getCreatedBy()); ?><?= $this->printHtml($answer->getStatus()); ?><?= $this->printHtml($answer->isAccepted()); ?> <?= $this->printHtml($answer->getAnswer()); ?><?= $this->printHtml($answer->getCreatedAt()->format('Y-m-d')); ?><?= $this->printHtml($answer->getCreatedBy()->getId()); ?><?= $this->printHtml($answer->getStatus()); ?><?= $this->printHtml($answer->isAccepted()); ?>
</div> </div>
</section> </section>
</div> </div>