/**
  * Create and load data for the objects used for this form.
  * 
  * Create the list object and if this is a form submission load
  * the data from the form data.
  */
 protected function loadObjects()
 {
     $this->evaluations = array();
     //make sure we have valid objects
     $ff = I2CE_FormFactory::instance();
     if ($this->id !== false) {
         $personScheduledCourse = $ff->createContainer($this->id);
         if (!$personScheduledCourse instanceof iHRIS_Person_Scheduled_Training_Course) {
             I2CE::raiseError("Cannot instantitatne person scheudled training course " . $this->id);
             return false;
         }
     } else {
         $personScheduledCourse = $ff->createContainer('person_scheduled_training_course');
         if (!$personScheduledCourse instanceof iHRIS_Person_Scheduled_Training_Course) {
             I2CE::raiseError("Cannot instantitatne person scheudled training course " . $this->id);
             return false;
         }
         $personScheduledCourse->load($this->post);
         $this->id = $personScheduledCourse->getNameId();
     }
     if ($personScheduledCourse->getId() == '0') {
         I2CE::raiseError("Bad ID");
         return false;
     }
     $personScheduledCourse->populate();
     $person_id = $personScheduledCourse->getParent();
     $person = $ff->createContainer($person_id);
     if (!$person instanceof iHRIS_Person) {
         I2CE::raiseError("No person:" . $person_id);
         return false;
     }
     $person->populate();
     $this->setObject($personScheduledCourse, I2CE_PageForm::EDIT_SECONDARY);
     $this->setObject($person, I2CE_PageForm::EDIT_PARENT);
     $comp_ids = iHRIS_Module_TrainingSimpleCompetency::getAssociatedCompetencies($personScheduledCourse);
     if (count($comp_ids) > 0) {
         $person_comps = array();
         foreach (I2CE_FormStorage::listFields('person_competency', 'competency', $person_id) as $pers_comp_id => $data) {
             if (!array_key_exists('competency', $data) || !$data['competency']) {
                 continue;
             }
             $person_comps[$data['competency']] = 'person_competency|' . $pers_comp_id;
         }
         $person_comp_objs = array();
         foreach ($comp_ids as $comp_id) {
             if (!array_key_exists($comp_id, $person_comps)) {
                 $pers_comp = $ff->createContainer('person_competency');
                 if (!$pers_comp instanceof iHRIS_PersonCompetency) {
                     I2CE::raiseError("Could not instantiatne person_competency");
                     return false;
                 }
                 $pers_comp->setParent($person_id);
                 $pers_comp->getField('competency')->setFromDB($comp_id);
             } else {
                 $pers_comp = $ff->createContainer($person_comps[$comp_id]);
                 if (!$pers_comp instanceof iHRIS_PersonCompetency) {
                     I2CE::raiseError("Could not instantiatne person_competency: " . $person_comps[$comp_id]);
                     return false;
                 }
                 $pers_comp->populate();
                 //don't need to populate here b/c taken care of by parent method
             }
             $node = $this->template->loadFile("training_course_evaluation_form.html", 'span');
             $pers_comp->load($this->post);
             $this->setObject($pers_comp, I2CE_PageForm::EDIT_SECONDARY, $node);
         }
     }
 }
 /**
  * Save the objects to the database.
  * 
  * Save the default object being edited and return to the view page.
  * @global array
  */
 protected function save()
 {
     if (!$this->permissionParser->hasTask('person_can_edit_child_form_person_scheduled_training_course')) {
         $this->userMessage("You do not have permission to add or edit a person's scheduleing of training course", 'notice', true);
         $this->setRedirect('noaccess');
         return false;
     }
     parent::save();
     $this->setRedirect("view?id=" . $this->getParent()->getNameId());
     if (!I2CE_ModuleFactory::instance()->isEnabled('training-simple-competency')) {
         return;
     }
     if (!iHRIS_Module_TrainingSimpleCompetency::assignCompetenciesFromCourseEval($this->getParent(), $this->getPrimary())) {
         I2CE::raiseError("Could not update person competncies for" . $this->getParent()->getNameId() . " from " . $this->getPrimary()->getNameId());
     }
 }