/** * @inheritdoc */ public function run() { if (!$this->height) { $this->height = $this->width; } if (!isset($this->linkOptions['href'])) { $this->linkOptions['href'] = $this->space->getUrl(); } if ($this->space->color != null) { $color = Html::encode($this->space->color); } else { $color = '#d7d7d7'; } if (!isset($this->htmlOptions['class'])) { $this->htmlOptions['class'] = ""; } if (!isset($this->htmlOptions['style'])) { $this->htmlOptions['style'] = ""; } $acronymHtmlOptions = $this->htmlOptions; $imageHtmlOptions = $this->htmlOptions; $acronymHtmlOptions['class'] .= " space-profile-acronym-" . $this->space->id . " space-acronym"; $acronymHtmlOptions['style'] .= " background-color: " . $color . "; width: " . $this->width . "px; height: " . $this->height . "px;"; $acronymHtmlOptions['style'] .= " " . $this->getDynamicStyles($this->width); $imageHtmlOptions['class'] .= " space-profile-image-" . $this->space->id . " img-rounded profile-user-photo"; $imageHtmlOptions['style'] .= " width: " . $this->width . "px; height: " . $this->height . "px"; $imageHtmlOptions['alt'] = Html::encode($this->space->name); $defaultImage = basename($this->space->getProfileImage()->getUrl()) == 'default_space.jpg' || basename($this->space->getProfileImage()->getUrl()) == 'default_space.jpg?cacheId=0' ? true : false; if (!$defaultImage) { $acronymHtmlOptions['class'] .= " hidden"; } else { $imageHtmlOptions['class'] .= " hidden"; } return $this->render('image', ['space' => $this->space, 'acronym' => $this->getAcronym(), 'link' => $this->link, 'linkOptions' => $this->linkOptions, 'acronymHtmlOptions' => $acronymHtmlOptions, 'imageHtmlOptions' => $imageHtmlOptions]); }
public function init() { $this->addItem(array('label' => Yii::t('AdminModule.manage', 'Basic'), 'url' => $this->space->createUrl('/space/manage/default/index'), 'sortOrder' => 100, 'isActive' => Yii::$app->controller->id == 'default' && Yii::$app->controller->action->id == 'index')); $this->addItem(array('label' => Yii::t('AdminModule.manage', 'Security'), 'url' => $this->space->createUrl('/space/manage/default/security'), 'sortOrder' => 200, 'isActive' => Yii::$app->controller->id == 'default' && Yii::$app->controller->action->id == 'security')); $this->addItem(array('label' => Yii::t('AdminModule.manage', 'Delete'), 'url' => $this->space->createUrl('/space/manage/default/delete'), 'sortOrder' => 500, 'isActive' => Yii::$app->controller->id == 'default' && Yii::$app->controller->action->id == 'delete')); parent::init(); }
/** * @inheritdoc */ public function run() { $memberQuery = $this->space->getMemberships(); $memberQuery->joinWith('user'); $memberQuery->limit($this->maxMembers); $memberQuery->where(['user.status' => \humhub\modules\user\models\User::STATUS_ENABLED]); return $this->render('members', ['space' => $this->space, 'maxMembers' => $this->maxMembers, 'members' => $memberQuery->all()]); }
public function init() { if ($this->space === null && Yii::$app->controller instanceof ContentContainerController && Yii::$app->controller->contentContainer instanceof Space) { $this->space = Yii::$app->controller->contentContainer; } if ($this->space === null) { throw new \yii\base\Exception("Could not instance space menu without space!"); } $this->addItemGroup(array('id' => 'modules', 'label' => Yii::t('SpaceModule.widgets_SpaceMenuWidget', '<strong>Space</strong> menu'), 'sortOrder' => 100)); $this->addItem(array('label' => Yii::t('SpaceModule.widgets_SpaceMenuWidget', 'Stream'), 'group' => 'modules', 'url' => $this->space->createUrl('/space/space/home'), 'icon' => '<i class="fa fa-bars"></i>', 'sortOrder' => 100, 'isActive' => Yii::$app->controller->id == "space" && (Yii::$app->controller->action->id == "index" || Yii::$app->controller->action->id == 'home') && Yii::$app->controller->module->id == "space")); parent::init(); }
/** * @inheritdoc */ public function run() { // Only visible for admins if (!$this->space->isAdmin()) { return; } $applicants = $this->space->getApplicants()->limit($this->maxApplicants)->all(); // No applicants if (count($applicants) === 0) { return; } return $this->render('pendingApprovals', ['applicants' => $applicants, 'space' => $this->space]); }
/** * Creates a new Space */ public function actionCreate() { if (!Yii::$app->user->getIdentity()->canCreateSpace()) { throw new HttpException(400, 'You are not allowed to create spaces!'); } $model = new Space(); $model->scenario = 'create'; $model->visibility = Setting::Get('defaultVisibility', 'space'); $model->join_policy = Setting::Get('defaultJoinPolicy', 'space'); if ($model->load(Yii::$app->request->post()) && $model->validate() && $model->save()) { Yii::$app->getSession()->setFlash('ws', 'created'); return $this->htmlRedirect($model->getUrl()); } return $this->renderAjax('create', array('model' => $model)); }
/** * Callback to validate module database records. * * @param Event $event */ public static function onIntegrityCheck($event) { $integrityController = $event->sender; $integrityController->showTestHeadline("Space Module - Spaces (" . Space::find()->count() . " entries)"); foreach (Space::find()->all() as $space) { foreach ($space->applicants as $applicant) { if ($applicant->user == null) { if ($integrityController->showFix("Deleting applicant record id " . $applicant->id . " without existing user!")) { $applicant->delete(); } } } } $integrityController->showTestHeadline("Space Module - Module (" . models\Module::find()->count() . " entries)"); foreach (models\Module::find()->joinWith('space')->all() as $module) { if ($module->space == null) { if ($integrityController->showFix("Deleting space module" . $module->id . " without existing space!")) { $module->delete(); } } } $integrityController->showTestHeadline("Space Module - Memberships (" . models\Membership::find()->count() . " entries)"); foreach (models\Membership::find()->joinWith('space')->all() as $membership) { if ($membership->space == null) { if ($integrityController->showFix("Deleting space membership" . $membership->space_id . " without existing space!")) { $membership->delete(); } } if ($membership->user == null) { if ($integrityController->showFix("Deleting space membership" . $membership->user_id . " without existing user!")) { $membership->delete(); } } } }
public function up() { $spaces = Space::find()->all(); $users = User::find()->all(); $containers = array_merge($users == null ? [] : $users, $spaces == null ? [] : $spaces); foreach ($containers as $container) { $created_by = $container instanceof User ? $container->id : $container instanceof Space ? $container->created_by : 1; $created_by = $created_by == null ? 1 : $created_by; if ($container->isModuleEnabled('cfiles')) { $this->insert('cfiles_folder', ['title' => Module::ROOT_TITLE, 'description' => Module::ROOT_DESCRIPTION, 'parent_folder_id' => 0, 'has_wall_entry' => false, 'type' => Folder::TYPE_FOLDER_ROOT]); $root_id = Yii::$app->db->getLastInsertID(); $this->insert('content', ['guid' => \humhub\libs\UUID::v4(), 'object_model' => Folder::className(), 'object_id' => $root_id, 'visibility' => 0, 'sticked' => 0, 'archived' => 0, 'created_at' => new \yii\db\Expression('NOW()'), 'created_by' => $created_by, 'updated_at' => new \yii\db\Expression('NOW()'), 'updated_by' => $created_by, 'contentcontainer_id' => $container->contentcontainer_id]); $this->insert('cfiles_folder', ['title' => Module::ALL_POSTED_FILES_TITLE, 'description' => Module::ALL_POSTED_FILES_DESCRIPTION, 'parent_folder_id' => $root_id, 'has_wall_entry' => false, 'type' => Folder::TYPE_FOLDER_POSTED]); $allpostedfiles_id = Yii::$app->db->getLastInsertID(); $this->insert('content', ['guid' => \humhub\libs\UUID::v4(), 'object_model' => Folder::className(), 'object_id' => $allpostedfiles_id, 'visibility' => 0, 'sticked' => 0, 'archived' => 0, 'created_at' => new \yii\db\Expression('NOW()'), 'created_by' => $created_by, 'updated_at' => new \yii\db\Expression('NOW()'), 'updated_by' => $created_by, 'contentcontainer_id' => $container->contentcontainer_id]); $posted_content_id = Yii::$app->db->getLastInsertID(); $filesQuery = File::find()->joinWith('baseFile')->contentContainer($container); $foldersQuery = Folder::find()->contentContainer($container); $filesQuery->andWhere(['cfiles_file.parent_folder_id' => 0]); // user maintained folders $foldersQuery->andWhere(['cfiles_folder.parent_folder_id' => 0]); // do not return any folders here that are root or allpostedfiles $foldersQuery->andWhere(['cfiles_folder.type' => null]); $rootsubfiles = $filesQuery->all(); $rootsubfolders = $foldersQuery->all(); foreach ($rootsubfiles as $file) { $this->update('cfiles_file', ['cfiles_file.parent_folder_id' => $root_id], ['id' => $file->id]); } foreach ($rootsubfolders as $folder) { $this->update('cfiles_folder', ['parent_folder_id' => $root_id], ['id' => $folder->id]); } } } }
/** * Executes the widgets */ public function run() { $statsCountSpaces = Space::find()->count(); $statsCountSpacesHidden = Space::find()->where(['visibility' => Space::VISIBILITY_NONE])->count(); $statsSpaceMostMembers = Space::find()->where('id = (SELECT space_id FROM space_membership GROUP BY space_id ORDER BY count(*) DESC LIMIT 1)')->one(); // Render widgets view return $this->render('spaceStats', array('statsSpaceMostMembers' => $statsSpaceMostMembers, 'statsCountSpaces' => $statsCountSpaces, 'statsCountSpacesHidden' => $statsCountSpacesHidden)); }
/** * @inheritdoc */ public function init() { parent::init(); $friendshipEnabled = Yii::$app->getModule('friendship')->getIsEnabled(); if ($this->user == null) { /** * For guests collect all wall_ids of "guest" public spaces / user profiles. * Generally show only public content */ $publicSpacesSql = (new \yii\db\Query())->select(["si.wall_id"])->from('space si')->where('si.visibility=' . \humhub\modules\space\models\Space::VISIBILITY_ALL); $union = Yii::$app->db->getQueryBuilder()->build($publicSpacesSql)[0]; $publicProfilesSql = (new \yii\db\Query())->select("pi.wall_id")->from('user pi')->where('pi.status=1 AND pi.visibility = ' . \humhub\modules\user\models\User::VISIBILITY_ALL); $union .= " UNION " . Yii::$app->db->getQueryBuilder()->build($publicProfilesSql)[0]; $this->activeQuery->andWhere('wall_entry.wall_id IN (' . $union . ')'); $this->activeQuery->andWhere(['content.visibility' => \humhub\modules\content\models\Content::VISIBILITY_PUBLIC]); } else { /** * Collect all wall_ids we need to include into dashboard stream */ // User to user follows $userFollow = (new \yii\db\Query())->select(["uf.wall_id"])->from('user_follow')->leftJoin('user uf', 'uf.id=user_follow.object_id AND user_follow.object_model=:userClass')->where('user_follow.user_id=' . $this->user->id . ' AND uf.wall_id IS NOT NULL'); $union = Yii::$app->db->getQueryBuilder()->build($userFollow)[0]; // User to space follows $spaceFollow = (new \yii\db\Query())->select("sf.wall_id")->from('user_follow')->leftJoin('space sf', 'sf.id=user_follow.object_id AND user_follow.object_model=:spaceClass')->where('user_follow.user_id=' . $this->user->id . ' AND sf.wall_id IS NOT NULL'); $union .= " UNION " . Yii::$app->db->getQueryBuilder()->build($spaceFollow)[0]; // User to space memberships $spaceMemberships = (new \yii\db\Query())->select("sm.wall_id")->from('space_membership')->leftJoin('space sm', 'sm.id=space_membership.space_id')->where('space_membership.user_id=' . $this->user->id . ' AND sm.wall_id IS NOT NULL AND space_membership.show_at_dashboard = 1'); $union .= " UNION " . Yii::$app->db->getQueryBuilder()->build($spaceMemberships)[0]; if ($friendshipEnabled) { // User to user follows $usersFriends = (new \yii\db\Query())->select(["ufr.wall_id"])->from('user ufr')->leftJoin('user_friendship recv', 'ufr.id=recv.friend_user_id AND recv.user_id=' . (int) $this->user->id)->leftJoin('user_friendship snd', 'ufr.id=snd.user_id AND snd.friend_user_id=' . (int) $this->user->id)->where('recv.id IS NOT NULL AND snd.id IS NOT NULL AND ufr.wall_id IS NOT NULL'); $union .= " UNION " . Yii::$app->db->getQueryBuilder()->build($usersFriends)[0]; } // Glue together also with current users wall $wallIdsSql = (new \yii\db\Query())->select('wall_id')->from('user uw')->where('uw.id=' . $this->user->id); $union .= " UNION " . Yii::$app->db->getQueryBuilder()->build($wallIdsSql)[0]; // Manual Union (https://github.com/yiisoft/yii2/issues/7992) // Double union query - to avoid MySQL performance problems $this->activeQuery->andWhere('wall_entry.wall_id IN (select subselect.wall_id from (' . $union . ') subselect)', [':spaceClass' => \humhub\modules\space\models\Space::className(), ':userClass' => \humhub\modules\user\models\User::className()]); /** * Begin visibility checks regarding the content container */ $this->activeQuery->leftJoin('wall', 'wall_entry.wall_id=wall.id'); $this->activeQuery->leftJoin('space_membership', 'wall.object_id=space_membership.space_id AND space_membership.user_id=:userId AND space_membership.status=:status', ['userId' => $this->user->id, ':status' => \humhub\modules\space\models\Membership::STATUS_MEMBER]); if ($friendshipEnabled) { $this->activeQuery->leftJoin('user_friendship', 'wall.object_id=user_friendship.user_id AND user_friendship.friend_user_id=:userId', ['userId' => $this->user->id]); } $condition = ' (wall.object_model=:userModel AND content.visibility=0 AND content.created_by = :userId) OR '; if ($friendshipEnabled) { // In case of friendship we can also display private content $condition .= ' (wall.object_model=:userModel AND content.visibility=0 AND user_friendship.id IS NOT NULL) OR '; } // In case of an space entry, we need to join the space membership to verify the user can see private space content $condition .= ' (wall.object_model=:spaceModel AND content.visibility = 0 AND space_membership.status = ' . \humhub\modules\space\models\Membership::STATUS_MEMBER . ') OR '; $condition .= ' (content.visibility = 1 OR content.visibility IS NULL) '; $this->activeQuery->andWhere($condition, [':userId' => $this->user->id, ':spaceModel' => \humhub\modules\space\models\Space::className(), ':userModel' => \humhub\modules\user\models\User::className()]); } }
/** * Gets a space setting * * @see \humhub\modules\content\components\ContentContainerSettingsManager::get * @param int $spaceId * @param string $name * @param string $moduleId * @param string $defaultValue * @return string */ public static function Get($space, $name, $moduleId = "", $defaultValue = "") { $user = Space::findOne(['id' => $space]); $value = self::getModule($moduleId)->settings->contentContainer($user)->get($name); if ($value === null) { return $defaultValue; } return $value; }
/** * @inheritdoc */ public function afterSave($insert, $changedAttributes) { if ($this->indexUrl != null) { Yii::$app->getModule('space')->settings->contentContainer($this)->set('indexUrl', $this->indexUrl); } else { //Remove entry from db Yii::$app->getModule('space')->settings->contentContainer($this)->delete('indexUrl'); } return parent::afterSave($insert, $changedAttributes); }
/** * Registers a user * @param $data * @return Bool */ private function registerUser($data) { $userModel = new User(); $userModel->scenario = 'registration'; $profileModel = $userModel->profile; $profileModel->scenario = 'registration'; // User: Set values $userModel->username = $data['username']; $userModel->email = $data['email']; $userModel->group_id = $data['group_id']; $userModel->status = User::STATUS_ENABLED; // Profile: Set values $profileModel->firstname = $data['firstname']; $profileModel->lastname = $data['lastname']; // Password: Set values $userPasswordModel = new Password(); $userPasswordModel->setPassword($data['password']); if ($userModel->save()) { // Save user profile $profileModel->user_id = $userModel->id; $profileModel->save(); // Save user password $userPasswordModel->user_id = $userModel->id; $userPasswordModel->save(); // Join space / create then join space foreach ($data['space_names'] as $key => $space_name) { // Find space by name attribute $space = Space::findOne(['name' => $space_name]); // Create the space if not found if ($space == null) { $space = new Space(); $space->name = $space_name; $space->save(); } // Add member into space $space->addMember($userModel->id); } return true; } else { Yii::$app->session->setFlash('error', Html::errorSummary($userModel)); return false; } }
/** * @inheritdoc */ public function run() { $friendshipsEnabled = Yii::$app->getModule('friendship')->getIsEnabled(); $countFriends = 0; if ($friendshipsEnabled) { $countFriends = Friendship::getFriendsQuery($this->user)->count(); } $countFollowing = $this->user->getFollowingCount(User::className()) + $this->user->getFollowingCount(Space::className()); $countUserSpaces = Membership::getUserSpaceQuery($this->user)->andWhere(['!=', 'space.visibility', Space::VISIBILITY_NONE])->andWhere(['space.status' => Space::STATUS_ENABLED])->count(); return $this->render('profileHeader', array('user' => $this->user, 'isProfileOwner' => $this->isProfileOwner, 'friendshipsEnabled' => $friendshipsEnabled, 'countFriends' => $countFriends, 'countFollowers' => $this->user->getFollowerCount(), 'countFollowing' => $countFollowing, 'countSpaces' => $countUserSpaces)); }
/** * Gets space url name by given guid * * @param string $guid * @return string|null the space url part */ public static function getUrlBySpaceGuid($guid) { if (isset(static::$spaceUrlMap[$guid])) { return static::$spaceUrlMap[$guid]; } $space = Space::findOne(['guid' => $guid]); if ($space !== null) { static::$spaceUrlMap[$space->guid] = $space->url != '' ? $space->url : $space->guid; return static::$spaceUrlMap[$space->guid]; } return null; }
public function testGetFollowers() { Yii::$app->user->switchIdentity(User::findOne(['id' => 1])); $space = Space::findOne(['id' => 3]); $space->follow(1); $space->follow(2); $space->follow(3); $users = $space->getFollowers(); $userIds = array_map(create_function('$user', 'return $user->id;'), $users); sort($userIds); $this->assertEquals(array(1, 2, 3), $userIds); }
/** * Space Section of directory * * Provides a list of all visible spaces. * * @todo Dont pass lucene hits to view, build user array inside of action */ public function actionSpaces() { $keyword = Yii::$app->request->get('keyword', ""); $page = (int) Yii::$app->request->get('page', 1); $searchResultSet = Yii::$app->search->find($keyword, ['model' => \humhub\modules\space\models\Space::className(), 'page' => $page, 'sortField' => $keyword == '' ? 'title' : null, 'pageSize' => Setting::Get('paginationSize')]); $pagination = new \yii\data\Pagination(['totalCount' => $searchResultSet->total, 'pageSize' => $searchResultSet->pageSize]); \yii\base\Event::on(Sidebar::className(), Sidebar::EVENT_INIT, function ($event) { $event->sender->addWidget(\humhub\modules\directory\widgets\NewSpaces::className(), [], ['sortOrder' => 10]); $event->sender->addWidget(\humhub\modules\directory\widgets\SpaceStatistics::className(), [], ['sortOrder' => 20]); }); return $this->render('spaces', array('keyword' => $keyword, 'spaces' => $searchResultSet->getResultInstances(), 'pagination' => $pagination)); }
/** * Tests spaces which automatically adds new members * Fixture Space 3 */ public function testAutoAddSpace() { $space2 = Space::findOne(['id' => 2]); $space3 = Space::findOne(['id' => 3]); $user = new User(); $user->username = "******"; $user->email = "*****@*****.**"; $this->assertTrue($user->save()); $this->assertFalse($space2->isMember($user->id)); // not assigned $this->assertTrue($space3->isMember($user->id)); // via global assign }
/** * Executes the widgets */ public function run() { $query = Space::find(); /** * Show private spaces only if user is member */ $query->leftJoin('space_membership', 'space.id=space_membership.space_id AND space_membership.user_id=:userId', [':userId' => \Yii::$app->user->id]); $query->andWhere(['!=', 'space.visibility', Space::VISIBILITY_NONE]); $query->orWhere(['space_membership.status' => Membership::STATUS_MEMBER]); $query->limit(10); $query->orderBy('created_at DESC'); return $this->render('newSpaces', array('newSpaces' => $query->all(), 'showMoreButton' => $this->showMoreButton)); }
public function init() { $this->addItem(array('label' => Yii::t('SpaceModule.widgets_SpaceMembersMenu', 'Members'), 'url' => $this->space->createUrl('/space/manage/member/index'), 'sortOrder' => 100, 'isActive' => Yii::$app->controller->action->id == 'index' && Yii::$app->controller->id === 'member')); $this->addItem(array('label' => Yii::t('SpaceModule.widgets_SpaceMembersMenu', 'Pending Invites'), 'url' => $this->space->createUrl('/space/manage/member/pending-invitations'), 'sortOrder' => 200, 'isActive' => Yii::$app->controller->action->id == 'pending-invitations')); $this->addItem(array('label' => Yii::t('SpaceModule.widgets_SpaceMembersMenu', 'Pending Approvals'), 'url' => $this->space->createUrl('/space/manage/member/pending-approvals'), 'sortOrder' => 300, 'isActive' => Yii::$app->controller->action->id == 'pending-approvals')); $this->addItem(array('label' => Yii::t('SpaceModule.widgets_SpaceMembersMenu', 'Permissions'), 'url' => $this->space->createUrl('/space/manage/member/permissions'), 'sortOrder' => 400, 'isActive' => Yii::$app->controller->action->id == 'permissions')); if ($this->space->isSpaceOwner()) { $this->addItem(array('label' => Yii::t('SpaceModule.widgets_SpaceMembersMenu', 'Owner'), 'url' => $this->space->createUrl('/space/manage/member/change-owner'), 'sortOrder' => 500, 'isActive' => Yii::$app->controller->action->id == 'change-owner')); } parent::init(); }
/** * Collects a list of all modules which are available for this space * * @return array */ public function getAvailableModules() { if ($this->_availableModules !== null) { return $this->_availableModules; } $this->_availableModules = array(); foreach (Yii::$app->moduleManager->getModules() as $moduleId => $module) { if ($module instanceof ContentContainerModule && Yii::$app->hasModule($module->id) && $module->hasContentContainerType(Space::className())) { $this->_availableModules[$module->id] = $module; } } return $this->_availableModules; }
/** * This validator function checks the defaultSpaceGuid. * * @param type $attribute * @param type $params */ public function checkSpaceGuid($attribute, $params) { if ($this->defaultSpaceGuid != "") { foreach (explode(',', $this->defaultSpaceGuid) as $spaceGuid) { if ($spaceGuid != "") { $space = \humhub\modules\space\models\Space::findOne(array('guid' => $spaceGuid)); if ($space == null) { $this->addError($attribute, Yii::t('AdminModule.forms_BasicSettingsForm', "Invalid space")); } } } } }
/** * Returns the current selected space by parameter guid * * If space doesnt exists or there a no permissions and exception * will thrown. * * @return Space * @throws HttpException */ public function getSpace() { if ($this->space != null) { return $this->space; } // Get Space GUID by parameter $guid = Yii::$app->request->get('sguid'); // Try Load the space $this->space = Space::findOne(['guid' => $guid]); if ($this->space == null) { throw new HttpException(404, Yii::t('SpaceModule.behaviors_SpaceControllerBehavior', 'Space not found!')); } $this->checkAccess(); return $this->space; }
public function actionDeleteContent() { $this->forcePostRequest(); $model = Yii::$app->request->get('model'); $id = Yii::$app->request->get('id'); $content = Content::get($model, $id); if ($content->content->canDelete()) { $content->delete(); } if (!$content->content->space_id) { return $this->htmlRedirect(Url::to(['/reportcontent/admin'])); } else { $space = Space::findOne(['id' => $content->content->space_id]); return $this->htmlRedirect($space->createUrl('/reportcontent/space-admin')); } }
/** * Creates data provider instance with search query applied * * @param array $params * * @return ActiveDataProvider */ public function search($params) { $query = Space::find(); $dataProvider = new ActiveDataProvider(['query' => $query, 'pagination' => ['pageSize' => 50]]); $dataProvider->setSort(['attributes' => ['id', 'name', 'visibility', 'join_policy']]); $this->load($params); if (!$this->validate()) { $query->where('0=1'); return $dataProvider; } $query->andFilterWhere(['id' => $this->id]); $query->andFilterWhere(['join_policy' => $this->join_policy]); $query->andFilterWhere(['visibility' => $this->visibility]); $query->andFilterWhere(['like', 'name', $this->name]); return $dataProvider; }
/** * Returns a List of Users */ public function actionBasic() { $form = new \humhub\modules\admin\models\forms\BasicSettingsForm(); $form->name = Setting::Get('name'); $form->baseUrl = Setting::Get('baseUrl'); $form->defaultLanguage = Setting::Get('defaultLanguage'); $form->timeZone = Setting::Get('timeZone'); $form->dashboardShowProfilePostForm = Setting::Get('showProfilePostForm', 'dashboard'); $form->tour = Setting::Get('enable', 'tour'); $form->share = Setting::Get('enable', 'share'); $form->defaultSpaceGuid = ""; foreach (\humhub\modules\space\models\Space::findAll(['auto_add_new_members' => 1]) as $defaultSpace) { $form->defaultSpaceGuid .= $defaultSpace->guid . ","; } if ($form->load(Yii::$app->request->post()) && $form->validate()) { Setting::Set('name', $form->name); Setting::Set('baseUrl', $form->baseUrl); Setting::Set('defaultLanguage', $form->defaultLanguage); Setting::Set('timeZone', $form->timeZone); Setting::Set('enable', $form->tour, 'tour'); Setting::Set('enable', $form->share, 'share'); Setting::Set('showProfilePostForm', $form->dashboardShowProfilePostForm, 'dashboard'); $spaceGuids = explode(",", $form->defaultSpaceGuid); // Remove Old Default Spaces foreach (\humhub\modules\space\models\Space::findAll(['auto_add_new_members' => 1]) as $space) { if (!in_array($space->guid, $spaceGuids)) { $space->auto_add_new_members = 0; $space->save(); } } // Add new Default Spaces foreach ($spaceGuids as $spaceGuid) { $space = \humhub\modules\space\models\Space::findOne(['guid' => $spaceGuid]); if ($space != null && $space->auto_add_new_members != 1) { $space->auto_add_new_members = 1; $space->save(); } } DynamicConfig::rewrite(); // set flash message Yii::$app->getSession()->setFlash('data-saved', Yii::t('AdminModule.controllers_SettingController', 'Saved')); return Yii::$app->response->redirect(Url::toRoute('/admin/setting/basic')); } return $this->render('basic', array('model' => $form)); }
public function up() { $this->renameClass('Activity', Activity::className()); // Space Created Activity - object_model/object_id (source fix) $activities = (new \yii\db\Query())->select("activity.*, content.space_id")->from('activity')->leftJoin('content', 'content.object_model=:activityModel AND content.object_id=activity.id', [':activityModel' => Activity::className()])->where(['class' => 'humhub\\modules\\space\\activities\\Created', 'activity.object_model' => ''])->all(); foreach ($activities as $activity) { $this->updateSilent('activity', ['object_model' => Space::className(), 'object_id' => $activity['space_id']], ['id' => $activity['id']]); } // Space Member added Activity - object_model/object_id (source fix) $activities = (new \yii\db\Query())->select("activity.*, content.space_id")->from('activity')->leftJoin('content', 'content.object_model=:activityModel AND content.object_id=activity.id', [':activityModel' => Activity::className()])->where(['class' => 'humhub\\modules\\space\\activities\\MemberAdded', 'activity.object_model' => ''])->all(); foreach ($activities as $activity) { $this->updateSilent('activity', ['object_model' => Space::className(), 'object_id' => $activity['space_id']], ['id' => $activity['id']]); } // Space Member removed Activity - object_model/object_id (source fix) $activities = (new \yii\db\Query())->select("activity.*, content.space_id")->from('activity')->leftJoin('content', 'content.object_model=:activityModel AND content.object_id=activity.id', [':activityModel' => Activity::className()])->where(['class' => 'humhub\\modules\\space\\activities\\MemberRemoved', 'activity.object_model' => ''])->all(); foreach ($activities as $activity) { $this->updateSilent('activity', ['object_model' => Space::className(), 'object_id' => $activity['space_id']], ['id' => $activity['id']]); } }
/** * @inheritdoc */ public function parseRequest($manager, $request) { $pathInfo = $request->getPathInfo(); if (substr($pathInfo, 0, 2) == "s/") { $parts = explode('/', $pathInfo, 3); if (isset($parts[1])) { $space = Space::find()->where(['guid' => $parts[1]])->one(); if ($space !== null) { if (!isset($parts[2]) || $parts[2] == "") { $parts[2] = $this->defaultRoute; } $params = $request->get(); $params['sguid'] = $space->guid; return [$parts[2], $params]; } } } return false; }
/** * Returns a workspace list by json * * It can be filtered by by keyword. */ public function actionSearchJson() { \Yii::$app->response->format = 'json'; $keyword = Yii::$app->request->get('keyword', ""); $page = (int) Yii::$app->request->get('page', 1); $limit = (int) Yii::$app->request->get('limit', \humhub\models\Setting::Get('paginationSize')); $searchResultSet = Yii::$app->search->find($keyword, ['model' => \humhub\modules\space\models\Space::className(), 'page' => $page, 'pageSize' => $limit]); $json = array(); foreach ($searchResultSet->getResultInstances() as $space) { $spaceInfo = array(); $spaceInfo['guid'] = $space->guid; $spaceInfo['title'] = Html::encode($space->name); $spaceInfo['tags'] = Html::encode($space->tags); $spaceInfo['image'] = Image::widget(['space' => $space, 'width' => 24]); $spaceInfo['link'] = $space->getUrl(); $json[] = $spaceInfo; } return $json; }
/** * Automatically loads the underlying contentContainer (User/Space) by using * the uguid/sguid request parameter * * @return boolean */ public function init() { $spaceGuid = Yii::$app->request->get('sguid', ''); $userGuid = Yii::$app->request->get('uguid', ''); if ($spaceGuid != "") { $this->contentContainer = Space::findOne(['guid' => $spaceGuid]); if ($this->contentContainer == null) { throw new \yii\web\HttpException(404, Yii::t('base', 'Space not found!')); } $this->attachBehavior('SpaceControllerBehavior', array('class' => \humhub\modules\space\behaviors\SpaceController::className(), 'space' => $this->contentContainer)); $this->subLayout = "@humhub/modules/space/views/space/_layout"; } elseif ($userGuid != "") { $this->contentContainer = User::findOne(['guid' => $userGuid]); if ($this->contentContainer == null) { throw new \yii\web\HttpException(404, Yii::t('base', 'User not found!')); } $this->attachBehavior('ProfileControllerBehavior', ['class' => \humhub\modules\user\behaviors\ProfileController::className(), 'user' => $this->contentContainer]); $this->subLayout = "@humhub/modules/user/views/profile/_layout"; } else { throw new \yii\web\HttpException(500, Yii::t('base', 'Could not determine content container!')); } /** * Auto check access rights to this container */ if ($this->contentContainer != null) { if ($this->autoCheckContainerAccess) { $this->checkContainerAccess(); } } if (!$this->checkModuleIsEnabled()) { throw new HttpException(405, Yii::t('base', 'Module is not enabled on this content container!')); } return parent::init(); }