dmBridge PHP API
DMTemplateSet.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 class DMTemplateSet extends DMModel {
00014 
00016    private $authorized_collections = array();
00018    private $default_collection;
00020    private $grid_view_fields = array();
00022    private $has_been_loaded = false;
00024    private $name;
00026    private $num_results_per_page;
00028    private $num_tile_columns;
00030    private $id;
00032    private $pathname;
00034    private $templates = array();
00035 
00036 
00046    public function __construct($id = null) {
00047       if (!is_null($id) && $id >= 0 && round($id) == $id) {
00048          $this->setID($id);
00049          $this->load();
00050       }
00051    }
00052 
00060    public function __toString() {
00061       return (string) $this->getName();
00062    }
00063 
00068    public function addAuthorizedCollection(DMCollection $c) {
00069       $match = false;
00070       foreach ($this->authorized_collections as $col) {
00071          if ($col->equals($c)) {
00072             $match = true;
00073          }
00074       }
00075       if (!$match) {
00076          $this->authorized_collections[] = $c;
00077       }
00078    }
00079 
00084    public function getAuthorizedCollections() {
00085       return $this->authorized_collections;
00086    }
00087 
00092    public function unsetAuthorizedCollections() {
00093       $this->authorized_collections = array();
00094    }
00095 
00102    public function isAuthorizedToViewCollection(DMCollection $c) {
00103       $aliases = array();
00104       $authorized = $this->getAuthorizedCollections();
00105       if (count($authorized) < 1) {
00106          return true;
00107       }
00108       foreach ($authorized as $tmp) {
00109          $aliases[] = $tmp->getAlias();
00110       }
00111       return (in_array($c->getAlias(), $aliases));
00112    }
00113 
00122    public function delete() {
00123       DMConfigXML::getInstance()->deleteTemplateSet($this);
00124       unset($this);
00125    }
00126 
00127    private function load() {
00128       if (!$this->has_been_loaded) {
00129          DMConfigXML::getInstance()->loadTemplateSet($this);
00130          $this->has_been_loaded = true;
00131       }
00132    }
00133 
00138    public function getDefaultCollection() {
00139       return $this->default_collection;
00140    }
00141 
00146    public function setDefaultCollection(DMCollection $col) {
00147       if ($col->getAlias() == "/dmdefault") {
00148          throw new DMIllegalArgumentException(
00149             DMLocalizedString::getString("INVALID_COLLECTION"));
00150       }
00151       $this->default_collection = $col;
00152    }
00153 
00161    public function getErrorTemplate() {
00162       $tpl = "/templates/error/view.html.php";
00163       $system = "/../system/error.html.php";
00164       $check_path = $_SERVER['DOCUMENT_ROOT'] . $this->getPath() . $tpl;
00165       $path = (file_exists($check_path)) ? $tpl : $system;
00166       return new DMTemplate($this, $path);
00167    }
00168 
00172    public function addGridViewField(DMDCElement $f) {
00173       $this->grid_view_fields[] = $f;
00174    }
00175 
00179    public function getGridViewFields() {
00180       return $this->grid_view_fields;
00181    }
00182 
00186    public function unsetGridViewFields() {
00187       $this->grid_view_fields = array();
00188    }
00189 
00194    public function getID() {
00195       return $this->id;
00196    }
00197 
00202    public function setID($id) {
00203       $this->id = $id;
00204    }
00205 
00210    public function getName() {
00211       return $this->name;
00212    }
00213 
00218    public function setName($str) {
00219       $this->name = (string) $str;
00220    }
00221 
00225    public function getNumResultsPerPage() {
00226       return $this->num_results_per_page;
00227    }
00228 
00232    public function setNumResultsPerPage($rpp) {
00233       $this->num_results_per_page = (int) $rpp;
00234    }
00235 
00239    public function getNumTileViewColumns() {
00240       return $this->num_tile_columns;
00241    }
00242 
00246    public function setNumTileViewColumns($int) {
00247       $this->num_tile_columns = (int) $int;
00248    }
00249 
00253    public function unsetNumTileViewColumns() {
00254       $this->num_tile_columns = null;
00255    }
00256 
00261    public function getPath() {
00262       if ($this->pathname) {
00263          return $this->pathname;
00264       }
00265       return dirname($_SERVER['PHP_SELF']) . "/templates/"
00266             . strtolower(
00267                DMString::paranoid(
00268                   str_replace(' ', '_', $this->getName()),
00269                   array("_", "-")));
00270    }
00271 
00277    public function setPath($path) {
00278       $this->pathname = $path;
00279    }
00280 
00285    public function getTemplates() {
00286       if (!count($this->templates)) {
00287          $all_templates = array(
00288             '/templates/error/view.html.php',
00289             '/templates/favorite/index.html.php',
00290             '/templates/object/no_results.html.php',
00291             '/templates/object/results.html.php',
00292             '/templates/object/results_faceted.html.php',
00293             '/templates/object/view_compound.html.php',
00294             '/templates/object/view_simple.html.php',
00295             '/templates/search/index.html.php',
00296             '/templates/user/login.html.php'
00297          );
00298          foreach ($all_templates as $relative_pathname) {
00299             $this->templates[] = new DMTemplate($this,
00300                $relative_pathname);
00301          }
00302       }
00303       return $this->templates;
00304    }
00305 
00312    public function getTemplateAtPathname($pathname) {
00313       foreach ($this->getTemplates() as $tpl) {
00314          if ($tpl->getRelativePathname() == $pathname) {
00315             return $tpl;
00316          }
00317       }
00318       return null;
00319    }
00320 
00321 }
 All Data Structures Functions Variables