diff --git a/application/modules/admin/controllers/CmsController.php b/application/modules/admin/controllers/CmsController.php index 1a9d96a3e4ec8372dd5ccc93c2d1aa27faeef9eb..ddc825c9a3f875356d947009e0f9b0140b8c67ce 100644 --- a/application/modules/admin/controllers/CmsController.php +++ b/application/modules/admin/controllers/CmsController.php @@ -360,27 +360,11 @@ class Admin_CmsController extends ZendAfi_Controller_Action { protected function _sendMailToValidators($article) { - $mail = new ZendAfi_Mail('utf8'); - $categorie = $article->getCategorie(); - $validate_article = Class_Permission::getWorkflow(Class_Article::STATUS_VALIDATED); - - $groups = array_filter(Class_Permission::validateArticle()->getGroups(), - function ($group) use ($categorie, $validate_article) - { - return $group->hasPermissionOn($validate_article, $categorie); - }); - - $mails = []; - foreach($groups as $group) { - $mails = array_merge($mails, - array_filter(array_map(function($user) - { - return $user->getMail(); - }, - $group->getUsers()))); - } + $mails = Class_Permission::getWorkflow(Class_Article::STATUS_VALIDATED) + ->getUsersOnModel($article->getCategorie()) + ->collect('mail'); - if (empty($mails)) + if ($mails->isEmpty()) return; $body = Class_AdminVar::getWorkflowTextMailArticlePending(); @@ -391,9 +375,10 @@ class Admin_CmsController extends ZendAfi_Controller_Action { $this->view->absoluteUrl($article->getUrl(), null, true), $body); + $mail = new ZendAfi_Mail('utf8'); $mail ->setFrom('no-reply@afi-sa.fr') - ->addTo(implode(',',$mails)) + ->addTo(implode(',', $mails->getArrayCopy())) ->setSubject($this->_('[Bokeh] Validation d\'article en attente: ') . $article->getTitre()) ->setBodyText($body); diff --git a/library/Class/Permission.php b/library/Class/Permission.php index 3b7a26bb29f6be45847d1763ca97fb772484738e..c4c31ea40a7ab908635093353be5c5350b879ef9 100644 --- a/library/Class/Permission.php +++ b/library/Class/Permission.php @@ -95,6 +95,8 @@ class PermissionLoader extends Storm_Model_Loader { } + + class Class_Permission extends Storm_Model_Abstract { protected $_table_name = 'permission'; protected $_loader_class = 'PermissionLoader'; @@ -117,4 +119,19 @@ class Class_Permission extends Storm_Model_Abstract { public function denyTo($group, $model) { Class_UserGroup_Permission::deny($this, $group, $model); } + + + public function getUsersOnModel($model) { + $groups = array_filter($this->getGroups(), + function ($group) use ($model) + { + return $group->hasPermissionOn($this, $model); + }); + $users = new Storm_Model_Collection(); + + foreach($groups as $group) + $users->addAll($group->getUsers()); + + return $users; + } } \ No newline at end of file diff --git a/library/ZendAfi/Controller/Action/Helper/ArticleListViewMode.php b/library/ZendAfi/Controller/Action/Helper/ArticleListViewMode.php index 4324c4d0a5d66c9a5f28060b408df994c88dbe1b..50e058377f7bcd36141871ef34deb9c9da06febd 100644 --- a/library/ZendAfi/Controller/Action/Helper/ArticleListViewMode.php +++ b/library/ZendAfi/Controller/Action/Helper/ArticleListViewMode.php @@ -132,8 +132,9 @@ class ZendAfi_Controller_Action_Helper_ArticleListViewMode extends ZendAfi_Contr return $this->_filtred_categories_ids; $categories = $this->getFilteredCategories($this->getRecursiveCategoriesForUser()); - $this->_filtred_categories_ids = array_map(function($model) { return $model->getId(); }, - $categories); + $this->_filtred_categories_ids = array_values( + array_map(function($model) { return $model->getId(); }, + $categories)); return $this->_filtred_categories_ids; } diff --git a/tests/application/modules/admin/controllers/CmsControllerTest.php b/tests/application/modules/admin/controllers/CmsControllerTest.php index dc3d37f50d784fe0ba429a1854fe6da1dfbe14d3..9e8a9c25b4e235dd21752490e143a7c88a3ddd30 100644 --- a/tests/application/modules/admin/controllers/CmsControllerTest.php +++ b/tests/application/modules/admin/controllers/CmsControllerTest.php @@ -157,7 +157,7 @@ abstract class CmsControllerTestCase extends Admin_AbstractControllerTestCase { ['id' => 1, 'libelle' => 'Root']); $this->_cat_atelier = $this->fixture('Class_ArticleCategorie', - ['id' => 42, + ['id' => 33, 'libelle' => 'Atelier', 'parent_categorie' => $this->root_category]);