dmBridge PHP API
DMCheckboxField.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 DMCheckboxField extends DMAbstractFormField implements DMFormField {
00016 
00018    private $is_checked = false;
00019 
00020 
00025    public function __construct($name) {
00026       parent::__construct($name);
00027       $this->setRequired(false);
00028    }
00029 
00033    public function isChecked() {
00034       return $this->is_checked;
00035    }
00036 
00041    public function setChecked($bool) {
00042       $this->is_checked = (bool) $bool;
00043    }
00044 
00049    public function getHTMLTag() {
00050       $dxml = new DMDOMDocument("1.0", "utf-8");
00051       $dxml->loadXML("<div/>");
00052 
00053       $class = "dmFormField";
00054       if (!$this->isValid() && $this->isUserData()) {
00055          $msg = $this->getValidationMessage();
00056          $dxml->documentElement->appendChild($dxml->createTextNode($msg));
00057          $class .= " dmInvalid";
00058       }
00059       $dxml->documentElement->setAttribute("class", $class);
00060 
00061       $input = $dxml->createElement("input");
00062       $input->setAttribute("type", "checkbox");
00063       $input->setAttribute("name", $this->getHTMLName());
00064       $input->setAttribute("value", DMString::websafe($this->getValue()));
00065       if ($this->isChecked()) {
00066          $input->setAttribute("checked", "checked");
00067       }
00068       if (!$this->isEnabled()) {
00069          $input->setAttribute("disabled", "disabled");
00070       }
00071       foreach ($this->getAttributes() as $k => $v) {
00072          $input->setAttribute($k, $v);
00073       }
00074       $dxml->documentElement->appendChild($input);
00075       $dxml->documentElement->appendChild(
00076          $dxml->createTextNode($this->getLabel()));
00077 
00078       return $dxml->saveHTML($dxml->documentElement);
00079    }
00080 
00081 }
00082 
 All Data Structures Functions Variables