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
135
136
137
138
139
140
141
142
143
144
145
146
147
148
|
<?php namespace controller;
class PhotoGallery {
public function get() { $db = \MysqliDb::getInstance();
$cols = Array ("id", "NameRO"); $ret = $db->get('gallerydir', null, $cols);
$items = array_map(function($item) { return array( 'id' => $item['id'], 'name' => $item['NameRO'] ); }, $ret);
return json_encode(array('status'=>1, 'items'=>$items)); } public function updatePhotoCategory() { $body = file_get_contents('php://input'); $requstOb = json_decode($body,true); $db = \MysqliDb::getInstance(); $data = Array ('NameRO' => $requstOb['name']); $db->where ('id', $requstOb['id']); $db->update ('gallerydir', $data);
$item = array('id' => $requstOb['id'], 'name'=>$requstOb['name']); return json_encode(array('status'=> 1, 'message'=>'Photo category updated.', 'items'=> $item)); }
public function addPhotoCategory() { $body = file_get_contents('php://input'); $requstOb = json_decode($body,true); $db = \MysqliDb::getInstance(); $data = Array ('NameRO' => $requstOb['name']); $id = $db->insert ('gallerydir', $data); $item = array('id' => $id,'name' => $requstOb['name']); return json_encode(array('status'=> 1, 'message'=>'Photo category added.', 'items'=>$item)); }
public function deletePhotoCategory() { $body = file_get_contents('php://input'); $requstOb = json_decode($body,true); $db = \MysqliDb::getInstance(); $db->where('AlbumID', $requstOb['id']); $ret = $db->get('gallery', null, array("ID")); if(count($ret) != 0) { return json_encode(array('status'=> 0, 'message'=>'Please delete all subitems first.')); }
$db->where('ID', $requstOb['id']); $id = $db->delete ('gallerydir'); $item = array('id' => $requstOb['id']); return json_encode(array('status'=> 1, 'message'=>'Photo category deleted.', 'items'=> $item)); }
public function getGallery($id) { $db = \MysqliDb::getInstance();
$cols = Array ("id", "NameRO", "Image", "Publish", "Date"); $db->where('AlbumID', $id); $ret = $db->get('gallery', null, $cols);
$items = array_map(function($item) { return array( 'id' => $item['id'], 'name' => $item['NameRO'], 'image' => $item['Image'], 'publish' => $item['Publish'], 'date' => $item['Date'] ); }, $ret);
return json_encode(array('status'=>1, 'galleryId'=>$id, 'items'=>$items)); }
public function deleteGalleryItem() { $body = file_get_contents('php://input'); $requstOb = json_decode($body,true); $db = \MysqliDb::getInstance(); $db->where('ID', $requstOb['id']); $db->delete ('gallery');
// TODO: delete image
$item = array('id' => $requstOb['id']);
return json_encode(array('status'=> 1, 'message'=>'Gallery Image deleted.', 'items'=> $item)); }
public function addGalleryItem() { $body = file_get_contents('php://input'); $requstOb = json_decode($body,true); $db = \MysqliDb::getInstance(); $data = Array ( 'NameRO' => $requstOb['title'], "Publish" => $requstOb['publish'], "Date" => time(), "Image" => "", "AlbumID" => $requstOb['gallery_id'] ); if(!empty($requstOb['fileName'])) { // copy file from temp $srcPath = $GLOBALS['paths']['images_temp'] . $requstOb['fileName']; $destPath = $GLOBALS['paths']['photo_gallery'] . $requstOb['fileName']; if(!rename($srcPath, $destPath)) { return json_encode(array('status'=> 0, 'message'=>'Unable to move uploaded file.', 'item'=>null)); } $data["Image"] = $requstOb['fileName']; } $id = $db->insert ('gallery', $data); $item = array( 'id' => $id, 'name' => $requstOb['title'], "publish" => $requstOb['publish'], ); if(isset($data['Image'])) { $item["image"] = $requstOb['fileName']; } return json_encode(array('status'=>1, 'message'=>'Photo gallery item added.', 'items'=>$item)); } } ?>
|