Exemple #1
0
 /** Get referenced row
  * @param string
  * @return NotORM_Row or null if the row does not exist
  */
 function __get($name)
 {
     $this->result->notORM->__updateRowClass($name);
     $column = $this->result->notORM->structure->getReferencedColumn($name, $this->result->table);
     $referenced =& $this->result->referenced[$name];
     if (!isset($referenced)) {
         $keys = array();
         foreach ($this->result->rows as $row) {
             if ($row[$column] !== null) {
                 $keys[$row[$column]] = null;
             }
         }
         if ($keys) {
             $table = $this->result->notORM->structure->getReferencedTable($name, $this->result->table);
             $referenced = new Result($table, $this->result->notORM);
             $referenced->where("{$table}." . $this->result->notORM->structure->getPrimary($table), array_keys($keys));
         } else {
             $referenced = array();
         }
     }
     if (!isset($referenced[$this[$column]])) {
         // referenced row may not exist
         return null;
     }
     return $referenced[$this[$column]];
 }
 public function delete($id)
 {
     $regno = Result::where('id', $id)->first();
     $data = $regno->regno;
     //        return $data;
     Result::destroy($id);
     return Redirect::to('results')->with('deleted', $data . ' is successFull Deleted from Database');
 }
 public function login()
 {
     $data = Input::all();
     $log = Auth::attempt(array('email' => $data['email'], 'password' => $data['password']));
     if ($log) {
         $search = $data['password'];
         $data = Result::where('regno', $search)->get();
         $count = Count($data);
         return View::make('StudentReport')->with('results', $data);
     } else {
         return Redirect::Route('home')->with('fail', 'Bad combination of username and password');
     }
 }
 public function Report()
 {
     $search = Input::get("search");
     // $data=Student::where('sname',"LIKE",'%'.$search.'%')->with('result')->get();
     $data = Result::where('regno', $search)->get();
     //var_dump($data);
     $size = Count($data);
     if ($size > 0) {
         return View::make("StudentReport")->with('results', $data);
         //return View::make("StudentReport")->with('students',$data);
     } else {
         return Redirect::to('search')->with('empty', 'No data Match with your search index');
     }
 }
 public function gen_calendar()
 {
     $date_start = date('Y-m-d', $_GET['start']);
     $date_end = date('Y-m-d', $_GET['end']);
     $variable = new Result();
     $variable->where("result_type_id", 0)->where("status", 1)->get();
     $day = 24 * 60 * 60 * 1000;
     foreach ($variable as $key => $value) {
         $title = null;
         $color = null;
         switch ($value->deposits) {
             case 1:
                 $color = "#337AB7";
                 break;
             default:
                 $color = "#5cb85c";
                 break;
         }
         $data_[] = array("title" => $value->title, "start" => date("Y-m-d", strtotime($value->import_time)), "url" => "reports/views/" . $value->id, "color" => $color);
     }
     echo json_encode(@$data_);
 }
Exemple #6
0
 /**
  * Delete the question
  *
  * @param $id
  */
 public function deleteAction($id)
 {
     $question = Question::find($id);
     if (is_null($question)) {
         return Redirect::route('tests.index')->with('error', 'Incorrect question id');
     }
     $test = $question->test;
     /**
      * Check if we have results already
      */
     if (count(Result::where('test_id', $test->id)->get())) {
         return Redirect::route('tests.index')->with('error', 'Нельзя редактировать тест, на который есть ответы');
     }
     DB::table('answer')->where('question_id', $id)->delete();
     DB::table('question')->where('id', $id)->delete();
     return Redirect::route('tests.show', $test->id);
 }
Exemple #7
0
 /**
  * Update the test
  *
  * @param $id
  */
 public function updateAction($id)
 {
     $test = Test::find($id);
     if (is_null($test)) {
         return Redirect::route('tests.index')->with('error', 'Incorrect test id');
     }
     $validation = Validator::make(Input::all(), Test::$rules);
     if (!$validation->passes()) {
         return Redirect::route('tests.edit', $id)->withInput()->withErrors($validation)->with('message', 'There were validation errors.');
     }
     $data = Input::all();
     $data['duration'] = $data['duration'] * 60;
     /**
      * Check if we have any answers already
      */
     $results = count(Result::where('test_id', $id)->get());
     if ($results > 0) {
         unset($data['type']);
     }
     /**
      * Check name duplicates
      */
     if (count(Test::where('name', $data['name'])->where('version', $data['version'])->where('id', '!=', $id)->get())) {
         /**
          * This test exists, generate new version
          */
         $data['version'] = $this->getNextVersion($data['name']);
     }
     $test->update($data);
     $test->active = isset($data['active']) && $data['active'];
     $test->save();
     return Redirect::route('tests.show', $id);
 }
