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
d03a501d
Commit
d03a501d
authored
Feb 03, 2016
by
Олег Гиммельшпах
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'master' of git.task-on.com:ktask/task-on.com
parents
fe8b7952
2231c98f
Changes
7
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
211 additions
and
37 deletions
+211
-37
common/modules/triggers/components/conditions/Conditions.php
common/modules/triggers/components/conditions/Conditions.php
+35
-2
common/modules/triggers/components/conditions/vendor/ConditionBase.php
...s/triggers/components/conditions/vendor/ConditionBase.php
+3
-2
common/modules/triggers/controllers/TriggerAdminController.php
...n/modules/triggers/controllers/TriggerAdminController.php
+4
-10
common/modules/triggers/forms/TriggerForm.php
common/modules/triggers/forms/TriggerForm.php
+4
-20
common/modules/triggers/models/TriggerCondition.php
common/modules/triggers/models/TriggerCondition.php
+23
-3
common/modules/triggers/models/TriggerParam.php
common/modules/triggers/models/TriggerParam.php
+60
-0
common/modules/triggers/models/TriggerTrigger.php
common/modules/triggers/models/TriggerTrigger.php
+82
-0
No files found.
common/modules/triggers/components/conditions/Conditions.php
View file @
d03a501d
...
...
@@ -8,6 +8,7 @@
*/
namespace
common\modules\triggers\components\conditions
;
use
common\modules\triggers\controllers\TriggerAdminController
;
use
yii\web\ServerErrorHttpException
;
class
Conditions
{
...
...
@@ -88,11 +89,43 @@ class Conditions {
return
null
;
}
public
static
function
getConditionHtml
(
$id
,
$key
,
$values
=
array
()){
$condition
=
Conditions
::
init
()
->
getConditionById
(
$id
);
$condition_key
=
rand
(
100
,
999
);
$result
=
'<div class="alert alert-info alert-dismissible" role="alert">'
;
$result
.=
'<button type="button" class="close" data-dismiss="alert" aria-label="Close"><span aria-hidden="true">×</span></button>'
;
$result
.=
'<strong>Условие: '
.
$condition
->
getName
()
.
'</strong>'
;
$result
.=
'<input type="hidden" name="Conditions['
.
$key
.
']['
.
$condition
->
getId
()
.
$condition_key
.
'][id]" value="'
.
$condition
->
getId
()
.
'"/>'
;
foreach
(
$condition
->
getParams
(
$key
,
$condition_key
,
$values
)
as
$param
)
{
$result
.=
$param
;
}
$result
.=
'</div>'
;
return
$result
;
}
/**
* @param array $condition_array
* @param null $key
* @return string
*/
public
function
getControlArea
(){
$html
=
'<div class="conditions-block"></div>'
;
public
static
function
getControlButtons
(
$condition_array
=
array
(),
$key
=
null
){
$key
=
(
$key
!==
null
)
?
$key
:
rand
(
100000
,
999999
);
return
'<tr data-key='
.
$key
.
'><td>'
.
Conditions
::
init
()
->
getControlArea
(
$condition_array
,
$key
)
.
'</td></tr>'
;
}
/**
* @param array $condition_array
* @param $key
* @return string
*/
public
function
getControlArea
(
$condition_array
=
array
(),
$key
=
null
){
$html
=
'<div class="conditions-block">'
;
if
(
count
(
$condition_array
)
>
0
)
{
foreach
(
$condition_array
as
$condition
)
{
$html
.=
self
::
getConditionHtml
(
$condition
[
'id'
],
(
$key
!==
null
)
?
$key
:
rand
(
100000
,
999999
),
(
array_key_exists
(
'params'
,
$condition
))
?
$condition
[
'params'
]
:
array
());
}
}
$html
.=
'</div>'
;
$html
.=
'<div class="btn-group" role="group">'
;
$html
.=
'<button type="button" class="btn btn-primary dropdown-toggle" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false"><i class="glyphicon glyphicon-plus"></i></button>'
;
$html
.=
'<ul class="dropdown-menu">'
;
...
...
common/modules/triggers/components/conditions/vendor/ConditionBase.php
View file @
d03a501d
...
...
@@ -49,9 +49,10 @@ class ConditionBase {
/**
* @param $group_key
* @param $condition_key
* @param array $values
* @return array
*/
public
function
getParams
(
$group_key
,
$condition_key
,
$value
=
null
){
public
function
getParams
(
$group_key
,
$condition_key
,
$value
s
=
array
()
){
$result
=
[];
if
(
isset
(
$this
->
config
[
'params'
]))
{
foreach
(
$this
->
config
[
'params'
]
as
$name
=>
$param
)
{
...
...
@@ -59,7 +60,7 @@ class ConditionBase {
switch
(
$type
)
{
case
'text'
:
default
:
$result
[]
=
'<input type="text" value="'
.
((
!
is_null
(
$value
))
?
$value
:
''
)
.
'" name="Conditions['
.
$group_key
.
']['
.
$this
->
getId
()
.
$condition_key
.
'
]['
.
$name
.
']" class="form-control" style="margin-top: 5px;" placeholder="'
.
((
isset
(
$param
[
'placeholder'
]))
?
$param
[
'placeholder'
]
:
''
)
.
'"/>'
;
$result
[]
=
'<input type="text" value="'
.
((
array_key_exists
(
$name
,
$values
))
?
$values
[
$name
]
:
''
)
.
'" name="Conditions['
.
$group_key
.
']['
.
$this
->
getId
()
.
$condition_key
.
'][params
]['
.
$name
.
']" class="form-control" style="margin-top: 5px;" placeholder="'
.
((
isset
(
$param
[
'placeholder'
]))
?
$param
[
'placeholder'
]
:
''
)
.
'"/>'
;
break
;
}
}
...
...
common/modules/triggers/controllers/TriggerAdminController.php
View file @
d03a501d
...
...
@@ -35,23 +35,15 @@ class TriggerAdminController extends AdminController {
}
public
function
actionGetandconditionhtml
(){
$result
=
'<tr data-key='
.
rand
(
100000
,
999999
)
.
'><td>'
.
Conditions
::
init
()
->
getControlArea
()
.
'</td></tr>'
;
$result
=
Conditions
::
getControlButtons
()
;
return
(
Yii
::
$app
->
request
->
isAjax
)
?
Json
::
encode
(
$result
)
:
$result
;
}
public
function
actionGetconditionhtml
(
$id
,
$key
){
$condition
=
Conditions
::
init
()
->
getConditionById
(
$id
);
$result
=
$this
->
renderPartial
(
'condition-html'
,
[
'object'
=>
$condition
,
'key'
=>
$key
]
);
$result
=
Conditions
::
getConditionHtml
(
$id
,
$key
);
return
Json
::
encode
(
$result
);
}
public
function
actionTesting
(){
return
$this
->
render
(
'testing'
...
...
@@ -109,8 +101,10 @@ class TriggerAdminController extends AdminController {
public
function
actionUpdate
(
$id
){
/** @var TriggerTrigger $model */
$model
=
TriggerTrigger
::
findOne
(
$id
);
$model
->
setScenario
(
'update'
);
if
(
$model
->
load
(
Yii
::
$app
->
request
->
post
()))
{
$model
->
conditions
=
Yii
::
$app
->
request
->
post
(
'Conditions'
);
$datetime
=
new
\DateTime
();
$model
->
owner_id
=
Yii
::
$app
->
user
->
getId
();
$model
->
date_create
=
$datetime
->
format
(
'Y-m-d H:i:s'
);
...
...
common/modules/triggers/forms/TriggerForm.php
View file @
d03a501d
<?php
/** @var \common\components\BaseForm $this */
/** @var \common\modules\triggers\models\TriggerTrigger $model */
use
\common\modules\triggers\components\conditions\Conditions
;
Yii
::
$app
->
controller
->
view
->
registerJsFile
(
'/js/triggers/conditions/admin-block.js'
)
;
$model
=
$this
->
model
;
// Формируем html будущей таблицы, открыли тег
$table
=
'<table class="table table-bordered">'
;
// Формируем тело будущей таблицы
$table
.=
'<tbody>'
;
// Если есть ошибка
if
(
$this
->
model
->
getErrors
(
'conditions'
))
{
$error
=
$this
->
model
->
getErrors
(
'conditions'
);
$table
.=
'<tr><td style="color: red;">'
.
$error
[
0
]
.
'</td></tr>'
;
}
// Тут добавляем кнопки управления по умолчанию
$table
.=
Yii
::
$app
->
controller
->
actionGetandconditionhtml
();
$table
.=
'</tbody>'
;
// Формируем футер
$table
.=
'<tfoot>'
;
$table
.=
'<td><button type="button" class="btn btn-primary add-and-condition">Добавить условие "И"</button></td>'
;
$table
.=
'</tfoot>'
;
// Закрываем таблицу
$table
.=
'</table>'
;
Yii
::
$app
->
controller
->
view
->
registerJsFile
(
'/js/triggers/conditions/admin-block.js'
);
return
[
'activeForm'
=>
[
'id'
=>
'trigger-form'
],
'elements'
=>
[
'table'
=>
$
table
,
'table'
=>
$
model
->
getConditionTable
()
,
'active'
=>
[
'type'
=>
'checkbox'
],
...
...
common/modules/triggers/models/TriggerCondition.php
View file @
d03a501d
...
...
@@ -10,10 +10,12 @@ use Yii;
* @property integer $id
* @property integer $group_number
* @property integer $trigger_id
* @property integer $condition_id
*
* @property TriggerTrigger $trigger
* @property TriggerParam[] $triggerParams
*/
class
TriggerCondition
extends
\
yii\db\ActiveRecord
class
TriggerCondition
extends
\
common\components\ActiveRecordModel
{
/**
* @inheritdoc
...
...
@@ -23,18 +25,27 @@ class TriggerCondition extends \yii\db\ActiveRecord
return
'trigger_condition'
;
}
public
function
name
()
{
return
'Условия триггера'
;
}
/**
* @inheritdoc
*/
public
function
rules
()
{
return
[
[[
'group_number'
,
'trigger_id'
],
'required'
],
[[
'group_number'
,
'trigger_id'
],
'integer'
],
[[
'group_number'
,
'trigger_id'
,
'condition_id'
],
'required'
],
[[
'group_number'
,
'trigger_id'
,
'condition_id'
],
'integer'
],
[[
'trigger_id'
],
'exist'
,
'skipOnError'
=>
true
,
'targetClass'
=>
TriggerTrigger
::
className
(),
'targetAttribute'
=>
[
'trigger_id'
=>
'id'
]],
];
}
public
function
behaviors
(){
return
[];
}
/**
* @inheritdoc
*/
...
...
@@ -44,6 +55,7 @@ class TriggerCondition extends \yii\db\ActiveRecord
'id'
=>
'ID'
,
'group_number'
=>
'Group Number'
,
'trigger_id'
=>
'Trigger ID'
,
'condition_id'
=>
'Идентификатор условия'
];
}
...
...
@@ -54,4 +66,12 @@ class TriggerCondition extends \yii\db\ActiveRecord
{
return
$this
->
hasOne
(
TriggerTrigger
::
className
(),
[
'id'
=>
'trigger_id'
]);
}
/**
* @return \yii\db\ActiveQuery
*/
public
function
getTriggerParams
()
{
return
$this
->
hasMany
(
TriggerParam
::
className
(),
[
'condition_id'
=>
'id'
]);
}
}
common/modules/triggers/models/TriggerParam.php
0 → 100644
View file @
d03a501d
<?php
namespace
common\modules\triggers\models
;
use
Yii
;
/**
* This is the model class for table "trigger_param".
*
* @property integer $id
* @property integer $condition_id
* @property string $key
* @property string $value
*
* @property TriggerCondition $condition
*/
class
TriggerParam
extends
\yii\db\ActiveRecord
{
/**
* @inheritdoc
*/
public
static
function
tableName
()
{
return
'trigger_param'
;
}
/**
* @inheritdoc
*/
public
function
rules
()
{
return
[
[[
'condition_id'
],
'required'
],
[[
'condition_id'
],
'integer'
],
[[
'key'
,
'value'
],
'string'
],
[[
'condition_id'
],
'exist'
,
'skipOnError'
=>
true
,
'targetClass'
=>
TriggerCondition
::
className
(),
'targetAttribute'
=>
[
'condition_id'
=>
'id'
]],
];
}
/**
* @inheritdoc
*/
public
function
attributeLabels
()
{
return
[
'id'
=>
'ID'
,
'condition_id'
=>
'Condition ID'
,
'key'
=>
'Key'
,
'value'
=>
'Value'
,
];
}
/**
* @return \yii\db\ActiveQuery
*/
public
function
getCondition
()
{
return
$this
->
hasOne
(
TriggerCondition
::
className
(),
[
'id'
=>
'condition_id'
]);
}
}
common/modules/triggers/models/TriggerTrigger.php
View file @
d03a501d
...
...
@@ -2,6 +2,7 @@
namespace
common\modules\triggers\models
;
use
common\modules\triggers\components\conditions\Conditions
;
use
Yii
;
use
common\modules\users\models\User
;
...
...
@@ -32,6 +33,80 @@ class TriggerTrigger extends \common\components\ActiveRecordModel
return
'Триггеры'
;
}
public
function
afterFind
(){
/** @var TriggerCondition $condition */
foreach
(
$this
->
triggerConditions
as
$condition
)
{
$this
->
conditions
[
$condition
->
group_number
][
$condition
->
getPrimaryKey
()]
=
[
'id'
=>
$condition
->
condition_id
];
foreach
(
$condition
->
triggerParams
as
$param
)
{
$this
->
conditions
[
$condition
->
group_number
][
$condition
->
getPrimaryKey
()][
'params'
][
$param
->
key
]
=
$param
->
value
;
}
}
}
public
function
afterSave
(
$insert
,
$changedAttributes
){
parent
::
afterSave
(
$insert
,
$changedAttributes
);
if
(
$this
->
scenario
==
'update'
)
{
foreach
(
$this
->
triggerConditions
as
$condition
)
{
TriggerParam
::
deleteAll
([
'condition_id'
=>
$condition
->
getPrimaryKey
()]);
TriggerCondition
::
deleteAll
([
'id'
=>
$condition
->
getPrimaryKey
()]);
}
}
// Сбросили ключи
$this
->
conditions
=
array_values
(
$this
->
conditions
);
// Перебираем условия в цикле
foreach
(
$this
->
conditions
as
$group_index
=>
$condition_array
)
{
foreach
(
$condition_array
as
$condition
)
{
$conditionModel
=
new
TriggerCondition
();
$conditionModel
->
group_number
=
$group_index
;
$conditionModel
->
trigger_id
=
$this
->
id
;
$conditionModel
->
condition_id
=
$condition
[
'id'
];
if
(
$conditionModel
->
save
())
{
if
(
array_key_exists
(
'params'
,
$condition
))
{
foreach
(
$condition
[
'params'
]
as
$key
=>
$param
)
{
$paramModel
=
new
TriggerParam
();
$paramModel
->
condition_id
=
$conditionModel
->
getPrimaryKey
();
$paramModel
->
key
=
$key
;
$paramModel
->
value
=
$param
;
if
(
!
$paramModel
->
save
())
echo
current
(
current
(
$paramModel
->
getErrors
()));
}
}
}
}
}
}
public
function
getConditionTable
(){
// Формируем html будущей таблицы, открыли тег
$table
=
'<table class="table table-bordered">'
;
// Формируем тело будущей таблицы
$table
.=
'<tbody>'
;
// Если есть ошибка
if
(
$this
->
getErrors
(
'conditions'
))
{
$error
=
$this
->
getErrors
(
'conditions'
);
$table
.=
'<tr><td style="color: red;">'
.
$error
[
0
]
.
'</td></tr>'
;
}
// Тут добавляем кнопки управления
if
(
count
(
$this
->
conditions
)
>
0
)
{
foreach
(
$this
->
conditions
as
$condition_array
)
{
$table
.=
self
::
getControlButtons
(
$condition_array
);
}
}
else
$table
.=
self
::
getControlButtons
();
$table
.=
'</tbody>'
;
// Формируем футер
$table
.=
'<tfoot>'
;
$table
.=
'<td><button type="button" class="btn btn-primary add-and-condition">Добавить условие "И"</button></td>'
;
$table
.=
'</tfoot>'
;
// Закрываем таблицу
$table
.=
'</table>'
;
return
$table
;
}
/**
* @inheritdoc
*/
...
...
@@ -106,4 +181,11 @@ class TriggerTrigger extends \common\components\ActiveRecordModel
{
return
$this
->
hasOne
(
User
::
className
(),
[
'id'
=>
'owner_id'
]);
}
public
function
scenarios
(){
return
[
'default'
=>
[
'active'
,
'name'
,
'description'
,
'owner_id'
,
'date_create'
,
'timeout'
,
'message_template_id'
,
'conditions'
],
'update'
=>
[
'active'
,
'name'
,
'description'
,
'owner_id'
,
'date_create'
,
'timeout'
,
'message_template_id'
,
'conditions'
],
];
}
}
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