Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
T
taskonsite-архив-перенесен
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Packages
Packages
Container Registry
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Dmitry Korolev
taskonsite-архив-перенесен
Commits
5e4cf68c
Commit
5e4cf68c
authored
Mar 16, 2016
by
Олег Гиммельшпах
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'master' of git.task-on.com:ktask/task-on.com
parents
b15b175e
578d46ee
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
85 additions
and
27 deletions
+85
-27
common/modules/triggers/components/conditions/Conditions.php
common/modules/triggers/components/conditions/Conditions.php
+3
-3
common/modules/triggers/components/conditions/conditions/CheckPresenceTime.php
...rs/components/conditions/conditions/CheckPresenceTime.php
+19
-2
common/modules/triggers/components/conditions/conditions/CheckUserToRegistration.php
...ponents/conditions/conditions/CheckUserToRegistration.php
+7
-2
common/modules/triggers/models/TriggerLogs.php
common/modules/triggers/models/TriggerLogs.php
+13
-1
common/modules/users/models/User.php
common/modules/users/models/User.php
+43
-19
No files found.
common/modules/triggers/components/conditions/Conditions.php
View file @
5e4cf68c
...
...
@@ -161,9 +161,9 @@ class Conditions {
// Привели массив в понятный вид
$conditionsArray
=
[];
foreach
(
$conditions
as
$i
=>
$condition
)
{
$object
=
Conditions
::
init
()
->
getConditionById
(
$condition
->
condition_id
);
if
(
$object
->
recall
===
false
)
return
false
;
//
$object=Conditions::init()->getConditionById($condition->condition_id);
//
if ($object->recall===false)
//
return false;
$conditionsArray
[
$i
][]
=
$condition
;
}
// На выходе получаем массив необходимого формата
// Обрабатываем отформатированный массив
...
...
common/modules/triggers/components/conditions/conditions/CheckPresenceTime.php
View file @
5e4cf68c
...
...
@@ -14,9 +14,11 @@ 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
;
use
common\modules\triggers\models\TriggerLogs
;
use
common\modules\triggers\models\TriggerParam
;
use
common\modules\triggers\models\TriggerSchedule
;
use
common\modules\triggers\models\TriggerTrigger
;
use
common\modules\users\models\User
;
use
yii\web\BadRequestHttpException
;
class
CheckPresenceTime
extends
ConditionBase
implements
ConditionInterface
{
...
...
@@ -75,10 +77,25 @@ class CheckPresenceTime extends ConditionBase implements ConditionInterface {
}
/**
* @param
$tim
e
* @param
TriggerSchedule $messag
e
* @return bool
*/
public
function
check
(
$time
){
public
function
check
(
$message
){
$user
=
User
::
find
()
->
where
([
'email'
=>
$message
->
email
])
->
one
();
if
(
!
is_null
(
$message
->
trigger_id
)
&&
!
is_null
(
$user
))
{
/** @var TriggerCondition[] $conditions */
$conditions
=
TriggerCondition
::
find
()
->
where
([
'trigger_id'
=>
$message
->
trigger_id
,
'condition_id'
=>
self
::
CONDITION_ID
])
->
all
();
foreach
(
$conditions
as
$condition
)
{
$urlParam
=
TriggerParam
::
find
()
->
where
([
'condition_id'
=>
$condition
->
getPrimaryKey
(),
'key'
=>
'url'
,
'value'
=>
\Yii
::
$app
->
request
->
getUrl
()])
->
one
();
$timeParam
=
TriggerParam
::
find
()
->
where
([
'condition_id'
=>
$condition
->
getPrimaryKey
(),
'key'
=>
'time'
])
->
one
();
if
(
!
is_null
(
$urlParam
)
&&
!
is_null
(
$timeParam
))
{
$sumTime
=
TriggerLogs
::
getSummaryTimeByUrl
(
$urlParam
,
$user
->
getPrimaryKey
());
if
(
$sumTime
>=
$timeParam
)
{
return
true
;
}
}
}
}
return
false
;
}
}
\ No newline at end of file
common/modules/triggers/components/conditions/conditions/CheckUserToRegistration.php
View file @
5e4cf68c
...
...
@@ -5,6 +5,7 @@ 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\TriggerLogs
;
use
common\modules\users\models\User
;
class
CheckUserToRegistration
extends
ConditionBase
implements
ConditionInterface
{
...
...
@@ -25,7 +26,11 @@ class CheckUserToRegistration extends ConditionBase implements ConditionInterfac
* @return bool
*/
public
function
check
(
$message
){
$exists
=
User
::
find
()
->
where
([
'email'
=>
$message
->
email
])
->
exists
();
return
$exists
;
$user
=
User
::
find
()
->
where
([
'email'
=>
$message
->
email
])
->
one
();
if
(
!
is_null
(
$user
))
{
$exists
=
TriggerLogs
::
find
()
->
where
([
'user_id'
=>
$user
->
getPrimaryKey
(),
'action'
=>
TriggerLogs
::
USER_REGISTRATION
])
->
exists
();
return
$exists
;
}
return
false
;
}
}
\ No newline at end of file
common/modules/triggers/models/TriggerLogs.php
View file @
5e4cf68c
...
...
@@ -45,7 +45,7 @@ class TriggerLogs extends \yii\db\ActiveRecord
var value = 5;
setInterval(function() {
$.ajax({
url: "/triggers/default/settimeoflogs",
url: "
http://taskon.task-on.com
/triggers/default/settimeoflogs",
method: "GET",
async: false,
data: {
...
...
@@ -103,5 +103,17 @@ class TriggerLogs extends \yii\db\ActiveRecord
public
function
getUser
()
{
return
$this
->
hasOne
(
User
::
className
(),
[
'id'
=>
'user_id'
]);
}
public
static
function
getSummaryTimeByUrl
(
$url
,
$user_id
)
{
/** @var TriggerLogs[] $model */
$model
=
TriggerLogs
::
find
()
->
where
([
'url'
=>
$url
,
'user_id'
=>
$user_id
])
->
all
();
$summ
=
0
;
foreach
(
$model
as
$item
)
{
$summ
+=
$item
->
presence_time
;
}
return
$summ
;
}
}
common/modules/users/models/User.php
View file @
5e4cf68c
...
...
@@ -4,8 +4,10 @@ namespace common\modules\users\models;
use
common\components\UnisenderAPI
;
use
common\modules\messageTemplate\controllers\TemplateAdminController
;
use
common\modules\messageTemplate\models\MessageTemplate
;
use
common\modules\triggers\components\conditions\Conditions
;
use
common\modules\triggers\components\conditions\conditions\CheckUserToRegistration
;
use
common\modules\triggers\models\TriggerCondition
;
use
common\modules\triggers\models\TriggerLogs
;
use
common\modules\triggers\models\TriggerSchedule
;
use
common\modules\triggers\models\TriggerTrigger
;
use
Yii
;
...
...
@@ -519,11 +521,21 @@ class User extends \common\components\ActiveRecordModel implements IdentityInter
if
(
!
parent
::
validate
(
$attributeNames
=
null
,
$clearErrors
=
true
))
return
false
;
// if ($this->scenario===self::SCENARIO_REGISTRATION || $this->scenario===self::SCENARIO_SOCIAL_REGISTRATION) {
// if (!$this->afterRegistration(['email' => $this->email, 'user_fio' => $this->getFio()]))
// return false;
// }
return
true
;
}
public
function
afterSave
(
$insert
,
$changedAttributes
)
{
parent
::
afterSave
(
$insert
,
$changedAttributes
);
if
(
$this
->
scenario
===
self
::
SCENARIO_REGISTRATION
||
$this
->
scenario
===
self
::
SCENARIO_SOCIAL_REGISTRATION
)
{
if
(
!
$this
->
afterRegistration
([
'email'
=>
$this
->
email
,
'user_fio'
=>
$this
->
getFio
()]))
return
false
;
}
return
true
;
}
public
function
afterDelete
()
...
...
@@ -579,28 +591,40 @@ class User extends \common\components\ActiveRecordModel implements IdentityInter
* Если указан, выполняем действия триггера
*/
public
function
afterRegistration
(
$params
=
array
()){
/** @var TriggerTrigger[] $actualTriggers */
$actualTriggers
=
TriggerTrigger
::
getActualTriggers
();
foreach
(
$actualTriggers
as
$trigger
)
{
$exists
=
TriggerCondition
::
find
()
->
where
([
'trigger_id'
=>
$trigger
->
id
,
'condition_id'
=>
CheckUserToRegistration
::
CONDITION_ID
])
->
exists
();
$count
=
TriggerCondition
::
find
()
->
where
([
'trigger_id'
=>
$trigger
->
id
])
->
count
();
// Добавляем в расписание срабатывание триггера регистрации только при условии что у триггера условие регистрации есть и оно там одно
if
(
$exists
===
true
&&
$count
==
1
)
{
$init
=
$trigger
->
initAction
(
$params
);
if
(
$init
===
true
)
{
$curl
=
curl_init
();
curl_setopt
(
$curl
,
CURLOPT_URL
,
Yii
::
$app
->
urlManager
->
createAbsoluteUrl
(
'/triggers/default/rechecktriggers'
));
curl_setopt
(
$curl
,
CURLOPT_RETURNTRANSFER
,
true
);
if
(
!
curl_exec
(
$curl
))
{
$this
->
addError
(
'email'
,
curl_error
(
$curl
));
$date
=
new
\DateTime
();
$model
=
new
TriggerLogs
();
$model
->
user_id
=
$this
->
getPrimaryKey
();
$model
->
action
=
TriggerLogs
::
USER_REGISTRATION
;
$model
->
url
=
Yii
::
$app
->
request
->
getUrl
();
$model
->
datetime
=
$date
->
format
(
'Y-m-d H:i:s'
);
$model
->
presence_time
=
1
;
if
(
$model
->
save
())
{
/** @var TriggerTrigger[] $actualTriggers */
$actualTriggers
=
TriggerTrigger
::
getActualTriggers
();
foreach
(
$actualTriggers
as
$trigger
)
{
$exists
=
TriggerCondition
::
find
()
->
where
([
'trigger_id'
=>
$trigger
->
id
,
'condition_id'
=>
CheckUserToRegistration
::
CONDITION_ID
])
->
exists
();
$count
=
TriggerCondition
::
find
()
->
where
([
'trigger_id'
=>
$trigger
->
id
])
->
count
();
// Добавляем в расписание срабатывание триггера регистрации только при условии что у триггера условие регистрации есть и оно там одно
if
(
$exists
===
true
&&
$count
==
1
)
{
$init
=
$trigger
->
initAction
(
$params
);
if
(
$init
===
true
)
{
$curl
=
curl_init
();
curl_setopt
(
$curl
,
CURLOPT_URL
,
Yii
::
$app
->
urlManager
->
createAbsoluteUrl
(
'/triggers/default/rechecktriggers'
));
curl_setopt
(
$curl
,
CURLOPT_RETURNTRANSFER
,
true
);
if
(
!
curl_exec
(
$curl
))
{
$this
->
addError
(
'email'
,
curl_error
(
$curl
));
return
false
;
}
return
true
;
}
else
{
$this
->
addError
(
'email'
,
$init
);
return
false
;
}
return
true
;
}
else
{
$this
->
addError
(
'email'
,
$init
);
return
false
;
}
}
}
else
{
$this
->
addError
(
'email'
,
current
(
current
(
$model
->
getErrors
())));
return
false
;
}
return
true
;
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment