Permalink
Browse files

Finish fail-save routing for admin controllers, encode and decode acc…

…ess JSON in form and controller
  • Loading branch information...
redaxmedia committed Aug 6, 2018
1 parent ba8c529 commit 47b68a7791395f8113fe0972a6c697b78d1a9a10
Showing with 429 additions and 82 deletions.
  1. +53 −6 includes/Admin/Controller/Article.php
  2. +53 −6 includes/Admin/Controller/Category.php
  3. +52 −6 includes/Admin/Controller/Comment.php
  4. +35 −8 includes/Admin/Controller/Common.php
  5. +53 −6 includes/Admin/Controller/Extra.php
  6. +51 −4 includes/Admin/Controller/Group.php
  7. +47 −5 includes/Admin/Controller/Module.php
  8. +1 −1 includes/Admin/Controller/Setting.php
  9. +52 −5 includes/Admin/Controller/User.php
  10. +2 −2 includes/Admin/Model/Article.php
  11. +2 −2 includes/Admin/Model/Category.php
  12. +2 −2 includes/Admin/Model/Comment.php
  13. +2 −2 includes/Admin/Model/Extra.php
  14. +2 −2 includes/Admin/Model/Group.php
  15. +1 −1 includes/Admin/Model/Module.php
  16. +1 −1 includes/Admin/Model/Setting.php
  17. +2 −2 includes/Admin/Model/User.php
  18. +1 −1 includes/Admin/Template/Helper.php
  19. +1 −3 includes/Admin/View/ArticleForm.php
  20. +1 −0 includes/Admin/View/ArticleTable.php
  21. +1 −3 includes/Admin/View/CategoryForm.php
  22. +1 −0 includes/Admin/View/CategoryTable.php
  23. +1 −3 includes/Admin/View/CommentForm.php
  24. +2 −1 includes/Admin/View/CommentTable.php
  25. +1 −3 includes/Admin/View/ExtraForm.php
  26. +1 −0 includes/Admin/View/ExtraTable.php
  27. +1 −0 includes/Admin/View/GroupTable.php
  28. +1 −3 includes/Admin/View/ModuleForm.php
  29. +1 −0 includes/Admin/View/ModuleTable.php
  30. +1 −0 includes/Admin/View/UserTable.php
  31. +1 −1 includes/Model/Comment.php
  32. +1 −1 includes/Model/Module.php
  33. +1 −1 includes/Model/User.php
  34. +1 −1 includes/Template/Helper.php
