/** * Form Validator which checks the invite field * * @param type $attribute * @param type $params */ public function checkInvite($attribute, $params) { // Check if email field is not empty if ($this->{$attribute} != "") { $invites = explode(",", $this->{$attribute}); foreach ($invites as $userGuid) { $userGuid = preg_replace("/[^A-Za-z0-9\\-]/", '', $userGuid); if ($userGuid == "") { continue; } // Try load user $user = User::findOne(['guid' => $userGuid]); if ($user != null) { $membership = Membership::findOne(['space_id' => $this->space->id, 'user_id' => $user->id]); if ($membership != null && $membership->status == Membership::STATUS_MEMBER) { $this->addError($attribute, Yii::t('SpaceModule.forms_SpaceInviteForm', "User '{username}' is already a member of this space!", ['username' => $user->getDisplayName()])); continue; } else { if ($membership != null && $membership->status == Membership::STATUS_APPLICANT) { $this->addError($attribute, Yii::t('SpaceModule.forms_SpaceInviteForm', "User '{username}' is already an applicant of this space!", ['username' => $user->getDisplayName()])); continue; } } $this->invites[] = $user; } else { $this->addError($attribute, Yii::t('SpaceModule.forms_SpaceInviteForm', "User not found!")); continue; } } } }
/** * Members Administration Action */ public function actionMembers() { $membersPerPage = 20; $space = $this->getSpace(); // User Role Management if (isset($_POST['users'])) { $users = Yii::$app->request->post('users'); // Loop over all users in Form foreach ($users as $userGuid) { // Get informations if (isset($_POST['user_' . $userGuid])) { $userSettings = Yii::$app->request->post('user_' . $userGuid); $user = User::findOne(['guid' => $userGuid]); if ($user != null) { // No changes on the Owner if ($space->isSpaceOwner($user->id)) { continue; } $membership = \humhub\modules\space\models\Membership::findOne(['user_id' => $user->id, 'space_id' => $space->id]); if ($membership != null) { $membership->invite_role = isset($userSettings['inviteRole']) && $userSettings['inviteRole'] == 1 ? 1 : 0; $membership->admin_role = isset($userSettings['adminRole']) && $userSettings['adminRole'] == 1 ? 1 : 0; $membership->share_role = isset($userSettings['shareRole']) && $userSettings['shareRole'] == 1 ? 1 : 0; $membership->save(); } } } } // Change owner if changed if ($space->isSpaceOwner()) { $owner = $space->getSpaceOwner(); $newOwnerId = Yii::$app->request->post('ownerId'); if ($newOwnerId != $owner->id) { if ($space->isMember($newOwnerId)) { $space->setSpaceOwner($newOwnerId); // Redirect to current space return $this->redirect($space->createUrl('admin/members')); } } } Yii::$app->getSession()->setFlash('data-saved', Yii::t('SpaceModule.controllers_AdminController', 'Saved')); } // Updated Users $query = $space->getMemberships(); #$query = Membership::find(); // Allow User Searches $search = Yii::$app->request->post('search'); if ($search != "") { $query->joinWith('user'); $query->andWhere('user.username LIKE :search OR user.email LIKE :search', [':search' => '%' . $search . '%']); } $countQuery = clone $query; $pagination = new \yii\data\Pagination(['totalCount' => $countQuery->count(), 'pageSize' => $membersPerPage]); $query->offset($pagination->offset)->limit($pagination->limit); $invitedMembers = Membership::findAll(['space_id' => $space->id, 'status' => Membership::STATUS_INVITED]); $members = $query->all(); return $this->render('members', array('space' => $space, 'pagination' => $pagination, 'members' => $members, 'invited_members' => $invitedMembers, 'search' => $search)); }
/** * Members Administration Action */ public function actionIndex() { $space = $this->getSpace(); $searchModel = new MembershipSearch(); $searchModel->space_id = $space->id; $searchModel->status = Membership::STATUS_MEMBER; $dataProvider = $searchModel->search(Yii::$app->request->queryParams); // User Group Change if (Yii::$app->request->post('dropDownColumnSubmit')) { Yii::$app->response->format = 'json'; $membership = Membership::findOne(['space_id' => $space->id, 'user_id' => Yii::$app->request->post('user_id')]); if ($membership === null) { throw new \yii\web\HttpException(404, 'Could not find membership!'); } if ($membership->load(Yii::$app->request->post()) && $membership->validate() && $membership->save()) { return Yii::$app->request->post(); } return $membership->getErrors(); } return $this->render('index', array('dataProvider' => $dataProvider, 'searchModel' => $searchModel, 'space' => $space)); }
/** * Returns the SpaceMembership Record for this Space * * If none Record is found, null is given */ public function getMembership($userId = "") { if ($userId == "") { $userId = Yii::$app->user->id; } return Membership::findOne(['user_id' => $userId, 'space_id' => $this->owner->id]); }