ILIAS  release_9 Revision v9.13-25-g2c18ec4c24f
ilTestArchiver Class Reference

Class ilTestArchiver. More...

+ Collaboration diagram for ilTestArchiver:

Public Member Functions

 getParticipantData ()
 
 setParticipantData ($participantData)
 
 handInParticipantQuestionMaterial ($active_fi, $pass, $question_fi, $original_filename, $file_path)
 Hands in a particpants question material, such as an upload or other binary content. More...
 
 handInParticipantMisc ($active_fi, $pass, $original_filename, $file_path)
 Hands in a participants file, which is relevant for archiving but an unspecified type. More...
 
 handInTestBestSolution ($best_solution)
 Hands in the best solution for a test. More...
 
 handInParticipantUploadedResults ($active_fi, $pass, $tst_obj)
 
 handInBestSolutionQuestionMaterial ($question_fi, $orginial_filename, $file_path)
 Hands in a file related to a question in context of the best solution. More...
 
 handInTestResult ($active_fi, $pass, $pdf_path)
 Hands in an individual test result for a pass. More...
 
 updateTestArchive ()
 Replaces the test-log with the current one. More...
 
 ensureZipExportDirectoryExists ()
 
 hasZipExportDirectory ()
 Returns if the export directory for zips exists. More...
 
 getZipExportDirectory ()
 Return the export directory, where zips are placed. More...
 
 compressTestArchive ()
 Generate the test archive for download. More...
 

Data Fields

const DIR_SEP = '/'
 
const HTML_SUBMISSION_FILENAME = 'test_submission.html'
 
const PASS_MATERIALS_PATH_COMPONENT = 'materials'
 
const QUESTION_PATH_COMPONENT_PREFIX = 'q_'
 
const TEST_BEST_SOLUTION_PATH_COMPONENT = 'best_solution'
 
const HTML_BEST_SOLUTION_FILENAME = 'best_solution.html'
 
const TEST_MATERIALS_PATH_COMPONENT = 'materials'
 
const TEST_OVERVIEW_HTML_FILENAME = 'results_overview_html_v'
 
const TEST_OVERVIEW_HTML_POSTFIX = '.html'
 
const LOG_DTSGROUP_FORMAT = 'D M j G:i:s T Y'
 
const LOG_ADDITION_STRING = ' Adding '
 
const LOG_CREATION_STRING = ' Creating '
 
const LOG_UPDATE_STRING = ' Updating '
 
const LOG_DELETION_STRING = ' Deleting '
 
const TEST_LOG_FILENAME = 'test.log'
 
const DATA_INDEX_FILENAME = 'data_index.csv'
 
const ARCHIVE_LOG = 'archive.log'
 
const EXPORT_DIRECTORY = 'archive_exports'
 

Protected Member Functions

 hasTestArchive ()
 Returns if the archive directory structure for the test the object is created for exists. More...
 
 createArchiveForTest ()
 Creates the directory for the test archive. More...
 
 getTestArchive ()
 Returns the (theoretical) path to the archive directory of the test, this object is created for. More...
 
 ensureTestArchiveIsAvailable ()
 Ensures the availability of the test archive directory. More...
 
 createZipExportDirectory ()
 
 hasPassDataDirectory ($active_fi, $pass)
 Checks if the directory for pass data is available. More...
 
 createPassDataDirectory ($active_fi, $pass)
 Creates pass data directory. More...
 
 getPassDataDirectory ($active_fi, $pass)
 Returns the pass data directory. More...
 
 ensurePassDataDirectoryIsAvailable ($active_fi, $pass)
 Ensures the availability of the participant data directory. More...
 
 hasPassMaterialsDirectory ($active_fi, $pass)
 Returns if the pass materials directory exists for a given pass. More...
 
 createPassMaterialsDirectory ($active_fi, $pass)
 Creates pass materials directory. More...
 
 getPassMaterialsDirectory ($active_fi, $pass)
 Returns the pass materials directory. More...
 
 ensurePassMaterialsDirectoryIsAvailable ($active_fi, $pass)
 Ensures the availability of the pass materials directory. More...
 
 readArchiveDataIndex ()
 Reads the archive data index. More...
 
 appendToArchiveDataIndex ($date, $active_fi, $pass, $user_firstname, $user_lastname, $matriculation)
 Appends a line to the archive data index. More...
 
 determinePassDataPath ($date, $active_fi, $pass, $user_firstname, $user_lastname, $matriculation)
 Determines the pass data path. More...
 
 logArchivingProcess ($message)
 Logs to the archive log. More...
 
 countFilesInDirectory ($directory, $pattern=null)
 Returns the count of files in a directory, eventually matching the given, optional, pattern. More...
 

Protected Attributes

const TEST_RESULT_FILENAME = 'test_result.html'
 
 $external_directory_path
 
 $client_id
 
 $test_obj_id
 
 $test_ref_id
 
 $archive_data_index
 
ilLanguage $lng
 
ilDBInterface $db
 
ilCtrl $ctrl
 
ilObjUser $user
 
ilTabsGUI $tabs
 
ilToolbarGUI $toolbar
 
ilGlobalTemplateInterface $tpl
 
UIFactory $ui_factory
 
UIRenderer $ui_renderer
 
ilAccess $access
 
InternalRequestService $testrequest
 
GlobalHttpState $http
 
RefineryFactory $refinery
 
ilTestHTMLGenerator $html_generator
 
 $participantData
 

Private Member Functions

 buildPassDataDirectory ($active_fi, $pass)
 

Private Attributes

ILIAS ResourceStorage Services $irss
 

Detailed Description

Class ilTestArchiver.

Helper class to deal with the generation and maintenance of test archives.

Author
Maximilian Becker mbeck.nosp@m.er@d.nosp@m.ataba.nosp@m.y.de
Version
$Id$

Definition at line 38 of file class.ilTestArchiver.php.

Member Function Documentation

◆ appendToArchiveDataIndex()

ilTestArchiver::appendToArchiveDataIndex (   $date,
  $active_fi,
  $pass,
  $user_firstname,
  $user_lastname,
  $matriculation 
)
protected

Appends a line to the archive data index.

