/**
  * Sample Data
  */
 public function actionSampleData()
 {
     if (Yii::$app->getModule('installer')->settings->get('sampleData') == 1) {
         // Sample Data already created
         return $this->redirect(Yii::$app->getModule('installer')->getNextConfigStepUrl());
     }
     $form = new \humhub\modules\installer\forms\SampleDataForm();
     $form->sampleData = 1;
     if ($form->load(Yii::$app->request->post()) && $form->validate()) {
         Yii::$app->getModule('installer')->settings->set('sampleData', $form->sampleData);
         if (Yii::$app->getModule('installer')->settings->get('sampleData') == 1) {
             // Add sample image to admin
             $admin = User::find()->where(['id' => 1])->one();
             $adminImage = new \humhub\libs\ProfileImage($admin->guid);
             $adminImage->setNew(Yii::getAlias("@webroot/resources/installer/user_male_1.jpg"));
             // Create second user
             $userModel = new User();
             $userModel->scenario = 'registration';
             $profileModel = $userModel->profile;
             $profileModel->scenario = 'registration';
             $userModel->status = User::STATUS_ENABLED;
             $userModel->username = "******";
             $userModel->email = "*****@*****.**";
             $userModel->language = '';
             $userModel->tags = "Microsoft Office, Marketing, SEM, Digital Native";
             $userModel->last_activity_email = new \yii\db\Expression('NOW()');
             $userModel->save();
             $profileImage = new \humhub\libs\ProfileImage($userModel->guid);
             $profileImage->setNew(Yii::getAlias("@webroot/resources/installer/user_male_2.jpg"));
             $profileModel->user_id = $userModel->id;
             $profileModel->firstname = "David";
             $profileModel->lastname = "Roberts";
             $profileModel->title = "Late riser";
             $profileModel->street = "2443 Queens Lane";
             $profileModel->zip = "24574";
             $profileModel->city = "Allwood";
             $profileModel->country = "Virginia";
             $profileModel->save();
             // Create third user
             $userModel2 = new User();
             $userModel2->scenario = 'registration';
             $profileModel2 = $userModel2->profile;
             $profileModel2->scenario = 'registration';
             $userModel2->status = User::STATUS_ENABLED;
             $userModel2->username = "******";
             $userModel2->email = "*****@*****.**";
             $userModel2->language = '';
             $userModel2->tags = "Yoga, Travel, English, German, French";
             $userModel2->last_activity_email = new \yii\db\Expression('NOW()');
             $userModel2->save();
             $profileImage2 = new \humhub\libs\ProfileImage($userModel2->guid);
             $profileImage2->setNew(Yii::getAlias("@webroot/resources/installer/user_female_1.jpg"));
             $profileModel2->user_id = $userModel2->id;
             $profileModel2->firstname = "Sara";
             $profileModel2->lastname = "Schuster";
             $profileModel2->title = "Do-gooder";
             $profileModel2->street = "Schmarjestrasse 51";
             $profileModel2->zip = "17095";
             $profileModel2->city = "Friedland";
             $profileModel2->country = "Niedersachsen";
             $profileModel2->save();
             // Switch Identity
             $user = User::find()->where(['id' => 1])->one();
             Yii::$app->user->switchIdentity($user);
             $space = Space::find()->where(['id' => 1])->one();
             // Create a sample post
             $post = new \humhub\modules\post\models\Post();
             $post->message = Yii::t("InstallerModule.controllers_ConfigController", "We're looking for great slogans of famous brands. Maybe you can come up with some samples?");
             $post->content->container = $space;
             $post->content->visibility = \humhub\modules\content\models\Content::VISIBILITY_PRIVATE;
             $post->save();
             // Switch Identity
             Yii::$app->user->switchIdentity($userModel);
             $comment = new \humhub\modules\comment\models\Comment();
             $comment->message = Yii::t("InstallerModule.controllers_ConfigController", "Nike – Just buy it. ;Wink;");
             $comment->object_model = $post->className();
             $comment->object_id = $post->getPrimaryKey();
             $comment->save();
             // Switch Identity
             Yii::$app->user->switchIdentity($userModel2);
             $comment2 = new \humhub\modules\comment\models\Comment();
             $comment2->message = Yii::t("InstallerModule.controllers_ConfigController", "Calvin Klein – Between love and madness lies obsession.");
             $comment2->object_model = $post->className();
             $comment2->object_id = $post->getPrimaryKey();
             $comment2->save();
             // Create Like Object
             $like = new \humhub\modules\like\models\Like();
             $like->object_model = $comment->className();
             $like->object_id = $comment->getPrimaryKey();
             $like->save();
             $like = new \humhub\modules\like\models\Like();
             $like->object_model = $post->className();
             $like->object_id = $post->getPrimaryKey();
             $like->save();
             // trigger install sample data event
             $this->trigger(self::EVENT_INSTALL_SAMPLE_DATA);
         }
         return $this->redirect(Yii::$app->getModule('installer')->getNextConfigStepUrl());
     }
     return $this->render('sample-data', array('model' => $form));
 }
 /**
  * Create installer sample data
  * 
  * @param \yii\base\Event $event
  */
 public static function onSampleDataInstall($event)
 {
     $space = Space::find()->where(['id' => 1])->one();
     // activate module at space
     if (!$space->isModuleEnabled("polls")) {
         $space->enableModule("polls");
     }
     // Switch Identity
     $user = User::find()->where(['id' => 1])->one();
     Yii::$app->user->switchIdentity($user);
     $poll = new Poll();
     $poll->question = Yii::t('PollsModule.events', "Right now, we are in the planning stages for our next meetup and we would like to know from you, where you would like to go?");
     $poll->answersText = Yii::t('PollsModule.events', "To Daniel\nClub A Steakhouse\nPisillo Italian Panini\n");
     $poll->content->container = $space;
     $poll->allow_multiple = Yii::$app->request->post('allowMultiple', 0);
     $poll->save();
     // load users
     $user2 = User::find()->where(['id' => 2])->one();
     $user3 = User::find()->where(['id' => 3])->one();
     // Switch Identity
     Yii::$app->user->switchIdentity($user2);
     // vote
     $poll->vote([2]);
     $comment = new \humhub\modules\comment\models\Comment();
     $comment->message = Yii::t('PollsModule.events', "Why don't we go to Bemelmans Bar?");
     $comment->object_model = $poll->className();
     $comment->object_id = $poll->getPrimaryKey();
     $comment->save();
     // Switch Identity
     Yii::$app->user->switchIdentity($user3);
     // vote
     $poll->vote([3]);
     $comment = new \humhub\modules\comment\models\Comment();
     $comment->message = Yii::t('PollsModule.events', "Again? ;Weary;");
     $comment->object_model = $poll->className();
     $comment->object_id = $poll->getPrimaryKey();
     $comment->save();
     // Switch Identity
     Yii::$app->user->switchIdentity($user);
 }