public function task($task_set_id_url = NULL) { $this->_add_mathjax(); $task_set_id = url_get_id($task_set_id_url); $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/task.js'); $this->_add_prettify(); $this->_add_scrollTo(); $this->_add_jquery_countdown(); $this->parser->assign('max_filesize', compute_size_with_unit(intval($this->config->item('maximum_solition_filesize') * 1024))); $cache_id = $this->usermanager->get_student_cache_id('task_set_' . $task_set_id); if (!$this->_is_cache_enabled() || !$this->parser->isCached($this->parser->find_view('frontend/tasks/task.tpl'), $cache_id)) { $task_set = $this->get_task_set_by_id($course, $group, $student, $task_set_id); if ($course->exists()) { $task_sets = $this->filter_valid_task_sets($task_set); $this->lang->init_overlays('task_sets', $task_sets, array('name')); $filtered_task_set = count($task_sets) == 1 ? $task_sets[0] : new Task_set(); if ($filtered_task_set->exists()) { $this->load->helper('tests'); $test_types_subtypes = get_all_supported_test_types_and_subtypes(); $this->lang->init_overlays('task_sets', $filtered_task_set, array('name', 'instructions')); $solution_versions = new Solution_version(); $solution_versions->where_related('solution/task_set', 'id', $task_set_id); $solution_versions->where_related('solution', 'student_id', $this->usermanager->get_student_id()); $query = $solution_versions->get_raw(); $versions_metadata = array(); if ($query->num_rows()) { foreach ($query->result() as $row) { $versions_metadata[$row->version] = clone $row; } } $query->free_result(); $this->parser->assign('task_set', $filtered_task_set); $this->parser->assign('task_set_can_upload', $this->can_upload_file($filtered_task_set, $course)); $this->parser->assign('solution_files', $filtered_task_set->get_student_files($student->id)); $this->parser->assign('test_types', $test_types_subtypes['types']); $this->parser->assign('test_subtypes', $test_types_subtypes['subtypes']); $this->parser->assign('versions_metadata', $versions_metadata); } else { $this->messages->add_message('lang:tasks_task_task_set_not_found', Messages::MESSAGE_TYPE_ERROR); redirect(create_internal_url('tasks/index')); } } $this->parser->assign(array('course' => $course)); } $this->parser->parse('frontend/tasks/task.tpl', array(), FALSE, $this->_is_cache_enabled(), $cache_id); }
/** * Compute file capacity and return value with unit. * @param string $filename path and file name. * @return string capacity of file in bytes, KiB, MiB or GiB. */ function get_file_size($filename) { $size_bytes = @filesize($filename); if ($size_bytes === FALSE || $size_bytes == 0) { return '0 B'; } return compute_size_with_unit($size_bytes); }
public function task($task_set_id_url = NULL, $task_id_url = NULL) { $this->_add_mathjax(); $task_set_id = url_get_id($task_set_id_url); $task_id = url_get_id($task_id_url); $this->_initialize_student_menu(); $this->_select_student_menu_pagetag('projects'); $this->parser->add_css_file('frontend_projects.css'); $this->parser->add_js_file('projects/task.js'); $this->_add_prettify(); $this->_add_jquery_countdown(); $this->parser->assign('max_filesize', compute_size_with_unit(intval($this->config->item('maximum_solition_filesize') * 1024))); $cache_id = $this->usermanager->get_student_cache_id('task_set_' . $task_set_id . '|task_' . $task_id); if (!$this->_is_cache_enabled() || !$this->parser->isCached($this->parser->find_view('frontend/projects/task.tpl'), $cache_id)) { $project_all = $this->get_task_set($task_set_id, $course, $student); $project = $this->filter_valid_task_sets($project_all); if ($course->exists()) { $this->lang->init_overlays('task_sets', $project, array('name')); $project = count($project) == 1 ? $project[0] : new Task_set(); $this->parser->assign('project', $project); $task = $project->task; $task->include_join_fields()->order_by('`task_task_set_rel`.`sorting`', 'asc'); $task->get_by_id($task_id); $project_selection = new Project_selection(); $project_selection->where('task_set_id', $project->id); $project_selection->where('student_id', $this->usermanager->get_student_id()); $project_selection->where('task_id', $task->id); $project_selection->get(); $students = new Student(); $students->where_related('project_selection', 'task_set_id', $project->id); $students->where_related('project_selection', 'task_id', $task->id); $students->get_iterated(); $solution_versions = new Solution_version(); $solution_versions->where_related('solution/task_set', 'id', $task_set_id); $solution_versions->where_related('solution', 'student_id', $this->usermanager->get_student_id()); $query = $solution_versions->get_raw(); $versions_metadata = array(); if ($query->num_rows()) { foreach ($query->result() as $row) { $versions_metadata[$row->version] = clone $row; } } $query->free_result(); $this->parser->assign('task', $task); $this->parser->assign('students', $students); $this->parser->assign('project_selection', $project_selection); $this->parser->assign('solution_files', $project->get_student_files($student->id)); $this->parser->assign('versions_metadata', $versions_metadata); } $this->parser->assign(array('course' => $course)); } $this->parser->parse('frontend/projects/task.tpl', array(), FALSE, $this->_is_cache_enabled(), $cache_id); }