dmBridge PHP API
UNLVHighlightCPController.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 UNLVHighlightCPController extends DMCPAdminController {
00014 
00015    public function index() {
00016       $this->preFlightCheck();
00017 
00018       if ($this->getHTTPRequest()->getMethod() == DMHTTPMethod::POST) {
00019          $this->delete();
00020       }
00021 
00022       $ds = UNLVHighlightDataStoreFactory::getDataStore();
00023       $this->tpl_vars['highlighted_objects'] = $ds->getHighlightedObjects();
00024       $this->tpl_vars['highlighted_object'] = $ds->getHighlightedObject();
00025 
00026       $this->renderModuleTemplate(
00027                dirname(__FILE__) . "/../cp_templates/index.html.php");
00028       die;
00029    }
00030 
00031    public function add() {
00032       $this->preFlightCheck();
00033 
00034       $this->setForm(new UNLVHighlightAddForm());
00035 
00036       if (DMHTTPRequest::getCurrent()->getMethod() == DMHTTPMethod::POST) {
00037          $this->handleForm(DMLocalizedString::getString(
00038                      "HIGHLIGHTED_OBJECT_ADDED",
00039                      dirname(__FILE__) . "/../strings.txt"));
00040       }
00041 
00042       $this->tpl_vars['alias'] = $this->getForm()->getFieldByName("alias")
00043             ->getHTMLTag();
00044       $this->tpl_vars['ptr'] = $this->getForm()->getFieldByName("ptr")
00045             ->getHTMLTag();
00046       $this->tpl_vars['year'] = $this->getForm()->getFieldByName("year")
00047             ->getHTMLTag();
00048       $this->tpl_vars['month'] = $this->getForm()->getFieldByName("month")
00049             ->getHTMLTag();
00050       $this->tpl_vars['day'] = $this->getForm()->getFieldByName("day")
00051             ->getHTMLTag();
00052       
00053       $this->renderModuleTemplate(
00054                dirname(__FILE__) . "/../cp_templates/add.html.php");
00055       die;
00056    }
00057 
00058    private function delete() {
00059       $rep = $this->getHTTPRequest()->getRepresentation();
00060       $dates = $rep->getFormValues("dates");
00061       $ds = UNLVHighlightDataStoreFactory::getDataStore();
00062       try {
00063          foreach ($dates as $date) {
00064             $date = new DMDateTime($date);
00065             $ds->deleteHighlightedObjectsOnDate($date);
00066          }
00067          $this->getSession()->setFlash(new DMFlash(
00068                DMLocalizedString::getString(
00069                      "HIGHLIGHTED_OBJECT_DELETED",
00070                      dirname(__FILE__) . "/../strings.txt"),
00071                true));
00072       } catch (DMIOException $e) {
00073          $this->getSession()->setFlash(
00074                new DMFlash($e->getMessage(), false));
00075       }
00076    }
00077 
00078 }
00079 
 All Data Structures Functions Variables