Beispiel #1
0
Language::loadLanguageFile('de', $langTemplate, 'json', dirname(__FILE__) . '/');
// load user data from the database
$databaseURI = $databaseURI . "/user/user/{$uid}";
$user = http_get($databaseURI, false);
$user = json_decode($user, true);
if (is_null($user)) {
    $user = array();
}
$menu = MakeNavigationElement($user, PRIVILEGE_LEVEL::STUDENT, true, true);
// construct a new header
$h = Template::WithTemplateFile('include/Header/Header.template.html');
$h->bind($user);
$h->bind(array("name" => Language::Get('main', 'title', $langTemplate), "hideBackLink" => "true", "notificationElements" => $notifications, "navigationElement" => $menu));
// sort courses by semester
if (isset($user['courses']) && is_array($user['courses'])) {
    foreach ($user['courses'] as &$course) {
        $course['semesterInt'] = substr($course['course']['semester'], -4) * 2;
        if (substr($course['course']['semester'], 0, 2) == 'WS') {
            $course['semesterInt']--;
        }
    }
    $user['courses'] = LArraySorter::orderBy($user['courses'], 'semesterInt', SORT_DESC, 'name', SORT_ASC);
}
$pageData = array('uid' => isset($user['id']) ? $user['id'] : null, 'courses' => isset($user['courses']) ? $user['courses'] : null, 'sites' => PRIVILEGE_LEVEL::$SITES, 'statusName' => PRIVILEGE_LEVEL::$NAMES);
// construct a login element
$courseSelect = Template::WithTemplateFile('include/CourseSelect/CourseSelect.template.html');
$courseSelect->bind($pageData);
// wrap all the elements in some HTML and show them on the page
$w = new HTMLWrapper($h, $courseSelect);
$w->set_config_file('include/configs/config_default.json');
$w->show();
}
// load CourseManagement data from GetSite
$URI = $getSiteURI . "/coursemanagement/user/{$uid}/course/{$cid}";
$courseManagement_data = http_get($URI, true);
$courseManagement_data = json_decode($courseManagement_data, true);
$dataList = array();
foreach ($courseManagement_data['users'] as $key => $user) {
    $dataList[] = array('pos' => $key, 'userName' => $user['userName'], 'lastName' => $user['lastName'], 'firstName' => $user['firstName']);
}
$sortTypes = array('lastName', 'firstName', 'userName');
if (!isset($_POST['sortUsers'])) {
    $_POST['sortUsers'] = null;
}
$_POST['sortUsers'] = in_array($_POST['sortUsers'], $sortTypes) ? $_POST['sortUsers'] : $sortTypes[0];
$sortTypes = array('lastName', 'firstName', 'userName');
$dataList = LArraySorter::orderby($dataList, $_POST['sortUsers'], SORT_ASC, $sortTypes[(array_search($_POST['sortUsers'], $sortTypes) + 1) % count($sortTypes)], SORT_ASC);
$tempData = array();
foreach ($dataList as $data) {
    $tempData[] = $courseManagement_data['users'][$data['pos']];
}
$courseManagement_data['users'] = $tempData;
if (isset($_POST['sortUsers'])) {
    $courseManagement_data['sortUsers'] = $_POST['sortUsers'];
}
$user_course_data = $courseManagement_data['user'];
$menu = MakeNavigationElement($user_course_data, PRIVILEGE_LEVEL::ADMIN, true);
// load externalId data
$URI = $serverURI . "/DB/DBExternalId/externalid/course/{$cid}";
$externalid_data = array();
$externalid_data['externalId'] = http_get($URI, true);
$externalid_data['externalId'] = json_decode($externalid_data['externalId'], true);
Beispiel #3
0
 public static function finalizeSheets($result)
 {
     $result['content'] = LArraySorter::orderBy($result['content'], 'startDate', SORT_ASC, 'id', SORT_ASC);
     // sets the sheet names
     $id = 1;
     reset($result['content']);
     $isArray = true;
     if (gettype(current($result['content'])) == 'object') {
         $isArray = false;
     }
     foreach ($result['content'] as &$sheet) {
         if ($isArray) {
             if (!isset($sheet['sheetName']) || $sheet['sheetName'] == null) {
                 $sheet['sheetName'] = 'Serie ' . (string) $id;
                 $id++;
             }
         } else {
             if ($sheet->getSheetName() == null) {
                 $sheet->setSheetName('Serie ' . (string) $id);
                 $id++;
             }
         }
     }
     return $result;
 }
</a>
        </div>
    </div>

    <div class="content-body-wrapper">
        <div class="content-body left">
            <ol class="full-width-list lower-alpha">
            
            <?php 
