/** @relation-command */ public function addOwnerUser($userID) { $relation = new UserMemberGroup(); $relation->user_id = $userID; $relation->group_id = $this->id; $relation->joinded_datetime = DateTimeHelper::now(); $relation->is_leader = 1; // remember to use 1 for boolean, using true will not make this record saving $relation->is_approved = 1; $relation->save(); }
public function actionJoinGroup() { if (!isset($_POST['id'])) { throw new CHttpException(404, 'The requested page does not exist.'); } $groupIdToJoin = $_POST['id']; $model = $this->loadModel($groupIdToJoin); if ($model->isUserJoined(Yii::app()->user->id)) { /** unexpected that user can call this action if it is either joined or pending*/ throw new CHttpException(404, 'The requested page does not exist.'); } $relation = new UserMemberGroup(); $relation->user_id = Yii::app()->user->id; $relation->group_id = $model->id; $relation->joinded_datetime = DateTimeHelper::now(); $relation->is_leader = 0; // remember to use 1 for boolean, using true will not make this record saving $relation->is_approved = $model->isAutoApprove(); if ($relation->save()) { $this->redirect(Yii::app()->request->urlReferrer); } }