Skip to content

Commit

Permalink
Ticket: Add configuration setting $_configuration['ticket_lp_quiz_inf…
Browse files Browse the repository at this point in the history
…o_add'] to add extra data, learningpath_id and exercise id in tickets report - refs #3564
  • Loading branch information
lcubas committed Nov 17, 2020
1 parent 4715f3b commit 84b413a
Show file tree
Hide file tree
Showing 10 changed files with 312 additions and 42 deletions.
20 changes: 20 additions & 0 deletions main/inc/ajax/exercise.ajax.php
Expand Up @@ -18,6 +18,26 @@
$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')) {
Expand Down
14 changes: 14 additions & 0 deletions main/inc/ajax/lp.ajax.php
Expand Up @@ -20,6 +20,20 @@
}

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;
Expand Down
88 changes: 65 additions & 23 deletions main/inc/lib/TicketManager.php
Expand Up @@ -53,13 +53,13 @@ public static function get_all_tickets_categories($projectId, $order = '')
$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
Expand Down Expand Up @@ -220,7 +220,7 @@ public static function userIsAssignedToCategory($userId, $categoryId)
$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);

Expand Down Expand Up @@ -287,6 +287,8 @@ public static function get_all_tickets_status()
* @param string $priority
* @param string $status
* @param int $assignedUserId
* @param int $exerciseId
* @param int $lpId
*
* @return bool
*/
Expand All @@ -303,7 +305,9 @@ public static function add(
$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);
Expand Down Expand Up @@ -365,13 +369,22 @@ public static function add(
'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;
}

if (!empty($sessionId)) {
$params['session_id'] = $sessionId;
}

$ticketId = Database::insert($table_support_tickets, $params);

if ($ticketId) {
Expand Down Expand Up @@ -670,7 +683,7 @@ public static function insertMessage(
if ($messageId) {
// update_total_message
$sql = "UPDATE $table_support_tickets
SET
SET
sys_lastedit_user_id = $userId,
sys_lastedit_datetime = '$now',
total_messages = (
Expand Down Expand Up @@ -827,26 +840,26 @@ public static function getTicketsByCurrentUser(
$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'];
Expand All @@ -870,7 +883,7 @@ public static function getTicketsByCurrentUser(
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%'
)";
}

Expand Down Expand Up @@ -908,11 +921,11 @@ public static function getTicketsByCurrentUser(

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%'
)
)";
Expand Down Expand Up @@ -1091,12 +1104,12 @@ public static function getTotalTicketsCurrentUser()
}
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%'
)
) ";
Expand Down Expand Up @@ -1159,9 +1172,9 @@ public static function get_ticket_detail_by_id($ticketId)
$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
Expand Down Expand Up @@ -1205,6 +1218,35 @@ public static function get_ticket_detail_by_id($ticketId)
if ($course) {
$row['course_url'] = '<a href="'.$course['course_public_url'].'?id_session='.$sessionId.'">'.$course['name'].'</a>';
}

$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'] = '<a href="'.api_get_path(WEB_CODE_PATH).'exercise/overview.php?'.$urlParamsExercise.'">'.$exerciseTitle.'</a>';
}

$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'] = '<a href="'.api_get_path(WEB_CODE_PATH).'lp/lp_controller.php?'.$urlParamsLp.'">'.$lpName.'</a>';
}
}

$userInfo = api_get_user_info($row['sys_insert_user_id']);
Expand All @@ -1214,8 +1256,8 @@ public static function get_ticket_detail_by_id($ticketId)
$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
Expand Down
16 changes: 16 additions & 0 deletions main/inc/lib/exercise.lib.php
Expand Up @@ -5628,6 +5628,22 @@ public static function generateAndShowCertificateBlock(
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
Expand Down
14 changes: 13 additions & 1 deletion main/inc/lib/template.lib.php
Expand Up @@ -1377,7 +1377,19 @@ public function assignBugNotification()
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);

Expand Down
8 changes: 8 additions & 0 deletions main/install/configuration.dist.php
Expand Up @@ -569,6 +569,14 @@
]
];*/

// 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;
Expand Down
36 changes: 33 additions & 3 deletions main/lp/learnpath.class.php
Expand Up @@ -1830,6 +1830,23 @@ public function getLastInFirstLevel()
}
}

/**
* 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.
*
Expand Down Expand Up @@ -12161,12 +12178,25 @@ public static function moveDownCategory($id)
}
}

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');
Expand Down

0 comments on commit 84b413a

Please sign in to comment.