예제 #1
0
 /**
  * Delete this object from database or specified relations.
  * If this object is deleted, all student files will be deleted as well.
  * @param DataMapper|string $object related object to delete from relation.
  * @param string $related_field relation internal name.
  */
 public function delete($object = '', $related_field = '')
 {
     $this_id = $this->id;
     $this_task_set_id = $this->task_set_id;
     $this_student_id = $this->student_id;
     parent::delete($object, $related_field);
     if (empty($object) && !is_array($object) && !empty($this_id)) {
         $task_set = new Task_set();
         $task_set->get_by_id($this_task_set_id);
         if ($task_set->exists()) {
             $student_files = $task_set->get_student_files($this_student_id);
             if (count($student_files) > 0) {
                 foreach ($student_files as $file) {
                     @unlink($file['filepath']);
                 }
             }
         }
     }
 }
예제 #2
0
 /**
  * Initialise download of all solutions in all task sets belonging to this course.
  */
 public function download_all_solutions()
 {
     if (!is_null($this->id)) {
         $task_sets = new Task_set();
         $task_sets->where_related('course', $this);
         $task_sets->get_iterated();
         $filename = $this->get_new_solution_zip_filename();
         $zip_archive = new ZipArchive();
         if ($zip_archive->open($filename, ZipArchive::CREATE)) {
             $period = $this->period->get();
             $readme = $this->lang->text($this->name);
             $readme .= "\r\n" . $this->lang->text($period->name);
             $zip_archive->addFromString('readme.txt', $readme);
             foreach ($task_sets as $task_set) {
                 $overlay_name = $this->lang->get_overlay('task_sets', $task_set->id, 'name');
                 $task_set->add_files_to_zip_archive($zip_archive, $this, normalizeForFilesystem(trim($overlay_name) == '' ? $task_set->name : $overlay_name) . '_(' . $task_set->id . ')');
             }
             $zip_archive->close();
             header('Content-Description: File Transfer');
             header('Content-Type: application/zip');
             header('Content-Disposition: attachment; filename=' . basename($filename));
             header('Content-Transfer-Encoding: binary');
             header('Expires: 0');
             header('Cache-Control: must-revalidate');
             header('Pragma: public');
             header('Content-Length: ' . filesize($filename));
             ob_clean();
             flush();
             $f = fopen($filename, 'r');
             while (!feof($f)) {
                 echo fread($f, 1024);
             }
             fclose($f);
             unlink($filename);
         } else {
             header("HTTP/1.0 404 Not Found");
         }
     } else {
         header("HTTP/1.0 404 Not Found");
     }
     die;
 }
예제 #3
0
 public function insert_to_task_set()
 {
     $this->load->library('form_validation');
     $task_set_id = intval($this->input->post('task_set_id'));
     $this->_transaction_isolation();
     $this->db->trans_begin();
     $task_set = new Task_set();
     $task_set->get_by_id($task_set_id);
     $this->form_validation->set_rules('task_id', 'task_id', 'required');
     $this->form_validation->set_rules('task_set_id', 'task_set_id', 'required');
     if ($task_set->exists()) {
         if ($task_set->content_type == 'task_set') {
             $this->form_validation->set_rules('points_total', 'lang:admin_tasks_add_to_task_set_form_field_points_total', 'required|number|greater_than_equal[0]');
             $this->form_validation->set_rules('test_max_points', 'lang:admin_tasks_add_to_task_set_form_field_test_max_points', 'required|number|greater_than_equal[0]');
             $this->form_validation->set_rules('test_min_points', 'lang:admin_tasks_add_to_task_set_form_field_test_min_points', 'required|number|less_than_field_or_equal[test_max_points]');
         } else {
             $this->form_validation->set_rules('max_projects_selections', 'lang:admin_tasks_add_to_task_set_form_field_max_projects_selections', 'required|integer|greater_than[0]');
         }
     }
     if ($this->form_validation->run()) {
         $task_id = intval($this->input->post('task_id'));
         $points_total = floatval($this->input->post('points_total'));
         $test_max_points = floatval($this->input->post('test_max_points'));
         $test_min_points = floatval($this->input->post('test_min_points'));
         $bonus_task = (int) (bool) intval($this->input->post('bonus_task'));
         $max_projects_selections = intval($this->input->post('max_projects_selections'));
         $internal_comment = $this->input->post('internal_comment');
         $task = new Task();
         $task->get_by_id($task_id);
         if (!$task->exists()) {
             $this->db->trans_rollback();
             $this->messages->add_message('lang:admin_tasks_error_message_task_not_found', Messages::MESSAGE_TYPE_ERROR);
         } elseif (!$task_set->exists()) {
             $this->db->trans_rollback();
             $this->messages->add_message('lang:admin_tasks_add_to_task_set_nothing_opened', Messages::MESSAGE_TYPE_ERROR);
         } elseif ($task_set->is_related_to($task)) {
             $this->db->trans_rollback();
             $this->messages->add_message('lang:admin_tasks_add_to_task_set_already_related', Messages::MESSAGE_TYPE_ERROR);
         } else {
             $related_task = $task_set->task->include_join_fields()->order_by('join_sorting', 'desc')->limit(1)->get();
             $new_sorting = $related_task->exists() ? intval($related_task->join_sorting) + 1 : 1;
             $task_set->save($task);
             $task_set->set_join_field($task, 'points_total', $points_total);
             $task_set->set_join_field($task, 'test_max_points', $test_max_points);
             $task_set->set_join_field($task, 'test_min_points', $test_min_points);
             $task_set->set_join_field($task, 'sorting', $new_sorting);
             $task_set->set_join_field($task, 'bonus_task', $bonus_task);
             $task_set->set_join_field($task, 'max_projects_selections', $max_projects_selections);
             $task_set->set_join_field($task, 'internal_comment', $internal_comment);
             if ($this->db->trans_status()) {
                 $this->db->trans_commit();
                 $this->messages->add_message('lang:admin_tasks_add_to_task_set_save_success', Messages::MESSAGE_TYPE_SUCCESS);
                 $this->_action_success();
             } else {
                 $this->db->trans_rollback();
                 $this->messages->add_message('lang:admin_tasks_add_to_task_set_save_failed', Messages::MESSAGE_TYPE_ERROR);
             }
         }
         redirect(create_internal_url('admin_tasks/add_to_task_set/task_id/' . $task_id));
     } else {
         $this->db->trans_rollback();
         $this->add_to_task_set();
     }
 }
예제 #4
0
 public function delete_permission($task_set_id, $task_set_permission_id)
 {
     $output = new stdClass();
     $output->result = FALSE;
     $output->message = '';
     $this->_transaction_isolation();
     $this->db->trans_begin();
     $task_set = new Task_set();
     $task_set->get_by_id((int) $task_set_id);
     $task_set_permission = new Task_set_permission();
     $task_set_permission->get_by_id((int) $task_set_permission_id);
     if ($task_set->exists() && !is_null($task_set->course_id)) {
         if ($task_set_permission->exists() && $task_set_permission->is_related_to($task_set)) {
             $task_set_permission->delete();
             if ($this->db->trans_status()) {
                 $this->db->trans_commit();
                 $output->result = TRUE;
                 $output->message = $this->lang->line('admin_task_set_permissions_success_message_deleted');
                 $this->_action_success();
             } else {
                 $this->db->trans_rollback();
                 $output->message = $this->lang->line('admin_task_set_permissions_error_message_delete_error');
             }
         } else {
             $this->db->trans_rollback();
             $output->message = $this->lang->line('admin_task_set_permissions_error_message_cant_find_task_set_permission_or_is_not_related_to_task_set');
         }
     } else {
         $this->db->trans_rollback();
         $output->message = $this->lang->line('lang:admin_task_set_permissions_error_message_cant_find_task_set_or_course');
     }
     $this->output->set_content_type('application/json');
     $this->output->set_output(json_encode($output));
 }
