本文整理汇总了PHP中Test::where方法的典型用法代码示例。如果您正苦于以下问题:PHP Test::where方法的具体用法?PHP Test::where怎么用?PHP Test::where使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Test
的用法示例。
在下文中一共展示了Test::where方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: findById
public function findById($id, $direction)
{
$testRun = TestRun::where('id', '=', $id)->with(['javaVersion.javaVendor', 'user'])->firstOrFail();
$tests = Test::where('test_run_id', '=', $testRun['id'])->with(['status'])->orderBy('status_id', $direction)->paginate(36);
$testRunArray = $testRun->toArray();
$testRunArray['tests'] = $tests->toArray();
return $testRunArray;
}
示例2: page
public function page()
{
// DB::beginTransaction();
// $result=Test::insert(array(
// 'username'=>'事务',
// 'password'=>'事务2',
// 'paid'=>1000
// ));
// DB::rollback();
// print_r(Test::find(12)->toArray());
$result = Test::where('paid', 5000)->get();
//print_r($result);
foreach ($result as $value) {
$value->paid = 10000;
$value->save();
}
}
示例3: submitTest
public function submitTest($testName)
{
$test = Test::where("name", "=", $testName)->first();
$user = null;
if (Session::has('athleteEmail')) {
$email = Session::get('athleteEmail');
Session::forget('athleteEmail');
$user = User::where("email", "=", $email)->first();
} else {
$user = Auth::user();
}
if ($user != null && $test != null) {
$userAnsweredTest = new UserAnsweredTest();
$userAnsweredTest->idUser = $user->idUser;
$userAnsweredTest->idTest = $test->idTest;
$userAnsweredTest->idProfileAtMoment = $user->idLastProfile;
$userAnsweredTest->save();
$questions = $test->questions->sortBy("number");
// Respuestas
foreach (Input::except('_token') as $input => $answer) {
$splited = explode("-", $input);
$questionNumber = end($splited);
// echo $questionNumber;
$question = $questions->filter(function ($value) use($questionNumber) {
return $value->number == $questionNumber;
})->first();
$userAnswer = new UserAnswer();
$userAnswer->idQuestion = $question->idQuestion;
$userAnswer->idTestAnswer = $answer;
$userAnsweredTest->userAnswers()->save($userAnswer);
}
return Redirect::to('test/' . $testName)->with(array('testSuccessMessage' => 'Gracias, el cuestionario se ha registrado exitosamente!'));
} else {
return Redirect::to('test/' . $testName)->with(array('testErrorMessage' => 'Lo sentimos, ha ocurrido un error al registrar el cuestionario.'));
}
}
示例4: testGetTurnAroundTime
public function testGetTurnAroundTime()
{
$testIDs = Test::where('test_status_id', '=', Test::COMPLETED)->orWhere('test_status_id', '=', Test::VERIFIED)->lists('id');
if (count($testIDs) == 0) {
$this->assertTrue(false);
}
foreach ($testIDs as $id) {
$test = Test::find($id);
$this->assertTrue($test->getTurnaroundTime() >= 0);
}
}
示例5: prevalenceRates
/**
* Display a both chart and table on load.
*
* @return Response
*/
public function prevalenceRates()
{
$from = Input::get('start');
$to = Input::get('end');
$today = date('Y-m-d');
$year = date('Y');
$testTypeID = Input::get('test_type');
// Apply filters if any
if (Input::has('filter')) {
if (!$to) {
$to = $today;
}
if (strtotime($from) > strtotime($to) || strtotime($from) > strtotime($today) || strtotime($to) > strtotime($today)) {
Session::flash('message', trans('messages.check-date-range'));
}
$months = json_decode(self::getMonths($from, $to));
$data = TestType::getPrevalenceCounts($from, $to, $testTypeID);
$chart = self::getPrevalenceRatesChart($testTypeID);
} else {
// Get all tests for the current year
$test = Test::where('time_created', 'LIKE', date('Y') . '%');
$periodStart = $test->min('time_created');
//Get the minimum date
$periodEnd = $test->max('time_created');
//Get the maximum date
$data = TestType::getPrevalenceCounts($periodStart, $periodEnd);
$chart = self::getPrevalenceRatesChart();
}
return View::make('reports.prevalence.index')->with('data', $data)->with('chart', $chart)->withInput(Input::all());
}
示例6: process
/**
* Function for processing the requests we receive from the external system
* and putting the data into our system.
*
* @var array lab_requests
*/
public function process($labRequest)
{
//First: Check if patient exists, if true dont save again
$patient = Patient::where('external_patient_number', '=', $labRequest->patient->id)->get();
if (!$patient->first()) {
$patient = new Patient();
$patient->external_patient_number = $labRequest->patient->id;
$patient->patient_number = $labRequest->patient->id;
$patient->name = $labRequest->patient->fullName;
$gender = array('Male' => Patient::MALE, 'Female' => Patient::FEMALE);
$patient->gender = $gender[$labRequest->patient->gender];
$patient->dob = $labRequest->patient->dateOfBirth;
$patient->address = $labRequest->address->address;
$patient->phone_number = $labRequest->address->phoneNumber;
$patient->created_by = User::EXTERNAL_SYSTEM_USER;
$patient->save();
} else {
$patient = $patient->first();
}
//We check if the test exists in our system if not we just save the request in stagingTable
if ($labRequest->parentLabNo == '0') {
$testTypeId = TestType::getTestTypeIdByTestName($labRequest->investigation);
} else {
$testTypeId = null;
}
if (is_null($testTypeId) && $labRequest->parentLabNo == '0') {
$this->saveToExternalDump($labRequest, ExternalDump::TEST_NOT_FOUND);
return;
}
//Check if visit exists, if true dont save again
$visitType = array('ip' => 'In-patient', 'op' => 'Out-patient');
//Should be a constant
$visit = Visit::where('visit_number', '=', $labRequest->patientVisitNumber)->where('visit_type', '=', $visitType[$labRequest->orderStage])->get();
if (!$visit->first()) {
$visit = new Visit();
$visit->patient_id = $patient->id;
$visit->visit_type = $visitType[$labRequest->orderStage];
$visit->visit_number = $labRequest->patientVisitNumber;
// We'll save Visit in a transaction a little bit below
} else {
$visit = $visit->first();
if (strcmp($visitType[$labRequest->orderStage], $visit->visit_type) != 0) {
$visit = new Visit();
$visit->patient_id = $patient->id;
$visit->visit_type = $visitType[$labRequest->orderStage];
$visit->visit_number = $labRequest->patientVisitNumber;
}
}
$test = null;
//Check if parentLabNO is 0 thus its the main test and not a measure
if ($labRequest->parentLabNo == '0') {
//Check via the labno, if this is a duplicate request and we already saved the test
$test = Test::where('external_id', '=', $labRequest->labNo)->get();
if (!$test->first()) {
//Specimen
$specimen = new Specimen();
$specimen->specimen_type_id = TestType::find($testTypeId)->specimenTypes->lists('id')[0];
// We'll save the Specimen in a transaction a little bit below
$test = new Test();
$test->test_type_id = $testTypeId;
$test->test_status_id = Test::NOT_RECEIVED;
$test->created_by = User::EXTERNAL_SYSTEM_USER;
//Created by external system 0
$test->requested_by = $labRequest->requestingClinician;
$test->external_id = $labRequest->labNo;
DB::transaction(function () use($visit, $specimen, $test) {
$visit->save();
$specimen->save();
$test->visit_id = $visit->id;
$test->specimen_id = $specimen->id;
$test->save();
});
$this->saveToExternalDump($labRequest, $test->id);
return;
}
}
$this->saveToExternalDump($labRequest, null);
}
示例7: groupedTestCount
/**
* Returns grouped test Counts with optional gender, age range, date range
*
* @param $testStatusID, $from, $to
*/
public function groupedTestCount($gender = null, $ageRange = null, $from = null, $to = null)
{
$tests = Test::where('test_type_id', $this->id)->whereIn('test_status_id', [Test::PENDING, Test::STARTED, Test::COMPLETED, Test::VERIFIED]);
if ($to && $from) {
$tests = $tests->whereBetween('time_created', [$from, $to]);
}
if ($gender) {
$tests = $tests->join('visits', 'tests.visit_id', '=', 'visits.id')->join('patients', 'visits.patient_id', '=', 'patients.id')->whereIn('gender', $gender);
}
if ($ageRange) {
$ageRange = explode('-', $ageRange);
$ageStart = $ageRange[0];
$ageEnd = $ageRange[1];
$now = new DateTime('now');
$finishDate = $now->sub(new DateInterval('P' . $ageStart . 'Y'))->format('Y-m-d');
$startDate = $now->sub(new DateInterval('P' . $ageEnd . 'Y'))->format('Y-m-d');
$tests = $tests->whereBetween('dob', [$startDate, $finishDate]);
}
return $tests->count();
}
示例8: deleteAction
/**
* Delete the category
*
* @param $id
*/
public function deleteAction($id)
{
$category = Category::find($id);
if (is_null($category)) {
return Redirect::route('categories.index')->with('error', 'Incorrect category id');
}
/**
* Check if in use
*/
if (count(Test::where('category_id', $id)->get())) {
return Redirect::route('categories.edit', $id)->withInput()->with('message', 'This category is in use and cannot be deleted.');
}
DB::table('category')->where('id', $id)->delete();
return Redirect::route('categories.index');
}
示例9: getNextVersion
/**
* Get next version for the test by its name
*
* @param $name
*
* @return int
*/
private function getNextVersion($name)
{
$tests = Test::where('name', $name)->get();
$max = 0;
foreach ($tests as $test) {
$max = (int) $test->version > $max ? (int) $test->version : $max;
}
return ++$max;
}
示例10: process
public function process($labRequest)
{
//First: Check if patient exists, if true dont save again
$patient = Patient::where('external_patient_number', '=', $labRequest->PatientNumber)->get();
if (!$patient->first()) {
$patient = new Patient();
$patient->external_patient_number = $labRequest->PatientNumber;
$patient->patient_number = $labRequest->PatientNumber;
$patient->name = $labRequest->FullNames;
$gender = array('M' => Patient::MALE, 'F' => Patient::FEMALE, 'U' => Patient::UNKNOWN);
$patient->gender = $gender[$labRequest->Sex];
$patient->dob = $this->getDobFromAge($labRequest->Age);
$patient->address = $labRequest->PoBox;
$patient->phone_number = $labRequest->PatientsContact;
$patient->created_by = User::EXTERNAL_SYSTEM_USER;
} else {
$patient = $patient->first();
}
//We check if the test exists in our system if not we just save the request in stagingTable
$testTypeId = TestType::getTestTypeIdByTestName($labRequest->investigation);
if (is_null($testTypeId) && $labRequest->parentLabNo == '0') {
$this->saveToExternalDump($labRequest, ExternalDump::TEST_NOT_FOUND);
return;
}
//Check if visit exists, if true dont save again
$visit = Visit::where('visit_number', '=', $labRequest->RevisitNumber)->get();
if (!$visit->first()) {
$visit = new Visit();
$visit->visit_type = 'Out-patient';
// We'll save Visit in a transaction a little bit below
} else {
$visit = $visit->first();
}
$test = null;
//Check via the labno, if this is a duplicate request and we already saved the test
$test = Test::where('external_id', '=', $labRequest->RequestID)->get();
if (!$test->first()) {
//Specimen
$specimen = new Specimen();
$specimen->specimen_type_id = TestType::find($testTypeId)->specimenTypes->lists('id')[0];
// We'll save the Specimen in a transaction a little bit below
$test = new Test();
$test->test_type_id = $testTypeId;
$test->test_status_id = Test::NOT_RECEIVED;
$test->created_by = User::EXTERNAL_SYSTEM_USER;
//Created by external system 0
$test->requested_by = $labRequest->DoctorRequesting;
$test->external_id = $labRequest->RequestID;
DB::transaction(function () use($visit, $specimen, $test, $patient) {
$patient->save();
$visit->patient_id = $patient->id;
$visit->visit_number = Visit::orderBy('id', 'desc')->first()->id + 1;
//$labRequest->RevisitNumber;
$visit->save();
$specimen->save();
$test->visit_id = $visit->id;
$test->specimen_id = $specimen->id;
$test->save();
});
$this->saveToExternalDump($labRequest, $test->id);
return;
}
$this->saveToExternalDump($labRequest, null);
mssql_close($connection);
}
示例11: upgrade_java_tests
public function upgrade_java_tests()
{
$this->load->database();
$tests = new Test();
$tests->include_related('task');
$tests->where('type', 'java');
$tests->where('subtype', 'unit_test');
$tests->order_by_related('task', 'name', 'asc');
$tests->order_by('name', 'asc');
$tests->get_iterated();
$unsuccessful_files = array();
if ($tests->exists()) {
echo 'Found ' . $tests->result_count() . ' java unit tests to check, starting process now.' . PHP_EOL;
$this->load->library('cli_progress_bar');
$this->cli_progress_bar->init($tests->result_count());
$this->cli_progress_bar->increment(0);
$this->load->helper('application');
foreach ($tests as $test) {
$this->cli_progress_bar->print_text('Task "' . $test->task_name . '" test "' . $test->name . '" ...', true);
$path_to_dir = APPPATH . '../private/uploads/unit_tests/test_' . $test->id;
$path_to_file = $path_to_dir . '/unit_test/unit_test.zip';
$backup_file = $path_to_dir . '/unit_test/unit_test.backup-' . date('U') . '-' . date('Y-m-d-H-i-s') . '.zip';
if (file_exists($path_to_file)) {
copy($path_to_file, $backup_file);
if (file_exists($backup_file)) {
$this->cli_progress_bar->tick();
do {
$temp_directory = $path_to_dir . '/temp_' . date('U') . '-' . rand(1000, 9999);
} while (file_exists($temp_directory) && is_dir($temp_directory));
mkdir($temp_directory);
if (file_exists($temp_directory) && is_dir($temp_directory)) {
$this->cli_progress_bar->tick();
$zip = new ZipArchive();
if ($zip->open($path_to_file)) {
$zip->extractTo($temp_directory);
$zip->close();
$configuration = @unserialize($test->configuration);
if (is_array($configuration) && array_key_exists('class_to_run', $configuration)) {
$this->cli_progress_bar->tick();
if ($this->upgrade_single_java_unit_test($temp_directory, 'Test' . $configuration['class_to_run'] . '.java')) {
$this->cli_progress_bar->tick();
$zip = new ZipArchive();
if ($zip->open($path_to_file)) {
if ($zip->addFile($temp_directory . '/' . 'Test' . $configuration['class_to_run'] . '.java', 'Test' . $configuration['class_to_run'] . '.java')) {
$this->cli_progress_bar->print_text(' ... Done');
} else {
$this->cli_progress_bar->print_text(' Can\'t update zip archive.');
$unsuccessful_files[] = $path_to_file;
}
$zip->close();
} else {
$this->cli_progress_bar->print_text(' Can\'t open zip archive.');
$unsuccessful_files[] = $path_to_file;
}
} else {
$unsuccessful_files[] = $path_to_file;
}
} else {
$this->cli_progress_bar->print_text(' Can\'t read test configuration.');
$unsuccessful_files[] = $path_to_file;
}
} else {
$this->cli_progress_bar->print_text(' Can\'t open zip archive.');
$unsuccessful_files[] = $path_to_file;
}
unlink_recursive($temp_directory, true);
} else {
$this->cli_progress_bar->print_text(' Can\'t create temporary directory.');
$unsuccessful_files[] = $path_to_file;
}
} else {
$this->cli_progress_bar->print_text(' Can\'t back up zip file.');
$unsuccessful_files[] = $path_to_file;
}
} else {
$this->cli_progress_bar->print_text(' Can\'t find zip file.');
}
$this->cli_progress_bar->increment();
}
} else {
echo 'No java unit tests found.';
}
if (count($unsuccessful_files)) {
echo PHP_EOL . 'Some files can\'t be processed:' . PHP_EOL;
foreach ($unsuccessful_files as $file) {
echo ' ' . $file . PHP_EOL;
}
}
}
示例12: getFilteredTests
private function getFilteredTests($city, $testId, $startDate, $endDate, $sportId, $genderId)
{
$test = Test::where('idTest', '=', $testId)->with('scales.ranges')->first();
// Filtrado (Ciudad)
$query = UserAnsweredTest::whereHas('profile', function ($query) use($city) {
$query->where('idCity', '=', $city);
});
// Filtrado (Test)
$query->whereHas('test', function ($query) use($test) {
$query->where('idTest', '=', $test->idTest);
});
// Filtrado (Fecha)
$query->whereBetween('created_at', array($startDate, $endDate));
// Filtrado (Deporte)
if ($sportId != -1) {
$query->whereHas('profile', function ($query) use($sportId) {
$query->where('idSport', '=', $sportId);
});
}
// Filtrado (Género)
if ($genderId != -1) {
$query->whereHas('user', function ($query) use($genderId) {
$query->where('idGender', '=', $genderId);
});
}
$answeredTests = $query->with('profile.city', 'user.gender', 'test.scales.ranges', 'userAnswers.question.scale', 'userAnswers.testAnswer')->get();
return array('test' => $test, 'answeredTests' => $answeredTests);
}
示例13: 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)));
}
}
示例14: testPaymentRequest
public function testPaymentRequest()
{
// Invoke API URL making a single test request (presumed successful)
$this->call('POST', 'api/receiver', array(), array(), array(), $this->labRequestJsonSimpleTest);
$labR = json_decode($this->labRequestJsonSimpleTest);
// Was the data stored in the external dump?
$externalDump = ExternalDump::where('lab_no', '=', $labR->labNo)->get();
$this->assertTrue(count($externalDump) > 0);
// Was a new patient created?
$patient = Patient::where('external_patient_number', '=', $externalDump->first()->patient_id)->get();
$this->assertTrue(count($patient) > 0);
// Is there a Visit for this new patient?
$visit = Visit::where('patient_id', '=', $patient->first()->id)->get();
$this->assertTrue(count($visit) > 0);
// Is there a Test for this visit?
$test = Test::where('visit_id', '=', $visit->first()->id)->get();
$this->assertTrue(count($visit) > 0);
// Is there a Specimen for this new Test?
$specimen = $test->first()->specimen;
$this->assertTrue(count($specimen) > 0);
$labRPR = json_decode($this->labRequestJsonSimpleTestPayMentRequest);
//Second request similar to first but with payment details
Interfacer::retrieve($labRPR);
// Was the data stored in the external dump?
// There should only be one record. The second only updates the first
$externalDumpPayment = ExternalDump::where('lab_no', '=', $labR->labNo)->get();
$this->assertTrue(count($externalDumpPayment) == 1);
$this->assertEquals($labRPR->receiptNumber, $externalDumpPayment->first()->receipt_number);
}
示例15: 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;
//.........这里部分代码省略.........