34 protected \ILIAS\Exercise\Submission\SubmissionManager
$sub_manager;
35 protected \ILIAS\Exercise\InternalDomainService
$domain;
56 bool $a_is_tutor =
false,
57 bool $a_public_submissions =
false
60 $this->main_tpl =
$DIC->ui()->mainTemplate();
62 $this->
user = $DIC->user();
63 $this->db =
$DIC->database();
64 $this->
lng = $DIC->language();
65 $this->
ctrl = $DIC->ctrl();
67 $this->assignment = $a_ass;
71 $this->user_id = $a_user_id;
72 $this->is_tutor = $a_is_tutor;
73 $this->public_submissions = $a_public_submissions;
82 $this->team = $a_team;
86 if ($this->assignment->getPeerReview()) {
89 $this->domain =
$DIC->exercise()->internal()->domain();
90 $this->sub_manager =
$DIC->exercise()->internal()->domain()->submission(
97 return $this->assignment->getAssignmentType()->getSubmissionType();
122 if ($this->peer_review) {
140 return $this->team->getMembers();
144 return array($this->user_id);
153 return "t" . $this->team->getId();
161 return (
bool) $this->sub_manager->getSubmissionsOfUser(
175 return $this->sub_manager->getSubmissionsOfUser(
186 return $this->sub_manager->getSubmissionsOfUser($this->
getUserId())->current();
192 $this->state->isSubmissionAllowed());
202 $this->public_submissions) {
207 if ($this->peer_review) {
209 foreach ($this->peer_review->getPeerReviewsByPeerId($this->getUserId()) as $giver) {
210 if ($giver[
"giver_id"] == $ilUser->getId()) {
226 if ($this->assignment->hasTeam() &&
227 !$this->team->getId()) {
233 public function isInTeam(?
int $a_user_id =
null): bool
238 $a_user_id = $ilUser->
getId();
240 return in_array($a_user_id, $this->
getUserIds());
247 return ($ilUser->getId() == $this->getUserId());
252 return ($this->peer_review &&
253 $this->peer_review->hasPeerReviewAccess($this->user_id));
263 $cnt_sub = $this->sub_manager->countSubmissionsOfUser(
281 $dl = $this->state->getOfficialDeadline();
283 return ($dl && $dl < time());
288 if ($this->ass_type->isSubmissionAssignedToTeam()) {
289 $storage_id = $this->
getTeam()->getId();
311 $q =
"SELECT exc_returned.returned_id AS id " .
312 "FROM exc_usr_tutor, exc_returned " .
313 "WHERE exc_returned.ass_id = exc_usr_tutor.ass_id " .
314 " AND exc_returned.user_id = exc_usr_tutor.usr_id " .
317 " AND exc_usr_tutor.tutor_id = " .
$ilDB->quote($tutor,
"integer") .
318 " AND exc_usr_tutor.download_time < exc_returned.ts ";
320 $new_up_set =
$ilDB->query(
$q);
323 while ($new_up_rec =
$ilDB->fetchAssoc($new_up_set)) {
324 $new_up[] = $new_up_rec[
"id"];
340 $set =
$ilDB->query(
"SELECT obj_id" .
341 " FROM exc_returned" .
342 " WHERE returned_id = " .
$ilDB->quote($a_returned_id,
"integer"));
343 $row =
$ilDB->fetchAssoc($set);
344 return (
int) $row[
"obj_id"];
359 $set =
$ilDB->query(
"SELECT obj_id, ass_id" .
360 " FROM exc_returned" .
361 " WHERE user_id = " .
$ilDB->quote($a_user_id,
"integer") .
362 " AND filetitle = " .
$ilDB->quote($a_filetitle,
"text"));
364 while ($row =
$ilDB->fetchAssoc($set)) {
365 $res[$row[
"ass_id"]] = $row;
372 $this->sub_manager->deleteAllSubmissionsOfUser($this->getUserId());
447 $db =
$DIC->database();
450 $submission =
new self($ass, $a_user_id);
451 $submission->deleteAllFiles();
454 $team = $submission->getTeam();
461 $member_status = $ass->getMemberStatus($a_user_id);
462 $member_status->setStatus(
"notgraded");
463 $member_status->update();
467 "DELETE FROM exc_usr_tutor " .
468 "WHERE ass_id = %s AND usr_id = %s",
469 array(
"integer",
"integer"),
470 array($ass->getId(), $a_user_id)
483 $ilUser = $this->user;
485 $q =
"SELECT download_time FROM exc_usr_tutor WHERE " .
486 " ass_id = " .
$ilDB->quote($this->getAssignment()->
getId(),
"integer") .
" AND " .
487 $ilDB->in(
"usr_id", $a_user_ids,
"",
"integer") .
" AND " .
488 " tutor_id = " .
$ilDB->quote($ilUser->getId(),
"integer") .
489 " ORDER BY download_time DESC";
491 $lu_rec =
$ilDB->fetchAssoc($lu_set);
492 return $lu_rec[
"download_time"] ??
"";
495 public function downloadFiles(
496 ?array $a_file_ids =
null,
497 bool $a_only_new =
false,
498 bool $a_peer_review_mask_filename =
false
500 $ilUser = $this->
user;
503 $user_ids = $this->getUserIds();
504 $is_team = $this->assignment->hasTeam();
506 $download_time =
null;
508 $download_time = $this->getLastDownloadTime($user_ids);
511 if ($this->is_tutor) {
512 $this->updateTutorDownloadTime();
515 if ($a_peer_review_mask_filename) {
518 foreach ($this->peer_review->getPeerReviewsByGiver($ilUser->getId()) as $idx => $item) {
519 if ($item[
"peer_id"] == $this->getUserId()) {
528 $subs = iterator_to_array($this->sub_manager->getSubmissionsOfUser(
535 if (count($subs) > 0) {
536 if (count($subs) == 1) {
538 $sub = current($subs);
540 $title = $sub->getTitle();
542 switch ($this->assignment->getType()) {
547 $this->assignment->getTitle() .
" - " .
548 $name[
"firstname"] .
" " .
549 $name[
"lastname"] .
" (" .
550 $name[
"login"] .
").zip";
556 $this->assignment->getTitle() .
" (Team " . $this->getTeam()->getId() .
").zip";
563 if ($a_peer_review_mask_filename) {
564 $title_a = explode(
".", $sub->getTitle());
565 $suffix = array_pop($title_a);
566 $title = $this->assignment->getTitle() .
"_peer" . $peer_id .
"." . $suffix;
567 } elseif ($sub->getLate()) {
568 $title =
$lng->txt(
"exc_late_submission") .
" - " .
572 $this->downloadSingleFile($sub, $title);
574 $this->sub_manager->deliverSubmissions(
577 $a_peer_review_mask_filename,
591 $ilUser = $this->user;
594 $exc_id = $this->assignment->getExerciseId();
595 $ass_id = $this->assignment->getId();
597 foreach ($this->getUserIds() as
$user_id) {
599 "DELETE FROM exc_usr_tutor " .
600 "WHERE ass_id = %s AND usr_id = %s AND tutor_id = %s",
601 array(
"integer",
"integer",
"integer"),
606 "INSERT INTO exc_usr_tutor (ass_id, obj_id, usr_id, tutor_id, download_time) VALUES " .
607 "(%s, %s, %s, %s, %s)",
608 array(
"integer",
"integer",
"integer",
"integer",
"timestamp"),
618 $this->domain->submission($this->assignment->
getId())->deliverFile(
630 if ($this->getAssignment()->getAssignmentType()->isSubmissionAssignedToTeam()) {
631 $team_id = $this->getTeam()->getId();
632 $where =
" team_id = " .
$ilDB->quote($team_id,
"integer") .
" ";
634 $where =
" " .
$ilDB->in(
"user_id", $this->getUserIds(),
"",
"integer") .
" ";
648 $ilDB->setLimit(1, 0);
650 $q =
"SELECT obj_id,user_id,ts FROM exc_returned" .
651 " WHERE ass_id = " .
$ilDB->quote($this->assignment->getId(),
"integer") .
652 " AND " . $this->getTableUserWhere() .
653 " AND (filename IS NOT NULL OR atext IS NOT NULL)" .
654 " AND ts IS NOT NULL" .
657 $array =
$ilDB->fetchAssoc($usr_set);
658 return ($array[
"ts"] ??
null);
667 $this->db->setLimit(1, 0);
669 $q =
"SELECT web_dir_access_time FROM exc_returned" .
670 " WHERE ass_id = " . $this->db->quote($this->assignment->getId(),
"integer") .
671 " AND (filename IS NOT NULL OR atext IS NOT NULL)" .
672 " AND web_dir_access_time IS NOT NULL" .
673 " AND " . $this->getTableUserWhere() .
674 " ORDER BY web_dir_access_time DESC";
676 $res = $this->db->query(
$q);
680 return $data[
"web_dir_access_time"] ??
null;
695 ?
string $a_text =
null
699 if ($this->getAssignment()->getAssignmentType()->isSubmissionAssignedToTeam()) {
701 $team_id = $this->getTeam()->getId();
713 $subs = $this->getSubmissionsForFilename($a_wsp_id, $repos_ass_type_ids);
715 throw new ilExerciseException(
"Repository object $a_wsp_id is already assigned to another assignment.");
719 $next_id =
$ilDB->nextId(
"exc_returned");
721 "INSERT INTO exc_returned " .
722 "(returned_id, obj_id, user_id, filetitle, ass_id, ts, atext, late, team_id) " .
723 "VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s)",
724 $ilDB->quote($next_id,
"integer"),
725 $ilDB->quote($this->assignment->getExerciseId(),
"integer"),
727 $ilDB->quote($a_wsp_id,
"text"),
728 $ilDB->quote($this->assignment->getId(),
"integer"),
730 $ilDB->quote($a_text,
"text"),
731 $ilDB->quote($this->isLate(),
"integer"),
732 $ilDB->quote($team_id,
"integer")
734 $ilDB->manipulate($query);
745 $this->deleteAllFiles();
758 if (!trim($a_text)) {
759 $this->sub_manager->deleteAllSubmissionsOfUser($this->getUserId());
763 $sub = $this->sub_manager->getSubmissionsOfUser($this->getUserId())->current();
766 return $this->addResourceObject(
"TEXT", $a_text);
770 $ilDB->manipulate(
"UPDATE exc_returned" .
771 " SET atext = " .
$ilDB->quote($a_text,
"text") .
773 ", late = " .
$ilDB->quote($this->isLate(),
"integer") .
774 " WHERE returned_id = " .
$ilDB->quote(
$id,
"integer"));
788 public function getDownloadedFilesInfoForTableGUIS(): array
791 $ilCtrl = $this->ctrl;
794 $result[
"files"][
"count"] =
"---";
798 $last_sub = $this->getLastSubmission();
804 $result[
"last_submission"][
"txt"] =
$lng->txt(
"exc_last_submission");
805 $result[
"last_submission"][
"value"] = $last_sub;
808 $ilCtrl->setParameterByClass(
"ilexsubmissionfilegui",
"member_id", $this->getUserId());
811 switch ($this->assignment->getType()) {
817 $subs = $this->sub_manager->getSubmissionsOfUser($this->getUserId());
820 foreach ($subs as $sub) {
821 if ($sub->getLate()) {
828 $result[
"files"][
"txt"] =
$lng->txt(
"exc_files_returned");
829 if ($late_files !== 0) {
830 $result[
"files"][
"txt"] .=
' - <span class="warning">' .
$lng->txt(
"exc_late_submission") .
" (" . $late_files .
")</span>";
833 $new = $this->lookupNewFiles();
835 $sub_cnt .=
" " . sprintf(
$lng->txt(
"cnt_new"), count($new));
838 $result[
"files"][
"count"] = $sub_cnt;
842 $result[
"files"][
"download_url"] =
843 $ilCtrl->getLinkTargetByClass(
"ilexsubmissionfilegui",
"downloadReturned");
845 if (count($new) <= 0) {
846 $result[
"files"][
"download_txt"] =
$lng->txt(
"exc_tbl_action_download_files");
848 $result[
"files"][
"download_txt"] =
$lng->txt(
"exc_tbl_action_download_all_files");
853 $result[
"files"][
"download_new_url"] =
854 $ilCtrl->getLinkTargetByClass(
"ilexsubmissionfilegui",
"downloadNewReturned");
856 $result[
"files"][
"download_new_txt"] =
$lng->txt(
"exc_tbl_action_download_new_files");
862 $result[
"files"][
"txt"] =
$lng->txt(
"exc_blog_returned");
864 $sub = $this->sub_manager->getSubmissionsOfUser($this->getUserId())->current();
866 if ($sub->getRid() !=
"") {
867 if ($sub->getLate()) {
868 $result[
"files"][
"txt"] .=
' - <span class="warning">' .
$lng->txt(
"exc_late_submission") .
"</span>";
871 $result[
"files"][
"count"] = 1;
873 $result[
"files"][
"download_url"] =
874 $ilCtrl->getLinkTargetByClass(
"ilexsubmissionfilegui",
"downloadReturned");
876 $result[
"files"][
"download_txt"] =
$lng->txt(
"exc_tbl_action_download_files");
882 $result[
"files"][
"txt"] =
$lng->txt(
"exc_portfolio_returned");
884 $sub = $this->sub_manager->getSubmissionsOfUser($this->getUserId())->current();
886 if ($sub->getRid() !=
"") {
887 if ($sub->getLate()) {
888 $result[
"files"][
"txt"] .=
' - <span class="warning">' .
$lng->txt(
"exc_late_submission") .
"</span>";
891 $result[
"files"][
"count"] = 1;
893 $result[
"files"][
"download_url"] =
894 $ilCtrl->getLinkTargetByClass(
"ilexsubmissionfilegui",
"downloadReturned");
896 $result[
"files"][
"download_txt"] =
$lng->txt(
"exc_tbl_action_download_files");
902 $result[
"files"][
"txt"] =
$lng->txt(
"exc_files_returned_text");
903 $sub = $this->sub_manager->getSubmissionsOfUser($this->getUserId())->current();
905 $result[
"files"][
"count"] = 1;
907 if (trim($sub->getText()) !==
'' && trim($sub->getText()) !==
'0') {
908 if ($sub->getLate()) {
909 $result[
"files"][
"txt"] .=
' - <span class="warning">' .
$lng->txt(
"exc_late_submission") .
"</span>";
912 $result[
"files"][
"download_url"] =
913 $ilCtrl->getLinkTargetByClass(
"ilexsubmissiontextgui",
"showAssignmentText");
915 $result[
"files"][
"download_txt"] =
$lng->txt(
"exc_tbl_action_text_assignment_show");
921 $result[
"files"][
"txt"] =
$lng->txt(
"exc_wiki_returned");
922 $sub = $this->sub_manager->getSubmissionsOfUser($this->getUserId())->current();
924 if ($sub->getRid() !=
"") {
925 if ($sub->getLate()) {
926 $result[
"files"][
"txt"] .=
' - <span class="warning">' .
$lng->txt(
"exc_late_submission") .
"</span>";
929 $result[
"files"][
"count"] = 1;
931 $result[
"files"][
"download_url"] =
932 $ilCtrl->getLinkTargetByClass(
"ilexsubmissionfilegui",
"downloadReturned");
934 $result[
"files"][
"download_txt"] =
$lng->txt(
"exc_tbl_action_download_files");
940 $ilCtrl->setParameterByClass(
"ilexsubmissionfilegui",
"member_id",
"");
950 array $a_assignment_types = array()
954 $db =
$DIC->database();
956 $query =
"SELECT * FROM exc_returned r LEFT JOIN exc_assignment a" .
957 " ON (r.ass_id = a.id) " .
958 " WHERE r.filetitle = " . $db->
quote($a_filename,
"string");
960 if (is_array($a_assignment_types) && $a_assignment_types !== []) {
961 $query .=
" AND " . $db->
in(
"a.type", $a_assignment_types,
false,
"integer");
964 $set = $db->
query($query);
981 trim($userName[
"lastname"]) .
"_" .
982 trim($userName[
"firstname"]) .
"_" .
983 trim($userName[
"login"]) .
"_" .
996 $participants = array();
997 $query =
"SELECT user_id FROM exc_returned WHERE ass_id = " .
998 $ilDB->quote($a_ass_id,
"integer") .
1000 $ilDB->quote($a_exercise_id,
"integer");
1004 while ($row =
$ilDB->fetchAssoc(
$res)) {
1005 $participants[] = $row[
'user_id'];
1008 return $participants;
1012 string $a_directory,
1020 $pathinfo = pathinfo($a_file);
1021 $file = $pathinfo[
"basename"];
1024 if (($pathinfo[
"extension"] ??
'') ===
'') {
1032 $DIC->legacyArchives()->unzip(
1033 $a_directory .
"/" . $file,
1039 unlink($a_directory .
"/" . $file);
1047 if (empty($filearray)) {
1049 $lng->txt(
"archive_broken"),
1055 foreach ($filearray[
"file"] as $key => $value) {
1057 if (substr($value, 0, 1) ==
"." || stristr(
1058 $filearray[
"path"][$key],
1061 unlink($filearray[
"path"][$key] . $value);
1062 unset($filearray[
"path"][$key]);
1063 unset($filearray[
"file"][$key]);
1070 unlink($filearray[
'path'][$key]);
1072 $lng->txt(
"file_is_infected") .
"<br />" . $vir[1],
1075 } elseif ($vir[1] !=
"") {
1086 foreach (array_count_values($filearray[
"file"]) as $key => $value) {
1088 if ($value !=
"1") {
1092 if (strlen($doublettes) > 0) {
1094 $lng->txt(
"exc_upload_error") .
"<br />" .
$lng->txt(
1095 "zip_structure_error"
1101 $mac_dir = $a_directory .
"/__MACOSX";
1102 if (file_exists($mac_dir)) {
$id
plugin.php for ilComponentBuildPluginInfoObjectiveTest::testAddPlugins
$structure
TOTAL STRUCTURE.
Class ilCtrl provides processing control methods.
static formatDate(ilDateTime $date, bool $a_skip_day=false, bool $a_include_wd=false, bool $include_seconds=false, ?ilObjUser $user=null,)
@classDescription Date and time handling
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
static getInstanceByUserId(int $a_assignment_id, int $a_user_id, bool $a_create_on_demand=false)
removeTeamMember(int $a_user_id, ?int $a_exc_ref_id=null)
static getInstancesByExercise(int $a_exc_id)
const TYPE_UPLOAD
direct checks against const should be avoided, use type objects instead
Exercise submission //TODO: This class has many static methods related to delivered "files".
downloadSingleFile(Submission $sub, string $title)
hasSubmittedPrintVersion()
static deleteUser(int $a_exc_id, int $a_user_id)
Deletes already delivered files.
ilExcAssMemberState $state
ILIAS Exercise InternalDomainService $domain
static lookupExerciseIdForReturnedId(int $a_returned_id)
Get exercise from submission id (used in ilObjMediaObject)
ilExPeerReview $peer_review
__construct(ilExAssignment $a_ass, int $a_user_id, ?ilExAssignmentTeam $a_team=null, bool $a_is_tutor=false, bool $a_public_submissions=false)
ilGlobalTemplateInterface $main_tpl
getSubmittedEntry(bool $print=false)
addResourceObject(string $a_wsp_id, ?string $a_text=null)
Add personal resource or repository object (ref_id) to assigment.
ilExAssignment $assignment
getLastOpeningHTMLView()
TODO -> get rid of getTableUserWhere and move to repository class Get a mysql timestamp from the last...
static getAssignmentParticipants(int $a_exercise_id, int $a_ass_id)
updateTutorDownloadTime()
ILIAS Exercise Submission SubmissionManager $sub_manager
static findUserFiles(int $a_user_id, string $a_filetitle)
Check if given file was assigned Used in Blog/Portfolio.
static processZipFile(string $a_directory, string $a_file, bool $structure)
ilExAssignmentTypeInterface $ass_type
lookupNewFiles(?int $a_tutor=null)
Check how much files have been uploaded by the learner after the last download of the tutor.
isInTeam(?int $a_user_id=null)
updateTextSubmission(string $a_text)
Handle text assignment submissions.
getFeedbackId()
used for the legacy storage path of feedbacks only
static getDirectoryNameFromUserData(int $a_user_id)
getLastSubmission()
TODO -> get rid of getTableUserWhere and move to repository class Get the date of the last submission...
static getSubmissionsForFilename(string $a_filename, array $a_assignment_types=array())
Get assignment return entries for a filename.
ilExAssignmentTypes $ass_types
getLastDownloadTime(array $a_user_ids)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
static getInstanceByIds(int $a_ass_id, int $a_user_id=0)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
static int $INFECTED_FILE
static int $DOUBLETTES_FOUND
static utf8_encode(string $string)
static getASCIIFilename(string $a_filename)
static recursive_dirscan(string $dir, array &$arr)
Recursively scans a given directory and writes path and filename into referenced array.
static delDir(string $a_dir, bool $a_clean_only=false)
removes a dir and all its content (subdirs and files) recursively
static moveUploadedFile(string $a_file, string $a_name, string $a_target, bool $a_raise_errors=true, string $a_mode="move_uploaded")
move uploaded file
static _lookupName(int $a_user_id)
static _lookupType(int $id, bool $reference=false)
static _lookupTitle(int $obj_id)
static now()
Return current timestamp in Y-m-d H:i:s format.
static virusHandling(string $a_file, string $a_orig_name='', bool $a_clean=true)
quote($value, string $type)
manipulateF(string $query, array $types, array $values)
query(string $query)
Run a (read-only) Query on the database.
fetchAssoc(ilDBStatement $statement)
in(string $field, array $values, bool $negate=false, string $type="")
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...