diff --git a/VERSIONS_HOTLINE/158355 b/VERSIONS_HOTLINE/158355 new file mode 100644 index 0000000000000000000000000000000000000000..7befd60a984833878e1c2a2f59e44a825d3c11a8 --- /dev/null +++ b/VERSIONS_HOTLINE/158355 @@ -0,0 +1 @@ + - correctif #158355 : Résultat de recherche : correction du comptage du badge des tomes "Déjà lu" dans une même série. \ No newline at end of file diff --git a/library/Class/Notice.php b/library/Class/Notice.php index f47fc9272be2135f076b21f43a293de537d4fada..ae2c4edf46992043ef1beecbde09ae8377e91953 100644 --- a/library/Class/Notice.php +++ b/library/Class/Notice.php @@ -671,16 +671,18 @@ class Class_Notice extends Storm_Model_Abstract { } - public function getNoticesMemeSeries() { + public function getNoticesMemeSeries() : array { if (isset($this->_same_serie_records)) return $this->_same_serie_records; if (!$this->hasSerie()) return $this->_same_serie_records = []; - return $this->_same_serie_records = $this->getLoader() - ->getAllNoticesByClefChapeau($this->getClefChapeau(), - ['limit' => 20]); + $params = ['type_doc' => $this->getTypeDoc(), + 'limit' => 20]; + + return $this->_same_serie_records = + $this->getLoader()->getAllNoticesByClefChapeau($this->getClefChapeau(), $params); } diff --git a/library/Class/Notice/Loader.php b/library/Class/Notice/Loader.php index 06b017ac556f7d215c9139a2fd71ea6e322ff340..33c66223625b5cb2a31967346003f8c7bf3ed37c 100644 --- a/library/Class/Notice/Loader.php +++ b/library/Class/Notice/Loader.php @@ -218,4 +218,20 @@ class Class_Notice_Loader extends Storm_Model_Loader { public function findAllByClefAlphaStartingWith(string $value) : array { return Class_Notice::findAllBy([Class_Notice::clauseStart('clef_alpha', $value)]); } + + + public function getIdsForSerie(Class_Notice $record) : array { + if ( ! $doc_type = $record->getTypeDoc()) + return []; + + if ( ! $clef_chapeau = $record->getClefChapeau()) + return []; + + $request = + sprintf('select id_notice from notices where type_doc = "%s" and clef_chapeau = "%s"', + $doc_type, + $clef_chapeau); + + return Class_Notice::getNoticeIdsByRequeteRecherche($request); + } } diff --git a/library/templates/Intonation/Library/View/Wrapper/Record.php b/library/templates/Intonation/Library/View/Wrapper/Record.php index 065f995e96cfa7f52b2c1dbd7a04a5ea2d098cd0..c3d6e5e9b34d1ce6eead06cbc1139f7c52b62dde 100644 --- a/library/templates/Intonation/Library/View/Wrapper/Record.php +++ b/library/templates/Intonation/Library/View/Wrapper/Record.php @@ -351,7 +351,7 @@ class Intonation_Library_View_Wrapper_Record extends Intonation_Library_View_Wra if ( ! $user = Class_Users::getIdentity()) return $badges; - if ( ! $same_serie_records = $this->_model->getNoticesMemeSeries()) + if ( ! $same_serie_records_ids = Class_Notice::getIdsForSerie($this->_model)) return $badges; if ( ! $readed_selection = Class_PanierNotice::findByLabelAndUser('Déjà lu', $user)) @@ -360,23 +360,21 @@ class Intonation_Library_View_Wrapper_Record extends Intonation_Library_View_Wra if ( ! $readed_records = $readed_selection->getNoticesAsArray()) return $badges; - $readed_records_in_series = - array_filter($readed_records, function ($record) - { - return $record->hasSerieTitle(); - }); + $readed_records_in_series = array_filter($readed_records, fn($record) => $record->hasSerieTitle()); if ( ! $readed_records_in_series) return $badges; - $readed_in_serie = array_uintersect($readed_records_in_series, - $same_serie_records, - function($record_1, $record_2) + $readed_records_in_series_ids = array_map(fn($record) => $record->getId(), $readed_records_in_series); + + $readed_in_serie = array_uintersect($readed_records_in_series_ids, + $same_serie_records_ids, + function($record_1_id, $record_2_id) { - if ($record_1->getId() == $record_2->getId()) + if ($record_1_id == $record_2_id) return 0; - if ($record_1->getId() > $record_2->getId()) + if ($record_1_id > $record_2_id) return 1; return -1; @@ -386,7 +384,7 @@ class Intonation_Library_View_Wrapper_Record extends Intonation_Library_View_Wra return $badges; $total_readed_in_serie = count($readed_in_serie); - $total_to_read = count($same_serie_records); + $total_to_read = count($same_serie_records_ids); $badges [] = (new Intonation_Library_Badge) ->setClass('record_serie') diff --git a/tests/application/modules/opac/controllers/NoticeAjaxControllerTest.php b/tests/application/modules/opac/controllers/NoticeAjaxControllerTest.php index ac2180a71a291d78d981451429c074faf33c4cf2..af58f7e3c24a63e0a23925c9433b4624edd28eed 100644 --- a/tests/application/modules/opac/controllers/NoticeAjaxControllerTest.php +++ b/tests/application/modules/opac/controllers/NoticeAjaxControllerTest.php @@ -1408,12 +1408,12 @@ class NoticeAjaxControllerDVDSeriesTest extends AbstractControllerTestCase { ->whenCalled('findAllBy') ->with(['clef_chapeau' => 'OZ', 'order' => 'tome_alpha desc', - 'limit' => 20]) + 'limit' => 20, + 'type_doc' => 4]) ->answers([$oz_season2, $oz_season3]); - - $this->dispatch('/noticeajax/series?id_notice=234',true); - $this->assertXPathContentContains('//div', utf8_encode('Voir tous les épisodes d\'OZ'),$this->_response->getBody()); + $this->dispatch('/noticeajax/series?id_notice=234'); + $this->assertXPathContentContains('//div', utf8_encode('Voir tous les épisodes d\'OZ')); } } diff --git a/tests/scenarios/Serials/SerialsDetailsTest.php b/tests/scenarios/Serials/SerialsDetailsTest.php index ec52577230a08756e321a21af503b9bcef50bbb6..1a9236ae9ea85de0bb24b40711e7f99339f83a36 100644 --- a/tests/scenarios/Serials/SerialsDetailsTest.php +++ b/tests/scenarios/Serials/SerialsDetailsTest.php @@ -91,7 +91,8 @@ class SerialsDetailsNoticeAjaxControllerPeriodiqueSerieTest extends SerialsDetai ->whenCalled('findAllBy') ->with(['clef_chapeau' => 'FAKIR', 'order' => 'tome_alpha desc', - 'limit' => 20]) + 'limit' => 20, + 'type_doc' => 2]) ->answers([$this->_fakir_56, $this->_fakir_57]); $this->dispatch('/noticeajax/series/id_notice/234'); diff --git a/tests/scenarios/Templates/MyBibAppTemplateTest.php b/tests/scenarios/Templates/MyBibAppTemplateTest.php index 52645279b54b7e1c5042a642d8989d474bccdc9a..67868cb47697f8dd2f77ec3a058e8a8966062beb 100644 --- a/tests/scenarios/Templates/MyBibAppTemplateTest.php +++ b/tests/scenarios/Templates/MyBibAppTemplateTest.php @@ -373,7 +373,10 @@ class MyBibAppTemplateReadedInSerieTest extends MyBibAppTemplateTestCase { true, false) ->answers([[12, ''], [15, '']]) - ; + + ->whenCalled('fetchAllByColumn') + ->with('select id_notice from notices where type_doc = "1" and clef_chapeau = "TROLLS DE TROY"') + ->answers([12,15]); Zend_Registry::set('sql', $sql); diff --git a/tests/scenarios/Templates/TemplatesAbonneSelectionsTest.php b/tests/scenarios/Templates/TemplatesAbonneSelectionsTest.php index ccaf4f743b7a8d98cba695c6781eba26d7ed4e54..90a186f52e9bd9a6ccf5ef116166e3515a560d49 100644 --- a/tests/scenarios/Templates/TemplatesAbonneSelectionsTest.php +++ b/tests/scenarios/Templates/TemplatesAbonneSelectionsTest.php @@ -768,7 +768,11 @@ abstract class TemplatesAbonneSelectionWithRecordsTestCase extends TemplatesAbon $sql = $this->mock() ->whenCalled('fetchAll') ->with('select id_notice, facettes from notices Where type=1 limit 10000', true, false) - ->answers([[89, 'T1'], [99, 'T1']]); + ->answers([[89, 'T1'], [99, 'T1']]) + + ->whenCalled('fetchAllByColumn') + ->with('select id_notice from notices where type_doc = "1" and clef_chapeau = "FAKIR"') + ->answers([89, 99]); Zend_Registry::set('sql', $sql); } @@ -808,7 +812,11 @@ abstract class TemplatesAbonneSelectionsAjouterWithHighlightParamsTestCase exten $sql = $this->mock() ->whenCalled('fetchAll') - ->answers([[89, 'T1', 99, 'T1']]); + ->answers([[89, 'T1', 99, 'T1']]) + + ->whenCalled('fetchAllByColumn') + ->with('select id_notice from notices where type_doc = "1" and clef_chapeau = "FAKIR"') + ->answers([89, 99]); Zend_Registry::set('sql', $sql); diff --git a/tests/scenarios/Templates/TemplatesReviewsTest.php b/tests/scenarios/Templates/TemplatesReviewsTest.php index ef0df4c036ed504e3bacdbe7e6b91c3e41f2fb73..dd2e4c9bc225fee67e0272c1d611cca3aac16517 100644 --- a/tests/scenarios/Templates/TemplatesReviewsTest.php +++ b/tests/scenarios/Templates/TemplatesReviewsTest.php @@ -923,7 +923,11 @@ class TemplatesReviewsDonnerDesAvisTest extends TemplatesIntonationTestCase { ->mock() ->whenCalled('fetchAll') ->with('select id_notice, facettes from notices Where (MATCH(titres, auteurs, editeur, collection, matieres, dewey, other_terms) AGAINST(\'+(FAKIR FAKIRS FAKIR)\' IN BOOLEAN MODE)) and type=1 order by alpha_auteur desc limit 10000', true, false) - ->answers([[89, 'T1'], [99, 'T1']]); + ->answers([[89, 'T1'], [99, 'T1']]) + + ->whenCalled('fetchAllByColumn') + ->with('select id_notice from notices where type_doc = "1" and clef_chapeau = "FAKIR"') + ->answers([89, 99]); Zend_Registry::set('sql', $sql); diff --git a/tests/scenarios/Templates/TemplatesSearchTest.php b/tests/scenarios/Templates/TemplatesSearchTest.php index 4bcdf53ff1838179e58a9a0c67a7be0a666bb098..01feef526f29211accd0adb2c55e7f9713381d24 100644 --- a/tests/scenarios/Templates/TemplatesSearchTest.php +++ b/tests/scenarios/Templates/TemplatesSearchTest.php @@ -1462,3 +1462,88 @@ class TemplatesSearchWithDomainIdsSettingsFromIndexPageTest extends Admin_Abstr $this->assertXPath('//input[@name="expressionRecherche"][@placeholder="Pomme, poire"]'); } } + + + + +class TemplatesSearchWithSerieTest extends AbstractControllerTestCase { + + protected + $_ids_for_fetch_all = [], + $_ids_for_fetch_all_by_column = []; + + + public function setUp() { + parent::setUp(); + $this->_buildTemplateProfil(['id' => 23]); + + $gunnm_fan = $this->fixture(Class_Users::class, + ['id' => 789, + 'login' => 'Lecteur de mangas', + 'password' => 'Gunnm']); + + ZendAfi_Auth::getInstance()->logUser($gunnm_fan); + Class_Template::current()->upgradeUser($gunnm_fan); + + $this->_buildRecords(); + + $readed_selection = Class_PanierNotice::findFirstBy(['libelle' => 'Déjà lu', + 'id_user' => 789]) + ->addNotice(Class_Notice::find(1)); + + $sql = $this->mock() + ->whenCalled('fetchAll') + ->with("select id_notice, facettes from notices Where (MATCH(titres, auteurs, editeur, collection, matieres, dewey, other_terms) AGAINST('+(GUNNM GUNNMS GUNM)' IN BOOLEAN MODE)) and type=1 order by MATCH(auteurs) AGAINST('P_GUNNM') desc, MATCH(titres) AGAINST('P_GUNNM') desc, MATCH(titres) AGAINST('GUNNM') desc, MATCH(auteurs) AGAINST('GUNNM') desc, date_creation desc", + true, + false) + ->answers($this->_ids_for_fetch_all) + + ->whenCalled('fetchAllByColumn') + ->with('select id_notice from notices where type_doc = "1" and clef_chapeau = "GUNNM"') + ->answers($this->_ids_for_fetch_all_by_column); + + Zend_Registry::set('sql', $sql); + + $this->dispatch('/recherche/gunnm'); + } + + + protected function _buildRecords() : void { + $ids = []; + for ( $i = 1 ; $i <= 30 ; $i ++) { + $this->fixture(Class_Notice::class, + ['id' => $i, + 'clef_chapeau' => 'GUNNM', + 'clef_alpha' => 'GUNNM--YUKITO-KISHIRO--TOME-' . $i . '--1', + 'tome_alpha' => $i, + 'type_doc' => Class_TypeDoc::LIVRE + ]) + ->set_subfield('461', 't', 'TOME ' . $i); + $this->_ids_for_fetch_all [] = [$i, '']; + $this->_ids_for_fetch_all_by_column [] = $i; + } + + $this->fixture(Class_Notice::class, + ['id' => 789789, + 'clef_chapeau' => 'GUNNM', + 'clef_alpha' => 'GUNNM--YUKITO-KISHIRO--4', + 'tome_alpha' => 1, + 'type_doc' => Class_TypeDoc::DVD + ]) + ->set_subfield('461', 't', 'DVD 1'); + + $this->_ids_for_fetch_all [] = [789789, '']; + } + + + /** @test */ + public function searchResultShouldContainsThirtyOneResult() { + $this->assertXPathContentContains('//div//span', '31 documents'); + } + + + /** @test */ + public function badgeReadedShouldContainsOneOnThirty() { + $this->assertXPathContentContains('//span[contains(@class, "record_serie")]', '1 sur 30'); + } +} \ No newline at end of file