diff --git a/Admin/Activate.php b/Admin/Activate.php new file mode 100644 index 0000000..b493777 --- /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 + */ +namespace Modules\News\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..6066416 --- /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 + */ +namespace Modules\News\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..7796b7c --- /dev/null +++ b/Admin/Install/Navigation.install.json @@ -0,0 +1,78 @@ +[ + { + "id": 1000701001, + "pid": "754a08ddf8bcb1cf22f310f09206dd783d42f7dd", + "type": 2, + "subtype": 1, + "name": "News", + "uri": "/{/lang}/backend/news/dashboard?{?}", + "target": "self", + "icon": null, + "order": 40, + "from": "News", + "permission": null, + "parent": 1000201001, + "children": [ + { + "id": 1000702001, + "pid": "d7470914e19522acc310a55e5cb13a6f0f7ca000", + "type": 3, + "subtype": 1, + "name": "News", + "uri": "/{/lang}/backend/news/dashboard?{?}", + "target": "self", + "icon": null, + "order": 1, + "from": "News", + "permission": null, + "parent": 1000701001, + "children": [] + }, + { + "id": 1000703001, + "pid": "d7470914e19522acc310a55e5cb13a6f0f7ca000", + "type": 3, + "subtype": 1, + "name": "Archive", + "uri": "/{/lang}/backend/news/archive?{?}", + "target": "self", + "icon": null, + "order": 5, + "from": "News", + "permission": null, + "parent": 1000701001, + "children": [] + }, + { + "id": 1000704001, + "pid": "d7470914e19522acc310a55e5cb13a6f0f7ca000", + "type": 3, + "subtype": 1, + "name": "Create", + "uri": "/{/lang}/backend/news/create?{?}", + "target": "self", + "icon": null, + "order": 10, + "from": "News", + "permission": null, + "parent": 1000701001, + "children": [] + }, + { + "id": 1000705001, + "pid": "d7470914e19522acc310a55e5cb13a6f0f7ca000", + "type": 3, + "subtype": 1, + "name": "Draft", + "uri": "/{/lang}/backend/news/draft/list?{?}", + "target": "self", + "icon": null, + "order": 15, + "from": "News", + "permission": null, + "parent": 1000701001, + "children": [] + } + ] + } +] diff --git a/Admin/Install/Navigation.php b/Admin/Install/Navigation.php new file mode 100644 index 0000000..6291373 --- /dev/null +++ b/Admin/Install/Navigation.php @@ -0,0 +1,40 @@ + + * @author Dennis Eichhorn + * @copyright Dennis Eichhorn + * @license OMS License 1.0 + * @version 1.0.0 + * @link http://orange-management.com + */ +namespace Modules\News\Admin\Install; +use phpOMS\DataStorage\Database\DatabasePool; + +/** + * 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 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..d414688 --- /dev/null +++ b/Admin/Installer.php @@ -0,0 +1,101 @@ + + * @author Dennis Eichhorn + * @copyright Dennis Eichhorn + * @license OMS License 1.0 + * @version 1.0.0 + * @link http://orange-management.com + */ +namespace Modules\News\Admin; + +use phpOMS\DataStorage\Database\DatabaseType; +use phpOMS\DataStorage\Database\DatabasePool; +use phpOMS\Module\InfoManager; +use phpOMS\Module\InstallerAbstract; + +/** + * News install class. + * + * @category Modules + * @package Modules\News + * @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 . 'news` ( + `news_id` int(11) NOT NULL AUTO_INCREMENT, + `news_title` varchar(250) NOT NULL, + `news_featured` tinyint(1) DEFAULT NULL, + `news_content` text NOT NULL, + `news_plain` text NOT NULL, + `news_type` tinyint(2) NOT NULL, + `news_status` tinyint(1) NOT NULL, + `news_lang` varchar(2) NOT NULL, + `news_publish` datetime NOT NULL, + `news_created_at` datetime NOT NULL, + `news_created_by` int(11) NOT NULL, + PRIMARY KEY (`news_id`), + KEY `news_created_by` (`news_created_by`) + )ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=1;' + )->execute(); + + $dbPool->get('core')->con->prepare( + 'ALTER TABLE `' . $dbPool->get('core')->prefix . 'news` + ADD CONSTRAINT `' . $dbPool->get('core')->prefix . 'news_ibfk_1` FOREIGN KEY (`news_created_by`) REFERENCES `' . $dbPool->get('core')->prefix . 'account` (`account_id`);' + )->execute(); + + $dbPool->get('core')->con->prepare( + 'CREATE TABLE if NOT EXISTS `' . $dbPool->get('core')->prefix . 'news_tag` ( + `news_tag_id` int(11) NOT NULL AUTO_INCREMENT, + `news_tag_news` int(11) NOT NULL, + `news_tag_tag` varchar(20) NOT NULL, + PRIMARY KEY (`news_tag_id`), + KEY `news_tag_news` (`news_tag_news`) + )ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=1;' + )->execute(); + + $dbPool->get('core')->con->prepare( + 'ALTER TABLE `' . $dbPool->get('core')->prefix . 'news_tag` + ADD CONSTRAINT `' . $dbPool->get('core')->prefix . 'news_tag_ibfk_1` FOREIGN KEY (`news_tag_news`) REFERENCES `' . $dbPool->get('core')->prefix . 'news` (`news_id`);' + )->execute(); + + $dbPool->get('core')->con->prepare( + 'CREATE TABLE if NOT EXISTS `' . $dbPool->get('core')->prefix . 'news_group` ( + `news_group_id` int(11) NOT NULL AUTO_INCREMENT, + `news_group_news` int(11) NOT NULL, + `news_group_group` int(11) NOT NULL, + PRIMARY KEY (`news_group_id`), + KEY `news_group_news` (`news_group_news`) + )ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=1;' + )->execute(); + + $dbPool->get('core')->con->prepare( + 'ALTER TABLE `' . $dbPool->get('core')->prefix . 'news_group` + ADD CONSTRAINT `' . $dbPool->get('core')->prefix . 'news_group_ibfk_1` FOREIGN KEY (`news_group_news`) REFERENCES `' . $dbPool->get('core')->prefix . 'news` (`news_id`);' + )->execute(); + break; + } + } +} diff --git a/Admin/Routes/Web/Api.php b/Admin/Routes/Web/Api.php new file mode 100644 index 0000000..e8069bf --- /dev/null +++ b/Admin/Routes/Web/Api.php @@ -0,0 +1,12 @@ + [ + [ + 'dest' => '\Modules\News\Controller:apiNewsCreate', + 'verb' => RouteVerb::SET, + ], + ], +]; diff --git a/Admin/Routes/Web/Backend.php b/Admin/Routes/Web/Backend.php new file mode 100644 index 0000000..9d7e386 --- /dev/null +++ b/Admin/Routes/Web/Backend.php @@ -0,0 +1,30 @@ + [ + [ + 'dest' => '\Modules\News\Controller:viewNewsDashboard', + 'verb' => RouteVerb::GET, + ], + ], + '^.*/backend/news/article.*$' => [ + [ + 'dest' => '\Modules\News\Controller:viewNewsArticle', + 'verb' => RouteVerb::GET, + ], + ], + '^.*/backend/news/archive.*$' => [ + [ + 'dest' => '\Modules\News\Controller:viewNewsArchive', + 'verb' => RouteVerb::GET, + ], + ], + '^.*/backend/news/create.*$' => [ + [ + 'dest' => '\Modules\News\Controller:viewNewsCreate', + 'verb' => RouteVerb::GET, + ], + ], +]; diff --git a/Admin/Routes/console.php b/Admin/Routes/console.php new file mode 100644 index 0000000..1ecbfac --- /dev/null +++ b/Admin/Routes/console.php @@ -0,0 +1,3 @@ + + * @author Dennis Eichhorn + * @copyright Dennis Eichhorn + * @license OMS License 1.0 + * @version 1.0.0 + * @link http://orange-management.com + */ +namespace Modules\News\Admin; + + +use phpOMS\DataStorage\Database\DatabasePool; +use phpOMS\DataStorage\Database\Schema\Builder; +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); + + $query = new Builder($dbPool->get()); + + $query->prefix($dbPool->get('core')->getPrefix())->drop( + 'news_group', + 'news_tag', + 'news' + ); + + $dbPool->get()->con->prepare($query->toSql())->execute(); + } +} diff --git a/Admin/Update.php b/Admin/Update.php new file mode 100644 index 0000000..26adeab --- /dev/null +++ b/Admin/Update.php @@ -0,0 +1,46 @@ + + * @author Dennis Eichhorn + * @copyright Dennis Eichhorn + * @license OMS License 1.0 + * @version 1.0.0 + * @link http://orange-management.com + */ +namespace Modules\News\Admin; + + +use phpOMS\DataStorage\Database\DatabasePool; +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, array $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..dd36927 --- /dev/null +++ b/Controller.php @@ -0,0 +1,289 @@ + + * @author Dennis Eichhorn + * @copyright Dennis Eichhorn + * @license OMS License 1.0 + * @version 1.0.0 + * @link http://orange-management.com + */ +namespace Modules\News; + +use Model\Message\FormValidation; +use Modules\News\Models\NewsArticle; +use Modules\News\Models\NewsArticleMapper; +use Modules\News\Models\NewsStatus; +use Modules\News\Models\NewsType; +use phpOMS\Account\Account; +use phpOMS\Localization\ISO639Enum; +use phpOMS\Message\RequestAbstract; +use phpOMS\Message\ResponseAbstract; +use phpOMS\Module\ModuleAbstract; +use phpOMS\Module\WebInterface; +use phpOMS\Utils\Parser\Markdown\Markdown; +use phpOMS\Views\View; + +/** + * News controller class. + * + * @category Modules + * @package Modules\News + * @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 = 'News'; + + /** + * Providing. + * + * @var string + * @since 1.0.0 + */ + protected static $providing = []; + + /** + * Dependencies. + * + * @var string + * @since 1.0.0 + */ + protected static $dependencies = [ + ]; + + /** + * @param RequestAbstract $request Request + * @param ResponseAbstract $response Response + * @param mixed $data Generic data + * + * @return \Serializable + * + * @since 1.0.0 + * @author Dennis Eichhorn + */ + public function viewNewsDashboard(RequestAbstract $request, ResponseAbstract $response, $data = null) : \Serializable + { + $view = new View($this->app, $request, $response); + $view->setTemplate('/Modules/News/Theme/Backend/news-dashboard'); + $view->addData('nav', $this->app->moduleManager->get('Navigation')->createNavigationMid(1000701001, $request, $response)); + + $news = NewsArticleMapper::getNewest(50); + $view->addData('news', $news); + + return $view; + } + + /** + * @param RequestAbstract $request Request + * @param ResponseAbstract $response Response + * @param mixed $data Generic data + * + * @return \Serializable + * + * @since 1.0.0 + * @author Dennis Eichhorn + */ + public function viewNewsArticle(RequestAbstract $request, ResponseAbstract $response, $data = null) : \Serializable + { + $view = new View($this->app, $request, $response); + $view->setTemplate('/Modules/News/Theme/Backend/news-single'); + $view->addData('nav', $this->app->moduleManager->get('Navigation')->createNavigationMid(1000701001, $request, $response)); + + $article = NewsArticleMapper::get((int) $request->getData('id')); + $view->addData('news', $article); + + return $view; + } + + /** + * @param RequestAbstract $request Request + * @param ResponseAbstract $response Response + * @param mixed $data Generic data + * + * @return \Serializable + * + * @since 1.0.0 + * @author Dennis Eichhorn + */ + public function viewNewsArchive(RequestAbstract $request, ResponseAbstract $response, $data = null) : \Serializable + { + $view = new View($this->app, $request, $response); + $view->setTemplate('/Modules/News/Theme/Backend/news-archive'); + $view->addData('nav', $this->app->moduleManager->get('Navigation')->createNavigationMid(1000701001, $request, $response)); + + return $view; + } + + /** + * @param RequestAbstract $request Request + * @param ResponseAbstract $response Response + * @param mixed $data Generic data + * + * @return \Serializable + * + * @since 1.0.0 + * @author Dennis Eichhorn + */ + public function viewNewsCreate(RequestAbstract $request, ResponseAbstract $response, $data = null) : \Serializable + { + $view = new View($this->app, $request, $response); + $view->setTemplate('/Modules/News/Theme/Backend/news-create'); + $view->addData('nav', $this->app->moduleManager->get('Navigation')->createNavigationMid(1000701001, $request, $response)); + + return $view; + } + + private function validateNewsCreate(RequestAbstract $request) : array + { + $val = []; + if ( + ($val['title'] = empty($request->getData('title'))) + || ($val['plain'] = empty($request->getData('plain'))) + || ($val['lang'] = ( + $request->getData('lang') !== null + && !ISO639Enum::isValidValue(strtolower($request->getData('lang'))) + )) + || ($val['type'] = ( + $request->getData('type') === null + || !NewsType::isValidValue((int) $request->getData('type')) + )) + || ($val['status'] = ( + $request->getData('status') === null + || !NewsStatus::isValidValue((int) $request->getData('status')) + )) + ) { + return $val; + } + + return []; + } + + /** + * @param RequestAbstract $request Request + * @param ResponseAbstract $response Response + * @param mixed $data Generic data + * + * @since 1.0.0 + * @author Dennis Eichhorn + */ + public function apiNewsCreate(RequestAbstract $request, ResponseAbstract $response, $data = null) + { + if (!empty($val = $this->validateNewsCreate($request))) { + $response->set('news_create', new FormValidation($val)); + + return; + } + + $mardkownParser = new Markdown(); + + $newsArticle = new NewsArticle(); + $newsArticle->setCreatedBy($request->getAccount()); + $newsArticle->setCreatedAt(new \DateTime('now')); + $newsArticle->setPublish(new \DateTime($request->getData('publish') ?? false)); + $newsArticle->setTitle($request->getData('title') ?? ''); + $newsArticle->setPlain($request->getData('plain') ?? ''); + $newsArticle->setContent($mardkownParser->parse($request->getData('plain') ?? '')); + $newsArticle->setLanguage(strtolower($request->getData('lang') ?? $request->getL11n()->getLanguage())); + $newsArticle->setType((int) ($request->getData('type') ?? 1)); + $newsArticle->setStatus((int) ($request->getData('status') ?? 1)); + $newsArticle->setFeatured((bool) ($request->getData('featured') ?? true)); + + NewsArticleMapper::create($newsArticle); + + $response->set('news', $newsArticle->jsonSerialize()); + } + + /** + * Get Newslists. + * + * @param int $limit News limit + * @param int $offset News offset + * @param string $orderBy Order criteria (database table name) + * @param string $ordered Order type (e.g. ASC) + * @param Account $account Accont for permission handling + * + * @return array + * + * @since 1.0.0 + * @author Dennis Eichhorn + */ + public function getNewsListR(int $limit = 50, int $offset = 0, string $orderBy = 'news_created', string $ordered = 'ASC', Account $account = null) + { + $query = NewsArticleMapper::find('news.news_id', 'news.news_author', 'news.news_publish', 'news.news_title') + ->where('news.news_type', '=', 1) + ->where('news.news_status', '=', 1) + ->orderBy($orderBy, $ordered) + ->offset($offset) + ->limit($limit); + + if (isset($account)) { + $query->where('account_permission.account_permission_account', '=', $account->getId()); + } + + return NewsArticleMapper::getAllByQuery($query); + } + + /** + * Get Headlinelist. + * + * @param int $limit News limit + * @param int $offset News offset + * @param string $orderBy Order criteria (database table name) + * @param string $ordered Order type (e.g. ASC) + * @param Account $account Accont for permission handling + * + * @return array + * + * @since 1.0.0 + * @author Dennis Eichhorn + */ + public function getHeadlineListR(int $limit = 50, int $offset = 0, string $orderBy = 'news_created', string $ordered = 'ASC', Account $account = null) + { + $query = NewsArticleMapper::find('news.news_id', 'news.news_author', 'news.news_publish', 'news.news_title') + ->where('news.news_type', '=', 0) + ->where('news.news_status', '=', 1) + ->orderBy($orderBy, $ordered) + ->offset($offset) + ->limit($limit); + + if (isset($account)) { + $query->where('account_permission.account_permission_account', '=', $account->getId()); + } + + return NewsArticleMapper::getAllByQuery($query); + } + +} diff --git a/Models/NewsArticle.php b/Models/NewsArticle.php new file mode 100644 index 0000000..3ad2beb --- /dev/null +++ b/Models/NewsArticle.php @@ -0,0 +1,424 @@ + + * @author Dennis Eichhorn + * @copyright Dennis Eichhorn + * @license OMS License 1.0 + * @version 1.0.0 + * @link http://orange-management.com + */ +namespace Modules\News\Models; + +use phpOMS\Contract\ArrayableInterface; +use phpOMS\Datatypes\Exception\InvalidEnumValue; +use phpOMS\Localization\ISO639x1Enum; + +/** + * News article class. + * + * @category Module + * @package Framework + * @author OMS Development Team + * @author Dennis Eichhorn + * @license OMS License 1.0 + * @link http://orange-management.com + * @since 1.0.0 + */ +class NewsArticle implements ArrayableInterface, \JsonSerializable +{ + + /** + * Article ID. + * + * @var int + * @since 1.0.0 + */ + private $id = 0; + + /** + * Title. + * + * @var string + * @since 1.0.0 + */ + private $title = ''; + + /** + * Content. + * + * @var string + * @since 1.0.0 + */ + private $content = ''; + + /** + * Unparsed. + * + * @var string + * @since 1.0.0 + */ + private $plain = ''; + + /** + * News type. + * + * @var int + * @since 1.0.0 + */ + private $type = NewsType::ARTICLE; + + /** + * News status. + * + * @var int + * @since 1.0.0 + */ + private $status = NewsStatus::DRAFT; + + /** + * Language. + * + * @var string + * @since 1.0.0 + */ + private $language = ISO639x1Enum::_EN; + + /** + * Created. + * + * @var \DateTime + * @since 1.0.0 + */ + private $createdAt = null; + + /** + * Creator. + * + * @var int + * @since 1.0.0 + */ + private $createdBy = 0; + + /** + * Publish. + * + * @var \DateTime + * @since 1.0.0 + */ + private $publish = null; + + /** + * Featured. + * + * @var bool + * @since 1.0.0 + */ + private $featured = false; + + /** + * Constructor. + * + * @since 1.0.0 + * @author Dennis Eichhorn + */ + public function __construct() + { + $this->createdAt = new \DateTime('NOW'); + $this->publish = new \DateTime('NOW'); + } + + /** + * @return string + * + * @since 1.0.0 + * @author Dennis Eichhorn + */ + public function getContent() : string + { + return $this->content; + } + + /** + * @param string $content + * + * @return void + * + * @since 1.0.0 + * @author Dennis Eichhorn + */ + public function setContent(string $content) + { + $this->content = $content; + } + + /** + * @param string $plain + * + * @return void + * + * @since 1.0.0 + * @author Dennis Eichhorn + */ + public function setPlain(string $plain) + { + $this->plain = $plain; + } + + /** + * @return string + * + * @since 1.0.0 + * @author Dennis Eichhorn + */ + public function getPlain() : string + { + return $this->plain; + } + + /** + * @return \DateTime + * + * @since 1.0.0 + * @author Dennis Eichhorn + */ + public function getCreatedAt() : \DateTime + { + return $this->createdAt; + } + + /** + * @return int + * + * @since 1.0.0 + * @author Dennis Eichhorn + */ + public function getId() : int + { + return $this->id; + } + + /** + * @return string + * + * @since 1.0.0 + * @author Dennis Eichhorn + */ + public function getLanguage() : string + { + return $this->language; + } + + /** + * @return \DateTime + * + * @since 1.0.0 + * @author Dennis Eichhorn + */ + public function getPublish() : \DateTime + { + return $this->publish; + } + + /** + * @param string $language + * + * @return void + * + * @since 1.0.0 + * @author Dennis Eichhorn + */ + public function setLanguage(string $language) + { + if(!ISO639x1Enum::isValidValue($language)) { + throw new InvalidEnumValue($language); + } + + $this->language = $language; + } + + /** + * @param \DateTime $publish + * + * @return void + * + * @since 1.0.0 + * @author Dennis Eichhorn + */ + public function setPublish(\DateTime $publish) + { + $this->publish = $publish; + } + + /** + * @return int + * + * @since 1.0.0 + * @author Dennis Eichhorn + */ + public function getCreatedBy() : int + { + return $this->createdBy; + } + + /** + * @param int $id + * + * @since 1.0.0 + * @author Dennis Eichhorn + */ + public function setCreatedBy(int $id) + { + $this->createdBy = $id; + } + + /** + * @param \DateTime $createdAt + * + * @return void + * + * @since 1.0.0 + * @author Dennis Eichhorn + */ + public function setCreatedAt(\DateTime $createdAt) + { + $this->createdAt = $createdAt; + } + + /** + * @return string + * + * @since 1.0.0 + * @author Dennis Eichhorn + */ + public function getTitle() : string + { + return $this->title; + } + + /** + * @param string $title + * + * @return mixed + * + * @since 1.0.0 + * @author Dennis Eichhorn + */ + public function setTitle(string $title) + { + $this->title = $title; + } + + /** + * @return int + * + * @since 1.0.0 + * @author Dennis Eichhorn + */ + public function getType() : int + { + return $this->type; + } + + /** + * @param int $type + * + * @return void + * + * @since 1.0.0 + * @author Dennis Eichhorn + */ + public function setType(int $type) + { + if(!NewsType::isValidValue($type)) { + throw new InvalidEnumValue($type); + } + + $this->type = $type; + } + + /** + * @return int + * + * @since 1.0.0 + * @author Dennis Eichhorn + */ + public function getStatus() : int + { + return $this->status; + } + + /** + * @param int $status + * + * @return void + * + * @throws InvalidEnumValue + * + * @since 1.0.0 + * @author Dennis Eichhorn + */ + public function setStatus(int $status) + { + if(!NewsStatus::isValidValue($status)) { + throw new InvalidEnumValue($status); + } + + $this->status = $status; + } + + /** + * @return bool + * + * @since 1.0.0 + * @author Dennis Eichhorn + */ + public function isFeatured() : bool + { + return $this->featured; + } + + /** + * @param bool $featured + * + * @return void + * + * @since 1.0.0 + * @author Dennis Eichhorn + */ + public function setFeatured(bool $featured) + { + $this->featured = $featured; + } + + public function toArray() : array + { + return [ + 'id' => $this->id, + 'title' => $this->title, + 'plain' => $this->plain, + 'content' => $this->content, + 'type' => $this->type, + 'status' => $this->status, + 'featured' => $this->featured, + 'publish' => $this->publish, + 'createdAt' => $this->createdAt, + 'createdBy' => $this->createdBy, + ]; + } + + public function __toString() + { + return json_encode($this->toArray()); + } + + public function jsonSerialize() + { + return $this->toArray(); + } +} diff --git a/Models/NewsArticleMapper.php b/Models/NewsArticleMapper.php new file mode 100644 index 0000000..47edc4d --- /dev/null +++ b/Models/NewsArticleMapper.php @@ -0,0 +1,136 @@ + + * @author Dennis Eichhorn + * @copyright Dennis Eichhorn + * @license OMS License 1.0 + * @version 1.0.0 + * @link http://orange-management.com + */ +namespace Modules\News\Models; + +use Modules\Admin\Models\AccountMapper; +use phpOMS\DataStorage\Database\DataMapperAbstract; +use phpOMS\DataStorage\Database\Query\Builder; +use phpOMS\DataStorage\Database\Query\Column; +use phpOMS\DataStorage\Database\RelationType; + +class NewsArticleMapper extends DataMapperAbstract +{ + + /** + * Columns. + * + * @var array + * @since 1.0.0 + */ + static protected $columns = [ + 'news_id' => ['name' => 'news_id', 'type' => 'int', 'internal' => 'id'], + 'news_created_by' => ['name' => 'news_created_by', 'type' => 'string', 'internal' => 'createdBy'], + 'news_publish' => ['name' => 'news_publish', 'type' => 'DateTime', 'internal' => 'publish'], + 'news_title' => ['name' => 'news_title', 'type' => 'string', 'internal' => 'title'], + 'news_plain' => ['name' => 'news_plain', 'type' => 'string', 'internal' => 'plain'], + 'news_content' => ['name' => 'news_content', 'type' => 'string', 'internal' => 'content'], + 'news_lang' => ['name' => 'news_lang', 'type' => 'string', 'internal' => 'language'], + 'news_status' => ['name' => 'news_status', 'type' => 'int', 'internal' => 'status'], + 'news_type' => ['name' => 'news_type', 'type' => 'int', 'internal' => 'type'], + 'news_featured' => ['name' => 'news_featured', 'type' => 'bool', 'internal' => 'featured'], + 'news_created_at' => ['name' => 'news_created_at', 'type' => 'DateTime', 'internal' => 'createdAt'], + ]; + + static protected $belongsTo = [ + 'createdBy' => [ + 'mapper' => AccountMapper::class, + 'src' => 'news_created_by', + ], + ]; + + /** + * Primary table. + * + * @var string + * @since 1.0.0 + */ + protected static $table = 'news'; + + /** + * Primary field name. + * + * @var string + * @since 1.0.0 + */ + protected static $primaryField = 'news_id'; + + /** + * Created at. + * + * @var string + * @since 1.0.0 + */ + protected static $createdAt = 'news_created_at'; + + /** + * 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); + $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(), 'news', 'news', 1, $objId, 1, 1, 1, 1, 1); + + self::$db->con->prepare($query->toSql())->execute(); + } catch (\Exception $e) { + 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', '=', 'news') + ->where('account_permission.account_permission_id1', '=', 1) + ->where('news.news_id', '=', new Column('account_permission.account_permission_id2')) + ->where('account_permission.account_permission_r', '=', 1); + } +} diff --git a/Models/NewsStatus.php b/Models/NewsStatus.php new file mode 100644 index 0000000..0e46e3b --- /dev/null +++ b/Models/NewsStatus.php @@ -0,0 +1,36 @@ + + * @author Dennis Eichhorn + * @copyright Dennis Eichhorn + * @license OMS License 1.0 + * @version 1.0.0 + * @link http://orange-management.com + */ +namespace Modules\News\Models; + +use phpOMS\Datatypes\Enum; + +/** + * News type status. + * + * @category Module + * @package Modules\News + * @author OMS Development Team + * @author Dennis Eichhorn + * @license OMS License 1.0 + * @link http://orange-management.com + * @since 1.0.0 + */ +abstract class NewsStatus extends Enum +{ + /* public */ const VISIBLE = 0; + + /* public */ const DRAFT = 1; +} diff --git a/Models/NewsType.php b/Models/NewsType.php new file mode 100644 index 0000000..49a9557 --- /dev/null +++ b/Models/NewsType.php @@ -0,0 +1,38 @@ + + * @author Dennis Eichhorn + * @copyright Dennis Eichhorn + * @license OMS License 1.0 + * @version 1.0.0 + * @link http://orange-management.com + */ +namespace Modules\News\Models; + +use phpOMS\Datatypes\Enum; + +/** + * News type enum. + * + * @category Module + * @package Modules\News + * @author OMS Development Team + * @author Dennis Eichhorn + * @license OMS License 1.0 + * @link http://orange-management.com + * @since 1.0.0 + */ +abstract class NewsType extends Enum +{ + /* public */ const ARTICLE = 0; + + /* public */ const LINK = 1; + + /* public */ const HEADLINE = 2; +} 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/Navigation.en.lang.php b/Theme/Backend/Lang/Navigation.en.lang.php new file mode 100644 index 0000000..dd07e4a --- /dev/null +++ b/Theme/Backend/Lang/Navigation.en.lang.php @@ -0,0 +1,21 @@ + + * @author Dennis Eichhorn + * @copyright Dennis Eichhorn + * @license OMS License 1.0 + * @version 1.0.0 + * @link http://orange-management.com + */ +return ['Navigation' => [ + 'Archive' => 'Archive', + 'Create' => 'Create', + 'Draft' => 'Draft', + 'News' => 'News', +]]; diff --git a/Theme/Backend/Lang/en.lang.php b/Theme/Backend/Lang/en.lang.php new file mode 100644 index 0000000..09b3b62 --- /dev/null +++ b/Theme/Backend/Lang/en.lang.php @@ -0,0 +1,40 @@ + + * @author Dennis Eichhorn + * @copyright Dennis Eichhorn + * @license OMS License 1.0 + * @version 1.0.0 + * @link http://orange-management.com + */ +return ['News' => [ + 'Additional' => 'Additional', + 'Archive' => 'Archive', + 'Author' => 'Author', + 'Date' => 'Date', + 'Draft' => 'Draft', + 'Featured' => 'Featured', + 'Groups' => 'Groups', + 'Headline' => 'Headline', + 'Headlines' => 'Headlines', + 'Link' => 'Link', + 'News' => 'News', + 'Permissions' => 'Permissions', + 'Plain' => 'Plain', + 'Preview' => 'Preview', + 'Publish' => 'Publish', + 'Settings' => 'Settings', + 'Status' => 'Status', + 'Title' => 'Title', + 'Type' => 'Type', + 'Visible' => 'Visible', + 'TYPE0' => 'Article', + 'TYPE1' => 'Link', + 'TYPE2' => 'Headline', +]]; diff --git a/Theme/Backend/dashboard-news.tpl.php b/Theme/Backend/dashboard-news.tpl.php new file mode 100644 index 0000000..02a9b4b --- /dev/null +++ b/Theme/Backend/dashboard-news.tpl.php @@ -0,0 +1,3 @@ +
+News +
\ No newline at end of file diff --git a/Theme/Backend/news-archive.tpl.php b/Theme/Backend/news-archive.tpl.php new file mode 100644 index 0000000..c327a27 --- /dev/null +++ b/Theme/Backend/news-archive.tpl.php @@ -0,0 +1,50 @@ + + * @author Dennis Eichhorn + * @copyright Dennis Eichhorn + * @license OMS License 1.0 + * @version 1.0.0 + * @link http://orange-management.com + */ +/** + * @var \phpOMS\Views\View $this + */ + +$footerView = new \Web\Views\Lists\PaginationView($this->app, $this->request, $this->response); +$footerView->setTemplate('/Web/Templates/Lists/Footer/PaginationBig'); +$footerView->setPages(20); +$footerView->setPage(1); + +echo $this->getData('nav')->render(); ?> + +
+
+
+ + + + + + + + $value) : $count++; ?> + + +
getText('Archive') ?>
getText('Type'); ?> + getText('Title'); ?> + getText('Author'); ?> + getText('Date'); ?> +
render(); ?> +
getText('Empty', 0, 0); ?> + +
+
+
+
diff --git a/Theme/Backend/news-create.tpl.php b/Theme/Backend/news-create.tpl.php new file mode 100644 index 0000000..698fa06 --- /dev/null +++ b/Theme/Backend/news-create.tpl.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 + */ +/** + * @var \phpOMS\Views\View $this + */ +echo $this->getData('nav')->render(); ?> + +
+
+ +
+ +
+
+
+
+ +
+
+
+
+
+
+
+
+
+
+ +
+
+
+
+
+
+
+
+
+ +
+
+
+
+
+
+
+
+ +
+
+
+
+
+
+
+
diff --git a/Theme/Backend/news-dashboard.tpl.php b/Theme/Backend/news-dashboard.tpl.php new file mode 100644 index 0000000..d126d6e --- /dev/null +++ b/Theme/Backend/news-dashboard.tpl.php @@ -0,0 +1,57 @@ + + * @author Dennis Eichhorn + * @copyright Dennis Eichhorn + * @license OMS License 1.0 + * @version 1.0.0 + * @link http://orange-management.com + */ +/** + * @var \phpOMS\Views\View $this + */ + +$newsList = $this->getData('news'); + +echo $this->getData('nav')->render(); ?> + +
+
+
+ + + + + + $news) : $count++; + $url = \phpOMS\Uri\UriFactory::build('/{/lang}/backend/news/article?{?}&id=' . $news->getId()); + $color = 'darkred'; + if($news->getType() === \Modules\News\Models\NewsType::ARTICLE) { $color = 'green'; } + elseif($news->getType() === \Modules\News\Models\NewsType::HEADLINE) { $color = 'purple'; } + elseif($news->getType() === \Modules\News\Models\NewsType::LINK) { $color = 'yellow'; } + ?> + +
getText('News') ?>
+ getText('Type'); ?> + getText('Title'); ?> + getText('Author'); ?> + getText('Date'); ?> +
isFeatured() ? '' : ''; ?> + getText('TYPE' . $news->getType()); ?> + getTitle(); ?> + getCreatedBy(); ?> + getPublish()->format('Y-m-d'); ?> + + +
getText('Empty', 0, 0); ?> + +
+
+
+
diff --git a/Theme/Backend/news-single.tpl.php b/Theme/Backend/news-single.tpl.php new file mode 100644 index 0000000..f28ce18 --- /dev/null +++ b/Theme/Backend/news-single.tpl.php @@ -0,0 +1,34 @@ + + * @author Dennis Eichhorn + * @copyright Dennis Eichhorn + * @license OMS License 1.0 + * @version 1.0.0 + * @link http://orange-management.com + */ +/** + * @var \phpOMS\Views\View $this + */ + +$news = $this->getData('news'); + +echo $this->getData('nav')->render(); ?> +
+
+
+

