@@ -7,5 +7,5 @@ |
||
7 | 7 | * @throws \Woo\GridView\Exceptions\GridViewConfigException |
8 | 8 | */ |
9 | 9 | function grid(array $config) { |
10 | - return (new \Woo\GridView\GridView($config))->render(); |
|
10 | + return (new \Woo\GridView\GridView($config))->render(); |
|
11 | 11 | } |
12 | 12 | \ No newline at end of file |
@@ -7,88 +7,88 @@ |
||
7 | 7 | |
8 | 8 | trait Configurable |
9 | 9 | { |
10 | - /** |
|
11 | - * Allows to load config into object properties |
|
12 | - * @param array $config |
|
13 | - * @throws GridViewConfigException |
|
14 | - */ |
|
15 | - public function loadConfig(array $config) |
|
16 | - { |
|
17 | - foreach ($config as $key => $value) { |
|
18 | - |
|
19 | - if (property_exists($this, $key)) { |
|
20 | - $this->$key = $value; |
|
21 | - } |
|
22 | - } |
|
23 | - |
|
24 | - $this->testConfig(); |
|
25 | - } |
|
26 | - |
|
27 | - /** |
|
28 | - * Should specify tests |
|
29 | - * @return array |
|
30 | - */ |
|
31 | - abstract protected function configTests() : array; |
|
32 | - |
|
33 | - /** |
|
34 | - * Allows to test attributes and types in config |
|
35 | - * @throws GridViewConfigException |
|
36 | - */ |
|
37 | - protected function testConfig() |
|
38 | - { |
|
39 | - foreach ($this->configTests() as $property => $tests) { |
|
40 | - |
|
41 | - if (!property_exists($this, $property)) { |
|
42 | - throw new GridViewConfigException( |
|
43 | - 'Unable to test ' . get_class($this) . ': property ' . $property . ' does not exist' |
|
44 | - ); |
|
45 | - } |
|
46 | - |
|
47 | - $testPassed = true; |
|
48 | - $testMessage = 'Validation failed'; |
|
49 | - |
|
50 | - foreach (explode('|', $tests) as $test) { |
|
51 | - |
|
52 | - switch ($test) { |
|
53 | - case 'int': |
|
54 | - $testPassed = is_numeric($this->$property); |
|
55 | - $testMessage = 'Property should be numeric'; |
|
56 | - break; |
|
57 | - |
|
58 | - case 'string': |
|
59 | - $testPassed = is_string($this->$property); |
|
60 | - $testMessage = 'Property should be a string'; |
|
61 | - break; |
|
62 | - |
|
63 | - case 'array': |
|
64 | - $testPassed = is_array($this->$property); |
|
65 | - $testMessage = 'Property should be an array'; |
|
66 | - break; |
|
67 | - |
|
68 | - case 'closure': |
|
69 | - $testPassed = $this->$property instanceof Closure; |
|
70 | - $testMessage = 'Property should be a valid callback (Closure instance)'; |
|
71 | - break; |
|
72 | - |
|
73 | - case 'boolean': |
|
74 | - $testPassed = is_bool($this->$property); |
|
75 | - $testMessage = 'Property should be boolean'; |
|
76 | - break; |
|
77 | - |
|
78 | - case 'any': |
|
79 | - break; |
|
80 | - |
|
81 | - default: |
|
82 | - $testPassed = $testPassed || is_a($this->$property, $test) || is_subclass_of($this->$property, $test); |
|
83 | - $testMessage = 'Property should be ' . $test . ' instance/class reference, check ' . $property; |
|
84 | - } |
|
85 | - } |
|
86 | - |
|
87 | - if (!$testPassed) { |
|
88 | - throw new GridViewConfigException( |
|
89 | - 'Tests ' . $tests . ' has failed on ' . get_class($this) . '::' . $property . ': ' . $testMessage |
|
90 | - ); |
|
91 | - } |
|
92 | - } |
|
93 | - } |
|
10 | + /** |
|
11 | + * Allows to load config into object properties |
|
12 | + * @param array $config |
|
13 | + * @throws GridViewConfigException |
|
14 | + */ |
|
15 | + public function loadConfig(array $config) |
|
16 | + { |
|
17 | + foreach ($config as $key => $value) { |
|
18 | + |
|
19 | + if (property_exists($this, $key)) { |
|
20 | + $this->$key = $value; |
|
21 | + } |
|
22 | + } |
|
23 | + |
|
24 | + $this->testConfig(); |
|
25 | + } |
|
26 | + |
|
27 | + /** |
|
28 | + * Should specify tests |
|
29 | + * @return array |
|
30 | + */ |
|
31 | + abstract protected function configTests() : array; |
|
32 | + |
|
33 | + /** |
|
34 | + * Allows to test attributes and types in config |
|
35 | + * @throws GridViewConfigException |
|
36 | + */ |
|
37 | + protected function testConfig() |
|
38 | + { |
|
39 | + foreach ($this->configTests() as $property => $tests) { |
|
40 | + |
|
41 | + if (!property_exists($this, $property)) { |
|
42 | + throw new GridViewConfigException( |
|
43 | + 'Unable to test ' . get_class($this) . ': property ' . $property . ' does not exist' |
|
44 | + ); |
|
45 | + } |
|
46 | + |
|
47 | + $testPassed = true; |
|
48 | + $testMessage = 'Validation failed'; |
|
49 | + |
|
50 | + foreach (explode('|', $tests) as $test) { |
|
51 | + |
|
52 | + switch ($test) { |
|
53 | + case 'int': |
|
54 | + $testPassed = is_numeric($this->$property); |
|
55 | + $testMessage = 'Property should be numeric'; |
|
56 | + break; |
|
57 | + |
|
58 | + case 'string': |
|
59 | + $testPassed = is_string($this->$property); |
|
60 | + $testMessage = 'Property should be a string'; |
|
61 | + break; |
|
62 | + |
|
63 | + case 'array': |
|
64 | + $testPassed = is_array($this->$property); |
|
65 | + $testMessage = 'Property should be an array'; |
|
66 | + break; |
|
67 | + |
|
68 | + case 'closure': |
|
69 | + $testPassed = $this->$property instanceof Closure; |
|
70 | + $testMessage = 'Property should be a valid callback (Closure instance)'; |
|
71 | + break; |
|
72 | + |
|
73 | + case 'boolean': |
|
74 | + $testPassed = is_bool($this->$property); |
|
75 | + $testMessage = 'Property should be boolean'; |
|
76 | + break; |
|
77 | + |
|
78 | + case 'any': |
|
79 | + break; |
|
80 | + |
|
81 | + default: |
|
82 | + $testPassed = $testPassed || is_a($this->$property, $test) || is_subclass_of($this->$property, $test); |
|
83 | + $testMessage = 'Property should be ' . $test . ' instance/class reference, check ' . $property; |
|
84 | + } |
|
85 | + } |
|
86 | + |
|
87 | + if (!$testPassed) { |
|
88 | + throw new GridViewConfigException( |
|
89 | + 'Tests ' . $tests . ' has failed on ' . get_class($this) . '::' . $property . ': ' . $testMessage |
|
90 | + ); |
|
91 | + } |
|
92 | + } |
|
93 | + } |
|
94 | 94 | } |
95 | 95 | \ No newline at end of file |
@@ -4,8 +4,8 @@ |
||
4 | 4 | |
5 | 5 | class BooleanFormatter implements IFormatter |
6 | 6 | { |
7 | - public function format($value): string |
|
8 | - { |
|
9 | - return $value ? 'Yes' : 'No'; |
|
10 | - } |
|
7 | + public function format($value): string |
|
8 | + { |
|
9 | + return $value ? 'Yes' : 'No'; |
|
10 | + } |
|
11 | 11 | } |
12 | 12 | \ No newline at end of file |
@@ -4,8 +4,8 @@ |
||
4 | 4 | |
5 | 5 | class RawFormatter implements IFormatter |
6 | 6 | { |
7 | - public function format($value): string |
|
8 | - { |
|
9 | - return $value; |
|
10 | - } |
|
7 | + public function format($value): string |
|
8 | + { |
|
9 | + return $value; |
|
10 | + } |
|
11 | 11 | } |
12 | 12 | \ No newline at end of file |
@@ -4,31 +4,31 @@ |
||
4 | 4 | |
5 | 5 | class CallbackColumn extends BaseColumn |
6 | 6 | { |
7 | - /** |
|
8 | - * @var string |
|
9 | - */ |
|
10 | - public $formatters = ['raw']; |
|
7 | + /** |
|
8 | + * @var string |
|
9 | + */ |
|
10 | + public $formatters = ['raw']; |
|
11 | 11 | |
12 | - /** |
|
13 | - * @var bool |
|
14 | - */ |
|
15 | - public $sortable = false; |
|
12 | + /** |
|
13 | + * @var bool |
|
14 | + */ |
|
15 | + public $sortable = false; |
|
16 | 16 | |
17 | - /** |
|
18 | - * @return array |
|
19 | - */ |
|
20 | - protected function configTests(): array |
|
21 | - { |
|
22 | - return array_merge(parent::configTests(), [ |
|
23 | - 'value' => 'closure', |
|
24 | - ]); |
|
25 | - } |
|
17 | + /** |
|
18 | + * @return array |
|
19 | + */ |
|
20 | + protected function configTests(): array |
|
21 | + { |
|
22 | + return array_merge(parent::configTests(), [ |
|
23 | + 'value' => 'closure', |
|
24 | + ]); |
|
25 | + } |
|
26 | 26 | |
27 | - /** |
|
28 | - * @inheritdoc |
|
29 | - */ |
|
30 | - public function _renderValue($row) |
|
31 | - { |
|
32 | - return call_user_func($this->value, $row); |
|
33 | - } |
|
27 | + /** |
|
28 | + * @inheritdoc |
|
29 | + */ |
|
30 | + public function _renderValue($row) |
|
31 | + { |
|
32 | + return call_user_func($this->value, $row); |
|
33 | + } |
|
34 | 34 | } |
35 | 35 | \ No newline at end of file |
@@ -23,144 +23,144 @@ |
||
23 | 23 | |
24 | 24 | class GridViewHelper |
25 | 25 | { |
26 | - /** |
|
27 | - * A list of grid aliases |
|
28 | - * @var array |
|
29 | - */ |
|
30 | - private static $aliases = [ |
|
31 | - 'column' => [ |
|
32 | - 'attribute' => AttributeColumn::class, |
|
33 | - 'raw' => CallbackColumn::class, |
|
34 | - 'callback' => CallbackColumn::class, |
|
35 | - 'actions' => ActionsColumn::class, |
|
36 | - 'view' => ViewColumn::class, |
|
37 | - ], |
|
38 | - 'formatter' => [ |
|
39 | - 'email' => EmailFormatter::class, |
|
40 | - 'image' => ImageFormatter::class, |
|
41 | - 'text' => TextFormatter::class, |
|
42 | - 'url' => UrlFormatter::class, |
|
43 | - 'raw' => RawFormatter::class, |
|
44 | - ], |
|
45 | - 'filter' => [ |
|
46 | - 'text' => TextFilter::class, |
|
47 | - 'dropdown' => DropdownFilter::class, |
|
48 | - ], |
|
49 | - 'renderer' => [ |
|
50 | - 'default' => DefaultRenderer::class, |
|
51 | - ], |
|
52 | - 'action' => [ |
|
53 | - 'delete' => DeleteAction::class, |
|
54 | - 'update' => EditAction::class, |
|
55 | - 'edit' => EditAction::class, |
|
56 | - 'show' => ShowAction::class, |
|
57 | - 'view' => ShowAction::class, |
|
58 | - 'action' => Action::class, |
|
59 | - ] |
|
60 | - ]; |
|
61 | - |
|
62 | - private function __construct() {} |
|
63 | - |
|
64 | - /** |
|
65 | - * Useful in case you want to register a new alias for your project |
|
66 | - * @param string $context |
|
67 | - * @param string $alias |
|
68 | - * @param string $aliasTo |
|
69 | - */ |
|
70 | - public static function registerAlias(string $context, string $alias, string $aliasTo) |
|
71 | - { |
|
72 | - self::$aliases[$context][$alias] = $aliasTo; |
|
73 | - } |
|
74 | - |
|
75 | - /** |
|
76 | - * Allows to resolve class name by its alias |
|
77 | - * @param string $context |
|
78 | - * @param string $alias |
|
79 | - * @return mixed |
|
80 | - */ |
|
81 | - public static function resolveAlias(string $context, string $alias) |
|
82 | - { |
|
83 | - return self::$aliases[$context][$alias] ?? $alias; |
|
84 | - } |
|
85 | - |
|
86 | - /** |
|
87 | - * Allows to convert options array to html string |
|
88 | - * @param array $htmlOptions |
|
89 | - * @param array $context - context is variables, which are allowed to use when property value calculated dynamically |
|
90 | - * @return string |
|
91 | - */ |
|
92 | - public static function htmlOptionsToString(array $htmlOptions, array $context = []) : string |
|
93 | - { |
|
94 | - if (empty($htmlOptions)) { |
|
95 | - return ''; |
|
96 | - } |
|
97 | - |
|
98 | - $out = []; |
|
99 | - |
|
100 | - foreach ($htmlOptions as $k => $v) { |
|
101 | - |
|
102 | - if ($v instanceof \Closure) { |
|
103 | - $v = call_user_func_array($v, $context); |
|
104 | - } |
|
105 | - |
|
106 | - $out[] = htmlentities($k) . '="' . htmlentities($v, ENT_COMPAT) . '"'; |
|
107 | - } |
|
108 | - |
|
109 | - return implode(' ', $out); |
|
110 | - } |
|
111 | - |
|
112 | - /** |
|
113 | - * Allows to make column title by it key or attribute name |
|
114 | - * @param string|int $key |
|
115 | - * @return string |
|
116 | - */ |
|
117 | - public static function columnTitle($key) : string |
|
118 | - { |
|
119 | - if (is_numeric($key)) { |
|
120 | - return 'Column'; |
|
121 | - } |
|
122 | - |
|
123 | - return ucwords( |
|
124 | - trim( |
|
125 | - preg_replace_callback( |
|
126 | - '/([A-Z]|_|\.)/', |
|
127 | - function($word) { |
|
128 | - $word = $word[0]; |
|
129 | - |
|
130 | - if ($word == '_' || $word == '.') { |
|
131 | - return ' '; |
|
132 | - } |
|
133 | - |
|
134 | - return ' ' . strtolower($word); |
|
135 | - }, |
|
136 | - $key |
|
137 | - ) |
|
138 | - ) |
|
139 | - ); |
|
140 | - } |
|
141 | - |
|
142 | - /** |
|
143 | - * Helper for internal purposes |
|
144 | - * @param $id |
|
145 | - * @param $component |
|
146 | - * @return string |
|
147 | - */ |
|
148 | - public static function gridIdFormatter($id, $component) |
|
149 | - { |
|
150 | - if ($id == 0) { |
|
151 | - return $component; |
|
152 | - } |
|
153 | - |
|
154 | - return 'grid[' . $id . '][' . $component . ']'; |
|
155 | - } |
|
156 | - |
|
157 | - /** |
|
158 | - * Generates page url with all requested params from request |
|
159 | - * @param $gridId |
|
160 | - * @param $page |
|
161 | - */ |
|
162 | - public static function pageUrl($gridId, $page) |
|
163 | - { |
|
164 | - return url()->current() . '?' . Arr::query([\Woo\GridView\GridViewHelper::gridIdFormatter($gridId, 'page') => $page] + request()->query()); |
|
165 | - } |
|
26 | + /** |
|
27 | + * A list of grid aliases |
|
28 | + * @var array |
|
29 | + */ |
|
30 | + private static $aliases = [ |
|
31 | + 'column' => [ |
|
32 | + 'attribute' => AttributeColumn::class, |
|
33 | + 'raw' => CallbackColumn::class, |
|
34 | + 'callback' => CallbackColumn::class, |
|
35 | + 'actions' => ActionsColumn::class, |
|
36 | + 'view' => ViewColumn::class, |
|
37 | + ], |
|
38 | + 'formatter' => [ |
|
39 | + 'email' => EmailFormatter::class, |
|
40 | + 'image' => ImageFormatter::class, |
|
41 | + 'text' => TextFormatter::class, |
|
42 | + 'url' => UrlFormatter::class, |
|
43 | + 'raw' => RawFormatter::class, |
|
44 | + ], |
|
45 | + 'filter' => [ |
|
46 | + 'text' => TextFilter::class, |
|
47 | + 'dropdown' => DropdownFilter::class, |
|
48 | + ], |
|
49 | + 'renderer' => [ |
|
50 | + 'default' => DefaultRenderer::class, |
|
51 | + ], |
|
52 | + 'action' => [ |
|
53 | + 'delete' => DeleteAction::class, |
|
54 | + 'update' => EditAction::class, |
|
55 | + 'edit' => EditAction::class, |
|
56 | + 'show' => ShowAction::class, |
|
57 | + 'view' => ShowAction::class, |
|
58 | + 'action' => Action::class, |
|
59 | + ] |
|
60 | + ]; |
|
61 | + |
|
62 | + private function __construct() {} |
|
63 | + |
|
64 | + /** |
|
65 | + * Useful in case you want to register a new alias for your project |
|
66 | + * @param string $context |
|
67 | + * @param string $alias |
|
68 | + * @param string $aliasTo |
|
69 | + */ |
|
70 | + public static function registerAlias(string $context, string $alias, string $aliasTo) |
|
71 | + { |
|
72 | + self::$aliases[$context][$alias] = $aliasTo; |
|
73 | + } |
|
74 | + |
|
75 | + /** |
|
76 | + * Allows to resolve class name by its alias |
|
77 | + * @param string $context |
|
78 | + * @param string $alias |
|
79 | + * @return mixed |
|
80 | + */ |
|
81 | + public static function resolveAlias(string $context, string $alias) |
|
82 | + { |
|
83 | + return self::$aliases[$context][$alias] ?? $alias; |
|
84 | + } |
|
85 | + |
|
86 | + /** |
|
87 | + * Allows to convert options array to html string |
|
88 | + * @param array $htmlOptions |
|
89 | + * @param array $context - context is variables, which are allowed to use when property value calculated dynamically |
|
90 | + * @return string |
|
91 | + */ |
|
92 | + public static function htmlOptionsToString(array $htmlOptions, array $context = []) : string |
|
93 | + { |
|
94 | + if (empty($htmlOptions)) { |
|
95 | + return ''; |
|
96 | + } |
|
97 | + |
|
98 | + $out = []; |
|
99 | + |
|
100 | + foreach ($htmlOptions as $k => $v) { |
|
101 | + |
|
102 | + if ($v instanceof \Closure) { |
|
103 | + $v = call_user_func_array($v, $context); |
|
104 | + } |
|
105 | + |
|
106 | + $out[] = htmlentities($k) . '="' . htmlentities($v, ENT_COMPAT) . '"'; |
|
107 | + } |
|
108 | + |
|
109 | + return implode(' ', $out); |
|
110 | + } |
|
111 | + |
|
112 | + /** |
|
113 | + * Allows to make column title by it key or attribute name |
|
114 | + * @param string|int $key |
|
115 | + * @return string |
|
116 | + */ |
|
117 | + public static function columnTitle($key) : string |
|
118 | + { |
|
119 | + if (is_numeric($key)) { |
|
120 | + return 'Column'; |
|
121 | + } |
|
122 | + |
|
123 | + return ucwords( |
|
124 | + trim( |
|
125 | + preg_replace_callback( |
|
126 | + '/([A-Z]|_|\.)/', |
|
127 | + function($word) { |
|
128 | + $word = $word[0]; |
|
129 | + |
|
130 | + if ($word == '_' || $word == '.') { |
|
131 | + return ' '; |
|
132 | + } |
|
133 | + |
|
134 | + return ' ' . strtolower($word); |
|
135 | + }, |
|
136 | + $key |
|
137 | + ) |
|
138 | + ) |
|
139 | + ); |
|
140 | + } |
|
141 | + |
|
142 | + /** |
|
143 | + * Helper for internal purposes |
|
144 | + * @param $id |
|
145 | + * @param $component |
|
146 | + * @return string |
|
147 | + */ |
|
148 | + public static function gridIdFormatter($id, $component) |
|
149 | + { |
|
150 | + if ($id == 0) { |
|
151 | + return $component; |
|
152 | + } |
|
153 | + |
|
154 | + return 'grid[' . $id . '][' . $component . ']'; |
|
155 | + } |
|
156 | + |
|
157 | + /** |
|
158 | + * Generates page url with all requested params from request |
|
159 | + * @param $gridId |
|
160 | + * @param $page |
|
161 | + */ |
|
162 | + public static function pageUrl($gridId, $page) |
|
163 | + { |
|
164 | + return url()->current() . '?' . Arr::query([\Woo\GridView\GridViewHelper::gridIdFormatter($gridId, 'page') => $page] + request()->query()); |
|
165 | + } |
|
166 | 166 | } |
@@ -9,166 +9,166 @@ |
||
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 | } |
@@ -15,232 +15,232 @@ |
||
15 | 15 | |
16 | 16 | class GridView |
17 | 17 | { |
18 | - use Configurable; |
|
19 | - |
|
20 | - /** |
|
21 | - * Counter for ids |
|
22 | - * @var int |
|
23 | - */ |
|
24 | - private static $counter = 0; |
|
25 | - |
|
26 | - /** |
|
27 | - * Grid id (used for request handling, for |
|
28 | - * @var int |
|
29 | - */ |
|
30 | - private $id; |
|
31 | - |
|
32 | - /** |
|
33 | - * DataProvider provides gridview with the data for representation |
|
34 | - * @var BaseDataProvider |
|
35 | - */ |
|
36 | - public $dataProvider; |
|
37 | - |
|
38 | - /** |
|
39 | - * Columns config. You may specify array or GridColumn instance |
|
40 | - * @var BaseColumn[] |
|
41 | - */ |
|
42 | - public $columns = []; |
|
43 | - |
|
44 | - /** |
|
45 | - * Common options for all columns, will be appended to all columns configs |
|
46 | - * @var array |
|
47 | - */ |
|
48 | - public $columnOptions = [ |
|
49 | - 'class' => AttributeColumn::class, |
|
50 | - ]; |
|
51 | - |
|
52 | - /** |
|
53 | - * Renders the final UI |
|
54 | - * @var string|BaseRenderer |
|
55 | - */ |
|
56 | - public $renderer = DefaultRenderer::class; |
|
57 | - |
|
58 | - /** |
|
59 | - * Allows to pass some options into renderer/customize rendered behavior |
|
60 | - * @var array |
|
61 | - */ |
|
62 | - public $rendererOptions = []; |
|
63 | - |
|
64 | - /** |
|
65 | - * Controls amount of data per page |
|
66 | - * @var int |
|
67 | - */ |
|
68 | - public $rowsPerPage = 25; |
|
69 | - |
|
70 | - /** |
|
71 | - * Allows to tune the <table> tag with html options |
|
72 | - * @var array |
|
73 | - */ |
|
74 | - public $tableHtmlOptions = [ |
|
75 | - 'class' => 'table table-bordered gridview-table', |
|
76 | - ]; |
|
77 | - |
|
78 | - /** |
|
79 | - * Indicate if filters will be shown or not |
|
80 | - * @var bool |
|
81 | - */ |
|
82 | - public $showFilters = true; |
|
83 | - |
|
84 | - /** |
|
85 | - * Flags allow to change standalone vue to. If false, GridView component should be included in your root Vue instance |
|
86 | - * @var bool |
|
87 | - */ |
|
88 | - public $standaloneVue = true; |
|
89 | - |
|
90 | - /** |
|
91 | - * List of additinal params which'll be added to filter requests |
|
92 | - * @var array |
|
93 | - */ |
|
94 | - public $additionalRequestParams = []; |
|
95 | - |
|
96 | - /** |
|
97 | - * @var Paginator |
|
98 | - */ |
|
99 | - protected $pagination; |
|
100 | - |
|
101 | - /** |
|
102 | - * @var GridViewRequest |
|
103 | - */ |
|
104 | - protected $request; |
|
105 | - |
|
106 | - /** |
|
107 | - * GridView constructor. |
|
108 | - * @param array $config |
|
109 | - * @throws Exceptions\GridViewConfigException |
|
110 | - */ |
|
111 | - public function __construct(array $config) |
|
112 | - { |
|
113 | - $this->id = self::$counter++; |
|
114 | - |
|
115 | - $this->loadConfig($config); |
|
116 | - |
|
117 | - /** |
|
118 | - * Making renderer |
|
119 | - */ |
|
120 | - if (!is_object($this->renderer)) { |
|
121 | - $className = GridViewHelper::resolveAlias('renderer', $this->renderer); |
|
122 | - $this->renderer = new $className(array_merge( |
|
123 | - $this->rendererOptions, [ |
|
124 | - 'gridView' => $this, |
|
125 | - ] |
|
126 | - )); |
|
127 | - } |
|
128 | - |
|
129 | - /** |
|
130 | - * Build columns from config |
|
131 | - */ |
|
132 | - $this->buildColumns(); |
|
133 | - |
|
134 | - $this->request = GridViewRequest::parse($this->id); |
|
135 | - $this->request->perPage = $this->rowsPerPage; |
|
136 | - |
|
137 | - $this->pagination = new LengthAwarePaginator( |
|
138 | - $this->dataProvider->getData($this->request), |
|
139 | - $this->dataProvider->getCount($this->request), |
|
140 | - $this->rowsPerPage, |
|
141 | - $this->request->page |
|
142 | - ); |
|
143 | - } |
|
144 | - |
|
145 | - /** |
|
146 | - * @return array |
|
147 | - */ |
|
148 | - protected function configTests(): array |
|
149 | - { |
|
150 | - return [ |
|
151 | - 'dataProvider' => BaseDataProvider::class, |
|
152 | - 'columns' => 'array', |
|
153 | - 'renderer' => BaseRenderer::class, |
|
154 | - 'rowsPerPage' => 'int', |
|
155 | - 'tableHtmlOptions' => 'array', |
|
156 | - 'showFilters' => 'boolean', |
|
157 | - ]; |
|
158 | - } |
|
159 | - |
|
160 | - /** |
|
161 | - * Build columns into objects |
|
162 | - */ |
|
163 | - protected function buildColumns() |
|
164 | - { |
|
165 | - foreach ($this->columns as $key => &$columnOptions) { |
|
166 | - |
|
167 | - /** |
|
168 | - * In case of when column is already build |
|
169 | - */ |
|
170 | - if (is_object($columnOptions)) { |
|
171 | - continue; |
|
172 | - } |
|
173 | - |
|
174 | - /** |
|
175 | - * When only attribute name/value passed |
|
176 | - */ |
|
177 | - if (is_string($columnOptions)) { |
|
178 | - $columnOptions = [ |
|
179 | - 'value' => $columnOptions, |
|
180 | - ]; |
|
181 | - } |
|
182 | - |
|
183 | - if ($columnOptions instanceof Closure) { |
|
184 | - $columnOptions = [ |
|
185 | - 'class' => CallbackColumn::class, |
|
186 | - 'value' => $columnOptions, |
|
187 | - 'title' => GridViewHelper::columnTitle($key), |
|
188 | - ]; |
|
189 | - } |
|
190 | - |
|
191 | - /** |
|
192 | - * Inline column declaration detector |
|
193 | - */ |
|
194 | - if (is_string($columnOptions['value']) && strpos($columnOptions['value'], 'view:') === 0) { |
|
195 | - $columnOptions['class'] = 'view'; |
|
196 | - $columnOptions['value'] = str_replace('view:', '', $columnOptions['value']); |
|
197 | - } |
|
198 | - |
|
199 | - $columnOptions = array_merge($this->columnOptions, $columnOptions); |
|
200 | - |
|
201 | - $className = GridViewHelper::resolveAlias('column', $columnOptions['class']); |
|
202 | - $columnOptions = new $className($columnOptions); |
|
203 | - } |
|
204 | - } |
|
205 | - |
|
206 | - /** |
|
207 | - * Draws widget and return html code |
|
208 | - * @return string |
|
209 | - */ |
|
210 | - public function render() |
|
211 | - { |
|
212 | - return $this->renderer->render($this); |
|
213 | - } |
|
214 | - |
|
215 | - /** |
|
216 | - * @return LengthAwarePaginator|Paginator |
|
217 | - */ |
|
218 | - public function getPagination() |
|
219 | - { |
|
220 | - return $this->pagination; |
|
221 | - } |
|
222 | - |
|
223 | - /** |
|
224 | - * @return GridViewRequest |
|
225 | - */ |
|
226 | - public function getRequest() |
|
227 | - { |
|
228 | - return $this->request; |
|
229 | - } |
|
230 | - |
|
231 | - /** |
|
232 | - * @return int |
|
233 | - */ |
|
234 | - public function getId() : int |
|
235 | - { |
|
236 | - return $this->id; |
|
237 | - } |
|
238 | - |
|
239 | - /** |
|
240 | - * @return string |
|
241 | - */ |
|
242 | - public function compileTableHtmlOptions() : string |
|
243 | - { |
|
244 | - return GridViewHelper::htmlOptionsToString($this->tableHtmlOptions); |
|
245 | - } |
|
18 | + use Configurable; |
|
19 | + |
|
20 | + /** |
|
21 | + * Counter for ids |
|
22 | + * @var int |
|
23 | + */ |
|
24 | + private static $counter = 0; |
|
25 | + |
|
26 | + /** |
|
27 | + * Grid id (used for request handling, for |
|
28 | + * @var int |
|
29 | + */ |
|
30 | + private $id; |
|
31 | + |
|
32 | + /** |
|
33 | + * DataProvider provides gridview with the data for representation |
|
34 | + * @var BaseDataProvider |
|
35 | + */ |
|
36 | + public $dataProvider; |
|
37 | + |
|
38 | + /** |
|
39 | + * Columns config. You may specify array or GridColumn instance |
|
40 | + * @var BaseColumn[] |
|
41 | + */ |
|
42 | + public $columns = []; |
|
43 | + |
|
44 | + /** |
|
45 | + * Common options for all columns, will be appended to all columns configs |
|
46 | + * @var array |
|
47 | + */ |
|
48 | + public $columnOptions = [ |
|
49 | + 'class' => AttributeColumn::class, |
|
50 | + ]; |
|
51 | + |
|
52 | + /** |
|
53 | + * Renders the final UI |
|
54 | + * @var string|BaseRenderer |
|
55 | + */ |
|
56 | + public $renderer = DefaultRenderer::class; |
|
57 | + |
|
58 | + /** |
|
59 | + * Allows to pass some options into renderer/customize rendered behavior |
|
60 | + * @var array |
|
61 | + */ |
|
62 | + public $rendererOptions = []; |
|
63 | + |
|
64 | + /** |
|
65 | + * Controls amount of data per page |
|
66 | + * @var int |
|
67 | + */ |
|
68 | + public $rowsPerPage = 25; |
|
69 | + |
|
70 | + /** |
|
71 | + * Allows to tune the <table> tag with html options |
|
72 | + * @var array |
|
73 | + */ |
|
74 | + public $tableHtmlOptions = [ |
|
75 | + 'class' => 'table table-bordered gridview-table', |
|
76 | + ]; |
|
77 | + |
|
78 | + /** |
|
79 | + * Indicate if filters will be shown or not |
|
80 | + * @var bool |
|
81 | + */ |
|
82 | + public $showFilters = true; |
|
83 | + |
|
84 | + /** |
|
85 | + * Flags allow to change standalone vue to. If false, GridView component should be included in your root Vue instance |
|
86 | + * @var bool |
|
87 | + */ |
|
88 | + public $standaloneVue = true; |
|
89 | + |
|
90 | + /** |
|
91 | + * List of additinal params which'll be added to filter requests |
|
92 | + * @var array |
|
93 | + */ |
|
94 | + public $additionalRequestParams = []; |
|
95 | + |
|
96 | + /** |
|
97 | + * @var Paginator |
|
98 | + */ |
|
99 | + protected $pagination; |
|
100 | + |
|
101 | + /** |
|
102 | + * @var GridViewRequest |
|
103 | + */ |
|
104 | + protected $request; |
|
105 | + |
|
106 | + /** |
|
107 | + * GridView constructor. |
|
108 | + * @param array $config |
|
109 | + * @throws Exceptions\GridViewConfigException |
|
110 | + */ |
|
111 | + public function __construct(array $config) |
|
112 | + { |
|
113 | + $this->id = self::$counter++; |
|
114 | + |
|
115 | + $this->loadConfig($config); |
|
116 | + |
|
117 | + /** |
|
118 | + * Making renderer |
|
119 | + */ |
|
120 | + if (!is_object($this->renderer)) { |
|
121 | + $className = GridViewHelper::resolveAlias('renderer', $this->renderer); |
|
122 | + $this->renderer = new $className(array_merge( |
|
123 | + $this->rendererOptions, [ |
|
124 | + 'gridView' => $this, |
|
125 | + ] |
|
126 | + )); |
|
127 | + } |
|
128 | + |
|
129 | + /** |
|
130 | + * Build columns from config |
|
131 | + */ |
|
132 | + $this->buildColumns(); |
|
133 | + |
|
134 | + $this->request = GridViewRequest::parse($this->id); |
|
135 | + $this->request->perPage = $this->rowsPerPage; |
|
136 | + |
|
137 | + $this->pagination = new LengthAwarePaginator( |
|
138 | + $this->dataProvider->getData($this->request), |
|
139 | + $this->dataProvider->getCount($this->request), |
|
140 | + $this->rowsPerPage, |
|
141 | + $this->request->page |
|
142 | + ); |
|
143 | + } |
|
144 | + |
|
145 | + /** |
|
146 | + * @return array |
|
147 | + */ |
|
148 | + protected function configTests(): array |
|
149 | + { |
|
150 | + return [ |
|
151 | + 'dataProvider' => BaseDataProvider::class, |
|
152 | + 'columns' => 'array', |
|
153 | + 'renderer' => BaseRenderer::class, |
|
154 | + 'rowsPerPage' => 'int', |
|
155 | + 'tableHtmlOptions' => 'array', |
|
156 | + 'showFilters' => 'boolean', |
|
157 | + ]; |
|
158 | + } |
|
159 | + |
|
160 | + /** |
|
161 | + * Build columns into objects |
|
162 | + */ |
|
163 | + protected function buildColumns() |
|
164 | + { |
|
165 | + foreach ($this->columns as $key => &$columnOptions) { |
|
166 | + |
|
167 | + /** |
|
168 | + * In case of when column is already build |
|
169 | + */ |
|
170 | + if (is_object($columnOptions)) { |
|
171 | + continue; |
|
172 | + } |
|
173 | + |
|
174 | + /** |
|
175 | + * When only attribute name/value passed |
|
176 | + */ |
|
177 | + if (is_string($columnOptions)) { |
|
178 | + $columnOptions = [ |
|
179 | + 'value' => $columnOptions, |
|
180 | + ]; |
|
181 | + } |
|
182 | + |
|
183 | + if ($columnOptions instanceof Closure) { |
|
184 | + $columnOptions = [ |
|
185 | + 'class' => CallbackColumn::class, |
|
186 | + 'value' => $columnOptions, |
|
187 | + 'title' => GridViewHelper::columnTitle($key), |
|
188 | + ]; |
|
189 | + } |
|
190 | + |
|
191 | + /** |
|
192 | + * Inline column declaration detector |
|
193 | + */ |
|
194 | + if (is_string($columnOptions['value']) && strpos($columnOptions['value'], 'view:') === 0) { |
|
195 | + $columnOptions['class'] = 'view'; |
|
196 | + $columnOptions['value'] = str_replace('view:', '', $columnOptions['value']); |
|
197 | + } |
|
198 | + |
|
199 | + $columnOptions = array_merge($this->columnOptions, $columnOptions); |
|
200 | + |
|
201 | + $className = GridViewHelper::resolveAlias('column', $columnOptions['class']); |
|
202 | + $columnOptions = new $className($columnOptions); |
|
203 | + } |
|
204 | + } |
|
205 | + |
|
206 | + /** |
|
207 | + * Draws widget and return html code |
|
208 | + * @return string |
|
209 | + */ |
|
210 | + public function render() |
|
211 | + { |
|
212 | + return $this->renderer->render($this); |
|
213 | + } |
|
214 | + |
|
215 | + /** |
|
216 | + * @return LengthAwarePaginator|Paginator |
|
217 | + */ |
|
218 | + public function getPagination() |
|
219 | + { |
|
220 | + return $this->pagination; |
|
221 | + } |
|
222 | + |
|
223 | + /** |
|
224 | + * @return GridViewRequest |
|
225 | + */ |
|
226 | + public function getRequest() |
|
227 | + { |
|
228 | + return $this->request; |
|
229 | + } |
|
230 | + |
|
231 | + /** |
|
232 | + * @return int |
|
233 | + */ |
|
234 | + public function getId() : int |
|
235 | + { |
|
236 | + return $this->id; |
|
237 | + } |
|
238 | + |
|
239 | + /** |
|
240 | + * @return string |
|
241 | + */ |
|
242 | + public function compileTableHtmlOptions() : string |
|
243 | + { |
|
244 | + return GridViewHelper::htmlOptionsToString($this->tableHtmlOptions); |
|
245 | + } |
|
246 | 246 | } |
@@ -6,58 +6,58 @@ |
||
6 | 6 | |
7 | 7 | abstract class BaseDataProvider |
8 | 8 | { |
9 | - /** |
|
10 | - * true means that all request filters are accepted, checks by default comparing (like) |
|
11 | - * false means that filtering is not enabled in this dataprovider |
|
12 | - * array should contain array of fields, available for filtering. |
|
13 | - * if key not specified, value should be a name of field, otherwise key - field name, |
|
14 | - * value - comparing type (=, like) or a callable function |
|
15 | - * @var bool|array |
|
16 | - */ |
|
17 | - protected $filters = false; |
|
18 | - |
|
19 | - /** |
|
20 | - * true means that all request sortings are accepted, checks by default sorting |
|
21 | - * false means that ordering is not enabled in this dataprovider |
|
22 | - * array should contain array of fields, available for filtering. |
|
23 | - * value should be a string |
|
24 | - * @var bool|array |
|
25 | - */ |
|
26 | - protected $ordering = false; |
|
27 | - |
|
28 | - /** |
|
29 | - * Should return total amount of rows |
|
30 | - * @param GridViewRequest $request |
|
31 | - * @return int |
|
32 | - */ |
|
33 | - abstract public function getCount(GridViewRequest $request) : int; |
|
34 | - |
|
35 | - /** |
|
36 | - * Should return a list of data for current page |
|
37 | - * @param GridViewRequest $request |
|
38 | - * @return mixed |
|
39 | - */ |
|
40 | - abstract public function getData(GridViewRequest $request); |
|
41 | - |
|
42 | - /** |
|
43 | - * Allows to set a list of fields, available for filtering |
|
44 | - * @param array|boolean $filters |
|
45 | - * @return $this |
|
46 | - */ |
|
47 | - public function setFilters($filters) |
|
48 | - { |
|
49 | - $this->filters = $filters; |
|
50 | - return $this; |
|
51 | - } |
|
52 | - |
|
53 | - /** |
|
54 | - * Allows to set a list of ordering fields |
|
55 | - * @param array|boolean $ordering |
|
56 | - * @return $this |
|
57 | - */ |
|
58 | - public function setOrdering($ordering) |
|
59 | - { |
|
60 | - $this->ordering = $ordering; |
|
61 | - return $this; |
|
62 | - } |
|
9 | + /** |
|
10 | + * true means that all request filters are accepted, checks by default comparing (like) |
|
11 | + * false means that filtering is not enabled in this dataprovider |
|
12 | + * array should contain array of fields, available for filtering. |
|
13 | + * if key not specified, value should be a name of field, otherwise key - field name, |
|
14 | + * value - comparing type (=, like) or a callable function |
|
15 | + * @var bool|array |
|
16 | + */ |
|
17 | + protected $filters = false; |
|
18 | + |
|
19 | + /** |
|
20 | + * true means that all request sortings are accepted, checks by default sorting |
|
21 | + * false means that ordering is not enabled in this dataprovider |
|
22 | + * array should contain array of fields, available for filtering. |
|
23 | + * value should be a string |
|
24 | + * @var bool|array |
|
25 | + */ |
|
26 | + protected $ordering = false; |
|
27 | + |
|
28 | + /** |
|
29 | + * Should return total amount of rows |
|
30 | + * @param GridViewRequest $request |
|
31 | + * @return int |
|
32 | + */ |
|
33 | + abstract public function getCount(GridViewRequest $request) : int; |
|
34 | + |
|
35 | + /** |
|
36 | + * Should return a list of data for current page |
|
37 | + * @param GridViewRequest $request |
|
38 | + * @return mixed |
|
39 | + */ |
|
40 | + abstract public function getData(GridViewRequest $request); |
|
41 | + |
|
42 | + /** |
|
43 | + * Allows to set a list of fields, available for filtering |
|
44 | + * @param array|boolean $filters |
|
45 | + * @return $this |
|
46 | + */ |
|
47 | + public function setFilters($filters) |
|
48 | + { |
|
49 | + $this->filters = $filters; |
|
50 | + return $this; |
|
51 | + } |
|
52 | + |
|
53 | + /** |
|
54 | + * Allows to set a list of ordering fields |
|
55 | + * @param array|boolean $ordering |
|
56 | + * @return $this |
|
57 | + */ |
|
58 | + public function setOrdering($ordering) |
|
59 | + { |
|
60 | + $this->ordering = $ordering; |
|
61 | + return $this; |
|
62 | + } |
|
63 | 63 | } |