Ejemplo n.º 1
0
 public function index()
 {
     $this->_initialize_student_menu();
     $this->_select_student_menu_pagetag('groups');
     $this->parser->add_css_file('frontend_groups.css');
     $cache_id = $this->usermanager->get_student_cache_id();
     if (!$this->_is_cache_enabled() || !$this->parser->isCached($this->parser->find_view('frontend/groups/index.tpl'), $cache_id)) {
         $student = new Student();
         $student->get_by_id($this->usermanager->get_student_id());
         $course = new Course();
         $course->where_related_active_for_student($student);
         $course->where_related('participant/student', $student);
         $course->where_related_participant('allowed', 1);
         $course->get();
         $can_change_group = FALSE;
         if ($course->exists()) {
             if (is_null($course->groups_change_deadline) || date('U', strtotime($course->groups_change_deadline)) >= time()) {
                 $can_change_group = TRUE;
             }
         }
         smarty_inject_days();
         $this->parser->assign(array('course' => $course, 'can_change_group' => $can_change_group));
     }
     $this->parser->parse('frontend/groups/index.tpl', array(), FALSE, $this->_is_cache_enabled(), $cache_id);
 }
Ejemplo n.º 2
0
 public function download_solutions($course_id)
 {
     $course = new Course();
     $course->get_by_id((int) $course_id);
     if ($course->exists()) {
         $course->download_all_solutions();
     } else {
         $this->messages->add_message('lang:admin_courses_message_cant_download_solutions', Messages::MESSAGE_TYPE_ERROR);
         redirect(create_internal_url('admin_courses'));
     }
 }
Ejemplo n.º 3
0
 public function activate_course($course_id)
 {
     $this->_initialize_student_menu();
     $this->output->set_content_type('application/json');
     $output = new stdClass();
     $output->status = FALSE;
     $output->message = '';
     $output->content = '';
     $output->metainfo = '';
     $this->_transaction_isolation();
     $this->db->trans_begin();
     $student = new Student();
     $student->get_by_id($this->usermanager->get_student_id());
     $course = new Course();
     $course->get_by_id($course_id);
     if ($course->exists()) {
         $participant = $student->participant->where_related($course)->where('allowed', 1)->get();
         if ($participant->exists()) {
             $student->save($course, 'active_course');
             $this->db->trans_commit();
             $this->usermanager->set_student_data_to_smarty();
             $period = $course->period->get();
             $output->content = $this->parser->parse('frontend/courses/period_courses.tpl', array('period' => $period), TRUE);
             $output->metainfo = $this->parser->parse('partials/frontend_general/selected_course.tpl', array(), TRUE);
             $output->status = TRUE;
             $output->message = sprintf($this->lang->line('courses_message_switched_to_course'), $this->lang->text($course->name) . ' / ' . $this->lang->text($period->name));
             $this->_action_success();
         } else {
             $output->message = $this->lang->line('courses_message_cant_switch_to_unsigned_course');
             $this->db->trans_rollback();
         }
     } else {
         $output->message = $this->lang->line('courses_message_course_not_found');
         $this->db->trans_rollback();
     }
     $this->output->set_output(json_encode($output));
 }