Parameters
$datestring Date for the directories path.
$active_fiinteger ActiveFI of the participant.
$passinteger Pass number of the participant.
$user_firstnamestring User firstname.
$user_lastnamestring User lastname.
$matriculationstring Matriculation number of the user.
Returns
void

Definition at line 770 of file class.ilTestArchiver.php.

References determinePassDataPath(), getTestArchive(), and readArchiveDataIndex().

Referenced by createPassMaterialsDirectory(), and getPassDataDirectory().

771  {
772  $line = $this->determinePassDataPath($date, $active_fi, $pass, $user_firstname, $user_lastname, $matriculation);
773 
774  $this->archive_data_index[] = $line;
775  $output_contents = '';
776 
777  foreach ($this->archive_data_index as $line_data) {
778  if ($line_data['identifier'] == "|") {
779  continue;
780  }
781  $output_contents .= implode('|', $line_data) . "\n";
782  }
783 
784  file_put_contents($this->getTestArchive() . self::DIR_SEP . self::DATA_INDEX_FILENAME, $output_contents);
785  $this->readArchiveDataIndex();
786  return;
787  }
determinePassDataPath($date, $active_fi, $pass, $user_firstname, $user_lastname, $matriculation)
Determines the pass data path.
readArchiveDataIndex()
Reads the archive data index.
getTestArchive()
Returns the (theoretical) path to the archive directory of the test, this object is created for...
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ buildPassDataDirectory()

ilTestArchiver::buildPassDataDirectory (   $active_fi,
  $pass 
)
private

Definition at line 556 of file class.ilTestArchiver.php.

References getTestArchive().

Referenced by getPassDataDirectory().

556  : ?string
557  {
558  foreach ($this->archive_data_index as $data_index_entry) {
559  if ($data_index_entry != null && $data_index_entry['identifier'] == $active_fi . '|' . $pass) {
560  array_shift($data_index_entry);
561  return $this->getTestArchive() . self::DIR_SEP . implode(self::DIR_SEP, $data_index_entry);
562  }
563  }
564 
565  return null;
566  }
getTestArchive()
Returns the (theoretical) path to the archive directory of the test, this object is created for...
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ compressTestArchive()

ilTestArchiver::compressTestArchive ( )

Generate the test archive for download.

Returns
void

Definition at line 508 of file class.ilTestArchiver.php.

References ensureZipExportDirectoryExists(), getTestArchive(), getZipExportDirectory(), updateTestArchive(), and ilFileUtils\zip().

509  {
510  $this->updateTestArchive();
512 
513  $zip_output_path = $this->getZipExportDirectory();
514  $zip_output_filename = 'test_archive_obj_' . $this->test_obj_id . '_' . time() . '_.zip';
515 
516  ilFileUtils::zip($this->getTestArchive(), $zip_output_path . self::DIR_SEP . $zip_output_filename, true);
517  return;
518  }
getZipExportDirectory()
Return the export directory, where zips are placed.
getTestArchive()
Returns the (theoretical) path to the archive directory of the test, this object is created for...
static zip(string $a_dir, string $a_file, bool $compress_content=false)
updateTestArchive()
Replaces the test-log with the current one.
+ Here is the call graph for this function:

◆ countFilesInDirectory()

ilTestArchiver::countFilesInDirectory (   $directory,
  $pattern = null 
)
protected

Returns the count of files in a directory, eventually matching the given, optional, pattern.

Parameters
$directory
null | string$pattern
Returns
integer

PhpAssignmentInConditionInspection

Definition at line 845 of file class.ilTestArchiver.php.

845  : int
846  {
847  $filecount = 0;
848 
850  if ($handle = opendir($directory)) {
851  while (($file = readdir($handle)) !== false) {
852  if (!in_array($file, array( '.', '..' )) && !is_dir($directory . $file)) {
853  if ($pattern && strpos($file, $pattern) === 0) {
854  $filecount++;
855  }
856  }
857  }
858  }
859  return $filecount;
860  }

◆ createArchiveForTest()

ilTestArchiver::createArchiveForTest ( )
protected

Creates the directory for the test archive.

Definition at line 381 of file class.ilTestArchiver.php.

References getTestArchive(), and ilFileUtils\makeDirParents().

Referenced by ensureTestArchiveIsAvailable().

382  {
384  //mkdir( $this->getTestArchive(), 0777, true );
385  }
static makeDirParents(string $a_dir)
Create a new directory and all parent directories.
getTestArchive()
Returns the (theoretical) path to the archive directory of the test, this object is created for...
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ createPassDataDirectory()

ilTestArchiver::createPassDataDirectory (   $active_fi,
  $pass 
)
protected

Creates pass data directory.

Parameters
$active_fiinteger ActiveFI of the participant.
$passinteger Pass number of the test.
Returns
void

Definition at line 550 of file class.ilTestArchiver.php.

References getPassDataDirectory().

Referenced by ensurePassDataDirectoryIsAvailable().

551  {
552  mkdir($this->getPassDataDirectory($active_fi, $pass), 0777, true);
553  return;
554  }
getPassDataDirectory($active_fi, $pass)
Returns the pass data directory.
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ createPassMaterialsDirectory()

ilTestArchiver::createPassMaterialsDirectory (   $active_fi,
  $pass 
)
protected

Creates pass materials directory.

Parameters
$active_fiinteger ActiveFI of the participant.
$passinteger Pass number of the test.
Returns
string

Definition at line 662 of file class.ilTestArchiver.php.

References $user, appendToArchiveDataIndex(), ilObjUser\getFirstname(), ilObjUser\getLastname(), ilObjUser\getMatriculation(), getParticipantData(), getPassMaterialsDirectory(), ilObjUser\setFirstname(), ilObjUser\setLastname(), and ilObjUser\setMatriculation().

Referenced by ensurePassMaterialsDirectoryIsAvailable().

662  : string
663  {
664  // Data are taken from the current user as the implementation expects the first interaction of the pass
665  // takes place from the usage/behaviour of the current user.
666 
667  $user = $this->user;
668 
669  if ($this->getParticipantData()) {
670  $usrData = $this->getParticipantData()->getUserDataByActiveId($active_fi);
671  $user = new ilObjUser();
672  $user->setFirstname($usrData['firstname']);
673  $user->setLastname($usrData['lastname']);
674  $user->setMatriculation($usrData['matriculation']);
675  $user->setFirstname($usrData['firstname']);
676  }
677 
679  date('c'),
680  $active_fi,
681  $pass,
682  $user->getFirstname(),
683  $user->getLastname(),
685  );
686  $material_directory = $this->getPassMaterialsDirectory($active_fi, $pass);
687  mkdir($material_directory, 0777, true);
688  return $material_directory;
689  }
setMatriculation(string $a_str)
getPassMaterialsDirectory($active_fi, $pass)
Returns the pass materials directory.
appendToArchiveDataIndex($date, $active_fi, $pass, $user_firstname, $user_lastname, $matriculation)
Appends a line to the archive data index.
setLastname(string $a_str)
setFirstname(string $a_str)
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ createZipExportDirectory()

ilTestArchiver::createZipExportDirectory ( )
protected

Definition at line 487 of file class.ilTestArchiver.php.

References getZipExportDirectory().

Referenced by ensureZipExportDirectoryExists().

488  {
489  mkdir($this->getZipExportDirectory(), 0777, true);
490  }
getZipExportDirectory()
Return the export directory, where zips are placed.
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ determinePassDataPath()

ilTestArchiver::determinePassDataPath (   $date,
  $active_fi,
  $pass,
  $user_firstname,
  $user_lastname,
  $matriculation 
)
protected

Determines the pass data path.

Parameters
$date
$active_fi
$pass
$user_firstname
$user_lastname
$matriculation
Returns
array

Definition at line 801 of file class.ilTestArchiver.php.

Referenced by appendToArchiveDataIndex().

801  : array
802  {
803  $date = date_create_from_format('Y-m-d\TH:i:sP', $date);
804  if (!$date) {
805  throw new Exception('Invalid date format. Expected ISO 8601 format.');
806  }
807 
808  $line = array(
809  'identifier' => $active_fi . '|' . $pass,
810  'yyyy' => date_format($date, 'Y'),
811  'mm' => date_format($date, 'm'),
812  'dd' => date_format($date, 'd'),
813  'directory' => $active_fi . '_' . $pass . '_' . $user_firstname . '_' . $user_lastname . '_' . $matriculation
814  );
815  return $line;
816  }
+ Here is the caller graph for this function:

◆ ensurePassDataDirectoryIsAvailable()

ilTestArchiver::ensurePassDataDirectoryIsAvailable (   $active_fi,
  $pass 
)
protected

Ensures the availability of the participant data directory.

Checks if the directory exists and creates it if necessary.

Parameters
$active_fiinteger Active-FI of the test participant
$passinteger Pass-number of the actual test
Returns
void

Definition at line 625 of file class.ilTestArchiver.php.

References createPassDataDirectory(), and hasPassDataDirectory().

Referenced by handInParticipantMisc(), handInParticipantQuestionMaterial(), handInParticipantUploadedResults(), and handInTestResult().

626  {
627  if (!$this->hasPassDataDirectory($active_fi, $pass)) {
628  $this->createPassDataDirectory($active_fi, $pass);
629  }
630  return;
631  }
createPassDataDirectory($active_fi, $pass)
Creates pass data directory.
hasPassDataDirectory($active_fi, $pass)
Checks if the directory for pass data is available.
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ ensurePassMaterialsDirectoryIsAvailable()

ilTestArchiver::ensurePassMaterialsDirectoryIsAvailable (   $active_fi,
  $pass 
)
protected

Ensures the availability of the pass materials directory.

Checks if the directory exists and creates it if necessary.

Parameters
$active_fiinteger Active-FI of the test participant
$passinteger Pass-number of the actual test

Definition at line 714 of file class.ilTestArchiver.php.

References createPassMaterialsDirectory(), and hasPassMaterialsDirectory().

Referenced by handInParticipantUploadedResults().

715  {
716  if (!$this->hasPassMaterialsDirectory($active_fi, $pass)) {
717  $this->createPassMaterialsDirectory($active_fi, $pass);
718  }
719  }
hasPassMaterialsDirectory($active_fi, $pass)
Returns if the pass materials directory exists for a given pass.
createPassMaterialsDirectory($active_fi, $pass)
Creates pass materials directory.
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ ensureTestArchiveIsAvailable()

ilTestArchiver::ensureTestArchiveIsAvailable ( )
protected

Ensures the availability of the test archive directory.

Checks if the directory exists and creates it if necessary.

Returns
void

Definition at line 406 of file class.ilTestArchiver.php.

References createArchiveForTest(), and hasTestArchive().

Referenced by handInBestSolutionQuestionMaterial(), handInParticipantMisc(), handInParticipantQuestionMaterial(), handInParticipantUploadedResults(), handInTestBestSolution(), and handInTestResult().

407  {
408  if (!$this->hasTestArchive()) {
409  $this->createArchiveForTest();
410  }
411  return;
412  }
createArchiveForTest()
Creates the directory for the test archive.
hasTestArchive()
Returns if the archive directory structure for the test the object is created for exists...
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ ensureZipExportDirectoryExists()

ilTestArchiver::ensureZipExportDirectoryExists ( )

Definition at line 470 of file class.ilTestArchiver.php.

References createZipExportDirectory(), and hasZipExportDirectory().

Referenced by compressTestArchive().

471  {
472  if (!$this->hasZipExportDirectory()) {
473  $this->createZipExportDirectory();
474  }
475  }
hasZipExportDirectory()
Returns if the export directory for zips exists.
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getParticipantData()

ilTestArchiver::getParticipantData ( )
Returns
ilTestParticipantData

Definition at line 164 of file class.ilTestArchiver.php.

References $participantData.

Referenced by createPassMaterialsDirectory(), and getPassDataDirectory().

+ Here is the caller graph for this function:

◆ getPassDataDirectory()

ilTestArchiver::getPassDataDirectory (   $active_fi,
  $pass 
)
protected

Returns the pass data directory.

Parameters
$active_fiinteger ActiveFI of the participant.
$passinteger Pass number of the test.
Returns
string $pass_data_directory Path to the pass data directory.

Definition at line 576 of file class.ilTestArchiver.php.

