Completed
Pull Request — master (#155)
by
unknown
03:10
created

DataRow::src()   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
namespace Nayjest\Grids;
3
4
/**
5
 * Class DataRow
6
 *
7
 * Abstract class for DataRowInterface implementations
8
 *
9
 * @package Nayjest\Grids
10
 */
11
abstract class DataRow implements DataRowInterface
12
{
13
14
    /** @var  mixed row data */
15
    protected $src;
16
17
    /** @var int row id */
18
    protected $id;
19
20
    /**
21
     * Constructor.
22
     *
23
     * @param $src
24
     * @param int $id
25
     */
26
    public function __construct($src, $id)
27
    {
28
        $this->src = $src;
29
        $this->id = $id;
30
    }
31
32
    /**
33
     * Returns row id.
34
     *
35
     * It's row number starting from 1, considering pagination.
36
     *
37
     * @return mixed
38
     */
39
    public function getId()
40
    {
41
        return $this->id;
42
    }
43
44
    /**
45
     * Returns row data source.
46
     *
47
     * @return mixed
48
     */
49
    public function getSrc()
50
    {
51
        return $this->src;
52
    }
53
54
    /**
55
     * Returns row data source.
56
     *
57
     * @return mixed
58
     */
59
    public function src()
60
    {
61
        return $this->getSrc();
62
    }
63
64
    /**
65
     * Returns value for specified column.
66
     *
67
     * @param string $fieldName
68
     * @return mixed
69
     */
70
    abstract protected function extractCellValue($fieldName);
71
72
    /**
73
     * Returns value of specified column from row.
74
     *
75
     * @param FieldConfig|string $field
76
     * @return mixed
77
     */
78
    public function getCellValue($field)
79
    {
80
        $fieldName = $field instanceof FieldConfig ? $field->getName() : $field;
81
        return $this->extractCellValue($fieldName);
82
    }
83
}
84