예제 #5
0
 public function delete_task_set_type()
 {
     $this->output->set_content_type('application/json');
     $this->load->library('form_validation');
     $this->form_validation->set_rules('task_set_type_id', 'task_set_type_id', 'required');
     $this->form_validation->set_rules('course_id', 'course_id', 'required');
     if ($this->form_validation->run()) {
         $course_id = intval($this->input->post('course_id'));
         $task_set_type_id = intval($this->input->post('task_set_type_id'));
         $course = new Course();
         $course->get_by_id($course_id);
         $task_set_type = new Task_set_type();
         $task_set_type->get_by_id($task_set_type_id);
         if ($course->exists() && $task_set_type->exists()) {
             $this->_transaction_isolation();
             $this->db->trans_begin();
             $course->delete($task_set_type);
             $task_sets = new Task_set();
             $task_sets->where_related_course('id', $course_id)->where_related_task_set_type('id', $task_set_type_id)->get_iterated();
             foreach ($task_sets as $task_set) {
                 $task_set->delete($task_set_type);
             }
             if ($this->db->trans_status()) {
                 $this->db->trans_commit();
                 $this->output->set_output(json_encode(TRUE));
                 return;
             } else {
                 $this->db->trans_rollback();
             }
         }
     }
     $this->output->set_output(json_encode(FALSE));
 }
예제 #6
0
 public function render()
 {
     if (isset($this->config['course_id'])) {
         $course = new Course();
         $course->include_related('period');
         $course->get_by_id((int) $this->config['course_id']);
         $this->parser->assign('course', $course);
         if ($course->exists()) {
             $task_sets = new Task_set();
             $task_sets->where_related($course);
             $task_sets->where('published', 1);
             $task_sets->where('content_type', 'task_set');
             $task_sets_count = $task_sets->count();
             $this->parser->assign('task_sets_count', $task_sets_count);
             $task_sets->where_related($course);
             $task_sets->where('published', 1);
             $task_sets->where('content_type', 'project');
             $projects_count = $task_sets->count();
             $this->parser->assign('projects_count', $projects_count);
             $groups = new Group();
             $groups->where_related($course);
             $groups_count = $groups->count();
             $this->parser->assign('groups_count', $groups_count);
             $students = new Student();
             $students->where_related('participant/course', 'id', $course->id);
             $students->where_related('participant', 'allowed', 1);
             $students_count = $students->count();
             $this->parser->assign('students_count', $students_count);
             $task_set_permissions = new Task_set_permission();
             $task_set_permissions->select_func('COUNT', '*', 'count');
             $task_set_permissions->where('enabled', 1);
             $task_set_permissions->where_related('task_set', 'id', '${parent}.id');
             $now = date('Y-m-d H:i:s');
             $plus_two_weeks = date('Y-m-d H:i:s', strtotime($now . ' + 2 weeks'));
             $minus_one_week = date('Y-m-d H:i:s', strtotime($now . ' - 1 week'));
             $task_sets->select('id, name, upload_end_time AS min_upload_end_time, upload_end_time AS max_upload_end_time');
             $task_sets->where_related($course);
             $task_sets->where('published', 1);
             $task_sets->where_subquery('0', $task_set_permissions);
             $task_sets->where('upload_end_time >=', $minus_one_week);
             $task_sets->where('upload_end_time <=', $plus_two_weeks);
             $task_sets_2 = new Task_set();
             $task_sets_2->select('id, name');
             $task_sets_2->where_related($course);
             $task_sets_2->where('published', 1);
             $task_sets_2->select_min('task_set_permissions.upload_end_time', 'min_upload_end_time');
             $task_sets_2->select_max('task_set_permissions.upload_end_time', 'max_upload_end_time');
             $task_sets_2->where_related('task_set_permission', 'enabled', 1);
             $task_sets_2->having('(MAX(`task_set_permissions`.`upload_end_time`) >= ' . $this->db->escape($minus_one_week) . ' AND MAX(`task_set_permissions`.`upload_end_time`) <= ' . $this->db->escape($plus_two_weeks) . ')');
             $task_sets_2->or_having('(MIN(`task_set_permissions`.`upload_end_time`) >= ' . $this->db->escape($minus_one_week) . ' AND MIN(`task_set_permissions`.`upload_end_time`) <= ' . $this->db->escape($plus_two_weeks) . ')');
             $task_sets_2->group_by('id');
             $task_sets->union_iterated($task_sets_2, FALSE, 'min_upload_end_time DESC, max_upload_end_time DESC', isset($this->config['number_of_task_sets']) ? (int) $this->config['number_of_task_sets'] : 5);
             $this->parser->assign('task_sets', $task_sets);
         }
     }
     $this->parser->parse('widgets/admin/course_overview/main.tpl');
 }
