tinyqc/app/Controllers/PageController.php
mahdahar ff90e0eb29 Initial commit: Add CodeIgniter 4 QC application with full MVC structure
- CodeIgniter 4 framework setup with SQL Server database config
- Models: Control, Test, Dept, Result, Daily/ Monthly entry models
- Controllers: Dashboard, Control, Test, Dept, Entry, Report, API endpoints
- Views: CRUD pages with modal dialogs, dashboard, reports
- Database: Migrations for control test and daily/monthly result tables
- Legacy v1 PHP application preserved in /v1 directory
- Documentation: AGENTS.md, VIEWS_RULES.md for development guidelines
2026-01-14 16:49:27 +07:00

159 lines
5.1 KiB
PHP

<?php
namespace App\Controllers;
class PageController extends BaseController
{
protected $dictDeptModel;
protected $dictTestModel;
protected $dictControlModel;
protected $resultModel;
protected $controlTestModel;
protected $commentModel;
public function __construct()
{
$this->dictDeptModel = new \App\Models\DictDeptModel();
$this->dictTestModel = new \App\Models\DictTestModel();
$this->dictControlModel = new \App\Models\DictControlModel();
$this->resultModel = new \App\Models\ResultModel();
$this->controlTestModel = new \App\Models\ControlTestModel();
$this->commentModel = new \App\Models\ResultCommentModel();
}
public function dashboard(): string
{
return view('dashboard', [
'depts' => $this->dictDeptModel->findAll(),
'tests' => $this->dictTestModel->getWithDept(),
'controls' => $this->dictControlModel->getWithDept(),
'recent_results' => $this->resultModel->findAll(20),
'page_title' => 'Dashboard',
'active_menu' => 'dashboard'
]);
}
public function dept(): string
{
return view('dept/index', [
'title' => 'Department Dictionary',
'depts' => $this->dictDeptModel->findAll(),
'active_menu' => 'dept',
'page_title' => 'Department Dictionary'
]);
}
public function test(): string
{
return view('test/index', [
'title' => 'Test Dictionary',
'tests' => $this->dictTestModel->getWithDept(),
'depts' => $this->dictDeptModel->findAll(),
'active_menu' => 'test',
'page_title' => 'Test Dictionary'
]);
}
public function control(): string
{
return view('control/index', [
'title' => 'Control Dictionary',
'controls' => $this->dictControlModel->getWithDept(),
'depts' => $this->dictDeptModel->findAll(),
'tests' => $this->dictTestModel->getWithDept(),
'active_menu' => 'control',
'page_title' => 'Control Dictionary'
]);
}
public function entry(): string
{
return view('entry/monthly', [
'title' => 'Monthly Entry',
'depts' => $this->dictDeptModel->findAll(),
'active_menu' => 'entry',
'page_title' => 'Monthly Entry'
]);
}
public function entryDaily(): string
{
return view('entry/daily', [
'title' => 'Daily Entry',
'depts' => $this->dictDeptModel->findAll(),
'active_menu' => 'entry_daily',
'page_title' => 'Daily Entry'
]);
}
public function report(): string
{
return view('report/index', [
'title' => 'Reports',
'depts' => $this->dictDeptModel->findAll(),
'tests' => $this->dictTestModel->findAll(),
'controls' => $this->dictControlModel->findAll(),
'active_menu' => 'report',
'page_title' => 'Reports'
]);
}
public function reportView(): string
{
$control1 = $this->request->getGet('control1') ?? 0;
$control2 = $this->request->getGet('control2') ?? 0;
$control3 = $this->request->getGet('control3') ?? 0;
$dates = $this->request->getGet('dates') ?? date('Y-m');
$test = $this->request->getGet('test') ?? 0;
$controls = [];
if ($control1) {
$c1 = $this->dictControlModel->find($control1);
if ($c1) $controls[] = $c1;
}
if ($control2) {
$c2 = $this->dictControlModel->find($control2);
if ($c2) $controls[] = $c2;
}
if ($control3) {
$c3 = $this->dictControlModel->find($control3);
if ($c3) $controls[] = $c3;
}
$reportData = [];
foreach ($controls as $control) {
$controlTest = $this->controlTestModel->getByControlAndTest($control['control_id'], $test);
$results = $this->resultModel->getByMonth($control['control_id'], $test, $dates);
$comment = $this->commentModel->getByControlTestMonth($control['control_id'], $test, $dates);
$outOfRangeCount = 0;
if ($controlTest && $controlTest['sd'] > 0) {
foreach ($results as $res) {
if (abs($res['resvalue'] - $controlTest['mean']) > 2 * $controlTest['sd']) {
$outOfRangeCount++;
}
}
}
$reportData[] = [
'control' => $control,
'controlTest' => $controlTest,
'results' => $results,
'comment' => $comment,
'test' => $this->dictTestModel->find($test),
'outOfRange' => $outOfRangeCount
];
}
return view('report/view', [
'title' => 'QC Report',
'reportData' => $reportData,
'dates' => $dates,
'test' => $test,
'depts' => $this->dictDeptModel->findAll(),
'active_menu' => 'report',
'page_title' => 'QC Report'
]);
}
}