References appendToArchiveDataIndex(), buildPassDataDirectory(), getParticipantData(), and ILIAS\Repository\user().

Referenced by createPassDataDirectory(), getPassMaterialsDirectory(), handInParticipantMisc(), handInParticipantQuestionMaterial(), handInTestResult(), and hasPassDataDirectory().

576  : ?string
577  {
578  $pass_data_dir = $this->buildPassDataDirectory($active_fi, $pass);
579 
580  if ($pass_data_dir !== null) {
581  return $pass_data_dir;
582  }
583 
584  $test_obj = new ilObjTest($this->test_obj_id, false);
585  if ($test_obj->getAnonymity()) {
586  $firstname = 'anonym';
587  $lastname = '';
588  $matriculation = '0';
589  } else {
590  if ($this->getParticipantData()) {
591  $usr_data = $this->getParticipantData()->getUserDataByActiveId($active_fi);
592  $firstname = $usr_data['firstname'];
593  $lastname = $usr_data['lastname'];
594  $matriculation = $usr_data['matriculation'];
595  } else {
596 
597  $firstname = $this->user->getFirstname();
598  $lastname = $this->user->getLastname();
599  $matriculation = $this->user->getMatriculation();
600  }
601  }
602 
604  date(DATE_ISO8601),
605  $active_fi,
606  $pass,
607  $firstname,
608  $lastname,
609  $matriculation
610  );
611 
612  return $this->buildPassDataDirectory($active_fi, $pass);
613  }
buildPassDataDirectory($active_fi, $pass)
appendToArchiveDataIndex($date, $active_fi, $pass, $user_firstname, $user_lastname, $matriculation)
Appends a line to the archive data index.
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getPassMaterialsDirectory()

ilTestArchiver::getPassMaterialsDirectory (   $active_fi,
  $pass 
)
protected

Returns the pass materials directory.

Parameters
$active_fiinteger ActiveFI of the participant.
$passinteger Pass number.
Returns
string $pass_materials_directory Path to the pass materials directory.

Definition at line 699 of file class.ilTestArchiver.php.

References getPassDataDirectory().

Referenced by createPassMaterialsDirectory(), handInParticipantUploadedResults(), and hasPassMaterialsDirectory().

699  : string
700  {
701  $pass_data_directory = $this->getPassDataDirectory($active_fi, $pass);
702  return $pass_data_directory . self::DIR_SEP . self::PASS_MATERIALS_PATH_COMPONENT;
703  }
getPassDataDirectory($active_fi, $pass)
Returns the pass data directory.
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getTestArchive()

ilTestArchiver::getTestArchive ( )
protected

Returns the (theoretical) path to the archive directory of the test, this object is created for.

Returns
string $test_archive Path to this tests archive directory.

Definition at line 392 of file class.ilTestArchiver.php.

References $test_obj_id.

Referenced by appendToArchiveDataIndex(), buildPassDataDirectory(), compressTestArchive(), createArchiveForTest(), handInBestSolutionQuestionMaterial(), handInTestBestSolution(), hasTestArchive(), logArchivingProcess(), readArchiveDataIndex(), and updateTestArchive().

392  : string
393  {
394  $test_archive_directory = $this->external_directory_path . self::DIR_SEP . $this->client_id . self::DIR_SEP . 'tst_data'
395  . self::DIR_SEP . 'archive' . self::DIR_SEP . 'tst_' . $this->test_obj_id;
396  return $test_archive_directory;
397  }
+ Here is the caller graph for this function:

◆ getZipExportDirectory()

ilTestArchiver::getZipExportDirectory ( )

Return the export directory, where zips are placed.

Returns
string

Definition at line 497 of file class.ilTestArchiver.php.

References $test_obj_id.

Referenced by compressTestArchive(), createZipExportDirectory(), and hasZipExportDirectory().

497  : string
498  {
499  return $this->external_directory_path . self::DIR_SEP . $this->client_id . self::DIR_SEP . 'tst_data'
500  . self::DIR_SEP . self::EXPORT_DIRECTORY . self::DIR_SEP . 'tst_' . $this->test_obj_id;
501  }
+ Here is the caller graph for this function:

◆ handInBestSolutionQuestionMaterial()

ilTestArchiver::handInBestSolutionQuestionMaterial (   $question_fi,
  $orginial_filename,
  $file_path 
)

Hands in a file related to a question in context of the best solution.

Parameters
$question_fiinteger QuestionFI of the question, material is to be stored for.
$orginial_filenamestring Original filename of the material to be stored.
$file_pathstring Path to the material to be stored.

Definition at line 318 of file class.ilTestArchiver.php.

References ensureTestArchiveIsAvailable(), getTestArchive(), and logArchivingProcess().

319  {
321 
322  $best_solution_path = $this->getTestArchive() . self::DIR_SEP . self::TEST_BEST_SOLUTION_PATH_COMPONENT;
323  if (!is_dir($best_solution_path)) {
324  mkdir($best_solution_path, 0777, true);
325  }
326 
327  $materials_path = $best_solution_path . self::DIR_SEP . self::TEST_MATERIALS_PATH_COMPONENT;
328  if (!is_dir($materials_path)) {
329  mkdir($materials_path, 0777, true);
330  }
331 
332  $question_materials_path = $materials_path . self::DIR_SEP . self::QUESTION_PATH_COMPONENT_PREFIX . $question_fi;
333  if (!is_dir($question_materials_path)) {
334  mkdir($question_materials_path, 0777, true);
335  }
336 
337  copy($file_path, $question_materials_path . self::DIR_SEP . $orginial_filename);
338 
339  $this->logArchivingProcess(
340  date(self::LOG_DTSGROUP_FORMAT) . self::LOG_ADDITION_STRING
341  . $question_materials_path . self::DIR_SEP . $orginial_filename
342  );
343  }
getTestArchive()
Returns the (theoretical) path to the archive directory of the test, this object is created for...
ensureTestArchiveIsAvailable()
Ensures the availability of the test archive directory.
logArchivingProcess($message)
Logs to the archive log.
+ Here is the call graph for this function:

◆ handInParticipantMisc()

ilTestArchiver::handInParticipantMisc (   $active_fi,
  $pass,
  $original_filename,
  $file_path 
)