예제 #7
0
 private function get_valuation_table_data($course_id, $group_id = NULL, $condensed = FALSE)
 {
     $table_data = array('header' => array(), 'content' => array());
     $course = new Course();
     $course->get_by_id(intval($course_id));
     $group = new Group();
     $group->get_by_id((int) $group_id);
     if ($course->exists()) {
         $students = new Student();
         $students->select('id, fullname, email');
         $students->include_related('participant/group', array('id', 'name'));
         $students->where_related('participant/course', 'id', $course->id);
         $students->where_related('participant', 'allowed', 1);
         $students->order_by_as_fullname('fullname');
         if ($group->exists()) {
             $students->where_related('participant/group', 'id', (int) $group_id);
         }
         $students->get_iterated();
         $task_sets_out_of_group_ids = array(0);
         $task_sets_data = array();
         $task_sets_ids = array();
         $projects_ids = array();
         if ($group->exists()) {
             $students_filter = new Student();
             $students_filter->select('id');
             $students_filter->where_related('participant/course', 'id', $course->id);
             $students_filter->where_related('participant', 'allowed', 1);
             $students_filter->where_related('participant/group', 'id', (int) $group->id);
             $solutions_filter = new Solution();
             $solutions_filter->select('id');
             $solutions_filter->where_in_subquery('student_id', $students_filter);
             $task_sets_out_of_group = new Task_set();
             $task_sets_out_of_group->select('id');
             $task_sets_out_of_group->where_in_subquery('id', $solutions_filter);
             $task_sets_out_of_group->where('published', 1);
             $task_sets_out_of_group->get();
             $task_sets_out_of_group_ids = $task_sets_out_of_group->all_to_single_array('id');
             $task_sets_out_of_group_ids[] = 0;
         }
         $content_type_task_set = new Task_set();
         $content_type_task_set->select('id, name, content_type, group_id, task_set_type_id');
         $content_type_task_set->include_related('task_set_type', 'name');
         $content_type_task_set->include_related('group', 'name');
         $content_type_task_set->where('content_type', 'task_set');
         $content_type_task_set->where('published', 1);
         $content_type_task_set->where_related_course($course);
         $content_type_task_set->order_by_related_with_constant('task_set_type', 'name', 'asc');
         $content_type_task_set->order_by('task_set_type_id', 'asc');
         $content_type_task_set->order_by('publish_start_time', 'asc');
         if ($group->exists()) {
             $content_type_task_set->group_start();
             $content_type_task_set->group_start('', 'OR ');
             $content_type_task_set->group_start();
             $content_type_task_set->or_where('group_id', NULL);
             $content_type_task_set->or_where('group_id', (int) $group_id);
             $content_type_task_set->group_end();
             $content_type_task_set->where_subquery(0, '(SELECT COUNT(`tsp`.`id`) AS `count` FROM `task_set_permissions` tsp WHERE `tsp`.`task_set_id` = `task_sets`.`id` AND `tsp`.`enabled` = 1)');
             $content_type_task_set->group_end();
             $content_type_task_set->group_start('', 'OR ');
             $content_type_task_set->where_related('task_set_permission', 'group_id', (int) $group_id);
             $content_type_task_set->where_related('task_set_permission', 'enabled', 1);
             $content_type_task_set->group_end();
             $content_type_task_set->or_where_in('id', $task_sets_out_of_group_ids);
             $content_type_task_set->group_end();
         }
         $content_type_task_set->get();
         $header_items = array();
         if ($content_type_task_set->result_count() > 0) {
             $last_task_set_type_id = NULL;
             foreach ($content_type_task_set->all as $task_set) {
                 $permissions = new Task_set_permission();
                 $permissions->select('id, group_id');
                 $permissions->include_related('group', 'name');
                 $permissions->where_related_task_set($task_set);
                 $permissions->where('enabled', 1);
                 $permissions->get_iterated();
                 if ($permissions->result_count() > 0) {
                     $group_ids = array();
                     $group_names = array();
                     foreach ($permissions as $permission) {
                         $group_ids[] = $permission->group_id;
                         $group_names[] = $this->lang->text($permission->group_name);
                     }
                     $task_sets_data[$task_set->id] = array('group_id' => $group_ids, 'group_name' => $group_names);
                 } else {
                     $task_sets_data[$task_set->id] = array('group_id' => array($task_set->group_id), 'group_name' => $this->lang->text($task_set->group_name));
                 }
                 if ($task_set->task_set_type_id !== $last_task_set_type_id) {
                     $last_task_set_type_id = $task_set->task_set_type_id;
                     $header_items[] = array('type' => 'task_set_type', 'id' => $task_set->task_set_type_id, 'name' => $this->lang->text($task_set->task_set_type_name), 'title' => '');
                 }
                 if (!$condensed) {
                     $header_items[] = array('type' => 'task_set', 'id' => $task_set->id, 'name' => $this->lang->get_overlay_with_default('task_sets', $task_set->id, 'name', $task_set->name), 'title' => is_array($task_sets_data[$task_set->id]['group_name']) ? implode(', ', $task_sets_data[$task_set->id]['group_name']) : $task_sets_data[$task_set->id]['group_name']);
                 }
                 $task_sets_ids[] = $task_set->id;
             }
         }
         $table_data['header']['content_type_task_set'] = array('content_type_name' => $this->lang->line('admin_solutions_valuation_tables_header_content_type_task_sets'), 'items' => $header_items);
         $content_type_project = new Task_set();
         $content_type_project->where('content_type', 'project');
         $content_type_project->where('published', 1);
         $content_type_project->where_related_course($course);
         $content_type_project->order_by_related_with_constant('task_set_type', 'name', 'asc');
         $content_type_project->order_by('publish_start_time', 'asc');
         $content_type_project->get();
         $header_items = array();
         if ($content_type_project->result_count() > 0) {
             foreach ($content_type_project->all as $project) {
                 if (!$condensed) {
                     $header_items[] = array('type' => 'task_set', 'id' => $project->id, 'name' => $this->lang->get_overlay_with_default('task_sets', $project->id, 'name', $project->name), 'title' => '');
                 }
                 $projects_ids[] = $project->id;
             }
         }
         $table_data['header']['content_type_project'] = array('content_type_name' => $this->lang->line('admin_solutions_valuation_tables_header_content_type_project'), 'items' => $header_items);
         foreach ($students as $student) {
             $student_line = array('fullname' => $student->fullname, 'email' => $student->email, 'id' => $student->id, 'total_points' => 0, 'task_sets_points' => array(), 'task_sets_points_total' => 0, 'projects_points' => array(), 'projects_points_total' => 0);
             $solutions_data = array();
             if ($content_type_task_set->result_count() > 0 || $content_type_project->result_count() > 0) {
                 $solutions = new Solution();
                 $solutions->select('task_set_id, points, tests_points, not_considered, revalidate');
                 $solutions->where_related_student($student);
                 $solutions->group_start();
                 if (count($task_sets_ids) > 0) {
                     $solutions->or_where_in('task_set_id', $task_sets_ids);
                 }
                 if (count($projects_ids) > 0) {
                     $solutions->or_where_in('task_set_id', $projects_ids);
                 }
                 $solutions->group_end();
                 $solutions->get_iterated();
                 foreach ($solutions as $solution) {
                     $solutions_data[$solution->task_set_id] = array('points' => is_null($solution->points) && is_null($solution->tests_points) ? NULL : $solution->points + $solution->tests_points, 'not_considered' => $solution->not_considered, 'revalidate' => $solution->revalidate);
                 }
             }
             $task_sets_points_array = array();
             if ($content_type_task_set->result_count() > 0) {
                 $task_sets_points = 0;
                 $last_task_set_type_id = NULL;
                 $last_task_set_type_key = NULL;
                 foreach ($content_type_task_set->all as $task_set) {
                     if ($last_task_set_type_id !== $task_set->task_set_type_id) {
                         $last_task_set_type_id = $task_set->task_set_type_id;
                         $task_sets_points_array[] = array('type' => 'task_set_type', 'points' => 0, 'flag' => 'ok');
                         $last_task_set_type_key = count($task_sets_points_array) - 1;
                     }
                     $points = 0;
                     if (isset($solutions_data[$task_set->id])) {
                         if ($solutions_data[$task_set->id]['not_considered']) {
                             if (!$condensed) {
                                 $task_sets_points_array[] = array('type' => 'task_set', 'points' => '*', 'flag' => 'notConsidered');
                             }
                         } else {
                             if (is_null($solutions_data[$task_set->id]['points'])) {
                                 if (!$condensed) {
                                     $task_sets_points_array[] = array('type' => 'task_set', 'points' => '!', 'flag' => 'revalidate');
                                 }
                             } elseif ($solutions_data[$task_set->id]['revalidate']) {
                                 if (!$condensed) {
                                     $task_sets_points_array[] = array('type' => 'task_set', 'points' => $solutions_data[$task_set->id]['points'], 'flag' => 'revalidate');
                                 }
                                 $points = floatval($solutions_data[$task_set->id]['points']);
                             } else {
                                 if (!$condensed) {
                                     $task_sets_points_array[] = array('type' => 'task_set', 'points' => $solutions_data[$task_set->id]['points'], 'flag' => 'ok');
                                 }
                                 $points = floatval($solutions_data[$task_set->id]['points']);
                             }
                         }
                     } else {
                         if (!$condensed) {
                             if (!is_null($task_sets_data[$task_set->id]['group_id'][0]) && !in_array($student->participant_group_id, $task_sets_data[$task_set->id]['group_id'])) {
                                 $task_sets_points_array[] = array('type' => 'task_set', 'points' => '-', 'flag' => 'notInGroup');
                             } else {
                                 $task_sets_points_array[] = array('type' => 'task_set', 'points' => 'x', 'flag' => 'notSubmitted');
                             }
                         }
                     }
                     $task_sets_points += $points;
                     $task_sets_points_array[$last_task_set_type_key]['points'] += $points;
                     $student_line['total_points'] += $points;
                     $student_line['task_sets_points_total'] = $task_sets_points;
                 }
             }
             $student_line['task_sets_points'] = $task_sets_points_array;
             $task_sets_points_array = array();
             if ($content_type_project->result_count() > 0) {
                 $task_sets_points = 0;
                 foreach ($content_type_project as $task_set) {
                     $points = 0;
                     if (isset($solutions_data[$task_set->id])) {
                         if ($solutions_data[$task_set->id]['not_considered']) {
                             if (!$condensed) {
                                 $task_sets_points_array[] = array('type' => 'task_set', 'points' => '*', 'flag' => 'notConsidered');
                             }
                         } else {
                             if (is_null($solutions_data[$task_set->id]['points'])) {
                                 if (!$condensed) {
                                     $task_sets_points_array[] = array('type' => 'task_set', 'points' => '!', 'flag' => 'revalidate');
                                 }
                             } elseif ($solutions_data[$task_set->id]['revalidate']) {
                                 if (!$condensed) {
                                     $task_sets_points_array[] = array('type' => 'task_set', 'points' => $solutions_data[$task_set->id]['points'], 'flag' => 'revalidate');
                                 }
                                 $points = floatval($solutions_data[$task_set->id]['points']);
                             } else {
                                 if (!$condensed) {
                                     $task_sets_points_array[] = array('type' => 'task_set', 'points' => $solutions_data[$task_set->id]['points'], 'flag' => 'ok');
                                 }
                                 $points = floatval($solutions_data[$task_set->id]['points']);
                             }
                         }
                     } else {
                         if (!$condensed) {
                             $task_sets_points_array[] = array('type' => 'task_set', 'points' => 'x', 'flag' => 'notSubmitted');
                         }
                     }
                     $task_sets_points += $points;
                     $student_line['total_points'] += $points;
                     $student_line['projects_points_total'] = $task_sets_points;
                 }
             }
             $student_line['projects_points'] = $task_sets_points_array;
             $table_data['content'][] = $student_line;
         }
     }
     return $table_data;
 }
