コード例 #1
0
ファイル: moss.php プロジェクト: andrejjursa/list-lms
 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();
         }
     }
 }
コード例 #2
0
ファイル: solutions.php プロジェクト: andrejjursa/list-lms
 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;
 }
コード例 #3
0
ファイル: comparator.php プロジェクト: andrejjursa/list-lms
 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();
     }
 }