Hands in a participants file, which is relevant for archiving but an unspecified type.

Examples for such are signature files, remarks, feedback or the like.

Parameters
$active_fiinteger Active-FI of the test participant
$passinteger Pass-number of the actual test
$original_filenamestring Original filename of the material to be stored.
$file_pathstring Location of the file to be archived

Definition at line 217 of file class.ilTestArchiver.php.

References ensurePassDataDirectoryIsAvailable(), ensureTestArchiveIsAvailable(), getPassDataDirectory(), and logArchivingProcess().

218  {
220  $this->ensurePassDataDirectoryIsAvailable($active_fi, $pass);
221  $new_path = $this->getPassDataDirectory($active_fi, $pass) . self::DIR_SEP . $original_filename;
222  copy($file_path, $new_path);
223  $this->logArchivingProcess(date(self::LOG_DTSGROUP_FORMAT) . self::LOG_ADDITION_STRING . $new_path);
224  }
getPassDataDirectory($active_fi, $pass)
Returns the pass data directory.
ensurePassDataDirectoryIsAvailable($active_fi, $pass)
Ensures the availability of the participant data directory.
ensureTestArchiveIsAvailable()
Ensures the availability of the test archive directory.
logArchivingProcess($message)
Logs to the archive log.
+ Here is the call graph for this function:

◆ handInParticipantQuestionMaterial()

ilTestArchiver::handInParticipantQuestionMaterial (   $active_fi,
  $pass,
  $question_fi,
  $original_filename,
  $file_path 
)

Hands in a particpants question material, such as an upload or other binary content.

Parameters
$active_fiinteger Active-FI of the test participant
$passinteger Pass-number of the actual test
$question_fiinteger Question-FI of the question, the file is to be stored for.
$original_filenamestring Original filename of the material to be stored.
$file_pathstring Location of the file to be archived

Definition at line 188 of file class.ilTestArchiver.php.

References ensurePassDataDirectoryIsAvailable(), ensureTestArchiveIsAvailable(), getPassDataDirectory(), and logArchivingProcess().

189  {
191  $this->ensurePassDataDirectoryIsAvailable($active_fi, $pass);
192 
193  $pass_question_directory = $this->getPassDataDirectory($active_fi, $pass)
194  . self::DIR_SEP . self::QUESTION_PATH_COMPONENT_PREFIX . $question_fi;
195  if (!is_dir($pass_question_directory)) {
196  mkdir($pass_question_directory, 0777, true);
197  }
198 
199  copy($file_path, $pass_question_directory . self::DIR_SEP . $original_filename);
200 
201  $this->logArchivingProcess(
202  date(self::LOG_DTSGROUP_FORMAT) . self::LOG_ADDITION_STRING
203  . $pass_question_directory . self::DIR_SEP . $original_filename
204  );
205  }
getPassDataDirectory($active_fi, $pass)
Returns the pass data directory.
ensurePassDataDirectoryIsAvailable($active_fi, $pass)
Ensures the availability of the participant data directory.
ensureTestArchiveIsAvailable()
Ensures the availability of the test archive directory.
logArchivingProcess($message)
Logs to the archive log.
+ Here is the call graph for this function:

◆ handInParticipantUploadedResults()

ilTestArchiver::handInParticipantUploadedResults (   $active_fi,
  $pass,
  $tst_obj 
)
Parameters
$active_fi
$pass
Returns
void

Definition at line 261 of file class.ilTestArchiver.php.

References CLIENT_WEB_DIR, ensurePassDataDirectoryIsAvailable(), ensurePassMaterialsDirectoryIsAvailable(), ensureTestArchiveIsAvailable(), getPassMaterialsDirectory(), and logArchivingProcess().

261  {
262  $questions = $tst_obj->getQuestionsOfPass($active_fi, $pass);
263  foreach ($questions as $question) {
264  $question = $tst_obj->getQuestionDataset($question['question_fi']);
265  if ($question->type_tag === 'assFileUpload') {
267  $this->ensurePassDataDirectoryIsAvailable($active_fi, $pass);
268  $this->ensurePassMaterialsDirectoryIsAvailable($active_fi, $pass);
269  $pass_material_directory = $this->getPassMaterialsDirectory($active_fi, $pass);
270  $archive_folder = $pass_material_directory . self::DIR_SEP . $question->question_id . self::DIR_SEP;
271  if (!file_exists($archive_folder)) {
272  mkdir($archive_folder, 0777, true);
273  }
274  // TODO old Filesystem remove on ILIAS 10
275  $local_folder = CLIENT_WEB_DIR . '/assessment/tst_' . $tst_obj->test_id . self::DIR_SEP . $active_fi . self::DIR_SEP . $question->question_id . '/files/';
276  if (file_exists($local_folder)) {
277  $folder_content = scandir($local_folder);
278  $folder_content = array_diff($folder_content, array('.', '..'));
279  foreach ($folder_content as $file_name) {
280  if (preg_match('/file_(\d+)_(\d+)_(\d+)/', $file_name, $matches)){
281  if ($active_fi == intval($matches[1]) && $pass == $matches[2]){
282  $local_file= $local_folder . $file_name;
283  $target_destination = $archive_folder . $file_name;
284  copy($local_file, $target_destination);
285  $this->logArchivingProcess(date(self::LOG_DTSGROUP_FORMAT) . self::LOG_ADDITION_STRING . $target_destination);
286  }
287  }
288  }
289  }
290  // IRSS
291  $resource_id = $tst_obj->getTextAnswer($active_fi, $question->question_id, $pass);
292  if ($resource_id == ''){
293  continue;
294  }
295  $irss_unique_id = $this->irss->manage()->find($resource_id);
296  if ($irss_unique_id != null){
297  $resource = $this->irss->manage()->getResource($irss_unique_id);
298  $information = $resource->getCurrentRevision()->getInformation();
299  $stream = $this->irss->consume()->stream($irss_unique_id);
300  // this feels unnecessary..
301  $file_stream = fopen($stream->getStream()->getMetadata('uri'), 'r');
302  $file_content = stream_get_contents($file_stream);
303  fclose($file_stream);
304  $target_destination = $archive_folder . $information->getTitle();
305  file_put_contents($target_destination, $file_content);
306  }
307  }
308  }
309  }
getPassMaterialsDirectory($active_fi, $pass)
Returns the pass materials directory.
ensurePassDataDirectoryIsAvailable($active_fi, $pass)
Ensures the availability of the participant data directory.
const CLIENT_WEB_DIR
Definition: constants.php:47
ensurePassMaterialsDirectoryIsAvailable($active_fi, $pass)
Ensures the availability of the pass materials directory.
ensureTestArchiveIsAvailable()
Ensures the availability of the test archive directory.
logArchivingProcess($message)
Logs to the archive log.
+ Here is the call graph for this function:

