ILIAS  release_8 Revision v8.23
ILIAS\Notes\NoteDBRepository Class Reference
+ Collaboration diagram for ILIAS\Notes\NoteDBRepository:

Public Member Functions

 __construct (InternalDataService $data, \ilDBInterface $db)
 
 createNote (Note $note)
 
 deleteNote (int $id)
 
 updateNoteText (int $id, string $text)
 
 getById (int $id)
 Get note by id. More...
 
 getNotesForContext (Context $context, int $type=Note::PRIVATE, bool $incl_sub=false, int $author=0, bool $ascending=false, string $since="", string $search_text="")
 Get all notes related to a specific object. More...
 
 getNotesForObjIds (array $obj_ids, int $type=Note::PRIVATE, bool $incl_sub=false, int $author=0, bool $ascending=false, string $since="", string $search_text="")
 Get all notes related to a specific object. More...
 
 getNrOfNotesForContext (Context $context, int $type=Note::PRIVATE, bool $incl_sub=false, int $author=0)
 
 getRelatedObjIdsOfUser (int $user_id, int $type)
 
 filterObjectsWithNotes (array $obj_ids, int $type)
 
 getUserCount (int $obj_id, int $sub_obj_id, string $obj_type)
 How many users have attached a note/comment to a given object? More...
 
 countNotesAndCommentsMultipleObjects (array $obj_ids, int $user_id, bool $no_sub_objs=false)
 Get all notes related to multiple repository objects. More...
 

Protected Member Functions

 getNoteFromRecord (array $rec)
 
 getQuery (?Context $context, int $type=Note::PRIVATE, bool $incl_sub=false, int $author=0, bool $ascending=false, bool $count=false, string $since="", array $obj_ids=[], string $search_text="")
 Get query. More...
 

Protected Attributes

ilDBInterface $db
 
InternalDataService $data
 

Detailed Description

Author
Alexander Killing killi.nosp@m.ng@l.nosp@m.eifos.nosp@m..de

Definition at line 26 of file class.NoteDBRepository.php.

Constructor & Destructor Documentation

◆ __construct()

ILIAS\Notes\NoteDBRepository::__construct ( InternalDataService  $data,
\ilDBInterface  $db 
)

Definition at line 31 of file class.NoteDBRepository.php.

References ILIAS\Notes\NoteDBRepository\$data, and ILIAS\Notes\NoteDBRepository\$db.

34  {
35  $this->db = $db;
36  $this->data = $data;
37  }

Member Function Documentation

◆ countNotesAndCommentsMultipleObjects()

ILIAS\Notes\NoteDBRepository::countNotesAndCommentsMultipleObjects ( array  $obj_ids,
int  $user_id,
bool  $no_sub_objs = false 
)

Get all notes related to multiple repository objects.

Todo:
this is currently used to implement a caching in ilObjListGUI objects.

the caching should be moved into this repo instead

Definition at line 350 of file class.NoteDBRepository.php.

References ILIAS\Notes\NoteDBRepository\$db, ILIAS\Notes\Note\PRIVATE, ILIAS\Notes\Note\PUBLIC, and ilDBInterface\quote().

354  : array {
355  $db = $this->db;
356 
357  $q = "SELECT count(id) c, rep_obj_id, type FROM note WHERE " .
358  " ((type = " . $db->quote(Note::PRIVATE, "integer") . " AND " .
359  "author = " . $db->quote($user_id, "integer") . ") OR " .
360  " type = " . $db->quote(Note::PUBLIC, "integer") . ") AND " .
361  $db->in("rep_obj_id", $obj_ids, false, "integer");
362 
363  if ($no_sub_objs) {
364  $q .= " AND obj_id = " . $db->quote(0, "integer");
365  }
366 
367  $q .= " GROUP BY rep_obj_id, type ";
368 
369  $cnt = array();
370  $set = $db->query($q);
371  while ($rec = $db->fetchAssoc($set)) {
372  $cnt[$rec["rep_obj_id"]][$rec["type"]] = $rec["c"];
373  }
374  return $cnt;
375  }
fetchAssoc(ilDBStatement $statement)
quote($value, string $type)
query(string $query)
Run a (read-only) Query on the database.
in(string $field, array $values, bool $negate=false, string $type="")
+ Here is the call graph for this function:

