Skip to content

Commit 4e0e2be

Browse files
committed
Pausetraining: Update send mail conditions BT#16298
Format code + remove unused function
1 parent 07b8e96 commit 4e0e2be

File tree

1 file changed

+25
-60
lines changed

1 file changed

+25
-60
lines changed

main/inc/lib/message.lib.php

Lines changed: 25 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ public static function getWhereConditions($extraParams)
128128
*
129129
* @param int $from
130130
* @param int $numberOfItems
131-
* @param string $column
131+
* @param int $column
132132
* @param string $direction
133133
* @param array $extraParams
134134
*
@@ -438,7 +438,7 @@ public static function messageWasAlreadySent($senderId, $receiverId, $subject, $
438438
/**
439439
* Sends a message to a user/group.
440440
*
441-
* @param int $receiver_user_id
441+
* @param int $receiverUserId
442442
* @param string $subject
443443
* @param string $content
444444
* @param array $attachments files array($_FILES) (optional)
@@ -457,7 +457,7 @@ public static function messageWasAlreadySent($senderId, $receiverId, $subject, $
457457
* @return bool
458458
*/
459459
public static function send_message(
460-
$receiver_user_id,
460+
$receiverUserId,
461461
$subject,
462462
$content,
463463
array $attachments = [],
@@ -475,15 +475,15 @@ public static function send_message(
475475
$status = 0
476476
) {
477477
$group_id = (int) $group_id;
478-
$receiver_user_id = (int) $receiver_user_id;
478+
$receiverUserId = (int) $receiverUserId;
479479
$parent_id = (int) $parent_id;
480480
$editMessageId = (int) $editMessageId;
481481
$topic_id = (int) $topic_id;
482482
$status = empty($status) ? MESSAGE_STATUS_UNREAD : (int) $status;
483483

484484
$sendEmail = true;
485-
if (!empty($receiver_user_id)) {
486-
$receiverUserInfo = api_get_user_info($receiver_user_id);
485+
if (!empty($receiverUserId)) {
486+
$receiverUserInfo = api_get_user_info($receiverUserId);
487487
if (empty($receiverUserInfo)) {
488488
return false;
489489
}
@@ -495,8 +495,8 @@ public static function send_message(
495495

496496
// Disabling messages depending the pausetraining plugin.
497497
$allowPauseFormation =
498-
api_get_plugin_setting('pausetraining', 'tool_enable') === 'true' &&
499-
api_get_plugin_setting('pausetraining', 'allow_users_to_edit_pause_formation') === 'true';
498+
'true' === api_get_plugin_setting('pausetraining', 'tool_enable') &&
499+
'true' === api_get_plugin_setting('pausetraining', 'allow_users_to_edit_pause_formation');
500500

501501
if ($allowPauseFormation) {
502502
$extraFieldValue = new ExtraFieldValue('user');
@@ -505,13 +505,19 @@ public static function send_message(
505505
'allow_notifications'
506506
);
507507

508+
// User doesn't want email notifications but chamilo inbox still available (Option was not set)
508509
if (empty($allowEmailNotifications)) {
509510
$sendEmail = false;
510511
}
511512

513+
// User doesn't want email notifications but chamilo inbox still available. (Option was set to "No")
512514
if (!empty($allowEmailNotifications) &&
513-
isset($allowEmailNotifications['value']) && 1 === (int) $allowEmailNotifications['value']
515+
isset($allowEmailNotifications['value']) && 0 === (int) $allowEmailNotifications['value']
514516
) {
517+
$sendEmail = false;
518+
}
519+
520+
if ($sendEmail) {
515521
$startDate = $extraFieldValue->get_values_by_handler_and_field_variable(
516522
$receiverUserInfo['user_id'],
517523
'start_pause_date'
@@ -607,7 +613,7 @@ public static function send_message(
607613
$now = api_get_utc_datetime();
608614
$table = Database::get_main_table(TABLE_MESSAGE);
609615

610-
if (!empty($receiver_user_id) || !empty($group_id)) {
616+
if (!empty($receiverUserId) || !empty($group_id)) {
611617
// message for user friend
612618
//@todo it's possible to edit a message? yes, only for groups
613619
if (!empty($editMessageId)) {
@@ -620,7 +626,7 @@ public static function send_message(
620626
} else {
621627
$params = [
622628
'user_sender_id' => $user_sender_id,
623-
'user_receiver_id' => $receiver_user_id,
629+
'user_receiver_id' => $receiverUserId,
624630
'msg_status' => $status,
625631
'send_date' => $now,
626632
'title' => $subject,
@@ -661,7 +667,7 @@ public static function send_message(
661667
$comment,
662668
$messageId,
663669
null,
664-
$receiver_user_id,
670+
$receiverUserId,
665671
$group_id
666672
);
667673
}
@@ -672,7 +678,7 @@ public static function send_message(
672678
if (empty($group_id) && MESSAGE_STATUS_UNREAD == $status) {
673679
$params = [
674680
'user_sender_id' => $user_sender_id,
675-
'user_receiver_id' => $receiver_user_id,
681+
'user_receiver_id' => $receiverUserId,
676682
'msg_status' => MESSAGE_STATUS_OUTBOX,
677683
'send_date' => $now,
678684
'title' => $subject,
@@ -720,7 +726,7 @@ public static function send_message(
720726
$notification->saveNotification(
721727
$messageId,
722728
$type,
723-
[$receiver_user_id],
729+
[$receiverUserId],
724730
$subject,
725731
$content,
726732
$sender_info,
@@ -772,7 +778,7 @@ public static function send_message(
772778
}
773779

774780
/**
775-
* @param int $receiver_user_id
781+
* @param int $receiverUserId
776782
* @param int $subject
777783
* @param string $message
778784
* @param int $sender_id
@@ -785,7 +791,7 @@ public static function send_message(
785791
* @return bool
786792
*/
787793
public static function send_message_simple(
788-
$receiver_user_id,
794+
$receiverUserId,
789795
$subject,
790796
$message,
791797
$sender_id = 0,
@@ -804,7 +810,7 @@ public static function send_message_simple(
804810
$files = $attachmentList;
805811
}
806812
$result = self::send_message(
807-
$receiver_user_id,
813+
$receiverUserId,
808814
$subject,
809815
$message,
810816
$files,
@@ -820,8 +826,8 @@ public static function send_message_simple(
820826
);
821827

822828
if ($sendCopyToDrhUsers) {
823-
$userInfo = api_get_user_info($receiver_user_id);
824-
$drhList = UserManager::getDrhListFromUser($receiver_user_id);
829+
$userInfo = api_get_user_info($receiverUserId);
830+
$drhList = UserManager::getDrhListFromUser($receiverUserId);
825831
if (!empty($drhList)) {
826832
foreach ($drhList as $drhInfo) {
827833
$message = sprintf(
@@ -844,47 +850,6 @@ public static function send_message_simple(
844850
return $result;
845851
}
846852

847-
/**
848-
* Update parent ids for other receiver user from current message in groups.
849-
*
850-
* @author Christian Fasanando Flores
851-
*
852-
* @param int $parent_id
853-
* @param int $receiver_user_id
854-
* @param int $messageId
855-
*/
856-
public static function update_parent_ids_from_reply(
857-
$parent_id,
858-
$receiver_user_id,
859-
$messageId
860-
) {
861-
$table = Database::get_main_table(TABLE_MESSAGE);
862-
$parent_id = intval($parent_id);
863-
$receiver_user_id = intval($receiver_user_id);
864-
$messageId = intval($messageId);
865-
866-
// first get data from message id (parent)
867-
$sql = "SELECT * FROM $table WHERE id = '$parent_id'";
868-
$rs_message = Database::query($sql);
869-
$row_message = Database::fetch_array($rs_message);
870-
871-
// get message id from data found early for other receiver user
872-
$sql = "SELECT id FROM $table
873-
WHERE
874-
user_sender_id ='{$row_message['user_sender_id']}' AND
875-
title='{$row_message['title']}' AND
876-
content='{$row_message['content']}' AND
877-
group_id='{$row_message['group_id']}' AND
878-
user_receiver_id='$receiver_user_id'";
879-
$result = Database::query($sql);
880-
$row = Database::fetch_array($result);
881-
882-
// update parent_id for other user receiver
883-
$sql = "UPDATE $table SET parent_id = ".$row['id']."
884-
WHERE id = $messageId";
885-
Database::query($sql);
886-
}
887-
888853
/**
889854
* @param int $user_receiver_id
890855
* @param int $id

0 commit comments

Comments
 (0)