Exemplo n.º 1
0
 /**
  * After Save Addons
  *
  * @return type
  */
 public function afterSave($insert, $changedAttributes)
 {
     if ($this->status == User::STATUS_ENABLED) {
         Yii::$app->search->update($this);
     } else {
         Yii::$app->search->delete($this);
     }
     if ($insert) {
         if ($this->status == User::STATUS_ENABLED) {
             $this->setUpApproved();
         } else {
             Group::notifyAdminsForUserApproval($this);
         }
         $this->profile->user_id = $this->id;
     }
     if (Yii::$app->user->id == $this->id) {
         Yii::$app->user->setIdentity($this);
     }
     return parent::afterSave($insert, $changedAttributes);
 }
Exemplo n.º 2
0
 /**
  * @inheritdoc
  */
 public function afterSave($insert, $changedAttributes)
 {
     Yii::$app->search->update($this);
     $user = \humhub\modules\user\models\User::findOne(['id' => $this->created_by]);
     if ($insert) {
         // Auto add creator as admin
         $membership = new Membership();
         $membership->space_id = $this->id;
         $membership->user_id = $user->id;
         $membership->status = Membership::STATUS_MEMBER;
         $membership->group_id = self::USERGROUP_ADMIN;
         $membership->save();
         $activity = new \humhub\modules\space\activities\Created();
         $activity->source = $this;
         $activity->originator = $user;
         $activity->create();
     }
     Yii::$app->cache->delete('userSpaces_' . $user->id);
     return parent::afterSave($insert, $changedAttributes);
 }
Exemplo n.º 3
0
 /**
  * After Save Addons
  */
 public function afterSave($insert, $changedAttributes)
 {
     Yii::$app->search->update($this);
     $user = \humhub\modules\user\models\User::findOne(['id' => $this->created_by]);
     if ($insert) {
         // Create new wall record for this space
         $wall = new Wall();
         $wall->object_model = $this->className();
         $wall->object_id = $this->id;
         $wall->save();
         $this->wall_id = $wall->id;
         $this->update(false, ['wall_id']);
         // Auto add creator as admin
         $membership = new Membership();
         $membership->space_id = $this->id;
         $membership->user_id = $user->id;
         $membership->status = Membership::STATUS_MEMBER;
         $membership->invite_role = 1;
         $membership->admin_role = 1;
         $membership->share_role = 1;
         $membership->save();
         $activity = new \humhub\modules\space\activities\Created();
         $activity->source = $this;
         $activity->originator = $user;
         $activity->create();
     }
     Yii::$app->cache->delete('userSpaces_' . $user->id);
     return parent::afterSave($insert, $changedAttributes);
 }
Exemplo n.º 4
0
 /**
  * After Save Addons
  *
  * @return type
  */
 public function afterSave($insert, $changedAttributes)
 {
     // Make sure we get an direct User model instance
     // (e.g. not UserEditForm) for search rebuild
     $user = User::findOne(['id' => $this->id]);
     if ($this->status == User::STATUS_ENABLED) {
         Yii::$app->search->update($user);
     } else {
         Yii::$app->search->delete($user);
     }
     if ($insert) {
         if ($this->status == User::STATUS_ENABLED) {
             $this->setUpApproved();
         } else {
             Group::notifyAdminsForUserApproval($this);
         }
         $this->profile->user_id = $this->id;
     }
     if (Yii::$app->user->id == $this->id) {
         Yii::$app->user->setIdentity($user);
     }
     return parent::afterSave($insert, $changedAttributes);
 }