generatePrintData()   A
last analyzed

Complexity

Conditions 5
Paths 6

Size

Total Lines 36

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 36
rs 9.0328
c 0
b 0
f 0
cc 5
nc 6
nop 1
1
<?php
2
if (!class_exists('GridFieldPrintAllAutomatedLinksButton')) {
3
    class GridFieldPrintAllAutomatedLinksButton extends GridFieldPrintButton {
4
        public function generatePrintData(GridField $gridField) {
5
            $printColumns = $this->getPrintColumnsForGridField($gridField);
6
            $header = null;
7
            if($this->printHasHeader) {
8
                $header = new ArrayList();
9
                foreach($printColumns as $field => $label){
10
                    $header->push(new ArrayData(array(
11
                        "CellString" => $label,
12
                        )));
13
                }
14
            }
15
16
            $items = $gridField->getList();
17
            $itemRows = new ArrayList();
18
            foreach($items as $item) {
19
                $itemRow = new ArrayList();
20
                foreach($printColumns as $field => $label) {
21
                    $value = $gridField->getDataFieldValue($item, $field);
22
                    $itemRow->push(new ArrayData(array(
23
                        "CellString" => $value,
24
                        )));
25
                }
26
                $itemRows->push(new ArrayData(array(
27
                    "ItemRow" => $itemRow
28
                    )));
29
                $item->destroy();
30
            }
31
            $ret = new ArrayData(array(
32
                "Title" => $this->getTitle($gridField),
33
                "Header" => $header,
34
                "ItemRows" => $itemRows,
35
                "Datetime" => SS_Datetime::now(),
36
                "Member" => Member::currentUser(),
37
                ));
38
            return $ret;
39
        }
40
    }
41
}
42