61 lines
1.8 KiB
PHP
61 lines
1.8 KiB
PHP
<?php
|
|
|
|
namespace App\Controllers;
|
|
|
|
class Tests extends BaseController {
|
|
|
|
public function index() {
|
|
$db = \Config\Database::connect();
|
|
$sql = "SELECT * FROM dict_tests";
|
|
$query = $db->query($sql);
|
|
$results = $query->getResultArray();
|
|
$data['tests'] = $results;
|
|
return view('tests_index.php', $data);
|
|
}
|
|
|
|
public function edit($testid) {
|
|
$data = array();
|
|
if ($testid != 0) {
|
|
$db = \Config\Database::connect();
|
|
$sql = "SELECT * FROM dict_tests where testid='$testid'";
|
|
$query = $db->query($sql);
|
|
$results = $query->getResultArray();
|
|
$data['tests'] = $results;
|
|
}
|
|
if ($this->request->getMethod() === 'post') {
|
|
$rules = [
|
|
'testcode' => 'required',
|
|
'testname' => 'required'
|
|
];
|
|
$testid = $this->request->getPost('testid');
|
|
$testcode = $this->request->getPost('testcode');
|
|
$testname = $this->request->getPost('testname');
|
|
$unit = $this->request->getPost('unit');
|
|
$method = $this->request->getPost('method');
|
|
$data['new_value'] = [
|
|
'testcode' => $testcode,
|
|
'testname' => $testname,
|
|
'unit' => $unit,
|
|
'method' => $method
|
|
];
|
|
if($this->validate($rules)){
|
|
if($testid == 0 ) {
|
|
$db = \Config\Database::connect();
|
|
$sql = "insert into dict_tests(testcode,testname,unit,method) values ('$testcode', '$testname', '$unit', '$method')";
|
|
$query = $db->query($sql);
|
|
return redirect()->to('/tests');
|
|
} else {
|
|
$db = \Config\Database::connect();
|
|
$sql = "update dict_tests set testcode='$testcode', testname='$testname', unit='$unit', method='$method' where testid='$testid'";
|
|
$query = $db->query($sql);
|
|
return redirect()->to('/tests');
|
|
}
|
|
} else {
|
|
$data['validation'] = $this->validator;
|
|
return view('tests_editor',$data);
|
|
}
|
|
}
|
|
return view('tests_editor', $data);
|
|
}
|
|
}
|