-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvalidations.php
61 lines (50 loc) · 1.74 KB
/
validations.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
<?php
include_once './utility/mysql.php';
include_once './tasks.php';
class validations
{
public static function get_all($status = 0)
{
$ret = array();
$res = mysql::queryf('SELECT * FROM validations WHERE status = %d', $status);
while ( $r = mysql_fetch_object($res) )
{
$r->segments = unserialize($r->segments);
$ret []= $r;
}
return $ret;
}
public static function get_validation($id)
{
$res = mysql::queryf('SELECT * FROM validations WHERE id = %d', $id);
if ( $r = mysql_fetch_object($res) )
{
$r->segments = unserialize($r->segments);
return $r;
}
return null;
}
public static function get_all_for_user($user_id, $status = 0)
{
$ret = array();
$res = mysql::queryf('SELECT * FROM validations WHERE used_id = %d AND status = %d',
$user_id, $status);
while ( $r = mysql_fetch_object($res) )
{
$r->segments = unserialize($r->segments);
$ret []= $r;
}
return $ret;
}
public static function add_validation( $task_id, $user_id, $status = 0, $segments = array() )
{
return mysql::insertf('INSERT INTO validations VALUES( NULL, %d, %d, %d, "%s")',
$task_id, $user_id, $status, serialize($segments));
}
public static function update_validation( $task_id, $user_id, $status = 0, $segments = array() )
{
return mysql::execf('UPDATE validations SET status = %d, segments = "%s" '.
'WHERE user_id = %d AND task_id = %d',
$status, serialize($segments), $user_id, $task_id);
}
}