tinyqc/app/Controllers/Qc/ResultsController.php
mahdahar 5cae572916 Refactor application structure, unify entry management, and overhaul UI with DaisyUI
- Reorganized Architecture: Moved Master data management (Controls, Departments, Tests) to a dedicated Master namespace/directory for better modularity.
- Unified Data Entry: Consolidated daily and monthly QC entry views and logic into a single streamlined system.
- UI/UX Modernization:
    - Integrated DaisyUI and Alpine.js for a responsive, themeable, and interactive experience.
    - Replaced legacy layouts with a new DaisyUI-based template.
    - Updated branding with new logo and favicon assets.
    - Cleaned up deprecated JavaScript assets (app.js, charts.js, tables.js).
- Backend Enhancements:
    - Added `ControlEntryModel` and `ResultCommentsController` for improved data handling and auditing.
    - Updated routing to support the new controller structure and consolidated API endpoints.
- Documentation & Assets:
    - Added [docs/PRD.md](cci:7://file:///c:/www/tinyqc/docs/PRD.md:0:0-0:0) and [docs/llms.txt](cci:7://file:///c:/www/tinyqc/docs/llms.txt:0:0-0:0) for project context and requirements.
    - Included database schema scripts and backups in the `backup/` directory.
- Cleanup: Removed legacy TUI progress files and unused commands.
2026-01-19 06:37:37 +07:00

100 lines
2.9 KiB
PHP

<?php
namespace App\Controllers\Qc;
use CodeIgniter\API\ResponseTrait;
use App\Controllers\BaseController;
use App\Models\Qc\ResultsModel;
class ResultsController extends BaseController {
use ResponseTrait;
protected $model;
protected $rules;
public function __construct() {
$this->model = new ResultsModel();
$this->rules = [];
}
public function index() {
$keyword = $this->request->getGet('keyword');
try {
$rows = $this->model->search($keyword);
return $this->respond([
'status' => 'success',
'message' => 'fetch success',
'data' => $rows
], 200);
} catch (\Exception $e) {
return $this->failServerError($e->getMessage());
}
}
public function show($id = null) {
try {
$row = $this->model->find($id);
if (!$row) {
return $this->respond([
'status' => 'success',
'message' => 'data not found.'
], 200);
}
return $this->respond([
'status' => 'success',
'message' => 'fetch success',
'data' => [$row]
], 200);
} catch (\Exception $e) {
return $this->failServerError($e->getMessage());
}
}
public function create() {
$input = $this->request->getJSON(true);
$input = camel_to_snake_array($input);
if (!$this->validate($this->rules)) {
return $this->failValidationErrors($this->validator->getErrors());
}
try {
$id = $this->model->insert($input, true);
return $this->respondCreated([
'status' => 'success',
'message' => $id
]);
} catch (\Exception $e) {
return $this->failServerError($e->getMessage());
}
}
public function update($id = null) {
$input = $this->request->getJSON(true);
$input = camel_to_snake_array($input);
if (!$this->validate($this->rules)) {
return $this->failValidationErrors($this->validator->getErrors());
}
try {
$this->model->update($id, $input);
return $this->respond([
'status' => 'success',
'message' => 'update success',
'data' => [$id]
], 200);
} catch (\Exception $e) {
return $this->failServerError($e->getMessage());
}
}
public function delete($id = null) {
try {
$this->model->delete($id);
return $this->respond([
'status' => 'success',
'message' => 'delete success',
'data' => [$id]
], 200);
} catch (\Exception $e) {
return $this->failServerError($e->getMessage());
}
}
}