diff --git a/Admin/Activate.php b/Admin/Activate.php index 4301169..b493777 100644 --- a/Admin/Activate.php +++ b/Admin/Activate.php @@ -2,7 +2,7 @@ /** * Orange Management * - * PHP Version 7.0 + * PHP Version 7.1 * * @category TBD * @package TBD @@ -16,7 +16,7 @@ namespace Modules\News\Admin; -use phpOMS\DataStorage\Database\Pool; +use phpOMS\DataStorage\Database\DatabasePool; use phpOMS\Module\ActivateAbstract; use phpOMS\Module\InfoManager; @@ -37,7 +37,7 @@ class Activate extends ActivateAbstract /** * {@inheritdoc} */ - public static function activate(Pool $dbPool, InfoManager $info) + public static function activate(DatabasePool $dbPool, InfoManager $info) { parent::activate($dbPool, $info); } diff --git a/Admin/Deactivate.php b/Admin/Deactivate.php index c511070..6066416 100644 --- a/Admin/Deactivate.php +++ b/Admin/Deactivate.php @@ -2,7 +2,7 @@ /** * Orange Management * - * PHP Version 7.0 + * PHP Version 7.1 * * @category TBD * @package TBD @@ -16,7 +16,7 @@ namespace Modules\News\Admin; -use phpOMS\DataStorage\Database\Pool; +use phpOMS\DataStorage\Database\DatabasePool; use phpOMS\Module\DeactivateAbstract; use phpOMS\Module\InfoManager; @@ -37,7 +37,7 @@ class Deactivate extends DeactivateAbstract /** * {@inheritdoc} */ - public static function deactivate(Pool $dbPool, InfoManager $info) + public static function deactivate(DatabasePool $dbPool, InfoManager $info) { parent::deactivate($dbPool, $info); } diff --git a/Admin/Install/Navigation.php b/Admin/Install/Navigation.php index 4cb1d28..6291373 100644 --- a/Admin/Install/Navigation.php +++ b/Admin/Install/Navigation.php @@ -2,7 +2,7 @@ /** * Orange Management * - * PHP Version 7.0 + * PHP Version 7.1 * * @category TBD * @package TBD @@ -14,7 +14,7 @@ * @link http://orange-management.com */ namespace Modules\News\Admin\Install; -use phpOMS\DataStorage\Database\Pool; +use phpOMS\DataStorage\Database\DatabasePool; /** * Navigation class. @@ -29,7 +29,7 @@ use phpOMS\DataStorage\Database\Pool; */ class Navigation { - public static function install(Pool $dbPool) + public static function install(string $path, DatabasePool $dbPool) { $navData = json_decode(file_get_contents(__DIR__ . '/Navigation.install.json'), true); diff --git a/Admin/Installer.php b/Admin/Installer.php index 3a30e24..d414688 100644 --- a/Admin/Installer.php +++ b/Admin/Installer.php @@ -2,7 +2,7 @@ /** * Orange Management * - * PHP Version 7.0 + * PHP Version 7.1 * * @category TBD * @package TBD @@ -16,7 +16,7 @@ namespace Modules\News\Admin; use phpOMS\DataStorage\Database\DatabaseType; -use phpOMS\DataStorage\Database\Pool; +use phpOMS\DataStorage\Database\DatabasePool; use phpOMS\Module\InfoManager; use phpOMS\Module\InstallerAbstract; @@ -37,9 +37,9 @@ class Installer extends InstallerAbstract /** * {@inheritdoc} */ - public static function install(Pool $dbPool, InfoManager $info) + public static function install(string $path, DatabasePool $dbPool, InfoManager $info) { - parent::install($dbPool, $info); + parent::install($path, $dbPool, $info); switch ($dbPool->get('core')->getType()) { case DatabaseType::MYSQL: @@ -49,6 +49,7 @@ class Installer extends InstallerAbstract `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, 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 index 09312f9..9d7e386 100644 --- a/Admin/Routes/Web/Backend.php +++ b/Admin/Routes/Web/Backend.php @@ -27,11 +27,4 @@ return [ 'verb' => RouteVerb::GET, ], ], - - '^.*/api/news.*$' => [ - [ - 'dest' => '\Modules\News\Controller:apiNewsCreate', - 'verb' => RouteVerb::SET, - ], - ], ]; diff --git a/Admin/Uninstall.php b/Admin/Uninstall.php index aa056c3..389019a 100644 --- a/Admin/Uninstall.php +++ b/Admin/Uninstall.php @@ -2,7 +2,7 @@ /** * Orange Management * - * PHP Version 7.0 + * PHP Version 7.1 * * @category TBD * @package TBD @@ -16,7 +16,7 @@ namespace Modules\News\Admin; -use phpOMS\DataStorage\Database\Pool; +use phpOMS\DataStorage\Database\DatabasePool; use phpOMS\DataStorage\Database\Schema\Builder; use phpOMS\Module\UninstallAbstract; @@ -37,7 +37,7 @@ class Uninstall extends UninstallAbstract /** * {@inheritdoc} */ - public static function uninstall(Pool $dbPool, InfoManager $info) + public static function uninstall(DatabasePool $dbPool, InfoManager $info) { parent::uninstall($dbPool, $info); diff --git a/Admin/Update.php b/Admin/Update.php index 6d60a87..26adeab 100644 --- a/Admin/Update.php +++ b/Admin/Update.php @@ -2,7 +2,7 @@ /** * Orange Management * - * PHP Version 7.0 + * PHP Version 7.1 * * @category TBD * @package TBD @@ -16,7 +16,7 @@ namespace Modules\News\Admin; -use phpOMS\DataStorage\Database\Pool; +use phpOMS\DataStorage\Database\DatabasePool; use phpOMS\Module\UpdateAbstract; use phpOMS\System\File\Directory; @@ -37,7 +37,7 @@ class Update extends UpdateAbstract /** * {@inheritdoc} */ - public static function update(Pool $dbPool, array $info) + public static function update(DatabasePool $dbPool, array $info) { Directory::deletePath(__DIR__ . '/Update'); mkdir('Update'); diff --git a/Controller.php b/Controller.php index 5f72cc1..dd36927 100644 --- a/Controller.php +++ b/Controller.php @@ -2,7 +2,7 @@ /** * Orange Management * - * PHP Version 7.0 + * PHP Version 7.1 * * @category TBD * @package TBD @@ -15,13 +15,18 @@ */ 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; /** @@ -44,7 +49,7 @@ class Controller extends ModuleAbstract implements WebInterface * @var string * @since 1.0.0 */ - const MODULE_PATH = __DIR__; + /* public */ const MODULE_PATH = __DIR__; /** * Module version. @@ -52,7 +57,7 @@ class Controller extends ModuleAbstract implements WebInterface * @var string * @since 1.0.0 */ - const MODULE_VERSION = '1.0.0'; + /* public */ const MODULE_VERSION = '1.0.0'; /** * Module name. @@ -60,7 +65,7 @@ class Controller extends ModuleAbstract implements WebInterface * @var string * @since 1.0.0 */ - const MODULE_NAME = 'News'; + /* public */ const MODULE_NAME = 'News'; /** * Providing. @@ -161,6 +166,31 @@ class Controller extends ModuleAbstract implements WebInterface 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 @@ -171,15 +201,23 @@ class Controller extends ModuleAbstract implements WebInterface */ 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($requst->getAccount()->getId()); + $newsArticle->setCreatedBy($request->getAccount()); $newsArticle->setCreatedAt(new \DateTime('now')); - $newsArticle->setPublish((bool) ($request->getData('publish') ?? false)); + $newsArticle->setPublish(new \DateTime($request->getData('publish') ?? false)); $newsArticle->setTitle($request->getData('title') ?? ''); $newsArticle->setPlain($request->getData('plain') ?? ''); - $newsArticle->setContent($request->getData('content') ?? ''); - $newsArticle->setLanguage($request->getData('lang') ?? $request->getL11n()->getLanguage()); - $newsArticle->setType((int) ($requst->getData('type') ?? 1)); + $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)); diff --git a/Models/NewsArticle.php b/Models/NewsArticle.php index 8d6fa40..3ad2beb 100644 --- a/Models/NewsArticle.php +++ b/Models/NewsArticle.php @@ -2,7 +2,7 @@ /** * Orange Management * - * PHP Version 7.0 + * PHP Version 7.1 * * @category TBD * @package TBD @@ -15,6 +15,7 @@ */ namespace Modules\News\Models; +use phpOMS\Contract\ArrayableInterface; use phpOMS\Datatypes\Exception\InvalidEnumValue; use phpOMS\Localization\ISO639x1Enum; @@ -56,6 +57,14 @@ class NewsArticle implements ArrayableInterface, \JsonSerializable */ private $content = ''; + /** + * Unparsed. + * + * @var string + * @since 1.0.0 + */ + private $plain = ''; + /** * News type. * @@ -148,6 +157,30 @@ class NewsArticle implements ArrayableInterface, \JsonSerializable $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 * @@ -325,7 +358,7 @@ class NewsArticle implements ArrayableInterface, \JsonSerializable * * @return void * - * @throws + * @throws InvalidEnumValue * * @since 1.0.0 * @author Dennis Eichhorn @@ -381,11 +414,11 @@ class NewsArticle implements ArrayableInterface, \JsonSerializable public function __toString() { - return $this->jsonSerialize(); + return json_encode($this->toArray()); } public function jsonSerialize() { - return json_encode($this->toArray()); + return $this->toArray(); } } diff --git a/Models/NewsArticleMapper.php b/Models/NewsArticleMapper.php index 289fa36..47edc4d 100644 --- a/Models/NewsArticleMapper.php +++ b/Models/NewsArticleMapper.php @@ -2,7 +2,7 @@ /** * Orange Management * - * PHP Version 7.0 + * PHP Version 7.1 * * @category TBD * @package TBD @@ -15,6 +15,7 @@ */ 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; @@ -26,7 +27,7 @@ class NewsArticleMapper extends DataMapperAbstract /** * Columns. * - * @var array + * @var array * @since 1.0.0 */ static protected $columns = [ @@ -34,6 +35,7 @@ class NewsArticleMapper extends DataMapperAbstract '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'], @@ -42,6 +44,13 @@ class NewsArticleMapper extends DataMapperAbstract 'news_created_at' => ['name' => 'news_created_at', 'type' => 'DateTime', 'internal' => 'createdAt'], ]; + static protected $belongsTo = [ + 'createdBy' => [ + 'mapper' => AccountMapper::class, + 'src' => 'news_created_by', + ], + ]; + /** * Primary table. * @@ -83,20 +92,20 @@ class NewsArticleMapper extends DataMapperAbstract $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); + ->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) { @@ -119,9 +128,9 @@ class NewsArticleMapper extends DataMapperAbstract 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); + ->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 index 64dc3c0..0e46e3b 100644 --- a/Models/NewsStatus.php +++ b/Models/NewsStatus.php @@ -2,7 +2,7 @@ /** * Orange Management * - * PHP Version 7.0 + * PHP Version 7.1 * * @category TBD * @package TBD @@ -30,7 +30,7 @@ use phpOMS\Datatypes\Enum; */ abstract class NewsStatus extends Enum { - const VISIBLE = 0; + /* public */ const VISIBLE = 0; - const DRAFT = 1; + /* public */ const DRAFT = 1; } diff --git a/Models/NewsType.php b/Models/NewsType.php index 7e6e891..49a9557 100644 --- a/Models/NewsType.php +++ b/Models/NewsType.php @@ -2,7 +2,7 @@ /** * Orange Management * - * PHP Version 7.0 + * PHP Version 7.1 * * @category TBD * @package TBD @@ -30,9 +30,9 @@ use phpOMS\Datatypes\Enum; */ abstract class NewsType extends Enum { - const ARTICLE = 0; + /* public */ const ARTICLE = 0; - const LINK = 1; + /* public */ const LINK = 1; - const HEADLINE = 2; + /* public */ const HEADLINE = 2; } diff --git a/Theme/Backend/Lang/en.lang.php b/Theme/Backend/Lang/en.lang.php index 55b12de..09b3b62 100644 --- a/Theme/Backend/Lang/en.lang.php +++ b/Theme/Backend/Lang/en.lang.php @@ -2,7 +2,7 @@ /** * Orange Management * - * PHP Version 7.0 + * PHP Version 7.1 * * @category TBD * @package TBD diff --git a/Theme/Backend/dashboard-news.tpl.php b/Theme/Backend/dashboard-news.tpl.php index c154c7d..02a9b4b 100644 --- a/Theme/Backend/dashboard-news.tpl.php +++ b/Theme/Backend/dashboard-news.tpl.php @@ -1,3 +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 index 043e533..42d7cdd 100644 --- a/Theme/Backend/news-archive.tpl.php +++ b/Theme/Backend/news-archive.tpl.php @@ -2,7 +2,7 @@ /** * Orange Management * - * PHP Version 7.0 + * PHP Version 7.1 * * @category TBD * @package TBD diff --git a/Theme/Backend/news-create.tpl.php b/Theme/Backend/news-create.tpl.php index a9becd4..415a2bc 100644 --- a/Theme/Backend/news-create.tpl.php +++ b/Theme/Backend/news-create.tpl.php @@ -2,7 +2,7 @@ /** * Orange Management * - * PHP Version 7.0 + * PHP Version 7.1 * * @category TBD * @package TBD @@ -19,56 +19,50 @@ echo $this->getData('nav')->render(); ?>
- +
-
+
-
-
+
-
- -
-
-
-
-
-
+ +
+
+
+
+
-
- -
-
-
-
-
+ +
+
+
+
-
- -
-
-
-
-
+ +
+
+
+
diff --git a/Theme/Backend/news-dashboard.tpl.php b/Theme/Backend/news-dashboard.tpl.php index 386795c..e0fdba6 100644 --- a/Theme/Backend/news-dashboard.tpl.php +++ b/Theme/Backend/news-dashboard.tpl.php @@ -2,7 +2,7 @@ /** * Orange Management * - * PHP Version 7.0 + * PHP Version 7.1 * * @category TBD * @package TBD @@ -31,20 +31,20 @@ echo $this->getData('nav')->render(); ?> getText('Title'); ?> getText('Author'); ?> getText('Date'); ?> - - $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'; } - ?> - - isFeatured() ? '' : ''; ?> - getText('TYPE' . $news->getType()); ?> - getTitle(); ?> - getCreatedBy(); ?> - getPublish()->format('Y-m-d'); ?> + + $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'; } + ?> + + 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 index 8933d1b..eb28f1c 100644 --- a/Theme/Backend/news-single.tpl.php +++ b/Theme/Backend/news-single.tpl.php @@ -2,7 +2,7 @@ /** * Orange Management * - * PHP Version 7.0 + * PHP Version 7.1 * * @category TBD * @package TBD diff --git a/Theme/backend/Lang/Navigation.en.lang.php b/Theme/backend/Lang/Navigation.en.lang.php index eea82e3..dd07e4a 100644 --- a/Theme/backend/Lang/Navigation.en.lang.php +++ b/Theme/backend/Lang/Navigation.en.lang.php @@ -2,7 +2,7 @@ /** * Orange Management * - * PHP Version 7.0 + * PHP Version 7.1 * * @category TBD * @package TBD