Skip to content

Commit

Permalink
Added course status in list
Browse files Browse the repository at this point in the history
In the user_courses list, added a colum to see the status of the course plan.
Created a function in UserCourseStatusModel to get the name of a status.
Fixed a display issue when date_end is not set (0000-00-00). In this case, it displays now nothing on the cell.
  • Loading branch information
DydyCraft-21 committed Jul 4, 2024
1 parent c37f6c5 commit a8607e6
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 8 deletions.
6 changes: 6 additions & 0 deletions orif/plafor/Controllers/Apprentice.php
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,13 @@ public function list_user_courses($id_apprentice = null)

// Get the course_plan informations for each user_course
foreach($user_courses as &$user_course)
{
$user_course['course_plan'] = $this->course_plan_model->withDeleted()->find($user_course['fk_course_plan']);
$user_course['status'] = $this->user_course_status_model->getUserCourseStatusName($user_course['fk_status']);

if($user_course['date_end'] === '0000-00-00')
$user_course['date_end'] = null;
}

$output = array(
'title' => sprintf(lang('plafor_lang.title_user_course_plan_list'), $user['username']),
Expand Down
14 changes: 14 additions & 0 deletions orif/plafor/Models/UserCourseStatusModel.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,20 @@ public static function getInstance(){
return UserCourseStatusModel::$userCourseStatusModel;
}


/**
* Gets the name of a status.
*
* @param int $id_user_course_status ID of the user course status
*
* @return string
*
*/
public function getUserCourseStatusName($id_user_course_status)
{
return $this->select('name')->where('id', $id_user_course_status)->first()['name'];
}

/**
* @param $userCourseStatusId
* @return array
Expand Down
18 changes: 10 additions & 8 deletions orif/plafor/Views/user_course/list.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,21 +36,23 @@
$data[] =
[
'id' => $user_course['id'],
'course_plan_number' => $user_course['course_plan']['formation_number'],
'course_plan_name' => $user_course['course_plan']['official_name'],
'date_begin' => Time::createFromFormat('Y-m-d', $user_course['date_begin'])->toLocalizedString('dd.MM.Y'),
'date_end' => Time::createFromFormat('Y-m-d', $user_course['date_end'])->toLocalizedString('dd.MM.Y'),
'course_plan_number' => $user_course['course_plan']['formation_number'],
'course_plan_name' => $user_course['course_plan']['official_name'],
'date_begin' => Time::createFromFormat('Y-m-d', $user_course['date_begin'])->toLocalizedString('dd.MM.Y'),
'date_end' => isset($user_course['date_end']) ? Time::createFromFormat('Y-m-d', $user_course['date_end'])->toLocalizedString('dd.MM.Y') : '',
'course_plan_status' => $user_course['status'],
];
}

echo view('Common\Views\items_list',
[
'columns' =>
[
'course_plan_number' => lang('plafor_lang.field_course_plan_formation_number'),
'course_plan_name' => lang('plafor_lang.field_course_plan_official_name'),
'date_begin' => lang('plafor_lang.field_user_course_date_begin_short'),
'date_end' => lang('plafor_lang.field_user_course_date_end_short'),
'course_plan_number' => lang('plafor_lang.field_course_plan_formation_number'),
'course_plan_name' => lang('plafor_lang.field_course_plan_official_name'),
'date_begin' => lang('plafor_lang.field_user_course_date_begin_short'),
'date_end' => lang('plafor_lang.field_user_course_date_end_short'),
'course_plan_status' => lang('plafor_lang.status'),
],
'items' => $data,
'primary_key_field' => 'id',
Expand Down

0 comments on commit a8607e6

Please sign in to comment.