|
@@ 45-66 (lines=22) @@
|
| 42 |
|
* @param null $user_id |
| 43 |
|
* @return OwnNote if not found |
| 44 |
|
*/ |
| 45 |
|
public function find($note_id, $user_id = null) { |
| 46 |
|
$params = [$note_id]; |
| 47 |
|
$uidSql = ''; |
| 48 |
|
if($user_id){ |
| 49 |
|
$params[] = $user_id; |
| 50 |
|
$uidSql = 'and n.uid = ?'; |
| 51 |
|
} |
| 52 |
|
$sql = "SELECT n.id, n.uid, n.name, n.grouping, n.shared, n.mtime, n.deleted, p.pid, GROUP_CONCAT(p.note SEPARATOR '') as note FROM *PREFIX*ownnote n INNER JOIN *PREFIX*ownnote_parts p ON n.id = p.id WHERE n.id= ? $uidSql and n.deleted = 0 GROUP BY p.id"; |
| 53 |
|
$results = []; |
| 54 |
|
foreach($this->execute($sql, $params)->fetchAll() as $item){ |
| 55 |
|
$note = new OwnNote(); |
| 56 |
|
$note->setId($item['id']); |
| 57 |
|
$note->setName($item['name']); |
| 58 |
|
$note->setGrouping($item['grouping']); |
| 59 |
|
$note->setMtime($item['mtime']); |
| 60 |
|
$note->setDeleted($item['deleted']); |
| 61 |
|
$note->setNote($item['note']); |
| 62 |
|
$note->setUid($item['uid']); |
| 63 |
|
$results[] = $note; |
| 64 |
|
} |
| 65 |
|
return array_shift($results); |
| 66 |
|
} |
| 67 |
|
|
| 68 |
|
|
| 69 |
|
/** |
|
@@ 96-117 (lines=22) @@
|
| 93 |
|
* @throws \OCP\AppFramework\Db\MultipleObjectsReturnedException if more than one result |
| 94 |
|
* @return OwnNote[] |
| 95 |
|
*/ |
| 96 |
|
public function findNotesByGroup($group, $userId) { |
| 97 |
|
$params = [$group]; |
| 98 |
|
$uidSql = ''; |
| 99 |
|
if($userId){ |
| 100 |
|
$params[] = $userId; |
| 101 |
|
$uidSql = 'and n.uid = ?'; |
| 102 |
|
} |
| 103 |
|
$sql = "SELECT n.uid, n.id, n.name, n.grouping, n.shared, n.mtime, n.deleted, p.pid, GROUP_CONCAT(p.note SEPARATOR '') as note FROM *PREFIX*ownnote n INNER JOIN *PREFIX*ownnote_parts p ON n.id = p.id WHERE n.deleted = 0 $uidSql and n.grouping = ? GROUP BY p.id"; |
| 104 |
|
$results = []; |
| 105 |
|
foreach($this->execute($sql, $params)->fetchAll() as $item){ |
| 106 |
|
$note = new OwnNote(); |
| 107 |
|
$note->setId($item['id']); |
| 108 |
|
$note->setName($item['name']); |
| 109 |
|
$note->setGrouping($item['grouping']); |
| 110 |
|
$note->setMtime($item['mtime']); |
| 111 |
|
$note->setDeleted($item['deleted']); |
| 112 |
|
$note->setNote($item['note']); |
| 113 |
|
$note->setUid($item['uid']); |
| 114 |
|
$results[] = $note; |
| 115 |
|
} |
| 116 |
|
return $results; |
| 117 |
|
} |
| 118 |
|
|
| 119 |
|
/** |
| 120 |
|
* Creates a note |