- Немного изменена логика выполнения скрипта на измерение времени пребывания на странице

parent 8e9e4f90
......@@ -9,6 +9,8 @@
namespace common\modules\triggers\components\conditions\conditions;
use common\modules\messageTemplate\components\Templates;
use common\modules\messageTemplate\models\MessageTemplate;
use common\modules\triggers\components\conditions\vendor\ConditionBase;
use common\modules\triggers\components\conditions\vendor\ConditionInterface;
use common\modules\triggers\models\TriggerCondition;
......@@ -49,39 +51,24 @@ class CheckPresenceTime extends ConditionBase implements ConditionInterface {
/** @var TriggerParam $paramTime */
$paramTime = TriggerParam::find()->where(['condition_id'=>$condition->getPrimaryKey(), 'key'=>'time'])->one();
// Если сработали условия что триггер есть, у него указаны время и URL и при этом он является триггером ДАННОГО типа
if ($condition->condition_id==self::CONDITION_ID && $paramUrl!==null && $paramUrl->value==\Yii::$app->request->getUrl() && $paramTime!==null) {
$now = new \DateTime();
$time = new \DateTime();
$time->modify('+ '.(((int)$trigger->timeout<(int)$cron_time) ? $cron_time : (int)$trigger->timeout+(int)$cron_time).' second');
// Заносим запись в базу
$model = new TriggerSchedule();
$model->sended = 0;
$model->checked = 0;
$model->message = 'Test the presence time';
$model->email = \common\modules\users\models\User::findOne(\Yii::$app->user->id)->email;
$model->time = $time->format('Y-m-d H:i:s');
$model->date_create = $now->format('Y-m-d H:i:s');
if ($model->save()) {
$view = \Yii::$app->controller->view;
// Создаем скрипт
$script ='$(document).ready(function() {
if ($condition->condition_id==self::CONDITION_ID && $paramUrl!==null && $paramUrl->value==\Yii::$app->request->getUrl() && $paramTime!==null && !\Yii::$app->user->isGuest) {
$view = \Yii::$app->controller->view;
// Создаем скрипт
$script ='$(document).ready(function() {
var timer='.((int)$paramTime->value*1000).';
setTimeout(function() {
$.ajax({
url: "/triggers/default/dropschedule",
url: "/triggers/default/initTrigger",
method: "GET",
async: false,
data: {
id: '.$model->getPrimaryKey().'
id: '.$trigger->getPrimaryKey().'
},
});
}, timer);
});';
// Регистрируем его
$view->registerJs($script, $view::POS_READY);
} else {
throw new BadRequestHttpException(current(current($model->getErrors())), 500);
}
// Регистрируем его
$view->registerJs($script, $view::POS_READY);
}
}
}
......@@ -92,6 +79,6 @@ class CheckPresenceTime extends ConditionBase implements ConditionInterface {
* @return bool
*/
public function check($time){
return true;
return false;
}
}
\ 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