Draft tag module

This commit is contained in:
Dennis Eichhorn 2019-02-19 21:15:06 +01:00
commit e084f4cc26
17 changed files with 805 additions and 0 deletions

24
Admin/Install/db.json Normal file
View File

@ -0,0 +1,24 @@
{
"tag": {
"name": "tag",
"fields": {
"tag_id": {
"name": "tag_id",
"type": "INT",
"null": false,
"primary": true,
"autoincrement": true
},
"tag_title": {
"name": "tag_title",
"type": "VARCHAR(255)",
"null": false
},
"tag_color": {
"name": "tag_color",
"type": "VARCHAR(8)",
"null": false
}
}
}
}

29
Admin/Installer.php Normal file
View File

@ -0,0 +1,29 @@
<?php
/**
* Orange Management
*
* PHP Version 7.2
*
* @package Modules\Tag\Admin
* @copyright Dennis Eichhorn
* @license OMS License 1.0
* @version 1.0.0
* @link http://website.orange-management.de
*/
declare(strict_types=1);
namespace Modules\Tag\Admin;
use phpOMS\Module\InstallerAbstract;
/**
* Installer class.
*
* @package Modules\Tag\Admin
* @license OMS License 1.0
* @link http://website.orange-management.de
* @since 1.0.0
*/
class Installer extends InstallerAbstract
{
}

38
Admin/Routes/Web/Api.php Normal file
View File

@ -0,0 +1,38 @@
<?php
use Modules\Tag\Controller\ApiController;
use Modules\Tag\Models\PermissionState;
use phpOMS\Account\PermissionType;
use phpOMS\Router\RouteVerb;
return [
'^.*/api/tag.*$' => [
[
'dest' => '\Modules\Tag\Controller\ApiController:apiTagCreate',
'verb' => RouteVerb::PUT,
'permission' => [
'module' => ApiController::MODULE_NAME,
'type' => PermissionType::CREATE,
'state' => PermissionState::TAG,
],
],
[
'dest' => '\Modules\Tag\Controller\ApiController:apiTagUpdate',
'verb' => RouteVerb::SET,
'permission' => [
'module' => ApiController::MODULE_NAME,
'type' => PermissionType::MODIFY,
'state' => PermissionState::Tag,
],
],
[
'dest' => '\Modules\Tag\Controller\ApiController:apiTagDelete',
'verb' => RouteVerb::DELETE,
'permission' => [
'module' => ApiController::MODULE_NAME,
'type' => PermissionType::DELETE,
'state' => PermissionState::TAG,
],
],
],
];

30
Admin/Status.php Normal file
View File

@ -0,0 +1,30 @@
<?php
/**
* Orange Management
*
* PHP Version 7.2
*
* @package Modules\Tag\Admin
* @copyright Dennis Eichhorn
* @license OMS License 1.0
* @version 1.0.0
* @link http://website.orange-management.de
*/
declare(strict_types=1);
namespace Modules\Tag\Admin;
use phpOMS\Module\StatusAbstract;
/**
* Navigation class.
*
* @package Modules\Tag\Admin
* @license OMS License 1.0
* @link http://website.orange-management.de
* @since 1.0.0
*/
class Status extends StatusAbstract
{
}

29
Admin/Uninstaller.php Normal file
View File

@ -0,0 +1,29 @@
<?php
/**
* Orange Management
*
* PHP Version 7.2
*
* @package Modules\Tag\Admin
* @copyright Dennis Eichhorn
* @license OMS License 1.0
* @version 1.0.0
* @link http://website.orange-management.de
*/
declare(strict_types=1);
namespace Modules\Tag\Admin;
use phpOMS\Module\UninstallerAbstract;
/**
* Uninstaller class.
*
* @package Modules\Tag\Admin
* @license OMS License 1.0
* @link http://website.orange-management.de
* @since 1.0.0
*/
class Uninstaller extends UninstallerAbstract
{
}

30
Admin/Updater.php Normal file
View File

@ -0,0 +1,30 @@
<?php
/**
* Orange Management
*
* PHP Version 7.2
*
* @package Modules\Tag\Admin
* @copyright Dennis Eichhorn
* @license OMS License 1.0
* @version 1.0.0
* @link http://website.orange-management.de
*/
declare(strict_types=1);
namespace Modules\Tag\Admin;
use phpOMS\Module\UpdaterAbstract;
/**
* Updater class.
*
* @package Modules\Tag\Admin
* @license OMS License 1.0
* @link http://website.orange-management.de
* @since 1.0.0
*/
class Updater extends UpdaterAbstract
{
}

