/** * Add a model to a collection * * @param \Model $objModel * @param \Model\Collection|null $objCollection * * @return \Model\Collection|null */ public static function addModelToCollection(\Model $objModel, \Model\Collection $objCollection = null) { $arrRegistered = array(); if ($objCollection !== null) { while ($objCollection->next()) { if ($objCollection->getTable() !== $objModel->getTable) { return $objCollection; } $intId = $objCollection->{$objModel::getPk()}; $arrRegistered[$intId] = $objCollection->current(); } } $arrRegistered[$objModel->{$objModel::getPk()}] = $objModel; return static::createCollection(array_filter(array_values($arrRegistered)), $objModel->getTable()); }