Core adjustments for pending issues

This commit is contained in:
Dennis Eichhorn 2016-10-02 12:07:05 +02:00
parent ac22080aba
commit c1b8b582d4
8 changed files with 121 additions and 81 deletions

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

@ -27,11 +27,4 @@ return [
'verb' => RouteVerb::GET,
],
],
'^.*/api/news.*$' => [
[
'dest' => '\Modules\News\Controller:apiNewsCreate',
'verb' => RouteVerb::SET,
],
],
];

View File

@ -172,14 +172,14 @@ class Controller extends ModuleAbstract implements WebInterface
public function apiNewsCreate(RequestAbstract $request, ResponseAbstract $response, $data = null)
{
$newsArticle = new NewsArticle();
$newsArticle->setCreatedBy($requst->getAccount()->getId());
$newsArticle->setCreatedBy($request->getAccount()->getId());
$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->setType((int) ($request->getData('type') ?? 1));
$newsArticle->setStatus((int) ($request->getData('status') ?? 1));
$newsArticle->setFeatured((bool) ($request->getData('featured') ?? true));

View File

@ -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 <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
*

View File

@ -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;
@ -42,6 +43,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 +91,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 +127,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);
}
}

View File

@ -19,12 +19,12 @@
echo $this->getData('nav')->render(); ?>
<section class="wf-75 floatLeft">
<?php include __DIR__ . '../../../Editor/Theme/Backend/editor.tpl.php'; ?>
<?php include __DIR__ . '/../../../Editor/Theme/Backend/editor.tpl.php'; ?>
</section>
<section class="wf-25 floatLeft">
<section class="box w-100">
<div class="inner">
<form id="newsForm">
<form id="newsForm" 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>
@ -32,43 +32,37 @@ echo $this->getData('nav')->render(); ?>
<option><?= $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') ?>"><td class="rightText"><input type="submit" value="<?= $this->l11n->lang[0]['Save'] ?>"> <input type="submit" value="<?= $this->getText('Publish') ?>">
<tr><td><input type="submit" value="<?= $this->getText('Delete') ?>"><td class="rightText"><input type="submit" value="<?= $this->getText('Save') ?>"> <input type="submit" value="<?= $this->getText('Publish') ?>">
</table>
</form>
</div>
</section>
<section class="box w-100">
<div class="inner">
<form id="newsForm">
<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="newsForm" value="1" id="news" checked><label for="news"><?= $this->getText('News') ?></label></span>
<tr><td colspan="2"><span class="radio"><input type="radio" name="type" form="newsForm" value="2" id="headline"><label for="headline"><?= $this->getText('Headline') ?></label></span>
<tr><td colspan="2"><span class="radio"><input type="radio" name="type" form="newsForm" value="3" id="link"><label for="link"><?= $this->getText('Link') ?></label></span>
</table>
</form>
<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="newsForm" value="1" id="news" checked><label for="news"><?= $this->getText('News') ?></label></span>
<tr><td colspan="2"><span class="radio"><input type="radio" name="type" form="newsForm" value="2" id="headline"><label for="headline"><?= $this->getText('Headline') ?></label></span>
<tr><td colspan="2"><span class="radio"><input type="radio" name="type" form="newsForm" value="3" id="link"><label for="link"><?= $this->getText('Link') ?></label></span>
</table>
</div>
</section>
<section class="box w-100">
<div class="inner">
<form id="newsForm">
<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="newsForm" name="permission"></span>
<tr><td><button><?= $this->getText('Add', 0, 0) ?></button>
</table>
</form>
<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="newsForm" name="permission"></span>
<tr><td><button><?= $this->getText('Add', 0, 0) ?></button>
</table>
</div>
</section>
<section class="box w-100">
<div class="inner">
<form id="newsForm">
<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="newsForm" name="groups"></span>
<tr><td><button><?= $this->getText('Add', 0, 0) ?></button>
</table>
</form>
<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="newsForm" name="groups"></span>
<tr><td><button><?= $this->getText('Add', 0, 0) ?></button>
</table>
</div>
</section>
</section>

View File

@ -31,20 +31,20 @@ echo $this->getData('nav')->render(); ?>
<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('News', '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>
<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); ?>

View File

@ -31,20 +31,20 @@ echo $this->getData('nav')->render(); ?>
<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('News', '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>
<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); ?>