Exemple #8
0
 /**
  * Display one result
  *
  * @param $id
  * @param $rid
  */
 public function showAction($id, $rid)
 {
     $test = Test::find($id);
     if (is_null($test)) {
         return Redirect::route('tests.index')->with('error', 'Incorrect test id');
     }
     $single = Result::find($rid);
     if (is_null($single) || $single->test_id != $id) {
         return Redirect::route('tests.index')->with('error', 'Невозможно найти результаты');
     }
     $results = Result::where('test_id', $id)->where('token', $single->token)->orderBy('question_id', 'asc')->get();
     if (!count($results)) {
         return Redirect::route('tests.index')->with('error', 'Отсутствуют результаты теста');
     }
     $score = 0;
     $max = 0;
     foreach ($results as $result) {
         $score += $result->weight;
         if ($max < $result->created_at->format('U')) {
             $max = $result->created_at->format('U');
         }
     }
     $weights = [];
     $tw = 0;
     foreach ($test->questions as $q) {
         $weights[$q->id] = 0;
         foreach ($q->answers as $a) {
             if (!$a->is_correct) {
                 continue;
             }
             $weights[$q->id] += $a->weight;
             $tw += $a->weight;
         }
         if ($q->type == Question::TYPE_STRING) {
             $weights[$q->id] += 1;
             $tw += 1;
         }
     }
     $token = Token::where('token', $result->token)->get();
     $ends = $max - $token[0]->start;
     $min = (int) ($ends / 60);
     $sec = $ends - $min * 60;
     $ends = ($min < 10 ? '0' . $min : $min) . ':' . ($sec < 10 ? '0' . $sec : $sec);
     return View::make('tests.results_show', ['token' => Token::where('token', $single->token)->get()[0], 'test' => $test, 'total_questions' => count($test->questions), 'total_weight' => $tw, 'results' => $results, 'weights' => $weights, 'score' => $score, 'duration' => $ends]);
 }
 public function add_result()
 {
     $requirements = ['exp_id', 'user_id', 'data'];
     $check = self::check_requirements($requirements);
     if ($check) {
         return Error::make(0, 100, $check);
     }
     $experiment = Experiment::where('exp_id', '=', Input::get('exp_id'))->first();
     if (is_null($experiment)) {
         return Error::make(1, 10);
     }
     $user = User::where('user_id', '=', Input::get('user_id'))->first();
     if (is_null($user)) {
         return Error::make(1, 1);
     }
     if (Input::has('result_id')) {
         $res = Result::where('result_id', '=', Input::get('result_id'))->first();
         if (intval(Input::get('exp_id')) != intval($res->exp_id)) {
             return Error::make(1, 11);
         }
         if (intval(Input::get('user_id')) != intval($res->user_id)) {
             return Error::make(1, 12);
         }
     }
     $columns = json_decode($experiment->specifications, true)["columns"];
     $results = json_decode(Input::get('data'), true);
     foreach ($results as $reading) {
         foreach ($columns as $column) {
             if (array_key_exists($column["title"], $reading)) {
                 if (!is_null($column["subcolumns"]) && sizeof($column["subcolumns"]) > 0) {
                     foreach ($column["subcolumns"] as $subcolumn) {
                         if (!array_key_exists($subcolumn["title"], $reading[$column["title"]])) {
                             return Error::make(101, 101, "Column " . $column["title"] . " has missing subcolumn " . $subcolumn["title"]);
                         }
                     }
                 }
             } else {
                 return Error::make(101, 101, "Missing column " . $column["title"]);
             }
         }
     }
     if (Input::has('result_id')) {
         try {
             Result::where('result_id', '=', intval(Input::get('result_id')))->update(array('data' => json_encode($results)));
             return Error::success("Results successfully updated", array('result_id' => intval(Input::get('result_id'))));
         } catch (Exception $e) {
             return Error::make(101, 101, $e->getMessage());
         }
     } else {
         $res = new Result();
         $res->data = json_encode($results);
         $res->user_id = intval(Input::get('user_id'));
         $res->exp_id = intval(Input::get('exp_id'));
         try {
             $res->save();
             return Error::success("Result successfully added!", array('result_id' => $res->id));
         } catch (Exception $e) {
             return Error::make(101, 101, $e->getMessage());
         }
     }
 }
 public function showExam($id)
 {
     $loginid = Session::get('user')->id;
     $collegeid = Session::get('user')->collegeid;
     $flag = Session::get('user')->flag;
     $tb = "";
     if ($flag == 1) {
         $tb = "Admin";
     } else {
         if ($flag == 2) {
             $tb = "Teacher";
         } else {
             if ($flag == 3) {
                 $tb = "Student";
             } else {
                 $tb = "Staff";
             }
         }
     }
     $dt = $tb::where('loginid', '=', $loginid)->first();
     $data['name'] = $dt->name;
     $data['pic'] = $dt->profilepic;
     $data['id'] = $loginid;
     //check for second attempt
     $checkattempt = Result::where('studentloginid', '=', $loginid)->where('attempt', '=', 1)->where('examid', $id)->count();
     if ($checkattempt < 1) {
         $collegeid = Session::get('user')->collegeid;
         $flag = Session::get('user')->flag;
         $tb = "";
         if ($flag == 1) {
             $tb = "Admin";
         } else {
             if ($flag == 2) {
                 $tb = "Teacher";
             } else {
                 if ($flag == 3) {
                     $tb = "Student";
                 } else {
                     $tb = "Staff";
                 }
             }
         }
         $dt = $tb::where('loginid', '=', $loginid)->first();
         $data['name'] = $dt->name;
         $data['pic'] = $dt->profilepic;
         $questions = $this->getExamData($id);
         return View::make('pages.get-exam', array('questions' => $questions, 'data' => $data, 'flag' => $flag));
     } else {
         return "you are ristricted now";
     }
 }