예제 #8
0
 private function get_task_set_overview($task_set_id, &$course)
 {
     $task_set = new Task_set();
     $task_set->where('published', 1);
     $task_set->include_related_count('task', 'total_tasks');
     $task_set->where('content_type', 'project');
     $task_set->order_by('publish_start_time', 'asc');
     $task_set->order_by('upload_end_time', 'asc');
     $task_set->order_by_with_overlay('name', 'asc');
     $task_set->get_by_id((int) $task_set_id);
     $course = new Course();
     $course->where_related('task_set', 'id', (int) $task_set->id);
     $course->include_related('period');
     $course->get();
     return $task_set;
 }
예제 #9
0
 public function send_deadline_notifications($lang_idiom = NULL)
 {
     $this->load->database();
     $this->load->model('translations');
     if (!is_null($lang_idiom)) {
         $this->lang->reinitialize_for_idiom($lang_idiom);
     }
     $translations = $this->translations->get_translations_for_idiom($this->lang->get_current_idiom());
     $this->lang->add_custom_translations($translations);
     $this->lang->load('cli');
     $current_time = Date('Y-m-d H:i:s');
     $one_day_back_time = Date('Y-m-d H:i:s', strtotime('now -1 day'));
     $task_sets1 = new Task_set();
     $task_sets1->select('id, name, course_id, group_id AS common_group_id, upload_end_time AS common_upload_end_time, deadline_notified AS common_deadline_notified, deadline_notification_emails AS common_deadline_notification_emails, deadline_notification_emails_handler AS common_deadline_notification_emails_handler');
     $task_sets1->select('null AS `task_set_permission_id`', FALSE);
     $task_sets1->where('deadline_notified', 0);
     $task_sets1->where('deadline_notification_emails_handler >', 0);
     $task_sets1->group_start();
     $task_sets1->not_group_start();
     $task_sets1->where('upload_end_time', NULL);
     $task_sets1->group_end();
     $task_sets1->where('upload_end_time <', $current_time);
     $task_sets1->where('upload_end_time >=', $one_day_back_time);
     $task_sets1->group_end();
     $task_sets1->where_subquery(0, '(SELECT COUNT(`tsp`.`id`) AS `count` FROM `task_set_permissions` tsp WHERE `tsp`.`task_set_id` = `task_sets`.`id` AND `tsp`.`enabled` = 1)');
     $task_sets1->where('published', 1);
     $task_sets2 = new Task_set();
     $task_sets2->select('id, name, course_id');
     $task_sets2->include_related('task_set_permission', 'group_id', 'common');
     $task_sets2->include_related('task_set_permission', 'upload_end_time', 'common');
     $task_sets2->include_related('task_set_permission', 'deadline_notified', 'common');
     $task_sets2->include_related('task_set_permission', 'deadline_notification_emails', 'common');
     $task_sets2->include_related('task_set_permission', 'deadline_notification_emails_handler', 'common');
     $task_sets2->include_related('task_set_permission', 'id');
     $task_sets2->where_related('task_set_permission', 'enabled', 1);
     $task_sets2->where_related('task_set_permission', 'deadline_notified', 0);
     $task_sets2->where_related('task_set_permission', 'deadline_notification_emails_handler >', 0);
     $task_sets2->group_start();
     $task_sets2->not_group_start();
     $task_sets2->where_related('task_set_permission', 'upload_end_time', NULL);
     $task_sets2->group_end();
     $task_sets2->where_related('task_set_permission', 'upload_end_time <', $current_time);
     $task_sets2->where_related('task_set_permission', 'upload_end_time >=', $one_day_back_time);
     $task_sets2->group_end();
     $task_sets2->where('published', 1);
     $task_sets1->union_iterated($task_sets2, TRUE);
     $this->load->library('email');
     $sent_notifications = 0;
     foreach ($task_sets1 as $task_set) {
         if ($task_set->common_deadline_notification_emails_handler > 0) {
             $emails = trim($task_set->common_deadline_notification_emails) != '' ? explode(',', $task_set->common_deadline_notification_emails) : array();
             array_walk($emails, function (&$email, $key) {
                 $email = trim($email);
             });
             if ($task_set->common_deadline_notification_emails_handler == 1) {
                 $groups = new Group();
                 $groups->where_related('course', 'id', $task_set->course_id);
                 $groups->include_related('room/teacher', '*');
                 $groups->group_start('NOT');
                 $groups->where_related('room', 'id', null);
                 $groups->or_where_related('room/teacher', 'id', null);
                 $groups->group_end();
                 $groups->group_by_related('room/teacher', 'email');
                 if (!is_null($task_set->common_group_id)) {
                     $groups->where('id', $task_set->common_group_id);
                 }
                 $groups->get_iterated();
                 foreach ($groups as $teacher) {
                     if (trim($teacher->room_teacher_email) != '') {
                         $email = trim($teacher->room_teacher_email);
                         if (!in_array($email, $emails)) {
                             $emails[] = $email;
                         }
                     }
                 }
             }
             $group = new Group();
             if (!is_null($task_set->common_group_id)) {
                 $group->get_by_id((int) $task_set->common_group_id);
             }
             if (count($emails)) {
                 $this->email->from_system();
                 $this->email->reply_to_system();
                 $this->email->build_message_body('file:emails/cli/deadline_notification.tpl', array('task_set' => $task_set, 'group' => $group));
                 if ($this->config->item('email_multirecipient_batch_mode')) {
                     $this->email->to($emails);
                     $this->email->subject('LIST: ' . $this->lang->line('cli_deadline_notification_subject'));
                     $this->email->send();
                 } else {
                     foreach ($emails as $email) {
                         $this->email->to($email);
                         $this->email->subject('TEST');
                         $this->email->send();
                     }
                 }
                 $sent_notifications++;
                 if (!is_null($task_set->task_set_permission_id)) {
                     $task_set_permission = new Task_set_permission();
                     $task_set_permission->get_by_id($task_set->task_set_permission_id);
                     if ($task_set_permission->exists()) {
                         $task_set_permission->deadline_notified = 1;
                         $task_set_permission->save();
                     }
                 } else {
                     $task_set_update = new Task_set();
                     $task_set_update->get_by_id($task_set->id);
                     if ($task_set_update->exists()) {
                         $task_set_update->deadline_notified = 1;
                         $task_set_update->save();
                     }
                 }
             }
         }
     }
     echo "Process finished, {$sent_notifications} notifications were sent ...\n";
 }