◆ createNote()

ILIAS\Notes\NoteDBRepository::createNote ( Note  $note)

Definition at line 39 of file class.NoteDBRepository.php.

References $context, ILIAS\Notes\NoteDBRepository\$db, $id, ILIAS\Notes\Note\getAuthor(), ILIAS\Notes\NoteDBRepository\getById(), ILIAS\Notes\Note\getContext(), ILIAS\Notes\Note\getCreationDate(), ILIAS\Notes\Note\getText(), and ILIAS\Notes\Note\getType().

41  : Note {
42  $db = $this->db;
43 
44  $id = $db->nextId("note");
45  $context = $note->getContext();
46  $db->insert("note", array(
47  "id" => array("integer", $id),
48  "rep_obj_id" => array("integer", $context->getObjId()),
49  "obj_id" => array("integer", $context->getSubObjId()),
50  "obj_type" => array("text", $context->getType()),
51  "news_id" => array("integer", $context->getNewsId()),
52  "type" => array("integer", $note->getType()),
53  "author" => array("integer", $note->getAuthor()),
54  "note_text" => array("clob", $note->getText()),
55  "creation_date" => array("timestamp", $note->getCreationDate()),
56  "no_repository" => array("integer", (int) !$context->getInRepository())
57  ));
58  return $this->getById($id);
59  }
$context
Definition: webdav.php:29
insert(string $table_name, array $values)
getById(int $id)
Get note by id.
nextId(string $table_name)
$id
plugin.php for ilComponentBuildPluginInfoObjectiveTest::testAddPlugins
Definition: plugin.php:23
+ Here is the call graph for this function:

◆ deleteNote()

ILIAS\Notes\NoteDBRepository::deleteNote ( int  $id)

Definition at line 61 of file class.NoteDBRepository.php.

References ILIAS\Notes\NoteDBRepository\$db, and ilDBInterface\quote().

61  : void
62  {
63  $db = $this->db;
64  $q = "DELETE FROM note WHERE id = " .
65  $db->quote($id, "integer");
66  $db->manipulate($q);
67  }
quote($value, string $type)
$id
plugin.php for ilComponentBuildPluginInfoObjectiveTest::testAddPlugins
Definition: plugin.php:23
manipulate(string $query)
Run a (write) Query on the database.
+ Here is the call graph for this function:

◆ filterObjectsWithNotes()

ILIAS\Notes\NoteDBRepository::filterObjectsWithNotes ( array  $obj_ids,
int  $type 
)
Parameters
int[]$obj_ids
Returns
int[]

Definition at line 308 of file class.NoteDBRepository.php.

References ILIAS\Notes\NoteDBRepository\$db, ilDBInterface\in(), and ILIAS\Repository\int().

308  : array
309  {
310  $db = $this->db;
311 
312  $q = "SELECT DISTINCT rep_obj_id FROM note WHERE " .
313  $db->in("rep_obj_id", $obj_ids, false, "integer") .
314  " AND type = " . $db->quote($type, "integer") .
315  " AND (no_repository IS NULL OR no_repository < " . $db->quote(1, "integer") . ")";
316 
317  $set = $db->query($q);
318  $ids = [];
319  while ($rec = $db->fetchAssoc($set)) {
320  $ids[] = (int) $rec["rep_obj_id"];
321  }
322  return $ids;
323  }
$type
fetchAssoc(ilDBStatement $statement)
quote($value, string $type)
query(string $query)
Run a (read-only) Query on the database.
in(string $field, array $values, bool $negate=false, string $type="")
+ Here is the call graph for this function:

◆ getById()

ILIAS\Notes\NoteDBRepository::getById ( int  $id)

Get note by id.

Exceptions
NoteNotFoundException

Definition at line 88 of file class.NoteDBRepository.php.

References ILIAS\Notes\NoteDBRepository\$db, ILIAS\Notes\NoteDBRepository\getNoteFromRecord(), and ilDBInterface\queryF().

Referenced by ILIAS\Notes\NoteDBRepository\createNote().

