| @@ 781-828 (lines=48) @@ | ||
| 778 | * Set the Prev and Next event |
|
| 779 | * @return $this |
|
| 780 | */ |
|
| 781 | public function setPrevNext() |
|
| 782 | { |
|
| 783 | if ($this->prevEvent && $this->nextEvent) { |
|
| 784 | return $this; |
|
| 785 | } |
|
| 786 | $entries = $this->entries(); |
|
| 787 | ||
| 788 | $isPrev = false; |
|
| 789 | $isNext = false; |
|
| 790 | $firstEvent = false; |
|
| 791 | $lastEvent = false; |
|
| 792 | ||
| 793 | foreach ($entries as $event) { |
|
| 794 | // Obtain th first event. |
|
| 795 | if (!$firstEvent) { |
|
| 796 | $firstEvent = $event; |
|
| 797 | } |
|
| 798 | $lastEvent = $event; |
|
| 799 | // Find the current event |
|
| 800 | if ($event->id() == $this->currentEvent()['id']) { |
|
| 801 | $isNext = true; |
|
| 802 | $isPrev = true; |
|
| 803 | ||
| 804 | continue; |
|
| 805 | } |
|
| 806 | if (!$isPrev) { |
|
| 807 | $this->prevEvent = $event; |
|
| 808 | } |
|
| 809 | // Store the next event |
|
| 810 | if ($isNext) { |
|
| 811 | $this->nextEvent = $event; |
|
| 812 | ||
| 813 | $isNext = false; |
|
| 814 | } |
|
| 815 | } |
|
| 816 | ||
| 817 | if ($this->entryCycle()) { |
|
| 818 | if (!$this->nextEvent) { |
|
| 819 | $this->nextEvent = $firstEvent; |
|
| 820 | } |
|
| 821 | ||
| 822 | if (!$this->prevEvent) { |
|
| 823 | $this->prevEvent = $lastEvent; |
|
| 824 | } |
|
| 825 | } |
|
| 826 | ||
| 827 | return $this; |
|
| 828 | } |
|
| 829 | ||
| 830 | /** |
|
| 831 | * Mapping between events and dates |
|
| @@ 566-614 (lines=49) @@ | ||
| 563 | * Set the Prev and Next news |
|
| 564 | * @return $this |
|
| 565 | */ |
|
| 566 | public function setPrevNext() |
|
| 567 | { |
|
| 568 | if ($this->nextNews && $this->prevNews) { |
|
| 569 | return $this; |
|
| 570 | } |
|
| 571 | $entries = $this->entries(); |
|
| 572 | ||
| 573 | $isPrev = false; |
|
| 574 | $isNext = false; |
|
| 575 | $firstNews = false; |
|
| 576 | $lastNews = false; |
|
| 577 | ||
| 578 | /** @var NewsInterface $news */ |
|
| 579 | foreach ($entries as $news) { |
|
| 580 | // Obtain th first news. |
|
| 581 | if (!$firstNews) { |
|
| 582 | $firstNews = $news; |
|
| 583 | } |
|
| 584 | $lastNews = $news; |
|
| 585 | // Find the current news |
|
| 586 | if ($news->id() == $this->currentNews()['id']) { |
|
| 587 | $isNext = true; |
|
| 588 | $isPrev = true; |
|
| 589 | ||
| 590 | continue; |
|
| 591 | } |
|
| 592 | if (!$isPrev) { |
|
| 593 | $this->prevNews = $news; |
|
| 594 | } |
|
| 595 | // Store the next news |
|
| 596 | if ($isNext) { |
|
| 597 | $this->nextNews = $news; |
|
| 598 | ||
| 599 | $isNext = false; |
|
| 600 | } |
|
| 601 | } |
|
| 602 | ||
| 603 | if ($this->entryCycle()) { |
|
| 604 | if (!$this->nextNews) { |
|
| 605 | $this->nextNews = $firstNews; |
|
| 606 | } |
|
| 607 | ||
| 608 | if (!$this->prevNews) { |
|
| 609 | $this->prevNews = $lastNews; |
|
| 610 | } |
|
| 611 | } |
|
| 612 | ||
| 613 | return $this; |
|
| 614 | } |
|
| 615 | } |
|
| 616 | ||