Skip to content

Commit 1b75983

Browse files
committed
Add setting "send_notification_when_document_added" see BT#13964
Sends a notification to all students and teachers from a course and all students and session course coaches from a session-course when a document is added.
1 parent a8b4e48 commit 1b75983

File tree

1 file changed

+30
-7
lines changed

1 file changed

+30
-7
lines changed

main/inc/lib/fileUpload.lib.php

Lines changed: 30 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1313,8 +1313,8 @@ function filter_extension(&$filename)
13131313
* @param int $readonly
13141314
* @param bool $saveVisibility
13151315
* @param int $group_id group.id
1316-
* @param int $session_id Session ID, if any
1317-
* @param int $userId creator id
1316+
* @param int $sessionId Session ID, if any
1317+
* @param int $userId creator user id
13181318
*
13191319
* @return int id if inserted document
13201320
*/
@@ -1328,13 +1328,13 @@ function add_document(
13281328
$readonly = 0,
13291329
$saveVisibility = true,
13301330
$group_id = 0,
1331-
$session_id = 0,
1331+
$sessionId = 0,
13321332
$userId = 0
13331333
) {
1334-
$session_id = empty($session_id) ? api_get_session_id() : $session_id;
1334+
$sessionId = empty($sessionId) ? api_get_session_id() : $sessionId;
13351335
$userId = empty($userId) ? api_get_user_id() : $userId;
13361336

1337-
$readonly = intval($readonly);
1337+
$readonly = (int) $readonly;
13381338
$c_id = $courseInfo['real_id'];
13391339
$params = [
13401340
'c_id' => $c_id,
@@ -1344,7 +1344,7 @@ function add_document(
13441344
'title' => $title,
13451345
'comment' => $comment,
13461346
'readonly' => $readonly,
1347-
'session_id' => $session_id,
1347+
'session_id' => $sessionId,
13481348
];
13491349
$table = Database::get_course_table(TABLE_DOCUMENT);
13501350
$documentId = Database::insert($table, $params);
@@ -1358,11 +1358,34 @@ function add_document(
13581358
TOOL_DOCUMENT,
13591359
$group_id,
13601360
$courseInfo,
1361-
$session_id,
1361+
$sessionId,
13621362
$userId
13631363
);
13641364
}
13651365

1366+
$allowNotification = api_get_configuration_value('send_notification_when_document_added');
1367+
if ($allowNotification) {
1368+
$courseTitle = $courseInfo['title'];
1369+
if (!empty($sessionId)) {
1370+
$sessionInfo = api_get_session_info($sessionId);
1371+
$courseTitle .= " ( ".$sessionInfo['name'].") ";
1372+
}
1373+
1374+
$url = api_get_path(WEB_CODE_PATH).
1375+
'document/showinframes.php?cidReq='.$courseInfo['code'].'&id_session='.$sessionId.'&id='.$documentId;
1376+
$link = Display::url(basename($title), $url, ['target' => '_blank']);
1377+
$userInfo = api_get_user_info($userId);
1378+
1379+
$message = sprintf(
1380+
get_lang('DocumentXHasBeenAddedToDocumentInYourCourseXByUserX'),
1381+
$link,
1382+
$courseTitle,
1383+
$userInfo['complete_name']
1384+
);
1385+
$subject = sprintf(get_lang('NewDocumentAddedToCourseX'), $courseTitle);
1386+
MessageManager::sendMessageToAllUsersInCourse($subject, $message, $courseInfo, $sessionId);
1387+
}
1388+
13661389
return $documentId;
13671390
} else {
13681391
return false;

0 commit comments

Comments
 (0)