/** * Populate the member variables of the object from the Cross Sectional Data Set * @param I2CE_Form $form * @return boolean */ public function populate($form) { $formName = $form->getName(); $this->ensureLocations($formName); $id = $form->getId(); if (!array_key_exists($id, $this->locations[$formName]) || ($location = $this->locations[$formName][$id]) === false) { return; } $data = $this->getFormData($formName, $location); foreach ($data as $field => $dbval) { if ($field == 'parent') { if ($dbval != '0') { $form->setParent($dbval); } } else { $fieldObj = $form->getField($field); if (!$fieldObj instanceof I2CE_FormField) { continue; } $fieldObj->setFromDB($dbval); } } return true; }
/** * Populate the member variables of the object from the database. * @param I2CE_Form $form */ public function populate($form) { $fields = array(); foreach ($form as $field => $fieldObj) { if (!$fieldObj->isInDB()) { continue; } $fields[] = $field; } $fields[] = 'last_modified'; $fields[] = 'created'; $populateQry = $this->getRequiredFieldsQuery($form->getName(), $fields, $form->getId(), true); if (!$populateQry) { return false; } $populateQry .= ' LIMIT 1'; $result = $this->db->getRow($populateQry); if (I2CE::pearError($result, "Error populating form " . $form->getName())) { return false; } $form_name = $form->getName(); foreach ($fields as $field) { $fieldObj = $form->getField($field); if (!$fieldObj instanceof I2CE_FormField) { continue; } $ref = strtolower($form_name . '+' . $field); if (isset($result->{$ref})) { $fieldObj->setFromDB($result->{$ref}); } } $ref = strtolower($form_name . '+parent'); if (isset($result->{$ref})) { $form->setParent($result->{$ref}); } $ref = strtolower($form_name . '+last_modified'); if (isset($result->{$ref})) { $form->setLastModified($result->{$ref}); } $ref = strtolower($form_name . '+created'); if (isset($result->{$ref})) { $form->setCreated($result->{$ref}); } return true; }
/** * Add a child form object to this forms list of children. * @param I2CE_Form $child_form The child form * @param boolean $replace Overwrite the child object if it already exists. */ public function addChildForm($child_form, $replace = false) { if (!$child_form instanceof I2CE_Form) { return false; } $form_name = $child_form->getName(); $id = $child_form->getId(); if (!array_key_exists($form_name, $this->children)) { $this->children[$form_name] = array(); } if (array_key_exists($id, $this->children[$form_name]) && $this->children[$form_name][$id] instanceof I2CE_Form && !$replace) { return; } $this->children[$form_name][$id] = $child_form; $child_form->setParent($this); }