From 59a0ea27c51bdbefc4a53e7e45220399b73ed9c6 Mon Sep 17 00:00:00 2001 From: Dennis Eichhorn Date: Mon, 20 Mar 2017 21:23:14 +0100 Subject: [PATCH] QA module draft --- Admin/Activate.php | 44 ++++++ Admin/Deactivate.php | 44 ++++++ Admin/Install/Navigation.install.json | 18 +++ Admin/Install/Navigation.php | 41 +++++ Admin/Installer.php | 131 ++++++++++++++++ Admin/Routes/Web/Backend.php | 30 ++++ Admin/Uninstall.php | 45 ++++++ Admin/Update.php | 47 ++++++ Controller.php | 80 ++++++++++ Models/QAAnswer.php | 102 ++++++++++++ Models/QAAnswerMapper.php | 143 +++++++++++++++++ Models/QABadge.php | 59 +++++++ Models/QABadgeMapper.php | 111 ++++++++++++++ Models/QACategory.php | 71 +++++++++ Models/QACategoryMapper.php | 112 ++++++++++++++ Models/QAQuestion.php | 151 ++++++++++++++++++ Models/QAQuestionMapper.php | 179 ++++++++++++++++++++++ Models/QAStatus.php | 41 +++++ Theme/Backend/Lang/Navigation.en.lang.php | 18 +++ Theme/Backend/Lang/en.lang.php | 18 +++ Theme/Backend/qa-dashboard.tpl.php | 0 info.json | 47 ++++++ 22 files changed, 1532 insertions(+) create mode 100644 Admin/Activate.php create mode 100644 Admin/Deactivate.php create mode 100644 Admin/Install/Navigation.install.json create mode 100644 Admin/Install/Navigation.php create mode 100644 Admin/Installer.php create mode 100644 Admin/Routes/Web/Backend.php create mode 100644 Admin/Uninstall.php create mode 100644 Admin/Update.php create mode 100644 Controller.php create mode 100644 Models/QAAnswer.php create mode 100644 Models/QAAnswerMapper.php create mode 100644 Models/QABadge.php create mode 100644 Models/QABadgeMapper.php create mode 100644 Models/QACategory.php create mode 100644 Models/QACategoryMapper.php create mode 100644 Models/QAQuestion.php create mode 100644 Models/QAQuestionMapper.php create mode 100644 Models/QAStatus.php create mode 100644 Theme/Backend/Lang/Navigation.en.lang.php create mode 100644 Theme/Backend/Lang/en.lang.php create mode 100644 Theme/Backend/qa-dashboard.tpl.php create mode 100644 info.json diff --git a/Admin/Activate.php b/Admin/Activate.php new file mode 100644 index 0000000..41cf2ba --- /dev/null +++ b/Admin/Activate.php @@ -0,0 +1,44 @@ + + * @author Dennis Eichhorn + * @copyright Dennis Eichhorn + * @license OMS License 1.0 + * @version 1.0.0 + * @link http://orange-management.com + */ +declare(strict_types=1); +namespace Modules\QA\Admin; + +use phpOMS\DataStorage\Database\DatabasePool; +use phpOMS\Module\ActivateAbstract; +use phpOMS\Module\InfoManager; + +/** + * Navigation class. + * + * @category Modules + * @package Modules\Admin + * @author OMS Development Team + * @author Dennis Eichhorn + * @license OMS License 1.0 + * @link http://orange-management.com + * @since 1.0.0 + */ +class Activate extends ActivateAbstract +{ + + /** + * {@inheritdoc} + */ + public static function activate(DatabasePool $dbPool, InfoManager $info) + { + parent::activate($dbPool, $info); + } +} diff --git a/Admin/Deactivate.php b/Admin/Deactivate.php new file mode 100644 index 0000000..1b638b0 --- /dev/null +++ b/Admin/Deactivate.php @@ -0,0 +1,44 @@ + + * @author Dennis Eichhorn + * @copyright Dennis Eichhorn + * @license OMS License 1.0 + * @version 1.0.0 + * @link http://orange-management.com + */ +declare(strict_types=1); +namespace Modules\QA\Admin; + +use phpOMS\DataStorage\Database\DatabasePool; +use phpOMS\Module\DeactivateAbstract; +use phpOMS\Module\InfoManager; + +/** + * Navigation class. + * + * @category Modules + * @package Modules\Admin + * @author OMS Development Team + * @author Dennis Eichhorn + * @license OMS License 1.0 + * @link http://orange-management.com + * @since 1.0.0 + */ +class Deactivate extends DeactivateAbstract +{ + + /** + * {@inheritdoc} + */ + public static function deactivate(DatabasePool $dbPool, InfoManager $info) + { + parent::deactivate($dbPool, $info); + } +} diff --git a/Admin/Install/Navigation.install.json b/Admin/Install/Navigation.install.json new file mode 100644 index 0000000..160d818 --- /dev/null +++ b/Admin/Install/Navigation.install.json @@ -0,0 +1,18 @@ +[ + { + "id": 1006001001, + "pid": "754a08ddf8bcb1cf22f310f09206dd783d42f7dd", + "type": 2, + "subtype": 1, + "name": "QA", + "uri": "/{/lang}/backend/qa/dashboard?{?}", + "target": "self", + "icon": null, + "order": 50, + "from": "QA", + "permission": null, + "parent": 1003301001, + "children": [ + ] + } +] diff --git a/Admin/Install/Navigation.php b/Admin/Install/Navigation.php new file mode 100644 index 0000000..b6200a1 --- /dev/null +++ b/Admin/Install/Navigation.php @@ -0,0 +1,41 @@ + + * @author Dennis Eichhorn + * @copyright Dennis Eichhorn + * @license OMS License 1.0 + * @version 1.0.0 + * @link http://orange-management.com + */ +declare(strict_types=1); +namespace Modules\QA\Admin\Install; +use phpOMS\DataStorage\Database\DatabasePool; + +/** + * Navigation class. + * + * @category Modules + * @package Modules\Kanban + * @author OMS Development Team + * @author Dennis Eichhorn + * @license OMS License 1.0 + * @link http://orange-management.com + * @since 1.0.0 + */ +class Navigation +{ + public static function install(string $path, DatabasePool $dbPool) + { + $navData = json_decode(file_get_contents(__DIR__ . '/Navigation.install.json'), true); + + $class = '\\Modules\\Navigation\\Admin\\Installer'; + /** @var $class \Modules\Navigation\Admin\Installer */ + $class::installExternal($dbPool, $navData); + } +} diff --git a/Admin/Installer.php b/Admin/Installer.php new file mode 100644 index 0000000..b041946 --- /dev/null +++ b/Admin/Installer.php @@ -0,0 +1,131 @@ + + * @author Dennis Eichhorn + * @copyright Dennis Eichhorn + * @license OMS License 1.0 + * @version 1.0.0 + * @link http://orange-management.com + */ +declare(strict_types=1); +namespace Modules\QA\Admin; + +use phpOMS\DataStorage\Database\DatabaseType; +use phpOMS\DataStorage\Database\DatabasePool; +use phpOMS\Module\InfoManager; +use phpOMS\Module\InstallerAbstract; + +/** + * Tasks install class. + * + * @category Modules + * @package Modules\Tasks + * @author OMS Development Team + * @author Dennis Eichhorn + * @license OMS License 1.0 + * @link http://orange-management.com + * @since 1.0.0 + */ +class Installer extends InstallerAbstract +{ + + /** + * {@inheritdoc} + */ + public static function install(string $path, DatabasePool $dbPool, InfoManager $info) + { + parent::install($path, $dbPool, $info); + + switch ($dbPool->get('core')->getType()) { + case DatabaseType::MYSQL: + $dbPool->get('core')->con->prepare( + 'CREATE TABLE if NOT EXISTS `' . $dbPool->get('core')->prefix . 'qa_category` ( + `qa_category_id` int(11) NOT NULL AUTO_INCREMENT, + `qa_category_name` varchar(255) NOT NULL, + `qa_category_parent` int(11) DEFAULT NULL, + PRIMARY KEY (`qa_category_id`), + KEY `qa_category_parent` (`qa_category_parent`) + )ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=1;' + )->execute(); + + $dbPool->get('core')->con->prepare( + 'ALTER TABLE `' . $dbPool->get('core')->prefix . 'qa_category` + ADD CONSTRAINT `' . $dbPool->get('core')->prefix . 'qa_category_ibfk_1` FOREIGN KEY (`qa_category_parent`) REFERENCES `' . $dbPool->get('core')->prefix . 'qa_category` (`qa_category_id`)' + )->execute(); + + $dbPool->get('core')->con->prepare( + 'CREATE TABLE if NOT EXISTS `' . $dbPool->get('core')->prefix . 'qa_badge` ( + `qa_badge_id` int(11) NOT NULL AUTO_INCREMENT, + `qa_badge_name` varchar(255) NOT NULL, + PRIMARY KEY (`qa_category_id`) + )ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=1;' + )->execute(); + + $dbPool->get('core')->con->prepare( + 'CREATE TABLE if NOT EXISTS `' . $dbPool->get('core')->prefix . 'qa_question` ( + `qa_question_id` int(11) NOT NULL AUTO_INCREMENT, + `qa_question_status` int(11) NOT NULL, + `qa_question_title` varchar(255) NOT NULL, + `qa_question_language` varchar(3) NOT NULL, + `qa_question_question` text NOT NULL, + `qa_question_created_by` int(11) NOT NULL, + `qa_question_created_at` datetime NOT NULL, + `qa_question_category` int(11) DEFAULT NULL, + PRIMARY KEY (`qa_question_id`), + KEY `qa_question_created_by` (`qa_question_created_by`), + KEY `qa_question_category` (`qa_question_category`) + )ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=1;' + )->execute(); + + $dbPool->get('core')->con->prepare( + 'ALTER TABLE `' . $dbPool->get('core')->prefix . 'qa_question` + ADD CONSTRAINT `' . $dbPool->get('core')->prefix . 'qa_question_ibfk_1` FOREIGN KEY (`qa_question_created_by`) REFERENCES `' . $dbPool->get('core')->prefix . 'account` (`account_id`), + ADD CONSTRAINT `' . $dbPool->get('core')->prefix . 'qa_question_ibfk_2` FOREIGN KEY (`qa_question_category`) REFERENCES `' . $dbPool->get('core')->prefix . 'qa_category` (`qa_category_id`);' + )->execute(); + + $dbPool->get('core')->con->prepare( + 'CREATE TABLE if NOT EXISTS `' . $dbPool->get('core')->prefix . 'qa_question_badge` ( + `qa_question_badge_id` int(11) NOT NULL AUTO_INCREMENT, + `qa_question_badge_question` varchar(255) NOT NULL, + `qa_question_badge_badge` int(11) DEFAULT NULL, + PRIMARY KEY (`qa_category_id`), + KEY `qa_question_badge_question` (`qa_question_badge_question`), + KEY `qa_question_badge_badge` (`qa_question_badge_badge`) + )ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=1;' + )->execute(); + + $dbPool->get('core')->con->prepare( + 'ALTER TABLE `' . $dbPool->get('core')->prefix . 'qa_question_badge` + ADD CONSTRAINT `' . $dbPool->get('core')->prefix . 'qa_question_badge_ibfk_1` FOREIGN KEY (`qa_question_badge_question`) REFERENCES `' . $dbPool->get('core')->prefix . 'qa_question` (`qa_question_id`), + ADD CONSTRAINT `' . $dbPool->get('core')->prefix . 'qa_question_badge_ibfk_2` FOREIGN KEY (`qa_question_badge_badge`) REFERENCES `' . $dbPool->get('core')->prefix . 'qa_badge` (`qa_badge_id`)' + )->execute(); + + $dbPool->get('core')->con->prepare( + 'CREATE TABLE if NOT EXISTS `' . $dbPool->get('core')->prefix . 'qa_answer` ( + `qa_answer_id` int(11) NOT NULL AUTO_INCREMENT, + `qa_answer_status` int(11) NOT NULL, + `qa_answer_answer` text NOT NULL, + `qa_answer_created_by` int(11) NOT NULL, + `qa_answer_created_at` datetime NOT NULL, + `qa_answer_question` int(11) DEFAULT NULL, + PRIMARY KEY (`qa_answer_id`), + KEY `qa_answer_created_by` (`qa_answer_created_by`), + KEY `qa_answer_question` (`qa_answer_question`) + )ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=1;' + )->execute(); + + $dbPool->get('core')->con->prepare( + 'ALTER TABLE `' . $dbPool->get('core')->prefix . 'qa_answer` + ADD CONSTRAINT `' . $dbPool->get('core')->prefix . 'qa_answer_ibfk_1` FOREIGN KEY (`qa_answer_created_by`) REFERENCES `' . $dbPool->get('core')->prefix . 'account` (`account_id`), + ADD CONSTRAINT `' . $dbPool->get('core')->prefix . 'qa_answer_ibfk_2` FOREIGN KEY (`qa_answer_question`) REFERENCES `' . $dbPool->get('core')->prefix . 'qa_question` (`qa_question_id`);' + )->execute(); + break; + } + } +} diff --git a/Admin/Routes/Web/Backend.php b/Admin/Routes/Web/Backend.php new file mode 100644 index 0000000..7c467bc --- /dev/null +++ b/Admin/Routes/Web/Backend.php @@ -0,0 +1,30 @@ + [ + [ + 'dest' => '\Modules\Knowledgebase\Controller:viewQADashboard', + 'verb' => RouteVerb::GET, + ], + ], + '^.*/backend/qa/category.*$' => [ + [ + 'dest' => '\Modules\QA\Controller:viewQACategory', + 'verb' => RouteVerb::GET, + ], + ], + '^.*/backend/qa/question.*$' => [ + [ + 'dest' => '\Modules\QA\Controller:viewQADoc', + 'verb' => RouteVerb::GET, + ], + ], + '^.*/backend/qa/create.*$' => [ + [ + 'dest' => '\Modules\QA\Controller:viewQACreate', + 'verb' => RouteVerb::GET, + ], + ], +]; diff --git a/Admin/Uninstall.php b/Admin/Uninstall.php new file mode 100644 index 0000000..e55e84d --- /dev/null +++ b/Admin/Uninstall.php @@ -0,0 +1,45 @@ + + * @author Dennis Eichhorn + * @copyright Dennis Eichhorn + * @license OMS License 1.0 + * @version 1.0.0 + * @link http://orange-management.com + */ +declare(strict_types=1); +namespace Modules\QA\Admin; + +use phpOMS\DataStorage\Database\DatabasePool; +use phpOMS\DataStorage\Database\Schema\Builder; +use phpOMS\Module\InfoManager; +use phpOMS\Module\UninstallAbstract; + +/** + * Navigation class. + * + * @category Modules + * @package Modules\Admin + * @author OMS Development Team + * @author Dennis Eichhorn + * @license OMS License 1.0 + * @link http://orange-management.com + * @since 1.0.0 + */ +class Uninstall extends UninstallAbstract +{ + + /** + * {@inheritdoc} + */ + public static function uninstall(DatabasePool $dbPool, InfoManager $info) + { + parent::uninstall($dbPool, $info); + } +} diff --git a/Admin/Update.php b/Admin/Update.php new file mode 100644 index 0000000..6131548 --- /dev/null +++ b/Admin/Update.php @@ -0,0 +1,47 @@ + + * @author Dennis Eichhorn + * @copyright Dennis Eichhorn + * @license OMS License 1.0 + * @version 1.0.0 + * @link http://orange-management.com + */ +declare(strict_types=1); +namespace Modules\Knowledgebase\Admin; + +use phpOMS\DataStorage\Database\DatabasePool; +use phpOMS\Module\InfoManager; +use phpOMS\Module\UpdateAbstract; +use phpOMS\System\File\Directory; + +/** + * Navigation class. + * + * @category Modules + * @package Modules\Admin + * @author OMS Development Team + * @author Dennis Eichhorn + * @license OMS License 1.0 + * @link http://orange-management.com + * @since 1.0.0 + */ +class Update extends UpdateAbstract +{ + + /** + * {@inheritdoc} + */ + public static function update(DatabasePool $dbPool, InfoManager $info) + { + Directory::deletePath(__DIR__ . '/Update'); + mkdir('Update'); + parent::update($dbPool, $info); + } +} diff --git a/Controller.php b/Controller.php new file mode 100644 index 0000000..11188dc --- /dev/null +++ b/Controller.php @@ -0,0 +1,80 @@ + + * @author Dennis Eichhorn + * @copyright Dennis Eichhorn + * @license OMS License 1.0 + * @version 1.0.0 + * @link http://orange-management.com + */ +declare(strict_types=1); +namespace Modules\QA; + +use phpOMS\Message\RequestAbstract; +use phpOMS\Message\ResponseAbstract; +use phpOMS\Module\ModuleAbstract; +use phpOMS\Module\WebInterface; +use phpOMS\Views\View; + +/** + * Task class. + * + * @category Modules + * @package Modules\QA + * @author OMS Development Team + * @author Dennis Eichhorn + * @license OMS License 1.0 + * @link http://orange-management.com + * @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 = 'QA'; + + /** + * Providing. + * + * @var string + * @since 1.0.0 + */ + protected static $providing = []; + + /** + * Dependencies. + * + * @var string + * @since 1.0.0 + */ + protected static $dependencies = [ + ]; + +} diff --git a/Models/QAAnswer.php b/Models/QAAnswer.php new file mode 100644 index 0000000..9b3faab --- /dev/null +++ b/Models/QAAnswer.php @@ -0,0 +1,102 @@ + + * @author Dennis Eichhorn + * @copyright Dennis Eichhorn + * @license OMS License 1.0 + * @version 1.0.0 + * @link http://orange-management.com + */ +declare(strict_types=1); +namespace Modules\QA\Models; + +/** + * Task class. + * + * @category Kanban + * @package Modules + * @author OMS Development Team + * @author Dennis Eichhorn + * @license OMS License 1.0 + * @link http://orange-management.com + * @since 1.0.0 + */ +class QAQuestion implements \JsonSerializable +{ + private $id = 0; + + private $status = QAStatus::ACTIVE; + + private $answer = ''; + + private $question = 0; + + private $createdBy = 0; + + private $createdAt = null; + + public function __construct() + { + $this->createdAt = new \DateTime('now'); + } + + public function getId() : int + { + return $this->id; + } + + public function getAnswer() : string + { + return $this->answer; + } + + public function setAnswer(string $answer) /* : void */ + { + $this->answer = $answer; + } + + public function getQuestion() : string + { + return $this->question; + } + + public function setQuestion(int $question) /* : void */ + { + $this->question = $question; + } + + public function getStatus() : int + { + return $this->status; + } + + public function setStatus(int $status) /* : void */ + { + $this->status = $status; + } + public function getCreatedBy() : int + { + return $this->createdBy; + } + + public function setCreatedBy(int $id) /* : void */ + { + $this->createdBy = $id; + } + + public function getCreatedAt() : \DateTime + { + return $this->createdAt; + } + + public function jsonSerialize() : array + { + return []; + } +} \ No newline at end of file diff --git a/Models/QAAnswerMapper.php b/Models/QAAnswerMapper.php new file mode 100644 index 0000000..33dd75d --- /dev/null +++ b/Models/QAAnswerMapper.php @@ -0,0 +1,143 @@ + + * @author Dennis Eichhorn + * @copyright Dennis Eichhorn + * @license OMS License 1.0 + * @version 1.0.0 + * @link http://orange-management.com + */ +declare(strict_types=1); +namespace Modules\QA\Models; + +use phpOMS\DataStorage\Database\DataMapperAbstract; +use phpOMS\DataStorage\Database\Query\Builder; +use phpOMS\DataStorage\Database\Query\Column; +use phpOMS\DataStorage\Database\RelationType; + +/** + * Mapper class. + * + * @category Tasks + * @package Modules + * @author OMS Development Team + * @author Dennis Eichhorn + * @license OMS License 1.0 + * @link http://orange-management.com + * @since 1.0.0 + */ +class QAAnswerMapper extends DataMapperAbstract +{ + + /** + * Columns. + * + * @var array + * @since 1.0.0 + */ + protected static $columns = [ + 'qa_answer_id' => ['name' => 'qa_answer_id', 'type' => 'int', 'internal' => 'id'], + 'qa_answer_answer' => ['name' => 'qa_answer_answer', 'type' => 'string', 'internal' => 'answer'], + 'qa_answer_question' => ['name' => 'qa_answer_question', 'type' => 'int', 'internal' => 'question'], + 'qa_answer_status' => ['name' => 'qa_answer_status', 'type' => 'int', 'internal' => 'status'], + 'qa_answer_created_by' => ['name' => 'qa_answer_created_by', 'type' => 'int', 'internal' => 'createdBy'], + 'qa_answer_created_at' => ['name' => 'qa_answer_created_at', 'type' => 'DateTime', 'internal' => 'createdAt'], + ]; + + /** + * Primary table. + * + * @var string + * @since 1.0.0 + */ + protected static $table = 'qa_answer'; + + /** + * Created at. + * + * @var string + * @since 1.0.0 + */ + protected static $createdAt = 'qa_answer_created_at'; + + /** + * Primary field name. + * + * @var string + * @since 1.0.0 + */ + protected static $primaryField = 'qa_answer_id'; + + /** + * Create object. + * + * @param mixed $obj Object + * @param int $relations Behavior for relations creation + * + * @return mixed + * + * @since 1.0.0 + * @author Dennis Eichhorn + */ + public static function create($obj, int $relations = RelationType::ALL) + { + try { + $objId = parent::create($obj, $relations); + + if($objId === null || !is_scalar($objId)) { + return $objId; + } + + $query = new Builder(self::$db); + + $query->prefix(self::$db->getPrefix()) + ->insert( + 'account_permission_account', + 'account_permission_from', + 'account_permission_for', + 'account_permission_id1', + 'account_permission_id2', + 'account_permission_r', + 'account_permission_w', + 'account_permission_m', + 'account_permission_d', + 'account_permission_p' + ) + ->into('account_permission') + ->values($obj->getCreatedBy(), 'task', 'task', 1, $objId, 1, 1, 1, 1, 1); + + self::$db->con->prepare($query->toSql())->execute(); + } catch (\Exception $e) { + var_dump($e->getMessage()); + + return false; + } + + return $objId; + } + + /** + * Find. + * + * @param array $columns Columns to select + * + * @return Builder + * + * @since 1.0.0 + * @author Dennis Eichhorn + */ + public static function find(...$columns) : Builder + { + return parent::find(...$columns)->from('account_permission') + ->where('account_permission.account_permission_for', '=', 'task') + ->where('account_permission.account_permission_id1', '=', 1) + ->where('task.task_id', '=', new Column('account_permission.account_permission_id2')) + ->where('account_permission.account_permission_r', '=', 1); + } +} diff --git a/Models/QABadge.php b/Models/QABadge.php new file mode 100644 index 0000000..9680592 --- /dev/null +++ b/Models/QABadge.php @@ -0,0 +1,59 @@ + + * @author Dennis Eichhorn + * @copyright Dennis Eichhorn + * @license OMS License 1.0 + * @version 1.0.0 + * @link http://orange-management.com + */ +declare(strict_types=1); +namespace Modules\Badge\Models; + +/** + * Task class. + * + * @category Kanban + * @package Modules + * @author OMS Development Team + * @author Dennis Eichhorn + * @license OMS License 1.0 + * @link http://orange-management.com + * @since 1.0.0 + */ +class QABadge implements \JsonSerializable +{ + private $id = 0; + + private $name = ''; + + public function __construct() + { + } + + public function getId() : int + { + return $this->id; + } + + public function getName() : string + { + return $this->name; + } + + public function setName(string $name) /* : void */ + { + $this->name = $name; + } + + public function jsonSerialize() : array + { + return []; + } +} \ No newline at end of file diff --git a/Models/QABadgeMapper.php b/Models/QABadgeMapper.php new file mode 100644 index 0000000..f023938 --- /dev/null +++ b/Models/QABadgeMapper.php @@ -0,0 +1,111 @@ + + * @author Dennis Eichhorn + * @copyright Dennis Eichhorn + * @license OMS License 1.0 + * @version 1.0.0 + * @link http://orange-management.com + */ +declare(strict_types=1); +namespace Modules\QA\Models; + +use phpOMS\DataStorage\Database\DataMapperAbstract; +use phpOMS\DataStorage\Database\Query\Builder; +use phpOMS\DataStorage\Database\Query\Column; +use phpOMS\DataStorage\Database\RelationType; + +/** + * Mapper class. + * + * @category QA + * @package Modules + * @author OMS Development Team + * @author Dennis Eichhorn + * @license OMS License 1.0 + * @link http://orange-management.com + * @since 1.0.0 + */ +class QABadgeMapper extends DataMapperAbstract +{ + + /** + * Columns. + * + * @var array + * @since 1.0.0 + */ + protected static $columns = [ + 'qa_badge_id' => ['name' => 'qa_badge_id', 'type' => 'int', 'internal' => 'id'], + 'qa_badge_name' => ['name' => 'qa_badge_name', 'type' => 'string', 'internal' => 'name'], + ]; + + /** + * Primary table. + * + * @var string + * @since 1.0.0 + */ + protected static $table = 'qa_badge'; + + /** + * Primary field name. + * + * @var string + * @since 1.0.0 + */ + protected static $primaryField = 'qa_badge_id'; + + /** + * Create object. + * + * @param mixed $obj Object + * @param int $relations Behavior for relations creation + * + * @return mixed + * + * @since 1.0.0 + * @author Dennis Eichhorn + */ + public static function create($obj, int $relations = RelationType::ALL) + { + try { + $objId = parent::create($obj, $relations); + + if($objId === null || !is_scalar($objId)) { + return $objId; + } + } catch (\Exception $e) { + var_dump($e->getMessage()); + + return false; + } + + return $objId; + } + + /** + * Find. + * + * @param array $columns Columns to select + * + * @return Builder + * + * @since 1.0.0 + * @author Dennis Eichhorn + */ + public static function find(...$columns) : Builder + { + return parent::find(...$columns)->from('account_permission') + ->where('account_permission.account_permission_for', '=', 'task') + ->where('account_permission.account_permission_id1', '=', 1) + ->where('task.task_id', '=', new Column('account_permission.account_permission_id2')) + ->where('account_permission.account_permission_r', '=', 1); + } +} diff --git a/Models/QACategory.php b/Models/QACategory.php new file mode 100644 index 0000000..cb4bb62 --- /dev/null +++ b/Models/QACategory.php @@ -0,0 +1,71 @@ + + * @author Dennis Eichhorn + * @copyright Dennis Eichhorn + * @license OMS License 1.0 + * @version 1.0.0 + * @link http://orange-management.com + */ +declare(strict_types=1); +namespace Modules\QA\Models; + +/** + * Task class. + * + * @category Kanban + * @package Modules + * @author OMS Development Team + * @author Dennis Eichhorn + * @license OMS License 1.0 + * @link http://orange-management.com + * @since 1.0.0 + */ +class QACategory implements \JsonSerializable +{ + private $id = 0; + + private $name = ''; + + private $parent = 0; + + public function __construct() + { + } + + public function getId() : int + { + return $this->id; + } + + public function getName() : string + { + return $this->name; + } + + public function setName(string $name) /* : void */ + { + $this->name = $name; + } + + public function getParent() : int + { + return $this->parent; + } + + public function setParent(int $parent) /* : void */ + { + $this->parent = $parent; + } + + public function jsonSerialize() : array + { + return []; + } +} \ No newline at end of file diff --git a/Models/QACategoryMapper.php b/Models/QACategoryMapper.php new file mode 100644 index 0000000..09c8cb1 --- /dev/null +++ b/Models/QACategoryMapper.php @@ -0,0 +1,112 @@ + + * @author Dennis Eichhorn + * @copyright Dennis Eichhorn + * @license OMS License 1.0 + * @version 1.0.0 + * @link http://orange-management.com + */ +declare(strict_types=1); +namespace Modules\QA\Models; + +use phpOMS\DataStorage\Database\DataMapperAbstract; +use phpOMS\DataStorage\Database\Query\Builder; +use phpOMS\DataStorage\Database\Query\Column; +use phpOMS\DataStorage\Database\RelationType; + +/** + * Mapper class. + * + * @category Tasks + * @package Modules + * @author OMS Development Team + * @author Dennis Eichhorn + * @license OMS License 1.0 + * @link http://orange-management.com + * @since 1.0.0 + */ +class QACategoryMapper extends DataMapperAbstract +{ + + /** + * Columns. + * + * @var array + * @since 1.0.0 + */ + protected static $columns = [ + 'qa_category_id' => ['name' => 'qa_category_id', 'type' => 'int', 'internal' => 'id'], + 'qa_category_name' => ['name' => 'qa_category_name', 'type' => 'string', 'internal' => 'name'], + 'qa_category_parent' => ['name' => 'qa_category_parent', 'type' => 'int', 'internal' => 'parent'], + ]; + + /** + * Primary table. + * + * @var string + * @since 1.0.0 + */ + protected static $table = 'qa_category'; + + /** + * Primary field name. + * + * @var string + * @since 1.0.0 + */ + protected static $primaryField = 'qa_category_id'; + + /** + * Create object. + * + * @param mixed $obj Object + * @param int $relations Behavior for relations creation + * + * @return mixed + * + * @since 1.0.0 + * @author Dennis Eichhorn + */ + public static function create($obj, int $relations = RelationType::ALL) + { + try { + $objId = parent::create($obj, $relations); + + if($objId === null || !is_scalar($objId)) { + return $objId; + } + } catch (\Exception $e) { + var_dump($e->getMessage()); + + return false; + } + + return $objId; + } + + /** + * Find. + * + * @param array $columns Columns to select + * + * @return Builder + * + * @since 1.0.0 + * @author Dennis Eichhorn + */ + public static function find(...$columns) : Builder + { + return parent::find(...$columns)->from('account_permission') + ->where('account_permission.account_permission_for', '=', 'task') + ->where('account_permission.account_permission_id1', '=', 1) + ->where('task.task_id', '=', new Column('account_permission.account_permission_id2')) + ->where('account_permission.account_permission_r', '=', 1); + } +} diff --git a/Models/QAQuestion.php b/Models/QAQuestion.php new file mode 100644 index 0000000..17b9314 --- /dev/null +++ b/Models/QAQuestion.php @@ -0,0 +1,151 @@ + + * @author Dennis Eichhorn + * @copyright Dennis Eichhorn + * @license OMS License 1.0 + * @version 1.0.0 + * @link http://orange-management.com + */ +declare(strict_types=1); +namespace Modules\QA\Models; + +/** + * Task class. + * + * @category Kanban + * @package Modules + * @author OMS Development Team + * @author Dennis Eichhorn + * @license OMS License 1.0 + * @link http://orange-management.com + * @since 1.0.0 + */ +class QAQuestion implements \JsonSerializable +{ + private $id = 0; + + private $name = ''; + + private $status = QAStatus::ACTIVE; + + private $question = ''; + + private $category = 0; + + private $language = ''; + + private $createdBy = 0; + + private $createdAt = null; + + private $badges = []; + + private $answers = []; + + public function __construct() + { + $this->createdAt = new \DateTime('now'); + } + + public function getId() : int + { + return $this->id; + } + + public function getLanguage() : string + { + return $this->language; + } + + public function setLanguage(string $language) /* : void */ + { + $this->language = $language; + } + + public function getName() : string + { + return $this->name; + } + + public function setName(string $name) /* : void */ + { + $this->name = $name; + } + + public function getQuestion() : string + { + return $this->question; + } + + public function setQuestion(string $question) /* : void */ + { + $this->question = $question; + } + + public function getStatus() : int + { + return $this->status; + } + + public function setStatus(int $status) /* : void */ + { + $this->status = $status; + } + + public function getCategory() : int + { + return $this->category; + } + + public function setCategory(int $category) /* : void */ + { + $this->category = $category; + } + + public function getCreatedBy() : int + { + return $this->createdBy; + } + + public function setCreatedBy(int $id) /* : void */ + { + $this->createdBy = $id; + } + + public function getCreatedAt() : \DateTime + { + return $this->createdAt; + } + + public function getBadges() : array + { + return $this->badges; + } + + public function addBadge($badge) /* : void */ + { + $this->badges[] = $badge; + } + + public function getAnswers() : array + { + return $this->answers; + } + + public function addAnswer($answer) /* : void */ + { + $this->answers[] = $answer; + } + + public function jsonSerialize() : array + { + return []; + } +} \ No newline at end of file diff --git a/Models/QAQuestionMapper.php b/Models/QAQuestionMapper.php new file mode 100644 index 0000000..5dbb993 --- /dev/null +++ b/Models/QAQuestionMapper.php @@ -0,0 +1,179 @@ + + * @author Dennis Eichhorn + * @copyright Dennis Eichhorn + * @license OMS License 1.0 + * @version 1.0.0 + * @link http://orange-management.com + */ +declare(strict_types=1); +namespace Modules\QA\Models; + +use phpOMS\DataStorage\Database\DataMapperAbstract; +use phpOMS\DataStorage\Database\Query\Builder; +use phpOMS\DataStorage\Database\Query\Column; +use phpOMS\DataStorage\Database\RelationType; + +/** + * Mapper class. + * + * @category Tasks + * @package Modules + * @author OMS Development Team + * @author Dennis Eichhorn + * @license OMS License 1.0 + * @link http://orange-management.com + * @since 1.0.0 + */ +class QAQuestionMapper extends DataMapperAbstract +{ + + /** + * Columns. + * + * @var array + * @since 1.0.0 + */ + protected static $columns = [ + 'qa_question_id' => ['name' => 'qa_question_id', 'type' => 'int', 'internal' => 'id'], + 'qa_question_title' => ['name' => 'qa_question_title', 'type' => 'string', 'internal' => 'name'], + 'qa_question_language' => ['name' => 'qa_question_language', 'type' => 'string', 'internal' => 'language'], + 'qa_question_question' => ['name' => 'qa_question_question', 'type' => 'string', 'internal' => 'question'], + 'qa_question_status' => ['name' => 'qa_question_status', 'type' => 'int', 'internal' => 'status'], + 'qa_question_category' => ['name' => 'qa_question_category', 'type' => 'int', 'internal' => 'category'], + 'qa_question_created_by' => ['name' => 'qa_question_created_by', 'type' => 'int', 'internal' => 'createdBy'], + 'qa_question_created_at' => ['name' => 'qa_question_created_at', 'type' => 'DateTime', 'internal' => 'createdAt'], + ]; + + /** + * Has many relation. + * + * @var array + * @since 1.0.0 + */ + protected static $hasMany = [ + 'badges' => [ + 'mapper' => QABadgeMapper::class, + 'table' => 'qa_question_badge', + 'dst' => 'qa_question_badge_badge', + 'src' => 'qa_question_badge_question', + ], + 'badges' => [ + 'mapper' => QAAnswerMapper::class, + 'table' => 'qa_answer', + 'dst' => 'qa_answer_question', + 'src' => null, + ], + ]; + + /** + * Has many relation. + * + * @var array + * @since 1.0.0 + */ + protected static $ownsOne = [ + 'category' => [ + 'mapper' => QACategoryMapper::class, + 'dst' => 'qa_question_category', + ], + ]; + + /** + * Primary table. + * + * @var string + * @since 1.0.0 + */ + protected static $table = 'qa_question'; + + /** + * Created at. + * + * @var string + * @since 1.0.0 + */ + protected static $createdAt = 'qa_question_created_at'; + + /** + * Primary field name. + * + * @var string + * @since 1.0.0 + */ + protected static $primaryField = 'qa_question_id'; + + /** + * Create object. + * + * @param mixed $obj Object + * @param int $relations Behavior for relations creation + * + * @return mixed + * + * @since 1.0.0 + * @author Dennis Eichhorn + */ + public static function create($obj, int $relations = RelationType::ALL) + { + try { + $objId = parent::create($obj, $relations); + + if($objId === null || !is_scalar($objId)) { + return $objId; + } + + $query = new Builder(self::$db); + + $query->prefix(self::$db->getPrefix()) + ->insert( + 'account_permission_account', + 'account_permission_from', + 'account_permission_for', + 'account_permission_id1', + 'account_permission_id2', + 'account_permission_r', + 'account_permission_w', + 'account_permission_m', + 'account_permission_d', + 'account_permission_p' + ) + ->into('account_permission') + ->values($obj->getCreatedBy(), 'task', 'task', 1, $objId, 1, 1, 1, 1, 1); + + self::$db->con->prepare($query->toSql())->execute(); + } catch (\Exception $e) { + var_dump($e->getMessage()); + + return false; + } + + return $objId; + } + + /** + * Find. + * + * @param array $columns Columns to select + * + * @return Builder + * + * @since 1.0.0 + * @author Dennis Eichhorn + */ + public static function find(...$columns) : Builder + { + return parent::find(...$columns)->from('account_permission') + ->where('account_permission.account_permission_for', '=', 'task') + ->where('account_permission.account_permission_id1', '=', 1) + ->where('task.task_id', '=', new Column('account_permission.account_permission_id2')) + ->where('account_permission.account_permission_r', '=', 1); + } +} diff --git a/Models/QAStatus.php b/Models/QAStatus.php new file mode 100644 index 0000000..75db8d7 --- /dev/null +++ b/Models/QAStatus.php @@ -0,0 +1,41 @@ + + * @author Dennis Eichhorn + * @copyright Dennis Eichhorn + * @license OMS License 1.0 + * @version 1.0.0 + * @link http://orange-management.com + */ +declare(strict_types=1); +namespace Modules\QA\Models; + +use phpOMS\Datatypes\Enum; + +/** + * Task status enum. + * + * @category QA + * @package Modules + * @author OMS Development Team + * @author Dennis Eichhorn + * @license OMS License 1.0 + * @link http://orange-management.com + * @since 1.0.0 + */ +abstract class QAStauts extends Enum +{ + /* public */ const ACTIVE = 1; + + /* public */ const INACTIVE = 2; + + /* public */ const DRAFT = 3; + + /* public */ const BLOCKED = 4; +} diff --git a/Theme/Backend/Lang/Navigation.en.lang.php b/Theme/Backend/Lang/Navigation.en.lang.php new file mode 100644 index 0000000..576f2a7 --- /dev/null +++ b/Theme/Backend/Lang/Navigation.en.lang.php @@ -0,0 +1,18 @@ + + * @author Dennis Eichhorn + * @copyright Dennis Eichhorn + * @license OMS License 1.0 + * @version 1.0.0 + * @link http://orange-management.com + */ +return ['Navigation' => [ + 'QA' => 'QA', +]]; diff --git a/Theme/Backend/Lang/en.lang.php b/Theme/Backend/Lang/en.lang.php new file mode 100644 index 0000000..171cc5d --- /dev/null +++ b/Theme/Backend/Lang/en.lang.php @@ -0,0 +1,18 @@ + + * @author Dennis Eichhorn + * @copyright Dennis Eichhorn + * @license OMS License 1.0 + * @version 1.0.0 + * @link http://orange-management.com + */ +return ['Knowledgebase' => [ + 'QA' => 'QA', +]]; diff --git a/Theme/Backend/qa-dashboard.tpl.php b/Theme/Backend/qa-dashboard.tpl.php new file mode 100644 index 0000000..e69de29 diff --git a/info.json b/info.json new file mode 100644 index 0000000..48e51f8 --- /dev/null +++ b/info.json @@ -0,0 +1,47 @@ +{ + "name": { + "id": 1006000000, + "internal": "QA", + "external": "QA" + }, + "category": "Tools", + "version": "1.0.0", + "requirements": { + "phpOMS": "1.0.0", + "phpOMS-db": "1.0.0" + }, + "creator": { + "name": "Orange Management", + "website": "www.spl1nes.com" + }, + "description": "QA module.", + "directory": "QA", + "dependencies": { + "Admin" : "1.0.0", + "Tasks" : "1.0.0", + "Calendar" : "1.0.0" + }, + "providing": { + "Navigation": "*" + }, + "load": [ + { + "pid": [ + "7322d5765c8b18b14c20d406e89c628fd0998688" + ], + "type": 4, + "for": 0, + "from": "QA", + "file": "QA" + }, + { + "pid": [ + "754a08ddf8bcb1cf22f310f09206dd783d42f7dd" + ], + "type": 5, + "from": "QA", + "for": "Navigation", + "file": "Navigation" + } + ] +}