$collection */ public function __construct( private OrmCollection $collection, private ?int $total = null ) {} /** * Get a total number of records in DB (that matches applied search parameters). */ public function getTotal(): ?int { return $this->total; } /** * Get an ORM collection. * * @return OrmCollection */ public function getCollection(): OrmCollection { return $this->collection; } /** * Get a value map list. * * @return stdClass[] */ public function getValueMapList(): array { if ( $this->collection instanceof EntityCollection && !$this->collection->getEntityType() ) { $list = []; foreach ($this->collection as $e) { $item = $e->getValueMap(); $item->_scope = $e->getEntityType(); $list[] = $item; } return $list; } return $this->collection->getValueMapList(); } /** * Create. * * @template CEntity of \Espo\ORM\Entity * @param OrmCollection $collection * @return self */ public static function create(OrmCollection $collection, ?int $total = null): self { return new self($collection, $total); } /** * Create w/o count. * * @template CEntity of \Espo\ORM\Entity * @param OrmCollection $collection * @return self */ public static function createNoCount(OrmCollection $collection, ?int $maxSize): self { if ( $maxSize !== null && $collection instanceof EntityCollection && count($collection) > $maxSize ) { $copyCollection = new EntityCollection([...$collection], $collection->getEntityType()); unset($copyCollection[count($copyCollection) - 1]); return new self($copyCollection, self::TOTAL_HAS_MORE); } return new self($collection, self::TOTAL_HAS_NO_MORE); } }