本文整理汇总了PHP中Test::find方法的典型用法代码示例。如果您正苦于以下问题:PHP Test::find方法的具体用法?PHP Test::find怎么用?PHP Test::find使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Test
的用法示例。
在下文中一共展示了Test::find方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: showChart
public function showChart()
{
$testID = Input::get('test');
$test = Test::find($testID)->name;
$data = array('test' => $test);
return View::make('chart', $data);
}
示例2: delete_delete
function delete_delete($data)
{
$sql = Test::find($data->id);
$retorno = $sql->to_json();
$sql->delete();
return '{"result": [' . $retorno . ']}';
}
示例3: edit
/**
* Show the form for editing the specified resource.
* GET /medications/{id}/edit
*
* @param int $id
* @return Response
*/
public function edit($id)
{
$test_items = Billing::select('id', 'item')->where('type', '=', 'Laboratory Test')->get();
$prescription_items = Billing::select('id', 'item')->where('type', '=', 'Medication')->get();
$medication = Medication::find($id);
$test = Test::find($id);
return View::make('medications.edit', compact('medication', 'test_items', 'prescription_items', 'test'));
}
示例4: test_find_all_returns_array
function test_find_all_returns_array()
{
# create two test entries to be found
Test::create(array("dummy" => "Test 1"), array("dummy" => "Test 2"));
$result = Test::find_all(array("conditions" => "id = 1"));
$this->assertTrue(is_array($result));
$this->assertEqual(count($result), 1);
$result = Test::find("all", array("conditions" => array("id = ?", 2)));
$this->assertTrue(is_array($result));
$this->assertEqual(count($result), 1);
}
示例5: test_has_many_with_preloaded_data
function test_has_many_with_preloaded_data()
{
setup_sqlite_test_db();
preload_sqlite_data();
$test1 = Test::find(1);
$results1 = $test1->test_results;
$this->assertEqual(count($results1), 1);
$test2 = Test::find(2);
$results2 = $test2->test_results;
$this->assertEqual(count($results2), 2);
}
示例6: delete_destroy
public function delete_destroy($id)
{
$test = Test::find($id);
if (!$test) {
return Response::error('404');
} else {
if ($test->destroy_if_user_can(Auth::user()->id)) {
return Redirect::to_route('test_list')->with('success', 'Test deleted.');
} else {
return Response::error('403');
}
}
}
示例7: showAction
/**
* Display one result
*
* @param $id
* @param $rid
*/
public function showAction($id, $rid)
{
$test = Test::find($id);
if (is_null($test)) {
return Redirect::route('tests.index')->with('error', 'Incorrect test id');
}
$single = Result::find($rid);
if (is_null($single) || $single->test_id != $id) {
return Redirect::route('tests.index')->with('error', 'Невозможно найти результаты');
}
$results = Result::where('test_id', $id)->where('token', $single->token)->orderBy('question_id', 'asc')->get();
if (!count($results)) {
return Redirect::route('tests.index')->with('error', 'Отсутствуют результаты теста');
}
$score = 0;
$max = 0;
foreach ($results as $result) {
$score += $result->weight;
if ($max < $result->created_at->format('U')) {
$max = $result->created_at->format('U');
}
}
$weights = [];
$tw = 0;
foreach ($test->questions as $q) {
$weights[$q->id] = 0;
foreach ($q->answers as $a) {
if (!$a->is_correct) {
continue;
}
$weights[$q->id] += $a->weight;
$tw += $a->weight;
}
if ($q->type == Question::TYPE_STRING) {
$weights[$q->id] += 1;
$tw += 1;
}
}
$token = Token::where('token', $result->token)->get();
$ends = $max - $token[0]->start;
$min = (int) ($ends / 60);
$sec = $ends - $min * 60;
$ends = ($min < 10 ? '0' . $min : $min) . ':' . ($sec < 10 ? '0' . $sec : $sec);
return View::make('tests.results_show', ['token' => Token::where('token', $single->token)->get()[0], 'test' => $test, 'total_questions' => count($test->questions), 'total_weight' => $tw, 'results' => $results, 'weights' => $weights, 'score' => $score, 'duration' => $ends]);
}
示例8: test_create
function test_create()
{
setup_sqlite_test_db();
# Create a dummy test entry, ensure it is of correct type and got its
# parameters correctly saved
$dummy = Test::create(array("dummy" => "Test456"));
$this->assertEqual(strtolower(get_class($dummy)), "test");
$this->assertEqual($dummy->_base_class, "Test");
$this->assertEqual($dummy->dummy, "Test456");
$this->assertTrue($dummy->id > 0);
# Now create two test entries at once
$dummys = Test::create(array("dummy" => "Test567"), array("dummy" => "Test678"));
$this->assertEqual(count($dummys), 2);
# Return the complete table and check there is exactly one row
$all_rows = Test::find("all");
$this->assertEqual(count($all_rows), 3);
# Return the first row and check it still matches our first dummy test entry
$first = Test::find("first");
$this->assertEqual($first->dummy, "Test456");
$this->assertTrue($first->id > 0);
}
示例9: store
/**
* Store a newly created resource in storage.
*
* @return Response
*/
public function store()
{
$action = Input::get('action');
$workUp = new Culture();
$workUp->user_id = Input::get('userId');
$workUp->test_id = Input::get('testId');
$workUp->observation = Input::get('obs');
if ($action == 'add') {
$workUp->save();
return 0;
} else {
if ($action == 'draw') {
$obsv = Test::find($workUp->test_id)->culture;
foreach ($obsv as $observation) {
$observation->user = User::find($observation->user_id)->name;
$observation->timeStamp = Culture::showTimeAgo($observation->created_at);
}
return json_encode($obsv);
}
}
}
示例10: testTableMethods
function testTableMethods()
{
$id = $this->addRow();
$updatedRow = array('name' => 'test updated', 'id' => $id);
$this->assert(Test::update($updatedRow) === $id, "Update failed");
$this->assert(Test::find($id)->export() == $updatedRow, "Test::find failed");
$s = Test::findAll();
$sc = $s->count();
$this->assert($s->count() == 1, "Test::findAll(NO ARGUMENTS) failed (incorrect count {$sc})");
$sf = $s->export()->fetch(PDO::FETCH_ASSOC);
$this->assert($s->export()->fetch(PDO::FETCH_ASSOC) == $updatedRow, "Test::findAll(NO ARGUMENTS) failed (incorrect row " . var_export($sf, 1) . ")");
$s = Test::findAll(array('name = ?' => $updatedRow['name']));
$sc = $s->count();
$this->assert($s->count() == 1, "Test::findAll(EXISTING_ROW) failed (incorrect count {$sc})");
$sf = $s->export()->fetch(PDO::FETCH_ASSOC);
$this->assert($sf == $updatedRow, "Test::findAll(EXISTING_ROW) failed (incorrect row " . var_export($sf, 1) . ")");
$s = Test::findAll(array('name = ?' => $updatedRow['non-existing']));
$sc = $s->count();
$this->assert($s->count() == 0, "Test::findAll(NON_EXISTING_ROW) failed (incorrect count {$sc})");
$sf = $s->export()->fetch(PDO::FETCH_ASSOC);
$this->assert($sf == false, "Test::findAll(NON_EXISTING_ROW) failed (incorrect row " . var_export($sf, 1) . ")");
}
示例11: surveylistAction
public function surveylistAction()
{
$manager = $this->session->get("Manager");
$tests = Test::find(array("school_id = :school_id:", "bind" => array("school_id" => $manager["school_id"]), "sort" => "id desc"));
$now = date("Y-m-d H:i:s");
$list = array();
foreach ($tests as $index => $test) {
/*
* status
* 0: 测试未开始
* 1: 测试正在进行中
* 2: 测试已经过期
*/
$import = Student::count(array("test_id= :test_id:", "bind" => array("test_id" => $test->t_id)));
$status = 0;
if ($now >= $test->begin_time && $now <= $test->end_time) {
$status = 1;
} else {
if ($now > $test->end_time) {
$status = 2;
}
}
$item = array("test_id" => $test->t_id, "people" => $test->people, "begin" => substr($test->begin_time, 0, strlen($test->begin_time) - 3), "end" => substr($test->end_time, 0, strlen($test->end_time) - 3), "description" => $test->description, "status" => $status, "import" => $import);
$list[$index] = $item;
}
$this->view->setVar("tests", $list);
// 设置url
$url = $this->makeurl();
$this->view->setVar("url", $url);
$this->view->setRenderLevel(\Phalcon\Mvc\View::LEVEL_ACTION_VIEW);
}
示例12: createJsonString
/**
* Retrieves the results and creates a JSON string
*
* @param testId the id of the test to send
* @param
*/
public function createJsonString($testId)
{
//if($comments==null or $comments==''){$comments = 'No Comments';
//We use curl to send the requests
$httpCurl = curl_init(Config::get('kblis.sanitas-url'));
curl_setopt($httpCurl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($httpCurl, CURLOPT_POST, true);
//If testID is null we cannot handle this test as we cannot know the results
if ($testId == null) {
return null;
}
//Get the test and results
$test = Test::find($testId);
$testResults = $test->testResults;
//Measures
$testTypeId = $test->testType()->get()->lists('id')[0];
$testType = TestType::find($testTypeId);
$testMeasures = $testType->measures;
//Get external requests and all its children
$externalDump = new ExternalDump();
$externRequest = ExternalDump::where('test_id', '=', $testId)->get();
if (!$externRequest->first()) {
//Not a request we can send back
return null;
}
$labNo = $externRequest->lists('lab_no')[0];
$externlabRequestTree = $externalDump->getLabRequestAndMeasures($labNo);
$interpretation = "";
//IF the test has no children prepend the status to the result
if ($externlabRequestTree->isEmpty()) {
if ($test->test_status_id == Test::COMPLETED) {
$interpretation = "Done: " . $test->interpretation;
} elseif ($test->test_status_id == Test::VERIFIED) {
$interpretation = "Tested and verified: " . $test->interpretation;
}
} else {
if ($test->test_status_id == Test::COMPLETED) {
$interpretation = "Done " . $test->interpretation;
} elseif ($test->test_status_id == Test::VERIFIED) {
$interpretation = "Tested and verified " . $test->interpretation;
}
}
//TestedBy
$tested_by = ExternalUser::where('internal_user_id', '=', $test->tested_by)->get()->first();
if ($tested_by == null) {
$tested_by = "59";
} else {
if ($tested_by->external_user_id == null) {
$tested_by = "59";
} else {
$tested_by = $tested_by->external_user_id;
}
}
if ($test->verified_by == 0 || $test->verified_by == null) {
$verified_by = "59";
} else {
$verified_by = ExternalUser::where('internal_user_id', '=', $test->verified_by)->get()->first();
if ($verified_by == null) {
$verified_by = "59";
} else {
if ($verified_by->external_user_id == null) {
$verified_by = "59";
} else {
$verified_by = $verified_by->external_user_id;
}
}
}
//TODO - relate measure to test-result
$range = Measure::getRange($test->visit->patient, $testResults->first()->measure_id);
$unit = Measure::find($testResults->first()->measure_id)->unit;
$result = $testResults->first()->result . " " . $range . " " . $unit;
$jsonResponseString = sprintf('{"labNo": "%s","requestingClinician": "%s", "result": "%s", "verifiedby": "%s", "techniciancomment": "%s"}', $labNo, $tested_by, $result, $verified_by, trim($interpretation));
$this->sendRequest($httpCurl, urlencode($jsonResponseString), $labNo);
//loop through labRequests and foreach of them get the result and put in an array
foreach ($externlabRequestTree as $key => $externlabRequest) {
$mKey = array_search($externlabRequest->investigation, $testMeasures->lists('name'));
if ($mKey === false) {
Log::error("MEASURE NOT FOUND: Measure {$externlabRequest->investigation} not found in our system");
} else {
$measureId = $testMeasures->get($mKey)->id;
$rKey = array_search($measureId, $testResults->lists('measure_id'));
$matchingResult = $testResults->get($rKey);
$range = Measure::getRange($test->visit->patient, $measureId);
$unit = Measure::find($measureId)->unit;
$result = $matchingResult->result . " " . $range . " " . $unit;
$jsonResponseString = sprintf('{"labNo": "%s","requestingClinician": "%s", "result": "%s", "verifiedby": "%s", "techniciancomment": "%s"}', $externlabRequest->lab_no, $tested_by, $result, $verified_by, "");
$this->sendRequest($httpCurl, urlencode($jsonResponseString), $externlabRequest->lab_no);
}
}
curl_close($httpCurl);
}
示例13: getDelete
public function getDelete($id)
{
$row = Test::find($id);
$row->delete();
return Redirect::to('/tests')->with('success', 'Deleted Successfully');
}
示例14: updateAction
/**
* Update the answers
*/
public function updateAction()
{
$data = Input::all();
$num = (int) $data['number_of_answers'];
$test = Test::find($data['test_id']);
$question = Question::find($data['id']);
if (is_null($test) || is_null($question) || $test->id != $question->test->id) {
return Redirect::route('tests.index')->with('error', 'Incorrect id');
}
$validation = Validator::make(['text' => $data['text']], Question::$rules);
if (!$validation->passes()) {
return Redirect::route('question.edit', ['id' => $question->id])->withInput()->withErrors($validation)->with('message', 'There were validation errors.');
}
$oldType = $question->type;
$question->text = $data['text'];
$question->number = $data['number'];
$question->type = $data['type'] ? $data['type'] : Question::TYPE_STRING;
$question->save();
/**
* Erase all old answers
*/
DB::table('answer')->where('question_id', $question->id)->delete();
/**
* Create answers
*/
for ($i = 1; $i <= $num; $i++) {
if (!isset($data['a_' . $i . '_text']) || !trim($data['a_' . $i . '_text'])) {
continue;
}
$answer = new Answer();
$answer->question_id = $question->id;
$answer->text = trim($data['a_' . $i . '_text']);
$answer->weight = (int) $data['a_' . $i . '_weight'];
if ($question->type == Question::TYPE_CHECKBOX) {
$answer->is_correct = isset($data['a_' . $i . '_correct']) ? true : false;
} elseif ($question->type == Question::TYPE_RADIO) {
$answer->is_correct = isset($data['a_0_correct']) && $data['a_0_correct'] == $i ? true : false;
}
if ($answer->is_correct && !$answer->weight) {
$answer->weight = 1;
}
if (!$answer->is_correct) {
$answer->weight = 0;
}
$answer->save();
}
return Redirect::route('tests.show', $test->id);
}
示例15: json_encode
<?php
echo json_encode(Test::find('tests'));