/**
  * Adds the report limit node to its content node
  * @param DOMNode $contentNode
  * @param DOMNode $limitnode
  * @param I2CE_MagicDataNode $limitConfig
  */
 protected function displayReportLimit($contentNode, $limitNode, $limitConfig)
 {
     if (!($limitContainer = $this->template->appendFileByNode('display_report_limit.html', '//*[@name="limit_container"][1]', $contentNode))) {
         I2CE::raiseError("Could not load display_report_limit.html");
         return false;
     }
     if (!$limitConfig->is_scalar('header')) {
         $header = $limitConfig->getName();
     } else {
         $header = $limitConfig->header;
     }
     $this->template->setDisplayDataImmediate('header', $header, $limitContainer);
     if (!($inputNode = $this->template->getElementByName('limit', 0, $limitContainer)) instanceof DOMElement) {
         I2CE::raiseError("Could not get limit node in display_report_limit.html");
         return false;
     }
     $inputNode->appendChild($limitNode);
     return true;
 }
 /**
  * Store the given I2CE_MagicDataNode into the database.
  * @param I2CE_MagicDataNode $node
  */
 public function store($node)
 {
     if ($node instanceof I2CE_MagicData) {
         $parent = '';
         $name = '';
         $path = '/';
     } else {
         $name = $node->getName();
         if (is_string($name) && strlen($name) == 0) {
             I2CE::raiseError("Non-existent name on a non-root magic data node");
             return false;
         }
         $parentNode = $node->getParent();
         if ($parentNode instanceof I2CE_MagicData) {
             $parent = '/';
             $path = '/' . $name;
         } else {
             $parent = $parentNode->getPath(false);
             $path = $parent . '/' . $name;
         }
     }
     $value = $node->getSaveValue();
     //$path_hash = md5($path);
     $path_hash = $this->getHash($node);
     if ($this->db_statements['store']->execute(array($path_hash, $parent, $name, $node->getType(), $value))) {
         return true;
     } else {
         I2CE_MagicDataNode::raiseError("Error saving to DB " . $node->getPath() . " Type: " . $node->getType() . " Value: " . $value);
         return false;
     }
 }
 /**
  * Add the select records.
  * @param DOMNode $detailNode.  The major node which contains the formBrowser we are creating
  * @param  I2CE_MagicDataNode $formConfig /modules/forms/forms/$formName
  */
 protected function addRecordSelect($formConfig, $detailNode, $id)
 {
     $selectNode = $this->template->getElementById('particular_record_select', $detailNode);
     if (!$selectNode instanceof DOMNode) {
         return;
     }
     $form = $formConfig->getName();
     $factory = I2CE_FormFactory::instance();
     $recordIds = $factory->getRecords($form);
     foreach ($recordIds as $recordId) {
         $text = 'Id: ' . $recordId;
         $primary_fields = array();
         $formConfig->setIfIsSet($primary_fields, "metadata/primary_field", true);
         if (!is_array($primary_fields)) {
             $primary_fields = array($primary_fields);
         }
         if (count($primary_fields) > 0) {
             $text .= ' --';
             $formObj = $factory->createContainer($form . '|' . $recordId);
             $formObj->populate();
             if (!$formObj instanceof I2CE_Form) {
                 $primary_fields = array();
             }
         }
         ksort($primary_fields);
         foreach ($primary_fields as $field) {
             $text .= " " . $formObj->getField($field)->getDisplayValue();
         }
         $selectNode->appendChild($this->template->createElement('option', array('value' => $recordId), $text));
         if ($formObj instanceof I2CE_Form) {
             $formObj->cleanup();
         }
     }
     $optionNode = $this->template->query(".//option[@value='{$id}']", $selectNode);
     if ($optionNode->length == 1) {
         $optionNode->item(0)->setAttribute("selected", "selected");
     }
     foreach (array("form_view_record", "particular_record_select") as $id) {
         $formNode = $this->template->getElementById($id, $detailNode);
         if ($formNode instanceof DOMNode) {
             $formNode->setAttribute('id', $this->formBrowserPrefix . '_' . $id);
         }
     }
     if ($this->page->hasAjax()) {
         $this->page->addAjaxUpdate($this->formBrowserPrefix . '_content', $this->formBrowserPrefix . '_particular_record_select', 'change', "formBrowser/showForm/{$form}?FBPrefix={$this->formBrowserPrefix}", $this->formBrowserPrefix . '_content', true, $this->formBrowserPrefix . '_form_view_record', true);
         $this->template->removeNodeById('form_view_record_button', $detailNode);
     }
 }