Internal - Fix php errors, use course.id instead of course.code

pull/3464/head
Julio Montoya 4 years ago
parent a5a5d7a58a
commit 81bcf3c32a
  1. 2
      public/main/auth/courses.php
  2. 2
      public/main/extra/myStudents.php
  3. 4
      public/main/inc/lib/agenda.lib.php
  4. 2
      public/main/inc/lib/api.lib.php
  5. 87
      public/main/inc/lib/course.lib.php
  6. 4
      public/main/inc/lib/document.lib.php
  7. 21
      public/main/inc/lib/formvalidator/FormValidator.class.php
  8. 2
      public/main/mySpace/lp_tracking.php
  9. 4
      public/main/mySpace/myStudents.php
  10. 4
      public/main/mySpace/student.php
  11. 2
      public/main/mySpace/teachers.php
  12. 5
      public/main/user/user_import.php
  13. 3
      src/CoreBundle/Repository/UserRepository.php

@ -434,7 +434,7 @@ switch ($action) {
$course['image_url'] = $settingsUrl[$courseCatalogSettings['image_url']];
$userRegisteredInCourse = CourseManager::is_user_subscribed_in_course($user_id, $course['code']);
$userRegisteredInCourseAsTeacher = CourseManager::is_course_teacher($user_id, $course['code']);
$userRegisteredInCourseAsTeacher = CourseManager::isCourseTeacher($user_id, $course['real_id']);
$userRegistered = $userRegisteredInCourse && $userRegisteredInCourseAsTeacher;
$course_public = COURSE_VISIBILITY_OPEN_WORLD == $course['visibility'];

@ -29,7 +29,7 @@ if (!api_is_allowed_to_create_course() &&
// Francois Belisle Kezber...
// If user is NOT a teacher -> student, but IS the teacher of the course... Won't have the global teacher status
// and won't be tutor... So have to check is_course_teacher
if ((1 != $user_course_status) && !(CourseManager::is_course_teacher(api_get_user_id(), $course_code))) {
if ((1 != $user_course_status) && !(CourseManager::isCourseTeacher(api_get_user_id(), api_get_course_int_id()))) {
api_not_allowed(true);
}
}

@ -1791,9 +1791,9 @@ class Agenda
if (api_is_platform_admin() || api_is_allowed_to_edit()) {
$isAllowToEdit = true;
} else {
$isAllowToEdit = CourseManager::is_course_teacher(
$isAllowToEdit = CourseManager::isCourseTeacher(
$userId,
$courseInfo['code']
$courseId
);
}

@ -7237,7 +7237,7 @@ function api_detect_user_roles($user_id, $courseId, $session_id = 0)
if (!empty($course_code)) {
if (empty($session_id)) {
if (CourseManager::is_course_teacher($user_id, $course_code)) {
if (CourseManager::isCourseTeacher($user_id, $courseInfo['real_id'])) {
$user_roles[] = COURSEMANAGER;
}
if (CourseManager::get_tutor_in_course_status($user_id, $courseInfo['real_id'])) {

@ -1161,78 +1161,9 @@ class CourseManager
$url = api_get_url_entity();
$user = api_get_user_entity($userId);
$repo = Container::getUserRepository();
return $repo->getCourses($user, $url, COURSEMANAGER, $keyword);
// Definitions database tables and variables
$tbl_course = Database::get_main_table(TABLE_MAIN_COURSE);
$tbl_course_user = Database::get_main_table(TABLE_MAIN_COURSE_USER);
$tblCourseCategory = Database::get_main_table(TABLE_MAIN_CATEGORY);
$userId = (int) $userId;
if (empty($userId)) {
return [];
}
$sql = "SELECT
course.code,
course.title,
course.id,
course.id as real_id,
course_category.code AS category_code
FROM $tbl_course_user as course_rel_user
INNER JOIN $tbl_course as course
ON course.id = course_rel_user.c_id
LEFT JOIN $tblCourseCategory
ON course.category_id = $tblCourseCategory.id
WHERE
course_rel_user.user_id = $userId AND
course_rel_user.status = 1
";
if (api_get_multiple_access_url()) {
$tbl_course_rel_access_url = Database::get_main_table(TABLE_MAIN_ACCESS_URL_REL_COURSE);
$access_url_id = api_get_current_access_url_id();
if (-1 != $access_url_id) {
$sql = "
SELECT
course.code,
course.title,
course.id,
course.id as real_id
FROM $tbl_course_user as course_rel_user
INNER JOIN $tbl_course as course
ON course.id = course_rel_user.c_id
INNER JOIN $tbl_course_rel_access_url course_rel_url
ON (course_rel_url.c_id = course.id)
WHERE
access_url_id = $access_url_id AND
course_rel_user.user_id = $userId AND
course_rel_user.status = 1
";
}
}
if (!empty($keyword)) {
$keyword = Database::escape_string($keyword);
$sql .= " AND (course.title LIKE '$keyword%' OR course.code LIKE '$keyword%')";
}
$sql .= ' ORDER BY course.title';
$query = Database::query($sql);
$data = [];
if (Database::num_rows($query) > 0) {
while ($row = Database::fetch_array($query, 'ASSOC')) {
$data[$row['id']] = $row;
}
}
return $data;
}
/**
@ -1371,22 +1302,20 @@ class CourseManager
/**
* Is the user a teacher in the given course?
*
* @param int $userId , the id (int) of the user
* @param string $course_code , the course code
* @param int $userId
* @param int $courseId
*
* @return bool if the user is a teacher in the course, false otherwise
*/
public static function is_course_teacher($userId, $course_code)
public static function isCourseTeacher($userId, $courseId)
{
if ($userId != strval(intval($userId))) {
return false;
}
$userId = (int) $userId;
$courseId = (int) $courseId;
$courseInfo = api_get_course_info($course_code);
if (empty($courseInfo)) {
if (empty($courseId) || empty($userId)) {
return false;
}
$courseId = $courseInfo['real_id'];
$sql = "SELECT status FROM ".Database::get_main_table(TABLE_MAIN_COURSE_USER)."
WHERE c_id = $courseId AND user_id = $userId ";
$result = Database::query($sql);
@ -5175,7 +5104,7 @@ class CourseManager
);
$userRegisteredInCourse = self::is_user_subscribed_in_course($user_id, $course_info['code']);
$userRegisteredInCourseAsTeacher = self::is_course_teacher($user_id, $course_info['code']);
$userRegisteredInCourseAsTeacher = self::isCourseTeacher($user_id, $courseId['c_id']);
$userRegistered = $userRegisteredInCourse && $userRegisteredInCourseAsTeacher;
$my_course['is_course_student'] = $userRegisteredInCourse;
$my_course['is_course_teacher'] = $userRegisteredInCourseAsTeacher;

@ -2984,7 +2984,7 @@ class DocumentManager
$userInfo = api_get_user_info();
$user_in_course = api_is_platform_admin();
if (!$user_in_course) {
if (CourseManager::is_course_teacher($user_id, $course_info['code'])) {
if (CourseManager::isCourseTeacher($user_id, $course_info['real_id'])) {
$user_in_course = true;
}
}
@ -3346,7 +3346,7 @@ class DocumentManager
if (!empty($document_data)) {
// If admin or course teacher, allow anyway
if (api_is_platform_admin() || CourseManager::is_course_teacher($user_id, $courseCode)) {
if (api_is_platform_admin() || CourseManager::isCourseTeacher($user_id, $courseInfo['real_id'])) {
return true;
}

@ -1730,6 +1730,18 @@ EOT;
}
}
/**
* Add email rule for an element.
*/
public function addEmailRule(string $element)
{
$this->addRule(
$element,
get_lang('The email address is not complete or contains some invalid characters'),
'email'
);
}
/**
* @param string $url page that will handle the upload
* @param string $inputName
@ -1864,15 +1876,6 @@ EOT;
});
</script>");
}
public function addEmailRule(string $element)
{
$this->addRule(
$element,
get_lang('The email address is not complete or contains some invalid characters'),
'email'
);
}
}
/**

@ -40,7 +40,7 @@ if (!$isBoss &&
!api_is_platform_admin(true) &&
!api_is_drh() &&
!api_is_course_tutor() &&
!CourseManager::is_course_teacher(api_get_user_id(), $courseCode) &&
!CourseManager::isCourseTeacher(api_get_user_id(), $courseInfo['real_id']) &&
!Tracking::is_allowed_to_coach_student(api_get_user_id(), $user_id)
) {
api_not_allowed('learnpath' !== api_get_origin());

@ -62,9 +62,9 @@ if (!api_is_session_admin() &&
$isTeacher = false;
// Check if is current teacher if set
if (!empty($courseInfo)) {
$isTeacher = CourseManager::is_course_teacher(
$isTeacher = CourseManager::isCourseTeacher(
api_get_user_id(),
$courseInfo['code']
$courseInfo['real_id']
);
}

@ -82,7 +82,7 @@ function get_users($from, $limit, $column, $direction)
}
$is_western_name_order = api_is_western_name_order();
$coach_id = api_get_user_id();
$column = 'u.id';
$column = 'u.user_id';
$drhLoaded = false;
if (api_is_drh()) {
@ -128,7 +128,7 @@ function get_users($from, $limit, $column, $direction)
$all_datas = [];
foreach ($students as $student_data) {
$student_id = $student_data['id'];
$student_id = $student_data['user_id'];
$student_data = api_get_user_info($student_id);
if (isset($_GET['id_session'])) {

@ -113,7 +113,7 @@ function get_users($from, $limit, $column, $direction)
$all_datas = [];
$url = api_get_path(WEB_CODE_PATH).'mySpace/myStudents.php';
foreach ($students as $student_data) {
$student_id = $student_data['id'];
$student_id = $student_data['user_id'];
$student_data = api_get_user_info($student_id);
if (isset($_GET['id_session'])) {
$courses = Tracking::get_course_list_in_session_from_student($student_id, $_GET['id_session']);

@ -32,6 +32,7 @@ $form->addElement('hidden', 'type', $userType);
$form->addButtonImport(get_lang('Import'));
$course_code = api_get_course_id();
$courseId = api_get_course_int_id();
if (empty($course_code)) {
api_not_allowed(true);
@ -89,11 +90,11 @@ if ($form->validate()) {
$user_ids = [];
foreach ($current_user_list as $user) {
if (COURSEMANAGER == $userType) {
if (CourseManager::is_course_teacher($user['user_id'], $course_code)) {
if (CourseManager::isCourseTeacher($user['user_id'], $courseId)) {
$user_ids[] = $user['user_id'];
}
} else {
if (!CourseManager::is_course_teacher($user['user_id'], $course_code)) {
if (!CourseManager::isCourseTeacher($user['user_id'], $courseId)) {
$user_ids[] = $user['user_id'];
}
}

@ -260,7 +260,6 @@ class UserRepository extends ResourceRepository implements UserLoaderInterface,
$qb
->select('DISTINCT course')
//->addSelect('user.courses')
->innerJoin(
CourseRelUser::class,
'courseRelUser',
@ -278,7 +277,7 @@ class UserRepository extends ResourceRepository implements UserLoaderInterface,
if (!empty($keyword)) {
$qb
->andWhere('course.title like = :keyword')
->andWhere('course.title like = :keyword OR course.code like = :keyword')
->setParameter('keyword', $keyword);
}

Loading…
Cancel
Save