dmBridge PHP API
DMQueryPredicate.php
00001 <?php
00002 #
00003 # dmBridge: a data access framework for CONTENTdm(R)
00004 #
00005 # Copyright © 2009, 2010 Board of Regents of the Nevada System of Higher
00006 # Education, on behalf of the University of Nevada, Las Vegas
00007 #
00008 
00016 class DMQueryPredicate {
00017 
00018    private static $valid_modes = array('all', 'exact', 'any', 'none');
00019 
00021    private $field;
00023    private $is_date = false;
00025    private $is_proximity = false;
00027    private $mode;
00029    private $string;
00030 
00031 
00035    public static final function getValidModes() {
00036       return self::$valid_modes;
00037    }
00038 
00042    public function __toString() {
00043       return (string) $this->getString();
00044    }
00045 
00050    public final function isBrowse() {
00051       if ($this->getField() == "any" && $this->getMode() == "any"
00052             && strlen($this->getString()) < 1) {
00053          return true;
00054       }
00055       return false;
00056    }
00057 
00062    public final function isDate() {
00063       return $this->is_date;
00064    }
00065 
00070    public final function setDate($bool) {
00071       $this->is_date = ($bool);
00072    }
00073 
00077    public final function getField() {
00078       return $this->field;
00079    }
00080 
00084    public final function setField(DMDCElement $field) {
00085       $this->field = $field;
00086    }
00087 
00091    public final function getMode() {
00092       return $this->mode;
00093    }
00094 
00100    public final function setMode($mode) {
00101       if (!in_array($mode, self::getValidModes())) {
00102          throw new DMIllegalArgumentException(
00103             sprintf(DMLocalizedString::getString("INVALID_MODE"),
00104                implode(', ', self::getValidModes())));
00105       }
00106       $this->mode = $mode;
00107    }
00108 
00113    public final function isProximity() {
00114       return $this->is_proximity;
00115    }
00116 
00121    public final function setProximity($bool) {
00122       $this->is_proximity = ($bool);
00123    }
00124 
00129    public final function getString() {
00130       return $this->string;
00131    }
00132 
00137    public final function setString($string) {
00138       $this->string = trim($string);
00139    }
00140 
00145    public final function isValid() {
00146       if (!in_array($this->getMode(), self::getValidModes())) {
00147          return false;
00148       }
00149       if (!$this->getField()) {
00150          return false;
00151       }
00152       if (strlen($this->getString()) < 1) {
00153          return false;
00154       }
00155       return true;
00156    }
00157 
00158 }
 All Data Structures Functions Variables