Friendica Communications Platform (please note that this is a clone of the repository at github, issues are handled there) https://friendi.ca
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

38 lines
890 B

  1. <?php
  2. namespace Friendica;
  3. /**
  4. * The Collection classes inheriting from this abstract class are meant to represent a list of database record.
  5. * The associated model class has to be provided in the child classes.
  6. *
  7. * Collections can be used with foreach(), accessed like an array and counted.
  8. */
  9. abstract class BaseCollection extends \ArrayIterator
  10. {
  11. /**
  12. * This property is used with paginated results to hold the total number of items satisfying the paginated request.
  13. * @var int
  14. */
  15. protected $totalCount = 0;
  16. /**
  17. * @param BaseModel[] $models
  18. * @param int|null $totalCount
  19. */
  20. public function __construct(array $models = [], int $totalCount = null)
  21. {
  22. parent::__construct($models);
  23. $this->models = $models;
  24. $this->totalCount = $totalCount ?? count($models);
  25. }
  26. /**
  27. * @return int
  28. */
  29. public function getTotalCount()
  30. {
  31. return $this->totalCount;
  32. }
  33. }