90  : Note {
91  $db = $this->db;
92 
93  $set = $db->queryF(
94  "SELECT * FROM note " .
95  " WHERE id = %s ",
96  ["integer"],
97  [$id]
98  );
99  if ($rec = $db->fetchAssoc($set)) {
100  return $this->getNoteFromRecord($rec);
101  }
102  throw new NoteNotFoundException("Note with ID $id not found.");
103  }
fetchAssoc(ilDBStatement $statement)
queryF(string $query, array $types, array $values)
$id
plugin.php for ilComponentBuildPluginInfoObjectiveTest::testAddPlugins
Definition: plugin.php:23
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getNoteFromRecord()

ILIAS\Notes\NoteDBRepository::getNoteFromRecord ( array  $rec)
protected

Definition at line 105 of file class.NoteDBRepository.php.

References ILIAS\Repository\int().

Referenced by ILIAS\Notes\NoteDBRepository\getById(), ILIAS\Notes\NoteDBRepository\getNotesForContext(), and ILIAS\Notes\NoteDBRepository\getNotesForObjIds().

105  : Note
106  {
107  return $this->data->note(
108  (int) $rec["id"],
109  $this->data->context(
110  (int) $rec["rep_obj_id"],
111  (int) $rec["obj_id"],
112  $rec["obj_type"],
113  (int) $rec["news_id"],
114  !$rec["no_repository"]
115  ),
116  (string) $rec["note_text"],
117  (int) $rec["author"],
118  (int) $rec["type"],
119  $rec["creation_date"],
120  $rec["update_date"]
121  );
122  }
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getNotesForContext()

ILIAS\Notes\NoteDBRepository::getNotesForContext ( Context  $context,
int  $type = Note::PRIVATE,
bool  $incl_sub = false,
int  $author = 0,
bool  $ascending = false,
string  $since = "",
string  $search_text = "" 
)

Get all notes related to a specific object.

Returns
Note[]

Definition at line 194 of file class.NoteDBRepository.php.

References ILIAS\Notes\NoteDBRepository\$db, $query, $type, ILIAS\Notes\NoteDBRepository\getNoteFromRecord(), and ILIAS\Notes\NoteDBRepository\getQuery().

202  : array {
203  $db = $this->db;
204 
205  $query = $this->getQuery(
206  $context,
207  $type,
208  $incl_sub,
209  $author,
210  $ascending,
211  false,
212  $since,
213  [],
214  $search_text
215  );
216 
217  $set = $db->query($query);
218  $notes = [];
219  while ($note_rec = $db->fetchAssoc($set)) {
220  $notes[] = $this->getNoteFromRecord($note_rec);
221  }
222  return $notes;
223  }
getQuery(?Context $context, int $type=Note::PRIVATE, bool $incl_sub=false, int $author=0, bool $ascending=false, bool $count=false, string $since="", array $obj_ids=[], string $search_text="")
Get query.
$context
Definition: webdav.php:29
$type
fetchAssoc(ilDBStatement $statement)
query(string $query)
Run a (read-only) Query on the database.
$query
+ Here is the call graph for this function:

◆ getNotesForObjIds()

ILIAS\Notes\NoteDBRepository::getNotesForObjIds ( array  $obj_ids,
int  $type = Note::PRIVATE,
bool  $incl_sub = false,
int  $author = 0,
bool  $ascending = false,
string  $since = "",
string  $search_text = "" 
)

Get all notes related to a specific object.

Returns
Note[]

Definition at line 229 of file class.NoteDBRepository.php.

References ILIAS\Notes\NoteDBRepository\$db, $query, $type, ILIAS\Notes\NoteDBRepository\getNoteFromRecord(), and ILIAS\Notes\NoteDBRepository\getQuery().

237  : array {
238  $db = $this->db;
239 
240  $query = $this->getQuery(
241  null,
242  $type,
243  $incl_sub,
244  $author,
245  $ascending,
246  false,
247  $since,
248  $obj_ids,
249  $search_text
250  );
251 
252  $set = $db->query($query);
253  $notes = [];
254  while ($note_rec = $db->fetchAssoc($set)) {
255  $notes[] = $this->getNoteFromRecord($note_rec);
256  }
257  return $notes;
258  }
getQuery(?Context $context, int $type=Note::PRIVATE, bool $incl_sub=false, int $author=0, bool $ascending=false, bool $count=false, string $since="", array $obj_ids=[], string $search_text="")
Get query.
$type
fetchAssoc(ilDBStatement $statement)
query(string $query)
Run a (read-only) Query on the database.
$query
+ Here is the call graph for this function:

