dmBridge PHP API
DMRating.php
00001 <?php
00002 #
00003 # dmBridge: a data access framework for CONTENTdm(R)
00004 #
00005 # Copyright © 2009, 2010, 2011 Board of Regents of the Nevada System of Higher
00006 # Education, on behalf of the University of Nevada, Las Vegas
00007 #
00008 
00018 class DMRating extends DMAbstractSocialEntity implements DMSocialEntity {
00019 
00020    private $max;
00021 
00022 
00032    public function __construct($value, $max) {
00033       parent::__construct();
00034       $this->setApproved(true);
00035       if ($value > $max) {
00036          throw new DMIllegalArgumentException(
00037             DMLocalizedString::getString('RATING_LARGER_THAN_MAX'));
00038       }
00039       $this->setValue($value);
00040       $this->setMax($max);
00041    }
00042 
00051    public function __toString() {
00052       return (string) round($this->getValue(), 2);
00053    }
00054 
00058    public final function getMax() {
00059       return $this->max;
00060    }
00061 
00066    public final function setMax($max) {
00067       if ((!is_numeric($max) or $max <= 0)
00068             or (!is_null($this->getValue()) && $max < $this->getValue())) {
00069          throw new DMIllegalArgumentException(
00070             DMLocalizedString::getString('INVALID_MAX_RATING'));
00071       }
00072       $this->max = (float) $max;
00073    }
00074 
00080    public final function getNormalizedValue() {
00081       return (float) $this->getValue() * (100 / $this->getMax());
00082    }
00083 
00089    public function getURI() {
00090       return null;
00091    }
00092 
00097    public function setValue($float) {
00098       if (!is_numeric($float) || $float < 0) {
00099          throw new DMIllegalArgumentException(
00100             DMLocalizedString::getString('INVALID_RATING'));
00101       }
00102       $this->value = (float) $float;
00103    }
00104 
00105 }
 All Data Structures Functions Variables