Bulkl path fix reverse

This commit is contained in:
Dennis Eichhorn 2017-02-12 21:43:10 +01:00
parent e8ab89e396
commit 90d1ec22c0
26 changed files with 1700 additions and 0 deletions

44
Admin/Activate.php Normal file
View File

@ -0,0 +1,44 @@
<?php
/**
* Orange Management
*
* PHP Version 7.1
*
* @category TBD
* @package TBD
* @author OMS Development Team <dev@oms.com>
* @author Dennis Eichhorn <d.eichhorn@oms.com>
* @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 <dev@oms.com>
* @author Dennis Eichhorn <d.eichhorn@oms.com>
* @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);
}
}

44
Admin/Deactivate.php Normal file
View File

@ -0,0 +1,44 @@
<?php
/**
* Orange Management
*
* PHP Version 7.1
*
* @category TBD
* @package TBD
* @author OMS Development Team <dev@oms.com>
* @author Dennis Eichhorn <d.eichhorn@oms.com>
* @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 <dev@oms.com>
* @author Dennis Eichhorn <d.eichhorn@oms.com>
* @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);
}
}

View File

@ -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": []
}
]
}
]

View File

@ -0,0 +1,40 @@
<?php
/**
* Orange Management
*
* PHP Version 7.1
*
* @category TBD
* @package TBD
* @author OMS Development Team <dev@oms.com>
* @author Dennis Eichhorn <d.eichhorn@oms.com>
* @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 <dev@oms.com>
* @author Dennis Eichhorn <d.eichhorn@oms.com>
* @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);
}
}

101
Admin/Installer.php Normal file
View File

@ -0,0 +1,101 @@
<?php
/**
* Orange Management
*
* PHP Version 7.1
*
* @category TBD
* @package TBD
* @author OMS Development Team <dev@oms.com>
* @author Dennis Eichhorn <d.eichhorn@oms.com>
* @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 <dev@oms.com>
* @author Dennis Eichhorn <d.eichhorn@oms.com>
* @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;
}
}
}

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

@ -0,0 +1,12 @@
<?php
use phpOMS\Router\RouteVerb;
return [
'^.*/api/news.*$' => [
[
'dest' => '\Modules\News\Controller:apiNewsCreate',
'verb' => RouteVerb::SET,
],
],
];

View File

@ -0,0 +1,30 @@
<?php
use phpOMS\Router\RouteVerb;
return [
'^.*/backend/news/dashboard.*$' => [
[
'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,
],
],
];

3
Admin/Routes/console.php Normal file
View File

@ -0,0 +1,3 @@
<?php
$moduleRoutes = [];

3
Admin/Routes/socket.php Normal file
View File

@ -0,0 +1,3 @@
<?php
$moduleRoutes = [];

54
Admin/Uninstall.php Normal file
View File

@ -0,0 +1,54 @@
<?php
/**
* Orange Management
*
* PHP Version 7.1
*
* @category TBD
* @package TBD
* @author OMS Development Team <dev@oms.com>
* @author Dennis Eichhorn <d.eichhorn@oms.com>
* @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 <dev@oms.com>
* @author Dennis Eichhorn <d.eichhorn@oms.com>
* @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();
}
}

46
Admin/Update.php Normal file
View File

@ -0,0 +1,46 @@
<?php
/**
* Orange Management
*
* PHP Version 7.1
*
* @category TBD
* @package TBD
* @author OMS Development Team <dev@oms.com>
* @author Dennis Eichhorn <d.eichhorn@oms.com>
* @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 <dev@oms.com>
* @author Dennis Eichhorn <d.eichhorn@oms.com>
* @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);
}
}

289
Controller.php Normal file
View File

@ -0,0 +1,289 @@
<?php
/**
* Orange Management
*
* PHP Version 7.1
*
* @category TBD
* @package TBD
* @author OMS Development Team <dev@oms.com>
* @author Dennis Eichhorn <d.eichhorn@oms.com>
* @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 <dev@oms.com>
* @author Dennis Eichhorn <d.eichhorn@oms.com>
* @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 <d.eichhorn@oms.com>
*/
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 <d.eichhorn@oms.com>
*/
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 <d.eichhorn@oms.com>
*/
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 <d.eichhorn@oms.com>
*/
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 <d.eichhorn@oms.com>
*/
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 <d.eichhorn@oms.com>
*/
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 <d.eichhorn@oms.com>
*/
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);
}
}

424
Models/NewsArticle.php Normal file
View File

@ -0,0 +1,424 @@
<?php
/**
* Orange Management
*
* PHP Version 7.1
*
* @category TBD
* @package TBD
* @author OMS Development Team <dev@oms.com>
* @author Dennis Eichhorn <d.eichhorn@oms.com>
* @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 <dev@oms.com>
* @author Dennis Eichhorn <d.eichhorn@oms.com>
* @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 <d.eichhorn@oms.com>
*/
public function __construct()
{
$this->createdAt = new \DateTime('NOW');
$this->publish = new \DateTime('NOW');
}
/**
* @return string
*
* @since 1.0.0
* @author Dennis Eichhorn <d.eichhorn@oms.com>
*/
public function getContent() : string
{
return $this->content;
}
/**
* @param string $content
*
* @return void
*
* @since 1.0.0
* @author Dennis Eichhorn <d.eichhorn@oms.com>
*/
public function setContent(string $content)
{
$this->content = $content;
}
/**
* @param string $plain
*
* @return void
*
* @since 1.0.0
* @author Dennis Eichhorn <d.eichhorn@oms.com>
*/
public function setPlain(string $plain)
{
$this->plain = $plain;
}
/**
* @return string
*
* @since 1.0.0
* @author Dennis Eichhorn <d.eichhorn@oms.com>
*/
public function getPlain() : string
{
return $this->plain;
}
/**
* @return \DateTime
*
* @since 1.0.0
* @author Dennis Eichhorn <d.eichhorn@oms.com>
*/
public function getCreatedAt() : \DateTime
{
return $this->createdAt;
}
/**
* @return int
*
* @since 1.0.0
* @author Dennis Eichhorn <d.eichhorn@oms.com>
*/
public function getId() : int
{
return $this->id;
}
/**
* @return string
*
* @since 1.0.0
* @author Dennis Eichhorn <d.eichhorn@oms.com>
*/
public function getLanguage() : string
{
return $this->language;
}
/**
* @return \DateTime
*
* @since 1.0.0
* @author Dennis Eichhorn <d.eichhorn@oms.com>
*/
public function getPublish() : \DateTime
{
return $this->publish;
}
/**
* @param string $language
*
* @return void
*
* @since 1.0.0
* @author Dennis Eichhorn <d.eichhorn@oms.com>
*/
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 <d.eichhorn@oms.com>
*/
public function setPublish(\DateTime $publish)
{
$this->publish = $publish;
}
/**
* @return int
*
* @since 1.0.0
* @author Dennis Eichhorn <d.eichhorn@oms.com>
*/
public function getCreatedBy() : int
{
return $this->createdBy;
}
/**
* @param int $id
*
* @since 1.0.0
* @author Dennis Eichhorn <d.eichhorn@oms.com>
*/
public function setCreatedBy(int $id)
{
$this->createdBy = $id;
}
/**
* @param \DateTime $createdAt
*
* @return void
*
* @since 1.0.0
* @author Dennis Eichhorn <d.eichhorn@oms.com>
*/
public function setCreatedAt(\DateTime $createdAt)
{
$this->createdAt = $createdAt;
}
/**
* @return string
*
* @since 1.0.0
* @author Dennis Eichhorn <d.eichhorn@oms.com>
*/
public function getTitle() : string
{
return $this->title;
}
/**
* @param string $title
*
* @return mixed
*
* @since 1.0.0
* @author Dennis Eichhorn <d.eichhorn@oms.com>
*/
public function setTitle(string $title)
{
$this->title = $title;
}
/**
* @return int
*
* @since 1.0.0
* @author Dennis Eichhorn <d.eichhorn@oms.com>
*/
public function getType() : int
{
return $this->type;
}
/**
* @param int $type
*
* @return void
*
* @since 1.0.0
* @author Dennis Eichhorn <d.eichhorn@oms.com>
*/
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 <d.eichhorn@oms.com>
*/
public function getStatus() : int
{
return $this->status;
}
/**
* @param int $status
*
* @return void
*
* @throws InvalidEnumValue
*
* @since 1.0.0
* @author Dennis Eichhorn <d.eichhorn@oms.com>
*/
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 <d.eichhorn@oms.com>
*/
public function isFeatured() : bool
{
return $this->featured;
}
/**
* @param bool $featured
*
* @return void
*
* @since 1.0.0
* @author Dennis Eichhorn <d.eichhorn@oms.com>
*/
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();
}
}

View File

