Entete.php 3.97 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
19
 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301  USA
20
 */
21 22 23


class ZendAfi_View_Helper_Notice_Entete extends ZendAfi_View_Helper_BaseHelper {
Patrick Barroca's avatar
Patrick Barroca committed
24 25 26 27 28 29 30
  public function notice_Entete($notice, $preferences) {
    if(!$notice)
      return '';

    if (!array_isset('entete', $preferences))
      return '';

31 32
    $entetes = str_split($preferences['entete']);
    $libelles_valeurs = $this->getValeurs($notice, $entetes);
Patrick Barroca's avatar
Patrick Barroca committed
33

Matthias Meusburger's avatar
Matthias Meusburger committed
34
    return $this->libellesValeursToHtmlAndSerie($libelles_valeurs, $notice);
Patrick Barroca's avatar
Patrick Barroca committed
35 36 37 38 39 40 41 42
  }


  public function addSeries($notice) {
    if (!$notice->hasTome())
      return '';

    $criteres = new Class_CriteresRecherche();
43
    $serie = $notice->getClefChapeau() . '-' . $notice->getTypeDoc();
Patrick Barroca's avatar
Patrick Barroca committed
44

Patrick Barroca's avatar
Patrick Barroca committed
45 46
    $label = Class_Codification::getLibelleForSerie($notice);

47
    return $this
Patrick Barroca's avatar
Patrick Barroca committed
48 49
      ->_tag('a',
             $label,
50
             ['class' => 'serie',
Patrick Barroca's avatar
Patrick Barroca committed
51
              'title' => $this->view->_('Lancer une recherche pour %s', lcfirst($label)),
52
              'href' => $this->view->url($criteres->getNewUrlCriteresSerie($serie), null, true)]);
Patrick Barroca's avatar
Patrick Barroca committed
53 54 55 56 57 58 59 60 61 62 63
  }


  public function firstAndSecond($entetes){
    $class =[];
    foreach($entetes as $champ){
      $class[$champ] = 'first';
    }
    return $class;
  }

64

Patrick Barroca's avatar
Patrick Barroca committed
65 66 67 68 69 70 71
  public function getValeurs($notice, $entetes) {
    $values = [];
    $facettes = $notice->getFacettes();
    array_walk(
      $entetes,
      function($item) use (&$values, $facettes, $notice) {
        $label = Class_Codification::getInstance()->getNomChamp($item, 1);
Matthias Meusburger's avatar
Matthias Meusburger committed
72 73
        if ($champ_notice = $notice->getChampNotice($item, $facettes))
          $values[] = [ 'label' => $label, 'champ' => $champ_notice ];
Patrick Barroca's avatar
Patrick Barroca committed
74 75 76 77 78 79
      });

    return array_filter($values);
  }


80 81 82 83 84 85 86
  public function libellesValeursToHtmlAndSerie($libelles_valeurs, $notice) {
    return $this->addSeries($notice)
      . $this->libellesValeursToHtml($libelles_valeurs);
  }


  public function libellesValeursToHtml($libelles_valeurs) {
Patrick Barroca's avatar
Patrick Barroca committed
87
    $i=0;
88
    $html = '';
Patrick Barroca's avatar
Patrick Barroca committed
89
    foreach($libelles_valeurs as $item){
90
      $html .= $this->libelleValeursToHtml($item, is_odd($i) ? 'second' : 'first');
Patrick Barroca's avatar
Patrick Barroca committed
91 92 93
      $i++;
    }

94 95
    return $this->_tag('dl', $html);
  }
Patrick Barroca's avatar
Patrick Barroca committed
96

97 98 99 100

  public function libelleValeursToHtml($item, $class) {
    return $this->_tag('dt', $item['label'],
                       ['class' => $class . ' ' . $this->labelToClassName($item['label'])])
Matthias Meusburger's avatar
Matthias Meusburger committed
101 102

      . $this->_tag('dd', $this->getValeursHtml($item['champ']),
103
                    ['class' => $class]);
Patrick Barroca's avatar
Patrick Barroca committed
104 105 106
  }


107
  public function labelToClassName($label) {
Matthias Meusburger's avatar
Matthias Meusburger committed
108 109
    return str_replace(['(', ')', 'é'],
                       ['', '', 'e'],
Matthias Meusburger's avatar
Matthias Meusburger committed
110
                       strtolower($label));
111 112 113
  }


Matthias Meusburger's avatar
Matthias Meusburger committed
114
  public function getValeursHtml($valeur) {
115 116 117
    if (gettype($valeur) != 'array')
      return $valeur;

Matthias Meusburger's avatar
Matthias Meusburger committed
118 119 120
    $html = '';
    foreach($valeur as $item)
      $html .= $this->getValeurHtml($item);
121

Matthias Meusburger's avatar
Matthias Meusburger committed
122 123 124 125 126 127 128
    return $html;
  }


  public function getValeurHtml($item) {
    if (is_object($item))
      return $item->renderOn($this->view);
129

Matthias Meusburger's avatar
Matthias Meusburger committed
130 131 132 133
    if (gettype($item) == 'array'){
      if ($item['url']) {
        return $this->_tag('a', $item['libelle'],
                           ['href' => $this->view->url($item['url'])]);
Patrick Barroca's avatar
Patrick Barroca committed
134
      }
135

Matthias Meusburger's avatar
Matthias Meusburger committed
136
      return '';
Patrick Barroca's avatar
Patrick Barroca committed
137
    }
138

Matthias Meusburger's avatar
Matthias Meusburger committed
139 140 141 142
    if (gettype($item) == 'string')
      return $this->_tag('div', $item);

    return $item;
Patrick Barroca's avatar
Patrick Barroca committed
143
  }
144 145 146
}

?>