@@ -5,7 +5,7 @@ discard block |
||
5 | 5 | */ |
6 | 6 | class GridRowsExtension extends DataExtension |
7 | 7 | { |
8 | - /* |
|
8 | + /* |
|
9 | 9 | If you are laying out using some form of grid, e.g. HTML table (ugh) or |
10 | 10 | bootstraps span classes it is useful to have the DataList split by row. |
11 | 11 | Here the DataList is generated from a method accessible to the current |
@@ -14,32 +14,32 @@ discard block |
||
14 | 14 | See README.md for a worked example |
15 | 15 | |
16 | 16 | */ |
17 | - public function SplitDataListIntoGridRows($itemsInGridMethod, $numberOfCols) |
|
18 | - { |
|
19 | - $methodFound = false; |
|
20 | - $itemsInGrid = null; |
|
17 | + public function SplitDataListIntoGridRows($itemsInGridMethod, $numberOfCols) |
|
18 | + { |
|
19 | + $methodFound = false; |
|
20 | + $itemsInGrid = null; |
|
21 | 21 | |
22 | - // Check first the controller and then the model for the method to call |
|
23 | - if ($this->owner->hasMethod($itemsInGridMethod)) { |
|
24 | - $itemsInGrid = $this->owner->$itemsInGridMethod(); |
|
25 | - $methodFound = true; |
|
26 | - } |
|
22 | + // Check first the controller and then the model for the method to call |
|
23 | + if ($this->owner->hasMethod($itemsInGridMethod)) { |
|
24 | + $itemsInGrid = $this->owner->$itemsInGridMethod(); |
|
25 | + $methodFound = true; |
|
26 | + } |
|
27 | 27 | |
28 | - if (!$methodFound && method_exists($this->owner->model, $itemsInGridMethod)) { |
|
29 | - $itemsInGrid = $this->owner->model->$itemsInGridMethod(); |
|
30 | - $methodFound = true; |
|
31 | - } |
|
28 | + if (!$methodFound && method_exists($this->owner->model, $itemsInGridMethod)) { |
|
29 | + $itemsInGrid = $this->owner->model->$itemsInGridMethod(); |
|
30 | + $methodFound = true; |
|
31 | + } |
|
32 | 32 | |
33 | - if ($itemsInGrid == null) { |
|
34 | - $message = 'Method not found. A grid cannot be formed from the ' |
|
35 | - . 'method ' . $itemsInGridMethod; |
|
36 | - throw new InvalidArgumentException($message); |
|
37 | - } |
|
33 | + if ($itemsInGrid == null) { |
|
34 | + $message = 'Method not found. A grid cannot be formed from the ' |
|
35 | + . 'method ' . $itemsInGridMethod; |
|
36 | + throw new InvalidArgumentException($message); |
|
37 | + } |
|
38 | 38 | |
39 | - return $this->createGrid($itemsInGrid, $numberOfCols); |
|
40 | - } |
|
39 | + return $this->createGrid($itemsInGrid, $numberOfCols); |
|
40 | + } |
|
41 | 41 | |
42 | - /* |
|
42 | + /* |
|
43 | 43 | If you are laying out using some form of grid, e.g. HTML table (ugh) or |
44 | 44 | bootstraps span classes it is useful to have the DataList split by row. |
45 | 45 | This is what this method does. |
@@ -47,40 +47,40 @@ discard block |
||
47 | 47 | See USAGE.md for a worked example |
48 | 48 | |
49 | 49 | */ |
50 | - public function SplitClassNameDataListIntoGridRows( |
|
51 | - $className, $numberOfCols, $limit = 10, $sort = 'LastEdited DESC') |
|
52 | - { |
|
53 | - $clazz = Injector::inst()->create($className); |
|
54 | - $itemsInGrid = $clazz->get()->limit($limit)->sort($sort); |
|
55 | - return $this->createGrid($itemsInGrid, $numberOfCols); |
|
56 | - } |
|
50 | + public function SplitClassNameDataListIntoGridRows( |
|
51 | + $className, $numberOfCols, $limit = 10, $sort = 'LastEdited DESC') |
|
52 | + { |
|
53 | + $clazz = Injector::inst()->create($className); |
|
54 | + $itemsInGrid = $clazz->get()->limit($limit)->sort($sort); |
|
55 | + return $this->createGrid($itemsInGrid, $numberOfCols); |
|
56 | + } |
|
57 | 57 | |
58 | - /* |
|
58 | + /* |
|
59 | 59 | The actual method that splits the DataList into an ArrayList of rows that |
60 | 60 | contain an ArrayList of Columns |
61 | 61 | */ |
62 | - private function createGrid($itemsInGrid, $numberOfCols) |
|
63 | - { |
|
64 | - $position = 1; |
|
65 | - $columns = new ArrayList(); |
|
66 | - $result = new ArrayList(); |
|
67 | - foreach ($itemsInGrid as $key => $item) { |
|
68 | - $columns->push($item); |
|
69 | - if (($position) >= $numberOfCols) { |
|
70 | - $position = 1; |
|
71 | - $row = new ArrayList(); |
|
72 | - $row->Columns = $columns; |
|
73 | - $result->push($row); |
|
74 | - $columns = new ArrayList(); |
|
75 | - } else { |
|
76 | - $position = $position + 1; |
|
77 | - } |
|
78 | - } |
|
79 | - if ($columns->Count() > 0) { |
|
80 | - $row = new ArrayList(); |
|
81 | - $row->Columns = $columns; |
|
82 | - $result->push($row); |
|
83 | - } |
|
84 | - return $result; |
|
85 | - } |
|
62 | + private function createGrid($itemsInGrid, $numberOfCols) |
|
63 | + { |
|
64 | + $position = 1; |
|
65 | + $columns = new ArrayList(); |
|
66 | + $result = new ArrayList(); |
|
67 | + foreach ($itemsInGrid as $key => $item) { |
|
68 | + $columns->push($item); |
|
69 | + if (($position) >= $numberOfCols) { |
|
70 | + $position = 1; |
|
71 | + $row = new ArrayList(); |
|
72 | + $row->Columns = $columns; |
|
73 | + $result->push($row); |
|
74 | + $columns = new ArrayList(); |
|
75 | + } else { |
|
76 | + $position = $position + 1; |
|
77 | + } |
|
78 | + } |
|
79 | + if ($columns->Count() > 0) { |
|
80 | + $row = new ArrayList(); |
|
81 | + $row->Columns = $columns; |
|
82 | + $result->push($row); |
|
83 | + } |
|
84 | + return $result; |
|
85 | + } |
|
86 | 86 | } |