diff --git a/Controller/ApiController.php b/Controller/ApiController.php index 9220ffc..39f950c 100755 --- a/Controller/ApiController.php +++ b/Controller/ApiController.php @@ -71,13 +71,13 @@ final class ApiController extends Controller { if (!empty($val = $this->validateQAQuestionCreate($request))) { $response->set('qa_question_create', new FormValidation($val)); - $response->getHeader()->setStatusCode(RequestStatusCode::R_400); + $response->header->status = RequestStatusCode::R_400; return; } $question = $this->createQAQuestionFromRequest($request, $response, $data); - $this->createModel($request->getHeader()->getAccount(), $question, QAQuestionMapper::class, 'question', $request->getOrigin()); + $this->createModel($request->header->account, $question, QAQuestionMapper::class, 'question', $request->getOrigin()); $this->fillJsonResponse($request, $response, NotificationLevel::OK, 'Question', 'Question successfully created.', $question); } @@ -97,12 +97,12 @@ final class ApiController extends Controller $mardkownParser = new Markdown(); $question = new QAQuestion(); - $question->setName((string) $request->getData('title')); - $question->setQuestion((string) $request->getData('plain')); + $question->name = (string) $request->getData('title'); + $question->question = (string) $request->getData('plain'); $question->setLanguage((string) $request->getData('language')); $question->setCategory(new NullQACategory((int) $request->getData('category'))); $question->setStatus((int) $request->getData('status')); - $question->setCreatedBy(new NullAccount($request->getHeader()->getAccount())); + $question->createdBy = new NullAccount($request->header->account); if (!empty($tags = $request->getDataJson('tags'))) { foreach ($tags as $tag) { @@ -113,7 +113,7 @@ final class ApiController extends Controller $internalResponse = new HttpResponse(); $this->app->moduleManager->get('Tag')->apiTagCreate($request, $internalResponse, $data); - $question->addTag($internalResponse->get($request->getUri()->__toString())['response']); + $question->addTag($internalResponse->get($request->uri->__toString())['response']); } else { $question->addTag(new NullTag((int) $tag['id'])); } @@ -167,13 +167,13 @@ final class ApiController extends Controller { if (!empty($val = $this->validateQAAnswerCreate($request))) { $response->set('qa_answer_create', new FormValidation($val)); - $response->getHeader()->setStatusCode(RequestStatusCode::R_400); + $response->header->status = RequestStatusCode::R_400; return; } $answer = $this->createQAAnswerFromRequest($request); - $this->createModel($request->getHeader()->getAccount(), $answer, QAAnswerMapper::class, 'answer', $request->getOrigin()); + $this->createModel($request->header->account, $answer, QAAnswerMapper::class, 'answer', $request->getOrigin()); $this->fillJsonResponse($request, $response, NotificationLevel::OK, 'Answer', 'Answer successfully created.', $answer); } @@ -191,10 +191,10 @@ final class ApiController extends Controller $mardkownParser = new Markdown(); $answer = new QAAnswer(); - $answer->setAnswer((string) $request->getData('plain')); - $answer->setQuestion(new NullQAQuestion((int) $request->getData('question'))); + $answer->answer = (string) $request->getData('plain'); + $answer->question = new NullQAQuestion((int) $request->getData('question')); $answer->setStatus((int) $request->getData('status')); - $answer->setCreatedBy(new NullAccount($request->getHeader()->getAccount())); + $answer->createdBy = new NullAccount($request->header->account); return $answer; } @@ -241,21 +241,21 @@ final class ApiController extends Controller { if (!empty($val = $this->validateQACategoryCreate($request))) { $response->set('qa_category_create', new FormValidation($val)); - $response->getHeader()->setStatusCode(RequestStatusCode::R_400); + $response->header->status = RequestStatusCode::R_400; return; } $category = $this->createQACategoryFromRequest($request); - $this->createModel($request->getHeader()->getAccount(), $category, QACategoryMapper::class, 'category', $request->getOrigin()); + $this->createModel($request->header->account, $category, QACategoryMapper::class, 'category', $request->getOrigin()); - $l11nRequest = new HttpRequest($request->getUri()); + $l11nRequest = new HttpRequest($request->uri); $l11nRequest->setData('category', $category->getId()); $l11nRequest->setData('name', $request->getData('name')); $l11nRequest->setData('language', $request->getData('language')); $l11nQACategory = $this->createQACategoryL11nFromRequest($l11nRequest); - $this->createModel($request->getHeader()->getAccount(), $l11nQACategory, QACategoryL11nMapper::class, 'tag_l11n', $request->getOrigin()); + $this->createModel($request->header->account, $l11nQACategory, QACategoryL11nMapper::class, 'tag_l11n', $request->getOrigin()); $category->setName($l11nQACategory); @@ -277,7 +277,7 @@ final class ApiController extends Controller //$category->setApp(new NullQAApp((int) ($request->getData('app') ?? 1))); if ($request->getData('parent') !== null) { - $category->setParent(new NullQACategory((int) $request->getData('parent'))); + $category->parent = new NullQACategory((int) $request->getData('parent')); } return $category; @@ -340,13 +340,13 @@ final class ApiController extends Controller { if (!empty($val = $this->validateQACategoryL11nCreate($request))) { $response->set('qa_category_l11n_create', new FormValidation($val)); - $response->getHeader()->setStatusCode(RequestStatusCode::R_400); + $response->header->status = RequestStatusCode::R_400; return; } $l11nQACategory = $this->createQACategoryL11nFromRequest($request); - $this->createModel($request->getHeader()->getAccount(), $l11nQACategory, QACategoryL11nMapper::class, 'qa_category_l11n', $request->getOrigin()); + $this->createModel($request->header->account, $l11nQACategory, QACategoryL11nMapper::class, 'qa_category_l11n', $request->getOrigin()); $this->fillJsonResponse($request, $response, NotificationLevel::OK, 'Localization', 'Category localization successfully created', $l11nQACategory); } @@ -367,7 +367,7 @@ final class ApiController extends Controller $l11nQACategory->setLanguage((string) ( $request->getData('language') ?? $request->getLanguage() )); - $l11nQACategory->setName((string) ($request->getData('name') ?? '')); + $l11nQACategory->name = (string) ($request->getData('name') ?? ''); return $l11nQACategory; } diff --git a/Models/QAAnswer.php b/Models/QAAnswer.php index ccdbe3a..44dc0a8 100755 --- a/Models/QAAnswer.php +++ b/Models/QAAnswer.php @@ -43,7 +43,7 @@ class QAAnswer implements \JsonSerializable * @var string * @since 1.0.0 */ - private $answer = ''; + public $answer = ''; /** * Answer raw. @@ -51,7 +51,7 @@ class QAAnswer implements \JsonSerializable * @var string * @since 1.0.0 */ - private $answerRaw = ''; + public $answerRaw = ''; /** * Question @@ -59,7 +59,7 @@ class QAAnswer implements \JsonSerializable * @var QAQuestion * @since 1.0.0 */ - private QAQuestion $question; + public QAQuestion $question; /** * Is accepted answer. @@ -75,7 +75,7 @@ class QAAnswer implements \JsonSerializable * @var Account * @since 1.0.0 */ - private Account $createdBy; + public Account $createdBy; /** * Created at. @@ -83,7 +83,7 @@ class QAAnswer implements \JsonSerializable * @var \DateTimeImmutable * @since 1.0.0 */ - private \DateTimeImmutable $createdAt; + public \DateTimeImmutable $createdAt; /** * Constructor. @@ -213,44 +213,6 @@ class QAAnswer implements \JsonSerializable return $this->isAccepted; } - /** - * Get created by - * - * @return Account - * - * @since 1.0.0 - */ - public function getCreatedBy() : Account - { - return $this->createdBy; - } - - /** - * Set created by - * - * @param Account $account Creator - * - * @return void - * - * @since 1.0.0 - */ - public function setCreatedBy(Account $account) : void - { - $this->createdBy = $account; - } - - /** - * Get created at - * - * @return \DateTimeImmutable - * - * @since 1.0.0 - */ - public function getCreatedAt() : \DateTimeImmutable - { - return $this->createdAt; - } - /** * {@inheritdoc} */ diff --git a/Models/QACategory.php b/Models/QACategory.php index d8440a8..7a66b6e 100755 --- a/Models/QACategory.php +++ b/Models/QACategory.php @@ -45,10 +45,20 @@ class QACategory implements \JsonSerializable /** * Parent category. * - * @var null|QACategory + * @var QACategory * @since 1.0.0 */ - private ?self $parent = null; + public self $parent; + + /** + * Constructor. + * + * @sicne 1.0.0 + */ + public function __construct() + { + $this->parent = new NullQACategory(); + } /** * Get id. @@ -88,40 +98,14 @@ class QACategory implements \JsonSerializable if ($name instanceof QACategoryL11n) { $this->name = $name; } elseif ($this->name instanceof QACategoryL11n && \is_string($name)) { - $this->name->setName($name); + $this->name->name = $name; } elseif (\is_string($name)) { $this->name = new QACategoryL11n(); - $this->name->setName($name); + $this->name->name = $name; $this->name->setLanguage($lang); } } - /** - * Get the parent category - * - * @return null|self - * - * @since 1.0.0 - */ - public function getParent() : ?self - { - return $this->parent; - } - - /** - * Set the parent category - * - * @param null|self $parent Parent category - * - * @return void - * - * @since 1.0.0 - */ - public function setParent(?self $parent) : void - { - $this->parent = $parent; - } - /** * {@inheritdoc} */ diff --git a/Models/QACategoryL11n.php b/Models/QACategoryL11n.php index 58dcd01..1a09750 100644 --- a/Models/QACategoryL11n.php +++ b/Models/QACategoryL11n.php @@ -57,7 +57,7 @@ class QACategoryL11n implements \JsonSerializable, ArrayableInterface * @var string * @since 1.0.0 */ - private string $name = ''; + public string $name = ''; /** * Constructor. @@ -148,20 +148,6 @@ class QACategoryL11n implements \JsonSerializable, ArrayableInterface return $this->name; } - /** - * Set name - * - * @param string $name Name - * - * @return void - * - * @since 1.0.0 - */ - public function setName(string $name) : void - { - $this->name = $name; - } - /** * {@inheritdoc} */ diff --git a/Models/QAQuestion.php b/Models/QAQuestion.php index e2a62f5..991e09f 100755 --- a/Models/QAQuestion.php +++ b/Models/QAQuestion.php @@ -42,7 +42,7 @@ class QAQuestion implements \JsonSerializable * @var string * @since 1.0.0 */ - private string $name = ''; + public string $name = ''; /** * Question status. @@ -58,7 +58,7 @@ class QAQuestion implements \JsonSerializable * @var string * @since 1.0.0 */ - private string $question = ''; + public string $question = ''; /** * Category. @@ -82,7 +82,7 @@ class QAQuestion implements \JsonSerializable * @var Account * @since 1.0.0 */ - private Account $createdBy; + public Account $createdBy; /** * Created at. @@ -90,7 +90,7 @@ class QAQuestion implements \JsonSerializable * @var \DateTimeImmutable * @since 1.0.0 */ - private \DateTimeImmutable $createdAt; + public \DateTimeImmutable $createdAt; /** * Tags. @@ -193,58 +193,6 @@ class QAQuestion implements \JsonSerializable return false; } - /** - * Get title. - * - * @return string - * - * @since 1.0.0 - */ - public function getName() : string - { - return $this->name; - } - - /** - * Set name. - * - * @param string $name Name - * - * @return void - * - * @since 1.0.0 - */ - public function setName(string $name) : void - { - $this->name = $name; - } - - /** - * Get the question. - * - * @return string - * - * @since 1.0.0 - */ - public function getQuestion() : string - { - return $this->question; - } - - /** - * Set the question - * - * @param string $question Question - * - * @return void - * - * @since 1.0.0 - */ - public function setQuestion(string $question) : void - { - $this->question = $question; - } - /** * Get the status * @@ -297,44 +245,6 @@ class QAQuestion implements \JsonSerializable $this->category = $category; } - /** - * Get created by - * - * @return Account - * - * @since 1.0.0 - */ - public function getCreatedBy() : Account - { - return $this->createdBy; - } - - /** - * Set created by - * - * @param Account $account Created by - * - * @return void - * - * @since 1.0.0 - */ - public function setCreatedBy(Account $account) : void - { - $this->createdBy = $account; - } - - /** - * Get created at date time - * - * @return \DateTimeImmutable - * - * @since 1.0.0 - */ - public function getCreatedAt() : \DateTimeImmutable - { - return $this->createdAt; - } - /** * Get tags * diff --git a/Theme/Backend/qa-dashboard.tpl.php b/Theme/Backend/qa-dashboard.tpl.php index 11a863d..dcce917 100755 --- a/Theme/Backend/qa-dashboard.tpl.php +++ b/Theme/Backend/qa-dashboard.tpl.php @@ -25,7 +25,7 @@ echo $this->getData('nav')->render(); ?> printHtml(\count($question->getAnswers())); ?>
- printHtml($question->getName()); ?> + printHtml($question->name); ?>
diff --git a/Theme/Backend/qa-question.tpl.php b/Theme/Backend/qa-question.tpl.php index 980bc1e..9ad1e13 100755 --- a/Theme/Backend/qa-question.tpl.php +++ b/Theme/Backend/qa-question.tpl.php @@ -29,12 +29,12 @@ echo $this->getData('nav')->render();
-

printHtml($question->getName()); ?>

+

printHtml($question->name); ?>

- printHtml($question->getQuestion()); ?> + printHtml($question->question); ?>
- <?= $this->getHtml('AccountImage', '0', '0'); ?> + <?= $this->getHtml('AccountImage', '0', '0'); ?>
@@ -45,7 +45,7 @@ echo $this->getData('nav')->render();
- printHtml($answer->getAnswer()); ?>printHtml($answer->getCreatedAt()->format('Y-m-d')); ?>printHtml($answer->getCreatedBy()->getId()); ?>printHtml($answer->getStatus()); ?>printHtml($answer->isAccepted()); ?> + printHtml($answer->getAnswer()); ?>printHtml($answer->getCreatedAt()->format('Y-m-d')); ?>printHtml($answer->createdBy->getId()); ?>printHtml($answer->getStatus()); ?>printHtml($answer->isAccepted()); ?>
diff --git a/Theme/Backend/qa-tag-list.tpl.php b/Theme/Backend/qa-tag-list.tpl.php index 1ea945d..77b04eb 100755 --- a/Theme/Backend/qa-tag-list.tpl.php +++ b/Theme/Backend/qa-tag-list.tpl.php @@ -40,7 +40,7 @@ echo $this->getData('nav')->render(); $url = \phpOMS\Uri\UriFactory::build('{/prefix}admin/account/settings?{?}&id=' . $value->getId()); ?> printHtml($value->getId()); ?> - printHtml($value->getName()); ?> + printHtml($value->name); ?> getHtml('Empty', '0', '0'); ?> diff --git a/tests/Models/2QACategoryMapperTest.php b/tests/Models/2QACategoryMapperTest.php index 4f78b25..0ab07d3 100755 --- a/tests/Models/2QACategoryMapperTest.php +++ b/tests/Models/2QACategoryMapperTest.php @@ -51,7 +51,7 @@ class QACategoryMapperTest extends \PHPUnit\Framework\TestCase $category = new QACategory(); $category->setName('Test Category2'); - $category->setParent(new NullQACategory(1)); + $category->parent = new NullQACategory(1); $id = QACategoryMapper::create($category); self::assertGreaterThan(0, $category->getId()); @@ -59,7 +59,7 @@ class QACategoryMapperTest extends \PHPUnit\Framework\TestCase $categoryR = QACategoryMapper::get($category->getId()); self::assertEquals($category->getName(), $categoryR->getName()); - self::assertEquals($category->getParent()->getId(), $categoryR->getParent()->getId()); + self::assertEquals($category->parent->getId(), $categoryR->parent->getId()); } /** diff --git a/tests/Models/3QAQuestionMapperTest.php b/tests/Models/3QAQuestionMapperTest.php index 372d43a..d5b4570 100755 --- a/tests/Models/3QAQuestionMapperTest.php +++ b/tests/Models/3QAQuestionMapperTest.php @@ -34,11 +34,11 @@ class QAQuestionMapperTest extends \PHPUnit\Framework\TestCase { $question = new QAQuestion(); - $question->setName('Question Name'); - $question->setQuestion('Question content'); + $question->name = 'Question Name'; + $question->question = 'Question content'; $question->setStatus(QAQuestionStatus::ACTIVE); $question->setCategory(new NullQACategory(1)); - $question->setCreatedBy(new NullAccount(1)); + $question->createdBy = new NullAccount(1); $question->setLanguage('en'); $id = QAQuestionMapper::create($question); @@ -46,12 +46,12 @@ class QAQuestionMapperTest extends \PHPUnit\Framework\TestCase self::assertEquals($id, $question->getId()); $questionR = QAQuestionMapper::get($question->getId()); - self::assertEquals($question->getName(), $questionR->getName()); - self::assertEquals($question->getQuestion(), $questionR->getQuestion()); + self::assertEquals($question->name, $questionR->name); + self::assertEquals($question->question, $questionR->question); self::assertEquals($question->getStatus(), $questionR->getStatus()); self::assertEquals($question->getLanguage(), $questionR->getLanguage()); self::assertEquals($question->getCategory()->getId(), $questionR->getCategory()->getId()); - self::assertEquals($question->getCreatedBy()->getId(), $questionR->getCreatedBy()->getId()); + self::assertEquals($question->createdBy->getId(), $questionR->createdBy->getId()); } /** @@ -65,11 +65,11 @@ class QAQuestionMapperTest extends \PHPUnit\Framework\TestCase $text = new Text(); $question = new QAQuestion(); - $question->setName($text->generateText(\mt_rand(1, 3))); - $question->setQuestion($text->generateText(\mt_rand(100, 500))); + $question->name = $text->generateText(\mt_rand(1, 3)); + $question->question = $text->generateText(\mt_rand(100, 500)); $question->setStatus(QAQuestionStatus::ACTIVE); $question->setCategory(new NullQACategory(\mt_rand(1, 9))); - $question->setCreatedBy(new NullAccount(1)); + $question->createdBy = new NullAccount(1); $question->setLanguage('en'); $id = QAQuestionMapper::create($question); diff --git a/tests/Models/4QAAnswerMapperTest.php b/tests/Models/4QAAnswerMapperTest.php index a48fa19..ea84c0d 100755 --- a/tests/Models/4QAAnswerMapperTest.php +++ b/tests/Models/4QAAnswerMapperTest.php @@ -36,7 +36,7 @@ class QAAnswerMapperTest extends \PHPUnit\Framework\TestCase $answer->setAnswer('Answer content'); $answer->setStatus(QAAnswerStatus::ACTIVE); - $answer->setCreatedBy(new NullAccount(1)); + $answer->createdBy = new NullAccount(1); $answer->setQuestion(new NullQAQuestion(1)); $answer->setAccepted(true); @@ -49,7 +49,7 @@ class QAAnswerMapperTest extends \PHPUnit\Framework\TestCase self::assertEquals($answer->getQuestion()->getId(), $answerR->getQuestion()->getId()); self::assertEquals($answer->getStatus(), $answerR->getStatus()); self::assertEquals($answer->isAccepted(), $answerR->isAccepted()); - self::assertEquals($answer->getCreatedBy()->getId(), $answerR->getCreatedBy()->getId()); + self::assertEquals($answer->createdBy->getId(), $answerR->createdBy->getId()); } /** @@ -64,7 +64,7 @@ class QAAnswerMapperTest extends \PHPUnit\Framework\TestCase $answer = new QAAnswer(); $answer->setAnswer($text->generateText(\mt_rand(100, 500))); - $answer->setCreatedBy(new NullAccount(1)); + $answer->createdBy = new NullAccount(1); $answer->setStatus(QAAnswerStatus::ACTIVE); $answer->setQuestion(new NullQAQuestion(1)); diff --git a/tests/Models/QAAnswerTest.php b/tests/Models/QAAnswerTest.php index 674d7ff..a3d60f4 100755 --- a/tests/Models/QAAnswerTest.php +++ b/tests/Models/QAAnswerTest.php @@ -37,8 +37,8 @@ class QAAnswerTest extends \PHPUnit\Framework\TestCase self::assertEquals(0, $answer->getQuestion()->getId()); self::assertFalse($answer->isAccepted()); self::assertEquals(QAAnswerStatus::ACTIVE, $answer->getStatus()); - self::assertEquals(0, $answer->getCreatedBy()->getId()); - self::assertInstanceOf('\DateTimeImmutable', $answer->getCreatedAt()); + self::assertEquals(0, $answer->createdBy->getId()); + self::assertInstanceOf('\DateTimeImmutable', $answer->createdAt); } /** @@ -52,12 +52,12 @@ class QAAnswerTest extends \PHPUnit\Framework\TestCase $answer->setAnswer('Answer content'); $answer->setStatus(QAAnswerStatus::ACTIVE); $answer->setQuestion(new NullQAQuestion(3)); - $answer->setCreatedBy(new NullAccount(1)); + $answer->createdBy = new NullAccount(1); $answer->setAccepted(true); self::assertEquals('Answer content', $answer->getAnswer()); self::assertEquals(QAAnswerStatus::ACTIVE, $answer->getStatus()); - self::assertEquals(1, $answer->getCreatedBy()->getId()); + self::assertEquals(1, $answer->createdBy->getId()); self::assertEquals(3, $answer->getQuestion()->getId()); self::assertTrue($answer->isAccepted()); } diff --git a/tests/Models/QACategoryTest.php b/tests/Models/QACategoryTest.php index 9641e3f..b74ff88 100755 --- a/tests/Models/QACategoryTest.php +++ b/tests/Models/QACategoryTest.php @@ -32,7 +32,7 @@ class QACategoryTest extends \PHPUnit\Framework\TestCase self::assertEquals(0, $category->getId()); self::assertEquals('', $category->getName()); - self::assertNull($category->getParent()); + self::assertEquals(0, $category->parent->getId()); } /** @@ -44,9 +44,9 @@ class QACategoryTest extends \PHPUnit\Framework\TestCase $category = new QACategory(); $category->setName('Category Name'); - $category->setParent(new NullQACategory(1)); + $category->parent = new NullQACategory(1); self::assertEquals('Category Name', $category->getName()); - self::assertEquals(1, $category->getParent()->getId()); + self::assertEquals(1, $category->parent->getId()); } } diff --git a/tests/Models/QAQuestionTest.php b/tests/Models/QAQuestionTest.php index 6e59c93..3560525 100755 --- a/tests/Models/QAQuestionTest.php +++ b/tests/Models/QAQuestionTest.php @@ -33,14 +33,14 @@ class QAQuestionTest extends \PHPUnit\Framework\TestCase $question = new QAQuestion(); self::assertEquals(0, $question->getId()); - self::assertEquals('', $question->getName()); - self::assertEquals('', $question->getQuestion()); + self::assertEquals('', $question->name); + self::assertEquals('', $question->question); self::assertEquals(QAQuestionStatus::ACTIVE, $question->getStatus()); self::assertEquals(0, $question->getCategory()->getId()); self::assertEquals('', $question->getLanguage()); - self::assertEquals(0, $question->getCreatedBy()->getId()); - self::assertInstanceOf('\DateTimeImmutable', $question->getCreatedAt()); - self::assertEquals([], $question->getBadges()); + self::assertEquals(0, $question->createdBy->getId()); + self::assertInstanceOf('\DateTimeImmutable', $question->createdAt); + self::assertEquals([], $question->getTags()); } /** @@ -51,18 +51,18 @@ class QAQuestionTest extends \PHPUnit\Framework\TestCase { $question = new QAQuestion(); - $question->setName('Question Name'); - $question->setQuestion('Question content'); + $question->name = 'Question Name'; + $question->question = 'Question content'; $question->setStatus(QAQuestionStatus::ACTIVE); $question->setCategory(new NullQACategory(1)); - $question->setCreatedBy(new NullAccount(1)); + $question->createdBy = new NullAccount(1); $question->setLanguage('en'); - self::assertEquals('Question Name', $question->getName()); - self::assertEquals('Question content', $question->getQuestion()); + self::assertEquals('Question Name', $question->name); + self::assertEquals('Question content', $question->question); self::assertEquals(QAQuestionStatus::ACTIVE, $question->getStatus()); self::assertEquals('en', $question->getLanguage()); self::assertEquals(1, $question->getCategory()->getId()); - self::assertEquals(1, $question->getCreatedBy()->getId()); + self::assertEquals(1, $question->createdBy->getId()); } }