23 $this->assignment = $a_ass;
24 $this->user_id = $a_user_id;
25 $this->is_tutor = (bool)$a_is_tutor;
26 $this->public_submissions = (bool)$a_public_submissions;
32 include_once
"Modules/Exercise/classes/class.ilExAssignmentTeam.php";
37 $this->team = $a_team;
41 if($this->assignment->getPeerReview())
43 include_once
"Modules/Exercise/classes/class.ilExPeerReview.php";
50 switch($this->assignment->getType())
98 if($this->peer_review)
118 return $this->team->getMembers();
122 return array($this->user_id);
129 return "t".$this->team->getId();
139 return (
bool)
sizeof($this->
getFiles(
null,
true));
154 !$this->assignment->notStartedYet() &&
155 $this->assignment->beforeDeadline());
165 $this->public_submissions)
171 if($this->peer_review)
174 foreach($this->peer_review->getPeerReviewsByPeerId($this->getUserId()) as $giver)
176 if($giver[
"giver_id"] ==
$ilUser->getId())
193 if($this->assignment->hasTeam() &&
194 !$this->team->getId())
209 return in_array($a_user_id, $this->
getUserIds());
216 return (
$ilUser->getId() == $this->getUserId());
221 return ($this->peer_review &&
222 $this->peer_review->hasPeerReviewAccess($this->user_id));
249 $dl = $this->assignment->getPersonalDeadline($this->
getUserId());
250 return ($dl && $dl < time());
255 include_once(
"./Modules/Exercise/classes/class.ilFSStorageExercise.php");
256 return new ilFSStorageExercise($this->assignment->getExerciseId(), $this->assignment->getId());
271 $deliver_result = $this->
initStorage()->uploadFile($a_http_post_files, $this->
getUserId(), $unzip);
275 $next_id =
$ilDB->nextId(
"exc_returned");
277 "(returned_id, obj_id, user_id, filename, filetitle, mimetype, ts, ass_id, late) ".
278 "VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s)",
279 $ilDB->quote($next_id,
"integer"),
280 $ilDB->quote($this->assignment->getExerciseId(),
"integer"),
281 $ilDB->quote($this->getUserId(),
"integer"),
282 $ilDB->quote($deliver_result[
"fullname"],
"text"),
284 $ilDB->quote($deliver_result[
"mimetype"],
"text"),
286 $ilDB->quote($this->assignment->getId(),
"integer"),
287 $ilDB->quote($this->isLate(),
"integer")
294 $a_http_post_files[
"name"]);
313 include_once (
"Services/Utilities/classes/class.ilFileUtils.php");
323 $max_num = $this->assignment->getMaxFile();
326 $current_num =
sizeof($this->
getFiles());
327 $zip_num =
sizeof($filearray[
"file"]);
328 if($current_num + $zip_num > $max_num)
337 foreach ($filearray[
"file"] as $key =>
$filename)
340 $a_http_post_files[
"type"] =
"other";
341 $a_http_post_files[
"tmp_name"] = $filearray[
"path"][$key].
"/".
$filename;
342 $a_http_post_files[
"error"] = 0;
343 $a_http_post_files[
"size"] = filesize($filearray[
"path"][$key].
"/".
$filename);
345 if(!$this->
uploadFile($a_http_post_files,
true))
367 $query =
"SELECT * FROM exc_returned".
368 " WHERE ass_id = ".$ilDB->quote($a_ass_id,
"integer").
369 " AND (filename IS NOT NULL OR atext IS NOT NULL)".
370 " AND ts IS NOT NULL";
379 include_once(
"./Modules/Exercise/classes/class.ilFSStorageExercise.php");
381 $path = $storage->getAbsoluteSubmissionPath();
383 $query =
"SELECT * FROM exc_returned WHERE ass_id = ".
384 $ilDB->quote($a_ass_id,
"integer");
394 return $delivered ? $delivered : array();
397 function getFiles(array $a_file_ids =
null, $a_only_valid =
false, $a_min_timestamp =
null)
401 $sql =
"SELECT * FROM exc_returned".
402 " WHERE ass_id = ".$ilDB->quote($this->
getAssignment()->getId(),
"integer").
403 " AND ".$ilDB->in(
"user_id", $this->
getUserIds(),
"",
"integer");
407 $sql .=
" AND ".$ilDB->in(
"returned_id", $a_file_ids,
false,
"integer");
412 $sql .=
" AND ts > ".$ilDB->quote($a_min_timestamp,
"timestamp");
417 $delivered_files = array();
427 !(trim(
$row[
"atext"])))
434 $row[
"timestamp14"] = substr(
$row[
"ts"], 0, 4).
435 substr(
$row[
"ts"], 5, 2).substr(
$row[
"ts"], 8, 2).
436 substr(
$row[
"ts"], 11, 2).substr(
$row[
"ts"], 14, 2).
437 substr(
$row[
"ts"], 17, 2);
439 "/".$row[
"user_id"].
"/".basename(
$row[
"filename"]);
442 if (is_file(
$row[
"filename"]) || (!in_array($this->assignment->getType(),
445 array_push($delivered_files,
$row);
450 return $delivered_files;
461 $q =
"SELECT exc_returned.returned_id AS id ".
462 "FROM exc_usr_tutor, exc_returned ".
463 "WHERE exc_returned.ass_id = exc_usr_tutor.ass_id ".
464 " AND exc_returned.user_id = exc_usr_tutor.usr_id ".
465 " AND exc_returned.ass_id = ".$ilDB->quote($this->
getAssignment()->getId(),
"integer").
466 " AND ".$ilDB->in(
"exc_returned.user_id", $this->
getUserIds(),
"",
"integer").
467 " AND exc_usr_tutor.tutor_id = ".$ilDB->quote($ilUser->getId(),
"integer").
468 " AND exc_usr_tutor.download_time < exc_returned.ts ";
470 $new_up_set =
$ilDB->query($q);
473 while ($new_up_rec =
$ilDB->fetchAssoc($new_up_set))
475 $new_up[] = $new_up_rec[
"id"];
491 $set =
$ilDB->query(
"SELECT obj_id".
492 " FROM exc_returned".
493 " WHERE returned_id = ".
$ilDB->quote($a_returned_id,
"integer"));
495 return (
int)
$row[
"obj_id"];
510 $set =
$ilDB->query(
"SELECT obj_id, ass_id".
511 " FROM exc_returned".
512 " WHERE user_id = ".
$ilDB->quote($a_user_id,
"integer").
513 " AND filetitle = ".$ilDB->quote($a_filetitle,
"text"));
527 $files[] = $item[
"returned_id"];
547 !
sizeof($file_id_array))
552 if (count($file_id_array))
555 " WHERE ".
$ilDB->in(
"returned_id", $file_id_array,
false,
"integer").
556 " AND ".$ilDB->in(
"user_id", $user_ids,
"",
"integer"));
560 $result_array = array();
564 array_push($result_array,
$row);
568 $ilDB->manipulate(
"DELETE FROM exc_returned".
569 " WHERE ".
$ilDB->in(
"returned_id", $file_id_array,
false,
"integer").
570 " AND ".$ilDB->in(
"user_id", $user_ids,
"",
"integer"));
574 foreach ($result_array as $key => $value)
576 if($value[
"filename"])
581 $value[
"filetitle"]);
584 $filename =
$path.
"/".$value[
"user_id"].
"/".basename($value[
"filename"]);
601 include_once(
"./Modules/Exercise/classes/class.ilExAssignment.php");
605 $submission =
new self($ass, $a_user_id);
606 $submission->deleteAllFiles();
609 $team = $submission->getTeam();
612 $team->removeTeamMember($a_user_id);
616 $member_status = $ass->getMemberStatus($a_user_id);
617 $member_status->setStatus(
"notgraded");
618 $member_status->update();
626 $q =
"SELECT download_time FROM exc_usr_tutor WHERE ".
627 " ass_id = ".$ilDB->quote($this->
getAssignment()->getId(),
"integer").
" AND ".
628 $ilDB->in(
"usr_id", $a_user_ids,
"",
"integer").
" AND ".
629 " tutor_id = ".$ilDB->quote(
$ilUser->getId(),
"integer");
630 $lu_set =
$ilDB->query($q);
631 $lu_rec =
$ilDB->fetchAssoc($lu_set);
632 return $lu_rec[
"download_time"];
635 function downloadFiles(array $a_file_ids =
null, $a_only_new =
false, $a_peer_review_mask_filename =
false)
640 $is_team = $this->assignment->hasTeam();
643 $download_time =
null;
654 if($a_peer_review_mask_filename)
658 foreach($this->peer_review->getPeerReviewsByGiver(
$ilUser->getId()) as $idx => $item)
660 if($item[
"peer_id"] == $this->
getUserId())
678 switch($this->assignment->getType())
684 $this->assignment->getTitle().
" - ".
685 $file[
"filetitle"][
"firstname"].
" ".
686 $file[
"filetitle"][
"lastname"].
" (".
687 $file[
"filetitle"][
"login"].
").zip";
694 if($a_peer_review_mask_filename)
696 $suffix = array_pop(explode(
".",
$file[
"filetitle"]));
697 $file[
"filetitle"] = $this->assignment->getTitle().
"_peer".$peer_id.
".".$suffix;
699 else if(
$file[
"late"])
701 $file[
"filetitle"] =
$lng->txt(
"exc_late_submission").
" - ".
709 $array_files = array();
712 $src = basename(
$file[
"filename"]);
713 if($a_peer_review_mask_filename)
715 $suffix = array_pop(explode(
".", $src));
716 $tgt = $this->assignment->getTitle().
"_peer".$peer_id.
717 "_".(++$seq).
".".$suffix;
719 $array_files[
$file[
"user_id"]][] = array(
726 $array_files[
$file[
"user_id"]][] = array(
728 "late" =>
$file[
"late"]
734 ($is_team ?
null : $this->
getUserId()), $is_team);
750 $exc_id = $this->assignment->getExerciseId();
751 $ass_id = $this->assignment->getId();
755 $ilDB->manipulateF(
"DELETE FROM exc_usr_tutor ".
756 "WHERE ass_id = %s AND usr_id = %s AND tutor_id = %s",
757 array(
"integer",
"integer",
"integer"),
760 $ilDB->manipulateF(
"INSERT INTO exc_usr_tutor (ass_id, obj_id, usr_id, tutor_id, download_time) VALUES ".
761 "(%s, %s, %s, %s, %s)",
762 array(
"integer",
"integer",
"integer",
"integer",
"timestamp"),
786 $tmpzipfile = $tmpfile .
".zip";
792 $deliverFilename = str_replace(
" ",
"_", $assTitle);
793 if ($a_user_id > 0 && !$a_multi_user)
796 $deliverFilename .=
"_".$userName[
"lastname"].
"_".$userName[
"firstname"];
800 $deliverFilename .=
"_files";
802 $orgDeliverFilename = trim($deliverFilename);
805 chdir($tmpdir.
"/".$deliverFilename);
808 $parsed_files = $duplicates = array();
828 $pos = strpos($newFilename ,
"_");
831 $newFilename = substr($newFilename, $pos + 1);
834 $chkName = strtolower($newFilename);
835 if(array_key_exists($chkName, $duplicates))
837 $suffix = strrpos($newFilename,
".");
838 $newFilename = substr($newFilename, 0, $suffix).
839 " (".(++$duplicates[$chkName]).
")".
840 substr($newFilename, $suffix);
844 $duplicates[$chkName] = 1;
849 $newFilename =
$lng->txt(
"exc_late_submission").
" - ".
855 $newFilename = $tmpdir.DIRECTORY_SEPARATOR.$deliverFilename.DIRECTORY_SEPARATOR.$newFilename;
857 $oldFilename = $pathname.DIRECTORY_SEPARATOR.$filename;
858 if (!copy ($oldFilename, $newFilename))
860 echo
'Could not copy '.$oldFilename.
' to '.$newFilename;
862 touch($newFilename, filectime($oldFilename));
888 include_once(
"./Modules/Exercise/classes/class.ilFSStorageExercise.php");
895 $savepath = $storage->getAbsoluteSubmissionPath();
903 if (!is_dir($savepath))
909 chdir($storage->getTempPath());
919 foreach (array_keys($members) as $id)
921 $directory = $savepath.DIRECTORY_SEPARATOR.$id;
924 if ($dirsize > disk_free_space($tmpdir))
937 $team_dirs = array();
940 foreach ($members as $id => $item)
942 $user = $item[
"name"];
943 $user_files = $item[
"files"];
945 $sourcedir = $savepath.DIRECTORY_SEPARATOR.$id;
946 if (!is_dir($sourcedir))
955 if(is_array($team_map) &&
956 array_key_exists($id, $team_map))
958 $team_id = $team_map[$id];
959 if(!array_key_exists($team_id, $team_dirs))
961 $team_dir =
$lng->txt(
"exc_team").
" ".$team_id;
963 $team_dirs[$team_id] = $team_dir;
965 $team_dir = $team_dirs[$team_id].DIRECTORY_SEPARATOR;
968 $targetdir = $team_dir.ilUtil::getASCIIFilename(
969 trim($userName[
"lastname"]).
"_".
970 trim($userName[
"firstname"]).
"_".
971 trim($userName[
"login"]).
"_".
976 $sourcefiles = scandir($sourcedir);
977 $duplicates = array();
978 foreach ($sourcefiles as $sourcefile) {
979 if ($sourcefile ==
"." || $sourcefile ==
"..")
984 $targetfile = trim(basename($sourcefile));
985 $pos = strpos($targetfile,
"_");
988 $targetfile= substr($targetfile, $pos + 1);
992 if(array_key_exists($targetfile, $duplicates))
994 $suffix = strrpos($targetfile,
".");
995 $targetfile = substr($targetfile, 0, $suffix).
996 " (".(++$duplicates[$targetfile]).
")".
997 substr($targetfile, $suffix);
1001 $duplicates[$targetfile] = 1;
1005 foreach($user_files as
$file)
1007 if(basename(
$file[
"filename"]) == $sourcefile)
1011 $targetfile =
$lng->txt(
"exc_late_submission").
" - ".
1019 $targetfile = $targetdir.DIRECTORY_SEPARATOR.$targetfile;
1020 $sourcefile = $sourcedir.DIRECTORY_SEPARATOR.$sourcefile;
1022 if (!copy ($sourcefile, $targetfile))
1024 include_once
"Modules/Exercise/exceptions/class.ilExerciseException.php";
1025 throw new ilExerciseException(
"Could not copy ".basename($sourcefile).
" to '".$targetfile.
"'.");
1030 touch($targetfile, filectime($sourcefile));
1037 unlink($targetfile);
1045 $tmpzipfile = $tmpfile .
".zip";
1054 ? strtolower(
$lng->txt(
"exc_assignment"))
1055 : $assTitle).
".zip",
"",
false,
true);
1069 $q =
"SELECT obj_id,user_id,ts FROM exc_returned".
1070 " WHERE ass_id = ".$ilDB->quote($this->assignment->getId(),
"integer").
1071 " AND ".$ilDB->in(
"user_id", $this->
getUserIds(),
"",
"integer").
1072 " AND (filename IS NOT NULL OR atext IS NOT NULL)".
1073 " AND ts IS NOT NULL".
1074 " ORDER BY ts DESC";
1075 $usr_set =
$ilDB->query($q);
1076 $array =
$ilDB->fetchAssoc($usr_set);
1095 $next_id =
$ilDB->nextId(
"exc_returned");
1097 "(returned_id, obj_id, user_id, filetitle, ass_id, ts, atext, late) ".
1098 "VALUES (%s, %s, %s, %s, %s, %s, %s, %s)",
1099 $ilDB->quote($next_id,
"integer"),
1100 $ilDB->quote($this->assignment->getExerciseId(),
"integer"),
1101 $ilDB->quote($this->getUserId(),
"integer"),
1102 $ilDB->quote($a_wsp_id,
"text"),
1103 $ilDB->quote($this->assignment->getId(),
"integer"),
1105 $ilDB->quote($a_text,
"text"),
1106 $ilDB->quote($this->isLate(),
"integer")
1122 $ilDB->manipulate(
"DELETE FROM exc_returned".
1123 " WHERE obj_id = ".
$ilDB->quote($this->assignment->getExerciseId(),
"integer").
1124 " AND user_id = ".$ilDB->quote($this->getUserId(),
"integer").
1125 " AND ass_id = ".$ilDB->quote($this->assignment->getId(),
"integer").
1126 " AND returned_id = ".$ilDB->quote($a_returned_id,
"integer"));
1155 $id =
$files[
"returned_id"];
1158 $ilDB->manipulate(
"UPDATE exc_returned".
1159 " SET atext = ".
$ilDB->quote($a_text,
"text").
1160 ", ts = ".$ilDB->quote(
ilUtil::now(),
"timestamp").
1161 ", late = ".$ilDB->quote($this->isLate(),
"integer").
1162 " WHERE returned_id = ".$ilDB->quote($id,
"integer"));
1180 $result[
"files"][
"count"] =
"---";
1199 $result[
"last_submission"][
"txt"] =
$lng->txt(
"exc_last_submission");
1200 $result[
"last_submission"][
"value"] = $last_sub;
1203 $ilCtrl->setParameterByClass(
"ilexsubmissionfilegui",
"member_id", $this->
getUserId());
1206 switch($this->assignment->getType())
1215 foreach($all_files as
$file)
1224 $result[
"files"][
"txt"] =
$lng->txt(
"exc_files_returned");
1227 $result[
"files"][
"txt"].=
' - <span class="warning">'.$lng->txt(
"exc_late_submission").
" (".$late_files.
")</span>";
1229 $sub_cnt = count($all_files);
1231 if (count(
$new) > 0)
1233 $sub_cnt.=
" ".sprintf(
$lng->txt(
"cnt_new"),count(
$new));
1236 $result[
"files"][
"count"] = $sub_cnt;
1241 $result[
"files"][
"download_url"] =
1242 $ilCtrl->getLinkTargetByClass(
"ilexsubmissionfilegui",
"downloadReturned");
1244 if (count(
$new) <= 0)
1246 $result[
"files"][
"download_txt"] =
$lng->txt(
"exc_tbl_action_download_files");
1250 $result[
"files"][
"download_txt"] =
$lng->txt(
"exc_tbl_action_download_all_files");
1254 if (count(
$new) > 0)
1256 $result[
"files"][
"download_new_url"] =
1257 $ilCtrl->getLinkTargetByClass(
"ilexsubmissionfilegui",
"downloadNewReturned");
1259 $result[
"files"][
"download_new_txt"] =
$lng->txt(
"exc_tbl_action_download_new_files");
1265 $result[
"files"][
"txt"] =
$lng->txt(
"exc_blog_returned");
1269 $blogs = array_pop($blogs);
1270 if($blogs && substr($blogs[
"filename"], -1) !=
"/")
1274 $result[
"files"][
"txt"].=
' - <span class="warning">'.$lng->txt(
"exc_late_submission").
"</span>";
1277 $result[
"files"][
"count"] = 1;
1279 $result[
"files"][
"download_url"] =
1280 $ilCtrl->getLinkTargetByClass(
"ilexsubmissionfilegui",
"downloadReturned");
1282 $result[
"files"][
"download_txt"] =
$lng->txt(
"exc_tbl_action_download_files");
1288 $result[
"files"][
"txt"] =
$lng->txt(
"exc_portfolio_returned");
1292 $portfolios = array_pop($portfolios);
1293 if($portfolios && substr($portfolios[
"filename"], -1) !=
"/")
1295 if($portfolios[
"late"])
1297 $result[
"files"][
"txt"].=
' - <span class="warning">'.$lng->txt(
"exc_late_submission").
"</span>";
1300 $result[
"files"][
"count"] = 1;
1302 $result[
"files"][
"download_url"] =
1303 $ilCtrl->getLinkTargetByClass(
"ilexsubmissionfilegui",
"downloadReturned");
1305 $result[
"files"][
"download_txt"] =
$lng->txt(
"exc_tbl_action_download_files");
1311 $result[
"files"][
"txt"] =
$lng->txt(
"exc_files_returned_text");
1315 $result[
"files"][
"count"] = 1;
1318 if(trim(
$files[
"atext"]))
1322 $result[
"files"][
"txt"].=
' - <span class="warning">'.$lng->txt(
"exc_late_submission").
"</span>";
1325 $result[
"files"][
"download_url"] =
1326 $ilCtrl->getLinkTargetByClass(
"ilexsubmissiontextgui",
"showAssignmentText");
1328 $result[
"files"][
"download_txt"] =
$lng->txt(
"exc_tbl_action_text_assignment_show");
1334 $ilCtrl->setParameterByClass(
"ilexsubmissionfilegui",
"member_id",
"");
sprintf('%.4f', $callTime)
An exception for terminatinating execution or to throw for unit testing.
static formatDate(ilDateTime $date)
Format a date @access public.
@classDescription Date and time handling
Exercise assignment team.
const TEAM_LOG_REMOVE_FILE
static getAssignmentTeamMap($a_ass_id)
Get team structure for assignment.
static getInstanceByUserId($a_assignment_id, $a_user_id, $a_create_on_demand=false)
getExerciseId()
Get exercise id.
getId()
Get assignment id.
static getInstancesByExercise($a_exc_id)
static lookupTitle($a_id)
Lookup title.
lookupNewFiles()
Check how much files have been uploaded by the learner after the last download of the tutor.
static deleteUser($a_exc_id, $a_user_id)
Delete all delivered files of user.
static getAllAssignmentFiles($a_exc_id, $a_ass_id)
downloadSingleFile($a_user_id, $filename, $filetitle)
processUploadedZipFile($fileTmp)
processes errorhandling etc for uploaded archive
addResourceObject($a_wsp_id, $a_text=null)
Add personal resource to assigment.
downloadMultipleFiles($a_filenames, $a_user_id, $a_multi_user=false)
isInTeam($a_user_id=null)
static lookupExerciseIdForReturnedId($a_returned_id)
Get exercise from submission id (used in ilObjMediaObject)
static hasAnySubmissions($a_ass_id)
static downloadAllAssignmentFiles(ilExAssignment $a_ass, array $members)
Download all submitted files of an assignment (all user)
deleteSelectedFiles(array $file_id_array)
Deletes already delivered files.
__construct(ilExAssignment $a_ass, $a_user_id, ilExAssignmentTeam $a_team=null, $a_is_tutor=false, $a_public_submissions=false)
downloadFiles(array $a_file_ids=null, $a_only_new=false, $a_peer_review_mask_filename=false)
updateTutorDownloadTime()
deleteResourceObject($a_returned_id)
Remove personal resource to assigment.
updateTextSubmission($a_text)
Handle text assignment submissions.
uploadFile($a_http_post_files, $unzip=false)
Save submitted file of user.
static findUserFiles($a_user_id, $a_filetitle)
Check if given file was assigned.
getDownloadedFilesInfoForTableGUIS($a_parent_obj, $a_parent_cmd=null)
getFiles(array $a_file_ids=null, $a_only_valid=false, $a_min_timestamp=null)
getLastSubmission()
Get the date of the last submission of a user for the assignment.
getLastDownloadTime(array $a_user_ids)
Class to report exception.
Class to report exception.
static getValidFilename($a_filename)
Get valid filename.
static processZipFile($a_directory, $a_file, $structure, $ref_id=null, $containerType=null, $tree=null, $access_handler=null)
unzips in given directory and processes uploaded zip for use as single files
static utf8_encode($string)
utf8-encodes string if it is not a valid utf8-string.
static recursive_dirscan($dir, &$arr)
Recursively scans a given directory and writes path and filename into referenced array.
static _lookupName($a_user_id)
lookup user name
static _lookupTitle($a_id)
lookup object title
static delDir($a_dir, $a_clean_only=false)
removes a dir and all its content (subdirs and files) recursively
static getMySQLTimestamp($a_ts)
Get MySQL timestamp in 4.1.x or higher format (yyyy-mm-dd hh:mm:ss) This function converts a timestam...
static escapeShellArg($a_arg)
static sendFailure($a_info="", $a_keep=false)
Send Failure Message to Screen.
static now()
Return current timestamp in Y-m-d H:i:s format.
static ilTempnam($a_temp_path=null)
Create a temporary file in an ILIAS writable directory.
static getASCIIFilename($a_filename)
convert utf8 to ascii filename
static unzip($a_file, $overwrite=false, $a_flat=false)
unzip file
static deliverFile($a_file, $a_filename, $a_mime='', $isInline=false, $removeAfterDelivery=false, $a_exit_after=true)
deliver file for download via browser.
static makeDir($a_dir)
creates a new directory and inherits all filesystem permissions of the parent directory You may pass ...
static dirsize($directory)
get size of a directory or a file.
if(!file_exists("$old.txt")) if( $old===$new) if(file_exists("$new.txt")) $file