Ejemplo n.º 1
0
 public static function ExtractCourse($data, $singleResult = false, $CourseExtension = '', $SheetExtension = '', $isResult = true)
 {
     // generates an assoc array of courses by using a defined list of
     // its attributes
     $courses = DBJson::getObjectsByAttributes($data, Course::getDBPrimaryKey(), Course::getDBConvert(), $CourseExtension);
     // generates an assoc array of settings by using a defined list of
     // its attributes
     $settings = DBJson::getObjectsByAttributes($data, Setting::getDBPrimaryKey(), Setting::getDBConvert());
     // generates an assoc array of exercise sheets by using a defined list of
     // its attributes
     $exerciseSheets = DBJson::getObjectsByAttributes($data, ExerciseSheet::getDBPrimaryKey(), array(ExerciseSheet::getDBPrimaryKey() => ExerciseSheet::getDBConvert()[ExerciseSheet::getDBPrimaryKey()]), $SheetExtension);
     // concatenates the courses and the associated settings
     $res = DBJson::concatObjectListResult($data, $courses, Course::getDBPrimaryKey(), Course::getDBConvert()['C_settings'], $settings, Setting::getDBPrimaryKey());
     // concatenates the courses and the associated exercise sheet IDs
     $res = DBJson::concatResultObjectListAsArray($data, $res, Course::getDBPrimaryKey(), Course::getDBConvert()['C_exerciseSheets'], $exerciseSheets, ExerciseSheet::getDBPrimaryKey(), $SheetExtension, $CourseExtension);
     if ($isResult) {
         $res = Course::decodeCourse($res, false);
         if ($singleResult == true) {
             // only one object as result
             if (count($res) > 0) {
                 $res = $res[0];
             }
         }
     }
     return $res;
 }
Ejemplo n.º 2
0
 public static function ExtractExerciseSheet($data, $singleResult = false, $SheetExtension = '', $SheetFileExtension = '', $SheetSolutionExtension = '', $isResult = true)
 {
     // generates an assoc array of an exercise sheet by using a defined list of its attributes
     $exerciseSheet = DBJson::getObjectsByAttributes($data, ExerciseSheet::getDBPrimaryKey(), ExerciseSheet::getDBConvert(), $SheetExtension);
     // generates an assoc array of an file by using a defined list of its attributes
     $exerciseSheetFile = DBJson::getObjectsByAttributes($data, File::getDBPrimaryKey(), File::getDBConvert(), $SheetFileExtension);
     // generates an assoc array of an file by using a defined list of its attributes
     $sampleSolutions = DBJson::getObjectsByAttributes($data, File::getDBPrimaryKey(), File::getDBConvert(), $SheetSolutionExtension . '2');
     // concatenates the exercise sheet and the associated sample solution
     $res = DBJson::concatObjectListsSingleResult($data, $exerciseSheet, ExerciseSheet::getDBPrimaryKey(), ExerciseSheet::getDBConvert()['F_id_file'], $exerciseSheetFile, File::getDBPrimaryKey(), $SheetFileExtension, $SheetExtension);
     // concatenates the exercise sheet and the associated exercise sheet file
     $res = DBJson::concatObjectListsSingleResult($data, $res, ExerciseSheet::getDBPrimaryKey(), ExerciseSheet::getDBConvert()['F_id_sampleSolution'], $sampleSolutions, File::getDBPrimaryKey(), $SheetSolutionExtension . '2', $SheetExtension);
     if ($isResult) {
         // to reindex
         $res = array_merge($res);
         $res = ExerciseSheet::decodeExerciseSheet($res, false);
         if ($singleResult == true) {
             // only one object as result
             if (count($res) > 0) {
                 $res = $res[0];
             }
         }
     }
     return $res;
 }
Ejemplo n.º 3
0
 public function getCourseSheets($callName, $input, $params = array())
 {
     $getSheets = function ($input, $courseid, $exercise = null) {
         $getExercises = function ($input, $sheet) {
             $result = Model::isEmpty();
             $result['content'] = array();
             $data = array();
             foreach ($input as $inp) {
                 if ($inp->getNumRows() > 0) {
                     // extract Course data from db answer
                     $result['content'] = Exercise::ExtractExercise($inp->getResponse(), false, '', '', '', '', false);
                     $data = array_merge($data, $inp->getResponse());
                     $result['status'] = 200;
                 }
             }
             $result['content'] = DBJson::concatResultObjectLists($data, $sheet, ExerciseSheet::getDBPrimaryKey(), ExerciseSheet::getDBConvert()['ES_exercises'], $result['content'], Exercise::getDBPrimaryKey());
             $result['content'] = array_merge($result['content']);
             return self::finalizeSheets($result);
         };
         $result = Model::isEmpty();
         $result['content'] = array();
         foreach ($input as $inp) {
             if ($inp->getNumRows() > 0) {
                 $result['content'] = ExerciseSheet::ExtractExerciseSheet($inp->getResponse(), false, '', '', '', $exercise !== null ? false : true);
                 $result['status'] = 200;
             }
         }
         if ($exercise === null) {
             return self::finalizeSheets($result);
         }
         return $this->_component->call('getCourseExercises', array("courseid" => $courseid), '', 200, $getExercises, array("sheet" => $result['content']), 'Model::isProblem', array(), 'Query');
     };
     $params = DBJson::mysql_real_escape_string($params);
     return $this->_component->call('getCourseSheets', $params, '', 200, $getSheets, $params, 'Model::isProblem', array(), 'Query');
 }