Rename course_rel_user.tutor_id with is_tutor

Remove course_rel_user.role field

see #7509
1.10.x
Julio Montoya 10 years ago
parent 61dbad42b6
commit bcdd4f0037
  1. 15
      main/admin/course_edit.php
  2. 9
      main/auth/shibboleth/lib/shibboleth_session.class.php
  3. 4
      main/dropbox/dropbox_functions.inc.php
  4. 6
      main/inc/lib/add_course.lib.inc.php
  5. 12
      main/inc/lib/api.lib.php
  6. 84
      main/inc/lib/course.lib.php
  7. 29
      main/inc/lib/groupmanager.lib.php
  8. 44
      main/inc/lib/login.lib.php
  9. 6
      main/inc/lib/myspace.lib.php
  10. 4
      main/inc/lib/sessionmanager.lib.php
  11. 32
      main/inc/local.inc.php
  12. 97
      main/user/user.php
  13. 92
      src/Chamilo/CoreBundle/Entity/CourseRelUser.php
  14. 8
      src/Chamilo/CoreBundle/Migrations/Schema/v1/Version110.php

@ -297,8 +297,6 @@ if ($form->validate()) {
$warn = substr($warn, 0, -1);
}
$tutor_id = isset($course['tutor_name']) ? $course['tutor_name'] : null;
$tutor_name = isset($platform_teachers[$tutor_id]) ? $platform_teachers[$tutor_id] : null;
$teachers = $course['course_teachers'];
$title = $course['title'];
@ -316,10 +314,10 @@ if ($form->validate()) {
$department_url = 'http://' . $department_url;
}
$sql = "UPDATE $course_table SET course_language='" . Database::escape_string($course_language) . "',
$sql = "UPDATE $course_table SET
course_language='" . Database::escape_string($course_language) . "',
title='" . Database::escape_string($title) . "',
category_code='" . Database::escape_string($category_code) . "',
tutor_name='" . Database::escape_string($tutor_name) . "',
visual_code='" . Database::escape_string($visual_code) . "',
department_name='" . Database::escape_string($department_name) . "',
department_url='" . Database::escape_string($department_url) . "',
@ -370,16 +368,17 @@ if ($form->validate()) {
}
}
// No need to register me as a teacher.
/*
$sql = "INSERT IGNORE INTO " . $course_user_table . " SET
c_id = " . $courseInfo['real_id'] . ",
user_id = '" . $tutor_id . "',
status = '1',
role = '',
tutor_id='0',
sort='0',
is_tutor ='0',
sort = '0',
user_course_cat='0'";
Database::query($sql);
*/
if (array_key_exists('add_teachers_to_sessions_courses', $courseInfo)) {
$sql = "UPDATE $course_table SET
add_teachers_to_sessions_courses = '$addTeacherToSessionCourses'

@ -2,10 +2,9 @@
namespace Shibboleth;
use \ChamiloSession as Session;
use \Chamilo;
use \Database;
use \Redirect;
use Chamilo;
use ChamiloSession as Session;
use Database;
/**
@ -57,7 +56,7 @@ class ShibbolethSession
/* This must be set for local.inc.php to register correctly the global variables in session
* This is BAD. Logic should be migrated into a function and stop relying on global variables.
*/
global $_uid, $is_allowedCreateCourse, $is_platformAdmin, $_real_cid, $_courseUser, $is_courseAdmin;
global $_uid, $is_allowedCreateCourse, $is_platformAdmin, $_real_cid, $is_courseAdmin;
global $is_courseMember, $is_courseTutor, $is_courseCoach, $is_allowed_in_course, $is_sessionAdmin, $_gid;
$_uid = $uid;

@ -7,7 +7,7 @@
* to one file -- Patrick Cool <patrick.cool@UGent.be>, Ghent University
* @author Julio Montoya adding c_id support
*/
use \ChamiloSession as Session;
use ChamiloSession as Session;
$this_section = SECTION_COURSES;
@ -541,7 +541,7 @@ function display_add_form($dropbox_unid, $viewReceivedCategory, $viewSentCategor
|| $dropbox_person -> isCourseAdmin
|| dropbox_cnf('allowStudentToStudent')
|| $current_user['status'] != 5 // Always allow teachers.
|| $current_user['tutor_id'] == 1 // Always allow tutors.
|| $current_user['is_tutor'] == 1 // Always allow tutors.
) && $current_user['user_id'] != $_user['user_id']) { // Don't include yourself.
if ($current_user['user_id'] == $current_user_id) {
continue;

@ -1334,8 +1334,7 @@ class AddCourse
c_id = '" . $course_id . "',
user_id = '" . intval($user_id) . "',
status = '1',
role = '" . self::lang2db(get_lang('Professor')) . "',
tutor_id = '0',
is_tutor = '0',
sort = '" . ($i_course_sort) . "',
user_course_cat = '0'";
Database::query($sql);
@ -1358,8 +1357,7 @@ class AddCourse
c_id = '" . Database::escape_string($course_id) . "',
user_id = '" . Database::escape_string($key) . "',
status = '1',
role = '',
tutor_id = '0',
is_tutor = '0',
sort = '" . ($sort + 1) . "',
user_course_cat = '0'";
Database::query($sql);

@ -19,7 +19,7 @@ define('REQUIRED_MIN_MEMORY_LIMIT', '128');
define('REQUIRED_MIN_UPLOAD_MAX_FILESIZE', '10');
define('REQUIRED_MIN_POST_MAX_SIZE', '10');
use \ChamiloSession as Session;
use ChamiloSession as Session;
// USER STATUS CONSTANTS
/** global status of a user: student */
@ -5414,7 +5414,7 @@ function api_is_course_visible_for_user($userid = null, $cid = null) {
$tbl_course_user = Database :: get_main_table(TABLE_MAIN_COURSE_USER);
$sql = "SELECT
tutor_id, status, role
is_tutor, status
FROM $tbl_course_user
WHERE
user_id = '$userid' AND
@ -5427,10 +5427,8 @@ function api_is_course_visible_for_user($userid = null, $cid = null) {
if (Database::num_rows($result) > 0) {
// This user has got a recorded state for this course.
$cuData = Database::fetch_array($result);
$_courseUser['role'] = $cuData['role'];
$is_courseMember = true;
$is_courseTutor = ($cuData['tutor_id'] == 1);
$is_courseTutor = ($cuData['is_tutor'] == 1);
$is_courseAdmin = ($cuData['status'] == 1);
}
@ -5454,16 +5452,13 @@ function api_is_course_visible_for_user($userid = null, $cid = null) {
$row = Database::store_result($result);
if ($row[0]['id_coach'] == $userid) {
$_courseUser['role'] = 'Professor';
$is_courseMember = true;
$is_courseTutor = true;
$is_courseAdmin = false;
$is_courseCoach = true;
$is_sessionAdmin = false;
Session::write('_courseUser',$_courseUser);
}
elseif ($row[0]['session_admin_id'] == $userid) {
$_courseUser['role'] = 'Professor';
$is_courseMember = false;
$is_courseTutor = false;
$is_courseAdmin = false;
@ -5481,7 +5476,6 @@ function api_is_course_visible_for_user($userid = null, $cid = null) {
//if ($row = Database::fetch_array($result)) {
if (Database::num_rows($result) > 0 ) {
$_courseUser['role'] = 'Professor';
$is_courseMember = true;
$is_courseTutor = true;
$is_courseCoach = true;

@ -337,6 +337,54 @@ class CourseManager
return $result['status'];
}
/**
* @param int $userId
* @param int $courseId
*
* @return mixed
*/
public static function getUserCourseInfo($userId, $courseId)
{
$result = Database::fetch_array(
Database::query(
"SELECT * FROM " . Database::get_main_table(TABLE_MAIN_COURSE_USER) . "
WHERE
c_id = '" . intval($courseId). "' AND
user_id = " . intval($userId)
)
);
return $result;
}
/**
* @param int $userId
* @param int $courseId
* @param bool $isTutor
* @return bool
*/
public static function updateUserCourseTutor($userId, $courseId, $isTutor)
{
$table = Database::escape_string(TABLE_MAIN_COURSE_USER);
$courseId = intval($courseId);
$isTutor = intval($isTutor);
$sql = "UPDATE $table SET is_tutor = '".$isTutor."'
WHERE
user_id = '".$userId."' AND
c_id = '".$courseId."'";
$result = Database::query($sql);
if (Database::affected_rows($result) > 0) {
return true;
} else {
return false;
}
}
/**
* @param int $user_id
* @param string $course_code
@ -346,12 +394,12 @@ class CourseManager
{
$result = Database::fetch_array(
Database::query(
"SELECT tutor_id FROM " . Database::get_main_table(TABLE_MAIN_COURSE_USER) . "
"SELECT is_tutor FROM " . Database::get_main_table(TABLE_MAIN_COURSE_USER) . "
WHERE course_code = '" . Database::escape_string($course_code) . "' AND user_id = " . intval($user_id)
)
);
return $result['tutor_id'];
return $result['is_tutor'];
}
/**
@ -1316,15 +1364,13 @@ class CourseManager
course.code,
course_rel_user.status as status_rel,
user.user_id,
course_rel_user.role,
course_rel_user.tutor_id,
course_rel_user.is_tutor,
user.* ';
} else {
$sql = 'SELECT DISTINCT
course_rel_user.status as status_rel,
user.user_id,
course_rel_user.role,
course_rel_user.tutor_id,
course_rel_user.is_tutor,
user.* ';
}
}
@ -1422,11 +1468,8 @@ class CourseManager
$user_info = $user;
$user_info['status'] = $user['status'];
if (isset($user['role'])) {
$user_info['role'] = $user['role'];
}
if (isset($user['tutor_id'])) {
$user_info['tutor_id'] = $user['tutor_id'];
if (isset($user['is_tutor'])) {
$user_info['is_tutor'] = $user['is_tutor'];
}
if (!empty($session_id)) {
@ -1687,10 +1730,9 @@ class CourseManager
while ($user = Database::fetch_array($rs)) {
$user_info = api_get_user_info($user['user_id']);
$user_info['status'] = $user['status'];
$user_info['role'] = $user['role'];
$user_info['tutor_id'] = $user['tutor_id'];
//$user_info['tutor_id'] = $user['tutor_id'];
$user_info['email'] = $user['email'];
$users[$user['id_user']] = $user_info;
$users[$user['user_id']] = $user_info;
}
$table = Database::get_main_table(TABLE_MAIN_SESSION);
@ -1700,8 +1742,7 @@ class CourseManager
$session_id_coach = Database::result($rs, 0, 'id_coach');
$user_info = api_get_user_info($session_id_coach);
$user_info['status'] = $user['status'];
$user_info['role'] = $user['role'];
$user_info['tutor_id'] = $user['tutor_id'];
//$user_info['tutor_id'] = $user['tutor_id'];
$user_info['email'] = $user['email'];
$users[$session_id_coach] = $user_info;
@ -2450,8 +2491,7 @@ class CourseManager
$information = self::get_course_information($course_code);
$courseId = $information['id'];
$student = Database::fetch_array(Database::query("SELECT * FROM " . Database::get_main_table(TABLE_MAIN_USER) . "
WHERE user_id='" . $user_id . "'"));
$student = api_get_user_info($user_id);
$name_course = $information['title'];
$sql = "SELECT * FROM " . Database::get_main_table(TABLE_MAIN_COURSE_USER) . " WHERE c_id ='" . $courseId . "'";
@ -2460,15 +2500,14 @@ class CourseManager
//if ($send_to_tutor_also = true)
// Proposed change:
if ($send_to_tutor_also) {
$sql .= " AND tutor_id=1";
$sql .= " AND is_tutor=1";
} else {
$sql .= " AND status=1";
}
$result = Database::query($sql);
while ($row = Database::fetch_array($result)) {
$tutor = Database::fetch_array(Database::query("SELECT * FROM " . Database::get_main_table(TABLE_MAIN_USER) . "
WHERE user_id='" . $row['user_id'] . "'"));
$tutor = api_get_user_info($row['user_id']);
$emailto = $tutor['email'];
$emailsubject = get_lang('NewUserInTheCourse') . ': ' . $name_course;
$emailbody = get_lang('Dear') . ': ' . api_get_person_name($tutor['firstname'], $tutor['lastname']) . "\n";
@ -5092,8 +5131,7 @@ class CourseManager
c_id = '" . $courseId . "',
user_id = '" . $userId . "',
status = '1',
role = '',
tutor_id = '0',
is_tutor = '0',
sort = '0',
user_course_cat='0'";
}

@ -445,7 +445,6 @@ class GroupManager
$result['id'] = $db_object->id;
$result['name'] = $db_object->name;
$result['status'] = $db_object->status;
$result['tutor_id'] = isset($db_object->tutor_id) ? $db_object->tutor_id : null;
$result['description'] = $db_object->description;
$result['maximum_number_of_students'] = $db_object->max_student;
$result['max_student'] = $db_object->max_student;
@ -1480,8 +1479,9 @@ class GroupManager
$course_id = api_get_course_int_id();
$sql = "SELECT tg.id, u.user_id, u.lastname, u.firstname, u.email
FROM ".$table_user." u, ".$table_group_tutor." tg
WHERE tg.c_id = $course_id AND
FROM ".$table_user." u, ".$table_group_tutor." tg
WHERE
tg.c_id = $course_id AND
tg.group_id='".$group_id."' AND
tg.user_id=u.user_id".$order_clause;
$db_result = Database::query($sql);
@ -1494,7 +1494,7 @@ class GroupManager
$member['email'] = $user->email;
$users[] = $member;
} else {
$users[]=$user->user_id;
$users[] = $user->user_id;
}
}
return $users;
@ -1684,7 +1684,7 @@ class GroupManager
$sql = "SELECT user.user_id AS user_id, user.lastname AS lastname, user.firstname AS firstname
FROM ".$user_table." user, ".$course_user_table." cu
WHERE cu.user_id=user.user_id
AND cu.tutor_id='1'
AND cu.is_tutor='1'
AND cu.c_id='".api_get_course_int_id()."'";
$resultTutor = Database::query($sql);
$tutors = array();
@ -1705,10 +1705,10 @@ class GroupManager
$course_user_table = Database::get_main_table(TABLE_MAIN_COURSE_USER);
$user_id = intval($user_id);
$sql = "SELECT tutor_id FROM ".$course_user_table."
WHERE user_id = '".$user_id."' AND c_id ='".api_get_course_int_id()."'"." AND tutor_id=1";
$sql = "SELECT is_tutor FROM ".$course_user_table."
WHERE user_id = '".$user_id."' AND c_id ='".api_get_course_int_id()."'"." AND is_tutor=1";
$db_result = Database::query($sql);
$result = (Database::num_rows($db_result) > 0);
$result = Database::num_rows($db_result) > 0;
return $result;
}
@ -1799,7 +1799,7 @@ class GroupManager
$firstname = $this_user['firstname'];
$status = $this_user['status'];
//$role = $this_user['role'];
$tutor_id = $this_user['tutor_id'];
$isTutor = $this_user['is_tutor'];
$full_name = api_get_person_name($firstname, $lastname);
if ($lastname == "" || $firstname == '') {
$full_name = $loginname;
@ -1809,7 +1809,7 @@ class GroupManager
$complete_user['firstname'] = $firstname;
$complete_user['lastname'] = $lastname;
$complete_user['status'] = $status;
$complete_user['tutor_id'] = $tutor_id;
$complete_user['is_tutor'] = $isTutor;
$student_number_of_groups = self :: user_in_number_of_groups($user_id, $category['id']);
//filter: only add users that have not exceeded their maximum amount of groups
if ($student_number_of_groups < $number_of_groups_limit) {
@ -1868,7 +1868,6 @@ class GroupManager
{
$user_array_out = array();
foreach ($user_array_in as $this_user) {
//if ($this_user['status_rel'] == STUDENT && $this_user['tutor_id'] == 0) {
if (api_get_session_id()) {
if ($this_user['status_session'] == 0) {
$user_array_out[] = $this_user;
@ -1952,8 +1951,6 @@ class GroupManager
return true;
} elseif (api_is_allowed_to_edit(false, true)) {
return true;
} elseif ($groupInfo['tutor_id'] == $user_id) { //this tutor implementation was dropped
return true;
} elseif ($groupInfo[$state_key] == self::TOOL_PRIVATE && !$user_is_in_group) {
return false;
} else {
@ -2188,7 +2185,11 @@ class GroupManager
$tutor = api_get_user_info($tutor_id);
$username = api_htmlentities(sprintf(get_lang('LoginX'), $tutor['username']), ENT_QUOTES);
if (api_get_setting('show_email_addresses') == 'true') {
$tutor_info .= Display::tag('span', Display::encrypted_mailto_link($tutor['mail'], api_get_person_name($tutor['firstName'], $tutor['lastName'])), array('title'=>$username)).', ';
$tutor_info .= Display::tag(
'span',
Display::encrypted_mailto_link($tutor['mail'], api_get_person_name($tutor['firstName'], $tutor['lastName'])),
array('title'=>$username)
).', ';
} else {
if (api_is_allowed_to_edit()) {
$tutor_info .= Display::tag('span', Display::encrypted_mailto_link($tutor['mail'], api_get_person_name($tutor['firstName'], $tutor['lastName'])), array('title'=>$username)).', ';

@ -1,6 +1,6 @@
<?php
use \ChamiloSession as Session;
use ChamiloSession as Session;
/* For licensing terms, see /license.txt */
/**
@ -319,7 +319,6 @@ class Login
global $_cid;
global $_course;
global $_real_cid;
global $_courseUser;
global $is_courseAdmin; //course teacher
global $is_courseTutor; //course teacher - some rights
@ -526,23 +525,26 @@ class Login
$result = Database::query($sql);
$cuData = null;
if (Database::num_rows($result) > 0) { // this user have a recorded state for this course
if (Database::num_rows($result) > 0) {
// this user have a recorded state for this course
$cuData = Database::fetch_array($result, 'ASSOC');
$is_courseAdmin = (bool) ($cuData['status'] == 1 );
$is_courseTutor = (bool) ($cuData['tutor_id'] == 1 );
$is_courseAdmin = (bool) $cuData['status'] == 1;
$is_courseTutor = (bool) $cuData['is_tutor'] == 1;
$is_courseMember = true;
//Checking if the user filled the course legal agreement
// Checking if the user filled the course legal agreement
if ($_course['activate_legal'] == 1 && !api_is_platform_admin()) {
$user_is_subscribed = CourseManager::is_user_accepted_legal($user_id, $_course['id'], $session_id);
$user_is_subscribed = CourseManager::is_user_accepted_legal(
$user_id,
$_course['id'],
$session_id
);
if (!$user_is_subscribed) {
$url = api_get_path(WEB_CODE_PATH) . 'course_info/legal.php?course_code=' . $_course['code'] . '&session_id=' . $session_id;
header('Location: ' . $url);
exit;
}
}
$_courseUser['role'] = $cuData['role'];
Session::write('_courseUser', $_courseUser);
}
//We are in a session course? Check session permissions
@ -572,7 +574,6 @@ class Login
//I'm a session admin?
if (isset($row) && isset($row[0]) && $row[0]['session_admin_id'] == $user_id) {
$_courseUser['role'] = 'Professor';
$is_courseMember = false;
$is_courseTutor = false;
$is_courseAdmin = false;
@ -595,7 +596,6 @@ class Login
switch ($session_course_status) {
case '2': // coach - teacher
$_courseUser['role'] = 'Professor';
$is_courseMember = true;
$is_courseTutor = true;
$is_courseCoach = true;
@ -606,14 +606,12 @@ class Login
} else {
$is_courseAdmin = false;
}
Session::write('_courseUser', $_courseUser);
break;
case '0': //student
$is_courseMember = true;
$is_courseTutor = false;
$is_courseAdmin = false;
$is_sessionAdmin = false;
Session::write('_courseUser', $_courseUser);
break;
default:
//unregister user
@ -621,7 +619,6 @@ class Login
$is_courseTutor = false;
$is_courseAdmin = false;
$is_sessionAdmin = false;
Session::erase('_courseUser');
break;
}
} else {
@ -630,7 +627,6 @@ class Login
$is_courseTutor = false;
$is_courseAdmin = false;
$is_sessionAdmin = false;
Session::erase('_courseUser');
}
}
}
@ -647,7 +643,6 @@ class Login
$is_courseTutor = false;
$is_courseCoach = false;
$is_sessionAdmin = false;
Session::erase('_courseUser');
}
//Checking the course access
@ -709,16 +704,13 @@ class Login
Session::write('is_allowed_in_course', $is_allowed_in_course);
Session::write('is_sessionAdmin', $is_sessionAdmin);
} else { // continue with the previous values
if (isset($_SESSION ['_courseUser'])) {
$_courseUser = $_SESSION ['_courseUser'];
}
$is_courseAdmin = $_SESSION ['is_courseAdmin'];
$is_courseTutor = $_SESSION ['is_courseTutor'];
$is_courseCoach = $_SESSION ['is_courseCoach'];
$is_courseMember = $_SESSION ['is_courseMember'];
$is_allowed_in_course = $_SESSION ['is_allowed_in_course'];
} else {
// continue with the previous values
$is_courseAdmin = $_SESSION['is_courseAdmin'];
$is_courseTutor = $_SESSION['is_courseTutor'];
$is_courseCoach = $_SESSION['is_courseCoach'];
$is_courseMember = $_SESSION['is_courseMember'];
$is_allowed_in_course = $_SESSION['is_allowed_in_course'];
}
}

@ -1,9 +1,9 @@
<?php
/* For licensing terms, see /license.txt */
use CpChart\Classes\pCache as pCache;
use CpChart\Classes\pData as pData;
use CpChart\Classes\pImage as pImage;
use CpChart\Classes\pCache as pCache;
/**
* Class MySpace
@ -1253,7 +1253,7 @@ class MySpace
FROM $tbl_user AS u
INNER JOIN $tbl_course_rel_user AS cu
ON cu.user_id = u.user_id
WHERE cu.c_id = '".$courseId."' AND ISNULL(cu.role);";
WHERE cu.c_id = '".$courseId."'";
$result = Database::query($sql);
$time_spent = 0;
$progress = 0;
@ -1402,7 +1402,7 @@ class MySpace
FROM $tbl_user AS u
INNER JOIN $tbl_course_rel_user AS cu
ON cu.user_id = u.user_id
WHERE cu.course_code = '".$course_code."' AND ISNULL(cu.role);";
WHERE cu.course_code = '".$course_code."'";
$result = Database::query($sql);
$time_spent = 0;
$progress = 0;

@ -2085,7 +2085,8 @@ class SessionManager
VALUES ('$sessionId', '$courseId')";
Database::query($sql);
//We add the current course in the existing courses array, to avoid adding another time the current course
// We add the current course in the existing courses array,
// to avoid adding another time the current course
$existingCourses[] = array('c_id' => $courseId);
$nbr_courses++;
@ -2111,7 +2112,6 @@ class SessionManager
SET nbr_courses = $nbr_courses
WHERE id = '$sessionId'";
Database::query($sql);
exit;
}
/**

@ -116,7 +116,7 @@
//require_once api_get_path(LIBRARY_PATH).'conditionallogin.lib.php'; moved to autologin
// verified if exists the username and password in session current
use \ChamiloSession as Session;
use ChamiloSession as Session;
//Conditional login
if (isset($_SESSION['conditional_login']['uid']) && $_SESSION['conditional_login']['can_login'] === true) {
@ -1042,11 +1042,8 @@ if ((isset($uidReset) && $uidReset) || (isset($cidReset) && $cidReset)) {
$cuData = Database::fetch_array($result, 'ASSOC');
$is_courseAdmin = (bool)($cuData['status'] == 1);
$is_courseTutor = (bool)($cuData['tutor_id'] == 1);
$is_courseTutor = (bool)($cuData['is_tutor'] == 1);
$is_courseMember = true;
$_courseUser['role'] = $cuData['role'];
Session::write('_courseUser', $_courseUser);
}
// We are in a session course? Check session permissions
@ -1076,7 +1073,6 @@ if ((isset($uidReset) && $uidReset) || (isset($cidReset) && $cidReset)) {
// Am I a session admin?
if (isset($row) && isset($row[0]) && $row[0]['session_admin_id'] == $user_id) {
$_courseUser['role'] = 'Professor';
$is_courseMember = false;
$is_courseTutor = false;
$is_courseAdmin = false;
@ -1093,7 +1089,6 @@ if ((isset($uidReset) && $uidReset) || (isset($cidReset) && $cidReset)) {
$result = Database::query($sql);
if (Database::num_rows($result)) {
$_courseUser['role'] = 'Professor';
$is_courseMember = true;
$is_courseTutor = false;
$is_courseCoach = true;
@ -1116,7 +1111,6 @@ if ((isset($uidReset) && $uidReset) || (isset($cidReset) && $cidReset)) {
switch ($session_course_status) {
case '2': // coach - teacher
$_courseUser['role'] = 'Professor';
$is_courseMember = true;
$is_courseTutor = true;
$is_courseCoach = true;
@ -1127,27 +1121,22 @@ if ((isset($uidReset) && $uidReset) || (isset($cidReset) && $cidReset)) {
} else {
$is_courseAdmin = false;
}
Session::write('_courseUser', $_courseUser);
break;
case '0': //Student
$_courseUser['role'] = '';
$is_courseMember = true;
$is_courseTutor = false;
$is_courseAdmin = false;
$is_courseCoach = false;
$is_sessionAdmin = false;
Session::write('_courseUser', $_courseUser);
break;
default:
//unregister user
$_courseUser['role'] = '';
$is_courseMember = false;
$is_courseTutor = false;
$is_courseAdmin = false;
$is_sessionAdmin = false;
$is_courseCoach = false;
Session::erase('_courseUser');
break;
}
} else {
@ -1157,7 +1146,6 @@ if ((isset($uidReset) && $uidReset) || (isset($cidReset) && $cidReset)) {
$is_courseAdmin = false;
$is_sessionAdmin = false;
$is_courseCoach = false;
Session::erase('_courseUser');
}
}
}
@ -1167,7 +1155,6 @@ if ((isset($uidReset) && $uidReset) || (isset($cidReset) && $cidReset)) {
$sessionInfo = SessionManager::getSessionFollowedByDrh($user_id, $session_id);
if (!empty($sessionInfo) && !empty($sessionInfo['course_list'])) {
if (isset($sessionInfo['course_list'][$_course['real_id']])) {
$_courseUser['role'] = '';
$is_courseMember = true;
$is_courseTutor = false;
$is_courseCoach = false;
@ -1184,12 +1171,11 @@ if ((isset($uidReset) && $uidReset) || (isset($cidReset) && $cidReset)) {
}
} else { // keys missing => not anymore in the course - user relation
// course
$is_courseMember = false;
$is_courseAdmin = false;
$is_courseTutor = false;
$is_courseCoach = false;
$is_sessionAdmin = false;
Session::erase('_courseUser');
$is_courseMember = false;
$is_courseAdmin = false;
$is_courseTutor = false;
$is_courseCoach = false;
$is_sessionAdmin = false;
}
//Checking the course access
@ -1280,10 +1266,6 @@ if ((isset($uidReset) && $uidReset) || (isset($cidReset) && $cidReset)) {
} else {
// continue with the previous values
if (isset($_SESSION['_courseUser'])) {
$_courseUser = $_SESSION ['_courseUser'];
}
$is_courseAdmin = isset($_SESSION ['is_courseAdmin']) ? $_SESSION ['is_courseAdmin'] : false;
$is_courseTutor = isset($_SESSION ['is_courseTutor']) ? $_SESSION ['is_courseTutor'] : false;
$is_courseCoach = isset($_SESSION ['is_courseCoach']) ? $_SESSION ['is_courseCoach'] : false;

@ -21,9 +21,6 @@ $this_section = SECTION_COURSES;
// notice for unauthorized people.
api_protect_course_script(true);
/* Libraries */
require_once api_get_path(LIBRARY_PATH).'export.lib.inc.php';
global $_configuration;
if (!api_is_platform_admin(true)) {
@ -36,7 +33,7 @@ if (!api_is_platform_admin(true)) {
/* Constants and variables */
$course_code = Database::escape_string(api_get_course_id());
$session_id = api_get_session_id();
$sessionId = api_get_session_id();
$is_western_name_order = api_is_western_name_order();
$sort_by_first_name = api_sort_by_first_name();
$course_info = api_get_course_info();
@ -45,7 +42,7 @@ $courseCode = api_get_course_id();
$courseId = api_get_course_int_id();
//Can't auto unregister from a session
if (!empty($session_id)) {
if (!empty($sessionId)) {
$course_info['unsubscribe'] = 0;
}
@ -75,6 +72,37 @@ $user_image_pdf_size = 80;
if (api_is_allowed_to_edit(null, true)) {
if (isset($_GET['action'])) {
switch ($_GET['action']) {
case 'set_tutor':
$userId = isset($_GET['user_id']) ? intval($_GET['user_id']) : null;
$isTutor = isset($_GET['is_tutor']) ? intval($_GET['is_tutor']) : 0;
if (!empty($userId)) {
if ($sessionId) {
/*$res = SessionManager::set_coach_to_course_session(
$userId,
$sessionId,
$courseCode,
true
);*/
} else {
/*if (!empty($_POST['promoteCourseAdmin']) && $_POST['promoteCourseAdmin']){
$userProperties['status'] = 1;
} else{
$userProperties['status'] = 5;
}
if (!empty($_POST['promoteTutor']) && $_POST['promoteTutor']){
$userProperties['tutor'] = 1;
} else{
$userProperties['tutor'] = 0;
}*/
CourseManager::updateUserCourseTutor(
$userId,
$courseId,
$isTutor
);
}
}
break;
case 'export':
$table_course_user = Database::get_main_table(TABLE_MAIN_COURSE_USER);
$table_users = Database::get_main_table(TABLE_MAIN_USER);
@ -191,7 +219,7 @@ if (api_is_allowed_to_edit(null, true)) {
$sql_query .= ' , '.Database::get_main_table(TABLE_MAIN_ACCESS_URL_REL_USER).' au ';
}
$sql_query .=" WHERE c_id = '$courseId' AND session_course_user.user_id = user.user_id ";
$sql_query .= ' AND session_id = '.$session_id;
$sql_query .= ' AND session_id = '.$sessionId;
if (api_is_multiple_url_enabled()) {
$sql_query .= " AND user.user_id = au.user_id AND access_url_id = $current_access_url_id ";
@ -256,7 +284,7 @@ if (api_is_allowed_to_edit(null, true)) {
}
}
if ($session_id == 0) {
if ($sessionId == 0) {
// users directly subscribed to the course
$table_course_user = Database :: get_main_table(TABLE_MAIN_COURSE_USER);
@ -585,10 +613,11 @@ function get_user_data($from, $number_of_items, $column, $direction)
{
global $origin;
global $is_western_name_order;
global $session_id;
global $extraFields;
$course_info = api_get_course_info();
$sessionId = api_get_session_id();
$course_code = api_get_course_id();
$a_users = array();
@ -631,13 +660,11 @@ function get_user_data($from, $number_of_items, $column, $direction)
break;
}
$session_id = api_get_session_id();
$course_code = api_get_course_id();
$active = isset($_GET['active']) ? $_GET['active'] : null;
$a_course_users = CourseManager :: get_user_list_from_course_code(
$course_code,
$session_id,
$sessionId,
$limit,
$order_by,
null,
@ -697,19 +724,20 @@ function get_user_data($from, $number_of_items, $column, $direction)
}
$temp[] = $o_course_user['username'];
// Description.
$temp[] = isset($o_course_user['role']) ? $o_course_user['role'] : null;
// Groups.
$temp[] = implode(', ', $groupsNameList);
// Status
$default_status = '-';
$default_status = get_lang('Student');
if ((isset($o_course_user['status_rel']) && $o_course_user['status_rel'] == 1) ||
(isset($o_course_user['status_session']) && $o_course_user['status_session'] == 2)
) {
$default_status = get_lang('CourseManager');
} elseif (isset($o_course_user['tutor_id']) && $o_course_user['tutor_id'] == 1) {
} elseif (isset($o_course_user['is_tutor']) && $o_course_user['is_tutor'] == 1) {
$default_status = get_lang('Tutor');
}
$temp[] = $default_status;
// Active
@ -728,6 +756,9 @@ function get_user_data($from, $number_of_items, $column, $direction)
// User id for actions
$temp[] = $user_id;
$temp['is_tutor'] = isset($o_course_user['is_tutor']) ? $o_course_user['is_tutor'] : '';
$temp['user_status_in_course'] = isset($o_course_user['status_rel']) ? $o_course_user['status_rel'] : '';
$temp['user_status_in_course_session'] = $o_course_user['status_session'];
} else {
$image_path = UserManager::get_user_picture_path_by_id($user_id, 'web', false, true);
$image_repository = $image_path['dir'];
@ -749,7 +780,6 @@ function get_user_data($from, $number_of_items, $column, $direction)
$temp[] = $o_course_user['firstname'];
}
$temp[] = $o_course_user['username'];
$temp[] = $o_course_user['role'];
// Group.
$temp[] = implode(', ', $groupsNameList);
@ -792,20 +822,23 @@ function active_filter($active, $url_params, $row)
if ($row[count($row)-1] <> $userId) {
$result = '<center><img src="../img/icons/16/'.$image.'.png" border="0" style="vertical-align: middle;" alt="'.get_lang(ucfirst($action)).'" title="'.get_lang(ucfirst($action)).'"/></center>';
}
return $result;
}
/**
* Build the modify-column of the table
* @param int $user_id The user id
* @return string Some HTML-code
*/
function modify_filter($user_id)
function modify_filter($user_id, $row, $data)
{
global $origin, $_course, $is_allowed_to_track, $charset, $course_info;
global $origin, $is_allowed_to_track, $charset;
$user_id = $data[0];
$course_info = $_course = api_get_course_info();
$current_user_id = api_get_user_id();
$sessionId = api_get_session_id();
$result = "";
@ -823,9 +856,22 @@ function modify_filter($user_id)
}
if (api_is_allowed_to_edit(null, true)) {
if (empty($sessionId)) {
$isTutor = isset($data['is_tutor']) ? intval($data['is_tutor']) : 0;
$isTutor = empty($isTutor) ? 1 : 0;
$disabled = '';
if ($data['user_status_in_course'] == COURSEMANAGER) {
$disabled = 'disabled';
}
$result .= Display::url(
get_lang('SetTutor'),
'user.php?'.api_get_cidreq().'&action=set_tutor&is_tutor='.$isTutor.'&user_id='.$user_id,
array('class' => 'btn btn-default '.$disabled)
).'&nbsp;';
}
// edit
$result .= '<a href="userInfo.php?'.api_get_cidreq().'&origin='.$origin.'&amp;editMainUserInfo='.$user_id.'" title="'.get_lang('Edit').'" >'.
Display::return_icon('edit.png', get_lang('Edit'),'',ICON_SIZE_SMALL).'</a>&nbsp;';
if (api_get_setting('allow_user_course_subscription_by_course_admin') == 'true' or api_is_platform_admin()) {
// unregister
if ($user_id != $current_user_id || api_is_platform_admin()) {
@ -880,8 +926,6 @@ if ($is_western_name_order) {
}
$indexList['username'] = $header_nr;
$table->set_header($header_nr++, get_lang('LoginName'));
$indexList['description'] = $header_nr;
$table->set_header($header_nr++, get_lang('Description'), false);
$indexList['groups'] = $header_nr;
$table->set_header($header_nr++, get_lang('GroupSingle'), false);
@ -934,13 +978,6 @@ if (!empty($_GET['keyword']) && !empty($_GET['submit'])) {
echo '<br/>'.get_lang('SearchResultsFor').' <span style="font-style: italic ;"> '.$keyword_name.' </span><br>';
}
if (api_get_setting('allow_user_headings') == 'true' &&
$is_courseAdmin &&
api_is_allowed_to_edit() && $origin != 'learnpath'
) {
// only course administrators see this line
echo "<div align=\"right\">", "<form method=\"post\" action=\"userInfo.php\">", get_lang("CourseAdministratorOnly"), " : ", "<input type=\"submit\" class=\"save\" name=\"viewDefList\" value=\"".get_lang("DefineHeadings")."\" />", "</form>", "</div>\n";
}
if ($origin != 'learnpath') {
Display::display_footer();
}

@ -3,7 +3,6 @@
namespace Chamilo\CoreBundle\Entity;
use Chamilo\CourseBundle\Entity\CGroupInfo;
use Chamilo\UserBundle\Entity\User;
use Doctrine\ORM\Mapping as ORM;
@ -47,18 +46,11 @@ class CourseRelUser
private $status;
/**
* @var string
* @todo this value should be renamed to description
* @ORM\Column(name="role", type="string", length=60, precision=0, scale=0, nullable=true, unique=false)
*/
private $role;
/**
* @var integer
* @var bool
*
* @ORM\Column(name="tutor_id", type="integer", precision=0, scale=0, nullable=true, unique=false)
* @ORM\Column(name="is_tutor", type="boolean", nullable=true, unique=false)
*/
private $tutorId;
private $tutor;
/**
* @var integer
@ -213,96 +205,44 @@ class CourseRelUser
return $this->status;
}
/**
* Set role
*
* @param string $role
* @return CourseRelUser
*/
public function setRole($role)
{
$this->role = $role;
return $this;
}
/**
* Get role
*
* @return string
*/
public function getRole()
{
return $this->role;
}
/**
* Set groupId
*
* @param integer $groupId
* @return CourseRelUser
*/
public function setGroupId($groupId)
{
$this->groupId = $groupId;
return $this;
}
/**
* Get groupId
*
* @return integer
*/
public function getGroupId()
{
return $this->groupId;
}
/**
* Set tutorId
* Set sort
*
* @param integer $tutorId
* @param integer $sort
* @return CourseRelUser
*/
public function setTutorId($tutorId)
public function setSort($sort)
{
$this->tutorId = $tutorId;
$this->sort = $sort;
return $this;
}
/**
* Get tutorId
* Get sort
*
* @return integer
*/
public function getTutorId()
public function getSort()
{
return $this->tutorId;
return $this->sort;
}
/**
* Set sort
*
* @param integer $sort
* @return CourseRelUser
* @return boolean
*/
public function setSort($sort)
public function isTutor()
{
$this->sort = $sort;
return $this;
return $this->tutor;
}
/**
* Get sort
*
* @return integer
* @param boolean $tutor
*/
public function getSort()
public function setTutor($tutor)
{
return $this->sort;
$this->tutor = $tutor;
}
/**

@ -3,8 +3,8 @@
namespace Chamilo\CoreBundle\Migrations\Schema\v1;
use Chamilo\CoreBundle\Migrations\AbstractMigrationChamilo,
Doctrine\DBAL\Schema\Schema;
use Chamilo\CoreBundle\Migrations\AbstractMigrationChamilo;
use Doctrine\DBAL\Schema\Schema;
/**
* Class Core
@ -323,6 +323,9 @@ class Version110 extends AbstractMigrationChamilo
$table = $schema->getTable('c_item_property');
$table->renameColumn('id_session', 'session_id');
$table = $schema->getTable('course_rel_user');
$table->renameColumn('tutor_id', 'is_tutor');
$this->addSql("ALTER TABLE session_rel_user DROP PRIMARY KEY");
$this->addSql("ALTER TABLE session_rel_user ADD COLUMN id int unsigned NOT NULL PRIMARY KEY AUTO_INCREMENT");
@ -461,6 +464,7 @@ class Version110 extends AbstractMigrationChamilo
$this->addSql("ALTER TABLE track_e_attempt DROP COLUMN course_code");
$this->addSql("ALTER TABLE course_rel_user DROP COLUMN group_id");
$this->addSql("ALTER TABLE course_rel_user DROP COLUMN role");
$this->addSql("DROP TABLE track_c_countries");
$this->addSql("DROP TABLE track_c_browsers");

Loading…
Cancel
Save