Skip to content
Snippets Groups Projects
BlogController.php 5.22 KiB
<?php
/**
 * Copyright (c) 2012, 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
 */


class BlogController extends ZendAfi_Controller_Action {
  private $_user = null; // Le user connecté
  private $modo_blog;
  private $_today;

  public function init() {
    $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');
  }



  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 = '';
      $this->view->name = 'Auteur introuvable';
    }

    $this->view->title = 'Avis';
    $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',
                                               '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');
  }


  public function viewcritiquesAction() {
    $this->view->page = $this->_getParam('page',1);
    $id_module = (int)$this->_getParam('id_module');
    $profil = Class_Profil::getCurrentProfil();
    $preferences =  $profil
      ->getModuleAccueilPreferences($id_module, 'CRITIQUES');
    $this->view->config=$profil->getConfigurationOf('blog','viewcritiques','');

    $avis = Class_AvisNotice::getAvisFromPreferences($preferences,[$this->view->page, $this->view->config['nb_display']]);

    $this->view->liste_avis = $avis;

    $params_url=$this->_request->getParams();
    unset($params_url['page']);
    unset($params_url['current_module']);
    $this->view->params_url=$params_url;
    $this->view->total=count(Class_AvisNotice::getAvisFromPreferences($preferences));
    $this->view->title = 'Dernières critiques';
    if (array_key_exists('titre', $preferences))
      $this->view->title = $preferences['titre'];
  }


  /**
   * 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() {
    $this->view->list = $this->_helper
      ->reviewListViewMode(['model' => Class_Catalogue::find($this->_getParam('id', 0)),
                            'id' => $this->_getParam('id'),
                            'page' => $this->_getParam('page', 1),
                            'truncate_at' => $this->_getParam('truncate_at')]);
  }
}