dmBridge PHP API
DMAbstractQuery.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 
00013 abstract class DMAbstractQuery {
00014 
00016    private $only_count = false;
00018    private $page = 1;
00020    protected $results_per_page = 20;
00022    private $collections = array();
00024    protected $results = array();
00026    protected $num_results = 0;
00028    private $objects;
00030    private $predicates = array();
00032    private $sort_fields = array();
00033 
00034 
00035    public function __construct() {
00036    }
00037 
00043    public function getCollections() {
00044       return $this->collections;
00045    }
00046 
00052    public function addCollection(DMCollection $collection) {
00053       $this->collections[] = $collection;
00054    }
00055 
00062    public function setCollections(array $collections) {
00063       foreach ($collections as $c) {
00064          if (!$c instanceof DMCollection) {
00065             throw new DMIllegalArgumentException(
00066                DMLocalizedString::getString("INVALID_COLLECTION"));
00067          }
00068       }
00069       $this->collections = $collections;
00070    }
00071 
00075    public function unsetCollections() {
00076       $this->collections = array();
00077    }
00078 
00083    public function onlyCount() {
00084       return $this->only_count;
00085    }
00086 
00092    public function getLimit() {
00093       return $this->results_per_page;
00094    }
00095 
00099    public function setLimit($limit) {
00100       $this->results_per_page = abs($limit);
00101    }
00102 
00107    public function setOnlyCount($bool) {
00108       $this->only_count = (bool) $bool;
00109    }
00110 
00114    public function getNumPages() {
00115       if ($this->getNumResultsPerPage() > 0) {
00116          return ceil($this->getNumResults() / $this->getNumResultsPerPage());
00117       }
00118       return 0;
00119    }
00120 
00124    public function getNumResults() {
00125       return $this->num_results;
00126    }
00127 
00131    protected function setNumResults($int) {
00132       $this->num_results = abs($int);
00133    }
00134 
00139    public function getNumResultsPerPage() {
00140       return $this->getLimit();
00141    }
00142 
00147    public function setNumResultsPerPage($rpp) {
00148       $this->setLimit($rpp);
00149    }
00150 
00155    public function addObject(DMObject $obj) {
00156       $this->objects[] = $obj;
00157    }
00158 
00163    public function getObjects() {
00164       return $this->objects;
00165    }
00166 
00170    public function getPage() {
00171       return $this->page;
00172    }
00173 
00177    public function setPage($int) {
00178       $this->page = abs((int) substr($int, 0, 8));
00179       if ($this->page < 1) {
00180          $this->page = 1;
00181       }
00182    }
00183 
00187    public function addPredicate(DMQueryPredicate $predicate) {
00188       $this->predicates[] = $predicate;
00189    }
00190 
00196    public function getPredicates($index = null) {
00197       if (array_key_exists($index, $this->predicates)) {
00198          return $this->predicates[$index];
00199       }
00200       return $this->predicates;
00201    }
00202 
00207    public function setPredicates(array $predicates) {
00208       $this->unsetPredicates();
00209       foreach ($predicates as $t) {
00210          if ($t instanceof DMQueryPredicate) {
00211             $this->addPredicate($t);
00212          } else {
00213             throw new DMIllegalArgumentException();
00214          }
00215       }
00216    }
00217 
00221    public function unsetPredicates() {
00222       $this->predicates = array();
00223    }
00224 
00229    public function getSortFields() {
00230       return $this->sort_fields;
00231    }
00232 
00237    public function setSortFields(array $fields) {
00238       $this->sort_fields = $fields;
00239    }
00240 
00244    public function getStart() {
00245       return ($this->getPage() - 1) * $this->getNumResultsPerPage();
00246    }
00247 
00248 }
 All Data Structures Functions Variables