dmBridge PHP API
DMObjectView.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 DMObjectView extends DMTemplateEngineView implements DMURIAddressable {
00016 
00020    private $comment_form;
00021 
00025    private $object;
00026 
00030    private $query;
00031 
00035    private $tag_form;
00036 
00044    public function __construct(DMTemplate $tpl, DMSession $session,
00045          DMObject $obj, DMObjectQuery $query = null) {
00046       parent::__construct($tpl, $session, $obj->getCollection());
00047       $this->setHelper(new DMObjectTemplateHelper($this, $session));
00048       $this->setCommentForm(new DMObjectCommentForm());
00049       $this->setTagForm(new DMTagForm());
00050       $this->object = $obj;
00051       $this->query = $query;
00052       $obj->getViewer()->setHelper($this->getHelper());
00053       $obj->getViewer()->viewerWillRender();
00054    }
00055 
00059    public function getCommentForm() {
00060       return $this->comment_form;
00061    }
00062 
00066    public function setCommentForm(DMObjectCommentForm $form) {
00067       $this->comment_form = $form;
00068    }
00069 
00073    public function getObject() {
00074       return $this->object;
00075    }
00076 
00080    public function setObject(DMObject $obj) {
00081       $this->object = $obj;
00082    }
00083 
00087    public function getQuery() {
00088       return $this->query;
00089    }
00090 
00094    public function setQuery(DMObjectQuery $query) {
00095       $this->query = $query;
00096    }
00097 
00104    public function getResultsView() {
00105       return $this->getSession()->getResultsView();
00106    }
00107 
00111    public function getTagForm() {
00112       return $this->tag_form;
00113    }
00114 
00118    public function setTagForm(DMTagForm $form) {
00119       $this->tag_form = $form;
00120    }
00121 
00126    public function getURI() {
00127       return $this->getObject()->getURI();
00128    }
00129 
00138    public function getViewForNextObject() {
00139       if (!$this->getQuery()) {
00140          return null;
00141       }
00142       $all = $this->getQuery()->getSearchResults();
00143       $count = count($all);
00144       for ($i = 0; $i < $count; $i++) {
00145          if ($all[$i]->equals($this->object)) {
00146             if (array_key_exists($i + 1, $all)) {
00147                return new DMObjectView($this->getTemplate(),
00148                      $this->getSession(), $all[$i + 1],
00149                      $this->getQuery());
00150             }
00151          }
00152       }
00153       return null;
00154    }
00155 
00164    public function getViewForPreviousObject() {
00165       if (!$this->getQuery()) {
00166          return null;
00167       }
00168       $all = $this->getQuery()->getSearchResults();
00169       $count = count($all);
00170       for ($i = 0; $i < $count; $i++) {
00171          if ($all[$i]->equals($this->object)) {
00172             if (array_key_exists($i - 1, $all)) {
00173                return new DMObjectView($this->getTemplate(),
00174                      $this->getSession(), $all[$i - 1],
00175                      $this->getQuery());
00176             }
00177          }
00178       }
00179       return null;
00180    }
00181 
00187    public function getViewerDefinitionForMediaType($type) {
00188       return $this->object->getCollection()
00189                   ->getViewerDefinitionForMediaType($type);
00190    }
00191 
00192 }
00193 
 All Data Structures Functions Variables