if (isset($exercises)) {
    foreach ($exercises as $key => $exercise) {
        if (!isset($exercise['id'])) {
            $exercises[$key]['id'] = null;
        }
    }
    $exercises = LArraySorter::orderBy($exercises, 'linkName', SORT_ASC);
    foreach ($exercises as $key => $exercise) {
        $subtask = Template::WithTemplateFile('include/CreateSheet/Subtask.template.php');
        $subtask->bind($exercise);
        if (isset($forms)) {
            $exerciseForms = array();
            foreach ($forms as $form) {
                if (!isset($form['exerciseId'])) {
                    continue;
                }
                if ($form['exerciseId'] == $exercise['id']) {
                    $exerciseForms[] = $form;
                }
            }
            if (!empty($exerciseForms)) {
                $subtask->bind(array('forms' => $exerciseForms));
Beispiel #5
0
 /**
  * Returns an exercise sheet with exercises.
  *
  * Called when this component receives an HTTP GET request to
  * /exercisesheet/exercisesheet/$sheetid(/).
  *
  * @param int $sheetid The id of the exercise sheet that should be returned.
  */
 public function getExerciseSheetCourseExercise($courseid)
 {
     $sheetanswer = Request::routeRequest('GET', '/exercisesheet/course/' . $courseid . '/exercise', array(), '', $this->_getExerciseSheet, 'exercisesheet');
     if ($sheetanswer['status'] == 200) {
         $body['sampleSolution'] = json_decode($sheetanswer['content'], true);
         $sheets = json_decode($sheetanswer['content'], true);
         // latest sheets on top
         if (is_array($sheets)) {
             $sheets = LArraySorter::reverse($sheets);
             // sort exercises by link = exerercises and linkName = subexercise ascendingly
             foreach ($sheets as &$sheet) {
                 if (isset($sheet['exercises']) && is_array($sheet['exercises'])) {
                     $sheet['exercises'] = LArraySorter::orderBy($sheet['exercises'], 'link', SORT_ASC, 'linkName', SORT_ASC);
                 }
             }
         }
         $sheets = json_encode($sheets);
         $this->app->response->setBody($sheets);
         $this->app->response->setStatus(200);
     } else {
         $this->app->response->setStatus(409);
     }
 }
Beispiel #6
0
 /**
  * Function that handles all requests for marking tool.
  * Used by the functions that are called by Slim when data for the marking
  * tool is requested
  *
  * @author Florian Lücke
  */
 public function markingToolBase($userid, $courseid, $sheetid, $tutorid, $statusid, $shouldfilter, $selector)
 {
     $response = array();
     //Get neccessary data
     $URL = "{$this->lURL}/exercisesheet/course/{$courseid}/exercise";
     $handler1 = Request_CreateRequest::createGet($URL, array(), '');
     $URL = "{$this->_getMarking->getAddress()}/marking/exercisesheet/{$sheetid}";
     $handler2 = Request_CreateRequest::createGet($URL, array(), '');
     $URL = "{$this->_getUser->getAddress()}/user/course/{$courseid}/status/1";
     $handler3 = Request_CreateRequest::createGet($URL, array(), '');
     $URL = "{$this->_getGroup->getAddress()}/group/exercisesheet/{$sheetid}";
     $handler4 = Request_CreateRequest::createGet($URL, array(), '');
     $URL = "{$this->_getSubmission->getAddress()}/submission/exercisesheet/{$sheetid}/selected";
     $handler5 = Request_CreateRequest::createGet($URL, array(), '');
     $URL = $this->_getExerciseType->getAddress() . '/exercisetype';
     $handler6 = Request_CreateRequest::createGet($URL, array(), '');
     $URL = "{$this->_getUser->getAddress()}/user/course/{$courseid}/status/2";
     $handler7 = Request_CreateRequest::createGet($URL, array(), '');
     $URL = "{$this->_getUser->getAddress()}/user/course/{$courseid}/status/3";
     $handler8 = Request_CreateRequest::createGet($URL, array(), '');
     $multiRequestHandle = new Request_MultiRequest();
     $multiRequestHandle->addRequest($handler1);
     $multiRequestHandle->addRequest($handler2);
     $multiRequestHandle->addRequest($handler3);
     $multiRequestHandle->addRequest($handler4);
     $multiRequestHandle->addRequest($handler5);
     $multiRequestHandle->addRequest($handler6);
     $multiRequestHandle->addRequest($handler7);
     $multiRequestHandle->addRequest($handler8);
     $answer = $multiRequestHandle->run();
     $sheets = json_decode($answer[0]['content'], true);
     $markings = json_decode($answer[1]['content'], true);
     $tutors = json_decode($answer[2]['content'], true);
     $groups = json_decode($answer[3]['content'], true);
     $submissions = json_decode($answer[4]['content'], true);
     $possibleExerciseTypes = json_decode($answer[5]['content'], true);
     $tutors = array_merge($tutors, json_decode($answer[6]['content'], true));
     $tutors = array_merge($tutors, json_decode($answer[7]['content'], true));
     // order exercise types by id
     $exerciseTypes = array();
     foreach ($possibleExerciseTypes as $exerciseType) {
         $exerciseTypes[$exerciseType['id']] = $exerciseType;
     }
     $namesOfExercises = array();
     // find the current sheet and it's exercises
     foreach ($sheets as &$sheet) {
         $thisSheetId = $sheet['id'];
         if ($thisSheetId == $sheetid) {
             $thisExerciseSheet = $sheet;
             // create exercise names
             //an array to descripe the subtasks
             $alphabet = range('a', 'z');
             $count = 0;
             $count = null;
             if (isset($sheet['exercises'])) {
                 $exercises = $sheet['exercises'];
                 foreach ($exercises as $key => $exercise) {
                     $exerciseId = $exercise['id'];
                     if ($count === null || $exercises[$count]['link'] != $exercise['link']) {
                         $count = $key;
                         $namesOfExercises[$exerciseId] = $exercise['link'];
                         $subtask = 0;
                     } else {
                         $subtask++;
                         $namesOfExercises[$exerciseId] = $exercise['link'] . $alphabet[$subtask];
                         $namesOfExercises[$exercises[$count]['id']] = $exercises[$count]['link'] . $alphabet[0];
                     }
                 }
             }
         }
         unset($sheet['exercises']);
     }
     if (isset($thisExerciseSheet) == false) {
         $this->app->halt(404, '{"code":404,reason":"invalid sheet id"}');
     }
     // save the index of each exercise and add exercise type name
     $exercises = array();
     $exerciseIndices = array();
     foreach ($thisExerciseSheet['exercises'] as $idx => $exercise) {
         $exerciseId = $exercise['id'];
         $typeId = $exercise['type'];
         if (isset($exerciseTypes[$typeId])) {
             $type = $exerciseTypes[$typeId];
             $exercise['typeName'] = $type['name'];
         } else {
             $exercise['typeName'] = "unknown";
         }
         $exerciseIndices[$exerciseId] = $idx;
         $exercises[] = $exercise;
     }
     // save a reference to each user's group and add exercises to each group
     $userGroups = array();
     foreach ($groups as &$group) {
         $leaderId = $group['leader']['id'];
         $userGroups[$leaderId] =& $group;
         if (isset($group['members'])) {
             foreach ($group['members'] as $member) {
                 $memberId = $member['id'];
                 $userGroups[$memberId] =& $group;
             }
         }
         $group['exercises'] = $exercises;
     }
     foreach ($markings as $key => $marking) {
         $markings[$key]['submissionId'] = $markings[$key]['submission']['id'];
     }
     foreach ($submissions as $submission) {
         $studentId = $submission['studentId'];
         $exerciseId = $submission['exerciseId'];
         $exerciseIndex = $exerciseIndices[$exerciseId];
         $group =& $userGroups[$studentId];
         $group['exercises'][$exerciseIndex]['submission'] = $submission;
     }
     $filteredGroups = array();
     foreach ($submissions as $submission) {
         $marking = LArraySorter::multidimensional_search($markings, array('submissionId' => $submission['id']));
         if ($marking !== false) {
             unset($markings[$marking]['submission']);
             $submission['marking'] = $markings[$marking];
         }
         // filter out markings by the tutor with id $tutorid
         if ($shouldfilter == false || $selector($submission, $tutorid, $statusid)) {
             //echo json_encode($submission);
             $exerciseId = $submission['exerciseId'];
             $exerciseIndex = $exerciseIndices[$exerciseId];
             $studentId = $submission['studentId'];
             // assign the submission to its group
             $group =& $userGroups[$studentId];
             $groupExercises =& $group['exercises'];
             $groupExercises[$exerciseIndex]['submission'] = $submission;
             $leaderId =& $group['leader']['id'];
             $filteredGroups[$leaderId] =& $group;
         } else {
             $exerciseId = $submission['exerciseId'];
             $exerciseIndex = $exerciseIndices[$exerciseId];
             $studentId = $submission['studentId'];
             $group =& $userGroups[$studentId];
             $groupExercises =& $group['exercises'];
             unset($groupExercises[$exerciseIndex]);
         }
     }
     if ($statusid === '0') {
         // remove groups with submissions
         $tempGroups = array();
         foreach ($groups as $key => $group) {
             $temp2Groups = array();
             foreach ($group['exercises'] as $key2 => $exercise) {
                 if (!isset($exercise['submission']) || isset($exercise['submission']['marking']['status']) && $exercise['submission']['marking']['status'] === '0') {
                     $temp2Groups[] = $exercise;
                 }
             }
             if (!empty($temp2Groups)) {
                 $group['exercises'] = $temp2Groups;
                 $tempGroups[] = $group;
             }
         }
         $groups = $tempGroups;
     }
     $response['groups'] = $shouldfilter == true && $statusid !== '0' ? array_values($filteredGroups) : $groups;
     $response['tutors'] = $tutors;
     $response['exerciseSheets'] = $sheets;
     $response['markingStatus'] = Marking::getStatusDefinition();
     $response['namesOfExercises'] = $namesOfExercises;
     $this->flag = 1;
     $response['user'] = $this->userWithCourse($userid, $courseid);
     $this->app->response->setBody(json_encode($response));
 }