dmBridge PHP API
UNLVHighlightSQLiteDataStore.php
00001 <?php
00002 #
00003 # UNLVHighlight: a dmBridge module for highlighting objects
00004 #
00005 # Copyright © 2011 Board of Regents of the Nevada System of Higher
00006 # Education, on behalf of the University of Nevada, Las Vegas
00007 #
00008 
00013 class UNLVHighlightSQLiteDataStore extends DMSQLiteDataStore
00014 implements UNLVHighlightDataStore {
00015 
00016    private static $instance;
00017 
00023    public static function getHighlightedObjectSQL() {
00024       return "SELECT alias, ptr, datetime FROM highlighted_object
00025          WHERE datetime <= DATETIME('now')
00026          ORDER BY datetime DESC
00027          LIMIT 1";
00028    }
00029 
00033    public static function getHighlightedObjectsSQL() {
00034       return "SELECT alias, ptr, datetime FROM highlighted_object
00035          ORDER BY datetime";
00036    }
00037 
00043    public static function getSetupSQL() {
00044       return array(
00045          'CREATE TABLE "highlighted_object" (
00046             "id" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL ,
00047             "alias" VARCHAR NOT NULL,
00048             "ptr" INTEGER NOT NULL,
00049             "datetime" VARCHAR NOT NULL
00050          );'
00051       );
00052    }
00053 
00059    public static function getUpgradeSQL() {
00060       return array(
00061          // currently empty because there is no previous version from which
00062          // to upgrade.
00063       );
00064    }
00065 
00070    public static function getInstance() {
00071       if (!self::$instance instanceof self) {
00072          self::$instance = new self;
00073       }
00074       return self::$instance;
00075    }
00076 
00081    public function addHighlightedObject(DMObject $obj, DMDateTime $datetime) {
00082       $sql = UNLVHighlightGenericDataStore::addHighlightedObjectSQL();
00083       $params = array(
00084          ':alias' => $obj->getCollection()->getAlias(),
00085          ':ptr' => $obj->getPtr(),
00086          ':datetime' => $datetime->asMySQLDateTime()
00087       );
00088       $this->write($sql, $params);
00089    }
00090 
00094    function deleteHighlightedObjectsOnDate(DMDateTime $date) {
00095       $sql = UNLVHighlightGenericDataStore::getDeleteObjectsSQL();
00096       $params = array(
00097          ':datetime' => $date->asMySQLDateTime()
00098       );
00099       $this->write($sql, $params);
00100    }
00101 
00105    public function getHighlightedObject() {
00106       $sql = self::getHighlightedObjectSQL();
00107       $result = $this->read($sql, array());
00108 
00109       if (count($result)) {
00110          $collection = DMCollectionFactory::getCollection(
00111                $result[0]['alias']);
00112          $obj = DMObjectFactory::getObject($collection, $result[0]['ptr']);
00113          $h_obj = new UNLVHighlightedObject(new DMDateTime($result[0]['datetime']));
00114          $obj->addAssociatedModel($h_obj);
00115          return $obj;
00116       }
00117       return null;
00118    }
00119 
00123    public function getHighlightedObjects() {
00124       $sql = self::getHighlightedObjectsSQL();
00125       $result = $this->read($sql, array());
00126 
00127       $objects = array();
00128       foreach ($result as $row) {
00129          try {
00130             $collection = DMCollectionFactory::getCollection($row['alias']);
00131             $obj = DMObjectFactory::getObject($collection, $row['ptr']);
00132 
00133             $h_obj = new UNLVHighlightedObject(new DMDateTime($row['datetime']));
00134             $obj->addAssociatedModel($h_obj);
00135 
00136             $objects[] = $obj;
00137          } catch (DMUnavailableModelException $e) {
00138             // nothing we can do; skip
00139          }
00140       }
00141       return $objects;
00142    }
00143 
00144 }
 All Data Structures Functions Variables