Avis.php 3.45 KB
Newer Older
1 2 3 4
<?php
/**
 * Copyright (c) 2012-2014, 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
 */

trait Trait_Avis {
Patrick Barroca's avatar
Patrick Barroca committed
23 24 25 26 27
  /** traits cannot have constants */
  public static $AVIS_ABONNE = 0;
  public static $AVIS_BIBLIO = 1;
  public static $STATUT_OK = 1;
  public static $STATUT_NOK = 0;
28 29


Patrick Barroca's avatar
Patrick Barroca committed
30 31 32
  public function getZendDateAvis() {
    return new Zend_Date($this->getDateAvis(), null, Zend_Registry::get('locale'));
  }
33 34


Patrick Barroca's avatar
Patrick Barroca committed
35 36 37
  public function getFormattedDateAvis($format = 'dd-MM-yyyy') {
    return $this->getZendDateAvis()->toString($format);
  }
38 39


Patrick Barroca's avatar
Patrick Barroca committed
40 41 42
  public function getReadableDateAvis() {
    return $this->getFormattedDateAvis('d MMMM yyyy');
  }
43 44


Patrick Barroca's avatar
Patrick Barroca committed
45 46 47 48 49
  public function getUserName() {
    if (!$this->hasUser())
      return '';
    return $this->getUser()->getNomAff();
  }
50 51


Patrick Barroca's avatar
Patrick Barroca committed
52 53 54 55 56
  public function getUserMail() {
    if (!$this->hasUser())
      return '';
    return $this->getUser()->getMail();
  }
57 58


Patrick Barroca's avatar
Patrick Barroca committed
59
  public function isWaitingForModeration() {
Patrick Barroca's avatar
Patrick Barroca committed
60 61 62 63
    return $this->shouldBeModerated()
      ? $this->isModerationNOK()
      : false;
  }
64 65


Patrick Barroca's avatar
Patrick Barroca committed
66
  public function shouldBeModerated() {
67 68 69
    return
      ($this->isWrittenByAbonne() && Class_AdminVar::isPatronReviewsModerated())
      || ($this->isWrittenByBibliothecaire() && Class_AdminVar::isLibrarianReviewsModerated());
Patrick Barroca's avatar
Patrick Barroca committed
70
  }
71 72


Patrick Barroca's avatar
Patrick Barroca committed
73
  public function isVisibleForUser($user) {
74
    if (!$this->getUser())
Patrick Barroca's avatar
Patrick Barroca committed
75
      return $this->hasBeenModerated();
76

77 78
    return ($user && ($this->getIdUser() == $user->ID_USER))
      ? true
Patrick Barroca's avatar
Patrick Barroca committed
79 80 81 82 83 84
      : $this->hasBeenModerated();
  }


  public function hasBeenModerated() {
    return !$this->isWaitingForModeration();
Patrick Barroca's avatar
Patrick Barroca committed
85
  }
86 87


Patrick Barroca's avatar
Patrick Barroca committed
88 89 90
  public function isWrittenByAbonne() {
    return $this->getAbonOuBib() == self::$AVIS_ABONNE;
  }
91

Patrick Barroca's avatar
Patrick Barroca committed
92

93 94 95 96
  public function isOrphan() {
    return $this->getFlags() == self::ORPHAN_FLAG ;
  }

Patrick Barroca's avatar
Patrick Barroca committed
97

98 99 100
  public function isArchived() {
    return $this->getFlags() == self::ARCHIVED_FLAG ;
  }
101

Patrick Barroca's avatar
Patrick Barroca committed
102

Patrick Barroca's avatar
Patrick Barroca committed
103 104 105
  public function beWrittenByAbonne() {
    return $this->setAbonOuBib(self::$AVIS_ABONNE);
  }
106 107


Patrick Barroca's avatar
Patrick Barroca committed
108 109 110
  public function isWrittenByBibliothecaire() {
    return $this->getAbonOuBib() == self::$AVIS_BIBLIO;
  }
111 112


Patrick Barroca's avatar
Patrick Barroca committed
113 114 115
  public function beWrittenByBibliothecaire() {
    return $this->setAbonOuBib(self::$AVIS_BIBLIO);
  }
116 117


Patrick Barroca's avatar
Patrick Barroca committed
118 119 120
  public function isModerationOK() {
    return $this->getStatut() == self::$STATUT_OK;
  }
121 122


Patrick Barroca's avatar
Patrick Barroca committed
123 124 125
  public function setModerationOK() {
    return $this->setStatut(self::$STATUT_OK);
  }
126 127


Patrick Barroca's avatar
Patrick Barroca committed
128 129 130 131 132
  public function isModerationNOK() {
    return $this->getStatut() == self::$STATUT_NOK;
  }


Patrick Barroca's avatar
Patrick Barroca committed
133 134 135
  public function setModerationNOK() {
    return $this->setStatut(self::$STATUT_NOK);
  }
136 137


Patrick Barroca's avatar
Patrick Barroca committed
138 139 140
  public function isAvisNotice() {
    return 'notices_avis' == $this->_table_name;
  }
141 142 143 144 145 146


  public function setFlagArchived() {
    $this->setFlags(static::ARCHIVED_FLAG);
    return $this;
  }
147
}