BlogController.php 5.93 KB
Newer Older
1 2 3 4
<?php
/**
 * Copyright (c) 2012, Agence Française Informatique (AFI). All rights reserved.
 *
Laurent's avatar
Laurent committed
5
 * BOKEH is free software; you can redistribute it and/or modify
6 7 8 9 10 11
 * 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).
 *
Laurent's avatar
Laurent committed
12
 * BOKEH is distributed in the hope that it will be useful,
13 14 15 16 17
 * 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
Laurent's avatar
Laurent committed
18
 * along with BOKEH; if not, write to the Free Software
Laurent's avatar
Laurent committed
19
 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301  USA
20
 */
21

22

23
class BlogController extends ZendAfi_Controller_Action {
Patrick Barroca's avatar
Patrick Barroca committed
24 25 26 27
  private $_user = null; // Le user connecté
  private $modo_blog;
  private $_today;

28

Patrick Barroca's avatar
Patrick Barroca committed
29
  public function init() {
30
    parent::init();
Patrick Barroca's avatar
Patrick Barroca committed
31 32 33 34 35 36 37 38 39 40 41
    $this->_user = Class_Users::getIdentity();
    $this->modo_blog = Class_AdminVar::get('MODO_BLOG');
    $this->_today = (new Class_Date())->DateTimeDuJour();
  }


  public function indexAction() {
    $this->_redirect('opac/blog/lastcritique/nb/10');
  }


42

Patrick Barroca's avatar
Patrick Barroca committed
43 44 45 46 47 48 49
  public function viewauteurAction()  {
    $id_user = (int)$this->_getParam('id', $this->_user->ID_USER);
    if ($auteur = Class_Users::find($id_user)) {
      $this->view->liste_avis = Class_AvisNotice::filterVisibleForUser($this->_user, $auteur->getAvis());
      $this->view->name = $auteur->getNomAff();
    } else {
      $this->view->liste_avis = '';
50
      $this->view->name = $this->_('Auteur introuvable');
Patrick Barroca's avatar
Patrick Barroca committed
51 52
    }

53
    $this->view->title = $this->_('Avis');
Patrick Barroca's avatar
Patrick Barroca committed
54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84
    $this->view->id_user = $id_user;

    $avis_helper = $this->view->getHelper('Avis');
    $avis_helper->addUrlContext(['retour_abonne' => 'viewavis']);
    if (($id_user == $this->_user->ID_USER) || Class_Users::isCurrentUserAdmin())
      $avis_helper->setActions(['del']);
  }


  public function delavisnoticeAction() {
    $id = $this->_getParam('id');
    $avis = Class_AvisNotice::find($id);
    if (($avis->getUser() == Class_Users::getIdentity())
        || Class_Users::isCurrentUserAdmin()) {
      $avis->delete();
      $this->_helper->notify($this->_("Avis supprimé"));
    }

    if (!$this->_getParam('js_redirect') === true){
      $redirect = $this->_getParam('redirect', 'blog/viewauteur/id/'.$avis->getIdUser());
      $this->_redirect($redirect);
      return;
    }

    $this->_javascriptRedirectToReferrer();
  }


  public function lastcritiqueAction()  {
    $nb_avis = (int)$this->_getParam('nb', 20);
    $liste_avis = Class_AvisNotice::findAllBy(['order' => 'date_avis desc',
85
                                               'flags' => Class_AvisNotice::NO_FLAG,
Patrick Barroca's avatar
Patrick Barroca committed
86 87 88 89 90 91 92 93 94 95
                                               'limit' => $nb_avis]);

    $this->view->nb_aff = $nb_avis;
    $this->view->liste_avis = Class_AvisNotice::filterVisibleForUser($this->_user,
                                                                     $liste_avis);
    $this->view->title = $this->view->_('Dernières critiques');
    $this->renderScript('blog/viewcritiques.phtml');
  }


96 97 98 99 100 101 102
	protected function updateBlogConfigDefault() {
		if (!$this->view->config['nb_display'] || $this->view->config['nb_display']<1) {
			$this->view->config['nb_display']=(new Class_Systeme_ModulesAppli())->getValeursParDefaut('blog', 'viewcritiques')['nb_display'];
		}
	}


Patrick Barroca's avatar
Patrick Barroca committed
103
  public function viewcritiquesAction() {
104
    $this->view->page = $this->_getParam('page', 1);
105
    $this->view->id_module = $id_module = (int)$this->_getParam('id_module');
106

107
    $profil = Class_Profil::getCurrentProfil();
108 109
    $preferences =  $profil->getModuleAccueilPreferences($id_module, 'CRITIQUES');
    $this->view->config = $profil->getConfigurationOf('blog', 'viewcritiques', '');
110
		$this->updateBlogConfigDefault();
Patrick Barroca's avatar
Patrick Barroca committed
111

112 113 114 115
    $this->view->liste_avis =
      Class_AvisNotice::getAvisFromPreferences($preferences,
                                               [$this->view->page,
                                                $this->view->config['nb_display']]);
116

117
    $params_url = $this->_request->getParams();
118
    unset($params_url['current_module']);
119 120 121 122 123 124
    $this->view->params_url = $params_url;

    $this->view->total = Class_AvisNotice::countAvisFromPreferences($preferences);

    $this->view->title = (array_key_exists('titre', $preferences))
      ? $preferences['titre']
125
      : $this->_('Dernières critiques');
Patrick Barroca's avatar
Patrick Barroca committed
126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162
  }


  /**
   * Affiche l'avis avec l'id donné pour pouvoir être lu par Read Speaker.
   */
  public function readavisAction() {
    $this
      ->getHelper('ViewRenderer')
      ->setLayoutScript('readspeaker.phtml');

    $this->view->avis = Class_AvisNotice::find($this->_getParam('id'));
  }


  public function viewavisAction()  {
    $id_avis = $this->_getParam('id');
    $avis = Class_AvisNotice::find($id_avis);

    $this->view->avis = $avis;
    $this->view->commentaires = [];
    $this->view->modo_blog = $this->modo_blog;
    $this->view->user_co = ($this->_user->ID_USER != '');
    $this->view->user = $this->_user;
  }


  public function alertAction() {
    $class_blog = new Class_Blog();
    $type = $this->_getParam('type');
    $id = $this->_getParam('id_avis');
    $class_blog->alertThis($id, $type);
    $this->_redirect($_SERVER['HTTP_REFERER']);
  }


  public function hierarchicalAction() {
163 164
    $cfg = Class_Profil::getCurrentProfil()->getConfigurationOf('blog','hierarchical','');
    $nb_display = isset($cfg['nb_display']) ? $cfg['nb_display'] : null;
Patrick Barroca's avatar
Patrick Barroca committed
165
    $this->view->list = $this->_helper
166 167 168 169 170
      ->ListViewMode_Review(['model' => Class_Catalogue::find($this->_getParam('id', 0)),
                             'id' => $this->_getParam('id'),
                             'page' => $this->_getParam('page', 1),
                             'truncate_at' => $this->_getParam('truncate_at'),
                             'nb_display' => $nb_display]);
Patrick Barroca's avatar
Patrick Barroca committed
171
  }
172
}