View File

@ -0,0 +1,176 @@
<?php
/**
* Orange Management
*
* PHP Version 7.2
*
* @package Modules\Tag
* @copyright Dennis Eichhorn
* @license OMS License 1.0
* @version 1.0.0
* @link http://website.orange-management.de
*/
declare(strict_types=1);
namespace Modules\Tag\Controller;
use Modules\Tag\Models\Tag;
use phpOMS\Message\NotificationLevel;
use phpOMS\Message\RequestAbstract;
use phpOMS\Message\ResponseAbstract;
use phpOMS\Model\Message\FormValidation;
/**
* Tag controller class.
*
* @package Modules\Tag
* @license OMS License 1.0
* @link http://website.orange-management.de
* @since 1.0.0
*/
final class ApiController extends Controller
{
/**
* Validate tag create request
*
* @param RequestAbstract $request Request
*
* @return array<string, bool>
*
* @since 1.0.0
*/
private function validateTagCreate(RequestAbstract $request) : array
{
$val = [];
if (($val['title'] = empty($request->getData('title')))
|| ($val['color'] = (!empty($request->getData('color')) && !\ctype_xdigit($request->getData('color'))))
) {
return $val;
}
return [];
}
/**
* Api method to create tag
*
* @param RequestAbstract $request Request
* @param ResponseAbstract $response Response
* @param mixed $data Generic data
*
* @return void
*
* @api
*
* @since 1.0.0
*/
public function apiTagUpdate(RequestAbstract $request, ResponseAbstract $response, $data = null) : void
{
$old = clone TagMapper::get((int) $request->getData('id'));
$new = $this->updateTagFromRequest($request);
$this->updateModel($request, $old, $new, TagMapper::class, 'tag');
$this->fillJsonResponse($request, $response, NotificationLevel::OK, 'Tag', 'Tag successfully updated', $new);
}
/**
* Method to update tag from request.
*
* @param RequestAbstract $request Request
*
* @return Tag
*
* @since 1.0.0
*/
private function updateTagFromRequest(RequestAbstract $request) : Tag
{
$tag = TagMapper::get((int) $request->getData('id'));
$tag->setTitle((string) ($request->getData('title') ?? $tag->getTitle()));
$tag->setColor($request->getData('color') ?? $tag->getColor());
return $tag;
}
/**
* Api method to create tag
*
* @param RequestAbstract $request Request
* @param ResponseAbstract $response Response
* @param mixed $data Generic data
*
* @return void
*
* @api
*
* @since 1.0.0
*/
public function apiTagCreate(RequestAbstract $request, ResponseAbstract $response, $data = null) : void
{
if (!empty($val = $this->validateTagCreate($request))) {
$response->set('tag_create', new FormValidation($val));
return;
}
$tag = $this->createTagFromRequest($request);
$this->createModel($request, $tag, TagMapper::class, 'tag');
$this->fillJsonResponse($request, $response, NotificationLevel::OK, 'Tag', 'Tag successfully created', $tag);
}
/**
* Method to create tag from request.
*
* @param RequestAbstract $request Request
*
* @return Tag
*
* @since 1.0.0
*/
private function createTagFromRequest(RequestAbstract $request) : Tag
{
$tag = new Tag();
$tag->setTitle((string) ($request->getData('title') ?? ''));
$tag->setColor($request->getData('color') ?? '00000000');
return $tag;
}
/**
* Api method to get a tag
*
* @param RequestAbstract $request Request
* @param ResponseAbstract $response Response
* @param mixed $data Generic data
*
* @return void
*
* @api
*
* @since 1.0.0
*/
public function apiTagGet(RequestAbstract $request, ResponseAbstract $response, $data = null) : void
{
$tag = TagMapper::get((int) $request->getData('id'));
$this->fillJsonResponse($request, $response, NotificationLevel::OK, 'Tag', 'Tag successfully returned', $tag);
}
/**
* Api method to delete tag
*
* @param RequestAbstract $request Request
* @param ResponseAbstract $response Response
* @param mixed $data Generic data
*
* @return void
*
* @api
*
* @since 1.0.0
*/
public function apiTagDelete(RequestAbstract $request, ResponseAbstract $response, $data = null) : void
{
$tag = TagMapper::get((int) $request->getData('id'));
$this->deleteModel($request, $tag, TagMapper::class, 'tag');
$this->fillJsonResponse($request, $response, NotificationLevel::OK, 'Tag', 'Tag successfully deleted', $tag);
}
}

78
Controller/Controller.php Normal file
View File

