Skip to content

Commit

Permalink
Removed duplicates functions in user course model
Browse files Browse the repository at this point in the history
  • Loading branch information
DydyCraft-21 committed Jul 10, 2024
1 parent 9ad4104 commit f6ba8cb
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 49 deletions.
12 changes: 6 additions & 6 deletions orif/plafor/Controllers/Apprentice.php
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,7 @@ public function list_user_courses($id_apprentice = null)
public function save_user_course($id_apprentice = 0, $id_user_course = 0)
{
// Access permissions
if ($this->session->get('user_access')>=config('\User\Config\UserConfig')->access_lvl_trainer)
if($this->session->get('user_access')>=config('\User\Config\UserConfig')->access_lvl_trainer)
{
$user_type_id = $this->user_type_model
->where('access_level', config('\User\Config\UserConfig')->access_level_apprentice)
Expand All @@ -256,12 +256,12 @@ public function save_user_course($id_apprentice = 0, $id_user_course = 0)
->where('fk_user_type', $user_type_id)
->find($id_apprentice);

$user_course = $this->user_course_model->getUserCourseById($id_user_course);
$user_course = $this->user_course_model->find($id_user_course);

if (is_null($apprentice))
if(is_null($apprentice))
return redirect()->to(base_url('plafor/apprentice/list_apprentice'));

if (count($_POST) > 0)
if(count($_POST) > 0)
{
$fk_course_plan = $this->request->getPost('course_plan');
$new_user_course = array(
Expand All @@ -278,7 +278,7 @@ public function save_user_course($id_apprentice = 0, $id_user_course = 0)

else
{
$user_has_course = $this->user_course_model->getUserCourseByUserAndCoursePlan($user_type_id, $new_user_course['fk_course_plan']) ? true : false;
$user_has_course = $this->user_course_model->where(['fk_user' => $id_apprentice, 'fk_course_plan' => $fk_course_plan])->findAll() ? true : false;

// If the apprentice already follows the course plan submitted, prevent the creation of the entry.
if(!$user_has_course)
Expand Down Expand Up @@ -322,7 +322,7 @@ public function save_user_course($id_apprentice = 0, $id_user_course = 0)
}
}

if ($this->user_course_model->errors() == null)
if($this->user_course_model->errors() == null)
return redirect()->to(base_url('plafor/apprentice/list_user_courses/' . $id_apprentice));
}

Expand Down
43 changes: 0 additions & 43 deletions orif/plafor/Models/UserCourseModel.php
Original file line number Diff line number Diff line change
Expand Up @@ -72,49 +72,6 @@ public static function getUserCourses($fk_user){
->findAll();
}


/**
* Gets a specific user_course entry-
*
* @param int $id_user_course ID of the user_course entry
*
* @return array
*
*/
public static function getUserCourseById($id_user_course)
{
return UserCourseModel::getInstance()
->where('id', $id_user_course)
->first();
}

/**
* Gets the user_course id from the user_course entry.
*
* @param int $fk_user ID of the user
* @param int $fk_course_plan ID of the course plan
* @param bool $onlyId If true, the function only returns the ID of the entry
*
* @return array
*
*/
public static function getUserCourseByUserAndCoursePlan($fk_user, $fk_course_plan, $onlyId = false)
{
$user_course = UserCourseModel::getInstance()
->where(
[
'fk_user' => $fk_user,
'fk_course_plan' => $fk_course_plan
])
->first();

if($onlyId)
return $user_course['id'];

else
return $user_course;
}

/**
* @param $fkCoursePlanId
* @return array
Expand Down

0 comments on commit f6ba8cb

Please sign in to comment.