Completed
Push — master ( a21e1b...e6e660 )
by Pavel
02:28
created

Row::getId()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 4
rs 10
cc 1
eloc 2
nc 1
nop 0
1
<?php
2
3
/**
4
 * @copyright   Copyright (c) 2015 ublaboo <[email protected]>
5
 * @author      Pavel Janda <[email protected]>
6
 * @package     Ublaboo
7
 */
8
9
namespace Ublaboo\DataGrid;
10
11
use Nette;
12
13
class Row extends Nette\Object
14
{
15
16
	/**
17
	 * @var DataGrid
18
	 */
19
	protected $datagrid;
20
21
	/**
22
	 * @var mixed
23
	 */
24
	protected $item;
25
26
	/**
27
	 * @var string
28
	 */
29
	protected $primary_key;
30
31
	/**
32
	 * @var mixed
33
	 */
34
	protected $id;
35
36
37
	/**
38
	 * @param mixed  $item
39
	 * @param string $primary_key
40
	 */
41
	public function __construct(DataGrid $datagrid, $item, $primary_key)
42
	{
43
		$this->datagrid = $datagrid;
44
		$this->item = $item;
45
		$this->primary_key = $primary_key;
46
47
		$this->id = is_object($item) ? $item->{$primary_key} : $item[$primary_key];
48
	}
49
50
51
	/**
52
	 * Get id value of item
53
	 * @return mixed
54
	 */
55
	public function getId()
56
	{
57
		return $this->id;
58
	}
59
60
61
	/**
62
	 * Get original item
63
	 * @return mixed
64
	 */
65
	public function getItem()
66
	{
67
		return $this->item;
68
	}
69
70
71
	public function hasGroupAction()
72
	{
73
		$condition = $this->datagrid->getRowCondition('group_action');
74
75
		return $condition ? $condition($this->item) : TRUE;
76
	}
77
78
79
	public function hasAction($key)
80
	{
81
		$condition = $this->datagrid->getRowCondition('action', $key);
82
83
		return $condition ? $condition($this->item) : TRUE;
84
	}
85
86
}
87