From 17f96f2598771c4586900ce3505a589dfb172dbc Mon Sep 17 00:00:00 2001 From: llaffont <llaffont@git-test.afi-sa.fr> Date: Mon, 4 Mar 2013 16:46:16 +0000 Subject: [PATCH] =?UTF-8?q?Administration=20des=20avis=20cms:=20-=20mise?= =?UTF-8?q?=20sous=20test=20-=20coche=20verte=20pour=20valider,=20croix=20?= =?UTF-8?q?rouge=20pour=20supprimer=20-=20lien=20pour=20envoyer=20mail=20?= =?UTF-8?q?=C3=A0=20l'abonn=C3=A9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../admin/controllers/ModoController.php | 404 +----------------- .../admin/views/scripts/modo/aviscms.phtml | 143 +++---- library/Class/Avis.php | 17 +- library/Class/Moderer.php | 22 +- public/admin/css/global.css | 2 + .../AdminAvisModerationControllerTest.php | 138 +++++- 6 files changed, 213 insertions(+), 513 deletions(-) diff --git a/application/modules/admin/controllers/ModoController.php b/application/modules/admin/controllers/ModoController.php index 4441668339c..8fc5010b593 100644 --- a/application/modules/admin/controllers/ModoController.php +++ b/application/modules/admin/controllers/ModoController.php @@ -62,23 +62,6 @@ class Admin_ModoController extends Zend_Controller_Action { } - public function updateavisnoticeAction() { - $class_modo = new Class_Moderer(); - $avis = $this->_getParam('avis', []); - if (0 == count($avis)) { - $this->_redirect('admin/modo/avisnotice'); - return; - } - - foreach ($avis as $item) { - $elems = explode('_', $item); - $class_modo->modererAvis($elems[0], $elems[1], $elems[2]); - } - - $this->_redirect('admin/modo/avisnotice'); - } - - public function tagnoticeAction() { $view_liste_tags=array(); $class_modo = new Class_Moderer(); @@ -126,27 +109,29 @@ class Admin_ModoController extends Zend_Controller_Action { public function aviscmsAction() { $class_modo = new Class_Moderer(); $this->view->subview = $this->view->partial('modo/aviscms.phtml', - array('liste_avis_abo' => $class_modo->getAllAvisCmsAModerer(0), - 'liste_avis_bib' => $class_modo->getAllAvisCmsAModerer(1))); + ['liste_avis' => $class_modo->getAllAvisCmsAModerer()]); $this->_forward('index'); } - public function updateaviscmsAction() { - $class_modo = new Class_Moderer(); - $items = $this->_getParam('avis', []); - if (0 == count($items)) { - $this->_redirect('admin/modo/aviscms'); - return; - } - - foreach ($items as $item) { - $elems = explode('_', $item); - $class_modo->modererAvisCms($elems[0], $elems[1], $elems[2]); - } - $this->_redirect('admin/modo/aviscms'); + public function deleteAviscmsAction() { + $avis = Class_Avis::find($this->_getParam('id')); + $avis->delete(); + $avis->maj_note_cms($avis->getIdCms(), $avis->getAbonOuBib()); + $this->_helper->notify($this->view->_('Avis %s supprimé', $avis->getEntete())); + $this->_redirect('/admin/modo/aviscms'); + + } + + + public function validateAviscmsAction() { + $avis = Class_Avis::find($this->_getParam('id')); + $avis->beValid()->save(); + $avis->maj_note_cms($avis->getIdCms(), $avis->getAbonOuBib()); + $this->_helper->notify($this->view->_('Avis %s validé', $avis->getEntete())); + $this->_redirect('/admin/modo/aviscms'); } - + public function membreviewAction() { $class_user = new Class_Users(); @@ -219,359 +204,6 @@ class Admin_ModoController extends Zend_Controller_Action { } - /** - * - * "Hell isn't bad place, - * Hell is from here to eternity" - * (Bruce Dickinson) - * - * - * - */ - - public function avisindexAction() { - $moderer = new Class_Moderer(); - - $this->view->title = "Avis"; - - $count = $this->_count; //number of rows to return at a time - $totalUnModRows = $moderer->countBibAbonAvisStatut0(); - if (is_string($totalUnModRows) ){ - $this->_redirect('admin/error/database'); - } - - $page = (int)$this->_request->getParam('page', 1); - if ( (($page -1) * $count) >= $totalUnModRows){ - $page = $page -1; - } - - $checkall = $this->_request->getParam('checkall', 0); - if ($checkall === 'v'){ - $this->view->deletechecked = ""; - $this->view->validatechecked = "checked"; - }elseif($checkall === 'd'){ - $this->view->deletechecked = "checked"; - $this->view->validatechecked = ""; - }else{ - $this->view->deletechecked = ""; - $this->view->validatechecked = ""; - } - - $offset = ($page - 1)*$count; - - if ($offset < 0) { - $offset = 0; - }elseif($offset > $totalUnModRows){ - $offset = $totalUnModRows; - } - - $this->view->moderer = $moderer; - $fetch = $moderer->fetchLimitBibAbonAvisByStatut0($count, $offset); - if ( is_string($fetch) ){ - $this->_redirect('admin/error/database'); - } - - $pages = (int)($totalUnModRows / $count); - $mod = $totalUnModRows % $count; - if ($mod > 0){ - $pages++; - } - - $this->view->dateClass = new Class_Date(); - $this->view->numPage = $page; - $this->view->nb_pages = $pages; - $this->view->url = "/admin/moderer/avisindex?page="; - - $this->view->pages = $pages; - $this->view->bibAvisRows = $fetch; - $this->view->offset = $offset; - $this->view->count = $count; - $this->view->total = $totalUnModRows; - } - - public function modifieravisAction() { - $viewRenderer = $this->getHelper('ViewRenderer'); - $viewRenderer->setLayoutScript('subModal.phtml'); - - $moderer = new Class_Moderer(); - - if ($this->_request->isPost()) { - $filter = new Zend_Filter_StripTags(); - $id_abon = $this->_request->getPost('id_abon'); - $ordre_abon = $this->_request->getPost('ordre_abon'); - $id_notice = $this->_request->getPost('id_notice'); - - $entete = trim($filter->filter($this->_request->getPost('entete'))); - $avis = trim($filter->filter($this->_request->getPost('avis'))); - - $data = array( - 'ENTETE' => $entete, - 'AVIS' => $avis, - ); - - // try to update avis - $errorMessage = $moderer->updateBibAbonAvis($id_abon, $ordre_abon, $id_notice, $data); - if ($errorMessage == ''){ - $viewRenderer = $this->getHelper('ViewRenderer'); - $viewRenderer->setNoRender(); - - $this->getResponse()->setHeader('Content-Type', 'text/html;charset=utf-8'); - $this->getResponse()->setBody("<script>window.top.hidePopWin(false);window.top.location='" . BASE_URL . "/admin/moderer/avisindex';</script>"); - - }else{ - $avis = $moderer->fetchRowBibAbonAvis($id_abon, $ordre_abon, $id_notice); - /* - * if $avis is a string, we have encountered a problem with the database - */ - if ( is_string($avis) ){ - $this->view->avis = new stdClass(); - $this->view->avis->ID_ABON = $id_abon; - $this->view->avis->ORDRE_ABON = $ordre_abon; - $this->view->avis->ID_NOTICE = $id_notice; - $this->view->avis->ENTETE = ''; - $this->view->avis->AVIS = ''; - $this->view->message = $avis; - }elseif($avis == null){ - $viewRenderer = $this->getHelper('ViewRenderer'); - $viewRenderer->setNoRender(); - - $this->getResponse()->setHeader('Content-Type', 'text/html;charset=utf-8'); - $this->getResponse()->setBody("<script>window.top.hidePopWin(false);window.top.location='" . BASE_URL . "/admin/moderer/avisindex';</script>"); - }else{ - $this->view->avis = $avis; - $this->view->message = $errorMessage; - } - } - } else { - $id_abon = $this->_request->getParam('id_abon', 0); - $ordre_abon = $this->_request->getParam('ordre_abon', 0); - $id_notice = $this->_request->getParam('id_notice', 0); - if ( ( $id_abon > 0 ) && ( $id_abon > 0 ) && ( $id_abon > 0 ) ) { - $avis = $moderer->fetchRowBibAbonAvis($id_abon, $ordre_abon, $id_notice); - /* - * if $avis is a string, we have encountered a problem with the database - * if $avis is null, the categorie does not exist in the database - */ - if ( is_string($avis) ){ - $this->view->avis = new stdClass(); - $this->view->avis->ID_ABON = $id_abon; - $this->view->avis->ORDRE_ABON = $ordre_abon; - $this->view->avis->ID_NOTICE = $id_notice; - $this->view->avis->ENTETE = ''; - $this->view->avis->AVIS = ''; - $this->view->message = $avis; - }elseif($avis == null){ - $viewRenderer = $this->getHelper('ViewRenderer'); - $viewRenderer->setNoRender(); - - $this->getResponse()->setHeader('Content-Type', 'text/html;charset=utf-8'); - $this->getResponse()->setBody("<script>window.top.hidePopWin(false);window.top.location='" . BASE_URL . "/admin/moderer/avisindex';</script>"); - } - else{ - $this->view->avis = $avis; - } - }else{ - $viewRenderer = $this->getHelper('ViewRenderer'); - $viewRenderer->setNoRender(); - - $this->getResponse()->setHeader('Content-Type', 'text/html;charset=utf-8'); - $this->getResponse()->setBody("<script>window.top.hidePopWin(false);window.top.location='" . BASE_URL . "/admin/moderer/avisindex';</script>"); - } - } - - } - - - public function cmsavisindexAction() { - $moderer = new Class_Moderer(); - - $this->view->title = "CMS Avis"; - - $count = $this->_count; //number of rows to return at a time - $totalUnModRows = $moderer->countBibCmsAvisStatut0(); - if (is_string($totalUnModRows)){ - $this->_redirect('admin/error/database'); - } - - $page = (int)$this->_request->getParam('page', 1); - if ( (($page -1) * $count) >= $totalUnModRows){ - $page = $page -1; - } - - $checkall = $this->_request->getParam('checkall', 0); - if ($checkall === 'v'){ - $this->view->deletechecked = ""; - $this->view->validatechecked = "checked"; - }elseif($checkall === 'd'){ - $this->view->deletechecked = "checked"; - $this->view->validatechecked = ""; - }else{ - $this->view->deletechecked = ""; - $this->view->validatechecked = ""; - } - - $offset = ($page - 1)*$count; - - if ($offset < 0) { - $offset = 0; - }elseif($offset > $totalUnModRows){ - $offset = $totalUnModRows; - } - - $this->view->moderer = $moderer; - $fetch = $moderer->fetchLimitBibCmsAvisByStatut0($count, $offset); - if ( is_string($fetch) ){ - $this->_redirect('admin/error/database'); - } - - $pages = (int)($totalUnModRows / $count); - $mod = $totalUnModRows % $count; - if ($mod > 0){ - $pages++; - } - - $this->view->dateClass = new Class_Date(); - $this->view->numPage = $page; - $this->view->nb_pages = $pages; - $this->view->url = "/admin/moderer/cmsavisindex?page="; - - $this->view->pages = $pages; - $this->view->bibAvisRows = $fetch; - $this->view->offset = $offset; - $this->view->count = $count; - $this->view->total = $totalUnModRows; - } - - public function modifiercmsavisAction() { - $viewRenderer = $this->getHelper('ViewRenderer'); - $viewRenderer->setLayoutScript('subModal.phtml'); - - $moderer = new Class_Moderer(); - - if ($this->_request->isPost()) { - $filter = new Zend_Filter_StripTags(); - $id_abon = $this->_request->getPost('id_abon'); - $ordre_abon = $this->_request->getPost('ordre_abon'); - $id_cms_article = $this->_request->getPost('id_cms_article'); - - $entete = trim($filter->filter($this->_request->getPost('entete'))); - $avis = trim($filter->filter($this->_request->getPost('avis'))); - - $data = array( - 'ENTETE' => $entete, - 'AVIS' => $avis, - ); - - // try to update avis - $errorMessage = $moderer->updateBibCmsAvis($id_abon, $ordre_abon, $id_cms_article, $data); - if ($errorMessage == ''){ - $viewRenderer = $this->getHelper('ViewRenderer'); - $viewRenderer->setNoRender(); - - $this->getResponse()->setHeader('Content-Type', 'text/html;charset=utf-8'); - $this->getResponse()->setBody("<script>window.top.hidePopWin(false);window.top.location='" . BASE_URL . "/admin/moderer/cmsavisindex';</script>"); - - }else{ - $avis = $moderer->fetchRowBibCmsAvis($id_abon, $ordre_abon, $id_cms_article); - /* - * if $avis is a string, we have encountered a problem with the database - */ - if ( is_string($avis) ){ - $this->view->avis = new stdClass(); - $this->view->avis->ID_ABON = $id_abon; - $this->view->avis->ORDRE_ABON = $ordre_abon; - $this->view->avis->ID_CMS_ARTICLE = $id_cms_article; - $this->view->avis->ENTETE = ''; - $this->view->avis->AVIS = ''; - $this->view->message = $avis; - }elseif($avis == null){ - $viewRenderer = $this->getHelper('ViewRenderer'); - $viewRenderer->setNoRender(); - - $this->getResponse()->setHeader('Content-Type', 'text/html;charset=utf-8'); - $this->getResponse()->setBody("<script>window.top.hidePopWin(false);window.top.location='" . BASE_URL . "/admin/moderer/cmsavisindex';</script>"); - }else{ - $this->view->avis = $avis; - $this->view->message = $errorMessage; - } - } - } else { - $id_abon = $this->_request->getParam('id_abon', 0); - $ordre_abon = $this->_request->getParam('ordre_abon', 0); - $id_cms_article = $this->_request->getParam('id_cms_article', 0); - if ( ( $id_abon > 0 ) && ( $id_abon > 0 ) && ( $id_abon > 0 ) ) { - $avis = $moderer->fetchRowBibCmsAvis($id_abon, $ordre_abon, $id_cms_article); - /* - * if $avis is a string, we have encountered a problem with the database - * if $avis is null, the categorie does not exist in the database - */ - if ( is_string($avis) ){ - $this->view->avis = new stdClass(); - $this->view->avis->ID_ABON = $id_abon; - $this->view->avis->ORDRE_ABON = $ordre_abon; - $this->view->avis->ID_CMS_ARTICLE = $id_cms_article; - $this->view->avis->ENTETE = ''; - $this->view->avis->AVIS = ''; - $this->view->message = $avis; - }elseif($avis == null){ - $viewRenderer = $this->getHelper('ViewRenderer'); - $viewRenderer->setNoRender(); - - $this->getResponse()->setHeader('Content-Type', 'text/html;charset=utf-8'); - $this->getResponse()->setBody("<script>window.top.hidePopWin(false);window.top.location='" . BASE_URL . "/admin/moderer/cmsavisindex';</script>"); - } - else{ - $this->view->avis = $avis; - } - }else{ - - $this->getResponse()->setHeader('Content-Type', 'text/html;charset=utf-8'); - $this->getResponse()->setBody("<script>window.top.hidePopWin(false);window.top.location='" . BASE_URL . "/admin/moderer/cmsavisindex';</script>"); - - } - } - - } - - - public function updatecmsavisAction() { - $id_abonArray = $this->_request->getParam('id_abon', 0); - $ordre_abonArray = $this->_request->getParam('ordre_abon', 0); - $id_cms_articleArray = $this->_request->getParam('id_cms_article', 0); - $validateArray = $this->_request->getParam('validate', 0); - - if (!$validateArray){ - $validateArray = array(); - } - - $avis = new Class_Avis(); - $moderer = new Class_Moderer(); - - foreach($validateArray as $key => $val) - { - $id_abon = $id_abonArray[$key]; - $ordre_abon = $ordre_abonArray[$key]; - $id_cms_article = $id_cms_articleArray[$key]; - - if ($val){ - $error = $moderer->updateBibCmsAvisStatut($id_abon, $ordre_abon, $id_cms_article); - if ($error != ''){ - $this->_redirect('admin/error/database'); - } - }else{ - $error = $moderer->deleteBibCmsAvis($id_abon, $ordre_abon, $id_cms_article); - $avis->maj_note_cms($id_cms_article); - if ($error != ''){ - $this->_redirect('admin/error/database'); - } - } - - } - - $this->_redirect('admin/moderer/cmsavisindex'); - } - - public function tagsindexAction() { $moderer = new Class_Moderer(); diff --git a/application/modules/admin/views/scripts/modo/aviscms.phtml b/application/modules/admin/views/scripts/modo/aviscms.phtml index c0fe2cac69e..0b66f6dabb1 100644 --- a/application/modules/admin/views/scripts/modo/aviscms.phtml +++ b/application/modules/admin/views/scripts/modo/aviscms.phtml @@ -1,101 +1,64 @@ <?php print('<h1>'.$this->traduire('Modération des avis sur les articles').'</h1>'); print('<br>'); -if(!count($this->liste_avis_abo) && !count($this->liste_avis_bib)) -{ - print('<h4>Il n\'y a aucun avis à modérer</h4>'); -} -else -{ +if(!count($this->liste_avis)) { + print('<h4>Il n\'y a aucun avis à modérer</h4>'); +} else { ?> -<form name="form" action="<?php echo BASE_URL ?>/admin/modo/updateaviscms" method="post"> <table cellpadding="5px" cellspacing="0"> - <tr class="soustitre"> - <td style="width:2%;"> </td> - <td style="width:90%;">Avis</td> - <td style="width:8%">Action</td> - </tr> - <tr> + <tr class="soustitre"> + <td style="width:2%;"> </td> + <td style="width:90%;">Avis</td> + <td style="width:8%">Action</td> + </tr> + <tr> <td colspan="3" class="separ"> </td> - </tr> - -<?php -} + </tr> + + <?php -$art_loader = Class_Article::getLoader(); + foreach ($this->liste_avis as $ligne => $avis) { + $news = $avis->getArticle(); + $article = '<b> Article : </b><a href="'.$this->url(['module' => 'admin', + 'controller' => 'cms', + 'action' => 'viewcms', + 'id' => $news->getId()], + null, + true).'" target="_blank">'.$news->getTitre().'</a>'; + + $user = $avis->getUser(); + $class = ($ligne & 1) ? "first" : "second"; + print('<tr class="'.$class.'">'); + print('<td valign="top">'.($ligne + 1).'</td>'); + + // Bloc avis + print('<td valign="top">'); + print("<b>Le : </b>". substr($avis->getDateAvis(),0,10)."<b> Par : </b>".$this->tagAnchor(['controller' => 'users', 'action' => 'edit', 'id' => $user->getId()], $user->getNomAff()).BR); + print($article.'<br><br>'); + print('<b>Note : </b>'.$avis->getNote().'</b>'); + print(' <b>Titre : </b>'.$avis->getEntete().'</b><br>'); + print('<b>Avis : </b>'.$avis->getAvis().'</b>'); + print('</td>'); + + // Action + print('<td valign="top">'); + print($this->tagAnchor(['action' => 'validate-aviscms', + 'id' => $avis->getId()], + $this->boutonIco("type=validate"))); + print($this->tagAnchor(['action' => 'delete-aviscms', + 'id' => $avis->getId()], + $this->boutonIco("type=del"))); + if ($avis->hasUserMail()) + print($this->boutonIco('type=MAIL', + 'mailto='.$avis->getUserMail().'?Subject='.rawurlencode($this->_('Avis:').' '.$avis->getEntete()))); -if(is_array($this->liste_avis_bib)) -{ - foreach ($this->liste_avis_bib as $avis) - { - $news = $art_loader->find($avis["ID_CMS"]); - $article = '<b> Article : </b><a href="'.BASE_URL.'/admin/cms/viewcms?id='.$news->ID_ARTICLE.'" target="_blank">'.$news->TITRE.'</a>'; - - $class_user = new Class_Users(); $user = $class_user->getUser($avis["ID_USER"]); - if(trim($user["PSEUDO"]) == "") {$pseudo = $user["LOGIN"];} else {$pseudo = $user["PSEUDO"];} - $ligne ++ ; if ($ligne & 1) $class="first"; else $class="second"; - print('<tr class="'.$class.'">'); - print('<td valign="top">'.$ligne.'</td>'); - - // Bloc avis - print('<td valign="top">'); - print("<b>Le : </b>". substr($avis["DATE_AVIS"],0,10)."<b> Par : </b>".$pseudo.BR); - print($article.'<br><br>'); - print('<b>Note : </b>'.$avis["NOTE"].'</b>'); - print(' <b>Titre : </b>'.$avis["ENTETE"].'</b><br>'); - print('<b>Avis : </b>'.$avis["AVIS"].'</b>'); - print('</td>'); - - // Action - $value=$avis["ID_USER"]."_".$avis["ID_CMS"]; - print('<td valign="top"><select name="avis['.$ligne.']">'); - print('<option value="1_'.$value.'">Valider</option>'); - print('<option value="2_'.$value.'">Supprimer</option>'); - print('<option value="0_'.$value.'" selected>Ne rien faire</option>'); - print('</select>'); - print('</td>'); - print('</tr>'); - } -} + print('</td>'); + print('</tr>'); + } -if(is_array($this->liste_avis_abo)) -{ - foreach ($this->liste_avis_abo as $avis) - { - $news = $art_loader->find($avis["ID_CMS"]); - $article = '<b> Article : </b><a href="'.BASE_URL.'/admin/cms/viewcms?id='.$news->ID_ARTICLE.'" target="_blank">'.$news->TITRE.'</a>'; - - $class_user = new Class_Users(); $user = $class_user->getUser($avis["ID_USER"]); - if(trim($user["PSEUDO"]) == "") {$pseudo = $user["LOGIN"];} else {$pseudo = $user["PSEUDO"];} - $ligne ++ ; if ($ligne & 1) $class="first"; else $class="second"; - print('<tr class="'.$class.'">'); - print('<td valign="top">'.$ligne.'</td>'); - - // Bloc avis - print('<td valign="top">'); - print("<b>Le : </b>". substr($avis["DATE_AVIS"],0,10)."<b> Par : </b>".$pseudo.BR); - print($article.'<br><br>'); - print('<b>Note : </b>'.$avis["NOTE"].'</b>'); - print(' <b>Titre : </b>'.$avis["ENTETE"].'</b><br>'); - print('<b>Avis : </b>'.$avis["AVIS"].'</b>'); - print('</td>'); - - // Action - $value=$avis["ID_USER"]."_".$avis["ID_CMS"]; - print('<td valign="top"><select name="avis['.$ligne.']">'); - print('<option value="1_'.$value.'">Valider</option>'); - print('<option value="2_'.$value.'">Supprimer</option>'); - print('<option value="0_'.$value.'" selected>Ne rien faire</option>'); - print('</select>'); - print('</td>'); - print('</tr>'); - } -} print('</table>'); -if (count($this->liste_avis_bib) > 0 || count($this->liste_avis_abo) > 0) print('<br><center><div>' . $this->bouton('type=V') . '</div>'); -print('</form>'); - +} ?> -<br> -<?php echo $this->message; ?> -<div id="ajax"></div> \ No newline at end of file + <?php echo $this->message; ?> + + <div id="ajax"></div> \ No newline at end of file diff --git a/library/Class/Avis.php b/library/Class/Avis.php index b4f53aad981..a956a44569b 100644 --- a/library/Class/Avis.php +++ b/library/Class/Avis.php @@ -31,7 +31,10 @@ class Class_Avis extends Storm_Model_Abstract { 'referenced_in' => 'id_user'), 'article' => array('model' => 'Class_Article', - 'referenced_in' => 'id_cms')); + 'referenced_in' => 'id_cms'), + + 'user' => array('model' => 'Class_Users', + 'referenced_in' => 'id_user')); var $sql; // Curseur sql var $_today; @@ -57,6 +60,11 @@ class Class_Avis extends Storm_Model_Abstract { return $auteur->getNomAff(); } + + public function beValid() { + return $this->setStatut(1); + } + //------------------------------------------------------------------------------------------------------ // html Avis pour le CMS pour les boites //------------------------------------------------------------------------------------------------------ @@ -182,4 +190,11 @@ class Class_Avis extends Storm_Model_Abstract { return $this->setAbonOuBib(self::AVIS_BIBLIO); } + + public function getUserMail() { + if (!$this->hasUser()) + return ''; + return $this->getUser()->getMail(); + } + } \ No newline at end of file diff --git a/library/Class/Moderer.php b/library/Class/Moderer.php index f3cab8c77d3..04719f9aa74 100644 --- a/library/Class/Moderer.php +++ b/library/Class/Moderer.php @@ -29,10 +29,9 @@ class Class_Moderer { } - public function getAllAvisCmsAModerer($abon_ou_bib = 0) { - $sqlStmt = sprintf("Select * from cms_avis Where STATUT=0 AND ABON_OU_BIB=%d order by DATE_AVIS DESC", - $abon_ou_bib); - return $this->sql->fetchAll($sqlStmt); + public function getAllAvisCmsAModerer() { + return Class_Avis::findAllBy(['statut' => 0, + 'order' => 'date_avis desc']); } @@ -43,21 +42,6 @@ class Class_Moderer { } - public function modererAvisCms($action, $id_user, $id_news) { - if ('1' == $action) - sqlExecute('update cms_avis set STATUT=1 where ID_USER=' . $id_user .' and ID_CMS=' . $id_news); - elseif ('2' == $action) - sqlExecute('delete from cms_avis where ID_USER=' . $id_user . ' and ID_CMS=' . $id_news); - - $avis = $this->sql->fetchAll('select * from cms_avis where ID_USER=' . $id_user . ' and ID_CMS='. $id_news); - if (1 == $avis[0]['STATUT']) { - $role_level = fetchOne('select ROLE_LEVEL from bib_admin_users where ID_USER=' . $id_user); - $class_avis = new Class_Avis(); - $class_avis->maj_note_cms($id_news, (($role_level < 3) ? 0 : 1)); - } - } - - public function getAllTagsAModerer() { $liste = fetchAll("select * from codif_tags where a_moderer > ''"); if (empty($liste)) diff --git a/public/admin/css/global.css b/public/admin/css/global.css index 1c16585b514..d06a3f69097 100644 --- a/public/admin/css/global.css +++ b/public/admin/css/global.css @@ -294,6 +294,8 @@ div#permalink { .modules .soustitre{font-size:10pt;font-weight:bold;color:#FF6600} .modules .first{font-size:10pt;height:20px} .modules .second{font-size:10pt;height:20px} +.modo_index .modules .first{height:auto} +.modo_index .modules .second{height:auto} .modules .survol:hover{background-color:#78AEFF;font-size:10pt;} .modules .separ{max-height:1px;height:1px;padding:0px;background-color:#A0A0A0;} .modules a {font-size:8pt;color:#0058A5;text-decoration:none;} diff --git a/tests/application/modules/admin/controllers/AdminAvisModerationControllerTest.php b/tests/application/modules/admin/controllers/AdminAvisModerationControllerTest.php index 8baec1bbb21..fa6ea2e3625 100644 --- a/tests/application/modules/admin/controllers/AdminAvisModerationControllerTest.php +++ b/tests/application/modules/admin/controllers/AdminAvisModerationControllerTest.php @@ -195,26 +195,14 @@ class AdminAvisModerationControllerAvisValidateTest extends AdminAvisModerationC -class AdminAvisModerationControllerCmsTest extends Admin_AbstractControllerTestCase { + +class AdminAvisModerationControllerCmsWithNoAvisTest extends Admin_AbstractControllerTestCase { public function setUp() { parent::setUp(); - $this->mock_sql = $this->getMockBuilder('Class_Systeme_Sql') - ->disableOriginalConstructor() - ->getMock(); - Zend_Registry::set('sql', $this->mock_sql); - - $this->mock_sql - ->expects($this->at(0)) - ->method('fetchAll') - ->with("Select * from cms_avis Where STATUT=0 AND ABON_OU_BIB=0 order by DATE_AVIS DESC") - ->will($this->returnValue(array())); - - $this->mock_sql - ->expects($this->at(1)) - ->method('fetchAll') - ->with("Select * from cms_avis Where STATUT=0 AND ABON_OU_BIB=1 order by DATE_AVIS DESC") - ->will($this->returnValue(array())); + Storm_Test_ObjectWrapper::onLoaderOfModel('Class_Avis') + ->whenCalled('findAllBy') + ->answers([]); $this->dispatch('/admin/modo/aviscms'); } @@ -227,4 +215,120 @@ class AdminAvisModerationControllerCmsTest extends Admin_AbstractControllerTestC + +abstract class AdminAvisModerationControllerCmsWithAvisTestCase extends Admin_AbstractControllerTestCase { + public function setUp() { + parent::setUp(); + + $avis = Class_Avis::newInstanceWithId(12, ['date_avis' => '2012-12-03', + 'note' => 4, + 'entete' => 'Mon avis', + 'avis' => 'Cet article est inspirant', + 'abon_ou_bib' => 0]) + ->setArticle(Class_Article::newInstanceWithId(9, ['titre' => 'Tintin à Annecy'])) + ->setUser(Class_Users::newInstanceWithId(34, ['pseudo' => 'Pat', + 'mail' => 'pat@afi.fr'])); + + Storm_Test_ObjectWrapper::onLoaderOfModel('Class_Avis') + ->whenCalled('findAllBy') + ->with(['statut' => 0, + 'order' => 'date_avis desc']) + ->answers([$avis]); + } +} + + + + + +class AdminAvisModerationControllerCmsWithAvisTest extends AdminAvisModerationControllerCmsWithAvisTestCase { + public function setUp() { + parent::setUp(); + $this->dispatch('/admin/modo/aviscms', true); + } + + + /** @test */ + public function pageShouldContainsLinkToArticle() { + $this->assertXPathContentContains('//a[contains(@href, "/admin/cms/viewcms/id/9")]', + "Tintin à Annecy", + $this->_response->getBody()); + } + + + /** @test */ + public function pageShouldContainsActionToValidateAvis() { + $this->assertXPath('//a[contains(@href, "/admin/modo/validate-aviscms/id/12")]'); + } + + + /** @test */ + public function pageShouldContainsActionToDeleteAvis() { + $this->assertXPath('//a[contains(@href, "/admin/modo/delete-aviscms/id/12")]'); + } + + + /** @test */ + public function pageShouldContainsActionToSendMail() { + $this->assertXPath('//a[contains(@href, "mailto:pat")]'); + } + + + /** @test */ + public function pageShouldContainsLinkToEditUser() { + $this->assertXPath('//a[contains(@href, "/admin/users/edit/id/34")]'); + } +} + + + + +class AdminAvisModerationControllerCmsDeleteAvisTest extends AdminAvisModerationControllerCmsWithAvisTestCase { + public function setUp() { + parent::setUp(); + Class_Avis::whenCalled('delete')->answers(true); + $this->dispatch('/admin/modo/delete-aviscms/id/12', true); + } + + /** @test */ + public function pageShouldRedirectToAvisCms() { + $this->assertRedirectTo('/admin/modo/aviscms'); + } + + + /** @test */ + public function avisShouldHaveBeenDeleted() { + $this->assertTrue(Class_Avis::methodHasBeenCalled('delete')); + } +} + + + +class AdminAvisModerationControllerCmsValidateAvisTest extends AdminAvisModerationControllerCmsWithAvisTestCase { + public function setUp() { + parent::setUp(); + Class_Avis::whenCalled('save')->answers(true); + $this->dispatch('/admin/modo/validate-aviscms/id/12', true); + } + + + /** @test */ + public function pageShouldRedirectToAvisCms() { + $this->assertRedirectTo('/admin/modo/aviscms'); + } + + + /** @test */ + public function avisShouldHaveBeenSaved() { + $this->assertTrue(Class_Avis::methodHasBeenCalled('save')); + } + + + /** @test */ + public function avisShouldBeValid() { + $this->assertEquals(1, Class_Avis::find(12)->getStatut()); + } +} + + ?> \ No newline at end of file -- GitLab