/** * @PreSave */ public function preSave(EntityEvent $event) { if (!$this->id) { $this->setPriority($event->getConnection()->fetchColumn('SELECT MAX(priority) + 1 FROM @system_role')); } }
/** * Delete all orphaned user role relations. * * @PostDelete */ public function postDelete(EntityEvent $event) { $event->getConnection()->delete('@system_user_role', ['user_id' => $this->getId()]); }
/** * @PreSave */ public function preSave(EntityEvent $event) { if (!$this->id) { $this->setPriority($event->getConnection()->fetchColumn('SELECT MAX(priority) + 1 FROM @system_menu_item WHERE menu_id=? AND DEPTH=0', [$this->getMenuId()]) ?: 0); } }
/** * @PreDelete */ public function preDelete(EntityEvent $event) { $event->getConnection()->delete('@blog_comment', ['post_id' => $this->getId()]); }