当前位置: 首页>>代码示例>>PHP>>正文


PHP Test::where_related方法代码示例

本文整理汇总了PHP中Test::where_related方法的典型用法代码示例。如果您正苦于以下问题:PHP Test::where_related方法的具体用法?PHP Test::where_related怎么用?PHP Test::where_related使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Test的用法示例。


在下文中一共展示了Test::where_related方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: clone_task

 public function clone_task($task_id)
 {
     $result = new stdClass();
     $result->result = FALSE;
     $this->_transaction_isolation();
     $this->db->trans_begin();
     $old_task = new Task();
     $old_task->get_by_id((int) $task_id);
     if ($old_task->exists()) {
         $new_task = $old_task->get_copy();
         if ($new_task->save()) {
             $this->lang->clone_overlays('tasks', $old_task->id, $new_task->id);
             $from = 'private/uploads/task_files/task_' . $old_task->id;
             $continue = TRUE;
             if (file_exists($from)) {
                 $to = 'private/uploads/task_files/task_' . $new_task->id;
                 if (!clone_directory($from, $to)) {
                     unlink_recursive($to, TRUE);
                     $this->db->trans_rollback();
                     $result->message = $this->lang->line('admin_tasks_error_message_files_not_cloned');
                     $continue = FALSE;
                 }
             }
             if ($continue) {
                 $old_categories = new Category();
                 $old_categories->where_related($old_task);
                 $old_categories->get();
                 if ($old_categories->result_count()) {
                     foreach ($old_categories->all as $old_category) {
                         $old_category->save($new_task);
                     }
                 }
                 $old_tests = new Test();
                 $old_tests->where_related($old_task);
                 $old_tests->get();
                 if ($old_tests->result_count()) {
                     foreach ($old_tests->all as $old_test) {
                         $new_test = $old_test->get_copy();
                         if ($new_test->save($new_task)) {
                             $this->lang->clone_overlays('tests', $old_test->id, $new_test->id);
                             $from = 'private/uploads/unit_tests/test_' . $old_test->id;
                             $to = 'private/uploads/unit_tests/test_' . $new_test->id;
                             clone_directory($from, $to);
                         }
                     }
                 }
                 $this->db->trans_commit();
                 $result->result = TRUE;
                 $result->message = $this->lang->line('admin_tasks_success_message_task_cloned');
             }
         } else {
             $this->db->trans_rollback();
             $result->message = $this->lang->line('admin_tasks_error_message_clone_dont_saved');
         }
     } else {
         $this->db->trans_rollback();
         $result->message = $this->lang->line('admin_tasks_error_message_task_not_found');
     }
     $this->output->set_content_type('application/json');
     $this->output->set_output(json_encode($result));
 }
开发者ID:andrejjursa,项目名称:list-lms,代码行数:61,代码来源:tasks.php

示例2: delete

 /**
  * Deletes relations (if parameters are set) or this object from database.
  * @param DataMapper|string $object related object to delete from relation.
  * @param string $related_field relation internal name.
  */
 public function delete($object = '', $related_field = '')
 {
     $this_id = $this->id;
     parent::delete($object, $related_field);
     if (empty($object) && !is_array($object) && !empty($this_id)) {
         $tests = new Test();
         $tests->where_related($this);
         $tests->get();
         if ($tests->result_count()) {
             foreach ($tests->all as $test) {
                 $test->delete();
             }
         }
         $path = 'private/uploads/task_files/task_' . intval($this_id) . '/';
         if (file_exists($path)) {
             unlink_recursive($path, TRUE);
         }
     }
 }
开发者ID:andrejjursa,项目名称:list-lms,代码行数:24,代码来源:task.php

示例3: 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;
//.........这里部分代码省略.........
开发者ID:andrejjursa,项目名称:list-lms,代码行数:101,代码来源:tests.php