예제 #10
0
 private function inject_all_task_sets()
 {
     $task_sets = new Task_set();
     $task_set_permissions = $task_sets->task_set_permission;
     $task_set_permissions->select_func('COUNT', '*', 'count');
     $task_set_permissions->where('enabled', 1);
     $task_set_permissions->where_related('task_set', 'id', '${parent}.id');
     $task_sets->select('*');
     $task_sets->include_related('group', 'name');
     $task_sets->select_subquery($task_set_permissions, 'task_set_permissions_count');
     $task_sets->order_by_with_overlay('name');
     $task_sets->get_iterated();
     $data = array();
     $this->lang->init_all_overlays('task_sets');
     foreach ($task_sets as $task_set) {
         $text_groups = '';
         if ((int) $task_set->task_set_permissions_count > 0) {
             $task_set_permissions = new Task_set_permission();
             $task_set_permissions->include_related('group', 'name');
             $task_set_permissions->where('enabled', 1);
             $task_set_permissions->where_related_task_set($task_set);
             $task_set_permissions->order_by_related_with_constant('group', 'name', 'asc');
             $task_set_permissions->get_iterated();
             $groups = array();
             foreach ($task_set_permissions as $task_set_permission) {
                 $groups[] = $this->lang->text($task_set_permission->group_name);
             }
             if (count($groups) > 0) {
                 $text_groups = ' ... (' . implode(', ', $groups) . ')';
             }
         } elseif (!is_null($task_set->group_id) && (int) $task_set->group_id > 0) {
             $text_groups = ' ... (' . $this->lang->text($task_set->group_name) . ')';
         }
         $data[$task_set->course_id][] = array('value' => $task_set->id, 'text' => $this->lang->get_overlay_with_default('task_sets', $task_set->id, 'name', $task_set->name) . $text_groups);
     }
     $this->parser->assign('task_sets', $data);
 }
예제 #11
0
 private function add_comment($task_set_id, $reply_at_id = NULL)
 {
     $comment_data = $this->input->post('comment');
     if (isset($comment_data['task_set_id']) && $comment_data['task_set_id'] == $task_set_id) {
         $this->_transaction_isolation();
         $this->db->trans_begin();
         $task_set = new Task_set();
         $task_set->get_by_id($task_set_id);
         if ($task_set->exists()) {
             if ((bool) $task_set->comments_enabled) {
                 $save_array = array();
                 $save_array['task_set'] = $task_set;
                 if (isset($comment_data['reply_at_id']) && $comment_data['reply_at_id'] == $reply_at_id) {
                     $reply_at = new Comment();
                     $reply_at->get_by_id($reply_at_id);
                     if ($reply_at->exists()) {
                         if ($reply_at->task_set_id == $task_set_id) {
                             $save_array['reply_at'] = $reply_at;
                         } else {
                             $this->db->trans_rollback();
                             $this->messages->add_message('lang:admin_task_sets_comments_error_reply_at_comment_from_different_task_set', Messages::MESSAGE_TYPE_ERROR);
                             return;
                         }
                     } else {
                         $this->db->trans_rollback();
                         $this->messages->add_message('lang:admin_task_sets_comments_error_reply_at_comment_not_exists', Messages::MESSAGE_TYPE_ERROR);
                         return;
                     }
                 }
                 $teacher = new Teacher();
                 $teacher->get_by_id($this->usermanager->get_teacher_id());
                 $save_array['teacher'] = $teacher;
                 $comment = new Comment();
                 $comment->text = strip_tags($comment_data['text'], '<a><strong><em><span>');
                 $comment->approved = 1;
                 if ($comment->save($save_array)) {
                     $this->db->trans_commit();
                     $this->messages->add_message('lang:admin_task_sets_comments_save_successfully', Messages::MESSAGE_TYPE_SUCCESS);
                     $all_students = $task_set->comment_subscriber_student;
                     $all_students->get();
                     $this->_send_multiple_emails($all_students, 'lang:admin_task_sets_comments_email_subject_new_post', 'file:emails/backend/comments/new_comment_student.tpl', array('task_set' => $task_set, 'teacher' => $teacher, 'comment' => $comment));
                     $all_teachers = $task_set->comment_subscriber_teacher;
                     $all_teachers->where('id !=', $this->usermanager->get_teacher_id());
                     $all_teachers->get();
                     $this->_send_multiple_emails($all_teachers, 'lang:admin_task_sets_comments_email_subject_new_post', 'file:emails/backend/comments/new_comment_teacher.tpl', array('task_set' => $task_set, 'teacher' => $teacher, 'comment' => $comment));
                 } else {
                     $this->db->trans_rollback();
                     $this->messages->add_message('lang:admin_task_sets_comments_error_save_failed', Messages::MESSAGE_TYPE_ERROR);
                 }
             } else {
                 $this->db->trans_rollback();
                 $this->messages->add_message('lang:admin_task_sets_comments_error_comments_disabled', Messages::MESSAGE_TYPE_ERROR);
             }
         } else {
             $this->db->trans_rollback();
             $this->messages->add_message('lang:admin_task_sets_error_task_set_not_found', Messages::MESSAGE_TYPE_ERROR);
         }
     } else {
         $this->messages->add_message('lang:admin_task_sets_error_task_set_not_found', Messages::MESSAGE_TYPE_ERROR);
     }
 }
예제 #12
0
 public function details($log_id)
 {
     $log = new Log();
     $log->include_related('student');
     $log->include_related('teacher');
     $log->get_by_id($log_id);
     if ($log->exists()) {
         if ($log->log_type == Log::LOG_TYPE_STUDENT_SOLUTION_UPLOAD || $log->log_type == Log::LOG_TYPE_TEACHER_SOLUTION_UPLOAD) {
             $solution = new Solution();
             $solution->include_related('student');
             $solution->include_related('task_set');
             $solution->include_related('task_set/course');
             $solution->include_related('task_set/course/period');
             $solution->get_by_id((int) $log->affected_row_primary_id);
             $this->parser->assign('solution', $solution);
         } elseif ($log->log_type == Log::LOG_TYPE_STUDENT_SOLUTION_DOWNLOAD) {
             $additional_data = unserialize($log->additional_data);
             $task_set = new Task_set();
             $task_set->include_related('course');
             $task_set->include_related('course/period');
             $task_set->get_by_id(@$additional_data['task_set_id']);
             $this->parser->assign(array('task_set' => $task_set, 'filename' => @$additional_data['solution_file']));
         }
     }
     $this->parser->add_css_file('admin_logs.css');
     $this->parser->parse('backend/logs/details.tpl', array('log' => $log));
 }
