/** * Get the list of students that have to submit their work * @param integer $workId The internal ID of the assignment * @param integer $courseId The course ID * @param integer $groupId The group ID, if any * @param integer $sessionId The session ID, if any * @param bool $getCount Whether we want just the amount or the full result * @return array|int An integer (if we just asked for the count) or an array of users */ function getStudentSubscribedToWork( $workId, $courseId, $groupId = null, $sessionId = null, $getCount = false ) { $usersInWork = null; $usersInCourse = null; if (empty($groupId)) { $courseInfo = api_get_course_info_by_id($courseId); $status = STUDENT; if (!empty($sessionId)) { $status = 0; } $usersInCourse = CourseManager::get_user_list_from_course_code( $courseInfo['code'], $sessionId, null, null, $status, $getCount ); } else { $usersInCourse = GroupManager::get_users( $groupId, false, null, null, $getCount, $courseId ); } if (ADD_DOCUMENT_TO_WORK == true) { $usersInWork = getAllUserToWork($workId, $courseId, $getCount); if (empty($usersInWork)) { return $usersInCourse; } else { return $usersInWork; } } else { return $usersInCourse; } }
} $url = api_get_path(WEB_CODE_PATH) . 'work/add_user.php?id=' . $workId; header('Location: ' . $url); exit; break; case 'delete': if (!empty($workId) && !empty($userId)) { deleteUserToWork($userId, $workId, api_get_course_int_id()); $url = api_get_path(WEB_CODE_PATH) . 'work/add_user.php?id=' . $workId; header('Location: ' . $url); exit; } break; } Display::display_header(null); $items = getAllUserToWork($workId, api_get_course_int_id()); $usersAdded = array(); if (!empty($items)) { echo Display::page_subheader(get_lang('UsersAdded')); echo '<div class="well">'; foreach ($items as $data) { $myUserId = $data['user_id']; $usersAdded[] = $myUserId; $userInfo = api_get_user_info($myUserId); $url = api_get_path(WEB_CODE_PATH) . 'work/add_user.php?action=delete&id=' . $workId . '&user_id=' . $myUserId; $link = Display::url(get_lang('Delete'), $url); echo $userInfo['complete_name'] . ' ' . $link . '<br />'; } echo '</div>'; } $userList = CourseManager::get_user_list_from_course_code($courseInfo['code'], api_get_session_id(), null, null, STUDENT);
/** * @param int $userId * @param int $workId * @param int $courseId * @return bool */ function userIsSubscribedToWork($userId, $workId, $courseId) { if (ADD_DOCUMENT_TO_WORK == false) { return true; } $subscribedUsers = getAllUserToWork($workId, $courseId); if (empty($subscribedUsers)) { return true; } else { $subscribedUsersIdList = array(); foreach ($subscribedUsers as $item) { $subscribedUsersIdList[] = $item['user_id']; } if (in_array($userId, $subscribedUsersIdList)) { return true; } } return false; }