dmBridge PHP API
DMAbstractController.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 abstract class DMAbstractController {
00016 
00018    const AUTHENTICATION_DELAY = 4;
00019 
00021    private $form;
00023    private $template_set;
00024 
00025    protected function authorize() {
00026       if (!$this->getUser()) {
00027          DMHTTPRequest::redirectToParams("objects/login");
00028          die;
00029       }
00030    }
00031 
00035    protected function getForm() {
00036       return $this->form;
00037    }
00038 
00042    protected function setForm(DMAbstractForm $form) {
00043       $this->form = $form;
00044    }
00045 
00049    protected final function getHTTPRequest() {
00050       return DMHTTPRequest::getCurrent();
00051    }
00052 
00056    protected final function getTemplateSet() {
00057       return $this->template_set;
00058    }
00059 
00063    public final function setTemplateSet(DMTemplateSet $set) {
00064       $this->template_set = $set;
00065    }
00066 
00071    protected function handleForm($flash_msg = null, $dest_params = null) {
00072       try {
00073          $this->getForm()->validate();
00074          $this->getForm()->doAction();
00075          $flash_msg = ($flash_msg)
00076             ? $flash_msg : DMLocalizedString::getString("PREFS_UPDATED");
00077          $this->getSession()->setFlash(
00078                new DMFlash($flash_msg, true));
00079          if ($dest_params) {
00080             DMHTTPRequest::redirectToParams($dest_params);
00081          } else {
00082             DMHTTPRequest::reload();
00083          }
00084          die;
00085       } catch (Exception $e) {
00086          $flash_msg = $e->getMessage();
00087       }
00088       $this->getSession()->setFlash(
00089             new DMFlash($flash_msg, false));
00090    }
00091 
00095    protected final function getSession() {
00096       return $this->getHTTPRequest()->getSession();
00097    }
00098 
00102    protected final function getUser() {
00103       return $this->getSession()->getUser();
00104    }
00105 
00106 }
 All Data Structures Functions Variables