start working on knowledgebase

This commit is contained in:
Dennis Eichhorn 2020-02-22 15:28:55 +01:00
parent bdf5b8b59f
commit 1ea1f65dca
8 changed files with 458 additions and 100 deletions

View File

@ -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"
}
}
}

27
Models/NullWikiApp.php Normal file
View File

@ -0,0 +1,27 @@
<?php
/**
* Orange Management
*
* PHP Version 7.4
*
* @package Modules\Knowledgebase\Models
* @copyright Dennis Eichhorn
* @license OMS License 1.0
* @version 1.0.0
* @link https://orange-management.org
*/
declare(strict_types=1);
namespace Modules\Knowledgebase\Models;
/**
* Task class.
*
* @package Modules\Knowledgebase\Models
* @license OMS License 1.0
* @link https://orange-management.org
* @since 1.0.0
*/
final class NullWikiApp extends WikiApp
{
}

99
Models/WikiApp.php Normal file
View File

@ -0,0 +1,99 @@
<?php
/**
* Orange Management
*
* PHP Version 7.4
*
* @package Modules\Knowledgebase\Models
* @copyright Dennis Eichhorn
* @license OMS License 1.0
* @version 1.0.0
* @link https://orange-management.org
*/
declare(strict_types=1);
namespace Modules\Knowledgebase\Models;
/**
* Wiki app class.
*
* @package Modules\Knowledgebase\Models
* @license OMS License 1.0
* @link https://orange-management.org
* @since 1.0.0
*/
class WikiApp implements \JsonSerializable
{
/**
* ID.
*
* @var int
* @since 1.0.0
*/
protected int $id = 0;
/**
* Application name.
*
* @var string
* @since 1.0.0
*/
protected string $name = '';
/**
* Get id.
*
* @return int Model id
*
* @since 1.0.0
*/
public function getId() : int
{
return $this->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();
}
}

55
Models/WikiAppMapper.php Normal file
View File

@ -0,0 +1,55 @@
<?php
/**
* Orange Management
*
* PHP Version 7.4
*
* @package Modules\Knowledgebase\Models
* @copyright Dennis Eichhorn
* @license OMS License 1.0
* @version 1.0.0
* @link https://orange-management.org
*/
declare(strict_types=1);
namespace Modules\Knowledgebase\Models;
use phpOMS\DataStorage\Database\DataMapperAbstract;
/**
* Mapper class.
*
* @package Modules\Knowledgebase\Models
* @license OMS License 1.0
* @link https://orange-management.org
* @since 1.0.0
*/
final class WikiAppMapper extends DataMapperAbstract
{
/**
* Columns.
*
* @var array<string, array{name:string, type:string, internal:string, autocomplete?:bool, readonly?:bool, writeonly?:bool, annotations?:array}>
* @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';
}

View File

@ -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();
}
}

View File

@ -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<string, array<string, null|string>>
* @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.
*

View File

@ -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;
}
/**

View File

@ -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<string, array<string, null|string>>
* @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.
*