本文整理汇总了PHP中humhub\modules\space\models\Space::findOne方法的典型用法代码示例。如果您正苦于以下问题:PHP Space::findOne方法的具体用法?PHP Space::findOne怎么用?PHP Space::findOne使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类humhub\modules\space\models\Space
的用法示例。
在下文中一共展示了Space::findOne方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: actionIndex
public function actionIndex()
{
$keyword = Yii::$app->request->get('keyword', "");
$scope = Yii::$app->request->get('scope', "");
$page = (int) Yii::$app->request->get('page', 1);
$limitSpaceGuids = Yii::$app->request->get('limitSpaceGuids', "");
$limitSpaces = array();
if ($limitSpaceGuids !== "") {
foreach (explode(",", $limitSpaceGuids) as $guid) {
$guid = trim($guid);
if ($guid != "") {
$space = Space::findOne(['guid' => trim($guid)]);
if ($space !== null) {
$limitSpaces[] = $space;
}
}
}
}
$options = ['page' => $page, 'sort' => $keyword == '' ? 'title' : null, 'pageSize' => Yii::$app->settings->get('paginationSize'), 'limitSpaces' => $limitSpaces];
if ($scope == self::SCOPE_CONTENT) {
$options['type'] = \humhub\modules\search\engine\Search::DOCUMENT_TYPE_CONTENT;
} elseif ($scope == self::SCOPE_SPACE) {
$options['model'] = Space::className();
} elseif ($scope == self::SCOPE_USER) {
$options['model'] = User::className();
} else {
$scope = self::SCOPE_ALL;
}
$searchResultSet = Yii::$app->search->find($keyword, $options);
$pagination = new \yii\data\Pagination();
$pagination->totalCount = $searchResultSet->total;
$pagination->pageSize = $searchResultSet->pageSize;
return $this->render('index', array('scope' => $scope, 'keyword' => $keyword, 'results' => $searchResultSet->getResultInstances(), 'pagination' => $pagination, 'totals' => $this->getTotals($keyword, $options), 'limitSpaceGuids' => $limitSpaceGuids));
}
示例2: Get
/**
* 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;
}
示例3: getUrlBySpaceGuid
/**
* 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;
}
示例4: testGetFollowers
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);
}
示例5: checkSpaceGuid
/**
* 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"));
}
}
}
}
}
示例6: testAutoAddSpace
/**
* 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 = "TestSpaceAutoAdd";
$user->email = "testautoadd@example.com";
$this->assertTrue($user->save());
$this->assertFalse($space2->isMember($user->id));
// not assigned
$this->assertTrue($space3->isMember($user->id));
// via global assign
}
示例7: getSpace
/**
* 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;
}
示例8: actionDeleteContent
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'));
}
}
示例9: actionBasic
/**
* 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));
}
示例10: registerUser
/**
* 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;
}
}
示例11: actionStartSpaceTour
/**
* This is a special case, because we need to find a space to start the tour
*/
public function actionStartSpaceTour()
{
$space = null;
// Loop over all spaces where the user is member
foreach (\humhub\modules\space\models\Membership::GetUserSpaces() as $space) {
if ($space->isAdmin()) {
// If user is admin on this space, it´s the perfect match
break;
}
}
if ($space === null) {
// If user is not member of any space, try to find a public space
// to run tour in
$space = Space::findOne(['!=', 'visibility' => Space::VISIBILITY_NONE]);
}
if ($space === null) {
throw new HttpException(404, 'Could not find any public space to run tour!');
}
return $this->redirect($space->createUrl('/space/space', array('tour' => true)));
}
示例12: testPublicContent
public function testPublicContent()
{
$this->becomeUser('User2');
$space = Space::findOne(['id' => 2]);
$post1 = new Post();
$post1->message = "Private Post";
$post1->content->setContainer($space);
$post1->content->visibility = Content::VISIBILITY_PRIVATE;
$post1->save();
$w1 = $post1->content->getFirstWallEntryId();
$post2 = new Post();
$post2->message = "Public Post";
$post2->content->setContainer($space);
$post2->content->visibility = Content::VISIBILITY_PUBLIC;
$post2->save();
$w2 = $post2->content->getFirstWallEntryId();
$this->becomeUser('Admin');
$ids = $this->getStreamActionIds($space, 2);
$this->assertFalse(in_array($w1, $ids));
$this->assertTrue(in_array($w2, $ids));
}
示例13: run
/**
* Displays / Run the Widgets
*/
public function run()
{
// Try to get current field value, when model & attribute attributes are specified.
if ($this->model != null && $this->attribute != null) {
$attribute = $this->attribute;
$this->value = $this->model->{$attribute};
}
if ($this->spaceSearchUrl == "") {
$this->spaceSearchUrl = \yii\helpers\Url::to(['/space/browse/search-json', 'keyword' => '-keywordPlaceholder-']);
}
if ($this->placeholder === null) {
$this->placeholder = Yii::t('SpaceModule.picker', 'Add {n,plural,=1{space} other{spaces}}', ['n' => $this->maxSpaces]);
}
// Currently populated spaces
$spaces = [];
foreach (explode(",", $this->value) as $guid) {
$space = Space::findOne(['guid' => trim($guid)]);
if ($space != null) {
$spaces[] = $space;
}
}
return $this->render('spacePicker', array('spaceSearchUrl' => $this->spaceSearchUrl, 'maxSpaces' => $this->maxSpaces, 'value' => $this->value, 'spaces' => $spaces, 'placeholder' => $this->placeholder, 'inputId' => $this->inputId));
}
示例14: actionAssignAllMembers
public function actionAssignAllMembers($spaceId)
{
$space = Space::findOne(['id' => $spaceId]);
if ($space == null) {
print "Error: Space not found! Check id!\n\n";
return;
}
$countMembers = 0;
$countAssigns = 0;
$this->stdout("\nAdding Members:\n\n");
foreach (User::find()->where(['status' => User::STATUS_ENABLED])->all() as $user) {
if ($space->isMember($user->id)) {
$countMembers++;
} else {
$this->stdout("\t" . $user->displayName . " added. \n", Console::FG_YELLOW);
#Yii::app()->user->setId($user->id);
Yii::$app->user->switchIdentity($user);
$space->addMember($user->id);
$countAssigns++;
}
}
$this->stdout("\nAdded " . $countAssigns . " new members to space " . $space->name . "\n", Console::FG_GREEN);
}
示例15: canRead
/**
* Checks if this content can readed
*
* @param type $userId
* @return type
*/
public function canRead($userId = "")
{
if ($userId == "") {
$userId = Yii::$app->user->id;
}
// For guests users
if (Yii::$app->user->isGuest) {
if ($this->visibility == 1) {
if ($this->container instanceof Space) {
if ($this->container->visibility == Space::VISIBILITY_ALL) {
return true;
}
} elseif ($this->container instanceof User) {
if ($this->container->visibility == User::VISIBILITY_ALL) {
return true;
}
}
}
return false;
}
if ($this->visibility == 0) {
// Space/User Content Access Check
if ($this->space_id != "") {
$space = null;
if (isset(Yii::$app->params['currentSpace']) && Yii::$app->params['currentSpace']->id == $this->space_id) {
$space = Yii::$app->params['currentSpace'];
} else {
$space = Space::findOne(['id' => $this->space_id]);
}
// Space Found
if ($space != null) {
if (!$space->isMember($userId)) {
return false;
}
}
} else {
// Check for user content
if ($userId != $this->user_id) {
return false;
}
}
}
return true;
}