Пример #1
0
 /**
  * Returns a List of all Comments belong to this Model
  */
 public function actionShow()
 {
     $content = $this->parentContent;
     $pagination = new \yii\data\Pagination(['totalCount' => Comment::GetCommentCount($content->className(), $content->getPrimaryKey()), 'pageSize' => $this->module->commentsBlockLoadSize]);
     $query = Comment::find();
     $query->orderBy('created_at DESC');
     $query->where(['object_model' => $content->className(), 'object_id' => $content->getPrimaryKey()]);
     $query->offset($pagination->offset)->limit($pagination->limit);
     $comments = array_reverse($query->all());
     $output = \humhub\modules\comment\widgets\ShowMore::widget(['pagination' => $pagination, 'object' => $content]);
     foreach ($comments as $comment) {
         $output .= \humhub\modules\comment\widgets\Comment::widget(['comment' => $comment]);
     }
     if (Yii::$app->request->get('mode') == 'popup') {
         return $this->renderAjax('showPopup', array('object' => $content, 'output' => $output, 'id' => $content->getUniqueId()));
     } else {
         return $this->renderAjaxContent($output);
     }
 }
Пример #2
0
 /**
  * Callback to validate module database records.
  *
  * @param Event $event
  */
 public static function onIntegrityCheck($event)
 {
     $integrityController = $event->sender;
     $integrityController->showTestHeadline("Comment Module (" . Comment::find()->count() . " entries)");
     // Loop over all comments
     foreach (Comment::find()->all() as $c) {
         // Check underlying record exists
         if ($c->source === null) {
             if ($integrityController->showFix("Deleting comment id " . $c->id . " without existing target!")) {
                 $c->delete();
             }
         }
         // User exists
         if ($c->user === null) {
             if ($integrityController->showFix("Deleting comment id " . $c->id . " without existing user!")) {
                 $c->delete();
             }
         }
     }
 }
Пример #3
0
 /**
  * Count number comments for this target object
  *
  * @param type $model
  * @param type $id
  * @return type
  */
 public static function GetCommentCount($model, $id)
 {
     $cacheID = sprintf("commentCount_%s_%s", $model, $id);
     $commentCount = Yii::$app->cache->get($cacheID);
     if ($commentCount === false) {
         $commentCount = Comment::find()->where(['object_model' => $model, 'object_id' => $id])->count();
         Yii::$app->cache->set($cacheID, $commentCount, \humhub\models\Setting::Get('expireTime', 'cache'));
     }
     return $commentCount;
 }
 /**
  * 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;
 }
Пример #5
0
 /**
  * On content deletion make sure to delete all its comments
  *
  * @param CEvent $event
  */
 public static function onContentDelete($event)
 {
     foreach (models\Comment::find()->where(['object_model' => $event->sender->className(), 'object_id' => $event->sender->id])->all() as $comment) {
         $comment->delete();
     }
 }