本文整理汇总了PHP中Student::exists方法的典型用法代码示例。如果您正苦于以下问题:PHP Student::exists方法的具体用法?PHP Student::exists怎么用?PHP Student::exists使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Student
的用法示例。
在下文中一共展示了Student::exists方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: generate_random_password_token
/**
* Create random password token for student.
* If student is exists, it will be automaticaly updated (only password token information).
*/
public function generate_random_password_token()
{
$this->load->library('form_validation');
do {
$this->password_token = sha1(time() . '-' . $this->config->item('encryption_key') . '-' . $_SERVER['SCRIPT_FILENAME'] . '-' . rand(1000000, 9999999));
} while (!$this->form_validation->is_unique($this->password_token, 'students.password_token'));
if (!is_null($this->id) && is_numeric($this->id) && intval($this->id) > 0) {
$student = new Student(intval($this->id));
if ($student->exists()) {
$student->password_token = $this->password_token;
$student->save();
}
unset($student);
}
}
示例2: send_group_mail
public function send_group_mail($group_id)
{
$group = new Group();
$group->get_by_id($group_id);
if ($group->exists()) {
$this->load->library('form_validation');
$this->form_validation->set_rules('group_mail[subject]', 'lang:admin_groups_group_email_form_field_subject', 'required');
$this->form_validation->set_rules('group_mail[body]', 'lang:admin_groups_group_email_form_field_body', 'required_no_html');
$this->form_validation->set_rules('group_mail[from]', 'lang:admin_groups_group_email_form_field_from', 'required');
$this->form_validation->set_rules('group_mail[student][]', 'lang:admin_groups_group_email_form_field_students', 'required');
if ($this->form_validation->run()) {
$data = $this->input->post('group_mail');
$students = new Student();
$students->where_related('participant/group', 'id', $group->id);
$students->where_related('participant/course', 'id', $group->course_id);
$students->where_related('participant', 'allowed', 1);
$students->where_in('id', $data['student']);
$students->get();
if ($students->exists()) {
$from = NULL;
$from_name = '';
$teacher = new Teacher();
$teacher->get_by_id($this->usermanager->get_teacher_id());
if ($data['from'] == 'me') {
$from = $teacher->email;
$from_name = $teacher->fullname;
}
$sender_copy = isset($data['sender_copy']) && $data['sender_copy'] == 1 ? TRUE : FALSE;
$sender_email = $teacher->email;
if ($this->_send_multiple_emails($students, $data['subject'], '{$data.body|add_base_url}', array('data' => $data), $from, $from_name, $sender_copy, $sender_email)) {
$this->messages->add_message('lang:admin_groups_group_email_success_sent', Messages::MESSAGE_TYPE_SUCCESS);
} else {
$this->messages->add_message('lang:admin_groups_group_email_error_send_failed', Messages::MESSAGE_TYPE_ERROR);
}
} else {
$this->messages->add_message('lang:admin_groups_group_email_error_no_students_selected', Messages::MESSAGE_TYPE_ERROR);
}
redirect(create_internal_url('admin_groups/group_mail/' . $group_id));
} else {
$this->group_mail($group_id);
}
} else {
$this->messages->add_message('lang:admin_groups_group_email_error_group_not_found', Messages::MESSAGE_TYPE_ERROR);
redirect(create_internal_url('admin_groups/group_mail/' . $group_id));
}
}
示例3: refresh_student_userdata
/**
* Reloads student data from database to session.
*/
public function refresh_student_userdata()
{
if ($this->is_student_session_valid()) {
$userdata = $this->CI->session->userdata(SESSION_AUTH_LOGIN_STUDENT);
$student = new Student();
$student->get_by_id(@$userdata['id']);
if ($student->exists()) {
$userdata = $student->to_array();
unset($userdata['password']);
unset($userdata['created']);
unset($userdata['updated']);
$this->CI->session->set_userdata(SESSION_AUTH_LOGIN_STUDENT, $userdata);
}
}
}
示例4: _send_multiple_emails
/**
* Sends message to all students or teachers. Do not use get_iterated() to execute select query!
* @param Student|Teacher $recipients list of students or teachers.
* @param string $subject email subject (accepts lang: prefix).
* @param string $template template body or file:path/to/template.tpl.
* @param string $template_variables array of template variables.
* @param string $from email addres of sender or NULL to use system address.
* @param string $from_name name of sender.
* @param boolean $sender_copy enable sending of copy to sender email address.
* @param string $sender_email sender email address.
* @return boolean TRUE, if all emails are sent, or FALSE if all or some emails failed to be send.
*/
protected function _send_multiple_emails($recipients, $subject, $template, $template_variables = array(), $from = NULL, $from_name = '', $sender_copy = FALSE, $sender_email = '')
{
if ($recipients instanceof Teacher || $recipients instanceof Student) {
$email_by_languages = array();
if ($recipients->exists()) {
foreach ($recipients->all as $recipient) {
$email_by_languages[$recipient->language][] = $recipient;
}
}
if (count($email_by_languages) == 0) {
return FALSE;
}
$this->load->library('email');
if (is_null($from)) {
$this->email->from_system();
$this->email->reply_to_system();
} else {
$this->email->from($from, $from_name);
$this->email->reply_to($from, $from_name);
}
$result = TRUE;
$lang_clone = clone $this->lang;
set_time_limit(0);
foreach ($email_by_languages as $language => $subrecipients) {
if (count($subrecipients) == 0) {
continue;
}
$this->_init_specific_language($language);
$this->email->build_message_body($template, $template_variables);
$email_subject = 'LIST' . ($subject ? ' - ' . $this->lang->text($subject) : '');
if ($this->config->item('email_multirecipient_batch_mode')) {
$to_list = array();
foreach ($subrecipients as $recipient) {
$to_list[] = $recipient->email;
}
if ($sender_copy === TRUE) {
$to_list[] = $sender_email;
}
$this->email->to($to_list);
$this->email->subject($email_subject);
$partial_result = $this->email->send();
$result = $result && $partial_result;
} else {
foreach ($subrecipients as $recipient) {
$this->email->to($recipient->email);
$this->email->subject($email_subject);
$partial_result = $this->email->send();
$result = $result && $partial_result;
}
if ($sender_copy === TRUE) {
$this->email->to($sender_email);
$this->email->subject($email_subject);
$partial_result = $this->email->send();
$result = $result && $partial_result;
}
}
}
$this->lang = $lang_clone;
set_time_limit((int) ini_get('max_execution_time'));
return $result;
} else {
return FALSE;
}
}
示例5: Common
<?php
session_start();
include "../Conversion.php";
include "../CommonMethods.php";
include "../Student.php";
$debug = false;
$COMMON = new Common($debug);
// See if student is in database
$student = new Student($COMMON, strtoupper($_POST["studID"]));
if (!$student->exists()) {
// Student does not exist, so create in database
Student::createStudent($COMMON, strtoupper($_POST["firstN"]), strtoupper($_POST["lastN"]), strtoupper($_POST["studID"]), $_POST["email"], NameToAbb($_POST["major"]));
}
// Save student ID for session
$_SESSION["studID"] = strtoupper($_POST["studID"]);
header('Location: 02StudHome.php');
示例6: save_email
public function save_email()
{
$this->usermanager->student_login_protected_redirect();
if ((bool) $this->config->item('student_mail_change')) {
$this->load->library('form_validation');
$student_id = intval($this->input->post('student_id'));
$this->form_validation->set_rules('student[email]', 'lang:students_my_account_field_email', 'required|valid_email|is_unique[students.email]');
$this->form_validation->set_rules('student[email_validation]', 'lang:students_my_account_field_email_validation', 'required|matches[student[email]]');
$this->form_validation->set_rules('student_id', 'id', 'required');
if ($this->form_validation->run()) {
if ($student_id == $this->usermanager->get_student_id()) {
$this->_transaction_isolation();
$this->db->trans_begin();
$student = new Student();
$student->get_by_id($student_id);
if ($student->exists()) {
$student_post = $this->input->post('student');
$student->email = $student_post['email'];
if ($student->save() && $this->db->trans_status()) {
$this->db->trans_commit();
$this->messages->add_message('lang:students_my_account_success_save', Messages::MESSAGE_TYPE_SUCCESS);
$this->_action_success();
} else {
$this->db->trans_rollback();
$this->messages->add_message('lang:students_my_account_error_save', Messages::MESSAGE_TYPE_ERROR);
}
} else {
$this->db->trans_rollback();
$this->messages->add_message('lang:students_my_account_error_invalid_account', Messages::MESSAGE_TYPE_ERROR);
}
} else {
$this->messages->add_message('lang:students_my_account_error_invalid_account', Messages::MESSAGE_TYPE_ERROR);
}
redirect(create_internal_url('students/my_account'));
} else {
$this->my_account();
}
} else {
$this->messages->add_message('lang:students_my_account_error_save', Messages::MESSAGE_TYPE_ERROR);
redirect(create_internal_url('students/my_account'));
}
}
示例7: batch_save_solutions
public function batch_save_solutions($task_set_id)
{
$this->_transaction_isolation();
$this->db->trans_begin();
$task_set = new Task_set();
$task_set->get_by_id($task_set_id);
if ($task_set->exists()) {
$data = $this->input->post('batch_valuation');
$saved_count = 0;
$save_status = TRUE;
if (is_array($data) && count($data) > 0) {
foreach ($data as $student_id => $solution_data) {
$student = new Student();
$student->get_by_id($student_id);
$task_set_check = new Task_set();
$task_set_check->where_related('course/participant/student', 'id', intval($student_id));
$task_set_check->where_related('course/participant', 'allowed', 1);
$task_set_check->group_start();
$task_set_check->or_group_start();
$task_set_check->group_start();
$task_set_check->or_where('group_id', NULL);
$task_set_check->or_where('`course_participants`.`group_id` = `task_sets`.`group_id`');
$task_set_check->group_end();
$task_set_check->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_check->group_end();
$task_set_check->or_where_related('task_set_permission', '`group_id` = `course_participants`.`group_id`');
$task_set_check->or_where_related('solution', 'student_id', $student->id);
$task_set_check->group_end();
$task_set_check->get_by_id($task_set_id);
if ($student->exists() && $task_set_check->exists() && array_key_exists('points', $solution_data) && is_numeric($solution_data['points'])) {
$solution = new Solution();
$solution->where_related_student('id', $student->id);
$solution->where_related_task_set('id', $task_set->id);
$solution->get();
if (is_null($solution->points) || floatval($solution->points) !== floatval($solution_data['points']) || $solution->not_considered != intval(@$solution_data['not_considered'])) {
$solution->teacher_id = $this->usermanager->get_teacher_id();
$solution->points = floatval($solution_data['points']);
$solution->revalidate = 0;
$solution->not_considered = intval(@$solution_data['not_considered']);
$save_status = $save_status & $solution->save(array($task_set, $student));
$saved_count++;
}
}
}
}
if ($this->db->trans_status() && $save_status && $saved_count > 0) {
$this->db->trans_commit();
$this->messages->add_message('lang:admin_solutions_batch_valuation_success_message_save_ok', Messages::MESSAGE_TYPE_SUCCESS);
$this->_action_success();
} else {
$this->db->trans_rollback();
$this->messages->add_message('lang:admin_solutions_batch_valuation_error_message_save_failed', Messages::MESSAGE_TYPE_ERROR);
}
} else {
$this->db->trans_rollback();
$this->messages->add_message('lang:admin_solutions_batch_valuation_error_message_save_failed', Messages::MESSAGE_TYPE_ERROR);
}
redirect(create_internal_url('admin_solutions/batch_valuation_list/' . $task_set_id));
}
示例8: add_participant
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();
}
}
示例9: import_single_line
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);
//.........这里部分代码省略.........
示例10: edit
public function edit()
{
$this->_select_teacher_menu_pagetag('task_sets');
$url = $this->uri->ruri_to_assoc(3);
$task_set_id = isset($url['task_set_id']) ? intval($url['task_set_id']) : intval($this->input->post('task_set_id'));
$task_set = new Task_set();
$task_set->get_by_id($task_set_id);
$ps_data = array();
$nps_data = array();
if ($task_set->exists() && $task_set->content_type == 'project') {
$project_selections = new Project_selection();
$project_selections->select('*');
$project_selections->include_related('student', array('fullname', 'email'));
$project_selections->where_related($task_set);
$project_selections->include_related('task', 'name');
$project_selections->include_related('task/task_set', 'id');
$project_selections->where_related('task/task_set', 'id', $task_set->id);
$project_selections->order_by('task_task_task_set_rel.sorting', 'ASC');
$project_selections->order_by_related_as_fullname('student', 'fullname', 'asc');
$project_selections->get();
if ($project_selections->exists()) {
foreach ($project_selections->all as $project_selection) {
$ps_data[$project_selection->task_id][] = $project_selection;
}
}
$project_selections->select_func('COUNT', '@id', 'count');
$project_selections->where('task_set_id', 'participant_course_task_sets.id', false);
$project_selections->where_related('student', 'id', '${parent}.id');
$students = new Student();
$students->where_related('participant/course/task_set', $task_set);
$students->where_related('participant', 'allowed', 1);
$students->where_subquery(0, $project_selections);
$students->order_by_as_fullname('fullname', 'asc');
$students->get();
if ($students->exists()) {
$nps_data = $students->all;
}
}
$this->_add_tinymce4();
$this->parser->add_js_file('jquery.activeform.js');
$this->parser->add_js_file('admin_task_sets/edit.js');
$this->parser->add_js_file('admin_task_sets/form.js');
$this->parser->add_css_file('admin_task_sets.css');
$this->inject_courses();
$this->inject_languages();
$this->inject_test_types();
$this->inject_course_groups();
$this->inject_course_group_rooms();
$this->inject_course_task_set_types();
$this->parser->parse('backend/task_sets/edit.tpl', array('task_set' => $task_set, 'project_selections' => $ps_data, 'not_project_selections' => $nps_data));
}
示例11: create_comment
private function create_comment()
{
$post_data = $this->input->post('comment');
if (array_key_exists('text', $post_data) && array_key_exists('task_set_id', $post_data) && array_key_exists('reply_at_id', $post_data)) {
$task_set = new Task_set();
$task_set->get_by_id(intval($post_data['task_set_id']));
$student = new Student();
$student->get_by_id($this->usermanager->get_student_id());
if ($task_set->exists() && $student->exists() && (bool) $task_set->comments_enabled) {
if (trim(strip_tags($post_data['text'])) != '') {
$text = strip_tags($post_data['text'], '<a><strong><em><span>');
$comment = new Comment();
$comment->text = $text;
$comment->approved = (bool) $task_set->comments_moderated ? 0 : 1;
$comment->reply_at_id = empty($post_data['reply_at_id']) ? NULL : intval($post_data['reply_at_id']);
$this->_transaction_isolation();
$this->db->trans_begin();
if ($comment->save(array($task_set, $student))) {
$this->db->trans_commit();
$this->messages->add_message('lang:tasks_comments_message_comment_post_success_save', Messages::MESSAGE_TYPE_SUCCESS);
if ((bool) $comment->approved) {
$all_students = $task_set->comment_subscriber_student;
$all_students->where('id !=', $this->usermanager->get_student_id());
$all_students->get();
$this->_send_multiple_emails($all_students, 'lang:tasks_comments_email_subject_new_post', 'file:emails/frontend/comments/new_comment_student.tpl', array('task_set' => $task_set, 'student' => $student, 'comment' => $comment));
$task_set_related_teachers = new Teacher();
if (!is_null($task_set->group_id)) {
$task_set_related_teachers->where_related('room/group', 'id', $task_set->group_id);
} else {
$task_set_related_teachers->where_related('room/group/course', 'id', $task_set->course_id);
}
$task_set_related_teachers->group_by('id');
$all_teachers = new Teacher();
$all_teachers->where_related('comment_subscription', 'id', $task_set->id);
$all_teachers->union($task_set_related_teachers, FALSE, '', NULL, NULL, 'id');
$all_teachers->check_last_query();
$this->_send_multiple_emails($all_teachers, 'lang:tasks_comments_email_subject_new_post', 'file:emails/frontend/comments/new_comment_teacher.tpl', array('task_set' => $task_set, 'student' => $student, 'comment' => $comment));
}
return TRUE;
} else {
$this->db->trans_rollback();
$this->messages->add_message('lang:tasks_comments_message_comment_post_error_save', Messages::MESSAGE_TYPE_ERROR);
return FALSE;
}
} else {
$this->messages->add_message('lang:tasks_comments_message_comment_post_error_empty', Messages::MESSAGE_TYPE_ERROR);
return FALSE;
}
} else {
$this->messages->add_message('lang:tasks_comments_message_not_found_or_disabled', Messages::MESSAGE_TYPE_ERROR);
return FALSE;
}
} else {
$this->messages->add_message('lang:tasks_comments_message_comment_post_error_data', Messages::MESSAGE_TYPE_ERROR);
return FALSE;
}
}
示例12: evaluate_test_result
public function evaluate_test_result($task_set_id, $student_id, $version, $test_type, $token)
{
$task_set = new Task_set();
$task_set->include_related('course', 'test_scoring_deadline');
$task_set->get_by_id((int) $task_set_id);
$student = new Student();
$student->get_by_id((int) $student_id);
$output = new stdClass();
$output->result = FALSE;
$output->message = '';
$output->points_new = 0;
$output->points_before = 0;
$this->load->model('test_score');
if ($task_set->exists() && $student->exists()) {
if ($task_set->course_test_scoring_deadline >= date('Y-m-d H:i:s') && $task_set->enable_tests_scoring > 0) {
$results = $this->test_score->get_data_for_student($student->id, $token, $test_type);
$this->_transaction_isolation();
$this->db->trans_start();
$tests = new Test();
$tests->where_related('task/task_set', 'id', $task_set->id);
$tests->where('type', $test_type);
$tests->where('enable_scoring >', 0);
$tests->group_by('task_id');
$tests->where('task_task_task_set_rel.bonus_task', 0);
$tests->get_iterated();
//$output->debug = $tests->check_last_query(array('', ''), TRUE);
$test_count = $tests->result_count();
$min_results = $task_set->test_min_needed > $test_count ? $test_count : $task_set->test_min_needed;
$course = new Course();
$course->where_related_task_set('id', $task_set->id);
$course->get();
$min_points_limit = -$course->default_points_to_remove;
if ($test_count > 0) {
$total_score = 0;
$score_array = array();
$bonus_tasks_array = array();
$score_percentage = array();
$bonus_tasks_percentage = array();
if (count($results)) {
foreach ($results as $task_id => $score) {
$this->db->select('*');
$this->db->where('task_set_id', $task_set->id);
$this->db->where('task_id', (int) $task_id);
$query = $this->db->get('task_task_set_rel');
if ($query->num_rows() > 0) {
$task_rel = $query->row_object();
$min = $task_rel->test_min_points;
$max = $task_rel->test_max_points;
$diff = abs($max - $min);
$score_percent = (double) $score / 100;
$sub_score = round(10 * ($min + $diff * $score_percent)) / 10;
if ($task_rel->bonus_task == 0) {
$score_array[$task_id] = $sub_score;
$score_percentage[$task_id] = $score;
} else {
$bonus_tasks_array[$task_id] = $sub_score;
$bonus_tasks_percentage[$task_id] = $score;
}
}
$query->free_result();
}
}
$max_results = $task_set->test_max_allowed < count($score_array) ? $task_set->test_max_allowed : count($score_array);
arsort($score_array, SORT_NUMERIC);
$i = 0;
foreach ($score_array as $task_id => $points) {
if ($i < $max_results) {
$total_score += $points;
$i++;
} else {
break;
}
}
$total_score = $total_score < $min_points_limit ? $min_points_limit : $total_score;
arsort($bonus_tasks_array, SORT_NUMERIC);
$total_score += array_sum($bonus_tasks_array);
if (count($score_array) >= $min_results) {
$tasks = new Task();
$tasks->where_related_task_set('id', $task_set_id);
$tasks->order_by('`task_task_set_rel`.`sorting`', 'asc');
$tasks->get_iterated();
//$output->debug = $tasks->check_last_query(array('', ''), TRUE);
$output->evaluation = $this->parser->parse('backend/tests/evaluation_table.tpl', array('tasks' => $tasks, 'real_points' => $score_array, 'bonus_points' => $bonus_tasks_array, 'real_percentage' => $score_percentage, 'bonus_percentage' => $bonus_tasks_percentage, 'max_results' => $max_results), TRUE);
$solution = new Solution();
$solution->where('task_set_id', $task_set->id);
$solution->where('student_id', $student->id);
$solution->get();
$save_solution = FALSE;
$solution_not_considered = FALSE;
$output->points_new = $total_score;
if ($solution->exists()) {
if ($solution->not_considered == 0) {
$output->points_before = $solution->points;
if ($solution->points < $total_score || is_null($solution->points)) {
$solution->points = $total_score;
$solution->comment = '';
$solution->teacher_id = NULL;
$solution->best_version = (int) $version;
$solution->revalidate = 0;
$save_solution = TRUE;
//.........这里部分代码省略.........
示例13: index
public function index($worker_id = 0)
{
$test_queue = new Test_queue();
$execute_tests = FALSE;
try {
$this->db->query('SET SESSION TRANSACTION ISOLATION LEVEL SERIALIZABLE;');
$this->db->trans_begin();
$test_queue->where('worker', NULL);
$test_queue->where('status', 0);
$test_queue->where('version >', 0);
$test_queue->group_start(' NOT ');
$test_queue->where('task_set_id', NULL);
$test_queue->group_end();
$test_queue->group_start(' NOT ');
$test_queue->where('student_id', NULL);
$test_queue->group_end();
$test_queue->order_by('priority', 'asc');
$test_queue->order_by('start', 'asc');
$test_queue->limit(1);
$sql_query = $test_queue->get_sql();
$sql_query = rtrim($sql_query, '; ' . "\n\r") . ' FOR UPDATE;';
$test_queue->query($sql_query);
if ($test_queue->exists()) {
$test_queue->worker = (int) $worker_id;
$test_queue->status = 1;
$test_queue->exec_start = date('Y-m-d H:i:s');
$test_queue->where('worker', NULL);
$test_queue->where('status', 0);
if ($test_queue->save()) {
$this->db->trans_commit();
$execute_tests = TRUE;
} else {
$this->db->trans_rollback();
}
} else {
$this->db->trans_rollback();
}
} catch (Exception $e) {
}
if ($test_queue->exists() && $execute_tests) {
//$this->db->query('SET SESSION TRANSACTION ISOLATION LEVEL READ COMMITTED;');
//$this->db->trans_begin();
$this->lang->reinitialize_for_idiom($test_queue->system_language);
$this->lang->load('admin/tests');
$task_set = new Task_set();
$task_set->include_related('course', 'test_scoring_deadline');
$task_set->get_by_id($test_queue->task_set_id);
$student = new Student();
$student->get_by_id($test_queue->student_id);
$tests = new Test();
$tests->where_related($test_queue);
$tests->get_iterated();
try {
if ($task_set->exists() && $student->exists() && $tests->exists()) {
$version = $test_queue->version;
$run_evaluation = $task_set->enable_tests_scoring > 0 && $task_set->course_test_scoring_deadline >= date('Y-m-d H:i:s') ? TRUE : FALSE;
$score_percent = array();
$score_points = array();
$bonus_percent = array();
$bonus_points = array();
$total_tests_count = $tests->result_count();
foreach ($tests as $test) {
$test_queue->single_test_exec_start = date('Y-m-d H:i:s');
$test_queue->save();
$files = $task_set->get_student_files($student->id, (int) $version);
if (isset($files[(int) $version]['filepath']) && file_exists($files[(int) $version]['filepath'])) {
$test_object = $this->load->test($test->type);
$test_object->initialize($test);
$token = '';
//echo 'Test queue ' . $test_queue->id . ' is running test ' . $test->id . ' ... ' . PHP_EOL;
try {
$test_output = $test_object->run($files[(int) $version]['filepath'], $run_evaluation && $test->enable_scoring > 0, $student->id, $token);
$test_score = $test_object->get_last_test_score();
} catch (Exception $e) {
$test_output = $e->getMessage();
$test_score = 0;
}
$test_queue->set_join_field($test, 'result_text', $test_output);
$test_queue->set_join_field($test, 'evaluation_table', $test_object->get_last_test_scoring());
$test_queue->set_join_field($test, 'result', $test_object->get_last_exit_code());
//echo 'Test queue ' . $test_queue->id . ' is done with test ' . $test->id . ' ... ' . PHP_EOL;
if ($run_evaluation && $test->enable_scoring > 0) {
$this->db->select('*');
$task_id = $test->task_id;
$this->db->where('task_set_id', $task_set->id);
$this->db->where('task_id', (int) $task_id);
$query = $this->db->get('task_task_set_rel');
if ($query->num_rows() > 0) {
$task_rel = $query->row_object();
$min = (double) $task_rel->test_min_points;
$max = (double) $task_rel->test_max_points;
$percent = (double) $test_score / 100.0;
$points = (1.0 - $percent) * $min + $percent * $max;
if ($task_rel->bonus_task == 0) {
$test_queue->set_join_field($test, 'percent_points', $test_score);
$test_queue->set_join_field($test, 'points', $points);
$score_percent[$task_id] = isset($score_percent[$task_id]) ? $score_percent[$task_id] + $percent : $percent;
$percent = (double) $score_percent[$task_id];
$points = (1.0 - $percent) * $min + $percent * $max;
$score_points[$task_id] = $points;
//.........这里部分代码省略.........