1: <?php
2: /**
3: * This file is part of the FastFeed package.
4: *
5: * (c) Daniel González <daniel@desarrolla2.com>
6: *
7: * For the full copyright and license information, please view the LICENSE
8: * file that was distributed with this source code.
9: */
10: namespace FastFeed\Processor;
11:
12: /**
13: * SortByDateProcessor
14: * Sort
15: */
16: class SortByDateProcessor implements ProcessorInterface
17: {
18: /**
19: * Execute processor
20: *
21: * @param array $items
22: *
23: * @return array
24: */
25: public function process(array $items)
26: {
27: $total = count($items);
28: for ($i = 1; $i < $total; $i++) {
29: for ($j = 0; $j < $total - $i; $j++) {
30: if (!$items[$j]->getDate() || !$items[$j + 1]->getDate()) {
31: continue;
32: }
33: if ($items[$j]->getDate()->getTimestamp() > $items[$j + 1]->getDate()->getTimestamp()) {
34: continue;
35: }
36: $aux = $items[$j + 1];
37: $items[$j + 1] = $items[$j];
38: $items[$j] = $aux;
39: }
40: }
41:
42: return $items;
43: }
44: }
45: