From 8fc837508fdccb40f8784fd3eb739c65bb9341db Mon Sep 17 00:00:00 2001 From: mahdahar <89adham@gmail.com> Date: Tue, 26 Nov 2024 16:45:56 +0700 Subject: [PATCH] add db.bak | starting dict-tests --- .gitignore | 2 +- app/Config/Routes.php | 2 + app/Controllers/DictTests.php | 45 +++++++-- app/Views/dictTests_index.php | 140 +++++++++++++++++++++++++--- app/Views/userroles_index.php | 1 - cmod.bak | Bin 0 -> 712704 bytes pbmcDps_dict_tests.csv | 168 ---------------------------------- 7 files changed, 167 insertions(+), 191 deletions(-) create mode 100644 cmod.bak delete mode 100644 pbmcDps_dict_tests.csv diff --git a/.gitignore b/.gitignore index c296bc4..6c63bf6 100644 --- a/.gitignore +++ b/.gitignore @@ -5,4 +5,4 @@ !.gitignore !env !cmod.sql -!pbmcDps_dict_tests.csv \ No newline at end of file +!cmod.bak \ No newline at end of file diff --git a/app/Config/Routes.php b/app/Config/Routes.php index 164fc74..f32ba2a 100644 --- a/app/Config/Routes.php +++ b/app/Config/Routes.php @@ -47,4 +47,6 @@ $routes->post('/api/users/savePass/(:any)', 'Users::savePass/$1'); $routes->post('/api/users/saveRole/(:any)', 'Users::saveRole/$1'); // API - DictTests +$routes->POST('/api/dictTests/search', 'DictTests::search'); $routes->get('/api/dictTests/index', 'DictTests::index'); +$routes->get('/api/dictTests/detail/(:any)', 'DictTests::detail/$1'); diff --git a/app/Controllers/DictTests.php b/app/Controllers/DictTests.php index 86faf69..4982cc9 100644 --- a/app/Controllers/DictTests.php +++ b/app/Controllers/DictTests.php @@ -8,7 +8,7 @@ class DictTests extends ResourceController { public function index() { $db = \Config\Database::connect(); - $sql = "select TESTCODE, SHORTTEXT, TEXT1 from cmod.dbo.CM_DICT_TESTS"; + $sql = "select TESTCODE, TEXT1, TEXT2 from cmod.dbo.CM_DICT_TESTS"; $query = $db->query($sql); $results = $query->getResultArray(); $data['dictTests'] = $results; @@ -16,24 +16,51 @@ class DictTests extends ResourceController { return $this->respond($data, 200); } - public function detail($userroleid) { + public function search() { $db = \Config\Database::connect(); - $sql = "select * from cmod.dbo.CM_USERROLES where USERROLEID='$userroleid'"; + $testcode = $this->request->getPost('testcode'); + $shorttext = $this->request->getPost('shorttext'); + $sql = "select dt.TESTCODE, dt.SHORTTEXT, cdt.TEXT1, cdt.TEXT2, cdt.UNIT, cdt.REFFTEXT from DICT_TESTS dt + left join cmod.dbo.CM_DICT_TESTS cdt on dt.TESTCODE=cdt.TESTCODE"; + // Initialize a WHERE clause + $where= ''; + + // Check if either testcode or shorttext is provided + if (!empty($testcode) || !empty($shorttext)) { + $where= ' WHERE '; + if (!empty($testcode)) { $where .= "dt.TESTCODE like '%$testcode%'"; } + if (!empty($shorttext)) { + if (!empty($testcode)) { $where .= ' OR '; } + $where .= "LOWER(dt.SHORTTEXT) LIKE '%$shorttext%'"; + } + } + $sql .= $where; + $query = $db->query($sql); + $results = $query->getResultArray(); + $data['dictTests'] = $results; + + return $this->respond($data, 200); + } + + public function detail($testcode) { + $db = \Config\Database::connect(); + $sql = "select * from cmod.dbo.CM_DICT_TESTS where TESTCODE='$testcode'"; $query = $db->query($sql); $results = $query->getResultArray(); $data = $results[0]; return $this->respond($data, 200); } - public function save($userroleid) { - $userrolecode = $this->request->getPost('userrolecode'); - $userrolename = $this->request->getPost('userrolename'); + public function save($testcode) { + $text1 = $this->request->getPost('text1'); + $text2 = $this->request->getPost('text2'); + $refftext = $this->request->getPost('refftext'); $db = \Config\Database::connect(); - if($userroleid == 0) { // new - $sql = "INSERT INTO cmod.dbo.CM_USERROLES(USERROLECODE, USERROLENAME, CREATEDATE) VALUES ('$userrolecode', '$userrolename', GETDATE())"; + if($testcode == 0) { // new + $sql = "INSERT INTO cmod.dbo.CM_DICT_TESTS (TESTCODE, TEXT1, TEXT2, REFFTEXT, LOGDATE ) VALUES ('$testcode', '$text1', '$text2', '$refftext' GETDATE())"; } else { //update - $sql = "UPDATE cmod.dbo.CM_USERROLES set USERROLENAME='$userrolename', USERROLECODE='$userrolecode' where USERROLEID='$userroleid'"; + $sql = "UPDATE cmod.dbo.CM_DICT_TESTS set TEXT1='$text1', TEXT2='$text2', REFFTEXT='$refftext', LOGDATE=GETDATE() where TESTCODE='$testcode'"; } if( $db->query($sql) ) { diff --git a/app/Views/dictTests_index.php b/app/Views/dictTests_index.php index 34795b0..a000e77 100644 --- a/app/Views/dictTests_index.php +++ b/app/Views/dictTests_index.php @@ -1,17 +1,32 @@ = $this->extend('layouts/main.php') ?> = $this->section('content') ?> -