Commit eaf050f2 authored by Ghislain Loas's avatar Ghislain Loas
Browse files

dev #64573 improve rating rendering

parent 4c95a090
Pipeline #6236 failed with stage
in 25 minutes and 6 seconds
......@@ -1341,10 +1341,11 @@ 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->setModerationOK();
if ($this->_getPost('entete') || $this->_getPost('avis'))
$rating->setModerationNOK();
if (!$form->isValidModelAndArray($rating, $post))
return $this->_redirectToReferer();
......@@ -1352,7 +1353,10 @@ class AbonneController extends ZendAfi_Controller_Action {
if (!$rating->save())
return false;
$this->_helper->notify($this->_('Votre avis a été pris en compte.'));
$this->_helper->notify($this->_('Votre avis %s / %s a été pris en compte.',
$this->_getPost('note'),
5));
return $this->_redirectToReferer();
}
}
\ No newline at end of file
......@@ -210,6 +210,29 @@ class AvisNoticeLoader extends Storm_Model_Loader {
public function findAllUserIds() {
return Zend_Registry::get('sql')->fetchAllByColumn('select distinct(id_user) as id from notices_avis');
}
public function groupByRecords($reviews) {
$reviews_by_records = [];
foreach ($reviews as $review) {
if ( !$record = $review->getFirstNotice())
continue;
if ( !isset($reviews_by_records [$record->getId()]))
$reviews_by_records [$record->getId()] = ['Record' => $record,
'Reviews' => []];
$reviews_by_records [$record->getId()]['Reviews'] = array_merge($reviews_by_records [$record->getId()]['Reviews'],
[$review]);
}
return array_map(function($element)
{
return new Class_ReviewsByRecord($element);
},
$reviews_by_records);
}
}
......
......@@ -20,7 +20,4 @@
*/
class Intonation_Library_Link extends Class_Entity {
}
?>
\ No newline at end of file
class Intonation_Library_Link extends Class_Entity {}
\ No newline at end of file
......@@ -34,12 +34,17 @@ class Intonation_Library_View_Wrapper_Abstract {
}
public function setModel($record) {
$this->_model = $record;
public function setModel($model) {
$this->_model = $model;
return $this;
}
public function getModel() {
return $this->_model;
}
public function getSecondaryLink() {
return null;
}
......
......@@ -23,7 +23,13 @@
class Intonation_Library_View_Wrapper_Review extends Intonation_Library_View_Wrapper_Abstract {
public function getTitle() {
return $this->_view->rating($this->_model->getNote()) . ' ' . $this->_model->getEntete();
$title = ($title = $this->_model->getEntete())
? BR . $title
: '';
return
$this->_view->rating($this->_model->getNote())
. $title;
}
......@@ -34,11 +40,11 @@ class Intonation_Library_View_Wrapper_Review extends Intonation_Library_View_Wra
public function getExplicitTitle() {
if ($author = $this->getAuthor())
return $this->_('"%s" écrit par "%s"',
return $this->_('Avis "%s" donné par "%s"',
$this->getTitle(),
$this->getAuthor());
return $this->_('"%s"',
return $this->_('Avis "%s"',
$this->getTitle());
}
......@@ -50,14 +56,15 @@ class Intonation_Library_View_Wrapper_Review extends Intonation_Library_View_Wra
public function getDocTypeLabel() {
$type_doc = Class_TypeDoc::find($this->getDocType());
return $type_doc ? $type_doc->getLabel() : '';;
return $type_doc ? $type_doc->getLabel() : '';
}
public function getMainLink() {
return new Intonation_Library_Link(['Url' => $this->_model->getUrl(),
'Text' => $this->_('Lire l\'avis'),
'Title' => $this->_getMainLinkTitle()]);
'Title' => $this->_getMainLinkTitle(),
'Popup' => true]);
}
......
......@@ -28,6 +28,7 @@ class Intonation_Library_Widget_Carousel_Definition extends Class_Systeme_Module
MULTIPLE_CAROUSEL = 'multiple_carousel',
CARD_OVERLAY = 'card-overlay',
CARD_DESCRIPTION = 'card-description',
CARD = 'card';
......
......@@ -99,7 +99,8 @@ class Intonation_Library_Widget_Carousel_Form extends ZendAfi_Form_Configuration
public function getRenderings() {
return [Intonation_Library_Widget_Carousel_Definition::CARD_OVERLAY => $this->_('Media'),
Intonation_Library_Widget_Carousel_Definition::CARD => $this->_('Media suivi par une description')];
return [Intonation_Library_Widget_Carousel_Definition::CARD_OVERLAY => $this->_('Média'),
Intonation_Library_Widget_Carousel_Definition::CARD => $this->_('Média suivi par une description'),
Intonation_Library_Widget_Carousel_Definition::CARD_DESCRIPTION => $this->_('Uniquement une description')];
}
}
\ No newline at end of file
......@@ -38,7 +38,7 @@ class Intonation_Library_Widget_Carousel_Review_Definition extends Intonation_Li
public function __construct() {
$this->_libelle = $this->_('Boite d\'avis');
$this->_form = 'Intonation_Library_Widget_Carousel_Review_Form';
$this->_view_helper = 'Intonation_Library_Widget_Carousel_Review_View';
$this->_view_helper = 'Intonation_Library_Widget_Carousel_ReviewsByRecord_View';
$this->_defaultValues = ['titre' => $this->_libelle,
'rendering' => static::CARD_OVERLAY,
'layout' => static::WALL,
......
......@@ -20,16 +20,17 @@
*/
class Intonation_Library_Widget_Carousel_Review_View extends Intonation_Library_Widget_Carousel_View {
class Intonation_Library_Widget_Carousel_ReviewsByRecord_View extends Intonation_Library_Widget_Carousel_View {
protected $_all_reviews = [];
protected function _findElements() {
$loader = Class_AvisNotice::getLoader();
$reviews_to_show = $loader->getAvisFromPreferences($this->preferences);
$reviews_to_show = $loader->getAvisFromPreferences($this->preferences, [0, 1000], true);
$this->_all_reviews = $reviews_to_show;
return $reviews_to_show;
return $loader->groupByRecords($reviews_to_show);
}
......@@ -61,6 +62,6 @@ class Intonation_Library_Widget_Carousel_Review_View extends Intonation_Library_
protected function _getWrapper() {
return 'Intonation_Library_View_Wrapper_Review';
return 'Intonation_Library_View_Wrapper_ReviewsByRecord';
}
}
\ No newline at end of file
......@@ -80,7 +80,7 @@ abstract class Intonation_Library_Widget_Carousel_View extends Zendafi_View_Help
'aria-expanded' => 'false'])
. $this->_tag('div',
$this->view->tagPre($this->_tag('iframe',
'',
'',
['src' => $this->view->absoluteUrl([
'module' => 'opac',
'controller' => 'widget',
......@@ -111,24 +111,16 @@ abstract class Intonation_Library_Widget_Carousel_View extends Zendafi_View_Help
if (!$elements = $this->_findElements())
return $this->_tag('p', $this->_('Aucun document'));
$content_callback = $this->_settings->getRendering() == Intonation_Library_Widget_Carousel_Definition::CARD_OVERLAY
? (function ($element)
{
return $this->view->cardifyWithOverlay($element);
})
: (function ($element)
{
return $this->view->cardify($element);
});
$content_callback = $this->_getContentCallback();
$elements = array_slice($elements, 0, $this->_settings->getSize());
$elements = array_map(function($element)
{
$wrapper = $this->_getWrapper();
return (new $wrapper)
->setView($this->view)
->setModel($element);
}, $elements);
{
$wrapper = $this->_getWrapper();
return (new $wrapper)
->setView($this->view)
->setModel($element);
}, $elements);
$elements = new Storm_Collection($elements);
......@@ -144,6 +136,29 @@ abstract class Intonation_Library_Widget_Carousel_View extends Zendafi_View_Help
}
protected function _getContentCallback() {
if ($this->_settings->getRendering() == Intonation_Library_Widget_Carousel_Definition::CARD_OVERLAY)
return function ($element)
{
return $this->view->cardifyWithOverlay($element);
};
if ($this->_settings->getRendering() == Intonation_Library_Widget_Carousel_Definition::CARD)
return function ($element)
{
return $this->view->cardify($element);
};
if ($this->_settings->getRendering() == Intonation_Library_Widget_Carousel_Definition::CARD_DESCRIPTION)
return function ($element)
{
return $this->view->cardifyOnlyDescription($element);
};
return function() {return '';};
}
abstract protected function _findElements();
abstract protected function _getWrapper();
abstract protected function _getLinkToAllUrl();
......
......@@ -22,9 +22,7 @@
class Intonation_View_Cardify extends ZendAfi_View_Helper_BaseHelper {
public function cardify($element) {
return $this->_tag('div',
$this->_cardWithPicture($element),
['class' => 'card no_overflow']);
return $this->_cardWithPicture($element);
}
......@@ -37,6 +35,6 @@ class Intonation_View_Cardify extends ZendAfi_View_Helper_BaseHelper {
: $this->_('Aïe, aïe, aïe ! Pas d\'image pour "%s".',
$element->getTitle()))]);
return $img . $this->view->cardifyOnlyDescription($element);
return $this->view->cardifyOnlyDescription($element, $img);
}
}
\ No newline at end of file
......@@ -22,7 +22,7 @@
class Intonation_View_CardifyOnlyDescription extends ZendAfi_View_Helper_BaseHelper {
public function cardifyOnlyDescription($element) {
public function cardifyOnlyDescription($element, $img = '') {
$content = [];
if ($title = $element->getTitle())
......@@ -68,6 +68,8 @@ class Intonation_View_CardifyOnlyDescription extends ZendAfi_View_Helper_BaseHel
implode($links),
['class' => 'card-footer d-flex flex-column flex-md-row justify-content-between']);
return implode($html);
return $this->_tag('div',
$img . implode($html),
['class' => 'card no_overflow']);
}
}
\ No newline at end of file
......@@ -24,9 +24,7 @@ class Intonation_View_Notice_Exemplaires extends ZendAfi_View_Helper_BaseHelper
public function Notice_Exemplaires($exemplaires, $nb_notices_oeuvre = 0, $aff = "normal") {
$callback = function ($element) {
return $this->_tag('div',
$this->view->cardifyOnlyDescription($element),
['class' => 'card']);
return $this->view->cardifyOnlyDescription($element);
};
usort($exemplaires,
......
......@@ -1873,15 +1873,23 @@ class TemplatesReviewsWidgetTest extends TemplatesIntonationTestCase {
'link_to_all' => 1,
'embeded_code'=> 1,
'IntonationShowFooter' => 1,
'rendering' => 'card',
'layout' => 'multiple_carousel'])
->updateProfile();
$this->fixture('Class_AvisNotice',
['id' => 4,
'id_notice' => 2,
'clef_oeuvre' => 'PSYKO',
'note' => '4',
'entete' => 'Le Roi',
'avis' => 'Le Roi des cons sur son throne']);
$this->fixture('Class_Notice',
['id' => 2,
'clef_oeuvre' => 'PSYKO',
]);
$this->dispatch('/opac/index/index/id_profil/72', true);
$this->assertXPathContentContains('//div', 'Le Roi');
}
......
Markdown is supported
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