/** * @param User $user */ protected function postCreate(User $user) { $userGroup = GroupQuery::create()->filterByIsDefault(true)->findOne(); if ($userGroup) { $user->addGroup($userGroup); $user->save(); } }
/** * Interal mechanism to add Groups to User * * @param User $model * @param mixed $data */ protected function doAddGroups(User $model, $data) { $errors = []; foreach ($data as $entry) { if (!isset($entry['id'])) { $errors[] = 'Missing id for Group'; } else { $related = GroupQuery::create()->findOneById($entry['id']); $model->addGroup($related); } } if (count($errors) > 0) { return new ErrorsException($errors); } }