@ -0,0 +1,78 @@
<?php
/**
* Orange Management
*
* PHP Version 7.2
*
* @package Modules\Tag
* @copyright Dennis Eichhorn
* @license OMS License 1.0
* @version 1.0.0
* @link http://website.orange-management.de
*/
declare(strict_types=1);
namespace Modules\Tag\Controller;
use phpOMS\Module\ModuleAbstract;
use phpOMS\Module\WebInterface;
/**
* Tag controller class.
*
* @package Modules\Tag
* @license OMS License 1.0
* @link http://website.orange-management.de
* @since 1.0.0
*/
class Controller extends ModuleAbstract implements WebInterface
{
/**
* Module path.
*
* @var string
* @since 1.0.0
*/
public const MODULE_PATH = __DIR__ . '/../';
/**
* Module version.
*
* @var string
* @since 1.0.0
*/
public const MODULE_VERSION = '1.0.0';
/**
* Module name.
*
* @var string
* @since 1.0.0
*/
public const MODULE_NAME = 'Tag';
/**
* Module id.
*
* @var int
* @since 1.0.0
*/
public const MODULE_ID = 1007500000;
/**
* Providing.
*
* @var string[]
* @since 1.0.0
*/
protected static $providing = [];
/**
* Dependencies.
*
* @var string[]
* @since 1.0.0
*/
protected static $dependencies = [];
}

58
Docs/introduction.md Normal file
View File

@ -0,0 +1,58 @@
# Introduction
The **News** module can create articles, headlines and links which can be shown in the intranet, website, blog etc.
## Target Group
The target groups for this module are intranet users that want to inform other people about changes or news. The module can also be used for websites or blogs in order to write and show articles to visitors/customers.
# Setup
The module can be installed through the integrated module downloader and installer or by uploading the module into the `Modules/` directory and executing the installation through the module installer.
The module is depending on the **Editor** module which provides most of the writing features.
# Features
## Timed Release
Articles can be written in advanced and stored as a draft for further adjustments. In case an article should be released at a specific date/time this can also be configured.
## Permissions & Groups
By assigning permissions and groups to articles it's possible to only make them visible to intended audiences and different pages (e.g. intranet, website, blog etc.).
## Localization
News articles can get assigned to a language upon which it will be visible only to those who have the same language configuration. This allows organizations to target news articles not only by groups and permissions but also by localization.
## Markdown
The module makes use of an extended markdown version for easy writing and modifications.
### Extendability
Modules can provide custom elements which allows them to provide elemnts that normal markdown doesn't support. Some modules that already provide custom elements for articles:
* Media
* Charts
* Spreadsheets
* Calendar/Events
* Tasks
* Checklists
* Profiles/Contacts
## Version Control
Articles can be version controlled which enables to easily see changes made by collaborators.
## Comments
One important module that is not required but can be used for better user interaction is the **Comments** module. This module allows to create comments to articles if enabled.
# Recommendation
Other modules that work great with this one together are:
* [Editor](Editor)
* [Comments](Comments)

27
Models/NullTag.php Normal file
View File

@ -0,0 +1,27 @@
<?php
/**
* Orange Management
*
* PHP Version 7.2
*
* @package Modules\Tag
* @copyright Dennis Eichhorn
* @license OMS License 1.0
* @version 1.0.0
* @link http://website.orange-management.de
*/
declare(strict_types=1);
namespace Modules\Tag\Models;
/**
* Null model
*
* @package Modules\Tag
* @license OMS License 1.0
* @link http://website.orange-management.de
* @since 1.0.0
*/
class NullTag extends Tag
{
}

View File

@ -0,0 +1,30 @@
<?php
/**
* Orange Management
*
* PHP Version 7.2
*
* @package Modules\Tag\Models
* @copyright Dennis Eichhorn
* @license OMS License 1.0
* @version 1.0.0
* @link http://website.orange-management.de
*/
declare(strict_types=1);
namespace Modules\Tag\Models;
use phpOMS\Stdlib\Base\Enum;
/**
* Permision state enum.
*
* @package Modules\Tag\Models
* @license OMS License 1.0
* @link http://website.orange-management.de
* @since 1.0.0
*/
abstract class PermissionState extends Enum
{
public const TAG = 1;
}

145
Models/Tag.php Normal file
View File

