diff --git a/application/modules/admin/controllers/ModoController.php b/application/modules/admin/controllers/ModoController.php index a553de9ff0e5e637fce202d500decb3c8588c25a..d9c9314525c6db4b9f6f8d7dc3f901d4380231b6 100644 --- a/application/modules/admin/controllers/ModoController.php +++ b/application/modules/admin/controllers/ModoController.php @@ -33,10 +33,65 @@ class Admin_ModoController extends ZendAfi_Controller_Action { $avis_bib = Class_AvisNotice::filterByBibliothecaire($all_avis); $avis_abo = Class_AvisNotice::filterByAbonne($all_avis); + $orphans = Class_AvisNotice::filterByOrphan($all_avis); + $archived = Class_AvisNotice::filterByArchived($all_avis); $this->view->subview = $this->view->partial('modo/avisnotice.phtml', ['list_avis_bibliothecaires' => $avis_bib, - 'list_avis_utilisateurs' => $avis_abo]); + 'list_avis_utilisateurs' => $avis_abo, + 'list_orphan_reviews' => $orphans, + 'list_archived_reviews' => $archived, + 'display_all' => true +]); + + $this->_forward('index'); + } + + + public function invisibleavisnoticeAction() { + if (!$review_id=$this->_request->getParam('id',0)) + $this->_forward('index'); + $review=Class_AvisNotice::find($review_id); + $review->setFlags(Class_AvisNotice::ARCHIVED_FLAG)->save(); + + $this->_forward('allreviews'); + } + + + public function visibleavisnoticeAction() { + if (!$review_id=$this->_request->getParam('id',0)) + $this->_forward('index'); + $review=Class_AvisNotice::find($review_id); + $review->setFlags(Class_AvisNotice::NO_FLAG)->save(); + + $this->_forward('allreviews'); + } + + + public function allreviewsAction() { + + $avis_bib = Class_AvisNotice::findAllBy(['abon_ou_bib' => Trait_Avis::$AVIS_BIBLIO, + 'flags' => 0, + 'order' => 'date_avis desc', + 'limitPage' => [1,20]]); + $avis_abo = Class_AvisNotice::findAllBy(['abon_ou_bib' => Trait_Avis::$AVIS_ABONNE, + 'flags' => 0, + 'order' => 'date_avis desc', + 'limitPage' => [1,20]]); + $orphans = Class_AvisNotice::findAllBy(['flags' => Class_AvisNotice::ORPHAN_FLAG, + 'order' => 'date_avis desc', + 'limitPage' => [1,20]]); + $archived = Class_AvisNotice::findAllBy(['flags' => Class_AvisNotice::ARCHIVED_FLAG, + 'order' => 'date_avis desc', + 'limitPage' => [1,20]]); + + $this->view->subview = $this->view->partial('modo/avisnotice.phtml', + ['list_avis_bibliothecaires' => $avis_bib, + 'list_avis_utilisateurs' => $avis_abo, + 'list_orphan_reviews' => $orphans, + 'list_archived_reviews' => $archived, + 'display_all' => false +]); $this->_forward('index'); } diff --git a/application/modules/admin/views/scripts/modo/_avis_partial.phtml b/application/modules/admin/views/scripts/modo/_avis_partial.phtml index 5c62ec2e78c9c948d5b15f2dd01bbfb9548ed157..d62871b971ccfd30203be4720ce61bb401a814fb 100644 --- a/application/modules/admin/views/scripts/modo/_avis_partial.phtml +++ b/application/modules/admin/views/scripts/modo/_avis_partial.phtml @@ -1,4 +1,9 @@ <div class="<?php echo $this->item_class ?>"> + <?php + $actions = ['validate', 'edit', 'del']; + if ($this->avis->getFlags()>=0) + $actions[] = ($this->avis->getFlags()==0) ? 'invisible' :'visible'; + $this->getHelper('avis')->setActions($actions); ?> <?php echo $this->avis($this->avis) ?> <div class='clear'></div> -</div> \ No newline at end of file +</div> diff --git a/application/modules/admin/views/scripts/modo/allreviews.phtml b/application/modules/admin/views/scripts/modo/allreviews.phtml new file mode 100644 index 0000000000000000000000000000000000000000..824c4a3bd6d48e4794d4faf640b24e4136c0a267 --- /dev/null +++ b/application/modules/admin/views/scripts/modo/allreviews.phtml @@ -0,0 +1,25 @@ +<?php + +echo '<h1>'.$this->traduire('Modération des avis sur les notices').'</h1>'; + +echo '<div id="avis-notice-liste" >'; + +echo $this->avisBloc('Bibliothécaires', $this->list_avis_bibliothecaires); + +echo $this->avisBloc('Abonnés', $this->list_avis_utilisateurs); + +echo $this->avisBloc('Avis orphelins', $this->list_orphan_reviews); + +echo $this->avisBloc('Avis archives', $this->list_archived_reviews); + +echo '</div>'; + +?> + +<script type='text/javascript'> + $(document).ready(function() { + $('.critique a:not(.actions a)').attr('target', '_blank'); + $('#avis-notice-liste').accordion({heightStyle:'content',disabled:false, icons:null}); + $('#avis-notice-liste .ui-accordion-content').show(); + }); +</script> diff --git a/application/modules/admin/views/scripts/modo/avisnotice.phtml b/application/modules/admin/views/scripts/modo/avisnotice.phtml index c0cd162c77e71ce0bb572cc29da49069b4b29a1b..8286f614fcaa940fb22b267ced6974ca4a3d1431 100644 --- a/application/modules/admin/views/scripts/modo/avisnotice.phtml +++ b/application/modules/admin/views/scripts/modo/avisnotice.phtml @@ -1,24 +1,27 @@ -<?php - -echo '<h1>'.$this->traduire('Modération des avis sur les notices').'</h1>'; +<?php +echo '<h1>'.$this->traduire('Modération des avis sur les notices').'</h1>'; +if ($this->display_all) + echo $this->tagAnchor(['action' => 'allreviews'],"Afficher tous les avis"); echo '<div id="avis-notice-liste" >'; echo $this->avisBloc('Bibliothécaires', $this->list_avis_bibliothecaires); echo $this->avisBloc('Abonnés', $this->list_avis_utilisateurs); -echo '</div>'; +echo $this->avisBloc('Avis orphelins', $this->list_orphan_reviews); +echo $this->avisBloc('Avis archives', $this->list_archived_reviews); +echo '</div>'; -?> +?> <script type='text/javascript'> $(document).ready(function() { $('.critique a:not(.actions a)').attr('target', '_blank'); - $('#avis-notice-liste').accordion({heightStyle:'content',disabled:true, icons:null}); + $('#avis-notice-liste').accordion({heightStyle:'content',collapsible:true,disabled:false, icons:null}); $('#avis-notice-liste .ui-accordion-content').show(); }); </script> diff --git a/cosmogramme/php/_init.php b/cosmogramme/php/_init.php index dcd5895a549aae6ff38388ecfabbb1f53252dc5b..fd12ea4641593a002fdb218c22c0c1e3dca605b0 100644 --- a/cosmogramme/php/_init.php +++ b/cosmogramme/php/_init.php @@ -1,7 +1,7 @@ <?php error_reporting(E_ERROR | E_PARSE); -define("PATCH_LEVEL","264"); +define("PATCH_LEVEL","265"); define("APPLI","cosmogramme"); define("COSMOPATH", "/var/www/html/vhosts/opac2/www/htdocs"); diff --git a/cosmogramme/sql/patch/patch_265.php b/cosmogramme/sql/patch/patch_265.php new file mode 100644 index 0000000000000000000000000000000000000000..8491258ebb0991426e0d90576317b381fd9fddad --- /dev/null +++ b/cosmogramme/sql/patch/patch_265.php @@ -0,0 +1,11 @@ +<?php +$adapter = Zend_Db_Table::getDefaultAdapter(); + +try { + $adapter->query('select flags from cms_avis limit 1'); +} catch (Exception $e) { + $adapter->query('ALTER TABLE cms_avis ADD COLUMN flags tinyint default 0'); + $adapter->query('ALTER TABLE cms_avis ADD INDEX (flags)'); +} + +?> \ No newline at end of file diff --git a/library/Class/Avis.php b/library/Class/Avis.php index 98b3157976343aad6a86c6f034e17849cdb05bac..7ada26071f2525136baffdeabfdac098968d719b 100644 --- a/library/Class/Avis.php +++ b/library/Class/Avis.php @@ -37,11 +37,10 @@ class Class_Avis extends Storm_Model_Abstract { protected $_default_attribute_values = ['entete' => '', 'avis' => '', + 'flags' => 0, 'note' => 0 ]; - - /** Ecrire 1 avis (update si existe déjà ) */ public static function ecrireCmsAvis($id_user, $role_level, $id_news, $note, $entete, $content) { $modo_avis_abo = getVar('MODO_AVIS'); // 0 apres / 1 avant de publier sur le site @@ -120,6 +119,10 @@ class Class_Avis extends Storm_Model_Abstract { $rank->save(); } + + public function getFlags() { + return -1; + } } ?> \ No newline at end of file diff --git a/library/Class/AvisNotice.php b/library/Class/AvisNotice.php index 6eeb31c449fa5327b995b4121571dcccd0aa04fc..245a31e070480393b667b39055ebf2a07deec974 100644 --- a/library/Class/AvisNotice.php +++ b/library/Class/AvisNotice.php @@ -42,6 +42,16 @@ class AvisNoticeLoader extends Storm_Model_Loader { return $this; } + public function findOrphanReviews() { + return Class_AvisNotice::findAllBy(['flags' => Class_AvisNotice::ORPHAN_FLAG, + 'order' => 'date_avis']); + } + + + public function findArchivedReviews() { + return Class_AvisNotice::findAllBy(['flags' => Class_AvisNotice::ARCHIVED_FLAG, + 'order' => 'date_avis']); + } protected function _addStatutAbonBibWhereClause($abon_ou_bib, &$params) { $modo_avis_abo = Class_AdminVar::get('MODO_AVIS'); // 0 apres / 1 avant de publier sur le site @@ -67,13 +77,6 @@ class AvisNoticeLoader extends Storm_Model_Loader { } - public function findAllAfter($record_id) { - $where = "id > " . $record_id ; - return Class_AvisNotice::findAllBy(['where' => $where, - 'order' => 'id', - 'limit' => '100']); - } - /* Renvoie les avis correspondants aux préférences de recherches données @@ -122,6 +125,7 @@ class Class_AvisNotice extends Storm_Model_Abstract { use Trait_Avis, Trait_Translator; const NO_FLAG=0; const ORPHAN_FLAG=1; + const ARCHIVED_FLAG=2; protected $_loader_class = 'AvisNoticeLoader'; protected $_table_name = 'notices_avis'; @@ -133,7 +137,8 @@ class Class_AvisNotice extends Storm_Model_Abstract { protected $_default_attribute_values = ['statut' => 0, 'flags' => self::NO_FLAG, 'clef_oeuvre' => '', - 'date_avis' => null]; + 'date_avis' => null, + 'note' => 0]; protected $_notices; protected $_import_mode = false; @@ -160,6 +165,16 @@ class Class_AvisNotice extends Storm_Model_Abstract { } + public static function filterByOrphan($avis_list) { + return self::filterByMethod($avis_list, 'isOrphan'); + } + + + public static function filterByArchived($avis_list) { + return self::filterByMethod($avis_list, 'isArchived'); + } + + public static function filterByBibliothecaire($avis_list) { return self::filterByMethod($avis_list, 'isWrittenByBibliothecaire'); } diff --git a/library/Trait/Avis.php b/library/Trait/Avis.php index 2c4a9c88d4e69f827226abf86169e864556ec52c..9cce4a6f6a7cbadd79d12a4672f3579c59a8aaae 100644 --- a/library/Trait/Avis.php +++ b/library/Trait/Avis.php @@ -16,7 +16,7 @@ * * You should have received a copy of the GNU AFFERO GENERAL PUBLIC LICENSE * along with BOKEH; if not, write to the Free Software - * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ trait Trait_Avis { @@ -79,6 +79,13 @@ trait Trait_Avis { return $this->getAbonOuBib() == self::$AVIS_ABONNE; } + public function isOrphan() { + return $this->getFlags() == self::ORPHAN_FLAG ; + } + + public function isArchived() { + return $this->getFlags() == self::ARCHIVED_FLAG ; + } public function beWrittenByAbonne() { return $this->setAbonOuBib(self::$AVIS_ABONNE); diff --git a/library/ZendAfi/View/Helper/AvisBloc.php b/library/ZendAfi/View/Helper/AvisBloc.php index a94796d343af099b55175467f60095791dcbef36..05d4817d0dec54deba2ca98ff15a481dabf3f03d 100644 --- a/library/ZendAfi/View/Helper/AvisBloc.php +++ b/library/ZendAfi/View/Helper/AvisBloc.php @@ -16,18 +16,18 @@ * * You should have received a copy of the GNU AFFERO GENERAL PUBLIC LICENSE * along with BOKEH; if not, write to the Free Software - * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ class ZendAfi_View_Helper_AvisBloc extends Zend_View_Helper_HtmlElement { - public function avisBloc($libelle_bloc, $avis_list) { + public function avisBloc($libelle_bloc, $avis_list) { $libelle_bloc = $this->view->_($libelle_bloc); return $this->renderHtmlAvisBloc($libelle_bloc, $avis_list); - } + } - public function renderHtmlAvisBloc($libelle, $list) { + public function renderHtmlAvisBloc($libelle, $list) { $html = '<h2>'.$libelle.'</h2>'; $html.= '<div>'; @@ -35,15 +35,14 @@ class ZendAfi_View_Helper_AvisBloc extends Zend_View_Helper_HtmlElement { $empty = $this->view->_('Aucun avis ' . ($libelle ? $libelle . ' ' : '') . 'à modérer.'); $html.='<p align="center" class="error">'.$empty.'</p>'; } else { - $this->view->getHelper('avis')->setActions(['validate', 'edit', 'del']); - $html.= $this->view->partialCycle('modo/_avis_partial.phtml', + + $html.= $this->view->partialCycle('modo/_avis_partial.phtml', 'avis', $list, ['first', - 'second']); + 'second']); } return $html.='</div>'; } } - diff --git a/library/ZendAfi/View/Helper/BoutonIco.php b/library/ZendAfi/View/Helper/BoutonIco.php index 7ec4993d55362d1254c1a69756f11cc6df7c4430..2f3e8972fb024485607eaea2940f69e6000e5709 100644 --- a/library/ZendAfi/View/Helper/BoutonIco.php +++ b/library/ZendAfi/View/Helper/BoutonIco.php @@ -16,7 +16,7 @@ * * You should have received a copy of the GNU AFFERO GENERAL PUBLIC LICENSE * along with BOKEH; if not, write to the Free Software - * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ class ZendAfi_View_Helper_BoutonIco extends ZendAfi_View_Helper_BaseHelper { @@ -43,7 +43,7 @@ class ZendAfi_View_Helper_BoutonIco extends ZendAfi_View_Helper_BaseHelper { $options = [ - 'src' => $this->picto, + 'src' => $this->picto, 'class' => 'ico']; if ($this->bulle) { @@ -51,7 +51,7 @@ class ZendAfi_View_Helper_BoutonIco extends ZendAfi_View_Helper_BaseHelper { $options['title'] = $this->bulle; } - if ('DEL' == strtoupper($this->type)) + if ('DEL' == strtoupper($this->type)) $options['onclick'] = 'javascript:return confirm(\'' . $this->traduire('Êtes vous sûr de vouloir supprimer cet élément ?') . '\');'; $html = $this->view->tag('img', null, $options); @@ -64,14 +64,16 @@ class ZendAfi_View_Helper_BoutonIco extends ZendAfi_View_Helper_BaseHelper { protected function predefined($type) { $mapping = [ - 'ADD' => ['add.gif', $this->traduire('Ajouter')], - 'EDIT'=> ['edit.gif', $this->traduire('Modifier')], - 'DEL' => ['del.gif', $this->traduire('Supprimer')], - 'CONFIRM'=> ['coche_verte.gif', $this->traduire('Confirmer')], - 'VALIDATE' => ['coche_verte.gif', $this->traduire('Valider')], - 'TEST' => ['tester.gif', $this->traduire('Tester')], - 'SHOW' => ['show.gif', $this->traduire('Visualiser')], - 'MAIL' => ['mail.png', $this->traduire('Envoyer par mail')] + 'ADD' => ['add.gif', $this->traduire('Ajouter')], + 'EDIT'=> ['edit.gif', $this->traduire('Modifier')], + 'DEL' => ['del.gif', $this->traduire('Supprimer')], + 'CONFIRM'=> ['coche_verte.gif', $this->traduire('Confirmer')], + 'VALIDATE' => ['coche_verte.gif', $this->traduire('Valider')], + 'TEST' => ['tester.gif', $this->traduire('Tester')], + 'SHOW' => ['show.gif', $this->traduire('Visualiser')], + 'MAIL' => ['mail.png', $this->traduire('Envoyer par mail')], + 'VISIBLE' => ['show.gif', $this->traduire('Rendre visible')], + 'INVISIBLE' => ['hide.gif', $this->traduire('Archiver')] ]; $type = strtoupper($type); diff --git a/tests/application/modules/admin/controllers/ModoControllerTest.php b/tests/application/modules/admin/controllers/ModoControllerTest.php index 4b042f15cc6a998d7c0ba9db5f9709e7f6499cfb..a4d7eaab000b08f11862b2dd13794db379555047 100644 --- a/tests/application/modules/admin/controllers/ModoControllerTest.php +++ b/tests/application/modules/admin/controllers/ModoControllerTest.php @@ -53,9 +53,25 @@ class ModoControllerIndexActionTest extends Admin_AbstractControllerTestCase { $this->fixture('Class_AvisNotice', ['id' => 1, 'id_notice' => 1002, 'entete' => 'Mon avis', + 'note'=> 2, + 'id_user' => null, 'avis' => 'Ce livre est vraiment bien !', 'statut' => 0]); + $this->fixture('Class_Notice', ['id' => 1032, + 'titre_principal' => 'B comme bière : la bière expliquée aux (grands) enfants']); + + $this->fixture('Class_AvisNotice', ['id' => 223, + 'id_notice' => 1002, + 'entete' => 'Bulles', + 'note'=> 2, + 'id_user' => null, + 'flags' => 0, + 'avis' => ' Pour faire aimer la biere aux enfants!', + 'id_notice' => 1032, + 'statut' => 0]); + + $this->fixture('Class_SuggestionAchat', ['id' => 92, 'titre' => 'Kikolol', 'auteur' => 'Moi', @@ -610,5 +626,60 @@ class ModoControllerAvisnoticeActionTest extends Admin_AbstractControllerTestCas public function avisnoticeShouldContainsListAvisAbonnes() { $this->assertXpathContentContains('//div//h2', 'Abonnés', $this->_response->getBody()); } + + + /** @test **/ + public function avisnoticeShouldContainsOrphanFlag() { + $this->assertXpathContentContains('//div//h2', 'Avis orphelins', $this->_response->getBody()); + } + +} + + + + + +class ModoControllerAllReviewsActionTest extends ModoControllerIndexActionTest { + + public function setup() { + parent::setup(); + $this->dispatch('admin/modo/allreviews', true); + } + + + /** @test **/ + public function moderatedReviewsShouldBeDisplayed() { + $this->assertXpathContentContains('//div//h2', 'B comme bière : la bière expliquée aux (grands) enfants', $this->_response->getBody()); + } + +} + + +class ModoControllerArchivedReviewsActionTest extends ModoControllerIndexActionTest { + + public function setup() { + parent::setup(); + + } + + + /** @test **/ + public function moderatedReviewsShouldBeArchived() { + $this->dispatch('admin/modo/invisibleavisnotice/id/223', true); + $this->assertEquals(2,Class_AvisNotice::find(223)->getFlags()); + } + + /** @test **/ + public function moderatedReviewsShouldBeVisible() { + $avis=(Class_AvisNotice::find(223)); + $avis->setFlags(2); + $avis->save(); + $this->dispatch('admin/modo/visibleavisnotice/id/223', true); + $this->assertEquals(0,Class_AvisNotice::find(223)->getFlags()); + } + } + + + ?> \ No newline at end of file