Ejemplo n.º 4
0
 public function add_participant()
 {
     $this->load->library('form_validation');
     $this->form_validation->set_rules('participant[course]', 'lang:admin_participants_form_field_course', 'required');
     $this->form_validation->set_rules('participant[students][]', 'lang:admin_participants_form_field_students', 'required');
     if ($this->form_validation->run()) {
         $this->_transaction_isolation();
         $this->db->trans_begin();
         $process_ok = TRUE;
         $participant_data = $this->input->post('participant');
         $course = new Course();
         $course->get_by_id(intval($participant_data['course']));
         $group = new Group();
         $group->get_by_id(intval(@$participant_data['group']));
         if (!$course->exists()) {
             $this->db->trans_rollback();
             $this->messages->add_message('lang:admin_participants_message_course_not_exists', Messages::MESSAGE_TYPE_ERROR);
             $process_ok = FALSE;
         }
         if ($process_ok && $course->exists()) {
             if ($group->exists() && !$group->is_related_to($course)) {
                 $this->db->trans_rollback();
                 $this->messages->add_message('lang:admin_participants_message_group_not_belongs_to_course', Messages::MESSAGE_TYPE_ERROR);
                 $process_ok = FALSE;
             }
         }
         $disapproved = 0;
         $added = 0;
         if ($process_ok) {
             foreach ($participant_data['students'] as $student_id) {
                 $student = new Student();
                 $student->where_related('participant/course', 'id', $course->id);
                 $student->get_by_id($student_id);
                 if ($student->exists()) {
                     continue;
                 }
                 $student->get_by_id($student_id);
                 $participant = new Participant();
                 $participant->allowed = intval(@$participant_data['allowed']);
                 $participant->save(array($student, $course, $group));
                 $added++;
                 if ($participant->allowed == 1) {
                     $disallowe_participant = FALSE;
                     if ($course->participant->where('allowed', 1)->count() > intval($course->capacity)) {
                         $disallowe_participant = TRUE;
                     }
                     if ($group->exists()) {
                         $group_for_test = new Group();
                         $rooms = $group_for_test->room;
                         $rooms->select_min('capacity');
                         $rooms->where('group_id', '${parent}.id', FALSE);
                         $group_for_test->select_subquery($rooms, 'group_capacity');
                         $group_for_test->include_related_count('participant');
                         $group_for_test->where_related_participant('allowed', 1);
                         $group_for_test->get_by_id(intval($group->id));
                         if ($group_for_test->exists()) {
                             if (intval($group_for_test->participant_count) > intval($group_for_test->group_capacity)) {
                                 $disallowe_participant = TRUE;
                             }
                         }
                     }
                     if ($disallowe_participant) {
                         $participant->allowed = 0;
                         $participant->save();
                         $disapproved++;
                     }
                 }
             }
         }
         if ($this->db->trans_status() && $process_ok) {
             $this->db->trans_commit();
             $info_approved = intval(@$participant_data['allowed']) == 1 ? $added - $disapproved : 0;
             $info_disappoved = intval(@$participant_data['allowed']) == 1 ? $disapproved : $added;
             $message = sprintf($this->lang->line('admin_participants_message_addition_successfull'), $info_approved, $info_disappoved);
             $this->messages->add_message($message, Messages::MESSAGE_TYPE_SUCCESS);
             $this->_action_success();
         } else {
             $this->db->trans_rollback();
             $this->messages->add_message('lang:admin_participants_messages_error_in_addition_transaction', Messages::MESSAGE_TYPE_ERROR);
         }
         redirect(create_internal_url('admin_participants/add_participant_form'));
     } else {
         $this->add_participant_form();
     }
 }
Ejemplo n.º 5
0
 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;
 }