示例4: upload_solution

 public function upload_solution($task_set_id = 0)
 {
     $this->usermanager->student_login_protected_redirect();
     $task_set = $this->get_task_set_by_id($course, $group, $student, $task_set_id);
     $task_sets = $this->filter_valid_task_sets($task_set);
     $filtered_task_set = count($task_sets) == 1 ? $task_sets[0] : new Task_set();
     if ($filtered_task_set->id == intval($task_set_id) && $this->can_upload_file($filtered_task_set, $course)) {
         $allowed_file_types_array = trim($filtered_task_set->allowed_file_types) != '' ? array_map('trim', explode(',', $filtered_task_set->allowed_file_types)) : array();
         $config['upload_path'] = 'private/uploads/solutions/task_set_' . intval($task_set_id) . '/';
         $config['allowed_types'] = 'zip' . (count($allowed_file_types_array) ? '|' . implode('|', $allowed_file_types_array) : '');
         $config['max_size'] = intval($this->config->item('maximum_solition_filesize'));
         $current_version = $filtered_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, TRUE);
         $this->load->library('upload', $config);
         if ($this->upload->do_upload('file')) {
             $upload_data = $this->upload->data();
             $mimes = $this->upload->mimes_types('zip');
             if (is_array($mimes) && !in_array($upload_data['file_type'], $mimes) || is_string($mimes) && $upload_data['file_type'] != $mimes) {
                 if (!$this->zip_plain_file_to_archive($upload_data['full_path'], $upload_data['client_name'], $upload_data['file_path'])) {
                     $this->messages->add_message('lang:tasks_task_error_cant_zip_file', Messages::MESSAGE_TYPE_ERROR);
                     redirect(create_internal_url('tasks/task/' . intval($task_set_id)));
                     die;
                 }
             }
             $this->_transaction_isolation();
             $this->db->trans_begin();
             $solution = new Solution();
             $solution->where('task_set_id', $filtered_task_set->id);
             $solution->where('student_id', $student->id);
             $solution->get();
             $revalidate = 1;
             if ($course->test_scoring_deadline >= date('Y-m-d H:i:s') && $filtered_task_set->enable_tests_scoring == 1 && $filtered_task_set->allowed_test_types != '') {
                 $test_types = explode(',', $filtered_task_set->allowed_test_types);
                 $tests = new Test();
                 $tests->where_related('task/task_set', 'id', $filtered_task_set->id);
                 $tests->where('enabled', 1);
                 $tests->where('enable_scoring', 1);
                 $tests->where_in('type', $test_types);
                 $revalidate = $tests->count() > 0 ? 0 : 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' => $filtered_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('tasks_task_solution_upload_log_message'), $config['file_name']), $student, $solution->id);
                 $this->db->trans_commit();
                 $this->messages->add_message('lang:tasks_task_solution_uploaded', Messages::MESSAGE_TYPE_SUCCESS);
                 $this->_action_success();
                 $this->output->set_internal_value('task_set_id', $solution->task_set_id);
             } else {
                 $this->db->trans_rollback();
                 @unlink($config['upload_path'] . $config['file_name']);
                 $this->messages->add_message('lang:tasks_task_solution_canceled_due_db_error', Messages::MESSAGE_TYPE_ERROR);
             }
             redirect(create_internal_url('tasks/task/' . intval($task_set_id)));
         } else {
             $this->parser->assign('file_error_message', $this->upload->display_errors('', ''));
             $this->task($task_set_id);
         }
     } else {
         $this->messages->add_message('lang:tasks_task_error_cant_upload_solution', Messages::MESSAGE_TYPE_ERROR);
         redirect(create_internal_url('tasks/task/' . intval($task_set_id)));
     }
 }
开发者ID:andrejjursa,项目名称:list-lms,代码行数:77,代码来源:tasks.php

示例5: 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;
//.........这里部分代码省略.........
开发者ID:andrejjursa,项目名称:list-lms,代码行数:101,代码来源:cli_test.php


注:本文中的Test::where_related方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。