From f48fb01d5f87870128f2779625f8867e2e84b95d Mon Sep 17 00:00:00 2001 From: efalcy <efalcy@afi-sa.fr> Date: Fri, 3 Jul 2015 17:53:57 +0200 Subject: [PATCH] premier chapitre : use adminVar to configure premier chapitre (remove configureAction), put html on phtml files , fix wrong urls --- .../controllers/PremierChapitreController.php | 196 ++---------------- .../admin/views/scripts/index/adminvar.phtml | 2 +- .../premier-chapitre/download-ref.phtml | 21 ++ .../scripts/premier-chapitre/index.phtml | 34 ++- .../premier-chapitre/link-notices.phtml | 23 ++ .../scripts/premier-chapitre/maj-ref.phtml | 28 +++ cosmogramme/php/_init.php | 2 +- cosmogramme/sql/patch/patch_261.php | 13 ++ library/Class/PremierChapitre.php | 20 +- library/Class/WebService/PremierChapitre.php | 21 +- 10 files changed, 159 insertions(+), 201 deletions(-) create mode 100644 application/modules/admin/views/scripts/premier-chapitre/download-ref.phtml create mode 100644 application/modules/admin/views/scripts/premier-chapitre/link-notices.phtml create mode 100644 application/modules/admin/views/scripts/premier-chapitre/maj-ref.phtml create mode 100644 cosmogramme/sql/patch/patch_261.php diff --git a/application/modules/admin/controllers/PremierChapitreController.php b/application/modules/admin/controllers/PremierChapitreController.php index b8e835a8c65..b1eb36da781 100644 --- a/application/modules/admin/controllers/PremierChapitreController.php +++ b/application/modules/admin/controllers/PremierChapitreController.php @@ -18,7 +18,7 @@ * along with BOKEH; if not, write to the Free Software * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ -class Admin_PremierChapitreController extends ZendAfi_Controller_Action { +class Admin_PremierChapitreController extends Zend_Controller_Action { use Trait_Translator; protected $_baseUrlOptions = ['module' => 'admin', 'controller' => 'premier-chapitre']; @@ -27,25 +27,6 @@ class Admin_PremierChapitreController extends ZendAfi_Controller_Action { private $pc_bmid; private $pc_bmkey; - private function objectsIntoArray($arrObjData, $arrSkipIndices = array()) { - $arrData = array(); - // if input is object, convert into array - if (is_object($arrObjData)) { - $arrObjData = get_object_vars($arrObjData); - } - if (is_array($arrObjData)) { - foreach ($arrObjData as $index => $value) { - if (is_object($value) || is_array($value)) { - $value = self::objectsIntoArray($value, $arrSkipIndices); // recursive call - } - if (in_array($index, $arrSkipIndices)) { - continue; - } - $arrData[$index] = $value; - } - } - return $arrData; - } public function init() { parent::init(); @@ -58,48 +39,25 @@ class Admin_PremierChapitreController extends ZendAfi_Controller_Action { public function preDispatch() { $no_front_actions = array(); - $request = $this->_request; - $action = $request->getActionName(); - if (!$this->active && $action != 'configure' && $action != 'adminvaredit') { - $request->setActionName('configure'); - $request->setDispatched(false); + + // Desactiver le view renderer normal + if (in_array($this->_request->getParam("action"),$no_front_actions)) { + $viewRenderer = $this->getHelper('ViewRenderer'); + $viewRenderer->setNoRender(); } - else - // Desactiver le view renderer normal - if (in_array($this->_request->getParam("action"),$no_front_actions)) { - $viewRenderer = $this->getHelper('ViewRenderer'); - $viewRenderer->setNoRender(); - } } - + public function indexAction() { - $contenu .= '<ul>'; - $contenu .= '<li><a href="/admin/premier-chapitre/configure/">Configuration</a></li>'; - //tant que le service n'est pas configuré on n'autorise pas les actions de mise en œuvre - if ($this->active) { - $contenu .= '<li><a href="/admin/premier-chapitre/maj-ref/">Mise à jour du référentiel</a></li>'; - $contenu .= '<li><a href="/admin/premier-chapitre/download-ref/">Téléchargement du référentiel</a></li>'; - $contenu .= '<li><a href="/admin/premier-chapitre/maj-db/">Mise à jour de la base</a></li>'; - $contenu .= '<li><a href="/admin/premier-chapitre/link-notices/">Lier les notices</a></li>'; - } - $contenu .= '</ul>'; $this->view->titre .= ' :: Index des fonctions'; - $this->view->contenu = $contenu; + } function majRefAction() { $data = false; $pc_ws = new Class_WebService_PremierChapitre(); - $data = $pc_ws->generate(); - if ($data) { - $contenu = date('H:i:s')." Le référentiel a bien été mise à jour\n"; - $contenu .= '<a href="/admin/premier-chapitre/download-ref/">Téléchargement du référentiel</a>'; - } - else $contenu = "Une erreur est survenue\nle référentiel n'a pas pu être mis a jour\nVeuillez réessayer ultérieurement"; - $this->view->contenu = '<pre>'.$contenu.'</pre>'; - $this->view->contenu .= "<br/><a href='/admin/premier-chapitre/'>Retour à l'index du service Premier-chapitre</a>"; + $this->view->data = $pc_ws->generate(); $this->view->titre .= ' :: Mise à jour du référentiel'; - $this->renderScript('premier-chapitre/index.phtml'); + } function downloadRefAction() { $data = false; @@ -113,7 +71,7 @@ class Admin_PremierChapitreController extends ZendAfi_Controller_Action { $this->view->contenu = '<pre>'.$contenu.'</pre>'; $this->view->contenu .= "<br/><a href='/admin/premier-chapitre/'>Retour à l'index du service Premier-chapitre</a>"; $this->view->titre .= ' :: Téléchargement du référentiel'; - $this->renderScript('premier-chapitre/index.phtml'); + } function majDbAction() { @@ -148,134 +106,18 @@ class Admin_PremierChapitreController extends ZendAfi_Controller_Action { $this->view->contenu = '<pre>'.$contenu.'</pre>'; $this->view->contenu .= "<br/><a href='/admin/premier-chapitre/'>Retour à l'index du service Premier-chapitre</a>"; $this->view->titre .= ' :: Liaison aux notices'; - $this->renderScript('premier-chapitre/index.phtml'); - } - - public function configureAction() { - $this->view->titre .= ' :: Configuration du service'; - Class_ScriptLoader::getInstance() - ->loadDataTables() - ->addJQueryReady("$('#adminvars').dataTable({ 'iDisplayLength': -1, 'bPaginate': false, 'columnDefs' : [{'orderable': false, 'targets': 2}] })") - ->loadJQueryUI() - ->addJQueryReady('$(document).tooltip({ - items: "[data-tooltip]", - content: function() { - var element = $(this); - var html = element.find("span").html(); - return (html.trim() != "") ? html : "Description non disponible"; - }, - position: { my: "left top+30", at: "left top"}, - hide: {duration: 1000} - })'); - - $var_connues = array('PREMIERCHAPITRE_BIB_ID', 'PREMIERCHAPITRE_BMID', 'PREMIERCHAPITRE_BMKEY'); - $existing_variables = Class_AdminVar::findAllBy(['where'=> "CLEF like 'PREMIERCHAPITRE%'",'order' => 'CLEF']); - $existing_clefs = []; - foreach ($existing_variables as $var) - $existing_clefs[] = $var->getId(); - - // creer les variables manquantes - foreach ($var_connues as $name) - if (!in_array($name, $existing_clefs)) - $existing_variables[] = Class_AdminVar::set($name, ''); - $table = '<table id="adminvars"> - <thead> - <tr class="soustitre"> - <th>'.$this->traduire('Clef').'</th> - <th>'.$this->traduire('Valeur').'</th> - <th>'.$this->traduire('action').'</th> - </tr> - </thead> - <tbody>'; - $ligne = 0; - foreach($existing_variables as $var) { - if(preg_match('^%0D%0A^',$var->getValeur())) - $value = urldecode(str_replace('%0D%0A','<br />',$var->getValeur())); - else - $value = urldecode($var->getValeur()); - $ligne ++ ; - $table .= '<tr class="'.(($ligne & 1) ? "first" : "second").'" data-tooltip=""> - <td style="vertical-align:top;" >'.$var->getClef().' - <span style="display:none;"> - '.Class_AdminVar::helpFor($var->getClef()).' - </span> - </td> - <td>'; - $table .= wordwrap($value, 35, "<br />", 1); - $table .=' </td> - <td style="width:2%;text-align:center"> - <a data-popup="true" href="'.$this->view->url(['action' => 'adminvaredit', 'cle' => $var->getClef()]).'">'.$this->view->boutonIco("type=edit").'</a> - </td> - </tr>'; - } - $table .= '</tbody></table>'; - $this->view->contenu = $table; - $this->view->contenu .= "<br/><a href='/admin/premier-chapitre/'>Retour à l'index du service Premier-chapitre</a>"; - $this->renderScript('premier-chapitre/index.phtml'); } - public function adminvareditAction() { - $id = $this->_getParam('cle'); - $cle = Class_AdminVar::find($id); - - if ($this->_request->isPost()) { - $filter = new Zend_Filter_StripTags(); - $new_valeur = $this->_request->getPost('valeur'); - $cle->setValeur(trim($filter->filter($new_valeur))); - $cle->save(); - $this->_helper->notify('Variable '.$id.' sauvegardée'); - $this->_redirect('admin/premier-chapitre/adminvaredit/cle/'.$id); - return; - } - $var_valeur = $cle->getValeur(); - - $var_cle = $cle->getId(); - $tuto = Class_AdminVar::helpFor($cle->getId()); - $contenu = '<center> -<div class="form" align="center"> -<form name="form" action="'.BASE_URL.'/admin/premier-chapitre/adminvaredit" method="post"> -<fieldset> -<legend>'.$this->view->traduire('Variable').'</legend> -<br /> -<div class="formTable"> -<table cellspacing="2"> - <tr> - <td class="droite">'.$var_cle.'</td> - <td class="gauche">'.$tuto.'</td> - </tr> - <tr> - <td class="droite">Nouvelle valeur</td> - <td class="gauche"><textarea rows="10" cols="60" name="valeur">'.$var_valeur.'</textarea></td> - </tr> -</table><br /> -</div> -<input type="hidden" name="cle" value="'.$var_cle.'"/> -</fieldset><br> - -<table> -<tr> - <td align="right" style="padding-right:5px;">'.$this->view->bouton('type=V').' </td> - <td align="left" style="padding-left:5px;"> '.$this->view->bouton('id=29','picto=back.gif','texte=Retour','url='.BASE_URL.'/admin/premier-chapitre/configure','largeur=120px').'</td> -</tr> -</table> -</form> -</div> -</center>'; - $this->view->titre .= ' :: Modifier la variable: ' . $cle->getId(); - $this->view->contenu = $contenu; - $this->renderScript('premier-chapitre/index.phtml'); - } - - public function __call($method, $args) { - if ('Action' == substr($method, -6)) { - // Si une méthode d'action n'est pas trouvée, - // rediriger vers l'action - return $this->_forward('index'); - } + public function __call($method, $args) { + if ('Action' == substr($method, -6)) { + // Si une méthode d'action n'est pas trouvée, + // rediriger vers l'action + return $this->_forward('index'); + } // pour tout autre méthode, levée d'une exception - throw new Exception('Méthode invalide "' . $method . '" appelée',500); - } + throw new Exception('Méthode invalide "' . $method . '" appelée',500); + } } ?> diff --git a/application/modules/admin/views/scripts/index/adminvar.phtml b/application/modules/admin/views/scripts/index/adminvar.phtml index f3c1403ba3c..f902a7f982c 100644 --- a/application/modules/admin/views/scripts/index/adminvar.phtml +++ b/application/modules/admin/views/scripts/index/adminvar.phtml @@ -36,7 +36,7 @@ hide: {duration: 1000} $ligne ++ ; ?> <tr class="<?php echo ($ligne & 1) ? "first" : "second";?>" data-tooltip=""> - <td style="vertical-align:top;" ><?php echo $var->getId();?> + <td style="vertical-align:top;" ><?php echo $var->getClef();?> <span style="display:none;"> <?php echo $var->getDescription();?> </span> diff --git a/application/modules/admin/views/scripts/premier-chapitre/download-ref.phtml b/application/modules/admin/views/scripts/premier-chapitre/download-ref.phtml new file mode 100644 index 00000000000..d02ffae608f --- /dev/null +++ b/application/modules/admin/views/scripts/premier-chapitre/download-ref.phtml @@ -0,0 +1,21 @@ +<div class="titre"> + <div class="titreInner"> + <h1><?php echo $this->escape($this->title);?></h1> + <div class="rss"></div> + </div> +</div> +<div class="contenu"> + <div class="contenuInner"> + <div class="news-3 news"> +<ul> + <?php + + + echo $this->contenu; + + +?> +</ul> + </div> + </div> +</div> diff --git a/application/modules/admin/views/scripts/premier-chapitre/index.phtml b/application/modules/admin/views/scripts/premier-chapitre/index.phtml index 984b2f459d8..ee73f869441 100644 --- a/application/modules/admin/views/scripts/premier-chapitre/index.phtml +++ b/application/modules/admin/views/scripts/premier-chapitre/index.phtml @@ -7,7 +7,37 @@ <div class="contenu"> <div class="contenuInner"> <div class="news-3 news"> -<?php echo $this->contenu;?> +<ul> + <?php + + + echo '<li>'.$this->tagAnchor($this->url([ + 'module' => 'admin', + 'controller' => 'premier-chapitre', + 'action' => 'maj-ref'],null,true), 'Mise à jour du référentiel').'</li>'; + + + + echo '<li>'.$this->tagAnchor($this->url([ + 'module' => 'admin', + 'controller' => 'premier-chapitre', + 'action' => 'download-ref'],null,true), 'Téléchargement du référentiel').'</li>'; + + + echo '<li>'.$this->tagAnchor($this->url([ + 'module' => 'admin', + 'controller' => 'premier-chapitre', + 'action' => 'maj-db'],null ,true), 'Mise à jour de la base').'</li>'; + + echo '<li>'.$this->tagAnchor($this->url([ + 'module' => 'admin', + 'controller' => 'premier-chapitre', + 'action' => 'link-notices'],null,true), 'Lier les notices').'</li>'; + + + +?> +</ul> </div> </div> -</div> \ No newline at end of file +</div> diff --git a/application/modules/admin/views/scripts/premier-chapitre/link-notices.phtml b/application/modules/admin/views/scripts/premier-chapitre/link-notices.phtml new file mode 100644 index 00000000000..46aa9e51e2b --- /dev/null +++ b/application/modules/admin/views/scripts/premier-chapitre/link-notices.phtml @@ -0,0 +1,23 @@ +<div class="titre"> + <div class="titreInner"> + <h1><?php echo $this->escape($this->title);?></h1> + <div class="rss"></div> + </div> +</div> +<div class="contenu"> + <div class="contenuInner"> + <div class="news-3 news"> +<pre> + <?php + + + +echo $this->contenu; + + + +?></pre> + + </div> + </div> +</div> diff --git a/application/modules/admin/views/scripts/premier-chapitre/maj-ref.phtml b/application/modules/admin/views/scripts/premier-chapitre/maj-ref.phtml new file mode 100644 index 00000000000..de238293de9 --- /dev/null +++ b/application/modules/admin/views/scripts/premier-chapitre/maj-ref.phtml @@ -0,0 +1,28 @@ +<div class="titre"> + <div class="titreInner"> + <h1><?php echo $this->escape($this->title);?></h1> + <div class="rss"></div> + </div> +</div> +<div class="contenu"> + <div class="contenuInner"> + <div class="news-3 news"> +<pre> + <?php + + + + if ($this->data) { + echo date('H:i:s')." Le référentiel a bien été mise à jour\n"; + echo $this->tagAnchor(['controller' => 'premier-chapitre', + 'action' => 'download-ref' ],"Téléchargement du référentiel"); + } + else echo "Une erreur est survenue\nle référentiel n'a pas pu être mis a jour\nVeuillez réessayer ultérieurement"; + + + +?></pre> + + </div> + </div> +</div> diff --git a/cosmogramme/php/_init.php b/cosmogramme/php/_init.php index d6376314714..e6e704e0fee 100644 --- a/cosmogramme/php/_init.php +++ b/cosmogramme/php/_init.php @@ -1,7 +1,7 @@ <?php error_reporting(E_ERROR | E_PARSE); -define("PATCH_LEVEL","259"); +define("PATCH_LEVEL","261"); define("APPLI","cosmogramme"); define("COSMOPATH", "/var/www/html/vhosts/opac2/www/htdocs"); diff --git a/cosmogramme/sql/patch/patch_261.php b/cosmogramme/sql/patch/patch_261.php new file mode 100644 index 00000000000..8f3c084dc6e --- /dev/null +++ b/cosmogramme/sql/patch/patch_261.php @@ -0,0 +1,13 @@ +<?php +$adapter = Zend_Registry::get('sql'); +$adapter->query('CREATE TABLE IF NOT EXISTS `premier_chapitre` ( ' + .'`ean` varchar(17) NOT NULL, ' + .'`url` varchar(250) NOT NULL, ' + .'`titre` text NOT NULL, ' + .'`auteur` text NOT NULL, ' + .'`couverture` varchar(250) NOT NULL, ' + .'`couverture_mini` varchar(250) NOT NULL, ' + .'`clef_oeuvre` varchar(200) NOT NULL ' + .') engine=MyISAM default charset=utf8;'); +$adapter->query('ALTER TABLE `premier_chapitre` ADD PRIMARY KEY (`ean`), ADD UNIQUE KEY `ean` (`ean`);'); +?> \ No newline at end of file diff --git a/library/Class/PremierChapitre.php b/library/Class/PremierChapitre.php index b4b73109d51..c171c596d0f 100644 --- a/library/Class/PremierChapitre.php +++ b/library/Class/PremierChapitre.php @@ -28,7 +28,7 @@ class PremierChapitreLoader extends Storm_Model_Loader { if (!empty($ean['isbn13'])) return str_replace('-','',$ean['isbn13']); return false; } - + public function getPremierChapitreIdsByRequete($req) { if (!$req) return []; @@ -53,25 +53,25 @@ class PremierChapitreLoader extends Storm_Model_Loader { return []; return $this->findAllBy(['ean' => $ids, 'order' => 'titre ASC']); } - + public function getAll($nb_par_page, $page_no=1) { - $req = "select t.`ean` from pc_database t left join notices n on replace(n.`isbn`,'-','') = t.`ean` or n.`clef_oeuvre` = t.`clef_oeuvre` where n.`id_notice` is not null"; + $req = "select t.`ean` from premier_chapitre t left join notices n on replace(n.`isbn`,'-','') = t.`ean` or n.`clef_oeuvre` = t.`clef_oeuvre` where n.`id_notice` is not null"; if ($nb_par_page) return $this->findAllByRequete($req,$nb_par_page,$page_no); else return $this->findAllByRequete($req); } - + public function getAleatoire($nb_aff) { if (!$nb_aff) $nb_aff = 8; - $req = "select t.`ean` from pc_database t\n"; + $req = "select t.`ean` from premier_chapitre t\n"; $req .="left join notices n on replace(n.`isbn`,'-','') = t.`ean`\n"; $req .= "where n.`id_notice` is not null ORDER BY RAND() LIMIT 0,".$nb_aff; return $this->findAllByRequete($req); } - + public function getByClef($clef) { return $this->findFirstBy(['clef_oeuvre' => $clef]); } - + public function getByNotice($ntc) { $pc = $this->getByClef($ntc->getClefOeuvre()); if (!$pc) { @@ -87,9 +87,9 @@ class PremierChapitreLoader extends Storm_Model_Loader { class Class_PremierChapitre extends Storm_Model_Abstract { protected $_loader_class = 'PremierChapitreLoader'; - protected $_table_name = 'pc_database'; + protected $_table_name = 'premier_chapitre'; protected $_table_primary = 'ean'; - + protected $_default_attribute_values = [ 'ean' => '', 'url' => '', @@ -99,7 +99,7 @@ class Class_PremierChapitre extends Storm_Model_Abstract { 'couverture_mini' => '', 'clef_oeuvre' => '']; protected $_belongs_to = ['notice' => ['model' => 'Class_Notice', 'referenced_in' => 'clef_oeuvre']]; - + public function getMiniature() { return $this->getCouvertureMini(); } diff --git a/library/Class/WebService/PremierChapitre.php b/library/Class/WebService/PremierChapitre.php index 963b8d0f8f2..2e13a733ec8 100644 --- a/library/Class/WebService/PremierChapitre.php +++ b/library/Class/WebService/PremierChapitre.php @@ -18,8 +18,8 @@ * along with BOKEH; if not, write to the Free Software * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ - -class Class_WebService_PremierChapitre {// extends Class_WebService_Abstract { - on redefini l'ensemble du modele a l'identique + +class Class_WebService_PremierChapitre {// extends Class_WebService_Abstract { - on redefini l'ensemble du modele a l'identique protected $_message; protected static $_http_client; protected static $_auth = false; @@ -29,7 +29,7 @@ class Class_WebService_PremierChapitre {// extends Class_WebService_Abstract { - private $pc_bib_id; private $pc_bmid; private $pc_bmkey; - + public function __construct() { $this->pc_bib_id = Class_AdminVar::get('PREMIERCHAPITRE_BIB_ID'); $this->pc_bmid = Class_AdminVar::get('PREMIERCHAPITRE_BMID'); @@ -71,7 +71,7 @@ class Class_WebService_PremierChapitre {// extends Class_WebService_Abstract { - } return static::$_auth; } - + public function generate() { if (!$this->authentify()) { throw new Exception("PremierChapitre : Erreur d'identification au service",500); @@ -98,6 +98,7 @@ class Class_WebService_PremierChapitre {// extends Class_WebService_Abstract { - throw new Exception("PremierChapitre : Erreur d'identification au service",500); return false; } + xdebug_break(); $download_url = static::$_baseurl.'plugin/php_download/download.php?f=liste_livre.xml&r='.$this->pc_bib_id; $data = $this->httpGet($download_url); $ret = file_put_contents(static::$_datafile,$data->getBody()); @@ -107,7 +108,7 @@ class Class_WebService_PremierChapitre {// extends Class_WebService_Abstract { - } return true; } - + public function updateDatabase() { if (!file_exists(static::$_datafile)) { $this->getDatafile(); @@ -132,7 +133,7 @@ class Class_WebService_PremierChapitre {// extends Class_WebService_Abstract { - //on procède à la moisson : mise a jour des données existantes et ajout des nouveaux enregistrements $cpt = ['maj' => 0, 'new' => 0, 'err' =>0, 'total' => count($datas['livre'])]; foreach ($datas['livre'] as $key => $item) { - //on nettoie l'ean/isbn + //on nettoie l'ean/isbn $id = Class_PremierChapitre::correct_ean($item['ean']); if ($id) { $item['ean'] = $id; @@ -174,9 +175,9 @@ class Class_WebService_PremierChapitre {// extends Class_WebService_Abstract { - } return $cpt; } - + public function linkToNotices() { - $data = fetchAll("select t.`ean`, n.`clef_oeuvre` from pc_database t left join notices n on replace(n.`isbn`,'-','') = t.`ean` where n.`clef_oeuvre` is not null"); + $data = fetchAll("select t.`ean`, n.`clef_oeuvre` from premier_chapitre t left join notices n on replace(n.`isbn`,'-','') = t.`ean` where n.`clef_oeuvre` is not null"); if (!$data) return false; $pc_all = Class_PremierChapitre::findAll(); $pc_db = array(); @@ -219,7 +220,7 @@ class Class_WebService_PremierChapitre {// extends Class_WebService_Abstract { - $client->setParameterPost($params); return $client->request(Zend_Http_Client::POST); } - + public function isEnabled() { return ('' != trim(Class_AdminVar::get('PREMIERCHAPITRE_BIB_ID'))); } @@ -248,7 +249,7 @@ class Class_WebService_PremierChapitre {// extends Class_WebService_Abstract { - } return $arrData; } - + public function update() { } public function harvest() { -- GitLab