function addBatch() { $users = str_getcsv($_POST['users']); $saved = TRUE; $testid = $this->session->userdata('testid'); $test = new Test(); $test->get_by_id($testid); $this->load->helper("pinyin"); foreach ($users as $user) { $u = new User(); $u->uStudId = $user[0]; $u->uName = str_replace(' ', '', $user[1]); //$u->uPassword = $user[0];//密码等于用户的学号 $pinyin = get_pinyin($u->uName); $u->uPassword = str_replace('_', '', $pinyin); //用拼音作为密码 $u->uType = 'student'; if (!$u->save()) { $saved = FALSE; break; } $test->save($u); } return 'saved'; }
function testRowMethods() { $id = $this->addRow(); $tr = new Test(); $loaded = $tr->load($id); $this->assert($updatedRow = $loaded, "Test->load() failed: " . var_export($loaded, 1)); $exp = $tr->export(); $this->assert($updatedRow = $exp, "Test->export() failed: " . var_export($exp, 1)); $newname = 'test updated again'; $tr->name = $newname; $save = $tr->save(); $this->assert($save, "Test->save() failed: " . var_export($tr->getErrorList(), 1)); $this->assert(Test::count() == 1, "Test::count() failed"); $tr->name = null; $this->assert(!$tr->save(), "Test->save() should have failed (required name rule should fail)!"); $tr->name = array('123'); $this->assert(!$tr->save(), "Test->save() should have failed (string name rule should fail)!"); $tr2 = new Test(); $tr2->name = '000 second row'; // three zeroes - to ensure it sorts above the first one $this->assert($tr2->save(), 'Test->save() failed: ' . var_export($tr->getErrorList(), 1)); $s = Test::findAll(); $s->setOrder('name'); $s->paginate(1, 1); $all = $s->export()->fetchAll(); $this->assert(1 == count($all), 'Select->count() failed after pagination'); $this->assert($tr2->name == $all[0]->name, 'Select->export() failed ordering'); }
function testTable() { $tb = Test::table(); $new_data = ['nickname' => 'z3']; $tb->insert($new_data); $this->assertEquals(1, $tb->count()); $this->assertEquals([['nickname' => 'z3']], $tb->selectData()); $update = $tb->update(['nickname' => 'w5']); $this->assertEquals(1, $update); $this->assertEquals([['nickname' => 'w5']], $tb->selectData()); $tb_new = clone $tb; $tb_new->where('nickname=%s', 'w5'); //$this->assertEquals('SELEC', $tb->buildSelect()); $this->assertEquals([['nickname' => 'w5']], $tb_new->selectData()); $tb_new->clearWhere(); $tb_new->andWhere(['nickname' => 'w5']); //$this->assertEquals('SELEC', $tb->buildSelect()); $this->assertEquals([['nickname' => 'w5']], $tb_new->selectData()); $this->assertEquals(1, $tb_new->update(['nickname' => 'z3'])); $this->assertEquals([['nickname' => 'z3']], $tb->selectData()); $obj_list = $tb->select(); $obj = $obj_list[0]; /* @var $obj Test */ $this->assertEquals('z3', $obj->nickname); $tb->delete(); $test = new Test(); $test->nickname = 'hehe'; $this->assertEquals(TRUE, $test->save()); $this->assertEquals('hehe', Test::table()->selectData()[0]['nickname']); $test->delete(); $this->assertEquals([], $tb->selectData()); $this->assertEquals('SELECT * FROM test Test', $tb->buildSelect()); $this->assertEquals('SELECT * FROM test Test LIMIT 10', $tb->buildSelect(10)); $this->assertEquals('SELECT * FROM test Test LIMIT 10 OFFSET 10', $tb->buildSelect(10, 10)); }
function actionAddMessage($nick, $msg) { $test = new Test(); $test->Name = $nick; $test->Message = $msg; $test->save(); $this->redirect('/'); }
/** * @covers ::initialize */ public function testConstruct() { $test = new Test(); $this->assertNotNull($test->uniqueKey); Test::save($test); $test2 = new Test(); $this->assertNotNull($test2->uniqueKey); $this->assertNotEquals($test->uniqueKey, $test2->uniqueKey); }
/** * @before _secure, _admin */ public function create() { $this->seo(array("title" => "Create Medical Test", "view" => $this->getLayoutView())); $view = $this->getActionView(); if (RequestMethods::post("action") == "medicaltest") { $medicaltest = new Test(array("title" => RequestMethods::post("title"), "details" => RequestMethods::post("details"), "reschedule" => RequestMethods::post("reschedule", 50))); $medicaltest->save(); $view->set("success", true); } }
function addTopicToTest($id = 1) { $toc = new Topic(); $toc->get_by_id($id); $t = new Test(); $t->get_by_id(2); if ($t->save($toc)) { echo $toc->to_json(); } }
/** * Creates a new model. * If creation is successful, the browser will be redirected to the 'view' page. */ public function actionCreate() { $model = new Test(); // Uncomment the following line if AJAX validation is needed // $this->performAjaxValidation($model); if (isset($_POST['Test'])) { $model->attributes = $_POST['Test']; if ($model->save()) { $this->redirect(array('view', 'id' => $model->id)); } } $this->render('create', array('model' => $model)); }
public function actionTest() { // $tests = Test::model()->findAll(); // $names=""; // foreach ($tests as $test) // { // $names=$names.$test->name."</br>"; // } // $this->render("test",array("names"=>$names)); // $new = new Test(); $new->name = "imya"; $new->text = "rrrr"; $new->save(); }
public function actionCreate() { $model = new Test(); if (isset($_POST['Test'])) { $model->setAttributes($_POST['Test']); if ($model->save()) { if (Yii::app()->getRequest()->getIsAjaxRequest()) { Yii::app()->end(); } else { $this->redirect(array('view', 'id' => $model->id)); } } } $this->render('create', array('model' => $model)); }
function test_new_and_save() { setup_sqlite_test_db(); # Create a dummy test entry, ensure it got its parameters and that it's # successfully saved $dummy = new Test(array("dummy" => "Test123")); $this->assertEqual($dummy->dummy, "Test123"); $this->assertTrue($dummy->save()); $this->assertTrue($dummy->id > 0); # Return the complete table and check there is exactly one row $all_rows = Test::find("all"); $this->assertEqual(count($all_rows), 1); # Return the first row and check it matches our dummy test entry $first = Test::find("first"); $this->assertEqual($first->dummy, "Test123"); $this->assertTrue($first->id > 0); }
function post_save($data) { $sql->null; if ($data->id) { //update $sql = Test::find($data->id); //date("d-m-Y H:i:s") date("Y-m-d H:i:s") tanto faz $sql->update_attributes(array('nome' => $data->nome, 'user_id' => $data->user_id, 'updated' => date("Y-m-d H:i:s"))); } else { //insert $attributes = array('nome' => $data->nome, 'user_id' => $data->user_id, 'created' => date("Y-m-d H:i:s")); $sql = new Test($attributes); } $sql->save(); $retorno = $sql->to_json(); return '{"result": [' . $retorno . ']}'; }
public function post_create() { $test = new Test(); $test->description = Input::get('description'); $test->url = Input::get('url'); $test->type = Input::get('type'); $test->user_id = Auth::user()->id; $test->options = Input::get('options'); try { if ($test->save()) { return Redirect::to_route('test_detail', array($test->id)); } else { return Redirect::to('test/create')->with('error', $test->errors->all())->with_input(); } } catch (Max_Tests_Exceeded_Exception $e) { return Redirect::to_route('test_list')->with('error', 'Sorry! You have reached the maximum amount of tests you are allowed.'); } }
public function post_add_test(Test $test) { if (!$this->bool_has_role) { return $this->roleHelper->call_redirect(); } else { $validation_rules = ['category' => 'required|max:50', 'sub_category' => 'required|max:50']; $this->validate($request, $validation_rules); $arr_test_info = array('category' => $request->category, 'sub_category' => $request->sub_category); // $user = new User; foreach ($arr_test_info as $key => $val) { $test->{$key} = $val; } $test->save(); $test_id = $test->id; // return to raw password for view // $arr_user_info['password'] = $request->password; $data = array('arr_test_info' => $arr_test_info, 'arr_logged_in_user' => $this->arr_logged_in_user); return view('test/add_test_results')->with('data', $data); } }
public function actionTest() { $transaction = Yii::app()->db->beginTransaction(); $errors = []; try { for ($i = 0; $i < 4; $i++) { $test1 = new Test(); $test1->attributes = ['name' => '10', 'user_id' => '123', 'no' => '123', 'date' => '2015-01-01', 'datetime' => '2015-01-01 10:10:10', 'varchar' => 'oke']; $test1->save(); if ($test1->hasErrors()) { $errors[] = $test1->errors; } } if (empty($errors)) { $transaction->commit(); } else { var_dump($errors); die; $transaction->rollback(); } } catch (Exception $e) { $transaction->rollback(); } }
public function postAdd() { $test = new Test(Input::all()); $test->save(); return Redirect::to('tests'); }
public function prepare_new_test($task_id) { $task = new Task(); $task->get_by_id($task_id); if (!$task->exists()) { $this->new_test_form($task_id); } else { $this->load->library('form_validation'); $this->form_validation->set_rules('test[name]', 'lang:admin_tests_test_form_field_name', 'required'); $this->form_validation->set_rules('test[type]', 'lang:admin_tests_test_form_field_type', 'required'); $this->form_validation->set_rules('test[subtype]', 'lang:admin_tests_test_form_field_subtype', 'required'); if ($this->form_validation->run()) { $this->_transaction_isolation(); $this->db->trans_begin(); $test_data = $this->input->post('test'); $test = new Test(); $test->name = trim($test_data['name']); $test->type = $test_data['type']; $test->subtype = $test_data['subtype']; $test->enabled = 1; $test->configuration = serialize(array()); if ($test->save($task) && $this->db->trans_status()) { $this->db->trans_commit(); @mkdir('private/uploads/unit_tests/test_' . $test->id, DIR_READ_MODE); $this->messages->add_message('lang:admin_tests_flash_message_new_test_saved', Messages::MESSAGE_TYPE_SUCCESS); $this->_action_success(); redirect(create_internal_url('admin_tests/configure_test/' . $test->id)); } else { $this->db->trans_rollback(); $this->messages->add_message('lang:admin_tests_flash_message_new_test_failed', Messages::MESSAGE_TYPE_ERROR); redirect(create_internal_url('admin_tests/new_test_form/' . $task->id)); } } else { $this->new_test_form($task_id); } } }
</select> </div> </fieldset> <fieldset class="buttons"> <button type="reset">RESET</button> <button type="submit" name="stage" value="2">submit</button> </fieldset> </form> </div>'; break; case "2": $test = new Test("00000", $_POST["startDate"], $_POST["type"], $_POST["startYear"], $_POST["stopYear"]); if ($test->validate()) { if ($test->save()) { $pageBody .= ' <table> <tbody> <tr> <th>date</th> <td>' . $test->getStartDate() . '</td> </tr> <tr> <th>type</th> <td>' . $test->getType() . '</td> </tr> <tr> <th>senior year</th> <td>' . $test->getStopYear() . '</td> </tr>
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); }
public function addTest($school) { $test = new Test(); $test->people = 2; $test->school_id = $school->school_id; $test->begin_time = '2014-12-5 00:00:00'; $test->end_time = '2014-12-15 23:59:59'; $parts = Part::find(); $test->exam_num = $parts->Count(); $test->description = '2014心理健康测评'; if (!$test->save()) { foreach ($school->getMessages() as $message) { throw new PDOException($message); } } foreach ($parts as $part) { $tprel = new Tprel(); $tprel->test_id = $test->t_id; $tprel->part_id = $part->p_id; $tprel->save(); } return $test; }
function actionUnitMethod($method) { $meth = Method::model()->findByPk($method); if ($meth == null) { throw new CHttpException(404, 'Method not found :-('); } $t = UnitTest::model()->findByAttributes(array('id_method' => $method)); if ($t != null) { $this->redirect(array('view', 'id' => $t->id_test)); } else { $model = new Test(); $special = new UnitTest(); $special->id_method = $id_method; // Uncomment the following line if AJAX validation is needed // $this->performAjaxValidation($model); if (isset($_POST['Test'])) { $model->attributes = $_POST['Test']; $special->id_test = 0; if ($model->save()) { $special->id_test = $model->id_test; $special->save(false); $this->redirect(array('view', 'id' => $model->id_test)); } } $this->render('create', array('model' => $model, 'special' => $special)); } }
/** * 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); }
public function edit($id = 0) { $obj = new Test(); $obj->get_by_id((int) $id); if (!$_POST) { echo $obj->to_json(); } else { if (isset($_POST['model']) and $model = $_POST['model']) { $obj->from_json($model); if ($obj->save()) { $this->_user->save($obj); //保存关系 echo $obj->to_json(); } else { echo json_encode(array('error' => $obj->error->string)); } } else { if (isset($_POST['_method']) and $_POST['_method'] === 'DELETE') { $this->_user->delete($obj); $obj->delete(); } } } }
public function addtestAction() { $this->response->setHeader("Content-Type", "text/plain; charset=utf-8"); if ($this->request->isPost()) { $test = new Test(); $sn = $this->request->getPost("date", "string"); $date = explode(" - ", $sn); // $people = $this->request->getPost("people", "int"); $people = 0; $description = $this->request->getPost("description", "string"); $parts = $this->request->getPost("part"); $pcount = count($parts); $test->people = $people; $manager = $this->session->get("Manager"); $test->school_id = $manager["school_id"]; $test->begin_time = date("Y-m-d H:i", strtotime($date[0])); $test->end_time = date("Y-m-d H:i", strtotime($date[1])); $test->exam_num = $pcount; $test->description = $description; $this->db->begin(); try { if ($test->save()) { foreach ($parts as $part) { $tprel = new Tprel(); $tprel->test_id = $test->t_id; $tprel->part_id = $part; $tprel->save(); } $this->db->commit(); echo "true"; } else { throw new PDOException(); } } catch (PDOException $ex) { $this->db->rollback(); echo $ex->getMessage(); echo "保存失败"; } } else { echo "请求数据无效!"; } $this->view->disable(); }
/** * Save a new Test. * * @return Response */ public function saveNewTest() { //Create New Test $rules = array('visit_type' => 'required', 'physician' => 'required', 'testtypes' => 'required'); $validator = Validator::make(Input::all(), $rules); // process the login if ($validator->fails()) { return Redirect::route('test.create', array(Input::get('patient_id')))->withInput()->withErrors($validator); } else { $visitType = ['Out-patient', 'In-patient']; $activeTest = array(); /* * - Create a visit * - Fields required: visit_type, patient_id */ $visit = new Visit(); $visit->patient_id = Input::get('patient_id'); $visit->visit_type = $visitType[Input::get('visit_type')]; $visit->save(); /* * - Create tests requested * - Fields required: visit_id, test_type_id, specimen_id, test_status_id, created_by, requested_by */ $testTypes = Input::get('testtypes'); if (is_array($testTypes)) { foreach ($testTypes as $value) { $testTypeID = (int) $value; // Create Specimen - specimen_type_id, accepted_by, referred_from, referred_to $specimen = new Specimen(); $specimen->specimen_type_id = TestType::find($testTypeID)->specimenTypes->lists('id')[0]; $specimen->accepted_by = Auth::user()->id; $specimen->save(); $test = new Test(); $test->visit_id = $visit->id; $test->test_type_id = $testTypeID; $test->specimen_id = $specimen->id; $test->test_status_id = Test::PENDING; $test->created_by = Auth::user()->id; $test->requested_by = Input::get('physician'); $test->save(); $activeTest[] = $test->id; } } $url = Session::get('SOURCE_URL'); return Redirect::to($url)->with('message', 'messages.success-creating-test')->with('activeTest', $activeTest); } }