From 9320354f3d8a8b7d43537f2698aa25958472268c Mon Sep 17 00:00:00 2001 From: Julio Montoya Date: Fri, 3 Jul 2020 14:19:26 +0200 Subject: [PATCH] Add my publications page see BT#17508 --- index.php | 2 +- main/inc/ajax/model.ajax.php | 29 +++ main/inc/lib/userportal.lib.php | 13 +- main/template/default/layout/layout_2_col.tpl | 5 + main/template/default/work/publications.tpl | 13 + main/work/publications.php | 20 ++ main/work/work.lib.php | 241 +++++++++++++++++- user_portal.php | 1 + 8 files changed, 320 insertions(+), 4 deletions(-) create mode 100644 main/template/default/work/publications.tpl create mode 100644 main/work/publications.php diff --git a/index.php b/index.php index ac4602b130..e33ad162cf 100755 --- a/index.php +++ b/index.php @@ -175,8 +175,8 @@ if ($includeFile) { } $controller->tpl->assign('navigation_links', $controller->return_navigation_links()); $controller->tpl->assign('notice_block', $controller->return_notice()); -//$controller->tpl->assign('main_navigation_block', $controller->return_navigation_links()); $controller->tpl->assign('help_block', $controller->return_help()); +$controller->tpl->assign('student_publication_block', $controller->studentPublicationBlock()); if (api_is_platform_admin() || api_is_drh()) { $controller->tpl->assign('skills_block', $controller->returnSkillLinks()); } diff --git a/main/inc/ajax/model.ajax.php b/main/inc/ajax/model.ajax.php index 80d8a77232..dc4a77b0f9 100755 --- a/main/inc/ajax/model.ajax.php +++ b/main/inc/ajax/model.ajax.php @@ -49,6 +49,7 @@ if (!in_array( 'get_hotpotatoes_exercise_results', 'get_work_teacher', 'get_work_student', + 'get_all_work_student', 'get_work_user_list', 'get_work_user_list_others', 'get_work_user_list_all', @@ -66,6 +67,7 @@ if (!in_array( 'get_usergroups_users', 'get_calendar_users', 'get_exercise_categories', + ] ) && !isset($_REQUEST['from_course_session'])) { api_protect_admin_script(true); @@ -546,6 +548,11 @@ switch ($action) { require_once api_get_path(SYS_CODE_PATH).'work/work.lib.php'; $count = getWorkListStudent(0, $limit, $sidx, $sord, $whereCondition, true); break; + case 'get_all_work_student': + require_once api_get_path(SYS_CODE_PATH).'work/work.lib.php'; + $withResults = isset($_REQUEST['with_results']) ? (int) $_REQUEST['with_results'] : 0; + $count = getAllWorkListStudent(0, $limit, $sidx, $sord, $whereCondition, true, $withResults); + break; case 'get_work_user_list_all': require_once api_get_path(SYS_CODE_PATH).'work/work.lib.php'; $work_id = $_REQUEST['work_id']; @@ -1279,6 +1286,27 @@ switch ($action) { $whereCondition ); break; + case 'get_all_work_student': + $columns = [ + 'type', + 'title', + 'expires_on', + ]; + + if ($withResults) { + $columns[] = 'feedback'; + $columns[] = 'last_upload'; + } + $result = getAllWorkListStudent( + $start, + $limit, + $sidx, + $sord, + $whereCondition, + false, + $withResults + ); + break; case 'get_work_user_list_all': $plagiarismColumns = []; if (api_get_configuration_value('allow_compilatio_tool')) { @@ -2366,6 +2394,7 @@ $allowed_actions = [ 'get_hotpotatoes_exercise_results', 'get_work_teacher', 'get_work_student', + 'get_all_work_student', 'get_work_user_list', 'get_work_user_list_others', 'get_work_user_list_all', diff --git a/main/inc/lib/userportal.lib.php b/main/inc/lib/userportal.lib.php index fd53e19c9d..798c919448 100755 --- a/main/inc/lib/userportal.lib.php +++ b/main/inc/lib/userportal.lib.php @@ -306,7 +306,7 @@ class IndexManager 'title' => get_lang('MyCertificates'), ]; } - if (api_get_setting('allow_public_certificates') == 'true') { + if (api_get_setting('allow_public_certificates') === 'true') { $items[] = [ 'icon' => Display::return_icon('search_graduation.png', get_lang('Search')), 'link' => api_get_path(WEB_CODE_PATH).'gradebook/search.php', @@ -351,6 +351,17 @@ class IndexManager return $items; } + public static function studentPublicationBlock() + { + $items[] = [ + 'icon' => Display::return_icon('lp_student_publication.png', get_lang('StudentPublication')), + 'link' => api_get_path(WEB_CODE_PATH).'work/publications.php', + 'title' => get_lang('MyStudentPublications'), + ]; + + return $items; + } + /** * Reacts on a failed login: * Displays an explanation with a link to the registration form. diff --git a/main/template/default/layout/layout_2_col.tpl b/main/template/default/layout/layout_2_col.tpl index 54b183934b..1bb1359697 100755 --- a/main/template/default/layout/layout_2_col.tpl +++ b/main/template/default/layout/layout_2_col.tpl @@ -93,6 +93,11 @@ {{ display.collapseMenu('skills', 'Skills'|get_lang, skills_block) }} {% endif %} + + {% if student_publication_block %} + {{ display.collapseMenu('student_publications', 'StudentPublications'|get_lang, student_publication_block) }} + {% endif %} + {% if grade_book_sidebar %}
diff --git a/main/template/default/work/publications.tpl b/main/template/default/work/publications.tpl new file mode 100644 index 0000000000..1f78a8a5c2 --- /dev/null +++ b/main/template/default/work/publications.tpl @@ -0,0 +1,13 @@ +{% extends 'layout/layout_1_col.tpl'|get_template %} + +{% block content %} + {{ introduction_message }} + +