◆ handInTestBestSolution()

ilTestArchiver::handInTestBestSolution (   $best_solution)

Hands in the best solution for a test.

Parameters
$html_stringstring HTML-string of the test submission
$pdf_pathstring Path to a pdf representation of the test submission.

Definition at line 232 of file class.ilTestArchiver.php.

References ensureTestArchiveIsAvailable(), getTestArchive(), and logArchivingProcess().

233  {
235 
236  $best_solution_path = $this->getTestArchive() . self::DIR_SEP . self::TEST_BEST_SOLUTION_PATH_COMPONENT;
237  if (!is_dir($best_solution_path)) {
238  mkdir($best_solution_path, 0777, true);
239  }
240 
241  $this->html_generator->generateHTML(
242  $best_solution,
243  $best_solution_path . self::DIR_SEP . self::HTML_BEST_SOLUTION_FILENAME
244  );
245 
246  $this->logArchivingProcess(
247  date(self::LOG_DTSGROUP_FORMAT) . self::LOG_ADDITION_STRING
248  . $best_solution_path . self::DIR_SEP . self::HTML_BEST_SOLUTION_FILENAME
249  );
250 
251  $this->logArchivingProcess(
252  date(self::LOG_DTSGROUP_FORMAT) . self::LOG_ADDITION_STRING . $best_solution_path
253  );
254  }
getTestArchive()
Returns the (theoretical) path to the archive directory of the test, this object is created for...
ensureTestArchiveIsAvailable()
Ensures the availability of the test archive directory.
logArchivingProcess($message)
Logs to the archive log.
+ Here is the call graph for this function:

◆ handInTestResult()

ilTestArchiver::handInTestResult (   $active_fi,
  $pass,
  $pdf_path 
)

Hands in an individual test result for a pass.

Parameters
$active_fiinteger ActiveFI of the participant.
$passinteger Pass of the test.
$pdf_pathstring Path to the PDF containing the result.
Returns
void

Definition at line 354 of file class.ilTestArchiver.php.

References ensurePassDataDirectoryIsAvailable(), ensureTestArchiveIsAvailable(), getPassDataDirectory(), and logArchivingProcess().

355  {
357  $this->ensurePassDataDirectoryIsAvailable($active_fi, $pass);
358  $new_path = $this->getPassDataDirectory($active_fi, $pass) . self::DIR_SEP . self::TEST_RESULT_FILENAME;
359  copy($pdf_path, $new_path);
360  $this->logArchivingProcess(date(self::LOG_DTSGROUP_FORMAT) . self::LOG_ADDITION_STRING . $new_path);
361  }
getPassDataDirectory($active_fi, $pass)
Returns the pass data directory.
ensurePassDataDirectoryIsAvailable($active_fi, $pass)
Ensures the availability of the participant data directory.
ensureTestArchiveIsAvailable()
Ensures the availability of the test archive directory.
logArchivingProcess($message)
Logs to the archive log.
+ Here is the call graph for this function:

◆ hasPassDataDirectory()

ilTestArchiver::hasPassDataDirectory (   $active_fi,
  $pass 
)
protected

Checks if the directory for pass data is available.

Parameters
$active_fiinteger ActiveFI of the pass.
$passinteger Pass-number of the pass.
Returns
bool $hasPassDataDirectory True, if the pass data directory exists.

Definition at line 536 of file class.ilTestArchiver.php.

References getPassDataDirectory().

Referenced by ensurePassDataDirectoryIsAvailable().

536  : bool
537  {
538  $pass_data_dir = $this->getPassDataDirectory($active_fi, $pass);
539  return is_dir($this->getPassDataDirectory($active_fi, $pass));
540  }
getPassDataDirectory($active_fi, $pass)
Returns the pass data directory.
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ hasPassMaterialsDirectory()

ilTestArchiver::hasPassMaterialsDirectory (   $active_fi,
  $pass 
)
protected

Returns if the pass materials directory exists for a given pass.

Parameters
$active_fiinteger ActiveFI for the participant.
$passinteger Pass number.
Returns
bool $hasPassmaterialsDirectory True, if the directory exists.

PhpUsageOfSilenceOperatorInspection

Definition at line 645 of file class.ilTestArchiver.php.

References getPassMaterialsDirectory().

Referenced by ensurePassMaterialsDirectoryIsAvailable().

645  : bool
646  {
648  if (@is_dir($this->getPassMaterialsDirectory($active_fi, $pass))) {
649  return true;
650  }
651  return false;
652  }
getPassMaterialsDirectory($active_fi, $pass)
Returns the pass materials directory.
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ hasTestArchive()

ilTestArchiver::hasTestArchive ( )
protected

Returns if the archive directory structure for the test the object is created for exists.

Returns
bool $hasTestArchive True, if the archive directory structure exists.

Definition at line 373 of file class.ilTestArchiver.php.

References getTestArchive().

Referenced by ensureTestArchiveIsAvailable().

373  : bool
374  {
375  return is_dir($this->getTestArchive());
376  }
getTestArchive()
Returns the (theoretical) path to the archive directory of the test, this object is created for...
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ hasZipExportDirectory()

ilTestArchiver::hasZipExportDirectory ( )

Returns if the export directory for zips exists.

Returns
bool

Definition at line 482 of file class.ilTestArchiver.php.

References getZipExportDirectory().

Referenced by ensureZipExportDirectoryExists().

482  : bool
483  {
484  return is_dir($this->getZipExportDirectory());
485  }
getZipExportDirectory()
Return the export directory, where zips are placed.
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ logArchivingProcess()

