当前位置: 首页>>代码示例>>PHP>>正文


PHP Space::save方法代码示例

本文整理汇总了PHP中humhub\modules\space\models\Space::save方法的典型用法代码示例。如果您正苦于以下问题:PHP Space::save方法的具体用法?PHP Space::save怎么用?PHP Space::save使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在humhub\modules\space\models\Space的用法示例。


在下文中一共展示了Space::save方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: actionCreate

 /**
  * 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));
 }
开发者ID:alefernie,项目名称:intranet,代码行数:18,代码来源:CreateController.php

示例2: 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;
     }
 }
开发者ID:ConnectedCommunities,项目名称:humhub-modules-bulk_import,代码行数:48,代码来源:MainController.php

示例3: actionAdmin

 /**
  * Setup Administrative User
  *
  * This should be the last step, before the user is created also the
  * application secret will created.
  */
 public function actionAdmin()
 {
     $userModel = new User();
     $userModel->scenario = 'registration';
     $userPasswordModel = new Password();
     $userPasswordModel->scenario = 'registration';
     $profileModel = $userModel->profile;
     $profileModel->scenario = 'registration';
     // Build Form Definition
     $definition = array();
     $definition['elements'] = array();
     // Add User Form
     $definition['elements']['User'] = array('type' => 'form', 'elements' => array('username' => array('type' => 'text', 'class' => 'form-control', 'maxlength' => 25), 'email' => array('type' => 'text', 'class' => 'form-control', 'maxlength' => 100)));
     // Add User Password Form
     $definition['elements']['Password'] = array('type' => 'form', 'elements' => array('newPassword' => array('type' => 'password', 'class' => 'form-control', 'maxlength' => 255), 'newPasswordConfirm' => array('type' => 'password', 'class' => 'form-control', 'maxlength' => 255)));
     // Add Profile Form
     $definition['elements']['Profile'] = array_merge(array('type' => 'form'), $profileModel->getFormDefinition());
     // Get Form Definition
     $definition['buttons'] = array('save' => array('type' => 'submit', 'class' => 'btn btn-primary', 'label' => Yii::t('InstallerModule.controllers_ConfigController', 'Create Admin Account')));
     $form = new \humhub\compat\HForm($definition);
     $form->models['User'] = $userModel;
     $form->models['User']->group_id = 1;
     $form->models['Password'] = $userPasswordModel;
     $form->models['Profile'] = $profileModel;
     if ($form->submitted('save') && $form->validate()) {
         if (Setting::Get('secret') == "") {
             Setting::Set('secret', \humhub\libs\UUID::v4());
         }
         $form->models['User']->status = User::STATUS_ENABLED;
         $form->models['User']->super_admin = true;
         $form->models['User']->language = '';
         $form->models['User']->last_activity_email = new \yii\db\Expression('NOW()');
         $form->models['User']->save();
         $form->models['Profile']->user_id = $form->models['User']->id;
         $form->models['Profile']->title = "System Administration";
         $form->models['Profile']->save();
         // Save User Password
         $form->models['Password']->user_id = $form->models['User']->id;
         $form->models['Password']->setPassword($form->models['Password']->newPassword);
         $form->models['Password']->save();
         $userId = $form->models['User']->id;
         // Switch Identity
         Yii::$app->user->switchIdentity($form->models['User']);
         // Create Welcome Space
         $space = new Space();
         $space->name = 'Welcome Space';
         $space->description = 'Your first sample space to discover the platform.';
         $space->join_policy = Space::JOIN_POLICY_FREE;
         $space->visibility = Space::VISIBILITY_ALL;
         $space->created_by = $userId;
         $space->auto_add_new_members = 1;
         $space->save();
         $profileImage = new \humhub\libs\ProfileImage($space->guid);
         $profileImage->setNew(Yii::getAlias("@webroot/resources/installer/welcome_space.jpg"));
         // Add Some Post to the Space
         $post = new \humhub\modules\post\models\Post();
         $post->message = "Yay! I've just installed HumHub :-)";
         $post->content->container = $space;
         $post->content->visibility = \humhub\modules\content\models\Content::VISIBILITY_PUBLIC;
         $post->save();
         return $this->redirect(Url::to(['finished']));
     }
     return $this->render('admin', array('hForm' => $form));
 }
