Skip to content
Snippets Groups Projects
ArticlesPeriodiques.php 3.94 KiB
Newer Older
<?php
/**
 * Copyright (c) 2012-2024, 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 Intonation_View_Notice_ArticlesPeriodiques extends ZendAfi_View_Helper_BaseHelper {
  public function Notice_ArticlesPeriodiques($notice) :string {
    $html = ($articles_html = $this->_renderSerialsArticles($notice))
      ? $articles_html
      : $this->_renderArticles($notice);

    return $html
       ? $this->_grid($this->_div(['class' => 'record_serials_articles_title'],
                                $this->_tag('h3', $this->_('Articles')))
                   . $this->_div(['class' => 'record_serials_articles_list'],
                                 $html),
                   ['class' => 'record_serials_articles'])
      : '';
  }


  protected function _renderSerialsArticles(Class_Notice $record) : string {
    if ( ! $articles = $record->getSerialsArticles())
      return '';

    $articles = (new Storm_Collection($articles))
      ->collect(fn($serial_article)
                => new Intonation_Library_View_Wrapper_SerialArticleByRecord($serial_article,
      $this->view->collection($articles,
                              fn($item) => $this->view->renderingDescription($item));
  protected function _renderArticles(Class_Notice $notice) :string {
      Class_Indexation::getInstance()
      ->serialCodeAlphaChapeau((string) $notice->getClefChapeau(),
                               (string) $notice->getTomeAlpha());

    $count_articles = Class_Notice::countBy(['clef_chapeau' => $headkey,
                                             'type_doc' => Class_TypeDoc::PERIODIQUE_ARTICLE,
                                             'order' => 'id_notice']);

    $articles = Class_Notice::findAllBy(['clef_chapeau' => $headkey,
                                         'type_doc' => Class_TypeDoc::PERIODIQUE_ARTICLE,
                                         'limit' => static::LIMIT,
                                         'order' => 'id_notice']);

    $articles = (new Storm_Collection($articles))
      ->collect(fn($article)
                => new Intonation_Library_View_Wrapper_SerialArticle($article,
                                                                     $this->view));
    if ($articles->isEmpty())
      return '';

    if ($count_articles > static::LIMIT)
      $actions [] = (new Intonation_Library_Link)
        ->setText($this->view->_('Voir les %d articles', $count_articles))
        ->setImage($this->view->templateIco('search_more','library'))
        ->setTitle($this->view->_('Rechercher dans le catalogue'))
        ->setUrl(Class_Url::relative(['controller' => 'recherche',
                                      'action' => 'simple',
                                      'rech_titres' => $headkey,
                                      'type_doc' => 'per_art']));
      $this->view->collection($articles,
                              $this->view->collectionActions($actions),
                              fn($item) => $this->view->renderingDescription($item));