ILIAS  trunk Revision v11.0_alpha-1713-gd8962da2f67
All Data Structures Namespaces Files Functions Variables Enumerations Enumerator Modules Pages
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 352 of file class.NoteDBRepository.php.

References ILIAS\Notes\NoteDBRepository\$db, $q, ILIAS\Notes\Note\PRIVATE, and ILIAS\Notes\Note\PUBLIC.

356  : array {
357  $db = $this->db;
358 
359  $q = "SELECT count(id) c, rep_obj_id, type FROM note WHERE " .
360  " ((type = " . $db->quote(Note::PRIVATE, "integer") . " AND " .
361  "author = " . $db->quote($user_id, "integer") . ") OR " .
362  " type = " . $db->quote(Note::PUBLIC, "integer") . ") AND " .
363  $db->in("rep_obj_id", $obj_ids, false, "integer");
364 
365  if ($no_sub_objs) {
366  $q .= " AND obj_id = " . $db->quote(0, "integer");
367  }
368 
369  $q .= " GROUP BY rep_obj_id, type ";
370 
371  $cnt = array();
372  $set = $db->query($q);
373  while ($rec = $db->fetchAssoc($set)) {
374  $cnt[$rec["rep_obj_id"]][$rec["type"]] = $rec["c"];
375  }
376  return $cnt;
377  }
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="")
$q
Definition: shib_logout.php:21

◆ 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\getRecipient(), 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  "recipient" => array("integer", $note->getRecipient()),
58  ));
59  return $this->getById($id);
60  }
$context
Definition: webdav.php:31
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 62 of file class.NoteDBRepository.php.

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

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

◆ filterObjectsWithNotes()

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

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

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

310  : array
311  {
312  $db = $this->db;
313 
314  $q = "SELECT DISTINCT rep_obj_id FROM note WHERE " .
315  $db->in("rep_obj_id", $obj_ids, false, "integer") .
316  " AND type = " . $db->quote($type, "integer") .
317  " AND (no_repository IS NULL OR no_repository < " . $db->quote(1, "integer") . ")";
318 
319  $set = $db->query($q);
320  $ids = [];
321  while ($rec = $db->fetchAssoc($set)) {
322  $ids[] = (int) $rec["rep_obj_id"];
323  }
324  return $ids;
325  }
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="")
$q
Definition: shib_logout.php:21
+ Here is the call graph for this function:

◆ getById()

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

Get note by id.

Exceptions
NoteNotFoundException

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

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

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

91  : Note {
92  $db = $this->db;
93 
94  $set = $db->queryF(
95  "SELECT * FROM note " .
96  " WHERE id = %s ",
97  ["integer"],
98  [$id]
99  );
100  if ($rec = $db->fetchAssoc($set)) {
101  return $this->getNoteFromRecord($rec);
102  }
103  throw new NoteNotFoundException("Note with ID $id not found.");
104  }
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 106 of file class.NoteDBRepository.php.

References ILIAS\Repository\int().

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

106  : Note
107  {
108  return $this->data->note(
109  (int) $rec["id"],
110  $this->data->context(
111  (int) $rec["rep_obj_id"],
112  (int) $rec["obj_id"],
113  $rec["obj_type"],
114  (int) $rec["news_id"],
115  !$rec["no_repository"]
116  ),
117  (string) $rec["note_text"],
118  (int) $rec["author"],
119  (int) $rec["type"],
120  $rec["creation_date"],
121  $rec["update_date"],
122  (int) $rec["recipient"]
123  );
124  }
+ 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 196 of file class.NoteDBRepository.php.

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

204  : array {
205  $db = $this->db;
206 
207  $query = $this->getQuery(
208  $context,
209  $type,
210  $incl_sub,
211  $author,
212  $ascending,
213  false,
214  $since,
215  [],
216  $search_text
217  );
218 
219  $set = $db->query($query);
220  $notes = [];
221  while ($note_rec = $db->fetchAssoc($set)) {
222  $notes[] = $this->getNoteFromRecord($note_rec);
223  }
224  return $notes;
225  }
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:31
fetchAssoc(ilDBStatement $statement)
query(string $query)
Run a (read-only) Query on the database.
+ 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 231 of file class.NoteDBRepository.php.

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

239  : array {
240  $db = $this->db;
241 
242  $query = $this->getQuery(
243  null,
244  $type,
245  $incl_sub,
246  $author,
247  $ascending,
248  false,
249  $since,
250  $obj_ids,
251  $search_text
252  );
253 
254  $set = $db->query($query);
255  $notes = [];
256  while ($note_rec = $db->fetchAssoc($set)) {
257  $notes[] = $this->getNoteFromRecord($note_rec);
258  }
259  return $notes;
260  }
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.
fetchAssoc(ilDBStatement $statement)
while($session_entry=$r->fetchRow(ilDBConstants::FETCHMODE_ASSOC)) return null
query(string $query)
Run a (read-only) Query on the database.
+ 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 262 of file class.NoteDBRepository.php.

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

267  : int {
268  $db = $this->db;
269 
270  $query = $this->getQuery(
271  $context,
272  $type,
273  $incl_sub,
274  $author,
275  false,
276  true
277  );
278 
279  $set = $db->query($query);
280  $rec = $db->fetchAssoc($set);
281  return (int) $rec["cnt"];
282  }
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:31
fetchAssoc(ilDBStatement $statement)
query(string $query)
Run a (read-only) Query on the database.
+ 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 130 of file class.NoteDBRepository.php.

References $context, ILIAS\Notes\NoteDBRepository\$db, 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().

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

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

290  : array {
291  $db = $this->db;
292 
293  $q = "SELECT DISTINCT rep_obj_id FROM note WHERE " .
294  " type = " . $db->quote($type, "integer") .
295  " AND author = " . $db->quote($user_id, "integer") .
296  " AND (no_repository IS NULL OR no_repository < " . $db->quote(1, "integer") . ")";
297 
298  $set = $db->query($q);
299  $ids = [];
300  while ($rec = $db->fetchAssoc($set)) {
301  $ids[] = (int) $rec["rep_obj_id"];
302  }
303  return $ids;
304  }
fetchAssoc(ilDBStatement $statement)
quote($value, string $type)
query(string $query)
Run a (read-only) Query on the database.
$q
Definition: shib_logout.php:21
+ 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 330 of file class.NoteDBRepository.php.

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

334  : int {
335  $db = $this->db;
336 
337  $set = $db->queryF(
338  "SELECT count(DISTINCT author) cnt FROM note WHERE " .
339  "rep_obj_id = %s AND obj_id = %s AND obj_type = %s",
340  array("integer", "integer", "text"),
341  array($obj_id, $sub_obj_id, $obj_type)
342  );
343  $rec = $db->fetchAssoc($set);
344  return (int) $rec["cnt"];
345  }
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 70 of file class.NoteDBRepository.php.

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

73  : void {
74  $db = $this->db;
75 
76  $update_date = \ilUtil::now();
77  $db->update("note", array(
78  "note_text" => array("clob", $text),
79  "update_date" => array("timestamp", $update_date),
80  ), array(
81  "id" => array("integer", $id)
82  ));
83  }
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: