summaryrefslogtreecommitdiffstats
path: root/library/SSRS/Object/ExecutionInfo.php
blob: 49e6d1579f1b6477bda2fbf4b418a9b22953314f (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
<?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 __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;
    }

}