本文整理汇总了PHP中Test::get_by_id方法的典型用法代码示例。如果您正苦于以下问题:PHP Test::get_by_id方法的具体用法?PHP Test::get_by_id怎么用?PHP Test::get_by_id使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Test
的用法示例。
在下文中一共展示了Test::get_by_id方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: getTest
function getTest()
{
$t = new Test();
foreach ($t->get_by_id(2)->topic->get() as $o) {
echo $o->to_json();
}
}
示例2: addBatch
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';
}
示例3: lists
function lists($id = 0)
{
if (!$id) {
$id = $this->session->userdata("testid");
}
$test = new Test();
$test->get_by_id((int) $id);
$t = $test->topic->get();
$this->session->set_userdata(array('testid' => $id));
//datamapper的json扩展真是强大
echo $t->all_to_json();
}
示例4: initialize
/**
* This method will initialize this instance of test object with Test model, or id of test model.
* @param DataMapper|integer $test_model Test model or id of test record.
* @throws TestException can be thrown if $test_model is not Test object, test record not exists or test type or subtype is not supported.
*/
public function initialize($test_model)
{
if (is_object($test_model) && !$test_model instanceof Test) {
throw new TestException($this->CI->lang->line('tests_general_error_cant_initialize_with_non_test_model'), 1000001);
} elseif (is_integer($test_model)) {
$test_model_id = $test_model;
$test_model = new Test();
$test_model->get_by_id($test_model_id);
}
if ($test_model->exists()) {
if ($test_model->type !== $this->test_type) {
throw new TestException(sprintf($this->CI->lang->line('tests_general_error_test_type_is_not_supported'), get_class($this)), 1000002);
} elseif (!array_key_exists($test_model->subtype, $this->test_subtypes)) {
throw new TestException(sprintf($this->CI->lang->line('tests_general_error_test_subtype_is_not_supported'), get_class($this)), 1000003);
}
$current_test = array('subtype' => $test_model->subtype, 'config' => unserialize($test_model->configuration), 'id' => $test_model->id, 'enable_scoring' => (int) $test_model->enable_scoring > 0 ? TRUE : FALSE, 'task_id' => $test_model->task_id, 'timeout' => $test_model->timeout);
$this->current_test = $current_test;
} else {
throw new TestException($this->CI->lang->line('tests_general_error_test_record_not_exists'), 1000004);
}
}
示例5: edit
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();
}
}
}
}
示例6: run_single_test
public function run_single_test($test_id, $source_file, $evaluation = FALSE, $student_id = NULL, $token = '')
{
$output = new stdClass();
$output->text = '';
$output->code = 0;
try {
$test = new Test();
$test->get_by_id(intval($test_id));
if ($test->exists()) {
$test_object = $this->load->test($test->type);
$test_object->initialize($test);
$output->text = $test_object->run(decode_from_url($source_file), (bool) (int) $evaluation && strlen($token) > 0, $student_id, $token);
}
} catch (Exception $e) {
$output->text = $e->getMessage();
$output->code = $e->getCode();
}
$this->output->set_content_type('application/json');
$this->output->set_output(json_encode($output));
}