Ejemplo n.º 6
0
 public function import_single_line()
 {
     $this->output->set_content_type('application/json');
     $firstname = $this->input->post('firstname');
     $lastname = $this->input->post('lastname');
     $fullname = $this->input->post('fullname');
     $email = $this->input->post('email');
     $options = $this->input->post('options');
     $this->parser->assign('firstname', $firstname);
     $this->parser->assign('lastname', $lastname);
     $this->parser->assign('fullname', $fullname);
     $this->parser->assign('email', $email);
     if ((trim($firstname) != '' && trim($lastname) != '' || trim($fullname) != '') && trim($email) != '') {
         $student_fullname = trim($fullname) != '' ? trim($fullname) : trim($firstname) . ' ' . trim($lastname);
         $this->_transaction_isolation();
         $this->db->trans_begin();
         $student = new Student();
         $student->where('email', trim($email));
         $student->get();
         if ($student->exists()) {
             if ($student->fullname != $student_fullname) {
                 $student->fullname = $student_fullname;
                 $student->save();
                 $this->db->trans_commit();
             } else {
                 $this->db->trans_rollback();
             }
             $this->parser->assign('error_message', 'lang:admin_students_csv_import_error_message_student_exists');
         } else {
             $this->load->library('form_validation');
             if ($this->form_validation->valid_email(trim($email))) {
                 $student->email = trim($email);
                 $student->fullname = $student_fullname;
                 $password = '';
                 if ($options['password_type'] == 'default') {
                     $password = $this->config->item('student_import_default_password');
                 } elseif ($options['password_type'] == 'random') {
                     $password = md5(base64_encode(rand(0, 99999999999) . time() . $student->fullname . $student->email) . $this->config->item('encryption_key'));
                     $password = substr($password, 0, rand(6, 20));
                 }
                 $student->password = $password != '' ? sha1($password) : '';
                 $student->language = $this->config->item('language');
                 if ($student->save()) {
                     $this->parser->assign('password', $password);
                     $this->db->trans_commit();
                     $this->parser->assign('success_message', 'lang:admin_students_csv_import_successfully_imported');
                     if ((bool) $options['send_mail']) {
                         if ($password == '') {
                             $this->_transaction_isolation();
                             $this->db->trans_begin();
                             $student->generate_random_password_token();
                             $this->db->trans_commit();
                         }
                         $this->_init_language_for_student($student);
                         $this->load->library('email');
                         $this->email->from_system();
                         $this->email->to($student->email);
                         $this->email->subject($this->lang->line('admin_students_csv_import_email_subject'));
                         $this->email->build_message_body('file:emails/backend/students/csv_import_email.tpl', array('student' => $student, 'password' => $password));
                         $sent = $this->email->send();
                         $this->_init_language_for_teacher();
                         if ($sent) {
                             $this->parser->assign('email_success_message', 'lang:admin_students_csv_import_email_sent_successfully');
                         } else {
                             $this->parser->assign('email_error_message', 'lang:admin_students_csv_import_email_sent_failed');
                         }
                     }
                 } else {
                     $this->db->trans_rollback();
                     $this->parser->assign('error_message', 'lang:admin_students_csv_import_error_message_student_save_error');
                 }
             } else {
                 $this->db->trans_rollback();
                 $this->parser->assign('error_message', 'lang:admin_students_csv_import_error_message_student_email_invalid');
             }
         }
         if ($student->exists()) {
             $this->parser->assign('student_id', $student->id);
             if (intval($options['assign_to_course']) > 0) {
                 $this->_transaction_isolation();
                 $this->db->trans_begin();
                 $course = new Course();
                 $course->get_by_id(intval($options['assign_to_course']));
                 if ($course->exists()) {
                     $participant = new Participant();
                     $participant->where_related('student', 'id', $student->id);
                     $participant->where_related('course', 'id', $course->id);
                     $participant->get();
                     if (!$participant->exists()) {
                         $participant->allowed = 0;
                         if ($participant->save(array('student' => $student, 'course' => $course))) {
                             $this->db->trans_commit();
                             $this->parser->assign('course_assignment_success_message', 'lang:admin_students_csv_import_successfully_added_course_participation');
                             $this->db->trans_begin();
                             $course = new Course();
                             $course->get_by_id(intval($options['assign_to_course']));
                             $participant->allowed = 1;
                             $participant->save();
                             $participants = new Participant();
                             $participants->where_related($course);
                             $participants->where('allowed', 1);
                             $participants_count = $participants->count();
                             if ($participants_count <= $course->capacity) {
                                 $this->db->trans_commit();
                                 $this->parser->assign('course_assignment_approwal_success_message', 'lang:admin_students_csv_import_successfully_added_course_participation_approwal');
                             } else {
                                 $this->db->trans_rollback();
                                 $this->parser->assign('course_assignment_approwal_error_message', 'lang:admin_students_csv_import_error_message_added_course_participation_approwal');
                             }
                         } else {
                             $this->db->trans_rollback();
                             $this->parser->assign('course_assignment_error_message', 'lang:admin_students_csv_import_error_message_participation_save_failed');
                         }
                     } else {
                         $this->db->trans_rollback();
                         $this->parser->assign('course_assignment_error_message', 'lang:admin_students_csv_import_error_message_already_in_course');
                     }
                 } else {
                     $this->db->trans_rollback();
                     $this->parser->assign('course_assignment_error_message', 'lang:admin_students_csv_import_error_message_course_not_found');
                 }
             }
         }
     } else {
         $this->parser->assign('error_message', 'lang:admin_students_csv_import_error_message_nothing_to_import');
     }
     $html = $this->parser->parse('backend/students/import_single_line.tpl', array(), TRUE);
     $this->output->set_output(json_encode($html));
 }
