dmBridge PHP API
UNLVRandomCPController.php
00001 <?php
00002 #
00003 # UNLVRandom: a dmBridge module for random objects
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 UNLVRandomCPController extends DMCPAdminController {
00014 
00015    public function index() {
00016       $this->preFlightCheck();
00017       $ds = UNLVRandomObject::getDataStore();
00018 
00019       if (DMHTTPRequest::getCurrent()->getMethod() == DMHTTPMethod::POST) {
00020          $flash = new DMFlash(
00021                DMLocalizedString::getString("NO_OBJECT_SELECTED"),
00022                false);
00023          $rep = DMHTTPRequest::getCurrent()->getRepresentation();
00024          if (is_array($rep->getFormValue("objects"))) {
00025             foreach ($rep->getFormValue("objects") as $obj) {
00026                $tmp = explode(DMAbstractForm::ALIAS_PTR_SEPARATOR, $obj);
00027                $col = DMCollectionFactory::getCollection(
00028                      DMCollection::getSanitizedAlias($tmp[0]));
00029                $obj = DMObjectFactory::getObject($col, (int) $tmp[1]);
00030                $ds->deleteRandomObject($obj);
00031                $flash = new DMFlash(
00032                      DMLocalizedString::getString(
00033                            "RANDOM_OBJECT_DELETED",
00034                            dirname(__FILE__) . "/../strings.txt"),
00035                      true);
00036             }
00037          }
00038          DMHTTPRequest::getCurrent()->getSession()->setFlash($flash);
00039          DMHTTPRequest::reload();
00040          die;
00041       }
00042 
00043       $this->tpl_vars['random_objects'] = $ds->getRandomObjects();
00044 
00045       $this->renderModuleTemplate(
00046                dirname(__FILE__) . "/../cp_templates/index.html.php");
00047       die;
00048    }
00049 
00050    public function add() {
00051       $this->preFlightCheck();
00052 
00053       $form = new UNLVRandomAddForm();
00054       $this->setForm($form);
00055       if (DMHTTPRequest::getCurrent()->getMethod() == DMHTTPMethod::POST) {
00056          $this->handleForm(DMLocalizedString::getString(
00057                "RANDOM_OBJECT_ADDED",
00058                dirname(__FILE__) . "/../strings.txt"));
00059       }
00060 
00061       $this->tpl_vars['alias'] = $form->getFieldByName('alias')->getHTMLTag();
00062       $this->tpl_vars['ptr'] = $form->getFieldByName('ptr')->getHTMLTag();
00063 
00064       $this->renderModuleTemplate(
00065                dirname(__FILE__) . "/../cp_templates/add.html.php");
00066       die;
00067    }
00068 
00069 }
00070 
 All Data Structures Functions Variables