◆ getNrOfNotesForContext()

ILIAS\Notes\NoteDBRepository::getNrOfNotesForContext ( Context  $context,
int  $type = Note::PRIVATE,
bool  $incl_sub = false,
int  $author = 0 
)

Definition at line 260 of file class.NoteDBRepository.php.

References ILIAS\Notes\NoteDBRepository\$db, $query, $type, and ILIAS\Notes\NoteDBRepository\getQuery().

265  : int {
266  $db = $this->db;
267 
268  $query = $this->getQuery(
269  $context,
270  $type,
271  $incl_sub,
272  $author,
273  false,
274  true
275  );
276 
277  $set = $db->query($query);
278  $rec = $db->fetchAssoc($set);
279  return (int) $rec["cnt"];
280  }
getQuery(?Context $context, int $type=Note::PRIVATE, bool $incl_sub=false, int $author=0, bool $ascending=false, bool $count=false, string $since="", array $obj_ids=[], string $search_text="")
Get query.
$context
Definition: webdav.php:29
$type
fetchAssoc(ilDBStatement $statement)
query(string $query)
Run a (read-only) Query on the database.
$query
+ Here is the call graph for this function:

◆ getQuery()

ILIAS\Notes\NoteDBRepository::getQuery ( ?Context  $context,
int  $type = Note::PRIVATE,
bool  $incl_sub = false,
int  $author = 0,
bool  $ascending = false,
bool  $count = false,
string  $since = "",
array  $obj_ids = [],
string  $search_text = "" 
)
protected

Get query.

Returns
string

Definition at line 128 of file class.NoteDBRepository.php.

References $context, ILIAS\Notes\NoteDBRepository\$db, $query, $type, ILIAS\Notes\Context\getInRepository(), ILIAS\Notes\Context\getNewsId(), ILIAS\Notes\Context\getObjId(), ILIAS\Notes\Context\getSubObjId(), ILIAS\Notes\Context\getType(), and ilDBInterface\quote().

Referenced by ILIAS\Notes\NoteDBRepository\getNotesForContext(), ILIAS\Notes\NoteDBRepository\getNotesForObjIds(), and ILIAS\Notes\NoteDBRepository\getNrOfNotesForContext().

138  : string {
139  $db = $this->db;
140 
141  $author_where = ($author > 0)
142  ? " AND author = " . $db->quote($author, "integer")
143  : "";
144 
145  $sub_where = ($context)
146  ? " rep_obj_id = " . $db->quote($context->getObjId(), "integer")
147  : " " . $db->in("rep_obj_id", $obj_ids, false, "integer");
148 
149  $sub_where .= ($context && !$incl_sub)
150  ? " AND note.obj_id = " . $db->quote($context->getSubObjId(), "integer") .
151  " AND note.obj_type = " . $db->quote($context->getType(), "text")
152  : "";
153 
154  if ($since !== "") {
155  $sub_where .= " AND creation_date > " . $db->quote($since, "timestamp");
156  }
157 
158  $news_where = "";
159  if ($context) {
160  $news_where =
161  " AND news_id = " . $db->quote($context->getNewsId(), "integer");
162 
163  $sub_where .= " AND no_repository = " . $db->quote(!$context->getInRepository(), "integer");
164  }
165 
166  // search text
167  $join = "";
168  if ($search_text !== "") {
169  $sub_where .= " AND (" . $db->like("note_text", "text", "%" . $search_text . "%");
170  $join = " JOIN usr_data ud ON (author = ud.usr_id)";
171  $join .= " LEFT JOIN object_data od ON (rep_obj_id = od.obj_id)";
172  $sub_where .= " OR " . $db->like("ud.lastname", "text", "%" . $search_text . "%");
173  $sub_where .= " OR " . $db->like("ud.firstname", "text", "%" . $search_text . "%");
174  $sub_where .= " OR " . $db->like("ud.login", "text", "%" . $search_text . "%");
175  $sub_where .= " OR " . $db->like("od.title", "text", "%" . $search_text . "%");
176  $sub_where .= ")";
177  }
178 
179  $fields = $count ? "count(*) cnt" : "note.*";
180  $query = "SELECT $fields FROM note $join WHERE " .
181  $sub_where .
182  " AND note.type = " . $db->quote($type, "integer") .
183  $author_where .
184  $news_where .
185  " ORDER BY creation_date ";
186  $query .= ($ascending) ? "ASC" : "DESC";
187  return $query;
188  }
$context
Definition: webdav.php:29
$type
like(string $column, string $type, string $value="?", bool $case_insensitive=true)
Generate a like subquery.
quote($value, string $type)
$query
in(string $field, array $values, bool $negate=false, string $type="")
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getRelatedObjIdsOfUser()

