public static function ExtractSubmission($data, $singleResult = false, $FileExtension = '', $SubmissionExtension = '', $isResult = true) { // generates an assoc array of files by using a defined list of // its attributes $files = DBJson::getObjectsByAttributes($data, File::getDBPrimaryKey(), File::getDBConvert(), $FileExtension); // generates an assoc array of submissions by using a defined list of // its attributes $submissions = DBJson::getObjectsByAttributes($data, Submission::getDBPrimaryKey(), Submission::getDBConvert(), $SubmissionExtension); // 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 submissions and the associated files $res = DBJson::concatObjectListsSingleResult($data, $submissions, Submission::getDBPrimaryKey(), Submission::getDBConvert()['S_file'], $files, File::getDBPrimaryKey(), $FileExtension, $SubmissionExtension); if ($isResult) { // to reindex $res = array_values($res); $res = Submission::decodeSubmission($res, false); if ($singleResult == true) { // only one object as result if (count($res) > 0) { $res = $res[0]; } } } return $res; }
public static function ExtractSetting($data, $singleResult = false, $SettingExtension = '', $isResult = true) { // generates an assoc array of Settings by using a defined list of // its attributes $res = DBJson::getObjectsByAttributes($data, Setting::getDBPrimaryKey(), Setting::getDBConvert(), $SettingExtension); if ($isResult) { // to reindex $res = array_values($res); $res = Setting::decodeSetting($res, false); if ($singleResult == true) { // only one object as result if (count($res) > 0) { $res = $res[0]; } } } return $res; }
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; }
public static function ExtractCourseStatus($data, $singleResult = false, $UserExtension = '', $CourseStatusExtension = '', $CourseExtension = '', $isResult = true) { // generates an assoc array of a user by using a defined list of its // attributes $user = DBJson::getObjectsByAttributes($data, User::getDBPrimaryKey(), User::getDBConvert(), $UserExtension); // generates an assoc array of course stats by using a defined list of // its attributes $courseStatus = DBJson::getObjectsByAttributes($data, CourseStatus::getDBPrimaryKey(), CourseStatus::getDBConvert(), $CourseStatusExtension); // generates an assoc array of courses by using a defined list of // its attributes $courses = DBJson::getObjectsByAttributes($data, Course::getDBPrimaryKey(), Course::getDBConvert(), $CourseExtension); // concatenates the course stats and the associated courses $res = DBJson::concatObjectListsSingleResult($data, $courseStatus, CourseStatus::getDBPrimaryKey(), CourseStatus::getDBConvert()['CS_course'], $courses, Course::getDBPrimaryKey(), $CourseExtension, $CourseStatusExtension); // concatenates the users and the associated course stats $res = DBJson::concatResultObjectLists($data, $user, User::getDBPrimaryKey(), User::getDBConvert()['U_courses'], $res, CourseStatus::getDBPrimaryKey(), $CourseStatusExtension, $UserExtension); if ($isResult) { // to reindex // $res = array_merge($res); $res = CourseStatus::decodeCourseStatus($res, false); if ($singleResult == true) { // only one object as result if (count($res) > 0) { $res = $res[0]; } } } return $res; }
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; }
public static function ExtractInvitation($data, $singleResult = false, $LeaderExtension = '', $MemberExtension = '', $InvitationExtension = '', $isResult = true) { // generates an assoc array of users by using a defined list of // its attributes $leader = DBJson::getObjectsByAttributes($data, User::getDBPrimaryKey(), User::getDBConvert(), $LeaderExtension); // generates an assoc array of users by using a defined list of // its attributes $member = DBJson::getObjectsByAttributes($data, User::getDBPrimaryKey(), User::getDBConvert(), $MemberExtension . '2'); // generates an assoc array of invitations by using a defined list of // its attributes $invitations = DBJson::getObjectsByAttributes($data, Invitation::getDBPrimaryKey(), Invitation::getDBConvert(), $InvitationExtension); // concatenates the invitations and the associated invitation leader $res = DBJson::concatObjectListsSingleResult($data, $invitations, Invitation::getDBPrimaryKey(), Invitation::getDBConvert()['U_leader'], $leader, User::getDBPrimaryKey(), $InvitationExtension, $LeaderExtension); // concatenates the invitations and the associated invitation member $res = DBJson::concatObjectListsSingleResult($data, $res, Invitation::getDBPrimaryKey(), Invitation::getDBConvert()['U_member'], $member, User::getDBPrimaryKey(), $MemberExtension . '2', $InvitationExtension); if ($isResult) { // to reindex $res = array_values($res); $res = Invitation::decodeInvitation($res, false); if ($singleResult == true) { // only one object as result if (count($res) > 0) { $res = $res[0]; } } } return $res; }
public static function ExtractGroup($data, $singleResult = false, $LeaderExtension = '', $MemberExtension = '', $GroupExtension = '', $isResult = true) { // generates an assoc array of an user by using a defined list of // its attributes $leader = DBJson::getObjectsByAttributes($data, User::getDBPrimaryKey(), User::getDBConvert(), $LeaderExtension); // generates an assoc array of users by using a defined list of // its attributes $member = DBJson::getObjectsByAttributes($data, User::getDBPrimaryKey(), User::getDBConvert(), $MemberExtension . '2'); // generates an assoc array of groups by using a defined list of // its attributes $groups = DBJson::getObjectsByAttributes($data, Group::getDBPrimaryKey(), Group::getDBConvert(), $GroupExtension); // concatenates the groups and the associated group leader $res = DBJson::concatObjectListsSingleResult($data, $groups, Group::getDBPrimaryKey(), Group::getDBConvert()['U_leader'], $leader, User::getDBPrimaryKey(), $LeaderExtension, $GroupExtension); // concatenates the groups and the associated group member $res = DBJson::concatResultObjectLists($data, $res, Group::getDBPrimaryKey(), Group::getDBConvert()['U_member'], $member, User::getDBPrimaryKey(), $MemberExtension . '2', $GroupExtension); if ($isResult) { // to reindex $res = array_merge($res); $res = Group::decodeGroup($res, false); if ($singleResult == true) { // only one object as result if (count($res) > 0) { $res = $res[0]; } } } return $res; }
public static function ExtractAttachment($data, $singleResult = false, $FileExtension = '', $AttachmentExtension = '', $isResult = true) { // generates an assoc array of files by using a defined list of // its attributes $files = DBJson::getObjectsByAttributes($data, File::getDBPrimaryKey(), File::getDBConvert(), $FileExtension); // generates an assoc array of attachments by using a defined list of // its attributes $attachments = DBJson::getObjectsByAttributes($data, Attachment::getDBPrimaryKey(), Attachment::getDBConvert(), $AttachmentExtension); // concatenates the attachments and the associated files $res = DBJson::concatObjectListsSingleResult($data, $attachments, Attachment::getDBPrimaryKey(), Attachment::getDBConvert()['F_file'], $files, File::getDBPrimaryKey(), $FileExtension, $AttachmentExtension); if ($isResult) { // to reindex $res = array_values($res); $res = Attachment::decodeAttachment($res, false); if ($singleResult == true) { // only one object as result if (count($res) > 0) { $res = $res[0]; } } } return $res; }
public static function ExtractForm($data, $singleResult = false, $FormsExtension = '', $ChoiceExtension = '', $isResult = true) { // generates an assoc array of an forms by using a defined // list of its attributes $forms = DBJson::getObjectsByAttributes($data, Form::getDBPrimaryKey(), Form::getDBConvert(), $FormsExtension); // generates an assoc array of choices by using a defined // list of its attributes $choices = DBJson::getObjectsByAttributes($data, Choice::getDBPrimaryKey(), Choice::getDBConvert(), $ChoiceExtension); // concatenates the forms and the associated choices $res = DBJson::concatObjectListResult($data, $forms, Form::getDBPrimaryKey(), Form::getDBConvert()['FO_choices'], $choices, Choice::getDBPrimaryKey(), $ChoiceExtension, $FormsExtension); if ($isResult) { // to reindex $res = array_values($res); $res = Form::decodeForm($res, false); if ($singleResult) { // only one object as result if (count($res) > 0) { $res = $res[0]; } } } return $res; }
/** * Initializes all components, with the data, which can be found in database. */ public function sendComponentDefinitions() { $this->_app->response->setStatus(200); // starts a query ob_start(); eval("?>" . file_get_contents(dirname(__FILE__) . '/Sql/GetComponentDefinitions.sql')); $sql = ob_get_contents(); ob_end_clean(); $result = DBRequest::request($sql, false, parse_ini_file(dirname(__FILE__) . '/config.ini', TRUE)); // checks the correctness of the query if ((!isset($result['errno']) || !$result['errno']) && $result['content']) { $data = DBJson::getRows($result['content']); $Components = DBJson::getObjectsByAttributes($data, Component::getDBPrimaryKey(), Component::getDBConvert()); $Links = DBJson::getObjectsByAttributes($data, Link::getDBPrimaryKey(), Link::getDBConvert()); $objects = DBJson::concatResultObjectLists($data, $Components, Component::getDBPrimaryKey(), Component::getDBConvert()['CO_links'], $Links, Link::getDBPrimaryKey()); $request = new Request_MultiRequest(); $data = parse_ini_file(dirname(__FILE__) . '/config.ini', TRUE); $tempObjects = array(); foreach ($objects as $object) { $object = Component::decodeComponent(json_encode($object)); // prüfen, welche Komponente auf diesem Server ist if (strpos($object->getAddress() . '/', $data['PL']['urlExtern'] . '/') === false) { continue; } $object->setAddress($data['PL']['url'] . substr($object->getAddress(), strlen($data['PL']['urlExtern']))); $links = $object->getLinks(); foreach ($links as &$link) { if (strpos($link->getAddress() . '/', $data['PL']['urlExtern'] . '/') === false) { continue; } $link->setAddress($data['PL']['url'] . substr($link->getAddress(), strlen($data['PL']['urlExtern']))); } $object->setLinks($links); $result = Request_CreateRequest::createPost($object->getAddress() . '/control', array(), Component::encodeComponent($object)); $tempObjects[] = $object; $request->addRequest($result); } $results = $request->run(); $objects = $tempObjects; $i = 0; $res = array(); foreach ($objects as $object) { $object = Component::decodeComponent(Component::encodeComponent($object)); $result = $results[$i++]; $newObject = new Component(); $newObject->setId($object->getId()); $newObject->setName($object->getName()); $newObject->setAddress($object->getAddress()); $newObject->setDef($object->getDef()); $newObject->setStatus($result['status']); $res[] = $newObject; if ($result['status'] != 201) { $add = ''; $this->_app->response->setStatus(409); if (isset($result['content'])) { $add = $result['content']; } Logger::Log($result['status'] . '--' . $object->getName() . '--' . $object->getAddress() . "\n" . $add . "\n", LogLevel::ERROR); } } $this->_app->response->setBody(json_encode($res)); } else { Logger::Log('GET SendComponentDefinitions failed', LogLevel::ERROR); $this->_app->response->setStatus(isset($result['status']) ? $result['status'] : 409); } }
public static function ExtractProcess($data, $singleResult = false, $ProcessExtension = '', $ComponentExtension = '', $ExerciseExtension = '', $isResult = true) { // generates an assoc array of processes by using a defined list of // its attributes $process = DBJson::getObjectsByAttributes($data, Process::getDBPrimaryKey(), Process::getDBConvert(), $ProcessExtension); // generates an assoc array of components by using a defined // list of its attributes $component = DBJson::getObjectsByAttributes($data, Component::getDBPrimaryKey(), Component::getDBConvert(), $ComponentExtension); // generates an assoc array of exercises by using a defined // list of its attributes $exercise = DBJson::getObjectsByAttributes($data, Exercise::getDBPrimaryKey(), Exercise::getDBConvert(), $ExerciseExtension); $attachment = Attachment::extractAttachment($data, false, '_PRO1', '_PRO1', false); $workFiles = Attachment::extractAttachment($data, false, '_PRO2', '_PRO2', false); // concatenates the processes and the associated attachments $process = DBJson::concatObjectListResult($data, $process, Process::getDBPrimaryKey(), Process::getDBConvert()['A_attachment'], $attachment, Attachment::getDBPrimaryKey(), '_PRO1', $ProcessExtension); // concatenates the processes and the associated attachments $process = DBJson::concatObjectListResult($data, $process, Process::getDBPrimaryKey(), Process::getDBConvert()['A_workFiles'], $workFiles, Attachment::getDBPrimaryKey(), '_PRO2', $ProcessExtension); // concatenates the processes and the associated components $process = DBJson::concatObjectListsSingleResult($data, $process, Process::getDBPrimaryKey(), Process::getDBConvert()['E_exercise'], $exercise, Exercise::getDBPrimaryKey(), $ExerciseExtension, $ProcessExtension); $res = DBJson::concatObjectListsSingleResult($data, $process, Process::getDBPrimaryKey(), Process::getDBConvert()['CO_target'], $component, Component::getDBPrimaryKey(), $ComponentExtension, $ProcessExtension); if ($isResult) { // to reindex $res = array_values($res); $res = Process::decodeProcess($res, false); if ($singleResult == true) { // only one object as result if (count($res) > 0) { $res = $res[0]; } } } return $res; }
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; }
public static function ExtractExternalId($data, $singleResult = false, $CourseExtension = '', $ExternalIdExtension = '', $isResult = true) { // generates an assoc array of courses by using a defined list of // its attributes $course = DBJson::getObjectsByAttributes($data, Course::getDBPrimaryKey(), Course::getDBConvert(), $CourseExtension); // generates an assoc array of external IDs by using a defined list of // its attributes $externalIds = DBJson::getObjectsByAttributes($data, ExternalId::getDBPrimaryKey(), ExternalId::getDBConvert(), $ExternalIdExtension); // concatenates the external IDs and the associated courses $res = DBJson::concatObjectListsSingleResult($data, $externalIds, ExternalId::getDBPrimaryKey(), ExternalId::getDBConvert()['EX_course'], $course, Course::getDBPrimaryKey(), $CourseExtension, $ExternalIdExtension); if ($isResult) { // to reindex $res = array_values($res); $res = ExternalId::decodeExternalId($res, false); if ($singleResult == true) { // only one object as result if (count($res) > 0) { $res = $res[0]; } } } return $res; }