Commit 0835b8f2 authored by Tino Goratsch's avatar Tino Goratsch

save current work in progress at implementing the data processor

parent 56aa14e8
<?php
/**
* Copyright (c) 2016 by the ACP3 Developers.
* See the LICENCE file at the top-level module directory for licencing details.
*/
namespace ACP3\Core\Model\DataProcessor\ColumnType;
class BooleanColumnType implements ColumnTypeStrategyInterface
{
/**
* @param mixed $value
* @return bool
*/
public function doEscape($value)
{
return boolval($value);
}
}
......@@ -10,6 +10,7 @@ namespace ACP3\Core\Model\DataProcessor;
interface ColumnTypes
{
const COLUMN_TYPE_DATETIME = 'datetime';
const COLUMN_TYPE_BOOLEAN = 'boolean';
const COLUMN_TYPE_INT = 'integer';
const COLUMN_TYPE_DOUBLE = 'double';
const COLUMN_TYPE_TEXT = 'text';
......
services:
core.model.column_type.boolean_column_type_strategy:
class: ACP3\Core\Model\DataProcessor\ColumnType\BooleanColumnType
core.model.column_type.date_time_column_type_strategy:
class: ACP3\Core\Model\DataProcessor\ColumnType\DateTimeColumnType
arguments:
......
......@@ -10,27 +10,11 @@ namespace ACP3\Modules\ACP3\Articles\Model;
use ACP3\Core\Model\AbstractModel;
use ACP3\Core\Model\DataProcessor;
use ACP3\Modules\ACP3\Articles\Installer\Schema;
use ACP3\Modules\ACP3\Articles\Model\Repository\ArticleRepository;
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
class ArticlesModel extends AbstractModel
{
const EVENT_PREFIX = Schema::MODULE_NAME;
/**
* ArticlesModel constructor.
* @param EventDispatcherInterface $eventDispatcher
* @param DataProcessor $dataProcessor
* @param ArticleRepository $articleRepository
*/
public function __construct(
EventDispatcherInterface $eventDispatcher,
DataProcessor $dataProcessor,
ArticleRepository $articleRepository
) {
parent::__construct($eventDispatcher, $dataProcessor, $articleRepository);
}
/**
* @param array $data
* @param int $userId
......
......@@ -7,57 +7,23 @@
namespace ACP3\Modules\ACP3\Categories\Model;
use ACP3\Core\Helpers\Secure;
use ACP3\Core\Model\AbstractModel;
use ACP3\Core\Model\DataProcessor;
use ACP3\Modules\ACP3\Categories\Installer\Schema;
use ACP3\Modules\ACP3\Categories\Model\Repository\CategoryRepository;
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
class CategoriesModel extends AbstractModel
{
const EVENT_PREFIX = Schema::MODULE_NAME;
/**
* @var Secure
*/
protected $secure;
/**
* CategoriesModel constructor.
* @param EventDispatcherInterface $eventDispatcher
* @param DataProcessor $dataProcessor
* @param Secure $secure
* @param CategoryRepository $categoryRepository
*/
public function __construct(
EventDispatcherInterface $eventDispatcher,
DataProcessor $dataProcessor,
Secure $secure,
CategoryRepository $categoryRepository
) {
parent::__construct($eventDispatcher, $dataProcessor, $categoryRepository);
$this->secure = $secure;
}
/**
* @param array $formData
* @param array $data
* @param int|null $entryId
* @return bool|int
*/
public function saveCategory(array $formData, $entryId = null)
public function saveCategory(array $data, $entryId = null)
{
$data = [
'title' => $this->secure->strEncode($formData['title']),
'description' => $this->secure->strEncode($formData['description']),
];
if (isset($formData['module'])) {
$data['module_id'] = (int)$formData['module'];
}
if (isset($formData['picture'])) {
$data['picture'] = $formData['picture'];
if (isset($data['module'])) {
$data['module_id'] = $data['module'];
}
return $this->save($data, $entryId);
......@@ -69,10 +35,10 @@ class CategoriesModel extends AbstractModel
protected function getAllowedColumns()
{
return [
'title',
'description',
'module_id',
'picture'
'title' => DataProcessor\ColumnTypes::COLUMN_TYPE_TEXT,
'description' => DataProcessor\ColumnTypes::COLUMN_TYPE_TEXT,
'module_id' => DataProcessor\ColumnTypes::COLUMN_TYPE_INT,
'picture' => DataProcessor\ColumnTypes::COLUMN_TYPE_RAW
];
}
}
......@@ -14,5 +14,4 @@ services:
arguments:
- '@core.event_dispatcher'
- '@core.model.data_processor'
- '@core.helpers.secure'
- '@categories.model.categories_repository'
......@@ -8,6 +8,7 @@ namespace ACP3\Modules\ACP3\Comments\Model;
use ACP3\Core\Model\AbstractModel;
use ACP3\Core\Model\DataProcessor\ColumnTypes;
use ACP3\Modules\ACP3\Comments\Installer\Schema;
class CommentsModel extends AbstractModel
......@@ -20,13 +21,13 @@ class CommentsModel extends AbstractModel
protected function getAllowedColumns()
{
return [
'ip',
'date',
'name',
'user_id',
'message',
'module_id',
'entry_id'
'ip' => ColumnTypes::COLUMN_TYPE_RAW,
'date' => ColumnTypes::COLUMN_TYPE_DATETIME,
'name' => ColumnTypes::COLUMN_TYPE_TEXT,
'user_id' => ColumnTypes::COLUMN_TYPE_INT,
'message' => ColumnTypes::COLUMN_TYPE_TEXT,
'module_id' => ColumnTypes::COLUMN_TYPE_INT,
'entry_id' => ColumnTypes::COLUMN_TYPE_INT
];
}
}
......@@ -7,53 +7,21 @@
namespace ACP3\Modules\ACP3\Emoticons\Model;
use ACP3\Core\Helpers\Secure;
use ACP3\Core\Model\AbstractModel;
use ACP3\Core\Model\DataProcessor;
use ACP3\Modules\ACP3\Emoticons\Installer\Schema;
use ACP3\Modules\ACP3\Emoticons\Model\Repository\EmoticonRepository;
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
class EmoticonsModel extends AbstractModel
{
const EVENT_PREFIX = Schema::MODULE_NAME;
/**
* @var Secure
*/
protected $secure;
/**
* EmoticonsModel constructor.
* @param EventDispatcherInterface $eventDispatcher
* @param DataProcessor $dataProcessor
* @param Secure $secure
* @param EmoticonRepository $emoticonRepository
*/
public function __construct(
EventDispatcherInterface $eventDispatcher,
DataProcessor $dataProcessor,
Secure $secure,
EmoticonRepository $emoticonRepository
) {
parent::__construct($eventDispatcher, $dataProcessor, $emoticonRepository);
$this->secure = $secure;
}
/**
* @param array $formData
* @param array $data
* @param int|null $entryId
* @return bool|int
*/
public function saveEmoticon(array $formData, $entryId = null)
public function saveEmoticon(array $data, $entryId = null)
{
$data = [
'code' => $this->secure->strEncode($formData['code']),
'description' => $this->secure->strEncode($formData['description']),
'img' => $formData['img'],
];
return $this->save($data, $entryId);
}
......@@ -63,9 +31,9 @@ class EmoticonsModel extends AbstractModel
protected function getAllowedColumns()
{
return [
'code',
'description',
'img'
'code' => DataProcessor\ColumnTypes::COLUMN_TYPE_TEXT,
'description' => DataProcessor\ColumnTypes::COLUMN_TYPE_TEXT,
'img' => DataProcessor\ColumnTypes::COLUMN_TYPE_RAW
];
}
}
......@@ -14,5 +14,4 @@ services:
arguments:
- '@core.event_dispatcher'
- '@core.model.data_processor'
- '@core.helpers.secure'
- '@emoticons.model.emoticonrepository'
......@@ -7,76 +7,29 @@
namespace ACP3\Modules\ACP3\Files\Model;
use ACP3\Core\Date;
use ACP3\Core\Helpers\Secure;
use ACP3\Core\Model\AbstractModel;
use ACP3\Core\Model\DataProcessor;
use ACP3\Modules\ACP3\Files\Installer\Schema;
use ACP3\Modules\ACP3\Files\Model\Repository\FilesRepository;
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
class FilesModel extends AbstractModel
{
const EVENT_PREFIX = Schema::MODULE_NAME;
/**
* @var Secure
*/
protected $secure;
/**
* @var FilesRepository
*/
protected $filesRepository;
/**
* @var Date
*/
protected $date;
/**
* FilesModel constructor.
* @param EventDispatcherInterface $eventDispatcher
* @param DataProcessor $dataProcessor
* @param Date $date
* @param Secure $secure
* @param FilesRepository $filesRepository
*/
public function __construct(
EventDispatcherInterface $eventDispatcher,
DataProcessor $dataProcessor,
Date $date,
Secure $secure,
FilesRepository $filesRepository
) {
parent::__construct($eventDispatcher, $dataProcessor, $filesRepository);
$this->secure = $secure;
$this->filesRepository = $filesRepository;
$this->date = $date;
}
/**
* @param array $formData
* @param array $data
* @param int $userId
* @param int|null $entryId
* @return bool|int
*/
public function saveFile(array $formData, $userId, $entryId = null)
public function saveFile(array $data, $userId, $entryId = null)
{
$data = [
'start' => $this->date->toSQL($formData['start']),
'end' => $this->date->toSQL($formData['end']),
'category_id' => (int)$formData['cat'],
'title' => $this->secure->strEncode($formData['title']),
'text' => $this->secure->strEncode($formData['text'], true),
'comments' => (int)$formData['comments'],
$data = array_merge($data, [
'category_id' => (int)$data['cat'],
'user_id' => $userId,
];
]);
if (!empty($formData['file'])) {
$data['file'] = $formData['file'];
}
if (!empty($formData['filesize'])) {
$data['size'] = $formData['filesize'];
if (!empty($data['filesize'])) {
$data['size'] = $data['filesize'];
}
return $this->save($data, $entryId);
......@@ -88,15 +41,15 @@ class FilesModel extends AbstractModel
protected function getAllowedColumns()
{
return [
'start',
'end',
'category_id',
'title',
'text',
'comments',
'user_id',
'file',
'size'
'start' => DataProcessor\ColumnTypes::COLUMN_TYPE_DATETIME,
'end' => DataProcessor\ColumnTypes::COLUMN_TYPE_DATETIME,
'category_id' => DataProcessor\ColumnTypes::COLUMN_TYPE_INT,
'title' => DataProcessor\ColumnTypes::COLUMN_TYPE_TEXT,
'text' => DataProcessor\ColumnTypes::COLUMN_TYPE_TEXT_WYSIWYG,
'comments' => DataProcessor\ColumnTypes::COLUMN_TYPE_INT,
'user_id' => DataProcessor\ColumnTypes::COLUMN_TYPE_INT,
'file' => DataProcessor\ColumnTypes::COLUMN_TYPE_RAW,
'size' => DataProcessor\ColumnTypes::COLUMN_TYPE_RAW
];
}
}
......@@ -14,6 +14,4 @@ services:
arguments:
- '@core.event_dispatcher'
- '@core.model.data_processor'
- '@core.date'
- '@core.helpers.secure'
- '@files.model.filesrepository'
......@@ -7,63 +7,23 @@
namespace ACP3\Modules\ACP3\Gallery\Model;
use ACP3\Core\Date;
use ACP3\Core\Helpers\Secure;
use ACP3\Core\Model\AbstractModel;
use ACP3\Core\Model\DataProcessor;
use ACP3\Modules\ACP3\Gallery\Installer\Schema;
use ACP3\Modules\ACP3\Gallery\Model\Repository\GalleryRepository;
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
class GalleryModel extends AbstractModel
{
const EVENT_PREFIX = Schema::MODULE_NAME;
/**
* @var Date
*/
protected $date;
/**
* @var Secure
*/
protected $secure;
/**
* GalleryModel constructor.
* @param EventDispatcherInterface $eventDispatcher
* @param DataProcessor $dataProcessor
* @param Date $date
* @param Secure $secure
* @param GalleryRepository $galleryRepository
*/
public function __construct(
EventDispatcherInterface $eventDispatcher,
DataProcessor $dataProcessor,
Date $date,
Secure $secure,
GalleryRepository $galleryRepository
) {
parent::__construct($eventDispatcher, $dataProcessor, $galleryRepository);
$this->date = $date;
$this->secure = $secure;
}
/**
* @param array $formData
* @param array $data
* @param int $userId
* @param int|null $galleryId
* @return int|bool
*/
public function saveGallery(array $formData, $userId, $galleryId = null)
public function saveGallery(array $data, $userId, $galleryId = null)
{
$data = [
'start' => $this->date->toSQL($formData['start']),
'end' => $this->date->toSQL($formData['end']),
'title' => $this->secure->strEncode($formData['title']),
'user_id' => $userId,
];
$data['user_id'] = $userId;
return $this->save($data, $galleryId);
}
......@@ -73,10 +33,10 @@ class GalleryModel extends AbstractModel
protected function getAllowedColumns()
{
return [
'start',
'end',
'ttile',
'user_id'
'start' => DataProcessor\ColumnTypes::COLUMN_TYPE_DATETIME,
'end' => DataProcessor\ColumnTypes::COLUMN_TYPE_DATETIME,
'ttile' => DataProcessor\ColumnTypes::COLUMN_TYPE_TEXT,
'user_id' => DataProcessor\ColumnTypes::COLUMN_TYPE_INT
];
}
}
......@@ -7,7 +7,6 @@
namespace ACP3\Modules\ACP3\Gallery\Model;
use ACP3\Core\Helpers\Secure;
use ACP3\Core\Model\AbstractModel;
use ACP3\Core\Model\DataProcessor;
use ACP3\Core\Settings\SettingsInterface;
......@@ -19,10 +18,6 @@ class PictureModel extends AbstractModel
{
const EVENT_PREFIX = Schema::MODULE_NAME;
/**
* @var Secure
*/
protected $secure;
/**
* @var PictureRepository
*/
......@@ -37,43 +32,36 @@ class PictureModel extends AbstractModel
* @param EventDispatcherInterface $eventDispatcher
* @param DataProcessor $dataProcessor
* @param SettingsInterface $config
* @param Secure $secure
* @param PictureRepository $pictureRepository
*/
public function __construct(
EventDispatcherInterface $eventDispatcher,
DataProcessor $dataProcessor,
SettingsInterface $config,
Secure $secure,
PictureRepository $pictureRepository
) {
parent::__construct($eventDispatcher, $dataProcessor, $pictureRepository);
$this->secure = $secure;
$this->config = $config;
}
/**
* @param array $formData
* @param array $data
* @param int $galleryId
* @param int|null $entryId
* @return bool|int
*/
public function savePicture(array $formData, $galleryId, $entryId = null)
public function savePicture(array $data, $galleryId, $entryId = null)
{
$settings = $this->config->getSettings(Schema::MODULE_NAME);
$data = [
$data = array_merge($data, [
'gallery_id' => $galleryId,
'description' => $this->secure->strEncode($formData['description'], true),
'comments' => $settings['comments'] == 1
? (isset($formData['comments']) && $formData['comments'] == 1 ? 1 : 0)
? (isset($data['comments']) && $data['comments'] == 1 ? 1 : 0)
: $settings['comments'],
];
]);
if (isset($formData['file'])) {
$data['file'] = $formData['file'];
}
if ($entryId === null) {
$picNum = $this->repository->getLastPictureByGalleryId($entryId);
$data['pic'] = !is_null($picNum) ? $picNum + 1 : 1;
......@@ -88,11 +76,11 @@ class PictureModel extends AbstractModel
protected function getAllowedColumns()
{
return [
'gallery_id',
'description',
'comments',
'file',
'pic'
'gallery_id' => DataProcessor\ColumnTypes::COLUMN_TYPE_INT,
'description' => DataProcessor\ColumnTypes::COLUMN_TYPE_TEXT_WYSIWYG,
'comments' => DataProcessor\ColumnTypes::COLUMN_TYPE_INT,
'file' => DataProcessor\ColumnTypes::COLUMN_TYPE_RAW,
'pic' => DataProcessor\ColumnTypes::COLUMN_TYPE_INT
];
}
}
......@@ -19,8 +19,6 @@ services:
arguments:
- '@core.event_dispatcher'
- '@core.model.data_processor'
- '@core.date'
- '@core.helpers.secure'
- '@gallery.model.galleryrepository'
gallery.model.picture_model:
......@@ -29,5 +27,4 @@ services:
- '@core.event_dispatcher'
- '@core.model.data_processor'
- '@core.config'
- '@core.helpers.secure'
- '@gallery.model.picturerepository'
......@@ -8,6 +8,7 @@ namespace ACP3\Modules\ACP3\Guestbook\Model;
use ACP3\Core\Model\AbstractModel;
use ACP3\Core\Model\DataProcessor\ColumnTypes;
use ACP3\Modules\ACP3\Guestbook\Installer\Schema;
class GuestbookModel extends AbstractModel
......@@ -20,14 +21,14 @@ class GuestbookModel extends AbstractModel
protected function getAllowedColumns()
{
return [
'date',
'ip',
'name',
'user_id',
'message',
'website',
'mail',
'active'
'date' => ColumnTypes::COLUMN_TYPE_DATETIME,
'ip' => ColumnTypes::COLUMN_TYPE_RAW,
'name' => ColumnTypes::COLUMN_TYPE_TEXT,
'user_id' => ColumnTypes::COLUMN_TYPE_INT,
'message' => ColumnTypes::COLUMN_TYPE_TEXT,
'website' => ColumnTypes::COLUMN_TYPE_TEXT,
'mail' => ColumnTypes::COLUMN_TYPE_RAW,
'active' => ColumnTypes::COLUMN_TYPE_INT
];
}
}
......@@ -76,13 +76,13 @@ class MenuItemsModel extends AbstractNestedSetModel
protected function getAllowedColumns()
{
return [
'mode',
'block_id',
'parent_id',
'display',
'title',
'uri',
'target'
'mode' => DataProcessor\ColumnTypes::COLUMN_TYPE_INT,
'block_id' => DataProcessor\ColumnTypes::COLUMN_TYPE_INT,
'parent_id' => DataProcessor\ColumnTypes::COLUMN_TYPE_INT,
'display' => DataProcessor\ColumnTypes::COLUMN_TYPE_INT,
'title' => DataProcessor\ColumnTypes::COLUMN_TYPE_TEXT,
'uri' => DataProcessor\ColumnTypes::COLUMN_TYPE_RAW,
'target' => DataProcessor\ColumnTypes::COLUMN_TYPE_INT
];
}
}
......@@ -7,53 +7,22 @@
namespace ACP3\Modules\ACP3\Menus\Model;
use ACP3\Core\Helpers\Secure;
use ACP3\Core\Model\AbstractModel;
use ACP3\Core\Model\DataProcessor;
use ACP3\Modules\ACP3\Menus\Installer\Schema;
use ACP3\Modules\ACP3\Menus\Model\Repository\MenuRepository;
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
class MenusModel extends AbstractModel
{
const EVENT_PREFIX = Schema::MODULE_NAME;
/**
* @var Secure
*/
protected $secure;
/**
* MenusModel constructor.
* @param EventDispatcherInterface $eventDispatcher
* @param DataProcessor $dataProcessor
* @param Secure $secure
* @param MenuRepository $menuRepository
*/
public function __construct(
EventDispatcherInterface $eventDispatcher,
DataProcessor $dataProcessor,
Secure $secure,
MenuRepository $menuRepository)
{
parent::__construct($eventDispatcher, $dataProcessor, $menuRepository);
$this->secure = $secure;
}
/**
* @param array $formData
* @param array $data
* @param null|int $menuId
* @return mixed
*/
public function saveMenu(array $formData, $menuId = null)
public function saveMenu(array $data, $menuId = null)
{
$values = [
'index_name' => $formData['index_name'],
'title' => $this->secure->strEncode($formData['title']),
];
return $this->save($values, $menuId);
return $this->save($data, $menuId);
}
/**
......@@ -62,8 +31,8 @@ class MenusModel extends AbstractModel
protected function getAllowedColumns()
{
return [
'index_name',
'title'
'index_name' => DataProcessor\ColumnTypes::COLUMN_TYPE_RAW,
'title' => DataProcessor\ColumnTypes::COLUMN_TYPE_TEXT
];
}
}
......@@ -14,7 +14,6 @@ services:
arguments:
- '@core.event_dispatcher'
- '@core.model.data_processor'
- '@core.helpers.secure'
- '@menus.model.menurepository'
menus.model.menu_items_model:
......
......@@ -7,8 +7,6 @@
namespace ACP3\Modules\ACP3\News\Model;
use ACP3\Core\Date;
use ACP3\Core\Helpers\Secure;
use ACP3\Core\Model\AbstractModel;
use ACP3\Core\Model\DataProcessor;
use ACP3\Core\Settings\SettingsInterface;
......@@ -20,14 +18,6 @@ class NewsModel extends AbstractModel
{
const EVENT_PREFIX = Schema::MODULE_NAME;
/**
* @var Date
*/
protected $date;
/**
* @var Secure
*/
protected $secure;
/**
* @var SettingsInterface
*/
......@@ -38,48 +28,35 @@ class NewsModel extends AbstractModel
* @param EventDispatcherInterface $eventDispatcher
* @param DataProcessor $dataProcessor
* @param SettingsInterface $config
* @param Date $date