예제 #1
0
파일: User.php 프로젝트: sawh/ostepu-system
 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;
 }
예제 #2
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');
 }
예제 #3
0
 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;
 }
예제 #4
0
 /**
  * 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);
     }
 }