| Total Complexity | 3 |
| Total Lines | 21 |
| Duplicated Lines | 0 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 0 |
| 1 | <?php |
||
| 9 | |||
| 10 | class ArticleCategoryBehavior extends Behavior |
||
| 11 | { |
||
| 12 | public function events() |
||
| 13 | { |
||
| 14 | return [ |
||
| 15 | ArticleCategory::EVENT_BEFORE_DELETE => 'beforeDelete', |
||
| 16 | ]; |
||
| 17 | } |
||
| 18 | |||
| 19 | public function beforeDelete(Event $event) |
||
| 20 | { |
||
| 21 | /** @var ArticleCategory $model */ |
||
| 22 | $model = $event->sender; |
||
| 23 | $count = Article::find() |
||
| 24 | ->where([ |
||
| 25 | 'category_id' => $model->id, |
||
| 26 | 'is_deleted' => 0, |
||
| 27 | ]) |
||
| 28 | ->count(); |
||
| 29 | if ($count > 0) { |
||
| 30 | throw new ForbiddenHttpException()('Unable to delete category since there are articles belong to it'); |
||
| 34 |