开发者ID:alefernie,项目名称:intranet,代码行数:70,代码来源:ConfigController.php

示例4: actionAdmin

 /**
  * Setup Administrative User
  *
  * This should be the last step, before the user is created also the
  * application secret will created.
  */
 public function actionAdmin()
 {
     // Admin account already created
     if (User::find()->count() > 0) {
         return $this->redirect(Yii::$app->getModule('installer')->getNextConfigStepUrl());
     }
     $userModel = new User();
     $userModel->scenario = 'registration_email';
     $userPasswordModel = new Password();
     $userPasswordModel->scenario = 'registration';
     $profileModel = $userModel->profile;
     $profileModel->scenario = 'registration';
     // Build Form Definition
     $definition = array();
     $definition['elements'] = array();
     // Add User Form
     $definition['elements']['User'] = array('type' => 'form', 'elements' => array('username' => array('type' => 'text', 'class' => 'form-control', 'maxlength' => 25), 'email' => array('type' => 'text', 'class' => 'form-control', 'maxlength' => 100)));
     // Add User Password Form
     $definition['elements']['Password'] = array('type' => 'form', 'elements' => array('newPassword' => array('type' => 'password', 'class' => 'form-control', 'maxlength' => 255), 'newPasswordConfirm' => array('type' => 'password', 'class' => 'form-control', 'maxlength' => 255)));
     // Add Profile Form
     $definition['elements']['Profile'] = array_merge(array('type' => 'form'), $profileModel->getFormDefinition());
     // Get Form Definition
     $definition['buttons'] = array('save' => array('type' => 'submit', 'class' => 'btn btn-primary', 'label' => Yii::t('InstallerModule.controllers_ConfigController', 'Create Admin Account')));
     $form = new \humhub\compat\HForm($definition);
     $form->models['User'] = $userModel;
     $form->models['Password'] = $userPasswordModel;
     $form->models['Profile'] = $profileModel;
     if ($form->submitted('save') && $form->validate()) {
         $form->models['User']->status = User::STATUS_ENABLED;
         $form->models['User']->language = '';
         $form->models['User']->tags = 'Administration, Support, HumHub';
         $form->models['User']->last_activity_email = new \yii\db\Expression('NOW()');
         $form->models['User']->save();
         $form->models['Profile']->user_id = $form->models['User']->id;
         $form->models['Profile']->title = "System Administration";
         $form->models['Profile']->save();
         // Save User Password
         $form->models['Password']->user_id = $form->models['User']->id;
         $form->models['Password']->setPassword($form->models['Password']->newPassword);
         $form->models['Password']->save();
         $userId = $form->models['User']->id;
         Group::getAdminGroup()->addUser($form->models['User']);
         // Reload User
         $adminUser = User::findOne(['id' => 1]);
         // Switch Identity
         Yii::$app->user->switchIdentity($adminUser);
         // Create Welcome Space
         $space = new Space();
         $space->name = Yii::t("InstallerModule.controllers_ConfigController", "Welcome Space");
         $space->description = Yii::t("InstallerModule.controllers_ConfigController", "Your first sample space to discover the platform.");
         $space->join_policy = Space::JOIN_POLICY_FREE;
         $space->visibility = Space::VISIBILITY_ALL;
         $space->created_by = $adminUser->id;
         $space->auto_add_new_members = 1;
         $space->color = '#6fdbe8';
         $space->save();
         // activate all available modules for this space
         foreach ($space->getAvailableModules() as $module) {
             $space->enableModule($module->id);
         }
         // Add Some Post to the Space
         $post = new \humhub\modules\post\models\Post();
         $post->message = Yii::t("InstallerModule.controllers_ConfigController", "Yay! I've just installed HumHub ;Cool;");
         $post->content->container = $space;
         $post->content->visibility = \humhub\modules\content\models\Content::VISIBILITY_PUBLIC;
         $post->save();
         return $this->redirect(Yii::$app->getModule('installer')->getNextConfigStepUrl());
     }
     return $this->render('admin', array('hForm' => $form));
 }
开发者ID:VasileGabriel,项目名称:humhub,代码行数:76,代码来源:ConfigController.php


注:本文中的humhub\modules\space\models\Space::save方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。