public static function ExtractExerciseFileType($data, $singleResult = false, $FileTypeExtension = '', $isResult = true)
 {
     // generates an assoc array of an exercise file type by using a defined
     // list of its attributes
     $res = DBJson::getResultObjectsByAttributes($data, ExerciseFileType::getDBPrimaryKey(), ExerciseFileType::getDBConvert(), $FileTypeExtension);
     if ($isResult) {
         // to reindex
         $res = array_merge($res);
         $res = ExerciseFileType::decodeExerciseFileType($res, false);
         if ($singleResult == true) {
             // only one object as result
             if (count($res) > 0) {
                 $res = $res[0];
             }
         }
     }
     return $res;
 }
Exemple #2
0
 public static function ExtractExercise($data, $singleResult = false, $ExerciseExtension = '', $AttachmentExtension = '', $SubmissionExtension = '', $FileTypeExtension = '', $isResult = true)
 {
     // generates an assoc array of an exercise by using a defined
     // list of its attributes
     $exercise = DBJson::getObjectsByAttributes($data, Exercise::getDBPrimaryKey(), Exercise::getDBConvert(), $ExerciseExtension);
     // generates an assoc array of files by using a defined
     // list of its attributes
     $attachments = DBJson::getObjectsByAttributes($data, File::getDBPrimaryKey(), File::getDBConvert(), $AttachmentExtension);
     // generates an assoc array of submissions by using a defined
     // list of its attributes
     $submissions = DBJson::getObjectsByAttributes($data, Submission::getDBPrimaryKey(), Submission::getDBConvert(), $SubmissionExtension . '2');
     // generates an assoc array of exercise file types by using a defined
     // list of its attributes
     $fileTypes = DBJson::getObjectsByAttributes($data, ExerciseFileType::getDBPrimaryKey(), ExerciseFileType::getDBConvert(), $FileTypeExtension);
     // sets the selectedForGroup attribute
     foreach ($submissions as &$submission) {
         if (isset($submission['selectedForGroup'])) {
             if (isset($submission['id']) && $submission['id'] == $submission['selectedForGroup']) {
                 $submission['selectedForGroup'] = (string) 1;
             } else {
                 unset($submission['selectedForGroup']);
             }
         }
     }
     // concatenates the exercise and the associated filetypes
     $exercise = DBJson::concatObjectListResult($data, $exercise, Exercise::getDBPrimaryKey(), Exercise::getDBConvert()['E_fileTypes'], $fileTypes, ExerciseFileType::getDBPrimaryKey(), $FileTypeExtension, $ExerciseExtension);
     // concatenates the exercise and the associated attachments
     $res = DBJson::concatObjectListResult($data, $exercise, Exercise::getDBPrimaryKey(), Exercise::getDBConvert()['E_attachments'], $attachments, File::getDBPrimaryKey(), $AttachmentExtension, $ExerciseExtension);
     // concatenates the exercise and the associated submissions
     $res = DBJson::concatObjectLists($data, $res, Exercise::getDBPrimaryKey(), Exercise::getDBConvert()['E_submissions'], $submissions, Submission::getDBPrimaryKey(), $SubmissionExtension . '2', $ExerciseExtension);
     if ($isResult) {
         // to reindex
         $res = array_values($res);
         $res = Exercise::decodeExercise($res, false);
         if ($singleResult) {
             // only one object as result
             if (count($res) > 0) {
                 $res = $res[0];
             }
         }
     }
     return $res;
 }