Commit 6111e529 authored by Ghislain Loas's avatar Ghislain Loas
Browse files

wip on perf

parent 3eb4c2be
Pipeline #8985 passed with stage
in 45 minutes and 25 seconds
......@@ -237,6 +237,7 @@ class AuthController extends ZendAfi_Controller_Action {
$this->view->options = ['data' => array_merge(
$preferences,
['redirect_url' => $this->_getParam('redirect_uri'),
'clear_action' => true,
'id_notice' => 0])];
$this->getHelper('ViewRenderer')->setLayoutScript('subModal.phtml');
......
<?php
echo $this->tag('h1', $this->titre);
echo $this->Widget_Login(new Class_Entity(array_merge(['FormOptions' => $this->options])));
echo $this->Widget_Login(new Class_Entity(['FormOptions' => $this->options,
'Preferences' => $this->options['data']]));
......@@ -74,7 +74,7 @@ class Telephone_AuthController extends AuthController {
protected function _loginCommon() {
$form = $this->_getFormLogin();
$form = $this->_getFormLogin()->setAction($this->view->url());
if ($this->_request->isPost()) {
if (!($error = $this->_authenticate())) {
$this->_redirect($redirectUrl);
......@@ -96,7 +96,6 @@ class Telephone_AuthController extends AuthController {
Class_Profil::getPortail()->getModuleAccueilPreferencesByType('LOGIN'));
$form = new ZendAfi_Form_Mobile_Login();
$form->setAction($this->view->url());
$form->getElement('username')
->setAttrib('placeholder', $settings['identifiant_exemple'])
......
......@@ -527,7 +527,7 @@ class Class_AvisNotice extends Storm_Model_Abstract {
public function getHumanDate() {
return Class_Date::humanDate($this->getDateAvis(), 'd MMMM yyyy HH:mm');
return strftime($this->_('%d %B %Y'), strtotime($this->getDateAvis()));
}
......
......@@ -260,8 +260,7 @@ class Class_Notice extends Storm_Model_Abstract {
public function getLocalAvis() {
if (!isset($this->_local_avis))
$this->_local_avis = Class_AvisNotice::findAllBy(['clef_oeuvre' => $this->getClefOeuvre(),
'source_actor_id' => null]);
$this->_local_avis = Class_AvisNotice::findAllBy(['clef_oeuvre' => $this->getClefOeuvre()]);
return $this->_local_avis;
}
......
......@@ -24,7 +24,9 @@ class Intonation_Library_Selection extends Class_Entity {
use Trait_Translator;
protected $_cache;
protected $_is_in_cache;
protected static $_selections_cache = [];
protected function _getImageForContext() {
......@@ -47,6 +49,7 @@ class Intonation_Library_Selection extends Class_Entity {
$selection);
}
protected function _getUrlForContext() {
$action = $this->_isIn()
? 'supprimer-de-la-selection'
......@@ -63,17 +66,27 @@ class Intonation_Library_Selection extends Class_Entity {
protected function _isIn() {
if ($this->_cache)
return $this->_cache;
if ($this->_is_in_cache)
return $this->_is_in_cache;
if (!$user = $this->getUser())
return $this->_cache = false;
return $this->_is_in_cache = false;
if (!$selection = $this->_getSelection($user))
return $this->_is_in_cache = false;
return $this->_is_in_cache = $selection->contains($this->getRecord());
}
protected function _getSelection($user) {
$title = $this->getTitle();
if (!$selection = Class_PanierNotice::findFirstBy(['libelle' => $this->getTitle(),
'id_user' => $user->getId()]))
return $this->_cache = false;
if (isset(static::$_selections_cache[$title]))
return static::$_selections_cache[$title];
return $this->_cache = $selection->contains($this->getRecord());
return static::$_selections_cache[$title] = Class_PanierNotice::findFirstBy(['libelle' => $title,
'id_user' => $user->getId()]);
}
......
......@@ -28,7 +28,8 @@ abstract class Intonation_Library_View_Wrapper_Abstract {
$_view,
$_model,
$_context_params = [],
$_rich_content;
$_rich_content,
$_in_js_search = false;
public function setView($view) {
......@@ -65,12 +66,19 @@ abstract class Intonation_Library_View_Wrapper_Abstract {
}
public function inJsSearch() {
$this->_in_js_search = true;
return $this;
}
public function getContentForJSSearch() {
return $this->_view->dNone(implode(' ', [$this->getMainTitle(),
$this->getSecondaryTitle(),
$this->getDescription(),
$this->getBadges(),
'%s']));
return $this->_in_js_search
? $this->_view->dNone(implode(' ', [$this->getMainTitle(),
$this->getSecondaryTitle(),
$this->getDescription(),
'%s']))
: '';
}
......
......@@ -75,13 +75,13 @@ class Intonation_Library_View_Wrapper_Article extends Intonation_Library_View_Wr
public function getDescription() {
return $this->_view->renderArticleBadges($this->_model)
return $this->getBadges()
. $this->_view->truncate($this->_model->getSummary());
}
public function getFullDescription() {
return $this->_view->renderArticleBadges($this->_model)
return $this->getBadges()
. $this->_model->getSummary();
}
......@@ -105,7 +105,80 @@ class Intonation_Library_View_Wrapper_Article extends Intonation_Library_View_Wr
public function getBadges() {
return $this->_view->renderArticleBadges($this->_model);
$badges = [];
if ($this->_model->isStatusDraft())
$badges [] = ((new Intonation_Library_Badge)
->setTag('span')
->setClass('danger')
->setText($this->_('Brouillon'))
->setTitle($this->_('Cet article "%s" est un brouillon.', $this->_model->getTitre())));
if (($library = $this->_model->getBib()) && !$library->isPortail())
$badges [] = ((new Intonation_Library_Badge)
->setTag('a')
->setUrl($this->_view->url(['controller' => 'bib',
'action' => 'en-lire-plus',
'id' => $library->getId()]))
->setClass('primary')
->setImage(Class_Template::current()
->getIco($this->_view,
'library',
'library'))
->setText($library->getLibelle())
->setTitle($this->_('Bibliothèque de l\'article "%s"', $this->_model->getTitre())));
$badges [] = ((new Intonation_Library_Badge)
->setTag('span')
->setClass('info')
->setText($this->_model->getCategorieLibelle())
->setTitle($this->_('Catégorie de l\'article "%s"', $this->_model->getTitre())));
if ($location = $this->_model->getLieuLibelle())
$badges [] = ((new Intonation_Library_Badge)
->setTag('span')
->setClass('secondary')
->setText($location)
->setTitle($this->_('Lieu relié à l\'article "%s"', $this->_model->getTitre())));
if ($event_start = $this->_model->getEventsDebut())
$badges [] = (new Intonation_Library_Badge)
->setTag('span')
->setClass('success')
->setText($this->_('%s à %s',
strftime($this->_('%d/%m/%Y'), strtotime($event_start)),
strftime($this->_('%H:%M'), strtotime($event_start))))
->setTitle($this->_('"%s" commence le %s à %s',
$this->_model->getTitre(),
strftime($this->_('%d %B %Y'), strtotime($event_start)),
strftime($this->_('%Hh%Mm'), strtotime($event_start))));
if ($event_end = $this->_model->getEventsFin())
$badges [] = (new Intonation_Library_Badge)
->setTag('span')
->setClass('warning')
->setText($this->_('%s à %s',
strftime($this->_('%d/%m/%Y'), strtotime($event_end)),
strftime($this->_('%H:%M'), strtotime($event_end))))
->setTitle($this->_('"%s" finit le %s à %s',
$this->_model->getTitre(),
strftime($this->_('%d %B %Y'), strtotime($event_end)),
strftime($this->_('%Hh%Mm'), strtotime($event_end))));
if ($tags = $this->_model->getTags()) {
foreach(array_filter(explode(';', $tags)) as $tag) {
$tag = trim(strip_tags($tag));
$badges [] = ((new Intonation_Library_Badge)
->setTag('span')
->setClass('dark')
->setText($tag)
->setTitle($this->_('L\'étiquette "%s" de l\'article "%s".',
$tag,
$this->_model->getTitre())));
}
}
return $this->_view->renderBadges($badges);
}
......
......@@ -27,7 +27,8 @@ class Intonation_Library_View_Wrapper_Newsletter extends Intonation_Library_View
public function getContentForJSSearch() {
$content = parent::getContentForJSSearch();
if(!$content = parent::getContentForJSSearch())
return '';
if ($this->_model->hasRecipient(Class_Users::getIdentity()))
return sprintf($content, $this->_('inscrit'));
......
......@@ -119,7 +119,147 @@ class Intonation_Library_View_Wrapper_Record extends Intonation_Library_View_Wra
public function getBadges() {
return $this->_view->renderRecordBadges($this->_model);
$badges = [
((new Intonation_Library_Badge)
->setTag('a')
->setClass('warning fs_1em')
->setUrl($this->_view->url(['controller' => 'recherche',
'action' => 'simple',
'facette' => Class_CodifTypeDoc::CODE_FACETTE. $this->_model->getTypeDoc(),
'page' => null]))
->setImage((Class_Template::current()
->getIco($this->_view,
$this->_model->getTypeDocLabel(),
'doc_types')))
->setText($this->_model->getTypeDocLabel())
->setTitle($this->_('Affiner le résultat de recherche avec le type de document %s du document %s',
$this->_model->getTypeDocLabel(),
$this->_model->getTitrePrincipal(' '))))];
$badges = $this->_addBookmarkedLibraries($badges, $this->_model);
$badges [] = ((new Intonation_Library_Badge)
->setTag('a')
->setClass('dark')
->setUrl($this->_view->url(['controller' => 'recherche',
'action' => 'simple',
'annee_debut' => $this->_model->getAnnee(),
'page' => null]))
->setImage(($this->_model->getAnnee()
? (Class_Template::current()
->getIco($this->_view,
'date-edition',
'library'))
: ''))
->setText($this->_model->getAnnee())
->setTitle($this->_('Affiner le résultat avec la date d\'édition du document %s : %d',
$this->_model->getTitrePrincipal(' '),
$this->_model->getAnnee())));
if ($count = $this->_model->numberOfAvisBibliothecaire()) {
$badges [] = ((new Intonation_Library_Badge)
->setTag('span')
->setClass('success')
->setText($this->_('%d avis pro.',
$count))
->setTitle($this->_('Nombre d\'avis des professionnels sur le document "%s".',
$this->_model->getTitrePrincipal(' '))));
$badges [] = ((new Intonation_Library_Badge)
->setTag('span')
->setClass('success')
->setText($this->_view->rating($this->_model->getNoteMoyenneAvisBibliothecaires()))
->setTitle($this->_('Note moyenne des avis des professionnels sur le document "%s".',
$this->_model->getTitrePrincipal(' '))));
}
if ($count = $this->_model->numberOfAvisAbonne()) {
$badges [] = ((new Intonation_Library_Badge)
->setTag('span')
->setClass('info')
->setText($this->_('%d avis abonné',
$count))
->setTitle($this->_('Nombre d\'avis des abonnés sur le document "%s".', $this->_model->getTitrePrincipal(' '))));
$badges [] = ((new Intonation_Library_Badge)
->setTag('span')
->setClass('info')
->setText($this->_view->rating($this->_model->getNoteMoyenneAvisAbonnes()))
->setTitle($this->_('Note moyenne des avis des abonnés sur le document "%s".', $this->_model->getTitrePrincipal(' '))));
}
foreach($this->_getFacets($this->_model) as $facet)
$badges [] = ((new Intonation_Library_Badge)
->setTag('a')
->setClass('primary')
->setImage(Class_Template::current()->getIco($this->_view,
'tag',
'utils'))
->setText($facet->getLabel())
->setTitle($facet->getTitle())
->setUrl($facet->getUrlForLink()));
return $this->_view->renderBadges($badges);
}
protected function _getFacets() {
$codes = [Class_CodifTags::CODE_FACETTE,
Class_CodifMatiere::CODE_FACETTE,
Class_CodifGenre::CODE_FACETTE,
Class_CodifCentreInteret::CODE_FACETTE];
$facets =[];
foreach($codes as $code)
$facets = array_merge($facets, $this->_model->getChampNotice($code, $this->_model->getFacettes()));
return $facets;
}
protected function _addBookmarkedLibraries($badges) {
if (!$user = Class_Users::getIdentity())
return $badges;
$settings = new Class_User_Settings($user);
if (!$libraries = $settings->getBookmarkedLibraries())
return $badges;
$items = $this->_model->getExemplaires();
$matches = array_map(function($item) use($libraries)
{
foreach($libraries as $library)
if($library->includeItem($item))
return new Class_Entity(['Item' => $item,
'Library' => $library]);
}, $items);
if (!$matches = array_filter($matches))
return $badges;
foreach ($matches as $match) {
if (!$match)
continue;
$badges [] = ((new Intonation_Library_Badge)
->setTag('a')
->setUrl($this->_view->url(['controller' => 'recherche',
'action' => 'simple',
'facette' => $match->getLibrary()->getFacetCode(),
'page' => null]))
->setClass('info')
->setImage(Class_Template::current()->getIco($this->_view,
'library',
'library'))
->setText($match->getLibrary()->getLabel())
->setTitle($this->_('Affiner le résultat avec le site %s', $match->getLibrary()->getLabel())));
}
return $badges;
}
......
......@@ -191,8 +191,10 @@ class Intonation_Library_View_Wrapper_Review extends Intonation_Library_View_Wra
public function getContentForJSSearch() {
return sprintf(parent::getContentForJSSearch(),
$this->_('%d/5 note étoile avis',$this->_model->getNote()));
return ($content = parent::getContentForJSSearch())
? sprintf($content,
$this->_('%d/5 note étoile avis',$this->_model->getNote()))
: '';
}
......
......@@ -96,8 +96,7 @@ class Intonation_Library_View_Wrapper_ReviewsByRecord extends Intonation_Library
foreach ($this->_reviews as $review)
$html [] = $this->_view->cardifyOnlyDescription($review);
return $this->_view->renderRecordBadges($this->_record->getModel())
. implode($html);
return $this->_record->getBadges() . implode($html);
}
......
......@@ -127,7 +127,7 @@ class Intonation_Library_View_Wrapper_Selection extends Intonation_Library_View_
->setClass('warning')
->setText($this->_('date : %s',
$this->_view->tag('span',
Class_Date::getHumanDate($this->_model->getDateMaj(), 'dd/MM/yyyy'),
strftime($this->_('%d %m %Y'), strtotime($this->_model->getDateMaj())),
['class' => 'badge badge-light fs_1em'])))
->setTitle($this->_('La date de dernière mise à jour de la sélection %s',
$this->_model->getLibelle())))];
......
......@@ -97,7 +97,152 @@ class Intonation_Library_View_Wrapper_User extends Intonation_Library_View_Wrapp
public function getBadges() {
return $this->_view->renderUserBadges($this->_model);
$cards = new Class_User_Cards($this->_model);
$badges = [];
if ($this->_model_library = $this->_model->getLibraryLabel())
$badges [] = ((new Intonation_Library_Badge)
->setTag('a')
->setUrl((($library = $this->_model->getLibrary())
? $this->_view->url(['controller' => 'bib',
'action' => 'en-lire-plus',
'id' => $library->getId()]) : ''))
->setClass('secondary')
->setImage(Class_Template::current()
->getIco($this->_view,
'library',
'library'))
->setText($this->_model_library)
->setTitle($this->_('Vous êtes rattaché(e) à la bibliothèque %s',
$this->_model_library)));
if ($card_number = $this->_model->getIdabon())
$badges [] = ((new Intonation_Library_Badge)
->setTag('span')
->setClass('dark')
->setImage(Class_Template::current()
->getIco($this->_view,
'card-number',
'library'))
->setText($card_number)
->setTitle($this->_('Votre numéro de carte %s',
$card_number)));
$validity_date = (new DateTime($this->_model->getDateFin()))->format($this->_('d/m/Y'));
$subscription = (new Class_User_ILSSubscription($this->_model));
$this->_model_validity = $subscription->isValid();
$validity_class = $this->_model_validity
? 'success'
: 'danger';
$validity_class = $subscription->isAboutToExpire()
? 'warning'
: $validity_class;
if ($this->_model->getDateFin())
$badges [] = ((new Intonation_Library_Badge)
->setTag('span')
->setClass($validity_class)
->setImage(Class_Template::current()
->getIco($this->_view,
'subscription',
'library'))
->setText($validity_date)
->setTitle($this->_('Vous êtes abonné(e) jusqu\'au %s',
$validity_date)));
if ($number_of_loans = $cards->getLoansCount())
$badges [] = ((new Intonation_Library_Badge)
->setTag('a')
->setUrl($this->_view->url(['controller' => 'abonne',
'action' => 'prets']))
->setClass('info')
->setImage(Class_Template::current()
->getIco($this->_view,
'loan',
'library'))
->setText($this->_('%d prêt(s) en cours',
$number_of_loans))
->setTitle($this->_('Vous avez %d prêt(s) en cours',
$number_of_loans)));
if ($number_of_late_loans = $cards->getLateLoansCount())
$badges [] = ((new Intonation_Library_Badge)
->setTag('a')
->setUrl($this->_view->url(['controller' => 'abonne',
'action' => 'prets']))
->setClass('danger')
->setImage(Class_Template::current()
->getIco($this->_view,
'late-loan',
'library'))
->setText($this->_('%d prêt(s) en retard en cours',
$number_of_late_loans))
->setTitle($this->_('Vous avez %d prêt(s) en retard en cours',
$number_of_late_loans)));
if ($number_of_holds = $cards->getHoldsCount())
$badges [] = ((new Intonation_Library_Badge)
->setTag('a')
->setUrl($this->_view->url(['controller' => 'abonne',
'action' => 'reservations']))
->setClass('light bg-white text-primary')
->setImage(Class_Template::current()
->getIco($this->_view,
'hold',
'library'))
->setText($this->_('%d réservation(s) en cours',
$number_of_holds))
->setTitle($this->_('Vous avez %d réservation(s) en cours',
$number_of_holds)));
if ($number_of_selections = $this->_model->numberOfPaniers())
$badges [] = ((new Intonation_Library_Badge)
->setTag('a')
->setUrl($this->_view->url(['controller' => 'abonne',
'action' => 'selections']))
->setClass('primary')
->setImage(Class_Template::current()
->getIco($this->_view,
'selection',
'library'))
->setText($this->_('%d sélection(s)',
$number_of_selections))
->setTitle($this->_('Vous avez %d sélection(s) de documents',
$number_of_selections)));
if ($number_of_searches = $this->_model->numberOfBookmarkedSearches())
$badges [] = ((new Intonation_Library_Badge)
->setTag('a')
->setUrl($this->_view->url(['controller' => 'abonne',
'action' => 'selections']))
->setClass('primary')
->setImage(Class_Template::current()
->getIco($this->_view,
'selection',
'library'))
->setText($this->_('%d recherche(s)',
$number_of_searches))