ILIAS  release_7 Revision v7.30-3-g800a261c036
class.InvitationsDBRepository.php
Go to the documentation of this file.
1<?php
2
4
5/* Copyright (c) 1998-2019 ILIAS open source, Extended GPL, see docs/LICENSE */
6
13{
17 protected $db;
18
22 public function __construct(\ilDBInterface $db = null)
23 {
24 global $DIC;
25
26 $this->db = (is_null($db))
27 ? $DIC->database()
28 : $db;
29 }
30
31
38 public function remove(int $survey_id, int $user_id)
39 {
40 $db = $this->db;
41
42 $db->manipulateF(
43 "DELETE FROM svy_invitation WHERE " .
44 " survey_id = %s AND user_id = %s",
45 ["integer", "integer"],
46 [$survey_id, $user_id]
47 );
48 }
49
50
57 public function add(int $survey_id, int $user_id)
58 {
59 $db = $this->db;
60
61 $db->replace(
62 "svy_invitation",
63 [ // pk
64 "survey_id" => ["integer", $survey_id],
65 "user_id" => ["integer", $user_id]
66 ],
67 []
68 );
69 }
70
77 public function getAllForSurvey(int $survey_id) : array
78 {
79 $db = $this->db;
80
81 $items = [];
82 $set = $db->queryF(
83 "SELECT user_id FROM svy_invitation " .
84 " WHERE survey_id = %s ",
85 ["integer"],
86 [$survey_id]
87 );
88
89 while ($rec = $db->fetchAssoc($set)) {
90 $items[] = $rec["user_id"];
91 }
92 return $items;
93 }
94
101 public function getAllForUser(int $user_id) : array
102 {
103 $db = $this->db;
104
105 $items = [];
106 $set = $db->queryF(
107 "SELECT survey_id FROM svy_invitation " .
108 " WHERE user_id = %s ",
109 ["integer"],
110 [$user_id]
111 );
112
113 while ($rec = $db->fetchAssoc($set)) {
114 $items[] = (int) $rec["survey_id"];
115 }
116 return $items;
117 }
118}
An exception for terminatinating execution or to throw for unit testing.
getAllForSurvey(int $survey_id)
Get invitations for survey.
add(int $survey_id, int $user_id)
Add invitation.
getAllForUser(int $user_id)
Get surveys where user is invited.
global $DIC
Definition: goto.php:24
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...