commit e084f4cc26e8b11e8eb5a57a7061362d62bd2344 Author: Dennis Eichhorn Date: Tue Feb 19 21:15:06 2019 +0100 Draft tag module diff --git a/Admin/Install/db.json b/Admin/Install/db.json new file mode 100644 index 0000000..4a9d949 --- /dev/null +++ b/Admin/Install/db.json @@ -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 + } + } + } +} \ No newline at end of file diff --git a/Admin/Installer.php b/Admin/Installer.php new file mode 100644 index 0000000..e253aa3 --- /dev/null +++ b/Admin/Installer.php @@ -0,0 +1,29 @@ + [ + [ + '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, + ], + ], + ], +]; diff --git a/Admin/Status.php b/Admin/Status.php new file mode 100644 index 0000000..26b57da --- /dev/null +++ b/Admin/Status.php @@ -0,0 +1,30 @@ + + * + * @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); + } +} diff --git a/Controller/Controller.php b/Controller/Controller.php new file mode 100644 index 0000000..cf1898f --- /dev/null +++ b/Controller/Controller.php @@ -0,0 +1,78 @@ +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(); + } +} diff --git a/Models/TagMapper.php b/Models/TagMapper.php new file mode 100644 index 0000000..634fff0 --- /dev/null +++ b/Models/TagMapper.php @@ -0,0 +1,66 @@ +> + * @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'; +} diff --git a/README.md b/README.md new file mode 100644 index 0000000..ea5b303 --- /dev/null +++ b/README.md @@ -0,0 +1 @@ +# News # diff --git a/Theme/Backend/Lang/en.lang.php b/Theme/Backend/Lang/en.lang.php new file mode 100644 index 0000000..3762365 --- /dev/null +++ b/Theme/Backend/Lang/en.lang.php @@ -0,0 +1,16 @@ + [ + 'Tag' => 'Tag', + 'Tags' => 'Tags', +]]; diff --git a/img/module_teaser_small.png b/img/module_teaser_small.png new file mode 100644 index 0000000..9147e4f Binary files /dev/null and b/img/module_teaser_small.png differ diff --git a/info.json b/info.json new file mode 100644 index 0000000..1dd1062 --- /dev/null +++ b/info.json @@ -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": [ + ] +}