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 render()
 {
     if (isset($this->config['course_id'])) {
         $course = new Course();
         $course->include_related('period');
         $course->get_by_id((int) $this->config['course_id']);
         $this->parser->assign('course', $course);
         if ($course->exists()) {
             $task_sets = new Task_set();
             $task_sets->where_related($course);
             $task_sets->where('published', 1);
             $task_sets->where('content_type', 'task_set');
             $task_sets_count = $task_sets->count();
             $this->parser->assign('task_sets_count', $task_sets_count);
             $task_sets->where_related($course);
             $task_sets->where('published', 1);
             $task_sets->where('content_type', 'project');
             $projects_count = $task_sets->count();
             $this->parser->assign('projects_count', $projects_count);
             $groups = new Group();
             $groups->where_related($course);
             $groups_count = $groups->count();
             $this->parser->assign('groups_count', $groups_count);
             $students = new Student();
             $students->where_related('participant/course', 'id', $course->id);
             $students->where_related('participant', 'allowed', 1);
             $students_count = $students->count();
             $this->parser->assign('students_count', $students_count);
             $task_set_permissions = new 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');
             $now = date('Y-m-d H:i:s');
             $plus_two_weeks = date('Y-m-d H:i:s', strtotime($now . ' + 2 weeks'));
             $minus_one_week = date('Y-m-d H:i:s', strtotime($now . ' - 1 week'));
             $task_sets->select('id, name, upload_end_time AS min_upload_end_time, upload_end_time AS max_upload_end_time');
             $task_sets->where_related($course);
             $task_sets->where('published', 1);
             $task_sets->where_subquery('0', $task_set_permissions);
             $task_sets->where('upload_end_time >=', $minus_one_week);
             $task_sets->where('upload_end_time <=', $plus_two_weeks);
             $task_sets_2 = new Task_set();
             $task_sets_2->select('id, name');
             $task_sets_2->where_related($course);
             $task_sets_2->where('published', 1);
             $task_sets_2->select_min('task_set_permissions.upload_end_time', 'min_upload_end_time');
             $task_sets_2->select_max('task_set_permissions.upload_end_time', 'max_upload_end_time');
             $task_sets_2->where_related('task_set_permission', 'enabled', 1);
             $task_sets_2->having('(MAX(`task_set_permissions`.`upload_end_time`) >= ' . $this->db->escape($minus_one_week) . ' AND MAX(`task_set_permissions`.`upload_end_time`) <= ' . $this->db->escape($plus_two_weeks) . ')');
             $task_sets_2->or_having('(MIN(`task_set_permissions`.`upload_end_time`) >= ' . $this->db->escape($minus_one_week) . ' AND MIN(`task_set_permissions`.`upload_end_time`) <= ' . $this->db->escape($plus_two_weeks) . ')');
             $task_sets_2->group_by('id');
             $task_sets->union_iterated($task_sets_2, FALSE, 'min_upload_end_time DESC, max_upload_end_time DESC', isset($this->config['number_of_task_sets']) ? (int) $this->config['number_of_task_sets'] : 5);
             $this->parser->assign('task_sets', $task_sets);
         }
     }
     $this->parser->parse('widgets/admin/course_overview/main.tpl');
 }
