Просмотр исходного кода

Announcements: Add "sender id" arg when sending an email BT#13672

jmontoyaa 7 лет назад
Родитель
Сommit
99f39aa7cf
3 измененных файлов с 15 добавлено и 32 удалено
  1. 2 1
      main/cron/import_csv.php
  2. 9 29
      main/inc/lib/AnnouncementEmail.php
  3. 4 2
      main/inc/lib/AnnouncementManager.php

+ 2 - 1
main/cron/import_csv.php

@@ -1216,7 +1216,8 @@ class ImportCsv
                                 $announcementId,
                                 false,
                                 false,
-                                $this->logger
+                                $this->logger,
+                                $this->defaultAdminId
                             );
                         } else {
                             $this->logger->addError("Error when trying to add announcement with title ".$subject." here: $info");

+ 9 - 29
main/inc/lib/AnnouncementEmail.php

@@ -92,9 +92,6 @@ class AnnouncementEmail
                 $this->session_id
             );
         }
-        if (!empty($this->logger)) {
-            $this->logger->addInfo('UserList: '.print_r($userList, 1));
-        }
 
         return $userList;
     }
@@ -191,21 +188,6 @@ class AnnouncementEmail
         return $newListUsers;
     }
 
-    /**
-     * Sender info
-     *
-     * @param string $key
-     * @param int $userId
-     *
-     * @return array
-     */
-    public function sender($key = '', $userId = 0)
-    {
-        $_user = api_get_user_info($userId);
-
-        return $key ? $_user[$key] : $_user;
-    }
-
     /**
      * Email subject
      *
@@ -238,7 +220,6 @@ class AnnouncementEmail
             $session_id
         );
 
-        $user_email = $this->sender('mail');
         // Build the link by hand because api_get_cidreq() doesn't accept course params
         $course_param = 'cidReq='.$courseCode.'&id_session='.$session_id.'&gidReq='.api_get_group_id();
         $course_name = $this->course('title');
@@ -257,12 +238,10 @@ class AnnouncementEmail
         }
 
         $result .= '<hr />';
-        $sender_name = api_get_person_name(
-            $this->sender('firstName'),
-            $this->sender('lastName'),
-            PERSON_NAME_EMAIL_ADDRESS
-        );
-        $result .= '<a href="mailto:'.$user_email.'">'.$sender_name.'</a><br/>';
+        $userInfo = api_get_user_info();
+        if (!empty($userInfo)) {
+            $result .= '<a href="mailto:'.$userInfo['mail'].'">'.$userInfo['complete_name'].'</a><br/>';
+        }
         $result .= '<a href="'.api_get_path(WEB_CODE_PATH).'announcements/announcements.php?'.$course_param.'">'.$course_name.'</a><br/>';
 
         return $result;
@@ -298,11 +277,12 @@ class AnnouncementEmail
      * Send emails to users.
      * @param bool $sendToUsersInSession
      * @param bool $sendToDrhUsers send a copy of the message to the DRH users
+     * @param int $senderId
      * related to the main user
      */
-    public function send($sendToUsersInSession = false, $sendToDrhUsers = false)
+    public function send($sendToUsersInSession = false, $sendToDrhUsers = false, $senderId = 0)
     {
-        $sender = $this->sender();
+        $senderId = empty($senderId) ? api_get_user_id() : (int) $senderId;
         $subject = $this->subject();
 
         // Send email one by one to avoid antispam
@@ -325,7 +305,7 @@ class AnnouncementEmail
                 $user['user_id'],
                 $subject,
                 $message,
-                $sender['user_id'],
+                $senderId,
                 $sendToDrhUsers,
                 true
             );
@@ -353,7 +333,7 @@ class AnnouncementEmail
                                 $user['user_id'],
                                 $subject,
                                 $message,
-                                $sender['user_id'],
+                                $senderId,
                                 false,
                                 true
                             );

+ 4 - 2
main/inc/lib/AnnouncementManager.php

@@ -1375,6 +1375,7 @@ class AnnouncementManager
      * @param bool $sendToUsersInSession
      * @param bool $sendToDrhUsers
      * @param Monolog\Handler\HandlerInterface logger
+     * @param int $senderId
      */
     public static function sendEmail(
         $courseInfo,
@@ -1382,10 +1383,11 @@ class AnnouncementManager
         $id,
         $sendToUsersInSession = false,
         $sendToDrhUsers = false,
-        $logger = null
+        $logger = null,
+        $senderId = 0
     ) {
         $email = new AnnouncementEmail($courseInfo, $sessionId, $id, $logger);
-        $email->send($sendToUsersInSession, $sendToDrhUsers);
+        $email->send($sendToUsersInSession, $sendToDrhUsers, $senderId);
     }
 
     /**