@ -0,0 +1,145 @@
<?php
/**
* Orange Management
*
* PHP Version 7.2
*
* @package Modules\Tag\Models
* @copyright Dennis Eichhorn
* @license OMS License 1.0
* @version 1.0.0
* @link http://website.orange-management.de
*/
declare(strict_types=1);
namespace Modules\Tag\Models;
use phpOMS\Contract\ArrayableInterface;
use phpOMS\Localization\ISO639x1Enum;
use phpOMS\Stdlib\Base\Exception\InvalidEnumValue;
/**
* Tag article class.
*
* @package Modules\Tag\Models
* @license OMS License 1.0
* @link http://website.orange-management.de
* @since 1.0.0
*/
class Tag implements ArrayableInterface, \JsonSerializable
{
/**
* Article ID.
*
* @var int
* @since 1.0.0
*/
private $id = 0;
/**
* Title.
*
* @var string
* @since 1.0.0
*/
private $title = '';
/**
* Color RGBA.
*
* @var string
* @since 1.0.0
*/
private $color = '000000';
/**
* Get color
*
* @return string
*
* @since 1.0.0
*/
public function getColor() : string
{
return $this->color;
}
/**
* Set color
*
* @param string $color Tag article color
*
* @return void
*
* @since 1.0.0
*/
public function setColor(string $color) : void
{
$this->color = $color;
}
/**
* Get id
*
* @return int
*
* @since 1.0.0
*/
public function getId() : int
{
return $this->id;
}
/**
* @return string
*
* @since 1.0.0
*/
public function getTitle() : string
{
return $this->title;
}
/**
* Set title
*
* @param string $title Tag article title
*
* @return void
*
* @since 1.0.0
*/
public function setTitle(string $title) : void
{
$this->title = $title;
}
/**
* {@inheritdoc}
*/
public function toArray() : array
{
return [
'id' => $this->id,
'title' => $this->title,
'color' => $this->color,
];
}
/**
* {@inheritdoc}
*/
public function __toString()
{
return (string) \json_encode($this->toArray());
}
/**
* {@inheritdoc}
*/
public function jsonSerialize()
{
return $this->toArray();
}
}

66
Models/TagMapper.php Normal file
View File

@ -0,0 +1,66 @@
<?php
/**
* Orange Management
*
* PHP Version 7.2
*
* @package Modules\Tag
* @copyright Dennis Eichhorn
* @license OMS License 1.0
* @version 1.0.0
* @link http://website.orange-management.de
*/
declare(strict_types=1);
namespace Modules\Tag\Models;
use Modules\Admin\Models\AccountMapper;
use phpOMS\DataStorage\Database\DataMapperAbstract;
/**
* Tag mapper class.
*
* @package Modules\Tag
* @license OMS License 1.0
* @link http://website.orange-management.de
* @since 1.0.0
*/
final class TagMapper extends DataMapperAbstract
{
/**
* Columns.
*
* @var array<string, array<string, bool|string>>
* @since 1.0.0
*/
protected static $columns = [
'tag_id' => ['name' => 'tag_id', 'type' => 'int', 'internal' => 'id'],
'tag_title' => ['name' => 'tag_title', 'type' => 'string', 'internal' => 'title'],
'tag_color' => ['name' => 'tag_color', 'type' => 'string', 'internal' => 'color'],
];
/**
* Primary table.
*
* @var string
* @since 1.0.0
*/
protected static $table = 'tag';
/**
* Primary field name.
*
* @var string
* @since 1.0.0
*/
protected static $primaryField = 'tag_id';
/**
* Created at.
*
* @var string
* @since 1.0.0
*/
protected static $createdAt = 'tag_created_at';
}

1
README.md Normal file
View File

@ -0,0 +1 @@
# News #

View File

@ -0,0 +1,16 @@
<?php
/**
* Orange Management
*
* PHP Version 7.2
*
* @package TBD
* @copyright Dennis Eichhorn
* @license OMS License 1.0
* @version 1.0.0
* @link http://website.orange-management.de
*/
return ['Tag' => [
'Tag' => 'Tag',
'Tags' => 'Tags',
]];

BIN
img/module_teaser_small.png Normal file

Binary file not shown.

28
info.json Normal file
View File

@ -0,0 +1,28 @@
{
"name": {
"id": 1007500000,
"internal": "Tag",
"external": "Tag"
},
"category": "Content",
"version": "1.0.0",
"requirements": {
"phpOMS": "1.0.0",
"phpOMS-db": "1.0.0"
},
"creator": {
"name": "Orange Management",
"website": "www.spl1nes.com"
},
"description": "Tag module.",
"directory": "News",
"dependencies": {
"Admin": "1.0.0",
"Home": "1.0.0"
},
"providing": {
"Navigation": "*"
},
"load": [
]
}