public function add(Searchable $obj) { // Get Primary Key $attributes = $obj->getSearchAttributes(); $index = $this->getIndex(); $doc = new \ZendSearch\Lucene\Document(); // Add Meta Data fields foreach ($this->getMetaInfoArray($obj) as $fieldName => $fieldValue) { $doc->addField(\ZendSearch\Lucene\Document\Field::keyword($fieldName, $fieldValue)); } // Add provided search infos foreach ($attributes as $key => $val) { $doc->addField(\ZendSearch\Lucene\Document\Field::Text($key, $val, 'UTF-8')); } // Add comments - if record is content if ($obj instanceof ContentActiveRecord) { $comments = ""; foreach (Comment::findAll(['object_id' => $obj->getPrimaryKey(), 'object_model' => $obj->className()]) as $comment) { $comments .= " " . $comment->message; } $doc->addField(\ZendSearch\Lucene\Document\Field::Text('comments', $comments, 'UTF-8')); } if (\Yii::$app->request->isConsoleRequest) { print "."; } $index->addDocument($doc); $index->commit(); }
/** * Executes the widget. */ public function run() { $modelName = $this->object->content->object_model; $modelId = $this->object->content->object_id; // Count all Comments $commentCount = \humhub\modules\comment\models\Comment::GetCommentCount($modelName, $modelId); $comments = \humhub\modules\comment\models\Comment::GetCommentsLimited($modelName, $modelId, 2); $isLimited = $commentCount > 2; return $this->render('comments', array('object' => $this->object, 'comments' => $comments, 'modelName' => $modelName, 'modelId' => $modelId, 'id' => $this->object->getUniqueId(), 'isLimited' => $isLimited, 'total' => $commentCount)); }
/** * 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(); } } } }
/** * Handles AJAX Request for Comment Deletion. * Currently this is only allowed for the Comment Owner. */ public function actionDelete() { $this->forcePostRequest(); $this->loadContentAddon(Comment::className(), Yii::$app->request->get('id')); if ($this->contentAddon->canDelete()) { $this->contentAddon->delete(); } else { throw new HttpException(500, Yii::t('CommentModule.controllers_CommentController', 'Insufficent permissions!')); } }
/** * Load all posted files from the database and get an array of them. * * @param array $filesOrder * orderBy array appended to the files query * @param array $foldersOrder * currently unused * @return Ambigous <multitype:, multitype:\yii\db\ActiveRecord > */ protected function getAllPostedFilesList($filesOrder = NULL, $foldersOrder = NULL) { // set ordering default if (!$filesOrder) { $filesOrder = ['file.updated_at' => SORT_DESC, 'file.title' => SORT_ASC]; } // Get Posted Files $query = \humhub\modules\file\models\File::find(); // join comments to the file if available $query->join('LEFT JOIN', 'comment', '(file.object_id=comment.id AND file.object_model=' . Yii::$app->db->quoteValue(Comment::className()) . ')'); // join parent post of comment or file $query->join('LEFT JOIN', 'content', '(comment.object_model=content.object_model AND comment.object_id=content.object_id) OR (file.object_model=content.object_model AND file.object_id=content.object_id)'); if (version_compare(Yii::$app->version, '1.1', 'lt')) { // select only the one for the given content container for Yii version < 1.1 if ($this->contentContainer instanceof \humhub\modules\user\models\User) { $query->andWhere(['content.user_id' => $this->contentContainer->id]); $query->andWhere(['IS', 'content.space_id', new \yii\db\Expression('NULL')]); } else { $query->andWhere(['content.space_id' => $this->contentContainer->id]); } } else { // select only the one for the given content container for Yii version >= 1.1 $query->andWhere(['content.contentcontainer_id' => $this->contentContainer->contentContainerRecord->id]); } // only accept Posts as the base content, so stuff from sumbmodules like files itsself or gallery will be excluded $query->andWhere(['or', ['=', 'comment.object_model', Post::className()], ['=', 'file.object_model', Post::className()]]); // Get Files from comments return ['postedFiles' => $query->orderBy($filesOrder)->all()]; }
public function up() { $this->renameClass('Comment', Comment::className()); }
/** * 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; }
/** * Returns count of existing comments * * @return Int Comment Count */ public function getCommentsCount() { return \humhub\modules\comment\models\Comment::GetCommentCount(get_class($this->object), $this->object->getPrimaryKey()); }
/** * 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; }
/** * 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(); } }
<div class="task-controls pull-right"> <a data-toggle="collapse" href="#task-comment-<?php echo $task->id; ?> " onclick="$('#comment_humhubmodulestasksmodelsTask_<?php echo $task->id; ?> ').show();return false;" aria-expanded="false" aria-controls="collapseTaskComments"><i class="fa fa-comment-o"></i> <?php echo $count = Comment::GetCommentCount($task->className(), $task->id); ?> </a> </div> <div class="task-controls pull-right assigned-users task-completed-controls" style="display: inline;"> <!-- Show assigned user --> <?php foreach ($task->assignedUsers as $user) { ?> <a href="<?php echo $user->getUrl(); ?>
/** * 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]); }
/** * 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(); }
/** * Get the post the file is connected to. * @param File $basefile the file. */ 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]); } $return = Post::findOne(['id' => $searchItem->object_id]); }