dmBridge PHP API
DMCPTemplateSetForm.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 DMCPTemplateSetForm extends DMAbstractForm {
00014 
00016    private $template_set;
00017 
00021    public function __construct(DMTemplateSet $ts) {
00022       $this->template_set = $ts;
00023       parent::__construct();
00024    }
00025 
00026    protected function init() {
00027       $f = new DMTextField("name");
00028       $f->addAttribute("id", "name");
00029       $f->addAttribute("size", 30);
00030       $f->setMinLength(2);
00031       $f->setMaxLength(50);
00032       $f->setLabel("Name");
00033       $this->addField($f);
00034 
00035       $f = new DMRadioField("default_collection");
00036       $f->setValue("/dmdefault");
00037       $f->setEnabled(false);
00038       $this->addField($f);
00039 
00040       $f = new DMCheckboxField("allowed_collections");
00041       $f->addAttribute("id", "all_aliases");
00042       $f->setValue("/dmdefault");
00043       $this->addField($f);
00044 
00045       foreach (DMCollection::getAuthorized() as $c) {
00046          $f = new DMRadioField("default_collection");
00047          $f->setValue($c->getAlias());
00048          $this->addField($f);
00049 
00050          $f = new DMCheckboxField("allowed_collections");
00051          $f->setValue($c->getAlias());
00052          $this->addField($f);
00053       }
00054 
00055       // results per page
00056       $f = new DMTextField("results_per_page");
00057       $f->setValue(20);
00058       $f->setType(DMFormFieldType::INTEGER);
00059       $f->setMin(10);
00060       $f->setMax(100);
00061       $f->setSize(3);
00062       $this->addField($f);
00063 
00064       // tile view
00065       $f = new DMSelectField("tile_cols");
00066       for ($i = 2; $i < 9; $i++) {
00067          $f->addOption($i);
00068       }
00069       $f->setValue(3);
00070       $this->addField($f);
00071    }
00072 
00073    protected function loadFromDataStore() {
00074       if (!$this->template_set->getID()) {
00075          return;
00076       }
00077       $this->getFieldByName("name")->setValue($this->template_set->getName());
00078       foreach ($this->getFieldsByName("default_collection") as $f) {
00079          if ($f->getValue()
00080                == $this->template_set->getDefaultCollection()->getAlias()) {
00081             $f->setChecked(true);
00082          }
00083       }
00084       foreach ($this->getFieldsByName("allowed_collections") as $f) {
00085          foreach ($this->template_set->getAuthorizedCollections() as $c) {
00086             if ($c->getAlias() == $f->getValue()) {
00087                $f->setChecked(true);
00088                break;
00089             }
00090          }
00091       }
00092 
00093       // results per page
00094       $this->getFieldByName("results_per_page")->setValue(
00095             $this->template_set->getNumResultsPerPage());
00096 
00097       // tile view
00098       $f = $this->getFieldByName("tile_cols");
00099       $f->setValue($this->template_set->getNumTileViewColumns());
00100    }
00101 
00102    public function doAction() {
00103       $this->template_set->setName(
00104             $this->getFieldByName("name")->getValue());
00105       try {
00106          $collection = DMCollectionFactory::getCollection(
00107                $this->getFieldByName("default_collection")->getValue());
00108          $this->template_set->setDefaultCollection($collection);
00109       } catch (DMUnavailableModelException $e) {
00110          // do nothing
00111       }
00112 
00113       $this->template_set->unsetAuthorizedCollections();
00114       foreach ($this->getFieldsByName("allowed_collections") as $f) {
00115          foreach (DMCollection::getAuthorized() as $c) {
00116             if ($f->getValue() == $c->getAlias()) {
00117                if ($f->isChecked()) {
00118                   $this->template_set->addAuthorizedCollection($c);
00119                }
00120             }
00121          }
00122          if ($f->getValue() == "/dmdefault") {
00123             $this->template_set->unsetAuthorizedCollections();
00124          }
00125       }
00126 
00127       // results per page
00128       $this->template_set->setNumResultsPerPage(
00129             $this->getFieldByName("results_per_page")->getValue());
00130 
00131       // tile view
00132       $this->template_set->setNumTileViewColumns(
00133             $this->getFieldByName("tile_cols")->getValue());
00134 
00135       DMConfigXML::getInstance()->saveTemplateSet($this->template_set);
00136    }
00137 
00138 }
 All Data Structures Functions Variables