1
0
mirror of https://github.com/freescout-helpdesk/freescout.git synced 2024-11-25 03:43:33 +01:00
freescout/app/SendLog.php

128 lines
3.2 KiB
PHP
Raw Normal View History

2018-08-08 09:52:53 +02:00
<?php
/**
* Outgoing emails.
*/
2018-08-08 09:56:03 +02:00
2018-08-08 09:52:53 +02:00
namespace App;
use Illuminate\Database\Eloquent\Model;
class SendLog extends Model
{
/**
* Status of the email sent to the customer or user.
2018-08-08 09:56:03 +02:00
* https://documentation.mailgun.com/en/latest/api-events.html#event-types.
2018-08-08 09:52:53 +02:00
*/
2018-08-08 09:56:03 +02:00
const STATUS_ACCEPTED = 1; // accepted (for delivery)
const STATUS_SEND_ERROR = 2;
const STATUS_DELIVERY_SUCCESS = 4;
const STATUS_DELIVERY_ERROR = 5; // rejected, failed
const STATUS_OPENED = 6;
const STATUS_CLICKED = 7;
const STATUS_UNSUBSCRIBED = 8;
const STATUS_COMPLAINED = 9;
2018-08-08 09:52:53 +02:00
2018-08-24 14:24:11 +02:00
/**
* Mail types.
*/
const MAIL_TYPE_EMAIL_TO_CUSTOMER = 1;
const MAIL_TYPE_USER_NOTIFICATION = 2;
const MAIL_TYPE_AUTO_REPLY = 3;
const MAIL_TYPE_WRONG_USER_EMAIL_MESSAGE = 4;
2018-08-08 09:52:53 +02:00
/**
* The attributes that are not mass assignable.
*
* @var array
*/
protected $guarded = ['id'];
/**
* Customer.
*/
public function customer()
{
return $this->belongsTo('App\Customer');
}
/**
* User.
*/
public function user()
{
return $this->belongsTo('App\User');
}
/**
* Thread.
*/
public function thread()
{
return $this->belongsTo('App\Thread');
}
/**
* Save log record.
*/
2018-08-24 14:24:11 +02:00
public static function log($thread_id, $message_id, $email, $mail_type, $status, $customer_id = null, $user_id = null, $status_message = null)
2018-08-08 09:52:53 +02:00
{
$send_log = new self();
$send_log->thread_id = $thread_id;
$send_log->message_id = $message_id;
$send_log->email = $email;
2018-08-24 14:24:11 +02:00
$send_log->mail_type = $mail_type;
2018-08-08 09:52:53 +02:00
$send_log->status = $status;
$send_log->customer_id = $customer_id;
$send_log->user_id = $user_id;
2018-08-20 19:41:51 +02:00
$send_log->status_message = $status_message;
2018-08-08 09:52:53 +02:00
$send_log->save();
return true;
}
2018-08-20 19:41:51 +02:00
/**
* Get name of the status.
*/
public function getStatusName()
{
switch ($this->status) {
case self::STATUS_ACCEPTED:
return __('Accepted for delivery');
case self::STATUS_SEND_ERROR:
return __('Send error');
case self::STATUS_DELIVERY_SUCCESS:
return __('Successfully delivered');
case self::STATUS_DELIVERY_ERROR:
return __('Delivery error');
case self::STATUS_OPENED:
return __('Recipient opened the message');
case self::STATUS_CLICKED:
return __('Recipient clicked a link in the message');
case self::STATUS_UNSUBSCRIBED:
return __('Recipient unsubscribed');
case self::STATUS_COMPLAINED:
return __('Recipient complained');
default:
return __('Unknown');
}
}
public function isErrorStatus()
{
if (in_array($this->status, [self::STATUS_SEND_ERROR, self::STATUS_DELIVERY_ERROR])) {
return true;
} else {
return false;
}
}
public function isSuccessStatus()
{
if (in_array($this->status, [self::STATUS_DELIVERY_SUCCESS])) {
return true;
} else {
return false;
}
}
2018-08-08 09:52:53 +02:00
}