public function up() { $activities = (new \yii\db\Query())->select("activity.*, content.user_id, user_follow.id as follow_id")->from('activity')->leftJoin('content', 'content.object_model=:activityModel AND content.object_id=activity.id', [':activityModel' => Activity::className()])->leftJoin('user_follow', 'activity.object_model=user_follow.object_model AND activity.object_id=user_follow.object_id AND user_follow.user_id=content.user_id')->where(['class' => 'humhub\\modules\\user\\activities\\UserFollow', 'activity.object_model' => 'humhub\\modules\\user\\models\\User']); foreach ($activities->each() as $activity) { if ($activity['follow_id'] != "") { $this->updateSilent('activity', ['object_model' => humhub\modules\user\models\Follow::className(), 'object_id' => $activity['follow_id']], ['id' => $activity['id']]); } } }
public function testModeActivity() { Yii::$app->user->switchIdentity(User::findOne(['id' => 2])); // Post of User 2 - should not be included in activities $post = new Post(); $post->message = "P5"; $post->content->setContainer(Yii::$app->user->getIdentity()); $post->save(); $streamAction = new Stream('stream', Yii::$app->controller); $streamAction->mode = Stream::MODE_ACTIVITY; $streamAction->init(); $wallEntries = $streamAction->getWallEntries(); assert(count($wallEntries) == 4); foreach ($wallEntries as $entry) { assert($entry->content->object_model == Activity::className() && $entry->content->created_by != 2); } }
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']]); } }
public function validateVisibility() { if ($this->object_model == Activity::className() || $this->getPolymorphicRelation()->className() == Activity::className()) { return; } if ($this->container->className() == Space::className()) { if (!$this->container->canShare() && $this->visibility) { $this->addError('visibility', Yii::t('base', 'You cannot create public visible content!')); } } }
public function setupCriteria() { $this->activeQuery->joinWith('content'); $this->activeQuery->joinWith('content.createdBy'); $this->activeQuery->joinWith('content.contentContainer'); $this->activeQuery->limit($this->limit); $this->activeQuery->andWhere(['user.status' => User::STATUS_ENABLED]); /** * Handle Stream Mode (Normal Stream or Activity Stream) */ if ($this->mode == self::MODE_ACTIVITY) { $this->activeQuery->andWhere(['content.object_model' => \humhub\modules\activity\models\Activity::className()]); // Dont show own activities if ($this->user !== null) { $this->activeQuery->leftJoin('activity', 'content.object_id=activity.id AND content.object_model=:activityModel', ['activityModel' => \humhub\modules\activity\models\Activity::className()]); $this->activeQuery->andWhere('content.created_by != :userId', array(':userId' => $this->user->id)); } } else { $this->activeQuery->andWhere(['!=', 'content.object_model', \humhub\modules\activity\models\Activity::className()]); } /** * Setup Sorting */ if ($this->sort == self::SORT_UPDATED_AT) { $this->activeQuery->orderBy('wall_entry.updated_at DESC'); if ($this->from != "") { $this->activeQuery->andWhere("wall_entry.updated_at < (SELECT updated_at FROM wall_entry wd WHERE wd.id=" . $this->from . ")"); } } else { $this->activeQuery->orderBy('wall_entry.id DESC'); if ($this->from != "") { $this->activeQuery->andWhere("wall_entry.id < " . $this->from); } } }
/** * Counts all new Items for this membership */ public function countNewItems($since = "") { $query = WallEntry::find()->joinWith('content'); $query->where(['!=', 'content.object_model', Activity::className()]); $query->andWhere(['wall_entry.wall_id' => $this->space->wall_id]); $query->andWhere(['>', 'wall_entry.created_at', $this->last_visit]); $count = $query->count(); $count += Comment::find()->where(['space_id' => $this->space_id])->andWhere(['>', 'created_at', $this->last_visit])->count(); return $count; }
/** * @inheritdoc */ public function afterSave($insert, $changedAttributes) { // Auto follow this content if ($this->className() != \humhub\modules\activity\models\Activity::className()) { $this->follow($this->content->user_id); } // Set polymorphic relation if ($insert) { $this->content->object_model = $this->className(); $this->content->object_id = $this->getPrimaryKey(); } // Always save content $this->content->save(); parent::afterSave($insert, $changedAttributes); if ($insert && $this->autoAddToWall && $this->wallEntryClass != "") { $this->content->addToWall(); } // When Space Content, update also last visit if ($this->content->space_id) { $membership = $this->content->space->getMembership(); if ($membership) { $membership->updateLastVisit(); } } }
/** * @inheritdoc */ public function afterSave($insert, $changedAttributes) { // Auto follow this content if ($this->className() != \humhub\modules\activity\models\Activity::className()) { $this->follow($this->content->created_by); } // Set polymorphic relation if ($insert) { $this->content->object_model = $this->className(); $this->content->object_id = $this->getPrimaryKey(); } // Always save content $this->content->save(); parent::afterSave($insert, $changedAttributes); if ($insert && $this->autoAddToWall && $this->wallEntryClass != "") { $this->content->addToWall(); } }