Пример #1
0
 public function task($task_set_id_url = NULL)
 {
     $this->_add_mathjax();
     $task_set_id = url_get_id($task_set_id_url);
     $this->usermanager->student_login_protected_redirect();
     $this->_initialize_student_menu();
     $this->_select_student_menu_pagetag('tasks');
     $this->parser->add_css_file('frontend_tasks.css');
     $this->parser->add_js_file('tasks/task.js');
     $this->_add_prettify();
     $this->_add_scrollTo();
     $this->_add_jquery_countdown();
     $this->parser->assign('max_filesize', compute_size_with_unit(intval($this->config->item('maximum_solition_filesize') * 1024)));
     $cache_id = $this->usermanager->get_student_cache_id('task_set_' . $task_set_id);
     if (!$this->_is_cache_enabled() || !$this->parser->isCached($this->parser->find_view('frontend/tasks/task.tpl'), $cache_id)) {
         $task_set = $this->get_task_set_by_id($course, $group, $student, $task_set_id);
         if ($course->exists()) {
             $task_sets = $this->filter_valid_task_sets($task_set);
             $this->lang->init_overlays('task_sets', $task_sets, array('name'));
             $filtered_task_set = count($task_sets) == 1 ? $task_sets[0] : new Task_set();
             if ($filtered_task_set->exists()) {
                 $this->load->helper('tests');
                 $test_types_subtypes = get_all_supported_test_types_and_subtypes();
                 $this->lang->init_overlays('task_sets', $filtered_task_set, array('name', 'instructions'));
                 $solution_versions = new Solution_version();
                 $solution_versions->where_related('solution/task_set', 'id', $task_set_id);
                 $solution_versions->where_related('solution', 'student_id', $this->usermanager->get_student_id());
                 $query = $solution_versions->get_raw();
                 $versions_metadata = array();
                 if ($query->num_rows()) {
                     foreach ($query->result() as $row) {
                         $versions_metadata[$row->version] = clone $row;
                     }
                 }
                 $query->free_result();
                 $this->parser->assign('task_set', $filtered_task_set);
                 $this->parser->assign('task_set_can_upload', $this->can_upload_file($filtered_task_set, $course));
                 $this->parser->assign('solution_files', $filtered_task_set->get_student_files($student->id));
                 $this->parser->assign('test_types', $test_types_subtypes['types']);
                 $this->parser->assign('test_subtypes', $test_types_subtypes['subtypes']);
                 $this->parser->assign('versions_metadata', $versions_metadata);
             } else {
                 $this->messages->add_message('lang:tasks_task_task_set_not_found', Messages::MESSAGE_TYPE_ERROR);
                 redirect(create_internal_url('tasks/index'));
             }
         }
         $this->parser->assign(array('course' => $course));
     }
     $this->parser->parse('frontend/tasks/task.tpl', array(), FALSE, $this->_is_cache_enabled(), $cache_id);
 }
Пример #2
0
 public function upload_solution($task_set_id_url, $task_id_url)
 {
     $task_set_id = url_get_id($task_set_id_url);
     $task_id = url_get_id($task_id_url);
     $this->_transaction_isolation();
     $this->db->trans_begin();
     $date = date('Y-m-d H:i:s');
     $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_set->where_related($course);
     $task_set->where('published', 1);
     $task_set->group_start();
     $task_set->where('publish_start_time <=', $date);
     $task_set->or_where('publish_start_time', NULL);
     $task_set->group_end();
     $task_set->get_by_id($task_set_id);
     $task = $task_set->task->include_join_fields()->get_by_id($task_id);
     $project_selection = new Project_selection();
     $project_selection->where_related($student);
     $project_selection->where_related($task_set);
     $project_selection->where_related($task);
     $project_selection->get();
     if ($student->exists() && $course->exists() && $task_set->exists() && $task->exists() && $project_selection->exists()) {
         if ($date <= $task_set->upload_end_time) {
             $config['upload_path'] = 'private/uploads/solutions/task_set_' . intval($task_set_id) . '/';
             $config['allowed_types'] = 'zip';
             $config['max_size'] = intval($this->config->item('maximum_solition_filesize'));
             $current_version = $task_set->get_student_file_next_version($student->id);
             $config['file_name'] = $student->id . '_' . $this->normalize_student_name($student) . '_' . substr(md5(time() . rand(-500000, 500000)), 0, 4) . '_' . $current_version . '.zip';
             @mkdir($config['upload_path'], DIR_READ_MODE);
             $this->load->library('upload', $config);
             if ($this->upload->do_upload('file')) {
                 $solution = new Solution();
                 $solution->where('task_set_id', $task_set->id);
                 $solution->where('student_id', $student->id);
                 $solution->get();
                 $revalidate = 1;
                 if ($solution->exists()) {
                     $solution->ip_address = $_SERVER["REMOTE_ADDR"];
                     $solution->revalidate = $revalidate;
                     $solution->save();
                 } else {
                     $solution = new Solution();
                     $solution->ip_address = $_SERVER["REMOTE_ADDR"];
                     $solution->revalidate = $revalidate;
                     $solution->save(array('student' => $student, 'task_set' => $task_set));
                 }
                 $solution_version = new Solution_version();
                 $solution_version->ip_address = $_SERVER["REMOTE_ADDR"];
                 $solution_version->version = $current_version;
                 $solution_version->save($solution);
                 if ($this->db->trans_status()) {
                     $log = new Log();
                     $log->add_student_solution_upload_log(sprintf($this->lang->line('projects_task_solution_upload_log_message'), $config['file_name']), $student, $solution->id);
                     $this->db->trans_commit();
                     $this->messages->add_message('lang:projects_task_solution_uploaded', Messages::MESSAGE_TYPE_SUCCESS);
                     $this->_action_success();
                     $this->output->set_internal_value('task_set_id', $solution->task_set_id);
                     $this->output->set_internal_value('task_id', $task->id);
                 } else {
                     $this->db->trans_rollback();
                     @unlink($config['upload_path'] . $config['file_name']);
                     $this->messages->add_message('lang:projects_task_solution_canceled_due_db_error', Messages::MESSAGE_TYPE_ERROR);
                 }
                 redirect(create_internal_url('projects/task/' . $task_set_id_url . '/' . $task_id_url));
             } else {
                 $this->db->trans_rollback();
                 $this->parser->assign('file_error_message', $this->upload->display_errors('', ''));
                 $this->task($task_set_id_url, $task_id_url);
             }
         } else {
             $this->db->trans_rollback();
             $this->messages->add_message('lang:projects_task_solution_upload_time_error', Messages::MESSAGE_TYPE_ERROR);
             redirect(create_internal_url('projects/task/' . $task_set_id_url . '/' . $task_id_url));
         }
     } else {
         $this->db->trans_rollback();
         $this->messages->add_message('lang:projects_task_solution_database_data_wrong_error', Messages::MESSAGE_TYPE_ERROR);
         redirect(create_internal_url('projects/task/' . $task_set_id_url . '/' . $task_id_url));
     }
 }