This repository has been archived by the owner on Nov 7, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathnoteresource.inc
99 lines (85 loc) · 1.8 KB
/
noteresource.inc
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
<?php
// $Id$
/**
* Callback for creating note resources.
*
* @param object $data
* @return object
*/
function _noteresource_create($data) {
global $user;
unset($data->id);
$data->uid = $user->uid;
$data->created = time();
$data->modified = time();
if (!isset($data->subject)) {
return services_error('Missing note attribute subject', 406);
}
if (!isset($data->note)) {
return services_error('Missing note attribute note', 406);
}
noteresource_write_note($data);
return (object)array(
'id' => $data->id,
'uri' => services_resource_uri(array('note', $data->id)),
);
}
/**
* Callback for retrieving note resources.
*
* @param int $id
* @return object
*/
function _noteresource_retrieve($id) {
return noteresource_get_note($id);
}
/**
* Callback for updating note resources.
*
* @param int $id
* @param object $data
* @return object
*/
function _noteresource_update($id, $data) {
global $user;
$note = noteresource_get_note($id);
unset($data->created);
$data->id = $id;
$data->uid = $note->uid;
$data->modified = time();
noteresource_write_note($data);
return (object)array(
'id' => $id,
'uri' => services_resource_uri(array('note', $id)),
);
}
/**
* Callback for deleting note resources.
*
* @param int $id
* @return object
*/
function _noteresource_delete($id) {
noteresource_delete_note($id);
return (object)array(
'id' => $id,
);
}
/**
* Callback for listing notes.
*
* @param int $page
* @param array $parameters
* @return array
*/
function _noteresource_index($page, $parameters) {
global $user;
$notes = array();
$res = db_query("SELECT * FROM {note} WHERE uid=%d ORDER BY modified DESC", array(
':uid' => $user->uid,
));
while ($note = db_fetch_object($res)) {
$notes[] = $note;
}
return $notes;
}