Ejemplo n.º 7
0
 private function get_task_set_by_id(&$course, &$group, &$student, $task_set_id)
 {
     $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_set2 = new Task_set();
     $group = new Group();
     if ($course->exists()) {
         $group->where_related_participant('student_id', $student->id);
         $group->where_related_participant('course_id', $course->id);
         $group->get();
         $task_set->select('`task_sets`.*, `rooms`.`time_day` AS `pb_time_day`, `rooms`.`time_begin` AS `pb_time_begin`, `rooms`.`id` AS `pb_room_id`, `task_sets`.`publish_start_time` AS `pb_publish_start_time`, `task_sets`.`upload_end_time` AS `pb_upload_end_time`');
         $task_set->where('published', 1);
         $task_set->where_related_course($course);
         $task_set->include_related('solution');
         $task_set->add_join_condition('`solutions`.`student_id` = ?', array($student->id));
         $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)');
         $task_set->group_start();
         $task_set->or_where('group_id', NULL);
         $task_set->or_where('group_id', $group->id);
         $task_set->group_end();
         $task_set->include_related('room', '*', TRUE, TRUE);
         $task_set->include_related_count('task', 'total_tasks');
         $task_set->include_related('task_set_type');
         $task_set->select_subquery('(SELECT SUM(`points_total`) AS `points` FROM `task_task_set_rel` WHERE `task_set_id` = `${parent}`.`id` AND `task_task_set_rel`.`bonus_task` = 0)', 'total_points');
         $task_set->where('id', $task_set_id);
         $task_set->include_related('course', 'test_scoring_deadline');
         $task_set->where('content_type', 'task_set');
         $task_set2->select('`task_sets`.*, `task_set_permission_rooms`.`time_day` AS `pb_time_day`, `task_set_permission_rooms`.`time_begin` AS `pb_time_begin`, `task_set_permission_rooms`.`id` AS `pb_room_id`, `task_set_permissions`.`publish_start_time` AS `pb_publish_start_time`, `task_set_permissions`.`upload_end_time` AS `pb_upload_end_time`');
         $task_set2->where('published', 1);
         $task_set2->where_related_course($course);
         $task_set2->where_related('task_set_permission', 'group_id', $group->id);
         $task_set2->where_related('task_set_permission', 'enabled', 1);
         $task_set2->include_related('solution');
         $task_set2->add_join_condition('`solutions`.`student_id` = ?', array($student->id));
         $task_set2->include_related('task_set_permission/room', '*', 'room', TRUE);
         $task_set2->include_related_count('task', 'total_tasks');
         $task_set2->include_related('task_set_type');
         $task_set2->select_subquery('(SELECT SUM(`points_total`) AS `points` FROM `task_task_set_rel` WHERE `task_set_id` = `${parent}`.`id` AND `task_task_set_rel`.`bonus_task` = 0)', 'total_points');
         $task_set2->where('id', $task_set_id);
         $task_set2->include_related('course', 'test_scoring_deadline');
         $task_set2->where('content_type', 'task_set');
         $task_set3 = new Task_set();
         $task_set3->select('`task_sets`.*, NULL AS `pb_time_day`, NULL AS `pb_time_begin`, NULL AS `pb_room_id`, NULL AS `pb_publish_start_time`, "0000-00-00 00:00:00" AS `pb_upload_end_time`', FALSE);
         $task_set3->where('published', 1);
         $task_set3->where_related_course($course);
         $task_set3->include_related('solution');
         $task_set3->add_join_condition('`solutions`.`student_id` = ?', array($student->id));
         $task_set3->where_related('solution', 'student_id', $student->id);
         $task_set3->include_related('room', '*', TRUE, TRUE);
         $task_set3->include_related_count('task', 'total_tasks');
         $task_set3->include_related('task_set_type');
         $task_set3->select_subquery('(SELECT SUM(`points_total`) AS `points` FROM `task_task_set_rel` WHERE `task_set_id` = `${parent}`.`id` AND `task_task_set_rel`.`bonus_task` = 0)', 'total_points');
         $task_set3->where('id', $task_set_id);
         $task_set3->include_related('course', 'test_scoring_deadline');
         $task_set3->where('content_type', 'task_set');
         $task_set2->union(array($task_set, $task_set3), FALSE, '', 1, 0, 'id');
     }
     return $task_set2;
 }