ilTestArchiver::logArchivingProcess (   $message)
protected

Logs to the archive log.

Parameters
$messagestring Complete log message.
Returns
void

Definition at line 825 of file class.ilTestArchiver.php.

References $message, and getTestArchive().

Referenced by handInBestSolutionQuestionMaterial(), handInParticipantMisc(), handInParticipantQuestionMaterial(), handInParticipantUploadedResults(), handInTestBestSolution(), and handInTestResult().

826  {
827  $archive = $this->getTestArchive() . self::DIR_SEP . self::ARCHIVE_LOG;
828  if (file_exists($archive)) {
829  $content = file_get_contents($archive) . "\n" . $message;
830  } else {
831  $content = $message;
832  }
833 
834  file_put_contents($archive, $content);
835  }
getTestArchive()
Returns the (theoretical) path to the archive directory of the test, this object is created for...
$message
Definition: xapiexit.php:32
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ readArchiveDataIndex()

ilTestArchiver::readArchiveDataIndex ( )
protected

Reads the archive data index.

Returns
array[array] $archive_data_index Archive data index.

The Archive Data Index is a csv-file containing the following columns <active_fi>|<pass>|<yyyy>|<mm>||<directory>

PhpUsageOfSilenceOperatorInspection

Definition at line 728 of file class.ilTestArchiver.php.

References getTestArchive().

Referenced by appendToArchiveDataIndex().

728  : array
729  {
734  $data_index_file = $this->getTestArchive() . self::DIR_SEP . self::DATA_INDEX_FILENAME;
735 
736  $contents = array();
737 
739  if (@file_exists($data_index_file)) {
740  $lines = explode("\n", file_get_contents($data_index_file));
741  foreach ($lines as $line) {
742  if (strlen($line) === 0) {
743  continue;
744  }
745  $line_items = explode('|', $line);
746  $line_data = [];
747  $line_data['identifier'] = $line_items[0] . '|' . $line_items[1];
748  $line_data['yyyy'] = $line_items[2];
749  $line_data['mm'] = $line_items[3];
750  $line_data['dd'] = $line_items[4];
751  $line_data['directory'] = $line_items[5];
752  $contents[] = $line_data;
753  }
754  }
755  return $contents;
756  }
getTestArchive()
Returns the (theoretical) path to the archive directory of the test, this object is created for...
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ setParticipantData()

ilTestArchiver::setParticipantData (   $participantData)
Parameters
ilTestParticipantData$participantData

Definition at line 172 of file class.ilTestArchiver.php.

References $participantData.

Referenced by ilTestArchiveService\archiveActivesPass().

173  {
174  $this->participantData = $participantData;
175  }
+ Here is the caller graph for this function:

◆ updateTestArchive()

ilTestArchiver::updateTestArchive ( )

Replaces the test-log with the current one.

Returns
void

PhpAssignmentInConditionInspection

Definition at line 419 of file class.ilTestArchiver.php.

References $filename, ILIAS\LTI\ToolProvider\$key, ILIAS\Repository\access(), ILIAS\Repository\ctrl(), getTestArchive(), ILIAS\FileDelivery\http(), ILIAS\Repository\lng(), ILIAS\Repository\refinery(), ILIAS\Repository\tabs(), ILIAS\Repository\toolbar(), and ILIAS\Repository\user().

Referenced by compressTestArchive().

420  {
421  $query = 'SELECT * FROM ass_log WHERE obj_fi = ' . $this->db->quote($this->test_obj_id, 'integer');
422  $result = $this->db->query($query);
423 
424  $outfile_lines = '';
426  while ($row = $this->db->fetchAssoc($result)) {
427  $outfile_lines .= "\r\n" . implode("\t", $row);
428  }
429  file_put_contents($this->getTestArchive() . self::DIR_SEP . self::TEST_LOG_FILENAME, $outfile_lines);
430 
431  // Generate test pass overview
432  $test = new ilObjTest($this->test_obj_id, false);
433  if ($this->test_ref_id !== null) {
434  $test->setRefId($this->test_ref_id);
435  }
436 
437  $gui = new ilParticipantsTestResultsGUI(
438  $this->ctrl,
439  $this->lng,
440  $this->db,
441  $this->user,
442  $this->tabs,
443  $this->toolbar,
444  $this->tpl,
445  $this->ui_factory,
446  $this->ui_renderer,
448  $this->testrequest,
449  $this->http,
450  $this->refinery
451  );
452  $gui->setTestObj($test);
453 
454  $objectiveOrientedContainer = new ilTestObjectiveOrientedContainer();
455  $gui->setObjectiveParent($objectiveOrientedContainer);
456  $array_of_actives = array();
457  $participants = $test->getParticipants();
458 
459  foreach ($participants as $key => $value) {
460  $array_of_actives[] = $key;
461  }
462  $output_template = $gui->createUserResults(true, false, true, $array_of_actives);
463 
464  $filename = realpath($this->getTestArchive()) . self::DIR_SEP . 'participant_pass_overview.html';
465  $this->html_generator->generateHTML($output_template->get(), $filename);
466 
467  return;
468  }
ilParticipantsTestResultsGUI: ilTestEvaluationGUI ilParticipantsTestResultsGUI: ilAssQuestionPageGUI...
static http()
Fetches the global http state from ILIAS.
string $key
Consumer key/client ID value.
Definition: System.php:193
$filename
Definition: buildRTE.php:78
getTestArchive()
Returns the (theoretical) path to the archive directory of the test, this object is created for...
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

Field Documentation

◆ $access

ilAccess ilTestArchiver::$access
protected

Definition at line 112 of file class.ilTestArchiver.php.

◆ $archive_data_index

ilTestArchiver::$archive_data_index
protected

Definition at line 101 of file class.ilTestArchiver.php.

◆ $client_id

ilTestArchiver::$client_id
protected

Definition at line 98 of file class.ilTestArchiver.php.

◆ $ctrl

ilCtrl ilTestArchiver::$ctrl
protected

Definition at line 105 of file class.ilTestArchiver.php.

◆ $db

ilDBInterface ilTestArchiver::$db
protected

Definition at line 104 of file class.ilTestArchiver.php.

◆ $external_directory_path

ilTestArchiver::$external_directory_path
protected