예제 #13
0
 private function get_task_set_by_id(&$course, &$group, &$student, $task_set_id)
 {
     $student = new Student();
     $student->get_by_id($this->usermanager->get_student_id());
     $course = new Course();
     $course->where_related('active_for_student', 'id', $student->id);
     $course->where_related('participant', 'student_id', $student->id);
     $course->where_related('participant', 'allowed', 1);
     $course->include_related('period', 'name');
     $course->get();
     $task_set = new Task_set();
     $task_set2 = new Task_set();
     $group = new Group();
     if ($course->exists()) {
         $group->where_related_participant('student_id', $student->id);
         $group->where_related_participant('course_id', $course->id);
         $group->get();
         $task_set->select('`task_sets`.*, `rooms`.`time_day` AS `pb_time_day`, `rooms`.`time_begin` AS `pb_time_begin`, `rooms`.`id` AS `pb_room_id`, `task_sets`.`publish_start_time` AS `pb_publish_start_time`, `task_sets`.`upload_end_time` AS `pb_upload_end_time`');
         $task_set->where('published', 1);
         $task_set->where_related_course($course);
         $task_set->include_related('solution');
         $task_set->add_join_condition('`solutions`.`student_id` = ?', array($student->id));
         $task_set->where_subquery(0, '(SELECT COUNT(`tsp`.`id`) AS `count` FROM `task_set_permissions` tsp WHERE `tsp`.`task_set_id` = `task_sets`.`id` AND `tsp`.`enabled` = 1)');
         $task_set->group_start();
         $task_set->or_where('group_id', NULL);
         $task_set->or_where('group_id', $group->id);
         $task_set->group_end();
         $task_set->include_related('room', '*', TRUE, TRUE);
         $task_set->include_related_count('task', 'total_tasks');
         $task_set->include_related('task_set_type');
         $task_set->select_subquery('(SELECT SUM(`points_total`) AS `points` FROM `task_task_set_rel` WHERE `task_set_id` = `${parent}`.`id` AND `task_task_set_rel`.`bonus_task` = 0)', 'total_points');
         $task_set->where('id', $task_set_id);
         $task_set->include_related('course', 'test_scoring_deadline');
         $task_set->where('content_type', 'task_set');
         $task_set2->select('`task_sets`.*, `task_set_permission_rooms`.`time_day` AS `pb_time_day`, `task_set_permission_rooms`.`time_begin` AS `pb_time_begin`, `task_set_permission_rooms`.`id` AS `pb_room_id`, `task_set_permissions`.`publish_start_time` AS `pb_publish_start_time`, `task_set_permissions`.`upload_end_time` AS `pb_upload_end_time`');
         $task_set2->where('published', 1);
         $task_set2->where_related_course($course);
         $task_set2->where_related('task_set_permission', 'group_id', $group->id);
         $task_set2->where_related('task_set_permission', 'enabled', 1);
         $task_set2->include_related('solution');
         $task_set2->add_join_condition('`solutions`.`student_id` = ?', array($student->id));
         $task_set2->include_related('task_set_permission/room', '*', 'room', TRUE);
         $task_set2->include_related_count('task', 'total_tasks');
         $task_set2->include_related('task_set_type');
         $task_set2->select_subquery('(SELECT SUM(`points_total`) AS `points` FROM `task_task_set_rel` WHERE `task_set_id` = `${parent}`.`id` AND `task_task_set_rel`.`bonus_task` = 0)', 'total_points');
         $task_set2->where('id', $task_set_id);
         $task_set2->include_related('course', 'test_scoring_deadline');
         $task_set2->where('content_type', 'task_set');
         $task_set3 = new Task_set();
         $task_set3->select('`task_sets`.*, NULL AS `pb_time_day`, NULL AS `pb_time_begin`, NULL AS `pb_room_id`, NULL AS `pb_publish_start_time`, "0000-00-00 00:00:00" AS `pb_upload_end_time`', FALSE);
         $task_set3->where('published', 1);
         $task_set3->where_related_course($course);
         $task_set3->include_related('solution');
         $task_set3->add_join_condition('`solutions`.`student_id` = ?', array($student->id));
         $task_set3->where_related('solution', 'student_id', $student->id);
         $task_set3->include_related('room', '*', TRUE, TRUE);
         $task_set3->include_related_count('task', 'total_tasks');
         $task_set3->include_related('task_set_type');
         $task_set3->select_subquery('(SELECT SUM(`points_total`) AS `points` FROM `task_task_set_rel` WHERE `task_set_id` = `${parent}`.`id` AND `task_task_set_rel`.`bonus_task` = 0)', 'total_points');
         $task_set3->where('id', $task_set_id);
         $task_set3->include_related('course', 'test_scoring_deadline');
         $task_set3->where('content_type', 'task_set');
         $task_set2->union(array($task_set, $task_set3), FALSE, '', 1, 0, 'id');
     }
     return $task_set2;
 }
예제 #14
0
 public function evaluate_test_result($task_set_id, $student_id, $version, $test_type, $token)
 {
     $task_set = new Task_set();
     $task_set->include_related('course', 'test_scoring_deadline');
     $task_set->get_by_id((int) $task_set_id);
     $student = new Student();
     $student->get_by_id((int) $student_id);
     $output = new stdClass();
     $output->result = FALSE;
     $output->message = '';
     $output->points_new = 0;
     $output->points_before = 0;
     $this->load->model('test_score');
     if ($task_set->exists() && $student->exists()) {
         if ($task_set->course_test_scoring_deadline >= date('Y-m-d H:i:s') && $task_set->enable_tests_scoring > 0) {
             $results = $this->test_score->get_data_for_student($student->id, $token, $test_type);
             $this->_transaction_isolation();
             $this->db->trans_start();
             $tests = new Test();
             $tests->where_related('task/task_set', 'id', $task_set->id);
             $tests->where('type', $test_type);
             $tests->where('enable_scoring >', 0);
             $tests->group_by('task_id');
             $tests->where('task_task_task_set_rel.bonus_task', 0);
             $tests->get_iterated();
             //$output->debug = $tests->check_last_query(array('', ''), TRUE);
             $test_count = $tests->result_count();
             $min_results = $task_set->test_min_needed > $test_count ? $test_count : $task_set->test_min_needed;
             $course = new Course();
             $course->where_related_task_set('id', $task_set->id);
             $course->get();
             $min_points_limit = -$course->default_points_to_remove;
             if ($test_count > 0) {
                 $total_score = 0;
                 $score_array = array();
                 $bonus_tasks_array = array();
                 $score_percentage = array();
                 $bonus_tasks_percentage = array();
                 if (count($results)) {
                     foreach ($results as $task_id => $score) {
                         $this->db->select('*');
                         $this->db->where('task_set_id', $task_set->id);
                         $this->db->where('task_id', (int) $task_id);
                         $query = $this->db->get('task_task_set_rel');
                         if ($query->num_rows() > 0) {
                             $task_rel = $query->row_object();
                             $min = $task_rel->test_min_points;
                             $max = $task_rel->test_max_points;
                             $diff = abs($max - $min);
                             $score_percent = (double) $score / 100;
                             $sub_score = round(10 * ($min + $diff * $score_percent)) / 10;
                             if ($task_rel->bonus_task == 0) {
                                 $score_array[$task_id] = $sub_score;
                                 $score_percentage[$task_id] = $score;
                             } else {
                                 $bonus_tasks_array[$task_id] = $sub_score;
                                 $bonus_tasks_percentage[$task_id] = $score;
                             }
                         }
                         $query->free_result();
                     }
                 }
                 $max_results = $task_set->test_max_allowed < count($score_array) ? $task_set->test_max_allowed : count($score_array);
                 arsort($score_array, SORT_NUMERIC);
                 $i = 0;
                 foreach ($score_array as $task_id => $points) {
                     if ($i < $max_results) {
                         $total_score += $points;
                         $i++;
                     } else {
                         break;
                     }
                 }
                 $total_score = $total_score < $min_points_limit ? $min_points_limit : $total_score;
                 arsort($bonus_tasks_array, SORT_NUMERIC);
                 $total_score += array_sum($bonus_tasks_array);
                 if (count($score_array) >= $min_results) {
                     $tasks = new Task();
                     $tasks->where_related_task_set('id', $task_set_id);
                     $tasks->order_by('`task_task_set_rel`.`sorting`', 'asc');
                     $tasks->get_iterated();
                     //$output->debug = $tasks->check_last_query(array('', ''), TRUE);
                     $output->evaluation = $this->parser->parse('backend/tests/evaluation_table.tpl', array('tasks' => $tasks, 'real_points' => $score_array, 'bonus_points' => $bonus_tasks_array, 'real_percentage' => $score_percentage, 'bonus_percentage' => $bonus_tasks_percentage, 'max_results' => $max_results), TRUE);
                     $solution = new Solution();
                     $solution->where('task_set_id', $task_set->id);
                     $solution->where('student_id', $student->id);
                     $solution->get();
                     $save_solution = FALSE;
                     $solution_not_considered = FALSE;
                     $output->points_new = $total_score;
                     if ($solution->exists()) {
                         if ($solution->not_considered == 0) {
                             $output->points_before = $solution->points;
                             if ($solution->points < $total_score || is_null($solution->points)) {
                                 $solution->points = $total_score;
                                 $solution->comment = '';
                                 $solution->teacher_id = NULL;
                                 $solution->best_version = (int) $version;
                                 $solution->revalidate = 0;
                                 $save_solution = TRUE;
                             }
                         } else {
                             $solution_not_considered = TRUE;
                         }
                     } else {
                         $solution->points = $total_score;
                         $solution->comment = '';
                         $solution->teacher_id = NULL;
                         $solution->best_version = (int) $version;
                         $solution->task_set_id = $task_set->id;
                         $solution->student_id = $student->id;
                         $solution->revalidate = 0;
                         $save_solution = TRUE;
                     }
                     if ($save_solution) {
                         $solution->save();
                         $output->result = TRUE;
                         $this->_action_success();
                     } else {
                         if (!$solution_not_considered) {
                             $output->message = sprintf($this->lang->line('admin_tests_test_result_nothing_to_update'), $output->points_new, $output->points_before);
                         } else {
                             $output->message = $this->lang->line('admin_tests_test_result_solution_not_considered');
                         }
                     }
                 } else {
                     $output->message = sprintf($this->lang->line('admin_tests_test_result_minimum_number_of_test_not_selected'), $min_results);
                 }
             } else {
                 $output->message = $this->lang->line('admin_tests_test_result_no_evaluationg_tests');
             }
             $this->db->trans_complete();
         } else {
             $output->message = $this->lang->line('admin_tests_test_result_disabled');
         }
     } else {
         $output->message = $this->lang->line('admin_tests_test_result_input_error');
     }
     $this->test_score->delete_token($token);
     $this->output->set_content_type('application/json');
     $this->output->set_output(json_encode($output));
 }