Beispiel #3
0
 /**
  * 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;
 }
Beispiel #4
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;
 }
Beispiel #5
0
 public function send_deadline_notifications($lang_idiom = NULL)
 {
     $this->load->database();
     $this->load->model('translations');
     if (!is_null($lang_idiom)) {
         $this->lang->reinitialize_for_idiom($lang_idiom);
     }
     $translations = $this->translations->get_translations_for_idiom($this->lang->get_current_idiom());
     $this->lang->add_custom_translations($translations);
     $this->lang->load('cli');
     $current_time = Date('Y-m-d H:i:s');
     $one_day_back_time = Date('Y-m-d H:i:s', strtotime('now -1 day'));
     $task_sets1 = new Task_set();
     $task_sets1->select('id, name, course_id, group_id AS common_group_id, upload_end_time AS common_upload_end_time, deadline_notified AS common_deadline_notified, deadline_notification_emails AS common_deadline_notification_emails, deadline_notification_emails_handler AS common_deadline_notification_emails_handler');
     $task_sets1->select('null AS `task_set_permission_id`', FALSE);
     $task_sets1->where('deadline_notified', 0);
     $task_sets1->where('deadline_notification_emails_handler >', 0);
     $task_sets1->group_start();
     $task_sets1->not_group_start();
     $task_sets1->where('upload_end_time', NULL);
     $task_sets1->group_end();
     $task_sets1->where('upload_end_time <', $current_time);
     $task_sets1->where('upload_end_time >=', $one_day_back_time);
     $task_sets1->group_end();
     $task_sets1->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_sets1->where('published', 1);
     $task_sets2 = new Task_set();
     $task_sets2->select('id, name, course_id');
     $task_sets2->include_related('task_set_permission', 'group_id', 'common');
     $task_sets2->include_related('task_set_permission', 'upload_end_time', 'common');
     $task_sets2->include_related('task_set_permission', 'deadline_notified', 'common');
     $task_sets2->include_related('task_set_permission', 'deadline_notification_emails', 'common');
     $task_sets2->include_related('task_set_permission', 'deadline_notification_emails_handler', 'common');
     $task_sets2->include_related('task_set_permission', 'id');
     $task_sets2->where_related('task_set_permission', 'enabled', 1);
     $task_sets2->where_related('task_set_permission', 'deadline_notified', 0);
     $task_sets2->where_related('task_set_permission', 'deadline_notification_emails_handler >', 0);
     $task_sets2->group_start();
     $task_sets2->not_group_start();
     $task_sets2->where_related('task_set_permission', 'upload_end_time', NULL);
     $task_sets2->group_end();
     $task_sets2->where_related('task_set_permission', 'upload_end_time <', $current_time);
     $task_sets2->where_related('task_set_permission', 'upload_end_time >=', $one_day_back_time);
     $task_sets2->group_end();
     $task_sets2->where('published', 1);
     $task_sets1->union_iterated($task_sets2, TRUE);
     $this->load->library('email');
     $sent_notifications = 0;
     foreach ($task_sets1 as $task_set) {
         if ($task_set->common_deadline_notification_emails_handler > 0) {
             $emails = trim($task_set->common_deadline_notification_emails) != '' ? explode(',', $task_set->common_deadline_notification_emails) : array();
             array_walk($emails, function (&$email, $key) {
                 $email = trim($email);
             });
             if ($task_set->common_deadline_notification_emails_handler == 1) {
                 $groups = new Group();
                 $groups->where_related('course', 'id', $task_set->course_id);
                 $groups->include_related('room/teacher', '*');
                 $groups->group_start('NOT');
                 $groups->where_related('room', 'id', null);
                 $groups->or_where_related('room/teacher', 'id', null);
                 $groups->group_end();
                 $groups->group_by_related('room/teacher', 'email');
                 if (!is_null($task_set->common_group_id)) {
                     $groups->where('id', $task_set->common_group_id);
                 }
                 $groups->get_iterated();
                 foreach ($groups as $teacher) {
                     if (trim($teacher->room_teacher_email) != '') {
                         $email = trim($teacher->room_teacher_email);
                         if (!in_array($email, $emails)) {
                             $emails[] = $email;
                         }
                     }
                 }
             }
             $group = new Group();
             if (!is_null($task_set->common_group_id)) {
                 $group->get_by_id((int) $task_set->common_group_id);
             }
             if (count($emails)) {
                 $this->email->from_system();
                 $this->email->reply_to_system();
                 $this->email->build_message_body('file:emails/cli/deadline_notification.tpl', array('task_set' => $task_set, 'group' => $group));
                 if ($this->config->item('email_multirecipient_batch_mode')) {
                     $this->email->to($emails);
                     $this->email->subject('LIST: ' . $this->lang->line('cli_deadline_notification_subject'));
                     $this->email->send();
                 } else {
                     foreach ($emails as $email) {
                         $this->email->to($email);
                         $this->email->subject('TEST');
                         $this->email->send();
                     }
                 }
                 $sent_notifications++;
                 if (!is_null($task_set->task_set_permission_id)) {
                     $task_set_permission = new Task_set_permission();
                     $task_set_permission->get_by_id($task_set->task_set_permission_id);
                     if ($task_set_permission->exists()) {
                         $task_set_permission->deadline_notified = 1;
                         $task_set_permission->save();
                     }
                 } else {
                     $task_set_update = new Task_set();
                     $task_set_update->get_by_id($task_set->id);
                     if ($task_set_update->exists()) {
                         $task_set_update->deadline_notified = 1;
                         $task_set_update->save();
                     }
                 }
             }
         }
     }
     echo "Process finished, {$sent_notifications} notifications were sent ...\n";
 }
Beispiel #6
0
 public function run_comparation()
 {
     $task_sets_setup_data = $this->input->post('task_sets_setup');
     $solutions_data = $this->input->post('solutions');
     $moss_setup_data = $this->input->post('moss_setup');
     $moss_base_files_data = $this->input->post('moss_base_files');
     $course = new Course();
     $course->get_by_id((int) $task_sets_setup_data['course']);
     $task_set = new Task_set();
     $task_set->where_related($course);
     $task_set->get_by_id(isset($task_sets_setup_data['task_set']) ? (int) $task_sets_setup_data['task_set'] : 0);
     $this->config->load('moss');
     $languages = $this->config->item('moss_langs_for_list');
     asort($languages);
     $this->parser->assign(array('course' => $course, 'task_set' => $task_set, 'languages' => $languages));
     $this->parser->assign('moss_enabled', $this->is_moss_user_id_set());
     if ($course->exists() && $task_set->exists()) {
         $this->load->library('form_validation');
         $this->form_validation->set_rules('solutions', 'lang:admin_moss_list_solutions_form_field_solution_selection', 'callback__selected_solutions');
         $this->form_validation->set_rules('moss_setup[l]', 'lang:admin_moss_list_solutions_form_field_language', 'required');
         $this->form_validation->set_rules('moss_setup[m]', 'lang:admin_moss_list_solutions_form_field_sensitivity', 'required|integer|greater_than[1]');
         $this->form_validation->set_rules('moss_setup[n]', 'lang:admin_moss_list_solutions_form_field_matching_files', 'required|integer|greater_than[1]');
         $this->form_validation->set_message('_selected_solutions', $this->lang->line('admin_moss_list_solutions_validation_callback_selected_solutions'));
         if ($this->form_validation->run() && $this->is_moss_user_id_set()) {
             $solutions = new Solution();
             $solutions->include_related('student');
             $solutions->where_related($task_set);
             $solutions->order_by_related_as_fullname('student', 'fullname', 'asc');
             $solutions->get_iterated();
             $this->parser->assign('solutions', $solutions);
             $tasks = new Task();
             $tasks->where_related($task_set);
             $tasks->get_iterated();
             $base_files_list = array();
             foreach ($tasks as $task) {
                 $base_files_list[$task->id] = array('task_id' => $task->id, 'task_name' => $this->lang->get_overlay_with_default('tasks', $task->id, 'name', $task->name), 'files' => $this->construct_base_files_for_task($task->id));
             }
             $this->parser->assign('base_files_list', $base_files_list);
             $path = $this->get_random_hash_folder($course->id, $task_set->id);
             $path_source = $path . '/source';
             $path_base = $path . '/base';
             @mkdir($path_source, DIR_WRITE_MODE, TRUE);
             @mkdir($path_base, DIR_WRITE_MODE, TRUE);
             $all_extracted = TRUE;
             $moss_langs_extensions = $this->config->item('moss_langs_file_extensions');
             if (isset($moss_langs_extensions[$moss_setup_data['l']])) {
                 $file_extensions = $moss_langs_extensions[$moss_setup_data['l']];
             } else {
                 $all_extracted = FALSE;
             }
             foreach ($solutions_data as $id => $config) {
                 if (!$all_extracted) {
                     break;
                 }
                 if (isset($config['selected']) && $config['selected'] == 1) {
                     set_time_limit(120);
                     $version = isset($config['version']) ? $config['version'] : 0;
                     $student = isset($config['student']) ? $config['student'] : 0;
                     $file = $task_set->get_student_files($student, $version);
                     if (count($file) == 1) {
                         $file = $file[$version];
                         $subdir = '/' . normalize($file['file_name']) . '_sid-' . $file['student_id'] . '_ver-' . $file['version'];
                         $extract_path = $path_source . $subdir;
                         @mkdir($extract_path, DIR_WRITE_MODE, TRUE);
                         $status = $task_set->extract_student_zip_to_folder($file['file'], $extract_path, $file_extensions);
                         $all_extracted = $all_extracted && $status;
                     }
                 }
             }
             if (is_array($moss_base_files_data) && count($moss_base_files_data)) {
                 foreach ($moss_base_files_data as $task_id => $path_array) {
                     if (!$all_extracted) {
                         break;
                     }
                     if (is_array($path_array) && count($path_array)) {
                         foreach ($path_array as $path_hash => $file_path) {
                             if (!$all_extracted) {
                                 break;
                             }
                             if (preg_match('/\\.zip(?P<indexNumberBox>\\[(?P<zipIndexNumber>[0-9]+)\\])$/', $file_path, $matches)) {
                                 $zipfile = mb_substr($file_path, 0, mb_strlen($file_path) - mb_strlen($matches['indexNumberBox']));
                                 $zipindex = (int) $matches['zipIndexNumber'];
                                 $zip = new ZipArchive();
                                 if ($zip->open($zipfile)) {
                                     set_time_limit(120);
                                     @mkdir($path_base . '/' . $task_id . '/' . $path_hash, DIR_WRITE_MODE, TRUE);
                                     if (!$zip->extractTo($path_base . '/' . $task_id . '/' . $path_hash, $zip->getNameIndex($zipindex))) {
                                         $all_extracted = FALSE;
                                     }
                                     $zip->close();
                                 } else {
                                     $all_extracted = FALSE;
                                 }
                             } else {
                                 set_time_limit(120);
                                 @mkdir($path_base . '/' . $task_id . '/' . $path_hash, DIR_WRITE_MODE, TRUE);
                                 $path_info = pathinfo($file_path);
                                 if (!copy($file_path, $path_base . '/' . $task_id . '/' . $path_hash . '/' . $path_info['basename'])) {
                                     $all_extracted = FALSE;
                                 }
                             }
                         }
                     }
                 }
             }
             if (!$all_extracted) {
                 unlink_recursive($path, TRUE);
             }
             $this->parser->assign('all_extracted', $all_extracted);
             $this->parser->assign('path', $path);
             $this->parser->assign('moss_config', $moss_setup_data);
             $this->parser->parse('backend/moss/run_comparation.tpl');
         } else {
             $this->list_solutions();
         }
     }
 }
Beispiel #7
0
 public function run_comparation()
 {
     $task_sets_setup_data = $this->input->post('task_sets_setup');
     $solutions_data = $this->input->post('solutions');
     $comparator_setup_data = $this->input->post('comparator_setup');
     $course = new Course();
     $course->get_by_id((int) $task_sets_setup_data['course']);
     $task_set = new Task_set();
     $task_set->where_related($course);
     $task_set->get_by_id(isset($task_sets_setup_data['task_set']) ? (int) $task_sets_setup_data['task_set'] : 0);
     $this->parser->assign(array('course' => $course, 'task_set' => $task_set));
     if ($course->exists() && $task_set->exists()) {
         $this->load->library('form_validation');
         $this->form_validation->set_rules('solutions', 'lang:admin_comparator_list_solutions_form_field_solution_selection', 'callback__selected_solutions');
         $this->form_validation->set_rules('comparator_setup[threshold]', 'lang:admin_comparator_list_solutions_form_field_threshold', 'required|numeric|greater_than_equal[0]|less_than_equal[1]');
         $this->form_validation->set_rules('comparator_setup[min_tree_size]', 'lang:admin_comparator_list_solutions_form_field_min_tree_size', 'required|integer|greater_than_equal[1]');
         $this->form_validation->set_rules('comparator_setup[max_cutted_tree_size]', 'lang:admin_comparator_list_solutions_form_field_max_cutted_tree_size', 'required|integer|greater_than_field_or_equal[comparator_setup[min_tree_size]]');
         $this->form_validation->set_rules('comparator_setup[branching_factor]', 'lang:admin_comparator_list_solutions_form_field_branching_factor', 'required|integer|greater_than_equal[1]');
         $this->form_validation->set_rules('comparator_setup[min_similarity]', 'lang:admin_comparator_list_solutions_form_field_minimum_similarity', 'required|numeric|greater_than_equal[0]|less_than_equal[1]');
         $this->form_validation->set_rules('comparator_setup[timeout]', 'lang:admin_comparator_list_solutions_form_field_timeout', 'required|integer|greater_than_equal[1]');
         $this->form_validation->set_message('_selected_solutions', $this->lang->line('admin_comparator_list_solutions_validation_callback_selected_solutions'));
         if ($this->form_validation->run()) {
             $solutions = new Solution();
             $solutions->include_related('student');
             $solutions->where_related($task_set);
             $solutions->order_by_related_as_fullname('student', 'fullname', 'asc');
             $solutions->get_iterated();
             $this->parser->assign('solutions', $solutions);
             $path = $this->get_random_hash_folder($course->id, $task_set->id);
             $path_source = $path . '/source';
             $path_output = $path . '/output';
             @mkdir($path_source, DIR_WRITE_MODE, TRUE);
             @mkdir($path_output, DIR_WRITE_MODE, TRUE);
             $all_extracted = TRUE;
             foreach ($solutions_data as $id => $config) {
                 if (isset($config['selected']) && $config['selected'] == 1) {
                     set_time_limit(120);
                     $version = isset($config['version']) ? $config['version'] : 0;
                     $student = isset($config['student']) ? $config['student'] : 0;
                     $file = $task_set->get_student_files($student, $version);
                     if (count($file) == 1) {
                         $file = $file[$version];
                         $subdir = '/' . normalize($file['file_name']) . '_sid-' . $file['student_id'] . '_ver-' . $file['version'];
                         $extract_path = $path_source . $subdir;
                         @mkdir($extract_path, DIR_WRITE_MODE, TRUE);
                         $status = $task_set->extract_student_zip_to_folder($file['file'], $extract_path, array('java'));
                         $all_extracted = $all_extracted && $status;
                     }
                 }
             }
             if (!$all_extracted) {
                 unlink_recursive($path, TRUE);
             }
             $this->parser->assign('all_extracted', $all_extracted);
             $this->parser->assign('path', $path);
             $this->parser->assign('comparator_config', array('t' => $comparator_setup_data['threshold'], 'm' => $comparator_setup_data['min_tree_size'], 'cut' => $comparator_setup_data['max_cutted_tree_size'], 'bf' => $comparator_setup_data['branching_factor'], 'mp' => $comparator_setup_data['min_similarity'], 'timeout' => $comparator_setup_data['timeout'] * 60000));
             $this->parser->parse('backend/comparator/run_comparation.tpl');
         } else {
             $this->list_solutions();
         }
     } else {
         $this->list_solutions();
     }
 }
Beispiel #8
0
 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));
 }
Beispiel #9
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;
 }
Beispiel #10
0
 public function upload_solution($task_set_id_url, $task_id_url)
 {
     $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();
     $date = date('Y-m-d H:i:s');
     $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_set->where_related($course);
     $task_set->where('published', 1);
     $task_set->group_start();
     $task_set->where('publish_start_time <=', $date);
     $task_set->or_where('publish_start_time', NULL);
     $task_set->group_end();
     $task_set->get_by_id($task_set_id);
     $task = $task_set->task->include_join_fields()->get_by_id($task_id);
     $project_selection = new Project_selection();
     $project_selection->where_related($student);
     $project_selection->where_related($task_set);
     $project_selection->where_related($task);
     $project_selection->get();
     if ($student->exists() && $course->exists() && $task_set->exists() && $task->exists() && $project_selection->exists()) {
         if ($date <= $task_set->upload_end_time) {
             $config['upload_path'] = 'private/uploads/solutions/task_set_' . intval($task_set_id) . '/';
             $config['allowed_types'] = 'zip';
             $config['max_size'] = intval($this->config->item('maximum_solition_filesize'));
             $current_version = $task_set->get_student_file_next_version($student->id);
             $config['file_name'] = $student->id . '_' . $this->normalize_student_name($student) . '_' . substr(md5(time() . rand(-500000, 500000)), 0, 4) . '_' . $current_version . '.zip';
             @mkdir($config['upload_path'], DIR_READ_MODE);
             $this->load->library('upload', $config);
             if ($this->upload->do_upload('file')) {
                 $solution = new Solution();
                 $solution->where('task_set_id', $task_set->id);
                 $solution->where('student_id', $student->id);
                 $solution->get();
                 $revalidate = 1;
                 if ($solution->exists()) {
                     $solution->ip_address = $_SERVER["REMOTE_ADDR"];
                     $solution->revalidate = $revalidate;
                     $solution->save();
                 } else {
                     $solution = new Solution();
                     $solution->ip_address = $_SERVER["REMOTE_ADDR"];
                     $solution->revalidate = $revalidate;
                     $solution->save(array('student' => $student, 'task_set' => $task_set));
                 }
                 $solution_version = new Solution_version();
                 $solution_version->ip_address = $_SERVER["REMOTE_ADDR"];
                 $solution_version->version = $current_version;
                 $solution_version->save($solution);
                 if ($this->db->trans_status()) {
                     $log = new Log();
                     $log->add_student_solution_upload_log(sprintf($this->lang->line('projects_task_solution_upload_log_message'), $config['file_name']), $student, $solution->id);
                     $this->db->trans_commit();
                     $this->messages->add_message('lang:projects_task_solution_uploaded', Messages::MESSAGE_TYPE_SUCCESS);
                     $this->_action_success();
                     $this->output->set_internal_value('task_set_id', $solution->task_set_id);
                     $this->output->set_internal_value('task_id', $task->id);
                 } else {
                     $this->db->trans_rollback();
                     @unlink($config['upload_path'] . $config['file_name']);
                     $this->messages->add_message('lang:projects_task_solution_canceled_due_db_error', Messages::MESSAGE_TYPE_ERROR);
                 }
                 redirect(create_internal_url('projects/task/' . $task_set_id_url . '/' . $task_id_url));
             } else {
                 $this->db->trans_rollback();
                 $this->parser->assign('file_error_message', $this->upload->display_errors('', ''));
                 $this->task($task_set_id_url, $task_id_url);
             }
         } else {
             $this->db->trans_rollback();
             $this->messages->add_message('lang:projects_task_solution_upload_time_error', 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('lang:projects_task_solution_database_data_wrong_error', Messages::MESSAGE_TYPE_ERROR);
         redirect(create_internal_url('projects/task/' . $task_set_id_url . '/' . $task_id_url));
     }
 }