/** * action without php in views * Update, Delete from gorups or groupmember * * @return ['myGroups'=>ActiveRecord, 'pagenation'=>Pagination] */ public function actionUserAction() { $request = Yii::$app->request; $groupinfo = $request->post(); if ($groupinfo == null) { return $this->render('error', ['name' => 'error', 'message' => 'Request is not operated...']); } $thisuser = $this->getUser()->username; $action = $groupinfo['action']; $groupname = str_replace('`', ' ', $groupinfo['groupname']); switch ($action) { case 'delete': $group = Groups::deleteAll(["l_user" => $thisuser, "groupname" => $groupname]); return $this->goHome(); case 'leave': $l_user = $groupinfo['l_user']; $group = Groups::findOne([["l_user" => $l_user, "groupname" => $groupname]]); if (count($group) != 0 && $group->status != 'c') { $grp_mem = Groupmembers::deleteAll(["l_user" => $groupinfo['l_user'], "groupname" => $groupname, "m_user" => $thisuser]); return $this->goHome(); } return $this->render('error', ['name' => 'error', 'message' => "Unable to leave {$groupname} created by {$l_user}. Checking the status of this group"]); case 'close': $group = Groups::findOne(["l_user" => $thisuser, "groupname" => $groupname]); $group->status = 'c'; $group->update(); return $this->goHome(); case 'join': //check existence of the group $l_user = $groupinfo['l_user']; $group = Groups::findOne([["l_user" => $l_user, "groupname" => $groupname]]); if (count($group) != 0) { $grp_mem = new Groupmembers(); $grp_mem->l_user = $l_user; $grp_mem->groupname = $groupname; $grp_mem->m_user = $thisuser; if ($grp_mem->save()) { return $this->goHome(); } return $this->render('error', ['name' => 'error', 'message' => "Unable to join {$groupname} created by {$l_user}"]); } return $this->render('error', ['name' => 'error', 'message' => "Unable to join {$groupname} created by {$l_user}"]); //return $this->goHome(); //return $this->goHome(); default: return $this->render('error', ['name' => 'error', 'message' => "No Action"]); } }