getTitle(); ?>

+
+
+ getContent(); ?> +
+
+
+
+
\ No newline at end of file diff --git a/img/module_teaser_small.png b/img/module_teaser_small.png new file mode 100644 index 0000000..f56e6ff 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..c713861 --- /dev/null +++ b/info.json @@ -0,0 +1,45 @@ +{ + "name": { + "id": 1000600000, + "internal": "News", + "external": "OMS News" + }, + "version": "1.0.0", + "requirements": { + "phpOMS": "1.0.0", + "phpOMS-db": "1.0.0" + }, + "creator": { + "name": "Orange Management", + "website": "www.spl1nes.com" + }, + "description": "News module.", + "directory": "News", + "dependencies": { + "Admin" : "1.0.0" + }, + "providing": { + "Navigation": "*" + }, + "load": [ + { + "pid": [ + "d7470914e19522acc310a55e5cb13a6f0f7ca000", + "0ac9153b72f8659e3c4b370f56bbcdf0eba86d6a" + ], + "type": 4, + "for": 0, + "from": "News", + "file": "News" + }, + { + "pid": [ + "754a08ddf8bcb1cf22f310f09206dd783d42f7dd" + ], + "type": 5, + "from": "News", + "for": "Navigation", + "file": "Navigation" + } + ] +}