예제 #15
0
function list_import_lamsfet_tasks_in_sets_relation($sets, $tasks, $tasks_in_sets)
{
    echo 'Starting task_task_set_rel import (' . count($tasks_in_sets) . ') [';
    if (count($tasks_in_sets)) {
        foreach ($tasks_in_sets as $task_in_set) {
            $task_set_id = $sets[$task_in_set->set_id]->_list_id;
            $task_id = $tasks[$task_in_set->task_id]->_list_id;
            $task_set = new Task_set();
            $task_set->get_by_id(intval($task_set_id));
            $task = new Task();
            $task->get_by_id(intval($task_id));
            if ($task_set->exists() && $task->exists()) {
                $task_set->save($task);
                $task_set->set_join_field($task, 'sorting', $task_in_set->order);
                $task_set->set_join_field($task, 'points_total', floatval($task_in_set->points));
                $task_set->set_join_field($task, 'bonus_task', 0);
            } else {
                echo ' ( TASK SET OR TASK NOT FOUND ' . $task_set_id . '(' . $task_in_set->set_id . ')/' . $task_id . '(' . $task_in_set->task_id . ') ) ';
            }
            echo '.';
        }
    }
    echo '] ... done' . "\n";
}
예제 #16
0
 public function render()
 {
     $course = new Course();
     $course->include_related('period');
     $course->get_by_id((int) @$this->config['course_id']);
     $this->parser->assign('course', $course);
     if ($course->exists()) {
         $solutions = new Solution();
         $solutions->select_func('COUNT', '@id', 'count');
         $solutions->where('revalidate', 1);
         $solutions->where_related('task_set', 'id', '${parent}.id');
         $solutions->where_related('student/participant/course', 'id', $course->id);
         $solutions->where_related('student/participant', 'allowed', 1);
         $task_sets = new Task_set();
         $task_sets->select('*');
         $task_sets->select_subquery($solutions, 'solutions_count');
         $task_sets->where_related($course);
         $task_sets->where_related('solution', 'revalidate', 1);
         $task_sets->where_related('solution/student/participant/course', 'id', $course->id);
         $task_sets->where_related('solution/student/participant', 'allowed', 1);
         $task_sets->group_by('id');
         $task_sets->order_by_with_overlay('name', 'ASC');
         $task_sets->get_iterated();
         $this->parser->assign('task_sets', $task_sets);
     }
     $this->parser->parse('widgets/admin/unevaluated_solutions/main.tpl');
 }
예제 #17
0
 /**
  * Loads and inject open task set to template.
  * Smarty template variable $list_open_task_set will be created.
  */
 protected function _initialize_open_task_set()
 {
     $task_set = new Task_set();
     $task_set->get_as_open();
     $this->parser->assign('list_open_task_set', $task_set);
 }
