dmBridge PHP API
DMDCElement.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 DMDCElement extends DMModel {
00016 
00017    private static $dc_fields = array(
00018       array(
00019          'name' => 'Title',
00020          'nick' => 'title',
00021          'type' => 'TEXT',
00022          'size' => 0,
00023          'search' => 1,
00024          'hide' => 0,
00025          'vocab' => 0,
00026          'dc' => 'title'
00027       ),
00028       array(
00029          'name' => 'Subject',
00030          'nick' => 'subjec',
00031          'type' => 'TEXT',
00032          'size' => 0,
00033          'search' => 1,
00034          'hide' => 0,
00035          'vocab' => 0,
00036          'dc' => 'subjec'
00037       ),
00038       array(
00039          'name' => 'Description',
00040          'nick' => 'descri',
00041          'type' => 'TEXT',
00042          'size' => 0,
00043          'search' => 1,
00044          'hide' => 0,
00045          'vocab' => 0,
00046          'dc' => 'descri'
00047       ),
00048       array(
00049          'name' => 'Creator',
00050          'nick' => 'creato',
00051          'type' => 'TEXT',
00052          'size' => 0,
00053          'search' => 1,
00054          'hide' => 0,
00055          'vocab' => 1,
00056          'dc' => 'creato'
00057       ),
00058       array(
00059          'name' => 'Publisher',
00060          'nick' => 'publis',
00061          'type' => 'TEXT',
00062          'size' => 0,
00063          'search' => 1,
00064          'hide' => 0,
00065          'vocab' => 1,
00066          'dc' => 'publis'
00067       ),
00068       array(
00069          'name' => 'Contributors',
00070          'nick' => 'contri',
00071          'type' => 'TEXT',
00072          'size' => 0,
00073          'search' => 1,
00074          'hide' => 0,
00075          'vocab' => 0,
00076          'dc' => 'contri'
00077       ),
00078       array(
00079          'name' => 'Date',
00080          'nick' => 'date',
00081          'type' => 'DATE',
00082          'size' => 0,
00083          'search' => 1,
00084          'hide' => 0,
00085          'vocab' => 0,
00086          'dc' => 'datea'
00087       ),
00088       array(
00089          'name' => 'Type',
00090          'nick' => 'type',
00091          'type' => 'TEXT',
00092          'size' => 0,
00093          'search' => 1,
00094          'hide' => 0,
00095          'vocab' => 0,
00096          'dc' => 'type'
00097       ),
00098       array(
00099          'name' => 'Format',
00100          'nick' => 'format',
00101          'type' => 'TEXT',
00102          'size' => 0,
00103          'search' => 1,
00104          'hide' => 0,
00105          'vocab' => 0,
00106          'dc' => 'format'
00107       ),
00108       array(
00109          'name' => 'Identifier',
00110          'nick' => 'identi',
00111          'type' => 'TEXT',
00112          'size' => 0,
00113          'search' => 1,
00114          'hide' => 0,
00115          'vocab' => 0,
00116          'dc' => 'identi'
00117       ),
00118       array(
00119          'name' => 'Source',
00120          'nick' => 'source',
00121          'type' => 'TEXT',
00122          'size' => 0,
00123          'search' => 1,
00124          'hide' => 0,
00125          'vocab' => 0,
00126          'dc' => 'identi'
00127       ),
00128       array(
00129          'name' => 'Language',
00130          'nick' => 'langua',
00131          'type' => 'TEXT',
00132          'size' => 0,
00133          'search' => 1,
00134          'hide' => 1,
00135          'vocab' => 0,
00136          'dc' => 'langua'
00137       ),
00138       array(
00139          'name' => 'Relation',
00140          'nick' => 'relati',
00141          'type' => 'TEXT',
00142          'size' => 0,
00143          'search' => 1,
00144          'hide' => 0,
00145          'vocab' => 0,
00146          'dc' => 'langua'
00147       ),
00148       array(
00149          'name' => 'Coverage',
00150          'nick' => 'covera',
00151          'type' => 'TEXT',
00152          'size' => 0,
00153          'search' => 1,
00154          'hide' => 0,
00155          'vocab' => 0,
00156          'dc' => 'covera'
00157       ),
00158       array(
00159          'name' => 'Rights',
00160          'nick' => 'rights',
00161          'type' => 'TEXT',
00162          'size' => 0,
00163          'search' => 1,
00164          'hide' => 0,
00165          'vocab' => 1,
00166          'dc' => 'rights'
00167       )
00168    );
00169 
00171    private $collection;
00173    private $controlled = false, $hidden = false,
00174       $searchable = false, $sortable = false, $is_default_sort = false;
00176    private $dc_nick;
00178    private $maxwords;
00180    private $name;
00182    private $nick;
00184    private $type;
00186    private $value;
00187 
00193    public static function getAll() {
00194       $return = array();
00195       foreach (self::$dc_fields as $f) {
00196          $field = new DMDCElement($f['nick']);
00197          $field->setName($f['name']);
00198          $field->setControlled($f['vocab']);
00199          $field->setSearchable($f['search']);
00200          $field->setHidden($f['hide']);
00201          $field->setDCNick($f['dc']);
00202          $field->setType($f['type']);
00203          $return[] = $field;
00204       }
00205       return $return;
00206    }
00207 
00212    public static function getNameForDCNick($nick) {
00213       foreach (self::$dc_fields as $field) {
00214          if (strtolower($field['nick']) == strtolower($nick)) {
00215             return $field['name'];
00216          }
00217       }
00218       return null;
00219    }
00220 
00225    public function __construct($nick) {
00226       $this->setNick($nick);
00227    }
00228 
00234    public function __toString() {
00235       return (string) $this->getValue();
00236    }
00237 
00242    public function getCollection() {
00243       return $this->collection;
00244    }
00245 
00250    public function setCollection(DMCollection $c) {
00251       $this->collection = $c;
00252    }
00253 
00258    public function isControlled() {
00259       return $this->controlled;
00260    }
00261 
00266    public function setControlled($bool) {
00267       $this->controlled = ($bool);
00268    }
00269 
00274    public function getDCName() {
00275       return self::getNameForDCNick($this->getDCNick());
00276    }
00277 
00282    public function getDCNick() {
00283       return $this->dc_nick;
00284    }
00285 
00290    public function setDCNick($nick) {
00291       $this->dc_nick = $nick;
00292    }
00293 
00298    public function isDefaultSort() {
00299       return $this->is_default_sort;
00300    }
00301 
00306    public function setDefaultSort($bool) {
00307       $this->is_default_sort = ($bool);
00308    }
00309 
00314    public function isHidden() {
00315       return $this->hidden;
00316    }
00317 
00322    public function setHidden($bool) {
00323       $this->hidden = ($bool);
00324    }
00325 
00330    public function getMaxWords() {
00331       return $this->maxwords;
00332    }
00333 
00338    public function setMaxWords($maxwords) {
00339       $this->maxwords = (int) $maxwords;
00340    }
00341 
00346    public function getName() {
00347       return $this->name;
00348    }
00349 
00354    public function setName($name) {
00355       $this->name = $name;
00356    }
00357 
00362    public function getNick() {
00363       return $this->nick;
00364    }
00365 
00370    public function setNick($nick) {
00371       $this->nick = $nick;
00372    }
00373 
00378    public function isSearchable() {
00379       return $this->searchable;
00380    }
00381 
00386    public function isSortable() {
00387       return $this->sortable;
00388    }
00389 
00394    public function setSearchable($bool) {
00395       $this->searchable = ($bool);
00396    }
00397 
00402    public function setSortable($bool) {
00403       $this->sortable = ($bool);
00404    }
00405 
00410    public function getType() {
00411       return $this->type;
00412    }
00413 
00420    public function setType($type) {
00421       if (!in_array($type, array("TEXT", "FTS", "FULLRES", "DATE"))) {
00422          throw new DMIllegalArgumentException("");
00423       }
00424       $this->type = $type;
00425    }
00426 
00431    public function getValue() {
00432       return $this->value;
00433    }
00434 
00439    public function setValue($value) {
00440       $this->value = (string) $value;
00441    }
00442 
00456    public function getVocabulary($dict = true, $include_unused = false) {
00457       if ($this->getCollection()) {
00458          return dmGetCollectionFieldVocabulary(
00459             $this->getCollection()->getAlias(), $this->getNick(),
00460             (int) $dict, (int) $include_unused);
00461       }
00462       return array();
00463    }
00464 
00465 }
 All Data Structures Functions Variables