Skip to content

Commit

Permalink
Admin: Add config assignment_base_course_teacher_access_to_all_session
Browse files Browse the repository at this point in the history
Show all student publications (from course and from all sessions) in
the work/pending.php page if true see  BT#18352
  • Loading branch information
jmontoyaa committed Feb 24, 2021
1 parent a9aec9c commit 5a10163
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 8 deletions.
6 changes: 5 additions & 1 deletion main/install/configuration.dist.php
Expand Up @@ -1787,7 +1787,8 @@
// Disable change user visibility tool icon.
//$_configuration['disable_change_user_visibility_for_public_courses'] = true;

// Add another layer of security by checking if the user is disabled at every page load (might generate considerable extra DB load)
// Add another layer of security by checking if the user is disabled
// at every page load (might generate considerable extra DB load)
// $_configuration['security_block_inactive_users_immediately'] = false;

// Allow all office suite documents to be uploaded in the "My files" section of the social network
Expand Down Expand Up @@ -1844,6 +1845,9 @@
// Show start/end date in LP list for students.
//$_configuration['lp_start_and_end_date_visible_in_student_view'] = true;

// Show all student publications (from course and from all sessions) in the work/pending.php page if true. BT#18352
//$_configuration['assignment_base_course_teacher_access_to_all_session'] = true;

// KEEP THIS AT THE END
// -------- Custom DB changes
// Add user activation by confirmation email
Expand Down
42 changes: 35 additions & 7 deletions main/work/work.lib.php
Expand Up @@ -2549,9 +2549,19 @@ function getAllWork(
return [];
}

$allowWorkFromAllSessions = api_get_configuration_value('assignment_base_course_teacher_access_to_all_session');
$coursesInSession = [];
$courses = CourseManager::get_courses_list_by_user_id($userId, false, false, false);
if (empty($courses)) {
return [];
if ($allowWorkFromAllSessions) {
if (empty($courses)) {
return [];
}
} else {
$coursesInSession = SessionManager::getCoursesForCourseSessionCoach($userId);

if (empty($courses) && empty($coursesInSession)) {
return [];
}
}

if (!empty($whereCondition)) {
Expand All @@ -2576,23 +2586,41 @@ function getAllWork(
}
$courseInfo = api_get_course_info_by_id($courseIdItem);
// Only teachers or platform admins.
$is_allowed_to_edit = api_is_platform_admin() || CourseManager::is_course_teacher($userId, $courseInfo['code']);
if (false === $is_allowed_to_edit) {
$isAllow = api_is_platform_admin() || CourseManager::is_course_teacher($userId, $courseInfo['code']);
if (false === $isAllow) {
continue;
}

//$session_id = isset($course['session_id']) ? $course['session_id'] : 0;
//$conditionSession = api_get_session_condition($session_id, true, false, 'w.session_id');
$conditionSession = '';
$conditionSession = ' AND (w.session_id = 0 OR w.session_id IS NULL)';
if ($allowWorkFromAllSessions) {
$conditionSession = '';
}
$parentCondition = '';
if ($withResults) {
$parentCondition = 'AND ww.parent_id is NOT NULL';
}
$courseQuery[] = " (work.c_id = $courseIdItem $conditionSession $parentCondition )";
$courseQuery[] = " (work.c_id = $courseIdItem $conditionSession $parentCondition ) ";
$courseList[$courseIdItem] = $courseInfo;
}

if (empty($courseList)) {
if (false === $allowWorkFromAllSessions) {
foreach ($coursesInSession as $courseIdInSession => $sessionList) {
if (!empty($sessionList)) {
if (!isset($courseList[$courseIdInSession])) {
$courseList[$courseIdInSession] = api_get_course_info_by_id($courseIdInSession);
}

foreach ($sessionList as $sessionId) {
$conditionSession = " AND (w.session_id = $sessionId)";
$courseQuery[] = " (work.c_id = $courseIdInSession $conditionSession $parentCondition ) ";
}
}
}
}

if (empty($courseQuery)) {
return [];
}

Expand Down

0 comments on commit 5a10163

Please sign in to comment.