ILIAS  release_8 Revision v8.24
class.SubmissionDBRepository.php
Go to the documentation of this file.
1<?php
2
20
28{
29 protected const TABLE_NAME = "exc_returned";
30 protected const TEAM_TABLE_NAME = "il_exc_team";
31
32 protected \ilDBInterface $db;
33
34 public function __construct(\ilDBInterface $db = null)
35 {
36 global $DIC;
37
38 $this->db = (is_null($db))
39 ? $DIC->database()
40 : $db;
41 }
42
43 public function getUserId(int $submission_id): int
44 {
45 $q = "SELECT user_id FROM " . self::TABLE_NAME .
46 " WHERE returned_id = " . $this->db->quote($submission_id, "integer");
47 $usr_set = $this->db->query($q);
48
49 $rec = $this->db->fetchAssoc($usr_set);
50 return (int) ($rec["user_id"] ?? 0);
51 }
52
53 public function hasSubmissions(int $assignment_id): int
54 {
55 $query = "SELECT * FROM " . self::TABLE_NAME .
56 " WHERE ass_id = " . $this->db->quote($assignment_id, "integer") .
57 " AND (filename IS NOT NULL OR atext IS NOT NULL)" .
58 " AND ts IS NOT NULL";
59 $res = $this->db->query($query);
60 return $res->numRows();
61 }
62
63 // Update web_dir_access_time. It defines last HTML opening data.
64 public function updateWebDirAccessTime(int $assignment_id, int $member_id): void
65 {
66 $this->db->manipulate("UPDATE " . self::TABLE_NAME .
67 " SET web_dir_access_time = " . $this->db->quote(\ilUtil::now(), "timestamp") .
68 " WHERE ass_id = " . $this->db->quote($assignment_id, "integer") .
69 " AND user_id = " . $this->db->quote($member_id, "integer"));
70 }
71
78 public function getUserSubmissionState(int $user_id, array $assignment_ids): array
79 {
80 $db = $this->db;
81
82 $submitted = [];
83 foreach ($assignment_ids as $id) {
84 $submitted[(int) $id] = false;
85 }
86
87 $set = $db->queryF(
88 "SELECT ass_id FROM " . self::TABLE_NAME .
89 " WHERE " . $db->in("ass_id", $assignment_ids, false, "integer") .
90 " AND user_id = %s " .
91 " AND (filename IS NOT NULL OR atext IS NOT NULL)" .
92 " AND ts IS NOT NULL",
93 ["integer"],
94 [$user_id]
95 );
96 while ($rec = $db->fetchAssoc($set)) {
97 $submitted[(int) $rec["ass_id"]] = true;
98 }
99
100 $set = $db->queryF(
101 "SELECT ret.ass_id FROM " . self::TABLE_NAME . " ret JOIN " .
102 self::TEAM_TABLE_NAME . " team ON (ret.team_id = team.id AND ret.ass_id = team.ass_id) " .
103 " WHERE " . $db->in("ret.ass_id", $assignment_ids, false, "integer") .
104 " AND team.user_id = %s " .
105 " AND (ret.filename IS NOT NULL OR ret.atext IS NOT NULL)" .
106 " AND ret.ts IS NOT NULL",
107 ["integer"],
108 [$user_id]
109 );
110 while ($rec = $db->fetchAssoc($set)) {
111 $submitted[(int) $rec["ass_id"]] = true;
112 }
113
114 return $submitted;
115 }
116}
$id
plugin.php for ilComponentBuildPluginInfoObjectiveTest::testAddPlugins
Definition: plugin.php:23
getUserSubmissionState(int $user_id, array $assignment_ids)
Checks if a user has submitted anything for a number of assignments.
static now()
Return current timestamp in Y-m-d H:i:s format.
global $DIC
Definition: feed.php:28
Interface ilDBInterface.
fetchAssoc(ilDBStatement $statement)
queryF(string $query, array $types, array $values)
in(string $field, array $values, bool $negate=false, string $type="")
$res
Definition: ltiservices.php:69
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
$query