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
39238dc2
Commit
39238dc2
authored
Feb 03, 2016
by
Shakarim Sapa
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
- Вынесена логика формирования таблицы с условиями в модель;
- Добавлены действия ПОСЛЕ сохранения модели;
parent
663225ff
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
44 additions
and
7 deletions
+44
-7
common/modules/triggers/models/TriggerTrigger.php
common/modules/triggers/models/TriggerTrigger.php
+44
-7
No files found.
common/modules/triggers/models/TriggerTrigger.php
View file @
39238dc2
...
...
@@ -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,17 +33,36 @@ 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
)
{
$conditionModel
=
new
TriggerCondition
();
$conditionModel
->
group_number
=
$group_index
;
$conditionModel
->
trigger_id
=
$this
->
id
;
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
))
{
...
...
@@ -66,12 +86,17 @@ class TriggerTrigger extends \common\components\ActiveRecordModel
// Формируем тело будущей таблицы
$table
.=
'<tbody>'
;
// Если есть ошибка
if
(
$this
->
model
->
getErrors
(
'conditions'
))
{
$error
=
$this
->
model
->
getErrors
(
'conditions'
);
if
(
$this
->
getErrors
(
'conditions'
))
{
$error
=
$this
->
getErrors
(
'conditions'
);
$table
.=
'<tr><td style="color: red;">'
.
$error
[
0
]
.
'</td></tr>'
;
}
// Тут добавляем кнопки управления по умолчанию
$table
.=
Yii
::
$app
->
controller
->
actionGetandconditionhtml
();
// Тут добавляем кнопки управления
if
(
count
(
$this
->
conditions
)
>
0
)
{
foreach
(
$this
->
conditions
as
$condition_array
)
{
$table
.=
self
::
getControlButtons
(
$condition_array
);
}
}
else
$table
.=
self
::
getControlButtons
();
$table
.=
'</tbody>'
;
// Формируем футер
$table
.=
'<tfoot>'
;
...
...
@@ -82,6 +107,11 @@ class TriggerTrigger extends \common\components\ActiveRecordModel
return
$table
;
}
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>'
;
}
/**
* @inheritdoc
*/
...
...
@@ -156,4 +186,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