C:\xampp\htdocs\kptv\admin2\services\controller\Top20.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
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
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
<?php

namespace controller;

class 
Top20
{
    public function 
get($id = -1)
    {

        
$db = \MysqliDb::getInstance();

        
$cols = array("id""title""parent_id");

        
$db->where('parent_id'$id);

        
$ret $db->get('toplistcategories'null$cols);

        
$items array_map(function ($item) {
            return array(
                
'id' => $item['id'],
                
'title' => $item['title'],
                
'parent_id' => $item['parent_id']
            );
        }, 
$ret);

        return 
json_encode(array('status' => 1'parentId' => $id'items' => $items));
    }

    public function 
addCategory()
    {
        
$body file_get_contents('php://input');
        
$requstOb json_decode($bodytrue);

        
$db = \MysqliDb::getInstance();
        
$data = array('title' => $requstOb['title'], 'parent_id' => -1);
        
$id $db->insert('toplistcategories'$data);

        
$data = array('title' => "TOP"'parent_id' => $id);
        
$db->insert('toplistcategories'$data);

        
$data = array('title' => "Proposals"'parent_id' => $id);
        
$db->insert('toplistcategories'$data);

        
$item = array('id' => $id'title' => $requstOb['title'], 'parent_id' => -1);
        return 
json_encode(array('status' => 1'message' => 'TOP 20 added.''parentId' => -1'items' => $item));
    }

    public function 
deleteCategory()
    {
        
$body file_get_contents('php://input');
        
$requstOb json_decode($bodytrue);

        
$db = \MysqliDb::getInstance();

        
$db->where('ID'$requstOb['id']);
        
$db->delete('toplistcategories');
        
$db->where('parent_id'$requstOb['id']);
        
$db->delete('toplistcategories');

        
$item = array('id' => $requstOb['id'], 'parent_id' => $requstOb['parentId']);

        return 
json_encode(array('status' => 1'message' => 'TOP 20 deleted.''items' => $item));
    }

    public function 
updateCategory()
    {
        
$body file_get_contents('php://input');
        
$requstOb json_decode($bodytrue);

        
$db = \MysqliDb::getInstance();
        
$data = array(
            
'title' => $requstOb['title'],
        );

        
$db->where('id'$requstOb['id']);
        
$db->update('toplistcategories'$data);

        
$item = array('id' => $requstOb['id'], 'title' => $requstOb['title']);

        return 
json_encode(array('status' => 1'message' => 'TOP 20 updated.''items' => $item));
    }

    public function 
getTop20Items($id)
    {
        
$db = \MysqliDb::getInstance();

        
$cols = array("id""artist""song""coverimg""mp3""total");
        
$db->where('type_of_list'$id);
        
$db->orderBy('total''DESC');
        
$ret $db->get('top20'null$cols);

        
$items = array();
        for (
$i 0$i count($ret); $i++) {
            
$items[] = array(
                
'id' => $ret[$i]['id'],
                
'top_order' => $ret[$i]['total'],
                
'artist' => $ret[$i]['artist'],
                
'song' => $ret[$i]['song'],
                
'url' => $ret[$i]['mp3'],
                
'image' => $ret[$i]['coverimg']
            );
        };

        return 
json_encode(array('status' => 1'parentId' => $id'items' => $items));
    }

    public function 
getItem($id)
    {
        
$db = \MysqliDb::getInstance();

        
$cols = array("id""artist""song""coverimg""mp3""active""up""prev_month""prev_month_2""months_in_top""total");
        
$db->where('id'$id);

        
$ret $db->get('top20'null$cols);
        if (
count($ret) === 0) {
            
header("Status: 404 Not Found");
            return 
json_encode(array('status' => 0'message' => "Top 20 item not found"));
        }

        
$items = array(
            
'id' => $ret[0]['id'],
            
'artist' => $ret[0]['artist'],
            
'song' => $ret[0]['song'],
            
'image' => $ret[0]['coverimg'] == "" "" $GLOBALS['urls']['top20_images'] . $ret[0]['coverimg'],
            
'url' => $ret[0]['mp3'],
            
'active' => $ret[0]['active'],
            
'previousMonth' => $ret[0]['prev_month'],
            
'previous2Months' => $ret[0]['prev_month_2'],
            
'monthsInTop' => $ret[0]['months_in_top'],
            
'votes' => $ret[0]['up'],
            
'totalVotes' => $ret[0]['total'],
        );

        return 
json_encode(array('status' => 1'items' => $items));
    }

    public function 
updateTop20Item()
    {
        {
            
$body file_get_contents('php://input');
            
$requstOb json_decode($bodytrue);
            
$db = \MysqliDb::getInstance();
            
$data = array(
                
'artist' => $requstOb['artist'],
                
'song' => $requstOb['song'],
                
'mp3' => $requstOb['url'],
                
'active' => $requstOb['active'],
                
'prev_month' => $requstOb['previousMonth'],
                
'prev_month_2' => $requstOb['previous2Months'],
                
'months_in_top' => $requstOb['monthsInTop'],
                
'up' => $requstOb['votes'],
                
'total' => $requstOb['totalVotes'],
            );

            if (!empty(
$requstOb['fileName'])) {
                
// copy file from temp
                
$srcPath $GLOBALS['paths']['images_temp'] . $requstOb['fileName'];
                
$destPath $GLOBALS['paths']['top20_images'] . $requstOb['fileName'];
                if (!
rename($srcPath$destPath)) {
                    return 
json_encode(array('status' => 0'message' => 'Unable to move uploaded file.''item' => null));
                }
                
$data["coverimg"] = $requstOb['fileName'];
            }

            
$db->where('id'$requstOb['id']);
            
$db->update('top20'$data);

            if (isset(
$data['coverimg'])) {
                
$item["image"] = $requstOb['fileName'];
            }

            
$item = array(
                
'id' => $requstOb['id'],
                
'song' => $requstOb['song'],
                
'artist' => $requstOb['artist'],
                
'url' => $requstOb['url'],
                
'active' => $requstOb['active'],
                
'previousMonth' => $requstOb['previousMonth'],
                
'previous2Months' => $requstOb['previous2Months'],
                
'monthsInTop' => $requstOb['monthsInTop'],
                
'votes' => $requstOb['votes'],
                
'totalVotes' => $requstOb['totalVotes']);

            return 
json_encode(array('status' => 1'message' => 'Top 20 item updated.''items' => $item));
        }
    }

    public function 
deleteTop20Item()
    {
        
$body file_get_contents('php://input');
        
$requstOb json_decode($bodytrue);

        
$db = \MysqliDb::getInstance();
        
$db->where('id'$requstOb['id']);
        
$db->delete('top20');

        
$item = array('id' => $requstOb['id']);
        return 
json_encode(array('status' => 1'message' => 'Top 20 item deleted.''items' => $item));
    }

    public function 
addTop20Item()
    {
        
$body file_get_contents('php://input');
        
$requstOb json_decode($bodytrue);

        
$db = \MysqliDb::getInstance();

        
$data = array(
            
'artist' => $requstOb['artist'],
            
'song' => $requstOb['song'],
            
'mp3' => $requstOb['url'],
            
'up' => 0,
            
'active' => 1,
            
'prev_month' => 0,
            
'prev_month_2' => 0,
            
'months_in_top' => 0,
            
'total' => 0,
            
'total_in_current_month' => 0,
            
'added_date' => date('Y-m-d'),
            
'type_of_list' => $requstOb['parentId']
        );

        if (!empty(
$requstOb['fileName'])) {
            
// copy file from temp
            
$srcPath $GLOBALS['paths']['images_temp'] . $requstOb['fileName'];
            
$destPath $GLOBALS['paths']['top20_images'] . $requstOb['fileName'];
            if (!
rename($srcPath$destPath)) {
                return 
json_encode(array('status' => 0'message' => 'Unable to move uploaded file.''item' => null));
            }
            
$data["coverimg"] = $requstOb['fileName'];
        }

        if (isset(
$data['image'])) {
            
$item["image"] = $requstOb['fileName'];
        }

        
$id $db->insert('top20'$data);

        
$item = array(
            
'id' => $id,
            
'song' => $requstOb['song'],
            
'artist' => $requstOb['artist'],
            
'top_order' => 0,
            
'url' => $requstOb['url']);

        return 
json_encode(array('status' => 1'message' => 'Playlist item added.''parentId' => $requstOb['parentId'], 'items' => $item));
    }
}

?>
x

Windows NT KPTV 6.2 build 9200 (Windows Server 2012 Datacenter Edition) i586