Skip to content
Snippets Groups Projects
Commit 194d64fc authored by Laurent's avatar Laurent
Browse files

dev #59497: select all + view selection as search result

parent 2c794cec
Branches
Tags
3 merge requests!2869Master,!2831Dev#59497 2 2955 contractuel minsoc09 selectionner pour mise en panier etou imprimer et pouvoir faire tout,!2828Dev#59497 2 2955 contractuel minsoc09 selectionner pour mise en panier etou imprimer et pouvoir faire tout
Pipeline #4960 failed with stage
in 44 minutes and 44 seconds
......@@ -21,29 +21,48 @@
class RecordsController extends ZendAfi_Controller_Action {
protected $_selection;
public function preDispatch() {
parent::preDispatch();
$this->_selection = new Class_RecordSelection();
}
public function selectToggleAction() {
$selection = new Class_RecordSelection();
$selection->toggle(Class_Notice::find($this->_getParam('id')));
$this->_helper->json(['count' => $selection->count()]);
$this->_selection->toggle(Class_Notice::find($this->_getParam('id')));
$this->_helper->json(['count' => $this->_selection->count()]);
}
public function selectClearAction() {
$selection = new Class_RecordSelection();
$selection->clear();
$this->_helper->json(['count' => $selection->count()]);
$this->_selection->clear();
$this->_helper->json(['count' => $this->_selection->count()]);
}
public function selectPageAction() {
$this->_selection->addAll($this->_resultFromParams()->fetchRecords());
$this->_helper->json(['count' => $this->_selection->count()]);
}
public function selectAllAction() {
$this->_selection->addAllIds($this->_resultFromParams()->fetchAllRecordsIds());
$this->_helper->json(['count' => $this->_selection->count()]);
}
public function selectViewAction() {
}
protected function _resultFromParams() {
$criteria = (new Class_CriteresRecherche())
->setParams($this->_request->getParams());
$search_result = Class_MoteurRecherche::getInstance()->lancerRecherche($criteria);
$records = $search_result->fetchRecords();
$selection = new Class_RecordSelection();
$selection->addAll($records);
$this->_helper->json(['count' => $selection->count()]);
return Class_MoteurRecherche::getInstance()
->lancerRecherche($criteria);
}
}
?>
\ No newline at end of file
......@@ -128,7 +128,8 @@ class Class_CriteresRecherche {
'fil',
'bib_select',
'serie',
'from']);
'from',
'selection']);
}
......@@ -266,6 +267,7 @@ class Class_CriteresRecherche {
public function getFiltres() {
$filtres = [];
if (!$this->isRecherchePanier()
&& !$this->isSelection()
&& !$this->isRechercheCatalogueEmpty()
&& $this->_profil) {
$filtres = array_merge($filtres,
......@@ -385,6 +387,13 @@ class Class_CriteresRecherche {
}
public function getSelection() {
return $this->isSelection()
? new Class_RecordSelection()
: null;
}
public function visitCatalogue($visitor, $catalogue) {
$visitor->visitCatalogue($catalogue);
......@@ -465,8 +474,15 @@ class Class_CriteresRecherche {
}
public function isRechercheCatalogueOuPanier() {
return ($this->isRechercheCatalogue() || $this->isRecherchePanier());
protected function isSelection() {
return (bool)$this->getParam('selection');
}
public function isRechercheCatalogueOuPanierOuSelection() {
return $this->isRechercheCatalogue()
|| $this->isRecherchePanier()
|| $this->isSelection();
}
......@@ -476,7 +492,7 @@ class Class_CriteresRecherche {
public function visitPanierCatalogue($visitor) {
if (!$this->isRechercheCatalogueOuPanier())
if (!$this->isRechercheCatalogueOuPanierOuSelection())
return $this;
if ($catalogue = $this->getCatalogue()) {
......@@ -489,6 +505,11 @@ class Class_CriteresRecherche {
return $this;
}
if (($selection = $this->getSelection()) && !$selection->isEmpty()) {
$visitor->visitSelection($selection);
return $this;
}
$visitor->setErreur($this->_('La sélection ne contient aucune notice'));
return $this;
}
......
......@@ -682,4 +682,12 @@ class Class_MoteurRecherche {
if ($diff = array_diff($version->getData(), $previous->getData()))
$this->setCondition('clef_alpha in (\'' . implode('\', \'', $diff) . '\')');
}
public function visitSelection($selection) {
if (!$selection || $selection->isEmpty())
return;
$this->setCondition('id_notice in (' . implode(',', $selection->values()). ')');
}
}
\ No newline at end of file
......@@ -38,6 +38,16 @@ class Class_RecordSelection {
}
public function isEmpty() {
return 0 === $this->count();
}
public function values() {
return $this->_getSelection();
}
public function includes($record) {
return in_array($record->getId(), $this->_getSelection());
}
......@@ -50,9 +60,7 @@ class Class_RecordSelection {
public function add($record) {
$selection = $this->_getSelection();
$selection []= $record->getId();
return $this->_setSelection($selection);
return $this->addId($record->getId());
}
......@@ -62,6 +70,19 @@ class Class_RecordSelection {
}
public function addAllIds($ids) {
array_map([$this, 'addId'], $ids);
return $this;
}
public function addId($id) {
$selection = $this->_getSelection();
$selection []= $id;
return $this->_setSelection($selection);
}
public function toggle($record) {
if (!$record)
return $this;
......@@ -76,4 +97,3 @@ class Class_RecordSelection {
$this->_setSelection([]);
}
}
?>
\ No newline at end of file
......@@ -46,6 +46,7 @@ trait Trait_SearchCriteriaVisitor {
public function setErreur($error) {}
public function visitSearchUrl($params) {}
public function visitPanier($panier) {}
public function visitSelection($selection) {}
public function visitFacetteDomainForOrConditions($catalog_id) {}
public function visitFilterOnDomain($criteria) {}
......
......@@ -168,6 +168,13 @@ class ZendAfi_View_Helper_TagCriteresRecherche extends ZendAfi_View_Helper_BaseH
}
public function visitSelection($selection) {
$this
->htmlAppend($this->getSuppressionImgUrlForLibelle($this->_('Sélection courante'),
$this->_criteres_recherche->getUrlCriteresWithoutElement('selection')));
}
public function visitSection($section) {
$url = $this->_criteres_recherche->getUrlCriteresWithoutElement('section');
$libelle = $this->_('Section: %s', Class_Codification::getInstance()->getLibelleFacette('S'.$section));
......
......@@ -48,9 +48,11 @@ class ZendAfi_View_Helper_TagSelectRecord extends ZendAfi_View_Helper_BaseHelper
. $this->_tag('span',
(new Class_RecordSelection())->count())
. $this->_tag('ul',
$this->_tag('li', $this->_clearSelectionLink())
.
$this->_tag('li', $this->_selectPageLink($criteria))
implode([$this->_tag('li', $this->_selectPageLink($criteria)),
$this->_tag('li', $this->_selectAllLink($criteria)),
$this->_tag('li', $this->_selectViewLink()),
$this->_tag('li', $this->_clearSelectionLink()),
])
),
['class' => 'record-selection']);
}
......@@ -95,4 +97,35 @@ class ZendAfi_View_Helper_TagSelectRecord extends ZendAfi_View_Helper_BaseHelper
$url_select_page)
]);
}
protected function _selectAllLink($criteria) {
Class_ScriptLoader::getInstance()
->addInlineScript('function updateRecordSelectionCountAndCheckAll(data) { '
.'updateRecordSelectionCount(data);'
.'$(\'input[id^=select_record_]\').prop(\'checked\', true);'
.'}');
$url_select_page = Class_Url::relative(array_merge($criteria->getUrlCriteresWithFacettes(),
['controller' => 'records',
'action' => 'select-all']));
return $this->_tag('a',
$this->_('Sélectionner tous les résultats'),
['href' => $url_select_page,
'onclick' => sprintf('$.get(\'%s\', updateRecordSelectionCountAndCheckAll); return false',
$url_select_page)
]);
}
protected function _selectViewLink() {
return $this->_tag('a',
$this->_('Voir la sélection'),
['href' => Class_Url::relative(['controller' => 'recherche',
'action' => 'simple',
'selection' => 1], null, true),
]);
}
}
......@@ -29,9 +29,8 @@ abstract class SearchSelectionTestCase extends AbstractControllerTestCase {
Class_AdminVar::set('ENABLE_SEARCH_MULTIPLE_RECORD_SELECTION', 1);
$this->mock_sql = $this->mock()
->whenCalled('execute')->answers('')
->whenCalled('fetchOne')->answers(null)
->whenCalled('fetchAll')->answers([ [8, 9] ]);
->whenCalled('fetchAll')->answers([[8, ''], [9, ''], [10, '']])
;
Zend_Registry::set('sql', $this->mock_sql);
Class_Profil::getCurrentProfil()
......@@ -68,7 +67,8 @@ abstract class SearchSelectionTestCase extends AbstractControllerTestCase {
'url_vignette'=>'no',
'url_image'=>'no',
'date_creation'=> '2015-11-28'])
]);
])
;
}
}
......@@ -101,7 +101,6 @@ class SearchSelectionWithSessionTest extends SearchSelectionTestCase {
}
/** @test */
public function pageShouldContainsRecordMillenium() {
$this->assertXPathContentContains('//div[@class="vignette_titre"]//a', 'Millenium');
......@@ -167,6 +166,34 @@ class SearchSelectionWithSessionTest extends SearchSelectionTestCase {
'Sélectionner toute la page',
$this->_response->getBody());
}
/** @test */
public function selectionMenuShouldContainsActionToSelectAllResults() {
$url = Class_url::relative(['module' => 'opac',
'controller' => 'records',
'action' => 'select-all',
'expressionRecherche' => 'pomme',
'page' => '1',
'facettes' => 'T3']);
$this->assertXPathContentContains('//div[@class="record-selection"]/ul/li/a[@href="' . $url . '"][@onclick="$.get(\'' . $url . '\', updateRecordSelectionCountAndCheckAll); return false"]',
'Sélectionner tous les résultats',
$this->_response->getBody());
}
/** @test */
public function selectionMenuShouldContainsActionToViewSelection() {
$url = Class_url::relative(['module' => 'opac',
'controller' => 'recherche',
'action' => 'simple',
'selection' => 1]);
$this->assertXPathContentContains('//div[@class="record-selection"]/ul/li/a[@href="' . $url . '"]',
'Voir la sélection',
$this->_response->getBody());
}
}
......@@ -248,6 +275,52 @@ class SearchSelectionSelectPageTest extends SearchSelectionTestCase {
class SearchSelectionSelectAllTest extends SearchSelectionTestCase {
public function setUp() {
parent::setUp();
$this->dispatch('/records/select-all/expressionRecherche/pomme/facettes/T3/page/1/page_size/2', true);
}
/** @test */
public function sessionShouldContainsAll() {
$this->assertEquals([8, 9, 10],
Zend_Registry::get('session')->search_record_selection);
return $this->_response->getBody();
}
}
class SearchSelectionSelectViewTest extends SearchSelectionTestCase {
public function setUp() {
parent::setUp();
Zend_Registry::get('session')->search_record_selection = [8, 10];
$this->mock_sql
->whenCalled('fetchAll')
->with('select id_notice, facettes from notices Where id_notice in (8,10)',
true, false)
->answers([ [8, ''], [10, '']])
->beStrict();
$this->dispatch('/recherche/simple/selection/1', true);
}
/** @test */
public function pageShouldContainsRecordMillenium() {
$this->assertXPathContentContains('//div[@class="vignette_titre"]//a', 'Millenium');
}
/** @test */
public function pageShouldContainsRemovableCriteriaSelectionCourante() {
$this->assertXPathContentContains('//div[@class="criteres_recherche"]//a', 'Sélection courante');
}
}
class SearchSelectionAdminVarsTest extends Admin_AbstractControllerTestCase {
protected $_storm_default_to_volatile = true;
......@@ -263,5 +336,3 @@ class SearchSelectionAdminVarsTest extends Admin_AbstractControllerTestCase {
$this->assertXpathContentContains('//td', 'ENABLE_SEARCH_MULTIPLE_RECORD_SELECTION');
}
}
?>
\ No newline at end of file
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment