19 declare(strict_types=1);
30 protected \ilExAssignmentTypeInterface
$type;
31 protected \ILIAS\Exercise\Team\TeamManager
$team;
42 $this->assignment = $domain->
assignment()->getAssignment($ass_id);
43 $this->type = $this->assignment->getAssignmentType();
45 $this->log = $this->domain->logger()->exc();
46 $this->team = $domain->
team();
51 return count(iterator_to_array(
62 ?array $submit_ids =
null,
63 bool $only_valid =
false,
64 ?
string $min_timestamp =
null,
65 bool $print_versions =
false 67 $type_uses_print_versions = in_array($this->assignment->getType(), [
72 $type_uses_uploads = $this->type->usesFileUpload();
73 if ($this->type->isSubmissionAssignedToTeam()) {
74 $team_id = $this->team->getTeamForMember($this->ass_id, $user_id);
76 yield
from $this->repo->getSubmissionsOfTeam(
79 $type_uses_print_versions,
88 $user_ids = $this->team->getTeamMemberIdsOrUserId(
92 yield
from $this->repo->getSubmissionsOfUsers(
95 $type_uses_print_versions,
112 $type_uses_uploads = $this->type->usesFileUpload();
113 $type_uses_print_versions = in_array($this->assignment->getType(), [
118 yield
from $this->repo->getSubmissionsOfUsers(
121 $type_uses_print_versions,
134 $id = $file[
"returned_id"];
138 $deadline = $assigment->getPersonalDeadline($file[
"user_id"]);
139 $last_deadline = max($deadline, $assigment->getExtendedDeadline());
147 $uploaded < $deadline)) {
151 elseif (!$file[
"late"] &&
154 $uploaded > $deadline) {
158 if ($late !==
null) {
159 $this->repo->updateLate(
175 foreach ($this->repo->getAllEntriesOfAssignment($assignment->getId()) as $row) {
176 $row[
"timestamp"] = $row[
"ts"];
187 return $this->repo->getMaxAmountOfSubmittedFiles(
188 $ass->getExerciseId(),
200 return $this->repo->getUsersWithSubmission(
214 $submission = new \ilExSubmission(
219 if (!$submission->canAddFile()) {
223 if ($this->type->isSubmissionAssignedToTeam()) {
224 $team_id = $submission->getTeam()->getId();
232 $success = $this->repo->addLocalFile(
233 $this->assignment->getExerciseId(),
239 $submission->isLate(),
243 if ($success && $team_id > 0) {
244 $this->domain->team()->writeLog(
263 $submission = new \ilExSubmission(
268 if (!$submission->canAddFile()) {
272 if ($this->type->isSubmissionAssignedToTeam()) {
273 $team_id = $submission->getTeam()->getId();
281 $success = $this->repo->addUpload(
282 $this->assignment->getExerciseId(),
288 $submission->isLate(),
292 if ($success && $team_id > 0) {
293 $this->domain->team()->writeLog(
305 $submission = new \ilExSubmission(
309 $max_file = $submission->getAssignment()->getMaxFile();
310 if ($max_file === 0) {
314 $max_file -= $cnt_sub;
315 return max($max_file, 0);
322 $submission = new \ilExSubmission(
326 if (!$submission->canAddFile()) {
329 if ($this->type->isSubmissionAssignedToTeam()) {
330 $team_id = $submission->getTeam()->getId();
338 $filenames = $this->repo->addZipUpload(
339 $this->assignment->getExerciseId(),
344 $submission->isLate(),
348 $this->log->debug(
"99");
351 $this->domain->team()->writeLog(
359 return count($filenames) > 0;
365 string $filetitle =
"" 367 $this->repo->deliverFile(
377 string $internal_file_path
381 $web_filesystem = $DIC->filesystem()->web();
383 $internal_dirs = dirname($internal_file_path);
384 $zip_file = basename($internal_file_path);
388 if ($web_filesystem->hasDir($internal_dirs)) {
389 $web_filesystem->deleteDir($internal_dirs);
391 $web_filesystem->createDir($internal_dirs);
392 if ($web_filesystem->has($internal_file_path)) {
393 $web_filesystem->delete($internal_file_path);
395 if (!$web_filesystem->has($internal_file_path)) {
397 $stream = $this->repo->getStream(
401 if (!is_null($stream)) {
402 $web_filesystem->writeStream($internal_file_path, $stream);
404 return ILIAS_ABSOLUTE_PATH .
405 DIRECTORY_SEPARATOR .
407 DIRECTORY_SEPARATOR .
409 DIRECTORY_SEPARATOR .
411 DIRECTORY_SEPARATOR .
413 DIRECTORY_SEPARATOR .
427 if (count($ids) == 0) {
431 foreach ($ids as
$id) {
433 if (!in_array($id, $all)) {
436 $s = $this->repo->getById($id);
441 $team_id = $this->team->getTeamForMember($this->ass_id, $user_id);
443 $this->team->writeLog(
459 $subs[] = $s->getId();
462 $subs[] = $s->getId();
483 foreach ($user_ids as $member_id) {
484 $submission = new \ilExSubmission($this->assignment, $member_id);
485 $submission->updateTutorDownloadTime();
488 if ($this->domain->profile()->exists($member_id)) {
491 $members[$sub->getUserId()][
"files"][$sub->getId()] = $sub;
495 $members[$member_id][
"name"] = $name[
"firstname"] .
" " . $name[
"lastname"];
498 $this->copySubmissionFilesToDir($members, $directory);
501 protected function copySubmissionFilesToDir(
507 $zip_archive = $DIC->archives()->zip([]);
510 $lng = $this->domain->lng();
540 if ($ass->hasTeam()) {
541 $team_dirs = array();
544 foreach ($members as
$id => $item) {
545 $user_files = $item[
"files"] ?? [];
549 if (is_array($team_map) &&
550 array_key_exists(
$id, $team_map)) {
552 if (!array_key_exists(
$team_id, $team_dirs)) {
556 $team_dir = $team_dirs[
$team_id] . DIRECTORY_SEPARATOR;
559 if ($ass->getAssignmentType()->isSubmissionAssignedToTeam()) {
563 if ($targetdir ==
"") {
568 if ($ass->getAssignmentType()->usesTeams()) {
569 $targetdir = $team_dir . $targetdir;
573 $log->debug(
"Creation target directory: " . $targetdir);
578 foreach ($user_files as $sub) {
579 $targetfile = $sub->getTitle();
585 $targetfile = $obj_type .
"_" . $obj_id .
".zip";
589 if (array_key_exists($targetfile, $duplicates)) {
590 $suffix = strrpos($targetfile,
".");
591 $targetfile = substr($targetfile, 0, $suffix) .
592 " (" . (++$duplicates[$targetfile]) .
")" .
593 substr($targetfile, $suffix);
595 $duplicates[$targetfile] = 1;
599 if ($sub->getLate()) {
600 $targetfile =
$lng->txt(
"exc_late_submission") .
" - " .
614 $stream = $this->repo->getStream($ass->getId(), $sub->getRid());
617 $dir = $to_path . DIRECTORY_SEPARATOR . $targetdir;
619 $file = $dir . DIRECTORY_SEPARATOR . $targetfile;
622 $stream->getContents()
637 return \ilFileUtils::getASCIIFilename(
638 trim($userName[
"lastname"]) .
"_" .
639 trim($userName[
"firstname"]) .
"_" .
640 trim($userName[
"login"]) .
"_" .
645 public function deliverSubmissions(
648 bool $peer_review_mask_filename =
false,
653 $filenames = array();
655 $is_team = $this->type->usesTeams() || $peer_review_mask_filename;
657 foreach ($subs as $sub) {
658 if ($this->type->isSubmissionAssignedToTeam()) {
659 $storage_id = $sub->getTeamId();
661 $storage_id = $sub->getUserId();
664 $src = $sub->getTitle();
665 if ($peer_review_mask_filename) {
666 $src_a = explode(
".", $src);
667 $suffix = array_pop($src_a);
668 $tgt = $this->assignment->getTitle() .
"_peer" . $peer_id .
669 "_" . (++$seq) .
"." . $suffix;
671 $filenames[$storage_id][] = array(
674 "rid" => $sub->getRid()
677 $filenames[$storage_id][] = array(
679 "late" => $sub->getLate(),
680 "rid" => $sub->getRid()
692 $lng = $this->domain->lng();
694 $zip = $DIC->archives()->zip([]);
698 $deliverFilename = str_replace(
" ",
"_", $assTitle);
699 if ($user_id > 0 && !$multi_user) {
701 $deliverFilename .=
"_" . $userName[
"lastname"] .
"_" . $userName[
"firstname"];
703 $deliverFilename .=
"_files";
705 $orgDeliverFilename = trim($deliverFilename);
709 $parsed_files = $duplicates = array();
710 foreach ($filenames as $files) {
712 foreach ($files as $file) {
714 if (isset($file[
"tgt"])) {
715 $newFilename = $file[
"tgt"];
718 $late = $file[
"late"];
723 $pos = strpos($newFilename,
"_");
724 if ($pos !==
false) {
725 $newFilename = substr($newFilename, $pos + 1);
728 $chkName = strtolower($newFilename);
729 if (array_key_exists($chkName, $duplicates)) {
730 $suffix = strrpos($newFilename,
".");
731 $newFilename = substr($newFilename, 0, $suffix) .
732 " (" . (++$duplicates[$chkName]) .
")" .
733 substr($newFilename, $suffix);
735 $duplicates[$chkName] = 1;
739 $newFilename =
$lng->txt(
"exc_late_submission") .
" - " .
745 $newFilename = $deliverFilename . DIRECTORY_SEPARATOR . $newFilename;
747 $this->repo->getStream(
762 $http_util = $DIC->exercise()->internal()->gui()->httpUtil();
763 $http_util->deliverStream(
765 $orgDeliverFilename .
".zip",
getAllSubmissionIdsOfUser(int $user_id)
All, include print, include all from team.
deleteSubmissions(int $user_id, array $ids)
Delete submissions.
deliverFile(int $user_id, string $rid, string $filetitle="")
static lookupTitle(int $a_id)
addZipUploads(int $user_id, UploadResult $result)
static _lookupName(int $a_user_id)
lookup user name
getSubmissionsOfOwners(array $user_ids)
This is only suitable for types like text or single upload, where no teams are used.
ILIAS Exercise Team TeamManager $team
ilExAssignment $assignment
static makeDirParents(string $a_dir)
Create a new directory and all parent directories.
__construct(InternalRepoService $repo, protected InternalDomainService $domain, protected \ilExcSubmissionStakeholder $stakeholder, protected int $ass_id)
static _lookupObjId(int $ref_id)
Submission repository Interface.
static getASCIIFilename(string $a_filename)
while($session_entry=$r->fetchRow(ilDBConstants::FETCHMODE_ASSOC)) return null
const TEAM_LOG_REMOVE_FILE
copySubmissionsToDir(array $user_ids, string $directory)
Should be replaced by writing into a zip directly in the future.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
recalculateLateSubmissions()
getDirectoryNameFromUserData(int $user_id)
there is still a version in ilExSubmission that needs to be replaced
getSubmissionsOfUser(int $user_id, ?array $submit_ids=null, bool $only_valid=false, ?string $min_timestamp=null, bool $print_versions=false)
Note: this includes submissions of other team members, if user is in a team.
SubmissionRepositoryInterface $repo
ilExAssignmentTypeInterface $type
countSubmissionsOfUser(int $user_id)
static getAssignmentTeamMap(int $a_ass_id)
addUpload(int $user_id, UploadResult $result, string $filename="")
copyRidToWebDir(string $rid, string $internal_file_path)
deleteAllSubmissionsOfUser(int $user_id)
getUsersWithSubmission()
Get all user ids, that have submitted something.
getMaxAmountOfSubmittedFiles(int $user_id=0)
static _lookupType(int $id, bool $reference=false)
remainingFilesAllowed(int $user_id)
addLocalFile(int $user_id, string $file, string $filename="")