Example #1
0
 public function edit()
 {
     $this->_select_teacher_menu_pagetag('task_sets');
     $url = $this->uri->ruri_to_assoc(3);
     $task_set_id = isset($url['task_set_id']) ? intval($url['task_set_id']) : intval($this->input->post('task_set_id'));
     $task_set = new Task_set();
     $task_set->get_by_id($task_set_id);
     $ps_data = array();
     $nps_data = array();
     if ($task_set->exists() && $task_set->content_type == 'project') {
         $project_selections = new Project_selection();
         $project_selections->select('*');
         $project_selections->include_related('student', array('fullname', 'email'));
         $project_selections->where_related($task_set);
         $project_selections->include_related('task', 'name');
         $project_selections->include_related('task/task_set', 'id');
         $project_selections->where_related('task/task_set', 'id', $task_set->id);
         $project_selections->order_by('task_task_task_set_rel.sorting', 'ASC');
         $project_selections->order_by_related_as_fullname('student', 'fullname', 'asc');
         $project_selections->get();
         if ($project_selections->exists()) {
             foreach ($project_selections->all as $project_selection) {
                 $ps_data[$project_selection->task_id][] = $project_selection;
             }
         }
         $project_selections->select_func('COUNT', '@id', 'count');
         $project_selections->where('task_set_id', 'participant_course_task_sets.id', false);
         $project_selections->where_related('student', 'id', '${parent}.id');
         $students = new Student();
         $students->where_related('participant/course/task_set', $task_set);
         $students->where_related('participant', 'allowed', 1);
         $students->where_subquery(0, $project_selections);
         $students->order_by_as_fullname('fullname', 'asc');
         $students->get();
         if ($students->exists()) {
             $nps_data = $students->all;
         }
     }
     $this->_add_tinymce4();
     $this->parser->add_js_file('jquery.activeform.js');
     $this->parser->add_js_file('admin_task_sets/edit.js');
     $this->parser->add_js_file('admin_task_sets/form.js');
     $this->parser->add_css_file('admin_task_sets.css');
     $this->inject_courses();
     $this->inject_languages();
     $this->inject_test_types();
     $this->inject_course_groups();
     $this->inject_course_group_rooms();
     $this->inject_course_task_set_types();
     $this->parser->parse('backend/task_sets/edit.tpl', array('task_set' => $task_set, 'project_selections' => $ps_data, 'not_project_selections' => $nps_data));
 }
Example #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));
     }
 }