public function select_project($task_set_id, $task_id, $student_id) { $output = new stdClass(); $output->message = ''; $output->status = FALSE; $this->_transaction_isolation(); $this->db->trans_begin(); $task_set = new Task_set(); $task_set->where('content_type', 'project'); $task_set->get_by_id((int) $task_set_id); $task = new Task(); $task->get_by_id((int) $task_id); $student = new Student(); $student->get_by_id((int) $student_id); $course = new Course(); $course->where_related_task_set($task_set); $course->get(); $participant = new Participant(); $participant->where_related_course($course); $participant->where_related($student); $participant->where('allowed', 1); $participant->get(); $project_selection = new Project_selection(); $project_selection->where_related_student($student); $project_selection->where_related_task_set($task_set); $project_selection->get(); if ($task_set->exists() && $task->exists() && $task_set->is_related_to($task) && $student->exists() && $course->exists() && $participant->exists()) { if ($task_set->get_student_files_count($student->id) == 0) { $all_project_selections = new Project_selection(); $all_project_selections->where_related_task_set($task_set); $all_project_selections->where_related_task($task); $currently_selected = $all_project_selections->count(); $jf_task = $task_set->task->include_join_fields()->get_by_id($task_id); $maximum_selections = (int) $jf_task->join_max_projects_selections; if ($project_selection->exists()) { if (!$project_selection->is_related_to($task)) { if ($currently_selected < $maximum_selections) { $project_selection->save($task); $output->status = TRUE; $output->message = $this->lang->line('admin_task_sets_project_selection_success'); } else { $output->message = $this->lang->line('admin_task_sets_project_selection_no_room'); } } else { $output->message = $this->lang->line('admin_task_sets_project_selection_already_selected'); } } else { if ($currently_selected < $maximum_selections) { $project_selection->save(array('student' => $student, 'task_set' => $task_set, 'task' => $task)); $output->status = TRUE; $output->message = $this->lang->line('admin_task_sets_project_selection_success'); } else { $output->message = $this->lang->line('admin_task_sets_project_selection_no_room'); } } } else { $output->message = $this->lang->line('admin_task_sets_project_selection_already_submited_solutions'); } } else { $output->message = $this->lang->line('admin_task_sets_project_selection_cant_find_data'); } if ($output->status) { $this->db->trans_commit(); $this->_action_success(); } else { $this->db->trans_rollback(); } $this->output->set_content_type('application/json'); $this->output->set_output(json_encode($output)); }
public function valuation($task_set_id, $solution_id) { $this->_add_mathjax(); $solution = new Solution(); $solution->select('`solutions`.*'); $solution->select_subquery('(SELECT SUM(`points_total`) AS `points` FROM `task_task_set_rel` WHERE `task_set_id` = `task_sets`.`id` AND `task_task_set_rel`.`bonus_task` = 0)', 'task_set_total_points'); $solution->include_related('task_set', '*', TRUE, TRUE); $solution->include_related('task_set/course', 'name'); $solution->include_related('task_set/course/period', 'name'); $solution->include_related('task_set/group', 'name'); $solution->include_related('student', array('fullname', 'email')); $solution->include_related('teacher', array('fullname', 'email')); $solution->where('student_id IS NOT NULL'); $solution->where('task_set_id', $task_set_id); $solution->get_by_id($solution_id); $group = new Group(); $group->where_related('participant', 'student_id', $solution->student_id); $group->where_related('participant/course/task_set', 'id', $task_set_id); $group->get(); $project_selection = new Project_selection(); $project_selection->select('`project_selections`.*, `task_task_task_set_rel`.`internal_comment` AS `task_join_internal_comment`'); $project_selection->include_related('task', '*', TRUE, TRUE); $project_selection->include_related('task/task_set', array('id', 'name')); $project_selection->where('task_set_id', $solution->task_set_id); $project_selection->where('student_id', $solution->student_id); $project_selection->where('task_task_sets.id', $solution->task_set_id); $project_selection->get(); $this->load->helper('tests'); $test_types_subtypes = get_all_supported_test_types_and_subtypes(); $this->parser->add_js_file('jquery.activeform.js'); $this->parser->add_js_file('admin_solutions/valuation.js'); $this->parser->add_css_file('admin_solutions.css', array('media' => '')); $this->_add_prettify(); $this->parser->parse('backend/solutions/valuation.tpl', array('solution' => $solution, 'group' => $group, 'test_types' => $test_types_subtypes['types'], 'test_subtypes' => $test_types_subtypes['subtypes'], 'project_selection' => $project_selection, 'add_url' => $this->uri->assoc_to_uri($this->uri->ruri_to_assoc(5)))); }
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)); } }