|
|
|
@ -57,112 +57,6 @@ class Auth |
|
|
|
|
return $data; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* stores the changes in a course category |
|
|
|
|
* (moving a course to a different course category). |
|
|
|
|
* |
|
|
|
|
* @param int $courseId |
|
|
|
|
* @param int Category id |
|
|
|
|
* |
|
|
|
|
* @return bool True if it success |
|
|
|
|
*/ |
|
|
|
|
public function updateCourseCategory($courseId, $newcategory) |
|
|
|
|
{ |
|
|
|
|
$courseId = (int) $courseId; |
|
|
|
|
$newcategory = (int) $newcategory; |
|
|
|
|
$current_user = api_get_user_id(); |
|
|
|
|
|
|
|
|
|
$table = Database::get_main_table(TABLE_MAIN_COURSE_USER); |
|
|
|
|
$max_sort_value = api_max_sort_value($newcategory, $current_user); |
|
|
|
|
$sql = "UPDATE $table SET |
|
|
|
|
user_course_cat='".$newcategory."', |
|
|
|
|
sort='".($max_sort_value + 1)."' |
|
|
|
|
WHERE |
|
|
|
|
c_id ='".$courseId."' AND |
|
|
|
|
user_id='".$current_user."' AND |
|
|
|
|
relation_type<>".COURSE_RELATION_TYPE_RRHH; |
|
|
|
|
$resultQuery = Database::query($sql); |
|
|
|
|
|
|
|
|
|
$result = false; |
|
|
|
|
if (Database::affected_rows($resultQuery)) { |
|
|
|
|
$result = true; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
return $result; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* moves the course one place up or down. |
|
|
|
|
* |
|
|
|
|
* @param string Direction (up/down) |
|
|
|
|
* @param string Course code |
|
|
|
|
* @param int Category id |
|
|
|
|
* |
|
|
|
|
* @return bool True if it success |
|
|
|
|
*/ |
|
|
|
|
public function move_course($direction, $course2move, $category) |
|
|
|
|
{ |
|
|
|
|
$table = Database::get_main_table(TABLE_MAIN_COURSE_USER); |
|
|
|
|
|
|
|
|
|
$current_user_id = api_get_user_id(); |
|
|
|
|
$all_user_courses = CourseManager::getCoursesByUserCourseCategory($current_user_id); |
|
|
|
|
|
|
|
|
|
// we need only the courses of the category we are moving in |
|
|
|
|
$user_courses = []; |
|
|
|
|
foreach ($all_user_courses as $key => $course) { |
|
|
|
|
if ($course['user_course_category'] == $category) { |
|
|
|
|
$user_courses[] = $course; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
$target_course = []; |
|
|
|
|
foreach ($user_courses as $count => $course) { |
|
|
|
|
if ($course2move == $course['code']) { |
|
|
|
|
// source_course is the course where we clicked the up or down icon |
|
|
|
|
$source_course = $course; |
|
|
|
|
// target_course is the course before/after the source_course (depending on the up/down icon) |
|
|
|
|
if ('up' == $direction) { |
|
|
|
|
$target_course = $user_courses[$count - 1]; |
|
|
|
|
} else { |
|
|
|
|
$target_course = $user_courses[$count + 1]; |
|
|
|
|
} |
|
|
|
|
break; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
$result = false; |
|
|
|
|
if (count($target_course) > 0 && count($source_course) > 0) { |
|
|
|
|
$courseInfo = api_get_course_info($source_course['code']); |
|
|
|
|
$courseId = $courseInfo['real_id']; |
|
|
|
|
|
|
|
|
|
$targetCourseInfo = api_get_course_info($target_course['code']); |
|
|
|
|
$targetCourseId = $targetCourseInfo['real_id']; |
|
|
|
|
|
|
|
|
|
$sql = "UPDATE $table |
|
|
|
|
SET sort='".$target_course['sort']."' |
|
|
|
|
WHERE |
|
|
|
|
c_id = '".$courseId."' AND |
|
|
|
|
user_id = '".$current_user_id."' AND |
|
|
|
|
relation_type<>".COURSE_RELATION_TYPE_RRHH; |
|
|
|
|
|
|
|
|
|
$result1 = Database::query($sql); |
|
|
|
|
|
|
|
|
|
$sql = "UPDATE $table SET sort='".$source_course['sort']."' |
|
|
|
|
WHERE |
|
|
|
|
c_id ='".$targetCourseId."' AND |
|
|
|
|
user_id='".$current_user_id."' AND |
|
|
|
|
relation_type<>".COURSE_RELATION_TYPE_RRHH; |
|
|
|
|
|
|
|
|
|
$result2 = Database::query($sql); |
|
|
|
|
|
|
|
|
|
if (Database::affected_rows($result1) && Database::affected_rows($result2)) { |
|
|
|
|
$result = true; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
return $result; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* unsubscribe the user from a given course. |
|
|
|
|
* |
|
|
|
|