{{ 'PendingStudentPublications' | get_lang }}

+ + {{ table }} + +

{{ 'StudentPublicationsSent' | get_lang }}

+ + {{ table_with_results }} +{% endblock %} diff --git a/main/work/publications.php b/main/work/publications.php new file mode 100644 index 0000000000..7a2c2eaaa6 --- /dev/null +++ b/main/work/publications.php @@ -0,0 +1,20 @@ +assign('introduction_message', Display::return_message(get_lang('StudentPublicationsIntro'))); +$tpl->assign('table', showStudentAllWorkGrid(0)); +$tpl->assign('table_with_results', showStudentAllWorkGrid(1)); + +$tpl->display($tpl->get_template('work/publications.tpl')); diff --git a/main/work/work.lib.php b/main/work/work.lib.php index 3778ca239e..9de5b03f5f 100755 --- a/main/work/work.lib.php +++ b/main/work/work.lib.php @@ -527,6 +527,57 @@ function showStudentWorkGrid() return $html; } + +/** + * Shows the work list (student view). + * + * @return string + */ +function showStudentAllWorkGrid($withResults = 1) +{ + $withResults = (int) $withResults; + $url = api_get_path(WEB_AJAX_PATH).'model.ajax.php?a=get_all_work_student&with_results='.$withResults; + + $columns = [ + get_lang('Type'), + get_lang('Title'), + get_lang('HandOutDateLimit') + ]; + + $id = 'workList'; + if ($withResults) { + $id = 'workListWithResults'; + $columns[] = get_lang('Feedback'); + $columns[] = get_lang('LastUpload'); + } + + $columnModel = [ + ['name' => 'type', 'index' => 'type', 'width' => '30', 'align' => 'center', 'sortable' => 'false'], + ['name' => 'title', 'index' => 'title', 'width' => '250', 'align' => 'left'], + ['name' => 'expires_on', 'index' => 'expires_on', 'width' => '80', 'align' => 'center', 'sortable' => 'false'], + ]; + + if ($withResults) { + $columnModel[] = ['name' => 'feedback', 'index' => 'feedback', 'width' => '80', 'align' => 'center', 'sortable' => 'false']; + $columnModel[] = ['name' => 'last_upload', 'index' => 'feedback', 'width' => '125', 'align' => 'center', 'sortable' => 'false']; + } + + $params = [ + 'autowidth' => 'true', + 'height' => 'auto', + ]; + + $html = ''; + + $html .= Display::grid_html($id); + + return $html; +} + /** * Shows the work list (teacher view). * @@ -1196,7 +1247,7 @@ function getWorkListStudent( $userId = api_get_user_id(); $isDrhOfCourse = CourseManager::isUserSubscribedInCourseAsDrh( - api_get_user_id(), + $userId, $courseInfo ); @@ -1328,6 +1379,190 @@ function getWorkListStudent( return $works; } + +/** + * @param int $start + * @param int $limit + * @param string $column + * @param string $direction + * @param string $where_condition + * @param bool $getCount + * @param int $withResults + * + * @return array + */ +function getAllWorkListStudent( + $start, + $limit, + $column, + $direction, + $where_condition, + $getCount = false, + $withResults = 1 +) { + $workTable = Database::get_course_table(TABLE_STUDENT_PUBLICATION); + $workTableAssignment = Database::get_course_table(TABLE_STUDENT_PUBLICATION_ASSIGNMENT); + + $userId = api_get_user_id(); + $courses = CourseManager::get_courses_list_by_user_id($userId, true); + + if (!empty($where_condition)) { + $where_condition = ' AND '.$where_condition; + } + + if (!in_array($direction, ['asc', 'desc'])) { + $direction = 'desc'; + } + + $column = !empty($column) ? Database::escape_string($column) : 'sent_date'; + $start = (int) $start; + $limit = (int) $limit; + $courseQuery = []; + $courseList = []; + foreach ($courses as $course) { + $course_id = $course['real_id']; + $courseInfo = api_get_course_info_by_id($course_id); + $session_id = isset($course['session_id']) ? $course['session_id'] : 0; + $conditionSession = api_get_session_condition($session_id, true, false, 'w.session_id'); + $courseQuery[] = " (w.c_id = $course_id $conditionSession )"; + $courseList[$course_id] = $courseInfo; + } + + $courseQueryToString = implode(' OR ',$courseQuery); + + if ($getCount) { + if (empty($courseQuery)) { + return 0; + } + $select = 'SELECT count(DISTINCT(w.id)) as count '; + } else { + if (empty($courseQuery)) { + return []; + } + $select = 'SELECT DISTINCT + w.url, + w.id, + w.c_id, + w.session_id, + a.expires_on, + a.ends_on, + a.enable_qualification, + w.qualification, + a.publication_id'; + } + + $check = " LEFT JOIN $workTable ww ON (ww.c_id = w.c_id AND ww.parent_id = w.id AND ww.user_id = $userId ) "; + $where = ' AND ww.url IS NULL '; + if ($withResults) { + $where = ''; + $check = " INNER JOIN $workTable ww ON (ww.c_id = w.c_id AND ww.parent_id = w.id AND ww.user_id = $userId) "; + } + + $sql = "$select + FROM $workTable w + LEFT JOIN $workTableAssignment a + ON (a.publication_id = w.id AND a.c_id = w.c_id) + $check + WHERE + w.parent_id = 0 AND + w.active IN (1, 0) AND + ($courseQueryToString) + $where_condition + $where + "; + + $sql .= " ORDER BY $column $direction "; + + if (!empty($start) && !empty($limit)) { + $sql .= " LIMIT $start, $limit"; + } + $result = Database::query($sql); + + if ($getCount) { + $row = Database::fetch_array($result); + + if ($row) { + return (int) $row['count']; + } + + return 0; + } + + $works = []; + while ($work = Database::fetch_array($result, 'ASSOC')) { + $courseId = $work['c_id']; + $courseInfo = $courseList[$work['c_id']]; + $courseCode = $courseInfo['code']; + $sessionId = $work['session_id']; + + $cidReq = api_get_cidreq_params($courseCode, $sessionId); + $url = api_get_path(WEB_CODE_PATH).'work/work_list.php?'.$cidReq; + $isSubscribed = userIsSubscribedToWork($userId, $work['id'], $courseId); + if ($isSubscribed == false) { + continue; + } + + $visibility = api_get_item_visibility($courseInfo, 'work', $work['id'], $sessionId); + + if ($visibility != 1) { + continue; + } + + $work['type'] = Display::return_icon('work.png'); + $work['expires_on'] = empty($work['expires_on']) ? null : api_get_local_time($work['expires_on']); + + if (empty($work['title'])) { + $work['title'] = basename($work['url']); + } + + if ($withResults) { + $whereCondition = " AND u.user_id = $userId "; + $workList = get_work_user_list( + 0, + 1000, + null, + null, + $work['id'], + $whereCondition, + null, + false, + $courseId, + $sessionId + ); + + $count = getTotalWorkComment($workList, $courseInfo); + $lastWork = getLastWorkStudentFromParentByUser($userId, $work, $courseInfo); + + if (!is_null($count) && !empty($count)) { + $urlView = api_get_path(WEB_CODE_PATH).'work/view.php?id='.$lastWork['id'].'&'.$cidReq; + + $feedback = ' '.Display::url( + Display::returnFontAwesomeIcon('comments-o'), + $urlView, + ['title' => get_lang('View')] + ); + + $work['feedback'] = ' '.Display::label($count.' '.get_lang('Feedback'), 'info').$feedback; + } + + if (!empty($lastWork)) { + $work['last_upload'] = (!empty($lastWork['qualification'])) ? $lastWork['qualification_rounded'].' - ' : ''; + $work['last_upload'] .= api_get_local_time($lastWork['sent_date']); + } + } + + $work['title'] = Display::url($work['title'], $url.'&id='.$work['id']); + /*$work['others'] = Display::url( + Display::return_icon('group.png', get_lang('Others')), + $urlOthers.$work['id'] + );*/ + $works[] = $work; + } + + return $works; +} + + /** * @param int $start * @param int $limit @@ -2100,7 +2335,9 @@ function get_work_user_list(
'.addslashes(get_lang('ClickOrDropOneFileHere')).' diff --git a/user_portal.php b/user_portal.php index a581c39264..b360d55924 100755 --- a/user_portal.php +++ b/user_portal.php @@ -328,6 +328,7 @@ $controller->tpl->assign('search_block', $controller->return_search_block()); $controller->tpl->assign('notice_block', $controller->return_notice()); $controller->tpl->assign('classes_block', $controller->returnClassesBlock()); $controller->tpl->assign('skills_block', $controller->returnSkillLinks()); +$controller->tpl->assign('student_publication_block', $controller->studentPublicationBlock()); $historyClass = ''; if (!empty($_GET['history'])) {