<?php declare(strict_types=1);
/**
* @copyright 2020 Crehler Sp. z o. o. <https://crehler.com>
*
* @author Jakub MedyĆski <jme@crehler.com>
* @support Crehler <support@crehler.com>
* @created 14 maj 2020
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Crehler\ShoppingList\ShoppingList;
use Shopware\Core\Framework\DataAbstractionLayer\EntityCollection;
/**
* @method void add(ShoppingListEntity $entity)
* @method void set(string $key, ShoppingListEntity $entity)
* @method ShoppingListEntity[] getIterator()
* @method ShoppingListEntity[] getElements()
* @method ShoppingListEntity|null get(string $key)
* @method ShoppingListEntity|null first()
* @method ShoppingListEntity|null last()
*/
class ShoppingListCollection extends EntityCollection
{
protected function getExpectedClass(): string
{
return ShoppingListEntity::class;
}
public function sortByLatest(): void
{
$this->sort(function (ShoppingListEntity $a, ShoppingListEntity $b) {
$aTime = $a->getUpdatedAt() ?? $a->getCreatedAt();
$bTime = $b->getUpdatedAt() ?? $b->getCreatedAt();
return $aTime < $bTime;
});
}
}