public function get_student_test_queue($task_set_id, $student_id) { $task_set = new Task_set(); $task_set->get_by_id((int) $task_set_id); $student = new Student(); $student->get_by_id((int) $student_id); $test_queue = new Test_queue(); if ($task_set->exists() && $student->exists()) { $max_allowed_to_enqueue = (int) $this->config->item('test_maximum_enqueued_pe_student'); if ($max_allowed_to_enqueue <= 0) { $max_allowed_to_enqueue = 1; } $test_status_0 = new Test(); $test_status_0->select_func('COUNT', array('@id'), 'tests_count'); $test_status_0->where_related('test_queue', 'id', '${parent}.id'); $test_queue_status_0 = new Test_queue(); $test_queue_status_0->select('*'); $test_queue_status_0->select_subquery($test_status_0, 'tests_count'); $test_queue_status_0->where_related($task_set); $test_queue_status_0->where_related($student); $test_queue_status_0->where('status', 0); $test_queue_status_0->order_by('status', 'desc'); $test_queue_status_0->order_by('finish', 'desc'); $test_queue_status_0->order_by('start', 'asc'); $test_status_1 = new Test(); $test_status_1->select_func('COUNT', array('@id'), 'tests_count'); $test_status_1->where_related('test_queue', 'id', '${parent}.id'); $test_queue_status_1 = new Test_queue(); $test_queue_status_1->select('*'); $test_queue_status_1->select_subquery($test_status_1, 'tests_count'); $test_queue_status_1->where_related($task_set); $test_queue_status_1->where_related($student); $test_queue_status_1->where('status', 1); $test_queue_status_1->order_by('status', 'desc'); $test_queue_status_1->order_by('finish', 'desc'); $test_queue_status_1->order_by('start', 'asc'); $test_status_2 = new Test(); $test_status_2->select_func('COUNT', array('@id'), 'tests_count'); $test_status_2->where_related('test_queue', 'id', '${parent}.id'); $test_queue_status_2 = new Test_queue(); $test_queue_status_2->select('*'); $test_queue_status_2->select_subquery($test_status_2, 'tests_count'); $test_queue_status_2->where_related($task_set); $test_queue_status_2->where_related($student); $test_queue_status_2->where('status', 2); $test_queue_status_2->order_by('status', 'desc'); $test_queue_status_2->order_by('finish', 'desc'); $test_queue_status_2->order_by('start', 'asc'); $test_queue_status_2->limit($max_allowed_to_enqueue * 2); $test_status_3 = new Test(); $test_status_3->select_func('COUNT', array('@id'), 'tests_count'); $test_status_3->where_related('test_queue', 'id', '${parent}.id'); $test_queue_status_3 = new Test_queue(); $test_queue_status_3->select('*'); $test_queue_status_3->select_subquery($test_status_3, 'tests_count'); $test_queue_status_3->where_related($task_set); $test_queue_status_3->where_related($student); $test_queue_status_3->where('status', 3); $test_queue_status_3->order_by('status', 'desc'); $test_queue_status_3->order_by('finish', 'desc'); $test_queue_status_3->order_by('start', 'asc'); $test_queue_status_3->limit($max_allowed_to_enqueue * 2); $test_queue_status_0->union_iterated(array($test_queue_status_1, $test_queue_status_2, $test_queue_status_3)); $test_queue = $test_queue_status_0; } //$test_queue->check_last_query(); $this->load->helper('tests'); $test_types = get_all_supported_test_types(); $this->parser->parse('backend/tests/get_student_test_queue.tpl', array('test_queue' => $test_queue, 'task_set' => $task_set, 'student' => $student, 'test_types' => $test_types)); }
public function reset_all() { echo 'Reseting old tests that may be freezed.' . PHP_EOL; $this->db->query('SET SESSION TRANSACTION ISOLATION LEVEL SERIALIZABLE;'); $this->db->trans_start(); $test_queue = new Test_queue(); $test_queue->where('status', 1); $test_queue->get_iterated(); if ($test_queue->result_count() > 0) { echo 'Found ' . $test_queue->result_count() . ' old tests.' . PHP_EOL; foreach ($test_queue as $single_test) { $tests = $single_test->test->get_iterated(); foreach ($tests as $test) { $set = array('result' => 0, 'result_text' => NULL, 'percent_points' => 0, 'percent_bonus' => 0, 'points' => 0, 'bonus' => 0, 'evaluation_table' => NULL); $this->db->set($set); $this->db->where('test_id', $test->id); $this->db->where('test_queue_id', $single_test->id); $this->db->update('test_test_queue_rel'); } $single_test->status = 0; $single_test->worker = NULL; $single_test->save(); } echo 'All old tests were reset.' . PHP_EOL; } else { echo 'Nothing found.' . PHP_EOL; } $this->db->trans_complete(); }