This repository was archived by the owner on Aug 22, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 34
Expand file tree
/
Copy pathUserNotes.php
More file actions
110 lines (91 loc) · 2.4 KB
/
UserNotes.php
File metadata and controls
110 lines (91 loc) · 2.4 KB
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
<?php
require_once dirname(__FILE__) . '/DBConnection.php';
class UserNotes {
private static $instance;
private $conn;
/**
* @static
* @return UserNotes
*/
public static function getInstance()
{
if (!isset(self::$instance)) {
$c = __CLASS__;
self::$instance = new $c;
}
return self::$instance;
}
public function __construct()
{
$this->conn = DBConnection::getInstance();
}
public function getNotes($file)
{
$am = AccountManager::getInstance();
$project = $am->project;
$s = 'SELECT
`id`, `user`, `date`, `note`
FROM
`userNotes`
WHERE
`project` = "%s" AND `file`="%s"';
$params = array(
$project,
$file // must be like this : fr/reference/cairo/cairocontext/appendpath.xml
);
$r = $this->conn->query($s, $params);
$infos = array();
while ($a = $r->fetch_assoc()) {
$infos[] = $a;
}
return $infos;
}
public function addNote($file, $note)
{
$am = AccountManager::getInstance();
$project = $am->project;
$vcsLogin = $am->vcsLogin;
$s = 'INSERT INTO
`userNotes`
(`project`, `file`, `user`, `date`, `note`)
VALUES
("%s", "%s", "%s", now(), "%s")';
$params = array(
$project,
$file,
$vcsLogin,
$note
);
$this->conn->query($s, $params);
}
public function delNote($noteID)
{
$am = AccountManager::getInstance();
$vcsLogin = $am->vcsLogin;
// A user can only delete his note. Not those of others users.
$s = 'SELECT user FROM
`userNotes`
WHERE
id = %d';
$params = array(
$noteID
);
$r = $this->conn->query($s, $params);
$a = $r->fetch_object();
if( $a->user == $vcsLogin ) {
// We can delete it
$s = 'DELETE FROM
`userNotes`
WHERE
id = %d';
$params = array(
$noteID
);
$this->conn->query($s, $params);
return true;
} else {
return false;
}
}
}
?>