From 84b413a01ec72aec059e83d434ffd66699dd0be8 Mon Sep 17 00:00:00 2001 From: Angel Cubas Date: Tue, 17 Nov 2020 17:35:32 -0500 Subject: [PATCH] Ticket: Add configuration setting $_configuration['ticket_lp_quiz_info_add'] to add extra data, learningpath_id and exercise id in tickets report - refs #3564 --- main/inc/ajax/exercise.ajax.php | 20 +++++ main/inc/ajax/lp.ajax.php | 14 +++ main/inc/lib/TicketManager.php | 88 ++++++++++++++----- main/inc/lib/exercise.lib.php | 16 ++++ main/inc/lib/template.lib.php | 14 ++- main/install/configuration.dist.php | 8 ++ main/lp/learnpath.class.php | 36 +++++++- main/ticket/new_ticket.php | 128 +++++++++++++++++++++++++--- main/ticket/ticket_details.php | 18 ++++ main/ticket/tickets.php | 12 ++- 10 files changed, 312 insertions(+), 42 deletions(-) diff --git a/main/inc/ajax/exercise.ajax.php b/main/inc/ajax/exercise.ajax.php index 7c203255c8..55927023f2 100755 --- a/main/inc/ajax/exercise.ajax.php +++ b/main/inc/ajax/exercise.ajax.php @@ -18,6 +18,26 @@ $currentUserId = api_get_user_id(); $exeId = isset($_REQUEST['exe_id']) ? $_REQUEST['exe_id'] : 0; switch ($action) { + case 'get_exercise_by_course': + $course_id = (isset($_GET['course_id']) && !empty($_GET['course_id'])) ? (int) $_GET['course_id'] : 0; + $session_id = (!empty($_GET['session_id'])) ? (int) $_GET['session_id'] : 0; + $data = []; + $onlyActiveExercises = !(api_is_platform_admin(true) || api_is_course_admin()); + $results = ExerciseLib::get_all_exercises_for_course_id( + null, + $session_id, + $course_id, + $onlyActiveExercises + ); + + if (!empty($results)) { + foreach ($results as $exercise) { + $data[] = ['id' => $exercise['id'], 'text' => html_entity_decode($exercise['title'])]; + } + } + + echo json_encode($data); + break; case 'update_duration': if (Session::read('login_as')) { diff --git a/main/inc/ajax/lp.ajax.php b/main/inc/ajax/lp.ajax.php index 4f7573196a..ff39c1ed54 100755 --- a/main/inc/ajax/lp.ajax.php +++ b/main/inc/ajax/lp.ajax.php @@ -20,6 +20,20 @@ if ($debug) { } switch ($action) { + case 'get_lp_list_by_course': + $course_id = (isset($_GET['course_id']) && !empty($_GET['course_id'])) ? (int) $_GET['course_id'] : 0; + $onlyActiveLp = !(api_is_platform_admin(true) || api_is_course_admin()); + $results = learnpath::getLpList($course_id, $onlyActiveLp); + $data= []; + + if (!empty($results)) { + foreach ($results as $lp) { + $data[] = ['id' => $lp['id'], 'text' => html_entity_decode($lp['name'])]; + } + } + + echo json_encode($data); + break; case 'get_documents': $courseInfo = api_get_course_info(); $folderId = isset($_GET['folder_id']) ? $_GET['folder_id'] : null; diff --git a/main/inc/lib/TicketManager.php b/main/inc/lib/TicketManager.php index 1130ec023b..a77961125c 100644 --- a/main/inc/lib/TicketManager.php +++ b/main/inc/lib/TicketManager.php @@ -53,13 +53,13 @@ class TicketManager $order = Database::escape_string($order); $projectId = (int) $projectId; - $sql = "SELECT - category.*, + $sql = "SELECT + category.*, category.id category_id, - project.other_area, + project.other_area, project.email - FROM - $table_support_category category + FROM + $table_support_category category INNER JOIN $table_support_project project ON project.id = category.project_id WHERE project.id = $projectId @@ -220,7 +220,7 @@ class TicketManager $table = Database::get_main_table(TABLE_TICKET_CATEGORY_REL_USER); $userId = (int) $userId; $categoryId = (int) $categoryId; - $sql = "SELECT * FROM $table + $sql = "SELECT * FROM $table WHERE category_id = $categoryId AND user_id = $userId"; $result = Database::query($sql); @@ -287,6 +287,8 @@ class TicketManager * @param string $priority * @param string $status * @param int $assignedUserId + * @param int $exerciseId + * @param int $lpId * * @return bool */ @@ -303,7 +305,9 @@ class TicketManager $source = '', $priority = '', $status = '', - $assignedUserId = 0 + $assignedUserId = 0, + $exerciseId = null, + $lpId = null ) { $table_support_tickets = Database::get_main_table(TABLE_TICKET_TICKET); $table_support_category = Database::get_main_table(TABLE_TICKET_CATEGORY); @@ -365,6 +369,14 @@ class TicketManager 'message' => $content, ]; + if (!empty($exerciseId)) { + $params['exercise_id'] = $exerciseId; + } + + if (!empty($lpId)) { + $params['lp_id'] = $lpId; + } + if (!empty($course_id)) { $params['course_id'] = $course_id; } @@ -372,6 +384,7 @@ class TicketManager if (!empty($sessionId)) { $params['session_id'] = $sessionId; } + $ticketId = Database::insert($table_support_tickets, $params); if ($ticketId) { @@ -670,7 +683,7 @@ class TicketManager if ($messageId) { // update_total_message $sql = "UPDATE $table_support_tickets - SET + SET sys_lastedit_user_id = $userId, sys_lastedit_datetime = '$now', total_messages = ( @@ -827,26 +840,26 @@ class TicketManager $column = 'ticket_id'; } - $sql = "SELECT DISTINCT + $sql = "SELECT DISTINCT ticket.*, ticket.id ticket_id, status.name AS status_name, ticket.start_date, ticket.sys_lastedit_datetime, cat.name AS category_name, - priority.name AS priority_name, + priority.name AS priority_name, ticket.total_messages AS total_messages, ticket.message AS message, ticket.subject AS subject, ticket.assigned_last_user - FROM $table_support_tickets ticket + FROM $table_support_tickets ticket INNER JOIN $table_support_category cat ON (cat.id = ticket.category_id) INNER JOIN $table_support_priority priority ON (ticket.priority_id = priority.id) INNER JOIN $table_support_status status ON (ticket.status_id = status.id) - WHERE 1=1 + WHERE 1=1 "; $projectId = (int) $_GET['project_id']; @@ -870,7 +883,7 @@ class TicketManager cat.name LIKE '%$keyword%' OR status.name LIKE '%$keyword%' OR priority.name LIKE '%$keyword%' OR - ticket.personal_email LIKE '%$keyword%' + ticket.personal_email LIKE '%$keyword%' )"; } @@ -908,11 +921,11 @@ class TicketManager if ($keyword_course != '') { $course_table = Database::get_main_table(TABLE_MAIN_COURSE); - $sql .= " AND ticket.course_id IN ( + $sql .= " AND ticket.course_id IN ( SELECT id FROM $course_table WHERE ( - title LIKE '%$keyword_course%' OR - code LIKE '%$keyword_course%' OR + title LIKE '%$keyword_course%' OR + code LIKE '%$keyword_course%' OR visual_code LIKE '%$keyword_course%' ) )"; @@ -1091,12 +1104,12 @@ class TicketManager } if ($keyword_course != '') { $course_table = Database::get_main_table(TABLE_MAIN_COURSE); - $sql .= " AND ticket.course_id IN ( + $sql .= " AND ticket.course_id IN ( SELECT id FROM $course_table WHERE ( - title LIKE '%$keyword_course%' OR - code LIKE '%$keyword_course%' OR + title LIKE '%$keyword_course%' OR + code LIKE '%$keyword_course%' OR visual_code LIKE '%$keyword_course%' ) ) "; @@ -1159,9 +1172,9 @@ class TicketManager $table_main_user = Database::get_main_table(TABLE_MAIN_USER); $sql = "SELECT - ticket.*, + ticket.*, cat.name, - status.name as status, + status.name as status, priority.name priority FROM $table_support_tickets ticket INNER JOIN $table_support_category cat @@ -1205,6 +1218,35 @@ class TicketManager if ($course) { $row['course_url'] = ''.$course['name'].''; } + + $row['exercise_url'] = null; + + if (!empty($row['exercise_id'])) { + $exerciseTitle = ExerciseLib::getExerciseTitleById($row['exercise_id']); + $dataExercise = [ + 'cidReq' => $course['code'], + 'id_session' => $sessionId, + 'exerciseId' => $row['exercise_id'] + ]; + $urlParamsExercise = http_build_query($dataExercise); + + $row['exercise_url'] = ''.$exerciseTitle.''; + } + + $row['lp_url'] = null; + + if (!empty($row['lp_id'])) { + $lpName = learnpath::getLpNameById($row['lp_id']); + $dataLp = [ + 'cidReq' => $course['code'], + 'id_session' => $sessionId, + 'lp_id' => $row['lp_id'], + 'action' => 'view' + ]; + $urlParamsLp = http_build_query($dataLp); + + $row['lp_url'] = ''.$lpName.''; + } } $userInfo = api_get_user_info($row['sys_insert_user_id']); @@ -1214,8 +1256,8 @@ class TicketManager $ticket['ticket'] = $row; } - $sql = "SELECT *, message.id as message_id - FROM $table_support_messages message + $sql = "SELECT *, message.id as message_id + FROM $table_support_messages message INNER JOIN $table_main_user user ON (message.sys_insert_user_id = user.user_id) WHERE diff --git a/main/inc/lib/exercise.lib.php b/main/inc/lib/exercise.lib.php index 4039f3a618..5ee63780c2 100644 --- a/main/inc/lib/exercise.lib.php +++ b/main/inc/lib/exercise.lib.php @@ -5628,6 +5628,22 @@ EOT; return Category::getDownloadCertificateBlock($certificate); } + /** + * @param int $exerciseId + */ + public static function getExerciseTitleById($exerciseId) + { + $em = Database::getManager(); + + return $em + ->createQuery('SELECT cq.title + FROM ChamiloCourseBundle:CQuiz cq + WHERE cq.iid = :iid' + ) + ->setParameter('iid', $exerciseId) + ->getSingleScalarResult(); + } + /** * @param int $exeId ID from track_e_exercises * @param int $userId User ID diff --git a/main/inc/lib/template.lib.php b/main/inc/lib/template.lib.php index 9b422f9e5d..f584cc8c64 100755 --- a/main/inc/lib/template.lib.php +++ b/main/inc/lib/template.lib.php @@ -1377,7 +1377,19 @@ class Template if (!empty($courseInfo)) { $courseParams = api_get_cidreq(); } - $url = api_get_path(WEB_CODE_PATH).'ticket/tickets.php?project_id='.$defaultProjectId.'&'.$courseParams; + + $extraParams = ''; + + if (api_get_configuration_value('ticket_add_quiz_and_lp')) { + if (isset($_GET['exerciseId']) && !empty($_GET['exerciseId'])) { + $extraParams = '&exerciseId=' . $_GET['exerciseId']; + } + + if (isset($_GET['lp_id']) && !empty($_GET['lp_id'])) { + $extraParams .= '&lpId=' . $_GET['lp_id']; + } + } + $url = api_get_path(WEB_CODE_PATH).'ticket/tickets.php?project_id='.$defaultProjectId.'&'.$courseParams.$extraParams; $allow = TicketManager::userIsAllowInProject(api_get_user_info(), $defaultProjectId); diff --git a/main/install/configuration.dist.php b/main/install/configuration.dist.php index 17c586d60c..6732673594 100755 --- a/main/install/configuration.dist.php +++ b/main/install/configuration.dist.php @@ -569,6 +569,14 @@ $_configuration['send_all_emails_to'] = [ ] ];*/ +// Allow additional data (exercise and learningpath) in the ticket +// - Required DB change +// ALTER TABLE ticket_ticket ADD exercise_id INT DEFAULT NULL AFTER course_id; +// ALTER TABLE ticket_ticket ADD CONSTRAINT FK_EB5B2A0D6285C987 FOREIGN KEY (exercise_id) REFERENCES c_quiz (iid); +// ALTER TABLE ticket_ticket ADD lp_id INT DEFAULT NULL AFTER exercise_id; +// ALTER TABLE ticket_ticket ADD CONSTRAINT FK_EB5B2A0D6285C231 FOREIGN KEY (lp_id) REFERENCES c_lp (iid); +// $_configuration['ticket_lp_quiz_info_add'] = false; + // Exercises configuration settings // Send only quiz answer notifications to course coaches and not general coach //$_configuration['block_quiz_mail_notification_general_coach'] = false; diff --git a/main/lp/learnpath.class.php b/main/lp/learnpath.class.php index cd357e7934..1706d8e46b 100755 --- a/main/lp/learnpath.class.php +++ b/main/lp/learnpath.class.php @@ -1830,6 +1830,23 @@ class learnpath } } + /** + * Get the learning path name by id + * + * @param int $lpId + * + * @return mixed + */ + public static function getLpNameById($lpId) + { + $em = Database::getManager(); + + return $em->createQuery('SELECT clp.name FROM ChamiloCourseBundle:CLp clp + WHERE clp.iid = :iid') + ->setParameter('iid', $lpId) + ->getSingleScalarResult(); + } + /** * Gets the navigation bar for the learnpath display screen. * @@ -12161,12 +12178,25 @@ EOD; } } - public static function getLpList($courseId) + public static function getLpList($courseId, $onlyActiveLp = true) { - $table = Database::get_course_table(TABLE_LP_MAIN); + $TABLE_LP = Database::get_course_table(TABLE_LP_MAIN); + $TABLE_ITEM_PROPERTY = Database::get_course_table(TABLE_ITEM_PROPERTY); $courseId = (int) $courseId; - $sql = "SELECT * FROM $table WHERE c_id = $courseId"; + $sql = "SELECT lp.id, lp.name + FROM $TABLE_LP lp + INNER JOIN $TABLE_ITEM_PROPERTY ip + ON lp.id = ip.ref + WHERE lp.c_id = $courseId "; + + if ($onlyActiveLp) { + $sql .= "AND ip.tool = 'learnpath' "; + $sql .= "AND ip.visibility = 1 "; + } + + $sql .= "GROUP BY lp.id"; + $result = Database::query($sql); return Database::store_result($result, 'ASSOC'); diff --git a/main/ticket/new_ticket.php b/main/ticket/new_ticket.php index 3812f47c88..6a6d759a9a 100644 --- a/main/ticket/new_ticket.php +++ b/main/ticket/new_ticket.php @@ -13,11 +13,14 @@ if (!api_is_platform_admin() && api_get_setting('ticket_allow_student_add') !== api_block_anonymous_users(); $courseId = api_get_course_int_id(); +$exerciseId = (isset($_GET['exerciseId']) && !empty($_GET['exerciseId'])) ? (int) $_GET['exerciseId'] : 0; +$lpId = (isset($_GET['lpId']) && !empty($_GET['lpId'])) ? (int) $_GET['lpId'] : 0; $htmlHeadXtra[] = '