Merge pull request #13 from chamilo/1.9.x

1.9.x
1.9.x
ycastillo 11 years ago
commit 84e2298d58
  1. 8
      main/admin/index.php
  2. 7
      main/attendance/attendance_list.php
  3. 2
      main/cron/import_csv.php
  4. 1
      main/inc/lib/course.lib.php
  5. 1
      main/inc/lib/pear/HTML/QuickForm.php
  6. 147
      main/inc/lib/sessionmanager.lib.php

@ -106,10 +106,10 @@ if (api_is_platform_admin()) {
$items = array();
$items[] = array('url'=>'course_list.php', 'label' => get_lang('CourseList'));
if (api_get_setting('course_validation') != 'true') {
$items[] = array('url'=>'course_add.php', 'label' => get_lang('AddCourse'));
} else {
$items[] = array('url'=>'course_add.php', 'label' => get_lang('AddCourse'));
if (api_get_setting('course_validation') == 'true') {
$items[] = array('url'=>'course_request_review.php', 'label' => get_lang('ReviewCourseRequests'));
$items[] = array('url'=>'course_request_accepted.php', 'label' => get_lang('AcceptedCourseRequests'));
$items[] = array('url'=>'course_request_rejected.php', 'label' => get_lang('RejectedCourseRequests'));

@ -19,7 +19,12 @@ if (api_is_allowed_to_edit(null, true)) {
echo '<a href="index.php?'.api_get_cidreq().$param_gradebook.'&action=attendance_add">'.Display::return_icon('new_attendance_list.png',get_lang('CreateANewAttendance'),'',ICON_SIZE_MEDIUM).'</a>';
echo '</div>';
}
$attendance = new Attendance();
if ($attendance->get_number_of_attendances() == 0) {
$attendance->set_name(get_lang('Attendances'));
$attendance->set_description(get_lang('Attendances'));
$attendance->attendance_add();
}
$table = new SortableTable('attendance_list', array('Attendance', 'get_number_of_attendances'), array('Attendance', 'get_attendance_data'), $default_column);
$table->set_additional_parameters($parameters);
$table->set_header(0, '', false, array('style'=>'width:20px;'));

@ -528,8 +528,6 @@ class ImportCsv
foreach ($data as $row) {
$row = $this->cleanCourseRow($row);
$courseCode = CourseManager::get_course_id_from_original_id($row['extra_'.$this->extraFieldIdNameList['course']], $this->extraFieldIdNameList['course']);
//$courseInfo = api_get_course_info($row['course_code']);
$courseInfo = api_get_course_info($courseCode);
if (empty($courseInfo)) {
// Create

@ -4016,7 +4016,6 @@ class CourseManager {
}
$course_user_table = Database::get_main_table(TABLE_MAIN_COURSE_USER);
$alreadyAddedTeachers = CourseManager::get_teacher_list_from_course_code($course_code);
if ($deleteTeachersNotInList) {

@ -1549,7 +1549,6 @@ class HTML_QuickForm extends HTML_Common
foreach ($this->_rules as $target => $rules) {
$submitValue = $this->getSubmitValue($target);
foreach ($rules as $rule) {
if ((isset($rule['group']) && isset($this->_errors[$rule['group']])) ||
isset($this->_errors[$target])) {

@ -785,7 +785,20 @@ class SessionManager
}
}
function subscribe_users_to_session_course($user_list, $session_id, $course_code, $session_visibility = SESSION_VISIBLE_READ_ONLY ) {
/**
* @param array $user_list
* @param int $session_id
* @param string $course_code
* @param int $session_visibility
* @return bool
*/
public static function subscribe_users_to_session_course(
$user_list,
$session_id,
$course_code,
$session_visibility = SESSION_VISIBLE_READ_ONLY
)
{
$tbl_session_rel_course = Database::get_main_table(TABLE_MAIN_SESSION_COURSE);
$tbl_session_rel_course_rel_user = Database::get_main_table(TABLE_MAIN_SESSION_COURSE_USER);
@ -798,24 +811,41 @@ class SessionManager
$session_visibility = intval($session_visibility);
$nbr_users = 0;
/*AND
visibility = $session_visibility*/
foreach ($user_list as $enreg_user) {
//if (!in_array($enreg_user, $existingUsers)) {
$enreg_user = intval($enreg_user);
$enreg_user = intval($enreg_user);
$sql = "SELECT count(id_user) as count
FROM $tbl_session_rel_course_rel_user
WHERE id_session = $session_id AND
course_code = '$course_code' and
id_user = $enreg_user ";
$result = Database::query($sql);
$count = 0;
if (Database::num_rows($result) > 0) {
$row = Database::fetch_array($result, 'ASSOC');
$count = $row['count'];
}
if ($count == 0) {
$insert_sql = "INSERT IGNORE INTO $tbl_session_rel_course_rel_user(id_session,course_code,id_user,visibility)
VALUES ('$session_id','$course_code','$enreg_user','$session_visibility')";
Database::query($insert_sql);
if (Database::affected_rows()) {
$nbr_users++;
}
//}
}
}
// count users in this session-course relation
$sql = "SELECT COUNT(id_user) as nbUsers FROM $tbl_session_rel_course_rel_user WHERE id_session='$session_id' AND course_code='$course_code' AND status<>2";
$sql = "SELECT COUNT(id_user) as nbUsers FROM $tbl_session_rel_course_rel_user
WHERE id_session='$session_id' AND course_code='$course_code' AND status<>2";
$rs = Database::query($sql);
list($nbr_users) = Database::fetch_array($rs);
// update the session-course relation to add the users total
$update_sql = "UPDATE $tbl_session_rel_course SET nbr_users=$nbr_users WHERE id_session='$session_id' AND course_code='$course_code'";
$update_sql = "UPDATE $tbl_session_rel_course SET nbr_users=$nbr_users
WHERE id_session='$session_id' AND course_code='$course_code'";
Database::query($update_sql);
}
@ -2159,6 +2189,7 @@ class SessionManager
}
} else {
// Updating the session.
$params = array(
'id_coach' => $coach_id,
'date_start' => $date_start,
@ -2178,7 +2209,6 @@ class SessionManager
}
if (isset($sessionId) && !empty($sessionId)) {
// The session already exists, update it then.
Database::update($tbl_session, $params, array('id = ?' => $sessionId));
$session_id = $sessionId;
} else {
@ -2196,7 +2226,9 @@ class SessionManager
Database::query("DELETE FROM $tbl_session_user WHERE id_session='$session_id'");
Database::query("DELETE FROM $tbl_session_course WHERE id_session='$session_id'");
Database::query("DELETE FROM $tbl_session_course_user WHERE id_session='$session_id'");
// Delete session course user relation ships *only* for students
Database::query("DELETE FROM $tbl_session_course_user WHERE id_session='$session_id' AND status <> 2");
}
$session_counter++;
}
@ -2228,6 +2260,8 @@ class SessionManager
if (CourseManager::course_exists($course_code)) {
$courseInfo = api_get_course_info($course_code);
// Adding the course to a session.
$sql_course = "INSERT IGNORE INTO $tbl_session_course
SET course_code = '$course_code', id_session='$session_id'";
@ -2250,66 +2284,79 @@ class SessionManager
$course_users = explode(',', $course_users);
$course_coaches = explode(',', $course_coaches);
// Checking if the flag is set TeachersWillBeAddedAsCoachInAllCourseSessions (course_edit.php)
$addTeachersToSession = true;
if (array_key_exists('add_teachers_to_sessions_courses', $courseInfo)) {
$addTeachersToSession = $courseInfo['add_teachers_to_sessions_courses'];
}
// Adding coaches to session course user
if (!empty($course_coaches)) {
$savedCoaches = array();
// Adding course teachers as course session teachers
$alreadyAddedTeachers = CourseManager::get_teacher_list_from_course_code($course_code);
if (!empty($alreadyAddedTeachers)) {
$teachersToAdd = array();
foreach ($alreadyAddedTeachers as $user) {
$teachersToAdd[] = $user['username'];
// only edit if add_teachers_to_sessions_courses is set.
if ($addTeachersToSession) {
// Adding course teachers as course session teachers
$alreadyAddedTeachers = CourseManager::get_teacher_list_from_course_code($course_code);
if (!empty($alreadyAddedTeachers)) {
$teachersToAdd = array();
foreach ($alreadyAddedTeachers as $user) {
$teachersToAdd[] = $user['username'];
}
$course_coaches = array_merge($course_coaches, $teachersToAdd);
}
$course_coaches = array_merge($course_coaches, $teachersToAdd);
}
foreach ($course_coaches as $course_coach) {
$course_coach = trim($course_coach);
$coach_id = UserManager::get_user_id_from_username($course_coach);
if ($coach_id !== false) {
$sql = "INSERT IGNORE INTO $tbl_session_course_user SET
id_user = '$coach_id',
course_code = '$course_code',
id_session = '$session_id',
status = 2 ";
Database::query($sql);
if ($debug) {
$logger->addInfo("Sessions - Adding course coach: user #$coach_id ($course_coach) to course: '$course_code' and session #$session_id");
foreach ($course_coaches as $course_coach) {
$course_coach = trim($course_coach);
$coach_id = UserManager::get_user_id_from_username($course_coach);
if ($coach_id !== false) {
// Just insert new coaches
SessionManager::updateCoaches($session_id, $course_code, array($coach_id), false);
/*$sql = "INSERT IGNORE INTO $tbl_session_course_user SET
id_user = '$coach_id',
course_code = '$course_code',
id_session = '$session_id',
status = 2 ";
Database::query($sql);*/
if ($debug) {
$logger->addInfo("Sessions - Adding course coach: user #$coach_id ($course_coach) to course: '$course_code' and session #$session_id");
}
$savedCoaches[] = $coach_id;
} else {
$error_message .= get_lang('UserDoesNotExist').' : '.$course_coach.$eol;
}
$savedCoaches[] = $coach_id;
} else {
$error_message .= get_lang('UserDoesNotExist').' : '.$course_coach.$eol;
}
}
}
$users_in_course_counter = 0;
//$users_in_course_counter = 0;
// Adding the relationship "Session - Course - User".
// Adding Students, updating relationship "Session - Course - User".
foreach ($course_users as $user) {
$user = trim($user);
$user_id = UserManager::get_user_id_from_username($user);
if ($user_id !== false) {
$sql = "INSERT IGNORE INTO $tbl_session_course_user SET
SessionManager::subscribe_users_to_session_course(array($user_id), $session_id, $course_code);
/*$sql = "INSERT IGNORE INTO $tbl_session_course_user SET
id_user='$user_id',
course_code='$course_code',
id_session = '$session_id'";
Database::query($sql);
Database::query($sql);*/
if ($debug) {
$logger->addInfo("Sessions - Adding student: user #$user_id ($user) to course: '$course_code' and session #$session_id");
}
$users_in_course_counter++;
//$users_in_course_counter++;
} else {
$error_message .= get_lang('UserDoesNotExist').': '.$user.$eol;
}
}
$sql = "UPDATE $tbl_session_course SET nbr_users = '$users_in_course_counter' WHERE course_code = '$course_code'";
Database::query($sql);
/*$sql = "UPDATE $tbl_session_course SET nbr_users = '$users_in_course_counter' WHERE course_code = '$course_code'";
Database::query($sql);*/
$course_info = CourseManager::get_course_information($course_code);
$inserted_in_course[$course_code] = $course_info['title'];
@ -2393,20 +2440,28 @@ class SessionManager
}
/**
* @param $sessionId
* @param $coachList
* @param $deleteCoachesNotInList
* @param int $sessionId
* @param string $courseCode
* @param array $coachList
* @param bool $deleteCoachesNotInList
*/
public static function updateCoaches($sessionId, $courseCode, $coachList, $deleteCoachesNotInList = false)
{
$currentCoaches = SessionManager::getCoachesByCourseSession($sessionId, $courseCode);
foreach ($coachList as $userId) {
SessionManager::set_coach_to_course_session($userId, $sessionId, $courseCode);
if (!empty($coachList)) {
foreach ($coachList as $userId) {
SessionManager::set_coach_to_course_session($userId, $sessionId, $courseCode);
}
}
if ($deleteCoachesNotInList) {
$coachesToDelete = array_diff($currentCoaches, $coachList);
if (!empty($coachList)) {
$coachesToDelete = array_diff($currentCoaches, $coachList);
} else {
$coachesToDelete = $currentCoaches;
}
if (!empty($coachesToDelete)) {
foreach ($coachesToDelete as $userId) {
SessionManager::set_coach_to_course_session($userId, $sessionId, $courseCode, true);

Loading…
Cancel
Save