Adding default VisibilityAfterExpiration see BT#8606

1.9.x
Julio Montoya 11 years ago
parent c651acd17f
commit ae24a5721a
  1. 15
      main/admin/session_import.php
  2. 83
      main/inc/lib/sessionmanager.lib.php

@ -42,7 +42,7 @@ $purification_option_for_usernames = false;
$inserted_in_course = array(); $inserted_in_course = array();
global $_configuration; global $_configuration;
$warn = null;
if (isset($_POST['formSent']) && $_POST['formSent']) { if (isset($_POST['formSent']) && $_POST['formSent']) {
if (isset($_FILES['import_file']['tmp_name']) && if (isset($_FILES['import_file']['tmp_name']) &&
!empty($_FILES['import_file']['tmp_name']) !empty($_FILES['import_file']['tmp_name'])
@ -462,6 +462,8 @@ if (isset($_POST['formSent']) && $_POST['formSent']) {
} else { } else {
// CSV // CSV
$updateCourseCoaches = isset($_POST['update_course_coaches']) ? true : false; $updateCourseCoaches = isset($_POST['update_course_coaches']) ? true : false;
$addOriginalCourseTeachersAsCourseSessionCoaches = isset($_POST['add_me_as_coach']) ? true : false;
$result = SessionManager::importCSV( $result = SessionManager::importCSV(
$_FILES['import_file']['tmp_name'], $_FILES['import_file']['tmp_name'],
$isOverwrite, $isOverwrite,
@ -474,7 +476,9 @@ if (isset($_POST['formSent']) && $_POST['formSent']) {
1, 1,
array(), array(),
$deleteUsersNotInList, $deleteUsersNotInList,
$updateCourseCoaches $updateCourseCoaches,
false,
$addOriginalCourseTeachersAsCourseSessionCoaches
); );
$sessionList = $result['session_list']; $sessionList = $result['session_list'];
$error_message = $result['error_message']; $error_message = $result['error_message'];
@ -536,9 +540,8 @@ $form->addElement('radio', 'file_type', array(null, '<a href="example_session.xm
$form->addElement('checkbox', 'overwrite', null, get_lang('IfSessionExistsUpdate')); $form->addElement('checkbox', 'overwrite', null, get_lang('IfSessionExistsUpdate'));
$form->addElement('checkbox', 'delete_users_not_in_list', null, get_lang('DeleteUsersNotInList')); $form->addElement('checkbox', 'delete_users_not_in_list', null, get_lang('DeleteUsersNotInList'));
$form->addElement('checkbox', 'update_course_coaches', null, get_lang('CleanAndUpdateCourseCoaches')); $form->addElement('checkbox', 'update_course_coaches', null, get_lang('CleanAndUpdateCourseCoaches'));
///$form->addElement('checkbox', 'add_me_as_coach', null, get_lang('AddMeAsCoach')); $form->addElement('checkbox', 'add_me_as_coach', null, get_lang('AddMeAsCoach'));
$form->addElement('checkbox', 'sendMail', null, get_lang('SendMailToUsers')); $form->addElement('checkbox', 'sendMail', null, get_lang('SendMailToUsers'));
$form->addElement('button', 'submit', get_lang('ImportSession')); $form->addElement('button', 'submit', get_lang('ImportSession'));
$defaults = array('sendMail' => 'true','file_type' => 'csv'); $defaults = array('sendMail' => 'true','file_type' => 'csv');
@ -551,10 +554,10 @@ $form->display();
<p><?php echo get_lang('CSVMustLookLike').' ('.get_lang('MandatoryFields').')'; ?> :</p> <p><?php echo get_lang('CSVMustLookLike').' ('.get_lang('MandatoryFields').')'; ?> :</p>
<blockquote> <blockquote>
<pre> <pre>
<strong>SessionName</strong>;Coach;<strong>DateStart</strong>;<strong>DateEnd</strong>;Users;Courses <strong>SessionName</strong>;Coach;<strong>DateStart</strong>;<strong>DateEnd</strong>;Users;Courses;VisibilityAfterExpiration
<strong>Example 1</strong>;username;<strong>yyyy/mm/dd;yyyy/mm/dd</strong>;username1|username2;course1[coach1][username1,username2,...]|course2[coach1][username1,username2,...];read_only <strong>Example 1</strong>;username;<strong>yyyy/mm/dd;yyyy/mm/dd</strong>;username1|username2;course1[coach1][username1,username2,...]|course2[coach1][username1,username2,...];read_only
<strong>Example 2</strong>;username;<strong>yyyy/mm/dd;yyyy/mm/dd</strong>;username1|username2;course1[coach1][username1,username2,...]|course2[coach1][username1,username2,...];accessible <strong>Example 2</strong>;username;<strong>yyyy/mm/dd;yyyy/mm/dd</strong>;username1|username2;course1[coach1][username1,username2,...]|course2[coach1][username1,username2,...];accessible
<strong>Example 3</strong>;username;<strong>yyyy/mm/dd;yyyy/mm/dd</strong>;username1|username2;course1[coach1][username1,username2,...]|course2[coach1][username1,username2,...];not_accesible <strong>Example 3</strong>;username;<strong>yyyy/mm/dd;yyyy/mm/dd</strong>;username1|username2;course1[coach1][username1,username2,...]|course2[coach1][username1,username2,...];not_accessible
</pre> </pre>
</blockquote> </blockquote>
<p><?php echo get_lang('XMLMustLookLike').' ('.get_lang('MandatoryFields').')'; ?> :</p> <p><?php echo get_lang('XMLMustLookLike').' ('.get_lang('MandatoryFields').')'; ?> :</p>

@ -1705,7 +1705,6 @@ class SessionManager
$session_visibility = intval($session_visibility); $session_visibility = intval($session_visibility);
$nbr_users = 0; $nbr_users = 0;
foreach ($user_list as $enreg_user) { foreach ($user_list as $enreg_user) {
$enreg_user = intval($enreg_user); $enreg_user = intval($enreg_user);
// Checking if user exists in session - course - user table. // Checking if user exists in session - course - user table.
@ -3352,7 +3351,8 @@ class SessionManager
$fieldsToAvoidUpdate = array(), $fieldsToAvoidUpdate = array(),
$deleteUsersNotInList = false, $deleteUsersNotInList = false,
$updateCourseCoaches = false, $updateCourseCoaches = false,
$sessionWithCoursesModifier = false $sessionWithCoursesModifier = false,
$addOriginalCourseTeachersAsCourseSessionCoaches = true
) { ) {
$content = file($file); $content = file($file);
@ -3402,7 +3402,10 @@ class SessionManager
foreach ($enreg as $tag_name) { foreach ($enreg as $tag_name) {
$tag_names[] = api_preg_replace('/[^a-zA-Z0-9_\-]/', '', $tag_name); $tag_names[] = api_preg_replace('/[^a-zA-Z0-9_\-]/', '', $tag_name);
} }
if (!in_array('SessionName', $tag_names) || !in_array('DateStart', $tag_names) || !in_array('DateEnd', $tag_names)) { if (!in_array('SessionName', $tag_names) ||
!in_array('DateStart', $tag_names) ||
!in_array('DateEnd', $tag_names)
) {
$error_message = get_lang('NoNeededData'); $error_message = get_lang('NoNeededData');
break; break;
} }
@ -3422,6 +3425,23 @@ class SessionManager
} }
$session_name = Database::escape_string($enreg['SessionName']); $session_name = Database::escape_string($enreg['SessionName']);
// Default visibility
$visibilityAfterExpirationPerSession = $sessionVisibility;
if (isset($enreg['VisibilityAfterExpiration'])) {
$visibility = $enreg['VisibilityAfterExpiration'];
switch ($visibility) {
case 'read_only':
$visibilityAfterExpirationPerSession = SESSION_VISIBLE_READ_ONLY;
break;
case 'accessible':
$visibilityAfterExpirationPerSession = SESSION_VISIBLE;
break;
case 'not_accessible':
$visibilityAfterExpirationPerSession = SESSION_INVISIBLE;
break;
}
}
if (empty($session_name)) { if (empty($session_name)) {
continue; continue;
@ -3429,7 +3449,6 @@ class SessionManager
$date_start = $enreg['DateStart']; $date_start = $enreg['DateStart'];
$date_end = $enreg['DateEnd']; $date_end = $enreg['DateEnd'];
$visibility = isset($enreg['Visibility']) ? $enreg['Visibility'] : $sessionVisibility;
$session_category_id = isset($enreg['SessionCategory']) ? $enreg['SessionCategory'] : null; $session_category_id = isset($enreg['SessionCategory']) ? $enreg['SessionCategory'] : null;
$sessionDescription = isset($enreg['SessionDescription']) ? $enreg['SessionDescription'] : null; $sessionDescription = isset($enreg['SessionDescription']) ? $enreg['SessionDescription'] : null;
@ -3476,7 +3495,7 @@ class SessionManager
id_coach = '$coach_id', id_coach = '$coach_id',
date_start = '$date_start', date_start = '$date_start',
date_end = '$date_end', date_end = '$date_end',
visibility = '$visibility', visibility = '$visibilityAfterExpirationPerSession',
session_category_id = '$session_category_id', session_category_id = '$session_category_id',
session_admin_id = " . intval($defaultUserId) . $extraParameters . $extraSessionParameters; session_admin_id = " . intval($defaultUserId) . $extraParameters . $extraSessionParameters;
Database::query($sql); Database::query($sql);
@ -3527,20 +3546,15 @@ class SessionManager
$session_id = $my_session_result['id']; $session_id = $my_session_result['id'];
if ($session_id) { if ($session_id) {
if ($session_id) {
foreach ($enreg as $key => $value) { foreach ($enreg as $key => $value) {
if (substr($key, 0, 6) == 'extra_') { //an extra field if (substr($key, 0, 6) == 'extra_') { //an extra field
self::update_session_extra_field_value($session_id, substr($key, 6), $value); self::update_session_extra_field_value($session_id, substr($key, 6), $value);
}
}
if ($debug) {
$logger->addInfo("Sessions - #$session_id created: $session_name");
}
} else {
if ($debug) {
$logger->addError("Sessions - Session NOT created: $session_name");
} }
} }
if ($debug) {
$logger->addInfo("Sessions - #$session_id created: $session_name");
}
// Delete session-user relation only for students // Delete session-user relation only for students
$sql = "DELETE FROM $tbl_session_user $sql = "DELETE FROM $tbl_session_user
@ -3561,6 +3575,9 @@ class SessionManager
} }
} }
} else { } else {
if ($debug) {
$logger->addError("Sessions - Session to be updated: $session_name");
}
// Updating the session. // Updating the session.
$params = array( $params = array(
@ -3592,7 +3609,6 @@ class SessionManager
} }
if ($session_id) { if ($session_id) {
foreach ($enreg as $key => $value) { foreach ($enreg as $key => $value) {
if (substr($key, 0, 6) == 'extra_') { //an extra field if (substr($key, 0, 6) == 'extra_') { //an extra field
self::update_session_extra_field_value($session_id, substr($key, 6), $value); self::update_session_extra_field_value($session_id, substr($key, 6), $value);
@ -3627,6 +3643,7 @@ class SessionManager
// Adding the relationship "Session - User" for students // Adding the relationship "Session - User" for students
$userList = array(); $userList = array();
if (is_array($users)) { if (is_array($users)) {
foreach ($users as $user) { foreach ($users as $user) {
$user_id = UserManager::get_user_id_from_username($user); $user_id = UserManager::get_user_id_from_username($user);
@ -3671,7 +3688,6 @@ class SessionManager
$removeAllTeachersFromCourse = false; $removeAllTeachersFromCourse = false;
if ($sessionWithCoursesModifier) { if ($sessionWithCoursesModifier) {
if (count($courses) >= 2) { if (count($courses) >= 2) {
// Only first teacher in course session; // Only first teacher in course session;
$onlyAddFirstCoachOrTeacher = true; $onlyAddFirstCoachOrTeacher = true;
@ -3719,7 +3735,11 @@ class SessionManager
// If any user provided for a course, use the users array. // If any user provided for a course, use the users array.
if (empty($course_users)) { if (empty($course_users)) {
if (!empty($userList)) { if (!empty($userList)) {
SessionManager::subscribe_users_to_session_course($userList, $session_id, $course_code); SessionManager::subscribe_users_to_session_course(
$userList,
$session_id,
$course_code
);
if ($debug) { if ($debug) {
$msg = "Sessions - Adding student list ".implode(', #', $userList)." to course: '$course_code' and session #$session_id"; $msg = "Sessions - Adding student list ".implode(', #', $userList)." to course: '$course_code' and session #$session_id";
$logger->addInfo($msg); $logger->addInfo($msg);
@ -3732,16 +3752,25 @@ class SessionManager
$savedCoaches = array(); $savedCoaches = array();
// only edit if add_teachers_to_sessions_courses is set. // only edit if add_teachers_to_sessions_courses is set.
if ($addTeachersToSession) { if ($addTeachersToSession) {
// Adding course teachers as course session teachers.
$alreadyAddedTeachers = CourseManager::get_teacher_list_from_course_code($course_code);
if (!empty($alreadyAddedTeachers)) { if ($addOriginalCourseTeachersAsCourseSessionCoaches) {
$teachersToAdd = array(); // Adding course teachers as course session teachers.
foreach ($alreadyAddedTeachers as $user) { $alreadyAddedTeachers = CourseManager::get_teacher_list_from_course_code(
$teachersToAdd[] = $user['username']; $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) { foreach ($course_coaches as $course_coach) {
$coach_id = UserManager::get_user_id_from_username($course_coach); $coach_id = UserManager::get_user_id_from_username($course_coach);
if ($coach_id !== false) { if ($coach_id !== false) {

Loading…
Cancel
Save