CommentStatisticsInterface.php 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. <?php
  2. namespace Drupal\comment;
  3. use Drupal\Core\Entity\FieldableEntityInterface;
  4. use Drupal\Core\Entity\EntityInterface;
  5. /**
  6. * Provides an interface for storing and retrieving comment statistics.
  7. */
  8. interface CommentStatisticsInterface {
  9. /**
  10. * Returns an array of ranking information for hook_ranking().
  11. *
  12. * @return array
  13. * Array of ranking information as expected by hook_ranking().
  14. *
  15. * @see hook_ranking()
  16. * @see comment_ranking()
  17. */
  18. public function getRankingInfo();
  19. /**
  20. * Read comment statistics records for an array of entities.
  21. *
  22. * @param \Drupal\Core\Entity\EntityInterface[] $entities
  23. * Array of entities on which commenting is enabled, keyed by id
  24. * @param string $entity_type
  25. * The entity type of the passed entities.
  26. * @param bool $accurate
  27. * (optional) Indicates if results must be completely up to date. If set to
  28. * FALSE, a replica database will used if available. Defaults to TRUE.
  29. *
  30. * @return object[]
  31. * Array of statistics records.
  32. */
  33. public function read($entities, $entity_type, $accurate = TRUE);
  34. /**
  35. * Delete comment statistics records for an entity.
  36. *
  37. * @param \Drupal\Core\Entity\EntityInterface $entity
  38. * The entity for which comment statistics should be deleted.
  39. */
  40. public function delete(EntityInterface $entity);
  41. /**
  42. * Update or insert comment statistics records after a comment is added.
  43. *
  44. * @param \Drupal\comment\CommentInterface $comment
  45. * The comment added or updated.
  46. */
  47. public function update(CommentInterface $comment);
  48. /**
  49. * Find the maximum number of comments for the given entity type.
  50. *
  51. * Used to influence search rankings.
  52. *
  53. * @param string $entity_type
  54. * The entity type to consider when fetching the maximum comment count for.
  55. *
  56. * @return int
  57. * The maximum number of comments for and entity of the given type.
  58. *
  59. * @see comment_update_index()
  60. */
  61. public function getMaximumCount($entity_type);
  62. /**
  63. * Insert an empty record for the given entity.
  64. *
  65. * @param \Drupal\Core\Entity\FieldableEntityInterface $entity
  66. * The created entity for which a statistics record is to be initialized.
  67. * @param array $fields
  68. * Array of comment field definitions for the given entity.
  69. */
  70. public function create(FieldableEntityInterface $entity, $fields);
  71. }