コード例 #1
0
 /**
  * Get the forms ids  for joining on the named parent form's id with the named child form on a given field
  * @param string $childFormName the name of the child form in the relationship
  * @param I2CE_Form $parentFormObj
  * @param array $joinData The array containg the join data
  * @param array $where
  * @param array $limit
  * @return mixed. An array of form ids
  */
 public function getFormIdsJoiningOn_child_field($childFormName, $parentFormObj, $joinData, $where, $limit)
 {
     if (!is_array($joinData) || !array_key_exists('field', $joinData) || !is_string($joinData['field']) || strlen($joinData['field']) == 0) {
         I2CE::raiseError("Join child field not specified for {$childFormName}");
         return array();
     }
     $form = $this->getForm($childFormName);
     $sub_where = array('operator' => 'FIELD_LIMIT', 'field' => $joinData['field'], 'style' => 'equals', 'data' => array('value' => $parentFormObj->getNameId()));
     if (count($where) > 0) {
         $where = array('operator' => 'AND', 'operand' => array($sub_where, $where));
     } else {
         $where = $sub_where;
     }
     $ids = I2CE_FormStorage::search($form, $parentFormObj->getNameId(), $where, array(), $limit);
     if (is_string($ids)) {
         $ids = array($ids);
     }
     if (is_array($ids)) {
         return $ids;
     } else {
         return array();
     }
     //return  " JOIN $refChildForm AS `$childFormName` ON `$childFormName`.`{$joinData['field']}` = `parent_form`.id ";
 }
コード例 #2
0
 /**
  * Updates time stamp on given object
  * @param I2CE_Form $form
  * @param int $timestamp.  If not set, defaults to current unix timestamp
  * @returns boolean. true on success
  */
 public function updateTimeStamp($form, $user, $timestamp = null)
 {
     if ($timestamp === null) {
         $timestamp = time();
     }
     if (!is_int($timestamp) || $timestamp < 0) {
         I2CE::raiseError("Invalid timestamp");
         return false;
     }
     $ff = I2CE_FormFactory::instance();
     $seen = array();
     //array to avoid recursion
     while ($form instanceof I2CE_Form) {
         if (in_array($form->getNameId(), $seen)) {
             break;
         }
         if ($form->getId() == '0') {
             I2CE::raiseError("Cannot update timestamp of object with blank ID");
             return false;
         }
         $seen[] = $form->getNameId();
         if ($this->isWritable($form)) {
             if (!($storageMechanism = self::getStorageMechanism($form)) instanceof I2CE_FormStorage_Mechanism) {
                 I2CE::raiseError("Invalid form storage mechanism for " . $form->getName);
                 return false;
             }
             I2CE_ModuleFactory::callHooks("form_pre_save", array('form' => $form, 'user' => $user));
             I2CE_ModuleFactory::callHooks("form_pre_save_" . $form->getName(), array('form' => $form, 'user' => $user));
             if (!$storageMechanism->updateTimeStamp($form, $timestamp)) {
                 return false;
             }
             I2CE_ModuleFactory::callHooks("form_post_save_" . $form->getName(), array('form' => $form, 'user' => $user));
             I2CE_ModuleFactory::callHooks("form_post_save", array('form' => $form, 'user' => $user));
         }
         $form = $ff->createContainer($form->getParent());
     }
     return true;
 }
コード例 #3
0
 /**
  * Gets the id's for the given child for this form.
  * @param I2CE_Form $form
  * @param  string $child_form_name the child form name 
  * @param mixed $order_by.  A string or array of strings.  The fields to oreder by .  defaults to empty array.
  * @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.  
  * @return array
  */
 public function getChildIds($form, $child_form_name, $order_by = array(), $where = array(), $limit = false)
 {
     $storageMechanism = self::getStorageMechanism($child_form_name);
     if (!$storageMechanism) {
         return array();
     }
     $ret = $storageMechanism->getIdsAsChild($child_form_name, $form->getNameId(), $order_by, $where, $limit);
     if (!is_array($ret)) {
         return array();
     }
     return $ret;
 }