forked from loduis/teamwork.com-project-management
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathModel.php
69 lines (62 loc) · 1.4 KB
/
Model.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 TeamWorkPm;
abstract class Model extends Rest\Model
{
/*------------------------------
PUBLIC METHOD
------------------------------*/
public function get($id, $params = null)
{
$id = (int) $id;
if ($id <= 0) {
throw new Exception('Invalid param id');
}
return $this->rest->get("$this->action/$id", $params);
}
/**
*
* @param array $data
* @return int
*/
public function insert(array $data)
{
return $this->rest->post($this->action, $data);
}
/**
*
* @param array $data
* @return bool
*/
public function update(array $data)
{
$id = empty($data['id']) ? 0: (int) $data['id'];
if ($id <= 0) {
throw new Exception('Required field id');
}
return $this->rest->put("$this->action/$id", $data);
}
/**
*
* @param array $data
* @return [bool|int]
*/
final public function save(array $data)
{
return array_key_exists('id', $data) ?
$this->update($data):
$this->insert($data);
}
/**
*
* @param int $id
* @return bool
*/
public function delete($id)
{
$id = (int) $id;
if ($id <= 0) {
throw new Exception('Invalid param id');
}
return $this->rest->delete("$this->action/$id");
}
}