@ -0,0 +1,136 @@
<?php
/**
* Orange Management
*
* PHP Version 7.1
*
* @category TBD
* @package TBD
* @author OMS Development Team <dev@oms.com>
* @author Dennis Eichhorn <d.eichhorn@oms.com>
* @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 <d.eichhorn@oms.com>
*/
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 <d.eichhorn@oms.com>
*/
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);
}
}

36
Models/NewsStatus.php Normal file
View File

@ -0,0 +1,36 @@
<?php
/**
* Orange Management
*
* PHP Version 7.1
*
* @category TBD
* @package TBD
* @author OMS Development Team <dev@oms.com>
* @author Dennis Eichhorn <d.eichhorn@oms.com>
* @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 <dev@oms.com>
* @author Dennis Eichhorn <d.eichhorn@oms.com>
* @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;
}

38
Models/NewsType.php Normal file
View File

@ -0,0 +1,38 @@
<?php
/**
* Orange Management
*
* PHP Version 7.1
*
* @category TBD
* @package TBD
* @author OMS Development Team <dev@oms.com>
* @author Dennis Eichhorn <d.eichhorn@oms.com>
* @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 <dev@oms.com>
* @author Dennis Eichhorn <d.eichhorn@oms.com>
* @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;
}

1
README.md Normal file
View File

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

View File

@ -0,0 +1,21 @@
<?php
/**
* Orange Management
*
* PHP Version 7.1
*
* @category TBD
* @package TBD
* @author OMS Development Team <dev@oms.com>
* @author Dennis Eichhorn <d.eichhorn@oms.com>
* @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',
]];

View File

@ -0,0 +1,40 @@
<?php
/**
* Orange Management
*
* PHP Version 7.1
*
* @category TBD
* @package TBD
* @author OMS Development Team <dev@oms.com>
* @author Dennis Eichhorn <d.eichhorn@oms.com>
* @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',
]];

View File

@ -0,0 +1,3 @@
<section id="news-dashboard" draggable>
News
</section>

View File

@ -0,0 +1,50 @@
<?php
/**
* Orange Management
*
* PHP Version 7.1
*
* @category TBD
* @package TBD
* @author OMS Development Team <dev@oms.com>
* @author Dennis Eichhorn <d.eichhorn@oms.com>
* @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(); ?>
<div class="row">
<div class="col-xs-12">
<div class="box wf-100">
<table class="table">
<caption><?= $this->getText('Archive') ?></caption>
<thead>
<tr>
<td><?= $this->getText('Type'); ?>
<td class="wf-100"><?= $this->getText('Title'); ?>
<td><?= $this->getText('Author'); ?>
<td><?= $this->getText('Date'); ?>
<tfoot>
<tr>
<td colspan="4"><?= $footerView->render(); ?>
<tbody>
<?php $count = 0; foreach([] as $key => $value) : $count++; ?>
<?php endforeach; ?>
<?php if($count === 0) : ?>
<tr><td colspan="4" class="empty"><?= $this->getText('Empty', 0, 0); ?>
<?php endif; ?>
</table>
</div>
</div>
</div>

View File

@ -0,0 +1,71 @@
<?php
/**
* Orange Management
*
* PHP Version 7.1
*
* @category TBD
* @package TBD
* @author OMS Development Team <dev@oms.com>
* @author Dennis Eichhorn <d.eichhorn@oms.com>
* @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(); ?>
<div class="row">
<div class="col-xs-12 col-md-9">
<?php include __DIR__ . '/../../../Editor/Theme/Backend/editor.tpl.php'; ?>
</div>
<div class="col-xs-12 col-md-3">
<section class="box wf-100">
<div class="inner">
<form id="docForm" method="POST" action="<?= \phpOMS\Uri\UriFactory::build('/{/lang}/api/news?{?}&csrf={$CSRF}'); ?>">
<table class="layout wf-100">
<tr><td colspan="2"><label for="publish"><?= $this->getText('Status') ?></label>
<tr><td colspan="2"><select name="status">
<option value="<?= Modules\News\Models\NewsStatus::DRAFT; ?>" selected><?= $this->getText('Draft') ?>
<option value="<?= Modules\News\Models\NewsStatus::VISIBLE; ?>"><?= $this->getText('Visible') ?>
<tr><td colspan="2"><label for="publish"><?= $this->getText('Publish') ?></label>
<tr><td colspan="2"><input type="datetime-local" id="publish" value="<?= (new \DateTime('NOW'))->format('Y-m-d\TH:i:s') ?>">
<tr><td><input type="submit" value="<?= $this->getText('Delete', 0) ?>"><td class="rightText"><input type="submit" value="<?= $this->getText('Save', 0) ?>"> <input type="submit" value="<?= $this->getText('Publish') ?>">
</table>
</form>
</div>
</section>
<section class="box wf-100">
<div class="inner">
<table class="layout wf-100">
<tr><td colspan="2"><label><?= $this->getText('Type') ?></label>
<tr><td colspan="2"><span class="radio"><input type="radio" name="type" form="docForm" value="<?= Modules\News\Models\NewsType::ARTICLE; ?>" id="news" checked><label for="news"><?= $this->getText('News') ?></label></span>
<tr><td colspan="2"><span class="radio"><input type="radio" name="type" form="docForm" value="<?= Modules\News\Models\NewsType::HEADLINE; ?>" id="headline"><label for="headline"><?= $this->getText('Headline') ?></label></span>
<tr><td colspan="2"><span class="radio"><input type="radio" name="type" form="docForm" value="<?= Modules\News\Models\NewsType::LINK; ?>" id="link"><label for="link"><?= $this->getText('Link') ?></label></span>
</table>
</div>
</section>
<section class="box wf-100">
<div class="inner">
<table class="layout wf-100">
<tr><td><label for="permission"><?= $this->getText('Permissions') ?></label>
<tr><td><span class="input"><button type="button" formaction=""><i class="fa fa-book"></i></button><input type="text" id="permission"><input type="hidden" form="docForm" name="permission"></span>
<tr><td><button><?= $this->getText('Add', 0, 0) ?></button>
</table>
</div>
</section>
<section class="box wf-100">
<div class="inner">
<table class="layout wf-100">
<tr><td colspan="2"><label for="groups"><?= $this->getText('Groups') ?></label>
<tr><td><span class="input"><button type="button" formaction=""><i class="fa fa-book"></i></button><input type="text" id="groups"><input type="hidden" form="docForm" name="groups"></span>
<tr><td><button><?= $this->getText('Add', 0, 0) ?></button>
</table>
</div>
</section>
</div>
</div>

View File

@ -0,0 +1,57 @@
<?php
/**
* Orange Management
*
* PHP Version 7.1
*
* @category TBD
* @package TBD
* @author OMS Development Team <dev@oms.com>
* @author Dennis Eichhorn <d.eichhorn@oms.com>
* @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(); ?>
<div class="row">
<div class="col-xs-12">
<div class="box wf-100">
<table class="table">
<caption><?= $this->getText('News') ?></caption>
<thead>
<tr>
<td>
<td><?= $this->getText('Type'); ?>
<td class="wf-100"><?= $this->getText('Title'); ?>
<td><?= $this->getText('Author'); ?>
<td><?= $this->getText('Date'); ?>
<tbody>
<?php $count = 0; foreach($newsList as $key => $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'; }
?>
<tr>
<td data-label=""><a href="<?= $url; ?>"><?= $news->isFeatured() ? '<i class="fa fa-star favorite"></i>' : ''; ?></a>
<td data-label="<?= $this->getText('Type'); ?>"><a href="<?= $url; ?>"><span class="tag <?= $color; ?>"><?= $this->getText('TYPE' . $news->getType()); ?></span></a>
<td data-label="<?= $this->getText('Title'); ?>"><a href="<?= $url; ?>"><?= $news->getTitle(); ?></a>
<td data-label="<?= $this->getText('Author'); ?>"><a href="<?= $url; ?>"><?= $news->getCreatedBy(); ?></a>
<td data-label="<?= $this->getText('Date'); ?>"><a href="<?= $url; ?>"><?= $news->getPublish()->format('Y-m-d'); ?></a>
<?php endforeach; ?>
<?php if($count === 0) : ?>
<tr><td colspan="5" class="empty"><?= $this->getText('Empty', 0, 0); ?>
<?php endif; ?>
</table>
</div>
</div>
</div>

View File

@ -0,0 +1,34 @@
<?php
/**
* Orange Management
*
* PHP Version 7.1
*
* @category TBD
* @package TBD
* @author OMS Development Team <dev@oms.com>
* @author Dennis Eichhorn <d.eichhorn@oms.com>
* @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(); ?>
<div class="row">
<div class="col-xs-12">
<section class="box wf-100">
<header><h1><?= $news->getTitle(); ?></h1></header>
<div class="inner">
<article>
<?= $news->getContent(); ?>
</article>
</div>
</section>
</div>
</div>

BIN
img/module_teaser_small.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 48 KiB

45
info.json Normal file
View File

@ -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"
}
]
}