-
Notifications
You must be signed in to change notification settings - Fork 20
/
Copy pathLsrorderModel.php
121 lines (96 loc) · 2.78 KB
/
LsrorderModel.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
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
<?php
/**
* @model Lsrorder
* https://api.test.inetwork.com/v1.0/accounts/lsrorders
*
*
*
* provides:
* get/0
*
*/
namespace Iris;
use AllowDynamicProperties;
#[AllowDynamicProperties]
final class Lsrorders extends RestEntry{
public function __construct($parent) {
$this->parent = $parent;
parent::_init($this->parent->get_rest_client(), $this->parent->get_relative_namespace());
}
public function get($filters = Array()) {
$orders = [];
$data = parent::_get('lsrorders', $filters, Array("page"=> 1, "size" => 30), Array("page", "size"));
print_r($data); exit;
if($data['ListOrderIdUserIdDate'] && $data['ListOrderIdUserIdDate']['TotalCount']) {
foreach($data['ListOrderIdUserIdDate']['OrderIdUserIdDate'] as $order) {
$orders[] = new Lsrorder($this, $order);
}
}
return $orders;
}
public function get_by_id($id) {
$order = new Lsrorder($this, array("Id" => $id));
$order->get();
return $order;
}
public function get_appendix() {
return '/orders';
}
public function create($data) {
$order = new Lsrorder($this, $data);
$order->save();
return $order;
}
}
#[AllowDynamicProperties]
final class Lsrorder extends RestEntry{
use BaseModel;
protected $fields = array(
/* TODO: fill fields
* */
"orderId" => array(
"type" => "string"
),
);
public function __construct($orders, $data)
{
if(isset($data)) {
if(is_object($data) && $data->Id)
$this->id = $data->Id;
if(is_array($data) && isset($data['Id']))
$this->id = $data['Id'];
}
$this->set_data($data);
if(!is_null($orders)) {
$this->parent = $orders;
parent::_init($orders->get_rest_client(), $orders->get_relative_namespace());
}
}
public function get() {
if(is_null($this->id))
throw new \Exception('Id should be provided');
$data = parent::_get($this->id);
$this->set_data($data['Order']);
}
public function save() {
if(!is_null($this->id))
parent::put($this->id, "Order", $this->to_array());
else {
$header = parent::post(null, "Order", $this->to_array());
$splitted = explode("/", $header['Location']);
$this->id = end($splitted);
}
}
public function history()
{
$url = sprintf('%s/%s', $this->id, 'history');
$data = parent::_get($url);
return $data;
}
public function notes()
{
$url = sprintf('%s/%s', $this->id, 'notes');
$data = parent::_get($url);
return $data;
}
}