/**
  * 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.  It determines the type based on the
  * {@link $type} member variable.
  */
 protected function loadObjects()
 {
     if (!$this->hasPermission('task(person_can_edit_child_form_person_position)')) {
         $this->userMessage("You can change a person's position");
         return false;
     }
     $this->current_person_position = false;
     $this->new_person_position = false;
     $this->current_salary = false;
     $this->new_salary = false;
     $this->current_position = false;
     $this->new_position = false;
     if ($this->isPost()) {
         if (!$this->request_exists('parent') || !($this->person = $this->factory->createContainer($this->request('parent'))) instanceof iHRIS_Person || $this->person->getId() == 0) {
             I2CE::raiseError("Invalid person from " . $this->request('parent'));
             return false;
         }
         $this->person->populate();
         if (($this->current_person_position = $this->person->getLastPosition()) instanceof iHRIS_PersonPosition && $this->current_person_position->getId() != 0) {
             $this->current_person_position->populate();
             $curr_per_pos_id = $this->current_person_position->getID();
             if (array_key_exists('forms', $this->post) && is_array($this->post['forms']) && array_key_exists('person_position', $this->post['forms']) && is_array($this->post['forms']['person_position']) && array_key_exists($curr_per_pos_id, $this->post['forms']['person_position']) && is_array($this->post['forms']['person_position'][$curr_per_pos_id])) {
                 $this->current_person_position->setFromPost($this->post['forms']['person_position'][$curr_per_pos_id]);
             }
             if (($this->current_salary = $this->current_person_position->getLastSalary()) instanceof iHRIS_Salary) {
                 $curr_sal_id = $this->current_salary->getID();
                 $this->current_salary->populate();
                 if (array_key_exists('forms', $this->post) && is_array($this->post['forms']) && array_key_exists('salary', $this->post['forms']) && is_array($this->post['forms']['salary']) && array_key_exists($curr_sal_id, $this->post['forms']['salary']) && is_array($this->post['forms']['salary'][$curr_sal_id])) {
                     $this->current_salary->setFromPost($this->post['forms']['salary'][$curr_sal_id]);
                 }
             }
             if (!($this->current_position = $this->factory->createContainer($this->current_person_position->getField('position')->getDBValue())) instanceof iHRIS_Position || $this->current_position->getID() == 0) {
                 I2CE::raiseError("Invalid Current position");
                 return false;
             } else {
                 $this->current_position->populate();
                 $curr_pos_id = $this->current_position->getID();
                 if (array_key_exists('forms', $this->post) && is_array($this->post['forms']) && array_key_exists('position', $this->post['forms']) && is_array($this->post['forms']['position']) && array_key_exists($curr_pos_id, $this->post['forms']['position']) && is_array($this->post['forms']['position'][$curr_pos_id])) {
                     $this->current_position->setFromPost($this->post['forms']['position'][$curr_pos_id]);
                 }
             }
         }
         $this->new_position = $this->factory->createContainer('position');
         $this->new_position->setFromPost($this->post['forms']['position'][0][0]);
         $this->new_person_position = $this->factory->createContainer('person_position');
         $this->new_person_position->setParent($this->person->getFormID());
         $this->new_person_position->setFromPost($this->post['forms']['person_position'][0][1]);
         if ($this->hasPermission('task(person_can_edit_child_form_salary)')) {
             $this->new_salary = $this->factory->createContainer('salary');
             $this->new_salary->setFromPost($this->post['forms']['salary'][0][0]);
         }
     } else {
         if ($this->get_exists('id')) {
             if (!($this->current_person_position = $this->factory->createContainer($this->get('id'))) instanceof iHRIS_PersonPosition || $this->current_person_position->getId() == 0) {
                 I2CE::raiseError("Invalid person position identified by " . $this->get('id'));
                 return false;
             }
             $this->current_person_position->populate();
             if (!($this->person = $this->factory->createContainer($this->current_person_position->getParent())) instanceof iHRIS_Person || $this->person->getId() == 0) {
                 I2CE::raiseError("invalid person associated to " . $this->get('id'));
                 return false;
             }
             $this->person->populate();
         } elseif ($this->get_exists('parent')) {
             if (!($this->person = $this->factory->createContainer($this->get('parent'))) instanceof iHRIS_Person || $this->person->getId() == 0) {
                 I2CE::raiseError("Invalid person from " . $this->get('parent'));
                 return false;
             }
             $this->person->populate();
             $this->current_person_position = $this->person->getLastPosition();
             //note: there may not be an current person position.
         } else {
             I2CE::raiseError("No forms specified");
             return false;
         }
         if ($this->current_person_position instanceof iHRIS_PersonPosition) {
             $this->current_position = $this->current_person_position->getField('position')->getMappedFormObject();
         }
         $this->current_salary = $this->current_person_position->getLastSalary();
         $this->new_position = $this->factory->createContainer('position');
         //create a new position
         $this->new_person_position = $this->factory->createContainer('person_position');
         //create a new person position
         $this->new_person_position->setParent($this->person->getFormId());
         if ($this->hasPermission('task(person_can_edit_child_form_salary)')) {
             $this->new_salary = $this->factory->createContainer('salary');
         }
     }
     if ($this->current_person_position instanceof iHRIS_PersonPosition) {
         if (!$this->current_person_position->getField('end_date')->isValid()) {
             $this->current_person_position->end_date = I2CE_Date::now();
         }
         if ($this->current_salary instanceof iHRIS_Salary) {
             $this->current_salary->end_date = $this->current_person_position->end_date;
         }
         if ($this->new_person_position instanceof iHRIS_PersonPosition) {
             $this->new_person_position->start_date = $this->current_person_position->end_date;
         }
         if ($this->new_salary instanceof iHRIS_Salary && !$this->new_salary->getField('start_date')->isValid()) {
             $this->new_salary->start_date = $this->new_person_position->start_date;
         }
     }
     return true;
 }