mirror of
https://github.com/Karaka-Management/oms-QA.git
synced 2026-02-04 02:28:40 +00:00
fixes Orange-Management/phpOMS#224 and fixes Orange-Management/phpOMS#212
This commit is contained in:
parent
52e9db17cf
commit
80c7d090e9
38
Models/NullQAAnswer.php
Normal file
38
Models/NullQAAnswer.php
Normal 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
38
Models/NullQACategory.php
Normal 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
38
Models/NullQAQuestion.php
Normal 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;
|
||||
}
|
||||
}
|
||||
|
|
@ -14,6 +14,9 @@ declare(strict_types=1);
|
|||
|
||||
namespace Modules\QA\Models;
|
||||
|
||||
use Modules\Admin\Models\Account;
|
||||
use Modules\Admin\Models\NullAccount;
|
||||
|
||||
/**
|
||||
* Answer class.
|
||||
*
|
||||
|
|
@ -50,7 +53,13 @@ class QAAnswer implements \JsonSerializable
|
|||
*/
|
||||
private $answerRaw = '';
|
||||
|
||||
private $question = 0;
|
||||
/**
|
||||
* Question
|
||||
*
|
||||
* @var QAQuestion
|
||||
* @since 1.0.0
|
||||
*/
|
||||
private QAQuestion $question;
|
||||
|
||||
/**
|
||||
* Is accepted answer.
|
||||
|
|
@ -60,8 +69,20 @@ class QAAnswer implements \JsonSerializable
|
|||
*/
|
||||
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;
|
||||
|
||||
/**
|
||||
|
|
@ -72,6 +93,8 @@ class QAAnswer implements \JsonSerializable
|
|||
public function __construct()
|
||||
{
|
||||
$this->createdAt = new \DateTime('now');
|
||||
$this->createdBy = new NullAccount();
|
||||
$this->question = new NullQAQuestion();
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -115,11 +138,11 @@ class QAAnswer implements \JsonSerializable
|
|||
/**
|
||||
* Get the question
|
||||
*
|
||||
* @return int
|
||||
* @return QAQuestion
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public function getQuestion() : int
|
||||
public function getQuestion() : QAQuestion
|
||||
{
|
||||
return $this->question;
|
||||
}
|
||||
|
|
@ -127,13 +150,13 @@ class QAAnswer implements \JsonSerializable
|
|||
/**
|
||||
* Set the question
|
||||
*
|
||||
* @param int $question Question
|
||||
* @param QAQuestion $question Question
|
||||
*
|
||||
* @return void
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public function setQuestion(int $question) : void
|
||||
public function setQuestion(QAQuestion $question) : void
|
||||
{
|
||||
$this->question = $question;
|
||||
}
|
||||
|
|
@ -193,11 +216,11 @@ class QAAnswer implements \JsonSerializable
|
|||
/**
|
||||
* Get created by
|
||||
*
|
||||
* @return int|\phpOMS\Account\Account
|
||||
* @return Account
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public function getCreatedBy()
|
||||
public function getCreatedBy() : Account
|
||||
{
|
||||
return $this->createdBy;
|
||||
}
|
||||
|
|
@ -205,15 +228,15 @@ class QAAnswer implements \JsonSerializable
|
|||
/**
|
||||
* Set created by
|
||||
*
|
||||
* @param mixed $id Creator
|
||||
* @param Account $account Creator
|
||||
*
|
||||
* @return void
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public function setCreatedBy($id) : void
|
||||
public function setCreatedBy(Account $account) : void
|
||||
{
|
||||
$this->createdBy = $id;
|
||||
$this->createdBy = $account;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -14,7 +14,7 @@ declare(strict_types=1);
|
|||
|
||||
namespace Modules\QA\Models;
|
||||
|
||||
use Modules\Profile\Models\ProfileMapper;
|
||||
use Modules\Admin\Models\AccountMapper;
|
||||
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_status' => ['name' => 'qa_answer_status', 'type' => 'int', 'internal' => 'status'],
|
||||
'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],
|
||||
];
|
||||
|
||||
/**
|
||||
* 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.
|
||||
*
|
||||
|
|
@ -66,17 +83,4 @@ final class QAAnswerMapper extends DataMapperAbstract
|
|||
* @since 1.0.0
|
||||
*/
|
||||
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',
|
||||
],
|
||||
];
|
||||
}
|
||||
|
|
|
|||
|
|
@ -43,10 +43,10 @@ class QACategory implements \JsonSerializable
|
|||
/**
|
||||
* Parent category.
|
||||
*
|
||||
* @var null|int|QACategory
|
||||
* @var null|QACategory
|
||||
* @since 1.0.0
|
||||
*/
|
||||
private $parent = null;
|
||||
private ?self $parent = null;
|
||||
|
||||
/**
|
||||
* Get id.
|
||||
|
|
@ -89,11 +89,11 @@ class QACategory implements \JsonSerializable
|
|||
/**
|
||||
* Get the parent category
|
||||
*
|
||||
* @return null|int
|
||||
* @return null|self
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public function getParent() : ?int
|
||||
public function getParent() : ?self
|
||||
{
|
||||
return $this->parent;
|
||||
}
|
||||
|
|
@ -101,13 +101,13 @@ class QACategory implements \JsonSerializable
|
|||
/**
|
||||
* Set the parent category
|
||||
*
|
||||
* @param int $parent Parent category
|
||||
* @param null|self $parent Parent category
|
||||
*
|
||||
* @return void
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public function setParent(int $parent) : void
|
||||
public function setParent(?self $parent) : void
|
||||
{
|
||||
$this->parent = $parent;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -38,6 +38,19 @@ final class QACategoryMapper extends DataMapperAbstract
|
|||
'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.
|
||||
*
|
||||
|
|
|
|||
|
|
@ -14,6 +14,8 @@ declare(strict_types=1);
|
|||
|
||||
namespace Modules\QA\Models;
|
||||
|
||||
use Modules\Admin\Models\Account;
|
||||
use Modules\Admin\Models\NullAccount;
|
||||
use Modules\Tag\Models\Tag;
|
||||
|
||||
/**
|
||||
|
|
@ -61,16 +63,28 @@ class QAQuestion implements \JsonSerializable
|
|||
/**
|
||||
* Category.
|
||||
*
|
||||
* @var int
|
||||
* @var QACategory
|
||||
* @since 1.0.0
|
||||
*/
|
||||
private $category = 0;
|
||||
private ?QACategory $category = null;
|
||||
|
||||
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.
|
||||
|
|
@ -96,6 +110,7 @@ class QAQuestion implements \JsonSerializable
|
|||
public function __construct()
|
||||
{
|
||||
$this->createdAt = new \DateTime('now');
|
||||
$this->createdBy = new NullAccount();
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -257,21 +272,21 @@ class QAQuestion implements \JsonSerializable
|
|||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public function getCategory()
|
||||
public function getCategory() : QACategory
|
||||
{
|
||||
return $this->category;
|
||||
return $this->category ?? new NullQACategory();
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the category
|
||||
*
|
||||
* @param int $category Category
|
||||
* @param null|QACategory $category Category
|
||||
*
|
||||
* @return void
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public function setCategory(int $category) : void
|
||||
public function setCategory(?QACategory $category) : void
|
||||
{
|
||||
$this->category = $category;
|
||||
}
|
||||
|
|
@ -279,11 +294,11 @@ class QAQuestion implements \JsonSerializable
|
|||
/**
|
||||
* Get created by
|
||||
*
|
||||
* @return int|\phpOMS\Account\Account
|
||||
* @return Account
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public function getCreatedBy()
|
||||
public function getCreatedBy() : Account
|
||||
{
|
||||
return $this->createdBy;
|
||||
}
|
||||
|
|
@ -291,15 +306,15 @@ class QAQuestion implements \JsonSerializable
|
|||
/**
|
||||
* Set created by
|
||||
*
|
||||
* @param mixed $id Created by
|
||||
* @param Account $account Created by
|
||||
*
|
||||
* @return void
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public function setCreatedBy($id) : void
|
||||
public function setCreatedBy(Account $account) : void
|
||||
{
|
||||
$this->createdBy = $id;
|
||||
$this->createdBy = $account;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -14,7 +14,7 @@ declare(strict_types=1);
|
|||
|
||||
namespace Modules\QA\Models;
|
||||
|
||||
use Modules\Profile\Models\ProfileMapper;
|
||||
use Modules\Admin\Models\AccountMapper;
|
||||
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_status' => ['name' => 'qa_question_status', 'type' => 'int', 'internal' => 'status'],
|
||||
'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],
|
||||
];
|
||||
|
||||
|
|
@ -80,7 +80,7 @@ final class QAQuestionMapper extends DataMapperAbstract
|
|||
*/
|
||||
protected static array $belongsTo = [
|
||||
'createdBy' => [
|
||||
'mapper' => ProfileMapper::class,
|
||||
'mapper' => AccountMapper::class,
|
||||
'self' => 'qa_question_created_by',
|
||||
],
|
||||
];
|
||||
|
|
|
|||
|
|
@ -43,7 +43,7 @@ echo $this->getData('nav')->render();
|
|||
<div class="col-xs-12">
|
||||
<section class="box wf-100">
|
||||
<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>
|
||||
</section>
|
||||
</div>
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user