statistics = $comment_statistics; } /** * {@inheritdoc} */ public static function createInstance(ContainerInterface $container, EntityTypeInterface $entity_info) { return new static( $entity_info, $container->get('database'), $container->get('entity.manager'), $container->get('comment.statistics') ); } /** * {@inheritdoc} */ protected function buildQuery($ids, $revision_id = FALSE) { $query = parent::buildQuery($ids, $revision_id); // Specify additional fields from the user table. $query->innerJoin('users', 'u', 'base.uid = u.uid'); // @todo: Move to a computed 'name' field instead. $query->addField('u', 'name', 'registered_name'); return $query; } /** * {@inheritdoc} */ protected function mapFromStorageRecords(array $records) { // Prepare standard comment fields. foreach ($records as $record) { $record->name = $record->uid ? $record->registered_name : $record->name; } return parent::mapFromStorageRecords($records); } /** * {@inheritdoc} */ public function updateEntityStatistics(CommentInterface $comment) { $this->statistics->update($comment); } /** * {@inheritdoc} */ public function getMaxThread(EntityInterface $comment) { $query = $this->database->select('comment', 'c') ->condition('entity_id', $comment->getCommentedEntityId()) ->condition('field_id', $comment->getFieldId()) ->condition('entity_type', $comment->getCommentedEntityTypeId()); $query->addExpression('MAX(thread)', 'thread'); return $query->execute() ->fetchField(); } /** * {@inheritdoc} */ public function getMaxThreadPerThread(EntityInterface $comment) { $query = $this->database->select('comment', 'c') ->condition('entity_id', $comment->getCommentedEntityId()) ->condition('field_id', $comment->getFieldId()) ->condition('entity_type', $comment->getCommentedEntityTypeId()) ->condition('thread', $comment->getParentComment()->getThread() . '.%', 'LIKE'); $query->addExpression('MAX(thread)', 'thread'); return $query->execute() ->fetchField(); } /** * {@inheritdoc} */ public function getChildCids(array $comments) { return $this->database->select('comment', 'c') ->fields('c', array('cid')) ->condition('pid', array_keys($comments)) ->execute() ->fetchCol(); } }