/
v.bolshakov
/
AIEcosystem-Testing
Обзор
Документация
Войти
/
v.bolshakov
/
AIEcosystem-Testing
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
CI/CD
Аналитика
Безопасность
dev
common/forms/base/ObjectIdForm.php
93 строки
2 KB
Developer
Initial commit
03 авг 2026, 17:43
03 авг 2026, 17:43
7433917
Код
Авторство
О чём код?
<?php namespace common\forms\base; use yii\helpers\ArrayHelper; /** * Базовая форма поиска объекта * * @author Dmitry E. Semenov <sde.tomsk@gmail.com> * @copyright Self (c) 2020 */ abstract class ObjectIdForm extends BaseModel { /** * id * @var integer */ public $oid = null; /** * @inheritdoc */ public function rules() { return [ [['oid'], 'string'], ]; } /** * @inheritdoc */ public function getPublicFields() { return [ 'oid', ]; } /** * Проверить доступ пользователя к редактированию данных * @return bool */ public function check() { return true; } /** * @inheritdoc */ public function loadModel($condition) { parent::loadModel($condition); foreach (['id', 'oid'] as $key) { $id = ArrayHelper::getValue($condition, $key); if ($id) { $this->oid = $id; break; } } if ($this->oid && !$this->check()) { $this->oid = null; $this->addError('oid', 'Нет доступа к редактированию данных'); } } /** * @inheritdoc */ public function beforeSave() { if ($this->oid && !$this->check()) { $this->addError('oid', 'Нет доступа к редактированию данных'); return false; } return parent::beforeSave(); } /** * @inheritdoc */ protected function doDelete() { $this->model->delete(true); return true; } }