diff --git a/application/modules/admin/controllers/ModoController.php b/application/modules/admin/controllers/ModoController.php index cdcc14fa778691fa094d159e1af0dddbd8b73143..67f2cac2d50e68c127976d7c2c1c435bea788746 100644 --- a/application/modules/admin/controllers/ModoController.php +++ b/application/modules/admin/controllers/ModoController.php @@ -99,7 +99,7 @@ class Admin_ModoController extends ZendAfi_Controller_Action { public function deleteCmsAvisAction() { $avis = Class_Avis::find($this->_getParam('id')); $avis->delete(); - $avis->maj_note_cms($avis->getIdCms(), $avis->getAbonOuBib()); + $avis->majNoteCms($avis->getIdCms(), $avis->getAbonOuBib()); $this->_redirect('opac/cms/articleview/id/'.$avis->getIdCms()); $this->_helper->notify($this->view->_('Avis %s supprimé', $avis->getEntete())); @@ -163,7 +163,7 @@ class Admin_ModoController extends ZendAfi_Controller_Action { public function delAviscmsAction() { $avis = Class_Avis::find($this->_getParam('id')); $avis->delete(); - $avis->maj_note_cms($avis->getIdCms(), $avis->getAbonOuBib()); + $avis->majNoteCms($avis->getIdCms(), $avis->getAbonOuBib()); $this->_helper->notify($this->view->_('Avis %s supprimé', $avis->getEntete())); $this->_redirect('/admin/modo/aviscms'); @@ -173,7 +173,7 @@ class Admin_ModoController extends ZendAfi_Controller_Action { public function validateAviscmsAction() { $avis = Class_Avis::find($this->_getParam('id')); $avis->beValid()->save(); - $avis->maj_note_cms($avis->getIdCms(), $avis->getAbonOuBib()); + $avis->majNoteCms($avis->getIdCms(), $avis->getAbonOuBib()); $this->_helper->notify($this->view->_('Avis %s validé', $avis->getEntete())); $this->_redirect('/admin/modo/aviscms'); } diff --git a/application/modules/opac/controllers/AbonneController.php b/application/modules/opac/controllers/AbonneController.php index d3ab612feeffc6fbd5c62383d48de161e1507c71..5c63564d643cfa42627b12fef265c5e5fc4d20f7 100644 --- a/application/modules/opac/controllers/AbonneController.php +++ b/application/modules/opac/controllers/AbonneController.php @@ -132,83 +132,6 @@ class AbonneController extends ZendAfi_Controller_Action { } - private function handleAvis($readSourceMethod, $writeAvisMethod) { - $cls_user= new Class_Users(); - - $avis = new Class_Avis(); - - // Validation du formulaire - if ($this->_request->isPost()) { - // Bornage du texte - $longueur_min = Class_AdminVar::get("AVIS_MIN_SAISIE"); - $longueur_max = Class_AdminVar::get("AVIS_MAX_SAISIE"); - if(!$longueur_min) $longueur_min=10; - if(!$longueur_max) $longueur_max=250; - - - $filter = new Zend_Filter_StripTags(); - $avisSignature = trim($filter->filter($this->_request->getPost('avisSignature'))); - $avisEntete = trim($filter->filter($this->_request->getPost('avisEntete'))); - $avisTexte = trim($filter->filter($this->_request->getPost('avisTexte'))); - $avisNote = trim($filter->filter($this->_request->getPost('avisNote'))); - $id = trim($filter->filter($this->_request->getPost('id'))); - - if ($avisEntete != '' and (strlen($avisTexte)>= $longueur_min and strlen($avisTexte)<= $longueur_max ) and $avisSignature != '') - { - $avis->$writeAvisMethod($this->_user->ID_USER,$this->_user->ROLE_LEVEL,$id,$avisNote,$avisEntete,$avisTexte); - $cls_user->updatePseudo($this->_user, $avisSignature); - - $this->_renderRefreshOnglet(); - } - else - { - if(strlen($avisTexte)< $longueur_min or strlen($avisTexte) > $longueur_max) - $this->view->message = $this->_("L'avis doit avoir une longueur comprise entre %d et %d caractères", $longueur_min, $longueur_max); - else - $this->view->message = $this->_('Il faut compléter tous les champs.'); - $this->view->avisSignature = $avisSignature; - $this->view->avisEntete = $avisEntete; - $this->view->avisTexte = $avisTexte; - $this->view->avisNote = $avisNote; - $this->view->id = $id; - - $viewRenderer = $this->getHelper('ViewRenderer'); - $viewRenderer->setLayoutScript('subModal.phtml'); - } - } - // Saisie du formulaire - else - { - $id = $this->_request->getParam('id', 0); - $this->view->message = ''; - $this->view->id = $id; - $this->view->avisSignature = $cls_user->getNomAff($this->_user->ID_USER); - $data = $avis->$readSourceMethod($this->_user->ID_USER, $id); - - $this->view->avisEntete = $data[0]["ENTETE"]; - $this->view->avisTexte = $data[0]["AVIS"]; - if(!$data[0]["NOTE"]) $data[0]["NOTE"]="0"; - $this->view->avisNote = $data[0]["NOTE"]; - if($this->view->avisEntete) $this->view->mode_modif=true; - else $this->view->mode_modif=false; - - $viewRenderer = $this->getHelper('ViewRenderer'); - $viewRenderer->setLayoutScript('subModal.phtml'); - } - } - - - protected function _renderRefreshOnglet() { - $this->getResponse()->setHeader('Content-Type', 'text/html;charset=utf-8'); - $js = 'location.reload()'; - if (array_key_exists('onglets', $_SESSION)) - $js = "refreshOnglet('" . $_SESSION["onglets"]["avis"] . "')"; - $this->getResponse()->setBody("<script>window.top.hidePopWin(false);window.top." . $js. ";</script>"); - $viewRenderer = $this->getHelper('ViewRenderer'); - $viewRenderer->setNoRender(); - } - - public function avisAction() { $id_notice = $this->_request->getParam('id_notice', 0); @@ -317,7 +240,68 @@ class AbonneController extends ZendAfi_Controller_Action { public function cmsavisAction() { - $this->handleAvis('getCmsAvisById', 'ecrireCmsAvis'); + $this->view->titre = $this->_('Votre avis'); + + // Validation du formulaire + if ($this->_request->isPost()) { + // Bornage du texte + $longueur_min = Class_AdminVar::get("AVIS_MIN_SAISIE"); + $longueur_max = Class_AdminVar::get("AVIS_MAX_SAISIE"); + if(!$longueur_min) $longueur_min=10; + if(!$longueur_max) $longueur_max=250; + + + $filter = new Zend_Filter_StripTags(); + $avisSignature = trim($filter->filter($this->_request->getPost('avisSignature'))); + $avisEntete = trim($filter->filter($this->_request->getPost('avisEntete'))); + $avisTexte = trim($filter->filter($this->_request->getPost('avisTexte'))); + $avisNote = trim($filter->filter($this->_request->getPost('avisNote'))); + $id = trim($filter->filter($this->_request->getParam('id'))); + + if ($avisEntete != '' and (strlen($avisTexte)>= $longueur_min and strlen($avisTexte)<= $longueur_max ) and $avisSignature != '') { + Class_Avis::ecrireCmsAvis($this->_user->ID_USER, + $this->_user->ROLE_LEVEL, + $id, + $avisNote, + $avisEntete, + $avisTexte); + $this->_user + ->setPseudo($avisSignature) + ->save(); + + $this->_redirect('/opac/cms/articleview/id/'.$id); + return; + } + else + { + if(strlen($avisTexte)< $longueur_min or strlen($avisTexte) > $longueur_max) + $this->view->message = $this->_("L'avis doit avoir une longueur comprise entre %d et %d caractères", $longueur_min, $longueur_max); + else + $this->view->message = $this->_('Il faut compléter tous les champs.'); + $this->view->avisSignature = $avisSignature; + $this->view->avisEntete = $avisEntete; + $this->view->avisTexte = $avisTexte; + $this->view->avisNote = $avisNote; + $this->view->id = $id; + } + } + // Saisie du formulaire + else + { + $id = $this->_request->getParam('id', 0); + $this->view->message = ''; + $this->view->id = $id; + $this->view->avisSignature = $cls_user->getNomAff($this->_user->getId()); + + if (!$avis = Class_Avis::findFirstBy(['id_user' => $this->_user->getId(), + 'id_cms' => $id])) + $avis = Class_Avis::newInstance(['id_user' => $this->_user->getId(), + 'id_cms' => $id]); + + $this->view->avisEntete = $avis->getEntete(); + $this->view->avisTexte = $avis->getAvis(); + $this->view->avisNote = $avis->getNote(); + } } diff --git a/application/modules/opac/controllers/BlogController.php b/application/modules/opac/controllers/BlogController.php index 33338e491ca39faa521f38c821e32dc66fa1acfc..5788de638ef22b102ac4d1630ec58307808e9748 100644 --- a/application/modules/opac/controllers/BlogController.php +++ b/application/modules/opac/controllers/BlogController.php @@ -16,7 +16,7 @@ * * You should have received a copy of the GNU AFFERO GENERAL PUBLIC LICENSE * along with BOKEH; if not, write to the Free Software - * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// // OPAC3: Blog @@ -28,7 +28,7 @@ class BlogController extends ZendAfi_Controller_Action { private $_user = null; // Le user connecté var $modo_blog; var $_today; - + function init() { //Verify that the user has successfully authenticated. If not, we redirect to the login. @@ -39,15 +39,15 @@ class BlogController extends ZendAfi_Controller_Action { $class_date = new Class_Date(); $this->_today = $class_date->DateTimeDuJour(); } - + function indexAction() { $this->_redirect('opac/blog/lastcritique/nb/10'); } - - //------------------------------------------------------------------------------------------------------ + + //------------------------------------------------------------------------------------------------------ // Donner son avis - //------------------------------------------------------------------------------------------------------ + //------------------------------------------------------------------------------------------------------ function viewauteurAction() { $id_user = (int)$this->_request->getParam('id', $this->_user->ID_USER); if ($auteur = Class_Users::getLoader()->find($id_user)) { @@ -57,7 +57,7 @@ class BlogController extends ZendAfi_Controller_Action { $this->view->liste_avis = ''; $this->view->name = 'Auteur introuvable'; } - + $this->view->title = "Avis"; $this->view->id_user = $id_user; @@ -84,12 +84,12 @@ class BlogController extends ZendAfi_Controller_Action { $this->_javascriptRedirectToReferrer(); } - + function lastcritiqueAction() { $nb_avis = (int)$this->_request->getParam('nb', 20); $liste_avis = Class_AvisNotice::getLoader()->findAllBy(array('order' => 'date_avis desc', 'limit' => $nb_avis)); - + $this->view->nb_aff = $nb_avis; $this->view->liste_avis = Class_AvisNotice::filterVisibleForUser($this->_user, $liste_avis); $this->view->title = $this->view->_("Dernières critiques"); @@ -102,7 +102,7 @@ class BlogController extends ZendAfi_Controller_Action { $preferences = Class_Profil::getCurrentProfil() ->getModuleAccueilPreferences($id_module, 'CRITIQUES'); $avis = Class_AvisNotice::getAvisFromPreferences($preferences); - + $this->view->nb_aff = 50; $this->view->liste_avis = $avis; $this->view->title = 'Dernières critiques'; @@ -119,13 +119,13 @@ class BlogController extends ZendAfi_Controller_Action { ->getHelper('ViewRenderer') ->setLayoutScript('readspeaker.phtml'); - $id_avis = $this->_request->getParam('id'); + $id_avis = $this->_request->getParam('id'); $this->view->avis = Class_AvisNotice::getLoader()->find($id_avis); } - + function viewavisAction() { - $id_avis = $this->_request->getParam('id'); + $id_avis = $this->_request->getParam('id'); $avis = Class_AvisNotice::getLoader()->find($id_avis); $this->view->avis = $avis; @@ -134,52 +134,9 @@ class BlogController extends ZendAfi_Controller_Action { $this->view->user_co = ($this->_user->ID_USER != ''); $this->view->user = $this->_user; } - - - function addcmtAction() { - $filter = new Zend_Filter_StripTags(); - $contenu = $filter->filter($this->_request->getPost('cmt')); - $id_avi = $this->_request->getPost('id_avis'); $id_avis = explode('-',$id_avi); - $pseudo = $this->_request->getPost('pseudo'); - $type = $this->_request->getPost('type'); - - if(trim($pseudo)=="") {$this->_redirect('blog/viewavis/id/'.$id_avi);} - - - if($type == "notice") $id_notice = $id_avis[0]; else $id_notice = 0; - if($type == "cms") $id_cms = $id_avis[0]; else $id_cms = 0; - if($this->modo_blog == 1) $statut =0; else $statut=1; - - if($this->_user->LOGIN) { - if($this->_user->ROLE_LEVEL >=3) $abon_ou_bib = 1; - else $abon_ou_bib = 0; - - $cls_user= new Class_Users(); - $cls_user->updatePseudo($this->_user, $pseudo); - } else { - $abon_ou_bib = 0; - } - - $data = array( - 'ID_CMT' => '', - 'ID_USER' => $this->_user->ID_USER, - 'ID_NOTICE' => $id_notice, - 'ID_CMS' => $id_cms, - 'DATE_CMT' => $this->_today, - 'DATE_MOD' => null, - 'CMT' => $contenu, - 'STATUT' => $statut, - 'ABON_OU_BIB' => $abon_ou_bib, - 'SIGNATURE' => $pseudo, - ); - - $class_blog = new Class_Blog(); - $class_blog->addCmt($data); - $this->_redirect('blog/viewavis/id/'.$id_avi); - } - - function alertAction() - { + + + function alertAction() { $class_blog = new Class_Blog(); $type = $this->_request->getParam('type'); $id = $this->_request->getParam('id_avis'); diff --git a/application/modules/opac/views/scripts/abonne/avis.phtml b/application/modules/opac/views/scripts/abonne/avis.phtml index 205501b56bc9825953a303d1295ac5f4c38c6f57..6ca3fc9bd736d670eed1d613e177592af94dfafc 100644 --- a/application/modules/opac/views/scripts/abonne/avis.phtml +++ b/application/modules/opac/views/scripts/abonne/avis.phtml @@ -1,9 +1,9 @@ <?php -echo $this->partial("abonne/avis_partial.phtml", +echo $this->partial("abonne/avis_partial.phtml", array( 'message' => $this->message, - 'action' => $this->url(array('controller' => 'abonne', - 'action' => 'avis', + 'action' => $this->url(array('controller' => 'abonne', + 'action' => 'avis', 'id_notice' => $this->id_notice, 'id' => $this->id)), 'id' => $this->id, @@ -11,19 +11,5 @@ echo $this->partial("abonne/avis_partial.phtml", 'avisEntete' => $this->avisEntete, 'avisTexte' => $this->avisTexte, 'avisNote' => $this->avisNote, - )); + )); ?> - -<script> -$('#opac-dialog form').submit(function(event) { - event.preventDefault(); - var form = $(this); - $.post(form.attr('action'), - form.serialize(), - function(data) { opacDialogClose(); - opacDialogFromData(data); - } - ); -} -); -</script> \ No newline at end of file diff --git a/application/modules/opac/views/scripts/abonne/avis_partial.phtml b/application/modules/opac/views/scripts/abonne/avis_partial.phtml index 7f00091c6a9f74622b197f3f7edf2068044292af..f86c9fa10a269238713933d8ebcb58908d2d7d00 100644 --- a/application/modules/opac/views/scripts/abonne/avis_partial.phtml +++ b/application/modules/opac/views/scripts/abonne/avis_partial.phtml @@ -37,4 +37,20 @@ </form> <br> </div> -</center> \ No newline at end of file +</center> + + + +<script> +$('#opac-dialog form').submit(function(event) { + event.preventDefault(); + var form = $(this); + $.post(form.attr('action'), + form.serialize(), + function(data) { opacDialogClose(); + opacDialogFromData(data); + } + ); +} +); +</script> diff --git a/ckeditor/core_five_filemanager/scripts/filemanager.js b/ckeditor/core_five_filemanager/scripts/filemanager.js index 984590c6727fda31ef3056afcd36873ac6f43b25..7e2ec29e587c2e25ee94bc2d6f59c2c790ab4518 100644 --- a/ckeditor/core_five_filemanager/scripts/filemanager.js +++ b/ckeditor/core_five_filemanager/scripts/filemanager.js @@ -952,10 +952,10 @@ $(function(){ if (is_image) { $.prompt( - [{title: 'Redimmensionner automatiquement l\'image si la résolution est supérieure à :', + [{title: 'Redimensionner automatiquement l\'image si la résolution est supérieure à :', buttons: { 'OK': true, - 'Ne pas redimmensionner': false}, + 'Ne pas redimensionner': false}, html: '<label><input type="radio" name="geometry" value="800">800x600</label>' +'<label><input type="radio" name="geometry" value="1024" checked="checked">1024x768</label>' +'<label><input type="radio" name="geometry" value="1280">1280x1024</label>', diff --git a/ckeditor/core_five_filemanager/scripts/languages/fr.js b/ckeditor/core_five_filemanager/scripts/languages/fr.js index 983ad12276de0e38660b3859fbb1ea6e48997d8c..b1d5a942a687cd4984c07b6f6b988d333d220094 100644 --- a/ckeditor/core_five_filemanager/scripts/languages/fr.js +++ b/ckeditor/core_five_filemanager/scripts/languages/fr.js @@ -53,5 +53,5 @@ "kb": "ko", "mb": "mo", "gb": "go", - "resize" : "redimmensionner automatiquement les images" + "resize" : "redimensionner automatiquement les images" } diff --git a/library/Class/Article.php b/library/Class/Article.php index 7282dc8c7ef77f15e52032da85e0bc624d28773b..b3fae930ac120e0de2392be6cdc6e9ea01a8a92c 100644 --- a/library/Class/Article.php +++ b/library/Class/Article.php @@ -1065,7 +1065,9 @@ class Class_Article extends Storm_Model_Abstract { public function getRank() { - return Class_CmsRank::getLoader()->findFirstBy(array('id_cms' => $this->getId())); + if (!$rank = Class_CmsRank::findFirstBy(['id_cms' => $this->getId()])) + $rank = Class_CmsRank::newInstance(['id_cms' => $this->getId()]); + return $rank; } @@ -1175,4 +1177,4 @@ class Class_Article extends Storm_Model_Abstract { } -?> +?> \ No newline at end of file diff --git a/library/Class/Avis.php b/library/Class/Avis.php index cf2ebfc8cf39d3d2b930e40ce2cf3fa921aed163..02e128d5e044be7ec8cf5cf29fbda77078f9bc3c 100644 --- a/library/Class/Avis.php +++ b/library/Class/Avis.php @@ -23,7 +23,7 @@ * Gestion des Avis sur les articles */ class Class_Avis extends Storm_Model_Abstract { - use Trait_Avis; + use Trait_Avis, Trait_TimeSource; protected $_table_name = 'cms_avis'; protected $_belongs_to = ['auteur' => ['model' => 'Class_Users', @@ -35,37 +35,10 @@ class Class_Avis extends Storm_Model_Abstract { 'user' => ['model' => 'Class_Users', 'referenced_in' => 'id_user']]; - var $sql; // Curseur sql - var $_today; - - - public function __construct() { - $this->sql = Zend_Registry::get('sql'); - $class_date = new Class_Date(); - $this->_today = $class_date->DateTimeDuJour(); - } - - - public function getNomAff() { - if (!$auteur = $this->getAuteur()) - return 'Anonyme'; - return $auteur->getNomAff(); - } - - - public function beValid() { - return $this->setStatut(1); - } - - - public function getCmsAvisById($id_user,$id_news) { - $req_news = "Select * from cms_avis Where ID_CMS=$id_news AND ID_USER=$id_user"; - return $this->sql->fetchAll($req_news); - } /** Ecrire 1 avis (update si existe déjà ) */ - public function ecrireCmsAvis($id_user, $role_level, $id_news, $note, $entete, $avis) { + public static function ecrireCmsAvis($id_user, $role_level, $id_news, $note, $entete, $content) { $modo_avis_abo = getVar('MODO_AVIS'); // 0 apres / 1 avant de publier sur le site $modo_avis_bib = getVar('MODO_AVIS_BIBLIO'); // 0 apres / 1 avant de publier sur le site @@ -79,85 +52,69 @@ class Class_Avis extends Storm_Model_Abstract { if($modo_avis_bib == 0) $statut = 1; } - try { - $avis = Class_Avis::getLoader()->findFirstBy(['id_user' => $id_user, - 'id_cms' => $id_news]); - - if (!$avis) - $avis = Class_Avis::getLoader()->newInstance(['id_user' => $id_user, - 'id_notice' => '', - 'id_cms' => $id_news, - 'date_avis' => $this->_today, - 'date_mod' => '']); - - $avis - ->setEntete(strLeft($entete, 100)) - ->setAvis($avis) - ->setNote($note) - ->setStatut($statut) - ->setAbonOuBib($abon_ou_bib) - ->save(); - - if (($modo_avis_abo == 0 && $role_level < 3) - || ($modo_avis_bib == 0 && $role_level >= 3)) - $this->maj_note_cms($id_news, $abon_ou_bib); - - } catch (Exception $e) { - logErrorMessage('Class: Class_Avis; Function: ecrireCmsAvis' . NL . $req . NL . $e->getMessage()); - return false; - } + $avis = Class_Avis::getLoader()->findFirstBy(['id_user' => $id_user, + 'id_cms' => $id_news]); + + if (!$avis) + $avis = Class_Avis::getLoader()->newInstance(['id_user' => $id_user, + 'id_notice' => '', + 'id_cms' => $id_news, + 'date_avis' => date('Y-m-d H:i:s', self::getTimeSource()->time()), + 'date_mod' => '']); + $avis + ->setEntete(strLeft($entete, 100)) + ->setAvis($content) + ->setNote($note) + ->setStatut($statut) + ->setAbonOuBib($abon_ou_bib) + ->save(); + + if (($modo_avis_abo == 0 && $role_level < 3) + || ($modo_avis_bib == 0 && $role_level >= 3)) + $avis->majNoteCms($id_news, $abon_ou_bib); + + return $avis; } - public function maj_note_cms($id_news, $abon_ou_bib) { - $sqlStmt = "Select count(*), avg(NOTE) From cms_avis Where ID_CMS=$id_news and ABON_OU_BIB='$abon_ou_bib' AND STATUT=1"; - $data = $this->sql->fetchAll($sqlStmt); - $note=round($data[0]["avg(NOTE)"],1); - if (strlen($note)==1) - $note.=".0"; - else { - $dec=strRight($note,1); - if($dec<3) $dec="0"; elseif($dec<"8")$dec="5";else {$note+=1; $dec=0;} - $note=strLeft($note,1).".".$dec; - } - $nombre=$data[0]["count(*)"]; - // Lire enreg rank - $enreg=fetchEnreg("select * from cms_rank where ID_CMS=$id_news"); - $sqlStmt = "Delete from cms_rank Where ID_CMS=$id_news"; - $stmt = $this->sql->query($sqlStmt); - if($abon_ou_bib==1) { - $abon_nombre_avis=$enreg["ABON_NOMBRE_AVIS"]; - $abon_note=$enreg["ABON_NOTE"]; - $bib_nombre_avis=$nombre; - $bib_note=$note; - } else { - $abon_nombre_avis=$nombre; - $abon_note=$note; - $bib_nombre_avis=$enreg["BIB_NOMBRE_AVIS"]; - $bib_note=$enreg["BIB_NOTE"]; - } + public function getNomAff() { + if (!$auteur = $this->getAuteur()) + return $this->_('Anonyme'); + return $auteur->getNomAff(); + } - if(!$abon_nombre_avis) $abon_nombre_avis=0; - if(!$bib_nombre_avis) $bib_nombre_avis=0; - $sqlStmt = "Insert Into cms_rank(ID_CMS,ABON_NOMBRE_AVIS,ABON_NOTE,BIB_NOMBRE_AVIS,BIB_NOTE) Values($id_news,$abon_nombre_avis,'$abon_note',$bib_nombre_avis,'$bib_note')"; - $stmt = $this->sql->query($sqlStmt); + public function beValid() { + return $this->setStatut(1); } - public function HtmlCmsAvecAvis($id_news) { - $req_news = "Select * from cms_article Where ID_ARTICLE=$id_news"; - $news = $this->sql->fetchAll($req_news); + public function majNoteCms($id_news, $abon_ou_bib) { + $note = 0; + if ( $all_avis = Class_Avis::getLoader()->findAllBy(['id_cms' => $id_news, + 'abon_ou_bib' => $abon_ou_bib, + 'statut' => 1])) { + $note = array_sum(array_map(function($a){return $a->getNote();}, $all_avis)) / count($all_avis); + } + + $note = sprintf("%01.1f", floor($note * 2)/2); + $nombre = count($all_avis); - if ($news[0]["AVIS"] != 1) - return ' '; + $rank = Class_Article::find($id_news)->getRank(); - $sqlStmt = "Select * from cms_rank Where ID_CMS=$id_news"; - $ret = $this->sql->fetchAll($sqlStmt); + if ($abon_ou_bib == static::$AVIS_BIBLIO) { + $rank + ->setBibNombreAvis($nombre) + ->setBibNote($note); + } else { + $rank + ->setAbonNombreAvis($nombre) + ->setAbonNote($note); + } - $nb_avis = (int)$ret[0]["BIB_NOMBRE_AVIS"] + (int)$ret[0]["ABON_NOMBRE_AVIS"]; - $label = ($nb_avis == 0) ? 'aucun avis' : ' avis ('.$nb_avis.')'; - return '<div align="right"><a href="'.BASE_URL.'/cms/articleview/id/'.$id_news.'">»' . $label . '</a></div>'; + $rank->save(); } -} \ No newline at end of file +} + +?> \ No newline at end of file diff --git a/library/Class/CmsRank.php b/library/Class/CmsRank.php index d1f8467ac54e28b30222540816bcac564f0d696d..72a6cb0d88097d784e4a9113ea80c7d03cba114e 100644 --- a/library/Class/CmsRank.php +++ b/library/Class/CmsRank.php @@ -16,29 +16,27 @@ * * You should have received a copy of the GNU AFFERO GENERAL PUBLIC LICENSE * along with BOKEH; if not, write to the Free Software - * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ class Class_CmsRank extends Storm_Model_Abstract { protected $_table_name = 'cms_rank'; - protected $_belongs_to = array('article' => array('model' => 'Class_Article', - 'referenced_in' => 'id_cms')); - protected $_default_attribute_values = array( + protected $_table_primary = 'id_cms'; + + protected $_belongs_to = ['article' => ['model' => 'Class_Article', + 'referenced_in' => 'id_cms']]; + + protected $_default_attribute_values = [ 'abon_nombre_avis' => 0, 'bib_nombre_avis' => 0, 'abon_note' => 0, - 'bib_note' => 0); + 'bib_note' => 0]; - public static function getLoader() { - return self::getLoaderFor(__CLASS__); - } - - public function getNbAvisTotal() { return $this->getBibNombreAvis() + $this->getAbonNombreAvis(); } } - + ?> \ No newline at end of file diff --git a/library/Class/Users.php b/library/Class/Users.php index e41ab42e8bb4d9c9e1539383e18bb2b85149df56..aee7ad6551a61019badd525f6da9e0ab71cb4425 100644 --- a/library/Class/Users.php +++ b/library/Class/Users.php @@ -789,18 +789,6 @@ class Class_Users extends Storm_Model_Abstract { } - //------------------------------------------------------------------------------------------------------ - // Ecriture user - //------------------------------------------------------------------------------------------------------ - public function updatePseudo($data_user, $pseudo) { - $user = $this->getLoader()->find($data_user->ID_USER); - if ($user == null) return false; - - return $user - ->setPseudo($pseudo) - ->save(); - } - //------------------------------------------------------------------------------------------------------ // Vérification pour eviter les doublons de login //------------------------------------------------------------------------------------------------------ diff --git a/library/ZendAfi/Controller/Plugin/AdminAuth.php b/library/ZendAfi/Controller/Plugin/AdminAuth.php index 19753e8d23cc6000467fc957b93236dcf0cf79e3..23b522f18961a664ea2f831ffd0be4418b921cc6 100644 --- a/library/ZendAfi/Controller/Plugin/AdminAuth.php +++ b/library/ZendAfi/Controller/Plugin/AdminAuth.php @@ -66,7 +66,7 @@ class ZendAfi_Controller_Plugin_AdminAuth extends Zend_Controller_Plugin_Abstrac if ((!$user = Class_Users::getIdentity()) && ($controller == "abonne" && $action !== "authenticate")) { $request->setParam('redirect', Class_Url::absolute()); $controller = 'auth'; - $action = 'login'; + $action = ($request->getParam('render') == 'popup') ? 'popup-login' : 'login'; } } diff --git a/library/ZendAfi/View/Helper/AvisCms.php b/library/ZendAfi/View/Helper/AvisCms.php index 8024f82fb8aa0d1cbc3876da7468ae398d92a27e..3bb676fa561aa838b79e9bdba3a5cc3066377396 100644 --- a/library/ZendAfi/View/Helper/AvisCms.php +++ b/library/ZendAfi/View/Helper/AvisCms.php @@ -16,18 +16,17 @@ * * You should have received a copy of the GNU AFFERO GENERAL PUBLIC LICENSE * along with BOKEH; if not, write to the Free Software - * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ class ZendAfi_View_Helper_AvisCms extends Zend_View_Helper_HtmlElement { public function avisCms($article) { return $this->rendHtmlBlockAvis($article); } - + function rendHtmlBlockAvis($article) { $nb_avis = 0; - if (!$rank = $article->getRank()) - $rank = Class_CmsRank::newInstance(); + $rank = $article->getRank(); $nb_avis = $rank->getNbAvisTotal(); $txt_nb_avis = ($nb_avis == 0) ?" Aucun avis" : " Avis (".$nb_avis.")"; @@ -35,20 +34,22 @@ class ZendAfi_View_Helper_AvisCms extends Zend_View_Helper_HtmlElement { $html = '<div class="avis_show_avis" onclick="showCmsAvis('.$id_news.', this)"><img src="'.URL_IMG.'bouton/plus_carre.gif" style="float:left" border="0" alt="Voir les avis" title="Voir les avis" id="plus"/> '.$txt_nb_avis.' </div>'; $html.='<div id="avis_'.$id_news.'" style="display:none;padding-left:5px;">'; $html.='<br />'; - $html.='<a href="#" onclick="javascript:fonction_abonne(\''.Class_Users::currentUserId().'\',\'/opac/abonne/cmsavis?id='.$id_news.'\')">» Donner ou modifier votre avis</a>'; + $html.= $this->view->tagAnchor(['controller' => 'abonne', 'action' => 'cmsavis', 'id' => $id_news], + '» '.$this->view->_('Donner ou modifier votre avis'), + ['data-popup' => 'true']); $html.='<ul class="notice_info">'; if ($rank->getBibNombreAvis()) $html.='<li>'.$this->view->noteImg($rank->getBibNote()).' <a href="#" onclick="showAvis('.$id_news.',\'bib\');return false;">Avis de bibliothécaires</a> '.$this->formatNoteLabel($rank->getBibNombreAvis()).'</li>'; if ($rank->getAbonNombreAvis()) $html.='<li>'.$this->view->noteImg($rank->getAbonNote()).' <a href="#" onclick="showAvis('.$id_news.',\'abo\');return false;">Avis de lecteurs du portail</a> '.$this->formatNoteLabel($rank->getAbonNombreAvis()).'</li>'; $html.='</ul>'; - + $view = (getVar('MODO_AVIS_BIBLIO') == 1) ? 1 : ""; - + $liste_avis = $this->getCmsAvisBiblio($article, $view); $style = (count($liste_avis) == 0) ? "none" : "block"; - + // Tableau bib $html.='<div id="bib_'.$id_news.'" style="display:'.$style.'"><table cellpadding="0" cellspacing="0" border="0" style="width:100%">'; $html.='<tr><td class="avis_from">Avis des bibliothécaires</td></tr>'; @@ -56,7 +57,7 @@ class ZendAfi_View_Helper_AvisCms extends Zend_View_Helper_HtmlElement { $html.='</table></div>'; $view = (getVar('MODO_AVIS') == 1) ? 1 : ""; - + // Tableau Abonne $liste_avis_abo = $this->getCmsAvisAbo($article, $view); @@ -65,13 +66,13 @@ class ZendAfi_View_Helper_AvisCms extends Zend_View_Helper_HtmlElement { $html.='<div id="abo_'.$id_news.'" style="display:'.$style.'"><table cellpadding="0" cellspacing="0" border="0" style="width:100%">'; $html.='<tr><td class="avis_from">Avis des lecteurs du portail</td></tr>'; $html.='<tr><td>'.$this->rendHTMLCmsAvis($liste_avis_abo,0).'</td></tr>'; - + $html.='</table></div>'; $html.='</div>'; $html.='<div style="width:100%;background:transparent url('.URL_IMG.'box/menu/separ.gif) repeat-x scroll center bottom"> </div>'; - + return($html); - } + } public function formatNoteLabel($note) { return $this->view->_plural($note, @@ -102,11 +103,11 @@ class ZendAfi_View_Helper_AvisCms extends Zend_View_Helper_HtmlElement { return Class_Avis::getLoader()->findAllBy($params); } - + // type =0 -> rend bulle blanche pour abonne // type =1 -> rend bulle bleue pour bibliothecaire function rendHTMLCmsAvis($avis_array, $type=0) { - if(!is_array($avis_array)) + if(!is_array($avis_array)) return ''; $html = array(); @@ -166,7 +167,7 @@ class ZendAfi_View_Helper_AvisCms extends Zend_View_Helper_HtmlElement { $html[]='</table>'; } - if(is_array($html)) + if(is_array($html)) return(implode("", $html)); return('<div style="padding-left:7px"> Aucun avis pour le moment.</div>'); diff --git a/tests/application/modules/admin/controllers/ModoControllerTest.php b/tests/application/modules/admin/controllers/ModoControllerTest.php index 13110c12a1a3134169dd725f0594daaca271e7f1..03e5c3bc71cbc27be9c9de22f21cd175617daf61 100644 --- a/tests/application/modules/admin/controllers/ModoControllerTest.php +++ b/tests/application/modules/admin/controllers/ModoControllerTest.php @@ -463,18 +463,24 @@ class ModoControllerDeleteAvisCmsTest extends Admin_AbstractControllerTestCase { public function setUp() { parent::setUp(); - Class_Avis::getLoader() - ->newInstanceWithId(34) - ->setAuteur(Class_Users::getLoader() - ->newInstanceWithId(98) - ->setPseudo('Mimi')) - ->setDateAvis('2012-02-05') - ->setNote(4) - ->setEntete('Hmmm') - ->setAvis('ça a l\'air bon') - ->beWrittenByAbonne() - ->setIdCms(28); + $this->fixture('Class_Article', ['id' => 28, + 'titre' => 'test', + 'contenu' => 'test']); + $this->fixture('Class_Avis', + ['id' => 34, + 'auteur' => $this->fixture('Class_Users', + ['id' => 98, + 'login' => 'mimi', + 'password' => 'secret', + 'pseudo' => 'mimi']), + 'date_avis' => '2012-02-05', + 'note' => 4, + 'entete' => 'Hmmmm', + 'avis' => 'ça a l\'air bon', + 'id_cms' => 28]) + ->beWrittenByAbonne() + ->assertSave(); Storm_Test_ObjectWrapper::onLoaderOfModel('Class_Avis') ->whenCalled('delete') diff --git a/tests/application/modules/opac/controllers/AbonneControllerCmsAvisTest.php b/tests/application/modules/opac/controllers/AbonneControllerCmsAvisTest.php index 012274cbe3d07446b46dc5fa5503bb77574f4c6a..40647670994b4d6fce3435a0d326fb3c75fa8684 100644 --- a/tests/application/modules/opac/controllers/AbonneControllerCmsAvisTest.php +++ b/tests/application/modules/opac/controllers/AbonneControllerCmsAvisTest.php @@ -16,21 +16,31 @@ * * You should have received a copy of the GNU AFFERO GENERAL PUBLIC LICENSE * along with BOKEH; if not, write to the Free Software - * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ abstract class AbonneControllerCmsAvisTestCase extends AbstractControllerTestCase { public function setUp() { parent::setUp(); + Storm_Model_Loader::defaultToVolatile(); $this->fixture('Class_Article', ['id' => 1, - 'titre' => 'Je suis Charlie', - 'contenu' => 'C\'est de la balle d\'être Charlie', - 'avis' => 1]); + 'titre' => 'Je suis Charlie', + 'contenu' => 'C\'est de la balle d\'être Charlie', + 'avis' => 1]); } + + + public function tearDown() { + Storm_Model_Loader::defaultToDb(); + parent::tearDown(); + } } + + + class AbonneControllerCmsAvisViewArticleWithoutCommentTest extends AbonneControllerCmsAvisTestCase { public function setUp() { parent::setUp(); @@ -40,67 +50,217 @@ class AbonneControllerCmsAvisViewArticleWithoutCommentTest extends AbonneControl /** @test */ - public function ArticleJeSuisCharlieShouldHaveLinkToAddComment() { - $this->assertXPathContentContains('//a[contains(@onclick, "/opac/abonne/cmsavis?id=1")]', 'Donner ou modifier votre avis'); + public function articleJeSuisCharlieShouldHaveLinkToAddComment() { + $this->assertXPathContentContains('//a[@href = "/abonne/cmsavis/id/1"][@data-popup="true"]', + 'Donner ou modifier votre avis'); + } + + + /** @test */ + public function articleWithoutCommentShouldNotHaveLinkToAccessLibrariansComments() { + $this->assertNotXPathContentContains('//a[contains(@onclick, "showAvis(1")]', + 'Avis de bibliothécaires'); + } + + + /** @test */ + public function articleWithoutCommentShouldNotHaveLinkToAccessBorrowersComments() { + $this->assertNotXPathContentContains('//a[contains(@onclick, "showAvis(1")]', + 'Avis de lecteurs du portail'); + } +} + + + +class AbonneControllerCmsAvisPostActionTest extends AbonneControllerCmsAvisTestCase { + public function setUp() { + parent::setUp(); + + Class_AdminVar::newInstanceWithId('MODO_AVIS_BIBLIO', ['valeur' => 0]); + Class_AdminVar::newInstanceWithId('MODO_AVIS', ['valeur' => 0]); + + Class_Avis::setTimeSource(new TimeSourceForTest('2015-01-15 17:18:35')); + + $this->postDispatch('/abonne/cmsavis/id/1', + ['avisSignature' => 'toto', + 'avisEntete' => 'Vive les dessins', + 'avisTexte' => 'A vos jolis crayons !', + 'avisNote' => 3]); + } + + + /** @test */ + public function responseShouldRedirectToArticle() { + $this->assertRedirectTo('/opac/cms/articleview/id/1', $this->getResponseLocation()); + } + + + /** @test */ + public function createdAvisEnTeteShouldBeViveLesDessins() { + $this->assertEquals('Vive les dessins', Class_Avis::find(1)->getEntete()); + + } + + + /** @test */ + public function createdAvisContentShouldBeAVosCrayons() { + $this->assertEquals('A vos jolis crayons !', Class_Avis::find(1)->getAvis()); + } + + + /** @test */ + public function createdAvisNoteShouldBeThree() { + $this->assertEquals(3, Class_Avis::find(1)->getNote()); + } + + /** @test */ + public function currentUsedPseudoShouldBeToto() { + $this->assertEquals('toto', Class_Users::getIdentity()->getPseudo()); + } + + /** @test */ + public function dateAvisShouldBeNow() { + $this->assertEquals('2015-01-15 17:18:35', Class_Avis::find(1)->getDateAvis()); + } + + + /** @test */ + public function createdAvisModerationShouldBeOK() { + $this->assertTrue(Class_Avis::find(1)->isModerationOK()); } /** @test */ - public function ArticleWithoutCommentShouldNotHaveLinkToAccessLibrariansComments() { - $this->assertNotXPathContentContains('//a[contains(@onclick, "showAvis(1")]', 'Avis de bibliothécaires'); + public function rankNoteShouldBeThree() { + $this->assertEquals(3, Class_Avis::find(1)->getArticle()->getRank()->getBibNote()); } /** @test */ - public function ArticleWithoutCommentShouldNotHaveLinkToAccessBorrowersComments() { - $this->assertNotXPathContentContains('//a[contains(@onclick, "showAvis(1")]', 'Avis de lecteurs du portail'); + public function userIdShouldBe666() { + $this->assertEquals(666, Class_Avis::find(1)->getIdUser()); } } -class AbonneControllerCmsAvisViewArticleWithCommentTest extends AbonneControllerCmsAvisTestCase { + + +class AbonneControllerCmsAvisPostWithErrorsActionTest extends AbonneControllerCmsAvisTestCase { public function setUp() { parent::setUp(); - $this->fixture('Class_Users' , ['id' => 112, - 'login' => 'max', - 'password' => 'maxLaMenace']); + $this->postDispatch('/abonne/cmsavis/id/1', + ['avisSignature' => 'toto', + 'avisEntete' => 'Vive les dessins', + 'avisTexte' => '', + 'avisNote' => 3]); + } - $this->fixture('Class_CmsRank', ['id' => 3, - 'id_cms' => 1, - 'abon_nombre_avis' => 1, - 'abon_note' => '4.0', - 'bib_nombre_avis' => 0, - 'bib_note' => '0.0']); + + /** @test */ + public function pageShouldContainsContentTooShort() { + $this->assertXPathContentContains('//p[@class="error"]', + 'doit avoir une longueur comprise entre'); + } +} + + + + +abstract class AbonneControllerCmsAvisViewArticleWithCommentTestCase extends AbonneControllerCmsAvisTestCase { + public function setUp() { + parent::setUp(); + + ZendAfi_Auth::getInstance() + ->logUser( + $this->fixture('Class_Users' , + ['id' => 112, + 'login' => 'max', + 'password' => 'maxLaMenace'])); + + $this->fixture('Class_CmsRank', ['id' => 1, + 'abon_nombre_avis' => 1, + 'abon_note' => '4.0', + 'bib_nombre_avis' => 0, + 'bib_note' => '0.0']); $this->fixture('Class_Avis' , ['id' => 7, - 'id_user' => 112, - 'id_cms' => '1', - 'entete' => 'Pas mal !', - 'avis' => 'J\'aime cet article', - 'note' => 4, - 'status' => 1]); + 'id_user' => 112, + 'id_cms' => '1', + 'entete' => 'Pas mal !', + 'avis' => 'J\'aime cet article', + 'note' => 4, + 'status' => 1]); + } +} + + + + +class AbonneControllerCmsAvisEditExistingTest extends AbonneControllerCmsAvisViewArticleWithCommentTestCase { + public function setUp() { + parent::setUp(); + + Class_AdminVar::newInstanceWithId('MODO_AVIS_BIBLIO', ['valeur' => 0]); + Class_AdminVar::newInstanceWithId('MODO_AVIS', ['valeur' => 0]); + $this->dispatch('/abonne/cmsavis/id/1', true); + } + + /** @test */ + public function inputAvisEnteteShouldContainsPasMal() { + $this->assertXPath('//input[@name="avisEntete"][@value="Pas mal !"]'); + } + + + /** @test */ + public function avisContentShouldBeJaimeCetArticle() { + $this->assertXPathContentContains('//textarea[@name="avisTexte"]', + 'J\'aime cet article'); + } + + + /** @test */ + public function avisSignatureShouldBeMax() { + $this->assertXPath('//input[@name="avisSignature"][@value="max"]'); + } + + + /** @test */ + public function selectedNoteShouldBeFour() { + $this->assertXPath('//select[@name="avisNote"]/option[@selected="1"][@value="4"]'); + } +} + + + + +class AbonneControllerCmsAvisViewArticleWithCommentTest extends AbonneControllerCmsAvisViewArticleWithCommentTestCase { + public function setUp() { + parent::setUp(); $this->dispatch('/cms/articleview/id/1', true); } /** @test */ - public function ArticleJeSuisCharlieShouldHaveLinkToAccessBorrowersComments() { - $this->assertXPathContentContains('//a[contains(@onclick, "showAvis(1")]', 'Avis de lecteurs du portail'); + public function articleJeSuisCharlieShouldHaveLinkToAccessBorrowersComments() { + $this->assertXPathContentContains('//a[contains(@onclick, "showAvis(1")]', 'Avis de lecteurs du portail', $this->_response->getBody()); } /** @test */ - public function ArticleJeSuisCharlieShouldHaveOneBorrowersComments() { + public function articleJeSuisCharlieShouldHaveOneBorrowersComments() { $this->assertXPathContentContains('//div[@id="avis_1"]/ul[@class="notice_info"]/li[1]', "(1 évaluation)"); } /** @test */ - public function ArticleJeSuisCharlieShouldHaveFourStarsImage() { + public function articleJeSuisCharlieShouldHaveFourStarsImage() { $this->assertXPath('//div[@id="avis_1"]/ul[@class="notice_info"]/li[1]/img[contains(@src, "stars-4.gif")]'); } } + + +?> \ No newline at end of file