コード例 #1
0
 /**
  * Populate all instances of the given child form for this object.
  * @param I2CE_Form $form
  * @param string $form_name: The form name to populate
  * @param mixed  $order_by  A field or array  of fields to sort by.  Preceded by "-" to sort in reverse order.
  *                    - array( "-start_date", "name" ). Defaults to null in which case if get the default sort
  *               order that is registered for the type (which defaults to none)
  * @param mixed @where an aarray of where information to limit getting the child id's by.   If null, we get
  * the default limits for the type (which defaults to none)
  * @param string $type.  Defaults to 'default'
  * @param mixed $limit. Defaults to false.  It true, returns only one result.  If an integer it is the numeber of records to limit to.
  *  If it is as an array of two integers, it is the offset and then number of results to limit to.  
  */
 public function populateChild($form, $form_name, $order_by = null, $where = null, $type = 'default', $limit = false)
 {
     if (!$form_name) {
         I2CE::raiseError("Invalid arguments passed to populateChild: ");
         return;
     }
     if (!is_string($type) || strlen($type) == 0) {
         $type = 'default';
     }
     if (is_scalar($order_by)) {
         $order_by = explode(",", $order_by);
     }
     if (!$form->getName()) {
         I2CE::raiseError("Form has no name");
         return;
     }
     $child_data_path = "/modules/forms/forms/" . $form->getName() . "/meta/child_form_data/{$type}/{$form_name}";
     if (I2CE::getConfig()->is_parent($child_data_path)) {
         $child_data = I2CE::getConfig()->{$child_data_path};
         if ($where === null && $child_data->is_parent('limits')) {
             $where = $child_data->limits->getAsArray();
         }
         if ($order_by === null && $child_data->is_scalar('order')) {
             $order_by = explode(',', $child_data->order);
         }
     }
     if (!is_array($where)) {
         $where = array();
     }
     if (!is_array($order_by)) {
         $order_by = array();
     }
     $ids = $form->getChildIds($form_name, $order_by, $where, $limit);
     foreach ($ids as $id) {
         $form->addChild($form_name, $id);
     }
 }
コード例 #2
0
 /**
  * Adds any child forms for this form.
  * @param DOMNode $detailNode.  The major node which contains the formBrowser we are creating
  * @param  I2CE_MagicDataNode $formConfig /modules/forms/forms/$formName
  * @param I2CE_Form $formObj the form object for the form we are displaying ( or null.if we are not looking at a particular record)
  * @returns boolean.  Return false if none were added, true if child forms were added.
  */
 public function addChildForms($detailNode, $formConfig, $formObj)
 {
     $view_child = '';
     $child_forms = array();
     $formConfig->setIfIsSet($child_forms, "meta/child_forms", true);
     if (count($child_forms) > 0) {
         $view_child = "formBrowser/showForm";
     }
     $prefixNode = $this->template->getElementById('child_fb_prefix', $detailNode);
     if ($prefixNode instanceof DOMNode) {
         $prefixNode->setAttribute('value', $this->formBrowserPrefix);
     }
     $this->template->setDisplayDataImmediate('form_view_child', $view_child, $detailNode);
     $selectNode = $this->template->getElementById('child_form_select', $detailNode);
     $added = false;
     if ($selectNode instanceof DOMNode && $formObj instanceof I2CE_Form) {
         foreach ($child_forms as $child) {
             $childIds = $formObj->getChildIds($child);
             foreach ($childIds as $childId) {
                 $added = true;
                 $selectNode->appendChild($this->template->createElement('option', array('value' => $child . ':' . $childId), $child . ' Id: ' . $childId));
             }
         }
     } else {
         if ($selectNode instanceof DOMNode) {
             foreach ($child_forms as $child) {
                 $added = true;
                 $selectNode->appendChild($this->template->createElement('option', array('value' => $child), $child));
             }
         }
     }
     foreach (array("form_view_child", "form_view_child_button") as $id) {
         $formNode = $this->template->getElementById($id, $detailNode);
         if ($formNode instanceof DOMNode) {
             $formNode->setAttribute('id', $this->formBrowserPrefix . '_' . $id);
         }
     }
     if ($this->page->hasAjax() && $added) {
         $this->page->addAjaxUpdate($this->formBrowserPrefix . '_content', $this->formBrowserPrefix . '_form_view_child_button', 'click', "formBrowser/{$this->formBrowserPrefix}", $this->formBrowserPrefix . '_content', true, $this->formBrowserPrefix . '_form_view_child', true);
     }
     if (!$added) {
         return false;
     } else {
         return true;
     }
 }