ILIAS  release_8 Revision v8.24
class.ilLPStatusSurveyFinished.php
Go to the documentation of this file.
1<?php
2
3declare(strict_types=0);
4
5// patch-begin svy_lp
6
7/* Copyright (c) 1998-2010 ILIAS open source, Extended GPL, see docs/LICENSE */
8
14{
15 public static function _getNotAttempted(int $a_obj_id): array
16 {
17 $invited = self::getInvitations($a_obj_id);
18 if ($invited === []) {
19 return [];
20 }
21 $users = array_diff(
22 (array) $invited,
24 );
25 $users = array_diff(
26 $users,
28 );
29 return $users;
30 }
31
32 public static function _getInProgress(int $a_obj_id): array
33 {
34 return self::getParticipants($a_obj_id);
35 }
36
37 public static function _getCompleted(int $a_obj_id): array
38 {
39 return self::getParticipants($a_obj_id, true);
40 }
41
42 public function determineStatus(
43 int $a_obj_id,
44 int $a_usr_id,
45 object $a_obj = null
46 ): int {
47 $survey_id = self::getSurveyId($a_obj_id);
48 if (!$survey_id) {
50 }
52
53 if (ilObjSurveyAccess::_isSurveyParticipant($a_usr_id, $survey_id)) {
55
56 if (ilObjSurveyAccess::_lookupFinished($a_obj_id, $a_usr_id)) {
58 }
59 }
60 return $status;
61 }
62
63 protected static function getSurveyId(int $a_obj_id): int
64 {
65 global $DIC;
66
67 $ilDB = $DIC['ilDB'];
68 $set = $ilDB->query(
69 "SELECT survey_id FROM svy_svy" .
70 " WHERE obj_fi = " . $ilDB->quote($a_obj_id)
71 );
72 $row = $ilDB->fetchAssoc($set);
73 return (int) ($row["survey_id"] ?? 0);
74 }
75
76 public static function getParticipants(
77 int $a_obj_id,
78 bool $a_only_finished = false
79 ): array {
80 global $DIC;
81
82 $ilDB = $DIC['ilDB'];
83 $res = array();
84 $survey_id = self::getSurveyId($a_obj_id);
85 if (!$survey_id) {
86 return $res;
87 }
88
89 $sql = "SELECT user_fi FROM svy_finished fin" .
90 " WHERE fin.survey_fi = " . $ilDB->quote($survey_id, "integer");
91
92 if ($a_only_finished) {
93 $sql .= " AND fin.state = " . $ilDB->quote(1, "integer");
94 }
95
96 $set = $ilDB->query($sql);
97 while ($row = $ilDB->fetchAssoc($set)) {
98 $res[] = (int) $row["user_fi"];
99 }
100 return $res;
101 }
102
107 public static function getInvitations(int $a_obj_id): array
108 {
109 global $DIC;
110
111 $db = $DIC->database();
112 $query = 'select user_id from svy_invitation si ' .
113 'join svy_svy ss on ss.survey_id = si.survey_id ' .
114 'where obj_fi = ' . $db->quote($a_obj_id, ilDBConstants::T_INTEGER);
115 $res = $db->query($query);
116 $invited = [];
117 while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
118 $invited[] = (int) $row->user_id;
119 }
120 return $invited;
121 }
122}
static getParticipants(int $a_obj_id, bool $a_only_finished=false)
determineStatus(int $a_obj_id, int $a_usr_id, object $a_obj=null)
static _getInProgress(int $a_obj_id)
Static function to read users who have the status 'in_progress'.
static _getCompleted(int $a_obj_id)
Static function to read the users who have the status 'completed'.
Abstract class ilLPStatus for all learning progress modes E.g ilLPStatusManual, ilLPStatusObjectives ...
const LP_STATUS_COMPLETED_NUM
const LP_STATUS_IN_PROGRESS_NUM
const LP_STATUS_NOT_ATTEMPTED_NUM
static _lookupFinished(int $a_obj_id, int $a_user_id=0)
get finished status
static _isSurveyParticipant(int $user_id, int $survey_id)
global $DIC
Definition: feed.php:28
$res
Definition: ltiservices.php:69
$query