Commit 49f0b25b authored by Tino Goratsch's avatar Tino Goratsch

some more refactoring for the various *Model classes

parent 2bf3d897
......@@ -113,7 +113,8 @@ class Create extends AbstractFormAction
return $this->actionHelper->handleCreatePostAction(function () use ($formData) {
$this->adminFormValidation->validate($formData);
$articleId = $this->articlesModel->saveArticle($formData, $this->user->getUserId());
$formData['user_id'] = $this->user->getUserId();
$articleId = $this->articlesModel->save($formData);
$this->insertUriAlias($formData, $articleId);
......
......@@ -138,12 +138,13 @@ class Edit extends AbstractFormAction
->setUriAlias(sprintf(Articles\Helpers::URL_KEY_PATTERN, $articleId))
->validate($formData);
$bool = $this->articlesModel->saveArticle($formData, $this->user->getUserId(), $articleId);
$formData['user_id'] = $this->user->getUserId();
$result = $this->articlesModel->save($formData, $articleId);
$this->insertUriAlias($formData, $articleId);
$this->createOrUpdateMenuItem($formData, $articleId);
return $bool;
return $result;
});
}
......
......@@ -15,19 +15,6 @@ class ArticlesModel extends AbstractModel
{
const EVENT_PREFIX = Schema::MODULE_NAME;
/**
* @param array $data
* @param int $userId
* @param int|null $entryId
* @return bool|int
*/
public function saveArticle(array $data, $userId, $entryId = null)
{
$data['user_id'] = $userId;
return $this->save($data, $entryId);
}
/**
* @return array
*/
......
......@@ -91,7 +91,7 @@ class Create extends Core\Controller\AbstractAdminAction
$formData['picture'] = $result['name'];
}
return $this->categoriesModel->saveCategory($formData);
return $this->categoriesModel->save($formData);
});
}
......
......@@ -98,7 +98,7 @@ class Edit extends Core\Controller\AbstractAdminAction
$formData['picture'] = $result['name'];
}
return $this->categoriesModel->saveCategory($formData, $categoryId);
return $this->categoriesModel->save($formData, $categoryId);
});
}
}
......@@ -16,17 +16,15 @@ class CategoriesModel extends AbstractModel
const EVENT_PREFIX = Schema::MODULE_NAME;
/**
* @param array $data
* @param int|null $entryId
* @return bool|int
* @inheritdoc
*/
public function saveCategory(array $data, $entryId = null)
public function save(array $data, $entryId = null)
{
if (isset($data['module'])) {
$data['module_id'] = $data['module'];
}
return $this->save($data, $entryId);
return parent::save($data, $entryId);
}
/**
......
......@@ -84,7 +84,7 @@ class Create extends Core\Controller\AbstractAdminAction
$result = $upload->moveFile($file->getPathname(), $file->getClientOriginalName());
$formData['img'] = $result['name'];
return $this->emoticonsModel->saveEmoticon($formData);
return $this->emoticonsModel->save($formData);
});
}
}
......@@ -97,7 +97,7 @@ class Edit extends Core\Controller\AbstractAdminAction
$formData['img'] = $result['name'];
}
return $this->emoticonsModel->saveEmoticon($formData, $emoticonId);
return $this->emoticonsModel->save($formData, $emoticonId);
});
}
}
......@@ -15,16 +15,6 @@ class EmoticonsModel extends AbstractModel
{
const EVENT_PREFIX = Schema::MODULE_NAME;
/**
* @param array $data
* @param int|null $entryId
* @return bool|int
*/
public function saveEmoticon(array $data, $entryId = null)
{
return $this->save($data, $entryId);
}
/**
* @return array
*/
......
......@@ -128,8 +128,9 @@ class Create extends AbstractFormAction
$formData['cat'] = $this->fetchCategoryId($formData);
$formData['comments'] = $this->useComments($formData);
$formData['user_id'] = $this->user->getUserId();
$lastId = $this->filesModel->saveFile($formData, $this->user->getUserId());
$lastId = $this->filesModel->save($formData);
$this->insertUriAlias($formData, $lastId);
......
......@@ -136,6 +136,7 @@ class Edit extends AbstractFormAction
$formData['cat'] = $this->fetchCategoryId($formData);
$formData['comments'] = $this->useComments($formData);
$formData['user_id'] = $this->user->getUserId();
if (!empty($file)) {
$newFileSql = $this->updateAssociatedFile($file, $formData, $dl['file']);
......@@ -143,7 +144,7 @@ class Edit extends AbstractFormAction
$formData = array_merge($formData, $newFileSql);
}
$bool = $this->filesModel->saveFile($formData, $this->user->getUserId(), $fileId);
$bool = $this->filesModel->save($formData, $fileId);
$this->insertUriAlias($formData, $fileId);
......
......@@ -16,23 +16,19 @@ class FilesModel extends AbstractModel
const EVENT_PREFIX = Schema::MODULE_NAME;
/**
* @param array $data
* @param int $userId
* @param int|null $entryId
* @return bool|int
* @inheritdoc
*/
public function saveFile(array $data, $userId, $entryId = null)
public function save(array $data, $entryId = null)
{
$data = array_merge($data, [
'category_id' => (int)$data['cat'],
'user_id' => $userId,
'category_id' => (int)$data['cat']
]);
if (!empty($data['filesize'])) {
$data['size'] = $data['filesize'];
}
return $this->save($data, $entryId);
return parent::save($data, $entryId);
}
/**
......
......@@ -81,7 +81,8 @@ class Create extends AbstractFormAction
return $this->actionHelper->handleCreatePostAction(function () use ($formData) {
$this->galleryFormValidation->validate($formData);
$lastId = $this->galleryModel->saveGallery($formData, $this->user->getUserId());
$formData['user_id'] = $this->user->getUserId();
$lastId = $this->galleryModel->save($formData);
$this->insertUriAlias($formData, $lastId);
......
......@@ -188,7 +188,8 @@ class Edit extends AbstractFormAction
->setUriAlias(sprintf(Gallery\Helpers::URL_KEY_PATTERN_GALLERY, $galleryId))
->validate($formData);
$bool = $this->galleryModel->saveGallery($formData, $this->user->getUserId(), $galleryId);
$formData['user_id'] = $this->user->getUserId();
$bool = $this->galleryModel->save($formData, $galleryId);
$this->insertUriAlias($formData, $galleryId);
......
......@@ -163,7 +163,8 @@ class Create extends AbstractFormAction
$result = $upload->moveFile($file->getPathname(), $file->getClientOriginalName());
$formData['file'] = $result['name'];
$lastId = $this->pictureModel->savePicture($formData, $galleryId);
$formData['gallery_id'] = $galleryId;
$lastId = $this->pictureModel->save($formData);
$bool2 = $this->generatePictureAlias($lastId);
......
......@@ -130,7 +130,8 @@ class Edit extends AbstractFormAction
$formData['file'] = $result['name'];
}
return $this->pictureModel->savePicture($formData, $picture['gallery_id'], $pictureId);
$formData['gallery_id'] = $picture['gallery_id'];
return $this->pictureModel->save($formData, $pictureId);
},
'acp/gallery/index/edit/id_' . $picture['gallery_id']
);
......
......@@ -15,18 +15,6 @@ class GalleryModel extends AbstractModel
{
const EVENT_PREFIX = Schema::MODULE_NAME;
/**
* @param array $data
* @param int $userId
* @param int|null $galleryId
* @return int|bool
*/
public function saveGallery(array $data, $userId, $galleryId = null)
{
$data['user_id'] = $userId;
return $this->save($data, $galleryId);
}
/**
* @return array
*/
......
......@@ -46,17 +46,13 @@ class PictureModel extends AbstractModel
}
/**
* @param array $data
* @param int $galleryId
* @param int|null $entryId
* @return bool|int
* @inheritdoc
*/
public function savePicture(array $data, $galleryId, $entryId = null)
public function save(array $data, $entryId = null)
{
$settings = $this->config->getSettings(Schema::MODULE_NAME);
$data = array_merge($data, [
'gallery_id' => $galleryId,
'comments' => $settings['comments'] == 1
? (isset($data['comments']) && $data['comments'] == 1 ? 1 : 0)
: $settings['comments'],
......@@ -67,7 +63,7 @@ class PictureModel extends AbstractModel
$data['pic'] = !is_null($picNum) ? $picNum + 1 : 1;
}
return $this->save($data, $entryId);
return parent::save($data, $entryId);
}
/**
......
......@@ -74,7 +74,7 @@ class Create extends Core\Controller\AbstractAdminAction
return $this->actionHelper->handleCreatePostAction(function () use ($formData) {
$this->menuFormValidation->validate($formData);
return $this->menusModel->saveMenu($formData);
return $this->menusModel->save($formData);
});
}
}
......@@ -88,7 +88,7 @@ class Edit extends Core\Controller\AbstractAdminAction
->setMenuId($menuId)
->validate($formData);
return $this->menusModel->saveMenu($formData, $menuId);
return $this->menusModel->save($formData, $menuId);
});
}
}
......@@ -118,7 +118,7 @@ class Create extends AbstractFormAction
$formData['mode'] = $this->fetchMenuItemModeForSave($formData);
$formData['uri'] = $this->fetchMenuItemUriForSave($formData);
$result = $this->menuItemsModel->saveMenuItem($formData);
$result = $this->menuItemsModel->save($formData);
$this->menusCache->saveMenusCache();
......
......@@ -130,7 +130,7 @@ class Edit extends AbstractFormAction
$formData['mode'] = $this->fetchMenuItemModeForSave($formData);
$formData['uri'] = $this->fetchMenuItemUriForSave($formData);
$result = $this->menuItemsModel->saveMenuItem($formData, $menuItemId);
$result = $this->menuItemsModel->save($formData, $menuItemId);
$this->menusCache->saveMenusCache();
......
......@@ -16,15 +16,13 @@ class MenuItemsModel extends AbstractNestedSetModel
const EVENT_PREFIX = Schema::MODULE_NAME;
/**
* @param array $data
* @param null|int $entryId
* @return bool|int
* @inheritdoc
*/
public function saveMenuItem(array $data, $entryId = null)
public function save(array $data, $entryId = null)
{
$data['target'] = $data['display'] == 0 ? 1 : $data['target'];
return $this->save($data, $entryId);
return parent::save($data, $entryId);
}
/**
......
......@@ -15,16 +15,6 @@ class MenusModel extends AbstractModel
{
const EVENT_PREFIX = Schema::MODULE_NAME;
/**
* @param array $data
* @param null|int $menuId
* @return mixed
*/
public function saveMenu(array $data, $menuId = null)
{
return $this->save($data, $menuId);
}
/**
* @return array
*/
......
......@@ -100,7 +100,8 @@ class Create extends AbstractFormAction
$this->adminFormValidation->validate($formData);
$formData['cat'] = $this->fetchCategoryIdForSave($formData);
$newsId = $this->newsModel->saveNews($formData, $this->user->getUserId());
$formData['user_id'] = $this->user->getUserId();
$newsId = $this->newsModel->save($formData);
$this->insertUriAlias($formData, $newsId);
......
......@@ -105,7 +105,8 @@ class Edit extends AbstractFormAction
->validate($formData);
$formData['cat'] = $this->fetchCategoryIdForSave($formData);
$bool = $this->newsModel->saveNews($formData, $this->user->getUserId(), $newsId);
$formData['user_id'] = $this->user->getUserId();
$bool = $this->newsModel->save($formData, $newsId);
$this->insertUriAlias($formData, $newsId);
......
......@@ -42,12 +42,9 @@ class NewsModel extends AbstractModel
}
/**
* @param array $data
* @param int $userId
* @param int|null $newsId
* @return bool|int
* @inheritdoc
*/
public function saveNews(array $data, $userId, $newsId = null)
public function save(array $data, $newsId = null)
{
$settings = $this->config->getSettings(Schema::MODULE_NAME);
......@@ -55,10 +52,9 @@ class NewsModel extends AbstractModel
'readmore' => $this->useReadMore($data, $settings),
'comments' => $this->useComments($data, $settings),
'category_id' => $data['cat'],
'user_id' => $userId,
]);
return $this->save($data, $newsId);
return parent::save($data, $newsId);
}
/**
......
......@@ -93,7 +93,8 @@ class Create extends AbstractFormAction
return $this->actionHelper->handlePostAction(function () use ($formData, $settings) {
$this->adminFormValidation->validate($formData);
$newsletterId = $this->newsletterModel->saveNewsletter($formData, $this->user->getUserId());
$formData['user_id'] = $this->user->getUserId();
$newsletterId = $this->newsletterModel->save($formData);
list($text, $result) = $this->sendTestNewsletter(
$formData['test'] == 1,
......
......@@ -106,7 +106,8 @@ class Edit extends AbstractFormAction
return $this->actionHelper->handlePostAction(function () use ($formData, $newsletter, $settings, $newsletterId) {
$this->adminFormValidation->validate($formData);
$bool = $this->newsletterModel->saveNewsletter($formData, $this->user->getUserId(), $newsletterId);
$formData['user_id'] = $this->user->getUserId();
$bool = $this->newsletterModel->saveNewsletter($formData, $newsletterId);
list($text, $result) = $this->sendTestNewsletter(
$formData['test'] == 1,
......
......@@ -42,22 +42,17 @@ class NewsletterModel extends AbstractModel
}
/**
* @param array $data
* @param int $userId
* @param int|null $newsletterId
* @return bool|int
* @inheritdoc
*/
public function saveNewsletter(array $data, $userId, $newsletterId = null)
public function save(array $data, $entryId = null)
{
$data['user_id'] = $userId;
if ($newsletterId === null) {
if ($entryId === null) {
$settings = $this->config->getSettings(Schema::MODULE_NAME);
$data['html'] = $settings['html'];
$data['status'] = 0;
}
return $this->save($data, $newsletterId);
return parent::save($data, $entryId);
}
/**
......
......@@ -89,7 +89,7 @@ class Create extends AbstractFormAction
return $this->actionHelper->handleCreatePostAction(function () use ($formData) {
$this->roleFormValidation->validate($formData);
$roleId = $this->roleModel->saveRole($formData);
$roleId = $this->roleModel->save($formData);
$this->rulesModel->updateRules($formData['privileges'], $roleId);
return $roleId;
......
......@@ -107,7 +107,7 @@ class Edit extends AbstractFormAction
$formData['parent_id'] = $roleId === 1 ? 0 : $formData['parent_id'];
$result = $this->rolesModel->saveRole($formData, $roleId);
$result = $this->rolesModel->save($formData, $roleId);
$this->rulesModel->updateRules($formData['privileges'], $roleId);
return $result;
......
......@@ -83,7 +83,7 @@ class Create extends AbstractFormAction
$this->resourceFormValidation->validate($formData);
$formData['module_id'] = $this->fetchModuleId($formData['modules']);
return $this->resourcesModel->saveResource($formData);
return $this->resourcesModel->save($formData);
});
}
}
......@@ -96,7 +96,7 @@ class Edit extends AbstractFormAction
$this->resourceFormValidation->validate($formData);
$formData['module_id'] = $this->fetchModuleId($formData['modules']);
return $this->resourcesModel->saveResource($formData, $resourceId);
return $this->resourcesModel->save($formData, $resourceId);
});
}
}
......@@ -16,18 +16,16 @@ class ResourcesModel extends AbstractModel
const EVENT_PREFIX = Schema::MODULE_NAME;
/**
* @param array $data
* @param int|null $entryId
* @return bool|int
* @inheritdoc
*/
public function saveResource(array $data, $entryId = null)
public function save(array $data, $entryId = null)
{
$data = array_merge($data, [
'page' => $data['resource'],
'privilege_id' => $data['privileges'],
]);
return $this->save($data, $entryId);
return parent::save($data, $entryId);
}
/**
......
......@@ -15,16 +15,6 @@ class RolesModel extends AbstractNestedSetModel
{
const EVENT_PREFIX = Schema::MODULE_NAME;
/**
* @param array $data
* @param int|null $entryId
* @return bool|int
*/
public function saveRole(array $data, $entryId = null)
{
return $this->save($data, $entryId);
}
/**
* @return array
*/
......
......@@ -97,7 +97,8 @@ class Create extends AbstractFormAction
return $this->actionHelper->handleCreatePostAction(function () use ($formData) {
$this->pollsValidator->validate($formData);
$pollId = $this->pollsModel->savePoll($formData, $this->user->getUserId());
$formData['user_id'] = $this->user->getUserId();
$pollId = $this->pollsModel->save($formData);
$bool2 = false;
if ($pollId !== false) {
......
......@@ -97,7 +97,8 @@ class Edit extends AbstractFormAction
return $this->actionHelper->handleEditPostAction(function () use ($formData, $pollId) {
$this->pollsValidator->validate($formData);
$bool = $this->pollsModel->savePoll($formData, $this->user->getUserId(), $pollId);
$formData['user_id'] = $this->user->getUserId();
$bool = $this->pollsModel->save($formData, $pollId);
if (!empty($formData['reset'])) {
$this->pollsModel->resetVotesByPollId($pollId);
......
......@@ -61,19 +61,6 @@ class PollsModel extends AbstractModel
$this->voteRepository = $voteRepository;
}
/**
* @param array $data
* @param int $userId
* @param null|int $pollId
* @return bool|int
*/
public function savePoll(array $data, $userId, $pollId = null)
{
$data['user_id'] = $userId;
return $this->save($data, $pollId);
}
/**
* @param array $answers
* @param int $pollId
......
......@@ -89,7 +89,7 @@ class Create extends Core\Controller\AbstractAdminAction
return $this->actionHelper->handleCreatePostAction(function () use ($formData) {
$this->adminFormValidation->validate($formData);
return $this->seoModel->saveUriAlias($formData);
return $this->seoModel->save($formData);
});
}
}
......@@ -97,7 +97,7 @@ class Edit extends Core\Controller\AbstractAdminAction
->setUriAlias($path)
->validate($formData);
return $this->seoModel->saveUriAlias($formData, $seoId);
return $this->seoModel->save($formData, $seoId);
});
}
}
......@@ -88,10 +88,10 @@ class UriAliasManager
// Update an existing result
if (!empty($seo)) {
$data['uri'] = $seo['uri'];
$bool = $this->seoModel->saveUriAlias($data, $seo['id']);
$bool = $this->seoModel->save($data, $seo['id']);
} else {
$data['uri'] = $path;
$bool = $this->seoModel->saveUriAlias($data);
$bool = $this->seoModel->save($data);
}
return $bool !== false;
......
......@@ -16,11 +16,9 @@ class SeoModel extends AbstractModel
const EVENT_PREFIX = Schema::MODULE_NAME;
/**
* @param array $data
* @param int|null $entryId
* @return bool|int
* @inheritdoc
*/
public function saveUriAlias(array $data, $entryId = null)
public function save(array $data, $entryId = null)
{
$data = array_merge($data, [
'keywords' => $data['seo_keywords'],
......@@ -28,7 +26,7 @@ class SeoModel extends AbstractModel
'robots' => $data['seo_robots']
]);
return $this->save($data, $entryId);
return parent::save($data, $entryId);
}
/**
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment