dmBridge PHP API
DMTagQuery.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 
00015 class DMTagQuery extends DMAbstractSocialDataQuery implements DMDataStoreQuery,
00016       DMURIAddressable {
00017 
00018    const DEFAULT_LIMIT = 50;
00019 
00021    private $sort_by_frequency;
00022 
00028    public function getSearchResults() {
00029       return $this->getSearchResultsAsObjects();
00030    }
00031 
00035    public function getSearchResultsAsCounts() {
00036       $this->setNumResults(
00037             $this->getDataStore()->getTagsForQueryAsCounts($this, true));
00038       return $this->getDataStore()->getTagsForQueryAsCounts($this, false);
00039    }
00040 
00044    public function getSearchResultsAsObjects() {
00045       $this->setNumResults(
00046             $this->getDataStore()->getTagsForQueryAsObjects($this, true));
00047       return $this->getDataStore()->getTagsForQueryAsObjects($this, false);
00048    }
00049 
00053    public final function isSortingByFrequency() {
00054       return $this->sort_by_frequency;
00055    }
00056 
00060    public final function setSortByFrequency($bool) {
00061       $this->sort_by_frequency = (bool) $bool;
00062    }
00063 
00067    public function getURI() {
00068       $terms = $this->getPredicates();
00069       $collections = $this->getCollections();
00070       $objects = $this->getObjects();
00071       $query = array();
00072       for ($i = 0; $i < count($collections); $i++) {
00073          $query['alias' . $i] = $collections[$i]->getAlias();
00074       }
00075       for ($i = 0; $i < count($objects); $i++) {
00076          $query['objects' . $i] = sprintf("%s,%d",
00077                $objects[$i]->getCollection()->getAlias(),
00078                $objects[$i]->getPtr());
00079       }
00080       if ($this->getPage() > 1) {
00081          $query['page'] = $this->getPage();
00082       }
00083       if ($this->getLimit() != self::DEFAULT_LIMIT) {
00084          $query['rpp'] = $this->getLimit();
00085       }
00086       if (count($terms)) {
00087          $query['term'] = $terms[0];
00088       }
00089       if (!$this->isSortingByFrequency()) {
00090          $query['sort'] = "random";
00091       }
00092 
00093       return DMInternalURI::getURIWithParams("tags/search", $query);
00094    }
00095 
00096 }
 All Data Structures Functions Variables