PrevNextSiblingExtension::PreviousSibling()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 2
c 0
b 0
f 0
dl 0
loc 4
rs 10
cc 1
nc 1
nop 0
1
<?php
2
3
namespace WebOfTalent\PrevNextSibling;
4
5
use SilverStripe\CMS\Model\SiteTree;
6
use SilverStripe\Core\Extension;
7
8
class PrevNextSiblingExtension extends Extension
9
{
10
    public function NextSibling()
11
    {
12
        $where = "\"ParentID\" = {$this->owner->ParentID} AND \"Sort\" > {$this->owner->Sort}";
13
        $result = SiteTree::get()->where($where)->sort('"Sort"')->First();
14
        return $result;
15
    }
16
17
    public function PreviousSibling()
18
    {
19
        $where = "\"ParentID\" = {$this->owner->ParentID} AND \"Sort\" < {$this->owner->Sort}";
20
        return SiteTree::get()->where($where)->sort('"Sort" DESC')->First();
21
    }
22
}
23