public function render() { $course = new Course(); $course->include_related('period'); $course->get_by_id((int) @$this->config['course_id']); $this->parser->assign('course', $course); if ($course->exists()) { $solutions = new Solution(); $solutions->select_func('COUNT', '@id', 'count'); $solutions->where('revalidate', 1); $solutions->where_related('task_set', 'id', '${parent}.id'); $solutions->where_related('student/participant/course', 'id', $course->id); $solutions->where_related('student/participant', 'allowed', 1); $task_sets = new Task_set(); $task_sets->select('*'); $task_sets->select_subquery($solutions, 'solutions_count'); $task_sets->where_related($course); $task_sets->where_related('solution', 'revalidate', 1); $task_sets->where_related('solution/student/participant/course', 'id', $course->id); $task_sets->where_related('solution/student/participant', 'allowed', 1); $task_sets->group_by('id'); $task_sets->order_by_with_overlay('name', 'ASC'); $task_sets->get_iterated(); $this->parser->assign('task_sets', $task_sets); } $this->parser->parse('widgets/admin/unevaluated_solutions/main.tpl'); }
public function index() { $this->usermanager->student_login_protected_redirect(); $this->_initialize_student_menu(); $this->_select_student_menu_pagetag('tasks'); $this->parser->add_css_file('frontend_tasks.css'); $this->parser->add_js_file('tasks/list.js'); $cache_id = $this->usermanager->get_student_cache_id(); if ($this->_is_cache_enabled()) { $this->smarty->caching = Smarty::CACHING_LIFETIME_SAVED; } if (!$this->_is_cache_enabled() || !$this->parser->isCached($this->parser->find_view('frontend/tasks/index.tpl'), $cache_id)) { $task_set = $this->get_task_sets($course, $group, $student); if ($course->exists()) { $task_set_types = $course->task_set_type->order_by_with_constant('name', 'asc')->get_iterated(); $this->parser->assign('task_set_types', $task_set_types); $task_sets = $this->filter_valid_task_sets($task_set); if ($this->_is_cache_enabled() && $this->filter_next_task_set_publication_min_cache_lifetime > 0 && $this->filter_next_task_set_publication_min_cache_lifetime <= $this->smarty->cache_lifetime) { $this->smarty->setCacheLifetime($this->filter_next_task_set_publication_min_cache_lifetime + 1); $this->parser->setCacheLifetimeForTemplateObject('frontend/tasks/index.tpl', $this->filter_next_task_set_publication_min_cache_lifetime + 1); } $this->lang->init_overlays('task_sets', $task_sets, array('name')); $this->parser->assign('task_sets', $task_sets); $points = $this->compute_points($task_sets, $student); $this->parser->assign('points', $points); } $this->parser->assign(array('course' => $course)); $projects = new Task_set(); if ($course->exists()) { $projects->where('content_type', 'project'); $projects->include_related('solution'); $projects->add_join_condition('`solutions`.`student_id` = ?', array($this->usermanager->get_student_id())); $projects->include_related('course'); $projects->include_related('course/period'); $projects->where('published', 1); $projects->group_start(); $projects->where('publish_start_time <=', date('Y-m-d H:i:s')); $projects->or_where('publish_start_time', NULL); $projects->group_end(); $projects->where_related('course', $course); $projects->order_by('publish_start_time'); $projects->get_iterated(); } $this->parser->assign('projects', $projects); } $this->parser->parse('frontend/tasks/index.tpl', array(), FALSE, $this->_is_cache_enabled() ? Smarty::CACHING_LIFETIME_SAVED : FALSE, $cache_id); }
/** * Initialise download of all solutions in all task sets belonging to this course. */ public function download_all_solutions() { if (!is_null($this->id)) { $task_sets = new Task_set(); $task_sets->where_related('course', $this); $task_sets->get_iterated(); $filename = $this->get_new_solution_zip_filename(); $zip_archive = new ZipArchive(); if ($zip_archive->open($filename, ZipArchive::CREATE)) { $period = $this->period->get(); $readme = $this->lang->text($this->name); $readme .= "\r\n" . $this->lang->text($period->name); $zip_archive->addFromString('readme.txt', $readme); foreach ($task_sets as $task_set) { $overlay_name = $this->lang->get_overlay('task_sets', $task_set->id, 'name'); $task_set->add_files_to_zip_archive($zip_archive, $this, normalizeForFilesystem(trim($overlay_name) == '' ? $task_set->name : $overlay_name) . '_(' . $task_set->id . ')'); } $zip_archive->close(); header('Content-Description: File Transfer'); header('Content-Type: application/zip'); header('Content-Disposition: attachment; filename=' . basename($filename)); header('Content-Transfer-Encoding: binary'); header('Expires: 0'); header('Cache-Control: must-revalidate'); header('Pragma: public'); header('Content-Length: ' . filesize($filename)); ob_clean(); flush(); $f = fopen($filename, 'r'); while (!feof($f)) { echo fread($f, 1024); } fclose($f); unlink($filename); } else { header("HTTP/1.0 404 Not Found"); } } else { header("HTTP/1.0 404 Not Found"); } die; }
private function inject_all_task_sets() { $task_sets = new Task_set(); $task_set_permissions = $task_sets->task_set_permission; $task_set_permissions->select_func('COUNT', '*', 'count'); $task_set_permissions->where('enabled', 1); $task_set_permissions->where_related('task_set', 'id', '${parent}.id'); $task_sets->select('*'); $task_sets->include_related('group', 'name'); $task_sets->select_subquery($task_set_permissions, 'task_set_permissions_count'); $task_sets->order_by_with_overlay('name'); $task_sets->get_iterated(); $data = array(); $this->lang->init_all_overlays('task_sets'); foreach ($task_sets as $task_set) { $text_groups = ''; if ((int) $task_set->task_set_permissions_count > 0) { $task_set_permissions = new Task_set_permission(); $task_set_permissions->include_related('group', 'name'); $task_set_permissions->where('enabled', 1); $task_set_permissions->where_related_task_set($task_set); $task_set_permissions->order_by_related_with_constant('group', 'name', 'asc'); $task_set_permissions->get_iterated(); $groups = array(); foreach ($task_set_permissions as $task_set_permission) { $groups[] = $this->lang->text($task_set_permission->group_name); } if (count($groups) > 0) { $text_groups = ' ... (' . implode(', ', $groups) . ')'; } } elseif (!is_null($task_set->group_id) && (int) $task_set->group_id > 0) { $text_groups = ' ... (' . $this->lang->text($task_set->group_name) . ')'; } $data[$task_set->course_id][] = array('value' => $task_set->id, 'text' => $this->lang->get_overlay_with_default('task_sets', $task_set->id, 'name', $task_set->name) . $text_groups); } $this->parser->assign('task_sets', $data); }