Exemple #11
0
 /**
  * Display question to the user
  *
  * @return mixed
  */
 public function indexAction()
 {
     Assets::reset()->add('main');
     $token = $this->getToken();
     if (!$token) {
         return Redirect::route('base');
     }
     if ($token->status != Token::TOKEN_STATUS_STARTED) {
         return Redirect::route('token.index', ['token' => $token->token]);
     }
     if (!$this->isTokenValid($token)) {
         Session::forget('token_string');
         $token->status = Token::TOKEN_STATUS_EXPIRED;
         $token->save();
         return Redirect::route('info')->with('message', 'Время теста истекло');
     }
     /**
      * get next question
      */
     $questions = $token->test->questions;
     $results = Result::where('token', $token->token)->where('test_id', $token->test->id)->get();
     $has_questions = count($questions);
     $has_results = count($results);
     if (count($results)) {
         if (count($results) == count($questions)) {
             /**
              * User have answered all questions
              */
             Session::forget('token_string');
             return Redirect::route('info')->with('message', 'Тест завершен. Вы ответили на все вопросы.');
         } else {
             /**
              * Ignore answered questions
              */
             $answered = [];
             foreach ($results as $result) {
                 $answered[] = $result->question->id;
             }
             foreach ($questions as $key => $q) {
                 if (in_array($q->id, $answered)) {
                     unset($questions[$key]);
                 }
             }
         }
     }
     /**
      * shuffle questions
      */
     $questions_ = [];
     foreach ($questions as $q) {
         $questions_[] = $q->id;
     }
     shuffle($questions_);
     if ($questionId = Session::get('question_id', false)) {
         $question = Question::find($questionId);
     } else {
         $question = Question::find($questions_[0]);
     }
     $answers_ = $question->answers;
     $answers = [];
     Session::forget('test_answers');
     $ta = [];
     foreach ($answers_ as $key => $answer) {
         $a = $answer->withHash();
         $ta[$answer->id] = $a->hash;
         $answers[] = $a;
     }
     Session::put('test_answers', $ta);
     Session::put('question_id', $question->id);
     shuffle($answers);
     return View::make('test.index', ['question' => $question, 'answers' => $answers, 'token' => $token, 'total' => $has_questions, 'answered' => $has_results]);
 }