-
Notifications
You must be signed in to change notification settings - Fork 96
/
Copy pathzsets.php
51 lines (41 loc) · 1.64 KB
/
zsets.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
<?php
class Zsets_Controller extends Controller
{
public function addAction()
{
$added = false;
if ($this->router->method == Router::POST) {
$value = $this->inputs->post('value', null);
$key = $this->inputs->post('key', null);
$score = $this->inputs->post('score', null);
if (isset($value) && trim($value) != '' && isset($key) && trim($key) != '' && isset($score) && trim($score) != '') {
$added = (boolean) $this->db->zAdd($key, (double) $score, $value);
}
}
Template::factory('json')->render($added);
}
public function viewAction($key, $page = 0)
{
$count = $this->db->zSize(urldecode($key));
$start = $page * 30;
$values = $this->db->zRange(urldecode($key), $start, $start + 29, true);
Template::factory()->render('zsets/view', array('count' => $count, 'values' => $values, 'key' => urldecode($key),
'page' => $page));
}
public function deleteAction($key, $value)
{
Template::factory('json')->render($this->db->zDelete(urldecode($key), urldecode($value)));
}
public function delallAction()
{
if ($this->router->method == Router::POST) {
$results = array();
$values = $this->inputs->post('values', array());
$keyinfo = $this->inputs->post('keyinfo', null);
foreach ($values as $key => $value) {
$results[$value] = $this->db->zDelete($keyinfo, $value);
}
Template::factory('json')->render($results);
}
}
}