FastFeed\Processor\SortByDateProcessor::process PHP Method

process() public method

Execute processor
public process ( array $items ) : array
$items array
return array
    public function process(array $items)
    {
        $total = count($items);
        for ($i = 1; $i < $total; $i++) {
            for ($j = 0; $j < $total - $i; $j++) {
                if (!$items[$j]->getDate() || !$items[$j + 1]->getDate()) {
                    continue;
                }
                if ($items[$j]->getDate()->getTimestamp() > $items[$j + 1]->getDate()->getTimestamp()) {
                    continue;
                }
                $aux = $items[$j + 1];
                $items[$j + 1] = $items[$j];
                $items[$j] = $aux;
            }
        }
        return $items;
    }

Usage Example

 public function testProcess()
 {
     $this->items[0] = new Item();
     $this->items[1] = new Item();
     $this->items[2] = new Item();
     $this->items[3] = new Item();
     $date0 = new DateTime();
     $date1 = new DateTime();
     $date0->modify('-1 day');
     $this->items[0]->setDate($date0);
     $this->items[1]->setDate($date1);
     $this->items[2]->setDate($date0);
     $this->items = $this->processor->process($this->items);
     $this->assertEquals($this->items[0]->getDate(), $date1);
 }
SortByDateProcessor