diff --git a/VERSIONS_WIP/25560 b/VERSIONS_WIP/25560 new file mode 100644 index 0000000000000000000000000000000000000000..0078a13b808b81af70004899505bf51404545452 --- /dev/null +++ b/VERSIONS_WIP/25560 @@ -0,0 +1 @@ +-ticket #25560 : boîte article, les articles sont ordonnables par nombre d'avis \ No newline at end of file diff --git a/application/modules/admin/views/scripts/modules/_options_cms.phtml b/application/modules/admin/views/scripts/modules/_options_cms.phtml index f76ca1c5a2ff59d55d0d2d054a701d544e3cc2a7..e8faee43fc5ef692a0b943afc470076df0323042 100644 --- a/application/modules/admin/views/scripts/modules/_options_cms.phtml +++ b/application/modules/admin/views/scripts/modules/_options_cms.phtml @@ -1,53 +1,53 @@ <fieldset> <legend>Articles à afficher</legend> <div id="table_selection"> - <?php - echo $this->treeSelect( - $this->preferences["id_items"], - $this->preferences["id_categorie"], - true, - $this->url(array('module' => 'admin', - 'controller' => 'bib', - 'action' => 'articles', - 'id_bib' => $this->id_bib)), - $this->form_selector); - ?> + <?php + echo $this->treeSelect( + $this->preferences["id_items"], + $this->preferences["id_categorie"], + true, + $this->url(array('module' => 'admin', + 'controller' => 'bib', + 'action' => 'articles', + 'id_bib' => $this->id_bib)), + $this->form_selector); + ?> </div> <table cellspacing="2" width="100%"> <tr> <td class="droite">Ordre d'affichage </td> <td class="gauche"> - <?php - echo $this->formRadioButtons("display_order", - $this->preferences["display_order"], - array( - "Selection" => "Par ordre de sélection", - "DateCreationDesc" => "Par date de création (plus récent en premier)", - "DebutPublicationDesc" => "Par date de début de publication (plus récent en premier)", - "EventDebut" => "Par date de début d'événement (plus ancien en premier)", - "Random" => "Par ordre aléatoire")); - ?> + <?php + echo $this->formRadioButtons("display_order", + $this->preferences["display_order"], + ["Selection" => "Par ordre de sélection", + "DateCreationDesc" => "Par date de création (plus récent en premier)", + "DebutPublicationDesc" => "Par date de début de publication (plus récent en premier)", + "EventDebut" => "Par date de début d'événement (plus ancien en premier)", + "CommentCount" => "Par nombre d'avis", + "Random" => "Par ordre aléatoire"]); + ?> </td> </tr> <script type="text/javascript"> - formSelectToggleVisibilityForElement("input.display_order", "#nb_analyse_option", "Random"); - formSelectToggleVisibilityForElement("input.display_order", - "#options_nb_articles", - ["DateCreationDesc", "DebutPublicationDesc", "EventDebut", "Random"]); + formSelectToggleVisibilityForElement("input.display_order", "#nb_analyse_option", "Random"); + formSelectToggleVisibilityForElement("input.display_order", + "#options_nb_articles", + ["DateCreationDesc", "DebutPublicationDesc", "EventDebut", "Random", "CommentCount"]); </script> <tr id="options_nb_articles"> <td class="droite" width="100px">Afficher </td> <td class="gauche"> <span id="nb_articles_aff"> - <input type="text" name="nb_aff" size="2" maxlength="2" + <input type="text" name="nb_aff" size="2" maxlength="2" value="<?php print($this->preferences["nb_aff"]); ?>"> articles </span> <span id="nb_analyse_option" style="display:none"> parmi les - <input type="text" name="nb_analyse" size="2" maxlength="3" + <input type="text" name="nb_analyse" size="2" maxlength="3" value="<?php print($this->preferences["nb_analyse"]); ?>"> plus récents </span> diff --git a/library/Class/Article.php b/library/Class/Article.php index c20381a9daaa5bae7817b4e83d276b657e29c9b2..8c01ef3327340ed8237290864c43d54357a0e591 100644 --- a/library/Class/Article.php +++ b/library/Class/Article.php @@ -164,18 +164,29 @@ class ArticleLoader extends Storm_Model_Loader { * @return ArticleLoader */ protected function _orderAndLimit() { + if ($this->_sort_order == 'CommentCount') { + $this->_select + ->join('cms_rank', + 'cms_rank.ID_CMS = cms_article.ID_ARTICLE', + []) + ->order('(cms_rank.abon_nombre_avis + cms_rank.bib_nombre_avis) desc'); + return $this; + } + + if (!$this->_has_selection) { $this->_select->order('DATE_CREATION DESC'); $this->_select->limit($this->_limit); + return $this; + } - } else { - if ($this->_id_categories) - $this->_select->order(sprintf("FIELD(`cms_article`.ID_CAT, %s)", implode(',', $this->_id_categories))); - if ($this->_id_articles) - $this->_select->order(sprintf("FIELD(ID_ARTICLE, %s)", implode(',', $this->_id_articles))); + if ($this->_id_categories) + $this->_select->order(sprintf("FIELD(`cms_article`.ID_CAT, %s)", implode(',', $this->_id_categories))); + + if ($this->_id_articles) + $this->_select->order(sprintf("FIELD(ID_ARTICLE, %s)", implode(',', $this->_id_articles))); - } return $this; } @@ -295,7 +306,7 @@ class ArticleLoader extends Storm_Model_Loader { $defaults = [ 'id_categorie' => '', // catégories d'article, ex: 12-2-8-1-89 'id_items' => '', // liste d'articles, ex: 39-28-7 - 'display_order' => '', // tri, cf. méthodes Class_Article::sortByXXX, Random, Selection + 'display_order' => '', // tri, cf. méthodes Class_Article::sortByXXX, Random, Selection, CommentCount 'nb_analyse' => 0, // afficher nb_aff articles (aléatoires) parmis nb_analyse articles ramenés sur un critère 'nb_aff' => null, // nb d'article à retourner 'langue' => null, // que les traductions de cette langue diff --git a/library/ZendAfi/View/Helper/Admin/HelpLink.php b/library/ZendAfi/View/Helper/Admin/HelpLink.php index 8e636ece5b633249af07be040b61f292551a8bd3..2a89cf30601e81e703f1c0594198e42101d87ec2 100644 --- a/library/ZendAfi/View/Helper/Admin/HelpLink.php +++ b/library/ZendAfi/View/Helper/Admin/HelpLink.php @@ -135,7 +135,8 @@ class ZendAfi_View_Helper_Admin_HelpLinkBokehWiki 'catalogue' => ['index' => 'Gestions_des_domaines'], 'profil' => ['index' => 'Configurer_un_profil', 'menusindex' => 'Configurer_un_menu'], - 'accueil' => ['critiques' => 'Boite_Critiques'], + 'accueil' => ['critiques' => 'Boite_Critiques', + 'news' => 'Boite_Article'], 'harvest' => ['jamendo-browse' => 'Jamendo']]; } diff --git a/tests/application/modules/admin/controllers/AccueilControllerCmsTest.php b/tests/application/modules/admin/controllers/AccueilControllerCmsTest.php index 0732d5356891d70de1bd5e40ea165af9a2c98fac..3e5cc481d36c2eec43aeeec578d5269b6bfecd14 100644 --- a/tests/application/modules/admin/controllers/AccueilControllerCmsTest.php +++ b/tests/application/modules/admin/controllers/AccueilControllerCmsTest.php @@ -85,6 +85,13 @@ class Admin_AccueilControllerCmsTestWithDefaultDiaporamaNavigation extends Admin public function windowHeightShouldBeSetTo250px() { $this->assertXPath('//div[@id="objet_props"]//input[@name="op_navigation_window_height"][@value="250"]'); } + + + /** @test */ + public function displayOrderCommentCountShouldBePresent() { + $this->assertXPath('//input[@type="radio"][@name="display_order"][@value="CommentCount"]', + $this->_response->getBody()); + } } diff --git a/tests/application/modules/admin/controllers/AccueilControllerTest.php b/tests/application/modules/admin/controllers/AccueilControllerTest.php index 25620bc3fa7e73df35f7440d972d2cdaac66d2f1..f8e47d5a542e932b4ec4f55f49d34db84af87f8d 100644 --- a/tests/application/modules/admin/controllers/AccueilControllerTest.php +++ b/tests/application/modules/admin/controllers/AccueilControllerTest.php @@ -315,7 +315,6 @@ class AccueilControllerConfigSitothequeDefaultsTest extends Admin_AbstractContro public function displayOrderSelectionShouldBePresent() { $this->assertXPath('//input[@type="radio"][@name="display_order"][@value="Selection"]'); } - } diff --git a/tests/library/Class/ArticleLoaderTest.php b/tests/library/Class/ArticleLoaderTest.php index 68480d00c2bf8d8ebb7aaf2a21696051666bdaa4..00cb0668fde804ede9adfd33d2041bbe08dd7bac 100644 --- a/tests/library/Class/ArticleLoaderTest.php +++ b/tests/library/Class/ArticleLoaderTest.php @@ -308,6 +308,16 @@ class ArticleLoaderGetArticlesByPreferencesTest extends ModelTestCase { } + /** @test */ + public function withOrderCommentCountShouldJoinWithCmsRank() { + $articles = $this->getArticles(['display_order' => 'CommentCount', + 'id_items' => '', + 'id_categorie' => '4-2']); + $this->assertSelect(sprintf("INNER JOIN `cms_rank` ON cms_rank.ID_CMS = cms_article.ID_ARTICLE WHERE %s AND (`cms_article`.ID_CAT in (4,2)) ORDER BY (cms_rank.abon_nombre_avis + cms_rank.bib_nombre_avis) desc", + self::WHERE_VISIBLE_CLAUSE)); + } + + /** @test */ public function withStatusShouldFilterByStatus() { $articles = $this->getArticles(array('status' => Class_Article::STATUS_ARCHIVED));