Completed
Push — master ( 8e6ba3...69e16e )
by Denis
01:13
created
src/Columns/BaseColumn.php 1 patch
Indentation   +161 added lines, -161 removed lines patch added patch discarded remove patch
@@ -9,166 +9,166 @@
 block discarded – undo
9 9
 
10 10
 abstract class BaseColumn
11 11
 {
12
-    use Configurable;
13
-
14
-    /**
15
-     * Column title
16
-     * @var string
17
-     */
18
-    public $title = '';
19
-
20
-    /**
21
-     * Column value. Could be an attribute,
22
-     * @var string|mixed
23
-     */
24
-    public $value = '';
25
-
26
-    /**
27
-     * @var BaseFilter
28
-     */
29
-    public $filter;
30
-
31
-    /**
32
-     * @var boolean|string
33
-     */
34
-    public $sortable = true;
35
-
36
-    /**
37
-     * @var array
38
-     */
39
-    public $headerHtmlOptions = [];
40
-
41
-    /**
42
-     * @var array
43
-     */
44
-    public $contentHtmlOptions = [];
45
-
46
-    /**
47
-     * @var array - allowed: raw, url, email, text, image
48
-     */
49
-    public $formatters = ['text'];
50
-
51
-    /**
52
-     * Value when column is empty
53
-     * @var string
54
-     */
55
-    public $emptyValue = '-';
56
-
57
-    /**
58
-     * BaseColumn constructor.
59
-     * @param array $config
60
-     * @throws \Woo\GridView\Exceptions\GridViewConfigException
61
-     */
62
-    public function __construct(array $config)
63
-    {
64
-        $this->loadConfig($config);
65
-
66
-        $this->buildFilter();
67
-    }
68
-
69
-    /**
70
-     * Allows to get sortable column's name
71
-     */
72
-    public function getSortableName()
73
-    {
74
-        if ($this->sortable === false) {
75
-            return false;
76
-        }
77
-
78
-        if (!is_bool($this->sortable)) {
79
-            return $this->sortable;
80
-        }
81
-
82
-        if (is_scalar($this->value)) {
83
-            return $this->value;
84
-        }
85
-
86
-        return false;
87
-    }
88
-
89
-    protected function buildFilter()
90
-    {
91
-        if (is_null($this->filter) || is_object($this->filter)) {
92
-            return;
93
-        }
94
-
95
-        if (is_string($this->filter)) {
96
-            $this->filter = [
97
-                'class' => $this->filter,
98
-                'name' => $this->value,
99
-            ];
100
-        }
101
-
102
-        if (empty($this->filter['class'])) {
103
-            $this->filter['class'] = TextFilter::class;
104
-        }
105
-
106
-        if (empty($this->filter['name'])) {
107
-            $this->filter['name'] = $this->value;
108
-        }
109
-
110
-        $className = GridViewHelper::resolveAlias('filter', $this->filter['class']);
111
-        $this->filter = new $className($this->filter);
112
-    }
113
-
114
-    /**
115
-     * @return array
116
-     */
117
-    protected function configTests(): array
118
-    {
119
-        return [
120
-            'title' => 'string',
121
-            'value' => 'any',
122
-            'headerHtmlOptions' => 'array',
123
-            'contentHtmlOptions' => 'array',
124
-            'formatters' => 'array',
125
-            'emptyValue' => 'string',
126
-            'sortable' => 'any',
127
-            'filter' => BaseFilter::class . '|null',
128
-        ];
129
-    }
130
-
131
-    /**
132
-     * Formatted header html options
133
-     * @return string
134
-     */
135
-    public function compileHeaderHtmlOptions() : string
136
-    {
137
-        return GridViewHelper::htmlOptionsToString($this->headerHtmlOptions);
138
-    }
139
-
140
-    /**
141
-     * Formatted content html options
142
-     * @param array $context
143
-     * @return string
144
-     */
145
-    public function compileContentHtmlOptions(array $context) : string
146
-    {
147
-        return GridViewHelper::htmlOptionsToString($this->contentHtmlOptions, $context);
148
-    }
149
-
150
-    /**
151
-     * Render column value for row
152
-     * @param array|object $row
153
-     * @return string|mixed
154
-     */
155
-    protected abstract function _renderValue($row);
156
-
157
-    /**
158
-     * Renders column content
159
-     * @param $row
160
-     * @return string
161
-     */
162
-    public function renderValue($row)
163
-    {
164
-        $value = $this->_renderValue($row);
165
-
166
-        foreach ($this->formatters as $formatter) {
167
-            $className = GridViewHelper::resolveAlias('formatter', $formatter);
168
-            $value = (new $className)->format($value);
169
-        }
170
-
171
-        return $value;
172
-    }
12
+	use Configurable;
13
+
14
+	/**
15
+	 * Column title
16
+	 * @var string
17
+	 */
18
+	public $title = '';
19
+
20
+	/**
21
+	 * Column value. Could be an attribute,
22
+	 * @var string|mixed
23
+	 */
24
+	public $value = '';
25
+
26
+	/**
27
+	 * @var BaseFilter
28
+	 */
29
+	public $filter;
30
+
31
+	/**
32
+	 * @var boolean|string
33
+	 */
34
+	public $sortable = true;
35
+
36
+	/**
37
+	 * @var array
38
+	 */
39
+	public $headerHtmlOptions = [];
40
+
41
+	/**
42
+	 * @var array
43
+	 */
44
+	public $contentHtmlOptions = [];
45
+
46
+	/**
47
+	 * @var array - allowed: raw, url, email, text, image
48
+	 */
49
+	public $formatters = ['text'];
50
+
51
+	/**
52
+	 * Value when column is empty
53
+	 * @var string
54
+	 */
55
+	public $emptyValue = '-';
56
+
57
+	/**
58
+	 * BaseColumn constructor.
59
+	 * @param array $config
60
+	 * @throws \Woo\GridView\Exceptions\GridViewConfigException
61
+	 */
62
+	public function __construct(array $config)
63
+	{
64
+		$this->loadConfig($config);
65
+
66
+		$this->buildFilter();
67
+	}
68
+
69
+	/**
70
+	 * Allows to get sortable column's name
71
+	 */
72
+	public function getSortableName()
73
+	{
74
+		if ($this->sortable === false) {
75
+			return false;
76
+		}
77
+
78
+		if (!is_bool($this->sortable)) {
79
+			return $this->sortable;
80
+		}
81
+
82
+		if (is_scalar($this->value)) {
83
+			return $this->value;
84
+		}
85
+
86
+		return false;
87
+	}
88
+
89
+	protected function buildFilter()
90
+	{
91
+		if (is_null($this->filter) || is_object($this->filter)) {
92
+			return;
93
+		}
94
+
95
+		if (is_string($this->filter)) {
96
+			$this->filter = [
97
+				'class' => $this->filter,
98
+				'name' => $this->value,
99
+			];
100
+		}
101
+
102
+		if (empty($this->filter['class'])) {
103
+			$this->filter['class'] = TextFilter::class;
104
+		}
105
+
106
+		if (empty($this->filter['name'])) {
107
+			$this->filter['name'] = $this->value;
108
+		}
109
+
110
+		$className = GridViewHelper::resolveAlias('filter', $this->filter['class']);
111
+		$this->filter = new $className($this->filter);
112
+	}
113
+
114
+	/**
115
+	 * @return array
116
+	 */
117
+	protected function configTests(): array
118
+	{
119
+		return [
120
+			'title' => 'string',
121
+			'value' => 'any',
122
+			'headerHtmlOptions' => 'array',
123
+			'contentHtmlOptions' => 'array',
124
+			'formatters' => 'array',
125
+			'emptyValue' => 'string',
126
+			'sortable' => 'any',
127
+			'filter' => BaseFilter::class . '|null',
128
+		];
129
+	}
130
+
131
+	/**
132
+	 * Formatted header html options
133
+	 * @return string
134
+	 */
135
+	public function compileHeaderHtmlOptions() : string
136
+	{
137
+		return GridViewHelper::htmlOptionsToString($this->headerHtmlOptions);
138
+	}
139
+
140
+	/**
141
+	 * Formatted content html options
142
+	 * @param array $context
143
+	 * @return string
144
+	 */
145
+	public function compileContentHtmlOptions(array $context) : string
146
+	{
147
+		return GridViewHelper::htmlOptionsToString($this->contentHtmlOptions, $context);
148
+	}
149
+
150
+	/**
151
+	 * Render column value for row
152
+	 * @param array|object $row
153
+	 * @return string|mixed
154
+	 */
155
+	protected abstract function _renderValue($row);
156
+
157
+	/**
158
+	 * Renders column content
159
+	 * @param $row
160
+	 * @return string
161
+	 */
162
+	public function renderValue($row)
163
+	{
164
+		$value = $this->_renderValue($row);
165
+
166
+		foreach ($this->formatters as $formatter) {
167
+			$className = GridViewHelper::resolveAlias('formatter', $formatter);
168
+			$value = (new $className)->format($value);
169
+		}
170
+
171
+		return $value;
172
+	}
173 173
 
174 174
 }
Please login to merge, or discard this patch.