Skip to content
Snippets Groups Projects

Premier chapitre

Closed Ghost User requested to merge (removed):premier-chapitre into master
Compare and
+ 1089
4
Preferences
Compare changes
Files
<?php
/**
* Copyright (c) 2015, Gael VINOT (Ville de Montrouge). All rights reserved.
*
* BOKEH is free software; you can redistribute it and/or modify
* it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE as published by
* the Free Software Foundation.
*
* There are special exceptions to the terms and conditions of the AGPL as it
* is applied to this software (see README file).
*
* BOKEH is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU AFFERO GENERAL PUBLIC LICENSE for more details.
*
* 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
*/
class Admin_PremierChapitreController extends ZendAfi_Controller_Action {
use Trait_Translator;
protected $_baseUrlOptions = ['module' => 'admin', 'controller' => 'premier-chapitre'];
private $active;
private $pc_bib_id;
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();
$this->view->titre = 'Premier Chapitre';
$this->pc_bib_id = Class_AdminVar::get('PREMIERCHAPITRE_BIB_ID');
$this->pc_bmid = Class_AdminVar::get('PREMIERCHAPITRE_BMID');
$this->pc_bmkey = Class_AdminVar::get('PREMIERCHAPITRE_BMKEY');
$this->active = (!empty($this->pc_bib_id) && !empty($this->pc_bmid) && !empty($this->pc_bmkey));
}
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);
}
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->titre .= ' :: Mise à jour du référentiel';
$this->renderScript('premier-chapitre/index.phtml');
}
function downloadRefAction() {
$data = false;
$pc_ws = new Class_WebService_PremierChapitre();
$data = $pc_ws->getDatafile();
if ($data){
$contenu = date('H:i:s')." Le référentiel a bien été téléchargé sur le serveur\nIl est possible de procéder à la mise à jour de la base\n";
$contenu .= '<a href="/admin/premier-chapitre/maj-db/">Mise à jour de la base</a>';
}
else $contenu = "Une erreur est survenue\nle référentiel n'a pas pu être téléchargé\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->titre .= ' :: Téléchargement du référentiel';
$this->renderScript('premier-chapitre/index.phtml');
}
function majDbAction() {
$data = false;
$pc_ws = new Class_WebService_PremierChapitre();
$data = $pc_ws->updateDatabase();
if ($data) {
$contenu = date('H:i:s')." La base a bien été mise à jour\n";
$contenu .= '* '.$data['total']." oeuvres ont été lues\n";
if ($data['new']) $contenu .= '* '.$data['new'].(($data['new']>1)?" ont été ajoutées":" a été ajoutée")."\n";
if ($data['maj']) $contenu .= '* '.$data['maj'].(($data['maj']>1)?" ont été mises":" a été mise")." à jour\n";
if ($data['err']) $contenu .= '* '.$data['err'].(($data['err']>1)?" erreurs n'ont pas été traitées":" erreur n'a pas été traitée")."\n";
$contenu .= '<a href="/admin/premier-chapitre/link-notices/">Lier les notices</a>';
}
else $contenu = "Une erreur est survenue\nLa base n'a pu être mise à 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->titre .= ' :: Mise à jour de la base';
$this->renderScript('premier-chapitre/index.phtml');
}
function linkNoticesAction() {
$data = false;
$pc_ws = new Class_WebService_PremierChapitre();
$data = $pc_ws->linkToNotices();
if ($data) {
$contenu = date('H:i:s')." Les premiers-chapitres ont bien été liés aux notices\n";
$contenu .= '* '.$data['total']." oeuvres ont été traités\n";
$contenu .= '* '.$data['maj'].(($data['maj']>1)?" ont été mises":" a été mise")." à jour\n";
}
else $contenu = "Une erreur est survenue\nLes liaisons n'ont pu être faites\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->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');
}
// pour tout autre méthode, levée d'une exception
throw new Exception('Méthode invalide "' . $method . '" appelée',500);
}
}
?>