TemplateController.php 3.51 KB
Newer Older
Ghislain Loas's avatar
Ghislain Loas committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
<?php
/**
 * Copyright (c) 2012-2017, Agence Française Informatique (AFI). 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
 */


23
class Admin_TemplateController extends ZendAfi_Controller_Action {
Ghislain Loas's avatar
Ghislain Loas committed
24 25 26


  public function getPlugins() {
Ghislain Loas's avatar
Ghislain Loas committed
27 28
    return ['ZendAfi_Controller_Plugin_ResourceDefinition_Template',
            'ZendAfi_Controller_Plugin_Manager_Template'];
Ghislain Loas's avatar
Ghislain Loas committed
29 30 31
  }


32 33 34 35 36 37 38 39 40 41
  public function preDispatch() {
    parent::preDispatch();

    if(Class_Template::isDisabled()) {
      $this->_helper->notify($this->_('Le magasin de thèmes n\'est pas activé. Vous n\'avez pas accès à cette fonctionnalité.'));
      $this->_redirect('/admin/index');
    }
  }


Ghislain Loas's avatar
Ghislain Loas committed
42
  public function indexAction() {
Ghislain Loas's avatar
Ghislain Loas committed
43
    $this->view->titre = $this->_('Magasin de thèmes');
Ghislain Loas's avatar
Ghislain Loas committed
44
    $this->view->templates = (new Class_Template_Loader)->getTemplates();
Ghislain Loas's avatar
Ghislain Loas committed
45
  }
Ghislain Loas's avatar
Ghislain Loas committed
46 47 48


  public function tryAction() {
Ghislain Loas's avatar
Ghislain Loas committed
49 50 51 52 53 54 55 56 57 58
    if(!$template = (new Class_Template_Loader)->find($this->_getParam('template'))) {
      $this->_helper->notify($this->_('Une erreur c\'est produite. Vous ne pouvez pas tester le template'));
      return $this->_redirectToIndex();
    }

    if(!$profile = Class_Profil::find($this->_getParam('on'))) {
      $this->_helper->notify($this->_('Une erreur c\'est produite. Vous ne pouvez pas tester le template'));
      return $this->_redirectToIndex();
    }

Ghislain Loas's avatar
Ghislain Loas committed
59
    if(!$id_profile = $template->tryOn($profile)) {
60 61 62 63
      $this->_helper->notify($this->_('Une erreur c\'est produite. Vous ne pouvez pas tester le template'));
      return $this->_redirectToIndex();
    }

Ghislain Loas's avatar
Ghislain Loas committed
64
    $this->_redirect('/opac/index/index/id_profil/' . $id_profile);
Ghislain Loas's avatar
Ghislain Loas committed
65
  }
Ghislain Loas's avatar
Ghislain Loas committed
66 67 68 69


  public function resetAction() {
    $template = Class_Template::current()->resetSettings();
Ghislain Loas's avatar
Ghislain Loas committed
70 71 72 73 74 75 76 77
    $this->_helper->notify($this->_('Thème %s réinitialisé', $template->getId()));
    return $this->_redirectClose($this->_getReferer());
  }


  public function updateAction() {
    $template = Class_Template::current()->updateSettings();
    $this->_helper->notify($this->_('Thème %s mis à jour', $template->getId()));
Ghislain Loas's avatar
Ghislain Loas committed
78 79
    return $this->_redirectClose($this->_getReferer());
  }
Ghislain Loas's avatar
Ghislain Loas committed
80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100


  public function applyAction() {
    if(!$this->view->template = (new Class_Template_Loader)->find($this->_getParam('template'))) {
      $this->_helper->notify($this->_('Une erreur c\'est produite. Vous ne pouvez pas tester le template'));
      return $this->_redirectToIndex();
    }

    $this->view->titre = $this->_('Appliquer le thème %s à un profil',
                                  $this->view->template->getTitle());

    if(!$profile = Class_Profil::find($this->_getParam('on')))
      return;

    if(!$profile_id = $this->view->template->applyOn($profile)) {
      $this->_helper->notify($this->_('Une erreur c\'est produite.'));
      return $this->_redirectToIndex();
    }

    $this->_redirect('/opac/index/index/id_profil/' . $profile_id);
  }
Ghislain Loas's avatar
Ghislain Loas committed
101
}