diff --git a/Admin/Install/db.json b/Admin/Install/db.json index aff9092..932b5fd 100644 --- a/Admin/Install/db.json +++ b/Admin/Install/db.json @@ -1,4 +1,22 @@ { + "wiki_app": { + "name": "wiki_app", + "comment": "This allows to create different wikis", + "fields": { + "wiki_app_id": { + "name": "wiki_app_id", + "type": "INT", + "null": false, + "primary": true, + "autoincrement": true + }, + "wiki_app_name": { + "name": "wiki_app_name", + "type": "VARCHAR(255)", + "null": false + } + } + }, "wiki_category": { "name": "wiki_category", "fields": { @@ -14,6 +32,11 @@ "type": "VARCHAR(255)", "null": false }, + "wiki_category_path": { + "name": "wiki_category_path", + "type": "VARCHAR(255)", + "null": false + }, "wiki_category_parent": { "name": "wiki_category_parent", "type": "INT", @@ -21,6 +44,14 @@ "null": true, "foreignTable": "wiki_category", "foreignKey": "wiki_category_id" + }, + "wiki_category_app": { + "name": "wiki_category_app", + "type": "INT", + "default": null, + "null": true, + "foreignTable": "wiki_app", + "foreignKey": "wiki_app_id" } } }, @@ -54,18 +85,6 @@ "type": "TEXT", "null": false }, - "wiki_article_created_at": { - "name": "wiki_article_created_at", - "type": "DATETIME", - "null": false - }, - "wiki_article_created_by": { - "name": "wiki_article_created_by", - "type": "INT", - "null": false, - "foreignTable": "account", - "foreignKey": "account_id" - }, "wiki_article_category": { "name": "wiki_article_category", "type": "INT", @@ -73,6 +92,14 @@ "null": true, "foreignTable": "wiki_category", "foreignKey": "wiki_category_id" + }, + "wiki_article_app": { + "name": "wiki_article_app", + "type": "INT", + "default": null, + "null": true, + "foreignTable": "wiki_app", + "foreignKey": "wiki_app_id" } } } diff --git a/Models/NullWikiApp.php b/Models/NullWikiApp.php new file mode 100644 index 0000000..0ce4330 --- /dev/null +++ b/Models/NullWikiApp.php @@ -0,0 +1,27 @@ +id; + } + + /** + * Set the name. + * + * @param string $name Name of the app + * + * @return void + * + * @since 1.0.0 + */ + public function setName(string $name) : void + { + $this->name = $name; + } + + /** + * Get the app name + * + * @return string + * + * @since 1.0.0 + */ + public function getName() : string + { + return $this->name; + } + + /** + * {@inheritdoc} + */ + public function toArray() : array + { + return [ + 'id' => $this->id, + 'name' => $this->name, + ]; + } + + /** + * {@inheritdoc} + */ + public function jsonSerialize() + { + return $this->toArray(); + } +} diff --git a/Models/WikiAppMapper.php b/Models/WikiAppMapper.php new file mode 100644 index 0000000..d2e1c8d --- /dev/null +++ b/Models/WikiAppMapper.php @@ -0,0 +1,55 @@ + + * @since 1.0.0 + */ + protected static array $columns = [ + 'wiki_app_id' => ['name' => 'wiki_app_id', 'type' => 'int', 'internal' => 'id'], + 'wiki_app_name' => ['name' => 'wiki_app_name', 'type' => 'string', 'internal' => 'name'], + ]; + + /** + * Primary table. + * + * @var string + * @since 1.0.0 + */ + protected static string $table = 'wiki_app'; + + /** + * Primary field name. + * + * @var string + * @since 1.0.0 + */ + protected static string $primaryField = 'wiki_app_id'; +} diff --git a/Models/WikiCategory.php b/Models/WikiCategory.php index 62e5537..f1878cd 100644 --- a/Models/WikiCategory.php +++ b/Models/WikiCategory.php @@ -15,7 +15,7 @@ declare(strict_types=1); namespace Modules\Knowledgebase\Models; /** - * Task class. + * Wiki category class. * * @package Modules\Knowledgebase\Models * @license OMS License 1.0 @@ -32,6 +32,16 @@ class WikiCategory implements \JsonSerializable */ protected int $id = 0; + /** + * App id. + * + * There can be different wikis + * + * @var null|int|WikiApp + * @since 1.0.0 + */ + private $app = null; + /** * Name. * @@ -40,6 +50,19 @@ class WikiCategory implements \JsonSerializable */ private string $name = ''; + /** + * Path. + * + * @var string + * @since 1.0.0 + */ + private string $path = '/'; + + /** + * Parent category. + * + * @var null|int|self + */ private $parent = null; /** @@ -54,6 +77,32 @@ class WikiCategory implements \JsonSerializable return $this->id; } + /** + * Get app + * + * @return null|int|WikiApp + * + * @since 1.0.0 + */ + public function getApp() + { + return $this->app; + } + + /** + * Set app + * + * @param int $app App + * + * @return void + * + * @since 1.0.0 + */ + public function setApp(int $app) : void + { + $this->app = $app; + } + /** * Get name * @@ -81,13 +130,39 @@ class WikiCategory implements \JsonSerializable } /** - * Get parent category + * Get path * - * @return null|int + * @return string * * @since 1.0.0 */ - public function getParent() : ?int + public function getPath() : string + { + return $this->path; + } + + /** + * Set path + * + * @param string $path Path + * + * @return void + * + * @since 1.0.0 + */ + public function setPath(string $path) : void + { + $this->path = $path; + } + + /** + * Get parent category + * + * @return null|int|self + * + * @since 1.0.0 + */ + public function getParent() { return $this->parent; } @@ -109,8 +184,21 @@ class WikiCategory implements \JsonSerializable /** * {@inheritdoc} */ - public function jsonSerialize() : array + public function toArray() : array { - return []; + return [ + 'id' => $this->id, + 'app' => $this->app, + 'name' => $this->name, + 'path' => $this->path, + ]; + } + + /** + * {@inheritdoc} + */ + public function jsonSerialize() + { + return $this->toArray(); } } diff --git a/Models/WikiCategoryMapper.php b/Models/WikiCategoryMapper.php index a14e7d9..a55794e 100644 --- a/Models/WikiCategoryMapper.php +++ b/Models/WikiCategoryMapper.php @@ -34,10 +34,29 @@ final class WikiCategoryMapper extends DataMapperAbstract */ protected static array $columns = [ 'wiki_category_id' => ['name' => 'wiki_category_id', 'type' => 'int', 'internal' => 'id'], + 'wiki_category_app' => ['name' => 'wiki_category_app', 'type' => 'int', 'internal' => 'app'], 'wiki_category_name' => ['name' => 'wiki_category_name', 'type' => 'string', 'internal' => 'name'], + 'wiki_category_path' => ['name' => 'wiki_category_path', 'type' => 'string', 'internal' => 'path'], 'wiki_category_parent' => ['name' => 'wiki_category_parent', 'type' => 'int', 'internal' => 'parent'], ]; + /** + * Has owns one relation. + * + * @var array> + * @since 1.0.0 + */ + protected static array $belongsTo = [ + 'parent' => [ + 'mapper' => WikiCategoryMapper::class, + 'self' => 'wiki_category_parent', + ], + 'app' => [ + 'mapper' => WikiAppMapper::class, + 'self' => 'wiki_category_app' + ], + ]; + /** * Primary table. * diff --git a/Models/WikiDoc.php b/Models/WikiDoc.php index eef4964..42e5d79 100644 --- a/Models/WikiDoc.php +++ b/Models/WikiDoc.php @@ -32,6 +32,16 @@ class WikiDoc implements \JsonSerializable */ protected int $id = 0; + /** + * App id. + * + * There can be different wikis + * + * @var null|int|WikiApp + * @since 1.0.0 + */ + private $app = null; + /** * Name. * @@ -40,29 +50,53 @@ class WikiDoc implements \JsonSerializable */ private string $name = ''; - private int $status = WikiStatus::ACTIVE; - - private $doc = ''; - - private $category = 0; - - private $language = ''; - - private $createdBy = 0; - - private $createdAt = null; - - private $badges = []; - /** - * Constructor. + * Article status. * + * @var int * @since 1.0.0 */ - public function __construct() - { - $this->createdAt = new \DateTime('now'); - } + private int $status = WikiStatus::ACTIVE; + + /** + * Document content. + * + * @var string + * @since 1.0.0 + */ + private string $doc = ''; + + /** + * Document raw content. + * + * @var string + * @since 1.0.0 + */ + private string $docRaw = ''; + + /** + * Category. + * + * @var int|WikiCategory + * @since 1.0.0 + */ + private $category = 0; + + /** + * Language. + * + * @var string + * @since 1.0.0 + */ + private $language = 'en'; + + /** + * Tags. + * + * @var array + * @since 1.0.0 + */ + private $tags = []; /** * Get id. @@ -76,6 +110,32 @@ class WikiDoc implements \JsonSerializable return $this->id; } + /** + * Get app + * + * @return null|int|WikiApp + * + * @since 1.0.0 + */ + public function getApp() + { + return $this->app; + } + + /** + * Set app + * + * @param int $app App + * + * @return void + * + * @since 1.0.0 + */ + public function setApp(int $app) : void + { + $this->app = $app; + } + /** * Get language * @@ -154,6 +214,32 @@ class WikiDoc implements \JsonSerializable $this->doc = $doc; } + /** + * Get content + * + * @return string + * + * @since 1.0.0 + */ + public function getDocRaw() : string + { + return $this->docRaw; + } + + /** + * Set content + * + * @param string $doc Document content + * + * @return void + * + * @since 1.0.0 + */ + public function setDocRaw(string $doc) : void + { + $this->docRaw = $doc; + } + /** * Get status * @@ -207,67 +293,29 @@ class WikiDoc implements \JsonSerializable } /** - * Get created by - * - * @return int|\phpOMS\Account\Account - * - * @since 1.0.0 - */ - public function getCreatedBy() : int - { - return $this->createdBy; - } - - /** - * Set created by - * - * @param mixed $id Created by - * - * @return void - * - * @since 1.0.0 - */ - public function setCreatedBy($id) : void - { - $this->createdBy = $id; - } - - /** - * Get created at date time - * - * @return \DateTime - * - * @since 1.0.0 - */ - public function getCreatedAt() : \DateTime - { - return $this->createdAt; - } - - /** - * Get badges + * Get tags * * @return array * * @since 1.0.0 */ - public function getBadges() : array + public function getTags() : array { - return $this->badges; + return $this->tags; } /** - * Add badge + * Add tag * - * @param mixed $badge Badge + * @param mixed $tag Tag * * @return void * * @since 1.0.0 */ - public function addBadge($badge) : void + public function addTag($tag) : void { - $this->badges[] = $badge; + $this->tags[] = $tag; } /** diff --git a/Models/WikiDocMapper.php b/Models/WikiDocMapper.php index 0c99864..ae24b83 100644 --- a/Models/WikiDocMapper.php +++ b/Models/WikiDocMapper.php @@ -33,14 +33,13 @@ final class WikiDocMapper extends DataMapperAbstract * @since 1.0.0 */ protected static array $columns = [ - 'wiki_article_id' => ['name' => 'wiki_article_id', 'type' => 'int', 'internal' => 'id'], - 'wiki_article_title' => ['name' => 'wiki_article_title', 'type' => 'string', 'internal' => 'name'], - 'wiki_article_language' => ['name' => 'wiki_article_language', 'type' => 'string', 'internal' => 'language'], - 'wiki_article_doc' => ['name' => 'wiki_article_doc', 'type' => 'string', 'internal' => 'doc'], - 'wiki_article_status' => ['name' => 'wiki_article_status', 'type' => 'int', 'internal' => 'status'], - 'wiki_article_category' => ['name' => 'wiki_article_category', 'type' => 'int', 'internal' => 'category'], - 'wiki_article_created_by' => ['name' => 'wiki_article_created_by', 'type' => 'int', 'internal' => 'createdBy'], - 'wiki_article_created_at' => ['name' => 'wiki_article_created_at', 'type' => 'DateTime', 'internal' => 'createdAt', 'readonly' => true], + 'wiki_article_id' => ['name' => 'wiki_article_id', 'type' => 'int', 'internal' => 'id'], + 'wiki_article_app' => ['name' => 'wiki_article_app', 'type' => 'int', 'internal' => 'app'], + 'wiki_article_title' => ['name' => 'wiki_article_title', 'type' => 'string', 'internal' => 'name'], + 'wiki_article_language' => ['name' => 'wiki_article_language', 'type' => 'string', 'internal' => 'language'], + 'wiki_article_doc' => ['name' => 'wiki_article_doc', 'type' => 'string', 'internal' => 'doc'], + 'wiki_article_status' => ['name' => 'wiki_article_status', 'type' => 'int', 'internal' => 'status'], + 'wiki_article_category' => ['name' => 'wiki_article_category', 'type' => 'int', 'internal' => 'category'], ]; /** @@ -65,10 +64,14 @@ final class WikiDocMapper extends DataMapperAbstract * @var array> * @since 1.0.0 */ - protected static array $ownsOne = [ + protected static array $belongsTo = [ 'category' => [ 'mapper' => WikiCategoryMapper::class, - 'external' => 'wiki_article_category', + 'self' => 'wiki_article_category', + ], + 'app' => [ + 'mapper' => WikiAppMapper::class, + 'self' => 'wiki_article_app' ], ]; @@ -80,14 +83,6 @@ final class WikiDocMapper extends DataMapperAbstract */ protected static string $table = 'wiki_article'; - /** - * Created at. - * - * @var string - * @since 1.0.0 - */ - protected static string $createdAt = 'wiki_article_created_at'; - /** * Primary field name. *