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'); }
public function run_comparation() { $task_sets_setup_data = $this->input->post('task_sets_setup'); $solutions_data = $this->input->post('solutions'); $moss_setup_data = $this->input->post('moss_setup'); $moss_base_files_data = $this->input->post('moss_base_files'); $course = new Course(); $course->get_by_id((int) $task_sets_setup_data['course']); $task_set = new Task_set(); $task_set->where_related($course); $task_set->get_by_id(isset($task_sets_setup_data['task_set']) ? (int) $task_sets_setup_data['task_set'] : 0); $this->config->load('moss'); $languages = $this->config->item('moss_langs_for_list'); asort($languages); $this->parser->assign(array('course' => $course, 'task_set' => $task_set, 'languages' => $languages)); $this->parser->assign('moss_enabled', $this->is_moss_user_id_set()); if ($course->exists() && $task_set->exists()) { $this->load->library('form_validation'); $this->form_validation->set_rules('solutions', 'lang:admin_moss_list_solutions_form_field_solution_selection', 'callback__selected_solutions'); $this->form_validation->set_rules('moss_setup[l]', 'lang:admin_moss_list_solutions_form_field_language', 'required'); $this->form_validation->set_rules('moss_setup[m]', 'lang:admin_moss_list_solutions_form_field_sensitivity', 'required|integer|greater_than[1]'); $this->form_validation->set_rules('moss_setup[n]', 'lang:admin_moss_list_solutions_form_field_matching_files', 'required|integer|greater_than[1]'); $this->form_validation->set_message('_selected_solutions', $this->lang->line('admin_moss_list_solutions_validation_callback_selected_solutions')); if ($this->form_validation->run() && $this->is_moss_user_id_set()) { $solutions = new Solution(); $solutions->include_related('student'); $solutions->where_related($task_set); $solutions->order_by_related_as_fullname('student', 'fullname', 'asc'); $solutions->get_iterated(); $this->parser->assign('solutions', $solutions); $tasks = new Task(); $tasks->where_related($task_set); $tasks->get_iterated(); $base_files_list = array(); foreach ($tasks as $task) { $base_files_list[$task->id] = array('task_id' => $task->id, 'task_name' => $this->lang->get_overlay_with_default('tasks', $task->id, 'name', $task->name), 'files' => $this->construct_base_files_for_task($task->id)); } $this->parser->assign('base_files_list', $base_files_list); $path = $this->get_random_hash_folder($course->id, $task_set->id); $path_source = $path . '/source'; $path_base = $path . '/base'; @mkdir($path_source, DIR_WRITE_MODE, TRUE); @mkdir($path_base, DIR_WRITE_MODE, TRUE); $all_extracted = TRUE; $moss_langs_extensions = $this->config->item('moss_langs_file_extensions'); if (isset($moss_langs_extensions[$moss_setup_data['l']])) { $file_extensions = $moss_langs_extensions[$moss_setup_data['l']]; } else { $all_extracted = FALSE; } foreach ($solutions_data as $id => $config) { if (!$all_extracted) { break; } if (isset($config['selected']) && $config['selected'] == 1) { set_time_limit(120); $version = isset($config['version']) ? $config['version'] : 0; $student = isset($config['student']) ? $config['student'] : 0; $file = $task_set->get_student_files($student, $version); if (count($file) == 1) { $file = $file[$version]; $subdir = '/' . normalize($file['file_name']) . '_sid-' . $file['student_id'] . '_ver-' . $file['version']; $extract_path = $path_source . $subdir; @mkdir($extract_path, DIR_WRITE_MODE, TRUE); $status = $task_set->extract_student_zip_to_folder($file['file'], $extract_path, $file_extensions); $all_extracted = $all_extracted && $status; } } } if (is_array($moss_base_files_data) && count($moss_base_files_data)) { foreach ($moss_base_files_data as $task_id => $path_array) { if (!$all_extracted) { break; } if (is_array($path_array) && count($path_array)) { foreach ($path_array as $path_hash => $file_path) { if (!$all_extracted) { break; } if (preg_match('/\\.zip(?P<indexNumberBox>\\[(?P<zipIndexNumber>[0-9]+)\\])$/', $file_path, $matches)) { $zipfile = mb_substr($file_path, 0, mb_strlen($file_path) - mb_strlen($matches['indexNumberBox'])); $zipindex = (int) $matches['zipIndexNumber']; $zip = new ZipArchive(); if ($zip->open($zipfile)) { set_time_limit(120); @mkdir($path_base . '/' . $task_id . '/' . $path_hash, DIR_WRITE_MODE, TRUE); if (!$zip->extractTo($path_base . '/' . $task_id . '/' . $path_hash, $zip->getNameIndex($zipindex))) { $all_extracted = FALSE; } $zip->close(); } else { $all_extracted = FALSE; } } else { set_time_limit(120); @mkdir($path_base . '/' . $task_id . '/' . $path_hash, DIR_WRITE_MODE, TRUE); $path_info = pathinfo($file_path); if (!copy($file_path, $path_base . '/' . $task_id . '/' . $path_hash . '/' . $path_info['basename'])) { $all_extracted = FALSE; } } } } } } if (!$all_extracted) { unlink_recursive($path, TRUE); } $this->parser->assign('all_extracted', $all_extracted); $this->parser->assign('path', $path); $this->parser->assign('moss_config', $moss_setup_data); $this->parser->parse('backend/moss/run_comparation.tpl'); } else { $this->list_solutions(); } } }
private function inject_batch_valuation($task_set_id) { $filter = $this->input->post('filter'); $filter = is_array($filter) && count($filter) > 0 ? $filter : $this->get_batch_valuation_filter((int) $task_set_id); $this->store_batch_valuation_filter($filter, (int) $task_set_id); $task_set = new Task_set(); $task_set->get_by_id($task_set_id); $task_set_permissions = new Task_set_permission(); $task_set_permissions->where_related($task_set); $task_set_permissions->where('enabled', 1); $task_set_permissions->get_iterated(); $solutions = new Solution(); $solutions->where_related($task_set); $solutions->group_by('student_id'); if (isset($filter['group']) && (int) $filter['group'] > 0) { $solutions->where_related('student/participant/group', 'id', (int) $filter['group']); } $solutions->get_iterated(); $additional_student_ids = array(0); foreach ($solutions as $solution) { $additional_student_ids[] = $solution->student_id; } $data = array(); if ($task_set->exists()) { $students = new Student(); $students->where_related('participant', 'allowed', 1); $students->where_related('participant/course/task_set', 'id', intval($task_set_id)); if ($task_set_permissions->result_count() == 0) { if (!is_null($task_set->group_id)) { $students->where_related('participant/group', 'id', intval($task_set->group_id)); } } else { $group_ids = array(); foreach ($task_set_permissions as $task_set_permission) { $group_ids[] = (int) $task_set_permission->group_id; } $students->where_in_related('participant/group', 'id', $group_ids); } $students->include_related('solution'); $students->add_join_condition('`solutions`.`task_set_id` = ?', array($task_set->id)); $students->order_by_as_fullname('fullname', 'asc'); $students->order_by('email', 'asc'); if (isset($filter['group']) && (int) $filter['group'] > 0) { $students->where_related('participant/group', 'id', (int) $filter['group']); } $students->or_where_in('id', $additional_student_ids); $students->get_iterated(); foreach ($students as $student) { $data[$student->id] = clone $student; } } $this->parser->assign('batch_valuation_students', $data); }
public function run_comparation() { $task_sets_setup_data = $this->input->post('task_sets_setup'); $solutions_data = $this->input->post('solutions'); $comparator_setup_data = $this->input->post('comparator_setup'); $course = new Course(); $course->get_by_id((int) $task_sets_setup_data['course']); $task_set = new Task_set(); $task_set->where_related($course); $task_set->get_by_id(isset($task_sets_setup_data['task_set']) ? (int) $task_sets_setup_data['task_set'] : 0); $this->parser->assign(array('course' => $course, 'task_set' => $task_set)); if ($course->exists() && $task_set->exists()) { $this->load->library('form_validation'); $this->form_validation->set_rules('solutions', 'lang:admin_comparator_list_solutions_form_field_solution_selection', 'callback__selected_solutions'); $this->form_validation->set_rules('comparator_setup[threshold]', 'lang:admin_comparator_list_solutions_form_field_threshold', 'required|numeric|greater_than_equal[0]|less_than_equal[1]'); $this->form_validation->set_rules('comparator_setup[min_tree_size]', 'lang:admin_comparator_list_solutions_form_field_min_tree_size', 'required|integer|greater_than_equal[1]'); $this->form_validation->set_rules('comparator_setup[max_cutted_tree_size]', 'lang:admin_comparator_list_solutions_form_field_max_cutted_tree_size', 'required|integer|greater_than_field_or_equal[comparator_setup[min_tree_size]]'); $this->form_validation->set_rules('comparator_setup[branching_factor]', 'lang:admin_comparator_list_solutions_form_field_branching_factor', 'required|integer|greater_than_equal[1]'); $this->form_validation->set_rules('comparator_setup[min_similarity]', 'lang:admin_comparator_list_solutions_form_field_minimum_similarity', 'required|numeric|greater_than_equal[0]|less_than_equal[1]'); $this->form_validation->set_rules('comparator_setup[timeout]', 'lang:admin_comparator_list_solutions_form_field_timeout', 'required|integer|greater_than_equal[1]'); $this->form_validation->set_message('_selected_solutions', $this->lang->line('admin_comparator_list_solutions_validation_callback_selected_solutions')); if ($this->form_validation->run()) { $solutions = new Solution(); $solutions->include_related('student'); $solutions->where_related($task_set); $solutions->order_by_related_as_fullname('student', 'fullname', 'asc'); $solutions->get_iterated(); $this->parser->assign('solutions', $solutions); $path = $this->get_random_hash_folder($course->id, $task_set->id); $path_source = $path . '/source'; $path_output = $path . '/output'; @mkdir($path_source, DIR_WRITE_MODE, TRUE); @mkdir($path_output, DIR_WRITE_MODE, TRUE); $all_extracted = TRUE; foreach ($solutions_data as $id => $config) { if (isset($config['selected']) && $config['selected'] == 1) { set_time_limit(120); $version = isset($config['version']) ? $config['version'] : 0; $student = isset($config['student']) ? $config['student'] : 0; $file = $task_set->get_student_files($student, $version); if (count($file) == 1) { $file = $file[$version]; $subdir = '/' . normalize($file['file_name']) . '_sid-' . $file['student_id'] . '_ver-' . $file['version']; $extract_path = $path_source . $subdir; @mkdir($extract_path, DIR_WRITE_MODE, TRUE); $status = $task_set->extract_student_zip_to_folder($file['file'], $extract_path, array('java')); $all_extracted = $all_extracted && $status; } } } if (!$all_extracted) { unlink_recursive($path, TRUE); } $this->parser->assign('all_extracted', $all_extracted); $this->parser->assign('path', $path); $this->parser->assign('comparator_config', array('t' => $comparator_setup_data['threshold'], 'm' => $comparator_setup_data['min_tree_size'], 'cut' => $comparator_setup_data['max_cutted_tree_size'], 'bf' => $comparator_setup_data['branching_factor'], 'mp' => $comparator_setup_data['min_similarity'], 'timeout' => $comparator_setup_data['timeout'] * 60000)); $this->parser->parse('backend/comparator/run_comparation.tpl'); } else { $this->list_solutions(); } } else { $this->list_solutions(); } }