@@ -40,7 +40,7 @@ public function process(string $action = null) : string
{
return $this->_error(
[
'route' => $postArray['id'] ? 'admin/edit/articles/' . $postArray['id'] : 'admin/new/articles',
'route' => $this->_getErrorRoute($postArray),
'message' => $validateArray
]);
}
@@ -74,7 +74,7 @@ public function process(string $action = null) : string
{
return $this->_success(
[
'route' => 'admin/view/articles#' . $postArray['alias'],
'route' => $this->_getSuccessRoute($postArray),
'timeout' => 2
]);
}
@@ -109,7 +109,7 @@ public function process(string $action = null) : string
{
return $this->_success(
[
'route' => 'admin/view/articles#' . $postArray['alias'],
'route' => $this->_getSuccessRoute($postArray),
'timeout' => 2
]);
}
@@ -119,7 +119,7 @@ public function process(string $action = null) : string
return $this->_error(
[
'route' => $postArray['id'] ? 'admin/edit/articles/' . $postArray['id'] : 'admin/new/articles'
'route' => $this->_getErrorRoute($postArray)
]);
}
@@ -157,7 +157,7 @@ protected function _sanitizePost() : array
'comments' => $specialFilter->sanitize($this->_request->getPost('comments')),
'status' => $specialFilter->sanitize($this->_request->getPost('status')),
'rank' => $specialFilter->sanitize($this->_request->getPost('rank')),
'access' => $specialFilter->sanitize($this->_request->getPost('access')),
'access' => json_encode($this->_request->getPost('access')),
'date' => strtotime($this->_request->getPost('date'))
];
}
@@ -226,7 +226,7 @@ protected function _create(array $createArray = []) : bool
* @since 4.0.0
*
* @param int $articleId identifier of the article
* @param array $updateArray
* @param array $updateArray array of the update
*
* @return bool
*/
@@ -236,4 +236,51 @@ public function _update(int $articleId = null, array $updateArray = []) : bool
$articleModel = new Admin\Model\Article();
return $articleModel->updateByIdAndArray($articleId, $updateArray);
}
/**
* get success route
*
* @since 4.0.0
*
* @param array $postArray array of the post
*
* @return string
*/
protected function _getSuccessRoute(array $postArray = []) : string
{
if ($this->_registry->get('articlesEdit') && $postArray['id'])
{
return 'admin/view/articles#row-' . $postArray['id'];
}
if ($this->_registry->get('articlesEdit') && $postArray['alias'])
{
$articleModel = new Admin\Model\Article();
return 'admin/view/articles#row-' . $articleModel->getByAlias($postArray['alias'])->id;
}
return 'admin';
}
/**
* get error route
*
* @since 4.0.0
*
* @param array $postArray array of the post
*
* @return string
*/
protected function _getErrorRoute(array $postArray = []) : string
{
if ($this->_registry->get('articlesEdit') && $postArray['id'])
{
return 'admin/edit/articles/' . $postArray['id'];
}
if ($this->_registry->get('articlesNew'))
{
return 'admin/new/articles';
}
return 'admin';
}
}
@@ -40,7 +40,7 @@ public function process(string $action = null) : string
{
return $this->_error(
[
'route' => $postArray['id'] ? 'admin/edit/categories/' . $postArray['id'] : 'admin/new/categories',
'route' => $this->_getErrorRoute($postArray),
'message' => $validateArray
]);
}
@@ -70,7 +70,7 @@ public function process(string $action = null) : string
{
return $this->_success(
[
'route' => 'admin/view/categories#' . $postArray['alias'],
'route' => $this->_getSuccessRoute($postArray),
'timeout' => 2
]);
}
@@ -101,7 +101,7 @@ public function process(string $action = null) : string
{
return $this->_success(
[
'route' => 'admin/view/categories#' . $postArray['alias'],
'route' => $this->_getSuccessRoute($postArray),
'timeout' => 2
]);
}
@@ -111,7 +111,7 @@ public function process(string $action = null) : string
return $this->_error(
[
'route' => $postArray['id'] ? 'admin/edit/categories/' . $postArray['id'] : 'admin/new/categories'
'route' => $this->_getErrorRoute($postArray)
]);
}
@@ -144,7 +144,7 @@ protected function _sanitizePost() : array
'parent' => $specialFilter->sanitize($this->_request->getPost('parent')),
'status' => $specialFilter->sanitize($this->_request->getPost('status')),
'rank' => $specialFilter->sanitize($this->_request->getPost('rank')),
'access' => $specialFilter->sanitize($this->_request->getPost('access')),
'access' => json_encode($this->_request->getPost('access')),
'date' => strtotime($this->_request->getPost('date'))
];
}
@@ -209,7 +209,7 @@ protected function _create(array $createArray = []) : bool
* @since 4.0.0
*
* @param int $categoryId identifier of the category
* @param array $updateArray
* @param array $updateArray array of the update
*
* @return bool
*/
@@ -219,4 +219,51 @@ public function _update(int $categoryId = null, array $updateArray = []) : bool
$categoryModel = new Admin\Model\Category();
return $categoryModel->updateByIdAndArray($categoryId, $updateArray);
}
/**
* get success route
*
* @since 4.0.0
*
* @param array $postArray array of the post
*
* @return string
*/
protected function _getSuccessRoute(array $postArray = []) : string
{
if ($this->_registry->get('categoriesEdit') && $postArray['id'])
{
return 'admin/view/categories#row-' . $postArray['id'];
}
if ($this->_registry->get('categoriesEdit') && $postArray['alias'])
{
$categoryModel = new Admin\Model\Category();
return 'admin/view/categories#row-' . $categoryModel->getByAlias($postArray['alias'])->id;
}
return 'admin';
}
/**
* get error route
*
* @since 4.0.0
*
* @param array $postArray array of the post
*
* @return string
*/
protected function _getErrorRoute(array $postArray = []) : string
{
if ($this->_registry->get('categoriesEdit') && $postArray['id'])
{
return 'admin/edit/categories/' . $postArray['id'];
}
if ($this->_registry->get('categoriesNew'))
{
return 'admin/new/categories';
}
return 'admin';
}
}
@@ -40,7 +40,7 @@ public function process(string $action = null) : string
{
return $this->_error(
[
'route' => $postArray['id'] ? 'admin/edit/comments/' . $postArray['id'] : 'admin/new/comments',
'route' => $this->_getErrorRoute($postArray),
'message' => $validateArray
]);
}
@@ -66,7 +66,7 @@ public function process(string $action = null) : string
{
return $this->_success(
[
'route' => 'admin/view/comments#' . $postArray['alias'],
'route' => $this->_getSuccessRoute($postArray),
'timeout' => 2
]);
}
@@ -91,7 +91,7 @@ public function process(string $action = null) : string
{
return $this->_success(
[
'route' => 'admin/view/comments#' . $postArray['alias'],
'route' => $this->_getSuccessRoute($postArray),
'timeout' => 2
]);
}
@@ -101,7 +101,7 @@ public function process(string $action = null) : string
return $this->_error(
[
'route' => $postArray['id'] ? 'admin/edit/comments/' . $postArray['id'] : 'admin/new/comments'
'route' => $this->_getErrorRoute($postArray)
]);
}
@@ -130,7 +130,7 @@ protected function _sanitizePost() : array
'article' => $specialFilter->sanitize($this->_request->getPost('article')),
'status' => $specialFilter->sanitize($this->_request->getPost('status')),
'rank' => $specialFilter->sanitize($this->_request->getPost('rank')),
'access' => $specialFilter->sanitize($this->_request->getPost('access')),
'access' => json_encode($this->_request->getPost('access')),
'date' => strtotime($this->_request->getPost('date'))
];
}
@@ -180,7 +180,7 @@ protected function _create(array $createArray = []) : bool
* @since 4.0.0
*
* @param int $commentId identifier of the comment
* @param array $updateArray
* @param array $updateArray array of the update
*
* @return bool
*/
@@ -190,4 +190,50 @@ public function _update(int $commentId = null, array $updateArray = []) : bool
$commentModel = new Admin\Model\Comment();
return $commentModel->updateByIdAndArray($commentId, $updateArray);
}
/**
* get success route
*
* @since 4.0.0
*
* @param array $postArray array of the post
*
* @return string
*/
protected function _getSuccessRoute(array $postArray = []) : string
{
if ($this->_registry->get('commentsEdit'))
{
if ($postArray['id'])
{
return 'admin/view/comments#row-' . $postArray['id'];
}
return 'admin/view/comments';
}
return 'admin';
}
/**
* get error route
*
* @since 4.0.0
*
* @param array $postArray array of the post
*
* @return string
*/
protected function _getErrorRoute(array $postArray = []) : string
{
if ($this->_registry->get('commentsEdit') && $postArray['id'])
{
return 'admin/edit/comments/' . $postArray['id'];
}
if ($this->_registry->get('commentsNew'))
{
return 'admin/new/comments';
}
return 'admin';
}
}
Oops, something went wrong.

0 comments on commit 47b68a7

Please sign in to comment.