dmBridge PHP API
DMSelectField.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 class DMSelectField extends DMAbstractFormField implements DMFormField {
00016 
00017    private $options = array();
00018 
00019 
00024    public function getHTMLTag() {
00025       $dxml = new DMDOMDocument("1.0", "utf-8");
00026       $dxml->loadXML("<div/>");
00027 
00028       $class = "dmFormField";
00029       if (!$this->isValid() && $this->isUserData()) {
00030          $msg = $this->getValidationMessage();
00031          $dxml->documentElement->appendChild($dxml->createTextNode($msg));
00032          $class .= " dmInvalid";
00033       }
00034       $dxml->documentElement->setAttribute("class", $class);
00035 
00036       $select = $dxml->createElement("select");
00037       $select->setAttribute("name", $this->getHTMLName());
00038       foreach ($this->getOptions() as $c) {
00039          $opt = $dxml->createElement("option",
00040                DMString::xmlentities($c['label']));
00041          $opt->setAttribute("value", $c['value']);
00042          if ($c['value'] == $this->getValue()) {
00043             $opt->setAttribute("selected", "selected");
00044          }
00045          $select->appendChild($opt);
00046       }
00047       if (!$this->isEnabled()) {
00048          $select->setAttribute("disabled", "disabled");
00049       }
00050       foreach ($this->getAttributes() as $k => $v) {
00051          $select->setAttribute($k, $v);
00052       }
00053       $dxml->documentElement->appendChild($select);
00054       return $dxml->saveHTML($dxml->documentElement);
00055    }
00056 
00065    public function addOption($value, $label = null) {
00066       if (empty($label)) {
00067          $label = $value;
00068       }
00069       $this->options[] = array(
00070          'value' => $value,
00071          'label' => $label
00072       );
00073    }
00074 
00080    public function getOptions() {
00081       return $this->options;
00082    }
00083 
00084 }
00085 
 All Data Structures Functions Variables