forked from Jaspersoft/jrs-rest-php-client
-
Notifications
You must be signed in to change notification settings - Fork 0
/
InputControl.php
69 lines (64 loc) · 1.6 KB
/
InputControl.php
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
<?php
namespace Jaspersoft\Dto\Report;
use Jaspersoft\Dto\DTOObject;
/**
* Deprecated in 2.1, use Jaspersoft\Dto\Report\InputControls\InputControlState instead.
* This class will be removed in v3.0.0
*
* Class InputControl
* @deprecated
* @package Jaspersoft\Dto\Report
*/
class InputControl extends DTOObject
{
/**
* @var string
*/
public $uri;
/**
* @var string
*/
public $id;
/**
* @var string
*/
public $value;
/**
* @var string
*/
public $error;
/**
* @var array
*/
public $options = array();
public function __construct($uri = null, $id = null, $value = null, $error = null)
{
$this->uri = (!empty($uri)) ? strval($uri) : null;
$this->id = (!empty($id)) ? strval($id) : null;
$this->value = (!empty($value)) ? strval($value) : null;
$this->error = (!empty($error)) ? strval($error) : null;
}
public static function createFromJSON($json)
{
$data_array = json_decode($json, true);
$result = array();
foreach($data_array['inputControlState'] as $k) {
$temp = @new self($k['uri'], $k['id'], $k['value'], $k['error']);
if (!empty($k['options'])) {
foreach ($k['options'] as $o) {
@$temp->addOption($o['label'], $o['value'], $o['selected']);
}
}
$result[] = $temp;
}
return $result;
}
private function addOption($label, $value, $selected)
{
$temp = array('label' => strval($label), 'value' => strval($value), 'selected' => $selected);
if($selected == 1) {
$temp['selected'] = 'true'; } else { $temp['selected'] = 'false';
}
$this->options[] = $temp;
}
}