diff --git a/Controller/ApiController.php b/Controller/ApiController.php index 80bb113..a285ffd 100755 --- a/Controller/ApiController.php +++ b/Controller/ApiController.php @@ -82,13 +82,13 @@ final class ApiController extends Controller { if (!empty($val = $this->validateEditorCreate($request))) { $response->set('editor_create', new FormValidation($val)); - $response->getHeader()->setStatusCode(RequestStatusCode::R_400); + $response->header->status = RequestStatusCode::R_400; return; } $doc = $this->createDocFromRequest($request); - $this->createModel($request->getHeader()->getAccount(), $doc, EditorDocMapper::class, 'doc', $request->getOrigin()); + $this->createModel($request->header->account, $doc, EditorDocMapper::class, 'doc', $request->getOrigin()); $this->fillJsonResponse($request, $response, NotificationLevel::OK, 'Document', 'Document successfully created', $doc); } @@ -104,11 +104,11 @@ final class ApiController extends Controller private function createDocFromRequest(RequestAbstract $request) : EditorDoc { $doc = new EditorDoc(); - $doc->setTitle((string) ($request->getData('title') ?? '')); - $doc->setPlain((string) ($request->getData('plain') ?? '')); - $doc->setContent(Markdown::parse((string) ($request->getData('plain') ?? ''))); + $doc->title = (string) ($request->getData('title') ?? ''); + $doc->plaint = (string) ($request->getData('plain') ?? ''); + $doc->content = Markdown::parse((string) ($request->getData('plain') ?? '')); $doc->setVirtualPath((string) ($request->getData('virtualpath') ?? '/')); - $doc->setCreatedBy(new NullAccount($request->getHeader()->getAccount())); + $doc->createdBy = new NullAccount($request->header->account); if (!empty($tags = $request->getDataJson('tags'))) { foreach ($tags as $tag) { @@ -119,7 +119,7 @@ final class ApiController extends Controller $internalResponse = new HttpResponse(); $this->app->moduleManager->get('Tag')->apiTagCreate($request, $internalResponse, null); - $doc->addTag($internalResponse->get($request->getUri()->__toString())['response']); + $doc->addTag($internalResponse->get($request->uri->__toString())['response']); } else { $doc->addTag(new NullTag((int) $tag['id'])); } @@ -147,7 +147,7 @@ final class ApiController extends Controller /** @var \Modules\Editor\Models\EditorDoc $old */ $old = clone EditorDocMapper::get((int) $request->getData('id')); $new = $this->updateEditorFromRequest($request); - $this->updateModel($request->getHeader()->getAccount(), $old, $new, EditorDocMapper::class, 'doc', $request->getOrigin()); + $this->updateModel($request->header->account, $old, $new, EditorDocMapper::class, 'doc', $request->getOrigin()); $this->fillJsonResponse($request, $response, NotificationLevel::OK, 'Document', 'Document successfully updated', $new); } @@ -164,9 +164,9 @@ final class ApiController extends Controller { /** @var \Modules\Editor\Models\EditorDoc $doc */ $doc = EditorDocMapper::get((int) $request->getData('id')); - $doc->setTitle((string) ($request->getData('title') ?? $doc->getTitle())); - $doc->setPlain((string) ($request->getData('plain') ?? $doc->getPlain())); - $doc->setContent(Markdown::parse((string) ($request->getData('plain') ?? $doc->getPlain()))); + $doc->title = (string) ($request->getData('title') ?? $doc->title); + $doc->plaint = (string) ($request->getData('plain') ?? $doc->plain); + $doc->content = Markdown::parse((string) ($request->getData('plain') ?? $doc->plain)); return $doc; } @@ -208,7 +208,7 @@ final class ApiController extends Controller { /** @var \Modules\Editor\Models\EditorDoc $doc */ $doc = EditorDocMapper::get((int) $request->getData('id')); - $this->deleteModel($request->getHeader()->getAccount(), $doc, EditorDocMapper::class, 'doc', $request->getOrigin()); + $this->deleteModel($request->header->account, $doc, EditorDocMapper::class, 'doc', $request->getOrigin()); $this->fillJsonResponse($request, $response, NotificationLevel::OK, 'Document', 'Document successfully deleted', $doc); } } diff --git a/Controller/BackendController.php b/Controller/BackendController.php index f992a04..73e950c 100755 --- a/Controller/BackendController.php +++ b/Controller/BackendController.php @@ -103,7 +103,7 @@ final class BackendController extends Controller $view->addData('nav', $this->app->moduleManager->get('Navigation')->createNavigationMid(1005301001, $request, $response)); $path = \str_replace('+', ' ', (string) ($request->getData('path') ?? '/')); - $docs = EditorDocMapper::withConditional('language', $response->getLanguage())::getByVirtualPath($path, $request->getHeader()->getAccount()); + $docs = EditorDocMapper::withConditional('language', $response->getLanguage())::getByVirtualPath($path, $request->header->account); list($collection, $parent) = CollectionMapper::getCollectionsByPath($path); @@ -133,14 +133,14 @@ final class BackendController extends Controller /** @var \Modules\Editor\Models\EditorDoc $doc */ $doc = EditorDocMapper::withConditional('language', $response->getLanguage())::get((int) $request->getData('id')); - $accountId = $request->getHeader()->getAccount(); + $accountId = $request->header->account; - if ($doc->getCreatedBy()->getId() !== $accountId + if ($doc->createdBy->getId() !== $accountId && !$this->app->accountManager->get($accountId)->hasPermission( PermissionType::READ, $this->app->orgId, $this->app->appName, self::MODULE_NAME, PermissionState::DOC, $doc->getId()) ) { $view->setTemplate('/Web/Backend/Error/403_inline'); - $response->getHeader()->setStatusCode(RequestStatusCode::R_403); + $response->header->status = RequestStatusCode::R_403; return $view; } @@ -179,14 +179,14 @@ final class BackendController extends Controller /** @var \Modules\Editor\Models\EditorDoc $doc */ $doc = EditorDocMapper::get((int) $request->getData('id')); - $accountId = $request->getHeader()->getAccount(); + $accountId = $request->header->account; - if ($doc->getCreatedBy()->getId() !== $accountId + if ($doc->createdBy->getId() !== $accountId && !$this->app->accountManager->get($accountId)->hasPermission( PermissionType::READ, $this->app->orgId, $this->app->appName, self::MODULE_NAME, PermissionState::DOC, $doc->getId()) ) { $view->setTemplate('/Web/Backend/Error/403_inline'); - $response->getHeader()->setStatusCode(RequestStatusCode::R_403); + $response->header->status = RequestStatusCode::R_403; return $view; } diff --git a/Models/EditorDoc.php b/Models/EditorDoc.php index 2e8be2a..99e91d2 100755 --- a/Models/EditorDoc.php +++ b/Models/EditorDoc.php @@ -43,7 +43,7 @@ class EditorDoc implements \JsonSerializable, ArrayableInterface * @var string * @since 1.0.0 */ - private string $title = ''; + public string $title = ''; /** * Content. @@ -51,7 +51,7 @@ class EditorDoc implements \JsonSerializable, ArrayableInterface * @var string * @since 1.0.0 */ - private string $content = ''; + public string $content = ''; /** * Unparsed. @@ -59,7 +59,7 @@ class EditorDoc implements \JsonSerializable, ArrayableInterface * @var string * @since 1.0.0 */ - private string $plain = ''; + public string $plain = ''; /** * Doc path for organizing. @@ -75,7 +75,7 @@ class EditorDoc implements \JsonSerializable, ArrayableInterface * @var \DateTimeImmutable * @since 1.0.0 */ - private \DateTimeImmutable $createdAt; + public \DateTimeImmutable $createdAt; /** * Creator. @@ -83,7 +83,7 @@ class EditorDoc implements \JsonSerializable, ArrayableInterface * @var Account * @since 1.0.0 */ - private Account $createdBy; + public Account $createdBy; /** * Tags. @@ -104,70 +104,6 @@ class EditorDoc implements \JsonSerializable, ArrayableInterface $this->createdAt = new \DateTimeImmutable('now'); } - /** - * Get the content - * - * @return string - * - * @since 1.0.0 - */ - public function getContent() : string - { - return $this->content; - } - - /** - * Set the content - * - * @param string $content Content - * - * @return void - * - * @since 1.0.0 - */ - public function setContent(string $content) : void - { - $this->content = $content; - } - - /** - * Set the plain text - * - * @param string $plain Plain text - * - * @return void - * - * @since 1.0.0 - */ - public function setPlain(string $plain) : void - { - $this->plain = $plain; - } - - /** - * Get the plain text - * - * @return string - * - * @since 1.0.0 - */ - public function getPlain() : string - { - return $this->plain; - } - - /** - * Get created at - * - * @return \DateTimeImmutable - * - * @since 1.0.0 - */ - public function getCreatedAt() : \DateTimeImmutable - { - return $this->createdAt; - } - /** * Get the id * @@ -180,56 +116,6 @@ class EditorDoc implements \JsonSerializable, ArrayableInterface return $this->id; } - /** - * Get created by - * - * @return Account - * - * @since 1.0.0 - */ - public function getCreatedBy() : Account - { - return $this->createdBy; - } - - /** - * Set created by - * - * @param Account $account Creator - * - * @since 1.0.0 - */ - public function setCreatedBy(Account $account) : void - { - $this->createdBy = $account; - } - - /** - * Get the title - * - * @return string - * - * @since 1.0.0 - */ - public function getTitle() : string - { - return $this->title; - } - - /** - * Set the title - * - * @param string $title Title - * - * @return mixed - * - * @since 1.0.0 - */ - public function setTitle(string $title) - { - $this->title = $title; - } - /** * Get the path * diff --git a/Theme/Backend/Components/Editor/TextView.php b/Theme/Backend/Components/Editor/TextView.php index c1b5485..2eb1cf3 100755 --- a/Theme/Backend/Components/Editor/TextView.php +++ b/Theme/Backend/Components/Editor/TextView.php @@ -44,7 +44,7 @@ class TextView extends View * @var string * @since 1.0.0 */ - private string $name = ''; + public string $name = ''; /** * Form id diff --git a/Theme/Backend/editor-create.tpl.php b/Theme/Backend/editor-create.tpl.php index cd766ae..4689175 100755 --- a/Theme/Backend/editor-create.tpl.php +++ b/Theme/Backend/editor-create.tpl.php @@ -28,7 +28,7 @@ echo $this->getData('nav')->render(); ?>
-
+
@@ -46,8 +46,8 @@ echo $this->getData('nav')->render(); ?> 'editor', 'plain', 'fEditor', - $doc->getPlain(), - $doc->getContent() + $doc->plain, + $doc->content ); ?>
diff --git a/Theme/Backend/editor-list.tpl.php b/Theme/Backend/editor-list.tpl.php index 0e2136c..5c701dc 100755 --- a/Theme/Backend/editor-list.tpl.php +++ b/Theme/Backend/editor-list.tpl.php @@ -69,21 +69,21 @@ echo $this->getData('nav')->render(); ?> getHtml('Created'); ?> $value) : ++$count; - $url = UriFactory::build('{/prefix}editor/list?path=' . \rtrim($value->getVirtualPath(), '/') . '/' . $value->getName()); + $url = UriFactory::build('{/prefix}editor/list?path=' . \rtrim($value->getVirtualPath(), '/') . '/' . $value->name); ?> - printHtml($value->getName()); ?> - printHtml($value->getCreatedBy()->getName1()); ?> - printHtml($value->getCreatedAt()->format('Y-m-d')); ?> + printHtml($value->name); ?> + printHtml($value->createdBy->name1); ?> + printHtml($value->createdAt->format('Y-m-d')); ?> $value) : ++$count; $url = UriFactory::build('{/prefix}editor/single?{?}&id=' . $value->getId()); ?> - printHtml($value->getTitle()); ?> - printHtml($value->getCreatedBy()->getName1()); ?> - printHtml($value->getCreatedAt()->format('Y-m-d H:i:s')); ?> + printHtml($value->title); ?> + printHtml($value->createdBy->name1); ?> + printHtml($value->createdAt->format('Y-m-d H:i:s')); ?> getHtml('Empty', '0', '0'); ?> diff --git a/Theme/Backend/editor-single.tpl.php b/Theme/Backend/editor-single.tpl.php index 7ead28f..dd6f042 100755 --- a/Theme/Backend/editor-single.tpl.php +++ b/Theme/Backend/editor-single.tpl.php @@ -29,10 +29,10 @@ echo $this->getData('nav')->render(); ?>
-
printHtml($doc->getTitle()); ?>
+
printHtml($doc->title); ?>
- getContent(); ?> + content; ?>
diff --git a/tests/Controller/ApiControllerTest.php b/tests/Controller/ApiControllerTest.php index 2b809b4..bbc43e6 100755 --- a/tests/Controller/ApiControllerTest.php +++ b/tests/Controller/ApiControllerTest.php @@ -98,13 +98,13 @@ class ApiControllerTest extends \PHPUnit\Framework\TestCase $response = new HttpResponse(); $request = new HttpRequest(new HttpUri('')); - $request->getHeader()->setAccount(1); + $request->header->account = 1; $request->setData('title', 'Controller Test Title'); $request->setData('plain', 'Controller Test Description'); $this->module->apiEditorCreate($request, $response); - self::assertEquals('Controller Test Title', $response->get('')['response']->getTitle()); + self::assertEquals('Controller Test Title', $response->get('')['response']->title); self::assertGreaterThan(0, $response->get('')['response']->getId()); } @@ -121,14 +121,14 @@ class ApiControllerTest extends \PHPUnit\Framework\TestCase $response = new HttpResponse(); $request = new HttpRequest(new HttpUri('')); - $request->getHeader()->setAccount(1); + $request->header->account = 1; $request->setData('title', 'Controller Test With Tag'); $request->setData('plain', 'Controller Test Description'); $request->setData('tag', '[' . $tagId . ']'); $this->module->apiEditorCreate($request, $response); - self::assertEquals('Controller Test With Tag', $response->get('')['response']->getTitle()); + self::assertEquals('Controller Test With Tag', $response->get('')['response']->title); self::assertGreaterThan(0, $response->get('')['response']->getId()); } @@ -141,12 +141,12 @@ class ApiControllerTest extends \PHPUnit\Framework\TestCase $response = new HttpResponse(); $request = new HttpRequest(new HttpUri('')); - $request->getHeader()->setAccount(1); + $request->header->account = 1; $request->setData('title', 'Controller Test Title'); $this->module->apiEditorCreate($request, $response); - self::assertEquals(RequestStatusCode::R_400, $response->getHeader()->getStatusCode()); + self::assertEquals(RequestStatusCode::R_400, $response->header->status); } /** @@ -158,14 +158,14 @@ class ApiControllerTest extends \PHPUnit\Framework\TestCase $response = new HttpResponse(); $request = new HttpRequest(new HttpUri('')); - $request->getHeader()->setAccount(1); + $request->header->account = 1; $request->setData('id', '1'); $request->setData('title', 'Changed Title'); $this->module->apiEditorUpdate($request, $response); - self::assertEquals('Changed Title', $response->get('')['response']->getTitle()); - self::assertEquals('Changed Title', EditorDocMapper::get(1)->getTitle()); + self::assertEquals('Changed Title', $response->get('')['response']->title); + self::assertEquals('Changed Title', EditorDocMapper::get(1)->title); self::assertEquals(1, $response->get('')['response']->getId()); } @@ -178,12 +178,12 @@ class ApiControllerTest extends \PHPUnit\Framework\TestCase $response = new HttpResponse(); $request = new HttpRequest(new HttpUri('')); - $request->getHeader()->setAccount(1); + $request->header->account = 1; $request->setData('id', '1'); $this->module->apiEditorGet($request, $response); - self::assertEquals('Changed Title', $response->get('')['response']->getTitle()); + self::assertEquals('Changed Title', $response->get('')['response']->title); } /** @@ -193,16 +193,16 @@ class ApiControllerTest extends \PHPUnit\Framework\TestCase public function testDeleteEditorDoc() : void { $doc = new EditorDoc(); - $doc->setTitle('TestTitle'); - $doc->setContent('TestContent'); - $doc->setCreatedBy(new NullAccount(1)); + $doc->title = 'TestTitle'; + $doc->content = 'TestContent'; + $doc->createdBy = new NullAccount(1); $docId = EditorDocMapper::create($doc); $response = new HttpResponse(); $request = new HttpRequest(new HttpUri('')); - $request->getHeader()->setAccount(1); + $request->header->account = 1; $request->setData('id', $docId); $this->module->apiEditorDelete($request, $response); diff --git a/tests/Models/EditorDocMapperTest.php b/tests/Models/EditorDocMapperTest.php index 8e3c04c..fcec992 100755 --- a/tests/Models/EditorDocMapperTest.php +++ b/tests/Models/EditorDocMapperTest.php @@ -32,21 +32,21 @@ class EditorDocMapperTest extends \PHPUnit\Framework\TestCase { $doc = new EditorDoc(); - $doc->setCreatedBy(new NullAccount(1)); - $doc->setTitle('Title'); - $doc->setContent('Content'); - $doc->setPath('/some/test/path'); + $doc->createdBy = new NullAccount(1); + $doc->title = 'Title'; + $doc->content = 'Content'; + $doc->setVirtualPath('/some/test/path'); $id = EditorDocMapper::create($doc); self::assertGreaterThan(0, $doc->getId()); self::assertEquals($id, $doc->getId()); $docR = EditorDocMapper::get($doc->getId()); - self::assertEquals($doc->getCreatedAt()->format('Y-m-d'), $docR->getCreatedAt()->format('Y-m-d')); - self::assertEquals($doc->getCreatedBy()->getId(), $docR->getCreatedBy()->getId()); - self::assertEquals($doc->getContent(), $docR->getContent()); - self::assertEquals($doc->getTitle(), $docR->getTitle()); - self::assertEquals($doc->getPath(), $docR->getPath()); + self::assertEquals($doc->createdAt->format('Y-m-d'), $docR->createdAt->format('Y-m-d')); + self::assertEquals($doc->createdBy->getId(), $docR->createdBy->getId()); + self::assertEquals($doc->content, $docR->content); + self::assertEquals($doc->title, $docR->title); + self::assertEquals($doc->getVirtualPath(), $docR->getVirtualPath()); } /** @@ -62,10 +62,10 @@ class EditorDocMapperTest extends \PHPUnit\Framework\TestCase // Test other - $doc->setCreatedBy(new NullAccount(\mt_rand(1, 1))); - $doc->setTitle($text->generateText(\mt_rand(3, 7))); - $doc->setContent($text->generateText(\mt_rand(20, 500))); - $doc->setPath('/some/test/path'); + $doc->createdBy = new NullAccount(\mt_rand(1, 1)); + $doc->title = $text->generateText(\mt_rand(3, 7)); + $doc->content = $text->generateText(\mt_rand(20, 500)); + $doc->setVirtualPath('/some/test/path'); $id = EditorDocMapper::create($doc); } diff --git a/tests/Models/EditorDocTest.php b/tests/Models/EditorDocTest.php index 93c05fc..0ec368f 100755 --- a/tests/Models/EditorDocTest.php +++ b/tests/Models/EditorDocTest.php @@ -37,12 +37,12 @@ class EditorDocTest extends \PHPUnit\Framework\TestCase public function testDefault() : void { self::assertEquals(0, $this->doc->getId()); - self::assertEquals(0, $this->doc->getCreatedBy()->getId()); - self::assertEquals('', $this->doc->getTitle()); - self::assertEquals('', $this->doc->getContent()); - self::assertEquals('', $this->doc->getPlain()); + self::assertEquals(0, $this->doc->createdBy->getId()); + self::assertEquals('', $this->doc->title); + self::assertEquals('', $this->doc->content); + self::assertEquals('', $this->doc->plain); self::assertEquals([], $this->doc->getTags()); - self::assertEquals((new \DateTime('now'))->format('Y-m-d'), $this->doc->getCreatedAt()->format('Y-m-d')); + self::assertEquals((new \DateTime('now'))->format('Y-m-d'), $this->doc->createdAt->format('Y-m-d')); } /** @@ -51,8 +51,8 @@ class EditorDocTest extends \PHPUnit\Framework\TestCase */ public function testCreatedByInputOutput() : void { - $this->doc->setCreatedBy(new NullAccount(1)); - self::assertEquals(1, $this->doc->getCreatedBy()->getId()); + $this->doc->createdBy = new NullAccount(1); + self::assertEquals(1, $this->doc->createdBy->getId()); } /** @@ -61,8 +61,8 @@ class EditorDocTest extends \PHPUnit\Framework\TestCase */ public function testTitleInputOutput() : void { - $this->doc->setTitle('Title'); - self::assertEquals('Title', $this->doc->getTitle()); + $this->doc->title = 'Title'; + self::assertEquals('Title', $this->doc->title); } /** @@ -71,8 +71,8 @@ class EditorDocTest extends \PHPUnit\Framework\TestCase */ public function testContentInputOutput() : void { - $this->doc->setContent('Content'); - self::assertEquals('Content', $this->doc->getContent()); + $this->doc->content = 'Content'; + self::assertEquals('Content', $this->doc->content); } /** @@ -81,8 +81,8 @@ class EditorDocTest extends \PHPUnit\Framework\TestCase */ public function testPlainInputOutput() : void { - $this->doc->setPlain('Plain'); - self::assertEquals('Plain', $this->doc->getPlain()); + $this->doc->plain = 'Plain'; + self::assertEquals('Plain', $this->doc->plain); } /** @@ -91,8 +91,8 @@ class EditorDocTest extends \PHPUnit\Framework\TestCase */ public function testPathInputOutput() : void { - $this->doc->setPath('/some/test/path'); - self::assertEquals('/some/test/path', $this->doc->getPath()); + $this->doc->setVirtualPath('/some/test/path'); + self::assertEquals('/some/test/path', $this->doc->getVirtualPath()); } /** @@ -114,18 +114,18 @@ class EditorDocTest extends \PHPUnit\Framework\TestCase */ public function testSerialization() : void { - $this->doc->setCreatedBy(new NullAccount(1)); - $this->doc->setTitle('Title'); - $this->doc->setContent('Content'); - $this->doc->setPlain('Plain'); - $this->doc->setPath('/some/path'); + $this->doc->createdBy = new NullAccount(1); + $this->doc->title = 'Title'; + $this->doc->content = 'Content'; + $this->doc->plaint = 'Plain'; + $this->doc->setVirtualPath('/some/path'); $arr = [ 'id' => 0, - 'title' => $this->doc->getTitle(), - 'plain' => $this->doc->getPlain(), - 'content' => $this->doc->getContent(), - 'createdAt' => $this->doc->getCreatedAt(), - 'createdBy' => $this->doc->getCreatedBy(), + 'title' => $this->doc->title, + 'plain' => $this->doc->plain, + 'content' => $this->doc->content, + 'createdAt' => $this->doc->createdAt, + 'createdBy' => $this->doc->createdBy, ]; self::assertEquals($arr, $this->doc->toArray()); self::assertEquals($arr, $this->doc->jsonSerialize());