diff --git a/VERSIONS_HOTLINE/135232 b/VERSIONS_HOTLINE/135232 new file mode 100644 index 0000000000000000000000000000000000000000..69972df8b80271538e3d4a07df69d13bf3417761 --- /dev/null +++ b/VERSIONS_HOTLINE/135232 @@ -0,0 +1,2 @@ + - ticket #135232 : Magasin de thèmes : Réactivation de la modération des avis de type note. + Le nom de l'auteur de l'avis est toujours visible même lorsqu'il s'agit d'une note. \ No newline at end of file diff --git a/application/modules/opac/controllers/AbonneController.php b/application/modules/opac/controllers/AbonneController.php index 64d2ad5846324e22b1399d6031b7b69071730e16..cd3961315a3df8a7c0fe30ee4826f0d8e9886984 100644 --- a/application/modules/opac/controllers/AbonneController.php +++ b/application/modules/opac/controllers/AbonneController.php @@ -1437,21 +1437,22 @@ class AbonneController extends ZendAfi_Controller_Action { ->setIdNotice($this->_getParam('record_id')) ->setClefOeuvre($this->_getParam('record_key')) ->setUserRole($this->_user) - ->setModerationOK() ->updateAttributes($post); - if ($this->_getPost('entete') || $this->_getPost('avis')) - $rating->setModerationNOK(); - - if (!$form->isValidModelAndArray($rating, $post)) + if ($form->isValidModelAndArray($rating, $post) + && $rating->save()) { + $this->_helper->notify($this->_('Votre avis %s / %s a été pris en compte.', + $this->_getPost('note'), + 5), + ['status' => 'success']); return $this->_redirectClose($this->_getReferer()); + } - if (!$rating->save()) - return false; - $this->_helper->notify($this->_('Votre avis %s / %s a été pris en compte.', + $this->_helper->notify($this->_('Votre avis %s / %s n\'a pas été pris en compte car une erreur est survenue.', $this->_getPost('note'), - 5)); + 5), + ['status' => 'error']); return $this->_redirectClose($this->_getReferer()); } @@ -1482,12 +1483,8 @@ class AbonneController extends ZendAfi_Controller_Action { ->setIdNotice($this->_getParam('record_id')) ->setClefOeuvre($this->_getParam('record_key')) ->setUserRole($this->_user) - ->setModerationOK() ->updateAttributes($post); - if ($this->_getPost('entete') || $this->_getPost('avis')) - $rating->setModerationNOK(); - if (!$form->isValidModelAndArray($rating, $post)) return $this->_response->setHttpResponseCode(520); diff --git a/library/templates/Intonation/Assets/css/intonation.css b/library/templates/Intonation/Assets/css/intonation.css index 93935a19163380fde76e08f8626b7353217acc3b..1fde9a1bd5c5f42b673b1f1ced6b509a067a90fb 100644 --- a/library/templates/Intonation/Assets/css/intonation.css +++ b/library/templates/Intonation/Assets/css/intonation.css @@ -89,6 +89,7 @@ div:hover > .img_as_background { .card-link img:first-child, i:first-child, +i:first-child:last-child, .widget.rech_simple .dropdown-menu i:first-child, .widget.rech_simple .criteres_recherche i:first-child, .card-link + .card-link, diff --git a/library/templates/Intonation/Library/Settings.php b/library/templates/Intonation/Library/Settings.php index 5c1103917834cfb9a526908c82cd01947a67b57e..3a61973ae2c4a2c82cff989e5f6be806065cb102 100644 --- a/library/templates/Intonation/Library/Settings.php +++ b/library/templates/Intonation/Library/Settings.php @@ -296,6 +296,7 @@ class Intonation_Library_Settings extends Intonation_System_Abstract { 'a class clear_history_button' => 'btn btn-sm btn-warning', 'form class user_configuration_form' => 'form row no-gutters', 'a class manage_activities_button' => 'btn btn-sm btn-success menu_admin_front_anchor', + 'input class zendafi_form_review_review_submit' => 'ml-auto mr-auto mt-3', ], 'icons_map_doc_types' => [], diff --git a/library/templates/Intonation/Library/View/Wrapper/Review.php b/library/templates/Intonation/Library/View/Wrapper/Review.php index da31ee306457858b2f635e680c6c8bb7095affc8..5c16f84f5c7a4849546802a30bc92380331ba8d6 100644 --- a/library/templates/Intonation/Library/View/Wrapper/Review.php +++ b/library/templates/Intonation/Library/View/Wrapper/Review.php @@ -22,42 +22,30 @@ class Intonation_Library_View_Wrapper_Review extends Intonation_Library_View_Wrapper_Abstract { - public function getMainTitle() { - if (($title = $this->_model->getEntete()) - && $this->_model->getAvis()) { - $html = [ - $this->_view->div(['class' => 'review_author'], - $this->_view->tag('span', - $this->getSecondaryTitle(), - ['class' => 'text-muted small'])), + protected $_badges_caches; + - $this->_view->div(['class' => 'review_date'], - $this->_view->tag('span', - $this->_('le %s', $this->_model->getHumanDate()), - ['class' => 'text-muted small'])), + public function getMainTitle() { + $html = + [$this->_view->div(['class' => 'review_author'], + $this->_view->tag('span', + $this->getSecondaryTitle(), - $this->_view->div(['class' => 'review_rating'], - $this->_view->rating($this->_model->getNote())), + ['class' => 'text-muted small'])), - $this->_view->div(['class' => 'review_title'], - $title) - ]; + $this->_view->div(['class' => 'review_date'], + $this->_view->tag('span', + $this->_('le %s', $this->_model->getHumanDate()), + ['class' => 'text-muted small'])), - return $this->_view->grid(implode($html)); - } - $html = [ - $this->_view->div(['class' => 'score_rating'], - $this->_view->rating($this->_model->getNote())), + $this->_view->div(['class' => 'review_rating'], + $this->_view->rating($this->_model->getNote()))]; - $this->_view->div(['class' => 'score_date'], - $this->_view->tag('span', - $this->_('le %s', $this->_model->getHumanDate()), - ['class' => 'text-muted small', - 'title' => $this->getSecondaryTitle()])) - ]; + if ($title = $this->_model->getEntete()) + $html [] = $this->_view->div(['class' => 'review_title'], $title); - return $this->_view->grid(implode($html)); + return $this->_view->grid($html); } @@ -146,7 +134,18 @@ class Intonation_Library_View_Wrapper_Review extends Intonation_Library_View_Wra public function getBadges() { - return ''; + if ($this->_badges_cache) + return $this->_badges_cache; + + if ( ! $this->_model->isWaitingForModeration()) + return ''; + + $badges = [((new Intonation_Library_Badge) + ->setClass('review_moderation') + ->setImage($this->getIco('check-list', 'utils')) + ->setText($this->_('En attente de modération')))]; + + return $this->_badges_cache = $this->_view->renderBadges($badges, $this); } diff --git a/library/templates/Intonation/View/RenderReviewForm.php b/library/templates/Intonation/View/RenderReviewForm.php index b7a549b5b5afcb833b7f625bb9ab16bf999be5b5..691edf58fcdd77de179ef78f2d35e1c50f63ba13 100644 --- a/library/templates/Intonation/View/RenderReviewForm.php +++ b/library/templates/Intonation/View/RenderReviewForm.php @@ -21,27 +21,42 @@ class Intonation_View_RenderReviewForm extends ZendAfi_View_Helper_BaseHelper { + + public function renderReviewForm($review, $ajax = false) { if (!$record = $review->getFirstNotice()) return ''; - $params = ['controller' => 'abonne', - 'action' => 'review', - 'record_id' => $record->getId(), - 'record_key' => $record->getClefOeuvre(), - 'id' => $review->getId()]; + $params = + ['controller' => 'abonne', + 'action' => $ajax ? 'ajax-review' : 'review', + 'record_id' => $record->getId(), + 'record_key' => $record->getClefOeuvre(), + 'id' => $review->getId()]; $form = ZendAfi_Form_Review::newWith($review->toArray()); + + $form->setAction($this->view->url($params, null, true)); + $form->getElement('entete')->setValue(''); - if ($ajax) { - $form->addElement('submit', - 'submit' . $form->getAttrib('id'), - ['label' => $this->_('Valider')]); + $form = $ajax + ? $this->_ajaxMode($form) + : $this->_standardMode($form); - Class_ScriptLoader::getInstance() - ->addJQueryReady( - sprintf(' + return $this->view->renderForm($form); + } + + + protected function _ajaxMode($form) { + $form->addElement('submit', + 'submit' . $form->getAttrib('id'), + ['label' => $this->_('Valider'), + 'onclick' => 'return confirm(\'Confirmer votre avis ?\');']); + + Class_ScriptLoader::getInstance() + ->addJQueryReady( + sprintf(' $("#%s").submit(function(e) { e.preventDefault(); e.stopPropagation(); @@ -58,11 +73,20 @@ $.ajax( }}); });', $form->getAttrib('id'))); - $params['action'] = 'ajax-review'; - } + return $form; + } - $form->setAction($this->view->url($params, null, true)); - return $this->view->renderForm($form); + protected function _standardMode($form) { + $form + ->addElement('submit', + 'review_submit', + ['label' => $this->_('Valider'), + 'title' => $this->_('Valider mon avis.'), + 'onclick' => sprintf("if (confirm('%s')) { %s }; return false;", + $this->_escapeJsAttrib($this->_('Confirmer votre avis ?')), + '$(this).parents(\'form\').submit()')]); + $form->addToDisplayGroup(['review_submit'], 'review'); + return $form; } } diff --git a/tests/scenarios/Templates/TemplatesReviewsTest.php b/tests/scenarios/Templates/TemplatesReviewsTest.php index 1f2911b8aeab2c7d54f5aff4d4b6f9481d8caf82..84adf3f4821a53f8d3a80875d197358474e5c68d 100644 --- a/tests/scenarios/Templates/TemplatesReviewsTest.php +++ b/tests/scenarios/Templates/TemplatesReviewsTest.php @@ -56,8 +56,8 @@ class TemplatesReviewsAddTest extends TemplatesIntonationTestCase { } /** @test */ - public function ratingShouldBeAutoModerated() { - $this->assertEquals(Trait_Avis::$STATUT_OK, $this->_review->getStatut()); + public function ratingShouldNotBeAutoModerated() { + $this->assertEquals(Trait_Avis::$STATUT_NOK, $this->_review->getStatut()); } /** @test */ @@ -102,8 +102,8 @@ class TemplatesReviewsAddAjaxTest extends TemplatesIntonationTestCase { } /** @test */ - public function ratingShouldBeAutoModerated() { - $this->assertEquals(Trait_Avis::$STATUT_OK, $this->_review->getStatut()); + public function ratingShouldNotBeAutoModerated() { + $this->assertEquals(Trait_Avis::$STATUT_NOK, $this->_review->getStatut()); } /** @test */ @@ -420,7 +420,7 @@ class TemplatesReviewsActionAdminLoggedWithLibrarianOnlyVarTest /** @test */ public function formToAddReviewShouldBePresent() { - $this->assertXPath('//form[contains(@action, "/abonne/review/record_id/2")]'); + $this->assertXPath('//form[contains(@action, "/abonne/review/record_id/2")]//input[@type="submit"][@class="zendafi_form_review_review_submit btn btn-sm btn-primary ml-auto mr-auto mt-3"]'); } } @@ -648,3 +648,50 @@ class TemplatesReviewsWidgetWithDescriptionLengthTest extends AbstractController 'La description s\'arrête ici …'); } } + + + + +class TemplatesReviewsAsAdminTest extends Admin_AbstractControllerTestCase { + protected $_storm_default_to_volatile = true; + + + public function setUp() { + parent::setUp(); + $this->_buildTemplateProfil(['id' => 90, + 'template' => 'MUSCLE']); + + $reviewer = $this->fixture('Class_Users', + ['id' => '88', + 'login' => 'Albert', + 'password' => 'secret', + 'role_level' => ZendAfi_Acl_AdminControllerRoles::INVITE]); + + $this->fixture('Class_Notice', + ['id' => 8, + 'clef_oeuvre' => 'PROMENADEPETITBONHOMME']); + + $this->fixture('Class_AvisNotice', + ['id' => 4, + 'id_notice' => 8, + 'clef_oeuvre' => 'PROMENADEPETITBONHOMME', + 'note' => 4, + 'entete' => 'To delete', + 'avis' => 'To delete', + ]) + ->beImportMode() + ->setEntete('') + ->setAvis('') + ->setUser($reviewer) + ->setUserRole($reviewer) + ->save(); + + $this->dispatch('admin/modo/avisnotice'); + } + + + /** @test */ + public function ratingFourShouldBeReadyToBeValidate() { + $this->assertXPath('//div//a[@href="/admin/modo/validateavisnotice/id/4/active_tab/1/page/0"]'); + } +} \ No newline at end of file diff --git a/tests/scenarios/Templates/TemplatesSearchTest.php b/tests/scenarios/Templates/TemplatesSearchTest.php index afe817e4dac959dcfacb2a9eccb7600065098865..4d8b2570da7192984e9c52d0e660bc67b806623a 100644 --- a/tests/scenarios/Templates/TemplatesSearchTest.php +++ b/tests/scenarios/Templates/TemplatesSearchTest.php @@ -264,13 +264,19 @@ class TemplatesSearchViewRecordTest extends TemplatesIntonationTestCase { /** @test */ public function scoreRating4StarsShouldBeDisplay() { - $this->assertXPath('//div[@class = "score_rating col-12 col-lg-6 text-md-left"]//span/i[@title="Note : 4 / 5"]'); + $this->assertXPath('//div[@class = "review_rating col-12"]//span/i[@title="Note : 4 / 5"]'); } /** @test */ public function scoreDateIn2016ShouldBeDisplay() { - $this->assertXPathContentContains('//div[@class = "score_date col-12 col-lg-5 text-md-right"]//span', 'le 18 mars 2016'); + $this->assertXPathContentContains('//div[@class = "review_date col-12 col-lg-6 text-md-right"]//span', 'le 18 mars 2016'); + } + + + /** @test */ + public function scoreAuthorShouldBeDisplay() { + $this->assertXPath('//div[@class = "review_author col-12 col-lg-6 text-md-left"]//span'); }