/** * @inheritdoc */ public function run() { $postCount = Content::find()->where(['object_model' => Post::className(), 'contentcontainer_id' => $this->space->contentContainerRecord->id])->count(); return $this->render('header', array('space' => $this->space, 'postCount' => $postCount)); }
/** * Action to list all posted files from the content container. * @return string */ public function actionAllPostedFiles() { $items = $this->getAllPostedFiles(); $content_file_wrapper = []; foreach ($items as $file) { $searchItem = $file; // if the item is connected to a Comment, we have to search for the corresponding Post if ($file->object_model === Comment::className()) { $searchItem = Comment::findOne(['id' => $file->object_id]); } $query = Content::find(); $query->andWhere(['content.object_id' => $searchItem->object_id, 'content.object_model' => $searchItem->object_model]); $content_file_wrapper[] = ['file' => $file, 'content' => $query->one()]; } return $this->render('allPostedFiles', ['contentContainer' => $this->contentContainer, 'items' => $content_file_wrapper]); }
/** * On rebuild of the search index, rebuild all user records * * @param type $event */ public static function onSearchRebuild($event) { foreach (Content::find()->all() as $content) { $contentObject = $content->getPolymorphicRelation(); if ($contentObject instanceof \humhub\modules\search\interfaces\Searchable) { Yii::$app->search->add($contentObject); } } }
/** * Get the post the file is connected to. */ public static function getBasePost($file = null) { if ($file === null) { return null; } $searchItem = $file; // if the item is connected to a Comment, we have to search for the corresponding Post if ($file->object_model === Comment::className()) { $searchItem = Comment::findOne(['id' => $file->object_id]); } $query = Content::find(); $query->andWhere(['content.object_id' => $searchItem->object_id, 'content.object_model' => $searchItem->object_model]); return $query->one(); }