Commit 07e57c23 authored by Shakarim Sapa's avatar Shakarim Sapa

- Добавлено сохранение условий и его параметров через модель (afterSave);

- Добавлен метод возвращающий таблицу управления моделью;
parent 2a4c1d9f
......@@ -32,6 +32,56 @@ class TriggerTrigger extends \common\components\ActiveRecordModel
return 'Триггеры';
}
public function afterSave($insert,$changedAttributes){
parent::afterSave($insert,$changedAttributes);
// Сбросили ключи
$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->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->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>';
return $table;
}
/**
* @inheritdoc
*/
......
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