/** * Populate the member variables of the object from the database. * @param I2CE_Form $form */ public function populate($form) { //this shoudn't really be called b/c it is a fuzzy method which is already implemented in I2CE_User_Form if (!$form instanceof I2CE_User_Form) { return; } $form->populate(); }
function populate($repopulate = false) { parent::populate($repopulate); //this will do the default population e.g. read it from the entry tables //now we can try and set the value of the average field if (!($aver = $this->getField('average')) instanceof I2CE_FormField_INT) { //I2CE::raiseError("Could not get average field") return; } $calc = $this->getAverageScore(); $aver->setFromDB((int) $calc); }
protected function loadPrimary() { $formFactory = I2CE_FormFactory::instance(); if ($this->get_exists('id')) { if (!($this->primObj = $formFactory->createContainer($this->get('id'))) instanceof I2CE_Form || $this->formRelationship->getPrimaryForm() != $this->primObj->getName()) { I2CE::raiseError("invalid form id :" . print_r($this->request(), true) . "\ndoes not match " . $this->formRelationship->getPrimaryForm()); return false; } $this->primObj->populate(); } return true; }
/** * Populate the member variables of the object from the database. */ public function populate() { parent::populate(); if ($this->trained_outside) { $this->out_cadre = $this->cadre; } else { $this->in_cadre = $this->cadre; $where_data = array('operator' => 'AND', 'operand' => array(array('operator' => 'FIELD_LIMIT', 'field' => 'training_institution', 'style' => 'equals', 'data' => array('value' => $this->getField("training_institution")->getDBValue())), array('operator' => 'FIELD_LIMIT', 'field' => 'cadre', 'style' => 'equals', 'data' => array('value' => $this->getField("in_cadre")->getDBValue())))); $training_program = I2CE_FormStorage::search('training_program', false, $where_data); if (count($training_program) > 0) { $this->getField("training_program")->setFromDB("training_program|" . $training_program[0]); } } }
/** * Use method to duplicate a form object. * @param I2CE_Form $form * @param boolean $recurse. Defaults to false. If true we duplicate all children, and {@param $save is forced to be true} * @param boolean $save. Defaults to true. If true we save the form at the same time we duplicate it. * @param string $parentid. Defaults to null in which case the parent id of the duplicated form is not set * @param I2CE_User $user, the user object to save. Defaults to null. * @returns mixed false on error or I2CE_Form, the duplicated form */ public function duplicate($form, $recurse = false, $save = true, $parentid = null, $user = null) { if (!$form instanceof I2CE_Form) { I2CE::raiseError("Not A form"); return false; } $form->populate(); $save |= $recurse; //if we recurse, we must save $ff = I2CE_FormFactory::instance(); $newForm = $ff->createForm($form->getName()); if (!$newForm instanceof I2CE_Form) { I2CE::raiseError("Could create form " . $form->getName() . "to duplicate "); return false; } foreach ($form as $field) { if (!$field instanceof I2CE_FormField) { continue; } $newField = $newForm->getField($field->getName()); if (!$newField instanceof I2CE_FormField) { I2CE::raiseError("Could not duplicate field " . $field->getName() . " of form " . $form->getName()); return false; } $newField->setFromDB($field->getDBValue()); } if ($parentid !== null) { $newForm->setParent($parentid); } if ($save) { if (!$user instanceof I2CE_User) { $user = new I2CE_User(); } $newForm->save($user); if ($recurse) { $child_forms = $form->getChildForms(); $form->populateChildren($child_forms); foreach ($form->getChildren() as $children) { foreach ($children as $childForm) { $childForm->duplicate(true, true, $newForm->getNameID(), $user); } } } } return $newForm; }