@@ 46-78 (lines=33) @@ | ||
43 | * @param bool|int $deleted |
|
44 | * @return Notebook[]|Notebook |
|
45 | */ |
|
46 | public function find($notebook_id, $user_id = null, $deleted = false) { |
|
47 | $params = []; |
|
48 | $where = []; |
|
49 | if($notebook_id){ |
|
50 | $where[] = 'g.id= ?'; |
|
51 | $params[] = $notebook_id; |
|
52 | } |
|
53 | ||
54 | if ($user_id) { |
|
55 | $params[] = $user_id; |
|
56 | $where[] = 'g.uid = ?'; |
|
57 | } |
|
58 | ||
59 | if ($deleted !== false) { |
|
60 | $params[] = $deleted; |
|
61 | $where[] = 'g.deleted = ?'; |
|
62 | } |
|
63 | $where = implode(' AND ', $where); |
|
64 | if($where){ |
|
65 | $where = 'WHERE '. $where; |
|
66 | } |
|
67 | $sql = "SELECT g.*, g.guid as guid, COUNT(n.id) as note_count FROM *PREFIX*nextnote_groups g LEFT JOIN *PREFIX*nextnote_notes n ON g.name=n.grouping $where GROUP BY g.id"; |
|
68 | $results = []; |
|
69 | foreach ($this->execute($sql, $params)->fetchAll() as $item) { |
|
70 | $results[] = $this->makeEntityFromDBResult($item); |
|
71 | } |
|
72 | // var_dump($results); |
|
73 | if(count($results) === 1){ |
|
74 | return reset($results); |
|
75 | } |
|
76 | ||
77 | return $results; |
|
78 | } |
|
79 | ||
80 | /** |
|
81 | * @param $group_name |
|
@@ 86-118 (lines=33) @@ | ||
83 | * @param bool $deleted |
|
84 | * @return Notebook[]|Notebook |
|
85 | */ |
|
86 | public function findByName($group_name, $user_id = null, $deleted = false) { |
|
87 | $params = []; |
|
88 | $where = []; |
|
89 | if($group_name){ |
|
90 | $where[] = 'g.name = ?'; |
|
91 | $params[] = $group_name; |
|
92 | } |
|
93 | ||
94 | if ($user_id) { |
|
95 | $params[] = $user_id; |
|
96 | $where[] = 'g.uid = ?'; |
|
97 | } |
|
98 | ||
99 | if ($deleted !== false) { |
|
100 | $params[] = $deleted; |
|
101 | $where[] = 'g.deleted = ?'; |
|
102 | } |
|
103 | $where = implode(' AND ', $where); |
|
104 | if($where){ |
|
105 | $where = 'WHERE '. $where; |
|
106 | } |
|
107 | $sql = "SELECT g.*, COUNT(n.id) as note_count FROM *PREFIX*nextnote_groups g LEFT JOIN *PREFIX*nextnote_notes n ON g.name=n.grouping $where GROUP BY g.id"; |
|
108 | $results = []; |
|
109 | foreach ($this->execute($sql, $params)->fetchAll() as $item) { |
|
110 | $results[] = $this->makeEntityFromDBResult($item); |
|
111 | } |
|
112 | ||
113 | if(count($results) === 1){ |
|
114 | return reset($results); |
|
115 | } |
|
116 | ||
117 | return $results; |
|
118 | } |
|
119 | ||
120 | /** |
|
121 | * Creates a group |