Ejemplo n.º 8
0
function list_import_lamsfet_excercise_groups(&$excercise_groups, $courses_terms)
{
    echo 'Starting groups import (' . count($excercise_groups) . ') ';
    $days = array(1 => 'Pondelok', 'Utorok', 'Streda', 'Štvrtok', 'Piatok', 'Sobora', 'Nedeľa');
    if (count($excercise_groups)) {
        foreach ($excercise_groups as $id => $excercise_group) {
            $course_id = $courses_terms[$excercise_group->course_term_id]->_list_id;
            $course = new Course();
            $course->get_by_id(intval($course_id));
            if ($course->exists()) {
                $group = new Group();
                list($h, $m, $s) = explode(':', $excercise_group->time);
                $time_begin = (int) $s + (int) $m * 60 + (int) $h * 3600;
                if ($time_begin >= 86400) {
                    $excercise_group->time = '00:00:00';
                    $time_begin = 0;
                }
                $group->name = 'Skupina ' . $excercise_group->place . ' ' . $days[$excercise_group->day] . ' ' . $excercise_group->time;
                $group->save($course);
                $excercise_groups[$id]->_list_id = $group->id;
                $room = new Room();
                $room->name = $excercise_group->place;
                $room->time_day = $excercise_group->day;
                $room->time_begin = $time_begin;
                $room->time_end = $room->time_begin + 5400;
                $room->capacity = $excercise_group->capacity;
                $room->teachers_plain = trim($excercise_group->teacher) != '' ? trim($excercise_group->teacher) : NULL;
                $room->save($group);
                $course->capacity += $room->capacity;
                $course->save();
                echo '.';
            } else {
                echo ' ( COURSE NOT FOUND ' . $course_id . '(' . $excercise_group->course_term_id . ') ) ';
            }
        }
    }
    echo '] ... done' . "\n";
}
Ejemplo n.º 9
0
 private function get_task_set($task_set_id, &$course, &$student)
 {
     $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();
     if ($course->exists()) {
         $task_set->where('published', 1);
         $task_set->where_related_course($course);
         $task_set->include_related('solution');
         $task_set->add_join_condition('`solutions`.`student_id` = ?', array($student->id));
         $task_set->include_related('solution/teacher', 'fullname');
         $task_set->include_related_count('task', 'total_tasks');
         $task_set->where('content_type', 'project');
         $task_set->include_related('project_selection');
         $task_set->add_join_condition('`project_selections`.`student_id` = ? AND `project_selections`.`task_set_id` = `task_sets`.`id`', array($student->id));
         $task_set->include_related('project_selection/task');
         $task_set->order_by('publish_start_time', 'asc');
         $task_set->order_by('upload_end_time', 'asc');
         $task_set->order_by_with_overlay('name', 'asc');
         $task_set->get_by_id((int) $task_set_id);
     }
     return $task_set;
 }