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 select_project($task_set_id_url = NULL, $task_id_url = NULL) { $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(); $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(); if ($course->exists()) { $task_set = new Task_set(); $task_set->where_related('course', $course); $task_set->where('published', 1); $task_set->get_by_id($task_set_id); if ($task_set->exists()) { if ($task_set->get_student_files_count($student->id) == 0 && date('Y-m-d H:i:s') <= $task_set->project_selection_deadline) { $task = $task_set->task->include_join_fields()->get_by_id($task_id); if ($task->exists()) { $project_selection = new Project_selection(); $project_selection->where_related('student', $student); $project_selection->where_related('task_set', $task_set); $project_selection->get(); $can_continue = TRUE; if ($project_selection->exists()) { if ($project_selection->task_id != $task->id) { $project_selection->task_id = $task->id; } else { $can_continue = FALSE; } } else { $project_selection->task_id = $task->id; $project_selection->task_set_id = $task_set->id; $project_selection->student_id = $student->id; } if ($can_continue) { $project_selection_count = new Project_selection(); $project_selection_count->where_related('task_set', $task_set); $project_selection_count->where_related('task', $task); $count = $project_selection_count->count(); if ($task->join_max_projects_selections > $count) { if ($project_selection->save()) { $this->db->trans_commit(); $this->_action_success(); $this->output->set_internal_value('task_set_id', $task_set->id); $this->messages->add_message($this->lang->line('projects_selection_success'), Messages::MESSAGE_TYPE_SUCCESS); redirect(create_internal_url('projects/task/' . $task_set_id_url . '/' . $task_id_url)); } else { $this->db->trans_rollback(); $this->messages->add_message($this->lang->line('projects_selection_error_save_failed'), 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($this->lang->line('projects_selection_error_no_free_space'), 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($this->lang->line('projects_selection_error_already_selected'), 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($this->lang->line('projects_selection_error_task_not_found'), Messages::MESSAGE_TYPE_ERROR); redirect(create_internal_url('projects/selection/' . $task_set_id_url)); } } else { $this->db->trans_rollback(); $this->messages->add_message($this->lang->line('projects_selection_error_selection_disabled'), Messages::MESSAGE_TYPE_ERROR); redirect(create_internal_url('projects/selection/' . $task_set_id_url)); } } else { $this->db->trans_rollback(); $this->messages->add_message($this->lang->line('projects_selection_error_task_set_not_found'), Messages::MESSAGE_TYPE_ERROR); redirect(create_internal_url('projects')); } } else { $this->db->trans_rollback(); $this->messages->add_message($this->lang->line('projects_selection_error_no_active_course'), Messages::MESSAGE_TYPE_ERROR); redirect(create_internal_url('projects')); } }