Passed
Push — master ( 2c2df9...4d0e35 )
by Karel
06:15
created

MenuItems::getTypeAttribute()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 6
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 4
nc 2
nop 0
dl 0
loc 6
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace Chuckbe\Chuckcms\Models;
4
5
use Chuckbe\Chuckcms\Models\Page;
6
use Eloquent;
7
8
/**
9
 * @property int $id
10
 * @property string $label
11
 * @property string $link
12
 * @property string $class
13
 * @property int $menu
14
 * @property int $sort
15
 * @property int $parent
16
 * @property int $depth
17
 */
18
class MenuItems extends Eloquent
19
{
20
21
    protected $table = null;
22
23
    public function __construct( array $attributes = [] ){
24
        //parent::construct( $attributes );
25
        $this->table = config('menu.table_prefix') . config('menu.table_name_items');
26
    }
27
28
    public function getsons($id) {
29
        return $this -> where("parent", $id) -> get();
30
    }
31
    public function getall($id) {
32
        return $this -> where("menu", $id) -> orderBy("sort", "asc")->get();
33
    }
34
35
    public static function getNextSortRoot($menu){
36
        return self::where('menu',$menu)->max('sort') + 1;
37
    }
38
39
    public function getLinkAttribute()
40
    {
41
        if(strpos($this->attributes['link'], 'page:') !== false ) {
42
            $page_id = explode(':', $this->attributes['link'])[1];
43
            return Page::getUrl($page_id);
44
        } else {
45
            return $this->attributes['link'];
46
        }
47
    }
48
49
    public function getRawLinkAttribute()
50
    {
51
        return $this->attributes['link'];
52
    }
53
54
    public function getTypeAttribute()
55
    {
56
        if(strpos($this->attributes['link'], 'page:') !== false ) {
57
            return 'Page';
58
        } else {
59
            return 'Link';
60
        }
61
    }
62
63
}
64