예제 #18
0
 public function index($worker_id = 0)
 {
     $test_queue = new Test_queue();
     $execute_tests = FALSE;
     try {
         $this->db->query('SET SESSION TRANSACTION ISOLATION LEVEL SERIALIZABLE;');
         $this->db->trans_begin();
         $test_queue->where('worker', NULL);
         $test_queue->where('status', 0);
         $test_queue->where('version >', 0);
         $test_queue->group_start(' NOT ');
         $test_queue->where('task_set_id', NULL);
         $test_queue->group_end();
         $test_queue->group_start(' NOT ');
         $test_queue->where('student_id', NULL);
         $test_queue->group_end();
         $test_queue->order_by('priority', 'asc');
         $test_queue->order_by('start', 'asc');
         $test_queue->limit(1);
         $sql_query = $test_queue->get_sql();
         $sql_query = rtrim($sql_query, '; ' . "\n\r") . ' FOR UPDATE;';
         $test_queue->query($sql_query);
         if ($test_queue->exists()) {
             $test_queue->worker = (int) $worker_id;
             $test_queue->status = 1;
             $test_queue->exec_start = date('Y-m-d H:i:s');
             $test_queue->where('worker', NULL);
             $test_queue->where('status', 0);
             if ($test_queue->save()) {
                 $this->db->trans_commit();
                 $execute_tests = TRUE;
             } else {
                 $this->db->trans_rollback();
             }
         } else {
             $this->db->trans_rollback();
         }
     } catch (Exception $e) {
     }
     if ($test_queue->exists() && $execute_tests) {
         //$this->db->query('SET SESSION TRANSACTION ISOLATION LEVEL READ COMMITTED;');
         //$this->db->trans_begin();
         $this->lang->reinitialize_for_idiom($test_queue->system_language);
         $this->lang->load('admin/tests');
         $task_set = new Task_set();
         $task_set->include_related('course', 'test_scoring_deadline');
         $task_set->get_by_id($test_queue->task_set_id);
         $student = new Student();
         $student->get_by_id($test_queue->student_id);
         $tests = new Test();
         $tests->where_related($test_queue);
         $tests->get_iterated();
         try {
             if ($task_set->exists() && $student->exists() && $tests->exists()) {
                 $version = $test_queue->version;
                 $run_evaluation = $task_set->enable_tests_scoring > 0 && $task_set->course_test_scoring_deadline >= date('Y-m-d H:i:s') ? TRUE : FALSE;
                 $score_percent = array();
                 $score_points = array();
                 $bonus_percent = array();
                 $bonus_points = array();
                 $total_tests_count = $tests->result_count();
                 foreach ($tests as $test) {
                     $test_queue->single_test_exec_start = date('Y-m-d H:i:s');
                     $test_queue->save();
                     $files = $task_set->get_student_files($student->id, (int) $version);
                     if (isset($files[(int) $version]['filepath']) && file_exists($files[(int) $version]['filepath'])) {
                         $test_object = $this->load->test($test->type);
                         $test_object->initialize($test);
                         $token = '';
                         //echo 'Test queue ' . $test_queue->id . ' is running test ' . $test->id . ' ... ' . PHP_EOL;
                         try {
                             $test_output = $test_object->run($files[(int) $version]['filepath'], $run_evaluation && $test->enable_scoring > 0, $student->id, $token);
                             $test_score = $test_object->get_last_test_score();
                         } catch (Exception $e) {
                             $test_output = $e->getMessage();
                             $test_score = 0;
                         }
                         $test_queue->set_join_field($test, 'result_text', $test_output);
                         $test_queue->set_join_field($test, 'evaluation_table', $test_object->get_last_test_scoring());
                         $test_queue->set_join_field($test, 'result', $test_object->get_last_exit_code());
                         //echo 'Test queue ' . $test_queue->id . ' is done with test ' . $test->id . ' ... ' . PHP_EOL;
                         if ($run_evaluation && $test->enable_scoring > 0) {
                             $this->db->select('*');
                             $task_id = $test->task_id;
                             $this->db->where('task_set_id', $task_set->id);
                             $this->db->where('task_id', (int) $task_id);
                             $query = $this->db->get('task_task_set_rel');
                             if ($query->num_rows() > 0) {
                                 $task_rel = $query->row_object();
                                 $min = (double) $task_rel->test_min_points;
                                 $max = (double) $task_rel->test_max_points;
                                 $percent = (double) $test_score / 100.0;
                                 $points = (1.0 - $percent) * $min + $percent * $max;
                                 if ($task_rel->bonus_task == 0) {
                                     $test_queue->set_join_field($test, 'percent_points', $test_score);
                                     $test_queue->set_join_field($test, 'points', $points);
                                     $score_percent[$task_id] = isset($score_percent[$task_id]) ? $score_percent[$task_id] + $percent : $percent;
                                     $percent = (double) $score_percent[$task_id];
                                     $points = (1.0 - $percent) * $min + $percent * $max;
                                     $score_points[$task_id] = $points;
                                 } else {
                                     $test_queue->set_join_field($test, 'percent_bonus', $test_score);
                                     $test_queue->set_join_field($test, 'bonus', $points);
                                     $bonus_percent[$task_id] = isset($bonus_percent[$task_id]) ? $bonus_percent[$task_id] + $percent : $percent;
                                     $percent = (double) $bonus_percent[$task_id];
                                     $points = (1.0 - $percent) * $min + $percent * $max;
                                     $bonus_points[$task_id] = $points;
                                 }
                             }
                             $query->free_result();
                         }
                     } else {
                         //$this->db->trans_rollback();
                         $test_queue->worker = NULL;
                         $test_queue->status = 3;
                         $test_queue->finish = date('Y-m-d H:i:s');
                         $test_queue->save();
                         die;
                     }
                 }
                 $tests = new Test();
                 $tests->where_related('task/task_set', 'id', $task_set->id);
                 $tests->where('type', $test_queue->test_type);
                 $tests->where('enable_scoring >', 0);
                 $tests->group_by('task_id');
                 $tests->where('task_task_task_set_rel.bonus_task', 0);
                 $tests->get_iterated();
                 $test_count = $tests->result_count();
                 $min_results = $task_set->test_min_needed > $test_count ? $test_count : $task_set->test_min_needed;
                 $course = new Course();
                 $course->where_related_task_set('id', $task_set->id);
                 $course->get();
                 $min_points_limit = -$course->default_points_to_remove;
                 if ($test_count > 0 && $run_evaluation) {
                     $max_results = $task_set->test_max_allowed < count($score_points) ? $task_set->test_max_allowed : count($score_points);
                     arsort($score_points, SORT_NUMERIC);
                     $i = 0;
                     $total_score = 0;
                     foreach ($score_points as $task_id => $points) {
                         if ($i < $max_results) {
                             $total_score += $points;
                             $i++;
                         } else {
                             break;
                         }
                     }
                     $total_score = $total_score < $min_points_limit ? $min_points_limit : $total_score;
                     $total_bonus = array_sum($bonus_points);
                     $total_score += $total_bonus;
                     if (count($score_points) >= $min_results) {
                         $solution = new Solution();
                         $solution->where('task_set_id', $task_set->id);
                         $solution->where('student_id', $student->id);
                         $solution->get();
                         $save_solution = FALSE;
                         $solution_not_considered = FALSE;
                         $solution_disable_evaluation = FALSE;
                         $best_old_score = $min_points_limit;
                         if ($solution->exists()) {
                             if ($solution->not_considered == 0) {
                                 if ($solution->disable_evaluation_by_tests == 0) {
                                     if ($solution->tests_points < $total_score || is_null($solution->tests_points)) {
                                         $solution->tests_points = $total_score;
                                         $solution->teacher_id = NULL;
                                         $solution->best_version = (int) $version;
                                         $solution->revalidate = 0;
                                         $save_solution = TRUE;
                                     } else {
                                         $best_old_score = $solution->tests_points;
                                     }
                                 } else {
                                     $solution_disable_evaluation = TRUE;
                                 }
                             } else {
                                 $solution_not_considered = TRUE;
                             }
                         } else {
                             $solution->tests_points = $total_score;
                             $solution->comment = '';
                             $solution->teacher_id = NULL;
                             $solution->best_version = (int) $version;
                             $solution->task_set_id = $task_set->id;
                             $solution->student_id = $student->id;
                             $solution->revalidate = 0;
                             $save_solution = TRUE;
                         }
                         if ($save_solution) {
                             $solution->save();
                             $this->parser->clearCache('frontend/tasks/index.tpl');
                             $test_queue->result_message = $this->lang->line('admin_tests_test_result_new_points_added');
                         } else {
                             if (!$solution_disable_evaluation) {
                                 if (!$solution_not_considered) {
                                     $test_queue->result_message = sprintf($this->lang->line('admin_tests_test_result_nothing_to_update'), $total_score, $best_old_score);
                                 } else {
                                     $test_queue->result_message = $this->lang->line('admin_tests_test_result_solution_not_considered');
                                 }
                             } else {
                                 $test_queue->result_message = $this->lang->line('admin_tests_test_result_solution_disable_evaluation');
                             }
                         }
                         $test_queue->points = $total_score - $total_bonus;
                         $test_queue->bonus = $total_bonus;
                     } else {
                         $test_queue->result_message = sprintf($this->lang->line('admin_tests_test_result_minimum_number_of_test_not_selected'), $min_results);
                     }
                     $result_table_tasks = new Task();
                     $result_table_tasks->where_related_task_set('id', $task_set->id);
                     $result_table_tasks->order_by('`task_task_set_rel`.`sorting`', 'asc');
                     $result_table_tasks->get_iterated();
                     $test_queue->result_html = $this->parser->parse('backend/tests/evaluation_table.tpl', array('tasks' => $result_table_tasks, 'real_points' => $score_points, 'bonus_points' => $bonus_points, 'real_percentage' => $score_percent, 'bonus_percentage' => $bonus_percent, 'max_results' => $max_results), TRUE);
                     $test_queue->worker = NULL;
                     $test_queue->status = 2;
                     $test_queue->finish = date('Y-m-d H:i:s');
                     $test_queue->save();
                     //$this->db->trans_commit();
                 } else {
                     if ($total_tests_count && !$run_evaluation) {
                         $test_queue->worker = NULL;
                         $test_queue->status = 2;
                         $test_queue->finish = date('Y-m-d H:i:s');
                         $test_queue->result_message = $this->lang->line('admin_tests_test_result_testing_finished');
                         $test_queue->save();
                         //$this->db->trans_commit();
                     } else {
                         //$this->db->trans_rollback();
                         $test_queue->worker = NULL;
                         $test_queue->status = 3;
                         $test_queue->finish = date('Y-m-d H:i:s');
                         $test_queue->result_message = $this->lang->line('admin_tests_test_result_no_test_selected');
                         $test_queue->save();
                     }
                 }
             } else {
                 //$this->db->trans_rollback();
                 $test_queue->worker = NULL;
                 $test_queue->status = 3;
                 $test_queue->finish = date('Y-m-d H:i:s');
                 $test_queue->result_message = $this->lang->line('admin_tests_test_result_configuration_error');
                 $test_queue->save();
             }
         } catch (Exception $e) {
             //$this->db->trans_rollback();
             $test_queue->worker = NULL;
             $test_queue->status = 3;
             $test_queue->finish = date('Y-m-d H:i:s');
             $test_queue->result_message = $this->lang->line('admin_tests_test_result_execution_error');
             $test_queue->result_html = '<pre>' . $e->getMessage() . '</pre>';
             $test_queue->save();
         }
     }
     //@unlink($test_locks_path . 'worker_' . (int)$worker_id . '_lock.txt');
 }