ILIAS\Notes\NoteDBRepository::getRelatedObjIdsOfUser ( int  $user_id,
int  $type 
)
Returns
int[]

Definition at line 285 of file class.NoteDBRepository.php.

References ILIAS\Notes\NoteDBRepository\$db, ILIAS\Repository\int(), and ilDBInterface\quote().

288  : array {
289  $db = $this->db;
290 
291  $q = "SELECT DISTINCT rep_obj_id FROM note WHERE " .
292  " type = " . $db->quote($type, "integer") .
293  " AND author = " . $db->quote($user_id, "integer") .
294  " AND (no_repository IS NULL OR no_repository < " . $db->quote(1, "integer") . ")";
295 
296  $set = $db->query($q);
297  $ids = [];
298  while ($rec = $db->fetchAssoc($set)) {
299  $ids[] = (int) $rec["rep_obj_id"];
300  }
301  return $ids;
302  }
$type
fetchAssoc(ilDBStatement $statement)
quote($value, string $type)
query(string $query)
Run a (read-only) Query on the database.
+ Here is the call graph for this function:

◆ getUserCount()

ILIAS\Notes\NoteDBRepository::getUserCount ( int  $obj_id,
int  $sub_obj_id,
string  $obj_type 
)

How many users have attached a note/comment to a given object?

Definition at line 328 of file class.NoteDBRepository.php.

References ILIAS\Notes\NoteDBRepository\$db, and ilDBInterface\queryF().

332  : int {
333  $db = $this->db;
334 
335  $set = $db->queryF(
336  "SELECT count(DISTINCT author) cnt FROM note WHERE " .
337  "rep_obj_id = %s AND obj_id = %s AND obj_type = %s",
338  array("integer", "integer", "text"),
339  array($obj_id, $sub_obj_id, $obj_type)
340  );
341  $rec = $db->fetchAssoc($set);
342  return (int) $rec["cnt"];
343  }
fetchAssoc(ilDBStatement $statement)
queryF(string $query, array $types, array $values)
+ Here is the call graph for this function:

◆ updateNoteText()

ILIAS\Notes\NoteDBRepository::updateNoteText ( int  $id,
string  $text 
)

Definition at line 69 of file class.NoteDBRepository.php.

References ILIAS\Notes\NoteDBRepository\$db, and ilUtil\now().

72  : void {
73  $db = $this->db;
74 
75  $update_date = \ilUtil::now();
76  $db->update("note", array(
77  "note_text" => array("clob", $text),
78  "update_date" => array("timestamp", $update_date),
79  ), array(
80  "id" => array("integer", $id)
81  ));
82  }
update(string $table_name, array $values, array $where)
$where MUST contain existing columns only.
static now()
Return current timestamp in Y-m-d H:i:s format.
$id
plugin.php for ilComponentBuildPluginInfoObjectiveTest::testAddPlugins
Definition: plugin.php:23
+ Here is the call graph for this function:

Field Documentation

◆ $data

InternalDataService ILIAS\Notes\NoteDBRepository::$data
protected

Definition at line 29 of file class.NoteDBRepository.php.

Referenced by ILIAS\Notes\NoteDBRepository\__construct().

◆ $db


The documentation for this class was generated from the following file: