ILIAS  trunk Revision v11.0_alpha-1689-g66c127b4ae8
All Data Structures Namespaces Files Functions Variables Enumerations Enumerator Modules Pages
class.InvitationsDBRepository.php
Go to the documentation of this file.
1 <?php
2 
19 declare(strict_types=1);
20 
22 
24 
31 {
32  protected \ilDBInterface $db;
34 
35  public function __construct(
36  InternalDataService $data,
37  \ilDBInterface $db
38  ) {
39  $this->data = $data;
40  $this->db = $db;
41  }
42 
43 
50  public function remove(int $survey_id, int $user_id): void
51  {
52  $db = $this->db;
53 
54  $db->manipulateF(
55  "DELETE FROM svy_invitation WHERE " .
56  " survey_id = %s AND user_id = %s",
57  ["integer", "integer"],
58  [$survey_id, $user_id]
59  );
60  }
61 
62  public function removeAll(int $survey_id): void
63  {
64  $db = $this->db;
65 
66  $db->manipulateF(
67  "DELETE FROM svy_invitation WHERE " .
68  " survey_id = %s",
69  ["integer"],
70  [$survey_id]
71  );
72  }
73 
74 
81  public function add(int $survey_id, int $user_id): void
82  {
83  $db = $this->db;
84 
85  $db->replace(
86  "svy_invitation",
87  [ // pk
88  "survey_id" => ["integer", $survey_id],
89  "user_id" => ["integer", $user_id]
90  ],
91  []
92  );
93  }
94 
101  public function getAllForSurvey(int $survey_id): array
102  {
103  $db = $this->db;
104 
105  $items = [];
106  $set = $db->queryF(
107  "SELECT user_id FROM svy_invitation " .
108  " WHERE survey_id = %s ",
109  ["integer"],
110  [$survey_id]
111  );
112 
113  while ($rec = $db->fetchAssoc($set)) {
114  $items[] = (int) $rec["user_id"];
115  }
116  return $items;
117  }
118 
124  public function getAllForUser(int $user_id): array
125  {
126  $db = $this->db;
127 
128  $items = [];
129  $set = $db->queryF(
130  "SELECT survey_id FROM svy_invitation " .
131  " WHERE user_id = %s ",
132  ["integer"],
133  [$user_id]
134  );
135 
136  while ($rec = $db->fetchAssoc($set)) {
137  $items[] = (int) $rec["survey_id"];
138  }
139  return $items;
140  }
141 }
manipulateF(string $query, array $types, array $values)
getAllForUser(int $user_id)
Get surveys where user is invited.
add(int $survey_id, int $user_id)
Add invitation.
queryF(string $query, array $types, array $values)
__construct(InternalDataService $data, \ilDBInterface $db)
replace(string $table, array $primary_keys, array $other_columns)
Replace into method.
getAllForSurvey(int $survey_id)
Get invitations for survey.