Minor - Format code - refs BT#18214

pull/3859/head
Angel Fernando Quiroz Campos 5 years ago
parent 5e29a97138
commit 9e77708dd7
  1. 218
      main/cron/learning_path_reminder.php

@ -8,6 +8,7 @@
* *
* @author Carlos Alvarado <carlos.alvarado@beeznest.com> * @author Carlos Alvarado <carlos.alvarado@beeznest.com>
*/ */
require_once __DIR__.'/../inc/global.inc.php'; require_once __DIR__.'/../inc/global.inc.php';
/** /**
@ -38,8 +39,10 @@ if (!isset($activeMessageNewlp['default_value'])) {
* @param string $courseName * @param string $courseName
* @param string $lpName * @param string $lpName
* @param string $link * @param string $link
*
* @return bool|int
*/ */
function sendMessage($toUser, $fromUser, $courseName, $lpName, $link) function sendMessage(array $toUser, int $fromUser, string $courseName, string $lpName, string $link)
{ {
$toUserId = $toUser['user_id']; $toUserId = $toUser['user_id'];
$subjectTemplate = new Template( $subjectTemplate = new Template(
@ -87,8 +90,10 @@ function sendMessage($toUser, $fromUser, $courseName, $lpName, $link)
* Obtains the data of the learning path and course searched by the id of the LP. * Obtains the data of the learning path and course searched by the id of the LP.
* *
* @param array $lpid * @param array $lpid
*
* @return array
*/ */
function getLpDataByArrayId($lpid = []) function getLpDataByArrayId(array $lpid = []): array
{ {
if (count($lpid) == 0) { if (count($lpid) == 0) {
return []; return [];
@ -98,10 +103,10 @@ function getLpDataByArrayId($lpid = [])
$sql = " $sql = "
SELECT SELECT
tblCourse.title AS course_name, tblCourse.title AS course_name,
tblCourse.`code` AS `code`, tblCourse.code AS code,
tblLp.id AS lp_id, tblLp.id AS lp_id,
tblLp.c_id AS c_id, tblLp.c_id AS c_id,
tblLp.`name` AS `name` tblLp.name AS name
FROM FROM
$lpTable AS tblLp $lpTable AS tblLp
INNER JOIN $tblCourse AS tblCourse ON tblLp.c_id = tblCourse.id INNER JOIN $tblCourse AS tblCourse ON tblLp.c_id = tblCourse.id
@ -121,7 +126,7 @@ function getLpDataByArrayId($lpid = [])
* Returns the id of the LPs that have the notification option active through the extra * Returns the id of the LPs that have the notification option active through the extra
* field 'notify_student_and_hrm_when_available'. * field 'notify_student_and_hrm_when_available'.
*/ */
function getLpIdWithNotify() function getLpIdWithNotify(): array
{ {
$extraFieldValuesTable = Database::get_main_table(TABLE_EXTRA_FIELD_VALUES); $extraFieldValuesTable = Database::get_main_table(TABLE_EXTRA_FIELD_VALUES);
$extraFieldTable = Database::get_main_table(TABLE_EXTRA_FIELD); $extraFieldTable = Database::get_main_table(TABLE_EXTRA_FIELD);
@ -135,7 +140,7 @@ function getLpIdWithNotify()
tblExtraField.variable = 'notify_student_and_hrm_when_available' tblExtraField.variable = 'notify_student_and_hrm_when_available'
) )
where where
tblExtraFieldValues.`value` = 1 tblExtraFieldValues.value = 1
"; ";
$result = Database::query($sql); $result = Database::query($sql);
$return = []; $return = [];
@ -145,21 +150,21 @@ function getLpIdWithNotify()
return $return; return $return;
} }
function getTutorIdFromCourseRelUser($cId = 0, $lpId = 0)
function getTutorIdFromCourseRelUser($cId = 0, $lpId = 0): int
{ {
$lpTable = Database::get_course_table(TABLE_LP_MAIN); $lpTable = Database::get_course_table(TABLE_LP_MAIN);
$tblCourseRelUser = Database::get_main_table(TABLE_MAIN_COURSE_USER); $tblCourseRelUser = Database::get_main_table(TABLE_MAIN_COURSE_USER);
$sql = " $sql = "SELECT DISTINCT
SELECT DISTINCT tblCourseRelUser.user_id AS user_id
tblCourseRelUser.user_id AS user_id FROM
FROM $lpTable AS tblLp
$lpTable AS tblLp INNER JOIN $tblCourseRelUser AS tblCourseRelUser ON ( tblCourseRelUser.c_id = tblLp.c_id)
INNER JOIN $tblCourseRelUser AS tblCourseRelUser ON ( tblCourseRelUser.c_id = tblLp.c_id) WHERE
WHERE tblCourseRelUser.user_id IS NOT NULL AND
tblCourseRelUser.user_id IS NOT NULL AND tblCourseRelUser.status = 1 AND
tblCourseRelUser.status = 1 AND tblLp.id = $lpId AND
tblLp.id = $lpId AND tblLp.c_id = $cId";
tblLp.c_id = $cId";
$result = Database::query($sql); $result = Database::query($sql);
$data = Database::fetch_assoc($result); $data = Database::fetch_assoc($result);
@ -185,9 +190,6 @@ function sendToArray(&$data, &$type, &$message, $lpId = 0)
} }
} }
/**
* @return null
*/
function learningPaths() function learningPaths()
{ {
$lpItems = getLpIdWithNotify(); $lpItems = getLpIdWithNotify();
@ -205,26 +207,24 @@ function learningPaths()
$tblSessionCourseUser = Database::get_main_table(TABLE_MAIN_SESSION_COURSE_USER); $tblSessionCourseUser = Database::get_main_table(TABLE_MAIN_SESSION_COURSE_USER);
$tblItempProperty = Database::get_course_table(TABLE_ITEM_PROPERTY); $tblItempProperty = Database::get_course_table(TABLE_ITEM_PROPERTY);
/* Gets subscribed users individually in lp's by LearnpathSubscription */ /* Gets subscribed users individually in lp's by LearnpathSubscription */
$sql = " $sql = "SELECT DISTINCT
SELECT DISTINCT tblItemProperty.session_id as session_id,
tblItemProperty.session_id as session_id, tblItemProperty.to_user_id as user_id,
tblItemProperty.to_user_id as user_id, tblItemProperty.insert_user_id as from_user_id,
tblItemProperty.insert_user_id as from_user_id, tblLp.id AS lp_id,
tblLp.id AS lp_id, tblItemProperty.lastedit_type
tblItemProperty.lastedit_type FROM
FROM $tblItempProperty as tblItemProperty
$tblItempProperty as tblItemProperty INNER JOIN $lpTable as tblLp ON
INNER JOIN $lpTable as tblLp ON (
( tblLp.iid = tblItemProperty.ref AND
tblLp.iid = tblItemProperty.ref AND tblItemProperty.lastedit_type = 'LearnpathSubscription'
tblItemProperty.lastedit_type = 'LearnpathSubscription' )
) WHERE
WHERE publicated_on <= '$date 23:59:59' AND
publicated_on <= '$date 23:59:59' AND publicated_on >= '$date 00:00:00' AND
publicated_on >= '$date 00:00:00' AND tblItemProperty.to_user_id IS NOT NULL AND
tblItemProperty.to_user_id IS NOT NULL AND tblLp.id in ($lpItemsString)";
tblLp.id in ($lpItemsString)
";
$result = Database::query($sql); $result = Database::query($sql);
$groupUsers = []; $groupUsers = [];
@ -234,9 +234,9 @@ function learningPaths()
if (isset($lpsData[$lpId])) { if (isset($lpsData[$lpId])) {
$lpData = $lpsData[$lpId]; $lpData = $lpsData[$lpId];
} }
$courseName = isset($lpData['course_name']) ? $lpData['course_name'] : null; $courseName = $lpData['course_name'] ?? null;
$courseCode = isset($lpData['code']) ? $lpData['code'] : null; $courseCode = $lpData['code'] ?? null;
$lpName = isset($lpData['name']) ? $lpData['name'] : null; $lpName = $lpData['name'] ?? null;
$sessionId = (int) $row['session_id']; $sessionId = (int) $row['session_id'];
$toUser = (int) $row['user_id']; $toUser = (int) $row['user_id'];
@ -256,31 +256,28 @@ function learningPaths()
$itemProcessed[$lpId][$sessionId]['LearnpathSubscription'][$toUser] = $groupUsers[$lpId][$sessionId][$toUser]; $itemProcessed[$lpId][$sessionId]['LearnpathSubscription'][$toUser] = $groupUsers[$lpId][$sessionId][$toUser];
} }
/* Gets subscribed users by classes in lp's by LearnpathSubscription */ /* Gets subscribed users by classes in lp's by LearnpathSubscription */
$sql = " $sql = "SELECT DISTINCT
SELECT DISTINCT tblItemProperty.session_id as session_id,
tblItemProperty.session_id as session_id, tblItemProperty.to_group_id as group_id,
tblItemProperty.to_group_id as group_id, tblUsergroupRelUser.user_id as user_id,
tblUsergroupRelUser.user_id as user_id, tblItemProperty.insert_user_id as from_user_id,
tblItemProperty.insert_user_id as from_user_id, tblLp.id AS lp_id,
tblLp.id AS lp_id, tblItemProperty.lastedit_type
tblItemProperty.lastedit_type FROM
FROM $tblItempProperty as tblItemProperty
$tblItempProperty as tblItemProperty INNER JOIN $lpTable as tblLp ON
INNER JOIN $lpTable as tblLp ON (
( tblLp.iid = tblItemProperty.ref AND
tblLp.iid = tblItemProperty.ref AND tblItemProperty.lastedit_type = 'LearnpathSubscription'
tblItemProperty.lastedit_type = 'LearnpathSubscription' )
INNER JOIN usergroup_rel_user as tblUsergroupRelUser on (
tblItemProperty.to_group_id = tblUsergroupRelUser.usergroup_id
) )
INNER JOIN usergroup_rel_user as tblUsergroupRelUser on ( WHERE
tblItemProperty.to_group_id = tblUsergroupRelUser.usergroup_id publicated_on <= '$date 23:59:59' AND
) publicated_on >= '$date 00:00:00' AND
WHERE tblItemProperty.to_group_id IS NOT NULL AND
publicated_on <= '$date 23:59:59' AND tblLp.id in ($lpItemsString)";
publicated_on >= '$date 00:00:00' AND
tblItemProperty.to_group_id IS NOT NULL AND
tblLp.id in ($lpItemsString)
";
$result = Database::query($sql); $result = Database::query($sql);
$groupUsers = []; $groupUsers = [];
while ($row = Database::fetch_array($result)) { while ($row = Database::fetch_array($result)) {
@ -289,9 +286,9 @@ function learningPaths()
if (isset($lpsData[$lpId])) { if (isset($lpsData[$lpId])) {
$lpData = $lpsData[$lpId]; $lpData = $lpsData[$lpId];
} }
$courseName = isset($lpData['course_name']) ? $lpData['course_name'] : null; $courseName = $lpData['course_name'] ?? null;
$courseCode = isset($lpData['code']) ? $lpData['code'] : null; $courseCode = $lpData['code'] ?? null;
$lpName = isset($lpData['name']) ? $lpData['name'] : null; $lpName = $lpData['name'] ?? null;
$sessionId = (int) $row['session_id']; $sessionId = (int) $row['session_id'];
$toUser = (int) $row['user_id']; $toUser = (int) $row['user_id'];
@ -319,21 +316,19 @@ function learningPaths()
} }
/* Get users who are enrolled in the course */ /* Get users who are enrolled in the course */
$sql = " $sql = "SELECT DISTINCT
SELECT DISTINCT tblCourseRelUser.user_id AS user_id,
tblCourseRelUser.user_id AS user_id, tblLp.id AS lp_id,
tblLp.id AS lp_id, tblLp.c_id AS c_id
tblLp.c_id AS c_id FROM
FROM $lpTable AS tblLp
$lpTable AS tblLp INNER JOIN $tblCourseRelUser AS tblCourseRelUser ON ( tblCourseRelUser.c_id = tblLp.c_id)
INNER JOIN $tblCourseRelUser AS tblCourseRelUser ON ( tblCourseRelUser.c_id = tblLp.c_id) WHERE
WHERE publicated_on <= '$date 23:59:59' AND
publicated_on <= '$date 23:59:59' AND publicated_on >= '$date 00:00:00' AND
publicated_on >= '$date 00:00:00' AND tblCourseRelUser.user_id IS NOT NULL AND
tblCourseRelUser.user_id IS NOT NULL AND tblCourseRelUser.status = 5 AND
tblCourseRelUser.status = 5 AND tblLp.id in ($lpItemsString)";
tblLp.id in ($lpItemsString)
";
$result = Database::query($sql); $result = Database::query($sql);
while ($row = Database::fetch_array($result)) { while ($row = Database::fetch_array($result)) {
@ -345,9 +340,9 @@ function learningPaths()
if (!isset($tutors[$row['c_id']][$row['lp_id']])) { if (!isset($tutors[$row['c_id']][$row['lp_id']])) {
$tutors[$row['c_id']][$row['lp_id']] = getTutorIdFromCourseRelUser($row['c_id'], $row['lp_id']); $tutors[$row['c_id']][$row['lp_id']] = getTutorIdFromCourseRelUser($row['c_id'], $row['lp_id']);
} }
$courseName = isset($lpData['course_name']) ? $lpData['course_name'] : null; $courseName = $lpData['course_name'] ?? null;
$courseCode = isset($lpData['code']) ? $lpData['code'] : null; $courseCode = $lpData['code'] ?? null;
$lpName = isset($lpData['name']) ? $lpData['name'] : null; $lpName = $lpData['name'] ?? null;
$toUser = (int) $row['user_id']; $toUser = (int) $row['user_id'];
$fromUser = $tutors[$row['c_id']][$row['lp_id']]; $fromUser = $tutors[$row['c_id']][$row['lp_id']];
$userInfo = api_get_user_info($toUser); $userInfo = api_get_user_info($toUser);
@ -374,25 +369,23 @@ function learningPaths()
} }
} }
/** Get the users who are registered in the sessions */ /** Get the users who are registered in the sessions */
$sql = " $sql = "SELECT DISTINCT
SELECT DISTINCT tblSessionRelCourseRelUser.user_id AS user_id,
tblSessionRelCourseRelUser.user_id AS user_id, tblLp.id AS lp_id,
tblLp.id AS lp_id, tblSessionRelCourseRelUser.session_id AS session_id,
tblSessionRelCourseRelUser.session_id AS session_id, tblLp.c_id AS c_id,
tblLp.c_id AS c_id, tblSessionRelCourseRelUser.status AS status
tblSessionRelCourseRelUser.`status` AS `status` FROM
FROM $lpTable AS tblLp
$lpTable AS tblLp INNER JOIN $tblSessionCourseUser AS tblSessionRelCourseRelUser ON (
INNER JOIN $tblSessionCourseUser AS tblSessionRelCourseRelUser ON ( tblSessionRelCourseRelUser.c_id = tblLp.c_id)
tblSessionRelCourseRelUser.c_id = tblLp.c_id) WHERE
WHERE publicated_on <= '$date 23:59:59' AND
publicated_on <= '$date 23:59:59' AND publicated_on >= '$date 00:00:00' AND
publicated_on >= '$date 00:00:00' AND tblSessionRelCourseRelUser.user_id IS NOT NULL AND
tblSessionRelCourseRelUser.user_id IS NOT NULL AND tblLp.id in ($lpItemsString) AND
tblLp.id in ($lpItemsString) AND tblSessionRelCourseRelUser.status = 0
tblSessionRelCourseRelUser.`status` = 0 ORDER BY tblSessionRelCourseRelUser.status";
ORDER BY tblSessionRelCourseRelUser.`status`
";
$result = Database::query($sql); $result = Database::query($sql);
while ($row = Database::fetch_array($result)) { while ($row = Database::fetch_array($result)) {
$lpId = (int) $row['lp_id']; $lpId = (int) $row['lp_id'];
@ -400,9 +393,9 @@ function learningPaths()
if (isset($lpsData[$lpId])) { if (isset($lpsData[$lpId])) {
$lpData = $lpsData[$lpId]; $lpData = $lpsData[$lpId];
} }
$courseName = isset($lpData['course_name']) ? $lpData['course_name'] : null; $courseName = $lpData['course_name'] ?? null;
$courseCode = isset($lpData['code']) ? $lpData['code'] : null; $courseCode = $lpData['code'] ?? null;
$lpName = isset($lpData['name']) ? $lpData['name'] : null; $lpName = $lpData['name'] ?? null;
$toUser = (int) $row['user_id']; $toUser = (int) $row['user_id'];
if (!isset($tutors[$row['c_id']][$row['lp_id']])) { if (!isset($tutors[$row['c_id']][$row['lp_id']])) {
$tutors[$row['c_id']][$row['lp_id']] = getTutorIdFromCourseRelUser($row['c_id'], $row['lp_id']); $tutors[$row['c_id']][$row['lp_id']] = getTutorIdFromCourseRelUser($row['c_id'], $row['lp_id']);
@ -442,7 +435,8 @@ function learningPaths()
foreach ($types as $type => $users) { foreach ($types as $type => $users) {
if ('LearnpathSubscription' == $type) { if ('LearnpathSubscription' == $type) {
sendToArray($users, $type, $message, $lpId); sendToArray($users, $type, $message, $lpId);
} else { }
else {
if (!isset($itemProcessed[$lpId][$sessionId]['LearnpathSubscription'])) { if (!isset($itemProcessed[$lpId][$sessionId]['LearnpathSubscription'])) {
sendToArray($users, $type, $message, $lpId); sendToArray($users, $type, $message, $lpId);
} }

Loading…
Cancel
Save