Exemplo n.º 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);
     }
 }