/** * Update the position for this to mark it as closed and then save the object. */ public function save() { if (!$this->hasPermission('task(person_can_edit_child_form_person_position)')) { $this->userMessage("You cannot change a person's position"); return false; } //we are only displaying one person_position form on the page, it is the new person_position form. W if ($this->current_person_position instanceof iHRIS_PersonPosition) { $this->current_person_position->save($this->user); } if ($this->current_position instanceof iHRIS_Position) { //now close out the current position $this->current_position->statusOnly(); $this->current_position->save($this->user); } //we can now save the details on the new position $this->new_position->setFromDB('position_status|closed'); $this->new_position->save($this->user); //now that the new position has been saved, we can link it to the new_person_position $this->new_person_position->getField('position')->setFromDB($this->new_position->getNameID()); $this->new_person_position->save($this->user); if ($this->hasPermission('task(person_can_edit_child_form_salary)')) { if ($this->current_salary instanceof iHRIS_Salary) { $this->current_salary->save($this->user); } $this->new_salary->setParent($this->new_person_position); $this->new_salary->save($this->user); } $this->setRedirect("view?id=" . $this->person->getFormID()); }
/** * Run extra validation for the fields being edited. */ protected function validate() { parent::validate(); if ($this->post_exists('position_option') && $this->post('position_option') == 'create' && $this->new_position instanceof iHRIS_Position) { $this->new_position->validate(); } if ($this->isPost() && $this->old_position instanceof iHRIS_Position) { if ($this->getPrimary()->start_date->compare($this->old_person_position->start_date) != -1) { $this->getPrimary()->setInvalidMessage('start_date', 'bad_date'); } if (!$this->old_position->getField('status')->isValid()) { $this->old_position->setInvalidMessage('status', 'required'); } //I2CE::raiseMessage("in validate " . $this->old_position->getField('status')->getDBValue() ); if (!$this->old_person_position->getField('reason')->isValid()) { $this->old_person_position->setInvalidMessage('reason', 'required'); } } }