示例#1
0
文件: Author.php 项目: yonkon/diplom
 public static function enqueue_message_to_email($message_id, $authors_ids, $notification_type = EmailNotification::TO_AUTHOR_ON_ASSIGN)
 {
     if (empty($message_id) || !is_numeric($message_id)) {
         return false;
     }
     assert(in_array($notification_type, EmailNotification::$NOTIFICATION_TYPES));
     // Если не надо уведомлять - выходим типа все ок
     if (!EmailNotificationType::isSendable($notification_type)) {
         return array();
     }
     $result = array();
     if (!is_array($authors_ids) && is_numeric($authors_ids)) {
         $authors_ids = array($authors_ids);
     }
     foreach ($authors_ids as $id) {
         if (is_numeric($id)) {
             try {
                 $author = Employee::find($id);
             } catch (Exception $e) {
                 $result['error'][] = $id;
                 continue;
             }
             $notification_id = EmailNotification::create(array('message_id' => $message_id, 'receiver_email' => $author['email'], 'type' => $notification_type));
             if ($notification_id) {
                 $result['success'][] = $id;
             }
         } else {
             $ids = explode(', ', $id);
             $temp_result = self::enqueue_message_to_email($message_id, $ids, $notification_type);
             if (count($temp_result['success'])) {
                 array_push($result['success'], $temp_result['success']);
             }
             if (count($temp_result['error'])) {
                 array_push($result['error'], $temp_result['error']);
             }
         }
     }
     return $result;
 }
示例#2
0
/**
 * @param int $message_id Message id in TABLE_MESSAGES
 * @param string $receiver_email receiver's Email address
 * @param int $message_type тип сообщения, из набора EmailNotificationType::$NOTIFICATION_TYPES
 * @see EmailNotificationType
 * @return mixed
 */
function enqueue_message_to_email($message_id, $receiver_email, $notification_type)
{
    assert(in_array($notification_type, EmailNotificationType::$NOTIFICATION_TYPES));
    if (empty($receiver_email)) {
        return false;
    }
    if (!EmailNotificationType::isPersistable($notification_type)) {
        return false;
    }
    return EmailNotification::create(array('message_id' => $message_id, 'receiver_email' => $receiver_email, 'type' => $notification_type));
}