Skip to content

Commit

Permalink
Merge pull request #117 from OrifInformatique/Release-4.3
Browse files Browse the repository at this point in the history
Fix error with soft deleted course plans
  • Loading branch information
DidierViret committed Jul 10, 2024
2 parents 9f94bdd + ddccf05 commit 0b9e4f9
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions orif/plafor/Controllers/Apprentice.php
Original file line number Diff line number Diff line change
Expand Up @@ -272,10 +272,10 @@ public function save_user_course($id_apprentice = 0, $id_user_course = 0)
'date_end' => $this->request->getPost('date_end'),
);

if (!is_null($user_course))
if (!is_null($user_course)) {
// User's course already exists - updates it
$this->user_course_model->update($id_user_course, $new_user_course);

}
else
{
$user_has_course = $this->user_course_model->where(['fk_user' => $id_apprentice, 'fk_course_plan' => $fk_course_plan])->findAll() ? true : false;
Expand Down Expand Up @@ -330,8 +330,15 @@ public function save_user_course($id_apprentice = 0, $id_user_course = 0)
$course_plans = [];
$status = [];

foreach ($this->course_plan_model->findAll() as $courseplan)
$course_plans[$courseplan['id']] = $courseplan['official_name'];
if ($id_user_course == 0) {
// New user course can only refer to an active course plan and not to a soft deleted one
foreach ($this->course_plan_model->findAll() as $courseplan)
$course_plans[$courseplan['id']] = $courseplan['official_name'];
} else {
// Existing user course can refer to an active or a soft deleted course plan
foreach ($this->course_plan_model->withDeleted()->findAll() as $courseplan)
$course_plans[$courseplan['id']] = $courseplan['official_name'];
}

foreach ($this->user_course_status_model->findAll() as $usercoursestatus)
$status[$usercoursestatus['id']] = $usercoursestatus['name'];
Expand Down

0 comments on commit 0b9e4f9

Please sign in to comment.