17 import(
'lib.pkp.classes.note.Note');
19 define(
'NOTE_ORDER_DATE_CREATED', 0x0001);
20 define(
'NOTE_ORDER_ID', 0x0002);
39 'SELECT * FROM notes WHERE note_id = ?', (
int) $noteId
42 $note = $this->
_fromRow($result->GetRowAssoc(
false));
56 'SELECT * FROM notes WHERE user_id = ? ORDER BY date_created DESC',
73 function getByAssoc($assocType, $assocId, $userId =
null, $orderBy = NOTE_ORDER_DATE_CREATED, $sortDirection = SORT_DIRECTION_DESC, $isAdmin =
false) {
74 $params = array((
int) $assocId, (
int) $assocType);
75 if ($userId) $params[] = (int) $userId;
80 $orderSanitized =
'note_id';
82 case NOTE_ORDER_DATE_CREATED:
84 $orderSanitized =
'date_created';
86 switch ($sortDirection) {
87 case SORT_DIRECTION_ASC:
88 $directionSanitized =
'ASC';
90 case SORT_DIRECTION_DESC:
92 $directionSanitized =
'DESC';
100 ' . ($userId?
' AND user_id = ?':
'') .
102 AND (title IS NOT NULL OR contents IS NOT NULL)') .
'
103 ORDER BY ' . $orderSanitized .
' ' . $directionSanitized,
117 $params = array((
int) $assocId, (
int) $assocType);
118 if ($userId) $params[] = (int) $userId;
123 WHERE assoc_id = ? AND assoc_type = ?
124 ' . ($userId?
' AND user_id = ?':
''),
127 $returner = isset($result->fields[0]) && $result->fields[0] == 0 ? false :
true;
140 $params = array((
int) $assocId, (
int) $assocType, (
int) $userId);
145 JOIN item_views v ON (v.assoc_type = ? AND v.assoc_id = CAST(n.note_id AS CHAR) AND v.user_id = ?)
146 WHERE n.assoc_type = ? AND
150 (
int) ASSOC_TYPE_NOTE,
157 $returner = isset($result->fields[0]) && $result->fields[0] == 0 ? false :
true;
170 $note->setId($row[
'note_id']);
171 $note->setUserId($row[
'user_id']);
172 $note->setDateCreated($this->
datetimeFromDB($row[
'date_created']));
173 $note->setDateModified($this->
datetimeFromDB($row[
'date_modified']));
174 $note->setContents($row[
'contents']);
175 $note->setTitle($row[
'title']);
176 $note->setAssocType($row[
'assoc_type']);
177 $note->setAssocId($row[
'assoc_id']);
192 sprintf(
'INSERT INTO notes
193 (user_id, date_created, date_modified, title, contents, assoc_type, assoc_id)
195 (?, %s, %s, ?, ?, ?, ?)',
200 (
int) $note->getUserId(),
202 $note->getContents(),
203 (
int) $note->getAssocType(),
204 (
int) $note->getAssocId()
209 return $note->getId();
219 sprintf(
'UPDATE notes SET
232 (
int) $note->getUserId(),
234 $note->getContents(),
235 (
int) $note->getAssocType(),
236 (
int) $note->getAssocId(),
256 $params = array((
int) $noteId);
257 if ($userId) $params[] = (int) $userId;
260 'DELETE FROM notes WHERE note_id = ?' .
261 ($userId?
' AND user_id = ?':
''),
272 $notes = $this->
getByAssoc($assocType, $assocId);
273 while ($note = $notes->next()) {