C:\xampp\htdocs\kptv\admin2\services\controller\RockLegends.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
<?php
namespace controller;

class 
RockLegends {

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

        
$cols = Array ("ID""NameRO""ImgID""OrderID");
        
$ret $db->get('articles'null$cols);

        
$ret array_map(function($item) {
            return array(
                
'id' => $item['ID'],
                
'title' => $item['NameRO'],
                
"image" => $item['ImgID'],
                
"display_order" => $item['OrderID']
            );
        }, 
$ret);

        return 
json_encode($ret);        
    }

    public function 
rockLegend($id
    {
        
$db = \MysqliDb::getInstance();
        
$cols = Array ("ID""NameRO""ContentRO""Content_Short""ImgID""OrderID");

        
$db->where ('ID'$id);
        
$ret $db->get('articles'null$cols);

        if(
count($ret) === 0) {
            
header("Status: 404 Not Found");
            return 
"";
        }

        
$item = array(
            
'id' => $ret[0]['ID'],
            
'title' => $ret[0]['NameRO'],
            
'content' => $ret[0]['ContentRO'],
            
'content_short' => $ret[0]['Content_Short'],
            
"image" => $ret[0]['ImgID'],             
            
"display_order" => $ret[0]['OrderID']            
        );

        return 
json_encode($item);
    }


    public function 
updateRockLegend() 
    {        
        
$body file_get_contents('php://input');
        
$requstOb json_decode($body,true);        

        
$db = \MysqliDb::getInstance();
        
$data = Array (
            
'NameRO' => $requstOb['title'],                
            
"ContentRO" => $requstOb['content'],
            
"Content_Short" => $requstOb['content_short'],            
            
"OrderID" => $requstOb['display_order']            
        );        
        
        if(!empty(
$requstOb['fileName'])) {
            
// copy file from temp
            
$srcPath $GLOBALS['paths']['images_temp'] . $requstOb['fileName'];
            
$destPath $GLOBALS['paths']['rock_legends'] . $requstOb['fileName'];            
            if(!
rename($srcPath$destPath)) {
                return 
json_encode(array('status'=> 0'message'=>'Unable to move uploaded file.''item'=>null));
            }
            
$data["ImgID"] = $requstOb['fileName'];
        }

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

        
$item = array(
            
'id' => $requstOb['id'],
            
'title' => $requstOb['title'],            
            
"display_order" => $requstOb['display_order']);
        
        if(isset(
$data['ImgID'])) {
            
$item["image"] = $requstOb['fileName'];
        }        

        return 
json_encode(array('status'=>1'message'=>'Rock Legend article updated.''item'=>$item));

    }

    public function 
addRockLegend() 
    {        
        
$body file_get_contents('php://input');
        
$requstOb json_decode($body,true);

        
$db = \MysqliDb::getInstance();
        
$data = Array (
            
'NameRO' => $requstOb['title'],                
            
"ContentRO" => $requstOb['content'],
            
"Content_Short" => $requstOb['content_short'],            
            
"OrderID" => $requstOb['display_order']            
        );
        
        if(!empty(
$requstOb['fileName'])) {
            
// copy file from temp
            
$srcPath $GLOBALS['paths']['images_temp'] . $requstOb['fileName'];
            
$destPath $GLOBALS['paths']['rock_legends'] . $requstOb['fileName'];            
            if(!
rename($srcPath$destPath)) {
                return 
json_encode(array('status'=> 0'message'=>'Unable to move uploaded file.''item'=>null));
            }
            
$data["ImgID"] = $requstOb['fileName'];
        }

        
$id $db->insert ('articles'$data);        
        
        
$item = array(
            
'id' => $id,
            
'title' => $requstOb['title'],
            
"display_order" => $requstOb['display_order']);
        
        if(isset(
$data['ImgID'])) {
            
$item["image"] = $requstOb['fileName'];
        }

        return 
json_encode(array('status'=>1'message'=>'Rock Legend article added.''item'=>$item));
    }

    
    public function 
deleteRockLegend()
    {        
        
$body file_get_contents('php://input');
        
$requstOb json_decode($body,true);
                
        
$db = \MysqliDb::getInstance();        
        
$db->where('ID'$requstOb['id']);        
        
$id $db->delete ('articles');

        
// TODO: delete image

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

        return 
json_encode(array('status'=> 1'message'=>'Rock Legend article deleted.''item'=> $item));
    }  

}
?>
x

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