public function get_task_set_list() { $filter = $this->input->post('filter'); $this->store_task_set_selection_filter($filter); $this->db->query('CREATE TEMPORARY TABLE course_task_set_type_rel_override AS ( SELECT ctstr.course_id, ctstr.task_set_type_id, ctstr.upload_solution FROM course_task_set_type_rel ctstr ) UNION ( SELECT cs.id as course_id, 0 AS task_set_type_id, 1 AS upload_solution FROM (SELECT id FROM courses) cs )'); $solutions = new Solution(); $solutions->select_func('COUNT', 'id', 'cnt'); $solutions->where_related('student/participant/course', 'id', '${parent}.course_id'); $solutions->where_related('task_set', 'id', '${parent}.id'); $task_sets = new Task_set(); //$task_sets->select('`task_sets`.*, `course_course_task_set_type_rel`.`upload_solution` AS `join_upload_solution`'); $task_sets->select('`task_sets`.*'); $task_sets->select_subquery('(SELECT `sq_ctst`.`upload_solution` FROM course_task_set_type_rel_override AS `sq_ctst` WHERE `sq_ctst`.`course_id` = `${parent}`.`course_id` AND `sq_ctst`.`task_set_type_id` = `${parent}`.`task_set_type_id`)', 'join_upload_solution'); $task_sets->include_related_count('task_set_permission'); $task_sets->add_join_condition('`task_set_permissions`.`enabled` = 1'); //$task_sets->include_related_count('solution'); $task_sets->select_subquery($solutions, 'solution_count'); $task_sets->include_related_count('task'); $task_sets->include_related('course', array('name', 'default_points_to_remove', 'id')); $task_sets->include_related('course/period', 'name'); $task_sets->include_related('group', 'name'); $task_sets->include_related('task_set_type', 'name'); //$task_sets->where_related('solution/student/participant/course', 'id', 'courses.id'); /*$task_sets->include_related('course/task_set_type'); $task_sets->where('(`course_task_set_types`.`id` = `task_sets`.`task_set_type_id`)');*/ //$task_sets->where('((`course_course_task_set_type_rel`.`task_set_type_id` = `task_sets`.`task_set_type_id` AND `task_sets`.`task_set_type_id` != 0) OR `task_sets`.`task_set_type_id` = 0)'); $task_sets->where('content_type', isset($filter['content_type']) ? $filter['content_type'] : 'task_set'); if (isset($filter['course']) && intval($filter['course']) > 0) { $task_sets->where_related_course('id', intval($filter['course'])); } if (isset($filter['group']) && $filter['group'] == 'NULL') { $task_sets->where_related_group('id', NULL); $task_sets->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)'); } else { if (isset($filter['group']) && intval($filter['group']) > 0) { $task_sets->group_start(); $task_sets->or_group_start(); $task_sets->where_related_group('id', intval($filter['group'])); $task_sets->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_sets->group_end(); $task_sets->or_group_start(); $task_sets->where_related('task_set_permission/group', 'id', intval($filter['group'])); $task_sets->where_related('task_set_permission', 'enabled', 1); $task_sets->group_end(); $task_sets->group_end(); } } if (isset($filter['content_type']) && $filter['content_type'] == 'task_set' && isset($filter['task_set_type']) && intval($filter['task_set_type']) > 0) { $task_sets->where_related_task_set_type('id', intval($filter['task_set_type'])); } $order_by_direction = $filter['order_by_direction'] == 'desc' ? 'desc' : 'asc'; if ($filter['order_by_field'] == 'course') { $task_sets->order_by_related('course/period', 'sorting', $order_by_direction); $task_sets->order_by_related_with_constant('course', 'name', $order_by_direction); } elseif ($filter['order_by_field'] == 'task_set_name') { $task_sets->order_by_with_overlay('name', $order_by_direction); } elseif ($filter['order_by_field'] == 'course_group') { $task_sets->order_by_related_with_constant('group', 'name', $order_by_direction); } elseif ($filter['order_by_field'] == 'task_set_type') { $task_sets->order_by_related_with_constant('task_set_type', 'name', $order_by_direction); } elseif ($filter['order_by_field'] == 'solution_count') { $task_sets->order_by('solution_count', $order_by_direction); } elseif ($filter['order_by_field'] == 'task_count') { $task_sets->order_by('task_count', $order_by_direction); } elseif ($filter['order_by_field'] == 'upload_end_time') { $task_sets->order_by('upload_end_time', $order_by_direction); } elseif ($filter['order_by_field'] == 'content_type') { $task_sets->order_by('content_type', $order_by_direction); } $task_sets->get_paged_iterated(isset($filter['page']) ? intval($filter['page']) : 1, isset($filter['rows_per_page']) ? intval($filter['rows_per_page']) : 25); //$task_sets->check_last_query(); $this->lang->init_overlays('task_sets', $task_sets->all_to_array(), array('name')); $this->parser->parse('backend/solutions/task_set_list.tpl', array('task_sets' => $task_sets)); }
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; }
public function get_all_task_sets() { $fields_config = array(array('name' => 'created', 'caption' => 'lang:common_table_header_created'), array('name' => 'updated', 'caption' => 'lang:common_table_header_updated'), array('name' => 'name', 'caption' => 'lang:admin_task_sets_table_header_name'), array('name' => 'content_type', 'caption' => 'lang:admin_task_sets_table_header_content_type'), array('name' => 'course', 'caption' => 'lang:admin_task_sets_table_header_course'), array('name' => 'group', 'caption' => 'lang:admin_task_sets_table_header_group'), array('name' => 'task_set_type', 'caption' => 'lang:admin_task_sets_table_header_task_set_type'), array('name' => 'tasks', 'caption' => 'lang:admin_task_sets_table_header_tasks'), array('name' => 'published', 'caption' => 'lang:admin_task_sets_table_header_published'), array('name' => 'publish_start_time', 'caption' => 'lang:admin_task_sets_table_header_publish_start_time'), array('name' => 'upload_end_time', 'caption' => 'lang:admin_task_sets_table_header_upload_end_time'), array('name' => 'project_selection_deadline', 'caption' => 'lang:admin_task_sets_table_header_project_selection_deadline')); $filter = $this->input->post('filter'); $this->store_filter($filter); $this->inject_stored_filter(); $task_sets = new Task_set(); $task_sets->include_related_count('task_set_permission'); $task_sets->add_join_condition('`task_set_permissions`.`enabled` = 1'); $task_sets->include_related('course', 'name', TRUE); $task_sets->include_related('course/period', 'name', TRUE); $task_sets->include_related('group', 'name', TRUE); $task_sets->include_related('task_set_type', 'name', TRUE); $task_sets->include_related_count('task'); $task_sets->include_related_count('comment'); if (isset($filter['course']) && intval($filter['course']) > 0) { $task_sets->where_related_course('id', intval($filter['course'])); if (isset($filter['group']) && $filter['group'] == 'none') { $task_sets->where_related_group('id', NULL); $task_sets->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)'); } else { if (isset($filter['group']) && intval($filter['group']) > 0) { $task_sets->group_start(); $task_sets->or_group_start(); $task_sets->where_related_group('id', intval($filter['group'])); $task_sets->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_sets->group_end(); $task_sets->or_group_start(); $task_sets->where_related('task_set_permission/group', 'id', intval($filter['group'])); $task_sets->where_related('task_set_permission', 'enabled', 1); $task_sets->group_end(); $task_sets->group_end(); } } } if (isset($filter['task_set_type']) && intval($filter['task_set_type']) > 0) { $task_sets->where_related_task_set_type('id', intval($filter['task_set_type'])); } if (isset($filter['tasks']) && is_numeric($filter['tasks']) && intval($filter['tasks']) == 0) { $task_sets->where_has_no_tasks(); } else { if (isset($filter['tasks']) && is_numeric($filter['tasks']) && intval($filter['tasks']) == 1) { $task_sets->where_has_tasks(); } } if (isset($filter['name']) && trim($filter['name']) != '') { $name_value = trim($filter['name']); $task_sets->like_with_overlay('name', $name_value); } $order_by_direction = $filter['order_by_direction'] == 'desc' ? 'desc' : 'asc'; if ($filter['order_by_field'] == 'created') { $task_sets->order_by('created', $order_by_direction); } elseif ($filter['order_by_field'] == 'updated') { $task_sets->order_by('updated', $order_by_direction); } elseif ($filter['order_by_field'] == 'name') { $task_sets->order_by_with_overlay('name', $order_by_direction); } elseif ($filter['order_by_field'] == 'course') { $task_sets->order_by_related('course/period', 'sorting', $order_by_direction); $task_sets->order_by_related_with_constant('course', 'name', $order_by_direction); } elseif ($filter['order_by_field'] == 'group') { $task_sets->order_by_related_with_constant('group', 'name', $order_by_direction); } elseif ($filter['order_by_field'] == 'task_set_type') { $task_sets->order_by_related_with_constant('task_set_type', 'name', $order_by_direction); } elseif ($filter['order_by_field'] == 'tasks') { $task_sets->order_by('task_count', $order_by_direction); } elseif ($filter['order_by_field'] == 'published') { $task_sets->order_by('published', $order_by_direction); } elseif ($filter['order_by_field'] == 'upload_end_time') { $task_sets->order_by('upload_end_time', $order_by_direction); } elseif ($filter['order_by_field'] == 'publish_start_time') { $task_sets->order_by('publish_start_time', $order_by_direction); } elseif ($filter['order_by_field'] == 'project_selection_deadline') { $task_sets->order_by('project_selection_deadline', $order_by_direction); } elseif ($filter['order_by_field'] == 'content_type') { $task_sets->order_by('content_type', $order_by_direction); } $task_sets->get_paged_iterated(isset($filter['page']) ? intval($filter['page']) : 1, isset($filter['rows_per_page']) ? intval($filter['rows_per_page']) : 25); $this->lang->init_overlays('task_sets', $task_sets->all_to_array(), array('name')); $opened_task_set = new Task_set(); $opened_task_set->get_as_open(); $this->parser->parse('backend/task_sets/table_content.tpl', array('task_sets' => $task_sets, 'opened_task_set' => $opened_task_set, 'fields_config' => $fields_config)); }
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; }