Completed
Push — master ( 144202...6a00f8 )
by Peter
11:59
created

SortAwareTrait::getModel()

Size

Total Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 1
ccs 0
cts 0
cp 0
nc 1
1
<?php
2
3
/*
4
 * To change this license header, choose License Headers in Project Properties.
5
 * To change this template file, choose Tools | Templates
6
 * and open the template in the editor.
7
 */
8
9
namespace Maslosoft\Mangan\Traits;
10
11
use Maslosoft\Mangan\Interfaces\SortInterface;
12
use Maslosoft\Mangan\Sort;
13
14
/**
15
 * SortAwareTrait
16
 *
17
 * @author Piotr Maselkowski <pmaselkowski at gmail.com>
18
 */
19
trait SortAwareTrait
20
{
21
22
	/**
23
	 * @var SortInterface
24
	 */
25
	private $sort;
26
27
	/**
28
	 * Returns the sort object.
29
	 * @return Sort the sorting object. If this is false, it means the sorting is disabled.
30
	 */
31 1
	public function getSort()
32
	{
33 1
		if ($this->sort === null)
34 1
		{
35 1
			$this->sort = new Sort;
36 1
			$this->sort->setModel($this->getModel());
37 1
		}
38 1
		return $this->sort;
39
	}
40
41
	/**
42
	 * Set sort
43
	 * @param SortInterface $sort
44
	 * @return static
45
	 */
46
	public function setSort(SortInterface $sort)
47
	{
48
		$this->sort = $sort;
49
		$this->sort->setModel($this->getModel());
50
		return $this;
51
	}
52
53
	abstract public function getModel();
54
}
55