forked from grobmeier/simplepo
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmessage_service.php
77 lines (66 loc) · 2.21 KB
/
message_service.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
<?php
// A really simple json RPC interface
require_once 'env_fix.php';
require_once 'config.php';
require_once 'DB.php';
$rpc = new JSON_RPC(new MessageService());
echo $rpc->getResponse($_POST["request"]);
class JSON_RPC {
protected $service;
function __construct($obj) {
$this->service = $obj;
}
function getResponse($request_string) {
$request = json_decode($request_string,true);
$response = array('error'=>null);
if($request['id'])
$response['id'] = $request['id'];
if(method_exists($this->service,$request['method'])) {
try {
$r = call_user_func_array(array($this->service, $request['method']), $request['params']);
$response['result'] = $r;
} catch (Exception $e) {
$response['error'] = array('code' => -31000,'message' => $e->getMessage());
}
} else {
$response['error'] = array('code' => -32601,'message' => 'Procedure not found.');
}
return json_encode($response);
}
}
class MessageService {
function __construct() {
}
function getMessages($id) {
$q = new Query();
$messages = $q->sql("SELECT *
FROM {messages}
WHERE catalogue_id=? AND is_header <> 1
ORDER BY msgstr != '', flags != 'fuzzy' ", $id)
->fetchAll();
foreach($messages as &$m) {
$m['fuzzy'] = strpos($m['flags'],'fuzzy') !== FALSE;
$m['is_obsolete'] = !!$m['is_obsolete'];
}
return $messages;
}
function getCatalogues(){
$q = new Query();
return $q->sql("SELECT c.name,c.id,COUNT(*) as message_count,
SUM(LENGTH(m.msgstr) >0 and m.flags != 'fuzzy') as translated_count,
SUM(LENGTH(m.msgstr) >0 and m.flags = 'fuzzy') as fuzzy_count
FROM {catalogues} c
LEFT JOIN {messages} m ON m.catalogue_id=c.id
GROUP BY c.id")->fetchAll();
}
function updateMessage($catalogue_id, $msgid, $comments, $msgstr, $fuzzy){
$q = new Query();
$flags = $fuzzy ? 'fuzzy' : '';
$q->sql("UPDATE {messages} SET comments=?, msgstr=?, flags=? WHERE msgid=? AND catalogue_id=?", $comments, $msgstr, $flags, $msgid, $catalogue_id)->execute();
var_dump($catalogue_id);
echo "true";
}
function makeError() {
throw new Exception("This is an error");
}
}