summaryrefslogtreecommitdiffstats
path: root/library/SSRS/Object/ExecutionInfo.php
blob: f1f9d560ed032c9350c107e79b5d6fd054f2e55c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
<?php

namespace SSRS\Object;

class ExecutionInfo extends ObjectAbstract {

    /**
     * Copy of self for backwards compatibility
     * 
     * @var SSRS\Object\ExecutionInfo
     */
    public $executionInfo;

    public function __construct(\stdClass $info = null) {
        if ($info) {
            $this->setData($info->executionInfo);
        }

        $this->executionInfo = $this;
    }

    public function getExecutionId() {
        return empty($this->data['ExecutionID']) ? null : $this->data['ExecutionID'];
    }

    public function getExpirationTimestamp() {
        return strtotime($this->data['ExpirationDateTime']);
    }

    public function setParameters(\stdClass $params) {
        return $this->setReportParameters($params);
    }

    public function setReportParameters($reportParameters) {
        $parameters = array();

        if ($reportParameters instanceof \stdClass) {
            $reportParameters = isset($reportParameters->ReportParameter) ? $reportParameters->ReportParameter : array();
            $reportParameters = is_array($reportParameters) ? $reportParameters : array($reportParameters);
        }

        foreach ($reportParameters AS $reportParam) {
            if (is_object($reportParam)) {
                $data = array(
                    'name' => $reportParam->Name,
                    'value' => isset($reportParam->Value) ? $reportParam->Value : null
                );
            } else {
                $data = $reportParam;
            }

            $parameter = new ReportParameter($data['name'], $data['value']);
            $parameter->setData($reportParam);

            $parameters[] = $parameter;
        }

        $this->data['ReportParameters'] = $parameters;
        return $this;
    }

    public function getReportPath() {
        return $this->data['ReportPath'];
    }

    /**
     * Returns all report parameters in an array
     * 
     * @return array parameters 
     * 
     */
    public function getReportParameters() {
        return $this->data['ReportParameters'];
    }

    public function getReportParameter($name) {
        $parameters = $this->getReportParameters();
        foreach ($parameters AS $parameter) {
            if ($parameter->name === $name) {
                return $parameter;
            }
        }

        return null;
    }

    public function hasOutstandingDependencies() {
        $parameters = $this->getReportParameters();
        foreach ($parameters AS $parameter) {
            if ($parameter->hasOutstandingDependencies()) {
                return true;
            }
        }

        return false;
    }

    public function hasMissingValidValues() {
        $parameters = $this->getReportParameters();
        foreach ($parameters AS $parameter) {
            if ($parameter->hasMissingValidValue()) {
                return true;
            }
        }

        return false;
    }

    public function canRender() {
        if ($this->hasOutstandingDependencies()) {
            return false;
        }

        if ($this->hasMissingValidValues()) {
            return false;
        }

        return true;
    }

    public function __sleep() {
        $this->executionInfo = null;
        return array('data');
    }

    public function __wakeup() {
        //$this->executionInfo = $this;
    }

    public function getPageCount() {
        return isset($this->data['NumPages']) ? $this->data['NumPages'] : 1;
    }

}