* @copyright Meritoo.pl */ class Surveys extends Collection { /** * {@inheritdoc} */ public function add($element, $index = null) { if (null === $index) { /* @var Survey $element */ $index = $element->getId(); } return parent::add($element, $index); } /** * Returns all or active only surveys * * @param bool $onlyActive (optional) If is set to true, active surveys are returned only. Otherwise - all. * @return $this */ public function getAll($onlyActive = false) { if ($this->isEmpty() || !$onlyActive) { return $this; } $all = new static(); /* @var Survey $survey */ foreach ($this as $survey) { if ($survey->isActive()) { $all->add($survey); } } return $all; } }