/** * Save the training object. * * Sets all the required fields for the training object based on the form data. * Since a training may be inside or outside the country certain fields may be required * depending on which case it is. * * @param I2CE_User &$user The user saving this object. * @param boolean $transact */ public function save(&$user, $transact = true) { if (I2CE_Validate::checkMap($this->training_program)) { $tp = I2CE_FormFactory::instance()->createContainer($this->getField("training_program")->getDBValue()); $tp->populate(); $this->in_cadre = $tp->cadre; $this->training_institution = $tp->training_institution; $this->trained_outside = false; $this->cadre = $this->in_cadre; unset($this->out_country); unset($this->out_institution); } else { $this->trained_outside = true; $this->cadre = $this->out_cadre; unset($this->training_institution); } parent::save($user, $transact); }
/** * Validate all fields for the training form. * @param I2CE_Form $form */ public function validate_form_training($form) { if (!I2CE_Validate::checkMap($form->training_program) && !I2CE_Validate::checkMap($form->out_cadre)) { $form->setInvalidMessage("training_program", 'bad_cadre'); } elseif (I2CE_Validate::checkMap($form->out_cadre)) { if (!I2CE_Validate::checkMap($form->out_country)) { $form->setInvalidMessage("out_country", 'bad_country'); } if (!I2CE_Validate::checkDate($form->graduation)) { $form->setInvalidMessage("graduation", 'required_out'); } } if (I2CE_Validate::checkDate($form->intake_date) && I2CE_Validate::checkDate($form->graduation)) { if ($form->graduation->before($form->intake_date)) { $form->setInvalidMessage("graduation", "bad_date"); } } }