Example #1
0
 /**
  * Adds a user to the group. This function will skip if the user is already
  * a member of the group.
  * @param User $user user id or user model
  * @param type $isManager
  */
 public function addUser($user, $isManager = false)
 {
     if ($this->isMember($user)) {
         return;
     }
     $userId = $user instanceof User ? $user->id : $user;
     $newGroupUser = new GroupUser();
     $newGroupUser->user_id = $userId;
     $newGroupUser->group_id = $this->id;
     $newGroupUser->created_at = new \yii\db\Expression('NOW()');
     $newGroupUser->created_by = Yii::$app->user->id;
     $newGroupUser->is_group_manager = $isManager;
     $newGroupUser->save();
 }