Commit d3473e86 authored by Laurent's avatar Laurent
Browse files

de v#27067 koha restful suggestion service

tab 2 spaces
parent f30544d9
......@@ -21,344 +21,344 @@
class Admin_ModulesController extends ZendAfi_Controller_Action {
protected
$profil,
$curent_profil,
$preferences,
$render;
protected
$profil,
$curent_profil,
$preferences,
$render;
public function init() {
parent::init();
if ($this->_request->getActionName() != 'kiosque-change-data') {
$this->render = $this->getHelper('ViewRenderer');
$this->render->setLayoutScript('subModal.phtml');
}
public function init() {
parent::init();
if ($this->_request->getActionName() != 'kiosque-change-data') {
$this->render = $this->getHelper('ViewRenderer');
$this->render->setLayoutScript('subModal.phtml');
}
$this->initParams();
if (array_key_exists('type_module', $this->_request->getParams()))
$this->initViewParams();
$this->initParams();
if (array_key_exists('type_module', $this->_request->getParams()))
$this->initViewParams();
}
}
public function preDispatch() {
parent::preDispatch();
if ($this->_request->getActionName()!='kiosque-change-data' &&
$this->_request->getActionName()!='search-result')
Zend_Layout::startMvc();
}
public function preDispatch() {
parent::preDispatch();
if ($this->_request->getActionName()!='kiosque-change-data' &&
$this->_request->getActionName()!='search-result')
Zend_Layout::startMvc();
}
protected function initParams() {
$this->profil = Class_Profil::getCurrentProfil();
$this->preferences = $this->profil
->getCfgModulesPreferences($this->_getParam('type_module'),
$this->_getParam('action1'),
$this->_getParam('action2'));
}
protected function initParams() {
$this->profil = Class_Profil::getCurrentProfil();
$this->preferences = $this->profil
->getCfgModulesPreferences($this->_getParam('type_module'),
$this->_getParam('action1'),
$this->_getParam('action2'));
}
protected function initViewParams() {
$cls_module = new Class_Systeme_ModulesAppli();
$this->view->titre_module = $cls_module->getLibelleModule($this->_getParam('type_module'),
$this->_getParam('action1'));
protected function initViewParams() {
$cls_module = new Class_Systeme_ModulesAppli();
$this->view->titre_module = $cls_module->getLibelleModule($this->_getParam('type_module'),
$this->_getParam('action1'));
$this->view->preferences = $this->preferences;
$this->view->url=$this->_request->getRequestUri();
$this->view->combo_templates =
ZendAfi_View_Helper_Accueil_Base::getComboTemplates($this->preferences['boite'],
$this->profil);
$this->view->id_profil = $this->profil->getId();
$this->view->id_bib = $this->profil->getIdSite();
$this->view->action = $this->_getParam('type_module').'_'.$this->_getParam('action1');
}
$this->view->preferences = $this->preferences;
$this->view->url=$this->_request->getRequestUri();
$this->view->combo_templates =
ZendAfi_View_Helper_Accueil_Base::getComboTemplates($this->preferences['boite'],
$this->profil);
$this->view->id_profil = $this->profil->getId();
$this->view->id_bib = $this->profil->getIdSite();
$this->view->action = $this->_getParam('type_module').'_'.$this->_getParam('action1');
}
protected function _simpleAction($script) {
if ($this->_request->isPost())
return $this->updateEtRetour($this->_request->getPost());
$this->render->renderScript('modules/' . $script . '.phtml');
}
protected function _simpleAction($script) {
if ($this->_request->isPost())
return $this->updateEtRetour($this->_request->getPost());
$this->render->renderScript('modules/' . $script . '.phtml');
}
public function indexAction() {
if($this->_getParam('action1') === 'formulairecontact')
return $this->_simpleAction('formulaire_contact');
return $this->_simpleAction('index_all');
}
public function indexAction() {
if($this->_getParam('action1') === 'formulairecontact')
return $this->_simpleAction('formulaire_contact');
return $this->_simpleAction('index_all');
}
public function abonneAction() {
if ($this->_getParam('action1') === 'suggestion-achat-add')
return $this->_simpleAction('abonne_suggestion_achat_add');
return $this->_simpleAction('abonne_all');
}
public function abonneAction() {
if ($this->_getParam('action1') === 'suggestion-achat-add')
return $this->_simpleAction('abonne_suggestion_achat_add');
return $this->_simpleAction('abonne_all');
}
public function authAction() {
return $this->_simpleAction('auth_'.$this->_getParam('action1'));
}
public function authAction() {
return $this->_simpleAction('auth_'.$this->_getParam('action1'));
}
public function cmsAction() {
return $this->_simpleAction(($this->_getParam('action1') == 'articleviewbydate')
? 'cms_articleviewbydate' : 'cms_all');
}
public function cmsAction() {
return $this->_simpleAction(($this->_getParam('action1') == 'articleviewbydate')
? 'cms_articleviewbydate' : 'cms_all');
}
public function rssAction() {
return $this->_simpleAction('rss_all');
}
public function rssAction() {
return $this->_simpleAction('rss_all');
}
public function bibAction() {
return $this->_simpleAction('bib_all');
}
public function bibAction() {
return $this->_simpleAction('bib_all');
}
public function sitoAction() {
return $this->_simpleAction('sito_all');
}
public function sitoAction() {
return $this->_simpleAction('sito_all');
}
public function blogAction() {
return $this->_simpleAction('blog_all');
}
public function blogAction() {
return $this->_simpleAction('blog_all');
}
public function formulairecontactAction() {
return $this->_simpleAction('formulaire_contact');
}
public function formulairecontactAction() {
return $this->_simpleAction('formulaire_contact');
}
public function rechercheAction() {
if ('resultat' == $this->_getParam('action1'))
return $this->_forward('search-result');
public function rechercheAction() {
if ('resultat' == $this->_getParam('action1'))
return $this->_forward('search-result');
if ($this->isValidPostNotice())
return $this->updateEtRetour($this->getPostNotice());
if ($this->isValidPostNotice())
return $this->updateEtRetour($this->getPostNotice());
if ($this->_request->isPost()
&& 'viewnotice' != $this->_getParam('action1'))
return $this->updateEtRetour($this->_request->getPost());
if ($this->_request->isPost()
&& 'viewnotice' != $this->_getParam('action1'))
return $this->updateEtRetour($this->_request->getPost());
$this->view->titre = 'Recherche';
$this->view->titre = 'Recherche';
if ('viewnotice' == $this->_getParam('action1')) {
$this->view->type_doc = $this->_getParam('action2');
$this->view->preferences = $this->noticeConsolidationOnglets($this->preferences);
}
if ('viewnotice' == $this->_getParam('action1')) {
$this->view->type_doc = $this->_getParam('action2');
$this->view->preferences = $this->noticeConsolidationOnglets($this->preferences);
}
$this->render->renderScript('modules/recherche_' . $this->_getParam('action1') . '.phtml');
}
$this->render->renderScript('modules/recherche_' . $this->_getParam('action1') . '.phtml');
}
protected function isValidPostNotice() {
if (!$this->_request->isPost()
|| 'viewnotice' != $this->_getParam('action1'))
return false;
protected function isValidPostNotice() {
if (!$this->_request->isPost()
|| 'viewnotice' != $this->_getParam('action1'))
return false;
$this->preferences['links_zones'] = $this->processLinksZones();
$lines = explode(';', $this->preferences['links_zones']);
if (empty($lines))
return true;
$this->preferences['links_zones'] = $this->processLinksZones();
$lines = explode(';', $this->preferences['links_zones']);
if (empty($lines))
return true;
$errors = [];
$digit = new Zend_Validate_Digits();
$alnum = new Zend_Validate_Regex('/^[a-zA-Z0-9]$/u');
foreach($lines as $line) {
$datas = explode('-', $line);
// empty line
if (1 == count($datas) && '' == $datas[0])
continue;
$errors = [];
$digit = new Zend_Validate_Digits();
$alnum = new Zend_Validate_Regex('/^[a-zA-Z0-9]$/u');
foreach($lines as $line) {
$datas = explode('-', $line);
// empty line
if (1 == count($datas) && '' == $datas[0])
continue;
if (3 !== count($datas)) {
$errors[] = $this->view->_('Les caractères ";" et "-" sont interdits');
continue;
}
if (3 !== count($datas)) {
$errors[] = $this->view->_('Les caractères ";" et "-" sont interdits');
continue;
}
if (!$digit->isValid($datas[0]))
$errors[] = $this->view->_('La zone "%s" n\'est pas une zone unimarc valide',
$datas[0]);
if (!$alnum->isValid($datas[1]))
$errors[] = $this->view->_('Le champ "%s" n\'est pas un champ unimarc valide',
$datas[1]);
if (!$alnum->isValid($datas[2]))
$errors[] = $this->view->_('Le champ "%s" n\'est pas un champ unimarc valide',
$datas[2]);
}
if (!$digit->isValid($datas[0]))
$errors[] = $this->view->_('La zone "%s" n\'est pas une zone unimarc valide',
$datas[0]);
if (!$alnum->isValid($datas[1]))
$errors[] = $this->view->_('Le champ "%s" n\'est pas un champ unimarc valide',
$datas[1]);
if (!$alnum->isValid($datas[2]))
$errors[] = $this->view->_('Le champ "%s" n\'est pas un champ unimarc valide',
$datas[2]);
}
$this->view->links_errors = $errors;
$this->view->links_errors = $errors;
return empty($errors);
}
return empty($errors);
}
public function searchResultAction() {
$post_values = $this->_request->getPost();
public function searchResultAction() {
$post_values = $this->_request->getPost();
$form =
ZendAfi_Form_Configuration_SearchResult::newConfigurationWith(
array_merge(Class_Profil::getCurrentProfil()
->getConfigurationOf('recherche', 'resultat', 'simple'),
$post_values));
$form =
ZendAfi_Form_Configuration_SearchResult::newConfigurationWith(
array_merge(Class_Profil::getCurrentProfil()
->getConfigurationOf('recherche', 'resultat', 'simple'),
$post_values));
if ($this->_request->isPost() && $form->isValid($post_values))
return $this->updateEtRetour($post_values);
if ($this->_request->isPost() && $form->isValid($post_values))
return $this->updateEtRetour($post_values);
$this->view->form = $form;
}
$this->view->form = $form;
}
public function noticeajaxAction() {
$this->view->type_doc = $this->action2;
$this->noticeConsolidationOnglets();
public function noticeajaxAction() {
$this->view->type_doc = $this->action2;
$this->noticeConsolidationOnglets();
if ($this->_request->isPost()) {
$enreg=$this->getPostNotice();
return $this->updateEtRetour($enreg);
}
if ($this->_request->isPost()) {
$enreg=$this->getPostNotice();
return $this->updateEtRetour($enreg);
}
$this->render->renderScript('modules/recherche_viewnotice.phtml');
}
$this->render->renderScript('modules/recherche_viewnotice.phtml');
}
protected function noticeConsolidationOnglets($preferences) {
if (!array_key_exists("onglets", $preferences))
$preferences["onglets"] = array();
protected function noticeConsolidationOnglets($preferences) {
if (!array_key_exists("onglets", $preferences))
$preferences["onglets"] = array();
$onglets = Class_Codification::getInstance()->getNomOnglet('');
foreach($onglets as $key => $valeur) {
if(!array_key_exists($key, $preferences["onglets"])) {
$preferences["onglets"][$key]["titre"] = "";
$preferences["onglets"][$key]["aff"] = 0;
$preferences["onglets"][$key]["ordre"] = 100;
$preferences["onglets"][$key]["largeur"] = 0;
}
}
$onglets = Class_Codification::getInstance()->getNomOnglet('');
foreach($onglets as $key => $valeur) {
if(!array_key_exists($key, $preferences["onglets"])) {
$preferences["onglets"][$key]["titre"] = "";
$preferences["onglets"][$key]["aff"] = 0;
$preferences["onglets"][$key]["ordre"] = 100;
$preferences["onglets"][$key]["largeur"] = 0;
}
}
foreach($preferences["onglets"] as $key => $valeur) {
if (!array_key_exists($key, $onglets))
unset($preferences["onglets"][$key]);
}
foreach($preferences["onglets"] as $key => $valeur) {
if (!array_key_exists($key, $onglets))
unset($preferences["onglets"][$key]);
}
return $preferences;
}
return $preferences;
}
protected function getPostNotice() {
foreach($this->_request->getPost() as $clef => $valeur) {
if (false === ($pos = strpos($clef, '_'))) {
$enreg[$clef] = $valeur;
continue;
}
if (in_array($clef, ['liste_codes', 'champs_codes'])) {
$enreg['entete'] = $valeur;
continue;
}
if ('analytics_' == substr($clef, 0, 10)) {
$enreg[$clef] = $valeur;
continue;
}
if (in_array($clef, ['link_zone','link_url', 'link_label']))
continue;
$type = substr($clef, 0, $pos);
$champ = substr($clef, $pos + 1);
protected function getPostNotice() {
foreach($this->_request->getPost() as $clef => $valeur) {
if (false === ($pos = strpos($clef, '_'))) {
$enreg[$clef] = $valeur;
continue;
}
if (in_array($clef, ['liste_codes', 'champs_codes'])) {
$enreg['entete'] = $valeur;
continue;
}
if ('analytics_' == substr($clef, 0, 10)) {
$enreg[$clef] = $valeur;
continue;
}
if (in_array($clef, ['link_zone','link_url', 'link_label']))
continue;
$type = substr($clef, 0, $pos);
$champ = substr($clef, $pos + 1);
if ($champ == 'ordre') {
$valeur = (int)$valeur;
if($valeur < 1 or $valeur > 100)
$valeur = '1';
}
if ($champ == 'ordre') {
$valeur = (int)$valeur;
if($valeur < 1 or $valeur > 100)
$valeur = '1';
}
if ($champ == 'largeur') {
$valeur = (int)$valeur;
if($valeur < 5 or $valeur > 50)
$valeur = '0';
}
if ($champ == 'largeur') {
$valeur = (int)$valeur;
if($valeur < 5 or $valeur > 50)
$valeur = '0';
}
$enreg['onglets'][$type][$champ] = $valeur;
}
$enreg['onglets'][$type][$champ] = $valeur;
}
if ($links_zones=$this->processLinksZones())
$enreg['links_zones'] = $links_zones;
if ($links_zones=$this->processLinksZones())
$enreg['links_zones'] = $links_zones;
return $enreg;
}
return $enreg;
}
protected function processLinksZones() {
$links_zones = $this->_getParam('link_zone', []);
$links_urls = $this->_getParam('link_url', []);
$links_labels = $this->_getParam('link_label', []);
protected function processLinksZones() {
$links_zones = $this->_getParam('link_zone', []);
$links_urls = $this->_getParam('link_url', []);
$links_labels = $this->_getParam('link_label', []);
$packer = new Class_Profil_ConfigPacker();
for ($i = 0; $i < count($links_zones); $i++) {
if ('' == $links_zones[$i] && '' == $links_urls[$i] && '' == $links_labels[$i])
continue;
$packer->add([$links_zones[$i], $links_urls[$i], $links_labels[$i]]);
}
$packer = new Class_Profil_ConfigPacker();
for ($i = 0; $i < count($links_zones); $i++) {
if ('' == $links_zones[$i] && '' == $links_urls[$i] && '' == $links_labels[$i])
continue;
$packer->add([$links_zones[$i], $links_urls[$i], $links_labels[$i]]);
}
return $packer->pack();
}
return $packer->pack();
}
protected function updateEtRetour($enreg) {
$cfg_modules = $this->profil->getCfgModulesAsArray();
$cfg_modules
[$this->_getParam('type_module')]
[$this->_getParam('action1') . $this->_getParam('action2')] = $enreg;
protected function updateEtRetour($enreg) {
$cfg_modules = $this->profil->getCfgModulesAsArray();
$cfg_modules
[$this->_getParam('type_module')]
[$this->_getParam('action1') . $this->_getParam('action2')] = $enreg;
$this->profil
->setCfgModules($cfg_modules)
->save();
$this->view->reload = 'SITE';
$this->render->renderScript('modules/_retour.phtml');
}
$this->profil
->setCfgModules($cfg_modules)
->save();
$this->view->reload = 'SITE';
$this->render->renderScript('modules/_retour.phtml');
}
protected function retourErreur($erreur) {
$this->view->erreur = $erreur;
$this->view->preferences = $this->_request->getPost();
}
protected function retourErreur($erreur) {
$this->view->erreur = $erreur;
$this->view->preferences = $this->_request->getPost();
}
public function kiosqueChangeDataAction() {
$this->id_module = $this->_getParam('id_module');
public function kiosqueChangeDataAction() {
$this->id_module = $this->_getParam('id_module');
$module_config = $this->profil
->getModuleAccueilConfig($this->_getParam('id_module'), 'KIOSQUE');
$module_config = $this->profil
->getModuleAccueilConfig($this->_getParam('id_module'), 'KIOSQUE');
$this->view->id_panier = $module_config['preferences']['id_panier'];
$this->view->id_catalogue = $module_config['preferences']['id_catalogue'];
$this->view->titre = $this->view->_('Sélectionnez un panier ou un domaine');
$this->view->id_panier = $module_config['preferences']['id_panier'];
$this->view->id_catalogue = $module_config['preferences']['id_catalogue'];
$this->view->titre = $this->view->_('Sélectionnez un panier ou un domaine');
if (!$this->_request->isPost())
return;
if (!$this->_request->isPost())
return;
$enreg = $this->_request->getPost();