Commit af2d4806 authored by Shakarim Sapa's avatar Shakarim Sapa

- Добавлена проверка НЕ прочитанности письма с конкретным шаблоном и в пределах указаной даты

parent f61fa92a
<?php
namespace common\modules\triggers\components\conditions\conditions;
use common\components\UnisenderAPI;
use common\modules\triggers\components\conditions\vendor\ConditionBase;
use common\modules\triggers\components\conditions\vendor\ConditionInterface;
use common\modules\triggers\models\TriggerParam;
use common\modules\triggers\models\TriggerSchedule;
use Faker\Provider\ka_GE\DateTime;
class CheckEmailAndTemplateToNotReading extends ConditionBase implements ConditionInterface {
const CONDITION_ID = 12;
public $name = 'Письмо с заданным шаблоном НЕ было прочтено до';
public $params=[];
public $model;
/**
* @param null|string $conditionName
* @return $this mixed
*/
public static function init($conditionName=__CLASS__){
return parent::init($conditionName);
}
/**
* @param TriggerSchedule $message
* @param array $params
* @return bool
*/
public function check($message=null, $params = array()){
if (!is_null($message)) {
// Создаем объект унисендера
$sender=new UnisenderAPI();
// Делаем запрос на получение статуса сообщения
$sender->getMessageStatuses($message->campaign_id, $message->message_id, $message->email);
return ($sender->isReaded());
}
if (!is_null($this->model) && !is_null($message)) {
// Получаем параметр link
$param_template = TriggerParam::find()->where(['condition_id' => $this->model->id, 'key' => 'template_id'])->one();
$param_date = TriggerParam::find()->where(['condition_id' => $this->model->id, 'key' => 'date'])->one();
// Если параметр есть, он длиннее нуля и не равен #
if (!is_null($param_template) && !is_null($param_date)) {
// Если идентификатор кампании в сообщении не равен нулю
if (!is_null($message->campaign_id)) {
$date_now = new \DateTime();
$check_date = new \DateTime($param_date);
// Создаем объект унисендера
$sender=new UnisenderAPI();
// Делаем запрос на получение статуса сообщения
$sender->getMessageStatuses($message->campaign_id, $message->message_id, $message->email);
return ($sender->isReaded()!==true && $message->template_id==$param_template && $date_now>$check_date) ? true : false;
}
}
}
return true;
}
}
\ No newline at end of file
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment