dmBridge PHP API
DMCPTemplateController.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 
00013 class DMCPTemplateController extends DMCPAdminController {
00014 
00015    public function add() {
00016       $this->preFlightCheck();
00017       $ts = new DMTemplateSet();
00018       $ts->setName("New Template Set");
00019 
00020       $form = new DMCPTemplateSetForm($ts);
00021       $this->setForm($form);
00022 
00023       if (DMHTTPRequest::getCurrent()->getMethod() == DMHTTPMethod::POST) {
00024          $this->handleForm(null, "admin/templates");
00025       }
00026 
00027       $this->initAddEditTemplate($ts);
00028    }
00029 
00030    private function delete() {
00031       $this->preFlightCheck();
00032       $rep = DMHTTPRequest::getCurrent()->getRepresentation();
00033       if ($rep->getFormValue("id")) {
00034          try {
00035             $tpl = new DMTemplateSet($rep->getFormValue("id"));
00036             $tpl->delete();
00037             DMHTTPRequest::getCurrent()->getSession()->setFlash(new DMFlash(
00038                   DMLocalizedString::getString("TEMPLATE_SET_DELETED"),
00039                   true));
00040          } catch (DMException $e) {
00041             DMHTTPRequest::getCurrent()->getSession()->setFlash(
00042                   new DMFlash($e->getMessage(), false));
00043          }
00044       }
00045    }
00046 
00047    public function edit($id) {
00048       $this->preFlightCheck();
00049       $id = (int) $id;
00050       $ts = new DMTemplateSet($id);
00051 
00052       $form = new DMCPTemplateSetForm($ts);
00053       $this->setForm($form);
00054 
00055       if (DMHTTPRequest::getCurrent()->getMethod() == DMHTTPMethod::POST) {
00056          $this->handleForm(
00057                DMLocalizedString::getString("TEMPLATE_SET_UPDATED"),
00058                "admin/templates");
00059       }
00060 
00061       $this->initAddEditTemplate($ts);
00062    }
00063 
00064    private function initAddEditTemplate(DMTemplateSet $ts) {
00065       $form = $this->getForm();
00066       try {
00067          // template set info
00068          $this->tpl_vars['template_set'] = $ts;
00069          $this->tpl_vars['all_collections'] = array_merge(
00070                array(DMCollectionFactory::getCollection("/dmdefault")),
00071                DMCollection::getAuthorized());
00072          foreach ($form->getFieldsByName("allowed_collections") as $field) {
00073             $this->tpl_vars['allowed_collections'][] = $field->getHTMLTag();
00074          }
00075          foreach ($form->getFieldsByName("default_collection") as $field) {
00076             $this->tpl_vars['default_collection'][] = $field->getHTMLTag();
00077          }
00078          $this->tpl_vars['name'] = $form->getFieldByName("name")->getHTMLTag();
00079 
00080          // results per page
00081          $this->tpl_vars['results_per_page']
00082                = $form->getFieldByName("results_per_page")->getHTMLTag();
00083 
00084          // tile view
00085          $this->tpl_vars['tile_cols'] = $form
00086                ->getFieldByName("tile_cols")->getHTMLTag();
00087       } catch (DMException $e) {
00088          DMHTTPRequest::getCurrent()->getSession()->setFlash(
00089                new DMFlash($e->getMessage(), false));
00090       }
00091 
00092       $this->renderTemplate("/templates/template/edit.html.php");
00093       die;
00094    }
00095 
00096    public function index() {
00097       $this->preFlightCheck();
00098 
00099       if (DMHTTPRequest::getCurrent()->getMethod() == DMHTTPMethod::POST) {
00100          $this->delete();
00101       }
00102 
00103       $this->renderTemplate("/templates/template/index.html.php");
00104       die;
00105    }
00106 
00107 }
00108 
 All Data Structures Functions Variables