ILIAS  trunk Revision v11.0_alpha-1753-gb21ca8c4367
All Data Structures Namespaces Files Functions Variables Enumerations Enumerator Modules Pages
class.ilLPStatusSurveyFinished.php
Go to the documentation of this file.
1 <?php
2 
19 declare(strict_types=0);
20 
21 // patch-begin svy_lp
27 {
28  public static function _getNotAttempted(int $a_obj_id): array
29  {
30  $invited = self::getInvitations($a_obj_id);
31  if ($invited === []) {
32  return [];
33  }
34  $users = array_diff(
35  (array) $invited,
37  );
38  $users = array_diff(
39  $users,
41  );
42  return $users;
43  }
44 
45  public static function _getInProgress(int $a_obj_id): array
46  {
47  return self::getParticipants($a_obj_id);
48  }
49 
50  public static function _getCompleted(int $a_obj_id): array
51  {
52  return self::getParticipants($a_obj_id, true);
53  }
54 
55  public function determineStatus(
56  int $a_obj_id,
57  int $a_usr_id,
58  ?object $a_obj = null
59  ): int {
60  $survey_id = self::getSurveyId($a_obj_id);
61  if (!$survey_id) {
63  }
65 
66  if (ilObjSurveyAccess::_isSurveyParticipant($a_usr_id, $survey_id)) {
68 
69  if (ilObjSurveyAccess::_lookupFinished($a_obj_id, $a_usr_id)) {
71  }
72  }
73  return $status;
74  }
75 
76  protected static function getSurveyId(int $a_obj_id): int
77  {
78  global $DIC;
79 
80  $ilDB = $DIC['ilDB'];
81  $set = $ilDB->query(
82  "SELECT survey_id FROM svy_svy" .
83  " WHERE obj_fi = " . $ilDB->quote($a_obj_id)
84  );
85  $row = $ilDB->fetchAssoc($set);
86  return (int) ($row["survey_id"] ?? 0);
87  }
88 
89  public static function getParticipants(
90  int $a_obj_id,
91  bool $a_only_finished = false
92  ): array {
93  global $DIC;
94 
95  $ilDB = $DIC['ilDB'];
96  $res = array();
97  $survey_id = self::getSurveyId($a_obj_id);
98  if (!$survey_id) {
99  return $res;
100  }
101 
102  $sql = "SELECT user_fi FROM svy_finished fin" .
103  " WHERE fin.survey_fi = " . $ilDB->quote($survey_id, "integer");
104 
105  if ($a_only_finished) {
106  $sql .= " AND fin.state = " . $ilDB->quote(1, "integer");
107  }
108 
109  $set = $ilDB->query($sql);
110  while ($row = $ilDB->fetchAssoc($set)) {
111  $res[] = (int) $row["user_fi"];
112  }
113  return $res;
114  }
115 
120  public static function getInvitations(int $a_obj_id): array
121  {
122  global $DIC;
123 
124  $db = $DIC->database();
125  $query = 'select user_id from svy_invitation si ' .
126  'join svy_svy ss on ss.survey_id = si.survey_id ' .
127  'where obj_fi = ' . $db->quote($a_obj_id, ilDBConstants::T_INTEGER);
128  $res = $db->query($query);
129  $invited = [];
130  while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
131  $invited[] = (int) $row->user_id;
132  }
133  return $invited;
134  }
135 }
const LP_STATUS_COMPLETED_NUM
$res
Definition: ltiservices.php:66
static _isSurveyParticipant(int $user_id, int $survey_id)
static _getCompleted(int $a_obj_id)
Static function to read the users who have the status &#39;completed&#39;.
const LP_STATUS_IN_PROGRESS_NUM
static _lookupFinished(int $a_obj_id, int $a_user_id=0)
get finished status
quote($value, string $type)
static _getInProgress(int $a_obj_id)
Static function to read users who have the status &#39;in_progress&#39;.
while($session_entry=$r->fetchRow(ilDBConstants::FETCHMODE_ASSOC)) return null
global $DIC
Definition: shib_login.php:22
query(string $query)
Run a (read-only) Query on the database.
const LP_STATUS_NOT_ATTEMPTED_NUM
static getParticipants(int $a_obj_id, bool $a_only_finished=false)
ilDBInterface $db
determineStatus(int $a_obj_id, int $a_usr_id, ?object $a_obj=null)