Definition at line 97 of file class.ilTestArchiver.php.

◆ $html_generator

ilTestHTMLGenerator ilTestArchiver::$html_generator
protected

Definition at line 117 of file class.ilTestArchiver.php.

◆ $http

GlobalHttpState ilTestArchiver::$http
protected

Definition at line 114 of file class.ilTestArchiver.php.

◆ $irss

ILIAS ResourceStorage Services ilTestArchiver::$irss
private

Definition at line 124 of file class.ilTestArchiver.php.

◆ $lng

ilLanguage ilTestArchiver::$lng
protected

Definition at line 103 of file class.ilTestArchiver.php.

◆ $participantData

ilTestArchiver::$participantData
protected

Definition at line 122 of file class.ilTestArchiver.php.

Referenced by getParticipantData(), and setParticipantData().

◆ $refinery

RefineryFactory ilTestArchiver::$refinery
protected

Definition at line 115 of file class.ilTestArchiver.php.

◆ $tabs

ilTabsGUI ilTestArchiver::$tabs
protected

Definition at line 107 of file class.ilTestArchiver.php.

◆ $test_obj_id

ilTestArchiver::$test_obj_id
protected

Definition at line 99 of file class.ilTestArchiver.php.

Referenced by getTestArchive(), and getZipExportDirectory().

◆ $test_ref_id

ilTestArchiver::$test_ref_id
protected

Definition at line 100 of file class.ilTestArchiver.php.

◆ $testrequest

InternalRequestService ilTestArchiver::$testrequest
protected

Definition at line 113 of file class.ilTestArchiver.php.

◆ $toolbar

ilToolbarGUI ilTestArchiver::$toolbar
protected

Definition at line 108 of file class.ilTestArchiver.php.

◆ $tpl

ilGlobalTemplateInterface ilTestArchiver::$tpl
protected

Definition at line 109 of file class.ilTestArchiver.php.

◆ $ui_factory

UIFactory ilTestArchiver::$ui_factory
protected

Definition at line 110 of file class.ilTestArchiver.php.

◆ $ui_renderer

UIRenderer ilTestArchiver::$ui_renderer
protected

Definition at line 111 of file class.ilTestArchiver.php.

◆ $user

ilObjUser ilTestArchiver::$user
protected

Definition at line 106 of file class.ilTestArchiver.php.

Referenced by createPassMaterialsDirectory().

◆ ARCHIVE_LOG

const ilTestArchiver::ARCHIVE_LOG = 'archive.log'

Definition at line 65 of file class.ilTestArchiver.php.

◆ DATA_INDEX_FILENAME

const ilTestArchiver::DATA_INDEX_FILENAME = 'data_index.csv'

Definition at line 64 of file class.ilTestArchiver.php.

◆ DIR_SEP

const ilTestArchiver::DIR_SEP = '/'

Definition at line 42 of file class.ilTestArchiver.php.

◆ EXPORT_DIRECTORY

const ilTestArchiver::EXPORT_DIRECTORY = 'archive_exports'

Definition at line 67 of file class.ilTestArchiver.php.

◆ HTML_BEST_SOLUTION_FILENAME

const ilTestArchiver::HTML_BEST_SOLUTION_FILENAME = 'best_solution.html'

Definition at line 49 of file class.ilTestArchiver.php.

◆ HTML_SUBMISSION_FILENAME

const ilTestArchiver::HTML_SUBMISSION_FILENAME = 'test_submission.html'

Definition at line 44 of file class.ilTestArchiver.php.

◆ LOG_ADDITION_STRING

const ilTestArchiver::LOG_ADDITION_STRING = ' Adding '

Definition at line 58 of file class.ilTestArchiver.php.

◆ LOG_CREATION_STRING

const ilTestArchiver::LOG_CREATION_STRING = ' Creating '

Definition at line 59 of file class.ilTestArchiver.php.

◆ LOG_DELETION_STRING

const ilTestArchiver::LOG_DELETION_STRING = ' Deleting '

Definition at line 61 of file class.ilTestArchiver.php.

◆ LOG_DTSGROUP_FORMAT

const ilTestArchiver::LOG_DTSGROUP_FORMAT = 'D M j G:i:s T Y'

Definition at line 57 of file class.ilTestArchiver.php.

◆ LOG_UPDATE_STRING

const ilTestArchiver::LOG_UPDATE_STRING = ' Updating '

Definition at line 60 of file class.ilTestArchiver.php.

◆ PASS_MATERIALS_PATH_COMPONENT

const ilTestArchiver::PASS_MATERIALS_PATH_COMPONENT = 'materials'

Definition at line 45 of file class.ilTestArchiver.php.

◆ QUESTION_PATH_COMPONENT_PREFIX

const ilTestArchiver::QUESTION_PATH_COMPONENT_PREFIX = 'q_'

Definition at line 46 of file class.ilTestArchiver.php.

◆ TEST_BEST_SOLUTION_PATH_COMPONENT

const ilTestArchiver::TEST_BEST_SOLUTION_PATH_COMPONENT = 'best_solution'

Definition at line 48 of file class.ilTestArchiver.php.

◆ TEST_LOG_FILENAME

const ilTestArchiver::TEST_LOG_FILENAME = 'test.log'

Definition at line 63 of file class.ilTestArchiver.php.

◆ TEST_MATERIALS_PATH_COMPONENT

const ilTestArchiver::TEST_MATERIALS_PATH_COMPONENT = 'materials'

Definition at line 50 of file class.ilTestArchiver.php.

◆ TEST_OVERVIEW_HTML_FILENAME

const ilTestArchiver::TEST_OVERVIEW_HTML_FILENAME = 'results_overview_html_v'

Definition at line 54 of file class.ilTestArchiver.php.

◆ TEST_OVERVIEW_HTML_POSTFIX

const ilTestArchiver::TEST_OVERVIEW_HTML_POSTFIX = '.html'

Definition at line 55 of file class.ilTestArchiver.php.

◆ TEST_RESULT_FILENAME

const ilTestArchiver::TEST_RESULT_FILENAME = 'test_result.html'
protected

Definition at line 52 of file class.ilTestArchiver.php.


The documentation for this class was generated from the following file: