Compare commits
No commits in common. "main" and "haris" have entirely different histories.
261
.gitignore
vendored
Executable file → Normal file
261
.gitignore
vendored
Executable file → Normal file
@ -1,129 +1,132 @@
|
||||
#-------------------------
|
||||
# Operating Specific Junk Files
|
||||
#-------------------------
|
||||
|
||||
# OS X
|
||||
.DS_Store
|
||||
.AppleDouble
|
||||
.LSOverride
|
||||
|
||||
# OS X Thumbnails
|
||||
._*
|
||||
|
||||
# Windows image file caches
|
||||
Thumbs.db
|
||||
ehthumbs.db
|
||||
Desktop.ini
|
||||
|
||||
# Recycle Bin used on file shares
|
||||
$RECYCLE.BIN/
|
||||
|
||||
# Windows Installer files
|
||||
*.cab
|
||||
*.msi
|
||||
*.msm
|
||||
*.msp
|
||||
|
||||
# Windows shortcuts
|
||||
*.lnk
|
||||
|
||||
# Linux
|
||||
*~
|
||||
|
||||
# KDE directory preferences
|
||||
.directory
|
||||
|
||||
# Linux trash folder which might appear on any partition or disk
|
||||
.Trash-*
|
||||
|
||||
#-------------------------
|
||||
# Environment Files
|
||||
#-------------------------
|
||||
# These should never be under version control,
|
||||
# as it poses a security risk.
|
||||
.env
|
||||
.vagrant
|
||||
Vagrantfile
|
||||
|
||||
#-------------------------
|
||||
# Temporary Files
|
||||
#-------------------------
|
||||
writable/cache/*
|
||||
!writable/cache/index.html
|
||||
|
||||
writable/logs/*
|
||||
!writable/logs/index.html
|
||||
|
||||
writable/session/*
|
||||
!writable/session/index.html
|
||||
|
||||
writable/uploads/*
|
||||
!writable/uploads/index.html
|
||||
|
||||
writable/debugbar/*
|
||||
!writable/debugbar/.gitkeep
|
||||
|
||||
php_errors.log
|
||||
|
||||
#-------------------------
|
||||
# User Guide Temp Files
|
||||
#-------------------------
|
||||
user_guide_src/build/*
|
||||
user_guide_src/cilexer/build/*
|
||||
user_guide_src/cilexer/dist/*
|
||||
user_guide_src/cilexer/pycilexer.egg-info/*
|
||||
|
||||
#-------------------------
|
||||
# Test Files
|
||||
#-------------------------
|
||||
tests/coverage*
|
||||
|
||||
# Don't save phpunit under version control.
|
||||
phpunit
|
||||
|
||||
#-------------------------
|
||||
# Composer
|
||||
#-------------------------
|
||||
vendor/
|
||||
|
||||
#-------------------------
|
||||
# IDE / Development Files
|
||||
#-------------------------
|
||||
|
||||
# Modules Testing
|
||||
_modules/*
|
||||
|
||||
# phpenv local config
|
||||
.php-version
|
||||
|
||||
# Jetbrains editors (PHPStorm, etc)
|
||||
.idea/
|
||||
*.iml
|
||||
|
||||
# NetBeans
|
||||
/nbproject/
|
||||
/build/
|
||||
/nbbuild/
|
||||
/dist/
|
||||
/nbdist/
|
||||
/nbactions.xml
|
||||
/nb-configuration.xml
|
||||
/.nb-gradle/
|
||||
|
||||
# Sublime Text
|
||||
*.tmlanguage.cache
|
||||
*.tmPreferences.cache
|
||||
*.stTheme.cache
|
||||
*.sublime-workspace
|
||||
*.sublime-project
|
||||
.phpintel
|
||||
/api/
|
||||
|
||||
# Visual Studio Code
|
||||
.vscode/
|
||||
|
||||
/results/
|
||||
/phpunit*.xml
|
||||
/public/.htaccess
|
||||
|
||||
|
||||
#-------------------------
|
||||
# Operating Specific Junk Files
|
||||
#-------------------------
|
||||
|
||||
# OS X
|
||||
.DS_Store
|
||||
.AppleDouble
|
||||
.LSOverride
|
||||
|
||||
# OS X Thumbnails
|
||||
._*
|
||||
|
||||
# Windows image file caches
|
||||
Thumbs.db
|
||||
ehthumbs.db
|
||||
Desktop.ini
|
||||
|
||||
# Recycle Bin used on file shares
|
||||
$RECYCLE.BIN/
|
||||
|
||||
# Windows Installer files
|
||||
*.cab
|
||||
*.msi
|
||||
*.msm
|
||||
*.msp
|
||||
|
||||
# Windows shortcuts
|
||||
*.lnk
|
||||
|
||||
# Linux
|
||||
*~
|
||||
|
||||
# KDE directory preferences
|
||||
.directory
|
||||
|
||||
# Linux trash folder which might appear on any partition or disk
|
||||
.Trash-*
|
||||
|
||||
#-------------------------
|
||||
# Environment Files
|
||||
#-------------------------
|
||||
# These should never be under version control,
|
||||
# as it poses a security risk.
|
||||
.env
|
||||
.vagrant
|
||||
Vagrantfile
|
||||
|
||||
#-------------------------
|
||||
# Temporary Files
|
||||
#-------------------------
|
||||
writable/cache/*
|
||||
!writable/cache/index.html
|
||||
|
||||
writable/logs/*
|
||||
!writable/logs/index.html
|
||||
|
||||
writable/session/*
|
||||
!writable/session/index.html
|
||||
|
||||
writable/uploads/*
|
||||
!writable/uploads/index.html
|
||||
|
||||
writable/debugbar/*
|
||||
!writable/debugbar/.gitkeep
|
||||
|
||||
php_errors.log
|
||||
|
||||
#-------------------------
|
||||
# User Guide Temp Files
|
||||
#-------------------------
|
||||
user_guide_src/build/*
|
||||
user_guide_src/cilexer/build/*
|
||||
user_guide_src/cilexer/dist/*
|
||||
user_guide_src/cilexer/pycilexer.egg-info/*
|
||||
|
||||
#-------------------------
|
||||
# Test Files
|
||||
#-------------------------
|
||||
tests/coverage*
|
||||
|
||||
# Don't save phpunit under version control.
|
||||
phpunit
|
||||
|
||||
#-------------------------
|
||||
# Composer
|
||||
#-------------------------
|
||||
vendor/
|
||||
|
||||
#-------------------------
|
||||
# IDE / Development Files
|
||||
#-------------------------
|
||||
|
||||
# Modules Testing
|
||||
_modules/*
|
||||
|
||||
# phpenv local config
|
||||
.php-version
|
||||
|
||||
# Jetbrains editors (PHPStorm, etc)
|
||||
.idea/
|
||||
*.iml
|
||||
|
||||
# NetBeans
|
||||
/nbproject/
|
||||
/build/
|
||||
/nbbuild/
|
||||
/dist/
|
||||
/nbdist/
|
||||
/nbactions.xml
|
||||
/nb-configuration.xml
|
||||
/.nb-gradle/
|
||||
|
||||
# Sublime Text
|
||||
*.tmlanguage.cache
|
||||
*.tmPreferences.cache
|
||||
*.stTheme.cache
|
||||
*.sublime-workspace
|
||||
*.sublime-project
|
||||
.phpintel
|
||||
/api/
|
||||
|
||||
# Visual Studio Code
|
||||
.vscode/
|
||||
|
||||
/results/
|
||||
/phpunit*.xml
|
||||
/public/.htaccess
|
||||
|
||||
#-------------------------
|
||||
# Claude
|
||||
#-------------------------
|
||||
.claude
|
||||
2
.serena/.gitignore
vendored
2
.serena/.gitignore
vendored
@ -1,2 +0,0 @@
|
||||
/cache
|
||||
/project.local.yml
|
||||
@ -1 +0,0 @@
|
||||
CLQMS backend is a PHP 8.1+ CodeIgniter 4 API-only project that follows PSR-12 spacing/brace rules and prefers short arrays. New PHP files should enable `declare(strict_types=1)` and use typed arguments/returns (nullable unions over doc-only hints). Controllers use `ResponseTrait` to emit `{ status, message, data }` JSON responses; shared logic lives in `app/Libraries`/`app/Traits`. Guard clauses and single-purpose helpers keep methods ~40 lines; repeated flows are extracted. Database work uses Query Builder/Model methods, `helper('utc')`, and `checkDbError()` for manual queries. Multi-table writes wrap `$this->db->transStart()/transComplete()` with status checks. Lookups leverage `App\\Libraries\\Lookups` and JSON files in `app/Libraries/Data/valuesets/`. Routes stay in `app/Config/Routes.php` grouped by resource; filters like `auth` guard protected routes. Audits/logging use `log_message` with sanitized data. Tests live under `tests/Feature` and `tests/Unit`, use PHPUnit 10.5+ conventions, and expect status assertions per HTTP semantics.
|
||||
@ -1,14 +0,0 @@
|
||||
Essential commands for CLQMS development (run from repo root on Windows PowerShell):
|
||||
|
||||
• `composer install` – install PHP dependencies before running CodeIgniter or tests.
|
||||
• `npm install` – sync `package-lock.json` for tooling such as API docs bundler.
|
||||
• `./vendor/bin/phpunit` – run entire PHPUnit suite (or target files via `--filter`).
|
||||
• `php spark test --filter <Class>::<method>` – focused test run when you know the class/method.
|
||||
• `php spark migrate` / `php spark migrate:rollback` – apply or roll back database migrations.
|
||||
• `php spark serve` – lightweight dev server for the API while developing locally.
|
||||
• `node public/bundle-api-docs.js` – regenerate bundled OpenAPI docs whenever the YAML files change.
|
||||
• `git status`, `git diff`, `git log --oneline`, `git add <paths>`, `git commit`, `git pull`, `git push` – version control workflow commands.
|
||||
• `ls` / `dir` / `Get-ChildItem` – inspect directories in PowerShell; `cd` to move between directories.
|
||||
• `type <file>` or `Get-Content` – view file contents when tools are not convenient.
|
||||
|
||||
Use these commands routinely after code changes, tests, or migrations.
|
||||
@ -1,10 +0,0 @@
|
||||
When a task is completed in CLQMS backend, follow these wrap-up steps:
|
||||
|
||||
1. Run relevant tests (`./vendor/bin/phpunit` or targeted `php spark test --filter ...`).
|
||||
2. If migrations changed, run `php spark migrate` / `php spark migrate:rollback` locally and ensure schema updates succeed.
|
||||
3. After editing OpenAPI documentation (YAML files or controller mappings), regenerate `public/api-docs.bundled.yaml` via `node public/bundle-api-docs.js` and check it into Git.
|
||||
4. Confirm code adheres to PSR-12/CodeIgniter conventions (strict types, response format, transactions, guard clauses) before committing.
|
||||
5. Review `git status/diff` to ensure only intended files are staged; do not commit `.env` or other secret files.
|
||||
6. For shared logic changes, double-check lookup JSON cache use and response logging.
|
||||
|
||||
These steps keep the API consistent, documented, and tested before merging or deploying.
|
||||
@ -1,154 +0,0 @@
|
||||
# the name by which the project can be referenced within Serena
|
||||
project_name: "clqms01-be"
|
||||
|
||||
|
||||
# list of languages for which language servers are started; choose from:
|
||||
# al bash clojure cpp csharp
|
||||
# csharp_omnisharp dart elixir elm erlang
|
||||
# fortran fsharp go groovy haskell
|
||||
# haxe java julia kotlin lua
|
||||
# markdown
|
||||
# matlab nix pascal perl php
|
||||
# php_phpactor powershell python python_jedi r
|
||||
# rego ruby ruby_solargraph rust scala
|
||||
# swift terraform toml typescript typescript_vts
|
||||
# vue yaml zig
|
||||
# (This list may be outdated. For the current list, see values of Language enum here:
|
||||
# https://github.com/oraios/serena/blob/main/src/solidlsp/ls_config.py
|
||||
# For some languages, there are alternative language servers, e.g. csharp_omnisharp, ruby_solargraph.)
|
||||
# Note:
|
||||
# - For C, use cpp
|
||||
# - For JavaScript, use typescript
|
||||
# - For Free Pascal/Lazarus, use pascal
|
||||
# Special requirements:
|
||||
# Some languages require additional setup/installations.
|
||||
# See here for details: https://oraios.github.io/serena/01-about/020_programming-languages.html#language-servers
|
||||
# When using multiple languages, the first language server that supports a given file will be used for that file.
|
||||
# The first language is the default language and the respective language server will be used as a fallback.
|
||||
# Note that when using the JetBrains backend, language servers are not used and this list is correspondingly ignored.
|
||||
languages:
|
||||
- php
|
||||
|
||||
# the encoding used by text files in the project
|
||||
# For a list of possible encodings, see https://docs.python.org/3.11/library/codecs.html#standard-encodings
|
||||
encoding: "utf-8"
|
||||
|
||||
# line ending convention to use when writing source files.
|
||||
# Possible values: unset (use global setting), "lf", "crlf", or "native" (platform default)
|
||||
# This does not affect Serena's own files (e.g. memories and configuration files), which always use native line endings.
|
||||
line_ending:
|
||||
|
||||
# The language backend to use for this project.
|
||||
# If not set, the global setting from serena_config.yml is used.
|
||||
# Valid values: LSP, JetBrains
|
||||
# Note: the backend is fixed at startup. If a project with a different backend
|
||||
# is activated post-init, an error will be returned.
|
||||
language_backend:
|
||||
|
||||
# whether to use project's .gitignore files to ignore files
|
||||
ignore_all_files_in_gitignore: true
|
||||
|
||||
# advanced configuration option allowing to configure language server-specific options.
|
||||
# Maps the language key to the options.
|
||||
# Have a look at the docstring of the constructors of the LS implementations within solidlsp (e.g., for C# or PHP) to see which options are available.
|
||||
# No documentation on options means no options are available.
|
||||
ls_specific_settings: {}
|
||||
|
||||
# list of additional paths to ignore in this project.
|
||||
# Same syntax as gitignore, so you can use * and **.
|
||||
# Note: global ignored_paths from serena_config.yml are also applied additively.
|
||||
ignored_paths: []
|
||||
|
||||
# whether the project is in read-only mode
|
||||
# If set to true, all editing tools will be disabled and attempts to use them will result in an error
|
||||
# Added on 2025-04-18
|
||||
read_only: false
|
||||
|
||||
# list of tool names to exclude.
|
||||
# This extends the existing exclusions (e.g. from the global configuration)
|
||||
#
|
||||
# Below is the complete list of tools for convenience.
|
||||
# To make sure you have the latest list of tools, and to view their descriptions,
|
||||
# execute `uv run scripts/print_tool_overview.py`.
|
||||
#
|
||||
# * `activate_project`: Activates a project based on the project name or path.
|
||||
# * `check_onboarding_performed`: Checks whether project onboarding was already performed.
|
||||
# * `create_text_file`: Creates/overwrites a file in the project directory.
|
||||
# * `delete_memory`: Delete a memory file. Should only happen if a user asks for it explicitly,
|
||||
# for example by saying that the information retrieved from a memory file is no longer correct
|
||||
# or no longer relevant for the project.
|
||||
# * `edit_memory`: Replaces content matching a regular expression in a memory.
|
||||
# * `execute_shell_command`: Executes a shell command.
|
||||
# * `find_file`: Finds files in the given relative paths
|
||||
# * `find_referencing_symbols`: Finds symbols that reference the given symbol using the language server backend
|
||||
# * `find_symbol`: Performs a global (or local) search using the language server backend.
|
||||
# * `get_current_config`: Prints the current configuration of the agent, including the active and available projects, tools, contexts, and modes.
|
||||
# * `get_symbols_overview`: Gets an overview of the top-level symbols defined in a given file.
|
||||
# * `initial_instructions`: Provides instructions Serena usage (i.e. the 'Serena Instructions Manual')
|
||||
# for clients that do not read the initial instructions when the MCP server is connected.
|
||||
# * `insert_after_symbol`: Inserts content after the end of the definition of a given symbol.
|
||||
# * `insert_before_symbol`: Inserts content before the beginning of the definition of a given symbol.
|
||||
# * `list_dir`: Lists files and directories in the given directory (optionally with recursion).
|
||||
# * `list_memories`: List available memories. Any memory can be read using the `read_memory` tool.
|
||||
# * `onboarding`: Performs onboarding (identifying the project structure and essential tasks, e.g. for testing or building).
|
||||
# * `read_file`: Reads a file within the project directory.
|
||||
# * `read_memory`: Read the content of a memory file. This tool should only be used if the information
|
||||
# is relevant to the current task. You can infer whether the information
|
||||
# is relevant from the memory file name.
|
||||
# You should not read the same memory file multiple times in the same conversation.
|
||||
# * `rename_memory`: Renames or moves a memory. Moving between project and global scope is supported
|
||||
# (e.g., renaming "global/foo" to "bar" moves it from global to project scope).
|
||||
# * `rename_symbol`: Renames a symbol throughout the codebase using language server refactoring capabilities.
|
||||
# For JB, we use a separate tool.
|
||||
# * `replace_content`: Replaces content in a file (optionally using regular expressions).
|
||||
# * `replace_symbol_body`: Replaces the full definition of a symbol using the language server backend.
|
||||
# * `safe_delete_symbol`:
|
||||
# * `search_for_pattern`: Performs a search for a pattern in the project.
|
||||
# * `write_memory`: Write some information (utf-8-encoded) about this project that can be useful for future tasks to a memory in md format.
|
||||
# The memory name should be meaningful.
|
||||
excluded_tools: []
|
||||
|
||||
# list of tools to include that would otherwise be disabled (particularly optional tools that are disabled by default).
|
||||
# This extends the existing inclusions (e.g. from the global configuration).
|
||||
included_optional_tools: []
|
||||
|
||||
# fixed set of tools to use as the base tool set (if non-empty), replacing Serena's default set of tools.
|
||||
# This cannot be combined with non-empty excluded_tools or included_optional_tools.
|
||||
fixed_tools: []
|
||||
|
||||
# list of mode names to that are always to be included in the set of active modes
|
||||
# The full set of modes to be activated is base_modes + default_modes.
|
||||
# If the setting is undefined, the base_modes from the global configuration (serena_config.yml) apply.
|
||||
# Otherwise, this setting overrides the global configuration.
|
||||
# Set this to [] to disable base modes for this project.
|
||||
# Set this to a list of mode names to always include the respective modes for this project.
|
||||
base_modes:
|
||||
|
||||
# list of mode names that are to be activated by default.
|
||||
# The full set of modes to be activated is base_modes + default_modes.
|
||||
# If the setting is undefined, the default_modes from the global configuration (serena_config.yml) apply.
|
||||
# Otherwise, this overrides the setting from the global configuration (serena_config.yml).
|
||||
# This setting can, in turn, be overridden by CLI parameters (--mode).
|
||||
default_modes:
|
||||
|
||||
# initial prompt for the project. It will always be given to the LLM upon activating the project
|
||||
# (contrary to the memories, which are loaded on demand).
|
||||
initial_prompt: ""
|
||||
|
||||
# time budget (seconds) per tool call for the retrieval of additional symbol information
|
||||
# such as docstrings or parameter information.
|
||||
# This overrides the corresponding setting in the global configuration; see the documentation there.
|
||||
# If null or missing, use the setting from the global configuration.
|
||||
symbol_info_budget:
|
||||
|
||||
# list of regex patterns which, when matched, mark a memory entry as read‑only.
|
||||
# Extends the list from the global configuration, merging the two lists.
|
||||
read_only_memory_patterns: []
|
||||
|
||||
# list of regex patterns for memories to completely ignore.
|
||||
# Matching memories will not appear in list_memories or activate_project output
|
||||
# and cannot be accessed via read_memory or write_memory.
|
||||
# To access ignored memory files, use the read_file tool on the raw file path.
|
||||
# Extends the list from the global configuration, merging the two lists.
|
||||
# Example: ["_archive/.*", "_episodes/.*"]
|
||||
ignored_memory_patterns: []
|
||||
388
AGENTS.md
Executable file → Normal file
388
AGENTS.md
Executable file → Normal file
@ -1,153 +1,235 @@
|
||||
# AGENTS.md - Code Guidelines for CLQMS
|
||||
|
||||
> **CLQMS (Clinical Laboratory Quality Management System)** – headless REST API backend built on CodeIgniter 4 with a focus on laboratory workflows, JWT authentication, and synchronized OpenAPI documentation.
|
||||
|
||||
---
|
||||
|
||||
## Repository Snapshot
|
||||
- `app/` holds controllers, models, filters, and traits wired through PSR-4 `App\` namespace.
|
||||
- `tests/` relies on CodeIgniter's testing helpers plus Faker for deterministic fixtures.
|
||||
- Shared response helpers and ValueSet lookups live under `app/Libraries` and `app/Traits` and should be reused before introducing new helpers.
|
||||
- Environment values, secrets, and database credentials live in `.env` but are never committed; treat the file as a reference for defaults.
|
||||
|
||||
---
|
||||
|
||||
## Build, Lint & Test
|
||||
All commands run from the repository root.
|
||||
|
||||
```bash
|
||||
# Run the entire PHPUnit suite
|
||||
./vendor/bin/phpunit
|
||||
|
||||
# Target a single test file (fast verification)
|
||||
./vendor/bin/phpunit tests/feature/Patients/PatientCreateTest.php
|
||||
|
||||
# Run one test case by method
|
||||
./vendor/bin/phpunit --filter testCreatePatientSuccess tests/feature/Patients/PatientCreateTest.php
|
||||
|
||||
# Generate scaffolding (model, controller, migration)
|
||||
php spark make:model <Name>
|
||||
php spark make:controller <Name>
|
||||
php spark make:migration <name>
|
||||
|
||||
# Database migrations
|
||||
php spark migrate
|
||||
php spark migrate:rollback
|
||||
|
||||
# After OpenAPI edits
|
||||
node public/bundle-api-docs.js
|
||||
```
|
||||
|
||||
Use `php spark test --filter <Class>::<method>` when filtering more than one test file is cumbersome.
|
||||
|
||||
---
|
||||
|
||||
## Agent Rules Scan
|
||||
- No `.cursor/rules/*` or `.cursorrules` directory detected; continue without Cursor-specific constraints.
|
||||
- No `.github/copilot-instructions.md` present; Copilot behaviors revert to general GitHub defaults.
|
||||
|
||||
---
|
||||
|
||||
## Coding Standards
|
||||
|
||||
### Language & Formatting
|
||||
- PHP 8.1+ is the baseline; enable `declare(strict_types=1)` at the top of new files when practical.
|
||||
- Follow PSR-12 for spacing, line length (~120), and brace placement; prefer 4 spaces and avoid tabs.
|
||||
- Use short arrays `[]`, and wrap multiline arguments/arrays with one-per-line items.
|
||||
- Favor expression statements that return early (guard clauses) and keep nested logic shallow.
|
||||
- Keep methods under ~40 lines when possible; extract private helpers for repeated flows.
|
||||
|
||||
### Naming & Types
|
||||
- Classes, controllers, libraries, and traits: PascalCase (e.g., `PatientImportController`).
|
||||
- Methods, services, traits: camelCase (`fetchActivePatients`).
|
||||
- Properties: camelCase for new code; legacy snake_case may persist but avoid new snake_case unless mirroring legacy columns.
|
||||
- Constants: UPPER_SNAKE_CASE.
|
||||
- DTOs/array shapes: Use descriptive names (`$patientInput`, `$validatedPayload`).
|
||||
- Type hints required for method arguments/returns; use union/nullables (e.g., `?string`) instead of doc-only comments.
|
||||
- Prefer PHPDoc only when type inference fails (complex union or array shapes) but still keep method summaries concise.
|
||||
|
||||
### Imports & Structure
|
||||
- Namespace declarations at the very top followed by grouped `use` statements.
|
||||
- Import order: Core framework (`CodeIgniter`), then `App\`, then third-party packages (Firebase, Faker, etc.). Keep each group alphabetical.
|
||||
- No inline `use` statements inside methods.
|
||||
- Keep `use` statements de-duplicated; rely on IDE or `phpcbf` to reorder.
|
||||
|
||||
### Controller Structure
|
||||
- Controllers orchestrate request validation, delegates to services/models, and return `ResponseTrait` responses; avoid direct DB queries here.
|
||||
- Inject models/services via constructor when they are reused. When instantiating on the fly, reference FQCN (`new \App\Models\...`).
|
||||
- Map HTTP verbs to semantic methods (`index`, `show`, `create`, `update`, `delete`). Keep action methods under 30 lines by delegating heavy lifting to models or libraries.
|
||||
- Always respond through `$this->respond()` or `$this->respondCreated()` so JSON structure stays consistent.
|
||||
|
||||
### Response & Error Handling
|
||||
- All responses follow `{ status, message, data }`. `status` values: `success`, `failed`, or `error`.
|
||||
- Use `$this->respondCreated()`, `$this->respondNoContent()`, or `$this->respond()` with explicit HTTP codes.
|
||||
- Wrap JWT/external calls in try/catch. Log unexpected exceptions with `log_message('error', $e->getMessage())` before responding with a sanitized failure.
|
||||
- For validation failures, return HTTP 400 with detailed message; unauthorized access returns 401. Maintain parity with existing tests.
|
||||
|
||||
### Database & Transactions
|
||||
- Use Query Builder or Model methods; enable `use App\Models\BaseModel` which handles UTC conversions.
|
||||
- Always call `helper('utc')` when manipulating timestamps.
|
||||
- Wrap multi-table changes in `$this->db->transStart()` / `$this->db->transComplete()` and check `transStatus()` to abort if false.
|
||||
- Run `checkDbError()` (existing helper) after saves when manual queries are necessary.
|
||||
|
||||
### Service Helpers & Libraries
|
||||
- Encapsulate complex lookups (ValueSet, encryption) inside `app/Libraries` or Traits.
|
||||
- Reuse `App\Libraries\Lookups` for consistent label/value translations.
|
||||
- Keep shared logic (e.g., response formatting, JWT decoding) inside Traits and import them via `use`.
|
||||
|
||||
### Testing & Coverage
|
||||
- Place feature tests under `tests/Feature`, unit tests under `tests/Unit`.
|
||||
- Test class names should follow `ClassNameTest`; methods follow `test<Action><Scenario><Result>` (e.g., `testCreatePatientValidationFail`).
|
||||
- Use `FeatureTestTrait` and `CIUnitTestCase` for API tests; prefer `withBodyFormat('json')->post()` flows.
|
||||
- Assert status codes: 200 for GET/PATCH, 201 for POST, 400 for validation, 401 for auth, 404 for missing resources, 500 for server errors.
|
||||
- Run targeted tests during development, full suite before merging.
|
||||
|
||||
### Documentation & API Sync
|
||||
- Whenever a controller or route changes, update `public/paths/<resource>.yaml` and matching `public/components/schemas`. Add tags or schema refs in `public/api-docs.yaml`.
|
||||
- After editing OpenAPI files, regenerate the bundled docs with `node public/bundle-api-docs.js`. Check `public/api-docs.bundled.yaml` into version control.
|
||||
- Keep the controller-to-YAML mapping table updated to reflect new resources.
|
||||
|
||||
### Routing Conventions
|
||||
- Keep route definitions grouped inside `$routes->group('api/<resource>')` blocks in `app/Config/Routes.php`.
|
||||
- Prefer nested controllers (e.g., `Patient\PatientController`) for domain partitioning.
|
||||
- Use RESTful verbs (GET: index/show, POST: create, PATCH: update, DELETE: delete) to keep behavior predictable.
|
||||
- Document side effects (snapshots, audit logs) directly in the corresponding OpenAPI `paths` file.
|
||||
|
||||
### Environment & Secrets
|
||||
- Use `.env` as the source of truth for database/jwt settings. Do not commit production credentials.
|
||||
- Sample values are provided in `.env`; copy to `.env.local` or CI secrets with overrides.
|
||||
- `JWT_SECRET` must be treated as sensitive and rotated via environment updates only.
|
||||
|
||||
### Workflows & Misc
|
||||
- Use `php spark migrate`/`migrate:rollback` for schema changes.
|
||||
- For seeding or test fixtures, prefer factories (Faker) seeded in `tests/Support` when available.
|
||||
- Document major changes in `issues.md` or dedicated feature docs under `docs/` before merging.
|
||||
|
||||
### Security & Filters
|
||||
- Apply the `auth` filter to every protected route, and keep `ApiKey` or other custom filters consolidated under `app/Filters`.
|
||||
- Sanitize user inputs via `filter_var`, `esc()` helpers, or validated entities before they hit the database.
|
||||
- Always use parameterized queries/Model `save()` methods to prevent SQL injection, especially with legacy PascalCase columns.
|
||||
- Respond 401 for missing tokens, 403 when permissions fail, and log sanitized details for ops debugging.
|
||||
|
||||
### Legacy Field Naming & ValueSets
|
||||
- Databases use PascalCase columns such as `PatientID`, `NameFirst`, `CreatedAt`. Keep migration checks aware of these names.
|
||||
- ValueSet lookups centralize label translation: `Lookups::get('gender')`, `Lookups::getLabel('gender', '1')`, `Lookups::transformLabels($payload, ['Sex' => 'gender'])`.
|
||||
- Prefer `App\Libraries\Lookups` or `app/Traits/ValueSetTrait` to avoid ad-hoc mappings.
|
||||
|
||||
### Nested Data Handling
|
||||
- For entities that carry related collections (`PatIdt`, `PatCom`, `PatAtt`), extract nested arrays before filtering and validating.
|
||||
- Use transactions whenever multi-table inserts/updates occur so orphan rows are avoided.
|
||||
- Guard against empty/null arrays by normalizing to `[]` before iterating.
|
||||
|
||||
### Observability & Logging
|
||||
- Use `log_message('info', ...)` for happy-path checkpoints and `'error'` for catch-all failures.
|
||||
- Avoid leaking sensitive values (tokens, secrets) in logs; log IDs or hash digests instead.
|
||||
- Keep `writable/logs` clean by rotating or pruning stale log files with automation outside the repo.
|
||||
|
||||
---
|
||||
|
||||
## Final Notes for Agents
|
||||
- This repo has no UI layer; focus exclusively on REST interactions.
|
||||
- Always pull `public/api-docs.bundled.yaml` in after running `node public/bundle-api-docs.js` so downstream services see the latest contract.
|
||||
- When in doubt, align with existing controller traits and response helpers to avoid duplicating logic.
|
||||
- Rely on Serena tools for guided edits, searches, and context summaries (use the available symbolic and search tools before running shell commands).
|
||||
# CLQMS Backend - Agent Instructions
|
||||
|
||||
**Project:** Clinical Laboratory Quality Management System (CLQMS) Backend
|
||||
**Framework:** CodeIgniter 4 (PHP 8.1+)
|
||||
**Platform:** Windows - Use PowerShell or CMD for terminal commands
|
||||
**Frontend:** Alpine.js (views/v2 directory)
|
||||
|
||||
## Build / Test Commands
|
||||
|
||||
```bash
|
||||
# Install dependencies
|
||||
composer install
|
||||
|
||||
# Run all tests
|
||||
composer test
|
||||
php vendor/bin/phpunit
|
||||
|
||||
# Run single test file
|
||||
php vendor/bin/phpunit tests/feature/Patients/PatientIndexTest.php
|
||||
|
||||
# Run single test method
|
||||
php vendor/bin/phpunit tests/feature/Patients/PatientIndexTest.php --filter=testIndexWithoutParams
|
||||
|
||||
# Run tests with coverage
|
||||
php vendor/bin/phpunit --coverage-html build/logs/html
|
||||
|
||||
# Run tests in verbose mode
|
||||
php vendor/bin/phpunit --verbose
|
||||
```
|
||||
|
||||
**Test Structure:**
|
||||
- Feature tests: `tests/feature/` - API endpoint testing with `FeatureTestTrait`
|
||||
- Unit tests: `tests/unit/` - Model/Logic testing
|
||||
- Base test case: `Tests\Support\v2\MasterTestCase.php` - Provides JWT auth and helper methods
|
||||
|
||||
## Code Style Guidelines
|
||||
|
||||
### PHP Standards
|
||||
- **PHP Version:** 8.1 minimum
|
||||
- **PSR-4 Autoloading:** Follow namespace-to-path conventions (`App\Controllers\*`, `App\Models\*`)
|
||||
- **Line endings:** Unix-style (LF) - configure editor accordingly
|
||||
|
||||
### Naming Conventions
|
||||
| Element | Convention | Examples |
|
||||
|---------|------------|----------|
|
||||
| Classes | PascalCase | `PatientController`, `BaseModel` |
|
||||
| Methods | camelCase | `getPatient()`, `createPatient()` |
|
||||
| Variables | camelCase | `$internalPID`, `$patientData` |
|
||||
| Constants | UPPER_SNAKE_CASE | `ORDER_PRIORITY`, `TEST_TYPE` |
|
||||
| Table names | snake_case | `patient`, `pat_idt`, `valueset` |
|
||||
| Column names | PascalCase (original DB) | `InternalPID`, `PatientID` |
|
||||
|
||||
### File Organization
|
||||
```
|
||||
app/
|
||||
├── Controllers/{Domain}/
|
||||
│ └── DomainController.php
|
||||
├── Models/{Domain}/
|
||||
│ └── DomainModel.php
|
||||
├── Libraries/
|
||||
│ └── ValueSet.php # Base lookup class (loads from JSON)
|
||||
│ └── Lookups.php # Extends ValueSet - use this for lookups
|
||||
└── Views/v2/
|
||||
```
|
||||
|
||||
### Imports and Namespaces
|
||||
```php
|
||||
<?php
|
||||
namespace App\Controllers\Patient;
|
||||
|
||||
use CodeIgniter\Controller;
|
||||
use CodeIgniter\API\ResponseTrait;
|
||||
use App\Models\Patient\PatientModel;
|
||||
```
|
||||
|
||||
- Use fully qualified class names or `use` statements
|
||||
- Group imports logically
|
||||
- Avoid unnecessary aliases
|
||||
|
||||
### Code Formatting
|
||||
- **Indentation:** 4 spaces (not tabs)
|
||||
- **Braces:** Allman style for classes/functions, K&R for control structures
|
||||
- **Line length:** Soft limit 120 characters
|
||||
- **Empty lines:** Single blank line between method definitions and logical groups
|
||||
|
||||
### Type Hints and Return Types
|
||||
```php
|
||||
// Required for new code
|
||||
public function getPatient(int $internalPID): ?array
|
||||
protected function createPatient(array $input): int
|
||||
private function checkDbError(object $db, string $context): void
|
||||
|
||||
// Use nullable types for optional returns
|
||||
public function findById(?int $id): ?array
|
||||
```
|
||||
|
||||
### Controller Patterns
|
||||
```php
|
||||
class PatientController extends Controller {
|
||||
use ResponseTrait;
|
||||
|
||||
protected $db;
|
||||
protected $model;
|
||||
protected $rules;
|
||||
|
||||
public function __construct() {
|
||||
$this->db = \Config\Database::connect();
|
||||
$this->model = new PatientModel();
|
||||
$this->rules = [...]; // Validation rules
|
||||
}
|
||||
|
||||
public function index() {
|
||||
try {
|
||||
$data = $this->model->findAll();
|
||||
return $this->respond([...], 200);
|
||||
} catch (\Exception $e) {
|
||||
return $this->failServerError($e->getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
### Model Patterns
|
||||
```php
|
||||
class PatientModel extends BaseModel {
|
||||
protected $table = 'patient';
|
||||
protected $primaryKey = 'InternalPID';
|
||||
protected $allowedFields = [...];
|
||||
protected $useSoftDeletes = true;
|
||||
protected $deletedField = 'DelDate';
|
||||
|
||||
public function getPatients(array $filters = []): array {
|
||||
// Query builder chain
|
||||
$this->select('...');
|
||||
$this->join(...);
|
||||
if (!empty($filters['key'])) {
|
||||
$this->where('key', $filters['key']);
|
||||
}
|
||||
return $this->findAll();
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
### Error Handling
|
||||
- Controllers: Use try-catch with `failServerError()`, `failValidationErrors()`, `failNotFound()`
|
||||
- Models: Throw `\Exception` with descriptive messages
|
||||
- Database errors: Check `$db->error()` after operations
|
||||
- Always validate input before DB operations
|
||||
|
||||
### Validation Rules
|
||||
```php
|
||||
protected $rules = [
|
||||
'PatientID' => 'required|regex_match[/^[A-Za-z0-9]+$/]|max_length[30]',
|
||||
'EmailAddress' => 'permit_empty|valid_email|max_length[100]',
|
||||
'Phone' => 'permit_empty|regex_match[/^\+?[0-9]{8,15}$/]',
|
||||
];
|
||||
```
|
||||
|
||||
### Date Handling
|
||||
- All dates stored/retrieved in UTC via `BaseModel` callbacks
|
||||
- Use `utc` helper functions: `convert_array_to_utc()`, `convert_array_to_utc_iso()`
|
||||
- Format: ISO 8601 (`Y-m-d\TH:i:s\Z`) for API responses
|
||||
|
||||
### API Response Format
|
||||
```php
|
||||
// Success
|
||||
return $this->respond([
|
||||
'status' => 'success',
|
||||
'message' => 'Data fetched successfully',
|
||||
'data' => $rows
|
||||
], 200);
|
||||
|
||||
// Created
|
||||
return $this->respondCreated([
|
||||
'status' => 'success',
|
||||
'message' => 'Record created'
|
||||
]);
|
||||
|
||||
// Error
|
||||
return $this->failServerError('Something went wrong: ' . $e->getMessage());
|
||||
```
|
||||
|
||||
### Database Transactions
|
||||
```php
|
||||
$db->transBegin();
|
||||
try {
|
||||
$this->insert($data);
|
||||
$this->checkDbError($db, 'Insert operation');
|
||||
$db->transCommit();
|
||||
return $insertId;
|
||||
} catch (\Exception $e) {
|
||||
$db->transRollback();
|
||||
throw $e;
|
||||
}
|
||||
```
|
||||
|
||||
### Frontend Integration (Alpine.js)
|
||||
- API calls use `BASEURL` global variable
|
||||
- Include `credentials: 'include'` for authenticated requests
|
||||
- Modals use `x-show` with `@click.self` backdrop close
|
||||
|
||||
### Lookups Library
|
||||
Use `App\Libraries\Lookups` (extends `ValueSet`) for all static lookup values. Data is loaded from JSON files in `app/Libraries/Data/valuesets/`:
|
||||
```php
|
||||
use App\Libraries\Lookups;
|
||||
|
||||
// Get formatted for frontend dropdowns [{value: 'X', label: 'Y'}, ...]
|
||||
$gender = Lookups::get('gender');
|
||||
$priorities = Lookups::get('order_priority');
|
||||
|
||||
// Get raw data [{key: 'X', value: 'Y'}, ...]
|
||||
$raw = Lookups::getRaw('gender');
|
||||
|
||||
// Get single label by key
|
||||
$label = Lookups::getLabel('gender', '1'); // Returns 'Female'
|
||||
|
||||
// Get options with key/value pairs
|
||||
$options = Lookups::getOptions('gender');
|
||||
// Returns: [['key' => '1', 'value' => 'Female'], ...]
|
||||
|
||||
// Transform data with lookup labels
|
||||
$patients = Lookups::transformLabels($patients, [
|
||||
'Sex' => 'gender',
|
||||
'Priority' => 'order_priority'
|
||||
]);
|
||||
|
||||
// Clear cache after data changes
|
||||
Lookups::clearCache();
|
||||
```
|
||||
|
||||
### Important Notes
|
||||
- **Soft deletes:** Use `DelDate` field instead of hard delete
|
||||
- **UTC timezone:** All dates normalized to UTC automatically
|
||||
- **JWT auth:** API endpoints require Bearer token in `Authorization` header
|
||||
- **No comments:** Do not add comments unless explicitly requested
|
||||
|
||||
44
LICENSE
Executable file → Normal file
44
LICENSE
Executable file → Normal file
@ -1,22 +1,22 @@
|
||||
The MIT License (MIT)
|
||||
|
||||
Copyright (c) 2014-2019 British Columbia Institute of Technology
|
||||
Copyright (c) 2019-present CodeIgniter Foundation
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
The MIT License (MIT)
|
||||
|
||||
Copyright (c) 2014-2019 British Columbia Institute of Technology
|
||||
Copyright (c) 2019-present CodeIgniter Foundation
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
|
||||
931
README.md
Executable file → Normal file
931
README.md
Executable file → Normal file
@ -1,539 +1,392 @@
|
||||
# CLQMS (Clinical Laboratory Quality Management System)
|
||||
|
||||
> **A REST API backend for modern clinical laboratory workflows.**
|
||||
|
||||
---
|
||||
|
||||
CLQMS is a **headless REST API backend** designed to streamline laboratory operations, ensure data integrity, and manage complex diagnostic workflows. Built on a foundation of precision and regulatory compliance, this system provides comprehensive JSON endpoints for laboratory operations.
|
||||
|
||||
**Key Characteristic:** This is an **API-only system** with no view layer. Frontend applications (web, mobile, desktop) consume these REST endpoints to build laboratory information systems.
|
||||
|
||||
---
|
||||
|
||||
## 🏛️ Core Architecture & Design
|
||||
|
||||
CLQMS is a **headless REST API system** following a clean architecture pattern. The system is designed to be consumed by any frontend client (web, mobile, desktop) through comprehensive JSON endpoints.
|
||||
|
||||
**API-First Architecture:**
|
||||
- **No View Layer:** This system provides REST APIs only - no HTML views, no server-side rendering
|
||||
- **Frontend Agnostic:** Any client can consume these APIs (React, Vue, Angular, mobile apps, desktop apps)
|
||||
- **JSON-First:** All requests/responses use JSON format
|
||||
- **Stateless:** Each API request is independent with JWT authentication
|
||||
|
||||
The system is currently undergoing a strategic **Architectural Redesign** to consolidate legacy structures into a high-performance, maintainable schema. This design focuses on reducing technical debt and improving data consistency across:
|
||||
|
||||
- **Unified Test Definitions:** Consolidating technical, calculated, and site-specific test data.
|
||||
- **Reference Range Centralization:** A unified engine for numeric, threshold, text, and coded results.
|
||||
- **Ordered Workflow Management:** Precise tracking of orders from collection to verification.
|
||||
|
||||
---
|
||||
|
||||
## 🛡️ Strategic Pillars
|
||||
|
||||
- **Precision & Accuracy:** Strict validation for all laboratory parameters and reference ranges.
|
||||
- **Scalability:** Optimized for high-volume diagnostic environments.
|
||||
- **Compliance:** Built-in audit trails and status history for full traceability.
|
||||
- **Interoperability:** Modular architecture designed for LIS, HIS, and analyzer integrations.
|
||||
|
||||
---
|
||||
|
||||
## 🛠️ Technical Stack
|
||||
|
||||
| Component | Specification |
|
||||
| :------------- | :------------ |
|
||||
| **Language** | PHP 8.1+ (PSR-compliant) |
|
||||
| **Framework** | CodeIgniter 4 (API-only mode) |
|
||||
| **Security** | JWT (JSON Web Tokens) Authorization |
|
||||
| **Database** | MySQL (Optimized Schema Migration in progress) |
|
||||
| **API Format** | RESTful JSON |
|
||||
| **Testing** | PHPUnit 10.5+ |
|
||||
|
||||
|
||||
---
|
||||
|
||||
## 📂 Documentation & Specifications
|
||||
|
||||
### Key Documents
|
||||
|
||||
| Document | Location | Description |
|
||||
|----------|----------|-------------|
|
||||
| **PRD** | `PRD.md` | Complete Product Requirements Document (API-focused) |
|
||||
| **Technical Guide** | `CLAUDE.md` | Architecture, coding standards, common commands |
|
||||
| **API Overview** | This file | REST API documentation and endpoints |
|
||||
| **Database Migrations** | `app/Database/Migrations/` | Database schema history |
|
||||
|
||||
### API Documentation
|
||||
|
||||
All API endpoints follow REST conventions:
|
||||
|
||||
**Base URL:** `/api`
|
||||
|
||||
**Authentication:** JWT token required for most endpoints (except `/api/login`, `/api/demo/*`)
|
||||
|
||||
**Response Format:**
|
||||
```json
|
||||
{
|
||||
"status": "success|error",
|
||||
"message": "Human-readable message",
|
||||
"data": { ... }
|
||||
}
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## 🔌 REST API Overview
|
||||
|
||||
### API Endpoint Categories
|
||||
|
||||
#### Authentication & Authorization
|
||||
|
||||
| Method | Endpoint | Description | Auth Required |
|
||||
|--------|----------|-------------|---------------|
|
||||
| `POST` | `/api/login` | User login, returns JWT token | No |
|
||||
| `POST` | `/api/logout` | Invalidate JWT token | Yes |
|
||||
| `POST` | `/api/refresh` | Refresh JWT token | Yes |
|
||||
|
||||
#### Patient Management
|
||||
|
||||
| Method | Endpoint | Description | Auth Required |
|
||||
|--------|----------|-------------|---------------|
|
||||
| `GET` | `/api/patient` | List patients with pagination | Yes |
|
||||
| `GET` | `/api/patient/{id}` | Get patient details | Yes |
|
||||
| `POST` | `/api/patient` | Create new patient | Yes |
|
||||
| `PATCH` | `/api/patient/{id}` | Update patient | Yes |
|
||||
| `DELETE` | `/api/patient/{id}` | Soft delete patient | Yes |
|
||||
|
||||
#### Order Management
|
||||
|
||||
| Method | Endpoint | Description | Auth Required |
|
||||
|--------|----------|-------------|---------------|
|
||||
| `GET` | `/api/ordertest` | List orders | Yes |
|
||||
| `GET` | `/api/ordertest/{id}` | Get order details | Yes |
|
||||
| `POST` | `/api/ordertest` | Create order | Yes |
|
||||
| `PATCH` | `/api/ordertest/{id}` | Update order | Yes |
|
||||
| `DELETE` | `/api/ordertest/{id}` | Delete order | Yes |
|
||||
| `POST` | `/api/ordertest/status` | Update order status | Yes |
|
||||
|
||||
#### Demo/Test Endpoints (No Auth)
|
||||
|
||||
| Method | Endpoint | Description | Auth Required |
|
||||
|--------|----------|-------------|---------------|
|
||||
| `POST` | `/api/demo/order` | Create demo order with patient | No |
|
||||
|
||||
#### Specimen Management
|
||||
|
||||
| Method | Endpoint | Description | Auth Required |
|
||||
|--------|----------|-------------|---------------|
|
||||
| `GET` | `/api/specimen` | List specimens | Yes |
|
||||
| `GET` | `/api/specimen/{id}` | Get specimen details | Yes |
|
||||
| `POST` | `/api/specimen` | Create specimen | Yes |
|
||||
| `PATCH` | `/api/specimen/{id}` | Update specimen | Yes |
|
||||
| `POST` | `/api/specimen/status` | Update specimen status | Yes |
|
||||
|
||||
#### Result Management
|
||||
|
||||
| Method | Endpoint | Description | Auth Required |
|
||||
|--------|----------|-------------|---------------|
|
||||
| `GET` | `/api/patresult` | List patient results | Yes |
|
||||
| `GET` | `/api/patresult/{id}` | Get result details | Yes |
|
||||
| `POST` | `/api/patresult` | Enter new result | Yes |
|
||||
| `PATCH` | `/api/patresult/{id}` | Update result | Yes |
|
||||
| `POST` | `/api/patresult/status` | Verify result (VER/REV/REP) | Yes |
|
||||
|
||||
#### Edge API (Instrument Integration)
|
||||
|
||||
| Method | Endpoint | Description | Auth Required |
|
||||
|--------|----------|-------------|---------------|
|
||||
| `POST` | `/api/edge/result` | Receive instrument results | API Key |
|
||||
| `GET` | `/api/edge/order` | Fetch pending orders | API Key |
|
||||
| `POST` | `/api/edge/order/{id}/ack` | Acknowledge order | API Key |
|
||||
| `POST` | `/api/edge/status` | Log instrument status | API Key |
|
||||
|
||||
### API Response Format
|
||||
|
||||
All API endpoints return JSON in this format:
|
||||
|
||||
**Success Response:**
|
||||
```json
|
||||
{
|
||||
"status": "success",
|
||||
"message": "Operation completed successfully",
|
||||
"data": {
|
||||
// Response data here
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
**Error Response:**
|
||||
```json
|
||||
{
|
||||
"status": "error",
|
||||
"message": "Error description",
|
||||
"errors": [
|
||||
{
|
||||
"field": "field_name",
|
||||
"message": "Validation error message"
|
||||
}
|
||||
]
|
||||
}
|
||||
```
|
||||
|
||||
### Authentication
|
||||
|
||||
Most endpoints require JWT authentication:
|
||||
|
||||
**Request Headers:**
|
||||
```
|
||||
Authorization: Bearer {jwt_token}
|
||||
Content-Type: application/json
|
||||
```
|
||||
|
||||
**Login Request Example:**
|
||||
```bash
|
||||
POST /api/login
|
||||
{
|
||||
"username": "labuser",
|
||||
"password": "password123"
|
||||
}
|
||||
```
|
||||
|
||||
**Login Response:**
|
||||
```json
|
||||
{
|
||||
"status": "success",
|
||||
"message": "Login successful",
|
||||
"data": {
|
||||
"token": "eyJ0eXAiOiJKV1QiLCJhbGc...",
|
||||
"expires_in": 3600,
|
||||
"user": {
|
||||
"id": 1,
|
||||
"username": "labuser",
|
||||
"name": "Lab User"
|
||||
}
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## Lookups Library (`app/Libraries/ValueSet.php`)
|
||||
|
||||
CLQMS uses a **JSON file-based lookup system** loaded via `App\Libraries\Lookups` class. All lookup data is stored as JSON files in `app/Libraries/Data/valuesets/` for easy maintenance and versioning.
|
||||
|
||||
### How It Works
|
||||
|
||||
- `Lookups` class extends `ValueSet` which handles caching and file loading
|
||||
- Each lookup is stored as `app/Libraries/Data/valuesets/{name}.json`
|
||||
- Lookup names are lowercase with underscores (e.g., `gender.json`, `order_priority.json`)
|
||||
|
||||
### Available Lookups
|
||||
|
||||
| Lookup File | Description | Example Values |
|
||||
|-------------|-------------|----------------|
|
||||
| `gender` | Patient gender | Female, Male, Unknown |
|
||||
| `order_priority` | Order priority levels | Stat, ASAP, Routine, Preop |
|
||||
| `order_status` | Order lifecycle status | STC, SCtd, SArrv, SRcvd |
|
||||
| `specimen_type` | Specimen types | BLD, SER, PLAS, UR, CSF |
|
||||
| `specimen_status` | Specimen status | Ordered, Collected, Received |
|
||||
| `specimen_condition` | Specimen quality flags | HEM, ITC, LIP, CLOT |
|
||||
| `specimen_activity` | Specimen workflow events | COLLECT, RECEIVE, REJECT |
|
||||
| `result_type` | Result data types | NMRIC, RANGE, TEXT, VSET |
|
||||
| `result_unit` | Common measurement units | g/dL, mg/dL, x10^6/mL |
|
||||
| `result_status` | Result validation status | Preliminary, Final, Corrected |
|
||||
| `test_type` | Test definition types | TEST, PARAM, CALC, GROUP |
|
||||
| `test_activity` | Test workflow activities | Order, Analyse, VER, REV |
|
||||
| `test_status` | Test active status | Active, Inactive, Discontinued |
|
||||
| `priority` | General priority values | STAT, HIGH, NORMAL, LOW |
|
||||
| `race` | Ethnicity/race categories | Jawa, Sunda, Batak, etc. |
|
||||
| `religion` | Religious affiliations | Islam, Kristen, Katolik, Hindu |
|
||||
| `marital_status` | Marital status | Single, Married, Divorced |
|
||||
| `death_indicator` | Death status flags | Yes, No |
|
||||
| `identifier_type` | ID document types | KTP, Passport, SSN, SIM |
|
||||
| `operation` | CRUD operation types | Create, Read, Update, Delete |
|
||||
| `site_type` | Healthcare facility types | GH, PH, GHL, PHL, GL, PL |
|
||||
| `site_class` | Facility classification | A, B, C, D, Utm, Ptm |
|
||||
| `ws_type` | Workstation types | Primary, Secondary |
|
||||
| `enable_disable` | Boolean toggle states | Enabled, Disabled |
|
||||
| `entity_type` | Entity classification | Patient, Provider, Site |
|
||||
| `requested_entity` | Requestor types | Physician, Nurse, Lab |
|
||||
| `location_type` | Location categories | OPD, IPD, ER, LAB |
|
||||
| `area_class` | Geographic classifications | Urban, Rural, Suburban |
|
||||
| `adt_event` | ADT event types | Admission, Transfer, Discharge |
|
||||
| `body_site` | Collection sites | Left Arm, Right Arm, Finger |
|
||||
| `collection_method` | Specimen collection methods | Venipuncture, Fingerstick |
|
||||
| `container_size` | Tube/container volumes | 3mL, 5mL, 10mL |
|
||||
| `container_class` | Container types | Vacutainer, Tube, Cup |
|
||||
| `container_cap_color` | Tube cap colors | Red, Purple, Blue, Green |
|
||||
| `additive` | Tube additives | EDTA, Heparin, Fluoride |
|
||||
| `fasting_status` | Fasting requirement flags | Fasting, Non-Fasting |
|
||||
| `ethnic` | Ethnicity categories | Various regional groups |
|
||||
| `math_sign` | Mathematical operators | +, -, *, /, =, <, > |
|
||||
| `formula_language` | Formula expression types | Formula, Expression |
|
||||
| `generate_by` | Generation methods | Auto, Manual, Import |
|
||||
| `did_type` | Device identification types | Serial, MAC, UUID |
|
||||
| `activity_result` | Activity outcomes | Success, Fail, Retry |
|
||||
| `reference_type` | Reference value types | NMRIC, TEXT, LIST |
|
||||
| `range_type` | Range calculation types | REF, CRTC, VAL, RERUN |
|
||||
| `numeric_ref_type` | Numeric ref types | Reference, Critical, Valid |
|
||||
| `text_ref_type` | Text reference types | Normal, Abnormal, Critical |
|
||||
| `request_status` | Request status | Pending, Approved, Rejected |
|
||||
| `v_category` | ValueSet categories | Various categories |
|
||||
|
||||
### Usage
|
||||
|
||||
```php
|
||||
use App\Libraries\Lookups;
|
||||
|
||||
// Get all lookups (loads all JSON files, cached)
|
||||
$allLookups = Lookups::getAll();
|
||||
|
||||
// Get single lookup formatted for dropdowns
|
||||
$gender = Lookups::get('gender');
|
||||
// Returns: [{"value":"1","label":"Female"},{"value":"2","label":"Male"},...]
|
||||
|
||||
// Get raw data without formatting
|
||||
$raw = Lookups::getRaw('gender');
|
||||
// Returns: [{"key":"1","value":"Female"},{"key":"2","value":"Male"},...]
|
||||
|
||||
// Get label for a specific key
|
||||
$label = Lookups::getLabel('gender', '1'); // Returns 'Female'
|
||||
|
||||
// Get key/value pairs for select inputs
|
||||
$options = Lookups::getOptions('gender');
|
||||
// Returns: [["key":"1","value":"Female"],...]
|
||||
|
||||
// Transform database records with lookup text labels
|
||||
$patients = [
|
||||
['ID' => 1, 'Sex' => '1', 'Priority' => 'S'],
|
||||
['ID' => 2, 'Sex' => '2', 'Priority' => 'R'],
|
||||
];
|
||||
$labeled = Lookups::transformLabels($patients, [
|
||||
'Sex' => 'gender',
|
||||
'Priority' => 'order_priority'
|
||||
]);
|
||||
// Result: [['ID'=>1, 'Sex'=>'1', 'SexText'=>'Female', 'Priority'=>'S', 'PriorityText'=>'Stat'],...]
|
||||
|
||||
// Clear cache after modifying valueset data
|
||||
Lookups::clearCache();
|
||||
```
|
||||
|
||||
### When to Use
|
||||
|
||||
| Approach | Use Case |
|
||||
|----------|----------|
|
||||
| **Lookups Library** | Server-side static values that rarely change (gender, status, types) - fast, cached |
|
||||
| **API `/api/valueset*`** | Dynamic values managed by admins at runtime, or for frontend clients needing lookup data |
|
||||
|
||||
### Adding New Lookups
|
||||
|
||||
1. Create `app/Libraries/Data/valuesets/{name}.json`:
|
||||
```json
|
||||
{
|
||||
"name": "example_lookup",
|
||||
"description": "Example lookup description",
|
||||
"values": [
|
||||
{"key": "1", "value": "Option One"},
|
||||
{"key": "2", "value": "Option Two"},
|
||||
{"key": "3", "value": "Option Three"}
|
||||
]
|
||||
}
|
||||
```
|
||||
|
||||
2. Access via `Lookups::get('example_lookup')`
|
||||
|
||||
---
|
||||
|
||||
## 📋 Master Data Management
|
||||
|
||||
CLQMS provides comprehensive master data management for laboratory operations. All master data is accessible via REST API endpoints.
|
||||
|
||||
### 🧪 Laboratory Tests
|
||||
|
||||
The Test Definitions module manages all laboratory test configurations including parameters, calculated tests, and test panels.
|
||||
|
||||
#### Test Types
|
||||
|
||||
| Type Code | Description | Table |
|
||||
|-----------|-------------|-------|
|
||||
| `TEST` | Individual laboratory test with technical specs | `testdefsite` + `testdeftech` |
|
||||
| `PARAM` | Parameter value (non-lab measurement) | `testdefsite` + `testdeftech` |
|
||||
| `CALC` | Calculated test with formula | `testdefsite` + `testdefcal` |
|
||||
| `GROUP` | Panel/profile containing multiple tests | `testdefsite` + `testdefgrp` |
|
||||
| `TITLE` | Section title for report organization | `testdefsite` |
|
||||
|
||||
#### API Endpoints
|
||||
|
||||
| Method | Endpoint | Description |
|
||||
|--------|----------|-------------|
|
||||
| `GET` | `/api/tests` | List all tests with optional filtering |
|
||||
| `GET` | `/api/tests/{id}` | Get test details with type-specific data |
|
||||
| `POST` | `/api/tests` | Create new test definition |
|
||||
| `PATCH` | `/api/tests` | Update existing test |
|
||||
| `DELETE` | `/api/tests` | Soft delete test (sets EndDate) |
|
||||
|
||||
#### Filtering Parameters
|
||||
|
||||
- `TestSiteName` - Search by test name (partial match)
|
||||
- `TestType` - Filter by test type VID (1-5)
|
||||
- `VisibleScr` - Filter by screen visibility (0/1)
|
||||
- `VisibleRpt` - Filter by report visibility (0/1)
|
||||
|
||||
#### Test Response Structure
|
||||
|
||||
```json
|
||||
{
|
||||
"status": "success",
|
||||
"message": "Data fetched successfully",
|
||||
"data": [
|
||||
{
|
||||
"TestSiteID": 1,
|
||||
"TestSiteCode": "CBC",
|
||||
"TestSiteName": "Complete Blood Count",
|
||||
"TestType": 4,
|
||||
"TypeCode": "GROUP",
|
||||
"TypeName": "Group Test",
|
||||
"SeqScr": 50,
|
||||
"VisibleScr": 1,
|
||||
"VisibleRpt": 1
|
||||
}
|
||||
]
|
||||
}
|
||||
```
|
||||
|
||||
### 📏 Reference Ranges
|
||||
|
||||
Reference Ranges define normal and critical values for test results. The system supports multiple reference range types based on patient demographics.
|
||||
|
||||
#### Reference Range Types
|
||||
|
||||
| Type | Table | Description |
|
||||
|------|-------|-------------|
|
||||
| Numeric | `refnum` | Numeric ranges with age/sex criteria |
|
||||
| Text | `reftxt` | Text-based reference values |
|
||||
|
||||
#### Numeric Reference Range Structure
|
||||
|
||||
| Field | Description |
|
||||
|-------|-------------|
|
||||
| `NumRefType` | Type: REF (Reference), CRTC (Critical), VAL (Validation), RERUN |
|
||||
| `RangeType` | RANGE or THOLD |
|
||||
| `Sex` | Gender filter (0=All, 1=Female, 2=Male) |
|
||||
| `AgeStart` | Minimum age (years) |
|
||||
| `AgeEnd` | Maximum age (years) |
|
||||
| `LowSign` | Low boundary sign (=, <, <=) |
|
||||
| `Low` | Low boundary value |
|
||||
| `HighSign` | High boundary sign (=, >, >=) |
|
||||
| `High` | High boundary value |
|
||||
| `Flag` | Result flag (H, L, A, etc.) |
|
||||
|
||||
#### API Endpoints
|
||||
|
||||
| Method | Endpoint | Description |
|
||||
|--------|----------|-------------|
|
||||
| `GET` | `/api/refnum` | List numeric reference ranges |
|
||||
| `GET` | `/api/refnum/{id}` | Get reference range details |
|
||||
| `POST` | `/api/refnum` | Create reference range |
|
||||
| `PATCH` | `/api/refnum` | Update reference range |
|
||||
| `DELETE` | `/api/refnum` | Soft delete reference range |
|
||||
|
||||
### 📑 Value Sets
|
||||
|
||||
Value Sets are configurable dropdown options used throughout the system. Each Value Set Definition (VSetDef) contains multiple Value Set Values (ValueSet).
|
||||
|
||||
#### Value Set Hierarchy
|
||||
|
||||
```
|
||||
valuesetdef (VSetDefID, VSName, VSDesc)
|
||||
└── valueset (VID, VSetID, VValue, VDesc, VOrder, VCategory)
|
||||
```
|
||||
|
||||
#### Common Value Sets
|
||||
|
||||
| VSetDefID | Name | Example Values |
|
||||
|-----------|------|----------------|
|
||||
| 1 | Priority | STAT (S), ASAP (A), Routine (R), Preop (P) |
|
||||
| 2 | Enable/Disable | Disabled (0), Enabled (1) |
|
||||
| 3 | Gender | Female (1), Male (2), Unknown (3) |
|
||||
| 10 | Order Status | STC, SCtd, SArrv, SRcvd, SAna, etc. |
|
||||
| 15 | Specimen Type | BLD, SER, PLAS, UR, CSF, etc. |
|
||||
| 16 | Unit | L, mL, g/dL, mg/dL, etc. |
|
||||
| 27 | Test Type | TEST, PARAM, CALC, GROUP, TITLE |
|
||||
| 28 | Result Unit | g/dL, g/L, mg/dL, x10^6/mL, etc. |
|
||||
| 35 | Test Activity | Order, Analyse, VER, REV, REP |
|
||||
|
||||
#### API Endpoints
|
||||
|
||||
| Method | Endpoint | Description |
|
||||
|--------|----------|-------------|
|
||||
| `GET` | `/api/valuesetdef` | List all value set definitions |
|
||||
| `GET` | `/api/valuesetdef/{id}` | Get valueset with all values |
|
||||
| `GET` | `/api/valuesetdef/{id}/values` | Get values for specific valueset |
|
||||
| `POST` | `/api/valuesetdef` | Create new valueset definition |
|
||||
| `PATCH` | `/api/valuesetdef` | Update valueset definition |
|
||||
| `DELETE` | `/api/valuesetdef` | Delete valueset definition |
|
||||
|
||||
#### Value Set Response Structure
|
||||
|
||||
```json
|
||||
{
|
||||
"status": "success",
|
||||
"data": {
|
||||
"VSetDefID": 27,
|
||||
"VSName": "Test Type",
|
||||
"VSDesc": "testdefsite.TestType",
|
||||
"values": [
|
||||
{ "VID": 1, "VValue": "TEST", "VDesc": "Test", "VOrder": 1 },
|
||||
{ "VID": 2, "VValue": "PARAM", "VDesc": "Parameter", "VOrder": 2 },
|
||||
{ "VID": 3, "VValue": "CALC", "VDesc": "Calculated Test", "VOrder": 3 },
|
||||
{ "VID": 4, "VValue": "GROUP", "VDesc": "Group Test", "VOrder": 4 },
|
||||
{ "VID": 5, "VValue": "TITLE", "VDesc": "Title", "VOrder": 5 }
|
||||
]
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
### 📊 Database Tables Summary
|
||||
|
||||
| Category | Tables | Purpose |
|
||||
|----------|--------|---------|
|
||||
| Tests | `testdefsite`, `testdeftech`, `testdefcal`, `testdefgrp`, `testmap` | Test definitions |
|
||||
| Reference Ranges | `refnum`, `reftxt` | Result validation |
|
||||
| Value Sets | `valuesetdef`, `valueset` | Configurable options |
|
||||
|
||||
---
|
||||
|
||||
## 🔌 Edge API - Instrument Integration
|
||||
|
||||
The **Edge API** provides endpoints for integrating laboratory instruments via the `tiny-edge` middleware. Results from instruments are staged in the `edgeres` table before processing into the main patient results (`patres`).
|
||||
|
||||
### Endpoints
|
||||
|
||||
| Method | Endpoint | Description |
|
||||
|--------|----------|-------------|
|
||||
| `POST` | `/api/edge/result` | Receive instrument results (stored in `edgeres`) |
|
||||
| `GET` | `/api/edge/order` | Fetch pending orders for an instrument |
|
||||
| `POST` | `/api/edge/order/:id/ack` | Acknowledge order delivery to instrument |
|
||||
| `POST` | `/api/edge/status` | Log instrument status updates |
|
||||
|
||||
### Workflow
|
||||
|
||||
```
|
||||
Instrument → tiny-edge → POST /api/edge/result → edgeres table → [Manual/Auto Processing] → patres table
|
||||
```
|
||||
|
||||
**Key Features:**
|
||||
- **Staging Table:** All results land in `edgeres` first for validation
|
||||
- **Rerun Handling:** Duplicate `SampleID` + `TestSiteCode` increments `AspCnt` in `patres`
|
||||
- **Configurable Processing:** Auto or manual processing based on settings
|
||||
- **Status Tracking:** Full audit trail via `edgestatus` and `edgeack` tables
|
||||
|
||||
---
|
||||
|
||||
### 📜 Usage Notice
|
||||
|
||||
**This is an API-only backend system.** There are no views, HTML templates, or server-side rendering components. Frontend applications should consume these REST endpoints to build user interfaces for laboratory operations.
|
||||
|
||||
This repository contains proprietary information intended for the 5Panda Team and authorized collaborators.
|
||||
|
||||
---
|
||||
*© 2025 5Panda Team. Engineering Precision in Clinical Diagnostics.*
|
||||
# CLQMS (Clinical Laboratory Quality Management System)
|
||||
|
||||
> **The core backend engine for modern clinical laboratory workflows.**
|
||||
|
||||
CLQMS is a robust, mission-critical API suite designed to streamline laboratory operations, ensure data integrity, and manage complex diagnostic workflows. Built on a foundation of precision and regulatory compliance, this system handles everything from patient registration to high-throughput test resulting.
|
||||
|
||||
---
|
||||
|
||||
## 🏛️ Core Architecture & Design
|
||||
|
||||
The system is currently undergoing a strategic **Architectural Redesign** to consolidate legacy structures into a high-performance, maintainable schema. This design, spearheaded by leadership, focuses on reducing technical debt and improving data consistency across:
|
||||
|
||||
- **Unified Test Definitions:** Consolidating technical, calculated, and site-specific test data.
|
||||
- **Reference Range Centralization:** A unified engine for numeric, threshold, text, and coded results.
|
||||
- **Ordered Workflow Management:** Precise tracking of orders from collection to verification.
|
||||
|
||||
---
|
||||
|
||||
## 🛡️ Strategic Pillars
|
||||
|
||||
- **Precision & Accuracy:** Strict validation for all laboratory parameters and reference ranges.
|
||||
- **Scalability:** Optimized for high-volume diagnostic environments.
|
||||
- **Compliance:** Built-in audit trails and status history for full traceability.
|
||||
- **Interoperability:** Modular architecture designed for LIS, HIS, and analyzer integrations.
|
||||
|
||||
---
|
||||
|
||||
## 🛠️ Technical Stack
|
||||
|
||||
| Component | Specification |
|
||||
| :------------- | :------------ |
|
||||
| **Language** | PHP 8.1+ (PSR-compliant) |
|
||||
| **Framework** | CodeIgniter 4 |
|
||||
| **Security** | JWT (JSON Web Tokens) Authorization |
|
||||
| **Database** | MySQL (Optimized Schema Migration in progress) |
|
||||
|
||||
|
||||
---
|
||||
|
||||
## 📂 Documentation & Specifications
|
||||
|
||||
For detailed architectural blueprints and API specifications, please refer to the internal documentation:
|
||||
|
||||
👉 **[Internal Documentation Index](./docs/README.md)**
|
||||
|
||||
Key documents:
|
||||
- [Database Schema Redesign Proposal](./docs/20251216002-Test_OrderTest_RefRange_schema_redesign_proposal.md)
|
||||
- [API Contract: Patient Registration](./docs/api_contract_patient_registration.md)
|
||||
- [Database Design Review (Reference)](./docs/20251212001-database_design_review_sonnet.md)
|
||||
|
||||
---
|
||||
|
||||
## Lookups Library (`app/Libraries/ValueSet.php`)
|
||||
|
||||
CLQMS uses a **JSON file-based lookup system** loaded via `App\Libraries\Lookups` class. All lookup data is stored as JSON files in `app/Libraries/Data/valuesets/` for easy maintenance and versioning.
|
||||
|
||||
### How It Works
|
||||
|
||||
- `Lookups` class extends `ValueSet` which handles caching and file loading
|
||||
- Each lookup is stored as `app/Libraries/Data/valuesets/{name}.json`
|
||||
- Lookup names are lowercase with underscores (e.g., `gender.json`, `order_priority.json`)
|
||||
|
||||
### Available Lookups
|
||||
|
||||
| Lookup File | Description | Example Values |
|
||||
|-------------|-------------|----------------|
|
||||
| `gender` | Patient gender | Female, Male, Unknown |
|
||||
| `order_priority` | Order priority levels | Stat, ASAP, Routine, Preop |
|
||||
| `order_status` | Order lifecycle status | STC, SCtd, SArrv, SRcvd |
|
||||
| `specimen_type` | Specimen types | BLD, SER, PLAS, UR, CSF |
|
||||
| `specimen_status` | Specimen status | Ordered, Collected, Received |
|
||||
| `specimen_condition` | Specimen quality flags | HEM, ITC, LIP, CLOT |
|
||||
| `specimen_activity` | Specimen workflow events | COLLECT, RECEIVE, REJECT |
|
||||
| `result_type` | Result data types | NMRIC, RANGE, TEXT, VSET |
|
||||
| `result_unit` | Common measurement units | g/dL, mg/dL, x10^6/mL |
|
||||
| `result_status` | Result validation status | Preliminary, Final, Corrected |
|
||||
| `test_type` | Test definition types | TEST, PARAM, CALC, GROUP |
|
||||
| `test_activity` | Test workflow activities | Order, Analyse, VER, REV |
|
||||
| `test_status` | Test active status | Active, Inactive, Discontinued |
|
||||
| `priority` | General priority values | STAT, HIGH, NORMAL, LOW |
|
||||
| `race` | Ethnicity/race categories | Jawa, Sunda, Batak, etc. |
|
||||
| `religion` | Religious affiliations | Islam, Kristen, Katolik, Hindu |
|
||||
| `marital_status` | Marital status | Single, Married, Divorced |
|
||||
| `death_indicator` | Death status flags | Yes, No |
|
||||
| `identifier_type` | ID document types | KTP, Passport, SSN, SIM |
|
||||
| `operation` | CRUD operation types | Create, Read, Update, Delete |
|
||||
| `site_type` | Healthcare facility types | GH, PH, GHL, PHL, GL, PL |
|
||||
| `site_class` | Facility classification | A, B, C, D, Utm, Ptm |
|
||||
| `ws_type` | Workstation types | Primary, Secondary |
|
||||
| `enable_disable` | Boolean toggle states | Enabled, Disabled |
|
||||
| `entity_type` | Entity classification | Patient, Provider, Site |
|
||||
| `requested_entity` | Requestor types | Physician, Nurse, Lab |
|
||||
| `location_type` | Location categories | OPD, IPD, ER, LAB |
|
||||
| `area_class` | Geographic classifications | Urban, Rural, Suburban |
|
||||
| `adt_event` | ADT event types | Admission, Transfer, Discharge |
|
||||
| `body_site` | Collection sites | Left Arm, Right Arm, Finger |
|
||||
| `collection_method` | Specimen collection methods | Venipuncture, Fingerstick |
|
||||
| `container_size` | Tube/container volumes | 3mL, 5mL, 10mL |
|
||||
| `container_class` | Container types | Vacutainer, Tube, Cup |
|
||||
| `container_cap_color` | Tube cap colors | Red, Purple, Blue, Green |
|
||||
| `additive` | Tube additives | EDTA, Heparin, Fluoride |
|
||||
| `fasting_status` | Fasting requirement flags | Fasting, Non-Fasting |
|
||||
| `ethnic` | Ethnicity categories | Various regional groups |
|
||||
| `math_sign` | Mathematical operators | +, -, *, /, =, <, > |
|
||||
| `formula_language` | Formula expression types | Formula, Expression |
|
||||
| `generate_by` | Generation methods | Auto, Manual, Import |
|
||||
| `did_type` | Device identification types | Serial, MAC, UUID |
|
||||
| `activity_result` | Activity outcomes | Success, Fail, Retry |
|
||||
| `reference_type` | Reference value types | NMRIC, TEXT, LIST |
|
||||
| `range_type` | Range calculation types | REF, CRTC, VAL, RERUN |
|
||||
| `numeric_ref_type` | Numeric ref types | Reference, Critical, Valid |
|
||||
| `text_ref_type` | Text reference types | Normal, Abnormal, Critical |
|
||||
| `request_status` | Request status | Pending, Approved, Rejected |
|
||||
| `v_category` | ValueSet categories | Various categories |
|
||||
|
||||
### Usage
|
||||
|
||||
```php
|
||||
use App\Libraries\Lookups;
|
||||
|
||||
// Get all lookups (loads all JSON files, cached)
|
||||
$allLookups = Lookups::getAll();
|
||||
|
||||
// Get single lookup formatted for dropdowns
|
||||
$gender = Lookups::get('gender');
|
||||
// Returns: [{"value":"1","label":"Female"},{"value":"2","label":"Male"},...]
|
||||
|
||||
// Get raw data without formatting
|
||||
$raw = Lookups::getRaw('gender');
|
||||
// Returns: [{"key":"1","value":"Female"},{"key":"2","value":"Male"},...]
|
||||
|
||||
// Get label for a specific key
|
||||
$label = Lookups::getLabel('gender', '1'); // Returns 'Female'
|
||||
|
||||
// Get key/value pairs for select inputs
|
||||
$options = Lookups::getOptions('gender');
|
||||
// Returns: [["key":"1","value":"Female"],...]
|
||||
|
||||
// Transform database records with lookup text labels
|
||||
$patients = [
|
||||
['ID' => 1, 'Sex' => '1', 'Priority' => 'S'],
|
||||
['ID' => 2, 'Sex' => '2', 'Priority' => 'R'],
|
||||
];
|
||||
$labeled = Lookups::transformLabels($patients, [
|
||||
'Sex' => 'gender',
|
||||
'Priority' => 'order_priority'
|
||||
]);
|
||||
// Result: [['ID'=>1, 'Sex'=>'1', 'SexText'=>'Female', 'Priority'=>'S', 'PriorityText'=>'Stat'],...]
|
||||
|
||||
// Clear cache after modifying valueset data
|
||||
Lookups::clearCache();
|
||||
```
|
||||
|
||||
### Frontend Usage (Alpine.js)
|
||||
|
||||
```php
|
||||
<?php
|
||||
// In your PHP view file
|
||||
use App\Libraries\Lookups;
|
||||
|
||||
$allLookups = Lookups::getAll();
|
||||
?>
|
||||
<script>
|
||||
const LOOKUPS = <?= json_encode($allLookups) ?>;
|
||||
console.log(LOOKUPS.gender);
|
||||
// Output: {"values":[{"key":"1","value":"Female"},{"key":"2","value":"Male"},...]}
|
||||
|
||||
// Convenience accessors
|
||||
const genderValues = LOOKUPS.gender.values;
|
||||
const genderDropdown = LOOKUPS.gender.values.map(v => ({value: v.key, label: v.value}));
|
||||
</script>
|
||||
```
|
||||
|
||||
### When to Use
|
||||
|
||||
| Approach | Use Case |
|
||||
|----------|----------|
|
||||
| **Lookups Library** | Static values that rarely change (gender, status, types) - fast, cached |
|
||||
| **API `/api/valueset*`** | Dynamic values managed by admins at runtime |
|
||||
|
||||
### Adding New Lookups
|
||||
|
||||
1. Create `app/Libraries/Data/valuesets/{name}.json`:
|
||||
```json
|
||||
{
|
||||
"name": "example_lookup",
|
||||
"description": "Example lookup description",
|
||||
"values": [
|
||||
{"key": "1", "value": "Option One"},
|
||||
{"key": "2", "value": "Option Two"},
|
||||
{"key": "3", "value": "Option Three"}
|
||||
]
|
||||
}
|
||||
```
|
||||
|
||||
2. Access via `Lookups::get('example_lookup')`
|
||||
|
||||
---
|
||||
|
||||
## 📋 Master Data Management
|
||||
|
||||
CLQMS provides comprehensive master data management for laboratory operations. All master data is accessible via the V2 UI at `/v2/master/*` endpoints.
|
||||
|
||||
### 🧪 Laboratory Tests (`/v2/master/tests`)
|
||||
|
||||
The Test Definitions module manages all laboratory test configurations including parameters, calculated tests, and test panels.
|
||||
|
||||
#### Test Types
|
||||
|
||||
| Type Code | Description | Table |
|
||||
|-----------|-------------|-------|
|
||||
| `TEST` | Individual laboratory test with technical specs | `testdefsite` + `testdeftech` |
|
||||
| `PARAM` | Parameter value (non-lab measurement) | `testdefsite` + `testdeftech` |
|
||||
| `CALC` | Calculated test with formula | `testdefsite` + `testdefcal` |
|
||||
| `GROUP` | Panel/profile containing multiple tests | `testdefsite` + `testdefgrp` |
|
||||
| `TITLE` | Section title for report organization | `testdefsite` |
|
||||
|
||||
#### API Endpoints
|
||||
|
||||
| Method | Endpoint | Description |
|
||||
|--------|----------|-------------|
|
||||
| `GET` | `/api/tests` | List all tests with optional filtering |
|
||||
| `GET` | `/api/tests/{id}` | Get test details with type-specific data |
|
||||
| `POST` | `/api/tests` | Create new test definition |
|
||||
| `PATCH` | `/api/tests` | Update existing test |
|
||||
| `DELETE` | `/api/tests` | Soft delete test (sets EndDate) |
|
||||
|
||||
#### Filtering Parameters
|
||||
|
||||
- `TestSiteName` - Search by test name (partial match)
|
||||
- `TestType` - Filter by test type VID (1-5)
|
||||
- `VisibleScr` - Filter by screen visibility (0/1)
|
||||
- `VisibleRpt` - Filter by report visibility (0/1)
|
||||
|
||||
#### Test Response Structure
|
||||
|
||||
```json
|
||||
{
|
||||
"status": "success",
|
||||
"message": "Data fetched successfully",
|
||||
"data": [
|
||||
{
|
||||
"TestSiteID": 1,
|
||||
"TestSiteCode": "CBC",
|
||||
"TestSiteName": "Complete Blood Count",
|
||||
"TestType": 4,
|
||||
"TypeCode": "GROUP",
|
||||
"TypeName": "Group Test",
|
||||
"SeqScr": 50,
|
||||
"VisibleScr": 1,
|
||||
"VisibleRpt": 1
|
||||
}
|
||||
]
|
||||
}
|
||||
```
|
||||
|
||||
### 📏 Reference Ranges (`/v2/master/refrange`)
|
||||
|
||||
Reference Ranges define normal and critical values for test results. The system supports multiple reference range types based on patient demographics.
|
||||
|
||||
#### Reference Range Types
|
||||
|
||||
| Type | Table | Description |
|
||||
|------|-------|-------------|
|
||||
| Numeric | `refnum` | Numeric ranges with age/sex criteria |
|
||||
| Threshold | `refthold` | Critical threshold values |
|
||||
| Text | `reftxt` | Text-based reference values |
|
||||
| Value Set | `refvset` | Coded reference values |
|
||||
|
||||
#### Numeric Reference Range Structure
|
||||
|
||||
| Field | Description |
|
||||
|-------|-------------|
|
||||
| `NumRefType` | Type: REF (Reference), CRTC (Critical), VAL (Validation), RERUN |
|
||||
| `RangeType` | RANGE or THOLD |
|
||||
| `Sex` | Gender filter (0=All, 1=Female, 2=Male) |
|
||||
| `AgeStart` | Minimum age (years) |
|
||||
| `AgeEnd` | Maximum age (years) |
|
||||
| `LowSign` | Low boundary sign (=, <, <=) |
|
||||
| `Low` | Low boundary value |
|
||||
| `HighSign` | High boundary sign (=, >, >=) |
|
||||
| `High` | High boundary value |
|
||||
| `Flag` | Result flag (H, L, A, etc.) |
|
||||
|
||||
#### API Endpoints
|
||||
|
||||
| Method | Endpoint | Description |
|
||||
|--------|----------|-------------|
|
||||
| `GET` | `/api/refnum` | List numeric reference ranges |
|
||||
| `GET` | `/api/refnum/{id}` | Get reference range details |
|
||||
| `POST` | `/api/refnum` | Create reference range |
|
||||
| `PATCH` | `/api/refnum` | Update reference range |
|
||||
| `DELETE` | `/api/refnum` | Soft delete reference range |
|
||||
|
||||
### 📑 Value Sets (`/v2/master/valuesets`)
|
||||
|
||||
Value Sets are configurable dropdown options used throughout the system. Each Value Set Definition (VSetDef) contains multiple Value Set Values (ValueSet).
|
||||
|
||||
#### Value Set Hierarchy
|
||||
|
||||
```
|
||||
valuesetdef (VSetDefID, VSName, VSDesc)
|
||||
└── valueset (VID, VSetID, VValue, VDesc, VOrder, VCategory)
|
||||
```
|
||||
|
||||
#### Common Value Sets
|
||||
|
||||
| VSetDefID | Name | Example Values |
|
||||
|-----------|------|----------------|
|
||||
| 1 | Priority | STAT (S), ASAP (A), Routine (R), Preop (P) |
|
||||
| 2 | Enable/Disable | Disabled (0), Enabled (1) |
|
||||
| 3 | Gender | Female (1), Male (2), Unknown (3) |
|
||||
| 10 | Order Status | STC, SCtd, SArrv, SRcvd, SAna, etc. |
|
||||
| 15 | Specimen Type | BLD, SER, PLAS, UR, CSF, etc. |
|
||||
| 16 | Unit | L, mL, g/dL, mg/dL, etc. |
|
||||
| 27 | Test Type | TEST, PARAM, CALC, GROUP, TITLE |
|
||||
| 28 | Result Unit | g/dL, g/L, mg/dL, x10^6/mL, etc. |
|
||||
| 35 | Test Activity | Order, Analyse, VER, REV, REP |
|
||||
|
||||
#### API Endpoints
|
||||
|
||||
| Method | Endpoint | Description |
|
||||
|--------|----------|-------------|
|
||||
| `GET` | `/api/valuesetdef` | List all value set definitions |
|
||||
| `GET` | `/api/valuesetdef/{id}` | Get valueset with all values |
|
||||
| `GET` | `/api/valuesetdef/{id}/values` | Get values for specific valueset |
|
||||
| `POST` | `/api/valuesetdef` | Create new valueset definition |
|
||||
| `PATCH` | `/api/valuesetdef` | Update valueset definition |
|
||||
| `DELETE` | `/api/valuesetdef` | Delete valueset definition |
|
||||
|
||||
#### Value Set Response Structure
|
||||
|
||||
```json
|
||||
{
|
||||
"status": "success",
|
||||
"data": {
|
||||
"VSetDefID": 27,
|
||||
"VSName": "Test Type",
|
||||
"VSDesc": "testdefsite.TestType",
|
||||
"values": [
|
||||
{ "VID": 1, "VValue": "TEST", "VDesc": "Test", "VOrder": 1 },
|
||||
{ "VID": 2, "VValue": "PARAM", "VDesc": "Parameter", "VOrder": 2 },
|
||||
{ "VID": 3, "VValue": "CALC", "VDesc": "Calculated Test", "VOrder": 3 },
|
||||
{ "VID": 4, "VValue": "GROUP", "VDesc": "Group Test", "VOrder": 4 },
|
||||
{ "VID": 5, "VValue": "TITLE", "VDesc": "Title", "VOrder": 5 }
|
||||
]
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
### 📊 Database Tables Summary
|
||||
|
||||
| Category | Tables | Purpose |
|
||||
|----------|--------|---------|
|
||||
| Tests | `testdefsite`, `testdeftech`, `testdefcal`, `testdefgrp`, `testmap` | Test definitions |
|
||||
| Reference Ranges | `refnum`, `refthold`, `reftxt`, `refvset` | Result validation |
|
||||
| Value Sets | `valuesetdef`, `valueset` | Configurable options |
|
||||
|
||||
---
|
||||
|
||||
## 🔌 Edge API - Instrument Integration
|
||||
|
||||
The **Edge API** provides endpoints for integrating laboratory instruments via the `tiny-edge` middleware. Results from instruments are staged in the `edgeres` table before processing into the main patient results (`patres`).
|
||||
|
||||
### Endpoints
|
||||
|
||||
| Method | Endpoint | Description |
|
||||
|--------|----------|-------------|
|
||||
| `POST` | `/api/edge/results` | Receive instrument results (stored in `edgeres`) |
|
||||
| `GET` | `/api/edge/orders` | Fetch pending orders for an instrument |
|
||||
| `POST` | `/api/edge/orders/:id/ack` | Acknowledge order delivery to instrument |
|
||||
| `POST` | `/api/edge/status` | Log instrument status updates |
|
||||
|
||||
### Workflow
|
||||
|
||||
```
|
||||
Instrument → tiny-edge → POST /api/edge/results → edgeres table → [Manual/Auto Processing] → patres table
|
||||
```
|
||||
|
||||
**Key Features:**
|
||||
- **Staging Table:** All results land in `edgeres` first for validation
|
||||
- **Rerun Handling:** Duplicate `SampleID` + `TestSiteCode` increments `AspCnt` in `patres`
|
||||
- **Configurable Processing:** Auto or manual processing based on settings
|
||||
- **Status Tracking:** Full audit trail via `edgestatus` and `edgeack` tables
|
||||
|
||||
---
|
||||
|
||||
### 📜 Usage Notice
|
||||
This repository contains proprietary information intended for the 5Panda Team and authorized collaborators.
|
||||
|
||||
---
|
||||
*© 2025 5Panda Team. Engineering Precision in Clinical Diagnostics.*
|
||||
|
||||
284
TODO.md
Normal file
284
TODO.md
Normal file
@ -0,0 +1,284 @@
|
||||
# CLQMS MVP Todo List
|
||||
|
||||
> Clinical Laboratory Quality Management System - Minimum Viable Product
|
||||
|
||||
## Quick Start: Create Order with Minimal Master Data
|
||||
|
||||
You **don't need** all master data finished to create an order. Here's what's actually required:
|
||||
|
||||
### Minimum Required (4 Tables)
|
||||
|
||||
```sql
|
||||
-- 1. Patient (already exists in codebase)
|
||||
-- Just need at least 1 patient
|
||||
|
||||
-- 2. Order Status Values (VSetID=11)
|
||||
INSERT INTO valueset (VID, VSetID, VValue, VDesc, VOrder) VALUES
|
||||
(1, 11, 'ORD', 'Ordered', 1),
|
||||
(2, 11, 'SCH', 'Scheduled', 2),
|
||||
(3, 11, 'ANA', 'Analysis', 3),
|
||||
(4, 11, 'VER', 'Verified', 4),
|
||||
(5, 11, 'REV', 'Reviewed', 5),
|
||||
(6, 11, 'REP', 'Reported', 6);
|
||||
|
||||
-- 3. Priority Values (VSetID=10)
|
||||
INSERT INTO valueset (VID, VSetID, VValue, VDesc, VOrder) VALUES
|
||||
(1, 10, 'S', 'Stat', 1),
|
||||
(2, 10, 'R', 'Routine', 2),
|
||||
(3, 10, 'A', 'ASAP', 3);
|
||||
|
||||
-- 4. Counter for Order ID
|
||||
INSERT INTO counter (CounterName, CounterValue) VALUES ('ORDER', 1);
|
||||
|
||||
-- Run seeder: php spark db:seed MinimalMasterDataSeeder
|
||||
```
|
||||
|
||||
### API Endpoints (No Auth Required for Testing)
|
||||
|
||||
```bash
|
||||
# Create demo order (auto-creates patient if needed)
|
||||
POST /api/demo/order
|
||||
{
|
||||
"PatientID": "PT001",
|
||||
"NameFirst": "John",
|
||||
"NameLast": "Doe",
|
||||
"Gender": "1",
|
||||
"Birthdate": "1990-05-15",
|
||||
"Priority": "R",
|
||||
"OrderingProvider": "Dr. Smith"
|
||||
}
|
||||
|
||||
# List orders
|
||||
GET /api/demo/orders
|
||||
|
||||
# Create order (requires auth)
|
||||
POST /api/ordertest
|
||||
{
|
||||
"InternalPID": 1,
|
||||
"Priority": "R",
|
||||
"OrderingProvider": "Dr. Smith"
|
||||
}
|
||||
|
||||
# Update order status
|
||||
POST /api/ordertest/status
|
||||
{
|
||||
"OrderID": "00250112000001",
|
||||
"OrderStatus": "SCH"
|
||||
}
|
||||
```
|
||||
|
||||
## Core Workflow
|
||||
Order → Collection → Reception → Preparation → Analysis → Verification → Review → Reporting
|
||||
|
||||
---
|
||||
|
||||
## Phase 1: Core Lab Workflow (Must Have)
|
||||
|
||||
### 1.1 Order Management
|
||||
- [ ] Complete `OrderTestController` create/update/delete
|
||||
- [ ] Implement order ID generation (LLYYMMDDXXXXX format)
|
||||
- [ ] Implement order attachment handling (ordercom, orderatt tables)
|
||||
- [ ] Add order status tracking (ORD→SCH→ANA→VER→REV→REP)
|
||||
- [ ] Create order test mapping (testmap table)
|
||||
- [ ] Add calculated test parameter auto-selection
|
||||
|
||||
### 1.2 Specimen Management
|
||||
- [ ] Complete `SpecimenController` API
|
||||
- [ ] Implement specimen ID generation (OrderID + SSS + C)
|
||||
- [ ] Build specimen collection API (Collection status)
|
||||
- [ ] Build specimen transport API (In-transport status)
|
||||
- [ ] Build specimen reception API (Received/Rejected status)
|
||||
- [ ] Build specimen preparation API (Centrifuge, Aliquot, Pre-treatment)
|
||||
- [ ] Build specimen storage API (Stored status)
|
||||
- [ ] Build specimen dispatching API (Dispatch status)
|
||||
- [ ] Implement specimen condition tracking (HEM, ITC, LIP flags)
|
||||
|
||||
### 1.3 Result Management
|
||||
- [ ] Complete `ResultController` with full CRUD
|
||||
- [ ] Implement result entry API (numeric, text, valueset, range)
|
||||
- [ ] Implement result verification workflow (Technical + Clinical)
|
||||
- [ ] Add reference range validation (numeric, threshold, text, valueset)
|
||||
- [ ] Implement critical value flagging (threshold-based)
|
||||
- [ ] Implement result rerun with AspCnt tracking
|
||||
- [ ] Add result report generation API
|
||||
|
||||
### 1.4 Patient Visit
|
||||
- [ ] Complete `PatVisitController` create/read
|
||||
- [ ] Implement patient visit to order linking
|
||||
- [ ] Add admission/discharge/transfer (ADT) tracking
|
||||
- [ ] Add diagnosis linking (patdiag table)
|
||||
|
||||
---
|
||||
|
||||
## Phase 2: Instrument Integration (Must Have)
|
||||
|
||||
### 2.1 Edge API
|
||||
- [ ] Complete `EdgeController` results endpoint
|
||||
- [ ] Implement edgeres table data handling
|
||||
- [ ] Implement edgestatus tracking
|
||||
- [ ] Implement edgeack acknowledgment
|
||||
- [ ] Build instrument orders endpoint (/api/edge/orders)
|
||||
- [ ] Build order acknowledgment endpoint (/api/edge/orders/:id/ack)
|
||||
- [ ] Build status logging endpoint (/api/edge/status)
|
||||
|
||||
### 2.2 Test Mapping
|
||||
- [ ] Implement test mapping CRUD (TestMapModel)
|
||||
- [ ] Build instrument code to LQMS test mapping
|
||||
- [ ] Add many-to-one mapping support (e.g., glucose variations)
|
||||
|
||||
---
|
||||
|
||||
## Phase 3: Quality Management (Should Have)
|
||||
|
||||
### 3.1 Quality Control
|
||||
- [ ] Build QC result entry API
|
||||
- [ ] Implement QC result storage (calres table)
|
||||
- [ ] Add Levey-Jennings data preparation endpoints
|
||||
- [ ] Implement QC validation (2SD auto-validation)
|
||||
- [ ] Add Sigma score calculation endpoint
|
||||
|
||||
### 3.2 Calibration
|
||||
- [ ] Build calibration result entry API
|
||||
- [ ] Implement calibration factor tracking
|
||||
- [ ] Add calibration history endpoint
|
||||
- [ ] Implement calibration validation
|
||||
|
||||
### 3.3 Audit Trail
|
||||
- [ ] Add audit logging middleware
|
||||
- [ ] Implement data change tracking (what/who/when/how/where)
|
||||
- [ ] Build audit query endpoint
|
||||
- [ ] Add security log endpoints
|
||||
|
||||
---
|
||||
|
||||
## Phase 4: Master Data (Already Have - Need Completion)
|
||||
|
||||
### 4.1 Test Definitions ✅ Existing
|
||||
- [ ] Test definitions (testdefsite)
|
||||
- [ ] Technical specs (testdeftech)
|
||||
- [ ] Calculated tests (testdefcal)
|
||||
- [ ] Group tests (testdefgrp)
|
||||
- [ ] Test parameters
|
||||
|
||||
### 4.2 Reference Ranges ✅ Existing
|
||||
- [ ] Numeric ranges (refnum)
|
||||
- [ ] Threshold ranges (refthold)
|
||||
- [ ] Text ranges (reftxt)
|
||||
- [ ] Value set ranges (refvset)
|
||||
|
||||
### 4.3 Organizations ✅ Existing
|
||||
- [ ] Sites (SiteController)
|
||||
- [ ] Departments (DepartmentController)
|
||||
- [ ] Workstations (WorkstationController)
|
||||
- [ ] Disciplines (DisciplineController)
|
||||
|
||||
### 4.4 Value Sets ✅ Existing
|
||||
- [ ] Value set definitions (ValueSetDefController)
|
||||
- [ ] Value set values (ValueSetController)
|
||||
|
||||
---
|
||||
|
||||
## Phase 5: Inventory & Billing (Nice to Have)
|
||||
|
||||
### 5.1 Inventory
|
||||
- [ ] Build counter management API
|
||||
- [ ] Implement product catalog endpoints
|
||||
- [ ] Add reagent tracking
|
||||
- [ ] Implement consumables usage logging
|
||||
|
||||
### 5.2 Billing
|
||||
- [ ] Add billing account linking
|
||||
- [ ] Implement tariff selection by service class
|
||||
- [ ] Build billing export endpoint
|
||||
|
||||
---
|
||||
|
||||
## Priority Matrix
|
||||
|
||||
| Priority | Feature | Controller/Model | Status |
|
||||
|----------|---------|-----------------|--------|
|
||||
| P0 | Order CRUD | OrderTestController + OrderTestModel | ✅ Done |
|
||||
| P0 | Specimen Status | SpecimenController | ⚠️ Needs API |
|
||||
| P0 | Result Entry | ResultController | ❌ Empty |
|
||||
| P0 | Result Verification | ResultController | ❌ Empty |
|
||||
| P1 | Visit Management | PatVisitController | ⚠️ Partial |
|
||||
| P1 | Instrument Integration | EdgeController | ⚠️ Partial |
|
||||
| P1 | Reference Range Validation | RefNumModel + API | ⚠️ Need API |
|
||||
| P2 | QC Results | New Controller | ❌ Not exist |
|
||||
| P2 | Audit Trail | New Model | ❌ Not exist |
|
||||
| P3 | Inventory | CounterController | ⚠️ Partial |
|
||||
| P3 | Billing | New Controller | ❌ Not exist |
|
||||
|
||||
---
|
||||
|
||||
## Quick Test: Does Order Creation Work?
|
||||
|
||||
```bash
|
||||
# Test 1: Create demo order (no auth required)
|
||||
curl -X POST http://localhost:8080/api/demo/order \
|
||||
-H "Content-Type: application/json" \
|
||||
-d '{"NameFirst": "Test", "NameLast": "Patient"}'
|
||||
|
||||
# Expected Response:
|
||||
{
|
||||
"status": "success",
|
||||
"message": "Demo order created successfully",
|
||||
"data": {
|
||||
"PatientID": "DEMO1736689600",
|
||||
"InternalPID": 1,
|
||||
"OrderID": "00250112000001",
|
||||
"OrderStatus": "ORD"
|
||||
}
|
||||
}
|
||||
|
||||
# Test 2: Update order status
|
||||
curl -X POST http://localhost:8080/api/ordertest/status \
|
||||
-H "Content-Type: application/json" \
|
||||
-H "Authorization: Bearer <token>" \
|
||||
-d '{"OrderID": "00250112000001", "OrderStatus": "SCH"}'
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## Success Criteria
|
||||
|
||||
### Functional
|
||||
- Patient registration works ✅
|
||||
- Test ordering generates valid OrderID and SID
|
||||
- Specimens track through collection → transport → reception → preparation → analysis
|
||||
- Results can be entered with reference range validation
|
||||
- Results verified through VER → REV → REP workflow
|
||||
- Instruments can send results via Edge API
|
||||
|
||||
### Non-Functional
|
||||
- JWT authentication required for all endpoints
|
||||
- Soft delete (DelDate) on all transactions
|
||||
- UTC timezone for all datetime fields
|
||||
- Audit logging for data changes
|
||||
- < 2s response time for standard queries
|
||||
|
||||
---
|
||||
|
||||
## Current Codebase Status
|
||||
|
||||
### Controllers (Need Work)
|
||||
- ❌ OrderTestController - placeholder code, incomplete
|
||||
- ❌ ResultController - only validates JWT
|
||||
- ✅ PatientController - complete
|
||||
- ✅ TestsController - complete
|
||||
- ✅ PatVisitController - partial
|
||||
|
||||
### Models (Good)
|
||||
- ✅ PatientModel - complete
|
||||
- ✅ TestDef* models - complete
|
||||
- ✅ Ref* models - complete
|
||||
- ✅ ValueSet* models - complete
|
||||
- ✅ SpecimenModel - exists, needs API
|
||||
|
||||
### Missing Controllers
|
||||
- ❌ SpecimenController - need full implementation
|
||||
- ❌ ResultController - need full implementation
|
||||
- ❌ QualityControlController - not exist
|
||||
- ❌ CalibrationController - not exist
|
||||
- ❌ AuditController - not exist
|
||||
- ❌ BillingController - not exist
|
||||
12
app/.htaccess
Executable file → Normal file
12
app/.htaccess
Executable file → Normal file
@ -1,6 +1,6 @@
|
||||
<IfModule authz_core_module>
|
||||
Require all denied
|
||||
</IfModule>
|
||||
<IfModule !authz_core_module>
|
||||
Deny from all
|
||||
</IfModule>
|
||||
<IfModule authz_core_module>
|
||||
Require all denied
|
||||
</IfModule>
|
||||
<IfModule !authz_core_module>
|
||||
Deny from all
|
||||
</IfModule>
|
||||
|
||||
30
app/Common.php
Executable file → Normal file
30
app/Common.php
Executable file → Normal file
@ -1,15 +1,15 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* The goal of this file is to allow developers a location
|
||||
* where they can overwrite core procedural functions and
|
||||
* replace them with their own. This file is loaded during
|
||||
* the bootstrap process and is called during the framework's
|
||||
* execution.
|
||||
*
|
||||
* This can be looked at as a `master helper` file that is
|
||||
* loaded early on, and may also contain additional functions
|
||||
* that you'd like to use throughout your entire application
|
||||
*
|
||||
* @see: https://codeigniter.com/user_guide/extending/common.html
|
||||
*/
|
||||
<?php
|
||||
|
||||
/**
|
||||
* The goal of this file is to allow developers a location
|
||||
* where they can overwrite core procedural functions and
|
||||
* replace them with their own. This file is loaded during
|
||||
* the bootstrap process and is called during the framework's
|
||||
* execution.
|
||||
*
|
||||
* This can be looked at as a `master helper` file that is
|
||||
* loaded early on, and may also contain additional functions
|
||||
* that you'd like to use throughout your entire application
|
||||
*
|
||||
* @see: https://codeigniter.com/user_guide/extending/common.html
|
||||
*/
|
||||
|
||||
406
app/Config/App.php
Executable file → Normal file
406
app/Config/App.php
Executable file → Normal file
@ -1,203 +1,203 @@
|
||||
<?php
|
||||
|
||||
namespace Config;
|
||||
|
||||
use CodeIgniter\Config\BaseConfig;
|
||||
|
||||
class App extends BaseConfig
|
||||
{
|
||||
/**
|
||||
* --------------------------------------------------------------------------
|
||||
* Base Site URL
|
||||
* --------------------------------------------------------------------------
|
||||
*
|
||||
* URL to your CodeIgniter root. Typically, this will be your base URL,
|
||||
* WITH a trailing slash:
|
||||
*
|
||||
* E.g., http://example.com/
|
||||
*/
|
||||
public string $baseURL = '';
|
||||
|
||||
/**
|
||||
* Allowed Hostnames in the Site URL other than the hostname in the baseURL.
|
||||
* If you want to accept multiple Hostnames, set this.
|
||||
*
|
||||
* E.g.,
|
||||
* When your site URL ($baseURL) is 'http://example.com/', and your site
|
||||
* also accepts 'http://media.example.com/' and 'http://accounts.example.com/':
|
||||
* ['media.example.com', 'accounts.example.com']
|
||||
*
|
||||
* @var list<string>
|
||||
*/
|
||||
public array $allowedHostnames = [];
|
||||
|
||||
/**
|
||||
* --------------------------------------------------------------------------
|
||||
* Index File
|
||||
* --------------------------------------------------------------------------
|
||||
*
|
||||
* Typically, this will be your `index.php` file, unless you've renamed it to
|
||||
* something else. If you have configured your web server to remove this file
|
||||
* from your site URIs, set this variable to an empty string.
|
||||
*/
|
||||
#public string $indexPage = 'index.php';
|
||||
public string $indexPage = '';
|
||||
|
||||
/**
|
||||
* --------------------------------------------------------------------------
|
||||
* URI PROTOCOL
|
||||
* --------------------------------------------------------------------------
|
||||
*
|
||||
* This item determines which server global should be used to retrieve the
|
||||
* URI string. The default setting of 'REQUEST_URI' works for most servers.
|
||||
* If your links do not seem to work, try one of the other delicious flavors:
|
||||
*
|
||||
* 'REQUEST_URI': Uses $_SERVER['REQUEST_URI']
|
||||
* 'QUERY_STRING': Uses $_SERVER['QUERY_STRING']
|
||||
* 'PATH_INFO': Uses $_SERVER['PATH_INFO']
|
||||
*
|
||||
* WARNING: If you set this to 'PATH_INFO', URIs will always be URL-decoded!
|
||||
*/
|
||||
public string $uriProtocol = 'REQUEST_URI';
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Allowed URL Characters
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| This lets you specify which characters are permitted within your URLs.
|
||||
| When someone tries to submit a URL with disallowed characters they will
|
||||
| get a warning message.
|
||||
|
|
||||
| As a security measure you are STRONGLY encouraged to restrict URLs to
|
||||
| as few characters as possible.
|
||||
|
|
||||
| By default, only these are allowed: `a-z 0-9~%.:_-`
|
||||
|
|
||||
| Set an empty string to allow all characters -- but only if you are insane.
|
||||
|
|
||||
| The configured value is actually a regular expression character group
|
||||
| and it will be used as: '/\A[<permittedURIChars>]+\z/iu'
|
||||
|
|
||||
| DO NOT CHANGE THIS UNLESS YOU FULLY UNDERSTAND THE REPERCUSSIONS!!
|
||||
|
|
||||
*/
|
||||
public string $permittedURIChars = 'a-z 0-9~%.:_\-';
|
||||
|
||||
/**
|
||||
* --------------------------------------------------------------------------
|
||||
* Default Locale
|
||||
* --------------------------------------------------------------------------
|
||||
*
|
||||
* The Locale roughly represents the language and location that your visitor
|
||||
* is viewing the site from. It affects the language strings and other
|
||||
* strings (like currency markers, numbers, etc), that your program
|
||||
* should run under for this request.
|
||||
*/
|
||||
public string $defaultLocale = 'en';
|
||||
|
||||
/**
|
||||
* --------------------------------------------------------------------------
|
||||
* Negotiate Locale
|
||||
* --------------------------------------------------------------------------
|
||||
*
|
||||
* If true, the current Request object will automatically determine the
|
||||
* language to use based on the value of the Accept-Language header.
|
||||
*
|
||||
* If false, no automatic detection will be performed.
|
||||
*/
|
||||
public bool $negotiateLocale = false;
|
||||
|
||||
/**
|
||||
* --------------------------------------------------------------------------
|
||||
* Supported Locales
|
||||
* --------------------------------------------------------------------------
|
||||
*
|
||||
* If $negotiateLocale is true, this array lists the locales supported
|
||||
* by the application in descending order of priority. If no match is
|
||||
* found, the first locale will be used.
|
||||
*
|
||||
* IncomingRequest::setLocale() also uses this list.
|
||||
*
|
||||
* @var list<string>
|
||||
*/
|
||||
public array $supportedLocales = ['en'];
|
||||
|
||||
/**
|
||||
* --------------------------------------------------------------------------
|
||||
* Application Timezone
|
||||
* --------------------------------------------------------------------------
|
||||
*
|
||||
* The default timezone that will be used in your application to display
|
||||
* dates with the date helper, and can be retrieved through app_timezone()
|
||||
*
|
||||
* @see https://www.php.net/manual/en/timezones.php for list of timezones
|
||||
* supported by PHP.
|
||||
*/
|
||||
public string $appTimezone = 'UTC';
|
||||
|
||||
/**
|
||||
* --------------------------------------------------------------------------
|
||||
* Default Character Set
|
||||
* --------------------------------------------------------------------------
|
||||
*
|
||||
* This determines which character set is used by default in various methods
|
||||
* that require a character set to be provided.
|
||||
*
|
||||
* @see http://php.net/htmlspecialchars for a list of supported charsets.
|
||||
*/
|
||||
public string $charset = 'UTF-8';
|
||||
|
||||
/**
|
||||
* --------------------------------------------------------------------------
|
||||
* Force Global Secure Requests
|
||||
* --------------------------------------------------------------------------
|
||||
*
|
||||
* If true, this will force every request made to this application to be
|
||||
* made via a secure connection (HTTPS). If the incoming request is not
|
||||
* secure, the user will be redirected to a secure version of the page
|
||||
* and the HTTP Strict Transport Security (HSTS) header will be set.
|
||||
*/
|
||||
public bool $forceGlobalSecureRequests = false;
|
||||
|
||||
/**
|
||||
* --------------------------------------------------------------------------
|
||||
* Reverse Proxy IPs
|
||||
* --------------------------------------------------------------------------
|
||||
*
|
||||
* If your server is behind a reverse proxy, you must whitelist the proxy
|
||||
* IP addresses from which CodeIgniter should trust headers such as
|
||||
* X-Forwarded-For or Client-IP in order to properly identify
|
||||
* the visitor's IP address.
|
||||
*
|
||||
* You need to set a proxy IP address or IP address with subnets and
|
||||
* the HTTP header for the client IP address.
|
||||
*
|
||||
* Here are some examples:
|
||||
* [
|
||||
* '10.0.1.200' => 'X-Forwarded-For',
|
||||
* '192.168.5.0/24' => 'X-Real-IP',
|
||||
* ]
|
||||
*
|
||||
* @var array<string, string>
|
||||
*/
|
||||
public array $proxyIPs = [];
|
||||
|
||||
/**
|
||||
* --------------------------------------------------------------------------
|
||||
* Content Security Policy
|
||||
* --------------------------------------------------------------------------
|
||||
*
|
||||
* Enables the Response's Content Secure Policy to restrict the sources that
|
||||
* can be used for images, scripts, CSS files, audio, video, etc. If enabled,
|
||||
* the Response object will populate default values for the policy from the
|
||||
* `ContentSecurityPolicy.php` file. Controllers can always add to those
|
||||
* restrictions at run time.
|
||||
*
|
||||
* For a better understanding of CSP, see these documents:
|
||||
*
|
||||
* @see http://www.html5rocks.com/en/tutorials/security/content-security-policy/
|
||||
* @see http://www.w3.org/TR/CSP/
|
||||
*/
|
||||
public bool $CSPEnabled = false;
|
||||
}
|
||||
<?php
|
||||
|
||||
namespace Config;
|
||||
|
||||
use CodeIgniter\Config\BaseConfig;
|
||||
|
||||
class App extends BaseConfig
|
||||
{
|
||||
/**
|
||||
* --------------------------------------------------------------------------
|
||||
* Base Site URL
|
||||
* --------------------------------------------------------------------------
|
||||
*
|
||||
* URL to your CodeIgniter root. Typically, this will be your base URL,
|
||||
* WITH a trailing slash:
|
||||
*
|
||||
* E.g., http://example.com/
|
||||
*/
|
||||
public string $baseURL = '';
|
||||
|
||||
/**
|
||||
* Allowed Hostnames in the Site URL other than the hostname in the baseURL.
|
||||
* If you want to accept multiple Hostnames, set this.
|
||||
*
|
||||
* E.g.,
|
||||
* When your site URL ($baseURL) is 'http://example.com/', and your site
|
||||
* also accepts 'http://media.example.com/' and 'http://accounts.example.com/':
|
||||
* ['media.example.com', 'accounts.example.com']
|
||||
*
|
||||
* @var list<string>
|
||||
*/
|
||||
public array $allowedHostnames = [];
|
||||
|
||||
/**
|
||||
* --------------------------------------------------------------------------
|
||||
* Index File
|
||||
* --------------------------------------------------------------------------
|
||||
*
|
||||
* Typically, this will be your `index.php` file, unless you've renamed it to
|
||||
* something else. If you have configured your web server to remove this file
|
||||
* from your site URIs, set this variable to an empty string.
|
||||
*/
|
||||
#public string $indexPage = 'index.php';
|
||||
public string $indexPage = '';
|
||||
|
||||
/**
|
||||
* --------------------------------------------------------------------------
|
||||
* URI PROTOCOL
|
||||
* --------------------------------------------------------------------------
|
||||
*
|
||||
* This item determines which server global should be used to retrieve the
|
||||
* URI string. The default setting of 'REQUEST_URI' works for most servers.
|
||||
* If your links do not seem to work, try one of the other delicious flavors:
|
||||
*
|
||||
* 'REQUEST_URI': Uses $_SERVER['REQUEST_URI']
|
||||
* 'QUERY_STRING': Uses $_SERVER['QUERY_STRING']
|
||||
* 'PATH_INFO': Uses $_SERVER['PATH_INFO']
|
||||
*
|
||||
* WARNING: If you set this to 'PATH_INFO', URIs will always be URL-decoded!
|
||||
*/
|
||||
public string $uriProtocol = 'REQUEST_URI';
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Allowed URL Characters
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| This lets you specify which characters are permitted within your URLs.
|
||||
| When someone tries to submit a URL with disallowed characters they will
|
||||
| get a warning message.
|
||||
|
|
||||
| As a security measure you are STRONGLY encouraged to restrict URLs to
|
||||
| as few characters as possible.
|
||||
|
|
||||
| By default, only these are allowed: `a-z 0-9~%.:_-`
|
||||
|
|
||||
| Set an empty string to allow all characters -- but only if you are insane.
|
||||
|
|
||||
| The configured value is actually a regular expression character group
|
||||
| and it will be used as: '/\A[<permittedURIChars>]+\z/iu'
|
||||
|
|
||||
| DO NOT CHANGE THIS UNLESS YOU FULLY UNDERSTAND THE REPERCUSSIONS!!
|
||||
|
|
||||
*/
|
||||
public string $permittedURIChars = 'a-z 0-9~%.:_\-';
|
||||
|
||||
/**
|
||||
* --------------------------------------------------------------------------
|
||||
* Default Locale
|
||||
* --------------------------------------------------------------------------
|
||||
*
|
||||
* The Locale roughly represents the language and location that your visitor
|
||||
* is viewing the site from. It affects the language strings and other
|
||||
* strings (like currency markers, numbers, etc), that your program
|
||||
* should run under for this request.
|
||||
*/
|
||||
public string $defaultLocale = 'en';
|
||||
|
||||
/**
|
||||
* --------------------------------------------------------------------------
|
||||
* Negotiate Locale
|
||||
* --------------------------------------------------------------------------
|
||||
*
|
||||
* If true, the current Request object will automatically determine the
|
||||
* language to use based on the value of the Accept-Language header.
|
||||
*
|
||||
* If false, no automatic detection will be performed.
|
||||
*/
|
||||
public bool $negotiateLocale = false;
|
||||
|
||||
/**
|
||||
* --------------------------------------------------------------------------
|
||||
* Supported Locales
|
||||
* --------------------------------------------------------------------------
|
||||
*
|
||||
* If $negotiateLocale is true, this array lists the locales supported
|
||||
* by the application in descending order of priority. If no match is
|
||||
* found, the first locale will be used.
|
||||
*
|
||||
* IncomingRequest::setLocale() also uses this list.
|
||||
*
|
||||
* @var list<string>
|
||||
*/
|
||||
public array $supportedLocales = ['en'];
|
||||
|
||||
/**
|
||||
* --------------------------------------------------------------------------
|
||||
* Application Timezone
|
||||
* --------------------------------------------------------------------------
|
||||
*
|
||||
* The default timezone that will be used in your application to display
|
||||
* dates with the date helper, and can be retrieved through app_timezone()
|
||||
*
|
||||
* @see https://www.php.net/manual/en/timezones.php for list of timezones
|
||||
* supported by PHP.
|
||||
*/
|
||||
public string $appTimezone = 'UTC';
|
||||
|
||||
/**
|
||||
* --------------------------------------------------------------------------
|
||||
* Default Character Set
|
||||
* --------------------------------------------------------------------------
|
||||
*
|
||||
* This determines which character set is used by default in various methods
|
||||
* that require a character set to be provided.
|
||||
*
|
||||
* @see http://php.net/htmlspecialchars for a list of supported charsets.
|
||||
*/
|
||||
public string $charset = 'UTF-8';
|
||||
|
||||
/**
|
||||
* --------------------------------------------------------------------------
|
||||
* Force Global Secure Requests
|
||||
* --------------------------------------------------------------------------
|
||||
*
|
||||
* If true, this will force every request made to this application to be
|
||||
* made via a secure connection (HTTPS). If the incoming request is not
|
||||
* secure, the user will be redirected to a secure version of the page
|
||||
* and the HTTP Strict Transport Security (HSTS) header will be set.
|
||||
*/
|
||||
public bool $forceGlobalSecureRequests = false;
|
||||
|
||||
/**
|
||||
* --------------------------------------------------------------------------
|
||||
* Reverse Proxy IPs
|
||||
* --------------------------------------------------------------------------
|
||||
*
|
||||
* If your server is behind a reverse proxy, you must whitelist the proxy
|
||||
* IP addresses from which CodeIgniter should trust headers such as
|
||||
* X-Forwarded-For or Client-IP in order to properly identify
|
||||
* the visitor's IP address.
|
||||
*
|
||||
* You need to set a proxy IP address or IP address with subnets and
|
||||
* the HTTP header for the client IP address.
|
||||
*
|
||||
* Here are some examples:
|
||||
* [
|
||||
* '10.0.1.200' => 'X-Forwarded-For',
|
||||
* '192.168.5.0/24' => 'X-Real-IP',
|
||||
* ]
|
||||
*
|
||||
* @var array<string, string>
|
||||
*/
|
||||
public array $proxyIPs = [];
|
||||
|
||||
/**
|
||||
* --------------------------------------------------------------------------
|
||||
* Content Security Policy
|
||||
* --------------------------------------------------------------------------
|
||||
*
|
||||
* Enables the Response's Content Secure Policy to restrict the sources that
|
||||
* can be used for images, scripts, CSS files, audio, video, etc. If enabled,
|
||||
* the Response object will populate default values for the policy from the
|
||||
* `ContentSecurityPolicy.php` file. Controllers can always add to those
|
||||
* restrictions at run time.
|
||||
*
|
||||
* For a better understanding of CSP, see these documents:
|
||||
*
|
||||
* @see http://www.html5rocks.com/en/tutorials/security/content-security-policy/
|
||||
* @see http://www.w3.org/TR/CSP/
|
||||
*/
|
||||
public bool $CSPEnabled = false;
|
||||
}
|
||||
|
||||
184
app/Config/Autoload.php
Executable file → Normal file
184
app/Config/Autoload.php
Executable file → Normal file
@ -1,92 +1,92 @@
|
||||
<?php
|
||||
|
||||
namespace Config;
|
||||
|
||||
use CodeIgniter\Config\AutoloadConfig;
|
||||
|
||||
/**
|
||||
* -------------------------------------------------------------------
|
||||
* AUTOLOADER CONFIGURATION
|
||||
* -------------------------------------------------------------------
|
||||
*
|
||||
* This file defines the namespaces and class maps so the Autoloader
|
||||
* can find the files as needed.
|
||||
*
|
||||
* NOTE: If you use an identical key in $psr4 or $classmap, then
|
||||
* the values in this file will overwrite the framework's values.
|
||||
*
|
||||
* NOTE: This class is required prior to Autoloader instantiation,
|
||||
* and does not extend BaseConfig.
|
||||
*/
|
||||
class Autoload extends AutoloadConfig
|
||||
{
|
||||
/**
|
||||
* -------------------------------------------------------------------
|
||||
* Namespaces
|
||||
* -------------------------------------------------------------------
|
||||
* This maps the locations of any namespaces in your application to
|
||||
* their location on the file system. These are used by the autoloader
|
||||
* to locate files the first time they have been instantiated.
|
||||
*
|
||||
* The 'Config' (APPPATH . 'Config') and 'CodeIgniter' (SYSTEMPATH) are
|
||||
* already mapped for you.
|
||||
*
|
||||
* You may change the name of the 'App' namespace if you wish,
|
||||
* but this should be done prior to creating any namespaced classes,
|
||||
* else you will need to modify all of those classes for this to work.
|
||||
*
|
||||
* @var array<string, list<string>|string>
|
||||
*/
|
||||
public $psr4 = [
|
||||
APP_NAMESPACE => APPPATH,
|
||||
];
|
||||
|
||||
/**
|
||||
* -------------------------------------------------------------------
|
||||
* Class Map
|
||||
* -------------------------------------------------------------------
|
||||
* The class map provides a map of class names and their exact
|
||||
* location on the drive. Classes loaded in this manner will have
|
||||
* slightly faster performance because they will not have to be
|
||||
* searched for within one or more directories as they would if they
|
||||
* were being autoloaded through a namespace.
|
||||
*
|
||||
* Prototype:
|
||||
* $classmap = [
|
||||
* 'MyClass' => '/path/to/class/file.php'
|
||||
* ];
|
||||
*
|
||||
* @var array<string, string>
|
||||
*/
|
||||
public $classmap = [];
|
||||
|
||||
/**
|
||||
* -------------------------------------------------------------------
|
||||
* Files
|
||||
* -------------------------------------------------------------------
|
||||
* The files array provides a list of paths to __non-class__ files
|
||||
* that will be autoloaded. This can be useful for bootstrap operations
|
||||
* or for loading functions.
|
||||
*
|
||||
* Prototype:
|
||||
* $files = [
|
||||
* '/path/to/my/file.php',
|
||||
* ];
|
||||
*
|
||||
* @var list<string>
|
||||
*/
|
||||
public $files = [];
|
||||
|
||||
/**
|
||||
* -------------------------------------------------------------------
|
||||
* Helpers
|
||||
* -------------------------------------------------------------------
|
||||
* Prototype:
|
||||
* $helpers = [
|
||||
* 'form',
|
||||
* ];
|
||||
*
|
||||
* @var list<string>
|
||||
*/
|
||||
public $helpers = [];
|
||||
}
|
||||
<?php
|
||||
|
||||
namespace Config;
|
||||
|
||||
use CodeIgniter\Config\AutoloadConfig;
|
||||
|
||||
/**
|
||||
* -------------------------------------------------------------------
|
||||
* AUTOLOADER CONFIGURATION
|
||||
* -------------------------------------------------------------------
|
||||
*
|
||||
* This file defines the namespaces and class maps so the Autoloader
|
||||
* can find the files as needed.
|
||||
*
|
||||
* NOTE: If you use an identical key in $psr4 or $classmap, then
|
||||
* the values in this file will overwrite the framework's values.
|
||||
*
|
||||
* NOTE: This class is required prior to Autoloader instantiation,
|
||||
* and does not extend BaseConfig.
|
||||
*/
|
||||
class Autoload extends AutoloadConfig
|
||||
{
|
||||
/**
|
||||
* -------------------------------------------------------------------
|
||||
* Namespaces
|
||||
* -------------------------------------------------------------------
|
||||
* This maps the locations of any namespaces in your application to
|
||||
* their location on the file system. These are used by the autoloader
|
||||
* to locate files the first time they have been instantiated.
|
||||
*
|
||||
* The 'Config' (APPPATH . 'Config') and 'CodeIgniter' (SYSTEMPATH) are
|
||||
* already mapped for you.
|
||||
*
|
||||
* You may change the name of the 'App' namespace if you wish,
|
||||
* but this should be done prior to creating any namespaced classes,
|
||||
* else you will need to modify all of those classes for this to work.
|
||||
*
|
||||
* @var array<string, list<string>|string>
|
||||
*/
|
||||
public $psr4 = [
|
||||
APP_NAMESPACE => APPPATH,
|
||||
];
|
||||
|
||||
/**
|
||||
* -------------------------------------------------------------------
|
||||
* Class Map
|
||||
* -------------------------------------------------------------------
|
||||
* The class map provides a map of class names and their exact
|
||||
* location on the drive. Classes loaded in this manner will have
|
||||
* slightly faster performance because they will not have to be
|
||||
* searched for within one or more directories as they would if they
|
||||
* were being autoloaded through a namespace.
|
||||
*
|
||||
* Prototype:
|
||||
* $classmap = [
|
||||
* 'MyClass' => '/path/to/class/file.php'
|
||||
* ];
|
||||
*
|
||||
* @var array<string, string>
|
||||
*/
|
||||
public $classmap = [];
|
||||
|
||||
/**
|
||||
* -------------------------------------------------------------------
|
||||
* Files
|
||||
* -------------------------------------------------------------------
|
||||
* The files array provides a list of paths to __non-class__ files
|
||||
* that will be autoloaded. This can be useful for bootstrap operations
|
||||
* or for loading functions.
|
||||
*
|
||||
* Prototype:
|
||||
* $files = [
|
||||
* '/path/to/my/file.php',
|
||||
* ];
|
||||
*
|
||||
* @var list<string>
|
||||
*/
|
||||
public $files = [];
|
||||
|
||||
/**
|
||||
* -------------------------------------------------------------------
|
||||
* Helpers
|
||||
* -------------------------------------------------------------------
|
||||
* Prototype:
|
||||
* $helpers = [
|
||||
* 'form',
|
||||
* ];
|
||||
*
|
||||
* @var list<string>
|
||||
*/
|
||||
public $helpers = [];
|
||||
}
|
||||
|
||||
68
app/Config/Boot/development.php
Executable file → Normal file
68
app/Config/Boot/development.php
Executable file → Normal file
@ -1,34 +1,34 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| ERROR DISPLAY
|
||||
|--------------------------------------------------------------------------
|
||||
| In development, we want to show as many errors as possible to help
|
||||
| make sure they don't make it to production. And save us hours of
|
||||
| painful debugging.
|
||||
|
|
||||
| If you set 'display_errors' to '1', CI4's detailed error report will show.
|
||||
*/
|
||||
error_reporting(E_ALL);
|
||||
ini_set('display_errors', '1');
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| DEBUG BACKTRACES
|
||||
|--------------------------------------------------------------------------
|
||||
| If true, this constant will tell the error screens to display debug
|
||||
| backtraces along with the other error information. If you would
|
||||
| prefer to not see this, set this value to false.
|
||||
*/
|
||||
defined('SHOW_DEBUG_BACKTRACE') || define('SHOW_DEBUG_BACKTRACE', true);
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| DEBUG MODE
|
||||
|--------------------------------------------------------------------------
|
||||
| Debug mode is an experimental flag that can allow changes throughout
|
||||
| the system. This will control whether Kint is loaded, and a few other
|
||||
| items. It can always be used within your own application too.
|
||||
*/
|
||||
defined('CI_DEBUG') || define('CI_DEBUG', true);
|
||||
<?php
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| ERROR DISPLAY
|
||||
|--------------------------------------------------------------------------
|
||||
| In development, we want to show as many errors as possible to help
|
||||
| make sure they don't make it to production. And save us hours of
|
||||
| painful debugging.
|
||||
|
|
||||
| If you set 'display_errors' to '1', CI4's detailed error report will show.
|
||||
*/
|
||||
error_reporting(E_ALL);
|
||||
ini_set('display_errors', '1');
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| DEBUG BACKTRACES
|
||||
|--------------------------------------------------------------------------
|
||||
| If true, this constant will tell the error screens to display debug
|
||||
| backtraces along with the other error information. If you would
|
||||
| prefer to not see this, set this value to false.
|
||||
*/
|
||||
defined('SHOW_DEBUG_BACKTRACE') || define('SHOW_DEBUG_BACKTRACE', true);
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| DEBUG MODE
|
||||
|--------------------------------------------------------------------------
|
||||
| Debug mode is an experimental flag that can allow changes throughout
|
||||
| the system. This will control whether Kint is loaded, and a few other
|
||||
| items. It can always be used within your own application too.
|
||||
*/
|
||||
defined('CI_DEBUG') || define('CI_DEBUG', true);
|
||||
|
||||
50
app/Config/Boot/production.php
Executable file → Normal file
50
app/Config/Boot/production.php
Executable file → Normal file
@ -1,25 +1,25 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| ERROR DISPLAY
|
||||
|--------------------------------------------------------------------------
|
||||
| Don't show ANY in production environments. Instead, let the system catch
|
||||
| it and display a generic error message.
|
||||
|
|
||||
| If you set 'display_errors' to '1', CI4's detailed error report will show.
|
||||
*/
|
||||
error_reporting(E_ALL & ~E_DEPRECATED);
|
||||
// If you want to suppress more types of errors.
|
||||
// error_reporting(E_ALL & ~E_NOTICE & ~E_DEPRECATED & ~E_STRICT & ~E_USER_NOTICE & ~E_USER_DEPRECATED);
|
||||
ini_set('display_errors', '0');
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| DEBUG MODE
|
||||
|--------------------------------------------------------------------------
|
||||
| Debug mode is an experimental flag that can allow changes throughout
|
||||
| the system. It's not widely used currently, and may not survive
|
||||
| release of the framework.
|
||||
*/
|
||||
defined('CI_DEBUG') || define('CI_DEBUG', false);
|
||||
<?php
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| ERROR DISPLAY
|
||||
|--------------------------------------------------------------------------
|
||||
| Don't show ANY in production environments. Instead, let the system catch
|
||||
| it and display a generic error message.
|
||||
|
|
||||
| If you set 'display_errors' to '1', CI4's detailed error report will show.
|
||||
*/
|
||||
error_reporting(E_ALL & ~E_DEPRECATED);
|
||||
// If you want to suppress more types of errors.
|
||||
// error_reporting(E_ALL & ~E_NOTICE & ~E_DEPRECATED & ~E_STRICT & ~E_USER_NOTICE & ~E_USER_DEPRECATED);
|
||||
ini_set('display_errors', '0');
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| DEBUG MODE
|
||||
|--------------------------------------------------------------------------
|
||||
| Debug mode is an experimental flag that can allow changes throughout
|
||||
| the system. It's not widely used currently, and may not survive
|
||||
| release of the framework.
|
||||
*/
|
||||
defined('CI_DEBUG') || define('CI_DEBUG', false);
|
||||
|
||||
76
app/Config/Boot/testing.php
Executable file → Normal file
76
app/Config/Boot/testing.php
Executable file → Normal file
@ -1,38 +1,38 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* The environment testing is reserved for PHPUnit testing. It has special
|
||||
* conditions built into the framework at various places to assist with that.
|
||||
* You can’t use it for your development.
|
||||
*/
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| ERROR DISPLAY
|
||||
|--------------------------------------------------------------------------
|
||||
| In development, we want to show as many errors as possible to help
|
||||
| make sure they don't make it to production. And save us hours of
|
||||
| painful debugging.
|
||||
*/
|
||||
error_reporting(E_ALL);
|
||||
ini_set('display_errors', '1');
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| DEBUG BACKTRACES
|
||||
|--------------------------------------------------------------------------
|
||||
| If true, this constant will tell the error screens to display debug
|
||||
| backtraces along with the other error information. If you would
|
||||
| prefer to not see this, set this value to false.
|
||||
*/
|
||||
defined('SHOW_DEBUG_BACKTRACE') || define('SHOW_DEBUG_BACKTRACE', true);
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| DEBUG MODE
|
||||
|--------------------------------------------------------------------------
|
||||
| Debug mode is an experimental flag that can allow changes throughout
|
||||
| the system. It's not widely used currently, and may not survive
|
||||
| release of the framework.
|
||||
*/
|
||||
defined('CI_DEBUG') || define('CI_DEBUG', true);
|
||||
<?php
|
||||
|
||||
/*
|
||||
* The environment testing is reserved for PHPUnit testing. It has special
|
||||
* conditions built into the framework at various places to assist with that.
|
||||
* You can’t use it for your development.
|
||||
*/
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| ERROR DISPLAY
|
||||
|--------------------------------------------------------------------------
|
||||
| In development, we want to show as many errors as possible to help
|
||||
| make sure they don't make it to production. And save us hours of
|
||||
| painful debugging.
|
||||
*/
|
||||
error_reporting(E_ALL);
|
||||
ini_set('display_errors', '1');
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| DEBUG BACKTRACES
|
||||
|--------------------------------------------------------------------------
|
||||
| If true, this constant will tell the error screens to display debug
|
||||
| backtraces along with the other error information. If you would
|
||||
| prefer to not see this, set this value to false.
|
||||
*/
|
||||
defined('SHOW_DEBUG_BACKTRACE') || define('SHOW_DEBUG_BACKTRACE', true);
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| DEBUG MODE
|
||||
|--------------------------------------------------------------------------
|
||||
| Debug mode is an experimental flag that can allow changes throughout
|
||||
| the system. It's not widely used currently, and may not survive
|
||||
| release of the framework.
|
||||
*/
|
||||
defined('CI_DEBUG') || define('CI_DEBUG', true);
|
||||
|
||||
40
app/Config/CURLRequest.php
Executable file → Normal file
40
app/Config/CURLRequest.php
Executable file → Normal file
@ -1,20 +1,20 @@
|
||||
<?php
|
||||
|
||||
namespace Config;
|
||||
|
||||
use CodeIgniter\Config\BaseConfig;
|
||||
|
||||
class CURLRequest extends BaseConfig
|
||||
{
|
||||
/**
|
||||
* --------------------------------------------------------------------------
|
||||
* CURLRequest Share Options
|
||||
* --------------------------------------------------------------------------
|
||||
*
|
||||
* Whether share options between requests or not.
|
||||
*
|
||||
* If true, all the options won't be reset between requests.
|
||||
* It may cause an error request with unnecessary headers.
|
||||
*/
|
||||
public bool $shareOptions = false;
|
||||
}
|
||||
<?php
|
||||
|
||||
namespace Config;
|
||||
|
||||
use CodeIgniter\Config\BaseConfig;
|
||||
|
||||
class CURLRequest extends BaseConfig
|
||||
{
|
||||
/**
|
||||
* --------------------------------------------------------------------------
|
||||
* CURLRequest Share Options
|
||||
* --------------------------------------------------------------------------
|
||||
*
|
||||
* Whether share options between requests or not.
|
||||
*
|
||||
* If true, all the options won't be reset between requests.
|
||||
* It may cause an error request with unnecessary headers.
|
||||
*/
|
||||
public bool $shareOptions = false;
|
||||
}
|
||||
|
||||
324
app/Config/Cache.php
Executable file → Normal file
324
app/Config/Cache.php
Executable file → Normal file
@ -1,162 +1,162 @@
|
||||
<?php
|
||||
|
||||
namespace Config;
|
||||
|
||||
use CodeIgniter\Cache\CacheInterface;
|
||||
use CodeIgniter\Cache\Handlers\DummyHandler;
|
||||
use CodeIgniter\Cache\Handlers\FileHandler;
|
||||
use CodeIgniter\Cache\Handlers\MemcachedHandler;
|
||||
use CodeIgniter\Cache\Handlers\PredisHandler;
|
||||
use CodeIgniter\Cache\Handlers\RedisHandler;
|
||||
use CodeIgniter\Cache\Handlers\WincacheHandler;
|
||||
use CodeIgniter\Config\BaseConfig;
|
||||
|
||||
class Cache extends BaseConfig
|
||||
{
|
||||
/**
|
||||
* --------------------------------------------------------------------------
|
||||
* Primary Handler
|
||||
* --------------------------------------------------------------------------
|
||||
*
|
||||
* The name of the preferred handler that should be used. If for some reason
|
||||
* it is not available, the $backupHandler will be used in its place.
|
||||
*/
|
||||
public string $handler = 'file';
|
||||
|
||||
/**
|
||||
* --------------------------------------------------------------------------
|
||||
* Backup Handler
|
||||
* --------------------------------------------------------------------------
|
||||
*
|
||||
* The name of the handler that will be used in case the first one is
|
||||
* unreachable. Often, 'file' is used here since the filesystem is
|
||||
* always available, though that's not always practical for the app.
|
||||
*/
|
||||
public string $backupHandler = 'dummy';
|
||||
|
||||
/**
|
||||
* --------------------------------------------------------------------------
|
||||
* Key Prefix
|
||||
* --------------------------------------------------------------------------
|
||||
*
|
||||
* This string is added to all cache item names to help avoid collisions
|
||||
* if you run multiple applications with the same cache engine.
|
||||
*/
|
||||
public string $prefix = '';
|
||||
|
||||
/**
|
||||
* --------------------------------------------------------------------------
|
||||
* Default TTL
|
||||
* --------------------------------------------------------------------------
|
||||
*
|
||||
* The default number of seconds to save items when none is specified.
|
||||
*
|
||||
* WARNING: This is not used by framework handlers where 60 seconds is
|
||||
* hard-coded, but may be useful to projects and modules. This will replace
|
||||
* the hard-coded value in a future release.
|
||||
*/
|
||||
public int $ttl = 60;
|
||||
|
||||
/**
|
||||
* --------------------------------------------------------------------------
|
||||
* Reserved Characters
|
||||
* --------------------------------------------------------------------------
|
||||
*
|
||||
* A string of reserved characters that will not be allowed in keys or tags.
|
||||
* Strings that violate this restriction will cause handlers to throw.
|
||||
* Default: {}()/\@:
|
||||
*
|
||||
* NOTE: The default set is required for PSR-6 compliance.
|
||||
*/
|
||||
public string $reservedCharacters = '{}()/\@:';
|
||||
|
||||
/**
|
||||
* --------------------------------------------------------------------------
|
||||
* File settings
|
||||
* --------------------------------------------------------------------------
|
||||
*
|
||||
* Your file storage preferences can be specified below, if you are using
|
||||
* the File driver.
|
||||
*
|
||||
* @var array<string, int|string|null>
|
||||
*/
|
||||
public array $file = [
|
||||
'storePath' => WRITEPATH . 'cache/',
|
||||
'mode' => 0640,
|
||||
];
|
||||
|
||||
/**
|
||||
* -------------------------------------------------------------------------
|
||||
* Memcached settings
|
||||
* -------------------------------------------------------------------------
|
||||
*
|
||||
* Your Memcached servers can be specified below, if you are using
|
||||
* the Memcached drivers.
|
||||
*
|
||||
* @see https://codeigniter.com/user_guide/libraries/caching.html#memcached
|
||||
*
|
||||
* @var array<string, bool|int|string>
|
||||
*/
|
||||
public array $memcached = [
|
||||
'host' => '127.0.0.1',
|
||||
'port' => 11211,
|
||||
'weight' => 1,
|
||||
'raw' => false,
|
||||
];
|
||||
|
||||
/**
|
||||
* -------------------------------------------------------------------------
|
||||
* Redis settings
|
||||
* -------------------------------------------------------------------------
|
||||
*
|
||||
* Your Redis server can be specified below, if you are using
|
||||
* the Redis or Predis drivers.
|
||||
*
|
||||
* @var array<string, int|string|null>
|
||||
*/
|
||||
public array $redis = [
|
||||
'host' => '127.0.0.1',
|
||||
'password' => null,
|
||||
'port' => 6379,
|
||||
'timeout' => 0,
|
||||
'database' => 0,
|
||||
];
|
||||
|
||||
/**
|
||||
* --------------------------------------------------------------------------
|
||||
* Available Cache Handlers
|
||||
* --------------------------------------------------------------------------
|
||||
*
|
||||
* This is an array of cache engine alias' and class names. Only engines
|
||||
* that are listed here are allowed to be used.
|
||||
*
|
||||
* @var array<string, class-string<CacheInterface>>
|
||||
*/
|
||||
public array $validHandlers = [
|
||||
'dummy' => DummyHandler::class,
|
||||
'file' => FileHandler::class,
|
||||
'memcached' => MemcachedHandler::class,
|
||||
'predis' => PredisHandler::class,
|
||||
'redis' => RedisHandler::class,
|
||||
'wincache' => WincacheHandler::class,
|
||||
];
|
||||
|
||||
/**
|
||||
* --------------------------------------------------------------------------
|
||||
* Web Page Caching: Cache Include Query String
|
||||
* --------------------------------------------------------------------------
|
||||
*
|
||||
* Whether to take the URL query string into consideration when generating
|
||||
* output cache files. Valid options are:
|
||||
*
|
||||
* false = Disabled
|
||||
* true = Enabled, take all query parameters into account.
|
||||
* Please be aware that this may result in numerous cache
|
||||
* files generated for the same page over and over again.
|
||||
* ['q'] = Enabled, but only take into account the specified list
|
||||
* of query parameters.
|
||||
*
|
||||
* @var bool|list<string>
|
||||
*/
|
||||
public $cacheQueryString = false;
|
||||
}
|
||||
<?php
|
||||
|
||||
namespace Config;
|
||||
|
||||
use CodeIgniter\Cache\CacheInterface;
|
||||
use CodeIgniter\Cache\Handlers\DummyHandler;
|
||||
use CodeIgniter\Cache\Handlers\FileHandler;
|
||||
use CodeIgniter\Cache\Handlers\MemcachedHandler;
|
||||
use CodeIgniter\Cache\Handlers\PredisHandler;
|
||||
use CodeIgniter\Cache\Handlers\RedisHandler;
|
||||
use CodeIgniter\Cache\Handlers\WincacheHandler;
|
||||
use CodeIgniter\Config\BaseConfig;
|
||||
|
||||
class Cache extends BaseConfig
|
||||
{
|
||||
/**
|
||||
* --------------------------------------------------------------------------
|
||||
* Primary Handler
|
||||
* --------------------------------------------------------------------------
|
||||
*
|
||||
* The name of the preferred handler that should be used. If for some reason
|
||||
* it is not available, the $backupHandler will be used in its place.
|
||||
*/
|
||||
public string $handler = 'file';
|
||||
|
||||
/**
|
||||
* --------------------------------------------------------------------------
|
||||
* Backup Handler
|
||||
* --------------------------------------------------------------------------
|
||||
*
|
||||
* The name of the handler that will be used in case the first one is
|
||||
* unreachable. Often, 'file' is used here since the filesystem is
|
||||
* always available, though that's not always practical for the app.
|
||||
*/
|
||||
public string $backupHandler = 'dummy';
|
||||
|
||||
/**
|
||||
* --------------------------------------------------------------------------
|
||||
* Key Prefix
|
||||
* --------------------------------------------------------------------------
|
||||
*
|
||||
* This string is added to all cache item names to help avoid collisions
|
||||
* if you run multiple applications with the same cache engine.
|
||||
*/
|
||||
public string $prefix = '';
|
||||
|
||||
/**
|
||||
* --------------------------------------------------------------------------
|
||||
* Default TTL
|
||||
* --------------------------------------------------------------------------
|
||||
*
|
||||
* The default number of seconds to save items when none is specified.
|
||||
*
|
||||
* WARNING: This is not used by framework handlers where 60 seconds is
|
||||
* hard-coded, but may be useful to projects and modules. This will replace
|
||||
* the hard-coded value in a future release.
|
||||
*/
|
||||
public int $ttl = 60;
|
||||
|
||||
/**
|
||||
* --------------------------------------------------------------------------
|
||||
* Reserved Characters
|
||||
* --------------------------------------------------------------------------
|
||||
*
|
||||
* A string of reserved characters that will not be allowed in keys or tags.
|
||||
* Strings that violate this restriction will cause handlers to throw.
|
||||
* Default: {}()/\@:
|
||||
*
|
||||
* NOTE: The default set is required for PSR-6 compliance.
|
||||
*/
|
||||
public string $reservedCharacters = '{}()/\@:';
|
||||
|
||||
/**
|
||||
* --------------------------------------------------------------------------
|
||||
* File settings
|
||||
* --------------------------------------------------------------------------
|
||||
*
|
||||
* Your file storage preferences can be specified below, if you are using
|
||||
* the File driver.
|
||||
*
|
||||
* @var array<string, int|string|null>
|
||||
*/
|
||||
public array $file = [
|
||||
'storePath' => WRITEPATH . 'cache/',
|
||||
'mode' => 0640,
|
||||
];
|
||||
|
||||
/**
|
||||
* -------------------------------------------------------------------------
|
||||
* Memcached settings
|
||||
* -------------------------------------------------------------------------
|
||||
*
|
||||
* Your Memcached servers can be specified below, if you are using
|
||||
* the Memcached drivers.
|
||||
*
|
||||
* @see https://codeigniter.com/user_guide/libraries/caching.html#memcached
|
||||
*
|
||||
* @var array<string, bool|int|string>
|
||||
*/
|
||||
public array $memcached = [
|
||||
'host' => '127.0.0.1',
|
||||
'port' => 11211,
|
||||
'weight' => 1,
|
||||
'raw' => false,
|
||||
];
|
||||
|
||||
/**
|
||||
* -------------------------------------------------------------------------
|
||||
* Redis settings
|
||||
* -------------------------------------------------------------------------
|
||||
*
|
||||
* Your Redis server can be specified below, if you are using
|
||||
* the Redis or Predis drivers.
|
||||
*
|
||||
* @var array<string, int|string|null>
|
||||
*/
|
||||
public array $redis = [
|
||||
'host' => '127.0.0.1',
|
||||
'password' => null,
|
||||
'port' => 6379,
|
||||
'timeout' => 0,
|
||||
'database' => 0,
|
||||
];
|
||||
|
||||
/**
|
||||
* --------------------------------------------------------------------------
|
||||
* Available Cache Handlers
|
||||
* --------------------------------------------------------------------------
|
||||
*
|
||||
* This is an array of cache engine alias' and class names. Only engines
|
||||
* that are listed here are allowed to be used.
|
||||
*
|
||||
* @var array<string, class-string<CacheInterface>>
|
||||
*/
|
||||
public array $validHandlers = [
|
||||
'dummy' => DummyHandler::class,
|
||||
'file' => FileHandler::class,
|
||||
'memcached' => MemcachedHandler::class,
|
||||
'predis' => PredisHandler::class,
|
||||
'redis' => RedisHandler::class,
|
||||
'wincache' => WincacheHandler::class,
|
||||
];
|
||||
|
||||
/**
|
||||
* --------------------------------------------------------------------------
|
||||
* Web Page Caching: Cache Include Query String
|
||||
* --------------------------------------------------------------------------
|
||||
*
|
||||
* Whether to take the URL query string into consideration when generating
|
||||
* output cache files. Valid options are:
|
||||
*
|
||||
* false = Disabled
|
||||
* true = Enabled, take all query parameters into account.
|
||||
* Please be aware that this may result in numerous cache
|
||||
* files generated for the same page over and over again.
|
||||
* ['q'] = Enabled, but only take into account the specified list
|
||||
* of query parameters.
|
||||
*
|
||||
* @var bool|list<string>
|
||||
*/
|
||||
public $cacheQueryString = false;
|
||||
}
|
||||
|
||||
158
app/Config/Constants.php
Executable file → Normal file
158
app/Config/Constants.php
Executable file → Normal file
@ -1,79 +1,79 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
| --------------------------------------------------------------------
|
||||
| App Namespace
|
||||
| --------------------------------------------------------------------
|
||||
|
|
||||
| This defines the default Namespace that is used throughout
|
||||
| CodeIgniter to refer to the Application directory. Change
|
||||
| this constant to change the namespace that all application
|
||||
| classes should use.
|
||||
|
|
||||
| NOTE: changing this will require manually modifying the
|
||||
| existing namespaces of App\* namespaced-classes.
|
||||
*/
|
||||
defined('APP_NAMESPACE') || define('APP_NAMESPACE', 'App');
|
||||
|
||||
/*
|
||||
| --------------------------------------------------------------------------
|
||||
| Composer Path
|
||||
| --------------------------------------------------------------------------
|
||||
|
|
||||
| The path that Composer's autoload file is expected to live. By default,
|
||||
| the vendor folder is in the Root directory, but you can customize that here.
|
||||
*/
|
||||
defined('COMPOSER_PATH') || define('COMPOSER_PATH', ROOTPATH . 'vendor/autoload.php');
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Timing Constants
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| Provide simple ways to work with the myriad of PHP functions that
|
||||
| require information to be in seconds.
|
||||
*/
|
||||
defined('SECOND') || define('SECOND', 1);
|
||||
defined('MINUTE') || define('MINUTE', 60);
|
||||
defined('HOUR') || define('HOUR', 3600);
|
||||
defined('DAY') || define('DAY', 86400);
|
||||
defined('WEEK') || define('WEEK', 604800);
|
||||
defined('MONTH') || define('MONTH', 2_592_000);
|
||||
defined('YEAR') || define('YEAR', 31_536_000);
|
||||
defined('DECADE') || define('DECADE', 315_360_000);
|
||||
|
||||
/*
|
||||
| --------------------------------------------------------------------------
|
||||
| Exit Status Codes
|
||||
| --------------------------------------------------------------------------
|
||||
|
|
||||
| Used to indicate the conditions under which the script is exit()ing.
|
||||
| While there is no universal standard for error codes, there are some
|
||||
| broad conventions. Three such conventions are mentioned below, for
|
||||
| those who wish to make use of them. The CodeIgniter defaults were
|
||||
| chosen for the least overlap with these conventions, while still
|
||||
| leaving room for others to be defined in future versions and user
|
||||
| applications.
|
||||
|
|
||||
| The three main conventions used for determining exit status codes
|
||||
| are as follows:
|
||||
|
|
||||
| Standard C/C++ Library (stdlibc):
|
||||
| http://www.gnu.org/software/libc/manual/html_node/Exit-Status.html
|
||||
| (This link also contains other GNU-specific conventions)
|
||||
| BSD sysexits.h:
|
||||
| http://www.gsp.com/cgi-bin/man.cgi?section=3&topic=sysexits
|
||||
| Bash scripting:
|
||||
| http://tldp.org/LDP/abs/html/exitcodes.html
|
||||
|
|
||||
*/
|
||||
defined('EXIT_SUCCESS') || define('EXIT_SUCCESS', 0); // no errors
|
||||
defined('EXIT_ERROR') || define('EXIT_ERROR', 1); // generic error
|
||||
defined('EXIT_CONFIG') || define('EXIT_CONFIG', 3); // configuration error
|
||||
defined('EXIT_UNKNOWN_FILE') || define('EXIT_UNKNOWN_FILE', 4); // file not found
|
||||
defined('EXIT_UNKNOWN_CLASS') || define('EXIT_UNKNOWN_CLASS', 5); // unknown class
|
||||
defined('EXIT_UNKNOWN_METHOD') || define('EXIT_UNKNOWN_METHOD', 6); // unknown class member
|
||||
defined('EXIT_USER_INPUT') || define('EXIT_USER_INPUT', 7); // invalid user input
|
||||
defined('EXIT_DATABASE') || define('EXIT_DATABASE', 8); // database error
|
||||
defined('EXIT__AUTO_MIN') || define('EXIT__AUTO_MIN', 9); // lowest automatically-assigned error code
|
||||
defined('EXIT__AUTO_MAX') || define('EXIT__AUTO_MAX', 125); // highest automatically-assigned error code
|
||||
<?php
|
||||
|
||||
/*
|
||||
| --------------------------------------------------------------------
|
||||
| App Namespace
|
||||
| --------------------------------------------------------------------
|
||||
|
|
||||
| This defines the default Namespace that is used throughout
|
||||
| CodeIgniter to refer to the Application directory. Change
|
||||
| this constant to change the namespace that all application
|
||||
| classes should use.
|
||||
|
|
||||
| NOTE: changing this will require manually modifying the
|
||||
| existing namespaces of App\* namespaced-classes.
|
||||
*/
|
||||
defined('APP_NAMESPACE') || define('APP_NAMESPACE', 'App');
|
||||
|
||||
/*
|
||||
| --------------------------------------------------------------------------
|
||||
| Composer Path
|
||||
| --------------------------------------------------------------------------
|
||||
|
|
||||
| The path that Composer's autoload file is expected to live. By default,
|
||||
| the vendor folder is in the Root directory, but you can customize that here.
|
||||
*/
|
||||
defined('COMPOSER_PATH') || define('COMPOSER_PATH', ROOTPATH . 'vendor/autoload.php');
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Timing Constants
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| Provide simple ways to work with the myriad of PHP functions that
|
||||
| require information to be in seconds.
|
||||
*/
|
||||
defined('SECOND') || define('SECOND', 1);
|
||||
defined('MINUTE') || define('MINUTE', 60);
|
||||
defined('HOUR') || define('HOUR', 3600);
|
||||
defined('DAY') || define('DAY', 86400);
|
||||
defined('WEEK') || define('WEEK', 604800);
|
||||
defined('MONTH') || define('MONTH', 2_592_000);
|
||||
defined('YEAR') || define('YEAR', 31_536_000);
|
||||
defined('DECADE') || define('DECADE', 315_360_000);
|
||||
|
||||
/*
|
||||
| --------------------------------------------------------------------------
|
||||
| Exit Status Codes
|
||||
| --------------------------------------------------------------------------
|
||||
|
|
||||
| Used to indicate the conditions under which the script is exit()ing.
|
||||
| While there is no universal standard for error codes, there are some
|
||||
| broad conventions. Three such conventions are mentioned below, for
|
||||
| those who wish to make use of them. The CodeIgniter defaults were
|
||||
| chosen for the least overlap with these conventions, while still
|
||||
| leaving room for others to be defined in future versions and user
|
||||
| applications.
|
||||
|
|
||||
| The three main conventions used for determining exit status codes
|
||||
| are as follows:
|
||||
|
|
||||
| Standard C/C++ Library (stdlibc):
|
||||
| http://www.gnu.org/software/libc/manual/html_node/Exit-Status.html
|
||||
| (This link also contains other GNU-specific conventions)
|
||||
| BSD sysexits.h:
|
||||
| http://www.gsp.com/cgi-bin/man.cgi?section=3&topic=sysexits
|
||||
| Bash scripting:
|
||||
| http://tldp.org/LDP/abs/html/exitcodes.html
|
||||
|
|
||||
*/
|
||||
defined('EXIT_SUCCESS') || define('EXIT_SUCCESS', 0); // no errors
|
||||
defined('EXIT_ERROR') || define('EXIT_ERROR', 1); // generic error
|
||||
defined('EXIT_CONFIG') || define('EXIT_CONFIG', 3); // configuration error
|
||||
defined('EXIT_UNKNOWN_FILE') || define('EXIT_UNKNOWN_FILE', 4); // file not found
|
||||
defined('EXIT_UNKNOWN_CLASS') || define('EXIT_UNKNOWN_CLASS', 5); // unknown class
|
||||
defined('EXIT_UNKNOWN_METHOD') || define('EXIT_UNKNOWN_METHOD', 6); // unknown class member
|
||||
defined('EXIT_USER_INPUT') || define('EXIT_USER_INPUT', 7); // invalid user input
|
||||
defined('EXIT_DATABASE') || define('EXIT_DATABASE', 8); // database error
|
||||
defined('EXIT__AUTO_MIN') || define('EXIT__AUTO_MIN', 9); // lowest automatically-assigned error code
|
||||
defined('EXIT__AUTO_MAX') || define('EXIT__AUTO_MAX', 125); // highest automatically-assigned error code
|
||||
|
||||
352
app/Config/ContentSecurityPolicy.php
Executable file → Normal file
352
app/Config/ContentSecurityPolicy.php
Executable file → Normal file
@ -1,176 +1,176 @@
|
||||
<?php
|
||||
|
||||
namespace Config;
|
||||
|
||||
use CodeIgniter\Config\BaseConfig;
|
||||
|
||||
/**
|
||||
* Stores the default settings for the ContentSecurityPolicy, if you
|
||||
* choose to use it. The values here will be read in and set as defaults
|
||||
* for the site. If needed, they can be overridden on a page-by-page basis.
|
||||
*
|
||||
* Suggested reference for explanations:
|
||||
*
|
||||
* @see https://www.html5rocks.com/en/tutorials/security/content-security-policy/
|
||||
*/
|
||||
class ContentSecurityPolicy extends BaseConfig
|
||||
{
|
||||
// -------------------------------------------------------------------------
|
||||
// Broadbrush CSP management
|
||||
// -------------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Default CSP report context
|
||||
*/
|
||||
public bool $reportOnly = false;
|
||||
|
||||
/**
|
||||
* Specifies a URL where a browser will send reports
|
||||
* when a content security policy is violated.
|
||||
*/
|
||||
public ?string $reportURI = null;
|
||||
|
||||
/**
|
||||
* Instructs user agents to rewrite URL schemes, changing
|
||||
* HTTP to HTTPS. This directive is for websites with
|
||||
* large numbers of old URLs that need to be rewritten.
|
||||
*/
|
||||
public bool $upgradeInsecureRequests = false;
|
||||
|
||||
// -------------------------------------------------------------------------
|
||||
// Sources allowed
|
||||
// NOTE: once you set a policy to 'none', it cannot be further restricted
|
||||
// -------------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Will default to self if not overridden
|
||||
*
|
||||
* @var list<string>|string|null
|
||||
*/
|
||||
public $defaultSrc;
|
||||
|
||||
/**
|
||||
* Lists allowed scripts' URLs.
|
||||
*
|
||||
* @var list<string>|string
|
||||
*/
|
||||
public $scriptSrc = 'self';
|
||||
|
||||
/**
|
||||
* Lists allowed stylesheets' URLs.
|
||||
*
|
||||
* @var list<string>|string
|
||||
*/
|
||||
public $styleSrc = 'self';
|
||||
|
||||
/**
|
||||
* Defines the origins from which images can be loaded.
|
||||
*
|
||||
* @var list<string>|string
|
||||
*/
|
||||
public $imageSrc = 'self';
|
||||
|
||||
/**
|
||||
* Restricts the URLs that can appear in a page's `<base>` element.
|
||||
*
|
||||
* Will default to self if not overridden
|
||||
*
|
||||
* @var list<string>|string|null
|
||||
*/
|
||||
public $baseURI;
|
||||
|
||||
/**
|
||||
* Lists the URLs for workers and embedded frame contents
|
||||
*
|
||||
* @var list<string>|string
|
||||
*/
|
||||
public $childSrc = 'self';
|
||||
|
||||
/**
|
||||
* Limits the origins that you can connect to (via XHR,
|
||||
* WebSockets, and EventSource).
|
||||
*
|
||||
* @var list<string>|string
|
||||
*/
|
||||
public $connectSrc = 'self';
|
||||
|
||||
/**
|
||||
* Specifies the origins that can serve web fonts.
|
||||
*
|
||||
* @var list<string>|string
|
||||
*/
|
||||
public $fontSrc;
|
||||
|
||||
/**
|
||||
* Lists valid endpoints for submission from `<form>` tags.
|
||||
*
|
||||
* @var list<string>|string
|
||||
*/
|
||||
public $formAction = 'self';
|
||||
|
||||
/**
|
||||
* Specifies the sources that can embed the current page.
|
||||
* This directive applies to `<frame>`, `<iframe>`, `<embed>`,
|
||||
* and `<applet>` tags. This directive can't be used in
|
||||
* `<meta>` tags and applies only to non-HTML resources.
|
||||
*
|
||||
* @var list<string>|string|null
|
||||
*/
|
||||
public $frameAncestors;
|
||||
|
||||
/**
|
||||
* The frame-src directive restricts the URLs which may
|
||||
* be loaded into nested browsing contexts.
|
||||
*
|
||||
* @var list<string>|string|null
|
||||
*/
|
||||
public $frameSrc;
|
||||
|
||||
/**
|
||||
* Restricts the origins allowed to deliver video and audio.
|
||||
*
|
||||
* @var list<string>|string|null
|
||||
*/
|
||||
public $mediaSrc;
|
||||
|
||||
/**
|
||||
* Allows control over Flash and other plugins.
|
||||
*
|
||||
* @var list<string>|string
|
||||
*/
|
||||
public $objectSrc = 'self';
|
||||
|
||||
/**
|
||||
* @var list<string>|string|null
|
||||
*/
|
||||
public $manifestSrc;
|
||||
|
||||
/**
|
||||
* Limits the kinds of plugins a page may invoke.
|
||||
*
|
||||
* @var list<string>|string|null
|
||||
*/
|
||||
public $pluginTypes;
|
||||
|
||||
/**
|
||||
* List of actions allowed.
|
||||
*
|
||||
* @var list<string>|string|null
|
||||
*/
|
||||
public $sandbox;
|
||||
|
||||
/**
|
||||
* Nonce tag for style
|
||||
*/
|
||||
public string $styleNonceTag = '{csp-style-nonce}';
|
||||
|
||||
/**
|
||||
* Nonce tag for script
|
||||
*/
|
||||
public string $scriptNonceTag = '{csp-script-nonce}';
|
||||
|
||||
/**
|
||||
* Replace nonce tag automatically
|
||||
*/
|
||||
public bool $autoNonce = true;
|
||||
}
|
||||
<?php
|
||||
|
||||
namespace Config;
|
||||
|
||||
use CodeIgniter\Config\BaseConfig;
|
||||
|
||||
/**
|
||||
* Stores the default settings for the ContentSecurityPolicy, if you
|
||||
* choose to use it. The values here will be read in and set as defaults
|
||||
* for the site. If needed, they can be overridden on a page-by-page basis.
|
||||
*
|
||||
* Suggested reference for explanations:
|
||||
*
|
||||
* @see https://www.html5rocks.com/en/tutorials/security/content-security-policy/
|
||||
*/
|
||||
class ContentSecurityPolicy extends BaseConfig
|
||||
{
|
||||
// -------------------------------------------------------------------------
|
||||
// Broadbrush CSP management
|
||||
// -------------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Default CSP report context
|
||||
*/
|
||||
public bool $reportOnly = false;
|
||||
|
||||
/**
|
||||
* Specifies a URL where a browser will send reports
|
||||
* when a content security policy is violated.
|
||||
*/
|
||||
public ?string $reportURI = null;
|
||||
|
||||
/**
|
||||
* Instructs user agents to rewrite URL schemes, changing
|
||||
* HTTP to HTTPS. This directive is for websites with
|
||||
* large numbers of old URLs that need to be rewritten.
|
||||
*/
|
||||
public bool $upgradeInsecureRequests = false;
|
||||
|
||||
// -------------------------------------------------------------------------
|
||||
// Sources allowed
|
||||
// NOTE: once you set a policy to 'none', it cannot be further restricted
|
||||
// -------------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Will default to self if not overridden
|
||||
*
|
||||
* @var list<string>|string|null
|
||||
*/
|
||||
public $defaultSrc;
|
||||
|
||||
/**
|
||||
* Lists allowed scripts' URLs.
|
||||
*
|
||||
* @var list<string>|string
|
||||
*/
|
||||
public $scriptSrc = 'self';
|
||||
|
||||
/**
|
||||
* Lists allowed stylesheets' URLs.
|
||||
*
|
||||
* @var list<string>|string
|
||||
*/
|
||||
public $styleSrc = 'self';
|
||||
|
||||
/**
|
||||
* Defines the origins from which images can be loaded.
|
||||
*
|
||||
* @var list<string>|string
|
||||
*/
|
||||
public $imageSrc = 'self';
|
||||
|
||||
/**
|
||||
* Restricts the URLs that can appear in a page's `<base>` element.
|
||||
*
|
||||
* Will default to self if not overridden
|
||||
*
|
||||
* @var list<string>|string|null
|
||||
*/
|
||||
public $baseURI;
|
||||
|
||||
/**
|
||||
* Lists the URLs for workers and embedded frame contents
|
||||
*
|
||||
* @var list<string>|string
|
||||
*/
|
||||
public $childSrc = 'self';
|
||||
|
||||
/**
|
||||
* Limits the origins that you can connect to (via XHR,
|
||||
* WebSockets, and EventSource).
|
||||
*
|
||||
* @var list<string>|string
|
||||
*/
|
||||
public $connectSrc = 'self';
|
||||
|
||||
/**
|
||||
* Specifies the origins that can serve web fonts.
|
||||
*
|
||||
* @var list<string>|string
|
||||
*/
|
||||
public $fontSrc;
|
||||
|
||||
/**
|
||||
* Lists valid endpoints for submission from `<form>` tags.
|
||||
*
|
||||
* @var list<string>|string
|
||||
*/
|
||||
public $formAction = 'self';
|
||||
|
||||
/**
|
||||
* Specifies the sources that can embed the current page.
|
||||
* This directive applies to `<frame>`, `<iframe>`, `<embed>`,
|
||||
* and `<applet>` tags. This directive can't be used in
|
||||
* `<meta>` tags and applies only to non-HTML resources.
|
||||
*
|
||||
* @var list<string>|string|null
|
||||
*/
|
||||
public $frameAncestors;
|
||||
|
||||
/**
|
||||
* The frame-src directive restricts the URLs which may
|
||||
* be loaded into nested browsing contexts.
|
||||
*
|
||||
* @var list<string>|string|null
|
||||
*/
|
||||
public $frameSrc;
|
||||
|
||||
/**
|
||||
* Restricts the origins allowed to deliver video and audio.
|
||||
*
|
||||
* @var list<string>|string|null
|
||||
*/
|
||||
public $mediaSrc;
|
||||
|
||||
/**
|
||||
* Allows control over Flash and other plugins.
|
||||
*
|
||||
* @var list<string>|string
|
||||
*/
|
||||
public $objectSrc = 'self';
|
||||
|
||||
/**
|
||||
* @var list<string>|string|null
|
||||
*/
|
||||
public $manifestSrc;
|
||||
|
||||
/**
|
||||
* Limits the kinds of plugins a page may invoke.
|
||||
*
|
||||
* @var list<string>|string|null
|
||||
*/
|
||||
public $pluginTypes;
|
||||
|
||||
/**
|
||||
* List of actions allowed.
|
||||
*
|
||||
* @var list<string>|string|null
|
||||
*/
|
||||
public $sandbox;
|
||||
|
||||
/**
|
||||
* Nonce tag for style
|
||||
*/
|
||||
public string $styleNonceTag = '{csp-style-nonce}';
|
||||
|
||||
/**
|
||||
* Nonce tag for script
|
||||
*/
|
||||
public string $scriptNonceTag = '{csp-script-nonce}';
|
||||
|
||||
/**
|
||||
* Replace nonce tag automatically
|
||||
*/
|
||||
public bool $autoNonce = true;
|
||||
}
|
||||
|
||||
214
app/Config/Cookie.php
Executable file → Normal file
214
app/Config/Cookie.php
Executable file → Normal file
@ -1,107 +1,107 @@
|
||||
<?php
|
||||
|
||||
namespace Config;
|
||||
|
||||
use CodeIgniter\Config\BaseConfig;
|
||||
use DateTimeInterface;
|
||||
|
||||
class Cookie extends BaseConfig
|
||||
{
|
||||
/**
|
||||
* --------------------------------------------------------------------------
|
||||
* Cookie Prefix
|
||||
* --------------------------------------------------------------------------
|
||||
*
|
||||
* Set a cookie name prefix if you need to avoid collisions.
|
||||
*/
|
||||
public string $prefix = '';
|
||||
|
||||
/**
|
||||
* --------------------------------------------------------------------------
|
||||
* Cookie Expires Timestamp
|
||||
* --------------------------------------------------------------------------
|
||||
*
|
||||
* Default expires timestamp for cookies. Setting this to `0` will mean the
|
||||
* cookie will not have the `Expires` attribute and will behave as a session
|
||||
* cookie.
|
||||
*
|
||||
* @var DateTimeInterface|int|string
|
||||
*/
|
||||
public $expires = 0;
|
||||
|
||||
/**
|
||||
* --------------------------------------------------------------------------
|
||||
* Cookie Path
|
||||
* --------------------------------------------------------------------------
|
||||
*
|
||||
* Typically will be a forward slash.
|
||||
*/
|
||||
public string $path = '/';
|
||||
|
||||
/**
|
||||
* --------------------------------------------------------------------------
|
||||
* Cookie Domain
|
||||
* --------------------------------------------------------------------------
|
||||
*
|
||||
* Set to `.your-domain.com` for site-wide cookies.
|
||||
*/
|
||||
public string $domain = '';
|
||||
|
||||
/**
|
||||
* --------------------------------------------------------------------------
|
||||
* Cookie Secure
|
||||
* --------------------------------------------------------------------------
|
||||
*
|
||||
* Cookie will only be set if a secure HTTPS connection exists.
|
||||
*/
|
||||
public bool $secure = false;
|
||||
|
||||
/**
|
||||
* --------------------------------------------------------------------------
|
||||
* Cookie HTTPOnly
|
||||
* --------------------------------------------------------------------------
|
||||
*
|
||||
* Cookie will only be accessible via HTTP(S) (no JavaScript).
|
||||
*/
|
||||
public bool $httponly = true;
|
||||
|
||||
/**
|
||||
* --------------------------------------------------------------------------
|
||||
* Cookie SameSite
|
||||
* --------------------------------------------------------------------------
|
||||
*
|
||||
* Configure cookie SameSite setting. Allowed values are:
|
||||
* - None
|
||||
* - Lax
|
||||
* - Strict
|
||||
* - ''
|
||||
*
|
||||
* Alternatively, you can use the constant names:
|
||||
* - `Cookie::SAMESITE_NONE`
|
||||
* - `Cookie::SAMESITE_LAX`
|
||||
* - `Cookie::SAMESITE_STRICT`
|
||||
*
|
||||
* Defaults to `Lax` for compatibility with modern browsers. Setting `''`
|
||||
* (empty string) means default SameSite attribute set by browsers (`Lax`)
|
||||
* will be set on cookies. If set to `None`, `$secure` must also be set.
|
||||
*
|
||||
* @phpstan-var 'None'|'Lax'|'Strict'|''
|
||||
*/
|
||||
public string $samesite = 'Lax';
|
||||
|
||||
/**
|
||||
* --------------------------------------------------------------------------
|
||||
* Cookie Raw
|
||||
* --------------------------------------------------------------------------
|
||||
*
|
||||
* This flag allows setting a "raw" cookie, i.e., its name and value are
|
||||
* not URL encoded using `rawurlencode()`.
|
||||
*
|
||||
* If this is set to `true`, cookie names should be compliant of RFC 2616's
|
||||
* list of allowed characters.
|
||||
*
|
||||
* @see https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Set-Cookie#attributes
|
||||
* @see https://tools.ietf.org/html/rfc2616#section-2.2
|
||||
*/
|
||||
public bool $raw = false;
|
||||
}
|
||||
<?php
|
||||
|
||||
namespace Config;
|
||||
|
||||
use CodeIgniter\Config\BaseConfig;
|
||||
use DateTimeInterface;
|
||||
|
||||
class Cookie extends BaseConfig
|
||||
{
|
||||
/**
|
||||
* --------------------------------------------------------------------------
|
||||
* Cookie Prefix
|
||||
* --------------------------------------------------------------------------
|
||||
*
|
||||
* Set a cookie name prefix if you need to avoid collisions.
|
||||
*/
|
||||
public string $prefix = '';
|
||||
|
||||
/**
|
||||
* --------------------------------------------------------------------------
|
||||
* Cookie Expires Timestamp
|
||||
* --------------------------------------------------------------------------
|
||||
*
|
||||
* Default expires timestamp for cookies. Setting this to `0` will mean the
|
||||
* cookie will not have the `Expires` attribute and will behave as a session
|
||||
* cookie.
|
||||
*
|
||||
* @var DateTimeInterface|int|string
|
||||
*/
|
||||
public $expires = 0;
|
||||
|
||||
/**
|
||||
* --------------------------------------------------------------------------
|
||||
* Cookie Path
|
||||
* --------------------------------------------------------------------------
|
||||
*
|
||||
* Typically will be a forward slash.
|
||||
*/
|
||||
public string $path = '/';
|
||||
|
||||
/**
|
||||
* --------------------------------------------------------------------------
|
||||
* Cookie Domain
|
||||
* --------------------------------------------------------------------------
|
||||
*
|
||||
* Set to `.your-domain.com` for site-wide cookies.
|
||||
*/
|
||||
public string $domain = '';
|
||||
|
||||
/**
|
||||
* --------------------------------------------------------------------------
|
||||
* Cookie Secure
|
||||
* --------------------------------------------------------------------------
|
||||
*
|
||||
* Cookie will only be set if a secure HTTPS connection exists.
|
||||
*/
|
||||
public bool $secure = false;
|
||||
|
||||
/**
|
||||
* --------------------------------------------------------------------------
|
||||
* Cookie HTTPOnly
|
||||
* --------------------------------------------------------------------------
|
||||
*
|
||||
* Cookie will only be accessible via HTTP(S) (no JavaScript).
|
||||
*/
|
||||
public bool $httponly = true;
|
||||
|
||||
/**
|
||||
* --------------------------------------------------------------------------
|
||||
* Cookie SameSite
|
||||
* --------------------------------------------------------------------------
|
||||
*
|
||||
* Configure cookie SameSite setting. Allowed values are:
|
||||
* - None
|
||||
* - Lax
|
||||
* - Strict
|
||||
* - ''
|
||||
*
|
||||
* Alternatively, you can use the constant names:
|
||||
* - `Cookie::SAMESITE_NONE`
|
||||
* - `Cookie::SAMESITE_LAX`
|
||||
* - `Cookie::SAMESITE_STRICT`
|
||||
*
|
||||
* Defaults to `Lax` for compatibility with modern browsers. Setting `''`
|
||||
* (empty string) means default SameSite attribute set by browsers (`Lax`)
|
||||
* will be set on cookies. If set to `None`, `$secure` must also be set.
|
||||
*
|
||||
* @phpstan-var 'None'|'Lax'|'Strict'|''
|
||||
*/
|
||||
public string $samesite = 'Lax';
|
||||
|
||||
/**
|
||||
* --------------------------------------------------------------------------
|
||||
* Cookie Raw
|
||||
* --------------------------------------------------------------------------
|
||||
*
|
||||
* This flag allows setting a "raw" cookie, i.e., its name and value are
|
||||
* not URL encoded using `rawurlencode()`.
|
||||
*
|
||||
* If this is set to `true`, cookie names should be compliant of RFC 2616's
|
||||
* list of allowed characters.
|
||||
*
|
||||
* @see https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Set-Cookie#attributes
|
||||
* @see https://tools.ietf.org/html/rfc2616#section-2.2
|
||||
*/
|
||||
public bool $raw = false;
|
||||
}
|
||||
|
||||
210
app/Config/Cors.php
Executable file → Normal file
210
app/Config/Cors.php
Executable file → Normal file
@ -1,105 +1,105 @@
|
||||
<?php
|
||||
|
||||
namespace Config;
|
||||
|
||||
use CodeIgniter\Config\BaseConfig;
|
||||
|
||||
/**
|
||||
* Cross-Origin Resource Sharing (CORS) Configuration
|
||||
*
|
||||
* @see https://developer.mozilla.org/en-US/docs/Web/HTTP/CORS
|
||||
*/
|
||||
class Cors extends BaseConfig
|
||||
{
|
||||
/**
|
||||
* The default CORS configuration.
|
||||
*
|
||||
* @var array{
|
||||
* allowedOrigins: list<string>,
|
||||
* allowedOriginsPatterns: list<string>,
|
||||
* supportsCredentials: bool,
|
||||
* allowedHeaders: list<string>,
|
||||
* exposedHeaders: list<string>,
|
||||
* allowedMethods: list<string>,
|
||||
* maxAge: int,
|
||||
* }
|
||||
*/
|
||||
public array $default = [
|
||||
/**
|
||||
* Origins for the `Access-Control-Allow-Origin` header.
|
||||
*
|
||||
* @see https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Access-Control-Allow-Origin
|
||||
*
|
||||
* E.g.:
|
||||
* - ['http://localhost:8080']
|
||||
* - ['https://www.example.com']
|
||||
*/
|
||||
'allowedOrigins' => ['http://localhost:5173', 'https://clqms01.services-summit.my.id'],
|
||||
|
||||
/**
|
||||
* Origin regex patterns for the `Access-Control-Allow-Origin` header.
|
||||
*
|
||||
* @see https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Access-Control-Allow-Origin
|
||||
*
|
||||
* NOTE: A pattern specified here is part of a regular expression. It will
|
||||
* be actually `#\A<pattern>\z#`.
|
||||
*
|
||||
* E.g.:
|
||||
* - ['https://\w+\.example\.com']
|
||||
*/
|
||||
'allowedOriginsPatterns' => [],
|
||||
|
||||
/**
|
||||
* Weather to send the `Access-Control-Allow-Credentials` header.
|
||||
*
|
||||
* The Access-Control-Allow-Credentials response header tells browsers whether
|
||||
* the server allows cross-origin HTTP requests to include credentials.
|
||||
*
|
||||
* @see https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Access-Control-Allow-Credentials
|
||||
*/
|
||||
'supportsCredentials' => true,
|
||||
|
||||
/**
|
||||
* Set headers to allow.
|
||||
*
|
||||
* The Access-Control-Allow-Headers response header is used in response to
|
||||
* a preflight request which includes the Access-Control-Request-Headers to
|
||||
* indicate which HTTP headers can be used during the actual request.
|
||||
*
|
||||
* @see https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Access-Control-Allow-Headers
|
||||
*/
|
||||
'allowedHeaders' => ['Content-Type', 'Authorization', 'X-Requested-With'],
|
||||
|
||||
/**
|
||||
* Set headers to expose.
|
||||
*
|
||||
* The Access-Control-Expose-Headers response header allows a server to
|
||||
* indicate which response headers should be made available to scripts running
|
||||
* in the browser, in response to a cross-origin request.
|
||||
*
|
||||
* @see https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Access-Control-Expose-Headers
|
||||
*/
|
||||
'exposedHeaders' => [],
|
||||
|
||||
/**
|
||||
* Set methods to allow.
|
||||
*
|
||||
* The Access-Control-Allow-Methods response header specifies one or more
|
||||
* methods allowed when accessing a resource in response to a preflight
|
||||
* request.
|
||||
*
|
||||
* E.g.:
|
||||
* - ['GET', 'POST', 'PUT', 'DELETE']
|
||||
*
|
||||
* @see https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Access-Control-Allow-Methods
|
||||
*/
|
||||
'allowedMethods' => ['GET', 'POST', 'PUT', 'DELETE', 'OPTIONS'],
|
||||
|
||||
/**
|
||||
* Set how many seconds the results of a preflight request can be cached.
|
||||
*
|
||||
* @see https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Access-Control-Max-Age
|
||||
*/
|
||||
'maxAge' => 7200,
|
||||
];
|
||||
}
|
||||
<?php
|
||||
|
||||
namespace Config;
|
||||
|
||||
use CodeIgniter\Config\BaseConfig;
|
||||
|
||||
/**
|
||||
* Cross-Origin Resource Sharing (CORS) Configuration
|
||||
*
|
||||
* @see https://developer.mozilla.org/en-US/docs/Web/HTTP/CORS
|
||||
*/
|
||||
class Cors extends BaseConfig
|
||||
{
|
||||
/**
|
||||
* The default CORS configuration.
|
||||
*
|
||||
* @var array{
|
||||
* allowedOrigins: list<string>,
|
||||
* allowedOriginsPatterns: list<string>,
|
||||
* supportsCredentials: bool,
|
||||
* allowedHeaders: list<string>,
|
||||
* exposedHeaders: list<string>,
|
||||
* allowedMethods: list<string>,
|
||||
* maxAge: int,
|
||||
* }
|
||||
*/
|
||||
public array $default = [
|
||||
/**
|
||||
* Origins for the `Access-Control-Allow-Origin` header.
|
||||
*
|
||||
* @see https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Access-Control-Allow-Origin
|
||||
*
|
||||
* E.g.:
|
||||
* - ['http://localhost:8080']
|
||||
* - ['https://www.example.com']
|
||||
*/
|
||||
'allowedOrigins' => ['http://localhost:5173', 'https://clqms01.services-summit.my.id'],
|
||||
|
||||
/**
|
||||
* Origin regex patterns for the `Access-Control-Allow-Origin` header.
|
||||
*
|
||||
* @see https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Access-Control-Allow-Origin
|
||||
*
|
||||
* NOTE: A pattern specified here is part of a regular expression. It will
|
||||
* be actually `#\A<pattern>\z#`.
|
||||
*
|
||||
* E.g.:
|
||||
* - ['https://\w+\.example\.com']
|
||||
*/
|
||||
'allowedOriginsPatterns' => [],
|
||||
|
||||
/**
|
||||
* Weather to send the `Access-Control-Allow-Credentials` header.
|
||||
*
|
||||
* The Access-Control-Allow-Credentials response header tells browsers whether
|
||||
* the server allows cross-origin HTTP requests to include credentials.
|
||||
*
|
||||
* @see https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Access-Control-Allow-Credentials
|
||||
*/
|
||||
'supportsCredentials' => true,
|
||||
|
||||
/**
|
||||
* Set headers to allow.
|
||||
*
|
||||
* The Access-Control-Allow-Headers response header is used in response to
|
||||
* a preflight request which includes the Access-Control-Request-Headers to
|
||||
* indicate which HTTP headers can be used during the actual request.
|
||||
*
|
||||
* @see https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Access-Control-Allow-Headers
|
||||
*/
|
||||
'allowedHeaders' => ['Content-Type', 'Authorization', 'X-Requested-With'],
|
||||
|
||||
/**
|
||||
* Set headers to expose.
|
||||
*
|
||||
* The Access-Control-Expose-Headers response header allows a server to
|
||||
* indicate which response headers should be made available to scripts running
|
||||
* in the browser, in response to a cross-origin request.
|
||||
*
|
||||
* @see https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Access-Control-Expose-Headers
|
||||
*/
|
||||
'exposedHeaders' => [],
|
||||
|
||||
/**
|
||||
* Set methods to allow.
|
||||
*
|
||||
* The Access-Control-Allow-Methods response header specifies one or more
|
||||
* methods allowed when accessing a resource in response to a preflight
|
||||
* request.
|
||||
*
|
||||
* E.g.:
|
||||
* - ['GET', 'POST', 'PUT', 'DELETE']
|
||||
*
|
||||
* @see https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Access-Control-Allow-Methods
|
||||
*/
|
||||
'allowedMethods' => ['GET', 'POST', 'PUT', 'DELETE', 'OPTIONS'],
|
||||
|
||||
/**
|
||||
* Set how many seconds the results of a preflight request can be cached.
|
||||
*
|
||||
* @see https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Access-Control-Max-Age
|
||||
*/
|
||||
'maxAge' => 7200,
|
||||
];
|
||||
}
|
||||
|
||||
407
app/Config/Database.php
Executable file → Normal file
407
app/Config/Database.php
Executable file → Normal file
@ -1,212 +1,209 @@
|
||||
<?php
|
||||
|
||||
namespace Config;
|
||||
|
||||
use CodeIgniter\Database\Config;
|
||||
|
||||
/**
|
||||
* Database Configuration
|
||||
*/
|
||||
class Database extends Config
|
||||
{
|
||||
/**
|
||||
* The directory that holds the Migrations and Seeds directories.
|
||||
*/
|
||||
public string $filesPath = APPPATH . 'Database' . DIRECTORY_SEPARATOR;
|
||||
|
||||
/**
|
||||
* Lets you choose which connection group to use if no other is specified.
|
||||
*/
|
||||
public string $defaultGroup = 'default';
|
||||
|
||||
/**
|
||||
* The default database connection.
|
||||
*
|
||||
* @var array<string, mixed>
|
||||
*/
|
||||
public array $default = [
|
||||
'DSN' => '',
|
||||
'hostname' => 'localhost',
|
||||
'username' => 'root',
|
||||
'password' => 'adminsakti',
|
||||
'database' => 'clqms01',
|
||||
'DBDriver' => 'MySQLi',
|
||||
'DBPrefix' => '',
|
||||
'pConnect' => false,
|
||||
'DBDebug' => true,
|
||||
'charset' => 'utf8mb4',
|
||||
'DBCollat' => 'utf8mb4_general_ci',
|
||||
'swapPre' => '',
|
||||
'encrypt' => false,
|
||||
'compress' => false,
|
||||
'strictOn' => false,
|
||||
'failover' => [],
|
||||
'port' => 3306,
|
||||
'numberNative' => false,
|
||||
'foundRows' => false,
|
||||
'dateFormat' => [
|
||||
'date' => 'Y-m-d',
|
||||
'datetime' => 'Y-m-d H:i:s',
|
||||
'time' => 'H:i:s',
|
||||
],
|
||||
];
|
||||
|
||||
// /**
|
||||
// * Sample database connection for SQLite3.
|
||||
// *
|
||||
// * @var array<string, mixed>
|
||||
// */
|
||||
// public array $default = [
|
||||
// 'database' => 'database.db',
|
||||
// 'DBDriver' => 'SQLite3',
|
||||
// 'DBPrefix' => '',
|
||||
// 'DBDebug' => true,
|
||||
// 'swapPre' => '',
|
||||
// 'failover' => [],
|
||||
// 'foreignKeys' => true,
|
||||
// 'busyTimeout' => 1000,
|
||||
// 'synchronous' => null,
|
||||
// 'dateFormat' => [
|
||||
// 'date' => 'Y-m-d',
|
||||
// 'datetime' => 'Y-m-d H:i:s',
|
||||
// 'time' => 'H:i:s',
|
||||
// ],
|
||||
// ];
|
||||
|
||||
// /**
|
||||
// * Sample database connection for Postgre.
|
||||
// *
|
||||
// * @var array<string, mixed>
|
||||
// */
|
||||
// public array $default = [
|
||||
// 'DSN' => '',
|
||||
// 'hostname' => 'localhost',
|
||||
// 'username' => 'root',
|
||||
// 'password' => 'root',
|
||||
// 'database' => 'ci4',
|
||||
// 'schema' => 'public',
|
||||
// 'DBDriver' => 'Postgre',
|
||||
// 'DBPrefix' => '',
|
||||
// 'pConnect' => false,
|
||||
// 'DBDebug' => true,
|
||||
// 'charset' => 'utf8',
|
||||
// 'swapPre' => '',
|
||||
// 'failover' => [],
|
||||
// 'port' => 5432,
|
||||
// 'dateFormat' => [
|
||||
// 'date' => 'Y-m-d',
|
||||
// 'datetime' => 'Y-m-d H:i:s',
|
||||
// 'time' => 'H:i:s',
|
||||
// ],
|
||||
// ];
|
||||
|
||||
// /**
|
||||
// * Sample database connection for SQLSRV.
|
||||
// *
|
||||
// * @var array<string, mixed>
|
||||
// */
|
||||
// public array $default = [
|
||||
// 'DSN' => '',
|
||||
// 'hostname' => 'localhost',
|
||||
// 'username' => 'root',
|
||||
// 'password' => 'root',
|
||||
// 'database' => 'ci4',
|
||||
// 'schema' => 'dbo',
|
||||
// 'DBDriver' => 'SQLSRV',
|
||||
// 'DBPrefix' => '',
|
||||
// 'pConnect' => false,
|
||||
// 'DBDebug' => true,
|
||||
// 'charset' => 'utf8',
|
||||
// 'swapPre' => '',
|
||||
// 'encrypt' => false,
|
||||
// 'failover' => [],
|
||||
// 'port' => 1433,
|
||||
// 'dateFormat' => [
|
||||
// 'date' => 'Y-m-d',
|
||||
// 'datetime' => 'Y-m-d H:i:s',
|
||||
// 'time' => 'H:i:s',
|
||||
// ],
|
||||
// ];
|
||||
|
||||
// /**
|
||||
// * Sample database connection for OCI8.
|
||||
// *
|
||||
// * You may need the following environment variables:
|
||||
// * NLS_LANG = 'AMERICAN_AMERICA.UTF8'
|
||||
// * NLS_DATE_FORMAT = 'YYYY-MM-DD HH24:MI:SS'
|
||||
// * NLS_TIMESTAMP_FORMAT = 'YYYY-MM-DD HH24:MI:SS'
|
||||
// * NLS_TIMESTAMP_TZ_FORMAT = 'YYYY-MM-DD HH24:MI:SS'
|
||||
// *
|
||||
// * @var array<string, mixed>
|
||||
// */
|
||||
// public array $default = [
|
||||
// 'DSN' => 'localhost:1521/XEPDB1',
|
||||
// 'username' => 'root',
|
||||
// 'password' => 'root',
|
||||
// 'DBDriver' => 'OCI8',
|
||||
// 'DBPrefix' => '',
|
||||
// 'pConnect' => false,
|
||||
// 'DBDebug' => true,
|
||||
// 'charset' => 'AL32UTF8',
|
||||
// 'swapPre' => '',
|
||||
// 'failover' => [],
|
||||
// 'dateFormat' => [
|
||||
// 'date' => 'Y-m-d',
|
||||
// 'datetime' => 'Y-m-d H:i:s',
|
||||
// 'time' => 'H:i:s',
|
||||
// ],
|
||||
// ];
|
||||
|
||||
/**
|
||||
* This database connection is used when running PHPUnit database tests.
|
||||
*
|
||||
* These values can be overridden in phpunit.xml.dist or .env file using:
|
||||
* - database.tests.hostname
|
||||
* - database.tests.database
|
||||
* - database.tests.username
|
||||
* - database.tests.password
|
||||
* - database.tests.DBDriver
|
||||
*
|
||||
* @var array<string, mixed>
|
||||
*/
|
||||
public array $tests = [
|
||||
'DSN' => '',
|
||||
'hostname' => 'localhost',
|
||||
'username' => 'root',
|
||||
'password' => 'adminsakti',
|
||||
'database' => 'clqms01_test',
|
||||
'DBDriver' => 'MySQLi',
|
||||
'DBPrefix' => '', // Needed to ensure we're working correctly with prefixes live. DO NOT REMOVE FOR CI DEVS
|
||||
'pConnect' => false,
|
||||
'DBDebug' => true,
|
||||
'charset' => 'utf8mb4',
|
||||
'DBCollat' => 'utf8mb4_general_ci',
|
||||
'swapPre' => '',
|
||||
'encrypt' => false,
|
||||
'compress' => false,
|
||||
'strictOn' => false,
|
||||
'failover' => [],
|
||||
'port' => 3306,
|
||||
'foreignKeys' => true,
|
||||
'busyTimeout' => 1000,
|
||||
'dateFormat' => [
|
||||
'date' => 'Y-m-d',
|
||||
'datetime' => 'Y-m-d H:i:s',
|
||||
'time' => 'H:i:s',
|
||||
],
|
||||
];
|
||||
|
||||
<?php
|
||||
|
||||
namespace Config;
|
||||
|
||||
use CodeIgniter\Database\Config;
|
||||
|
||||
/**
|
||||
* Database Configuration
|
||||
*/
|
||||
class Database extends Config
|
||||
{
|
||||
/**
|
||||
* The directory that holds the Migrations and Seeds directories.
|
||||
*/
|
||||
public string $filesPath = APPPATH . 'Database' . DIRECTORY_SEPARATOR;
|
||||
|
||||
/**
|
||||
* Lets you choose which connection group to use if no other is specified.
|
||||
*/
|
||||
public string $defaultGroup = 'default';
|
||||
|
||||
/**
|
||||
* The default database connection.
|
||||
*
|
||||
* @var array<string, mixed>
|
||||
*/
|
||||
public array $default = [
|
||||
'DSN' => '',
|
||||
'hostname' => 'localhost',
|
||||
'username' => 'root',
|
||||
'password' => 'adminsakti',
|
||||
'database' => 'clqms01',
|
||||
'DBDriver' => 'MySQLi',
|
||||
'DBPrefix' => '',
|
||||
'pConnect' => false,
|
||||
'DBDebug' => true,
|
||||
'charset' => 'utf8mb4',
|
||||
'DBCollat' => 'utf8mb4_general_ci',
|
||||
'swapPre' => '',
|
||||
'encrypt' => false,
|
||||
'compress' => false,
|
||||
'strictOn' => false,
|
||||
'failover' => [],
|
||||
'port' => 3306,
|
||||
'numberNative' => false,
|
||||
'foundRows' => false,
|
||||
'dateFormat' => [
|
||||
'date' => 'Y-m-d',
|
||||
'datetime' => 'Y-m-d H:i:s',
|
||||
'time' => 'H:i:s',
|
||||
],
|
||||
];
|
||||
|
||||
// /**
|
||||
// * Sample database connection for SQLite3.
|
||||
// *
|
||||
// * @var array<string, mixed>
|
||||
// */
|
||||
// public array $default = [
|
||||
// 'database' => 'database.db',
|
||||
// 'DBDriver' => 'SQLite3',
|
||||
// 'DBPrefix' => '',
|
||||
// 'DBDebug' => true,
|
||||
// 'swapPre' => '',
|
||||
// 'failover' => [],
|
||||
// 'foreignKeys' => true,
|
||||
// 'busyTimeout' => 1000,
|
||||
// 'synchronous' => null,
|
||||
// 'dateFormat' => [
|
||||
// 'date' => 'Y-m-d',
|
||||
// 'datetime' => 'Y-m-d H:i:s',
|
||||
// 'time' => 'H:i:s',
|
||||
// ],
|
||||
// ];
|
||||
|
||||
// /**
|
||||
// * Sample database connection for Postgre.
|
||||
// *
|
||||
// * @var array<string, mixed>
|
||||
// */
|
||||
// public array $default = [
|
||||
// 'DSN' => '',
|
||||
// 'hostname' => 'localhost',
|
||||
// 'username' => 'root',
|
||||
// 'password' => 'root',
|
||||
// 'database' => 'ci4',
|
||||
// 'schema' => 'public',
|
||||
// 'DBDriver' => 'Postgre',
|
||||
// 'DBPrefix' => '',
|
||||
// 'pConnect' => false,
|
||||
// 'DBDebug' => true,
|
||||
// 'charset' => 'utf8',
|
||||
// 'swapPre' => '',
|
||||
// 'failover' => [],
|
||||
// 'port' => 5432,
|
||||
// 'dateFormat' => [
|
||||
// 'date' => 'Y-m-d',
|
||||
// 'datetime' => 'Y-m-d H:i:s',
|
||||
// 'time' => 'H:i:s',
|
||||
// ],
|
||||
// ];
|
||||
|
||||
// /**
|
||||
// * Sample database connection for SQLSRV.
|
||||
// *
|
||||
// * @var array<string, mixed>
|
||||
// */
|
||||
// public array $default = [
|
||||
// 'DSN' => '',
|
||||
// 'hostname' => 'localhost',
|
||||
// 'username' => 'root',
|
||||
// 'password' => 'root',
|
||||
// 'database' => 'ci4',
|
||||
// 'schema' => 'dbo',
|
||||
// 'DBDriver' => 'SQLSRV',
|
||||
// 'DBPrefix' => '',
|
||||
// 'pConnect' => false,
|
||||
// 'DBDebug' => true,
|
||||
// 'charset' => 'utf8',
|
||||
// 'swapPre' => '',
|
||||
// 'encrypt' => false,
|
||||
// 'failover' => [],
|
||||
// 'port' => 1433,
|
||||
// 'dateFormat' => [
|
||||
// 'date' => 'Y-m-d',
|
||||
// 'datetime' => 'Y-m-d H:i:s',
|
||||
// 'time' => 'H:i:s',
|
||||
// ],
|
||||
// ];
|
||||
|
||||
// /**
|
||||
// * Sample database connection for OCI8.
|
||||
// *
|
||||
// * You may need the following environment variables:
|
||||
// * NLS_LANG = 'AMERICAN_AMERICA.UTF8'
|
||||
// * NLS_DATE_FORMAT = 'YYYY-MM-DD HH24:MI:SS'
|
||||
// * NLS_TIMESTAMP_FORMAT = 'YYYY-MM-DD HH24:MI:SS'
|
||||
// * NLS_TIMESTAMP_TZ_FORMAT = 'YYYY-MM-DD HH24:MI:SS'
|
||||
// *
|
||||
// * @var array<string, mixed>
|
||||
// */
|
||||
// public array $default = [
|
||||
// 'DSN' => 'localhost:1521/XEPDB1',
|
||||
// 'username' => 'root',
|
||||
// 'password' => 'root',
|
||||
// 'DBDriver' => 'OCI8',
|
||||
// 'DBPrefix' => '',
|
||||
// 'pConnect' => false,
|
||||
// 'DBDebug' => true,
|
||||
// 'charset' => 'AL32UTF8',
|
||||
// 'swapPre' => '',
|
||||
// 'failover' => [],
|
||||
// 'dateFormat' => [
|
||||
// 'date' => 'Y-m-d',
|
||||
// 'datetime' => 'Y-m-d H:i:s',
|
||||
// 'time' => 'H:i:s',
|
||||
// ],
|
||||
// ];
|
||||
|
||||
/**
|
||||
* This database connection is used when running PHPUnit database tests.
|
||||
*
|
||||
* These values can be overridden in phpunit.xml.dist or .env file using:
|
||||
* - database.tests.hostname
|
||||
* - database.tests.database
|
||||
* - database.tests.username
|
||||
* - database.tests.password
|
||||
* - database.tests.DBDriver
|
||||
*
|
||||
* @var array<string, mixed>
|
||||
*/
|
||||
public array $tests = [
|
||||
'DSN' => '',
|
||||
'hostname' => 'localhost',
|
||||
'username' => 'root',
|
||||
'password' => 'adminsakti',
|
||||
'database' => 'clqms01',
|
||||
'DBDriver' => 'MySQLi',
|
||||
'DBPrefix' => '', // Needed to ensure we're working correctly with prefixes live. DO NOT REMOVE FOR CI DEVS
|
||||
'pConnect' => false,
|
||||
'DBDebug' => true,
|
||||
'charset' => 'utf8mb4',
|
||||
'DBCollat' => 'utf8mb4_general_ci',
|
||||
'swapPre' => '',
|
||||
'encrypt' => false,
|
||||
'compress' => false,
|
||||
'strictOn' => false,
|
||||
'failover' => [],
|
||||
'port' => 3306,
|
||||
'foreignKeys' => true,
|
||||
'busyTimeout' => 1000,
|
||||
'dateFormat' => [
|
||||
'date' => 'Y-m-d',
|
||||
'datetime' => 'Y-m-d H:i:s',
|
||||
'time' => 'H:i:s',
|
||||
],
|
||||
];
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
|
||||
// Ensure that we always set the database group to 'tests' if
|
||||
// we are currently running an automated test suite, so that
|
||||
// we don't overwrite live data on accident.
|
||||
|
||||
// Ensure that we always set the database group to 'tests' if
|
||||
// we are currently running an automated test suite, so that
|
||||
// we don't overwrite live data on accident.
|
||||
if (ENVIRONMENT === 'testing') {
|
||||
if ($this->tests['database'] === $this->default['database']) {
|
||||
throw new \RuntimeException('Tests database cannot match the default database.');
|
||||
}
|
||||
$this->defaultGroup = 'tests';
|
||||
}
|
||||
}
|
||||
|
||||
86
app/Config/DocTypes.php
Executable file → Normal file
86
app/Config/DocTypes.php
Executable file → Normal file
@ -1,43 +1,43 @@
|
||||
<?php
|
||||
|
||||
namespace Config;
|
||||
|
||||
class DocTypes
|
||||
{
|
||||
/**
|
||||
* List of valid document types.
|
||||
*
|
||||
* @var array<string, string>
|
||||
*/
|
||||
public array $list = [
|
||||
'xhtml11' => '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">',
|
||||
'xhtml1-strict' => '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">',
|
||||
'xhtml1-trans' => '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">',
|
||||
'xhtml1-frame' => '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Frameset//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-frameset.dtd">',
|
||||
'xhtml-basic11' => '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML Basic 1.1//EN" "http://www.w3.org/TR/xhtml-basic/xhtml-basic11.dtd">',
|
||||
'html5' => '<!DOCTYPE html>',
|
||||
'html4-strict' => '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">',
|
||||
'html4-trans' => '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">',
|
||||
'html4-frame' => '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Frameset//EN" "http://www.w3.org/TR/html4/frameset.dtd">',
|
||||
'mathml1' => '<!DOCTYPE math SYSTEM "http://www.w3.org/Math/DTD/mathml1/mathml.dtd">',
|
||||
'mathml2' => '<!DOCTYPE math PUBLIC "-//W3C//DTD MathML 2.0//EN" "http://www.w3.org/Math/DTD/mathml2/mathml2.dtd">',
|
||||
'svg10' => '<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.0//EN" "http://www.w3.org/TR/2001/REC-SVG-20010904/DTD/svg10.dtd">',
|
||||
'svg11' => '<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">',
|
||||
'svg11-basic' => '<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1 Basic//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11-basic.dtd">',
|
||||
'svg11-tiny' => '<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1 Tiny//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11-tiny.dtd">',
|
||||
'xhtml-math-svg-xh' => '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1 plus MathML 2.0 plus SVG 1.1//EN" "http://www.w3.org/2002/04/xhtml-math-svg/xhtml-math-svg.dtd">',
|
||||
'xhtml-math-svg-sh' => '<!DOCTYPE svg:svg PUBLIC "-//W3C//DTD XHTML 1.1 plus MathML 2.0 plus SVG 1.1//EN" "http://www.w3.org/2002/04/xhtml-math-svg/xhtml-math-svg.dtd">',
|
||||
'xhtml-rdfa-1' => '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML+RDFa 1.0//EN" "http://www.w3.org/MarkUp/DTD/xhtml-rdfa-1.dtd">',
|
||||
'xhtml-rdfa-2' => '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML+RDFa 1.1//EN" "http://www.w3.org/MarkUp/DTD/xhtml-rdfa-2.dtd">',
|
||||
];
|
||||
|
||||
/**
|
||||
* Whether to remove the solidus (`/`) character for void HTML elements (e.g. `<input>`)
|
||||
* for HTML5 compatibility.
|
||||
*
|
||||
* Set to:
|
||||
* `true` - to be HTML5 compatible
|
||||
* `false` - to be XHTML compatible
|
||||
*/
|
||||
public bool $html5 = true;
|
||||
}
|
||||
<?php
|
||||
|
||||
namespace Config;
|
||||
|
||||
class DocTypes
|
||||
{
|
||||
/**
|
||||
* List of valid document types.
|
||||
*
|
||||
* @var array<string, string>
|
||||
*/
|
||||
public array $list = [
|
||||
'xhtml11' => '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">',
|
||||
'xhtml1-strict' => '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">',
|
||||
'xhtml1-trans' => '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">',
|
||||
'xhtml1-frame' => '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Frameset//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-frameset.dtd">',
|
||||
'xhtml-basic11' => '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML Basic 1.1//EN" "http://www.w3.org/TR/xhtml-basic/xhtml-basic11.dtd">',
|
||||
'html5' => '<!DOCTYPE html>',
|
||||
'html4-strict' => '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">',
|
||||
'html4-trans' => '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">',
|
||||
'html4-frame' => '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Frameset//EN" "http://www.w3.org/TR/html4/frameset.dtd">',
|
||||
'mathml1' => '<!DOCTYPE math SYSTEM "http://www.w3.org/Math/DTD/mathml1/mathml.dtd">',
|
||||
'mathml2' => '<!DOCTYPE math PUBLIC "-//W3C//DTD MathML 2.0//EN" "http://www.w3.org/Math/DTD/mathml2/mathml2.dtd">',
|
||||
'svg10' => '<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.0//EN" "http://www.w3.org/TR/2001/REC-SVG-20010904/DTD/svg10.dtd">',
|
||||
'svg11' => '<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">',
|
||||
'svg11-basic' => '<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1 Basic//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11-basic.dtd">',
|
||||
'svg11-tiny' => '<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1 Tiny//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11-tiny.dtd">',
|
||||
'xhtml-math-svg-xh' => '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1 plus MathML 2.0 plus SVG 1.1//EN" "http://www.w3.org/2002/04/xhtml-math-svg/xhtml-math-svg.dtd">',
|
||||
'xhtml-math-svg-sh' => '<!DOCTYPE svg:svg PUBLIC "-//W3C//DTD XHTML 1.1 plus MathML 2.0 plus SVG 1.1//EN" "http://www.w3.org/2002/04/xhtml-math-svg/xhtml-math-svg.dtd">',
|
||||
'xhtml-rdfa-1' => '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML+RDFa 1.0//EN" "http://www.w3.org/MarkUp/DTD/xhtml-rdfa-1.dtd">',
|
||||
'xhtml-rdfa-2' => '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML+RDFa 1.1//EN" "http://www.w3.org/MarkUp/DTD/xhtml-rdfa-2.dtd">',
|
||||
];
|
||||
|
||||
/**
|
||||
* Whether to remove the solidus (`/`) character for void HTML elements (e.g. `<input>`)
|
||||
* for HTML5 compatibility.
|
||||
*
|
||||
* Set to:
|
||||
* `true` - to be HTML5 compatible
|
||||
* `false` - to be XHTML compatible
|
||||
*/
|
||||
public bool $html5 = true;
|
||||
}
|
||||
|
||||
242
app/Config/Email.php
Executable file → Normal file
242
app/Config/Email.php
Executable file → Normal file
@ -1,121 +1,121 @@
|
||||
<?php
|
||||
|
||||
namespace Config;
|
||||
|
||||
use CodeIgniter\Config\BaseConfig;
|
||||
|
||||
class Email extends BaseConfig
|
||||
{
|
||||
public string $fromEmail = '';
|
||||
public string $fromName = '';
|
||||
public string $recipients = '';
|
||||
|
||||
/**
|
||||
* The "user agent"
|
||||
*/
|
||||
public string $userAgent = 'CodeIgniter';
|
||||
|
||||
/**
|
||||
* The mail sending protocol: mail, sendmail, smtp
|
||||
*/
|
||||
public string $protocol = 'mail';
|
||||
|
||||
/**
|
||||
* The server path to Sendmail.
|
||||
*/
|
||||
public string $mailPath = '/usr/sbin/sendmail';
|
||||
|
||||
/**
|
||||
* SMTP Server Hostname
|
||||
*/
|
||||
public string $SMTPHost = '';
|
||||
|
||||
/**
|
||||
* SMTP Username
|
||||
*/
|
||||
public string $SMTPUser = '';
|
||||
|
||||
/**
|
||||
* SMTP Password
|
||||
*/
|
||||
public string $SMTPPass = '';
|
||||
|
||||
/**
|
||||
* SMTP Port
|
||||
*/
|
||||
public int $SMTPPort = 25;
|
||||
|
||||
/**
|
||||
* SMTP Timeout (in seconds)
|
||||
*/
|
||||
public int $SMTPTimeout = 5;
|
||||
|
||||
/**
|
||||
* Enable persistent SMTP connections
|
||||
*/
|
||||
public bool $SMTPKeepAlive = false;
|
||||
|
||||
/**
|
||||
* SMTP Encryption.
|
||||
*
|
||||
* @var string '', 'tls' or 'ssl'. 'tls' will issue a STARTTLS command
|
||||
* to the server. 'ssl' means implicit SSL. Connection on port
|
||||
* 465 should set this to ''.
|
||||
*/
|
||||
public string $SMTPCrypto = 'tls';
|
||||
|
||||
/**
|
||||
* Enable word-wrap
|
||||
*/
|
||||
public bool $wordWrap = true;
|
||||
|
||||
/**
|
||||
* Character count to wrap at
|
||||
*/
|
||||
public int $wrapChars = 76;
|
||||
|
||||
/**
|
||||
* Type of mail, either 'text' or 'html'
|
||||
*/
|
||||
public string $mailType = 'text';
|
||||
|
||||
/**
|
||||
* Character set (utf-8, iso-8859-1, etc.)
|
||||
*/
|
||||
public string $charset = 'UTF-8';
|
||||
|
||||
/**
|
||||
* Whether to validate the email address
|
||||
*/
|
||||
public bool $validate = false;
|
||||
|
||||
/**
|
||||
* Email Priority. 1 = highest. 5 = lowest. 3 = normal
|
||||
*/
|
||||
public int $priority = 3;
|
||||
|
||||
/**
|
||||
* Newline character. (Use “\r\n” to comply with RFC 822)
|
||||
*/
|
||||
public string $CRLF = "\r\n";
|
||||
|
||||
/**
|
||||
* Newline character. (Use “\r\n” to comply with RFC 822)
|
||||
*/
|
||||
public string $newline = "\r\n";
|
||||
|
||||
/**
|
||||
* Enable BCC Batch Mode.
|
||||
*/
|
||||
public bool $BCCBatchMode = false;
|
||||
|
||||
/**
|
||||
* Number of emails in each BCC batch
|
||||
*/
|
||||
public int $BCCBatchSize = 200;
|
||||
|
||||
/**
|
||||
* Enable notify message from server
|
||||
*/
|
||||
public bool $DSN = false;
|
||||
}
|
||||
<?php
|
||||
|
||||
namespace Config;
|
||||
|
||||
use CodeIgniter\Config\BaseConfig;
|
||||
|
||||
class Email extends BaseConfig
|
||||
{
|
||||
public string $fromEmail = '';
|
||||
public string $fromName = '';
|
||||
public string $recipients = '';
|
||||
|
||||
/**
|
||||
* The "user agent"
|
||||
*/
|
||||
public string $userAgent = 'CodeIgniter';
|
||||
|
||||
/**
|
||||
* The mail sending protocol: mail, sendmail, smtp
|
||||
*/
|
||||
public string $protocol = 'mail';
|
||||
|
||||
/**
|
||||
* The server path to Sendmail.
|
||||
*/
|
||||
public string $mailPath = '/usr/sbin/sendmail';
|
||||
|
||||
/**
|
||||
* SMTP Server Hostname
|
||||
*/
|
||||
public string $SMTPHost = '';
|
||||
|
||||
/**
|
||||
* SMTP Username
|
||||
*/
|
||||
public string $SMTPUser = '';
|
||||
|
||||
/**
|
||||
* SMTP Password
|
||||
*/
|
||||
public string $SMTPPass = '';
|
||||
|
||||
/**
|
||||
* SMTP Port
|
||||
*/
|
||||
public int $SMTPPort = 25;
|
||||
|
||||
/**
|
||||
* SMTP Timeout (in seconds)
|
||||
*/
|
||||
public int $SMTPTimeout = 5;
|
||||
|
||||
/**
|
||||
* Enable persistent SMTP connections
|
||||
*/
|
||||
public bool $SMTPKeepAlive = false;
|
||||
|
||||
/**
|
||||
* SMTP Encryption.
|
||||
*
|
||||
* @var string '', 'tls' or 'ssl'. 'tls' will issue a STARTTLS command
|
||||
* to the server. 'ssl' means implicit SSL. Connection on port
|
||||
* 465 should set this to ''.
|
||||
*/
|
||||
public string $SMTPCrypto = 'tls';
|
||||
|
||||
/**
|
||||
* Enable word-wrap
|
||||
*/
|
||||
public bool $wordWrap = true;
|
||||
|
||||
/**
|
||||
* Character count to wrap at
|
||||
*/
|
||||
public int $wrapChars = 76;
|
||||
|
||||
/**
|
||||
* Type of mail, either 'text' or 'html'
|
||||
*/
|
||||
public string $mailType = 'text';
|
||||
|
||||
/**
|
||||
* Character set (utf-8, iso-8859-1, etc.)
|
||||
*/
|
||||
public string $charset = 'UTF-8';
|
||||
|
||||
/**
|
||||
* Whether to validate the email address
|
||||
*/
|
||||
public bool $validate = false;
|
||||
|
||||
/**
|
||||
* Email Priority. 1 = highest. 5 = lowest. 3 = normal
|
||||
*/
|
||||
public int $priority = 3;
|
||||
|
||||
/**
|
||||
* Newline character. (Use “\r\n” to comply with RFC 822)
|
||||
*/
|
||||
public string $CRLF = "\r\n";
|
||||
|
||||
/**
|
||||
* Newline character. (Use “\r\n” to comply with RFC 822)
|
||||
*/
|
||||
public string $newline = "\r\n";
|
||||
|
||||
/**
|
||||
* Enable BCC Batch Mode.
|
||||
*/
|
||||
public bool $BCCBatchMode = false;
|
||||
|
||||
/**
|
||||
* Number of emails in each BCC batch
|
||||
*/
|
||||
public int $BCCBatchSize = 200;
|
||||
|
||||
/**
|
||||
* Enable notify message from server
|
||||
*/
|
||||
public bool $DSN = false;
|
||||
}
|
||||
|
||||
184
app/Config/Encryption.php
Executable file → Normal file
184
app/Config/Encryption.php
Executable file → Normal file
@ -1,92 +1,92 @@
|
||||
<?php
|
||||
|
||||
namespace Config;
|
||||
|
||||
use CodeIgniter\Config\BaseConfig;
|
||||
|
||||
/**
|
||||
* Encryption configuration.
|
||||
*
|
||||
* These are the settings used for encryption, if you don't pass a parameter
|
||||
* array to the encrypter for creation/initialization.
|
||||
*/
|
||||
class Encryption extends BaseConfig
|
||||
{
|
||||
/**
|
||||
* --------------------------------------------------------------------------
|
||||
* Encryption Key Starter
|
||||
* --------------------------------------------------------------------------
|
||||
*
|
||||
* If you use the Encryption class you must set an encryption key (seed).
|
||||
* You need to ensure it is long enough for the cipher and mode you plan to use.
|
||||
* See the user guide for more info.
|
||||
*/
|
||||
public string $key = '';
|
||||
|
||||
/**
|
||||
* --------------------------------------------------------------------------
|
||||
* Encryption Driver to Use
|
||||
* --------------------------------------------------------------------------
|
||||
*
|
||||
* One of the supported encryption drivers.
|
||||
*
|
||||
* Available drivers:
|
||||
* - OpenSSL
|
||||
* - Sodium
|
||||
*/
|
||||
public string $driver = 'OpenSSL';
|
||||
|
||||
/**
|
||||
* --------------------------------------------------------------------------
|
||||
* SodiumHandler's Padding Length in Bytes
|
||||
* --------------------------------------------------------------------------
|
||||
*
|
||||
* This is the number of bytes that will be padded to the plaintext message
|
||||
* before it is encrypted. This value should be greater than zero.
|
||||
*
|
||||
* See the user guide for more information on padding.
|
||||
*/
|
||||
public int $blockSize = 16;
|
||||
|
||||
/**
|
||||
* --------------------------------------------------------------------------
|
||||
* Encryption digest
|
||||
* --------------------------------------------------------------------------
|
||||
*
|
||||
* HMAC digest to use, e.g. 'SHA512' or 'SHA256'. Default value is 'SHA512'.
|
||||
*/
|
||||
public string $digest = 'SHA512';
|
||||
|
||||
/**
|
||||
* Whether the cipher-text should be raw. If set to false, then it will be base64 encoded.
|
||||
* This setting is only used by OpenSSLHandler.
|
||||
*
|
||||
* Set to false for CI3 Encryption compatibility.
|
||||
*/
|
||||
public bool $rawData = true;
|
||||
|
||||
/**
|
||||
* Encryption key info.
|
||||
* This setting is only used by OpenSSLHandler.
|
||||
*
|
||||
* Set to 'encryption' for CI3 Encryption compatibility.
|
||||
*/
|
||||
public string $encryptKeyInfo = '';
|
||||
|
||||
/**
|
||||
* Authentication key info.
|
||||
* This setting is only used by OpenSSLHandler.
|
||||
*
|
||||
* Set to 'authentication' for CI3 Encryption compatibility.
|
||||
*/
|
||||
public string $authKeyInfo = '';
|
||||
|
||||
/**
|
||||
* Cipher to use.
|
||||
* This setting is only used by OpenSSLHandler.
|
||||
*
|
||||
* Set to 'AES-128-CBC' to decrypt encrypted data that encrypted
|
||||
* by CI3 Encryption default configuration.
|
||||
*/
|
||||
public string $cipher = 'AES-256-CTR';
|
||||
}
|
||||
<?php
|
||||
|
||||
namespace Config;
|
||||
|
||||
use CodeIgniter\Config\BaseConfig;
|
||||
|
||||
/**
|
||||
* Encryption configuration.
|
||||
*
|
||||
* These are the settings used for encryption, if you don't pass a parameter
|
||||
* array to the encrypter for creation/initialization.
|
||||
*/
|
||||
class Encryption extends BaseConfig
|
||||
{
|
||||
/**
|
||||
* --------------------------------------------------------------------------
|
||||
* Encryption Key Starter
|
||||
* --------------------------------------------------------------------------
|
||||
*
|
||||
* If you use the Encryption class you must set an encryption key (seed).
|
||||
* You need to ensure it is long enough for the cipher and mode you plan to use.
|
||||
* See the user guide for more info.
|
||||
*/
|
||||
public string $key = '';
|
||||
|
||||
/**
|
||||
* --------------------------------------------------------------------------
|
||||
* Encryption Driver to Use
|
||||
* --------------------------------------------------------------------------
|
||||
*
|
||||
* One of the supported encryption drivers.
|
||||
*
|
||||
* Available drivers:
|
||||
* - OpenSSL
|
||||
* - Sodium
|
||||
*/
|
||||
public string $driver = 'OpenSSL';
|
||||
|
||||
/**
|
||||
* --------------------------------------------------------------------------
|
||||
* SodiumHandler's Padding Length in Bytes
|
||||
* --------------------------------------------------------------------------
|
||||
*
|
||||
* This is the number of bytes that will be padded to the plaintext message
|
||||
* before it is encrypted. This value should be greater than zero.
|
||||
*
|
||||
* See the user guide for more information on padding.
|
||||
*/
|
||||
public int $blockSize = 16;
|
||||
|
||||
/**
|
||||
* --------------------------------------------------------------------------
|
||||
* Encryption digest
|
||||
* --------------------------------------------------------------------------
|
||||
*
|
||||
* HMAC digest to use, e.g. 'SHA512' or 'SHA256'. Default value is 'SHA512'.
|
||||
*/
|
||||
public string $digest = 'SHA512';
|
||||
|
||||
/**
|
||||
* Whether the cipher-text should be raw. If set to false, then it will be base64 encoded.
|
||||
* This setting is only used by OpenSSLHandler.
|
||||
*
|
||||
* Set to false for CI3 Encryption compatibility.
|
||||
*/
|
||||
public bool $rawData = true;
|
||||
|
||||
/**
|
||||
* Encryption key info.
|
||||
* This setting is only used by OpenSSLHandler.
|
||||
*
|
||||
* Set to 'encryption' for CI3 Encryption compatibility.
|
||||
*/
|
||||
public string $encryptKeyInfo = '';
|
||||
|
||||
/**
|
||||
* Authentication key info.
|
||||
* This setting is only used by OpenSSLHandler.
|
||||
*
|
||||
* Set to 'authentication' for CI3 Encryption compatibility.
|
||||
*/
|
||||
public string $authKeyInfo = '';
|
||||
|
||||
/**
|
||||
* Cipher to use.
|
||||
* This setting is only used by OpenSSLHandler.
|
||||
*
|
||||
* Set to 'AES-128-CBC' to decrypt encrypted data that encrypted
|
||||
* by CI3 Encryption default configuration.
|
||||
*/
|
||||
public string $cipher = 'AES-256-CTR';
|
||||
}
|
||||
|
||||
110
app/Config/Events.php
Executable file → Normal file
110
app/Config/Events.php
Executable file → Normal file
@ -1,55 +1,55 @@
|
||||
<?php
|
||||
|
||||
namespace Config;
|
||||
|
||||
use CodeIgniter\Events\Events;
|
||||
use CodeIgniter\Exceptions\FrameworkException;
|
||||
use CodeIgniter\HotReloader\HotReloader;
|
||||
|
||||
/*
|
||||
* --------------------------------------------------------------------
|
||||
* Application Events
|
||||
* --------------------------------------------------------------------
|
||||
* Events allow you to tap into the execution of the program without
|
||||
* modifying or extending core files. This file provides a central
|
||||
* location to define your events, though they can always be added
|
||||
* at run-time, also, if needed.
|
||||
*
|
||||
* You create code that can execute by subscribing to events with
|
||||
* the 'on()' method. This accepts any form of callable, including
|
||||
* Closures, that will be executed when the event is triggered.
|
||||
*
|
||||
* Example:
|
||||
* Events::on('create', [$myInstance, 'myMethod']);
|
||||
*/
|
||||
|
||||
Events::on('pre_system', static function (): void {
|
||||
if (ENVIRONMENT !== 'testing') {
|
||||
if (ini_get('zlib.output_compression')) {
|
||||
throw FrameworkException::forEnabledZlibOutputCompression();
|
||||
}
|
||||
|
||||
while (ob_get_level() > 0) {
|
||||
ob_end_flush();
|
||||
}
|
||||
|
||||
ob_start(static fn ($buffer) => $buffer);
|
||||
}
|
||||
|
||||
/*
|
||||
* --------------------------------------------------------------------
|
||||
* Debug Toolbar Listeners.
|
||||
* --------------------------------------------------------------------
|
||||
* If you delete, they will no longer be collected.
|
||||
*/
|
||||
if (CI_DEBUG && ! is_cli()) {
|
||||
Events::on('DBQuery', 'CodeIgniter\Debug\Toolbar\Collectors\Database::collect');
|
||||
service('toolbar')->respond();
|
||||
// Hot Reload route - for framework use on the hot reloader.
|
||||
if (ENVIRONMENT === 'development') {
|
||||
service('routes')->get('__hot-reload', static function (): void {
|
||||
(new HotReloader())->run();
|
||||
});
|
||||
}
|
||||
}
|
||||
});
|
||||
<?php
|
||||
|
||||
namespace Config;
|
||||
|
||||
use CodeIgniter\Events\Events;
|
||||
use CodeIgniter\Exceptions\FrameworkException;
|
||||
use CodeIgniter\HotReloader\HotReloader;
|
||||
|
||||
/*
|
||||
* --------------------------------------------------------------------
|
||||
* Application Events
|
||||
* --------------------------------------------------------------------
|
||||
* Events allow you to tap into the execution of the program without
|
||||
* modifying or extending core files. This file provides a central
|
||||
* location to define your events, though they can always be added
|
||||
* at run-time, also, if needed.
|
||||
*
|
||||
* You create code that can execute by subscribing to events with
|
||||
* the 'on()' method. This accepts any form of callable, including
|
||||
* Closures, that will be executed when the event is triggered.
|
||||
*
|
||||
* Example:
|
||||
* Events::on('create', [$myInstance, 'myMethod']);
|
||||
*/
|
||||
|
||||
Events::on('pre_system', static function (): void {
|
||||
if (ENVIRONMENT !== 'testing') {
|
||||
if (ini_get('zlib.output_compression')) {
|
||||
throw FrameworkException::forEnabledZlibOutputCompression();
|
||||
}
|
||||
|
||||
while (ob_get_level() > 0) {
|
||||
ob_end_flush();
|
||||
}
|
||||
|
||||
ob_start(static fn ($buffer) => $buffer);
|
||||
}
|
||||
|
||||
/*
|
||||
* --------------------------------------------------------------------
|
||||
* Debug Toolbar Listeners.
|
||||
* --------------------------------------------------------------------
|
||||
* If you delete, they will no longer be collected.
|
||||
*/
|
||||
if (CI_DEBUG && ! is_cli()) {
|
||||
Events::on('DBQuery', 'CodeIgniter\Debug\Toolbar\Collectors\Database::collect');
|
||||
service('toolbar')->respond();
|
||||
// Hot Reload route - for framework use on the hot reloader.
|
||||
if (ENVIRONMENT === 'development') {
|
||||
service('routes')->get('__hot-reload', static function (): void {
|
||||
(new HotReloader())->run();
|
||||
});
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
212
app/Config/Exceptions.php
Executable file → Normal file
212
app/Config/Exceptions.php
Executable file → Normal file
@ -1,106 +1,106 @@
|
||||
<?php
|
||||
|
||||
namespace Config;
|
||||
|
||||
use CodeIgniter\Config\BaseConfig;
|
||||
use CodeIgniter\Debug\ExceptionHandler;
|
||||
use CodeIgniter\Debug\ExceptionHandlerInterface;
|
||||
use Psr\Log\LogLevel;
|
||||
use Throwable;
|
||||
|
||||
/**
|
||||
* Setup how the exception handler works.
|
||||
*/
|
||||
class Exceptions extends BaseConfig
|
||||
{
|
||||
/**
|
||||
* --------------------------------------------------------------------------
|
||||
* LOG EXCEPTIONS?
|
||||
* --------------------------------------------------------------------------
|
||||
* If true, then exceptions will be logged
|
||||
* through Services::Log.
|
||||
*
|
||||
* Default: true
|
||||
*/
|
||||
public bool $log = true;
|
||||
|
||||
/**
|
||||
* --------------------------------------------------------------------------
|
||||
* DO NOT LOG STATUS CODES
|
||||
* --------------------------------------------------------------------------
|
||||
* Any status codes here will NOT be logged if logging is turned on.
|
||||
* By default, only 404 (Page Not Found) exceptions are ignored.
|
||||
*
|
||||
* @var list<int>
|
||||
*/
|
||||
public array $ignoreCodes = [404];
|
||||
|
||||
/**
|
||||
* --------------------------------------------------------------------------
|
||||
* Error Views Path
|
||||
* --------------------------------------------------------------------------
|
||||
* This is the path to the directory that contains the 'cli' and 'html'
|
||||
* directories that hold the views used to generate errors.
|
||||
*
|
||||
* Default: APPPATH.'Views/errors'
|
||||
*/
|
||||
public string $errorViewPath = __DIR__ . '/../Views/errors';
|
||||
|
||||
/**
|
||||
* --------------------------------------------------------------------------
|
||||
* HIDE FROM DEBUG TRACE
|
||||
* --------------------------------------------------------------------------
|
||||
* Any data that you would like to hide from the debug trace.
|
||||
* In order to specify 2 levels, use "/" to separate.
|
||||
* ex. ['server', 'setup/password', 'secret_token']
|
||||
*
|
||||
* @var list<string>
|
||||
*/
|
||||
public array $sensitiveDataInTrace = [];
|
||||
|
||||
/**
|
||||
* --------------------------------------------------------------------------
|
||||
* WHETHER TO THROW AN EXCEPTION ON DEPRECATED ERRORS
|
||||
* --------------------------------------------------------------------------
|
||||
* If set to `true`, DEPRECATED errors are only logged and no exceptions are
|
||||
* thrown. This option also works for user deprecations.
|
||||
*/
|
||||
public bool $logDeprecations = true;
|
||||
|
||||
/**
|
||||
* --------------------------------------------------------------------------
|
||||
* LOG LEVEL THRESHOLD FOR DEPRECATIONS
|
||||
* --------------------------------------------------------------------------
|
||||
* If `$logDeprecations` is set to `true`, this sets the log level
|
||||
* to which the deprecation will be logged. This should be one of the log
|
||||
* levels recognized by PSR-3.
|
||||
*
|
||||
* The related `Config\Logger::$threshold` should be adjusted, if needed,
|
||||
* to capture logging the deprecations.
|
||||
*/
|
||||
public string $deprecationLogLevel = LogLevel::WARNING;
|
||||
|
||||
/*
|
||||
* DEFINE THE HANDLERS USED
|
||||
* --------------------------------------------------------------------------
|
||||
* Given the HTTP status code, returns exception handler that
|
||||
* should be used to deal with this error. By default, it will run CodeIgniter's
|
||||
* default handler and display the error information in the expected format
|
||||
* for CLI, HTTP, or AJAX requests, as determined by is_cli() and the expected
|
||||
* response format.
|
||||
*
|
||||
* Custom handlers can be returned if you want to handle one or more specific
|
||||
* error codes yourself like:
|
||||
*
|
||||
* if (in_array($statusCode, [400, 404, 500])) {
|
||||
* return new \App\Libraries\MyExceptionHandler();
|
||||
* }
|
||||
* if ($exception instanceOf PageNotFoundException) {
|
||||
* return new \App\Libraries\MyExceptionHandler();
|
||||
* }
|
||||
*/
|
||||
public function handler(int $statusCode, Throwable $exception): ExceptionHandlerInterface
|
||||
{
|
||||
return new ExceptionHandler($this);
|
||||
}
|
||||
}
|
||||
<?php
|
||||
|
||||
namespace Config;
|
||||
|
||||
use CodeIgniter\Config\BaseConfig;
|
||||
use CodeIgniter\Debug\ExceptionHandler;
|
||||
use CodeIgniter\Debug\ExceptionHandlerInterface;
|
||||
use Psr\Log\LogLevel;
|
||||
use Throwable;
|
||||
|
||||
/**
|
||||
* Setup how the exception handler works.
|
||||
*/
|
||||
class Exceptions extends BaseConfig
|
||||
{
|
||||
/**
|
||||
* --------------------------------------------------------------------------
|
||||
* LOG EXCEPTIONS?
|
||||
* --------------------------------------------------------------------------
|
||||
* If true, then exceptions will be logged
|
||||
* through Services::Log.
|
||||
*
|
||||
* Default: true
|
||||
*/
|
||||
public bool $log = true;
|
||||
|
||||
/**
|
||||
* --------------------------------------------------------------------------
|
||||
* DO NOT LOG STATUS CODES
|
||||
* --------------------------------------------------------------------------
|
||||
* Any status codes here will NOT be logged if logging is turned on.
|
||||
* By default, only 404 (Page Not Found) exceptions are ignored.
|
||||
*
|
||||
* @var list<int>
|
||||
*/
|
||||
public array $ignoreCodes = [404];
|
||||
|
||||
/**
|
||||
* --------------------------------------------------------------------------
|
||||
* Error Views Path
|
||||
* --------------------------------------------------------------------------
|
||||
* This is the path to the directory that contains the 'cli' and 'html'
|
||||
* directories that hold the views used to generate errors.
|
||||
*
|
||||
* Default: APPPATH.'Views/errors'
|
||||
*/
|
||||
public string $errorViewPath = __DIR__ . '/../Views/errors';
|
||||
|
||||
/**
|
||||
* --------------------------------------------------------------------------
|
||||
* HIDE FROM DEBUG TRACE
|
||||
* --------------------------------------------------------------------------
|
||||
* Any data that you would like to hide from the debug trace.
|
||||
* In order to specify 2 levels, use "/" to separate.
|
||||
* ex. ['server', 'setup/password', 'secret_token']
|
||||
*
|
||||
* @var list<string>
|
||||
*/
|
||||
public array $sensitiveDataInTrace = [];
|
||||
|
||||
/**
|
||||
* --------------------------------------------------------------------------
|
||||
* WHETHER TO THROW AN EXCEPTION ON DEPRECATED ERRORS
|
||||
* --------------------------------------------------------------------------
|
||||
* If set to `true`, DEPRECATED errors are only logged and no exceptions are
|
||||
* thrown. This option also works for user deprecations.
|
||||
*/
|
||||
public bool $logDeprecations = true;
|
||||
|
||||
/**
|
||||
* --------------------------------------------------------------------------
|
||||
* LOG LEVEL THRESHOLD FOR DEPRECATIONS
|
||||
* --------------------------------------------------------------------------
|
||||
* If `$logDeprecations` is set to `true`, this sets the log level
|
||||
* to which the deprecation will be logged. This should be one of the log
|
||||
* levels recognized by PSR-3.
|
||||
*
|
||||
* The related `Config\Logger::$threshold` should be adjusted, if needed,
|
||||
* to capture logging the deprecations.
|
||||
*/
|
||||
public string $deprecationLogLevel = LogLevel::WARNING;
|
||||
|
||||
/*
|
||||
* DEFINE THE HANDLERS USED
|
||||
* --------------------------------------------------------------------------
|
||||
* Given the HTTP status code, returns exception handler that
|
||||
* should be used to deal with this error. By default, it will run CodeIgniter's
|
||||
* default handler and display the error information in the expected format
|
||||
* for CLI, HTTP, or AJAX requests, as determined by is_cli() and the expected
|
||||
* response format.
|
||||
*
|
||||
* Custom handlers can be returned if you want to handle one or more specific
|
||||
* error codes yourself like:
|
||||
*
|
||||
* if (in_array($statusCode, [400, 404, 500])) {
|
||||
* return new \App\Libraries\MyExceptionHandler();
|
||||
* }
|
||||
* if ($exception instanceOf PageNotFoundException) {
|
||||
* return new \App\Libraries\MyExceptionHandler();
|
||||
* }
|
||||
*/
|
||||
public function handler(int $statusCode, Throwable $exception): ExceptionHandlerInterface
|
||||
{
|
||||
return new ExceptionHandler($this);
|
||||
}
|
||||
}
|
||||
|
||||
74
app/Config/Feature.php
Executable file → Normal file
74
app/Config/Feature.php
Executable file → Normal file
@ -1,37 +1,37 @@
|
||||
<?php
|
||||
|
||||
namespace Config;
|
||||
|
||||
use CodeIgniter\Config\BaseConfig;
|
||||
|
||||
/**
|
||||
* Enable/disable backward compatibility breaking features.
|
||||
*/
|
||||
class Feature extends BaseConfig
|
||||
{
|
||||
/**
|
||||
* Use improved new auto routing instead of the legacy version.
|
||||
*/
|
||||
public bool $autoRoutesImproved = true;
|
||||
|
||||
/**
|
||||
* Use filter execution order in 4.4 or before.
|
||||
*/
|
||||
public bool $oldFilterOrder = false;
|
||||
|
||||
/**
|
||||
* The behavior of `limit(0)` in Query Builder.
|
||||
*
|
||||
* If true, `limit(0)` returns all records. (the behavior of 4.4.x or before in version 4.x.)
|
||||
* If false, `limit(0)` returns no records. (the behavior of 3.1.9 or later in version 3.x.)
|
||||
*/
|
||||
public bool $limitZeroAsAll = true;
|
||||
|
||||
/**
|
||||
* Use strict location negotiation.
|
||||
*
|
||||
* By default, the locale is selected based on a loose comparison of the language code (ISO 639-1)
|
||||
* Enabling strict comparison will also consider the region code (ISO 3166-1 alpha-2).
|
||||
*/
|
||||
public bool $strictLocaleNegotiation = false;
|
||||
}
|
||||
<?php
|
||||
|
||||
namespace Config;
|
||||
|
||||
use CodeIgniter\Config\BaseConfig;
|
||||
|
||||
/**
|
||||
* Enable/disable backward compatibility breaking features.
|
||||
*/
|
||||
class Feature extends BaseConfig
|
||||
{
|
||||
/**
|
||||
* Use improved new auto routing instead of the legacy version.
|
||||
*/
|
||||
public bool $autoRoutesImproved = true;
|
||||
|
||||
/**
|
||||
* Use filter execution order in 4.4 or before.
|
||||
*/
|
||||
public bool $oldFilterOrder = false;
|
||||
|
||||
/**
|
||||
* The behavior of `limit(0)` in Query Builder.
|
||||
*
|
||||
* If true, `limit(0)` returns all records. (the behavior of 4.4.x or before in version 4.x.)
|
||||
* If false, `limit(0)` returns no records. (the behavior of 3.1.9 or later in version 3.x.)
|
||||
*/
|
||||
public bool $limitZeroAsAll = true;
|
||||
|
||||
/**
|
||||
* Use strict location negotiation.
|
||||
*
|
||||
* By default, the locale is selected based on a loose comparison of the language code (ISO 639-1)
|
||||
* Enabling strict comparison will also consider the region code (ISO 3166-1 alpha-2).
|
||||
*/
|
||||
public bool $strictLocaleNegotiation = false;
|
||||
}
|
||||
|
||||
220
app/Config/Filters.php
Executable file → Normal file
220
app/Config/Filters.php
Executable file → Normal file
@ -1,110 +1,110 @@
|
||||
<?php
|
||||
|
||||
namespace Config;
|
||||
|
||||
use CodeIgniter\Config\Filters as BaseFilters;
|
||||
// use CodeIgniter\Filters\Cors;
|
||||
use CodeIgniter\Filters\CSRF;
|
||||
use CodeIgniter\Filters\DebugToolbar;
|
||||
use CodeIgniter\Filters\ForceHTTPS;
|
||||
use CodeIgniter\Filters\Honeypot;
|
||||
use CodeIgniter\Filters\InvalidChars;
|
||||
use CodeIgniter\Filters\PageCache;
|
||||
use CodeIgniter\Filters\PerformanceMetrics;
|
||||
use CodeIgniter\Filters\SecureHeaders;
|
||||
|
||||
class Filters extends BaseFilters
|
||||
{
|
||||
/**
|
||||
* Configures aliases for Filter classes to
|
||||
* make reading things nicer and simpler.
|
||||
*
|
||||
* @var array<string, class-string|list<class-string>>
|
||||
*
|
||||
* [filter_name => classname]
|
||||
* or [filter_name => [classname1, classname2, ...]]
|
||||
*/
|
||||
public array $aliases = [
|
||||
'csrf' => CSRF::class,
|
||||
'toolbar' => DebugToolbar::class,
|
||||
'honeypot' => Honeypot::class,
|
||||
'invalidchars' => InvalidChars::class,
|
||||
'secureheaders' => SecureHeaders::class,
|
||||
// 'cors' => Cors::class,
|
||||
'cors' => \App\Filters\Cors::class,
|
||||
'forcehttps' => ForceHTTPS::class,
|
||||
'pagecache' => PageCache::class,
|
||||
'performance' => PerformanceMetrics::class,
|
||||
'auth' => \App\Filters\AuthFilter::class,
|
||||
];
|
||||
|
||||
/**
|
||||
* List of special required filters.
|
||||
*
|
||||
* The filters listed here are special. They are applied before and after
|
||||
* other kinds of filters, and always applied even if a route does not exist.
|
||||
*
|
||||
* Filters set by default provide framework functionality. If removed,
|
||||
* those functions will no longer work.
|
||||
*
|
||||
* @see https://codeigniter.com/user_guide/incoming/filters.html#provided-filters
|
||||
*
|
||||
* @var array{before: list<string>, after: list<string>}
|
||||
*/
|
||||
public array $required = [
|
||||
'before' => [
|
||||
// 'forcehttps', // Force Global Secure Requests - disabled for localhost
|
||||
'pagecache', // Web Page Caching
|
||||
],
|
||||
'after' => [
|
||||
'pagecache', // Web Page Caching
|
||||
'performance', // Performance Metrics
|
||||
'toolbar', // Debug Toolbar
|
||||
],
|
||||
];
|
||||
|
||||
/**
|
||||
* List of filter aliases that are always
|
||||
* applied before and after every request.
|
||||
*
|
||||
* @var array<string, array<string, array<string, string>>>|array<string, list<string>>
|
||||
*/
|
||||
public array $globals = [
|
||||
'before' => [
|
||||
'cors',
|
||||
// 'honeypot',
|
||||
// 'csrf',
|
||||
// 'invalidchars',
|
||||
],
|
||||
'after' => [
|
||||
// 'honeypot',
|
||||
// 'secureheaders',
|
||||
],
|
||||
];
|
||||
|
||||
/**
|
||||
* List of filter aliases that works on a
|
||||
* particular HTTP method (GET, POST, etc.).
|
||||
*
|
||||
* Example:
|
||||
* 'POST' => ['foo', 'bar']
|
||||
*
|
||||
* If you use this, you should disable auto-routing because auto-routing
|
||||
* permits any HTTP method to access a controller. Accessing the controller
|
||||
* with a method you don't expect could bypass the filter.
|
||||
*
|
||||
* @var array<string, list<string>>
|
||||
*/
|
||||
public array $methods = [];
|
||||
|
||||
/**
|
||||
* List of filter aliases that should run on any
|
||||
* before or after URI patterns.
|
||||
*
|
||||
* Example:
|
||||
* 'isLoggedIn' => ['before' => ['account/*', 'profiles/*']]
|
||||
*
|
||||
* @var array<string, array<string, list<string>>>
|
||||
*/
|
||||
public array $filters = [];
|
||||
}
|
||||
<?php
|
||||
|
||||
namespace Config;
|
||||
|
||||
use CodeIgniter\Config\Filters as BaseFilters;
|
||||
// use CodeIgniter\Filters\Cors;
|
||||
use CodeIgniter\Filters\CSRF;
|
||||
use CodeIgniter\Filters\DebugToolbar;
|
||||
use CodeIgniter\Filters\ForceHTTPS;
|
||||
use CodeIgniter\Filters\Honeypot;
|
||||
use CodeIgniter\Filters\InvalidChars;
|
||||
use CodeIgniter\Filters\PageCache;
|
||||
use CodeIgniter\Filters\PerformanceMetrics;
|
||||
use CodeIgniter\Filters\SecureHeaders;
|
||||
|
||||
class Filters extends BaseFilters
|
||||
{
|
||||
/**
|
||||
* Configures aliases for Filter classes to
|
||||
* make reading things nicer and simpler.
|
||||
*
|
||||
* @var array<string, class-string|list<class-string>>
|
||||
*
|
||||
* [filter_name => classname]
|
||||
* or [filter_name => [classname1, classname2, ...]]
|
||||
*/
|
||||
public array $aliases = [
|
||||
'csrf' => CSRF::class,
|
||||
'toolbar' => DebugToolbar::class,
|
||||
'honeypot' => Honeypot::class,
|
||||
'invalidchars' => InvalidChars::class,
|
||||
'secureheaders' => SecureHeaders::class,
|
||||
// 'cors' => Cors::class,
|
||||
'cors' => \App\Filters\Cors::class,
|
||||
'forcehttps' => ForceHTTPS::class,
|
||||
'pagecache' => PageCache::class,
|
||||
'performance' => PerformanceMetrics::class,
|
||||
'auth' => \App\Filters\AuthFilter::class,
|
||||
];
|
||||
|
||||
/**
|
||||
* List of special required filters.
|
||||
*
|
||||
* The filters listed here are special. They are applied before and after
|
||||
* other kinds of filters, and always applied even if a route does not exist.
|
||||
*
|
||||
* Filters set by default provide framework functionality. If removed,
|
||||
* those functions will no longer work.
|
||||
*
|
||||
* @see https://codeigniter.com/user_guide/incoming/filters.html#provided-filters
|
||||
*
|
||||
* @var array{before: list<string>, after: list<string>}
|
||||
*/
|
||||
public array $required = [
|
||||
'before' => [
|
||||
// 'forcehttps', // Force Global Secure Requests - disabled for localhost
|
||||
'pagecache', // Web Page Caching
|
||||
],
|
||||
'after' => [
|
||||
'pagecache', // Web Page Caching
|
||||
'performance', // Performance Metrics
|
||||
'toolbar', // Debug Toolbar
|
||||
],
|
||||
];
|
||||
|
||||
/**
|
||||
* List of filter aliases that are always
|
||||
* applied before and after every request.
|
||||
*
|
||||
* @var array<string, array<string, array<string, string>>>|array<string, list<string>>
|
||||
*/
|
||||
public array $globals = [
|
||||
'before' => [
|
||||
'cors',
|
||||
// 'honeypot',
|
||||
// 'csrf',
|
||||
// 'invalidchars',
|
||||
],
|
||||
'after' => [
|
||||
// 'honeypot',
|
||||
// 'secureheaders',
|
||||
],
|
||||
];
|
||||
|
||||
/**
|
||||
* List of filter aliases that works on a
|
||||
* particular HTTP method (GET, POST, etc.).
|
||||
*
|
||||
* Example:
|
||||
* 'POST' => ['foo', 'bar']
|
||||
*
|
||||
* If you use this, you should disable auto-routing because auto-routing
|
||||
* permits any HTTP method to access a controller. Accessing the controller
|
||||
* with a method you don't expect could bypass the filter.
|
||||
*
|
||||
* @var array<string, list<string>>
|
||||
*/
|
||||
public array $methods = [];
|
||||
|
||||
/**
|
||||
* List of filter aliases that should run on any
|
||||
* before or after URI patterns.
|
||||
*
|
||||
* Example:
|
||||
* 'isLoggedIn' => ['before' => ['account/*', 'profiles/*']]
|
||||
*
|
||||
* @var array<string, array<string, list<string>>>
|
||||
*/
|
||||
public array $filters = [];
|
||||
}
|
||||
|
||||
24
app/Config/ForeignCharacters.php
Executable file → Normal file
24
app/Config/ForeignCharacters.php
Executable file → Normal file
@ -1,12 +1,12 @@
|
||||
<?php
|
||||
|
||||
namespace Config;
|
||||
|
||||
use CodeIgniter\Config\ForeignCharacters as BaseForeignCharacters;
|
||||
|
||||
/**
|
||||
* @immutable
|
||||
*/
|
||||
class ForeignCharacters extends BaseForeignCharacters
|
||||
{
|
||||
}
|
||||
<?php
|
||||
|
||||
namespace Config;
|
||||
|
||||
use CodeIgniter\Config\ForeignCharacters as BaseForeignCharacters;
|
||||
|
||||
/**
|
||||
* @immutable
|
||||
*/
|
||||
class ForeignCharacters extends BaseForeignCharacters
|
||||
{
|
||||
}
|
||||
|
||||
128
app/Config/Format.php
Executable file → Normal file
128
app/Config/Format.php
Executable file → Normal file
@ -1,64 +1,64 @@
|
||||
<?php
|
||||
|
||||
namespace Config;
|
||||
|
||||
use CodeIgniter\Config\BaseConfig;
|
||||
use CodeIgniter\Format\JSONFormatter;
|
||||
use CodeIgniter\Format\XMLFormatter;
|
||||
|
||||
class Format extends BaseConfig
|
||||
{
|
||||
/**
|
||||
* --------------------------------------------------------------------------
|
||||
* Available Response Formats
|
||||
* --------------------------------------------------------------------------
|
||||
*
|
||||
* When you perform content negotiation with the request, these are the
|
||||
* available formats that your application supports. This is currently
|
||||
* only used with the API\ResponseTrait. A valid Formatter must exist
|
||||
* for the specified format.
|
||||
*
|
||||
* These formats are only checked when the data passed to the respond()
|
||||
* method is an array.
|
||||
*
|
||||
* @var list<string>
|
||||
*/
|
||||
public array $supportedResponseFormats = [
|
||||
'application/json',
|
||||
'application/xml', // machine-readable XML
|
||||
'text/xml', // human-readable XML
|
||||
];
|
||||
|
||||
/**
|
||||
* --------------------------------------------------------------------------
|
||||
* Formatters
|
||||
* --------------------------------------------------------------------------
|
||||
*
|
||||
* Lists the class to use to format responses with of a particular type.
|
||||
* For each mime type, list the class that should be used. Formatters
|
||||
* can be retrieved through the getFormatter() method.
|
||||
*
|
||||
* @var array<string, string>
|
||||
*/
|
||||
public array $formatters = [
|
||||
'application/json' => JSONFormatter::class,
|
||||
'application/xml' => XMLFormatter::class,
|
||||
'text/xml' => XMLFormatter::class,
|
||||
];
|
||||
|
||||
/**
|
||||
* --------------------------------------------------------------------------
|
||||
* Formatters Options
|
||||
* --------------------------------------------------------------------------
|
||||
*
|
||||
* Additional Options to adjust default formatters behaviour.
|
||||
* For each mime type, list the additional options that should be used.
|
||||
*
|
||||
* @var array<string, int>
|
||||
*/
|
||||
public array $formatterOptions = [
|
||||
'application/json' => JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES,
|
||||
'application/xml' => 0,
|
||||
'text/xml' => 0,
|
||||
];
|
||||
}
|
||||
<?php
|
||||
|
||||
namespace Config;
|
||||
|
||||
use CodeIgniter\Config\BaseConfig;
|
||||
use CodeIgniter\Format\JSONFormatter;
|
||||
use CodeIgniter\Format\XMLFormatter;
|
||||
|
||||
class Format extends BaseConfig
|
||||
{
|
||||
/**
|
||||
* --------------------------------------------------------------------------
|
||||
* Available Response Formats
|
||||
* --------------------------------------------------------------------------
|
||||
*
|
||||
* When you perform content negotiation with the request, these are the
|
||||
* available formats that your application supports. This is currently
|
||||
* only used with the API\ResponseTrait. A valid Formatter must exist
|
||||
* for the specified format.
|
||||
*
|
||||
* These formats are only checked when the data passed to the respond()
|
||||
* method is an array.
|
||||
*
|
||||
* @var list<string>
|
||||
*/
|
||||
public array $supportedResponseFormats = [
|
||||
'application/json',
|
||||
'application/xml', // machine-readable XML
|
||||
'text/xml', // human-readable XML
|
||||
];
|
||||
|
||||
/**
|
||||
* --------------------------------------------------------------------------
|
||||
* Formatters
|
||||
* --------------------------------------------------------------------------
|
||||
*
|
||||
* Lists the class to use to format responses with of a particular type.
|
||||
* For each mime type, list the class that should be used. Formatters
|
||||
* can be retrieved through the getFormatter() method.
|
||||
*
|
||||
* @var array<string, string>
|
||||
*/
|
||||
public array $formatters = [
|
||||
'application/json' => JSONFormatter::class,
|
||||
'application/xml' => XMLFormatter::class,
|
||||
'text/xml' => XMLFormatter::class,
|
||||
];
|
||||
|
||||
/**
|
||||
* --------------------------------------------------------------------------
|
||||
* Formatters Options
|
||||
* --------------------------------------------------------------------------
|
||||
*
|
||||
* Additional Options to adjust default formatters behaviour.
|
||||
* For each mime type, list the additional options that should be used.
|
||||
*
|
||||
* @var array<string, int>
|
||||
*/
|
||||
public array $formatterOptions = [
|
||||
'application/json' => JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES,
|
||||
'application/xml' => 0,
|
||||
'text/xml' => 0,
|
||||
];
|
||||
}
|
||||
|
||||
88
app/Config/Generators.php
Executable file → Normal file
88
app/Config/Generators.php
Executable file → Normal file
@ -1,44 +1,44 @@
|
||||
<?php
|
||||
|
||||
namespace Config;
|
||||
|
||||
use CodeIgniter\Config\BaseConfig;
|
||||
|
||||
class Generators extends BaseConfig
|
||||
{
|
||||
/**
|
||||
* --------------------------------------------------------------------------
|
||||
* Generator Commands' Views
|
||||
* --------------------------------------------------------------------------
|
||||
*
|
||||
* This array defines the mapping of generator commands to the view files
|
||||
* they are using. If you need to customize them for your own, copy these
|
||||
* view files in your own folder and indicate the location here.
|
||||
*
|
||||
* You will notice that the views have special placeholders enclosed in
|
||||
* curly braces `{...}`. These placeholders are used internally by the
|
||||
* generator commands in processing replacements, thus you are warned
|
||||
* not to delete them or modify the names. If you will do so, you may
|
||||
* end up disrupting the scaffolding process and throw errors.
|
||||
*
|
||||
* YOU HAVE BEEN WARNED!
|
||||
*
|
||||
* @var array<string, array<string, string>|string>
|
||||
*/
|
||||
public array $views = [
|
||||
'make:cell' => [
|
||||
'class' => 'CodeIgniter\Commands\Generators\Views\cell.tpl.php',
|
||||
'view' => 'CodeIgniter\Commands\Generators\Views\cell_view.tpl.php',
|
||||
],
|
||||
'make:command' => 'CodeIgniter\Commands\Generators\Views\command.tpl.php',
|
||||
'make:config' => 'CodeIgniter\Commands\Generators\Views\config.tpl.php',
|
||||
'make:controller' => 'CodeIgniter\Commands\Generators\Views\controller.tpl.php',
|
||||
'make:entity' => 'CodeIgniter\Commands\Generators\Views\entity.tpl.php',
|
||||
'make:filter' => 'CodeIgniter\Commands\Generators\Views\filter.tpl.php',
|
||||
'make:migration' => 'CodeIgniter\Commands\Generators\Views\migration.tpl.php',
|
||||
'make:model' => 'CodeIgniter\Commands\Generators\Views\model.tpl.php',
|
||||
'make:seeder' => 'CodeIgniter\Commands\Generators\Views\seeder.tpl.php',
|
||||
'make:validation' => 'CodeIgniter\Commands\Generators\Views\validation.tpl.php',
|
||||
'session:migration' => 'CodeIgniter\Commands\Generators\Views\migration.tpl.php',
|
||||
];
|
||||
}
|
||||
<?php
|
||||
|
||||
namespace Config;
|
||||
|
||||
use CodeIgniter\Config\BaseConfig;
|
||||
|
||||
class Generators extends BaseConfig
|
||||
{
|
||||
/**
|
||||
* --------------------------------------------------------------------------
|
||||
* Generator Commands' Views
|
||||
* --------------------------------------------------------------------------
|
||||
*
|
||||
* This array defines the mapping of generator commands to the view files
|
||||
* they are using. If you need to customize them for your own, copy these
|
||||
* view files in your own folder and indicate the location here.
|
||||
*
|
||||
* You will notice that the views have special placeholders enclosed in
|
||||
* curly braces `{...}`. These placeholders are used internally by the
|
||||
* generator commands in processing replacements, thus you are warned
|
||||
* not to delete them or modify the names. If you will do so, you may
|
||||
* end up disrupting the scaffolding process and throw errors.
|
||||
*
|
||||
* YOU HAVE BEEN WARNED!
|
||||
*
|
||||
* @var array<string, array<string, string>|string>
|
||||
*/
|
||||
public array $views = [
|
||||
'make:cell' => [
|
||||
'class' => 'CodeIgniter\Commands\Generators\Views\cell.tpl.php',
|
||||
'view' => 'CodeIgniter\Commands\Generators\Views\cell_view.tpl.php',
|
||||
],
|
||||
'make:command' => 'CodeIgniter\Commands\Generators\Views\command.tpl.php',
|
||||
'make:config' => 'CodeIgniter\Commands\Generators\Views\config.tpl.php',
|
||||
'make:controller' => 'CodeIgniter\Commands\Generators\Views\controller.tpl.php',
|
||||
'make:entity' => 'CodeIgniter\Commands\Generators\Views\entity.tpl.php',
|
||||
'make:filter' => 'CodeIgniter\Commands\Generators\Views\filter.tpl.php',
|
||||
'make:migration' => 'CodeIgniter\Commands\Generators\Views\migration.tpl.php',
|
||||
'make:model' => 'CodeIgniter\Commands\Generators\Views\model.tpl.php',
|
||||
'make:seeder' => 'CodeIgniter\Commands\Generators\Views\seeder.tpl.php',
|
||||
'make:validation' => 'CodeIgniter\Commands\Generators\Views\validation.tpl.php',
|
||||
'session:migration' => 'CodeIgniter\Commands\Generators\Views\migration.tpl.php',
|
||||
];
|
||||
}
|
||||
|
||||
84
app/Config/Honeypot.php
Executable file → Normal file
84
app/Config/Honeypot.php
Executable file → Normal file
@ -1,42 +1,42 @@
|
||||
<?php
|
||||
|
||||
namespace Config;
|
||||
|
||||
use CodeIgniter\Config\BaseConfig;
|
||||
|
||||
class Honeypot extends BaseConfig
|
||||
{
|
||||
/**
|
||||
* Makes Honeypot visible or not to human
|
||||
*/
|
||||
public bool $hidden = true;
|
||||
|
||||
/**
|
||||
* Honeypot Label Content
|
||||
*/
|
||||
public string $label = 'Fill This Field';
|
||||
|
||||
/**
|
||||
* Honeypot Field Name
|
||||
*/
|
||||
public string $name = 'honeypot';
|
||||
|
||||
/**
|
||||
* Honeypot HTML Template
|
||||
*/
|
||||
public string $template = '<label>{label}</label><input type="text" name="{name}" value="">';
|
||||
|
||||
/**
|
||||
* Honeypot container
|
||||
*
|
||||
* If you enabled CSP, you can remove `style="display:none"`.
|
||||
*/
|
||||
public string $container = '<div style="display:none">{template}</div>';
|
||||
|
||||
/**
|
||||
* The id attribute for Honeypot container tag
|
||||
*
|
||||
* Used when CSP is enabled.
|
||||
*/
|
||||
public string $containerId = 'hpc';
|
||||
}
|
||||
<?php
|
||||
|
||||
namespace Config;
|
||||
|
||||
use CodeIgniter\Config\BaseConfig;
|
||||
|
||||
class Honeypot extends BaseConfig
|
||||
{
|
||||
/**
|
||||
* Makes Honeypot visible or not to human
|
||||
*/
|
||||
public bool $hidden = true;
|
||||
|
||||
/**
|
||||
* Honeypot Label Content
|
||||
*/
|
||||
public string $label = 'Fill This Field';
|
||||
|
||||
/**
|
||||
* Honeypot Field Name
|
||||
*/
|
||||
public string $name = 'honeypot';
|
||||
|
||||
/**
|
||||
* Honeypot HTML Template
|
||||
*/
|
||||
public string $template = '<label>{label}</label><input type="text" name="{name}" value="">';
|
||||
|
||||
/**
|
||||
* Honeypot container
|
||||
*
|
||||
* If you enabled CSP, you can remove `style="display:none"`.
|
||||
*/
|
||||
public string $container = '<div style="display:none">{template}</div>';
|
||||
|
||||
/**
|
||||
* The id attribute for Honeypot container tag
|
||||
*
|
||||
* Used when CSP is enabled.
|
||||
*/
|
||||
public string $containerId = 'hpc';
|
||||
}
|
||||
|
||||
62
app/Config/Images.php
Executable file → Normal file
62
app/Config/Images.php
Executable file → Normal file
@ -1,31 +1,31 @@
|
||||
<?php
|
||||
|
||||
namespace Config;
|
||||
|
||||
use CodeIgniter\Config\BaseConfig;
|
||||
use CodeIgniter\Images\Handlers\GDHandler;
|
||||
use CodeIgniter\Images\Handlers\ImageMagickHandler;
|
||||
|
||||
class Images extends BaseConfig
|
||||
{
|
||||
/**
|
||||
* Default handler used if no other handler is specified.
|
||||
*/
|
||||
public string $defaultHandler = 'gd';
|
||||
|
||||
/**
|
||||
* The path to the image library.
|
||||
* Required for ImageMagick, GraphicsMagick, or NetPBM.
|
||||
*/
|
||||
public string $libraryPath = '/usr/local/bin/convert';
|
||||
|
||||
/**
|
||||
* The available handler classes.
|
||||
*
|
||||
* @var array<string, string>
|
||||
*/
|
||||
public array $handlers = [
|
||||
'gd' => GDHandler::class,
|
||||
'imagick' => ImageMagickHandler::class,
|
||||
];
|
||||
}
|
||||
<?php
|
||||
|
||||
namespace Config;
|
||||
|
||||
use CodeIgniter\Config\BaseConfig;
|
||||
use CodeIgniter\Images\Handlers\GDHandler;
|
||||
use CodeIgniter\Images\Handlers\ImageMagickHandler;
|
||||
|
||||
class Images extends BaseConfig
|
||||
{
|
||||
/**
|
||||
* Default handler used if no other handler is specified.
|
||||
*/
|
||||
public string $defaultHandler = 'gd';
|
||||
|
||||
/**
|
||||
* The path to the image library.
|
||||
* Required for ImageMagick, GraphicsMagick, or NetPBM.
|
||||
*/
|
||||
public string $libraryPath = '/usr/local/bin/convert';
|
||||
|
||||
/**
|
||||
* The available handler classes.
|
||||
*
|
||||
* @var array<string, string>
|
||||
*/
|
||||
public array $handlers = [
|
||||
'gd' => GDHandler::class,
|
||||
'imagick' => ImageMagickHandler::class,
|
||||
];
|
||||
}
|
||||
|
||||
126
app/Config/Kint.php
Executable file → Normal file
126
app/Config/Kint.php
Executable file → Normal file
@ -1,63 +1,63 @@
|
||||
<?php
|
||||
|
||||
namespace Config;
|
||||
|
||||
use Kint\Parser\ConstructablePluginInterface;
|
||||
use Kint\Renderer\Rich\TabPluginInterface;
|
||||
use Kint\Renderer\Rich\ValuePluginInterface;
|
||||
|
||||
/**
|
||||
* --------------------------------------------------------------------------
|
||||
* Kint
|
||||
* --------------------------------------------------------------------------
|
||||
*
|
||||
* We use Kint's `RichRenderer` and `CLIRenderer`. This area contains options
|
||||
* that you can set to customize how Kint works for you.
|
||||
*
|
||||
* @see https://kint-php.github.io/kint/ for details on these settings.
|
||||
*/
|
||||
class Kint
|
||||
{
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Global Settings
|
||||
|--------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
/**
|
||||
* @var list<class-string<ConstructablePluginInterface>|ConstructablePluginInterface>|null
|
||||
*/
|
||||
public $plugins;
|
||||
|
||||
public int $maxDepth = 6;
|
||||
public bool $displayCalledFrom = true;
|
||||
public bool $expanded = false;
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| RichRenderer Settings
|
||||
|--------------------------------------------------------------------------
|
||||
*/
|
||||
public string $richTheme = 'aante-light.css';
|
||||
public bool $richFolder = false;
|
||||
|
||||
/**
|
||||
* @var array<string, class-string<ValuePluginInterface>>|null
|
||||
*/
|
||||
public $richObjectPlugins;
|
||||
|
||||
/**
|
||||
* @var array<string, class-string<TabPluginInterface>>|null
|
||||
*/
|
||||
public $richTabPlugins;
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| CLI Settings
|
||||
|--------------------------------------------------------------------------
|
||||
*/
|
||||
public bool $cliColors = true;
|
||||
public bool $cliForceUTF8 = false;
|
||||
public bool $cliDetectWidth = true;
|
||||
public int $cliMinWidth = 40;
|
||||
}
|
||||
<?php
|
||||
|
||||
namespace Config;
|
||||
|
||||
use Kint\Parser\ConstructablePluginInterface;
|
||||
use Kint\Renderer\Rich\TabPluginInterface;
|
||||
use Kint\Renderer\Rich\ValuePluginInterface;
|
||||
|
||||
/**
|
||||
* --------------------------------------------------------------------------
|
||||
* Kint
|
||||
* --------------------------------------------------------------------------
|
||||
*
|
||||
* We use Kint's `RichRenderer` and `CLIRenderer`. This area contains options
|
||||
* that you can set to customize how Kint works for you.
|
||||
*
|
||||
* @see https://kint-php.github.io/kint/ for details on these settings.
|
||||
*/
|
||||
class Kint
|
||||
{
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Global Settings
|
||||
|--------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
/**
|
||||
* @var list<class-string<ConstructablePluginInterface>|ConstructablePluginInterface>|null
|
||||
*/
|
||||
public $plugins;
|
||||
|
||||
public int $maxDepth = 6;
|
||||
public bool $displayCalledFrom = true;
|
||||
public bool $expanded = false;
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| RichRenderer Settings
|
||||
|--------------------------------------------------------------------------
|
||||
*/
|
||||
public string $richTheme = 'aante-light.css';
|
||||
public bool $richFolder = false;
|
||||
|
||||
/**
|
||||
* @var array<string, class-string<ValuePluginInterface>>|null
|
||||
*/
|
||||
public $richObjectPlugins;
|
||||
|
||||
/**
|
||||
* @var array<string, class-string<TabPluginInterface>>|null
|
||||
*/
|
||||
public $richTabPlugins;
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| CLI Settings
|
||||
|--------------------------------------------------------------------------
|
||||
*/
|
||||
public bool $cliColors = true;
|
||||
public bool $cliForceUTF8 = false;
|
||||
public bool $cliDetectWidth = true;
|
||||
public int $cliMinWidth = 40;
|
||||
}
|
||||
|
||||
300
app/Config/Logger.php
Executable file → Normal file
300
app/Config/Logger.php
Executable file → Normal file
@ -1,150 +1,150 @@
|
||||
<?php
|
||||
|
||||
namespace Config;
|
||||
|
||||
use CodeIgniter\Config\BaseConfig;
|
||||
use CodeIgniter\Log\Handlers\FileHandler;
|
||||
|
||||
class Logger extends BaseConfig
|
||||
{
|
||||
/**
|
||||
* --------------------------------------------------------------------------
|
||||
* Error Logging Threshold
|
||||
* --------------------------------------------------------------------------
|
||||
*
|
||||
* You can enable error logging by setting a threshold over zero. The
|
||||
* threshold determines what gets logged. Any values below or equal to the
|
||||
* threshold will be logged.
|
||||
*
|
||||
* Threshold options are:
|
||||
*
|
||||
* - 0 = Disables logging, Error logging TURNED OFF
|
||||
* - 1 = Emergency Messages - System is unusable
|
||||
* - 2 = Alert Messages - Action Must Be Taken Immediately
|
||||
* - 3 = Critical Messages - Application component unavailable, unexpected exception.
|
||||
* - 4 = Runtime Errors - Don't need immediate action, but should be monitored.
|
||||
* - 5 = Warnings - Exceptional occurrences that are not errors.
|
||||
* - 6 = Notices - Normal but significant events.
|
||||
* - 7 = Info - Interesting events, like user logging in, etc.
|
||||
* - 8 = Debug - Detailed debug information.
|
||||
* - 9 = All Messages
|
||||
*
|
||||
* You can also pass an array with threshold levels to show individual error types
|
||||
*
|
||||
* array(1, 2, 3, 8) = Emergency, Alert, Critical, and Debug messages
|
||||
*
|
||||
* For a live site you'll usually enable Critical or higher (3) to be logged otherwise
|
||||
* your log files will fill up very fast.
|
||||
*
|
||||
* @var int|list<int>
|
||||
*/
|
||||
public $threshold = (ENVIRONMENT === 'production') ? 4 : 9;
|
||||
|
||||
/**
|
||||
* --------------------------------------------------------------------------
|
||||
* Date Format for Logs
|
||||
* --------------------------------------------------------------------------
|
||||
*
|
||||
* Each item that is logged has an associated date. You can use PHP date
|
||||
* codes to set your own date formatting
|
||||
*/
|
||||
public string $dateFormat = 'Y-m-d H:i:s';
|
||||
|
||||
/**
|
||||
* --------------------------------------------------------------------------
|
||||
* Log Handlers
|
||||
* --------------------------------------------------------------------------
|
||||
*
|
||||
* The logging system supports multiple actions to be taken when something
|
||||
* is logged. This is done by allowing for multiple Handlers, special classes
|
||||
* designed to write the log to their chosen destinations, whether that is
|
||||
* a file on the getServer, a cloud-based service, or even taking actions such
|
||||
* as emailing the dev team.
|
||||
*
|
||||
* Each handler is defined by the class name used for that handler, and it
|
||||
* MUST implement the `CodeIgniter\Log\Handlers\HandlerInterface` interface.
|
||||
*
|
||||
* The value of each key is an array of configuration items that are sent
|
||||
* to the constructor of each handler. The only required configuration item
|
||||
* is the 'handles' element, which must be an array of integer log levels.
|
||||
* This is most easily handled by using the constants defined in the
|
||||
* `Psr\Log\LogLevel` class.
|
||||
*
|
||||
* Handlers are executed in the order defined in this array, starting with
|
||||
* the handler on top and continuing down.
|
||||
*
|
||||
* @var array<class-string, array<string, int|list<string>|string>>
|
||||
*/
|
||||
public array $handlers = [
|
||||
/*
|
||||
* --------------------------------------------------------------------
|
||||
* File Handler
|
||||
* --------------------------------------------------------------------
|
||||
*/
|
||||
FileHandler::class => [
|
||||
// The log levels that this handler will handle.
|
||||
'handles' => [
|
||||
'critical',
|
||||
'alert',
|
||||
'emergency',
|
||||
'debug',
|
||||
'error',
|
||||
'info',
|
||||
'notice',
|
||||
'warning',
|
||||
],
|
||||
|
||||
/*
|
||||
* The default filename extension for log files.
|
||||
* An extension of 'php' allows for protecting the log files via basic
|
||||
* scripting, when they are to be stored under a publicly accessible directory.
|
||||
*
|
||||
* NOTE: Leaving it blank will default to 'log'.
|
||||
*/
|
||||
'fileExtension' => '',
|
||||
|
||||
/*
|
||||
* The file system permissions to be applied on newly created log files.
|
||||
*
|
||||
* IMPORTANT: This MUST be an integer (no quotes) and you MUST use octal
|
||||
* integer notation (i.e. 0700, 0644, etc.)
|
||||
*/
|
||||
'filePermissions' => 0644,
|
||||
|
||||
/*
|
||||
* Logging Directory Path
|
||||
*
|
||||
* By default, logs are written to WRITEPATH . 'logs/'
|
||||
* Specify a different destination here, if desired.
|
||||
*/
|
||||
'path' => '',
|
||||
],
|
||||
|
||||
/*
|
||||
* The ChromeLoggerHandler requires the use of the Chrome web browser
|
||||
* and the ChromeLogger extension. Uncomment this block to use it.
|
||||
*/
|
||||
// 'CodeIgniter\Log\Handlers\ChromeLoggerHandler' => [
|
||||
// /*
|
||||
// * The log levels that this handler will handle.
|
||||
// */
|
||||
// 'handles' => ['critical', 'alert', 'emergency', 'debug',
|
||||
// 'error', 'info', 'notice', 'warning'],
|
||||
// ],
|
||||
|
||||
/*
|
||||
* The ErrorlogHandler writes the logs to PHP's native `error_log()` function.
|
||||
* Uncomment this block to use it.
|
||||
*/
|
||||
// 'CodeIgniter\Log\Handlers\ErrorlogHandler' => [
|
||||
// /* The log levels this handler can handle. */
|
||||
// 'handles' => ['critical', 'alert', 'emergency', 'debug', 'error', 'info', 'notice', 'warning'],
|
||||
//
|
||||
// /*
|
||||
// * The message type where the error should go. Can be 0 or 4, or use the
|
||||
// * class constants: `ErrorlogHandler::TYPE_OS` (0) or `ErrorlogHandler::TYPE_SAPI` (4)
|
||||
// */
|
||||
// 'messageType' => 0,
|
||||
// ],
|
||||
];
|
||||
}
|
||||
<?php
|
||||
|
||||
namespace Config;
|
||||
|
||||
use CodeIgniter\Config\BaseConfig;
|
||||
use CodeIgniter\Log\Handlers\FileHandler;
|
||||
|
||||
class Logger extends BaseConfig
|
||||
{
|
||||
/**
|
||||
* --------------------------------------------------------------------------
|
||||
* Error Logging Threshold
|
||||
* --------------------------------------------------------------------------
|
||||
*
|
||||
* You can enable error logging by setting a threshold over zero. The
|
||||
* threshold determines what gets logged. Any values below or equal to the
|
||||
* threshold will be logged.
|
||||
*
|
||||
* Threshold options are:
|
||||
*
|
||||
* - 0 = Disables logging, Error logging TURNED OFF
|
||||
* - 1 = Emergency Messages - System is unusable
|
||||
* - 2 = Alert Messages - Action Must Be Taken Immediately
|
||||
* - 3 = Critical Messages - Application component unavailable, unexpected exception.
|
||||
* - 4 = Runtime Errors - Don't need immediate action, but should be monitored.
|
||||
* - 5 = Warnings - Exceptional occurrences that are not errors.
|
||||
* - 6 = Notices - Normal but significant events.
|
||||
* - 7 = Info - Interesting events, like user logging in, etc.
|
||||
* - 8 = Debug - Detailed debug information.
|
||||
* - 9 = All Messages
|
||||
*
|
||||
* You can also pass an array with threshold levels to show individual error types
|
||||
*
|
||||
* array(1, 2, 3, 8) = Emergency, Alert, Critical, and Debug messages
|
||||
*
|
||||
* For a live site you'll usually enable Critical or higher (3) to be logged otherwise
|
||||
* your log files will fill up very fast.
|
||||
*
|
||||
* @var int|list<int>
|
||||
*/
|
||||
public $threshold = (ENVIRONMENT === 'production') ? 4 : 9;
|
||||
|
||||
/**
|
||||
* --------------------------------------------------------------------------
|
||||
* Date Format for Logs
|
||||
* --------------------------------------------------------------------------
|
||||
*
|
||||
* Each item that is logged has an associated date. You can use PHP date
|
||||
* codes to set your own date formatting
|
||||
*/
|
||||
public string $dateFormat = 'Y-m-d H:i:s';
|
||||
|
||||
/**
|
||||
* --------------------------------------------------------------------------
|
||||
* Log Handlers
|
||||
* --------------------------------------------------------------------------
|
||||
*
|
||||
* The logging system supports multiple actions to be taken when something
|
||||
* is logged. This is done by allowing for multiple Handlers, special classes
|
||||
* designed to write the log to their chosen destinations, whether that is
|
||||
* a file on the getServer, a cloud-based service, or even taking actions such
|
||||
* as emailing the dev team.
|
||||
*
|
||||
* Each handler is defined by the class name used for that handler, and it
|
||||
* MUST implement the `CodeIgniter\Log\Handlers\HandlerInterface` interface.
|
||||
*
|
||||
* The value of each key is an array of configuration items that are sent
|
||||
* to the constructor of each handler. The only required configuration item
|
||||
* is the 'handles' element, which must be an array of integer log levels.
|
||||
* This is most easily handled by using the constants defined in the
|
||||
* `Psr\Log\LogLevel` class.
|
||||
*
|
||||
* Handlers are executed in the order defined in this array, starting with
|
||||
* the handler on top and continuing down.
|
||||
*
|
||||
* @var array<class-string, array<string, int|list<string>|string>>
|
||||
*/
|
||||
public array $handlers = [
|
||||
/*
|
||||
* --------------------------------------------------------------------
|
||||
* File Handler
|
||||
* --------------------------------------------------------------------
|
||||
*/
|
||||
FileHandler::class => [
|
||||
// The log levels that this handler will handle.
|
||||
'handles' => [
|
||||
'critical',
|
||||
'alert',
|
||||
'emergency',
|
||||
'debug',
|
||||
'error',
|
||||
'info',
|
||||
'notice',
|
||||
'warning',
|
||||
],
|
||||
|
||||
/*
|
||||
* The default filename extension for log files.
|
||||
* An extension of 'php' allows for protecting the log files via basic
|
||||
* scripting, when they are to be stored under a publicly accessible directory.
|
||||
*
|
||||
* NOTE: Leaving it blank will default to 'log'.
|
||||
*/
|
||||
'fileExtension' => '',
|
||||
|
||||
/*
|
||||
* The file system permissions to be applied on newly created log files.
|
||||
*
|
||||
* IMPORTANT: This MUST be an integer (no quotes) and you MUST use octal
|
||||
* integer notation (i.e. 0700, 0644, etc.)
|
||||
*/
|
||||
'filePermissions' => 0644,
|
||||
|
||||
/*
|
||||
* Logging Directory Path
|
||||
*
|
||||
* By default, logs are written to WRITEPATH . 'logs/'
|
||||
* Specify a different destination here, if desired.
|
||||
*/
|
||||
'path' => '',
|
||||
],
|
||||
|
||||
/*
|
||||
* The ChromeLoggerHandler requires the use of the Chrome web browser
|
||||
* and the ChromeLogger extension. Uncomment this block to use it.
|
||||
*/
|
||||
// 'CodeIgniter\Log\Handlers\ChromeLoggerHandler' => [
|
||||
// /*
|
||||
// * The log levels that this handler will handle.
|
||||
// */
|
||||
// 'handles' => ['critical', 'alert', 'emergency', 'debug',
|
||||
// 'error', 'info', 'notice', 'warning'],
|
||||
// ],
|
||||
|
||||
/*
|
||||
* The ErrorlogHandler writes the logs to PHP's native `error_log()` function.
|
||||
* Uncomment this block to use it.
|
||||
*/
|
||||
// 'CodeIgniter\Log\Handlers\ErrorlogHandler' => [
|
||||
// /* The log levels this handler can handle. */
|
||||
// 'handles' => ['critical', 'alert', 'emergency', 'debug', 'error', 'info', 'notice', 'warning'],
|
||||
//
|
||||
// /*
|
||||
// * The message type where the error should go. Can be 0 or 4, or use the
|
||||
// * class constants: `ErrorlogHandler::TYPE_OS` (0) or `ErrorlogHandler::TYPE_SAPI` (4)
|
||||
// */
|
||||
// 'messageType' => 0,
|
||||
// ],
|
||||
];
|
||||
}
|
||||
|
||||
100
app/Config/Migrations.php
Executable file → Normal file
100
app/Config/Migrations.php
Executable file → Normal file
@ -1,50 +1,50 @@
|
||||
<?php
|
||||
|
||||
namespace Config;
|
||||
|
||||
use CodeIgniter\Config\BaseConfig;
|
||||
|
||||
class Migrations extends BaseConfig
|
||||
{
|
||||
/**
|
||||
* --------------------------------------------------------------------------
|
||||
* Enable/Disable Migrations
|
||||
* --------------------------------------------------------------------------
|
||||
*
|
||||
* Migrations are enabled by default.
|
||||
*
|
||||
* You should enable migrations whenever you intend to do a schema migration
|
||||
* and disable it back when you're done.
|
||||
*/
|
||||
public bool $enabled = true;
|
||||
|
||||
/**
|
||||
* --------------------------------------------------------------------------
|
||||
* Migrations Table
|
||||
* --------------------------------------------------------------------------
|
||||
*
|
||||
* This is the name of the table that will store the current migrations state.
|
||||
* When migrations runs it will store in a database table which migration
|
||||
* files have already been run.
|
||||
*/
|
||||
public string $table = 'migrations';
|
||||
|
||||
/**
|
||||
* --------------------------------------------------------------------------
|
||||
* Timestamp Format
|
||||
* --------------------------------------------------------------------------
|
||||
*
|
||||
* This is the format that will be used when creating new migrations
|
||||
* using the CLI command:
|
||||
* > php spark make:migration
|
||||
*
|
||||
* NOTE: if you set an unsupported format, migration runner will not find
|
||||
* your migration files.
|
||||
*
|
||||
* Supported formats:
|
||||
* - YmdHis_
|
||||
* - Y-m-d-His_
|
||||
* - Y_m_d_His_
|
||||
*/
|
||||
public string $timestampFormat = 'Y-m-d-His_';
|
||||
}
|
||||
<?php
|
||||
|
||||
namespace Config;
|
||||
|
||||
use CodeIgniter\Config\BaseConfig;
|
||||
|
||||
class Migrations extends BaseConfig
|
||||
{
|
||||
/**
|
||||
* --------------------------------------------------------------------------
|
||||
* Enable/Disable Migrations
|
||||
* --------------------------------------------------------------------------
|
||||
*
|
||||
* Migrations are enabled by default.
|
||||
*
|
||||
* You should enable migrations whenever you intend to do a schema migration
|
||||
* and disable it back when you're done.
|
||||
*/
|
||||
public bool $enabled = true;
|
||||
|
||||
/**
|
||||
* --------------------------------------------------------------------------
|
||||
* Migrations Table
|
||||
* --------------------------------------------------------------------------
|
||||
*
|
||||
* This is the name of the table that will store the current migrations state.
|
||||
* When migrations runs it will store in a database table which migration
|
||||
* files have already been run.
|
||||
*/
|
||||
public string $table = 'migrations';
|
||||
|
||||
/**
|
||||
* --------------------------------------------------------------------------
|
||||
* Timestamp Format
|
||||
* --------------------------------------------------------------------------
|
||||
*
|
||||
* This is the format that will be used when creating new migrations
|
||||
* using the CLI command:
|
||||
* > php spark make:migration
|
||||
*
|
||||
* NOTE: if you set an unsupported format, migration runner will not find
|
||||
* your migration files.
|
||||
*
|
||||
* Supported formats:
|
||||
* - YmdHis_
|
||||
* - Y-m-d-His_
|
||||
* - Y_m_d_His_
|
||||
*/
|
||||
public string $timestampFormat = 'Y-m-d-His_';
|
||||
}
|
||||
|
||||
1068
app/Config/Mimes.php
Executable file → Normal file
1068
app/Config/Mimes.php
Executable file → Normal file
File diff suppressed because it is too large
Load Diff
164
app/Config/Modules.php
Executable file → Normal file
164
app/Config/Modules.php
Executable file → Normal file
@ -1,82 +1,82 @@
|
||||
<?php
|
||||
|
||||
namespace Config;
|
||||
|
||||
use CodeIgniter\Modules\Modules as BaseModules;
|
||||
|
||||
/**
|
||||
* Modules Configuration.
|
||||
*
|
||||
* NOTE: This class is required prior to Autoloader instantiation,
|
||||
* and does not extend BaseConfig.
|
||||
*/
|
||||
class Modules extends BaseModules
|
||||
{
|
||||
/**
|
||||
* --------------------------------------------------------------------------
|
||||
* Enable Auto-Discovery?
|
||||
* --------------------------------------------------------------------------
|
||||
*
|
||||
* If true, then auto-discovery will happen across all elements listed in
|
||||
* $aliases below. If false, no auto-discovery will happen at all,
|
||||
* giving a slight performance boost.
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
public $enabled = true;
|
||||
|
||||
/**
|
||||
* --------------------------------------------------------------------------
|
||||
* Enable Auto-Discovery Within Composer Packages?
|
||||
* --------------------------------------------------------------------------
|
||||
*
|
||||
* If true, then auto-discovery will happen across all namespaces loaded
|
||||
* by Composer, as well as the namespaces configured locally.
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
public $discoverInComposer = true;
|
||||
|
||||
/**
|
||||
* The Composer package list for Auto-Discovery
|
||||
* This setting is optional.
|
||||
*
|
||||
* E.g.:
|
||||
* [
|
||||
* 'only' => [
|
||||
* // List up all packages to auto-discover
|
||||
* 'codeigniter4/shield',
|
||||
* ],
|
||||
* ]
|
||||
* or
|
||||
* [
|
||||
* 'exclude' => [
|
||||
* // List up packages to exclude.
|
||||
* 'pestphp/pest',
|
||||
* ],
|
||||
* ]
|
||||
*
|
||||
* @var array{only?: list<string>, exclude?: list<string>}
|
||||
*/
|
||||
public $composerPackages = [];
|
||||
|
||||
/**
|
||||
* --------------------------------------------------------------------------
|
||||
* Auto-Discovery Rules
|
||||
* --------------------------------------------------------------------------
|
||||
*
|
||||
* Aliases list of all discovery classes that will be active and used during
|
||||
* the current application request.
|
||||
*
|
||||
* If it is not listed, only the base application elements will be used.
|
||||
*
|
||||
* @var list<string>
|
||||
*/
|
||||
public $aliases = [
|
||||
'events',
|
||||
'filters',
|
||||
'registrars',
|
||||
'routes',
|
||||
'services',
|
||||
];
|
||||
}
|
||||
<?php
|
||||
|
||||
namespace Config;
|
||||
|
||||
use CodeIgniter\Modules\Modules as BaseModules;
|
||||
|
||||
/**
|
||||
* Modules Configuration.
|
||||
*
|
||||
* NOTE: This class is required prior to Autoloader instantiation,
|
||||
* and does not extend BaseConfig.
|
||||
*/
|
||||
class Modules extends BaseModules
|
||||
{
|
||||
/**
|
||||
* --------------------------------------------------------------------------
|
||||
* Enable Auto-Discovery?
|
||||
* --------------------------------------------------------------------------
|
||||
*
|
||||
* If true, then auto-discovery will happen across all elements listed in
|
||||
* $aliases below. If false, no auto-discovery will happen at all,
|
||||
* giving a slight performance boost.
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
public $enabled = true;
|
||||
|
||||
/**
|
||||
* --------------------------------------------------------------------------
|
||||
* Enable Auto-Discovery Within Composer Packages?
|
||||
* --------------------------------------------------------------------------
|
||||
*
|
||||
* If true, then auto-discovery will happen across all namespaces loaded
|
||||
* by Composer, as well as the namespaces configured locally.
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
public $discoverInComposer = true;
|
||||
|
||||
/**
|
||||
* The Composer package list for Auto-Discovery
|
||||
* This setting is optional.
|
||||
*
|
||||
* E.g.:
|
||||
* [
|
||||
* 'only' => [
|
||||
* // List up all packages to auto-discover
|
||||
* 'codeigniter4/shield',
|
||||
* ],
|
||||
* ]
|
||||
* or
|
||||
* [
|
||||
* 'exclude' => [
|
||||
* // List up packages to exclude.
|
||||
* 'pestphp/pest',
|
||||
* ],
|
||||
* ]
|
||||
*
|
||||
* @var array{only?: list<string>, exclude?: list<string>}
|
||||
*/
|
||||
public $composerPackages = [];
|
||||
|
||||
/**
|
||||
* --------------------------------------------------------------------------
|
||||
* Auto-Discovery Rules
|
||||
* --------------------------------------------------------------------------
|
||||
*
|
||||
* Aliases list of all discovery classes that will be active and used during
|
||||
* the current application request.
|
||||
*
|
||||
* If it is not listed, only the base application elements will be used.
|
||||
*
|
||||
* @var list<string>
|
||||
*/
|
||||
public $aliases = [
|
||||
'events',
|
||||
'filters',
|
||||
'registrars',
|
||||
'routes',
|
||||
'services',
|
||||
];
|
||||
}
|
||||
|
||||
60
app/Config/Optimize.php
Executable file → Normal file
60
app/Config/Optimize.php
Executable file → Normal file
@ -1,30 +1,30 @@
|
||||
<?php
|
||||
|
||||
namespace Config;
|
||||
|
||||
/**
|
||||
* Optimization Configuration.
|
||||
*
|
||||
* NOTE: This class does not extend BaseConfig for performance reasons.
|
||||
* So you cannot replace the property values with Environment Variables.
|
||||
*/
|
||||
class Optimize
|
||||
{
|
||||
/**
|
||||
* --------------------------------------------------------------------------
|
||||
* Config Caching
|
||||
* --------------------------------------------------------------------------
|
||||
*
|
||||
* @see https://codeigniter.com/user_guide/concepts/factories.html#config-caching
|
||||
*/
|
||||
public bool $configCacheEnabled = false;
|
||||
|
||||
/**
|
||||
* --------------------------------------------------------------------------
|
||||
* Config Caching
|
||||
* --------------------------------------------------------------------------
|
||||
*
|
||||
* @see https://codeigniter.com/user_guide/concepts/autoloader.html#file-locator-caching
|
||||
*/
|
||||
public bool $locatorCacheEnabled = false;
|
||||
}
|
||||
<?php
|
||||
|
||||
namespace Config;
|
||||
|
||||
/**
|
||||
* Optimization Configuration.
|
||||
*
|
||||
* NOTE: This class does not extend BaseConfig for performance reasons.
|
||||
* So you cannot replace the property values with Environment Variables.
|
||||
*/
|
||||
class Optimize
|
||||
{
|
||||
/**
|
||||
* --------------------------------------------------------------------------
|
||||
* Config Caching
|
||||
* --------------------------------------------------------------------------
|
||||
*
|
||||
* @see https://codeigniter.com/user_guide/concepts/factories.html#config-caching
|
||||
*/
|
||||
public bool $configCacheEnabled = false;
|
||||
|
||||
/**
|
||||
* --------------------------------------------------------------------------
|
||||
* Config Caching
|
||||
* --------------------------------------------------------------------------
|
||||
*
|
||||
* @see https://codeigniter.com/user_guide/concepts/autoloader.html#file-locator-caching
|
||||
*/
|
||||
public bool $locatorCacheEnabled = false;
|
||||
}
|
||||
|
||||
74
app/Config/Pager.php
Executable file → Normal file
74
app/Config/Pager.php
Executable file → Normal file
@ -1,37 +1,37 @@
|
||||
<?php
|
||||
|
||||
namespace Config;
|
||||
|
||||
use CodeIgniter\Config\BaseConfig;
|
||||
|
||||
class Pager extends BaseConfig
|
||||
{
|
||||
/**
|
||||
* --------------------------------------------------------------------------
|
||||
* Templates
|
||||
* --------------------------------------------------------------------------
|
||||
*
|
||||
* Pagination links are rendered out using views to configure their
|
||||
* appearance. This array contains aliases and the view names to
|
||||
* use when rendering the links.
|
||||
*
|
||||
* Within each view, the Pager object will be available as $pager,
|
||||
* and the desired group as $pagerGroup;
|
||||
*
|
||||
* @var array<string, string>
|
||||
*/
|
||||
public array $templates = [
|
||||
'default_full' => 'CodeIgniter\Pager\Views\default_full',
|
||||
'default_simple' => 'CodeIgniter\Pager\Views\default_simple',
|
||||
'default_head' => 'CodeIgniter\Pager\Views\default_head',
|
||||
];
|
||||
|
||||
/**
|
||||
* --------------------------------------------------------------------------
|
||||
* Items Per Page
|
||||
* --------------------------------------------------------------------------
|
||||
*
|
||||
* The default number of results shown in a single page.
|
||||
*/
|
||||
public int $perPage = 20;
|
||||
}
|
||||
<?php
|
||||
|
||||
namespace Config;
|
||||
|
||||
use CodeIgniter\Config\BaseConfig;
|
||||
|
||||
class Pager extends BaseConfig
|
||||
{
|
||||
/**
|
||||
* --------------------------------------------------------------------------
|
||||
* Templates
|
||||
* --------------------------------------------------------------------------
|
||||
*
|
||||
* Pagination links are rendered out using views to configure their
|
||||
* appearance. This array contains aliases and the view names to
|
||||
* use when rendering the links.
|
||||
*
|
||||
* Within each view, the Pager object will be available as $pager,
|
||||
* and the desired group as $pagerGroup;
|
||||
*
|
||||
* @var array<string, string>
|
||||
*/
|
||||
public array $templates = [
|
||||
'default_full' => 'CodeIgniter\Pager\Views\default_full',
|
||||
'default_simple' => 'CodeIgniter\Pager\Views\default_simple',
|
||||
'default_head' => 'CodeIgniter\Pager\Views\default_head',
|
||||
];
|
||||
|
||||
/**
|
||||
* --------------------------------------------------------------------------
|
||||
* Items Per Page
|
||||
* --------------------------------------------------------------------------
|
||||
*
|
||||
* The default number of results shown in a single page.
|
||||
*/
|
||||
public int $perPage = 20;
|
||||
}
|
||||
|
||||
150
app/Config/Paths.php
Executable file → Normal file
150
app/Config/Paths.php
Executable file → Normal file
@ -1,75 +1,75 @@
|
||||
<?php
|
||||
|
||||
namespace Config;
|
||||
|
||||
/**
|
||||
* Paths
|
||||
*
|
||||
* Holds the paths that are used by the system to
|
||||
* locate the main directories, app, system, etc.
|
||||
*
|
||||
* Modifying these allows you to restructure your application,
|
||||
* share a system folder between multiple applications, and more.
|
||||
*
|
||||
* All paths are relative to the project's root folder.
|
||||
*/
|
||||
class Paths
|
||||
{
|
||||
/**
|
||||
* ---------------------------------------------------------------
|
||||
* SYSTEM FOLDER NAME
|
||||
* ---------------------------------------------------------------
|
||||
*
|
||||
* This must contain the name of your "system" folder. Include
|
||||
* the path if the folder is not in the same directory as this file.
|
||||
*/
|
||||
public string $systemDirectory = __DIR__ . '/../../vendor/codeigniter4/framework/system';
|
||||
|
||||
/**
|
||||
* ---------------------------------------------------------------
|
||||
* APPLICATION FOLDER NAME
|
||||
* ---------------------------------------------------------------
|
||||
*
|
||||
* If you want this front controller to use a different "app"
|
||||
* folder than the default one you can set its name here. The folder
|
||||
* can also be renamed or relocated anywhere on your server. If
|
||||
* you do, use a full server path.
|
||||
*
|
||||
* @see http://codeigniter.com/user_guide/general/managing_apps.html
|
||||
*/
|
||||
public string $appDirectory = __DIR__ . '/..';
|
||||
|
||||
/**
|
||||
* ---------------------------------------------------------------
|
||||
* WRITABLE DIRECTORY NAME
|
||||
* ---------------------------------------------------------------
|
||||
*
|
||||
* This variable must contain the name of your "writable" directory.
|
||||
* The writable directory allows you to group all directories that
|
||||
* need write permission to a single place that can be tucked away
|
||||
* for maximum security, keeping it out of the app and/or
|
||||
* system directories.
|
||||
*/
|
||||
public string $writableDirectory = __DIR__ . '/../../writable';
|
||||
|
||||
/**
|
||||
* ---------------------------------------------------------------
|
||||
* TESTS DIRECTORY NAME
|
||||
* ---------------------------------------------------------------
|
||||
*
|
||||
* This variable must contain the name of your "tests" directory.
|
||||
*/
|
||||
public string $testsDirectory = __DIR__ . '/../../tests';
|
||||
|
||||
/**
|
||||
* ---------------------------------------------------------------
|
||||
* VIEW DIRECTORY NAME
|
||||
* ---------------------------------------------------------------
|
||||
*
|
||||
* This variable must contain the name of the directory that
|
||||
* contains the view files used by your application. By
|
||||
* default this is in `app/Views`. This value
|
||||
* is used when no value is provided to `Services::renderer()`.
|
||||
*/
|
||||
public string $viewDirectory = __DIR__ . '/../Views';
|
||||
}
|
||||
<?php
|
||||
|
||||
namespace Config;
|
||||
|
||||
/**
|
||||
* Paths
|
||||
*
|
||||
* Holds the paths that are used by the system to
|
||||
* locate the main directories, app, system, etc.
|
||||
*
|
||||
* Modifying these allows you to restructure your application,
|
||||
* share a system folder between multiple applications, and more.
|
||||
*
|
||||
* All paths are relative to the project's root folder.
|
||||
*/
|
||||
class Paths
|
||||
{
|
||||
/**
|
||||
* ---------------------------------------------------------------
|
||||
* SYSTEM FOLDER NAME
|
||||
* ---------------------------------------------------------------
|
||||
*
|
||||
* This must contain the name of your "system" folder. Include
|
||||
* the path if the folder is not in the same directory as this file.
|
||||
*/
|
||||
public string $systemDirectory = __DIR__ . '/../../vendor/codeigniter4/framework/system';
|
||||
|
||||
/**
|
||||
* ---------------------------------------------------------------
|
||||
* APPLICATION FOLDER NAME
|
||||
* ---------------------------------------------------------------
|
||||
*
|
||||
* If you want this front controller to use a different "app"
|
||||
* folder than the default one you can set its name here. The folder
|
||||
* can also be renamed or relocated anywhere on your server. If
|
||||
* you do, use a full server path.
|
||||
*
|
||||
* @see http://codeigniter.com/user_guide/general/managing_apps.html
|
||||
*/
|
||||
public string $appDirectory = __DIR__ . '/..';
|
||||
|
||||
/**
|
||||
* ---------------------------------------------------------------
|
||||
* WRITABLE DIRECTORY NAME
|
||||
* ---------------------------------------------------------------
|
||||
*
|
||||
* This variable must contain the name of your "writable" directory.
|
||||
* The writable directory allows you to group all directories that
|
||||
* need write permission to a single place that can be tucked away
|
||||
* for maximum security, keeping it out of the app and/or
|
||||
* system directories.
|
||||
*/
|
||||
public string $writableDirectory = __DIR__ . '/../../writable';
|
||||
|
||||
/**
|
||||
* ---------------------------------------------------------------
|
||||
* TESTS DIRECTORY NAME
|
||||
* ---------------------------------------------------------------
|
||||
*
|
||||
* This variable must contain the name of your "tests" directory.
|
||||
*/
|
||||
public string $testsDirectory = __DIR__ . '/../../tests';
|
||||
|
||||
/**
|
||||
* ---------------------------------------------------------------
|
||||
* VIEW DIRECTORY NAME
|
||||
* ---------------------------------------------------------------
|
||||
*
|
||||
* This variable must contain the name of the directory that
|
||||
* contains the view files used by your application. By
|
||||
* default this is in `app/Views`. This value
|
||||
* is used when no value is provided to `Services::renderer()`.
|
||||
*/
|
||||
public string $viewDirectory = __DIR__ . '/../Views';
|
||||
}
|
||||
|
||||
56
app/Config/Publisher.php
Executable file → Normal file
56
app/Config/Publisher.php
Executable file → Normal file
@ -1,28 +1,28 @@
|
||||
<?php
|
||||
|
||||
namespace Config;
|
||||
|
||||
use CodeIgniter\Config\Publisher as BasePublisher;
|
||||
|
||||
/**
|
||||
* Publisher Configuration
|
||||
*
|
||||
* Defines basic security restrictions for the Publisher class
|
||||
* to prevent abuse by injecting malicious files into a project.
|
||||
*/
|
||||
class Publisher extends BasePublisher
|
||||
{
|
||||
/**
|
||||
* A list of allowed destinations with a (pseudo-)regex
|
||||
* of allowed files for each destination.
|
||||
* Attempts to publish to directories not in this list will
|
||||
* result in a PublisherException. Files that do no fit the
|
||||
* pattern will cause copy/merge to fail.
|
||||
*
|
||||
* @var array<string, string>
|
||||
*/
|
||||
public $restrictions = [
|
||||
ROOTPATH => '*',
|
||||
FCPATH => '#\.(s?css|js|map|html?|xml|json|webmanifest|ttf|eot|woff2?|gif|jpe?g|tiff?|png|webp|bmp|ico|svg)$#i',
|
||||
];
|
||||
}
|
||||
<?php
|
||||
|
||||
namespace Config;
|
||||
|
||||
use CodeIgniter\Config\Publisher as BasePublisher;
|
||||
|
||||
/**
|
||||
* Publisher Configuration
|
||||
*
|
||||
* Defines basic security restrictions for the Publisher class
|
||||
* to prevent abuse by injecting malicious files into a project.
|
||||
*/
|
||||
class Publisher extends BasePublisher
|
||||
{
|
||||
/**
|
||||
* A list of allowed destinations with a (pseudo-)regex
|
||||
* of allowed files for each destination.
|
||||
* Attempts to publish to directories not in this list will
|
||||
* result in a PublisherException. Files that do no fit the
|
||||
* pattern will cause copy/merge to fail.
|
||||
*
|
||||
* @var array<string, string>
|
||||
*/
|
||||
public $restrictions = [
|
||||
ROOTPATH => '*',
|
||||
FCPATH => '#\.(s?css|js|map|html?|xml|json|webmanifest|ttf|eot|woff2?|gif|jpe?g|tiff?|png|webp|bmp|ico|svg)$#i',
|
||||
];
|
||||
}
|
||||
|
||||
696
app/Config/Routes.php
Executable file → Normal file
696
app/Config/Routes.php
Executable file → Normal file
@ -1,388 +1,316 @@
|
||||
<?php
|
||||
|
||||
use CodeIgniter\Router\RouteCollection;
|
||||
|
||||
/**
|
||||
* @var RouteCollection $routes
|
||||
*/
|
||||
$routes->get('/', function () {
|
||||
return "Backend Running";
|
||||
});
|
||||
|
||||
$routes->options('(:any)', function () {
|
||||
return '';
|
||||
});
|
||||
|
||||
$routes->group('api', ['filter' => 'auth'], function ($routes) {
|
||||
<?php
|
||||
|
||||
use CodeIgniter\Router\RouteCollection;
|
||||
|
||||
/**
|
||||
* @var RouteCollection $routes
|
||||
*/
|
||||
$routes->get('/', function () {
|
||||
return redirect()->to('/v2');
|
||||
});
|
||||
|
||||
$routes->options('(:any)', function () {
|
||||
return '';
|
||||
});
|
||||
|
||||
$routes->group('api', ['filter' => 'auth'], function ($routes) {
|
||||
$routes->get('dashboard', 'DashboardController::index');
|
||||
$routes->get('result', 'ResultController::index');
|
||||
$routes->get('sample', 'SampleController::index');
|
||||
$routes->get('audit-logs', 'Audit\AuditLogController::index');
|
||||
|
||||
// Results CRUD
|
||||
$routes->group('result', function ($routes) {
|
||||
$routes->get('/', 'ResultController::index');
|
||||
$routes->post('/', 'ResultController::create');
|
||||
$routes->get('(:num)', 'ResultController::show/$1');
|
||||
$routes->patch('(:any)', 'ResultController::update/$1');
|
||||
$routes->delete('(:num)', 'ResultController::delete/$1');
|
||||
});
|
||||
|
||||
// Reports
|
||||
$routes->get('report/(:num)', 'ReportController::view/$1');
|
||||
});
|
||||
|
||||
|
||||
|
||||
// V2 Auth API Routes (public - no auth required)
|
||||
$routes->group('v2/auth', function ($routes) {
|
||||
$routes->post('login', 'AuthV2Controller::login');
|
||||
$routes->post('register', 'AuthV2Controller::register');
|
||||
$routes->get('check', 'AuthV2Controller::checkAuth');
|
||||
$routes->post('logout', 'AuthV2Controller::logout');
|
||||
});
|
||||
|
||||
// Faker
|
||||
$routes->get('faker/faker-patient/(:num)', 'faker\FakerPatient::sendMany/$1');
|
||||
|
||||
$routes->group('api', function ($routes) {
|
||||
// Auth
|
||||
$routes->group('auth', function ($routes) {
|
||||
$routes->post('login', 'AuthController::login');
|
||||
$routes->post('change_pass', 'AuthController::change_pass');
|
||||
$routes->post('register', 'AuthController::register');
|
||||
$routes->get('check', 'AuthController::checkAuth');
|
||||
$routes->post('logout', 'AuthController::logout');
|
||||
});
|
||||
|
||||
// Patient
|
||||
$routes->group('patient', function ($routes) {
|
||||
$routes->get('/', 'Patient\PatientController::index');
|
||||
$routes->post('/', 'Patient\PatientController::create');
|
||||
$routes->get('(:num)', 'Patient\PatientController::show/$1');
|
||||
$routes->delete('/', 'Patient\PatientController::delete');
|
||||
$routes->patch('(:any)', 'Patient\PatientController::update/$1');
|
||||
$routes->get('check', 'Patient\PatientController::patientCheck');
|
||||
});
|
||||
|
||||
// PatVisit
|
||||
$routes->group('patvisit', function ($routes) {
|
||||
$routes->get('/', 'PatVisitController::index');
|
||||
$routes->post('/', 'PatVisitController::create');
|
||||
$routes->get('patient/(:num)', 'PatVisitController::showByPatient/$1');
|
||||
$routes->get('(:any)', 'PatVisitController::show/$1');
|
||||
$routes->delete('/', 'PatVisitController::delete');
|
||||
$routes->patch('(:any)', 'PatVisitController::update/$1');
|
||||
});
|
||||
|
||||
$routes->group('patvisitadt', function ($routes) {
|
||||
$routes->get('visit/(:num)', 'PatVisitController::getADTByVisit/$1');
|
||||
$routes->get('(:num)', 'PatVisitController::showADT/$1');
|
||||
$routes->post('/', 'PatVisitController::createADT');
|
||||
$routes->patch('(:any)', 'PatVisitController::updateADT/$1');
|
||||
$routes->delete('/', 'PatVisitController::deleteADT');
|
||||
});
|
||||
|
||||
// Master Data
|
||||
|
||||
// Location
|
||||
$routes->group('location', function ($routes) {
|
||||
$routes->get('/', 'LocationController::index');
|
||||
$routes->get('(:num)', 'LocationController::show/$1');
|
||||
$routes->post('/', 'LocationController::create');
|
||||
$routes->patch('(:any)', 'LocationController::update/$1');
|
||||
$routes->delete('/', 'LocationController::delete');
|
||||
});
|
||||
|
||||
// Contact
|
||||
$routes->group('contact', function ($routes) {
|
||||
$routes->get('/', 'Contact\ContactController::index');
|
||||
$routes->get('(:num)', 'Contact\ContactController::show/$1');
|
||||
$routes->post('/', 'Contact\ContactController::create');
|
||||
$routes->patch('(:any)', 'Contact\ContactController::update/$1');
|
||||
$routes->delete('/', 'Contact\ContactController::delete');
|
||||
});
|
||||
|
||||
$routes->group('occupation', function ($routes) {
|
||||
$routes->get('/', 'Contact\OccupationController::index');
|
||||
$routes->get('(:num)', 'Contact\OccupationController::show/$1');
|
||||
$routes->post('/', 'Contact\OccupationController::create');
|
||||
$routes->patch('(:any)', 'Contact\OccupationController::update/$1');
|
||||
//$routes->delete('/', 'Contact\OccupationController::delete');
|
||||
});
|
||||
|
||||
$routes->group('medicalspecialty', function ($routes) {
|
||||
$routes->get('/', 'Contact\MedicalSpecialtyController::index');
|
||||
$routes->get('(:num)', 'Contact\MedicalSpecialtyController::show/$1');
|
||||
$routes->post('/', 'Contact\MedicalSpecialtyController::create');
|
||||
$routes->patch('(:any)', 'Contact\MedicalSpecialtyController::update/$1');
|
||||
});
|
||||
|
||||
// Lib ValueSet (file-based)
|
||||
$routes->group('valueset', function ($routes) {
|
||||
$routes->get('/', 'ValueSetController::index');
|
||||
$routes->get('(:any)', 'ValueSetController::index/$1');
|
||||
$routes->post('refresh', 'ValueSetController::refresh');
|
||||
|
||||
// User ValueSet (database-based)
|
||||
$routes->group('user', function ($routes) {
|
||||
$routes->group('items', function ($routes) {
|
||||
$routes->get('/', 'ValueSetController::items');
|
||||
$routes->get('(:num)', 'ValueSetController::showItem/$1');
|
||||
$routes->post('/', 'ValueSetController::createItem');
|
||||
$routes->put('(:num)', 'ValueSetController::updateItem/$1');
|
||||
$routes->delete('(:num)', 'ValueSetController::deleteItem/$1');
|
||||
});
|
||||
|
||||
$routes->group('def', function ($routes) {
|
||||
$routes->get('/', 'ValueSetDefController::index');
|
||||
$routes->get('(:num)', 'ValueSetDefController::show/$1');
|
||||
$routes->post('/', 'ValueSetDefController::create');
|
||||
$routes->put('(:num)', 'ValueSetDefController::update/$1');
|
||||
$routes->delete('(:num)', 'ValueSetDefController::delete/$1');
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
// Result ValueSet
|
||||
$routes->group('result', function ($routes) {
|
||||
$routes->group('valueset', function ($routes) {
|
||||
$routes->get('/', 'Result\ResultValueSetController::index');
|
||||
$routes->get('(:num)', 'Result\ResultValueSetController::show/$1');
|
||||
$routes->post('/', 'Result\ResultValueSetController::create');
|
||||
$routes->put('(:num)', 'Result\ResultValueSetController::update/$1');
|
||||
$routes->delete('(:num)', 'Result\ResultValueSetController::delete/$1');
|
||||
});
|
||||
});
|
||||
|
||||
$routes->post('calc/testsite/(:num)', 'CalculatorController::calculateByTestSite/$1');
|
||||
$routes->post('calc/testcode/(:any)', 'CalculatorController::calculateByCodeOrName/$1');
|
||||
|
||||
// Counter
|
||||
$routes->group('counter', function ($routes) {
|
||||
$routes->get('/', 'CounterController::index');
|
||||
$routes->get('(:num)', 'CounterController::show/$1');
|
||||
$routes->post('/', 'CounterController::create');
|
||||
$routes->patch('(:any)', 'CounterController::update/$1');
|
||||
$routes->delete('/', 'CounterController::delete');
|
||||
});
|
||||
|
||||
// AreaGeo
|
||||
$routes->group('areageo', function ($routes) {
|
||||
$routes->get('/', 'AreaGeoController::index');
|
||||
$routes->get('provinces', 'AreaGeoController::getProvinces');
|
||||
$routes->get('cities', 'AreaGeoController::getCities');
|
||||
});
|
||||
|
||||
// Organization
|
||||
$routes->group('organization', function ($routes) {
|
||||
// Account
|
||||
$routes->group('account', function ($routes) {
|
||||
$routes->get('/', 'Organization\AccountController::index');
|
||||
$routes->get('(:num)', 'Organization\AccountController::show/$1');
|
||||
$routes->post('/', 'Organization\AccountController::create');
|
||||
$routes->patch('(:any)', 'Organization\AccountController::update/$1');
|
||||
$routes->delete('/', 'Organization\AccountController::delete');
|
||||
});
|
||||
|
||||
// Site
|
||||
$routes->group('site', function ($routes) {
|
||||
$routes->get('/', 'Organization\SiteController::index');
|
||||
$routes->get('(:num)', 'Organization\SiteController::show/$1');
|
||||
$routes->post('/', 'Organization\SiteController::create');
|
||||
$routes->patch('(:any)', 'Organization\SiteController::update/$1');
|
||||
$routes->delete('/', 'Organization\SiteController::delete');
|
||||
});
|
||||
|
||||
// Discipline
|
||||
$routes->group('discipline', function ($routes) {
|
||||
$routes->get('/', 'Organization\DisciplineController::index');
|
||||
$routes->get('(:num)', 'Organization\DisciplineController::show/$1');
|
||||
$routes->post('/', 'Organization\DisciplineController::create');
|
||||
$routes->patch('(:any)', 'Organization\DisciplineController::update/$1');
|
||||
$routes->delete('/', 'Organization\DisciplineController::delete');
|
||||
});
|
||||
|
||||
// Department
|
||||
$routes->group('department', function ($routes) {
|
||||
$routes->get('/', 'Organization\DepartmentController::index');
|
||||
$routes->get('(:num)', 'Organization\DepartmentController::show/$1');
|
||||
$routes->post('/', 'Organization\DepartmentController::create');
|
||||
$routes->patch('(:any)', 'Organization\DepartmentController::update/$1');
|
||||
$routes->delete('/', 'Organization\DepartmentController::delete');
|
||||
});
|
||||
|
||||
// Workstation
|
||||
$routes->group('workstation', function ($routes) {
|
||||
$routes->get('/', 'Organization\WorkstationController::index');
|
||||
$routes->get('(:num)', 'Organization\WorkstationController::show/$1');
|
||||
$routes->post('/', 'Organization\WorkstationController::create');
|
||||
$routes->patch('(:any)', 'Organization\WorkstationController::update/$1');
|
||||
$routes->delete('/', 'Organization\WorkstationController::delete');
|
||||
});
|
||||
|
||||
// HostApp
|
||||
$routes->group('hostapp', function ($routes) {
|
||||
$routes->get('/', 'Organization\HostAppController::index');
|
||||
$routes->get('(:num)', 'Organization\HostAppController::show/$1');
|
||||
$routes->post('/', 'Organization\HostAppController::create');
|
||||
$routes->patch('(:num)', 'Organization\HostAppController::update/$1');
|
||||
$routes->delete('/', 'Organization\HostAppController::delete');
|
||||
});
|
||||
|
||||
// HostComPara
|
||||
$routes->group('hostcompara', function ($routes) {
|
||||
$routes->get('/', 'Organization\HostComParaController::index');
|
||||
$routes->get('(:num)', 'Organization\HostComParaController::show/$1');
|
||||
$routes->post('/', 'Organization\HostComParaController::create');
|
||||
$routes->patch('(:num)', 'Organization\HostComParaController::update/$1');
|
||||
$routes->delete('/', 'Organization\HostComParaController::delete');
|
||||
});
|
||||
|
||||
// CodingSys
|
||||
$routes->group('codingsys', function ($routes) {
|
||||
$routes->get('/', 'Organization\CodingSysController::index');
|
||||
$routes->get('(:num)', 'Organization\CodingSysController::show/$1');
|
||||
$routes->post('/', 'Organization\CodingSysController::create');
|
||||
$routes->patch('(:any)', 'Organization\CodingSysController::update/$1');
|
||||
$routes->delete('/', 'Organization\CodingSysController::delete');
|
||||
});
|
||||
});
|
||||
|
||||
// Infrastructure
|
||||
$routes->group('equipmentlist', function ($routes) {
|
||||
$routes->get('/', 'Infrastructure\EquipmentListController::index');
|
||||
$routes->get('(:num)', 'Infrastructure\EquipmentListController::show/$1');
|
||||
$routes->post('/', 'Infrastructure\EquipmentListController::create');
|
||||
$routes->patch('(:any)', 'Infrastructure\EquipmentListController::update/$1');
|
||||
$routes->delete('/', 'Infrastructure\EquipmentListController::delete');
|
||||
});
|
||||
|
||||
// Users
|
||||
$routes->group('user', function ($routes) {
|
||||
$routes->get('/', 'User\UserController::index');
|
||||
$routes->get('(:num)', 'User\UserController::show/$1');
|
||||
$routes->post('/', 'User\UserController::create');
|
||||
$routes->patch('(:any)', 'User\UserController::update/$1');
|
||||
$routes->delete('(:num)', 'User\UserController::delete/$1');
|
||||
});
|
||||
|
||||
// Specimen
|
||||
$routes->group('specimen', function ($routes) {
|
||||
// Container aliases - 'container' and 'containerdef' both point to ContainerDefController
|
||||
$routes->group('container', function ($routes) {
|
||||
$routes->get('/', 'Specimen\ContainerDefController::index');
|
||||
$routes->get('(:num)', 'Specimen\ContainerDefController::show/$1');
|
||||
$routes->post('/', 'Specimen\ContainerDefController::create');
|
||||
$routes->patch('(:any)', 'Specimen\ContainerDefController::update/$1');
|
||||
});
|
||||
$routes->group('containerdef', function ($routes) {
|
||||
$routes->get('/', 'Specimen\ContainerDefController::index');
|
||||
$routes->get('(:num)', 'Specimen\ContainerDefController::show/$1');
|
||||
$routes->post('/', 'Specimen\ContainerDefController::create');
|
||||
$routes->patch('(:any)', 'Specimen\ContainerDefController::update/$1');
|
||||
});
|
||||
|
||||
$routes->group('prep', function ($routes) {
|
||||
$routes->get('/', 'Specimen\SpecimenPrepController::index');
|
||||
$routes->get('(:num)', 'Specimen\SpecimenPrepController::show/$1');
|
||||
$routes->post('/', 'Specimen\SpecimenPrepController::create');
|
||||
$routes->patch('(:any)', 'Specimen\SpecimenPrepController::update/$1');
|
||||
});
|
||||
|
||||
$routes->group('status', function ($routes) {
|
||||
$routes->get('/', 'Specimen\SpecimenStatusController::index');
|
||||
$routes->get('(:num)', 'Specimen\SpecimenStatusController::show/$1');
|
||||
$routes->post('/', 'Specimen\SpecimenStatusController::create');
|
||||
$routes->patch('(:any)', 'Specimen\SpecimenStatusController::update/$1');
|
||||
});
|
||||
|
||||
$routes->group('collection', function ($routes) {
|
||||
$routes->get('/', 'Specimen\SpecimenCollectionController::index');
|
||||
$routes->get('(:num)', 'Specimen\SpecimenCollectionController::show/$1');
|
||||
$routes->post('/', 'Specimen\SpecimenCollectionController::create');
|
||||
$routes->patch('(:any)', 'Specimen\SpecimenCollectionController::update/$1');
|
||||
});
|
||||
|
||||
$routes->get('/', 'Specimen\SpecimenController::index');
|
||||
$routes->get('(:num)', 'Specimen\SpecimenController::show/$1');
|
||||
$routes->post('/', 'Specimen\SpecimenController::create');
|
||||
$routes->patch('(:any)', 'Specimen\SpecimenController::update/$1');
|
||||
$routes->delete('(:num)', 'Specimen\SpecimenController::delete/$1');
|
||||
});
|
||||
|
||||
// Test
|
||||
$routes->group('test', function ($routes) {
|
||||
$routes->get('/', 'Test\TestsController::index');
|
||||
$routes->get('(:num)', 'Test\TestsController::show/$1');
|
||||
$routes->post('/', 'Test\TestsController::create');
|
||||
$routes->patch('(:segment)', 'Test\TestsController::update/$1');
|
||||
$routes->group('testmap', function ($routes) {
|
||||
$routes->get('/', 'Test\TestMapController::index');
|
||||
$routes->get('(:num)', 'Test\TestMapController::show/$1');
|
||||
$routes->post('/', 'Test\TestMapController::create');
|
||||
$routes->patch('(:segment)', 'Test\TestMapController::update/$1');
|
||||
$routes->delete('/', 'Test\TestMapController::delete');
|
||||
|
||||
// Filter routes
|
||||
$routes->get('by-testcode/(:any)', 'Test\TestMapController::showByTestCode/$1');
|
||||
|
||||
// TestMapDetail nested routes
|
||||
$routes->group('detail', function ($routes) {
|
||||
$routes->get('/', 'Test\TestMapDetailController::index');
|
||||
$routes->get('(:num)', 'Test\TestMapDetailController::show/$1');
|
||||
$routes->post('/', 'Test\TestMapDetailController::create');
|
||||
$routes->patch('(:segment)', 'Test\TestMapDetailController::update/$1');
|
||||
$routes->delete('/', 'Test\TestMapDetailController::delete');
|
||||
$routes->get('by-testmap/(:num)', 'Test\TestMapDetailController::showByTestMap/$1');
|
||||
$routes->post('batch', 'Test\TestMapDetailController::batchCreate');
|
||||
$routes->patch('batch', 'Test\TestMapDetailController::batchUpdate');
|
||||
$routes->delete('batch', 'Test\TestMapDetailController::batchDelete');
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
// Orders
|
||||
$routes->group('ordertest', function ($routes) {
|
||||
$routes->get('/', 'OrderTestController::index');
|
||||
$routes->get('(:any)', 'OrderTestController::show/$1');
|
||||
$routes->post('/', 'OrderTestController::create');
|
||||
$routes->patch('(:any)', 'OrderTestController::update/$1');
|
||||
$routes->delete('/', 'OrderTestController::delete');
|
||||
$routes->post('status', 'OrderTestController::updateStatus');
|
||||
});
|
||||
|
||||
// Rules
|
||||
$routes->group('rule', ['filter' => 'auth'], function ($routes) {
|
||||
$routes->get('/', 'Rule\RuleController::index');
|
||||
$routes->get('(:num)', 'Rule\RuleController::show/$1');
|
||||
$routes->post('/', 'Rule\RuleController::create');
|
||||
$routes->patch('(:any)', 'Rule\RuleController::update/$1');
|
||||
$routes->delete('(:num)', 'Rule\RuleController::delete/$1');
|
||||
$routes->post('validate', 'Rule\RuleController::validateExpr');
|
||||
$routes->post('compile', 'Rule\RuleController::compile');
|
||||
});
|
||||
|
||||
// Public Routes (no auth required)
|
||||
$routes->get('/v2/login', 'PagesController::login');
|
||||
|
||||
// V2 Auth API Routes (public - no auth required)
|
||||
$routes->group('v2/auth', function ($routes) {
|
||||
$routes->post('login', 'AuthV2Controller::login');
|
||||
$routes->post('register', 'AuthV2Controller::register');
|
||||
$routes->get('check', 'AuthV2Controller::checkAuth');
|
||||
$routes->post('logout', 'AuthV2Controller::logout');
|
||||
});
|
||||
|
||||
// Protected Page Routes - V2 (requires auth)
|
||||
$routes->group('v2', ['filter' => 'auth'], function ($routes) {
|
||||
$routes->get('/', 'PagesController::dashboard');
|
||||
$routes->get('dashboard', 'PagesController::dashboard');
|
||||
$routes->get('patients', 'PagesController::patients');
|
||||
$routes->get('requests', 'PagesController::requests');
|
||||
$routes->get('settings', 'PagesController::settings');
|
||||
|
||||
// Master Data - Organization
|
||||
$routes->get('master/organization/accounts', 'PagesController::masterOrgAccounts');
|
||||
$routes->get('master/organization/sites', 'PagesController::masterOrgSites');
|
||||
$routes->get('master/organization/disciplines', 'PagesController::masterOrgDisciplines');
|
||||
$routes->get('master/organization/departments', 'PagesController::masterOrgDepartments');
|
||||
$routes->get('master/organization/workstations', 'PagesController::masterOrgWorkstations');
|
||||
|
||||
// Master Data - Specimen
|
||||
$routes->get('master/specimen/containers', 'PagesController::masterSpecimenContainers');
|
||||
$routes->get('master/specimen/preparations', 'PagesController::masterSpecimenPreparations');
|
||||
|
||||
// Master Data - Tests & ValueSets
|
||||
$routes->get('master/tests', 'PagesController::masterTests');
|
||||
$routes->get('master/valuesets', 'PagesController::masterValueSets');
|
||||
});
|
||||
|
||||
// Faker
|
||||
$routes->get('faker/faker-patient/(:num)', 'faker\FakerPatient::sendMany/$1');
|
||||
|
||||
$routes->group('api', function ($routes) {
|
||||
// Auth
|
||||
$routes->group('auth', function ($routes) {
|
||||
$routes->post('login', 'AuthController::login');
|
||||
$routes->post('change_pass', 'AuthController::change_pass');
|
||||
$routes->post('register', 'AuthController::register');
|
||||
$routes->get('check', 'AuthController::checkAuth');
|
||||
$routes->post('logout', 'AuthController::logout');
|
||||
});
|
||||
|
||||
|
||||
// Demo/Test Routes (No Auth)
|
||||
$routes->group('api/demo', function ($routes) {
|
||||
$routes->post('order', 'Test\DemoOrderController::createDemoOrder');
|
||||
$routes->get('order', 'Test\DemoOrderController::listDemoOrders');
|
||||
});
|
||||
|
||||
// Edge API - Integration with tiny-edge
|
||||
$routes->group('edge', function ($routes) {
|
||||
$routes->post('result', 'EdgeController::results');
|
||||
$routes->get('order', 'EdgeController::orders');
|
||||
$routes->post('order/(:num)/ack', 'EdgeController::ack/$1');
|
||||
$routes->post('status', 'EdgeController::status');
|
||||
});
|
||||
});
|
||||
|
||||
// Khusus
|
||||
/*
|
||||
$routes->get('/api/zones', 'Zones::index');
|
||||
$routes->get('/api/zones/synchronize', 'Zones::synchronize');
|
||||
$routes->get('/api/zones/provinces', 'Zones::getProvinces');
|
||||
$routes->get('/api/zones/cities', 'Zones::getCities');
|
||||
*/
|
||||
|
||||
// Patient
|
||||
$routes->group('patient', function ($routes) {
|
||||
$routes->get('/', 'Patient\PatientController::index');
|
||||
$routes->post('/', 'Patient\PatientController::create');
|
||||
$routes->get('(:num)', 'Patient\PatientController::show/$1');
|
||||
$routes->delete('/', 'Patient\PatientController::delete');
|
||||
$routes->patch('/', 'Patient\PatientController::update');
|
||||
$routes->get('check', 'Patient\PatientController::patientCheck');
|
||||
});
|
||||
|
||||
// PatVisit
|
||||
$routes->group('patvisit', function ($routes) {
|
||||
$routes->get('/', 'PatVisitController::index');
|
||||
$routes->post('/', 'PatVisitController::create');
|
||||
$routes->get('patient/(:num)', 'PatVisitController::showByPatient/$1');
|
||||
$routes->get('(:any)', 'PatVisitController::show/$1');
|
||||
$routes->delete('/', 'PatVisitController::delete');
|
||||
$routes->patch('/', 'PatVisitController::update');
|
||||
});
|
||||
|
||||
$routes->group('patvisitadt', function ($routes) {
|
||||
$routes->post('/', 'PatVisitController::createADT');
|
||||
$routes->patch('/', 'PatVisitController::updateADT');
|
||||
});
|
||||
|
||||
// Master Data
|
||||
$routes->group('race', function ($routes) {
|
||||
$routes->get('/', 'Race::index');
|
||||
$routes->get('(:num)', 'Race::show/$1');
|
||||
});
|
||||
|
||||
$routes->group('country', function ($routes) {
|
||||
$routes->get('/', 'Country::index');
|
||||
$routes->get('(:num)', 'Country::show/$1');
|
||||
});
|
||||
|
||||
$routes->group('religion', function ($routes) {
|
||||
$routes->get('/', 'Religion::index');
|
||||
$routes->get('(:num)', 'Religion::show/$1');
|
||||
});
|
||||
|
||||
$routes->group('ethnic', function ($routes) {
|
||||
$routes->get('/', 'Ethnic::index');
|
||||
$routes->get('(:num)', 'Ethnic::show/$1');
|
||||
});
|
||||
|
||||
// Location
|
||||
$routes->group('location', function ($routes) {
|
||||
$routes->get('/', 'LocationController::index');
|
||||
$routes->get('(:num)', 'LocationController::show/$1');
|
||||
$routes->post('/', 'LocationController::create');
|
||||
$routes->patch('/', 'LocationController::update');
|
||||
$routes->delete('/', 'LocationController::delete');
|
||||
});
|
||||
|
||||
// Contact
|
||||
$routes->group('contact', function ($routes) {
|
||||
$routes->get('/', 'Contact\ContactController::index');
|
||||
$routes->get('(:num)', 'Contact\ContactController::show/$1');
|
||||
$routes->post('/', 'Contact\ContactController::create');
|
||||
$routes->patch('/', 'Contact\ContactController::update');
|
||||
$routes->delete('/', 'Contact\ContactController::delete');
|
||||
});
|
||||
|
||||
$routes->group('occupation', function ($routes) {
|
||||
$routes->get('/', 'Contact\OccupationController::index');
|
||||
$routes->get('(:num)', 'Contact\OccupationController::show/$1');
|
||||
$routes->post('/', 'Contact\OccupationController::create');
|
||||
$routes->patch('/', 'Contact\OccupationController::update');
|
||||
//$routes->delete('/', 'Contact\OccupationController::delete');
|
||||
});
|
||||
|
||||
$routes->group('medicalspecialty', function ($routes) {
|
||||
$routes->get('/', 'Contact\MedicalSpecialtyController::index');
|
||||
$routes->get('(:num)', 'Contact\MedicalSpecialtyController::show/$1');
|
||||
$routes->post('/', 'Contact\MedicalSpecialtyController::create');
|
||||
$routes->patch('/', 'Contact\MedicalSpecialtyController::update');
|
||||
});
|
||||
|
||||
$routes->group('valueset', function ($routes) {
|
||||
$routes->get('/', 'ValueSetController::index');
|
||||
$routes->get('(:any)', 'ValueSetController::index/$1');
|
||||
$routes->post('refresh', 'ValueSetController::refresh');
|
||||
|
||||
$routes->get('items', 'ValueSetController::items');
|
||||
$routes->get('items/(:num)', 'ValueSetController::showItem/$1');
|
||||
$routes->post('items', 'ValueSetController::createItem');
|
||||
$routes->put('items/(:num)', 'ValueSetController::updateItem/$1');
|
||||
$routes->delete('items/(:num)', 'ValueSetController::deleteItem/$1');
|
||||
});
|
||||
|
||||
$routes->group('valuesetdef', function ($routes) {
|
||||
$routes->get('/', 'ValueSetDefController::index');
|
||||
$routes->get('(:num)', 'ValueSetDefController::show/$1');
|
||||
$routes->post('/', 'ValueSetDefController::create');
|
||||
$routes->put('(:num)', 'ValueSetDefController::update/$1');
|
||||
$routes->delete('(:num)', 'ValueSetDefController::delete/$1');
|
||||
});
|
||||
|
||||
// Counter
|
||||
$routes->group('counter', function ($routes) {
|
||||
$routes->get('/', 'CounterController::index');
|
||||
$routes->get('(:num)', 'CounterController::show/$1');
|
||||
$routes->post('/', 'CounterController::create');
|
||||
$routes->patch('/', 'CounterController::update');
|
||||
$routes->delete('/', 'CounterController::delete');
|
||||
});
|
||||
|
||||
// AreaGeo
|
||||
$routes->group('areageo', function ($routes) {
|
||||
$routes->get('/', 'AreaGeoController::index');
|
||||
$routes->get('provinces', 'AreaGeoController::getProvinces');
|
||||
$routes->get('cities', 'AreaGeoController::getCities');
|
||||
});
|
||||
|
||||
// Organization
|
||||
$routes->group('organization', function ($routes) {
|
||||
// Account
|
||||
$routes->group('account', function ($routes) {
|
||||
$routes->get('/', 'Organization\AccountController::index');
|
||||
$routes->get('(:num)', 'Organization\AccountController::show/$1');
|
||||
$routes->post('/', 'Organization\AccountController::create');
|
||||
$routes->patch('/', 'Organization\AccountController::update');
|
||||
$routes->delete('/', 'Organization\AccountController::delete');
|
||||
});
|
||||
|
||||
// Site
|
||||
$routes->group('site', function ($routes) {
|
||||
$routes->get('/', 'Organization\SiteController::index');
|
||||
$routes->get('(:num)', 'Organization\SiteController::show/$1');
|
||||
$routes->post('/', 'Organization\SiteController::create');
|
||||
$routes->patch('/', 'Organization\SiteController::update');
|
||||
$routes->delete('/', 'Organization\SiteController::delete');
|
||||
});
|
||||
|
||||
// Discipline
|
||||
$routes->group('discipline', function ($routes) {
|
||||
$routes->get('/', 'Organization\DisciplineController::index');
|
||||
$routes->get('(:num)', 'Organization\DisciplineController::show/$1');
|
||||
$routes->post('/', 'Organization\DisciplineController::create');
|
||||
$routes->patch('/', 'Organization\DisciplineController::update');
|
||||
$routes->delete('/', 'Organization\DisciplineController::delete');
|
||||
});
|
||||
|
||||
// Department
|
||||
$routes->group('department', function ($routes) {
|
||||
$routes->get('/', 'Organization\DepartmentController::index');
|
||||
$routes->get('(:num)', 'Organization\DepartmentController::show/$1');
|
||||
$routes->post('/', 'Organization\DepartmentController::create');
|
||||
$routes->patch('/', 'Organization\DepartmentController::update');
|
||||
$routes->delete('/', 'Organization\DepartmentController::delete');
|
||||
});
|
||||
|
||||
// Workstation
|
||||
$routes->group('workstation', function ($routes) {
|
||||
$routes->get('/', 'Organization\WorkstationController::index');
|
||||
$routes->get('(:num)', 'Organization\WorkstationController::show/$1');
|
||||
$routes->post('/', 'Organization\WorkstationController::create');
|
||||
$routes->patch('/', 'Organization\WorkstationController::update');
|
||||
$routes->delete('/', 'Organization\WorkstationController::delete');
|
||||
});
|
||||
});
|
||||
|
||||
// Specimen
|
||||
$routes->group('specimen', function ($routes) {
|
||||
// Container aliases - 'container' and 'containerdef' both point to ContainerDefController
|
||||
$routes->group('container', function ($routes) {
|
||||
$routes->get('/', 'Specimen\ContainerDefController::index');
|
||||
$routes->get('(:num)', 'Specimen\ContainerDefController::show/$1');
|
||||
$routes->post('/', 'Specimen\ContainerDefController::create');
|
||||
$routes->patch('/', 'Specimen\ContainerDefController::update');
|
||||
});
|
||||
$routes->group('containerdef', function ($routes) {
|
||||
$routes->get('/', 'Specimen\ContainerDefController::index');
|
||||
$routes->get('(:num)', 'Specimen\ContainerDefController::show/$1');
|
||||
$routes->post('/', 'Specimen\ContainerDefController::create');
|
||||
$routes->patch('/', 'Specimen\ContainerDefController::update');
|
||||
});
|
||||
|
||||
$routes->group('prep', function ($routes) {
|
||||
$routes->get('/', 'Specimen\SpecimenPrepController::index');
|
||||
$routes->get('(:num)', 'Specimen\SpecimenPrepController::show/$1');
|
||||
$routes->post('/', 'Specimen\SpecimenPrepController::create');
|
||||
$routes->patch('/', 'Specimen\SpecimenPrepController::update');
|
||||
});
|
||||
|
||||
$routes->group('status', function ($routes) {
|
||||
$routes->get('/', 'Specimen\SpecimenStatusController::index');
|
||||
$routes->get('(:num)', 'Specimen\SpecimenStatusController::show/$1');
|
||||
$routes->post('/', 'Specimen\SpecimenStatusController::create');
|
||||
$routes->patch('/', 'Specimen\SpecimenStatusController::update');
|
||||
});
|
||||
|
||||
$routes->group('collection', function ($routes) {
|
||||
$routes->get('/', 'Specimen\SpecimenCollectionController::index');
|
||||
$routes->get('(:num)', 'Specimen\SpecimenCollectionController::show/$1');
|
||||
$routes->post('/', 'Specimen\SpecimenCollectionController::create');
|
||||
$routes->patch('/', 'Specimen\SpecimenCollectionController::update');
|
||||
});
|
||||
|
||||
$routes->get('/', 'Specimen\SpecimenController::index');
|
||||
$routes->get('(:num)', 'Specimen\SpecimenController::show/$1');
|
||||
$routes->post('/', 'Specimen\SpecimenController::create');
|
||||
$routes->patch('/', 'Specimen\SpecimenController::update');
|
||||
});
|
||||
|
||||
// Tests
|
||||
$routes->group('tests', function ($routes) {
|
||||
$routes->get('/', 'TestsController::index');
|
||||
$routes->get('(:num)', 'TestsController::show/$1');
|
||||
$routes->post('/', 'TestsController::create');
|
||||
$routes->patch('/', 'TestsController::update');
|
||||
});
|
||||
|
||||
// Orders
|
||||
$routes->group('ordertest', function ($routes) {
|
||||
$routes->get('/', 'OrderTestController::index');
|
||||
$routes->get('(:any)', 'OrderTestController::show/$1');
|
||||
$routes->post('/', 'OrderTestController::create');
|
||||
$routes->patch('/', 'OrderTestController::update');
|
||||
$routes->delete('/', 'OrderTestController::delete');
|
||||
$routes->post('status', 'OrderTestController::updateStatus');
|
||||
});
|
||||
|
||||
// Demo/Test Routes (No Auth)
|
||||
$routes->group('api/demo', function ($routes) {
|
||||
$routes->post('order', 'Test\DemoOrderController::createDemoOrder');
|
||||
$routes->get('orders', 'Test\DemoOrderController::listDemoOrders');
|
||||
});
|
||||
|
||||
// Edge API - Integration with tiny-edge
|
||||
$routes->group('edge', function ($routes) {
|
||||
$routes->post('results', 'EdgeController::results');
|
||||
$routes->get('orders', 'EdgeController::orders');
|
||||
$routes->post('orders/(:num)/ack', 'EdgeController::ack/$1');
|
||||
$routes->post('status', 'EdgeController::status');
|
||||
});
|
||||
});
|
||||
|
||||
// Khusus
|
||||
/*
|
||||
$routes->get('/api/zones', 'Zones::index');
|
||||
$routes->get('/api/zones/synchronize', 'Zones::synchronize');
|
||||
$routes->get('/api/zones/provinces', 'Zones::getProvinces');
|
||||
$routes->get('/api/zones/cities', 'Zones::getCities');
|
||||
*/
|
||||
|
||||
|
||||
280
app/Config/Routing.php
Executable file → Normal file
280
app/Config/Routing.php
Executable file → Normal file
@ -1,140 +1,140 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* This file is part of CodeIgniter 4 framework.
|
||||
*
|
||||
* (c) CodeIgniter Foundation <admin@codeigniter.com>
|
||||
*
|
||||
* For the full copyright and license information, please view
|
||||
* the LICENSE file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Config;
|
||||
|
||||
use CodeIgniter\Config\Routing as BaseRouting;
|
||||
|
||||
/**
|
||||
* Routing configuration
|
||||
*/
|
||||
class Routing extends BaseRouting
|
||||
{
|
||||
/**
|
||||
* For Defined Routes.
|
||||
* An array of files that contain route definitions.
|
||||
* Route files are read in order, with the first match
|
||||
* found taking precedence.
|
||||
*
|
||||
* Default: APPPATH . 'Config/Routes.php'
|
||||
*
|
||||
* @var list<string>
|
||||
*/
|
||||
public array $routeFiles = [
|
||||
APPPATH . 'Config/Routes.php',
|
||||
];
|
||||
|
||||
/**
|
||||
* For Defined Routes and Auto Routing.
|
||||
* The default namespace to use for Controllers when no other
|
||||
* namespace has been specified.
|
||||
*
|
||||
* Default: 'App\Controllers'
|
||||
*/
|
||||
public string $defaultNamespace = 'App\Controllers';
|
||||
|
||||
/**
|
||||
* For Auto Routing.
|
||||
* The default controller to use when no other controller has been
|
||||
* specified.
|
||||
*
|
||||
* Default: 'Home'
|
||||
*/
|
||||
public string $defaultController = 'Home';
|
||||
|
||||
/**
|
||||
* For Defined Routes and Auto Routing.
|
||||
* The default method to call on the controller when no other
|
||||
* method has been set in the route.
|
||||
*
|
||||
* Default: 'index'
|
||||
*/
|
||||
public string $defaultMethod = 'index';
|
||||
|
||||
/**
|
||||
* For Auto Routing.
|
||||
* Whether to translate dashes in URIs for controller/method to underscores.
|
||||
* Primarily useful when using the auto-routing.
|
||||
*
|
||||
* Default: false
|
||||
*/
|
||||
public bool $translateURIDashes = false;
|
||||
|
||||
/**
|
||||
* Sets the class/method that should be called if routing doesn't
|
||||
* find a match. It can be the controller/method name like: Users::index
|
||||
*
|
||||
* This setting is passed to the Router class and handled there.
|
||||
*
|
||||
* If you want to use a closure, you will have to set it in the
|
||||
* routes file by calling:
|
||||
*
|
||||
* $routes->set404Override(function() {
|
||||
* // Do something here
|
||||
* });
|
||||
*
|
||||
* Example:
|
||||
* public $override404 = 'App\Errors::show404';
|
||||
*/
|
||||
public ?string $override404 = null;
|
||||
|
||||
/**
|
||||
* If TRUE, the system will attempt to match the URI against
|
||||
* Controllers by matching each segment against folders/files
|
||||
* in APPPATH/Controllers, when a match wasn't found against
|
||||
* defined routes.
|
||||
*
|
||||
* If FALSE, will stop searching and do NO automatic routing.
|
||||
*/
|
||||
public bool $autoRoute = false;
|
||||
|
||||
/**
|
||||
* For Defined Routes.
|
||||
* If TRUE, will enable the use of the 'prioritize' option
|
||||
* when defining routes.
|
||||
*
|
||||
* Default: false
|
||||
*/
|
||||
public bool $prioritize = false;
|
||||
|
||||
/**
|
||||
* For Defined Routes.
|
||||
* If TRUE, matched multiple URI segments will be passed as one parameter.
|
||||
*
|
||||
* Default: false
|
||||
*/
|
||||
public bool $multipleSegmentsOneParam = false;
|
||||
|
||||
/**
|
||||
* For Auto Routing (Improved).
|
||||
* Map of URI segments and namespaces.
|
||||
*
|
||||
* The key is the first URI segment. The value is the controller namespace.
|
||||
* E.g.,
|
||||
* [
|
||||
* 'blog' => 'Acme\Blog\Controllers',
|
||||
* ]
|
||||
*
|
||||
* @var array<string, string>
|
||||
*/
|
||||
public array $moduleRoutes = [];
|
||||
|
||||
/**
|
||||
* For Auto Routing (Improved).
|
||||
* Whether to translate dashes in URIs for controller/method to CamelCase.
|
||||
* E.g., blog-controller -> BlogController
|
||||
*
|
||||
* If you enable this, $translateURIDashes is ignored.
|
||||
*
|
||||
* Default: false
|
||||
*/
|
||||
public bool $translateUriToCamelCase = true;
|
||||
}
|
||||
<?php
|
||||
|
||||
/**
|
||||
* This file is part of CodeIgniter 4 framework.
|
||||
*
|
||||
* (c) CodeIgniter Foundation <admin@codeigniter.com>
|
||||
*
|
||||
* For the full copyright and license information, please view
|
||||
* the LICENSE file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Config;
|
||||
|
||||
use CodeIgniter\Config\Routing as BaseRouting;
|
||||
|
||||
/**
|
||||
* Routing configuration
|
||||
*/
|
||||
class Routing extends BaseRouting
|
||||
{
|
||||
/**
|
||||
* For Defined Routes.
|
||||
* An array of files that contain route definitions.
|
||||
* Route files are read in order, with the first match
|
||||
* found taking precedence.
|
||||
*
|
||||
* Default: APPPATH . 'Config/Routes.php'
|
||||
*
|
||||
* @var list<string>
|
||||
*/
|
||||
public array $routeFiles = [
|
||||
APPPATH . 'Config/Routes.php',
|
||||
];
|
||||
|
||||
/**
|
||||
* For Defined Routes and Auto Routing.
|
||||
* The default namespace to use for Controllers when no other
|
||||
* namespace has been specified.
|
||||
*
|
||||
* Default: 'App\Controllers'
|
||||
*/
|
||||
public string $defaultNamespace = 'App\Controllers';
|
||||
|
||||
/**
|
||||
* For Auto Routing.
|
||||
* The default controller to use when no other controller has been
|
||||
* specified.
|
||||
*
|
||||
* Default: 'Home'
|
||||
*/
|
||||
public string $defaultController = 'Home';
|
||||
|
||||
/**
|
||||
* For Defined Routes and Auto Routing.
|
||||
* The default method to call on the controller when no other
|
||||
* method has been set in the route.
|
||||
*
|
||||
* Default: 'index'
|
||||
*/
|
||||
public string $defaultMethod = 'index';
|
||||
|
||||
/**
|
||||
* For Auto Routing.
|
||||
* Whether to translate dashes in URIs for controller/method to underscores.
|
||||
* Primarily useful when using the auto-routing.
|
||||
*
|
||||
* Default: false
|
||||
*/
|
||||
public bool $translateURIDashes = false;
|
||||
|
||||
/**
|
||||
* Sets the class/method that should be called if routing doesn't
|
||||
* find a match. It can be the controller/method name like: Users::index
|
||||
*
|
||||
* This setting is passed to the Router class and handled there.
|
||||
*
|
||||
* If you want to use a closure, you will have to set it in the
|
||||
* routes file by calling:
|
||||
*
|
||||
* $routes->set404Override(function() {
|
||||
* // Do something here
|
||||
* });
|
||||
*
|
||||
* Example:
|
||||
* public $override404 = 'App\Errors::show404';
|
||||
*/
|
||||
public ?string $override404 = null;
|
||||
|
||||
/**
|
||||
* If TRUE, the system will attempt to match the URI against
|
||||
* Controllers by matching each segment against folders/files
|
||||
* in APPPATH/Controllers, when a match wasn't found against
|
||||
* defined routes.
|
||||
*
|
||||
* If FALSE, will stop searching and do NO automatic routing.
|
||||
*/
|
||||
public bool $autoRoute = false;
|
||||
|
||||
/**
|
||||
* For Defined Routes.
|
||||
* If TRUE, will enable the use of the 'prioritize' option
|
||||
* when defining routes.
|
||||
*
|
||||
* Default: false
|
||||
*/
|
||||
public bool $prioritize = false;
|
||||
|
||||
/**
|
||||
* For Defined Routes.
|
||||
* If TRUE, matched multiple URI segments will be passed as one parameter.
|
||||
*
|
||||
* Default: false
|
||||
*/
|
||||
public bool $multipleSegmentsOneParam = false;
|
||||
|
||||
/**
|
||||
* For Auto Routing (Improved).
|
||||
* Map of URI segments and namespaces.
|
||||
*
|
||||
* The key is the first URI segment. The value is the controller namespace.
|
||||
* E.g.,
|
||||
* [
|
||||
* 'blog' => 'Acme\Blog\Controllers',
|
||||
* ]
|
||||
*
|
||||
* @var array<string, string>
|
||||
*/
|
||||
public array $moduleRoutes = [];
|
||||
|
||||
/**
|
||||
* For Auto Routing (Improved).
|
||||
* Whether to translate dashes in URIs for controller/method to CamelCase.
|
||||
* E.g., blog-controller -> BlogController
|
||||
*
|
||||
* If you enable this, $translateURIDashes is ignored.
|
||||
*
|
||||
* Default: false
|
||||
*/
|
||||
public bool $translateUriToCamelCase = true;
|
||||
}
|
||||
|
||||
172
app/Config/Security.php
Executable file → Normal file
172
app/Config/Security.php
Executable file → Normal file
@ -1,86 +1,86 @@
|
||||
<?php
|
||||
|
||||
namespace Config;
|
||||
|
||||
use CodeIgniter\Config\BaseConfig;
|
||||
|
||||
class Security extends BaseConfig
|
||||
{
|
||||
/**
|
||||
* --------------------------------------------------------------------------
|
||||
* CSRF Protection Method
|
||||
* --------------------------------------------------------------------------
|
||||
*
|
||||
* Protection Method for Cross Site Request Forgery protection.
|
||||
*
|
||||
* @var string 'cookie' or 'session'
|
||||
*/
|
||||
public string $csrfProtection = 'cookie';
|
||||
|
||||
/**
|
||||
* --------------------------------------------------------------------------
|
||||
* CSRF Token Randomization
|
||||
* --------------------------------------------------------------------------
|
||||
*
|
||||
* Randomize the CSRF Token for added security.
|
||||
*/
|
||||
public bool $tokenRandomize = false;
|
||||
|
||||
/**
|
||||
* --------------------------------------------------------------------------
|
||||
* CSRF Token Name
|
||||
* --------------------------------------------------------------------------
|
||||
*
|
||||
* Token name for Cross Site Request Forgery protection.
|
||||
*/
|
||||
public string $tokenName = 'csrf_test_name';
|
||||
|
||||
/**
|
||||
* --------------------------------------------------------------------------
|
||||
* CSRF Header Name
|
||||
* --------------------------------------------------------------------------
|
||||
*
|
||||
* Header name for Cross Site Request Forgery protection.
|
||||
*/
|
||||
public string $headerName = 'X-CSRF-TOKEN';
|
||||
|
||||
/**
|
||||
* --------------------------------------------------------------------------
|
||||
* CSRF Cookie Name
|
||||
* --------------------------------------------------------------------------
|
||||
*
|
||||
* Cookie name for Cross Site Request Forgery protection.
|
||||
*/
|
||||
public string $cookieName = 'csrf_cookie_name';
|
||||
|
||||
/**
|
||||
* --------------------------------------------------------------------------
|
||||
* CSRF Expires
|
||||
* --------------------------------------------------------------------------
|
||||
*
|
||||
* Expiration time for Cross Site Request Forgery protection cookie.
|
||||
*
|
||||
* Defaults to two hours (in seconds).
|
||||
*/
|
||||
public int $expires = 7200;
|
||||
|
||||
/**
|
||||
* --------------------------------------------------------------------------
|
||||
* CSRF Regenerate
|
||||
* --------------------------------------------------------------------------
|
||||
*
|
||||
* Regenerate CSRF Token on every submission.
|
||||
*/
|
||||
public bool $regenerate = true;
|
||||
|
||||
/**
|
||||
* --------------------------------------------------------------------------
|
||||
* CSRF Redirect
|
||||
* --------------------------------------------------------------------------
|
||||
*
|
||||
* Redirect to previous page with error on failure.
|
||||
*
|
||||
* @see https://codeigniter4.github.io/userguide/libraries/security.html#redirection-on-failure
|
||||
*/
|
||||
public bool $redirect = (ENVIRONMENT === 'production');
|
||||
}
|
||||
<?php
|
||||
|
||||
namespace Config;
|
||||
|
||||
use CodeIgniter\Config\BaseConfig;
|
||||
|
||||
class Security extends BaseConfig
|
||||
{
|
||||
/**
|
||||
* --------------------------------------------------------------------------
|
||||
* CSRF Protection Method
|
||||
* --------------------------------------------------------------------------
|
||||
*
|
||||
* Protection Method for Cross Site Request Forgery protection.
|
||||
*
|
||||
* @var string 'cookie' or 'session'
|
||||
*/
|
||||
public string $csrfProtection = 'cookie';
|
||||
|
||||
/**
|
||||
* --------------------------------------------------------------------------
|
||||
* CSRF Token Randomization
|
||||
* --------------------------------------------------------------------------
|
||||
*
|
||||
* Randomize the CSRF Token for added security.
|
||||
*/
|
||||
public bool $tokenRandomize = false;
|
||||
|
||||
/**
|
||||
* --------------------------------------------------------------------------
|
||||
* CSRF Token Name
|
||||
* --------------------------------------------------------------------------
|
||||
*
|
||||
* Token name for Cross Site Request Forgery protection.
|
||||
*/
|
||||
public string $tokenName = 'csrf_test_name';
|
||||
|
||||
/**
|
||||
* --------------------------------------------------------------------------
|
||||
* CSRF Header Name
|
||||
* --------------------------------------------------------------------------
|
||||
*
|
||||
* Header name for Cross Site Request Forgery protection.
|
||||
*/
|
||||
public string $headerName = 'X-CSRF-TOKEN';
|
||||
|
||||
/**
|
||||
* --------------------------------------------------------------------------
|
||||
* CSRF Cookie Name
|
||||
* --------------------------------------------------------------------------
|
||||
*
|
||||
* Cookie name for Cross Site Request Forgery protection.
|
||||
*/
|
||||
public string $cookieName = 'csrf_cookie_name';
|
||||
|
||||
/**
|
||||
* --------------------------------------------------------------------------
|
||||
* CSRF Expires
|
||||
* --------------------------------------------------------------------------
|
||||
*
|
||||
* Expiration time for Cross Site Request Forgery protection cookie.
|
||||
*
|
||||
* Defaults to two hours (in seconds).
|
||||
*/
|
||||
public int $expires = 7200;
|
||||
|
||||
/**
|
||||
* --------------------------------------------------------------------------
|
||||
* CSRF Regenerate
|
||||
* --------------------------------------------------------------------------
|
||||
*
|
||||
* Regenerate CSRF Token on every submission.
|
||||
*/
|
||||
public bool $regenerate = true;
|
||||
|
||||
/**
|
||||
* --------------------------------------------------------------------------
|
||||
* CSRF Redirect
|
||||
* --------------------------------------------------------------------------
|
||||
*
|
||||
* Redirect to previous page with error on failure.
|
||||
*
|
||||
* @see https://codeigniter4.github.io/userguide/libraries/security.html#redirection-on-failure
|
||||
*/
|
||||
public bool $redirect = (ENVIRONMENT === 'production');
|
||||
}
|
||||
|
||||
64
app/Config/Services.php
Executable file → Normal file
64
app/Config/Services.php
Executable file → Normal file
@ -1,32 +1,32 @@
|
||||
<?php
|
||||
|
||||
namespace Config;
|
||||
|
||||
use CodeIgniter\Config\BaseService;
|
||||
|
||||
/**
|
||||
* Services Configuration file.
|
||||
*
|
||||
* Services are simply other classes/libraries that the system uses
|
||||
* to do its job. This is used by CodeIgniter to allow the core of the
|
||||
* framework to be swapped out easily without affecting the usage within
|
||||
* the rest of your application.
|
||||
*
|
||||
* This file holds any application-specific services, or service overrides
|
||||
* that you might need. An example has been included with the general
|
||||
* method format you should use for your service methods. For more examples,
|
||||
* see the core Services file at system/Config/Services.php.
|
||||
*/
|
||||
class Services extends BaseService
|
||||
{
|
||||
/*
|
||||
* public static function example($getShared = true)
|
||||
* {
|
||||
* if ($getShared) {
|
||||
* return static::getSharedInstance('example');
|
||||
* }
|
||||
*
|
||||
* return new \CodeIgniter\Example();
|
||||
* }
|
||||
*/
|
||||
}
|
||||
<?php
|
||||
|
||||
namespace Config;
|
||||
|
||||
use CodeIgniter\Config\BaseService;
|
||||
|
||||
/**
|
||||
* Services Configuration file.
|
||||
*
|
||||
* Services are simply other classes/libraries that the system uses
|
||||
* to do its job. This is used by CodeIgniter to allow the core of the
|
||||
* framework to be swapped out easily without affecting the usage within
|
||||
* the rest of your application.
|
||||
*
|
||||
* This file holds any application-specific services, or service overrides
|
||||
* that you might need. An example has been included with the general
|
||||
* method format you should use for your service methods. For more examples,
|
||||
* see the core Services file at system/Config/Services.php.
|
||||
*/
|
||||
class Services extends BaseService
|
||||
{
|
||||
/*
|
||||
* public static function example($getShared = true)
|
||||
* {
|
||||
* if ($getShared) {
|
||||
* return static::getSharedInstance('example');
|
||||
* }
|
||||
*
|
||||
* return new \CodeIgniter\Example();
|
||||
* }
|
||||
*/
|
||||
}
|
||||
|
||||
254
app/Config/Session.php
Executable file → Normal file
254
app/Config/Session.php
Executable file → Normal file
@ -1,127 +1,127 @@
|
||||
<?php
|
||||
|
||||
namespace Config;
|
||||
|
||||
use CodeIgniter\Config\BaseConfig;
|
||||
use CodeIgniter\Session\Handlers\BaseHandler;
|
||||
use CodeIgniter\Session\Handlers\FileHandler;
|
||||
|
||||
class Session extends BaseConfig
|
||||
{
|
||||
/**
|
||||
* --------------------------------------------------------------------------
|
||||
* Session Driver
|
||||
* --------------------------------------------------------------------------
|
||||
*
|
||||
* The session storage driver to use:
|
||||
* - `CodeIgniter\Session\Handlers\FileHandler`
|
||||
* - `CodeIgniter\Session\Handlers\DatabaseHandler`
|
||||
* - `CodeIgniter\Session\Handlers\MemcachedHandler`
|
||||
* - `CodeIgniter\Session\Handlers\RedisHandler`
|
||||
*
|
||||
* @var class-string<BaseHandler>
|
||||
*/
|
||||
public string $driver = FileHandler::class;
|
||||
|
||||
/**
|
||||
* --------------------------------------------------------------------------
|
||||
* Session Cookie Name
|
||||
* --------------------------------------------------------------------------
|
||||
*
|
||||
* The session cookie name, must contain only [0-9a-z_-] characters
|
||||
*/
|
||||
public string $cookieName = 'ci_session';
|
||||
|
||||
/**
|
||||
* --------------------------------------------------------------------------
|
||||
* Session Expiration
|
||||
* --------------------------------------------------------------------------
|
||||
*
|
||||
* The number of SECONDS you want the session to last.
|
||||
* Setting to 0 (zero) means expire when the browser is closed.
|
||||
*/
|
||||
public int $expiration = 7200;
|
||||
|
||||
/**
|
||||
* --------------------------------------------------------------------------
|
||||
* Session Save Path
|
||||
* --------------------------------------------------------------------------
|
||||
*
|
||||
* The location to save sessions to and is driver dependent.
|
||||
*
|
||||
* For the 'files' driver, it's a path to a writable directory.
|
||||
* WARNING: Only absolute paths are supported!
|
||||
*
|
||||
* For the 'database' driver, it's a table name.
|
||||
* Please read up the manual for the format with other session drivers.
|
||||
*
|
||||
* IMPORTANT: You are REQUIRED to set a valid save path!
|
||||
*/
|
||||
public string $savePath = WRITEPATH . 'session';
|
||||
|
||||
/**
|
||||
* --------------------------------------------------------------------------
|
||||
* Session Match IP
|
||||
* --------------------------------------------------------------------------
|
||||
*
|
||||
* Whether to match the user's IP address when reading the session data.
|
||||
*
|
||||
* WARNING: If you're using the database driver, don't forget to update
|
||||
* your session table's PRIMARY KEY when changing this setting.
|
||||
*/
|
||||
public bool $matchIP = false;
|
||||
|
||||
/**
|
||||
* --------------------------------------------------------------------------
|
||||
* Session Time to Update
|
||||
* --------------------------------------------------------------------------
|
||||
*
|
||||
* How many seconds between CI regenerating the session ID.
|
||||
*/
|
||||
public int $timeToUpdate = 300;
|
||||
|
||||
/**
|
||||
* --------------------------------------------------------------------------
|
||||
* Session Regenerate Destroy
|
||||
* --------------------------------------------------------------------------
|
||||
*
|
||||
* Whether to destroy session data associated with the old session ID
|
||||
* when auto-regenerating the session ID. When set to FALSE, the data
|
||||
* will be later deleted by the garbage collector.
|
||||
*/
|
||||
public bool $regenerateDestroy = false;
|
||||
|
||||
/**
|
||||
* --------------------------------------------------------------------------
|
||||
* Session Database Group
|
||||
* --------------------------------------------------------------------------
|
||||
*
|
||||
* DB Group for the database session.
|
||||
*/
|
||||
public ?string $DBGroup = null;
|
||||
|
||||
/**
|
||||
* --------------------------------------------------------------------------
|
||||
* Lock Retry Interval (microseconds)
|
||||
* --------------------------------------------------------------------------
|
||||
*
|
||||
* This is used for RedisHandler.
|
||||
*
|
||||
* Time (microseconds) to wait if lock cannot be acquired.
|
||||
* The default is 100,000 microseconds (= 0.1 seconds).
|
||||
*/
|
||||
public int $lockRetryInterval = 100_000;
|
||||
|
||||
/**
|
||||
* --------------------------------------------------------------------------
|
||||
* Lock Max Retries
|
||||
* --------------------------------------------------------------------------
|
||||
*
|
||||
* This is used for RedisHandler.
|
||||
*
|
||||
* Maximum number of lock acquisition attempts.
|
||||
* The default is 300 times. That is lock timeout is about 30 (0.1 * 300)
|
||||
* seconds.
|
||||
*/
|
||||
public int $lockMaxRetries = 300;
|
||||
}
|
||||
<?php
|
||||
|
||||
namespace Config;
|
||||
|
||||
use CodeIgniter\Config\BaseConfig;
|
||||
use CodeIgniter\Session\Handlers\BaseHandler;
|
||||
use CodeIgniter\Session\Handlers\FileHandler;
|
||||
|
||||
class Session extends BaseConfig
|
||||
{
|
||||
/**
|
||||
* --------------------------------------------------------------------------
|
||||
* Session Driver
|
||||
* --------------------------------------------------------------------------
|
||||
*
|
||||
* The session storage driver to use:
|
||||
* - `CodeIgniter\Session\Handlers\FileHandler`
|
||||
* - `CodeIgniter\Session\Handlers\DatabaseHandler`
|
||||
* - `CodeIgniter\Session\Handlers\MemcachedHandler`
|
||||
* - `CodeIgniter\Session\Handlers\RedisHandler`
|
||||
*
|
||||
* @var class-string<BaseHandler>
|
||||
*/
|
||||
public string $driver = FileHandler::class;
|
||||
|
||||
/**
|
||||
* --------------------------------------------------------------------------
|
||||
* Session Cookie Name
|
||||
* --------------------------------------------------------------------------
|
||||
*
|
||||
* The session cookie name, must contain only [0-9a-z_-] characters
|
||||
*/
|
||||
public string $cookieName = 'ci_session';
|
||||
|
||||
/**
|
||||
* --------------------------------------------------------------------------
|
||||
* Session Expiration
|
||||
* --------------------------------------------------------------------------
|
||||
*
|
||||
* The number of SECONDS you want the session to last.
|
||||
* Setting to 0 (zero) means expire when the browser is closed.
|
||||
*/
|
||||
public int $expiration = 7200;
|
||||
|
||||
/**
|
||||
* --------------------------------------------------------------------------
|
||||
* Session Save Path
|
||||
* --------------------------------------------------------------------------
|
||||
*
|
||||
* The location to save sessions to and is driver dependent.
|
||||
*
|
||||
* For the 'files' driver, it's a path to a writable directory.
|
||||
* WARNING: Only absolute paths are supported!
|
||||
*
|
||||
* For the 'database' driver, it's a table name.
|
||||
* Please read up the manual for the format with other session drivers.
|
||||
*
|
||||
* IMPORTANT: You are REQUIRED to set a valid save path!
|
||||
*/
|
||||
public string $savePath = WRITEPATH . 'session';
|
||||
|
||||
/**
|
||||
* --------------------------------------------------------------------------
|
||||
* Session Match IP
|
||||
* --------------------------------------------------------------------------
|
||||
*
|
||||
* Whether to match the user's IP address when reading the session data.
|
||||
*
|
||||
* WARNING: If you're using the database driver, don't forget to update
|
||||
* your session table's PRIMARY KEY when changing this setting.
|
||||
*/
|
||||
public bool $matchIP = false;
|
||||
|
||||
/**
|
||||
* --------------------------------------------------------------------------
|
||||
* Session Time to Update
|
||||
* --------------------------------------------------------------------------
|
||||
*
|
||||
* How many seconds between CI regenerating the session ID.
|
||||
*/
|
||||
public int $timeToUpdate = 300;
|
||||
|
||||
/**
|
||||
* --------------------------------------------------------------------------
|
||||
* Session Regenerate Destroy
|
||||
* --------------------------------------------------------------------------
|
||||
*
|
||||
* Whether to destroy session data associated with the old session ID
|
||||
* when auto-regenerating the session ID. When set to FALSE, the data
|
||||
* will be later deleted by the garbage collector.
|
||||
*/
|
||||
public bool $regenerateDestroy = false;
|
||||
|
||||
/**
|
||||
* --------------------------------------------------------------------------
|
||||
* Session Database Group
|
||||
* --------------------------------------------------------------------------
|
||||
*
|
||||
* DB Group for the database session.
|
||||
*/
|
||||
public ?string $DBGroup = null;
|
||||
|
||||
/**
|
||||
* --------------------------------------------------------------------------
|
||||
* Lock Retry Interval (microseconds)
|
||||
* --------------------------------------------------------------------------
|
||||
*
|
||||
* This is used for RedisHandler.
|
||||
*
|
||||
* Time (microseconds) to wait if lock cannot be acquired.
|
||||
* The default is 100,000 microseconds (= 0.1 seconds).
|
||||
*/
|
||||
public int $lockRetryInterval = 100_000;
|
||||
|
||||
/**
|
||||
* --------------------------------------------------------------------------
|
||||
* Lock Max Retries
|
||||
* --------------------------------------------------------------------------
|
||||
*
|
||||
* This is used for RedisHandler.
|
||||
*
|
||||
* Maximum number of lock acquisition attempts.
|
||||
* The default is 300 times. That is lock timeout is about 30 (0.1 * 300)
|
||||
* seconds.
|
||||
*/
|
||||
public int $lockMaxRetries = 300;
|
||||
}
|
||||
|
||||
244
app/Config/Toolbar.php
Executable file → Normal file
244
app/Config/Toolbar.php
Executable file → Normal file
@ -1,122 +1,122 @@
|
||||
<?php
|
||||
|
||||
namespace Config;
|
||||
|
||||
use CodeIgniter\Config\BaseConfig;
|
||||
use CodeIgniter\Debug\Toolbar\Collectors\Database;
|
||||
use CodeIgniter\Debug\Toolbar\Collectors\Events;
|
||||
use CodeIgniter\Debug\Toolbar\Collectors\Files;
|
||||
use CodeIgniter\Debug\Toolbar\Collectors\Logs;
|
||||
use CodeIgniter\Debug\Toolbar\Collectors\Routes;
|
||||
use CodeIgniter\Debug\Toolbar\Collectors\Timers;
|
||||
use CodeIgniter\Debug\Toolbar\Collectors\Views;
|
||||
|
||||
/**
|
||||
* --------------------------------------------------------------------------
|
||||
* Debug Toolbar
|
||||
* --------------------------------------------------------------------------
|
||||
*
|
||||
* The Debug Toolbar provides a way to see information about the performance
|
||||
* and state of your application during that page display. By default it will
|
||||
* NOT be displayed under production environments, and will only display if
|
||||
* `CI_DEBUG` is true, since if it's not, there's not much to display anyway.
|
||||
*/
|
||||
class Toolbar extends BaseConfig
|
||||
{
|
||||
/**
|
||||
* --------------------------------------------------------------------------
|
||||
* Toolbar Collectors
|
||||
* --------------------------------------------------------------------------
|
||||
*
|
||||
* List of toolbar collectors that will be called when Debug Toolbar
|
||||
* fires up and collects data from.
|
||||
*
|
||||
* @var list<class-string>
|
||||
*/
|
||||
public array $collectors = [
|
||||
Timers::class,
|
||||
Database::class,
|
||||
Logs::class,
|
||||
Views::class,
|
||||
// \CodeIgniter\Debug\Toolbar\Collectors\Cache::class,
|
||||
Files::class,
|
||||
Routes::class,
|
||||
Events::class,
|
||||
];
|
||||
|
||||
/**
|
||||
* --------------------------------------------------------------------------
|
||||
* Collect Var Data
|
||||
* --------------------------------------------------------------------------
|
||||
*
|
||||
* If set to false var data from the views will not be collected. Useful to
|
||||
* avoid high memory usage when there are lots of data passed to the view.
|
||||
*/
|
||||
public bool $collectVarData = true;
|
||||
|
||||
/**
|
||||
* --------------------------------------------------------------------------
|
||||
* Max History
|
||||
* --------------------------------------------------------------------------
|
||||
*
|
||||
* `$maxHistory` sets a limit on the number of past requests that are stored,
|
||||
* helping to conserve file space used to store them. You can set it to
|
||||
* 0 (zero) to not have any history stored, or -1 for unlimited history.
|
||||
*/
|
||||
public int $maxHistory = 20;
|
||||
|
||||
/**
|
||||
* --------------------------------------------------------------------------
|
||||
* Toolbar Views Path
|
||||
* --------------------------------------------------------------------------
|
||||
*
|
||||
* The full path to the the views that are used by the toolbar.
|
||||
* This MUST have a trailing slash.
|
||||
*/
|
||||
public string $viewsPath = SYSTEMPATH . 'Debug/Toolbar/Views/';
|
||||
|
||||
/**
|
||||
* --------------------------------------------------------------------------
|
||||
* Max Queries
|
||||
* --------------------------------------------------------------------------
|
||||
*
|
||||
* If the Database Collector is enabled, it will log every query that the
|
||||
* the system generates so they can be displayed on the toolbar's timeline
|
||||
* and in the query log. This can lead to memory issues in some instances
|
||||
* with hundreds of queries.
|
||||
*
|
||||
* `$maxQueries` defines the maximum amount of queries that will be stored.
|
||||
*/
|
||||
public int $maxQueries = 100;
|
||||
|
||||
/**
|
||||
* --------------------------------------------------------------------------
|
||||
* Watched Directories
|
||||
* --------------------------------------------------------------------------
|
||||
*
|
||||
* Contains an array of directories that will be watched for changes and
|
||||
* used to determine if the hot-reload feature should reload the page or not.
|
||||
* We restrict the values to keep performance as high as possible.
|
||||
*
|
||||
* NOTE: The ROOTPATH will be prepended to all values.
|
||||
*
|
||||
* @var list<string>
|
||||
*/
|
||||
public array $watchedDirectories = [
|
||||
'app',
|
||||
];
|
||||
|
||||
/**
|
||||
* --------------------------------------------------------------------------
|
||||
* Watched File Extensions
|
||||
* --------------------------------------------------------------------------
|
||||
*
|
||||
* Contains an array of file extensions that will be watched for changes and
|
||||
* used to determine if the hot-reload feature should reload the page or not.
|
||||
*
|
||||
* @var list<string>
|
||||
*/
|
||||
public array $watchedExtensions = [
|
||||
'php', 'css', 'js', 'html', 'svg', 'json', 'env',
|
||||
];
|
||||
}
|
||||
<?php
|
||||
|
||||
namespace Config;
|
||||
|
||||
use CodeIgniter\Config\BaseConfig;
|
||||
use CodeIgniter\Debug\Toolbar\Collectors\Database;
|
||||
use CodeIgniter\Debug\Toolbar\Collectors\Events;
|
||||
use CodeIgniter\Debug\Toolbar\Collectors\Files;
|
||||
use CodeIgniter\Debug\Toolbar\Collectors\Logs;
|
||||
use CodeIgniter\Debug\Toolbar\Collectors\Routes;
|
||||
use CodeIgniter\Debug\Toolbar\Collectors\Timers;
|
||||
use CodeIgniter\Debug\Toolbar\Collectors\Views;
|
||||
|
||||
/**
|
||||
* --------------------------------------------------------------------------
|
||||
* Debug Toolbar
|
||||
* --------------------------------------------------------------------------
|
||||
*
|
||||
* The Debug Toolbar provides a way to see information about the performance
|
||||
* and state of your application during that page display. By default it will
|
||||
* NOT be displayed under production environments, and will only display if
|
||||
* `CI_DEBUG` is true, since if it's not, there's not much to display anyway.
|
||||
*/
|
||||
class Toolbar extends BaseConfig
|
||||
{
|
||||
/**
|
||||
* --------------------------------------------------------------------------
|
||||
* Toolbar Collectors
|
||||
* --------------------------------------------------------------------------
|
||||
*
|
||||
* List of toolbar collectors that will be called when Debug Toolbar
|
||||
* fires up and collects data from.
|
||||
*
|
||||
* @var list<class-string>
|
||||
*/
|
||||
public array $collectors = [
|
||||
Timers::class,
|
||||
Database::class,
|
||||
Logs::class,
|
||||
Views::class,
|
||||
// \CodeIgniter\Debug\Toolbar\Collectors\Cache::class,
|
||||
Files::class,
|
||||
Routes::class,
|
||||
Events::class,
|
||||
];
|
||||
|
||||
/**
|
||||
* --------------------------------------------------------------------------
|
||||
* Collect Var Data
|
||||
* --------------------------------------------------------------------------
|
||||
*
|
||||
* If set to false var data from the views will not be collected. Useful to
|
||||
* avoid high memory usage when there are lots of data passed to the view.
|
||||
*/
|
||||
public bool $collectVarData = true;
|
||||
|
||||
/**
|
||||
* --------------------------------------------------------------------------
|
||||
* Max History
|
||||
* --------------------------------------------------------------------------
|
||||
*
|
||||
* `$maxHistory` sets a limit on the number of past requests that are stored,
|
||||
* helping to conserve file space used to store them. You can set it to
|
||||
* 0 (zero) to not have any history stored, or -1 for unlimited history.
|
||||
*/
|
||||
public int $maxHistory = 20;
|
||||
|
||||
/**
|
||||
* --------------------------------------------------------------------------
|
||||
* Toolbar Views Path
|
||||
* --------------------------------------------------------------------------
|
||||
*
|
||||
* The full path to the the views that are used by the toolbar.
|
||||
* This MUST have a trailing slash.
|
||||
*/
|
||||
public string $viewsPath = SYSTEMPATH . 'Debug/Toolbar/Views/';
|
||||
|
||||
/**
|
||||
* --------------------------------------------------------------------------
|
||||
* Max Queries
|
||||
* --------------------------------------------------------------------------
|
||||
*
|
||||
* If the Database Collector is enabled, it will log every query that the
|
||||
* the system generates so they can be displayed on the toolbar's timeline
|
||||
* and in the query log. This can lead to memory issues in some instances
|
||||
* with hundreds of queries.
|
||||
*
|
||||
* `$maxQueries` defines the maximum amount of queries that will be stored.
|
||||
*/
|
||||
public int $maxQueries = 100;
|
||||
|
||||
/**
|
||||
* --------------------------------------------------------------------------
|
||||
* Watched Directories
|
||||
* --------------------------------------------------------------------------
|
||||
*
|
||||
* Contains an array of directories that will be watched for changes and
|
||||
* used to determine if the hot-reload feature should reload the page or not.
|
||||
* We restrict the values to keep performance as high as possible.
|
||||
*
|
||||
* NOTE: The ROOTPATH will be prepended to all values.
|
||||
*
|
||||
* @var list<string>
|
||||
*/
|
||||
public array $watchedDirectories = [
|
||||
'app',
|
||||
];
|
||||
|
||||
/**
|
||||
* --------------------------------------------------------------------------
|
||||
* Watched File Extensions
|
||||
* --------------------------------------------------------------------------
|
||||
*
|
||||
* Contains an array of file extensions that will be watched for changes and
|
||||
* used to determine if the hot-reload feature should reload the page or not.
|
||||
*
|
||||
* @var list<string>
|
||||
*/
|
||||
public array $watchedExtensions = [
|
||||
'php', 'css', 'js', 'html', 'svg', 'json', 'env',
|
||||
];
|
||||
}
|
||||
|
||||
504
app/Config/UserAgents.php
Executable file → Normal file
504
app/Config/UserAgents.php
Executable file → Normal file
@ -1,252 +1,252 @@
|
||||
<?php
|
||||
|
||||
namespace Config;
|
||||
|
||||
use CodeIgniter\Config\BaseConfig;
|
||||
|
||||
/**
|
||||
* -------------------------------------------------------------------
|
||||
* User Agents
|
||||
* -------------------------------------------------------------------
|
||||
*
|
||||
* This file contains four arrays of user agent data. It is used by the
|
||||
* User Agent Class to help identify browser, platform, robot, and
|
||||
* mobile device data. The array keys are used to identify the device
|
||||
* and the array values are used to set the actual name of the item.
|
||||
*/
|
||||
class UserAgents extends BaseConfig
|
||||
{
|
||||
/**
|
||||
* -------------------------------------------------------------------
|
||||
* OS Platforms
|
||||
* -------------------------------------------------------------------
|
||||
*
|
||||
* @var array<string, string>
|
||||
*/
|
||||
public array $platforms = [
|
||||
'windows nt 10.0' => 'Windows 10',
|
||||
'windows nt 6.3' => 'Windows 8.1',
|
||||
'windows nt 6.2' => 'Windows 8',
|
||||
'windows nt 6.1' => 'Windows 7',
|
||||
'windows nt 6.0' => 'Windows Vista',
|
||||
'windows nt 5.2' => 'Windows 2003',
|
||||
'windows nt 5.1' => 'Windows XP',
|
||||
'windows nt 5.0' => 'Windows 2000',
|
||||
'windows nt 4.0' => 'Windows NT 4.0',
|
||||
'winnt4.0' => 'Windows NT 4.0',
|
||||
'winnt 4.0' => 'Windows NT',
|
||||
'winnt' => 'Windows NT',
|
||||
'windows 98' => 'Windows 98',
|
||||
'win98' => 'Windows 98',
|
||||
'windows 95' => 'Windows 95',
|
||||
'win95' => 'Windows 95',
|
||||
'windows phone' => 'Windows Phone',
|
||||
'windows' => 'Unknown Windows OS',
|
||||
'android' => 'Android',
|
||||
'blackberry' => 'BlackBerry',
|
||||
'iphone' => 'iOS',
|
||||
'ipad' => 'iOS',
|
||||
'ipod' => 'iOS',
|
||||
'os x' => 'Mac OS X',
|
||||
'ppc mac' => 'Power PC Mac',
|
||||
'freebsd' => 'FreeBSD',
|
||||
'ppc' => 'Macintosh',
|
||||
'linux' => 'Linux',
|
||||
'debian' => 'Debian',
|
||||
'sunos' => 'Sun Solaris',
|
||||
'beos' => 'BeOS',
|
||||
'apachebench' => 'ApacheBench',
|
||||
'aix' => 'AIX',
|
||||
'irix' => 'Irix',
|
||||
'osf' => 'DEC OSF',
|
||||
'hp-ux' => 'HP-UX',
|
||||
'netbsd' => 'NetBSD',
|
||||
'bsdi' => 'BSDi',
|
||||
'openbsd' => 'OpenBSD',
|
||||
'gnu' => 'GNU/Linux',
|
||||
'unix' => 'Unknown Unix OS',
|
||||
'symbian' => 'Symbian OS',
|
||||
];
|
||||
|
||||
/**
|
||||
* -------------------------------------------------------------------
|
||||
* Browsers
|
||||
* -------------------------------------------------------------------
|
||||
*
|
||||
* The order of this array should NOT be changed. Many browsers return
|
||||
* multiple browser types so we want to identify the subtype first.
|
||||
*
|
||||
* @var array<string, string>
|
||||
*/
|
||||
public array $browsers = [
|
||||
'OPR' => 'Opera',
|
||||
'Flock' => 'Flock',
|
||||
'Edge' => 'Spartan',
|
||||
'Edg' => 'Edge',
|
||||
'Chrome' => 'Chrome',
|
||||
// Opera 10+ always reports Opera/9.80 and appends Version/<real version> to the user agent string
|
||||
'Opera.*?Version' => 'Opera',
|
||||
'Opera' => 'Opera',
|
||||
'MSIE' => 'Internet Explorer',
|
||||
'Internet Explorer' => 'Internet Explorer',
|
||||
'Trident.* rv' => 'Internet Explorer',
|
||||
'Shiira' => 'Shiira',
|
||||
'Firefox' => 'Firefox',
|
||||
'Chimera' => 'Chimera',
|
||||
'Phoenix' => 'Phoenix',
|
||||
'Firebird' => 'Firebird',
|
||||
'Camino' => 'Camino',
|
||||
'Netscape' => 'Netscape',
|
||||
'OmniWeb' => 'OmniWeb',
|
||||
'Safari' => 'Safari',
|
||||
'Mozilla' => 'Mozilla',
|
||||
'Konqueror' => 'Konqueror',
|
||||
'icab' => 'iCab',
|
||||
'Lynx' => 'Lynx',
|
||||
'Links' => 'Links',
|
||||
'hotjava' => 'HotJava',
|
||||
'amaya' => 'Amaya',
|
||||
'IBrowse' => 'IBrowse',
|
||||
'Maxthon' => 'Maxthon',
|
||||
'Ubuntu' => 'Ubuntu Web Browser',
|
||||
'Vivaldi' => 'Vivaldi',
|
||||
];
|
||||
|
||||
/**
|
||||
* -------------------------------------------------------------------
|
||||
* Mobiles
|
||||
* -------------------------------------------------------------------
|
||||
*
|
||||
* @var array<string, string>
|
||||
*/
|
||||
public array $mobiles = [
|
||||
// legacy array, old values commented out
|
||||
'mobileexplorer' => 'Mobile Explorer',
|
||||
// 'openwave' => 'Open Wave',
|
||||
// 'opera mini' => 'Opera Mini',
|
||||
// 'operamini' => 'Opera Mini',
|
||||
// 'elaine' => 'Palm',
|
||||
'palmsource' => 'Palm',
|
||||
// 'digital paths' => 'Palm',
|
||||
// 'avantgo' => 'Avantgo',
|
||||
// 'xiino' => 'Xiino',
|
||||
'palmscape' => 'Palmscape',
|
||||
// 'nokia' => 'Nokia',
|
||||
// 'ericsson' => 'Ericsson',
|
||||
// 'blackberry' => 'BlackBerry',
|
||||
// 'motorola' => 'Motorola'
|
||||
|
||||
// Phones and Manufacturers
|
||||
'motorola' => 'Motorola',
|
||||
'nokia' => 'Nokia',
|
||||
'palm' => 'Palm',
|
||||
'iphone' => 'Apple iPhone',
|
||||
'ipad' => 'iPad',
|
||||
'ipod' => 'Apple iPod Touch',
|
||||
'sony' => 'Sony Ericsson',
|
||||
'ericsson' => 'Sony Ericsson',
|
||||
'blackberry' => 'BlackBerry',
|
||||
'cocoon' => 'O2 Cocoon',
|
||||
'blazer' => 'Treo',
|
||||
'lg' => 'LG',
|
||||
'amoi' => 'Amoi',
|
||||
'xda' => 'XDA',
|
||||
'mda' => 'MDA',
|
||||
'vario' => 'Vario',
|
||||
'htc' => 'HTC',
|
||||
'samsung' => 'Samsung',
|
||||
'sharp' => 'Sharp',
|
||||
'sie-' => 'Siemens',
|
||||
'alcatel' => 'Alcatel',
|
||||
'benq' => 'BenQ',
|
||||
'ipaq' => 'HP iPaq',
|
||||
'mot-' => 'Motorola',
|
||||
'playstation portable' => 'PlayStation Portable',
|
||||
'playstation 3' => 'PlayStation 3',
|
||||
'playstation vita' => 'PlayStation Vita',
|
||||
'hiptop' => 'Danger Hiptop',
|
||||
'nec-' => 'NEC',
|
||||
'panasonic' => 'Panasonic',
|
||||
'philips' => 'Philips',
|
||||
'sagem' => 'Sagem',
|
||||
'sanyo' => 'Sanyo',
|
||||
'spv' => 'SPV',
|
||||
'zte' => 'ZTE',
|
||||
'sendo' => 'Sendo',
|
||||
'nintendo dsi' => 'Nintendo DSi',
|
||||
'nintendo ds' => 'Nintendo DS',
|
||||
'nintendo 3ds' => 'Nintendo 3DS',
|
||||
'wii' => 'Nintendo Wii',
|
||||
'open web' => 'Open Web',
|
||||
'openweb' => 'OpenWeb',
|
||||
|
||||
// Operating Systems
|
||||
'android' => 'Android',
|
||||
'symbian' => 'Symbian',
|
||||
'SymbianOS' => 'SymbianOS',
|
||||
'elaine' => 'Palm',
|
||||
'series60' => 'Symbian S60',
|
||||
'windows ce' => 'Windows CE',
|
||||
|
||||
// Browsers
|
||||
'obigo' => 'Obigo',
|
||||
'netfront' => 'Netfront Browser',
|
||||
'openwave' => 'Openwave Browser',
|
||||
'mobilexplorer' => 'Mobile Explorer',
|
||||
'operamini' => 'Opera Mini',
|
||||
'opera mini' => 'Opera Mini',
|
||||
'opera mobi' => 'Opera Mobile',
|
||||
'fennec' => 'Firefox Mobile',
|
||||
|
||||
// Other
|
||||
'digital paths' => 'Digital Paths',
|
||||
'avantgo' => 'AvantGo',
|
||||
'xiino' => 'Xiino',
|
||||
'novarra' => 'Novarra Transcoder',
|
||||
'vodafone' => 'Vodafone',
|
||||
'docomo' => 'NTT DoCoMo',
|
||||
'o2' => 'O2',
|
||||
|
||||
// Fallback
|
||||
'mobile' => 'Generic Mobile',
|
||||
'wireless' => 'Generic Mobile',
|
||||
'j2me' => 'Generic Mobile',
|
||||
'midp' => 'Generic Mobile',
|
||||
'cldc' => 'Generic Mobile',
|
||||
'up.link' => 'Generic Mobile',
|
||||
'up.browser' => 'Generic Mobile',
|
||||
'smartphone' => 'Generic Mobile',
|
||||
'cellphone' => 'Generic Mobile',
|
||||
];
|
||||
|
||||
/**
|
||||
* -------------------------------------------------------------------
|
||||
* Robots
|
||||
* -------------------------------------------------------------------
|
||||
*
|
||||
* There are hundred of bots but these are the most common.
|
||||
*
|
||||
* @var array<string, string>
|
||||
*/
|
||||
public array $robots = [
|
||||
'googlebot' => 'Googlebot',
|
||||
'msnbot' => 'MSNBot',
|
||||
'baiduspider' => 'Baiduspider',
|
||||
'bingbot' => 'Bing',
|
||||
'slurp' => 'Inktomi Slurp',
|
||||
'yahoo' => 'Yahoo',
|
||||
'ask jeeves' => 'Ask Jeeves',
|
||||
'fastcrawler' => 'FastCrawler',
|
||||
'infoseek' => 'InfoSeek Robot 1.0',
|
||||
'lycos' => 'Lycos',
|
||||
'yandex' => 'YandexBot',
|
||||
'mediapartners-google' => 'MediaPartners Google',
|
||||
'CRAZYWEBCRAWLER' => 'Crazy Webcrawler',
|
||||
'adsbot-google' => 'AdsBot Google',
|
||||
'feedfetcher-google' => 'Feedfetcher Google',
|
||||
'curious george' => 'Curious George',
|
||||
'ia_archiver' => 'Alexa Crawler',
|
||||
'MJ12bot' => 'Majestic-12',
|
||||
'Uptimebot' => 'Uptimebot',
|
||||
];
|
||||
}
|
||||
<?php
|
||||
|
||||
namespace Config;
|
||||
|
||||
use CodeIgniter\Config\BaseConfig;
|
||||
|
||||
/**
|
||||
* -------------------------------------------------------------------
|
||||
* User Agents
|
||||
* -------------------------------------------------------------------
|
||||
*
|
||||
* This file contains four arrays of user agent data. It is used by the
|
||||
* User Agent Class to help identify browser, platform, robot, and
|
||||
* mobile device data. The array keys are used to identify the device
|
||||
* and the array values are used to set the actual name of the item.
|
||||
*/
|
||||
class UserAgents extends BaseConfig
|
||||
{
|
||||
/**
|
||||
* -------------------------------------------------------------------
|
||||
* OS Platforms
|
||||
* -------------------------------------------------------------------
|
||||
*
|
||||
* @var array<string, string>
|
||||
*/
|
||||
public array $platforms = [
|
||||
'windows nt 10.0' => 'Windows 10',
|
||||
'windows nt 6.3' => 'Windows 8.1',
|
||||
'windows nt 6.2' => 'Windows 8',
|
||||
'windows nt 6.1' => 'Windows 7',
|
||||
'windows nt 6.0' => 'Windows Vista',
|
||||
'windows nt 5.2' => 'Windows 2003',
|
||||
'windows nt 5.1' => 'Windows XP',
|
||||
'windows nt 5.0' => 'Windows 2000',
|
||||
'windows nt 4.0' => 'Windows NT 4.0',
|
||||
'winnt4.0' => 'Windows NT 4.0',
|
||||
'winnt 4.0' => 'Windows NT',
|
||||
'winnt' => 'Windows NT',
|
||||
'windows 98' => 'Windows 98',
|
||||
'win98' => 'Windows 98',
|
||||
'windows 95' => 'Windows 95',
|
||||
'win95' => 'Windows 95',
|
||||
'windows phone' => 'Windows Phone',
|
||||
'windows' => 'Unknown Windows OS',
|
||||
'android' => 'Android',
|
||||
'blackberry' => 'BlackBerry',
|
||||
'iphone' => 'iOS',
|
||||
'ipad' => 'iOS',
|
||||
'ipod' => 'iOS',
|
||||
'os x' => 'Mac OS X',
|
||||
'ppc mac' => 'Power PC Mac',
|
||||
'freebsd' => 'FreeBSD',
|
||||
'ppc' => 'Macintosh',
|
||||
'linux' => 'Linux',
|
||||
'debian' => 'Debian',
|
||||
'sunos' => 'Sun Solaris',
|
||||
'beos' => 'BeOS',
|
||||
'apachebench' => 'ApacheBench',
|
||||
'aix' => 'AIX',
|
||||
'irix' => 'Irix',
|
||||
'osf' => 'DEC OSF',
|
||||
'hp-ux' => 'HP-UX',
|
||||
'netbsd' => 'NetBSD',
|
||||
'bsdi' => 'BSDi',
|
||||
'openbsd' => 'OpenBSD',
|
||||
'gnu' => 'GNU/Linux',
|
||||
'unix' => 'Unknown Unix OS',
|
||||
'symbian' => 'Symbian OS',
|
||||
];
|
||||
|
||||
/**
|
||||
* -------------------------------------------------------------------
|
||||
* Browsers
|
||||
* -------------------------------------------------------------------
|
||||
*
|
||||
* The order of this array should NOT be changed. Many browsers return
|
||||
* multiple browser types so we want to identify the subtype first.
|
||||
*
|
||||
* @var array<string, string>
|
||||
*/
|
||||
public array $browsers = [
|
||||
'OPR' => 'Opera',
|
||||
'Flock' => 'Flock',
|
||||
'Edge' => 'Spartan',
|
||||
'Edg' => 'Edge',
|
||||
'Chrome' => 'Chrome',
|
||||
// Opera 10+ always reports Opera/9.80 and appends Version/<real version> to the user agent string
|
||||
'Opera.*?Version' => 'Opera',
|
||||
'Opera' => 'Opera',
|
||||
'MSIE' => 'Internet Explorer',
|
||||
'Internet Explorer' => 'Internet Explorer',
|
||||
'Trident.* rv' => 'Internet Explorer',
|
||||
'Shiira' => 'Shiira',
|
||||
'Firefox' => 'Firefox',
|
||||
'Chimera' => 'Chimera',
|
||||
'Phoenix' => 'Phoenix',
|
||||
'Firebird' => 'Firebird',
|
||||
'Camino' => 'Camino',
|
||||
'Netscape' => 'Netscape',
|
||||
'OmniWeb' => 'OmniWeb',
|
||||
'Safari' => 'Safari',
|
||||
'Mozilla' => 'Mozilla',
|
||||
'Konqueror' => 'Konqueror',
|
||||
'icab' => 'iCab',
|
||||
'Lynx' => 'Lynx',
|
||||
'Links' => 'Links',
|
||||
'hotjava' => 'HotJava',
|
||||
'amaya' => 'Amaya',
|
||||
'IBrowse' => 'IBrowse',
|
||||
'Maxthon' => 'Maxthon',
|
||||
'Ubuntu' => 'Ubuntu Web Browser',
|
||||
'Vivaldi' => 'Vivaldi',
|
||||
];
|
||||
|
||||
/**
|
||||
* -------------------------------------------------------------------
|
||||
* Mobiles
|
||||
* -------------------------------------------------------------------
|
||||
*
|
||||
* @var array<string, string>
|
||||
*/
|
||||
public array $mobiles = [
|
||||
// legacy array, old values commented out
|
||||
'mobileexplorer' => 'Mobile Explorer',
|
||||
// 'openwave' => 'Open Wave',
|
||||
// 'opera mini' => 'Opera Mini',
|
||||
// 'operamini' => 'Opera Mini',
|
||||
// 'elaine' => 'Palm',
|
||||
'palmsource' => 'Palm',
|
||||
// 'digital paths' => 'Palm',
|
||||
// 'avantgo' => 'Avantgo',
|
||||
// 'xiino' => 'Xiino',
|
||||
'palmscape' => 'Palmscape',
|
||||
// 'nokia' => 'Nokia',
|
||||
// 'ericsson' => 'Ericsson',
|
||||
// 'blackberry' => 'BlackBerry',
|
||||
// 'motorola' => 'Motorola'
|
||||
|
||||
// Phones and Manufacturers
|
||||
'motorola' => 'Motorola',
|
||||
'nokia' => 'Nokia',
|
||||
'palm' => 'Palm',
|
||||
'iphone' => 'Apple iPhone',
|
||||
'ipad' => 'iPad',
|
||||
'ipod' => 'Apple iPod Touch',
|
||||
'sony' => 'Sony Ericsson',
|
||||
'ericsson' => 'Sony Ericsson',
|
||||
'blackberry' => 'BlackBerry',
|
||||
'cocoon' => 'O2 Cocoon',
|
||||
'blazer' => 'Treo',
|
||||
'lg' => 'LG',
|
||||
'amoi' => 'Amoi',
|
||||
'xda' => 'XDA',
|
||||
'mda' => 'MDA',
|
||||
'vario' => 'Vario',
|
||||
'htc' => 'HTC',
|
||||
'samsung' => 'Samsung',
|
||||
'sharp' => 'Sharp',
|
||||
'sie-' => 'Siemens',
|
||||
'alcatel' => 'Alcatel',
|
||||
'benq' => 'BenQ',
|
||||
'ipaq' => 'HP iPaq',
|
||||
'mot-' => 'Motorola',
|
||||
'playstation portable' => 'PlayStation Portable',
|
||||
'playstation 3' => 'PlayStation 3',
|
||||
'playstation vita' => 'PlayStation Vita',
|
||||
'hiptop' => 'Danger Hiptop',
|
||||
'nec-' => 'NEC',
|
||||
'panasonic' => 'Panasonic',
|
||||
'philips' => 'Philips',
|
||||
'sagem' => 'Sagem',
|
||||
'sanyo' => 'Sanyo',
|
||||
'spv' => 'SPV',
|
||||
'zte' => 'ZTE',
|
||||
'sendo' => 'Sendo',
|
||||
'nintendo dsi' => 'Nintendo DSi',
|
||||
'nintendo ds' => 'Nintendo DS',
|
||||
'nintendo 3ds' => 'Nintendo 3DS',
|
||||
'wii' => 'Nintendo Wii',
|
||||
'open web' => 'Open Web',
|
||||
'openweb' => 'OpenWeb',
|
||||
|
||||
// Operating Systems
|
||||
'android' => 'Android',
|
||||
'symbian' => 'Symbian',
|
||||
'SymbianOS' => 'SymbianOS',
|
||||
'elaine' => 'Palm',
|
||||
'series60' => 'Symbian S60',
|
||||
'windows ce' => 'Windows CE',
|
||||
|
||||
// Browsers
|
||||
'obigo' => 'Obigo',
|
||||
'netfront' => 'Netfront Browser',
|
||||
'openwave' => 'Openwave Browser',
|
||||
'mobilexplorer' => 'Mobile Explorer',
|
||||
'operamini' => 'Opera Mini',
|
||||
'opera mini' => 'Opera Mini',
|
||||
'opera mobi' => 'Opera Mobile',
|
||||
'fennec' => 'Firefox Mobile',
|
||||
|
||||
// Other
|
||||
'digital paths' => 'Digital Paths',
|
||||
'avantgo' => 'AvantGo',
|
||||
'xiino' => 'Xiino',
|
||||
'novarra' => 'Novarra Transcoder',
|
||||
'vodafone' => 'Vodafone',
|
||||
'docomo' => 'NTT DoCoMo',
|
||||
'o2' => 'O2',
|
||||
|
||||
// Fallback
|
||||
'mobile' => 'Generic Mobile',
|
||||
'wireless' => 'Generic Mobile',
|
||||
'j2me' => 'Generic Mobile',
|
||||
'midp' => 'Generic Mobile',
|
||||
'cldc' => 'Generic Mobile',
|
||||
'up.link' => 'Generic Mobile',
|
||||
'up.browser' => 'Generic Mobile',
|
||||
'smartphone' => 'Generic Mobile',
|
||||
'cellphone' => 'Generic Mobile',
|
||||
];
|
||||
|
||||
/**
|
||||
* -------------------------------------------------------------------
|
||||
* Robots
|
||||
* -------------------------------------------------------------------
|
||||
*
|
||||
* There are hundred of bots but these are the most common.
|
||||
*
|
||||
* @var array<string, string>
|
||||
*/
|
||||
public array $robots = [
|
||||
'googlebot' => 'Googlebot',
|
||||
'msnbot' => 'MSNBot',
|
||||
'baiduspider' => 'Baiduspider',
|
||||
'bingbot' => 'Bing',
|
||||
'slurp' => 'Inktomi Slurp',
|
||||
'yahoo' => 'Yahoo',
|
||||
'ask jeeves' => 'Ask Jeeves',
|
||||
'fastcrawler' => 'FastCrawler',
|
||||
'infoseek' => 'InfoSeek Robot 1.0',
|
||||
'lycos' => 'Lycos',
|
||||
'yandex' => 'YandexBot',
|
||||
'mediapartners-google' => 'MediaPartners Google',
|
||||
'CRAZYWEBCRAWLER' => 'Crazy Webcrawler',
|
||||
'adsbot-google' => 'AdsBot Google',
|
||||
'feedfetcher-google' => 'Feedfetcher Google',
|
||||
'curious george' => 'Curious George',
|
||||
'ia_archiver' => 'Alexa Crawler',
|
||||
'MJ12bot' => 'Majestic-12',
|
||||
'Uptimebot' => 'Uptimebot',
|
||||
];
|
||||
}
|
||||
|
||||
88
app/Config/Validation.php
Executable file → Normal file
88
app/Config/Validation.php
Executable file → Normal file
@ -1,44 +1,44 @@
|
||||
<?php
|
||||
|
||||
namespace Config;
|
||||
|
||||
use CodeIgniter\Config\BaseConfig;
|
||||
use CodeIgniter\Validation\StrictRules\CreditCardRules;
|
||||
use CodeIgniter\Validation\StrictRules\FileRules;
|
||||
use CodeIgniter\Validation\StrictRules\FormatRules;
|
||||
use CodeIgniter\Validation\StrictRules\Rules;
|
||||
|
||||
class Validation extends BaseConfig
|
||||
{
|
||||
// --------------------------------------------------------------------
|
||||
// Setup
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Stores the classes that contain the
|
||||
* rules that are available.
|
||||
*
|
||||
* @var list<string>
|
||||
*/
|
||||
public array $ruleSets = [
|
||||
Rules::class,
|
||||
FormatRules::class,
|
||||
FileRules::class,
|
||||
CreditCardRules::class,
|
||||
];
|
||||
|
||||
/**
|
||||
* Specifies the views that are used to display the
|
||||
* errors.
|
||||
*
|
||||
* @var array<string, string>
|
||||
*/
|
||||
public array $templates = [
|
||||
'list' => 'CodeIgniter\Validation\Views\list',
|
||||
'single' => 'CodeIgniter\Validation\Views\single',
|
||||
];
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
// Rules
|
||||
// --------------------------------------------------------------------
|
||||
}
|
||||
<?php
|
||||
|
||||
namespace Config;
|
||||
|
||||
use CodeIgniter\Config\BaseConfig;
|
||||
use CodeIgniter\Validation\StrictRules\CreditCardRules;
|
||||
use CodeIgniter\Validation\StrictRules\FileRules;
|
||||
use CodeIgniter\Validation\StrictRules\FormatRules;
|
||||
use CodeIgniter\Validation\StrictRules\Rules;
|
||||
|
||||
class Validation extends BaseConfig
|
||||
{
|
||||
// --------------------------------------------------------------------
|
||||
// Setup
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Stores the classes that contain the
|
||||
* rules that are available.
|
||||
*
|
||||
* @var list<string>
|
||||
*/
|
||||
public array $ruleSets = [
|
||||
Rules::class,
|
||||
FormatRules::class,
|
||||
FileRules::class,
|
||||
CreditCardRules::class,
|
||||
];
|
||||
|
||||
/**
|
||||
* Specifies the views that are used to display the
|
||||
* errors.
|
||||
*
|
||||
* @var array<string, string>
|
||||
*/
|
||||
public array $templates = [
|
||||
'list' => 'CodeIgniter\Validation\Views\list',
|
||||
'single' => 'CodeIgniter\Validation\Views\single',
|
||||
];
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
// Rules
|
||||
// --------------------------------------------------------------------
|
||||
}
|
||||
|
||||
124
app/Config/View.php
Executable file → Normal file
124
app/Config/View.php
Executable file → Normal file
@ -1,62 +1,62 @@
|
||||
<?php
|
||||
|
||||
namespace Config;
|
||||
|
||||
use CodeIgniter\Config\View as BaseView;
|
||||
use CodeIgniter\View\ViewDecoratorInterface;
|
||||
|
||||
/**
|
||||
* @phpstan-type parser_callable (callable(mixed): mixed)
|
||||
* @phpstan-type parser_callable_string (callable(mixed): mixed)&string
|
||||
*/
|
||||
class View extends BaseView
|
||||
{
|
||||
/**
|
||||
* When false, the view method will clear the data between each
|
||||
* call. This keeps your data safe and ensures there is no accidental
|
||||
* leaking between calls, so you would need to explicitly pass the data
|
||||
* to each view. You might prefer to have the data stick around between
|
||||
* calls so that it is available to all views. If that is the case,
|
||||
* set $saveData to true.
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
public $saveData = true;
|
||||
|
||||
/**
|
||||
* Parser Filters map a filter name with any PHP callable. When the
|
||||
* Parser prepares a variable for display, it will chain it
|
||||
* through the filters in the order defined, inserting any parameters.
|
||||
* To prevent potential abuse, all filters MUST be defined here
|
||||
* in order for them to be available for use within the Parser.
|
||||
*
|
||||
* Examples:
|
||||
* { title|esc(js) }
|
||||
* { created_on|date(Y-m-d)|esc(attr) }
|
||||
*
|
||||
* @var array<string, string>
|
||||
* @phpstan-var array<string, parser_callable_string>
|
||||
*/
|
||||
public $filters = [];
|
||||
|
||||
/**
|
||||
* Parser Plugins provide a way to extend the functionality provided
|
||||
* by the core Parser by creating aliases that will be replaced with
|
||||
* any callable. Can be single or tag pair.
|
||||
*
|
||||
* @var array<string, callable|list<string>|string>
|
||||
* @phpstan-var array<string, list<parser_callable_string>|parser_callable_string|parser_callable>
|
||||
*/
|
||||
public $plugins = [];
|
||||
|
||||
/**
|
||||
* View Decorators are class methods that will be run in sequence to
|
||||
* have a chance to alter the generated output just prior to caching
|
||||
* the results.
|
||||
*
|
||||
* All classes must implement CodeIgniter\View\ViewDecoratorInterface
|
||||
*
|
||||
* @var list<class-string<ViewDecoratorInterface>>
|
||||
*/
|
||||
public array $decorators = [];
|
||||
}
|
||||
<?php
|
||||
|
||||
namespace Config;
|
||||
|
||||
use CodeIgniter\Config\View as BaseView;
|
||||
use CodeIgniter\View\ViewDecoratorInterface;
|
||||
|
||||
/**
|
||||
* @phpstan-type parser_callable (callable(mixed): mixed)
|
||||
* @phpstan-type parser_callable_string (callable(mixed): mixed)&string
|
||||
*/
|
||||
class View extends BaseView
|
||||
{
|
||||
/**
|
||||
* When false, the view method will clear the data between each
|
||||
* call. This keeps your data safe and ensures there is no accidental
|
||||
* leaking between calls, so you would need to explicitly pass the data
|
||||
* to each view. You might prefer to have the data stick around between
|
||||
* calls so that it is available to all views. If that is the case,
|
||||
* set $saveData to true.
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
public $saveData = true;
|
||||
|
||||
/**
|
||||
* Parser Filters map a filter name with any PHP callable. When the
|
||||
* Parser prepares a variable for display, it will chain it
|
||||
* through the filters in the order defined, inserting any parameters.
|
||||
* To prevent potential abuse, all filters MUST be defined here
|
||||
* in order for them to be available for use within the Parser.
|
||||
*
|
||||
* Examples:
|
||||
* { title|esc(js) }
|
||||
* { created_on|date(Y-m-d)|esc(attr) }
|
||||
*
|
||||
* @var array<string, string>
|
||||
* @phpstan-var array<string, parser_callable_string>
|
||||
*/
|
||||
public $filters = [];
|
||||
|
||||
/**
|
||||
* Parser Plugins provide a way to extend the functionality provided
|
||||
* by the core Parser by creating aliases that will be replaced with
|
||||
* any callable. Can be single or tag pair.
|
||||
*
|
||||
* @var array<string, callable|list<string>|string>
|
||||
* @phpstan-var array<string, list<parser_callable_string>|parser_callable_string|parser_callable>
|
||||
*/
|
||||
public $plugins = [];
|
||||
|
||||
/**
|
||||
* View Decorators are class methods that will be run in sequence to
|
||||
* have a chance to alter the generated output just prior to caching
|
||||
* the results.
|
||||
*
|
||||
* All classes must implement CodeIgniter\View\ViewDecoratorInterface
|
||||
*
|
||||
* @var list<class-string<ViewDecoratorInterface>>
|
||||
*/
|
||||
public array $decorators = [];
|
||||
}
|
||||
|
||||
99
app/Controllers/AreaGeoController.php
Executable file → Normal file
99
app/Controllers/AreaGeoController.php
Executable file → Normal file
@ -1,52 +1,47 @@
|
||||
<?php
|
||||
namespace App\Controllers;
|
||||
|
||||
use App\Traits\ResponseTrait;
|
||||
use App\Controllers\BaseController;
|
||||
use App\Models\AreaGeoModel;
|
||||
|
||||
class AreaGeoController extends BaseController {
|
||||
use ResponseTrait;
|
||||
|
||||
protected $model;
|
||||
|
||||
public function __construct() {
|
||||
$this->model = new AreaGeoModel();
|
||||
}
|
||||
|
||||
public function index() {
|
||||
try {
|
||||
$filters = [
|
||||
'AreaGeoID' => $this->request->getVar('AreaGeoID') ?? null,
|
||||
'AreaName' => $this->request->getVar('AreaName') ?? null
|
||||
];
|
||||
$rows = $this->model->getAreaGeos( $filters );
|
||||
|
||||
if(empty($rows)){return $this->respond(['status'=>'success', 'message'=>"no data found.", 'data'=>$rows], 200);}
|
||||
return $this->respond(['status'=>'success', 'message'=>"data fetched successfully", 'data'=>$rows], 200);
|
||||
} catch (\Exception $e) {
|
||||
return $this->respond([ 'status' => 'error', 'message' => $e->getMessage() ], 200);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public function getProvinces() {
|
||||
$rows = $this->model->getProvinces();
|
||||
$transformed = array_map(function($row) {
|
||||
return ['value' => $row['AreaGeoID'], 'label' => $row['AreaName']];
|
||||
}, $rows);
|
||||
if (empty($transformed)) { return $this->respond([ 'status' => 'success', 'data' => [] ], 200); }
|
||||
return $this->respond([ 'status' => 'success', 'data' => $transformed ], 200);
|
||||
}
|
||||
|
||||
public function getCities() {
|
||||
$filter = [ 'Parent' => $this->request->getVar('ProvinceID') ?? null ];
|
||||
$rows = $this->model->getCities($filter);
|
||||
$transformed = array_map(function($row) {
|
||||
return ['value' => $row['AreaGeoID'], 'label' => $row['AreaName']];
|
||||
}, $rows);
|
||||
if (empty($transformed)) { return $this->respond([ 'status' => 'success', 'data' => [] ], 200); }
|
||||
return $this->respond([ 'status' => 'success', 'data' => $transformed ], 200);
|
||||
}
|
||||
|
||||
}
|
||||
<?php
|
||||
namespace App\Controllers;
|
||||
|
||||
use CodeIgniter\API\ResponseTrait;
|
||||
use App\Controllers\BaseController;
|
||||
use App\Models\AreaGeoModel;
|
||||
|
||||
class AreaGeoController extends BaseController {
|
||||
use ResponseTrait;
|
||||
|
||||
protected $model;
|
||||
|
||||
public function __construct() {
|
||||
$this->model = new AreaGeoModel();
|
||||
}
|
||||
|
||||
public function index() {
|
||||
try {
|
||||
$filters = [
|
||||
'AreaGeoID' => $this->request->getVar('AreaGeoID') ?? null,
|
||||
'AreaName' => $this->request->getVar('AreaName') ?? null
|
||||
];
|
||||
$rows = $this->model->getAreaGeos( $filters );
|
||||
|
||||
if(empty($rows)){return $this->respond(['status'=>'success', 'message'=>"no data found.", 'data'=>$rows], 200);}
|
||||
return $this->respond(['status'=>'success', 'message'=>"data fetched successfully", 'data'=>$rows], 200);
|
||||
} catch (\Exception $e) {
|
||||
return $this->respond([ 'status' => 'error', 'message' => $e->getMessage() ], 200);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public function getProvinces() {
|
||||
$rows = $this->model->getProvinces();
|
||||
if (empty($rows)) { return $this->respond([ 'status' => 'success', 'message' => "data not found", 'data' => '' ], 200); }
|
||||
return $this->respond([ 'status' => 'success', 'message'=> "Data fetched successfully", 'data' => $rows ], 200);
|
||||
}
|
||||
|
||||
public function getCities() {
|
||||
$filter = [ 'Parent' => $this->request->getVar('Parent') ?? null ];
|
||||
$rows = $this->model->getCities($filter);
|
||||
|
||||
if (empty($rows)) { return $this->respond([ 'status' => 'success', 'message' => "data not found", 'data' => [] ], 200); }
|
||||
return $this->respond([ 'status' => 'success', 'message'=> "Data fetched successfully", 'data' => $rows ], 200);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -1,60 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Controllers\Audit;
|
||||
|
||||
use App\Controllers\BaseController;
|
||||
use App\Services\AuditLogService;
|
||||
use App\Traits\ResponseTrait;
|
||||
use CodeIgniter\HTTP\ResponseInterface;
|
||||
use InvalidArgumentException;
|
||||
|
||||
class AuditLogController extends BaseController
|
||||
{
|
||||
use ResponseTrait;
|
||||
|
||||
private AuditLogService $auditLogService;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->auditLogService = new AuditLogService();
|
||||
}
|
||||
|
||||
public function index(): ResponseInterface
|
||||
{
|
||||
$filters = [
|
||||
'table' => $this->request->getGet('table'),
|
||||
'rec_id' => $this->request->getGet('rec_id') ?? $this->request->getGet('recId'),
|
||||
'event_id' => $this->request->getGet('event_id') ?? $this->request->getGet('eventId'),
|
||||
'activity_id' => $this->request->getGet('activity_id') ?? $this->request->getGet('activityId'),
|
||||
'from' => $this->request->getGet('from'),
|
||||
'to' => $this->request->getGet('to'),
|
||||
'search' => $this->request->getGet('search'),
|
||||
'page' => $this->request->getGet('page'),
|
||||
'perPage' => $this->request->getGet('perPage') ?? $this->request->getGet('per_page'),
|
||||
];
|
||||
|
||||
try {
|
||||
$payload = $this->auditLogService->fetchLogs($filters);
|
||||
|
||||
return $this->respond([
|
||||
'status' => 'success',
|
||||
'message' => 'Audit logs retrieved successfully',
|
||||
'data' => $payload,
|
||||
], 200);
|
||||
|
||||
} catch (InvalidArgumentException $e) {
|
||||
return $this->respond([
|
||||
'status' => 'failed',
|
||||
'message' => $e->getMessage(),
|
||||
'data' => null,
|
||||
], 400);
|
||||
} catch (\Throwable $e) {
|
||||
log_message('error', 'AuditLogController::index error: ' . $e->getMessage());
|
||||
return $this->respond([
|
||||
'status' => 'failed',
|
||||
'message' => 'Unable to retrieve audit logs',
|
||||
'data' => null,
|
||||
], 500);
|
||||
}
|
||||
}
|
||||
}
|
||||
650
app/Controllers/AuthController.php
Executable file → Normal file
650
app/Controllers/AuthController.php
Executable file → Normal file
@ -1,329 +1,321 @@
|
||||
<?php
|
||||
|
||||
namespace App\Controllers;
|
||||
|
||||
use App\Traits\ResponseTrait;
|
||||
use CodeIgniter\Controller;
|
||||
|
||||
use Firebase\JWT\JWT;
|
||||
use Firebase\JWT\Key;
|
||||
use Firebase\JWT\ExpiredException;
|
||||
use Firebase\JWT\SignatureInvalidException;
|
||||
use Firebase\JWT\BeforeValidException;
|
||||
use CodeIgniter\Cookie\Cookie;
|
||||
|
||||
class AuthController extends Controller
|
||||
{
|
||||
use ResponseTrait;
|
||||
|
||||
protected $db;
|
||||
|
||||
// ok
|
||||
public function __construct()
|
||||
{
|
||||
$this->db = \Config\Database::connect();
|
||||
}
|
||||
|
||||
// ok
|
||||
public function checkAuth()
|
||||
{
|
||||
$token = $this->request->getCookie('token');
|
||||
$key = getenv('JWT_SECRET');
|
||||
|
||||
// Jika token FE tidak ada langsung kabarkan failed
|
||||
if (!$token) {
|
||||
return $this->respond([
|
||||
'status' => 'failed',
|
||||
'message' => 'No token found'
|
||||
], 401);
|
||||
}
|
||||
|
||||
try {
|
||||
// Decode Token dengan Key yg ada di .env
|
||||
$decodedPayload = JWT::decode($token, new Key($key, 'HS256'));
|
||||
|
||||
return $this->respond([
|
||||
'status' => 'success',
|
||||
'message' => 'Authenticated',
|
||||
'data' => $decodedPayload
|
||||
], 200);
|
||||
|
||||
} catch (ExpiredException $e) {
|
||||
return $this->respond([
|
||||
'status' => 'failed',
|
||||
'message' => 'Token expired',
|
||||
'data' => []
|
||||
], 401);
|
||||
|
||||
} catch (SignatureInvalidException $e) {
|
||||
return $this->respond([
|
||||
'status' => 'failed',
|
||||
'message' => 'Invalid token signature',
|
||||
'data' => []
|
||||
], 401);
|
||||
|
||||
} catch (BeforeValidException $e) {
|
||||
return $this->respond([
|
||||
'status' => 'failed',
|
||||
'message' => 'Token not valid yet',
|
||||
'data' => []
|
||||
], 401);
|
||||
|
||||
} catch (\Exception $e) {
|
||||
return $this->respond([
|
||||
'status' => 'failed',
|
||||
'message' => 'Invalid token: ' . $e->getMessage(),
|
||||
'data' => []
|
||||
], 401);
|
||||
}
|
||||
}
|
||||
|
||||
// ok
|
||||
// public function login() {
|
||||
|
||||
// // Ambil dari JSON Form dan Key .env
|
||||
// $username = $this->request->getVar('username');
|
||||
// $password = $this->request->getVar('password');
|
||||
// $key = getenv('JWT_SECRET');
|
||||
|
||||
// if (!$username) {
|
||||
// return $this->fail('Username required.', 400);
|
||||
// }
|
||||
|
||||
// $sql = "SELECT * FROM users WHERE username=" . $this->db->escape($username);
|
||||
// $query = $this->db->query($sql);
|
||||
// $row = $query->getResultArray();
|
||||
|
||||
// if (!$row) { return $this->fail('User not found.', 401); }
|
||||
// $row = $row[0];
|
||||
// if (!password_verify($password, $row['password'])) {
|
||||
// return $this->fail('Invalid password.', 401);
|
||||
// }
|
||||
|
||||
// // Buat JWT payload
|
||||
// $exp = time() + 864000;
|
||||
// $payload = [
|
||||
// 'userid' => $row['id'],
|
||||
// 'roleid' => $row['role_id'],
|
||||
// 'username' => $row['username'],
|
||||
// 'exp' => $exp
|
||||
// ];
|
||||
|
||||
// try {
|
||||
// // Melakukan Hash terhadap Payload dengan Kunci .env menggunakan Algortima HMAC + SHA-256
|
||||
// $jwt = JWT::encode($payload, $key, 'HS256');
|
||||
// } catch (Exception $e) {
|
||||
// return $this->fail('Error generating JWT: ' . $e->getMessage(), 500);
|
||||
// }
|
||||
|
||||
// // Kirim Respon ke HttpOnly yg akan disimpan di browser dan tidak akan dapat diakses oleh siapapun
|
||||
// // $isSecure = isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] === 'on';
|
||||
// $this->response->setCookie([
|
||||
// // 'name' => 'token', // nama token
|
||||
// // 'value' => $jwt, // value dari jwt yg sudah di hash
|
||||
// // 'expire' => 864000, // 10 hari
|
||||
// // 'path' => '/', // valid untuk semua path
|
||||
// // 'secure' => $isSecure, // true for HTTPS, false for HTTP (localhost)
|
||||
// // 'httponly' => true, // dipakai agar cookie berikut tidak dapat diakses oleh javascript
|
||||
// // 'samesite' => $isSecure ? Cookie::SAMESITE_NONE : Cookie::SAMESITE_LAX
|
||||
// ]);
|
||||
|
||||
|
||||
// // Response tanpa token di body
|
||||
// return $this->respond([
|
||||
// 'status' => 'success',
|
||||
// 'code' => 200,
|
||||
// 'message' => 'Login successful'
|
||||
// ], 200);
|
||||
// }
|
||||
public function login()
|
||||
{
|
||||
|
||||
// Ambil dari JSON Form dan Key .env
|
||||
$username = $this->request->getVar('username');
|
||||
$password = $this->request->getVar('password');
|
||||
$key = getenv('JWT_SECRET');
|
||||
|
||||
if (!$username) {
|
||||
return $this->fail('Username required.', 400);
|
||||
}
|
||||
|
||||
$sql = "SELECT * FROM users WHERE username=" . $this->db->escape($username);
|
||||
$query = $this->db->query($sql);
|
||||
$row = $query->getResultArray();
|
||||
|
||||
if (!$row) {
|
||||
return $this->fail('User not found.', 401);
|
||||
}
|
||||
$row = $row[0];
|
||||
if (!password_verify($password, $row['password'])) {
|
||||
return $this->fail('Invalid password.', 401);
|
||||
}
|
||||
|
||||
// Buat JWT payload
|
||||
$exp = time() + 864000;
|
||||
$payload = [
|
||||
'userid' => $row['id'],
|
||||
'roleid' => $row['role_id'],
|
||||
'username' => $row['username'],
|
||||
'exp' => $exp
|
||||
];
|
||||
|
||||
try {
|
||||
// Melakukan Hash terhadap Payload dengan Kunci .env menggunakan Algortima HMAC + SHA-256
|
||||
$jwt = JWT::encode($payload, $key, 'HS256');
|
||||
} catch (\Exception $e) {
|
||||
return $this->fail('Error generating JWT: ' . $e->getMessage(), 500);
|
||||
}
|
||||
|
||||
// Detect if HTTPS is being used
|
||||
$isSecure = isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] === 'on';
|
||||
|
||||
// Kirim Respon ke HttpOnly yg akan disimpan di browser dan tidak akan dapat diakses oleh siapapun
|
||||
$this->response->setCookie([
|
||||
'name' => 'token', // nama token
|
||||
'value' => $jwt, // value dari jwt yg sudah di hash
|
||||
'expire' => 864000, // 10 hari
|
||||
'path' => '/', // valid untuk semua path
|
||||
'secure' => $isSecure,
|
||||
'httponly' => true, // dipakai agar cookie berikut tidak dapat diakses oleh javascript
|
||||
'samesite' => $isSecure ? Cookie::SAMESITE_NONE : Cookie::SAMESITE_LAX
|
||||
]);
|
||||
|
||||
// Response tanpa token di body
|
||||
return $this->respond([
|
||||
'status' => 'success',
|
||||
'code' => 200,
|
||||
'message' => 'Login successful'
|
||||
], 200);
|
||||
}
|
||||
|
||||
// ok
|
||||
// public function logout() {
|
||||
// // Definisikan ini pada cookies browser, harus sama dengan cookies login
|
||||
// // $isSecure = isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] === 'on';
|
||||
// return $this->response->setCookie([
|
||||
// 'name' => 'token',
|
||||
// 'value' => '',
|
||||
// 'expire' => time() - 3600,
|
||||
// 'path' => '/',
|
||||
// 'secure' => $isSecure,
|
||||
// 'httponly' => true,
|
||||
// 'samesite' => $isSecure ? Cookie::SAMESITE_NONE : Cookie::SAMESITE_LAX
|
||||
|
||||
// ])->setJSON([
|
||||
// 'status' => 'success',
|
||||
// 'code' => 200,
|
||||
// 'message' => 'Logout successful'
|
||||
// ], 200);
|
||||
// }
|
||||
public function logout()
|
||||
{
|
||||
// Detect if HTTPS is being used
|
||||
$isSecure = isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] === 'on';
|
||||
|
||||
// Definisikan ini pada cookies browser, harus sama dengan cookies login
|
||||
return $this->response->setCookie([
|
||||
'name' => 'token',
|
||||
'value' => '',
|
||||
'expire' => time() - 3600,
|
||||
'path' => '/',
|
||||
'secure' => $isSecure,
|
||||
'httponly' => true,
|
||||
'samesite' => $isSecure ? Cookie::SAMESITE_NONE : Cookie::SAMESITE_LAX
|
||||
|
||||
])->setJSON([
|
||||
'status' => 'success',
|
||||
'code' => 200,
|
||||
'message' => 'Logout successful'
|
||||
], 200);
|
||||
}
|
||||
|
||||
// ok
|
||||
public function register()
|
||||
{
|
||||
|
||||
$username = strtolower($this->request->getJsonVar('username'));
|
||||
$password = $this->request->getJsonVar('password');
|
||||
|
||||
// Validasi Awal Dari BE
|
||||
if (empty($username) || empty($password)) {
|
||||
return $this->respond([
|
||||
'status' => 'failed',
|
||||
'code' => 400,
|
||||
'message' => 'Username and password are required'
|
||||
], 400); // Gunakan 400 Bad Request
|
||||
}
|
||||
|
||||
// Cek Duplikasi Username
|
||||
$exists = $this->db->query("SELECT id FROM users WHERE username = ?", [$username])->getRow();
|
||||
if ($exists) {
|
||||
return $this->respond(['status' => 'failed', 'code' => 409, 'message' => 'Username already exists'], 409);
|
||||
}
|
||||
|
||||
$hashedPassword = password_hash($password, PASSWORD_DEFAULT);
|
||||
|
||||
// Mulai transaksi Insert
|
||||
$this->db->transStart();
|
||||
$this->db->query(
|
||||
"INSERT INTO users(username, password, role_id) VALUES(?, ?, ?)",
|
||||
[$username, $hashedPassword, 1]
|
||||
);
|
||||
$this->db->transComplete();
|
||||
|
||||
// Cek status transaksi
|
||||
if ($this->db->transStatus() === false) {
|
||||
return $this->respond([
|
||||
'status' => 'error',
|
||||
'code' => 500,
|
||||
'message' => 'Failed to create user. Please try again later.'
|
||||
], 500);
|
||||
}
|
||||
|
||||
// Respon sukses jika kueri berhasil
|
||||
return $this->respond([
|
||||
'status' => 'success',
|
||||
'code' => 201,
|
||||
'message' => 'User ' . $username . ' successfully created.'
|
||||
], 201);
|
||||
|
||||
}
|
||||
|
||||
// public function change_pass() {
|
||||
// $db = \Config\Database::connect();
|
||||
// $username = $this->request->getJsonVar('username');
|
||||
// $password = $this->request->getJsonVar('password');
|
||||
// $password = password_hash($password, PASSWORD_DEFAULT);
|
||||
|
||||
// $master = $this->request->getJsonVar('master');
|
||||
// $masterkey = getenv('masterkey');
|
||||
|
||||
// if($master != $masterkey) {
|
||||
// return $this->fail('Invalid master key.', 401);
|
||||
// }
|
||||
|
||||
// $sql = "update users set password='$password' where username='$username'";
|
||||
// $query = $db->query($sql);
|
||||
// $response = [
|
||||
// 'message' => "Password Changed for $username"
|
||||
// ];
|
||||
// return $this->respond($response);
|
||||
// }
|
||||
|
||||
public function coba()
|
||||
{
|
||||
|
||||
$token = $this->request->getCookie('token');
|
||||
$key = getenv('JWT_SECRET');
|
||||
|
||||
// Decode Token dengan Key yg ada di .env
|
||||
$decodedPayload = JWT::decode($token, new Key($key, 'HS256'));
|
||||
|
||||
return $this->respond([
|
||||
'status' => 'success',
|
||||
'message' => 'Authenticated',
|
||||
'data' => $decodedPayload
|
||||
], 200);
|
||||
}
|
||||
|
||||
}
|
||||
<?php
|
||||
|
||||
namespace App\Controllers;
|
||||
|
||||
use CodeIgniter\API\ResponseTrait;
|
||||
use CodeIgniter\Controller;
|
||||
|
||||
use Firebase\JWT\JWT;
|
||||
use Firebase\JWT\Key;
|
||||
use Firebase\JWT\ExpiredException;
|
||||
use Firebase\JWT\SignatureInvalidException;
|
||||
use Firebase\JWT\BeforeValidException;
|
||||
use CodeIgniter\Cookie\Cookie;
|
||||
|
||||
class AuthController extends Controller
|
||||
{
|
||||
use ResponseTrait;
|
||||
|
||||
// ok
|
||||
public function __construct()
|
||||
{
|
||||
$this->db = \Config\Database::connect();
|
||||
}
|
||||
|
||||
// ok
|
||||
public function checkAuth()
|
||||
{
|
||||
$token = $this->request->getCookie('token');
|
||||
$key = getenv('JWT_SECRET');
|
||||
|
||||
// Jika token FE tidak ada langsung kabarkan failed
|
||||
if (!$token) {
|
||||
return $this->respond([
|
||||
'status' => 'failed',
|
||||
'message' => 'No token found'
|
||||
], 401);
|
||||
}
|
||||
|
||||
try {
|
||||
// Decode Token dengan Key yg ada di .env
|
||||
$decodedPayload = JWT::decode($token, new Key($key, 'HS256'));
|
||||
|
||||
return $this->respond([
|
||||
'status' => 'success',
|
||||
'message' => 'Authenticated',
|
||||
'data' => $decodedPayload
|
||||
], 200);
|
||||
|
||||
} catch (ExpiredException $e) {
|
||||
return $this->respond([
|
||||
'status' => 'failed',
|
||||
'message' => 'Token expired',
|
||||
'data' => []
|
||||
], 401);
|
||||
|
||||
} catch (SignatureInvalidException $e) {
|
||||
return $this->respond([
|
||||
'status' => 'failed',
|
||||
'message' => 'Invalid token signature',
|
||||
'data' => []
|
||||
], 401);
|
||||
|
||||
} catch (BeforeValidException $e) {
|
||||
return $this->respond([
|
||||
'status' => 'failed',
|
||||
'message' => 'Token not valid yet',
|
||||
'data' => []
|
||||
], 401);
|
||||
|
||||
} catch (\Exception $e) {
|
||||
return $this->respond([
|
||||
'status' => 'failed',
|
||||
'message' => 'Invalid token: ' . $e->getMessage(),
|
||||
'data' => []
|
||||
], 401);
|
||||
}
|
||||
}
|
||||
|
||||
// ok
|
||||
// public function login() {
|
||||
|
||||
// // Ambil dari JSON Form dan Key .env
|
||||
// $username = $this->request->getVar('username');
|
||||
// $password = $this->request->getVar('password');
|
||||
// $key = getenv('JWT_SECRET');
|
||||
|
||||
// if (!$username) {
|
||||
// return $this->fail('Username required.', 400);
|
||||
// }
|
||||
|
||||
// $sql = "SELECT * FROM users WHERE username=" . $this->db->escape($username);
|
||||
// $query = $this->db->query($sql);
|
||||
// $row = $query->getResultArray();
|
||||
|
||||
// if (!$row) { return $this->fail('User not found.', 401); }
|
||||
// $row = $row[0];
|
||||
// if (!password_verify($password, $row['password'])) {
|
||||
// return $this->fail('Invalid password.', 401);
|
||||
// }
|
||||
|
||||
// // Buat JWT payload
|
||||
// $exp = time() + 864000;
|
||||
// $payload = [
|
||||
// 'userid' => $row['id'],
|
||||
// 'roleid' => $row['role_id'],
|
||||
// 'username' => $row['username'],
|
||||
// 'exp' => $exp
|
||||
// ];
|
||||
|
||||
// try {
|
||||
// // Melakukan Hash terhadap Payload dengan Kunci .env menggunakan Algortima HMAC + SHA-256
|
||||
// $jwt = JWT::encode($payload, $key, 'HS256');
|
||||
// } catch (Exception $e) {
|
||||
// return $this->fail('Error generating JWT: ' . $e->getMessage(), 500);
|
||||
// }
|
||||
|
||||
// // Kirim Respon ke HttpOnly yg akan disimpan di browser dan tidak akan dapat diakses oleh siapapun
|
||||
// // $isSecure = isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] === 'on';
|
||||
// $this->response->setCookie([
|
||||
// // 'name' => 'token', // nama token
|
||||
// // 'value' => $jwt, // value dari jwt yg sudah di hash
|
||||
// // 'expire' => 864000, // 10 hari
|
||||
// // 'path' => '/', // valid untuk semua path
|
||||
// // 'secure' => $isSecure, // true for HTTPS, false for HTTP (localhost)
|
||||
// // 'httponly' => true, // dipakai agar cookie berikut tidak dapat diakses oleh javascript
|
||||
// // 'samesite' => $isSecure ? Cookie::SAMESITE_NONE : Cookie::SAMESITE_LAX
|
||||
// ]);
|
||||
|
||||
|
||||
// // Response tanpa token di body
|
||||
// return $this->respond([
|
||||
// 'status' => 'success',
|
||||
// 'code' => 200,
|
||||
// 'message' => 'Login successful'
|
||||
// ], 200);
|
||||
// }
|
||||
public function login()
|
||||
{
|
||||
|
||||
// Ambil dari JSON Form dan Key .env
|
||||
$username = $this->request->getVar('username');
|
||||
$password = $this->request->getVar('password');
|
||||
$key = getenv('JWT_SECRET');
|
||||
|
||||
if (!$username) {
|
||||
return $this->fail('Username required.', 400);
|
||||
}
|
||||
|
||||
$sql = "SELECT * FROM users WHERE username=" . $this->db->escape($username);
|
||||
$query = $this->db->query($sql);
|
||||
$row = $query->getResultArray();
|
||||
|
||||
if (!$row) {
|
||||
return $this->fail('User not found.', 401);
|
||||
}
|
||||
$row = $row[0];
|
||||
if (!password_verify($password, $row['password'])) {
|
||||
return $this->fail('Invalid password.', 401);
|
||||
}
|
||||
|
||||
// Buat JWT payload
|
||||
$exp = time() + 864000;
|
||||
$payload = [
|
||||
'userid' => $row['id'],
|
||||
'roleid' => $row['role_id'],
|
||||
'username' => $row['username'],
|
||||
'exp' => $exp
|
||||
];
|
||||
|
||||
try {
|
||||
// Melakukan Hash terhadap Payload dengan Kunci .env menggunakan Algortima HMAC + SHA-256
|
||||
$jwt = JWT::encode($payload, $key, 'HS256');
|
||||
} catch (Exception $e) {
|
||||
return $this->fail('Error generating JWT: ' . $e->getMessage(), 500);
|
||||
}
|
||||
|
||||
// Kirim Respon ke HttpOnly yg akan disimpan di browser dan tidak akan dapat diakses oleh siapapun
|
||||
$this->response->setCookie([
|
||||
'name' => 'token', // nama token
|
||||
'value' => $jwt, // value dari jwt yg sudah di hash
|
||||
'expire' => 864000, // 10 hari
|
||||
'path' => '/', // valid untuk semua path
|
||||
'secure' => true, // set true kalau sudah HTTPS
|
||||
'httponly' => true, // dipakai agar cookie berikut tidak dapat diakses oleh javascript
|
||||
'samesite' => Cookie::SAMESITE_NONE
|
||||
]);
|
||||
|
||||
// Response tanpa token di body
|
||||
return $this->respond([
|
||||
'status' => 'success',
|
||||
'code' => 200,
|
||||
'message' => 'Login successful'
|
||||
], 200);
|
||||
}
|
||||
|
||||
// ok
|
||||
// public function logout() {
|
||||
// // Definisikan ini pada cookies browser, harus sama dengan cookies login
|
||||
// // $isSecure = isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] === 'on';
|
||||
// return $this->response->setCookie([
|
||||
// 'name' => 'token',
|
||||
// 'value' => '',
|
||||
// 'expire' => time() - 3600,
|
||||
// 'path' => '/',
|
||||
// 'secure' => $isSecure,
|
||||
// 'httponly' => true,
|
||||
// 'samesite' => $isSecure ? Cookie::SAMESITE_NONE : Cookie::SAMESITE_LAX
|
||||
|
||||
// ])->setJSON([
|
||||
// 'status' => 'success',
|
||||
// 'code' => 200,
|
||||
// 'message' => 'Logout successful'
|
||||
// ], 200);
|
||||
// }
|
||||
public function logout()
|
||||
{
|
||||
// Definisikan ini pada cookies browser, harus sama dengan cookies login
|
||||
return $this->response->setCookie([
|
||||
'name' => 'token',
|
||||
'value' => '',
|
||||
'expire' => time() - 3600,
|
||||
'path' => '/',
|
||||
'secure' => true,
|
||||
'httponly' => true,
|
||||
'samesite' => Cookie::SAMESITE_NONE
|
||||
|
||||
])->setJSON([
|
||||
'status' => 'success',
|
||||
'code' => 200,
|
||||
'message' => 'Logout successful'
|
||||
], 200);
|
||||
}
|
||||
|
||||
// ok
|
||||
public function register()
|
||||
{
|
||||
|
||||
$username = strtolower($this->request->getJsonVar('username'));
|
||||
$password = $this->request->getJsonVar('password');
|
||||
|
||||
// Validasi Awal Dari BE
|
||||
if (empty($username) || empty($password)) {
|
||||
return $this->respond([
|
||||
'status' => 'failed',
|
||||
'code' => 400,
|
||||
'message' => 'Username and password are required'
|
||||
], 400); // Gunakan 400 Bad Request
|
||||
}
|
||||
|
||||
// Cek Duplikasi Username
|
||||
$exists = $this->db->query("SELECT id FROM users WHERE username = ?", [$username])->getRow();
|
||||
if ($exists) {
|
||||
return $this->respond(['status' => 'failed', 'code' => 409, 'message' => 'Username already exists'], 409);
|
||||
}
|
||||
|
||||
$hashedPassword = password_hash($password, PASSWORD_DEFAULT);
|
||||
|
||||
// Mulai transaksi Insert
|
||||
$this->db->transStart();
|
||||
$this->db->query(
|
||||
"INSERT INTO users(username, password, role_id) VALUES(?, ?, ?)",
|
||||
[$username, $hashedPassword, 1]
|
||||
);
|
||||
$this->db->transComplete();
|
||||
|
||||
// Cek status transaksi
|
||||
if ($this->db->transStatus() === false) {
|
||||
return $this->respond([
|
||||
'status' => 'error',
|
||||
'code' => 500,
|
||||
'message' => 'Failed to create user. Please try again later.'
|
||||
], 500);
|
||||
}
|
||||
|
||||
// Respon sukses jika kueri berhasil
|
||||
return $this->respond([
|
||||
'status' => 'success',
|
||||
'code' => 201,
|
||||
'message' => 'User ' . $username . ' successfully created.'
|
||||
], 201);
|
||||
|
||||
}
|
||||
|
||||
// public function change_pass() {
|
||||
// $db = \Config\Database::connect();
|
||||
// $username = $this->request->getJsonVar('username');
|
||||
// $password = $this->request->getJsonVar('password');
|
||||
// $password = password_hash($password, PASSWORD_DEFAULT);
|
||||
|
||||
// $master = $this->request->getJsonVar('master');
|
||||
// $masterkey = getenv('masterkey');
|
||||
|
||||
// if($master != $masterkey) {
|
||||
// return $this->fail('Invalid master key.', 401);
|
||||
// }
|
||||
|
||||
// $sql = "update users set password='$password' where username='$username'";
|
||||
// $query = $db->query($sql);
|
||||
// $response = [
|
||||
// 'message' => "Password Changed for $username"
|
||||
// ];
|
||||
// return $this->respond($response);
|
||||
// }
|
||||
|
||||
public function coba()
|
||||
{
|
||||
|
||||
$token = $this->request->getCookie('token');
|
||||
$key = getenv('JWT_SECRET');
|
||||
|
||||
// Decode Token dengan Key yg ada di .env
|
||||
$decodedPayload = JWT::decode($token, new Key($key, 'HS256'));
|
||||
|
||||
return $this->respond([
|
||||
'status' => 'success',
|
||||
'message' => 'Authenticated',
|
||||
'data' => $decodedPayload
|
||||
], 200);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
476
app/Controllers/AuthV2Controller.php
Executable file → Normal file
476
app/Controllers/AuthV2Controller.php
Executable file → Normal file
@ -1,238 +1,238 @@
|
||||
<?php
|
||||
|
||||
namespace App\Controllers;
|
||||
|
||||
use App\Traits\ResponseTrait;
|
||||
use CodeIgniter\Controller;
|
||||
|
||||
use Firebase\JWT\JWT;
|
||||
use Firebase\JWT\Key;
|
||||
use Firebase\JWT\ExpiredException;
|
||||
use Firebase\JWT\SignatureInvalidException;
|
||||
use Firebase\JWT\BeforeValidException;
|
||||
use CodeIgniter\Cookie\Cookie;
|
||||
|
||||
/**
|
||||
* AuthV2 Controller
|
||||
*
|
||||
* Handles authentication for V2 UI
|
||||
* Separate from the main Auth controller to avoid conflicts
|
||||
*/
|
||||
class AuthV2Controller extends Controller
|
||||
{
|
||||
use ResponseTrait;
|
||||
|
||||
protected $db;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->db = \Config\Database::connect();
|
||||
}
|
||||
|
||||
/**
|
||||
* Check authentication status
|
||||
* GET /v2/auth/check
|
||||
*/
|
||||
public function checkAuth()
|
||||
{
|
||||
$token = $this->request->getCookie('token');
|
||||
$key = getenv('JWT_SECRET');
|
||||
|
||||
if (!$token) {
|
||||
return $this->respond([
|
||||
'status' => 'failed',
|
||||
'message' => 'No token found'
|
||||
], 401);
|
||||
}
|
||||
|
||||
try {
|
||||
$decodedPayload = JWT::decode($token, new Key($key, 'HS256'));
|
||||
|
||||
return $this->respond([
|
||||
'status' => 'success',
|
||||
'message' => 'Authenticated',
|
||||
'data' => $decodedPayload
|
||||
], 200);
|
||||
|
||||
} catch (ExpiredException $e) {
|
||||
return $this->respond([
|
||||
'status' => 'failed',
|
||||
'message' => 'Token expired'
|
||||
], 401);
|
||||
|
||||
} catch (SignatureInvalidException $e) {
|
||||
return $this->respond([
|
||||
'status' => 'failed',
|
||||
'message' => 'Invalid token signature'
|
||||
], 401);
|
||||
|
||||
} catch (BeforeValidException $e) {
|
||||
return $this->respond([
|
||||
'status' => 'failed',
|
||||
'message' => 'Token not valid yet'
|
||||
], 401);
|
||||
|
||||
} catch (\Exception $e) {
|
||||
return $this->respond([
|
||||
'status' => 'failed',
|
||||
'message' => 'Invalid token: ' . $e->getMessage()
|
||||
], 401);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Login user
|
||||
* POST /v2/auth/login
|
||||
*/
|
||||
public function login()
|
||||
{
|
||||
$username = $this->request->getVar('username');
|
||||
$password = $this->request->getVar('password');
|
||||
$key = getenv('JWT_SECRET');
|
||||
|
||||
// Validate username
|
||||
if (!$username) {
|
||||
return $this->respond([
|
||||
'status' => 'failed',
|
||||
'message' => 'Username is required'
|
||||
], 400);
|
||||
}
|
||||
|
||||
// Find user
|
||||
$sql = "SELECT * FROM users WHERE username = " . $this->db->escape($username);
|
||||
$query = $this->db->query($sql);
|
||||
$row = $query->getResultArray();
|
||||
|
||||
if (!$row) {
|
||||
return $this->respond([
|
||||
'status' => 'failed',
|
||||
'message' => 'User not found'
|
||||
], 401);
|
||||
}
|
||||
|
||||
$row = $row[0];
|
||||
|
||||
// Verify password
|
||||
if (!password_verify($password, $row['password'])) {
|
||||
return $this->respond([
|
||||
'status' => 'failed',
|
||||
'message' => 'Invalid password'
|
||||
], 401);
|
||||
}
|
||||
|
||||
// Create JWT payload
|
||||
$exp = time() + 864000; // 10 days
|
||||
$payload = [
|
||||
'userid' => $row['id'],
|
||||
'roleid' => $row['role_id'],
|
||||
'username' => $row['username'],
|
||||
'exp' => $exp
|
||||
];
|
||||
|
||||
try {
|
||||
$jwt = JWT::encode($payload, $key, 'HS256');
|
||||
} catch (\Exception $e) {
|
||||
return $this->respond([
|
||||
'status' => 'failed',
|
||||
'message' => 'Error generating JWT: ' . $e->getMessage()
|
||||
], 500);
|
||||
}
|
||||
|
||||
// Detect if HTTPS is being used
|
||||
$isSecure = isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] === 'on';
|
||||
|
||||
// Set HTTP-only cookie
|
||||
$this->response->setCookie([
|
||||
'name' => 'token',
|
||||
'value' => $jwt,
|
||||
'expire' => 864000,
|
||||
'path' => '/',
|
||||
'secure' => $isSecure, // false for localhost HTTP
|
||||
'httponly' => true,
|
||||
'samesite' => $isSecure ? Cookie::SAMESITE_NONE : Cookie::SAMESITE_LAX
|
||||
]);
|
||||
|
||||
return $this->respond([
|
||||
'status' => 'success',
|
||||
'message' => 'Login successful',
|
||||
'data' => [
|
||||
'username' => $row['username'],
|
||||
'role_id' => $row['role_id']
|
||||
]
|
||||
], 200);
|
||||
}
|
||||
|
||||
/**
|
||||
* Logout user
|
||||
* POST /v2/auth/logout
|
||||
*/
|
||||
public function logout()
|
||||
{
|
||||
// Detect if HTTPS is being used
|
||||
$isSecure = isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] === 'on';
|
||||
|
||||
// Clear the token cookie
|
||||
return $this->response->setCookie([
|
||||
'name' => 'token',
|
||||
'value' => '',
|
||||
'expire' => time() - 3600,
|
||||
'path' => '/',
|
||||
'secure' => $isSecure,
|
||||
'httponly' => true,
|
||||
'samesite' => $isSecure ? Cookie::SAMESITE_NONE : Cookie::SAMESITE_LAX
|
||||
])->setJSON([
|
||||
'status' => 'success',
|
||||
'message' => 'Logout successful'
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Register new user
|
||||
* POST /v2/auth/register
|
||||
*/
|
||||
public function register()
|
||||
{
|
||||
$username = strtolower($this->request->getJsonVar('username'));
|
||||
$password = $this->request->getJsonVar('password');
|
||||
|
||||
// Validate input
|
||||
if (empty($username) || empty($password)) {
|
||||
return $this->respond([
|
||||
'status' => 'failed',
|
||||
'message' => 'Username and password are required'
|
||||
], 400);
|
||||
}
|
||||
|
||||
// Check for existing username
|
||||
$exists = $this->db->query("SELECT id FROM users WHERE username = ?", [$username])->getRow();
|
||||
if ($exists) {
|
||||
return $this->respond([
|
||||
'status' => 'failed',
|
||||
'message' => 'Username already exists'
|
||||
], 409);
|
||||
}
|
||||
|
||||
// Hash password
|
||||
$hashedPassword = password_hash($password, PASSWORD_DEFAULT);
|
||||
|
||||
// Insert user
|
||||
$this->db->transStart();
|
||||
$this->db->query(
|
||||
"INSERT INTO users(username, password, role_id) VALUES(?, ?, ?)",
|
||||
[$username, $hashedPassword, 1]
|
||||
);
|
||||
$this->db->transComplete();
|
||||
|
||||
if ($this->db->transStatus() === false) {
|
||||
return $this->respond([
|
||||
'status' => 'failed',
|
||||
'message' => 'Failed to create user'
|
||||
], 500);
|
||||
}
|
||||
|
||||
return $this->respond([
|
||||
'status' => 'success',
|
||||
'message' => 'User ' . $username . ' successfully created'
|
||||
], 201);
|
||||
}
|
||||
}
|
||||
<?php
|
||||
|
||||
namespace App\Controllers;
|
||||
|
||||
use CodeIgniter\API\ResponseTrait;
|
||||
use CodeIgniter\Controller;
|
||||
|
||||
use Firebase\JWT\JWT;
|
||||
use Firebase\JWT\Key;
|
||||
use Firebase\JWT\ExpiredException;
|
||||
use Firebase\JWT\SignatureInvalidException;
|
||||
use Firebase\JWT\BeforeValidException;
|
||||
use CodeIgniter\Cookie\Cookie;
|
||||
|
||||
/**
|
||||
* AuthV2 Controller
|
||||
*
|
||||
* Handles authentication for V2 UI
|
||||
* Separate from the main Auth controller to avoid conflicts
|
||||
*/
|
||||
class AuthV2Controller extends Controller
|
||||
{
|
||||
use ResponseTrait;
|
||||
|
||||
protected $db;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->db = \Config\Database::connect();
|
||||
}
|
||||
|
||||
/**
|
||||
* Check authentication status
|
||||
* GET /v2/auth/check
|
||||
*/
|
||||
public function checkAuth()
|
||||
{
|
||||
$token = $this->request->getCookie('token');
|
||||
$key = getenv('JWT_SECRET');
|
||||
|
||||
if (!$token) {
|
||||
return $this->respond([
|
||||
'status' => 'failed',
|
||||
'message' => 'No token found'
|
||||
], 401);
|
||||
}
|
||||
|
||||
try {
|
||||
$decodedPayload = JWT::decode($token, new Key($key, 'HS256'));
|
||||
|
||||
return $this->respond([
|
||||
'status' => 'success',
|
||||
'message' => 'Authenticated',
|
||||
'data' => $decodedPayload
|
||||
], 200);
|
||||
|
||||
} catch (ExpiredException $e) {
|
||||
return $this->respond([
|
||||
'status' => 'failed',
|
||||
'message' => 'Token expired'
|
||||
], 401);
|
||||
|
||||
} catch (SignatureInvalidException $e) {
|
||||
return $this->respond([
|
||||
'status' => 'failed',
|
||||
'message' => 'Invalid token signature'
|
||||
], 401);
|
||||
|
||||
} catch (BeforeValidException $e) {
|
||||
return $this->respond([
|
||||
'status' => 'failed',
|
||||
'message' => 'Token not valid yet'
|
||||
], 401);
|
||||
|
||||
} catch (\Exception $e) {
|
||||
return $this->respond([
|
||||
'status' => 'failed',
|
||||
'message' => 'Invalid token: ' . $e->getMessage()
|
||||
], 401);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Login user
|
||||
* POST /v2/auth/login
|
||||
*/
|
||||
public function login()
|
||||
{
|
||||
$username = $this->request->getVar('username');
|
||||
$password = $this->request->getVar('password');
|
||||
$key = getenv('JWT_SECRET');
|
||||
|
||||
// Validate username
|
||||
if (!$username) {
|
||||
return $this->respond([
|
||||
'status' => 'failed',
|
||||
'message' => 'Username is required'
|
||||
], 400);
|
||||
}
|
||||
|
||||
// Find user
|
||||
$sql = "SELECT * FROM users WHERE username = " . $this->db->escape($username);
|
||||
$query = $this->db->query($sql);
|
||||
$row = $query->getResultArray();
|
||||
|
||||
if (!$row) {
|
||||
return $this->respond([
|
||||
'status' => 'failed',
|
||||
'message' => 'User not found'
|
||||
], 401);
|
||||
}
|
||||
|
||||
$row = $row[0];
|
||||
|
||||
// Verify password
|
||||
if (!password_verify($password, $row['password'])) {
|
||||
return $this->respond([
|
||||
'status' => 'failed',
|
||||
'message' => 'Invalid password'
|
||||
], 401);
|
||||
}
|
||||
|
||||
// Create JWT payload
|
||||
$exp = time() + 864000; // 10 days
|
||||
$payload = [
|
||||
'userid' => $row['id'],
|
||||
'roleid' => $row['role_id'],
|
||||
'username' => $row['username'],
|
||||
'exp' => $exp
|
||||
];
|
||||
|
||||
try {
|
||||
$jwt = JWT::encode($payload, $key, 'HS256');
|
||||
} catch (\Exception $e) {
|
||||
return $this->respond([
|
||||
'status' => 'failed',
|
||||
'message' => 'Error generating JWT: ' . $e->getMessage()
|
||||
], 500);
|
||||
}
|
||||
|
||||
// Detect if HTTPS is being used
|
||||
$isSecure = isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] === 'on';
|
||||
|
||||
// Set HTTP-only cookie
|
||||
$this->response->setCookie([
|
||||
'name' => 'token',
|
||||
'value' => $jwt,
|
||||
'expire' => 864000,
|
||||
'path' => '/',
|
||||
'secure' => $isSecure, // false for localhost HTTP
|
||||
'httponly' => true,
|
||||
'samesite' => $isSecure ? Cookie::SAMESITE_NONE : Cookie::SAMESITE_LAX
|
||||
]);
|
||||
|
||||
return $this->respond([
|
||||
'status' => 'success',
|
||||
'message' => 'Login successful',
|
||||
'data' => [
|
||||
'username' => $row['username'],
|
||||
'role_id' => $row['role_id']
|
||||
]
|
||||
], 200);
|
||||
}
|
||||
|
||||
/**
|
||||
* Logout user
|
||||
* POST /v2/auth/logout
|
||||
*/
|
||||
public function logout()
|
||||
{
|
||||
// Detect if HTTPS is being used
|
||||
$isSecure = isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] === 'on';
|
||||
|
||||
// Clear the token cookie
|
||||
return $this->response->setCookie([
|
||||
'name' => 'token',
|
||||
'value' => '',
|
||||
'expire' => time() - 3600,
|
||||
'path' => '/',
|
||||
'secure' => $isSecure,
|
||||
'httponly' => true,
|
||||
'samesite' => $isSecure ? Cookie::SAMESITE_NONE : Cookie::SAMESITE_LAX
|
||||
])->setJSON([
|
||||
'status' => 'success',
|
||||
'message' => 'Logout successful'
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Register new user
|
||||
* POST /v2/auth/register
|
||||
*/
|
||||
public function register()
|
||||
{
|
||||
$username = strtolower($this->request->getJsonVar('username'));
|
||||
$password = $this->request->getJsonVar('password');
|
||||
|
||||
// Validate input
|
||||
if (empty($username) || empty($password)) {
|
||||
return $this->respond([
|
||||
'status' => 'failed',
|
||||
'message' => 'Username and password are required'
|
||||
], 400);
|
||||
}
|
||||
|
||||
// Check for existing username
|
||||
$exists = $this->db->query("SELECT id FROM users WHERE username = ?", [$username])->getRow();
|
||||
if ($exists) {
|
||||
return $this->respond([
|
||||
'status' => 'failed',
|
||||
'message' => 'Username already exists'
|
||||
], 409);
|
||||
}
|
||||
|
||||
// Hash password
|
||||
$hashedPassword = password_hash($password, PASSWORD_DEFAULT);
|
||||
|
||||
// Insert user
|
||||
$this->db->transStart();
|
||||
$this->db->query(
|
||||
"INSERT INTO users(username, password, role_id) VALUES(?, ?, ?)",
|
||||
[$username, $hashedPassword, 1]
|
||||
);
|
||||
$this->db->transComplete();
|
||||
|
||||
if ($this->db->transStatus() === false) {
|
||||
return $this->respond([
|
||||
'status' => 'failed',
|
||||
'message' => 'Failed to create user'
|
||||
], 500);
|
||||
}
|
||||
|
||||
return $this->respond([
|
||||
'status' => 'success',
|
||||
'message' => 'User ' . $username . ' successfully created'
|
||||
], 201);
|
||||
}
|
||||
}
|
||||
|
||||
116
app/Controllers/BaseController.php
Executable file → Normal file
116
app/Controllers/BaseController.php
Executable file → Normal file
@ -1,58 +1,58 @@
|
||||
<?php
|
||||
|
||||
namespace App\Controllers;
|
||||
|
||||
use CodeIgniter\Controller;
|
||||
use CodeIgniter\HTTP\CLIRequest;
|
||||
use CodeIgniter\HTTP\IncomingRequest;
|
||||
use CodeIgniter\HTTP\RequestInterface;
|
||||
use CodeIgniter\HTTP\ResponseInterface;
|
||||
use Psr\Log\LoggerInterface;
|
||||
|
||||
/**
|
||||
* Class BaseController
|
||||
*
|
||||
* BaseController provides a convenient place for loading components
|
||||
* and performing functions that are needed by all your controllers.
|
||||
* Extend this class in any new controllers:
|
||||
* class Home extends BaseController
|
||||
*
|
||||
* For security be sure to declare any new methods as protected or private.
|
||||
*/
|
||||
abstract class BaseController extends Controller
|
||||
{
|
||||
/**
|
||||
* Instance of the main Request object.
|
||||
*
|
||||
* @var CLIRequest|IncomingRequest
|
||||
*/
|
||||
protected $request;
|
||||
|
||||
/**
|
||||
* An array of helpers to be loaded automatically upon
|
||||
* class instantiation. These will be available
|
||||
* to all other controllers that extend BaseController.
|
||||
*
|
||||
* @var list<string>
|
||||
*/
|
||||
protected $helpers = ['json'];
|
||||
|
||||
/**
|
||||
* Be sure to declare properties for any property fetch you initialized.
|
||||
* The creation of dynamic property is deprecated in PHP 8.2.
|
||||
*/
|
||||
// protected $session;
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function initController(RequestInterface $request, ResponseInterface $response, LoggerInterface $logger)
|
||||
{
|
||||
// Do Not Edit This Line
|
||||
parent::initController($request, $response, $logger);
|
||||
|
||||
// Preload any models, libraries, etc, here.
|
||||
|
||||
// E.g.: $this->session = service('session');
|
||||
}
|
||||
}
|
||||
<?php
|
||||
|
||||
namespace App\Controllers;
|
||||
|
||||
use CodeIgniter\Controller;
|
||||
use CodeIgniter\HTTP\CLIRequest;
|
||||
use CodeIgniter\HTTP\IncomingRequest;
|
||||
use CodeIgniter\HTTP\RequestInterface;
|
||||
use CodeIgniter\HTTP\ResponseInterface;
|
||||
use Psr\Log\LoggerInterface;
|
||||
|
||||
/**
|
||||
* Class BaseController
|
||||
*
|
||||
* BaseController provides a convenient place for loading components
|
||||
* and performing functions that are needed by all your controllers.
|
||||
* Extend this class in any new controllers:
|
||||
* class Home extends BaseController
|
||||
*
|
||||
* For security be sure to declare any new methods as protected or private.
|
||||
*/
|
||||
abstract class BaseController extends Controller
|
||||
{
|
||||
/**
|
||||
* Instance of the main Request object.
|
||||
*
|
||||
* @var CLIRequest|IncomingRequest
|
||||
*/
|
||||
protected $request;
|
||||
|
||||
/**
|
||||
* An array of helpers to be loaded automatically upon
|
||||
* class instantiation. These helpers will be available
|
||||
* to all other controllers that extend BaseController.
|
||||
*
|
||||
* @var list<string>
|
||||
*/
|
||||
protected $helpers = [];
|
||||
|
||||
/**
|
||||
* Be sure to declare properties for any property fetch you initialized.
|
||||
* The creation of dynamic property is deprecated in PHP 8.2.
|
||||
*/
|
||||
// protected $session;
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function initController(RequestInterface $request, ResponseInterface $response, LoggerInterface $logger)
|
||||
{
|
||||
// Do Not Edit This Line
|
||||
parent::initController($request, $response, $logger);
|
||||
|
||||
// Preload any models, libraries, etc, here.
|
||||
|
||||
// E.g.: $this->session = service('session');
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,183 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Controllers;
|
||||
|
||||
use App\Traits\ResponseTrait;
|
||||
use App\Services\CalculatorService;
|
||||
use App\Models\Test\TestDefCalModel;
|
||||
use CodeIgniter\Controller;
|
||||
use CodeIgniter\HTTP\ResponseInterface;
|
||||
|
||||
class CalculatorController extends Controller
|
||||
{
|
||||
use ResponseTrait;
|
||||
|
||||
protected CalculatorService $calculator;
|
||||
protected TestDefCalModel $calcModel;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->calculator = new CalculatorService();
|
||||
$this->calcModel = new TestDefCalModel();
|
||||
}
|
||||
|
||||
/**
|
||||
* POST api/calculate
|
||||
* Calculate a formula with provided variables
|
||||
*
|
||||
* Request: {
|
||||
* "formula": "{result} * {factor} + {gender}",
|
||||
* "variables": {
|
||||
* "result": 100,
|
||||
* "factor": 0.5,
|
||||
* "gender": "female"
|
||||
* }
|
||||
* }
|
||||
*/
|
||||
public function calculate(): ResponseInterface
|
||||
{
|
||||
try {
|
||||
$data = $this->request->getJSON(true);
|
||||
|
||||
if (empty($data['formula'])) {
|
||||
return $this->respond([
|
||||
'status' => 'failed',
|
||||
'message' => 'Formula is required'
|
||||
], 400);
|
||||
}
|
||||
|
||||
$result = $this->calculator->calculate(
|
||||
$data['formula'],
|
||||
$data['variables'] ?? []
|
||||
);
|
||||
|
||||
return $this->respond([
|
||||
'status' => 'success',
|
||||
'data' => [
|
||||
'result' => $result,
|
||||
'formula' => $data['formula'],
|
||||
'variables' => $data['variables'] ?? []
|
||||
]
|
||||
], 200);
|
||||
|
||||
} catch (\Exception $e) {
|
||||
return $this->respond([
|
||||
'status' => 'failed',
|
||||
'message' => $e->getMessage()
|
||||
], 400);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* POST api/calculate/validate
|
||||
* Validate a formula syntax
|
||||
*
|
||||
* Request: {
|
||||
* "formula": "{result} * 2 + 5"
|
||||
* }
|
||||
*/
|
||||
public function validateFormula(): ResponseInterface
|
||||
{
|
||||
try {
|
||||
$data = $this->request->getJSON(true);
|
||||
|
||||
if (empty($data['formula'])) {
|
||||
return $this->respond([
|
||||
'status' => 'failed',
|
||||
'message' => 'Formula is required'
|
||||
], 400);
|
||||
}
|
||||
|
||||
$validation = $this->calculator->validate($data['formula']);
|
||||
|
||||
return $this->respond([
|
||||
'status' => $validation['valid'] ? 'success' : 'failed',
|
||||
'data' => [
|
||||
'valid' => $validation['valid'],
|
||||
'error' => $validation['error'],
|
||||
'variables' => $this->calculator->extractVariables($data['formula'])
|
||||
]
|
||||
], 200);
|
||||
|
||||
} catch (\Exception $e) {
|
||||
return $this->respond([
|
||||
'status' => 'failed',
|
||||
'message' => $e->getMessage()
|
||||
], 400);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* POST api/calc/testsite/{testSiteID}
|
||||
* Calculate using TestDefCal definition
|
||||
*
|
||||
* Request: {
|
||||
* "result": 85,
|
||||
* "gender": "female",
|
||||
* "age": 30
|
||||
* }
|
||||
*/
|
||||
public function calculateByTestSite($testSiteID): ResponseInterface
|
||||
{
|
||||
try {
|
||||
$calcDef = $this->calcModel->existsByTestSiteID($testSiteID);
|
||||
|
||||
if (!$calcDef) {
|
||||
return $this->respond([
|
||||
'status' => 'failed',
|
||||
'message' => 'No calculation defined for this test site'
|
||||
], 404);
|
||||
}
|
||||
|
||||
$testValues = $this->request->getJSON(true);
|
||||
$result = $this->calculator->calculateFromDefinition($calcDef, $testValues);
|
||||
|
||||
return $this->respond([
|
||||
'status' => 'success',
|
||||
'data' => [
|
||||
'result' => $result,
|
||||
'testSiteID' => $testSiteID,
|
||||
'formula' => $calcDef['FormulaCode'],
|
||||
'variables' => $testValues
|
||||
]
|
||||
], 200);
|
||||
|
||||
} catch (\Exception $e) {
|
||||
return $this->respond([
|
||||
'status' => 'failed',
|
||||
'message' => $e->getMessage()
|
||||
], 400);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* POST api/calc/testcode/{codeOrName}
|
||||
* Evaluate a configured calculation by its code or name and return only the result map.
|
||||
*/
|
||||
public function calculateByCodeOrName($codeOrName): ResponseInterface
|
||||
{
|
||||
try {
|
||||
$calcDef = $this->calcModel->findActiveByCodeOrName($codeOrName);
|
||||
|
||||
if (!$calcDef || empty($calcDef['FormulaCode'])) {
|
||||
return $this->response->setJSON(new \stdClass());
|
||||
}
|
||||
|
||||
$input = $this->request->getJSON(true);
|
||||
$variables = is_array($input) ? $input : [];
|
||||
|
||||
$result = $this->calculator->calculate($calcDef['FormulaCode'], $variables);
|
||||
|
||||
if ($result === null) {
|
||||
return $this->response->setJSON(new \stdClass());
|
||||
}
|
||||
|
||||
$responseKey = $calcDef['TestSiteCode'] ?? strtoupper($codeOrName);
|
||||
|
||||
return $this->response->setJSON([ $responseKey => $result ]);
|
||||
} catch (\Exception $e) {
|
||||
log_message('error', "Calc lookup failed for {$codeOrName}: " . $e->getMessage());
|
||||
return $this->response->setJSON(new \stdClass());
|
||||
}
|
||||
}
|
||||
}
|
||||
76
app/Controllers/Contact/ContactController.php
Executable file → Normal file
76
app/Controllers/Contact/ContactController.php
Executable file → Normal file
@ -1,42 +1,33 @@
|
||||
<?php
|
||||
namespace App\Controllers\Contact;
|
||||
|
||||
use App\Traits\PatchValidationTrait;
|
||||
use App\Traits\ResponseTrait;
|
||||
use CodeIgniter\API\ResponseTrait;
|
||||
use App\Controllers\BaseController;
|
||||
use App\Libraries\ValueSet;
|
||||
|
||||
use App\Models\Contact\ContactModel;
|
||||
|
||||
class ContactController extends BaseController {
|
||||
use ResponseTrait;
|
||||
use PatchValidationTrait;
|
||||
|
||||
protected $db;
|
||||
protected $model;
|
||||
protected $rules;
|
||||
protected $patchRules;
|
||||
|
||||
public function __construct() {
|
||||
$this->db = \Config\Database::connect();
|
||||
$this->model = new ContactModel();
|
||||
$this->rules = [ 'NameFirst' => 'required' ];
|
||||
$this->patchRules = [ 'NameFirst' => 'permit_empty' ];
|
||||
}
|
||||
|
||||
public function index() {
|
||||
$ContactName = $this->request->getVar('ContactName');
|
||||
$Specialty = $this->request->getVar('Specialty');
|
||||
$rows = $this->model->getContacts($ContactName, $Specialty);
|
||||
|
||||
|
||||
if (empty($rows)) {
|
||||
return $this->respond([ 'status' => 'success', 'message' => "no Data.", 'data' => [] ], 200);
|
||||
}
|
||||
|
||||
$rows = ValueSet::transformLabels($rows, [
|
||||
'Specialty' => 'specialty',
|
||||
'Occupation' => 'occupation',
|
||||
]);
|
||||
|
||||
return $this->respond([ 'status' => 'success', 'message'=> "fetch success", 'data' => $rows ], 200);
|
||||
}
|
||||
|
||||
@ -48,11 +39,6 @@ class ContactController extends BaseController {
|
||||
return $this->respond([ 'status' => 'success', 'message' => "no Data.", 'data' => null ], 200);
|
||||
}
|
||||
|
||||
$row = ValueSet::transformLabels([$row], [
|
||||
'Specialty' => 'specialty',
|
||||
'Occupation' => 'occupation',
|
||||
])[0];
|
||||
|
||||
return $this->respond([ 'status' => 'success', 'message'=> "fetch success", 'data' => $row ], 200);
|
||||
}
|
||||
|
||||
@ -72,60 +58,20 @@ class ContactController extends BaseController {
|
||||
$input = $this->request->getJSON(true);
|
||||
if (!$this->validateData($input, $this->rules)) { return $this->failValidationErrors($this->validator->getErrors()); }
|
||||
try {
|
||||
$result = $this->model->saveContact($input);
|
||||
|
||||
if (($result['status'] ?? 'error') !== 'success') {
|
||||
return $this->respond([
|
||||
'status' => 'failed',
|
||||
'message' => $result['message'] ?? 'Failed to create contact',
|
||||
'data' => []
|
||||
], 400);
|
||||
}
|
||||
|
||||
return $this->respondCreated([ 'status' => 'success', 'message' => 'data created successfully', 'data' => $result ], 201);
|
||||
$id = $this->model->saveContact($input,true);
|
||||
return $this->respondCreated([ 'status' => 'success', 'message' => 'data created successfully', 'data' => $id ], 201);
|
||||
} catch (\Throwable $e) {
|
||||
return $this->failServerError('Something went wrong: ' . $e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
public function update($ContactID = null) {
|
||||
$input = $this->requirePatchPayload($this->request->getJSON(true));
|
||||
if ($input === null) {
|
||||
return;
|
||||
}
|
||||
|
||||
$id = $this->requirePatchId($ContactID, 'ContactID');
|
||||
if ($id === null) {
|
||||
return;
|
||||
}
|
||||
|
||||
$existing = $this->model->find($id);
|
||||
if (!$existing) {
|
||||
return $this->respond([
|
||||
'status' => 'failed',
|
||||
'message' => 'Contact not found',
|
||||
'data' => []
|
||||
], 404);
|
||||
}
|
||||
|
||||
$validationInput = array_intersect_key($input, $this->patchRules);
|
||||
if (!empty($validationInput) && !$this->validateData($validationInput, $this->patchRules)) {
|
||||
return $this->failValidationErrors($this->validator->getErrors());
|
||||
}
|
||||
|
||||
$input['ContactID'] = $id;
|
||||
public function update() {
|
||||
$input = $this->request->getJSON(true);
|
||||
if (!$this->validateData($input, $this->rules)) { return $this->failValidationErrors($this->validator->getErrors()); }
|
||||
try {
|
||||
$result = $this->model->saveContact($input);
|
||||
|
||||
if (($result['status'] ?? 'error') !== 'success') {
|
||||
return $this->respond([
|
||||
'status' => 'failed',
|
||||
'message' => $result['message'] ?? 'Failed to update contact',
|
||||
'data' => []
|
||||
], 400);
|
||||
}
|
||||
|
||||
return $this->respond([ 'status' => 'success', 'message' => 'data updated successfully', 'data' => $result ], 200);
|
||||
$this->model->saveContact($input);
|
||||
$id = $input['ContactID'];
|
||||
return $this->respondCreated([ 'status' => 'success', 'message' => 'data updated successfully', 'data' => $id ], 201);
|
||||
} catch (\Throwable $e) {
|
||||
return $this->failServerError('Something went wrong: ' . $e->getMessage());
|
||||
}
|
||||
|
||||
124
app/Controllers/Contact/MedicalSpecialtyController.php
Executable file → Normal file
124
app/Controllers/Contact/MedicalSpecialtyController.php
Executable file → Normal file
@ -1,68 +1,64 @@
|
||||
<?php
|
||||
namespace App\Controllers\Contact;
|
||||
|
||||
use App\Traits\ResponseTrait;
|
||||
use App\Controllers\BaseController;
|
||||
use App\Models\Contact\MedicalSpecialtyModel;
|
||||
|
||||
class MedicalSpecialtyController extends BaseController {
|
||||
use ResponseTrait;
|
||||
|
||||
protected $db;
|
||||
protected $model;
|
||||
protected $rules;
|
||||
|
||||
public function __construct() {
|
||||
$this->db = \Config\Database::connect();
|
||||
$this->model = new MedicalSpecialtyModel();
|
||||
$this->rules = [ 'SpecialtyText' => 'required' ];
|
||||
}
|
||||
|
||||
public function index() {
|
||||
$Parent = $this->request->getVar('Parent');
|
||||
$SpecialtyText = $this->request->getVar('SpecialtyText');
|
||||
$rows = $this->model->getOccupations($Parent,$SpecialtyText);
|
||||
|
||||
if (empty($rows)) {
|
||||
return $this->respond([ 'status' => 'success', 'message' => "no Data."], 200);
|
||||
}
|
||||
|
||||
return $this->respond([ 'status' => 'success', 'message'=> "fetch success", 'data' => $rows ], 200);
|
||||
}
|
||||
|
||||
public function show($SpecialtyID = null) {
|
||||
$model = new MedicalSpecialtyModel();
|
||||
$row = $model->find($SpecialtyID);
|
||||
if (empty($row)) {
|
||||
return $this->respond([ 'status' => 'success', 'message' => "no Data.", 'data' => null], 200);
|
||||
}
|
||||
return $this->respond([ 'status' => 'success', 'message'=> "fetch success", 'data' => $row ], 200);
|
||||
}
|
||||
|
||||
public function create() {
|
||||
$input = $this->request->getJSON(true);
|
||||
try {
|
||||
$this->model->insert($input);
|
||||
$id = $this->model->getInsertID();
|
||||
return $this->respondCreated([ 'status' => 'success', 'message' => 'data created successfully', 'data' => $id ], 201);
|
||||
} catch (\Throwable $e) {
|
||||
$this->db->transRollback();
|
||||
return $this->failServerError('Exception : ' . $e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
public function update($SpecialtyID = null) {
|
||||
$input = $this->request->getJSON(true);
|
||||
if (!$SpecialtyID || !ctype_digit((string) $SpecialtyID)) {
|
||||
return $this->respond(['status' => 'error', 'message' => 'SpecialtyID is required and must be a valid integer'], 400);
|
||||
<?php
|
||||
namespace App\Controllers\Contact;
|
||||
|
||||
use CodeIgniter\API\ResponseTrait;
|
||||
use App\Controllers\BaseController;
|
||||
use App\Models\Contact\MedicalSpecialtyModel;
|
||||
|
||||
class MedicalSpecialtyController extends BaseController {
|
||||
use ResponseTrait;
|
||||
|
||||
protected $db;
|
||||
protected $model;
|
||||
protected $rules;
|
||||
|
||||
public function __construct() {
|
||||
$this->db = \Config\Database::connect();
|
||||
$this->model = new MedicalSpecialtyModel();
|
||||
$this->rules = [ 'SpecialtyText' => 'required' ];
|
||||
}
|
||||
|
||||
public function index() {
|
||||
$Parent = $this->request->getVar('Parent');
|
||||
$SpecialtyText = $this->request->getVar('SpecialtyText');
|
||||
$rows = $this->model->getOccupations($Parent,$SpecialtyText);
|
||||
|
||||
if (empty($rows)) {
|
||||
return $this->respond([ 'status' => 'success', 'message' => "no Data."], 200);
|
||||
}
|
||||
$input['SpecialtyID'] = (int) $SpecialtyID;
|
||||
|
||||
return $this->respond([ 'status' => 'success', 'message'=> "fetch success", 'data' => $rows ], 200);
|
||||
}
|
||||
|
||||
public function show($SpecialtyID = null) {
|
||||
$model = new MedicalSpecialtyModel();
|
||||
$row = $model->find($SpecialtyID);
|
||||
if (empty($row)) {
|
||||
return $this->respond([ 'status' => 'success', 'message' => "no Data.", 'data' => null], 200);
|
||||
}
|
||||
return $this->respond([ 'status' => 'success', 'message'=> "fetch success", 'data' => $row ], 200);
|
||||
}
|
||||
|
||||
public function create() {
|
||||
$input = $this->request->getJSON(true);
|
||||
try {
|
||||
$this->model->insert($input);
|
||||
$id = $this->model->getInsertID();
|
||||
return $this->respondCreated([ 'status' => 'success', 'message' => 'data created successfully', 'data' => $id ], 201);
|
||||
} catch (\Throwable $e) {
|
||||
$this->db->transRollback();
|
||||
return $this->failServerError('Exception : ' . $e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
public function update() {
|
||||
$input = $this->request->getJSON(true);
|
||||
try {
|
||||
$this->model->update($input['SpecialtyID'], $input);
|
||||
return $this->respondCreated([ 'status' => 'success', 'message' => 'Data updated successfully', 'data' => $input['SpecialtyID'] ], 201);
|
||||
} catch (\Throwable $e) {
|
||||
return $this->failServerError('Exception : ' . $e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
} catch (\Throwable $e) {
|
||||
return $this->failServerError('Exception : ' . $e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
124
app/Controllers/Contact/OccupationController.php
Executable file → Normal file
124
app/Controllers/Contact/OccupationController.php
Executable file → Normal file
@ -1,68 +1,64 @@
|
||||
<?php
|
||||
namespace App\Controllers\Contact;
|
||||
|
||||
use App\Traits\ResponseTrait;
|
||||
use App\Controllers\BaseController;
|
||||
use App\Models\Contact\OccupationModel;
|
||||
|
||||
class OccupationController extends BaseController {
|
||||
use ResponseTrait;
|
||||
|
||||
protected $db;
|
||||
protected $model;
|
||||
protected $rules;
|
||||
|
||||
public function __construct() {
|
||||
$this->db = \Config\Database::connect();
|
||||
$this->model = new OccupationModel();
|
||||
$this->rules = [ 'OccCode' => 'required','OccText' => 'required' ];
|
||||
}
|
||||
|
||||
public function index() {
|
||||
$OccCode = $this->request->getVar('OccCode');
|
||||
$OccText = $this->request->getVar('OccText');
|
||||
$rows = $this->model->getOccupations($OccCode,$OccText);
|
||||
|
||||
if (empty($rows)) {
|
||||
return $this->respond([ 'status' => 'success', 'message' => "no Data."], 200);
|
||||
}
|
||||
|
||||
return $this->respond([ 'status' => 'success', 'message'=> "fetch success", 'data' => $rows ], 200);
|
||||
}
|
||||
|
||||
public function show($OccupationID = null) {
|
||||
$model = new OccupationModel();
|
||||
$row = $model->find($OccupationID);
|
||||
if (empty($row)) {
|
||||
return $this->respond([ 'status' => 'success', 'message' => "no Data.", 'data' => null ], 200);
|
||||
}
|
||||
return $this->respond([ 'status' => 'success', 'message'=> "fetch success", 'data' => $row ], 200);
|
||||
}
|
||||
|
||||
public function create() {
|
||||
$input = $this->request->getJSON(true);
|
||||
try {
|
||||
$this->model->insert($input);
|
||||
$id = $this->model->getInsertID();
|
||||
return $this->respondCreated([ 'status' => 'success', 'message' => 'data created successfully', 'data' => $id ], 201);
|
||||
} catch (\Throwable $e) {
|
||||
$this->db->transRollback();
|
||||
return $this->failServerError('Exception : ' . $e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
public function update($OccupationID = null) {
|
||||
$input = $this->request->getJSON(true);
|
||||
if (!$OccupationID || !ctype_digit((string) $OccupationID)) {
|
||||
return $this->respond(['status' => 'error', 'message' => 'OccupationID is required and must be a valid integer'], 400);
|
||||
<?php
|
||||
namespace App\Controllers\Contact;
|
||||
|
||||
use CodeIgniter\API\ResponseTrait;
|
||||
use App\Controllers\BaseController;
|
||||
use App\Models\Contact\OccupationModel;
|
||||
|
||||
class OccupationController extends BaseController {
|
||||
use ResponseTrait;
|
||||
|
||||
protected $db;
|
||||
protected $model;
|
||||
protected $rules;
|
||||
|
||||
public function __construct() {
|
||||
$this->db = \Config\Database::connect();
|
||||
$this->model = new OccupationModel();
|
||||
$this->rules = [ 'OccCode' => 'required','OccText' => 'required' ];
|
||||
}
|
||||
|
||||
public function index() {
|
||||
$OccCode = $this->request->getVar('OccCode');
|
||||
$OccText = $this->request->getVar('OccText');
|
||||
$rows = $this->model->getOccupations($OccCode,$OccText);
|
||||
|
||||
if (empty($rows)) {
|
||||
return $this->respond([ 'status' => 'success', 'message' => "no Data."], 200);
|
||||
}
|
||||
$input['OccupationID'] = (int) $OccupationID;
|
||||
|
||||
return $this->respond([ 'status' => 'success', 'message'=> "fetch success", 'data' => $rows ], 200);
|
||||
}
|
||||
|
||||
public function show($OccupationID = null) {
|
||||
$model = new OccupationModel();
|
||||
$row = $model->find($OccupationID);
|
||||
if (empty($row)) {
|
||||
return $this->respond([ 'status' => 'success', 'message' => "no Data.", 'data' => null ], 200);
|
||||
}
|
||||
return $this->respond([ 'status' => 'success', 'message'=> "fetch success", 'data' => $row ], 200);
|
||||
}
|
||||
|
||||
public function create() {
|
||||
$input = $this->request->getJSON(true);
|
||||
try {
|
||||
$this->model->insert($input);
|
||||
$id = $this->model->getInsertID();
|
||||
return $this->respondCreated([ 'status' => 'success', 'message' => 'data created successfully', 'data' => $id ], 201);
|
||||
} catch (\Throwable $e) {
|
||||
$this->db->transRollback();
|
||||
return $this->failServerError('Exception : ' . $e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
public function update() {
|
||||
$input = $this->request->getJSON(true);
|
||||
try {
|
||||
$this->model->update($input['OccupationID'], $input);
|
||||
return $this->respondCreated([ 'status' => 'success', 'message' => 'Data updated successfully', 'data' => $input['OccupationID'] ], 201);
|
||||
} catch (\Throwable $e) {
|
||||
return $this->failServerError('Exception : ' . $e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
} catch (\Throwable $e) {
|
||||
return $this->failServerError('Exception : ' . $e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
126
app/Controllers/CounterController.php
Executable file → Normal file
126
app/Controllers/CounterController.php
Executable file → Normal file
@ -1,69 +1,65 @@
|
||||
<?php
|
||||
namespace App\Controllers;
|
||||
|
||||
use App\Traits\ResponseTrait;
|
||||
use App\Controllers\BaseController;
|
||||
use App\Models\CounterModel;
|
||||
|
||||
class CounterController extends BaseController {
|
||||
use ResponseTrait;
|
||||
|
||||
protected $model;
|
||||
public function __construct() {
|
||||
$this->model = new CounterModel();
|
||||
}
|
||||
|
||||
public function index() {
|
||||
$rows = $this->model->findAll();
|
||||
|
||||
if (empty($rows)) {
|
||||
return $this->respond([ 'status' => 'success', 'message' => "No Data.", 'data' => [] ], 200);
|
||||
}
|
||||
|
||||
return $this->respond([ 'status' => 'success', 'message'=> "Data fetched successfully", 'data' => $rows ], 200);
|
||||
}
|
||||
|
||||
public function show($CounterID = null) {
|
||||
$row = $this->model->find($CounterID);
|
||||
|
||||
if (empty($row)) {
|
||||
return $this->respond([ 'status' => 'success', 'message' => "No Data.", 'data' => null ], 200);
|
||||
}
|
||||
|
||||
return $this->respond([ 'status' => 'success', 'message'=> "Data fetched successfully", 'data' => $row ], 200);
|
||||
}
|
||||
|
||||
public function create() {
|
||||
$input = $this->request->getJSON(true);
|
||||
try {
|
||||
$id = $this->model->insert($input,true);
|
||||
return $this->respondCreated([ 'status' => 'success', 'message' => 'Data created successfully', 'data' => $id ], 201);
|
||||
} catch (\Throwable $e) {
|
||||
return $this->failServerError('Something went wrong: ' . $e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
public function update($CounterID = null) {
|
||||
$input = $this->request->getJSON(true);
|
||||
if (!$CounterID || !ctype_digit((string) $CounterID)) {
|
||||
return $this->respond(['status' => 'error', 'message' => 'CounterID is required and must be a valid integer'], 400);
|
||||
<?php
|
||||
namespace App\Controllers;
|
||||
|
||||
use CodeIgniter\API\ResponseTrait;
|
||||
use App\Controllers\BaseController;
|
||||
use App\Models\CounterModel;
|
||||
|
||||
class CounterController extends BaseController {
|
||||
use ResponseTrait;
|
||||
|
||||
protected $model;
|
||||
public function __construct() {
|
||||
$this->model = new CounterModel();
|
||||
}
|
||||
|
||||
public function index() {
|
||||
$rows = $this->model->findAll();
|
||||
|
||||
if (empty($rows)) {
|
||||
return $this->respond([ 'status' => 'success', 'message' => "No Data.", 'data' => [] ], 200);
|
||||
}
|
||||
$input['CounterID'] = (int) $CounterID;
|
||||
|
||||
return $this->respond([ 'status' => 'success', 'message'=> "Data fetched successfully", 'data' => $rows ], 200);
|
||||
}
|
||||
|
||||
public function show($CounterID = null) {
|
||||
$row = $this->model->find($CounterID);
|
||||
|
||||
if (empty($row)) {
|
||||
return $this->respond([ 'status' => 'success', 'message' => "No Data.", 'data' => null ], 200);
|
||||
}
|
||||
|
||||
return $this->respond([ 'status' => 'success', 'message'=> "Data fetched successfully", 'data' => $row ], 200);
|
||||
}
|
||||
|
||||
public function create() {
|
||||
$input = $this->request->getJSON(true);
|
||||
try {
|
||||
$id = $this->model->insert($input,true);
|
||||
return $this->respondCreated([ 'status' => 'success', 'message' => 'Data created successfully', 'data' => $id ], 201);
|
||||
} catch (\Throwable $e) {
|
||||
return $this->failServerError('Something went wrong: ' . $e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
public function update() {
|
||||
$input = $this->request->getJSON(true);
|
||||
try {
|
||||
$this->model->update($input['CounterID'], $input);
|
||||
return $this->respondCreated([ 'status' => 'success', 'message' => 'Data updated successfully', 'data' => $input['CounterID'] ], 201);
|
||||
} catch (\Throwable $e) {
|
||||
return $this->failServerError('Something went wrong: ' . $e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
public function delete() {
|
||||
$input = $this->request->getJSON(true);
|
||||
try {
|
||||
$this->model->delete($input['CounterID'], $input);
|
||||
return $this->respondCreated([ 'status' => 'success', 'message' => 'Data deleted successfully', 'data' => $input['CounterID'] ], 201);
|
||||
} catch (\Throwable $e) {
|
||||
return $this->failServerError('Something went wrong: ' . $e->getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (\Throwable $e) {
|
||||
return $this->failServerError('Something went wrong: ' . $e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
public function delete() {
|
||||
$input = $this->request->getJSON(true);
|
||||
try {
|
||||
$this->model->delete($input['CounterID'], $input);
|
||||
return $this->respondCreated([ 'status' => 'success', 'message' => 'Data deleted successfully', 'data' => $input['CounterID'] ], 201);
|
||||
} catch (\Throwable $e) {
|
||||
return $this->failServerError('Something went wrong: ' . $e->getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
72
app/Controllers/DashboardController.php
Executable file → Normal file
72
app/Controllers/DashboardController.php
Executable file → Normal file
@ -1,36 +1,36 @@
|
||||
<?php
|
||||
|
||||
namespace App\Controllers;
|
||||
|
||||
use App\Traits\ResponseTrait;
|
||||
use CodeIgniter\Controller;
|
||||
|
||||
use Firebase\JWT\JWT;
|
||||
use Firebase\JWT\Key;
|
||||
use Firebase\JWT\ExpiredException;
|
||||
use Firebase\JWT\SignatureInvalidException;
|
||||
use Firebase\JWT\BeforeValidException;
|
||||
use CodeIgniter\Cookie\Cookie;
|
||||
|
||||
class DashboardController extends Controller
|
||||
{
|
||||
use ResponseTrait;
|
||||
|
||||
public function index()
|
||||
{
|
||||
|
||||
$token = $this->request->getCookie('token');
|
||||
$key = getenv('JWT_SECRET');
|
||||
|
||||
// Decode Token dengan Key yg ada di .env
|
||||
$decodedPayload = JWT::decode($token, new Key($key, 'HS256'));
|
||||
|
||||
return $this->respond([
|
||||
'status' => 'success',
|
||||
'code' => 200,
|
||||
'message' => 'Authenticated',
|
||||
'data' => $decodedPayload
|
||||
], 200);
|
||||
}
|
||||
|
||||
}
|
||||
<?php
|
||||
|
||||
namespace App\Controllers;
|
||||
|
||||
use CodeIgniter\API\ResponseTrait;
|
||||
use CodeIgniter\Controller;
|
||||
|
||||
use Firebase\JWT\JWT;
|
||||
use Firebase\JWT\Key;
|
||||
use Firebase\JWT\ExpiredException;
|
||||
use Firebase\JWT\SignatureInvalidException;
|
||||
use Firebase\JWT\BeforeValidException;
|
||||
use CodeIgniter\Cookie\Cookie;
|
||||
|
||||
class DashboardController extends Controller
|
||||
{
|
||||
use ResponseTrait;
|
||||
|
||||
public function index()
|
||||
{
|
||||
|
||||
$token = $this->request->getCookie('token');
|
||||
$key = getenv('JWT_SECRET');
|
||||
|
||||
// Decode Token dengan Key yg ada di .env
|
||||
$decodedPayload = JWT::decode($token, new Key($key, 'HS256'));
|
||||
|
||||
return $this->respond([
|
||||
'status' => 'success',
|
||||
'code' => 200,
|
||||
'message' => 'Authenticated',
|
||||
'data' => $decodedPayload
|
||||
], 200);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
336
app/Controllers/EdgeController.php
Executable file → Normal file
336
app/Controllers/EdgeController.php
Executable file → Normal file
@ -1,169 +1,169 @@
|
||||
<?php
|
||||
|
||||
namespace App\Controllers;
|
||||
|
||||
use App\Traits\ResponseTrait;
|
||||
use CodeIgniter\Controller;
|
||||
|
||||
class EdgeController extends Controller
|
||||
{
|
||||
use ResponseTrait;
|
||||
|
||||
protected $db;
|
||||
protected $edgeResModel;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->db = \Config\Database::connect();
|
||||
$this->edgeResModel = new \App\Models\EdgeResModel();
|
||||
}
|
||||
|
||||
/**
|
||||
* POST /api/edge/result
|
||||
* Receive results from tiny-edge
|
||||
*/
|
||||
public function results()
|
||||
{
|
||||
try {
|
||||
$input = $this->request->getJSON(true);
|
||||
|
||||
if (empty($input)) {
|
||||
return $this->failValidationErrors('Invalid JSON payload');
|
||||
}
|
||||
|
||||
// Extract key fields from payload
|
||||
$sampleId = $input['sample_id'] ?? null;
|
||||
$instrumentId = $input['instrument_id'] ?? null;
|
||||
$patientId = $input['patient_id'] ?? null;
|
||||
|
||||
// Store in edgeres table
|
||||
$data = [
|
||||
'SiteID' => 1, // Default site, can be configured
|
||||
'InstrumentID' => $instrumentId,
|
||||
'SampleID' => $sampleId,
|
||||
'PatientID' => $patientId,
|
||||
'Payload' => json_encode($input),
|
||||
'Status' => 'pending',
|
||||
'AutoProcess' => 0, // Default to manual processing
|
||||
'CreateDate' => date('Y-m-d H:i:s')
|
||||
];
|
||||
|
||||
$id = $this->edgeResModel->insert($data);
|
||||
|
||||
if (!$id) {
|
||||
return $this->failServerError('Failed to save result');
|
||||
}
|
||||
|
||||
return $this->respondCreated([
|
||||
'status' => 'success',
|
||||
'message' => 'Result received and queued',
|
||||
'data' => [
|
||||
'edge_res_id' => $id,
|
||||
'sample_id' => $sampleId,
|
||||
'instrument_id' => $instrumentId
|
||||
]
|
||||
]);
|
||||
|
||||
} catch (\Throwable $e) {
|
||||
return $this->failServerError('Error processing result: ' . $e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* GET /api/edge/order
|
||||
* Return pending orders for an instrument
|
||||
*/
|
||||
public function orders()
|
||||
{
|
||||
try {
|
||||
$instrumentId = $this->request->getGet('instrument');
|
||||
|
||||
if (!$instrumentId) {
|
||||
return $this->failValidationErrors('instrument parameter is required');
|
||||
}
|
||||
|
||||
// TODO: Implement order fetching logic
|
||||
// For now, return empty array
|
||||
return $this->respond([
|
||||
'status' => 'success',
|
||||
'message' => 'Orders fetched',
|
||||
'data' => []
|
||||
]);
|
||||
|
||||
} catch (\Throwable $e) {
|
||||
return $this->failServerError('Error fetching orders: ' . $e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* POST /api/edge/order/:id/ack
|
||||
* Acknowledge order delivery
|
||||
*/
|
||||
public function ack($orderId = null)
|
||||
{
|
||||
try {
|
||||
if (!$orderId) {
|
||||
return $this->failValidationErrors('Order ID is required');
|
||||
}
|
||||
|
||||
$input = $this->request->getJSON(true);
|
||||
$instrumentId = $input['instrument_id'] ?? null;
|
||||
|
||||
// Log acknowledgment
|
||||
$this->db->table('edgeack')->insert([
|
||||
'OrderID' => $orderId,
|
||||
'InstrumentID' => $instrumentId,
|
||||
'AckDate' => date('Y-m-d H:i:s'),
|
||||
'CreateDate' => date('Y-m-d H:i:s')
|
||||
]);
|
||||
|
||||
return $this->respond([
|
||||
'status' => 'success',
|
||||
'message' => 'Order acknowledged',
|
||||
'data' => [
|
||||
'order_id' => $orderId
|
||||
]
|
||||
]);
|
||||
|
||||
} catch (\Throwable $e) {
|
||||
return $this->failServerError('Error acknowledging order: ' . $e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
<?php
|
||||
|
||||
namespace App\Controllers;
|
||||
|
||||
use CodeIgniter\API\ResponseTrait;
|
||||
use CodeIgniter\Controller;
|
||||
|
||||
class EdgeController extends Controller
|
||||
{
|
||||
use ResponseTrait;
|
||||
|
||||
protected $db;
|
||||
protected $edgeResModel;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->db = \Config\Database::connect();
|
||||
$this->edgeResModel = new \App\Models\EdgeResModel();
|
||||
}
|
||||
|
||||
/**
|
||||
* POST /api/edge/results
|
||||
* Receive results from tiny-edge
|
||||
*/
|
||||
public function results()
|
||||
{
|
||||
try {
|
||||
$input = $this->request->getJSON(true);
|
||||
|
||||
if (empty($input)) {
|
||||
return $this->failValidationErrors('Invalid JSON payload');
|
||||
}
|
||||
|
||||
// Extract key fields from payload
|
||||
$sampleId = $input['sample_id'] ?? null;
|
||||
$instrumentId = $input['instrument_id'] ?? null;
|
||||
$patientId = $input['patient_id'] ?? null;
|
||||
|
||||
// Store in edgeres table
|
||||
$data = [
|
||||
'SiteID' => 1, // Default site, can be configured
|
||||
'InstrumentID' => $instrumentId,
|
||||
'SampleID' => $sampleId,
|
||||
'PatientID' => $patientId,
|
||||
'Payload' => json_encode($input),
|
||||
'Status' => 'pending',
|
||||
'AutoProcess' => 0, // Default to manual processing
|
||||
'CreateDate' => date('Y-m-d H:i:s')
|
||||
];
|
||||
|
||||
$id = $this->edgeResModel->insert($data);
|
||||
|
||||
if (!$id) {
|
||||
return $this->failServerError('Failed to save result');
|
||||
}
|
||||
|
||||
return $this->respondCreated([
|
||||
'status' => 'success',
|
||||
'message' => 'Result received and queued',
|
||||
'data' => [
|
||||
'edge_res_id' => $id,
|
||||
'sample_id' => $sampleId,
|
||||
'instrument_id' => $instrumentId
|
||||
]
|
||||
]);
|
||||
|
||||
} catch (\Throwable $e) {
|
||||
return $this->failServerError('Error processing result: ' . $e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* GET /api/edge/orders
|
||||
* Return pending orders for an instrument
|
||||
*/
|
||||
public function orders()
|
||||
{
|
||||
try {
|
||||
$instrumentId = $this->request->getGet('instrument');
|
||||
|
||||
if (!$instrumentId) {
|
||||
return $this->failValidationErrors('instrument parameter is required');
|
||||
}
|
||||
|
||||
// TODO: Implement order fetching logic
|
||||
// For now, return empty array
|
||||
return $this->respond([
|
||||
'status' => 'success',
|
||||
'message' => 'Orders fetched',
|
||||
'data' => []
|
||||
]);
|
||||
|
||||
} catch (\Throwable $e) {
|
||||
return $this->failServerError('Error fetching orders: ' . $e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* POST /api/edge/orders/:id/ack
|
||||
* Acknowledge order delivery
|
||||
*/
|
||||
public function ack($orderId = null)
|
||||
{
|
||||
try {
|
||||
if (!$orderId) {
|
||||
return $this->failValidationErrors('Order ID is required');
|
||||
}
|
||||
|
||||
$input = $this->request->getJSON(true);
|
||||
$instrumentId = $input['instrument_id'] ?? null;
|
||||
|
||||
// Log acknowledgment
|
||||
$this->db->table('edgeack')->insert([
|
||||
'OrderID' => $orderId,
|
||||
'InstrumentID' => $instrumentId,
|
||||
'AckDate' => date('Y-m-d H:i:s'),
|
||||
'CreateDate' => date('Y-m-d H:i:s')
|
||||
]);
|
||||
|
||||
return $this->respond([
|
||||
'status' => 'success',
|
||||
'message' => 'Order acknowledged',
|
||||
'data' => [
|
||||
'order_id' => $orderId
|
||||
]
|
||||
]);
|
||||
|
||||
} catch (\Throwable $e) {
|
||||
return $this->failServerError('Error acknowledging order: ' . $e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* POST /api/edge/status
|
||||
* Log instrument status
|
||||
*/
|
||||
public function status()
|
||||
{
|
||||
try {
|
||||
$input = $this->request->getJSON(true);
|
||||
|
||||
$instrumentId = $input['instrument_id'] ?? null;
|
||||
$status = $input['status'] ?? null;
|
||||
$lastActivity = $input['last_activity'] ?? null;
|
||||
$timestamp = $input['timestamp'] ?? date('Y-m-d H:i:s');
|
||||
|
||||
if (!$instrumentId || !$status) {
|
||||
return $this->failValidationErrors('instrument_id and status are required');
|
||||
}
|
||||
|
||||
// Store status log
|
||||
$this->db->table('edgestatus')->insert([
|
||||
'InstrumentID' => $instrumentId,
|
||||
'Status' => $status,
|
||||
'LastActivity' => $lastActivity,
|
||||
'Timestamp' => $timestamp,
|
||||
'CreateDate' => date('Y-m-d H:i:s')
|
||||
]);
|
||||
|
||||
return $this->respond([
|
||||
'status' => 'success',
|
||||
'message' => 'Status logged'
|
||||
]);
|
||||
|
||||
} catch (\Throwable $e) {
|
||||
return $this->failServerError('Error logging status: ' . $e->getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
* Log instrument status
|
||||
*/
|
||||
public function status()
|
||||
{
|
||||
try {
|
||||
$input = $this->request->getJSON(true);
|
||||
|
||||
$instrumentId = $input['instrument_id'] ?? null;
|
||||
$status = $input['status'] ?? null;
|
||||
$lastActivity = $input['last_activity'] ?? null;
|
||||
$timestamp = $input['timestamp'] ?? date('Y-m-d H:i:s');
|
||||
|
||||
if (!$instrumentId || !$status) {
|
||||
return $this->failValidationErrors('instrument_id and status are required');
|
||||
}
|
||||
|
||||
// Store status log
|
||||
$this->db->table('edgestatus')->insert([
|
||||
'InstrumentID' => $instrumentId,
|
||||
'Status' => $status,
|
||||
'LastActivity' => $lastActivity,
|
||||
'Timestamp' => $timestamp,
|
||||
'CreateDate' => date('Y-m-d H:i:s')
|
||||
]);
|
||||
|
||||
return $this->respond([
|
||||
'status' => 'success',
|
||||
'message' => 'Status logged'
|
||||
]);
|
||||
|
||||
} catch (\Throwable $e) {
|
||||
return $this->failServerError('Error logging status: ' . $e->getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
66
app/Controllers/HomeController.php
Executable file → Normal file
66
app/Controllers/HomeController.php
Executable file → Normal file
@ -1,33 +1,33 @@
|
||||
<?php
|
||||
|
||||
namespace App\Controllers;
|
||||
|
||||
use App\Traits\ResponseTrait;
|
||||
use CodeIgniter\Controller;
|
||||
|
||||
use Firebase\JWT\JWT;
|
||||
use Firebase\JWT\Key;
|
||||
use Firebase\JWT\ExpiredException;
|
||||
use Firebase\JWT\SignatureInvalidException;
|
||||
use Firebase\JWT\BeforeValidException;
|
||||
use CodeIgniter\Cookie\Cookie;
|
||||
|
||||
class HomeController extends Controller {
|
||||
use ResponseTrait;
|
||||
|
||||
public function index() {
|
||||
|
||||
// $token = $this->request->getCookie('token');
|
||||
// $key = getenv('JWT_SECRET');
|
||||
|
||||
// // Decode Token dengan Key yg ada di .env
|
||||
// $decodedPayload = JWT::decode($token, new Key($key, 'HS256'));
|
||||
|
||||
// return $this->respond([
|
||||
// 'status' => 'success',
|
||||
// 'code' => 200,
|
||||
// 'message' => 'Authenticated',
|
||||
// 'data' => $decodedPayload
|
||||
// ], 200);
|
||||
}
|
||||
}
|
||||
<?php
|
||||
|
||||
namespace App\Controllers;
|
||||
|
||||
use CodeIgniter\API\ResponseTrait;
|
||||
use CodeIgniter\Controller;
|
||||
|
||||
use Firebase\JWT\JWT;
|
||||
use Firebase\JWT\Key;
|
||||
use Firebase\JWT\ExpiredException;
|
||||
use Firebase\JWT\SignatureInvalidException;
|
||||
use Firebase\JWT\BeforeValidException;
|
||||
use CodeIgniter\Cookie\Cookie;
|
||||
|
||||
class HomeController extends Controller {
|
||||
use ResponseTrait;
|
||||
|
||||
public function index() {
|
||||
|
||||
// $token = $this->request->getCookie('token');
|
||||
// $key = getenv('JWT_SECRET');
|
||||
|
||||
// // Decode Token dengan Key yg ada di .env
|
||||
// $decodedPayload = JWT::decode($token, new Key($key, 'HS256'));
|
||||
|
||||
// return $this->respond([
|
||||
// 'status' => 'success',
|
||||
// 'code' => 200,
|
||||
// 'message' => 'Authenticated',
|
||||
// 'data' => $decodedPayload
|
||||
// ], 200);
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,116 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Controllers\Infrastructure;
|
||||
|
||||
use App\Controllers\BaseController;
|
||||
use App\Traits\ResponseTrait;
|
||||
use App\Models\Infrastructure\EquipmentListModel;
|
||||
|
||||
class EquipmentListController extends BaseController {
|
||||
use ResponseTrait;
|
||||
|
||||
protected $db;
|
||||
protected $model;
|
||||
|
||||
public function __construct() {
|
||||
$this->db = \Config\Database::connect();
|
||||
$this->model = new EquipmentListModel();
|
||||
}
|
||||
|
||||
public function index() {
|
||||
$filter = [
|
||||
'IEID' => $this->request->getVar('IEID'),
|
||||
'InstrumentName' => $this->request->getVar('InstrumentName'),
|
||||
'DepartmentID' => $this->request->getVar('DepartmentID'),
|
||||
'WorkstationID' => $this->request->getVar('WorkstationID'),
|
||||
'isEnable' => $this->request->getVar('isEnable'),
|
||||
];
|
||||
|
||||
$rows = $this->model->getEquipmentLists($filter);
|
||||
|
||||
if (empty($rows)) {
|
||||
return $this->respond([
|
||||
'status' => 'success',
|
||||
'message' => 'no Data.',
|
||||
'data' => []
|
||||
], 200);
|
||||
}
|
||||
|
||||
return $this->respond([
|
||||
'status' => 'success',
|
||||
'message' => 'fetch success',
|
||||
'data' => $rows
|
||||
], 200);
|
||||
}
|
||||
|
||||
public function show($EID = null) {
|
||||
$row = $this->model->getEquipmentList($EID);
|
||||
|
||||
if (empty($row)) {
|
||||
return $this->respond([
|
||||
'status' => 'success',
|
||||
'message' => 'no Data.',
|
||||
'data' => null
|
||||
], 200);
|
||||
}
|
||||
|
||||
return $this->respond([
|
||||
'status' => 'success',
|
||||
'message' => 'fetch success',
|
||||
'data' => $row
|
||||
], 200);
|
||||
}
|
||||
|
||||
public function create() {
|
||||
$input = $this->request->getJSON(true);
|
||||
|
||||
try {
|
||||
$EID = $this->model->insert($input, true);
|
||||
return $this->respondCreated([
|
||||
'status' => 'success',
|
||||
'message' => 'data created successfully',
|
||||
'data' => $EID
|
||||
], 201);
|
||||
} catch (\Throwable $e) {
|
||||
return $this->failServerError('Something went wrong: ' . $e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
public function update($EID = null) {
|
||||
$input = $this->request->getJSON(true);
|
||||
|
||||
try {
|
||||
if (!$EID || !ctype_digit((string) $EID)) {
|
||||
return $this->failValidationErrors('EID is required.');
|
||||
}
|
||||
$input['EID'] = (int) $EID;
|
||||
$this->model->update($EID, $input);
|
||||
return $this->respond([
|
||||
'status' => 'success',
|
||||
'message' => 'data updated successfully',
|
||||
'data' => $EID
|
||||
], 200);
|
||||
} catch (\Throwable $e) {
|
||||
return $this->failServerError('Something went wrong: ' . $e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
public function delete() {
|
||||
try {
|
||||
$input = $this->request->getJSON(true);
|
||||
$EID = $input['EID'];
|
||||
|
||||
if (!$EID) {
|
||||
return $this->failValidationErrors('EID is required.');
|
||||
}
|
||||
|
||||
$this->model->delete($EID);
|
||||
return $this->respondDeleted([
|
||||
'status' => 'success',
|
||||
'message' => "{$EID} deleted successfully."
|
||||
]);
|
||||
} catch (\Throwable $e) {
|
||||
return $this->failServerError('Something went wrong: ' . $e->getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
153
app/Controllers/LocationController.php
Executable file → Normal file
153
app/Controllers/LocationController.php
Executable file → Normal file
@ -1,126 +1,75 @@
|
||||
<?php
|
||||
namespace App\Controllers;
|
||||
|
||||
use App\Traits\PatchValidationTrait;
|
||||
use App\Traits\ResponseTrait;
|
||||
<?php
|
||||
namespace App\Controllers;
|
||||
|
||||
use CodeIgniter\API\ResponseTrait;
|
||||
use App\Controllers\BaseController;
|
||||
use App\Models\Location\LocationModel;
|
||||
|
||||
|
||||
class LocationController extends BaseController {
|
||||
use ResponseTrait;
|
||||
use PatchValidationTrait;
|
||||
|
||||
protected $model;
|
||||
protected $rules;
|
||||
protected $patchRules;
|
||||
|
||||
|
||||
public function __construct() {
|
||||
$this->model = new LocationModel();
|
||||
$this->rules = [
|
||||
'LocCode' => 'required|max_length[6]',
|
||||
'LocFull' => 'required',
|
||||
];
|
||||
$this->patchRules = [
|
||||
'SiteID' => 'permit_empty|is_natural_no_zero',
|
||||
'LocCode' => 'permit_empty|max_length[6]',
|
||||
'Parent' => 'permit_empty|is_natural',
|
||||
'LocFull' => 'permit_empty',
|
||||
'Description' => 'permit_empty|max_length[255]',
|
||||
'LocType' => 'permit_empty',
|
||||
'Street1' => 'permit_empty|max_length[255]',
|
||||
'Street2' => 'permit_empty|max_length[255]',
|
||||
'City' => 'permit_empty|max_length[255]',
|
||||
'Province' => 'permit_empty|max_length[255]',
|
||||
'PostCode' => 'permit_empty|max_length[20]',
|
||||
'GeoLocationSystem' => 'permit_empty|max_length[255]',
|
||||
'GeoLocationData' => 'permit_empty|max_length[255]',
|
||||
'Phone' => 'permit_empty|max_length[20]',
|
||||
'Email' => 'permit_empty|valid_email|max_length[255]',
|
||||
];
|
||||
}
|
||||
|
||||
public function index() {
|
||||
$LocName = $this->request->getVar('LocName');
|
||||
$LocCode = $this->request->getVar('LocCode');
|
||||
$rows = $this->model->getLocations($LocCode,$LocName);
|
||||
if (empty($rows)) {
|
||||
return $this->respond([ 'status' => 'success', 'message' => "no Data.", 'data' => [] ], 200);
|
||||
}
|
||||
|
||||
return $this->respond([ 'status' => 'success', 'message'=> "fetch success", 'data' => $rows ], 200);
|
||||
}
|
||||
|
||||
public function show($LocationID = null) {
|
||||
$row = $this->model->getLocation($LocationID);
|
||||
if (empty($row)) {
|
||||
return $this->respond([ 'status' => 'success', 'message' => "no Data.", 'data' => null ], 200);
|
||||
}
|
||||
|
||||
return $this->respond([ 'status' => 'success', 'message'=> "fetch success", 'data' => $row ], 200);
|
||||
}
|
||||
|
||||
public function create() {
|
||||
$input = $this->request->getJSON(true);
|
||||
if (!$this->validateData($input, $this->rules)) { return $this->failValidationErrors($this->validator->getErrors()); }
|
||||
try {
|
||||
$result = $this->model->saveLocation($input);
|
||||
return $this->respondCreated([ 'status' => 'success', 'message' => 'data created successfully', 'data' => $result ], 201);
|
||||
} catch (\Throwable $e) {
|
||||
return $this->failServerError('Something went wrong: ' . $e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
public function update($LocationID = null) {
|
||||
$input = $this->requirePatchPayload($this->request->getJSON(true));
|
||||
if ($input === null) {
|
||||
return;
|
||||
|
||||
public function index() {
|
||||
$LocName = $this->request->getVar('LocName');
|
||||
$LocCode = $this->request->getVar('LocCode');
|
||||
$rows = $this->model->getLocations($LocCode,$LocName);
|
||||
if (empty($rows)) {
|
||||
return $this->respond([ 'status' => 'success', 'message' => "no Data.", 'data' => [] ], 200);
|
||||
}
|
||||
|
||||
$id = $this->requirePatchId($LocationID, 'LocationID');
|
||||
if ($id === null) {
|
||||
return;
|
||||
return $this->respond([ 'status' => 'success', 'message'=> "fetch success", 'data' => $rows ], 200);
|
||||
}
|
||||
|
||||
public function show($LocationID = null) {
|
||||
$row = $this->model->getLocation($LocationID);
|
||||
if (empty($row)) {
|
||||
return $this->respond([ 'status' => 'success', 'message' => "no Data.", 'data' => null ], 200);
|
||||
}
|
||||
|
||||
$existing = $this->model->find($id);
|
||||
if (!$existing) {
|
||||
return $this->respond([
|
||||
'status' => 'failed',
|
||||
'message' => 'Location not found',
|
||||
'data' => []
|
||||
], 404);
|
||||
}
|
||||
return $this->respond([ 'status' => 'success', 'message'=> "fetch success", 'data' => $row ], 200);
|
||||
}
|
||||
|
||||
$validationInput = array_intersect_key($input, $this->patchRules);
|
||||
if ($validationInput === []) {
|
||||
return $this->respond([
|
||||
'status' => 'failed',
|
||||
'message' => 'No valid fields provided for update.',
|
||||
'data' => []
|
||||
], 422);
|
||||
}
|
||||
|
||||
if (!$this->validateData($validationInput, $this->patchRules)) {
|
||||
return $this->failValidationErrors($this->validator->getErrors());
|
||||
}
|
||||
|
||||
$input['LocationID'] = $id;
|
||||
public function create() {
|
||||
$input = $this->request->getJSON(true);
|
||||
if (!$this->validateData($input, $this->rules)) { return $this->failValidationErrors($this->validator->getErrors()); }
|
||||
try {
|
||||
$result = $this->model->saveLocation($input);
|
||||
return $this->respond([ 'status' => 'success', 'message' => 'data updated successfully', 'data' => $result ], 200);
|
||||
return $this->respondCreated([ 'status' => 'success', 'message' => 'data created successfully', 'data' => $result ], 201);
|
||||
} catch (\Throwable $e) {
|
||||
return $this->failServerError('Something went wrong: ' . $e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
public function delete() {
|
||||
$input = $this->request->getJSON(true);
|
||||
try {
|
||||
$LocationID = $input["LocationID"];
|
||||
$this->model->deleteLocation($LocationID);
|
||||
return $this->respondDeleted([ 'status' => 'success', 'message' => "Location with {$LocationID} deleted successfully." ]);
|
||||
} catch (\Throwable $e) {
|
||||
return $this->failServerError('Something went wrong: ' . $e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
public function update() {
|
||||
$input = $this->request->getJSON(true);
|
||||
try {
|
||||
if (!$this->validateData($input, $this->rules)) { return $this->failValidationErrors( $this->validator->getErrors()); }
|
||||
$result = $this->model->saveLocation($input, true);
|
||||
return $this->respondCreated([ 'status' => 'success', 'message' => 'data updated successfully', 'data' => $result ], 201);
|
||||
} catch (\Throwable $e) {
|
||||
return $this->failServerError('Something went wrong: ' . $e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
public function delete() {
|
||||
$input = $this->request->getJSON(true);
|
||||
try {
|
||||
$LocationID = $input["LocationID"];
|
||||
$this->model->deleteLocation($LocationID);
|
||||
return $this->respondDeleted([ 'status' => 'success', 'message' => "Location with {$LocationID} deleted successfully." ]);
|
||||
} catch (\Throwable $e) {
|
||||
return $this->failServerError('Something went wrong: ' . $e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
453
app/Controllers/OrderTestController.php
Executable file → Normal file
453
app/Controllers/OrderTestController.php
Executable file → Normal file
@ -1,295 +1,192 @@
|
||||
<?php
|
||||
namespace App\Controllers;
|
||||
|
||||
use App\Traits\ResponseTrait;
|
||||
use CodeIgniter\Controller;
|
||||
use App\Libraries\ValueSet;
|
||||
<?php
|
||||
namespace App\Controllers;
|
||||
|
||||
use CodeIgniter\API\ResponseTrait;
|
||||
use CodeIgniter\Controller;
|
||||
use App\Models\OrderTest\OrderTestModel;
|
||||
use App\Models\Patient\PatientModel;
|
||||
use App\Models\PatVisit\PatVisitModel;
|
||||
|
||||
class OrderTestController extends Controller {
|
||||
use ResponseTrait;
|
||||
|
||||
protected $db;
|
||||
protected $model;
|
||||
protected $patientModel;
|
||||
protected $visitModel;
|
||||
protected $rules;
|
||||
|
||||
public function __construct() {
|
||||
$this->db = \Config\Database::connect();
|
||||
$this->model = new OrderTestModel();
|
||||
$this->patientModel = new PatientModel();
|
||||
$this->visitModel = new PatVisitModel();
|
||||
$this->rules = [
|
||||
'InternalPID' => 'required|is_natural'
|
||||
];
|
||||
}
|
||||
|
||||
public function index() {
|
||||
$internalPID = $this->request->getVar('InternalPID');
|
||||
$includeDetails = $this->request->getVar('include') === 'details';
|
||||
|
||||
try {
|
||||
if ($internalPID) {
|
||||
$rows = $this->model->getOrdersByPatient($internalPID);
|
||||
} else {
|
||||
$rows = $this->db->table('ordertest')
|
||||
->where('DelDate', null)
|
||||
->orderBy('TrnDate', 'DESC')
|
||||
->get()
|
||||
->getResultArray();
|
||||
}
|
||||
|
||||
$rows = ValueSet::transformLabels($rows, [
|
||||
'Priority' => 'order_priority',
|
||||
'OrderStatus' => 'order_status',
|
||||
]);
|
||||
|
||||
if ($includeDetails && !empty($rows)) {
|
||||
foreach ($rows as &$row) {
|
||||
$row['Specimens'] = $this->getOrderSpecimens($row['InternalOID']);
|
||||
$row['Tests'] = $this->getOrderTests($row['InternalOID']);
|
||||
}
|
||||
}
|
||||
|
||||
return $this->respond([
|
||||
'status' => 'success',
|
||||
'message' => 'Data fetched successfully',
|
||||
'data' => $rows
|
||||
], 200);
|
||||
} catch (\Exception $e) {
|
||||
return $this->failServerError('Something went wrong: ' . $e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
public function show($orderID = null) {
|
||||
try {
|
||||
$row = $this->model->getOrder($orderID);
|
||||
if (empty($row)) {
|
||||
return $this->respond([
|
||||
'status' => 'success',
|
||||
'message' => 'Data not found.',
|
||||
'data' => null
|
||||
], 200);
|
||||
}
|
||||
|
||||
$row = ValueSet::transformLabels([$row], [
|
||||
'Priority' => 'order_priority',
|
||||
'OrderStatus' => 'order_status',
|
||||
])[0];
|
||||
|
||||
// Include specimens and tests
|
||||
$row['Specimens'] = $this->getOrderSpecimens($row['InternalOID']);
|
||||
$row['Tests'] = $this->getOrderTests($row['InternalOID']);
|
||||
|
||||
return $this->respond([
|
||||
'status' => 'success',
|
||||
'message' => 'Data fetched successfully',
|
||||
'data' => $row
|
||||
], 200);
|
||||
} catch (\Exception $e) {
|
||||
return $this->failServerError('Something went wrong: ' . $e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
private function getOrderSpecimens($internalOID) {
|
||||
$specimens = $this->db->table('specimen s')
|
||||
->select('s.*, cd.ConCode, cd.ConName')
|
||||
->join('containerdef cd', 'cd.ConDefID = s.ConDefID', 'left')
|
||||
->where('s.OrderID', $internalOID)
|
||||
->where('s.EndDate IS NULL')
|
||||
->get()
|
||||
->getResultArray();
|
||||
|
||||
// Get status for each specimen
|
||||
foreach ($specimens as &$specimen) {
|
||||
$status = $this->db->table('specimenstatus')
|
||||
->where('SID', $specimen['SID'])
|
||||
->where('EndDate IS NULL')
|
||||
->orderBy('CreateDate', 'DESC')
|
||||
->get()
|
||||
->getRowArray();
|
||||
$specimen['Status'] = $status['SpcStatus'] ?? 'PENDING';
|
||||
}
|
||||
|
||||
return $specimens;
|
||||
}
|
||||
|
||||
private function getOrderTests($internalOID) {
|
||||
$tests = $this->db->table('patres pr')
|
||||
->select('pr.*, tds.TestSiteCode, tds.TestSiteName, tds.TestType, tds.SeqScr AS TestSeqScr, tds.SeqRpt AS TestSeqRpt, tds.DisciplineID, d.DisciplineCode, d.DisciplineName, d.SeqScr AS DisciplineSeqScr, d.SeqRpt AS DisciplineSeqRpt')
|
||||
->join('testdefsite tds', 'tds.TestSiteID = pr.TestSiteID', 'left')
|
||||
->join('discipline d', 'd.DisciplineID = tds.DisciplineID', 'left')
|
||||
->where('pr.OrderID', $internalOID)
|
||||
->where('pr.DelDate IS NULL')
|
||||
->orderBy('COALESCE(d.SeqScr, 999999) ASC')
|
||||
->orderBy('COALESCE(d.SeqRpt, 999999) ASC')
|
||||
->orderBy('COALESCE(tds.SeqScr, 999999) ASC')
|
||||
->orderBy('COALESCE(tds.SeqRpt, 999999) ASC')
|
||||
->orderBy('pr.ResultID ASC')
|
||||
->get()
|
||||
->getResultArray();
|
||||
|
||||
foreach ($tests as &$test) {
|
||||
$discipline = [
|
||||
'DisciplineID' => $test['DisciplineID'] ?? null,
|
||||
'DisciplineCode' => $test['DisciplineCode'] ?? null,
|
||||
'DisciplineName' => $test['DisciplineName'] ?? null,
|
||||
'SeqScr' => $test['DisciplineSeqScr'] ?? null,
|
||||
'SeqRpt' => $test['DisciplineSeqRpt'] ?? null,
|
||||
];
|
||||
|
||||
$test['Discipline'] = $discipline;
|
||||
$test['SeqScr'] = $test['TestSeqScr'] ?? null;
|
||||
$test['SeqRpt'] = $test['TestSeqRpt'] ?? null;
|
||||
$test['DisciplineID'] = $discipline['DisciplineID'];
|
||||
|
||||
unset($test['DisciplineCode'], $test['DisciplineName'], $test['DisciplineSeqScr'], $test['DisciplineSeqRpt'], $test['TestSeqScr'], $test['TestSeqRpt']);
|
||||
}
|
||||
unset($test);
|
||||
|
||||
return $tests;
|
||||
}
|
||||
|
||||
public function create() {
|
||||
$input = $this->request->getJSON(true);
|
||||
|
||||
if (!$this->validateData($input, $this->rules)) {
|
||||
return $this->failValidationErrors($this->validator->getErrors());
|
||||
}
|
||||
|
||||
try {
|
||||
if (!$this->patientModel->find($input['InternalPID'])) {
|
||||
return $this->failValidationErrors(['InternalPID' => 'Patient not found']);
|
||||
}
|
||||
|
||||
if (!empty($input['PatVisitID'])) {
|
||||
$visit = $this->visitModel->find($input['PatVisitID']);
|
||||
if (!$visit) {
|
||||
return $this->failValidationErrors(['PatVisitID' => 'Visit not found']);
|
||||
}
|
||||
}
|
||||
|
||||
$orderID = $this->model->createOrder($input);
|
||||
|
||||
// Fetch complete order details
|
||||
$order = $this->model->getOrder($orderID);
|
||||
$order['Specimens'] = $this->getOrderSpecimens($order['InternalOID']);
|
||||
$order['Tests'] = $this->getOrderTests($order['InternalOID']);
|
||||
|
||||
// Rule engine triggers are fired at the test/result level (test_created, result_updated)
|
||||
|
||||
class OrderTestController extends Controller {
|
||||
use ResponseTrait;
|
||||
|
||||
protected $db;
|
||||
protected $model;
|
||||
protected $patientModel;
|
||||
protected $visitModel;
|
||||
protected $rules;
|
||||
|
||||
public function __construct() {
|
||||
$this->db = \Config\Database::connect();
|
||||
$this->model = new OrderTestModel();
|
||||
$this->patientModel = new PatientModel();
|
||||
$this->visitModel = new PatVisitModel();
|
||||
$this->rules = [
|
||||
'InternalPID' => 'required|is_natural'
|
||||
];
|
||||
}
|
||||
|
||||
public function index() {
|
||||
$internalPID = $this->request->getVar('InternalPID');
|
||||
|
||||
try {
|
||||
if ($internalPID) {
|
||||
$rows = $this->model->getOrdersByPatient($internalPID);
|
||||
} else {
|
||||
$rows = $this->db->table('ordertest')
|
||||
->where('DelDate', null)
|
||||
->orderBy('OrderDateTime', 'DESC')
|
||||
->get()
|
||||
->getResultArray();
|
||||
}
|
||||
|
||||
return $this->respond([
|
||||
'status' => 'success',
|
||||
'message' => 'Data fetched successfully',
|
||||
'data' => $rows
|
||||
], 200);
|
||||
} catch (\Exception $e) {
|
||||
return $this->failServerError('Something went wrong: ' . $e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
public function show($orderID = null) {
|
||||
try {
|
||||
$row = $this->model->getOrder($orderID);
|
||||
if (empty($row)) {
|
||||
return $this->respond([
|
||||
'status' => 'success',
|
||||
'message' => 'Data not found.',
|
||||
'data' => null
|
||||
], 200);
|
||||
}
|
||||
return $this->respond([
|
||||
'status' => 'success',
|
||||
'message' => 'Data fetched successfully',
|
||||
'data' => $row
|
||||
], 200);
|
||||
} catch (\Exception $e) {
|
||||
return $this->failServerError('Something went wrong: ' . $e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
public function create() {
|
||||
$input = $this->request->getJSON(true);
|
||||
|
||||
if (!$this->validateData($input, $this->rules)) {
|
||||
return $this->failValidationErrors($this->validator->getErrors());
|
||||
}
|
||||
|
||||
try {
|
||||
if (!$this->patientModel->find($input['InternalPID'])) {
|
||||
return $this->failValidationErrors(['InternalPID' => 'Patient not found']);
|
||||
}
|
||||
|
||||
if (!empty($input['PatVisitID'])) {
|
||||
$visit = $this->visitModel->find($input['PatVisitID']);
|
||||
if (!$visit) {
|
||||
return $this->failValidationErrors(['PatVisitID' => 'Visit not found']);
|
||||
}
|
||||
}
|
||||
|
||||
$orderID = $this->model->createOrder($input);
|
||||
|
||||
return $this->respondCreated([
|
||||
'status' => 'success',
|
||||
'message' => 'Order created successfully',
|
||||
'data' => $order
|
||||
'data' => ['OrderID' => $orderID]
|
||||
], 201);
|
||||
} catch (\Exception $e) {
|
||||
return $this->failServerError('Something went wrong: ' . $e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
public function update($OrderID = null) {
|
||||
} catch (\Exception $e) {
|
||||
return $this->failServerError('Something went wrong: ' . $e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
public function update() {
|
||||
$input = $this->request->getJSON(true);
|
||||
|
||||
if ($OrderID === null || $OrderID === '') {
|
||||
if (empty($input['OrderID'])) {
|
||||
return $this->failValidationErrors(['OrderID' => 'OrderID is required']);
|
||||
}
|
||||
|
||||
if (isset($input['OrderID']) && (string) $input['OrderID'] !== (string) $OrderID) {
|
||||
return $this->failValidationErrors(['OrderID' => 'OrderID in URL does not match body']);
|
||||
}
|
||||
|
||||
try {
|
||||
$input['OrderID'] = $OrderID;
|
||||
$order = $this->model->getOrder($OrderID);
|
||||
$order = $this->model->getOrder($input['OrderID']);
|
||||
if (!$order) {
|
||||
return $this->failNotFound('Order not found');
|
||||
}
|
||||
|
||||
$updateData = [];
|
||||
if (isset($input['Priority'])) $updateData['Priority'] = $input['Priority'];
|
||||
if (isset($input['OrderStatus'])) $updateData['OrderStatus'] = $input['OrderStatus'];
|
||||
if (isset($input['OrderingProvider'])) $updateData['OrderingProvider'] = $input['OrderingProvider'];
|
||||
if (isset($input['DepartmentID'])) $updateData['DepartmentID'] = $input['DepartmentID'];
|
||||
if (isset($input['WorkstationID'])) $updateData['WorkstationID'] = $input['WorkstationID'];
|
||||
|
||||
if (!empty($updateData)) {
|
||||
$this->model->update($order['InternalOID'], $updateData);
|
||||
}
|
||||
|
||||
$updatedOrder = $this->model->getOrder($OrderID);
|
||||
$updatedOrder['Specimens'] = $this->getOrderSpecimens($updatedOrder['InternalOID']);
|
||||
$updatedOrder['Tests'] = $this->getOrderTests($updatedOrder['InternalOID']);
|
||||
|
||||
return $this->respond([
|
||||
'status' => 'success',
|
||||
'message' => 'Order updated successfully',
|
||||
'data' => $updatedOrder
|
||||
], 200);
|
||||
} catch (\Exception $e) {
|
||||
return $this->failServerError('Something went wrong: ' . $e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
public function delete() {
|
||||
$input = $this->request->getJSON(true);
|
||||
$orderID = $input['OrderID'] ?? null;
|
||||
|
||||
if (empty($orderID)) {
|
||||
return $this->failValidationErrors(['OrderID' => 'OrderID is required']);
|
||||
}
|
||||
|
||||
try {
|
||||
$order = $this->model->getOrder($orderID);
|
||||
if (!$order) {
|
||||
return $this->failNotFound('Order not found');
|
||||
}
|
||||
|
||||
$this->model->softDelete($orderID);
|
||||
|
||||
return $this->respondDeleted([
|
||||
'status' => 'success',
|
||||
'message' => 'Order deleted successfully'
|
||||
]);
|
||||
} catch (\Exception $e) {
|
||||
return $this->failServerError('Something went wrong: ' . $e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
public function updateStatus() {
|
||||
$input = $this->request->getJSON(true);
|
||||
|
||||
if (empty($input['OrderID']) || empty($input['OrderStatus'])) {
|
||||
return $this->failValidationErrors(['error' => 'OrderID and OrderStatus are required']);
|
||||
}
|
||||
|
||||
$validStatuses = ['ORD', 'SCH', 'ANA', 'VER', 'REV', 'REP'];
|
||||
if (!in_array($input['OrderStatus'], $validStatuses)) {
|
||||
return $this->failValidationErrors(['OrderStatus' => 'Invalid status. Valid: ' . implode(', ', $validStatuses)]);
|
||||
}
|
||||
|
||||
try {
|
||||
$order = $this->model->getOrder($input['OrderID']);
|
||||
if (!$order) {
|
||||
return $this->failNotFound('Order not found');
|
||||
}
|
||||
|
||||
$this->model->updateStatus($input['OrderID'], $input['OrderStatus']);
|
||||
|
||||
$updatedOrder = $this->model->getOrder($input['OrderID']);
|
||||
$updatedOrder['Specimens'] = $this->getOrderSpecimens($updatedOrder['InternalOID']);
|
||||
$updatedOrder['Tests'] = $this->getOrderTests($updatedOrder['InternalOID']);
|
||||
|
||||
return $this->respond([
|
||||
'status' => 'success',
|
||||
'message' => 'Order status updated successfully',
|
||||
'data' => $updatedOrder
|
||||
], 200);
|
||||
} catch (\Exception $e) {
|
||||
return $this->failServerError('Something went wrong: ' . $e->getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$updateData = [];
|
||||
if (isset($input['Priority'])) $updateData['Priority'] = $input['Priority'];
|
||||
if (isset($input['OrderStatus'])) $updateData['OrderStatus'] = $input['OrderStatus'];
|
||||
if (isset($input['OrderingProvider'])) $updateData['OrderingProvider'] = $input['OrderingProvider'];
|
||||
if (isset($input['DepartmentID'])) $updateData['DepartmentID'] = $input['DepartmentID'];
|
||||
if (isset($input['WorkstationID'])) $updateData['WorkstationID'] = $input['WorkstationID'];
|
||||
|
||||
if (!empty($updateData)) {
|
||||
$this->model->update($input['OrderID'], $updateData);
|
||||
}
|
||||
|
||||
return $this->respond([
|
||||
'status' => 'success',
|
||||
'message' => 'Order updated successfully',
|
||||
'data' => $this->model->getOrder($input['OrderID'])
|
||||
], 200);
|
||||
} catch (\Exception $e) {
|
||||
return $this->failServerError('Something went wrong: ' . $e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
public function delete() {
|
||||
$input = $this->request->getJSON(true);
|
||||
$orderID = $input['OrderID'] ?? null;
|
||||
|
||||
if (empty($orderID)) {
|
||||
return $this->failValidationErrors(['OrderID' => 'OrderID is required']);
|
||||
}
|
||||
|
||||
try {
|
||||
$order = $this->model->getOrder($orderID);
|
||||
if (!$order) {
|
||||
return $this->failNotFound('Order not found');
|
||||
}
|
||||
|
||||
$this->model->softDelete($orderID);
|
||||
|
||||
return $this->respondDeleted([
|
||||
'status' => 'success',
|
||||
'message' => 'Order deleted successfully'
|
||||
]);
|
||||
} catch (\Exception $e) {
|
||||
return $this->failServerError('Something went wrong: ' . $e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
public function updateStatus() {
|
||||
$input = $this->request->getJSON(true);
|
||||
|
||||
if (empty($input['OrderID']) || empty($input['OrderStatus'])) {
|
||||
return $this->failValidationErrors(['error' => 'OrderID and OrderStatus are required']);
|
||||
}
|
||||
|
||||
$validStatuses = ['ORD', 'SCH', 'ANA', 'VER', 'REV', 'REP'];
|
||||
if (!in_array($input['OrderStatus'], $validStatuses)) {
|
||||
return $this->failValidationErrors(['OrderStatus' => 'Invalid status. Valid: ' . implode(', ', $validStatuses)]);
|
||||
}
|
||||
|
||||
try {
|
||||
$order = $this->model->getOrder($input['OrderID']);
|
||||
if (!$order) {
|
||||
return $this->failNotFound('Order not found');
|
||||
}
|
||||
|
||||
$this->model->updateStatus($input['OrderID'], $input['OrderStatus']);
|
||||
|
||||
return $this->respond([
|
||||
'status' => 'success',
|
||||
'message' => 'Order status updated successfully',
|
||||
'data' => $this->model->getOrder($input['OrderID'])
|
||||
], 200);
|
||||
} catch (\Exception $e) {
|
||||
return $this->failServerError('Something went wrong: ' . $e->getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
134
app/Controllers/Organization/AccountController.php
Executable file → Normal file
134
app/Controllers/Organization/AccountController.php
Executable file → Normal file
@ -1,77 +1,62 @@
|
||||
<?php
|
||||
namespace App\Controllers\Organization;
|
||||
|
||||
use App\Traits\PatchValidationTrait;
|
||||
use App\Traits\ResponseTrait;
|
||||
<?php
|
||||
namespace App\Controllers\Organization;
|
||||
|
||||
use CodeIgniter\API\ResponseTrait;
|
||||
use App\Controllers\BaseController;
|
||||
|
||||
use App\Models\Organization\AccountModel;
|
||||
|
||||
|
||||
class AccountController extends BaseController {
|
||||
use ResponseTrait;
|
||||
use PatchValidationTrait;
|
||||
|
||||
protected $db;
|
||||
protected $model;
|
||||
|
||||
public function __construct() {
|
||||
$this->db = \Config\Database::connect();
|
||||
$this->model = new AccountModel();
|
||||
}
|
||||
|
||||
public function index() {
|
||||
$filter = [
|
||||
'Parent' => $this->request->getVar('Parent'),
|
||||
'AccountName' => $this->request->getVar('AccountName'),
|
||||
];
|
||||
|
||||
$rows = $this->model->getAccounts($filter);
|
||||
|
||||
if (empty($rows)) {
|
||||
return $this->respond([ 'status' => 'success', 'message' => "no Data.", 'data' => [] ], 200);
|
||||
}
|
||||
|
||||
return $this->respond([ 'status' => 'success', 'message'=> "fetch success", 'data' => $rows ], 200);
|
||||
}
|
||||
|
||||
public function show($AccountID = null) {
|
||||
//$rows = $this->model->where('AccountID', $AccountID)->findAll();
|
||||
$row = $this->model->getAccount($AccountID);
|
||||
|
||||
if (empty($row)) {
|
||||
return $this->respond([ 'status' => 'success', 'message' => "no Data.", 'data' => null ], 200);
|
||||
}
|
||||
|
||||
return $this->respond([ 'status' => 'success', 'message'=> "fetch success", 'data' => $row ], 200);
|
||||
}
|
||||
|
||||
|
||||
protected $db;
|
||||
protected $model;
|
||||
|
||||
public function __construct() {
|
||||
$this->db = \Config\Database::connect();
|
||||
$this->model = new AccountModel();
|
||||
}
|
||||
|
||||
public function index() {
|
||||
$filter = [
|
||||
'Parent' => $this->request->getVar('Parent'),
|
||||
'AccountName' => $this->request->getVar('AccountName'),
|
||||
];
|
||||
|
||||
$rows = $this->model->getAccounts($filter);
|
||||
|
||||
if (empty($rows)) {
|
||||
return $this->respond([ 'status' => 'success', 'message' => "no Data.", 'data' => [] ], 200);
|
||||
}
|
||||
|
||||
return $this->respond([ 'status' => 'success', 'message'=> "fetch success", 'data' => $rows ], 200);
|
||||
}
|
||||
|
||||
public function show($AccountID = null) {
|
||||
//$rows = $this->model->where('AccountID', $AccountID)->findAll();
|
||||
$row = $this->model->getAccount($AccountID);
|
||||
|
||||
if (empty($row)) {
|
||||
return $this->respond([ 'status' => 'success', 'message' => "no Data.", 'data' => null ], 200);
|
||||
}
|
||||
|
||||
return $this->respond([ 'status' => 'success', 'message'=> "fetch success", 'data' => $row ], 200);
|
||||
}
|
||||
|
||||
public function delete() {
|
||||
try {
|
||||
$input = $this->request->getJSON(true);
|
||||
$id = $this->requirePatchId($input['AccountID'] ?? null, 'AccountID');
|
||||
if ($id === null) {
|
||||
return;
|
||||
}
|
||||
$id = $input["AccountID"];
|
||||
if (!$id) { return $this->failValidationErrors('ID is required.'); }
|
||||
$this->model->delete($id);
|
||||
return $this->respondDeleted([ 'status' => 'success', 'message' => "{$id} deleted successfully."]);
|
||||
} catch (\Throwable $e) {
|
||||
return $this->failServerError('Something went wrong: ' . $e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public function create() {
|
||||
$input = $this->request->getJSON(true);
|
||||
|
||||
$validation = service('validation');
|
||||
$validation->setRules([
|
||||
'AccountName' => 'required|string|max_length[255]',
|
||||
'Parent' => 'permit_empty|integer',
|
||||
]);
|
||||
|
||||
if (!$validation->run($input)) {
|
||||
return $this->failValidationErrors($validation->getErrors());
|
||||
}
|
||||
|
||||
try {
|
||||
$id = $this->model->insert($input,true);
|
||||
return $this->respondCreated([ 'status' => 'success', 'message' => 'data created successfully', 'data' => $id ], 201);
|
||||
@ -79,37 +64,14 @@ class AccountController extends BaseController {
|
||||
return $this->failServerError('Something went wrong: ' . $e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
public function update($AccountID = null) {
|
||||
$input = $this->requirePatchPayload($this->request->getJSON(true));
|
||||
if ($input === null) {
|
||||
return;
|
||||
}
|
||||
|
||||
$id = $this->requirePatchId($AccountID, 'AccountID');
|
||||
if ($id === null) {
|
||||
return;
|
||||
}
|
||||
|
||||
$existing = $this->model->find($id);
|
||||
if (!$existing) {
|
||||
return $this->respond([ 'status' => 'failed', 'message' => 'Account not found', 'data' => [] ], 404);
|
||||
}
|
||||
|
||||
$validation = service('validation');
|
||||
$validation->setRules([
|
||||
'AccountName' => 'permit_empty|string|max_length[255]',
|
||||
'Parent' => 'permit_empty|integer',
|
||||
]);
|
||||
|
||||
if (!$validation->run($input)) {
|
||||
return $this->failValidationErrors($validation->getErrors());
|
||||
}
|
||||
|
||||
$input['AccountID'] = $id;
|
||||
public function update() {
|
||||
$input = $this->request->getJSON(true);
|
||||
try {
|
||||
$id = $input['AccountID'];
|
||||
if (!$id) { return $this->failValidationErrors('ID is required.'); }
|
||||
$this->model->update($id, $input);
|
||||
return $this->respond([ 'status' => 'success', 'message' => 'data updated successfully', 'data' => $id ], 200);
|
||||
return $this->respondCreated([ 'status' => 'success', 'message' => 'data updated successfully', 'data' => $id ], 201);
|
||||
} catch (\Throwable $e) {
|
||||
return $this->failServerError('Something went wrong: ' . $e->getMessage());
|
||||
}
|
||||
|
||||
@ -1,112 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Controllers\Organization;
|
||||
|
||||
use App\Traits\PatchValidationTrait;
|
||||
use App\Traits\ResponseTrait;
|
||||
use App\Controllers\BaseController;
|
||||
use App\Models\Organization\CodingSysModel;
|
||||
|
||||
class CodingSysController extends BaseController {
|
||||
use ResponseTrait;
|
||||
use PatchValidationTrait;
|
||||
|
||||
protected $db;
|
||||
protected $model;
|
||||
|
||||
public function __construct() {
|
||||
$this->db = \Config\Database::connect();
|
||||
$this->model = new CodingSysModel();
|
||||
}
|
||||
|
||||
public function index() {
|
||||
$filter = [
|
||||
'CodingSysAbb' => $this->request->getVar('CodingSysAbb'),
|
||||
'FullText' => $this->request->getVar('FullText'),
|
||||
];
|
||||
|
||||
$builder = $this->model;
|
||||
|
||||
if (!empty($filter['CodingSysAbb'])) {
|
||||
$builder->like('CodingSysAbb', $filter['CodingSysAbb'], 'both');
|
||||
}
|
||||
if (!empty($filter['FullText'])) {
|
||||
$builder->like('FullText', $filter['FullText'], 'both');
|
||||
}
|
||||
|
||||
$rows = $builder->findAll();
|
||||
|
||||
if (empty($rows)) {
|
||||
return $this->respond(['status' => 'success', 'message' => 'no Data.', 'data' => []], 200);
|
||||
}
|
||||
|
||||
return $this->respond(['status' => 'success', 'message' => 'fetch success', 'data' => $rows], 200);
|
||||
}
|
||||
|
||||
public function show($CodingSysID = null) {
|
||||
$row = $this->model->where('CodingSysID', $CodingSysID)->first();
|
||||
|
||||
if (empty($row)) {
|
||||
return $this->respond(['status' => 'success', 'message' => 'no Data.', 'data' => null], 200);
|
||||
}
|
||||
|
||||
return $this->respond(['status' => 'success', 'message' => 'fetch success', 'data' => $row], 200);
|
||||
}
|
||||
|
||||
public function delete() {
|
||||
try {
|
||||
$input = $this->request->getJSON(true);
|
||||
$id = $input['CodingSysID'] ?? null;
|
||||
|
||||
if (!$id) {
|
||||
return $this->failValidationErrors('CodingSysID is required.');
|
||||
}
|
||||
|
||||
$this->model->delete($id);
|
||||
return $this->respondDeleted(['status' => 'success', 'message' => "{$id} deleted successfully."]);
|
||||
} catch (\Throwable $e) {
|
||||
return $this->failServerError('Something went wrong: ' . $e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
public function create() {
|
||||
$input = $this->request->getJSON(true);
|
||||
|
||||
try {
|
||||
$id = $this->model->insert($input, true);
|
||||
return $this->respondCreated(['status' => 'success', 'message' => 'data created successfully', 'data' => $id], 201);
|
||||
} catch (\Throwable $e) {
|
||||
return $this->failServerError('Something went wrong: ' . $e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
public function update($CodingSysID = null) {
|
||||
$input = $this->requirePatchPayload($this->request->getJSON(true));
|
||||
if ($input === null) {
|
||||
return;
|
||||
}
|
||||
|
||||
$id = $this->requirePatchId($CodingSysID, 'CodingSysID');
|
||||
if ($id === null) {
|
||||
return;
|
||||
}
|
||||
|
||||
$existing = $this->model->find($id);
|
||||
if (!$existing) {
|
||||
return $this->respond(['status' => 'failed', 'message' => 'CodingSys not found', 'data' => []], 404);
|
||||
}
|
||||
|
||||
if (isset($input['CodingSysID']) && (string) $input['CodingSysID'] !== (string) $id) {
|
||||
return $this->failValidationErrors('CodingSysID in URL does not match body.');
|
||||
}
|
||||
|
||||
$input['CodingSysID'] = $id;
|
||||
|
||||
try {
|
||||
$this->model->update($id, $input);
|
||||
return $this->respondCreated(['status' => 'success', 'message' => 'data updated successfully', 'data' => $id], 201);
|
||||
} catch (\Throwable $e) {
|
||||
return $this->failServerError('Something went wrong: ' . $e->getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
138
app/Controllers/Organization/DepartmentController.php
Executable file → Normal file
138
app/Controllers/Organization/DepartmentController.php
Executable file → Normal file
@ -1,91 +1,75 @@
|
||||
<?php
|
||||
namespace App\Controllers\Organization;
|
||||
|
||||
use App\Traits\PatchValidationTrait;
|
||||
use App\Traits\ResponseTrait;
|
||||
<?php
|
||||
namespace App\Controllers\Organization;
|
||||
|
||||
use CodeIgniter\API\ResponseTrait;
|
||||
use App\Controllers\BaseController;
|
||||
|
||||
use App\Models\Organization\DepartmentModel;
|
||||
|
||||
|
||||
class DepartmentController extends BaseController {
|
||||
use ResponseTrait;
|
||||
use PatchValidationTrait;
|
||||
|
||||
protected $db;
|
||||
protected $model;
|
||||
|
||||
public function __construct() {
|
||||
$this->db = \Config\Database::connect();
|
||||
$this->model = new DepartmentModel();
|
||||
}
|
||||
|
||||
public function index() {
|
||||
$filter = [
|
||||
'DepartmentCode' => $this->request->getVar('DepartmentCode'),
|
||||
'DepartmentName' => $this->request->getVar('DepartmentName'),
|
||||
];
|
||||
$rows = $this->model->getDepartments($filter);
|
||||
|
||||
if (empty($rows)) {
|
||||
return $this->respond([ 'status' => 'success', 'message' => "no Data.", 'data' => [] ], 200);
|
||||
}
|
||||
|
||||
return $this->respond([ 'status' => 'success', 'message'=> "fetch success", 'data' => $rows ], 200);
|
||||
}
|
||||
|
||||
public function show($DepartmentID = null) {
|
||||
$row = $this->model->getDepartment($DepartmentID);
|
||||
if (empty($row)) {
|
||||
return $this->respond([ 'status' => 'success', 'message' => "no Data.", 'data' => null ], 200);
|
||||
}
|
||||
|
||||
return $this->respond([ 'status' => 'success', 'message'=> "fetch success", 'data' => $row ], 200);
|
||||
}
|
||||
|
||||
public function delete() {
|
||||
try {
|
||||
$input = $this->request->getJSON(true);
|
||||
$id = $input["DepartmentID"];
|
||||
if (!$id) { return $this->failValidationErrors('ID is required.'); }
|
||||
$this->model->delete($id);
|
||||
return $this->respondDeleted([ 'status' => 'success', 'message' => "{$id} deleted successfully."]);
|
||||
} catch (\Throwable $e) {
|
||||
return $this->failServerError('Something went wrong: ' . $e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
public function create() {
|
||||
$input = $this->request->getJSON(true);
|
||||
try {
|
||||
$id = $this->model->insert($input,true);
|
||||
return $this->respondCreated([ 'status' => 'success', 'message' => 'data created successfully', 'data' => $id ], 201);
|
||||
} catch (\Throwable $e) {
|
||||
return $this->failServerError('Something went wrong: ' . $e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
public function update($DepartmentID = null) {
|
||||
$input = $this->requirePatchPayload($this->request->getJSON(true));
|
||||
if ($input === null) {
|
||||
return;
|
||||
|
||||
protected $db;
|
||||
protected $model;
|
||||
|
||||
public function __construct() {
|
||||
$this->db = \Config\Database::connect();
|
||||
$this->model = new DepartmentModel();
|
||||
}
|
||||
|
||||
public function index() {
|
||||
$filter = [
|
||||
'DepartmentCode' => $this->request->getVar('DepartmentCode'),
|
||||
'DepartmentName' => $this->request->getVar('DepartmentName'),
|
||||
];
|
||||
$rows = $this->model->getDepartments($filter);
|
||||
|
||||
if (empty($rows)) {
|
||||
return $this->respond([ 'status' => 'success', 'message' => "no Data.", 'data' => [] ], 200);
|
||||
}
|
||||
|
||||
$id = $this->requirePatchId($DepartmentID, 'DepartmentID');
|
||||
if ($id === null) {
|
||||
return;
|
||||
return $this->respond([ 'status' => 'success', 'message'=> "fetch success", 'data' => $rows ], 200);
|
||||
}
|
||||
|
||||
public function show($DepartmentID = null) {
|
||||
$row = $this->model->getDepartment($DepartmentID);
|
||||
if (empty($row)) {
|
||||
return $this->respond([ 'status' => 'success', 'message' => "no Data.", 'data' => null ], 200);
|
||||
}
|
||||
|
||||
$existing = $this->model->find($id);
|
||||
if (!$existing) {
|
||||
return $this->respond([ 'status' => 'failed', 'message' => 'Department not found', 'data' => [] ], 404);
|
||||
}
|
||||
return $this->respond([ 'status' => 'success', 'message'=> "fetch success", 'data' => $row ], 200);
|
||||
}
|
||||
|
||||
$input['DepartmentID'] = $id;
|
||||
public function delete() {
|
||||
try {
|
||||
$this->model->update($id, $input);
|
||||
return $this->respond([ 'status' => 'success', 'message' => 'data updated successfully', 'data' => $id ], 200);
|
||||
$input = $this->request->getJSON(true);
|
||||
$id = $input["DepartmentID"];
|
||||
if (!$id) { return $this->failValidationErrors('ID is required.'); }
|
||||
$this->model->delete($id);
|
||||
return $this->respondDeleted([ 'status' => 'success', 'message' => "{$id} deleted successfully."]);
|
||||
} catch (\Throwable $e) {
|
||||
return $this->failServerError('Something went wrong: ' . $e->getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public function create() {
|
||||
$input = $this->request->getJSON(true);
|
||||
try {
|
||||
$id = $this->model->insert($input,true);
|
||||
return $this->respondCreated([ 'status' => 'success', 'message' => 'data created successfully', 'data' => $id ], 201);
|
||||
} catch (\Throwable $e) {
|
||||
return $this->failServerError('Something went wrong: ' . $e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
public function update() {
|
||||
$input = $this->request->getJSON(true);
|
||||
try {
|
||||
$id = $input['DepartmentID'];
|
||||
$this->model->update($id, $input);
|
||||
return $this->respondCreated([ 'status' => 'success', 'message' => 'data updated successfully', 'data' => $id ], 201);
|
||||
} catch (\Throwable $e) {
|
||||
return $this->failServerError('Something went wrong: ' . $e->getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
159
app/Controllers/Organization/DisciplineController.php
Executable file → Normal file
159
app/Controllers/Organization/DisciplineController.php
Executable file → Normal file
@ -1,78 +1,60 @@
|
||||
<?php
|
||||
namespace App\Controllers\Organization;
|
||||
|
||||
use App\Traits\PatchValidationTrait;
|
||||
use App\Traits\ResponseTrait;
|
||||
<?php
|
||||
namespace App\Controllers\Organization;
|
||||
|
||||
use CodeIgniter\API\ResponseTrait;
|
||||
use App\Controllers\BaseController;
|
||||
|
||||
use App\Models\Organization\DisciplineModel;
|
||||
|
||||
|
||||
class DisciplineController extends BaseController {
|
||||
use ResponseTrait;
|
||||
use PatchValidationTrait;
|
||||
|
||||
protected $db;
|
||||
protected $model;
|
||||
|
||||
public function __construct() {
|
||||
$this->db = \Config\Database::connect();
|
||||
$this->model = new DisciplineModel();
|
||||
}
|
||||
|
||||
public function index() {
|
||||
$filter = [
|
||||
'DisciplineCode' => $this->request->getVar('DisciplineCode'),
|
||||
'DisciplineName' => $this->request->getVar('DisciplineName'),
|
||||
];
|
||||
$rows = $this->model->getDisciplines($filter);
|
||||
|
||||
if (empty($rows)) {
|
||||
return $this->respond([ 'status' => 'success', 'message' => "no Data.", 'data' => [] ], 200);
|
||||
}
|
||||
|
||||
return $this->respond([ 'status' => 'success', 'message'=> "fetch success", 'data' => $rows ], 200);
|
||||
}
|
||||
|
||||
public function show($DisciplineID = null) {
|
||||
$row = $this->model->where('DisciplineID', $DisciplineID)->first();
|
||||
|
||||
if (empty($row)) {
|
||||
return $this->respond([ 'status' => 'success', 'message' => "no Data.", 'data' => null ], 200);
|
||||
}
|
||||
|
||||
return $this->respond([ 'status' => 'success', 'message'=> "fetch success", 'data' => $row ], 200);
|
||||
}
|
||||
|
||||
|
||||
protected $db;
|
||||
protected $model;
|
||||
|
||||
public function __construct() {
|
||||
$this->db = \Config\Database::connect();
|
||||
$this->model = new DisciplineModel();
|
||||
}
|
||||
|
||||
public function index() {
|
||||
$filter = [
|
||||
'DisciplineCode' => $this->request->getVar('DisciplineCode'),
|
||||
'DisciplineName' => $this->request->getVar('DisciplineName'),
|
||||
];
|
||||
$rows = $this->model->getDisciplines($filter);
|
||||
|
||||
if (empty($rows)) {
|
||||
return $this->respond([ 'status' => 'success', 'message' => "no Data.", 'data' => [] ], 200);
|
||||
}
|
||||
|
||||
return $this->respond([ 'status' => 'success', 'message'=> "fetch success", 'data' => $rows ], 200);
|
||||
}
|
||||
|
||||
public function show($DisciplineID = null) {
|
||||
$row = $this->model->where('DisciplineID', $DisciplineID)->first();
|
||||
|
||||
if (empty($row)) {
|
||||
return $this->respond([ 'status' => 'success', 'message' => "no Data.", 'data' => null ], 200);
|
||||
}
|
||||
|
||||
return $this->respond([ 'status' => 'success', 'message'=> "fetch success", 'data' => $row ], 200);
|
||||
}
|
||||
|
||||
public function delete() {
|
||||
try {
|
||||
$input = $this->request->getJSON(true);
|
||||
$id = $this->requirePatchId($input['DisciplineID'] ?? null, 'DisciplineID');
|
||||
if ($id === null) {
|
||||
return;
|
||||
}
|
||||
$id = $input["DisciplineID"];
|
||||
if (!$id) { return $this->failValidationErrors('ID is required.'); }
|
||||
$this->model->delete($id);
|
||||
return $this->respondDeleted([ 'status' => 'success', 'message' => "{$id} deleted successfully."]);
|
||||
} catch (\Throwable $e) {
|
||||
return $this->failServerError('Something went wrong: ' . $e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public function create() {
|
||||
$input = $this->request->getJSON(true);
|
||||
|
||||
$validation = service('validation');
|
||||
$validation->setRules([
|
||||
'DisciplineCode' => 'required|string|max_length[50]',
|
||||
'DisciplineName' => 'required|string|max_length[255]',
|
||||
'Parent' => 'permit_empty|integer',
|
||||
'SeqScr' => 'permit_empty|integer',
|
||||
'SeqRpt' => 'permit_empty|integer',
|
||||
]);
|
||||
|
||||
if (!$validation->run($input)) {
|
||||
return $this->failValidationErrors($validation->getErrors());
|
||||
}
|
||||
|
||||
try {
|
||||
$id = $this->model->insert($input,true);
|
||||
return $this->respondCreated([ 'status' => 'success', 'message' => 'data created successfully', 'data' => $id ], 201);
|
||||
@ -80,52 +62,21 @@ class DisciplineController extends BaseController {
|
||||
return $this->failServerError('Something went wrong: ' . $e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
public function update($DisciplineID = null) {
|
||||
$input = $this->requirePatchPayload($this->request->getJSON(true));
|
||||
if ($input === null) {
|
||||
return;
|
||||
}
|
||||
|
||||
$id = $this->requirePatchId($DisciplineID, 'DisciplineID');
|
||||
if ($id === null) {
|
||||
return;
|
||||
}
|
||||
|
||||
$existing = $this->model->find($id);
|
||||
if (!$existing) {
|
||||
return $this->respond([ 'status' => 'failed', 'message' => 'Discipline not found', 'data' => [] ], 404);
|
||||
}
|
||||
|
||||
$validation = service('validation');
|
||||
$validation->setRules([
|
||||
'DisciplineCode' => 'permit_empty|string|max_length[50]',
|
||||
'DisciplineName' => 'permit_empty|string|max_length[255]',
|
||||
'Parent' => 'permit_empty|integer',
|
||||
'SeqScr' => 'permit_empty|integer',
|
||||
'SeqRpt' => 'permit_empty|integer',
|
||||
]);
|
||||
|
||||
if (!$validation->run($input)) {
|
||||
return $this->failValidationErrors($validation->getErrors());
|
||||
}
|
||||
|
||||
$input['DisciplineID'] = $id;
|
||||
public function update() {
|
||||
$input = $this->request->getJSON(true);
|
||||
$id = $input['DisciplineID'];
|
||||
$this->model->update($id, $input);
|
||||
return $this->respondCreated([ 'status' => 'success', 'message' => 'data updated successfully', 'data' => $id ], 201);
|
||||
/*
|
||||
try {
|
||||
$this->model->update($id, $input);
|
||||
return $this->respond([ 'status' => 'success', 'message' => 'data updated successfully', 'data' => $id ], 200);
|
||||
$id = $input['DisciplineID'];
|
||||
$this->model->where('DisciplineID', $id)->update();
|
||||
echo $this->model->getLastQuery();
|
||||
return $this->respondCreated([ 'status' => 'success', 'message' => 'data updated successfully', 'data' => $id ], 201);
|
||||
} catch (\Throwable $e) {
|
||||
return $this->failServerError('Something went wrong: ' . $e->getMessage());
|
||||
return $this->failServerError('Something went wrong: ' . $e->getMessage() );
|
||||
}
|
||||
/*
|
||||
try {
|
||||
$id = $input['DisciplineID'];
|
||||
$this->model->where('DisciplineID', $id)->update();
|
||||
echo $this->model->getLastQuery();
|
||||
return $this->respondCreated([ 'status' => 'success', 'message' => 'data updated successfully', 'data' => $id ], 201);
|
||||
} catch (\Throwable $e) {
|
||||
return $this->failServerError('Something went wrong: ' . $e->getMessage() );
|
||||
}
|
||||
*/
|
||||
}
|
||||
}
|
||||
*/
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,124 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Controllers\Organization;
|
||||
|
||||
use App\Traits\PatchValidationTrait;
|
||||
use App\Traits\ResponseTrait;
|
||||
use App\Controllers\BaseController;
|
||||
use App\Models\Organization\HostAppModel;
|
||||
|
||||
class HostAppController extends BaseController {
|
||||
use ResponseTrait;
|
||||
use PatchValidationTrait;
|
||||
|
||||
protected $db;
|
||||
protected $model;
|
||||
|
||||
public function __construct() {
|
||||
$this->db = \Config\Database::connect();
|
||||
$this->model = new HostAppModel();
|
||||
}
|
||||
|
||||
public function index() {
|
||||
$filter = [
|
||||
'HostAppID' => $this->request->getVar('HostAppID'),
|
||||
'HostAppName' => $this->request->getVar('HostAppName'),
|
||||
];
|
||||
|
||||
$builder = $this->model->select('hostapp.*, site.SiteName')
|
||||
->join('site', 'site.SiteID = hostapp.SiteID', 'left');
|
||||
|
||||
if (!empty($filter['HostAppID'])) {
|
||||
if (!ctype_digit((string) $filter['HostAppID'])) {
|
||||
return $this->failValidationErrors('HostAppID filter must be a valid integer.');
|
||||
}
|
||||
$builder->where('hostapp.HostAppID', (int) $filter['HostAppID']);
|
||||
}
|
||||
if (!empty($filter['HostAppName'])) {
|
||||
$builder->like('hostapp.HostAppName', $filter['HostAppName'], 'both');
|
||||
}
|
||||
|
||||
$rows = $builder->findAll();
|
||||
|
||||
if (empty($rows)) {
|
||||
return $this->respond(['status' => 'success', 'message' => 'no Data.', 'data' => []], 200);
|
||||
}
|
||||
|
||||
return $this->respond(['status' => 'success', 'message' => 'fetch success', 'data' => $rows], 200);
|
||||
}
|
||||
|
||||
public function show($HostAppID = null) {
|
||||
$id = $this->requirePatchId($HostAppID, 'HostAppID');
|
||||
if ($id === null) {
|
||||
return;
|
||||
}
|
||||
|
||||
$row = $this->model->select('hostapp.*, site.SiteName')
|
||||
->join('site', 'site.SiteID = hostapp.SiteID', 'left')
|
||||
->where('hostapp.HostAppID', $id)
|
||||
->first();
|
||||
|
||||
if (empty($row)) {
|
||||
return $this->respond(['status' => 'success', 'message' => 'no Data.', 'data' => null], 200);
|
||||
}
|
||||
|
||||
return $this->respond(['status' => 'success', 'message' => 'fetch success', 'data' => $row], 200);
|
||||
}
|
||||
|
||||
public function delete() {
|
||||
try {
|
||||
$input = $this->request->getJSON(true);
|
||||
$id = $this->requirePatchId($input['HostAppID'] ?? null, 'HostAppID');
|
||||
if ($id === null) {
|
||||
return;
|
||||
}
|
||||
|
||||
$this->model->delete($id);
|
||||
return $this->respondDeleted(['status' => 'success', 'message' => "{$id} deleted successfully."]);
|
||||
} catch (\Throwable $e) {
|
||||
return $this->failServerError('Something went wrong: ' . $e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
public function create() {
|
||||
$input = $this->request->getJSON(true);
|
||||
|
||||
try {
|
||||
unset($input['HostAppID']);
|
||||
$id = $this->model->insert($input, true);
|
||||
return $this->respondCreated(['status' => 'success', 'message' => 'data created successfully', 'data' => $id], 201);
|
||||
} catch (\Throwable $e) {
|
||||
return $this->failServerError('Something went wrong: ' . $e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
public function update($HostAppID = null) {
|
||||
$input = $this->requirePatchPayload($this->request->getJSON(true));
|
||||
if ($input === null) {
|
||||
return;
|
||||
}
|
||||
|
||||
$id = $this->requirePatchId($HostAppID, 'HostAppID');
|
||||
if ($id === null) {
|
||||
return;
|
||||
}
|
||||
|
||||
$existing = $this->model->find($id);
|
||||
if (!$existing) {
|
||||
return $this->respond(['status' => 'failed', 'message' => 'HostApp not found', 'data' => []], 404);
|
||||
}
|
||||
|
||||
if (isset($input['HostAppID'])) {
|
||||
if ((string) $input['HostAppID'] !== (string) $id) {
|
||||
return $this->failValidationErrors('HostAppID in URL does not match body.');
|
||||
}
|
||||
unset($input['HostAppID']);
|
||||
}
|
||||
try {
|
||||
$this->model->update($id, $input);
|
||||
return $this->respond(['status' => 'success', 'message' => 'data updated successfully', 'data' => $id], 200);
|
||||
} catch (\Throwable $e) {
|
||||
return $this->failServerError('Something went wrong: ' . $e->getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -1,135 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Controllers\Organization;
|
||||
|
||||
use App\Traits\PatchValidationTrait;
|
||||
use App\Traits\ResponseTrait;
|
||||
use App\Controllers\BaseController;
|
||||
use App\Models\Organization\HostComParaModel;
|
||||
|
||||
class HostComParaController extends BaseController {
|
||||
use ResponseTrait;
|
||||
use PatchValidationTrait;
|
||||
|
||||
protected $db;
|
||||
protected $model;
|
||||
|
||||
public function __construct() {
|
||||
$this->db = \Config\Database::connect();
|
||||
$this->model = new HostComParaModel();
|
||||
}
|
||||
|
||||
public function index() {
|
||||
$filter = [
|
||||
'HostAppID' => $this->request->getVar('HostAppID'),
|
||||
'HostIP' => $this->request->getVar('HostIP'),
|
||||
];
|
||||
|
||||
$builder = $this->model->select('hostcompara.*, hostapp.HostAppName')
|
||||
->join('hostapp', 'hostapp.HostAppID = hostcompara.HostAppID', 'left');
|
||||
|
||||
if (!empty($filter['HostAppID'])) {
|
||||
if (!ctype_digit((string) $filter['HostAppID'])) {
|
||||
return $this->failValidationErrors('HostAppID filter must be a valid integer.');
|
||||
}
|
||||
$builder->where('hostcompara.HostAppID', (int) $filter['HostAppID']);
|
||||
}
|
||||
if (!empty($filter['HostIP'])) {
|
||||
$builder->like('hostcompara.HostIP', $filter['HostIP'], 'both');
|
||||
}
|
||||
|
||||
$rows = $builder->findAll();
|
||||
|
||||
if (empty($rows)) {
|
||||
return $this->respond(['status' => 'success', 'message' => 'no Data.', 'data' => []], 200);
|
||||
}
|
||||
|
||||
return $this->respond(['status' => 'success', 'message' => 'fetch success', 'data' => $rows], 200);
|
||||
}
|
||||
|
||||
public function show($HostAppID = null) {
|
||||
$id = $this->requirePatchId($HostAppID, 'HostAppID');
|
||||
if ($id === null) {
|
||||
return;
|
||||
}
|
||||
|
||||
$row = $this->model->select('hostcompara.*, hostapp.HostAppName')
|
||||
->join('hostapp', 'hostapp.HostAppID = hostcompara.HostAppID', 'left')
|
||||
->where('hostcompara.HostAppID', $id)
|
||||
->first();
|
||||
|
||||
if (empty($row)) {
|
||||
return $this->respond(['status' => 'success', 'message' => 'no Data.', 'data' => null], 200);
|
||||
}
|
||||
|
||||
return $this->respond(['status' => 'success', 'message' => 'fetch success', 'data' => $row], 200);
|
||||
}
|
||||
|
||||
public function delete() {
|
||||
try {
|
||||
$input = $this->request->getJSON(true);
|
||||
$id = $this->requirePatchId($input['HostAppID'] ?? null, 'HostAppID');
|
||||
if ($id === null) {
|
||||
return;
|
||||
}
|
||||
|
||||
$this->model->delete($id);
|
||||
return $this->respondDeleted(['status' => 'success', 'message' => "{$id} deleted successfully."]);
|
||||
} catch (\Throwable $e) {
|
||||
return $this->failServerError('Something went wrong: ' . $e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
public function create() {
|
||||
$input = $this->request->getJSON(true);
|
||||
|
||||
try {
|
||||
$hostAppId = $input['HostAppID'] ?? null;
|
||||
if ($hostAppId === null) {
|
||||
return $this->failValidationErrors('HostAppID is required.');
|
||||
}
|
||||
|
||||
if (!ctype_digit((string) $hostAppId)) {
|
||||
return $this->failValidationErrors('HostAppID must be a valid integer.');
|
||||
}
|
||||
|
||||
$input['HostAppID'] = (int) $hostAppId;
|
||||
|
||||
$id = $this->model->insert($input, true);
|
||||
return $this->respondCreated(['status' => 'success', 'message' => 'data created successfully', 'data' => $id], 201);
|
||||
} catch (\Throwable $e) {
|
||||
return $this->failServerError('Something went wrong: ' . $e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
public function update($HostAppID = null) {
|
||||
$input = $this->requirePatchPayload($this->request->getJSON(true));
|
||||
if ($input === null) {
|
||||
return;
|
||||
}
|
||||
|
||||
$id = $this->requirePatchId($HostAppID, 'HostAppID');
|
||||
if ($id === null) {
|
||||
return;
|
||||
}
|
||||
|
||||
$existing = $this->model->find($id);
|
||||
if (!$existing) {
|
||||
return $this->respond(['status' => 'failed', 'message' => 'HostComPara not found', 'data' => []], 404);
|
||||
}
|
||||
|
||||
if (isset($input['HostAppID'])) {
|
||||
if ((string) $input['HostAppID'] !== (string) $id) {
|
||||
return $this->failValidationErrors('HostAppID in URL does not match body.');
|
||||
}
|
||||
unset($input['HostAppID']);
|
||||
}
|
||||
|
||||
try {
|
||||
$this->model->update($id, $input);
|
||||
return $this->respond(['status' => 'success', 'message' => 'data updated successfully', 'data' => $id], 200);
|
||||
} catch (\Throwable $e) {
|
||||
return $this->failServerError('Something went wrong: ' . $e->getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
164
app/Controllers/Organization/SiteController.php
Executable file → Normal file
164
app/Controllers/Organization/SiteController.php
Executable file → Normal file
@ -1,114 +1,76 @@
|
||||
<?php
|
||||
namespace App\Controllers\Organization;
|
||||
|
||||
use App\Traits\PatchValidationTrait;
|
||||
use App\Traits\ResponseTrait;
|
||||
<?php
|
||||
namespace App\Controllers\Organization;
|
||||
|
||||
use CodeIgniter\API\ResponseTrait;
|
||||
use App\Controllers\BaseController;
|
||||
|
||||
use App\Models\Organization\SiteModel;
|
||||
|
||||
|
||||
class SiteController extends BaseController {
|
||||
use ResponseTrait;
|
||||
use PatchValidationTrait;
|
||||
|
||||
protected $db;
|
||||
protected $model;
|
||||
|
||||
public function __construct() {
|
||||
$this->db = \Config\Database::connect();
|
||||
$this->model = new SiteModel();
|
||||
}
|
||||
|
||||
public function index() {
|
||||
$filter = [
|
||||
'SiteCode' => $this->request->getVar('SiteCode'),
|
||||
'SiteName' => $this->request->getVar('SiteName'),
|
||||
];
|
||||
$rows = $this->model->getSites($filter);
|
||||
if (empty($rows)) {
|
||||
return $this->respond([ 'status' => 'success', 'message' => "no Data.", 'data' => [] ], 200);
|
||||
}
|
||||
return $this->respond([ 'status' => 'success', 'message'=> "fetch success", 'data' => $rows ], 200);
|
||||
}
|
||||
|
||||
|
||||
|
||||
public function show($SiteID = null) {
|
||||
//$rows = $this->model->where('SiteID', $SiteID)->findAll();
|
||||
$row = $this->model->getSite($SiteID);
|
||||
|
||||
if (empty($row)) {
|
||||
return $this->respond([ 'status' => 'success', 'message' => "no Data.", 'data' => null ], 200);
|
||||
}
|
||||
|
||||
return $this->respond([ 'status' => 'success', 'message'=> "fetch success", 'data' => $row ], 200);
|
||||
}
|
||||
|
||||
public function delete() {
|
||||
try {
|
||||
$input = $this->request->getJSON(true);
|
||||
$id = $input["SiteID"];
|
||||
if (!$id) { return $this->failValidationErrors('ID is required.'); }
|
||||
$this->model->delete($id);
|
||||
return $this->respondDeleted([ 'status' => 'success', 'message' => "{$id} deleted successfully."]);
|
||||
} catch (\Throwable $e) {
|
||||
return $this->failServerError('Something went wrong: ' . $e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
public function create() {
|
||||
$input = $this->request->getJSON(true);
|
||||
|
||||
$validation = service('validation');
|
||||
$validation->setRules([
|
||||
'SiteCode' => 'required|regex_match[/^[A-Z0-9]{2,6}$/]',
|
||||
'SiteName' => 'required',
|
||||
]);
|
||||
|
||||
if (!$validation->run($input)) {
|
||||
return $this->failValidationErrors($validation->getErrors());
|
||||
}
|
||||
|
||||
try {
|
||||
$id = $this->model->insert($input,true);
|
||||
return $this->respondCreated([ 'status' => 'success', 'message' => 'data created successfully', 'data' => $id ], 201);
|
||||
} catch (\Throwable $e) {
|
||||
return $this->failServerError('Something went wrong: ' . $e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
public function update($SiteID = null) {
|
||||
$input = $this->requirePatchPayload($this->request->getJSON(true));
|
||||
if ($input === null) {
|
||||
return;
|
||||
|
||||
protected $db;
|
||||
protected $model;
|
||||
|
||||
public function __construct() {
|
||||
$this->db = \Config\Database::connect();
|
||||
$this->model = new SiteModel();
|
||||
}
|
||||
|
||||
public function index() {
|
||||
$filter = [
|
||||
'SiteCode' => $this->request->getVar('SiteCode'),
|
||||
'SiteName' => $this->request->getVar('SiteName'),
|
||||
];
|
||||
$rows = $this->model->getSites($filter);
|
||||
if (empty($rows)) {
|
||||
return $this->respond([ 'status' => 'success', 'message' => "no Data.", 'data' => [] ], 200);
|
||||
}
|
||||
return $this->respond([ 'status' => 'success', 'message'=> "fetch success", 'data' => $rows ], 200);
|
||||
}
|
||||
|
||||
|
||||
|
||||
public function show($SiteID = null) {
|
||||
//$rows = $this->model->where('SiteID', $SiteID)->findAll();
|
||||
$row = $this->model->getSite($SiteID);
|
||||
|
||||
if (empty($row)) {
|
||||
return $this->respond([ 'status' => 'success', 'message' => "no Data.", 'data' => null ], 200);
|
||||
}
|
||||
|
||||
$id = $this->requirePatchId($SiteID, 'SiteID');
|
||||
if ($id === null) {
|
||||
return;
|
||||
}
|
||||
return $this->respond([ 'status' => 'success', 'message'=> "fetch success", 'data' => $row ], 200);
|
||||
}
|
||||
|
||||
$existing = $this->model->find($id);
|
||||
if (!$existing) {
|
||||
return $this->respond([ 'status' => 'failed', 'message' => 'Site not found', 'data' => [] ], 404);
|
||||
}
|
||||
|
||||
$input['SiteID'] = $id;
|
||||
|
||||
if (!empty($input['SiteCode'])) {
|
||||
$validation = service('validation');
|
||||
$validation->setRules([
|
||||
'SiteCode' => 'regex_match[/^[A-Z0-9]{2,6}$/]',
|
||||
]);
|
||||
|
||||
if (!$validation->run($input)) {
|
||||
return $this->failValidationErrors($validation->getErrors());
|
||||
}
|
||||
}
|
||||
|
||||
public function delete() {
|
||||
try {
|
||||
$input = $this->request->getJSON(true);
|
||||
$id = $input["SiteID"];
|
||||
if (!$id) { return $this->failValidationErrors('ID is required.'); }
|
||||
$this->model->delete($id);
|
||||
return $this->respondDeleted([ 'status' => 'success', 'message' => "{$id} deleted successfully."]);
|
||||
} catch (\Throwable $e) {
|
||||
return $this->failServerError('Something went wrong: ' . $e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
public function create() {
|
||||
$input = $this->request->getJSON(true);
|
||||
try {
|
||||
$id = $this->model->insert($input,true);
|
||||
return $this->respondCreated([ 'status' => 'success', 'message' => 'data created successfully', 'data' => $id ], 201);
|
||||
} catch (\Throwable $e) {
|
||||
return $this->failServerError('Something went wrong: ' . $e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
public function update() {
|
||||
$input = $this->request->getJSON(true);
|
||||
try {
|
||||
$id = $input['SiteID'];
|
||||
if (!$id) { return $this->failValidationErrors('ID is required.'); }
|
||||
$this->model->update($id, $input);
|
||||
return $this->respond([ 'status' => 'success', 'message' => 'data updated successfully', 'data' => $id ], 200);
|
||||
return $this->respondCreated([ 'status' => 'success', 'message' => 'data updated successfully', 'data' => $id ], 201);
|
||||
} catch (\Throwable $e) {
|
||||
return $this->failServerError('Something went wrong: ' . $e->getMessage());
|
||||
}
|
||||
|
||||
134
app/Controllers/Organization/WorkstationController.php
Executable file → Normal file
134
app/Controllers/Organization/WorkstationController.php
Executable file → Normal file
@ -1,90 +1,74 @@
|
||||
<?php
|
||||
namespace App\Controllers\Organization;
|
||||
|
||||
use App\Traits\PatchValidationTrait;
|
||||
use App\Traits\ResponseTrait;
|
||||
<?php
|
||||
namespace App\Controllers\Organization;
|
||||
|
||||
use CodeIgniter\API\ResponseTrait;
|
||||
use App\Controllers\BaseController;
|
||||
|
||||
use App\Models\Organization\WorkstationModel;
|
||||
|
||||
|
||||
class WorkstationController extends BaseController {
|
||||
use ResponseTrait;
|
||||
use PatchValidationTrait;
|
||||
|
||||
protected $db;
|
||||
protected $model;
|
||||
|
||||
public function __construct() {
|
||||
$this->db = \Config\Database::connect();
|
||||
$this->model = new WorkstationModel();
|
||||
}
|
||||
|
||||
public function index() {
|
||||
$filter = [
|
||||
'WorkstationCode' => $this->request->getVar('WorkstationCode'),
|
||||
'WorkstationName' => $this->request->getVar('WorkstationName'),
|
||||
];
|
||||
$rows = $this->model->getWorkstations($filter);
|
||||
|
||||
if (empty($rows)) {
|
||||
return $this->respond([ 'status' => 'success', 'message' => "no Data.", 'data' => [] ], 200);
|
||||
}
|
||||
|
||||
return $this->respond([ 'status' => 'success', 'message'=> "fetch success", 'data' => $rows ], 200);
|
||||
}
|
||||
|
||||
public function show($WorkstationID = null) {
|
||||
$row = $this->model->getWorkstation($WorkstationID);
|
||||
|
||||
if (empty($row)) {
|
||||
return $this->respond([ 'status' => 'success', 'message' => "no Data.", 'data' => null ], 200);
|
||||
}
|
||||
|
||||
return $this->respond([ 'status' => 'success', 'message'=> "fetch success", 'data' => $row ], 200);
|
||||
}
|
||||
|
||||
public function delete() {
|
||||
try {
|
||||
$input = $this->request->getJSON(true);
|
||||
$id = $input["WorkstationID"];
|
||||
if (!$id) { return $this->failValidationErrors('ID is required.'); }
|
||||
$this->model->delete($id);
|
||||
return $this->respondDeleted([ 'status' => 'success', 'message' => "{$id} deleted successfully."]);
|
||||
} catch (\Throwable $e) {
|
||||
return $this->failServerError('Something went wrong: ' . $e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
public function create() {
|
||||
$input = $this->request->getJSON(true);
|
||||
try {
|
||||
$id = $this->model->insert($input,true);
|
||||
return $this->respondCreated([ 'status' => 'success', 'message' => 'data created successfully', 'data' => $id ], 201);
|
||||
} catch (\Throwable $e) {
|
||||
return $this->failServerError('Something went wrong: ' . $e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
public function update($WorkstationID = null) {
|
||||
$input = $this->requirePatchPayload($this->request->getJSON(true));
|
||||
if ($input === null) {
|
||||
return;
|
||||
|
||||
protected $db;
|
||||
protected $model;
|
||||
|
||||
public function __construct() {
|
||||
$this->db = \Config\Database::connect();
|
||||
$this->model = new WorkstationModel();
|
||||
}
|
||||
|
||||
public function index() {
|
||||
$filter = [
|
||||
'WorkstationCode' => $this->request->getVar('WorkstationCode'),
|
||||
'WorkstationName' => $this->request->getVar('WorkstationName'),
|
||||
];
|
||||
$rows = $this->model->getWorkstations($filter);
|
||||
|
||||
if (empty($rows)) {
|
||||
return $this->respond([ 'status' => 'success', 'message' => "no Data.", 'data' => [] ], 200);
|
||||
}
|
||||
|
||||
$id = $this->requirePatchId($WorkstationID, 'WorkstationID');
|
||||
if ($id === null) {
|
||||
return;
|
||||
return $this->respond([ 'status' => 'success', 'message'=> "fetch success", 'data' => $rows ], 200);
|
||||
}
|
||||
|
||||
public function show($WorkstationID = null) {
|
||||
$row = $this->model->getWorkstation($WorkstationID);
|
||||
|
||||
if (empty($row)) {
|
||||
return $this->respond([ 'status' => 'success', 'message' => "no Data.", 'data' => null ], 200);
|
||||
}
|
||||
|
||||
$existing = $this->model->find($id);
|
||||
if (!$existing) {
|
||||
return $this->respond([ 'status' => 'failed', 'message' => 'Workstation not found', 'data' => [] ], 404);
|
||||
}
|
||||
return $this->respond([ 'status' => 'success', 'message'=> "fetch success", 'data' => $row ], 200);
|
||||
}
|
||||
|
||||
$input['WorkstationID'] = $id;
|
||||
public function delete() {
|
||||
try {
|
||||
$input = $this->request->getJSON(true);
|
||||
$id = $input["WorkstationID"];
|
||||
if (!$id) { return $this->failValidationErrors('ID is required.'); }
|
||||
$this->model->delete($id);
|
||||
return $this->respondDeleted([ 'status' => 'success', 'message' => "{$id} deleted successfully."]);
|
||||
} catch (\Throwable $e) {
|
||||
return $this->failServerError('Something went wrong: ' . $e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
public function create() {
|
||||
$input = $this->request->getJSON(true);
|
||||
try {
|
||||
$id = $this->model->insert($input,true);
|
||||
return $this->respondCreated([ 'status' => 'success', 'message' => 'data created successfully', 'data' => $id ], 201);
|
||||
} catch (\Throwable $e) {
|
||||
return $this->failServerError('Something went wrong: ' . $e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
public function update() {
|
||||
$input = $this->request->getJSON(true);
|
||||
try {
|
||||
$id = $input['WorkstationID'];
|
||||
$this->model->update($id, $input);
|
||||
return $this->respond([ 'status' => 'success', 'message' => 'data updated successfully', 'data' => $id ], 200);
|
||||
return $this->respondCreated([ 'status' => 'success', 'message' => 'data updated successfully', 'data' => $id ], 201);
|
||||
} catch (\Throwable $e) {
|
||||
return $this->failServerError('Something went wrong: ' . $e->getMessage());
|
||||
}
|
||||
|
||||
192
app/Controllers/PagesController.php
Executable file → Normal file
192
app/Controllers/PagesController.php
Executable file → Normal file
@ -1,14 +1,178 @@
|
||||
<?php
|
||||
|
||||
namespace App\Controllers;
|
||||
|
||||
/**
|
||||
* PagesController - Serves view pages
|
||||
*
|
||||
* This controller only returns views. No business logic.
|
||||
* All data is fetched via API calls from the frontend.
|
||||
*/
|
||||
class PagesController extends BaseController
|
||||
{
|
||||
// Add page methods here as needed
|
||||
}
|
||||
<?php
|
||||
|
||||
namespace App\Controllers;
|
||||
|
||||
/**
|
||||
* PagesController - Serves view pages
|
||||
*
|
||||
* This controller only returns views. No business logic.
|
||||
* All data is fetched via API calls from the frontend.
|
||||
*/
|
||||
class PagesController extends BaseController
|
||||
{
|
||||
/**
|
||||
* Dashboard page
|
||||
*/
|
||||
public function dashboard()
|
||||
{
|
||||
return view('v2/dashboard/dashboard_index', [
|
||||
'pageTitle' => 'Dashboard',
|
||||
'activePage' => 'dashboard'
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Patients page
|
||||
*/
|
||||
public function patients()
|
||||
{
|
||||
return view('v2/patients/patients_index', [
|
||||
'pageTitle' => 'Patients',
|
||||
'activePage' => 'patients'
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Lab Requests page
|
||||
*/
|
||||
public function requests()
|
||||
{
|
||||
return view('v2/requests/requests_index', [
|
||||
'pageTitle' => 'Lab Requests',
|
||||
'activePage' => 'requests'
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Settings page
|
||||
*/
|
||||
public function settings()
|
||||
{
|
||||
return view('v2/settings/settings_index', [
|
||||
'pageTitle' => 'Settings',
|
||||
'activePage' => 'settings'
|
||||
]);
|
||||
}
|
||||
|
||||
// ========================================
|
||||
// Master Data - Organization
|
||||
// ========================================
|
||||
|
||||
/**
|
||||
* Master Data - Organization Accounts
|
||||
*/
|
||||
public function masterOrgAccounts()
|
||||
{
|
||||
return view('v2/master/organization/accounts_index', [
|
||||
'pageTitle' => 'Organization Accounts',
|
||||
'activePage' => 'master-org-accounts'
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Master Data - Organization Sites
|
||||
*/
|
||||
public function masterOrgSites()
|
||||
{
|
||||
return view('v2/master/organization/sites_index', [
|
||||
'pageTitle' => 'Organization Sites',
|
||||
'activePage' => 'master-org-sites'
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Master Data - Organization Disciplines
|
||||
*/
|
||||
public function masterOrgDisciplines()
|
||||
{
|
||||
return view('v2/master/organization/disciplines_index', [
|
||||
'pageTitle' => 'Disciplines',
|
||||
'activePage' => 'master-org-disciplines'
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Master Data - Organization Departments
|
||||
*/
|
||||
public function masterOrgDepartments()
|
||||
{
|
||||
return view('v2/master/organization/departments_index', [
|
||||
'pageTitle' => 'Departments',
|
||||
'activePage' => 'master-org-departments'
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Master Data - Organization Workstations
|
||||
*/
|
||||
public function masterOrgWorkstations()
|
||||
{
|
||||
return view('v2/master/organization/workstations_index', [
|
||||
'pageTitle' => 'Workstations',
|
||||
'activePage' => 'master-org-workstations'
|
||||
]);
|
||||
}
|
||||
|
||||
// ========================================
|
||||
// Master Data - Specimen
|
||||
// ========================================
|
||||
|
||||
/**
|
||||
* Master Data - Specimen Containers
|
||||
*/
|
||||
public function masterSpecimenContainers()
|
||||
{
|
||||
return view('v2/master/specimen/containers_index', [
|
||||
'pageTitle' => 'Container Definitions',
|
||||
'activePage' => 'master-specimen-containers'
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Master Data - Specimen Preparations
|
||||
*/
|
||||
public function masterSpecimenPreparations()
|
||||
{
|
||||
return view('v2/master/specimen/preparations_index', [
|
||||
'pageTitle' => 'Specimen Preparations',
|
||||
'activePage' => 'master-specimen-preparations'
|
||||
]);
|
||||
}
|
||||
|
||||
// ========================================
|
||||
// Master Data - Tests & ValueSets
|
||||
// ========================================
|
||||
|
||||
/**
|
||||
* Master Data - Lab Tests
|
||||
*/
|
||||
public function masterTests()
|
||||
{
|
||||
return view('v2/master/tests/tests_index', [
|
||||
'pageTitle' => 'Lab Tests',
|
||||
'activePage' => 'master-tests'
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Master Data - Value Sets
|
||||
*/
|
||||
public function masterValueSets()
|
||||
{
|
||||
return view('v2/master/valuesets/valuesets_index', [
|
||||
'pageTitle' => 'Value Sets',
|
||||
'activePage' => 'master-valuesets'
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Login page
|
||||
*/
|
||||
public function login()
|
||||
{
|
||||
return view('v2/auth/login', [
|
||||
'pageTitle' => 'Login',
|
||||
'activePage' => ''
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
348
app/Controllers/PatVisitController.php
Executable file → Normal file
348
app/Controllers/PatVisitController.php
Executable file → Normal file
@ -1,315 +1,85 @@
|
||||
<?php
|
||||
namespace App\Controllers;
|
||||
|
||||
use App\Traits\PatchValidationTrait;
|
||||
use App\Traits\ResponseTrait;
|
||||
use App\Controllers\BaseController;
|
||||
use App\Models\PatVisit\PatVisitModel;
|
||||
use App\Models\PatVisit\PatVisitADTModel;
|
||||
use App\Models\Patient\PatientModel;
|
||||
|
||||
<?php
|
||||
namespace App\Controllers;
|
||||
|
||||
use CodeIgniter\API\ResponseTrait;
|
||||
use App\Controllers\BaseController;
|
||||
use App\Models\PatVisit\PatVisitModel;
|
||||
use App\Models\PatVisit\PatVisitADTModel;
|
||||
|
||||
class PatVisitController extends BaseController {
|
||||
use ResponseTrait;
|
||||
use PatchValidationTrait;
|
||||
|
||||
protected $model;
|
||||
|
||||
public function __construct() {
|
||||
$this->model = new PatVisitModel();
|
||||
}
|
||||
|
||||
public function index() {
|
||||
try {
|
||||
$InternalPID = $this->request->getVar('InternalPID');
|
||||
$PVID = $this->request->getVar('PVID');
|
||||
$PatientID = $this->request->getVar('PatientID');
|
||||
$PatientName = $this->request->getVar('PatientName');
|
||||
$CreateDateFrom = $this->request->getVar('CreateDateFrom');
|
||||
$CreateDateTo = $this->request->getVar('CreateDateTo');
|
||||
|
||||
$builder = $this->model->select('patvisit.*, patient.NameFirst, patient.NameLast, patient.PatientID, location.LocFull as LastLocation')
|
||||
->join('patient', 'patient.InternalPID=patvisit.InternalPID', 'left')
|
||||
->join('(SELECT a1.*
|
||||
FROM patvisitadt a1
|
||||
INNER JOIN (
|
||||
SELECT InternalPVID, MAX(PVADTID) AS MaxID
|
||||
FROM patvisitadt
|
||||
GROUP BY InternalPVID
|
||||
) a2 ON a1.InternalPVID = a2.InternalPVID AND a1.PVADTID = a2.MaxID
|
||||
) AS latest_patvisitadt', 'latest_patvisitadt.InternalPVID = patvisit.InternalPVID', 'left')
|
||||
->join('location', 'location.LocationID = latest_patvisitadt.LocationID', 'left');
|
||||
|
||||
if ($InternalPID) {
|
||||
$builder->where('patvisit.InternalPID', $InternalPID);
|
||||
}
|
||||
if ($PVID) {
|
||||
$builder->like('patvisit.PVID', $PVID, 'both');
|
||||
}
|
||||
if ($PatientID) {
|
||||
$builder->like('patient.PatientID', $PatientID, 'both');
|
||||
}
|
||||
if ($PatientName) {
|
||||
$builder->groupStart()
|
||||
->like('patient.NameFirst', $PatientName, 'both')
|
||||
->orLike('patient.NameLast', $PatientName, 'both')
|
||||
->groupEnd();
|
||||
}
|
||||
if ($CreateDateFrom) {
|
||||
$builder->where('patvisit.CreateDate >=', $CreateDateFrom);
|
||||
}
|
||||
if ($CreateDateTo) {
|
||||
$builder->where('patvisit.CreateDate <=', $CreateDateTo);
|
||||
}
|
||||
|
||||
$rows = $builder->orderBy('patvisit.CreateDate', 'DESC')->findAll();
|
||||
|
||||
if (empty($rows)) {
|
||||
return $this->respond(['status' => 'success', 'message' => 'data not found', 'data' => []], 200);
|
||||
}
|
||||
|
||||
return $this->respond(['status' => 'success', 'message' => 'data found', 'data' => $rows], 200);
|
||||
} catch (\Exception $e) {
|
||||
return $this->failServerError('Something went wrong: ' . $e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
public function show($PVID = null) {
|
||||
try {
|
||||
$row = $this->model->show($PVID);
|
||||
if (empty($row)) {
|
||||
return $this->respond([ 'status' => 'success', 'message'=> "data not found", 'data' => [] ], 200);
|
||||
}
|
||||
return $this->respond([ 'status' => 'success', 'message'=> "data found", 'data' => $row ], 200);
|
||||
} catch (\Exception $e) {
|
||||
return $this->failServerError('Something went wrong '.$e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
public function showByPatient($InternalPID = null) {
|
||||
try {
|
||||
$rows = $this->model->showByPatient($InternalPID);
|
||||
if($rows == []) { $message = "data not found"; }
|
||||
else { $message = "data found"; }
|
||||
return $this->respond(['status' => 'success', 'message'=> $message, 'data' => $rows ], 200);
|
||||
} catch (\Exception $e) {
|
||||
return $this->failServerError('Something went wrong '.$e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
public function update($InternalPVID = null) {
|
||||
$input = $this->requirePatchPayload($this->request->getJSON(true));
|
||||
if ($input === null) {
|
||||
return;
|
||||
}
|
||||
|
||||
protected $model;
|
||||
|
||||
$id = $this->requirePatchId($InternalPVID, 'InternalPVID');
|
||||
if ($id === null) {
|
||||
return;
|
||||
}
|
||||
public function __construct() {
|
||||
$this->model = new PatVisitModel();
|
||||
}
|
||||
|
||||
$visit = $this->model->find($id);
|
||||
if (!$visit) {
|
||||
return $this->respond(['status' => 'failed', 'message' => 'Visit not found', 'data' => []], 404);
|
||||
}
|
||||
$input['InternalPVID'] = $id;
|
||||
public function show($PVID = null) {
|
||||
try {
|
||||
$row = $this->model->show($PVID);
|
||||
if (empty($row)) {
|
||||
return $this->respond([ 'status' => 'success', 'message'=> "data not found", 'data' => null ], 200);
|
||||
}
|
||||
return $this->respond([ 'status' => 'success', 'message'=> "data found", 'data' => $row ], 200);
|
||||
} catch (\Exception $e) {
|
||||
return $this->failServerError('Something went wrong '.$e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
public function showByPatient($InternalPID = null) {
|
||||
try {
|
||||
$rows = $this->model->showByPatient($InternalPID);
|
||||
if($rows == []) { $message = "data not found"; }
|
||||
else { $message = "data found"; }
|
||||
return $this->respond(['status' => 'success', 'message'=> $message, 'data' => $rows ], 200);
|
||||
} catch (\Exception $e) {
|
||||
return $this->failServerError('Something went wrong '.$e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
public function update() {
|
||||
$input = $this->request->getJSON(true);
|
||||
try {
|
||||
if (!$input["InternalPVID"] || !is_numeric($input["InternalPVID"])) { return $this->respond(['status' => 'error', 'message' => 'Invalid or missing ID'], 400); }
|
||||
$data = $this->model->updatePatVisit($input);
|
||||
return $this->respond(['status' => 'success', 'message' => 'Data updated successfully', 'data' => $data], 200);
|
||||
return $this->respond(['status' => 'success', 'message' => 'Data updated successfully', 'data' => $data], 201);
|
||||
} catch (\Exception $e) {
|
||||
return $this->failServerError('Something went wrong: ' . $e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
public function create() {
|
||||
$input = $this->request->getJSON(true);
|
||||
try {
|
||||
// Validate required fields
|
||||
if (!isset($input['InternalPID']) || !is_numeric($input['InternalPID'])) {
|
||||
return $this->respond(['status' => 'error', 'message' => 'InternalPID is required and must be numeric'], 400);
|
||||
}
|
||||
|
||||
// Check if patient exists
|
||||
$patientModel = new PatientModel();
|
||||
$patient = $patientModel->find($input['InternalPID']);
|
||||
if (!$patient) {
|
||||
return $this->respond(['status' => 'error', 'message' => 'Patient not found'], 404);
|
||||
}
|
||||
|
||||
$data = $this->model->createPatVisit($input);
|
||||
return $this->respond(['status' => 'success', 'message' => 'Data created successfully', 'data' => $data], 201);
|
||||
} catch (\Exception $e) {
|
||||
return $this->failServerError('Something went wrong: ' . $e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
public function delete() {
|
||||
$input = $this->request->getJSON(true);
|
||||
try {
|
||||
if (!isset($input["InternalPVID"]) || !is_numeric($input["InternalPVID"])) {
|
||||
return $this->respond(['status' => 'error', 'message' => 'Invalid or missing ID'], 400);
|
||||
}
|
||||
|
||||
// Check if visit exists
|
||||
$visit = $this->model->find($input["InternalPVID"]);
|
||||
if (!$visit) {
|
||||
return $this->respond(['status' => 'error', 'message' => 'Visit not found'], 404);
|
||||
}
|
||||
|
||||
// Soft delete using EndDate (configured in model)
|
||||
$result = $this->model->delete($input["InternalPVID"]);
|
||||
|
||||
if ($result) {
|
||||
return $this->respond(['status' => 'success', 'message' => 'Data deleted successfully'], 200);
|
||||
} else {
|
||||
return $this->respond(['status' => 'error', 'message' => 'Failed to delete data'], 500);
|
||||
}
|
||||
} catch (\Exception $e) {
|
||||
return $this->failServerError('Something went wrong: ' . $e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public function create() {
|
||||
$input = $this->request->getJSON(true);
|
||||
try {
|
||||
$data = $this->model->createPatVisit($input);
|
||||
return $this->respond(['status' => 'success', 'message' => 'Data created successfully', 'data' => $data], 201);
|
||||
} catch (\Exception $e) {
|
||||
return $this->failServerError('Something went wrong: ' . $e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
public function createADT() {
|
||||
$input = $this->request->getJSON(true);
|
||||
$internalPVID = $input['InternalPVID'] ?? $input['InternalPID'] ?? null;
|
||||
if (!$internalPVID || !is_numeric($internalPVID)) {
|
||||
return $this->respond(['status' => 'error', 'message' => 'Invalid or missing InternalPVID'], 400);
|
||||
}
|
||||
$input['InternalPVID'] = (int) $internalPVID;
|
||||
if (!$input["InternalPVID"] || !is_numeric($input["InternalPVID"])) { return $this->respond(['status' => 'error', 'message' => 'Invalid or missing ID'], 400); }
|
||||
$modelPVA = new PatVisitADTModel();
|
||||
try {
|
||||
$data = $modelPVA->insert($input, true);
|
||||
$record = $modelPVA->find($data);
|
||||
if ($record) {
|
||||
$record['ADTID'] = $record['PVADTID'];
|
||||
}
|
||||
return $this->respond(['status' => 'success', 'message' => 'Data created successfully', 'data' => $record ?? ['ADTID' => $data]], 201);
|
||||
return $this->respond(['status' => 'success', 'message' => 'Data created successfully', 'data' => $data], 201);
|
||||
} catch (\Exception $e) {
|
||||
return $this->failServerError('Something went wrong: ' . $e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
public function updateADT($PVADTID = null) {
|
||||
$input = $this->requirePatchPayload($this->request->getJSON(true));
|
||||
if ($input === null) {
|
||||
return;
|
||||
}
|
||||
|
||||
$id = $this->requirePatchId($PVADTID, 'PVADTID');
|
||||
if ($id === null) {
|
||||
return;
|
||||
}
|
||||
|
||||
public function updateADT() {
|
||||
$input = $this->request->getJSON(true);
|
||||
if (!$input["PVADTID"] || !is_numeric($input["PVADTID"])) { return $this->respond(['status' => 'error', 'message' => 'Invalid or missing ID'], 400); }
|
||||
$modelPVA = new PatVisitADTModel();
|
||||
$adt = $modelPVA->find($id);
|
||||
if (!$adt) {
|
||||
return $this->respond(['status' => 'failed', 'message' => 'ADT record not found', 'data' => []], 404);
|
||||
}
|
||||
|
||||
$internalPVID = null;
|
||||
if (array_key_exists('InternalPVID', $adt) && !empty($adt['InternalPVID'])) {
|
||||
$internalPVID = $adt['InternalPVID'];
|
||||
} elseif (array_key_exists('InternalPID', $adt) && !empty($adt['InternalPID'])) {
|
||||
$internalPVID = $adt['InternalPID'];
|
||||
}
|
||||
|
||||
if ($internalPVID !== null && (!array_key_exists('InternalPVID', $input) || $input['InternalPVID'] === null || $input['InternalPVID'] === '')) {
|
||||
$input['InternalPVID'] = $internalPVID;
|
||||
}
|
||||
|
||||
$input['PVADTID'] = $id;
|
||||
try {
|
||||
$data = $modelPVA->update($id, $input);
|
||||
return $this->respond(['status' => 'success', 'message' => 'Data updated successfully', 'data' => $data], 200);
|
||||
$data = $modelPVA->update($input['PVADTID'], $input);
|
||||
return $this->respond(['status' => 'success', 'message' => 'Data updated successfully', 'data' => $data], 201);
|
||||
} catch (\Exception $e) {
|
||||
return $this->failServerError('Something went wrong: ' . $e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
public function getADTByVisit($InternalPVID = null) {
|
||||
try {
|
||||
if (!$InternalPVID || !is_numeric($InternalPVID)) {
|
||||
return $this->respond(['status' => 'error', 'message' => 'Invalid or missing InternalPVID'], 400);
|
||||
}
|
||||
|
||||
$modelPVA = new PatVisitADTModel();
|
||||
$rows = $modelPVA->select('patvisitadt.*, location.LocFull as LocationName,
|
||||
attDoc.NameFirst as AttDocFirstName, attDoc.NameLast as AttDocLastName,
|
||||
refDoc.NameFirst as RefDocFirstName, refDoc.NameLast as RefDocLastName,
|
||||
admDoc.NameFirst as AdmDocFirstName, admDoc.NameLast as AdmDocLastName,
|
||||
cnsDoc.NameFirst as CnsDocFirstName, cnsDoc.NameLast as CnsDocLastName')
|
||||
->join('location', 'location.LocationID = patvisitadt.LocationID', 'left')
|
||||
->join('contact attDoc', 'attDoc.ContactID = patvisitadt.AttDoc', 'left')
|
||||
->join('contact refDoc', 'refDoc.ContactID = patvisitadt.RefDoc', 'left')
|
||||
->join('contact admDoc', 'admDoc.ContactID = patvisitadt.AdmDoc', 'left')
|
||||
->join('contact cnsDoc', 'cnsDoc.ContactID = patvisitadt.CnsDoc', 'left')
|
||||
->where('patvisitadt.InternalPVID', $InternalPVID)
|
||||
->where('patvisitadt.DelDate', null)
|
||||
->orderBy('patvisitadt.CreateDate', 'ASC')
|
||||
->findAll();
|
||||
|
||||
if (empty($rows)) {
|
||||
return $this->respond(['status' => 'success', 'message' => 'No ADT history found', 'data' => []], 200);
|
||||
}
|
||||
|
||||
return $this->respond(['status' => 'success', 'message' => 'ADT history retrieved', 'data' => $rows], 200);
|
||||
} catch (\Exception $e) {
|
||||
return $this->failServerError('Something went wrong: ' . $e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
public function showADT($PVADTID = null) {
|
||||
try {
|
||||
if (!$PVADTID || !is_numeric($PVADTID)) {
|
||||
return $this->respond(['status' => 'error', 'message' => 'Invalid or missing PVADTID'], 400);
|
||||
}
|
||||
|
||||
$modelPVA = new PatVisitADTModel();
|
||||
$row = $modelPVA->select('patvisitadt.*, location.LocFull as LocationName,
|
||||
attDoc.NameFirst as AttDocFirstName, attDoc.NameLast as AttDocLastName,
|
||||
refDoc.NameFirst as RefDocFirstName, refDoc.NameLast as RefDocLastName,
|
||||
admDoc.NameFirst as AdmDocFirstName, admDoc.NameLast as AdmDocLastName,
|
||||
cnsDoc.NameFirst as CnsDocFirstName, cnsDoc.NameLast as CnsDocLastName')
|
||||
->join('location', 'location.LocationID = patvisitadt.LocationID', 'left')
|
||||
->join('contact attDoc', 'attDoc.ContactID = patvisitadt.AttDoc', 'left')
|
||||
->join('contact refDoc', 'refDoc.ContactID = patvisitadt.RefDoc', 'left')
|
||||
->join('contact admDoc', 'admDoc.ContactID = patvisitadt.AdmDoc', 'left')
|
||||
->join('contact cnsDoc', 'cnsDoc.ContactID = patvisitadt.CnsDoc', 'left')
|
||||
->where('patvisitadt.PVADTID', $PVADTID)
|
||||
->where('patvisitadt.DelDate', null)
|
||||
->first();
|
||||
|
||||
if (empty($row)) {
|
||||
return $this->respond(['status' => 'success', 'message' => 'ADT record not found', 'data' => []], 200);
|
||||
}
|
||||
|
||||
return $this->respond(['status' => 'success', 'message' => 'ADT record retrieved', 'data' => $row], 200);
|
||||
} catch (\Exception $e) {
|
||||
return $this->failServerError('Something went wrong: ' . $e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
public function deleteADT() {
|
||||
$input = $this->request->getJSON(true);
|
||||
try {
|
||||
if (!isset($input["PVADTID"]) || !is_numeric($input["PVADTID"])) {
|
||||
return $this->respond(['status' => 'error', 'message' => 'Invalid or missing PVADTID'], 400);
|
||||
}
|
||||
|
||||
$modelPVA = new PatVisitADTModel();
|
||||
$adt = $modelPVA->find($input["PVADTID"]);
|
||||
if (!$adt) {
|
||||
return $this->respond(['status' => 'error', 'message' => 'ADT record not found'], 404);
|
||||
}
|
||||
|
||||
$result = $modelPVA->delete($input["PVADTID"]);
|
||||
|
||||
if ($result) {
|
||||
return $this->respond(['status' => 'success', 'message' => 'ADT record deleted successfully'], 200);
|
||||
} else {
|
||||
return $this->respond(['status' => 'error', 'message' => 'Failed to delete ADT record'], 500);
|
||||
}
|
||||
} catch (\Exception $e) {
|
||||
return $this->failServerError('Something went wrong: ' . $e->getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
441
app/Controllers/Patient/PatientController.php
Executable file → Normal file
441
app/Controllers/Patient/PatientController.php
Executable file → Normal file
@ -1,318 +1,217 @@
|
||||
<?php
|
||||
namespace App\Controllers\Patient;
|
||||
|
||||
use App\Traits\ResponseTrait;
|
||||
use CodeIgniter\Controller;
|
||||
use App\Libraries\ValueSet;
|
||||
use App\Models\Patient\PatientModel;
|
||||
|
||||
<?php
|
||||
namespace App\Controllers\Patient;
|
||||
|
||||
use CodeIgniter\API\ResponseTrait;
|
||||
use CodeIgniter\Controller;
|
||||
|
||||
use App\Models\Patient\PatientModel;
|
||||
|
||||
class PatientController extends Controller {
|
||||
use ResponseTrait;
|
||||
|
||||
protected $db;
|
||||
protected $model;
|
||||
protected $rules;
|
||||
|
||||
public function __construct() {
|
||||
$this->db = \Config\Database::connect();
|
||||
$this->model = new PatientModel();
|
||||
$this->rules = [
|
||||
'PatientID' => 'required|regex_match[/^[A-Za-z0-9.-]+$/]|max_length[30]',
|
||||
'AlternatePID' => 'permit_empty|regex_match[/^[A-Za-z0-9.-]+$/]|max_length[30]',
|
||||
'Prefix' => 'permit_empty|regex_match[/^[A-Za-z\'\. ]+$/]|max_length[10]',
|
||||
'Sex' => 'required',
|
||||
|
||||
'NameFirst' => 'required|regex_match[/^[A-Za-z\'\. ]+$/]|min_length[1]|max_length[60]',
|
||||
'NameMiddle' => 'permit_empty|regex_match[/^[A-Za-z\'\. ]+$/]|min_length[1]|max_length[60]',
|
||||
'NameMaiden' => 'permit_empty|regex_match[/^[A-Za-z\'\. ]+$/]|min_length[1]|max_length[60]',
|
||||
'NameLast' => 'permit_empty|regex_match[/^[A-Za-z\'\. ]+$/]|min_length[1]|max_length[60]',
|
||||
|
||||
'Suffix' => 'permit_empty|regex_match[/^[A-Za-z\'\. ]+$/]|max_length[10]',
|
||||
'PlaceOfBirth' => 'permit_empty|regex_match[/^[A-Za-z\'\. ]+$/]|max_length[100]',
|
||||
'Citizenship' => 'permit_empty|regex_match[/^[A-Za-z\'\. ]+$/]|max_length[100]',
|
||||
|
||||
'Street_1' => 'permit_empty|regex_match[/^[A-Za-z0-9\'.,\/\- ]+$/]|max_length[255]',
|
||||
'Street_2' => 'permit_empty|regex_match[/^[A-Za-z0-9\'.,\/\- ]+$/]|max_length[255]',
|
||||
'Street_3' => 'permit_empty|regex_match[/^[A-Za-z0-9\'.,\/\- ]+$/]|max_length[255]',
|
||||
|
||||
'EmailAddress1' => 'permit_empty|valid_email|max_length[100]',
|
||||
'EmailAddress2' => 'permit_empty|valid_email|max_length[100]',
|
||||
|
||||
'Birthdate' => 'required',
|
||||
'PatIdt.IdentifierType' => 'permit_empty',
|
||||
'PatIdt.Identifier' => 'permit_empty|max_length[255]',
|
||||
|
||||
'ZIP' => 'permit_empty|is_natural|max_length[10]',
|
||||
'Phone' => 'permit_empty|regex_match[/^\\+?[0-9]{8,15}$/]',
|
||||
'MobilePhone' => 'permit_empty|regex_match[/^\\+?[0-9]{8,15}$/]'
|
||||
];
|
||||
}
|
||||
|
||||
public function index() {
|
||||
$filters = [
|
||||
'InternalPID' => $this->request->getVar('InternalPID'),
|
||||
'PatientID' => $this->request->getVar('PatientID'),
|
||||
'Name' => $this->request->getVar('Name'),
|
||||
'Birthdate' => $this->request->getVar('Birthdate'),
|
||||
];
|
||||
|
||||
try {
|
||||
$rows = $this->model->getPatients($filters);
|
||||
|
||||
$rows = ValueSet::transformLabels($rows, [
|
||||
'Sex' => 'sex',
|
||||
]);
|
||||
|
||||
return $this->respond([ 'status' => 'success', 'message'=> "data fetched successfully", 'data' => $rows ], 200);
|
||||
} catch (\Exception $e) {
|
||||
return $this->failServerError('Exception : '.$e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
public function show($InternalPID = null) {
|
||||
try {
|
||||
$row = $this->model->getPatient($InternalPID);
|
||||
if (empty($row)) { return $this->respond([ 'status' => 'success', 'message' => "data not found.", 'data' => null ], 200); }
|
||||
|
||||
$row = ValueSet::transformLabels([$row], [
|
||||
'Sex' => 'sex',
|
||||
])[0];
|
||||
|
||||
return $this->respond([ 'status' => 'success', 'message' => "data fetched successfully", 'data' => $row ], 200);
|
||||
} catch (\Exception $e) {
|
||||
return $this->failServerError('Something went wrong: ' . $e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
public function create() {
|
||||
$input = $this->request->getJSON(true);
|
||||
use ResponseTrait;
|
||||
|
||||
// Khusus untuk Override PATIDT
|
||||
$type = $input['PatIdt']['IdentifierType'] ?? null;
|
||||
$identifierRulesMap = $this->getPatIdtIdentifierRulesMap();
|
||||
if ($type === null || $type === '' || !is_string($type)) {
|
||||
$identifierRule = 'permit_empty|max_length[255]';
|
||||
$this->rules['PatIdt.IdentifierType'] = 'permit_empty';
|
||||
$this->rules['PatIdt.Identifier'] = $identifierRule;
|
||||
} else {
|
||||
$identifierRule = $identifierRulesMap[$type] ?? 'permit_empty|max_length[255]';
|
||||
$this->rules['PatIdt.IdentifierType'] = 'required';
|
||||
$this->rules['PatIdt.Identifier'] = $identifierRule;
|
||||
}
|
||||
|
||||
if (!$this->validateData($input, $this->rules)) { return $this->failValidationErrors($this->validator->getErrors()); }
|
||||
try {
|
||||
$InternalPID = $this->model->createPatient($input);
|
||||
return $this->respondCreated([ 'status' => 'success', 'message' => "data $InternalPID created successfully" ]);
|
||||
} catch (\Exception $e) {
|
||||
return $this->failServerError('Something went wrong: ' . $e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
public function update($InternalPID = null) {
|
||||
$input = $this->request->getJSON(true) ?? [];
|
||||
protected $db;
|
||||
protected $model;
|
||||
protected $rules;
|
||||
|
||||
if (!$InternalPID || !ctype_digit((string) $InternalPID)) {
|
||||
return $this->respond([
|
||||
'status' => 'error',
|
||||
'message' => 'InternalPID is required and must be a valid integer.'
|
||||
], 400);
|
||||
}
|
||||
public function __construct() {
|
||||
$this->db = \Config\Database::connect();
|
||||
$this->model = new PatientModel();
|
||||
$this->rules = [
|
||||
'PatientID' => 'required|regex_match[/^[A-Za-z0-9]+$/]|max_length[30]',
|
||||
'AlternatePID' => 'permit_empty|regex_match[/^[A-Za-z0-9]+$/]|max_length[30]',
|
||||
'Prefix' => 'permit_empty|regex_match[/^[A-Za-z\'\. ]+$/]|max_length[10]',
|
||||
'Sex' => 'required',
|
||||
|
||||
if (!is_array($input) || $input === []) {
|
||||
return $this->respond([
|
||||
'status' => 'failed',
|
||||
'message' => 'Patch payload is required.'
|
||||
], 400);
|
||||
}
|
||||
'NameFirst' => 'required|regex_match[/^[A-Za-z\'\. ]+$/]|min_length[1]|max_length[60]',
|
||||
'NameMiddle' => 'permit_empty|regex_match[/^[A-Za-z\'\. ]+$/]|min_length[1]|max_length[60]',
|
||||
'NameMaiden' => 'permit_empty|regex_match[/^[A-Za-z\'\. ]+$/]|min_length[1]|max_length[60]',
|
||||
'NameLast' => 'permit_empty|regex_match[/^[A-Za-z\'\. ]+$/]|min_length[1]|max_length[60]',
|
||||
|
||||
if (array_key_exists('PatIdt', $input) && $input['PatIdt'] !== null && !is_array($input['PatIdt'])) {
|
||||
return $this->failValidationErrors([
|
||||
'PatIdt' => 'PatIdt must be an object or null.'
|
||||
]);
|
||||
}
|
||||
'Suffix' => 'permit_empty|regex_match[/^[A-Za-z\'\. ]+$/]|max_length[10]',
|
||||
'PlaceOfBirth' => 'permit_empty|regex_match[/^[A-Za-z\'\. ]+$/]|max_length[100]',
|
||||
'Citizenship' => 'permit_empty|regex_match[/^[A-Za-z\'\. ]+$/]|max_length[100]',
|
||||
|
||||
$patchRules = $this->buildPatchRules($input);
|
||||
if ($patchRules !== [] && !$this->validateData($input, $patchRules)) {
|
||||
return $this->failValidationErrors($this->validator->getErrors());
|
||||
}
|
||||
'Street_1' => 'permit_empty|regex_match[/^[A-Za-z0-9\'.,\/\- ]+$/]|max_length[255]',
|
||||
'Street_2' => 'permit_empty|regex_match[/^[A-Za-z0-9\'.,\/\- ]+$/]|max_length[255]',
|
||||
'Street_3' => 'permit_empty|regex_match[/^[A-Za-z0-9\'.,\/\- ]+$/]|max_length[255]',
|
||||
|
||||
'EmailAddress1' => 'permit_empty|valid_email|max_length[100]',
|
||||
'EmailAddress2' => 'permit_empty|valid_email|max_length[100]',
|
||||
|
||||
'Birthdate' => 'required',
|
||||
'PatIdt.IdentifierType' => 'permit_empty',
|
||||
'PatIdt.Identifier' => 'permit_empty|max_length[255]',
|
||||
|
||||
'ZIP' => 'permit_empty|is_natural|max_length[10]',
|
||||
'Phone' => 'permit_empty|regex_match[/^\\+?[0-9]{8,15}$/]',
|
||||
'MobilePhone' => 'permit_empty|regex_match[/^\\+?[0-9]{8,15}$/]'
|
||||
];
|
||||
}
|
||||
|
||||
public function index() {
|
||||
$filters = [
|
||||
'InternalPID' => $this->request->getVar('InternalPID'),
|
||||
'PatientID' => $this->request->getVar('PatientID'),
|
||||
'Name' => $this->request->getVar('Name'),
|
||||
'Birthdate' => $this->request->getVar('Birthdate'),
|
||||
];
|
||||
|
||||
try {
|
||||
$updatedPid = $this->model->updatePatientPartial((int) $InternalPID, $input);
|
||||
if ($updatedPid === null) {
|
||||
return $this->respond([
|
||||
'status' => 'failed',
|
||||
'message' => "data $InternalPID not found"
|
||||
], 404);
|
||||
}
|
||||
$rows = $this->model->getPatients($filters);
|
||||
return $this->respond([ 'status' => 'success', 'message'=> "data fetched successfully", 'data' => $rows ], 200);
|
||||
} catch (\Exception $e) {
|
||||
return $this->failServerError('Exception : '.$e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
return $this->respond([ 'status' => 'success', 'message' => "data $updatedPid update successfully" ], 200);
|
||||
public function show($InternalPID = null) {
|
||||
try {
|
||||
$row = $this->model->getPatient($InternalPID);
|
||||
if (empty($row)) { return $this->respond([ 'status' => 'success', 'message' => "data not found.", 'data' => null ], 200); }
|
||||
return $this->respond([ 'status' => 'success', 'message' => "data fetched successfully", 'data' => $row ], 200);
|
||||
} catch (\Exception $e) {
|
||||
return $this->failServerError('Something went wrong: ' . $e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
private function buildPatchRules(array $input): array
|
||||
{
|
||||
$rules = [];
|
||||
public function create() {
|
||||
$input = $this->request->getJSON(true);
|
||||
|
||||
$fieldRules = [
|
||||
'PatientID' => 'permit_empty|regex_match[/^[A-Za-z0-9.-]+$/]|max_length[30]',
|
||||
'AlternatePID' => 'permit_empty|regex_match[/^[A-Za-z0-9.-]+$/]|max_length[30]',
|
||||
'Prefix' => 'permit_empty|regex_match[/^[A-Za-z\'\. ]+$/]|max_length[10]',
|
||||
'Sex' => 'permit_empty',
|
||||
'NameFirst' => 'required|regex_match[/^[A-Za-z\'\. ]+$/]|min_length[1]|max_length[60]',
|
||||
'NameMiddle' => 'permit_empty|regex_match[/^[A-Za-z\'\. ]+$/]|min_length[1]|max_length[60]',
|
||||
'NameMaiden' => 'permit_empty|regex_match[/^[A-Za-z\'\. ]+$/]|min_length[1]|max_length[60]',
|
||||
'NameLast' => 'permit_empty|regex_match[/^[A-Za-z\'\. ]+$/]|min_length[1]|max_length[60]',
|
||||
'Suffix' => 'permit_empty|regex_match[/^[A-Za-z\'\. ]+$/]|max_length[10]',
|
||||
'PlaceOfBirth' => 'permit_empty|regex_match[/^[A-Za-z\'\. ]+$/]|max_length[100]',
|
||||
'Citizenship' => 'permit_empty|regex_match[/^[A-Za-z\'\. ]+$/]|max_length[100]',
|
||||
'Street_1' => 'permit_empty|regex_match[/^[A-Za-z0-9\'.,\/\- ]+$/]|max_length[255]',
|
||||
'Street_2' => 'permit_empty|regex_match[/^[A-Za-z0-9\'.,\/\- ]+$/]|max_length[255]',
|
||||
'Street_3' => 'permit_empty|regex_match[/^[A-Za-z0-9\'.,\/\- ]+$/]|max_length[255]',
|
||||
'EmailAddress1' => 'permit_empty|valid_email|max_length[100]',
|
||||
'EmailAddress2' => 'permit_empty|valid_email|max_length[100]',
|
||||
'Birthdate' => 'permit_empty',
|
||||
'ZIP' => 'permit_empty|is_natural|max_length[10]',
|
||||
'Phone' => 'permit_empty|regex_match[/^\\+?[0-9]{8,15}$/]',
|
||||
'MobilePhone' => 'permit_empty|regex_match[/^\\+?[0-9]{8,15}$/]',
|
||||
'Country' => 'permit_empty|max_length[10]',
|
||||
'Race' => 'permit_empty|max_length[100]',
|
||||
'MaritalStatus' => 'permit_empty',
|
||||
'Religion' => 'permit_empty|max_length[100]',
|
||||
'Ethnic' => 'permit_empty|max_length[100]',
|
||||
'isDead' => 'permit_empty',
|
||||
'TimeOfDeath' => 'permit_empty',
|
||||
'PatCom' => 'permit_empty|string',
|
||||
'PatAtt' => 'permit_empty',
|
||||
'LinkTo' => 'permit_empty',
|
||||
'Custodian' => 'permit_empty',
|
||||
// Khusus untuk Override PATIDT
|
||||
$type = $input['PatIdt']['IdentifierType'] ?? null;
|
||||
$identifierRulesMap = [
|
||||
'KTP' => 'required|regex_match[/^[0-9]{16}$/]', // 16 pas digit numeric
|
||||
'PASS' => 'required|regex_match[/^[A-Za-z0-9]{1,9}$/]', // alphanumeric max 9
|
||||
'SSN' => 'required|regex_match[/^[0-9]{9}$/]', // numeric, pas 9 digit
|
||||
'SIM' => 'required|regex_match[/^[0-9]{19,20}$/]', // numeric 19–20 digit
|
||||
'KTAS' => 'required|regex_match[/^[0-9]{11}$/]', // numeric, pas 11 digit
|
||||
];
|
||||
|
||||
foreach ($fieldRules as $field => $rule) {
|
||||
if (array_key_exists($field, $input) && $field !== 'PatIdt') {
|
||||
$rules[$field] = $rule;
|
||||
}
|
||||
if ($type === null || $type === '' || !is_string($type)) {
|
||||
$identifierRule = 'permit_empty|max_length[255]';
|
||||
$this->rules['PatIdt.IdentifierType'] = 'permit_empty';
|
||||
$this->rules['PatIdt.Identifier'] = $identifierRule;
|
||||
} else {
|
||||
$identifierRule = $identifierRulesMap[$type] ?? 'permit_empty|max_length[255]';
|
||||
$this->rules['PatIdt.IdentifierType'] = 'required';
|
||||
$this->rules['PatIdt.Identifier'] = $identifierRule;
|
||||
}
|
||||
|
||||
if (array_key_exists('PatIdt', $input) && $input['PatIdt'] !== null) {
|
||||
$type = $input['PatIdt']['IdentifierType'] ?? null;
|
||||
$identifierRulesMap = $this->getPatIdtIdentifierRulesMap();
|
||||
$identifierRule = is_string($type)
|
||||
? ($identifierRulesMap[$type] ?? 'required|max_length[255]')
|
||||
: 'required|max_length[255]';
|
||||
|
||||
$rules['PatIdt.IdentifierType'] = 'required';
|
||||
$rules['PatIdt.Identifier'] = $identifierRule;
|
||||
if (!$this->validateData($input, $this->rules)) { return $this->failValidationErrors($this->validator->getErrors()); }
|
||||
try {
|
||||
$InternalPID = $this->model->createPatient($input);
|
||||
return $this->respondCreated([ 'status' => 'success', 'message' => "data $InternalPID created successfully" ]);
|
||||
} catch (\Exception $e) {
|
||||
return $this->failServerError('Something went wrong: ' . $e->getMessage());
|
||||
}
|
||||
|
||||
return $rules;
|
||||
}
|
||||
|
||||
private function getPatIdtIdentifierRulesMap(): array
|
||||
{
|
||||
return [
|
||||
public function update() {
|
||||
$input = $this->request->getJSON(true);
|
||||
|
||||
// Khusus untuk Override PATIDT
|
||||
$type = $input['PatIdt']['IdentifierType'] ?? null;
|
||||
$identifierRulesMap = [
|
||||
'KTP' => 'required|regex_match[/^[0-9]{16}$/]',
|
||||
'PASS' => 'required|regex_match[/^[A-Za-z0-9]{1,9}$/]',
|
||||
'SSN' => 'required|regex_match[/^[0-9]{9}$/]',
|
||||
'SIM' => 'required|regex_match[/^[0-9]{19,20}$/]',
|
||||
'KTAS' => 'required|regex_match[/^[0-9]{11}$/]',
|
||||
'PASS' => 'required|regex_match[/^[A-Za-z0-9]{6,9}$/]',
|
||||
'SSN' => 'required|regex_match[/^[0-9]{3}-[0-9]{2}-[0-9]{4}$/]',
|
||||
'SIM' => 'required|regex_match[/^[A-Za-z0-9]{12,14}$/]',
|
||||
'KTAS' => 'required|regex_match[/^[A-Za-z0-9]{12,15}$/]',
|
||||
];
|
||||
if ($type === null || $type === '' || !is_string($type)) {
|
||||
$identifierRule = 'permit_empty|max_length[255]';
|
||||
$this->rules['PatIdt.IdentifierType'] = 'permit_empty';
|
||||
$this->rules['PatIdt.Identifier'] = $identifierRule;
|
||||
} else {
|
||||
$identifierRule = $identifierRulesMap[$type] ?? 'permit_empty|max_length[255]';
|
||||
$this->rules['PatIdt.IdentifierType'] = 'required';
|
||||
$this->rules['PatIdt.Identifier'] = $identifierRule;
|
||||
}
|
||||
|
||||
if (!$this->validateData($input, $this->rules)) { return $this->failValidationErrors($this->validator->getErrors()); }
|
||||
try {
|
||||
$InternalPID = $this->model->updatePatient($input);
|
||||
return $this->respondCreated([ 'status' => 'success', 'message' => "data $InternalPID update successfully" ]);
|
||||
} catch (\Exception $e) {
|
||||
return $this->failServerError('Something went wrong: ' . $e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
public function delete() {
|
||||
try {
|
||||
$input = $this->request->getJSON(true);
|
||||
$InternalPID = $input["InternalPID"];
|
||||
|
||||
// Mencegah Inputan 0, [], null, sql injection
|
||||
if (empty($InternalPID) || !ctype_digit((string) $InternalPID)) {
|
||||
return $this->respond([
|
||||
'status' => 'error',
|
||||
'message' => "Patient ID must be a valid integer."
|
||||
], 400);
|
||||
}
|
||||
|
||||
$patient = $this->db->table('patient')->where('InternalPID', $InternalPID)->get()->getRow();
|
||||
|
||||
if (!$patient) {
|
||||
return $this->failNotFound("Patient ID with {$InternalPID} not found.");
|
||||
}
|
||||
|
||||
$this->db->table('patient')->where('InternalPID', $InternalPID)->update(['DelDate' => date('Y-m-d H:i:s')]);
|
||||
|
||||
return $this->respondDeleted([
|
||||
'status' => 'success',
|
||||
'message' => "Patient ID with {$InternalPID} deleted successfully."
|
||||
]);
|
||||
|
||||
} catch (\Exception $e) {
|
||||
return $this->failServerError("Internal server error: " . $e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public function delete() {
|
||||
try {
|
||||
$input = $this->request->getJSON(true);
|
||||
$InternalPID = $input["InternalPID"];
|
||||
|
||||
// Mencegah Inputan 0, [], null, sql injection
|
||||
if (empty($InternalPID) || !ctype_digit((string) $InternalPID)) {
|
||||
return $this->respond([
|
||||
'status' => 'error',
|
||||
'message' => "Patient ID must be a valid integer."
|
||||
], 400);
|
||||
}
|
||||
|
||||
$patient = $this->db->table('patient')->where('InternalPID', $InternalPID)->get()->getRow();
|
||||
|
||||
if (!$patient) {
|
||||
return $this->failNotFound("Patient ID with {$InternalPID} not found.");
|
||||
}
|
||||
|
||||
$this->db->table('patient')->where('InternalPID', $InternalPID)->update(['DelDate' => date('Y-m-d H:i:s')]);
|
||||
|
||||
return $this->respondDeleted([
|
||||
'status' => 'success',
|
||||
'message' => "Patient ID with {$InternalPID} deleted successfully."
|
||||
]);
|
||||
|
||||
} catch (\Exception $e) {
|
||||
return $this->failServerError("Internal server error: " . $e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
public function patientCheck() {
|
||||
try {
|
||||
$PatientID = $this->request->getVar('PatientID');
|
||||
$EmailAddress = $this->request->getVar('EmailAddress');
|
||||
$Phone = $this->request->getVar('Phone');
|
||||
$EmailAddress1 = $this->request->getVar('EmailAddress1');
|
||||
|
||||
$tableName = '';
|
||||
$searchName = '';
|
||||
|
||||
if (!empty($PatientID)){
|
||||
if (!preg_match('/^[A-Za-z0-9.-]+$/', (string) $PatientID)) {
|
||||
return $this->respond([
|
||||
'status' => 'error',
|
||||
'message' => 'PatientID format is invalid.',
|
||||
'data' => null
|
||||
], 400);
|
||||
}
|
||||
|
||||
$patient = $this->db->table('patient')
|
||||
->where('PatientID', $PatientID)
|
||||
->get()
|
||||
->getRowArray();
|
||||
} elseif (!empty($EmailAddress)) {
|
||||
$patient = $this->db->table('patient')
|
||||
->groupStart()
|
||||
->where('EmailAddress1', $EmailAddress)
|
||||
->orWhere('EmailAddress2', $EmailAddress)
|
||||
->groupEnd()
|
||||
->get()
|
||||
->getRowArray();
|
||||
} elseif (!empty($Phone)){
|
||||
$patient = $this->db->table('patient')
|
||||
->groupStart()
|
||||
->where('Phone', $Phone)
|
||||
->orWhere('MobilePhone', $Phone)
|
||||
->groupEnd()
|
||||
->get()
|
||||
->getRowArray();
|
||||
$tableName = 'PatientID';
|
||||
$searchName = $PatientID;
|
||||
} elseif (!empty($EmailAddress1)){
|
||||
$tableName = 'EmailAddress1';
|
||||
$searchName = $EmailAddress1;
|
||||
} else {
|
||||
return $this->respond([
|
||||
'status' => 'error',
|
||||
'message' => 'PatientID, EmailAddress, or Phone parameter is required.',
|
||||
'message' => 'PatientID or EmailAddress1 parameter is required.',
|
||||
'data' => null
|
||||
], 400);
|
||||
}
|
||||
|
||||
$patient = $this->db->table('patient')
|
||||
->where($tableName, $searchName)
|
||||
->get()
|
||||
->getRowArray();
|
||||
|
||||
if (!$patient) {
|
||||
return $this->respond([
|
||||
'status' => 'success',
|
||||
'message' => !empty($PatientID) ? 'PatientID not found.' : (!empty($Phone) ? 'Phone not found.' : 'EmailAddress not found.'),
|
||||
'message' => "$tableName not found.",
|
||||
'data' => true,
|
||||
], 200);
|
||||
}
|
||||
|
||||
return $this->respond([
|
||||
'status' => 'success',
|
||||
'message' => !empty($PatientID) ? 'PatientID already exists.' : (!empty($Phone) ? 'Phone already exists.' : 'EmailAddress already exists.'),
|
||||
'message' => "$tableName already exists.",
|
||||
'data' => false,
|
||||
], 200);
|
||||
|
||||
|
||||
} catch (\Exception $e) {
|
||||
// Error Server Mengembalikan 500
|
||||
return $this->failServerError('Something went wrong.'.$e->getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
} catch (\Exception $e) {
|
||||
// Error Server Mengembalikan 500
|
||||
return $this->failServerError('Something went wrong.'.$e->getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,75 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Controllers;
|
||||
|
||||
use App\Traits\ResponseTrait;
|
||||
use CodeIgniter\Controller;
|
||||
use App\Models\PatResultModel;
|
||||
use App\Models\OrderTest\OrderTestModel;
|
||||
use App\Models\Patient\PatientModel;
|
||||
|
||||
class ReportController extends Controller {
|
||||
use ResponseTrait;
|
||||
|
||||
protected $resultModel;
|
||||
protected $orderModel;
|
||||
protected $patientModel;
|
||||
|
||||
public function __construct() {
|
||||
$this->resultModel = new PatResultModel();
|
||||
$this->orderModel = new OrderTestModel();
|
||||
$this->patientModel = new PatientModel();
|
||||
}
|
||||
|
||||
/**
|
||||
* Generate HTML lab report for an order
|
||||
* GET /api/report/{orderID}
|
||||
*/
|
||||
public function view($orderID) {
|
||||
try {
|
||||
// Get order details
|
||||
$order = $this->orderModel->find((int)$orderID);
|
||||
|
||||
if (!$order) {
|
||||
return $this->respond([
|
||||
'status' => 'failed',
|
||||
'message' => 'Order not found',
|
||||
'data' => []
|
||||
], 404);
|
||||
}
|
||||
|
||||
// Get patient details
|
||||
$patient = $this->patientModel->find($order['InternalPID']);
|
||||
|
||||
if (!$patient) {
|
||||
return $this->respond([
|
||||
'status' => 'failed',
|
||||
'message' => 'Patient not found',
|
||||
'data' => []
|
||||
], 404);
|
||||
}
|
||||
|
||||
// Get results for this order
|
||||
$results = $this->resultModel->getByOrder((int)$orderID);
|
||||
|
||||
// Prepare data for the view
|
||||
$data = [
|
||||
'patient' => $patient,
|
||||
'order' => $order,
|
||||
'results' => $results,
|
||||
'generatedAt' => date('Y-m-d H:i:s')
|
||||
];
|
||||
|
||||
// Return HTML view
|
||||
return view('reports/lab_report', $data);
|
||||
|
||||
} catch (\Exception $e) {
|
||||
log_message('error', 'ReportController::view error: ' . $e->getMessage());
|
||||
return $this->respond([
|
||||
'status' => 'failed',
|
||||
'message' => 'Failed to generate report',
|
||||
'data' => []
|
||||
], 500);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -1,144 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Controllers\Result;
|
||||
|
||||
use App\Models\ValueSet\ValueSetModel;
|
||||
use App\Traits\ResponseTrait;
|
||||
|
||||
class ResultValueSetController extends \CodeIgniter\Controller
|
||||
{
|
||||
use ResponseTrait;
|
||||
|
||||
protected $dbModel;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->dbModel = new ValueSetModel();
|
||||
}
|
||||
|
||||
public function index()
|
||||
{
|
||||
$search = $this->request->getGet('search') ?? $this->request->getGet('param') ?? null;
|
||||
$VSetID = $this->request->getGet('VSetID') ?? null;
|
||||
|
||||
$rows = $this->dbModel->getValueSets($search, $VSetID);
|
||||
|
||||
return $this->respond([
|
||||
'status' => 'success',
|
||||
'data' => $rows
|
||||
], 200);
|
||||
}
|
||||
|
||||
public function show($id = null)
|
||||
{
|
||||
$row = $this->dbModel->getValueSet($id);
|
||||
if (!$row) {
|
||||
return $this->failNotFound("ValueSet item not found: $id");
|
||||
}
|
||||
|
||||
return $this->respond([
|
||||
'status' => 'success',
|
||||
'data' => $row
|
||||
], 200);
|
||||
}
|
||||
|
||||
public function create()
|
||||
{
|
||||
$input = $this->request->getJSON(true);
|
||||
if (!$input) {
|
||||
return $this->failValidationErrors(['Invalid JSON input']);
|
||||
}
|
||||
|
||||
$data = [
|
||||
'SiteID' => $input['SiteID'] ?? 1,
|
||||
'VSetID' => $input['VSetID'] ?? null,
|
||||
'VOrder' => $input['VOrder'] ?? 0,
|
||||
'VValue' => $input['VValue'] ?? '',
|
||||
'VDesc' => $input['VDesc'] ?? '',
|
||||
'VCategory' => $input['VCategory'] ?? null
|
||||
];
|
||||
|
||||
if ($data['VSetID'] === null) {
|
||||
return $this->failValidationErrors(['VSetID is required']);
|
||||
}
|
||||
|
||||
try {
|
||||
$id = $this->dbModel->insert($data, true);
|
||||
if (!$id) {
|
||||
return $this->failValidationErrors($this->dbModel->errors());
|
||||
}
|
||||
|
||||
$newRow = $this->dbModel->getValueSet($id);
|
||||
return $this->respondCreated([
|
||||
'status' => 'success',
|
||||
'message' => 'ValueSet item created',
|
||||
'data' => $newRow
|
||||
]);
|
||||
} catch (\Exception $e) {
|
||||
return $this->failServerError('Failed to create: ' . $e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
public function update($id = null)
|
||||
{
|
||||
$input = $this->request->getJSON(true);
|
||||
if (!$input) {
|
||||
return $this->failValidationErrors(['Invalid JSON input']);
|
||||
}
|
||||
|
||||
$existing = $this->dbModel->getValueSet($id);
|
||||
if (!$existing) {
|
||||
return $this->failNotFound("ValueSet item not found: $id");
|
||||
}
|
||||
|
||||
$data = [];
|
||||
if (isset($input['VSetID'])) $data['VSetID'] = $input['VSetID'];
|
||||
if (isset($input['VOrder'])) $data['VOrder'] = $input['VOrder'];
|
||||
if (isset($input['VValue'])) $data['VValue'] = $input['VValue'];
|
||||
if (isset($input['VDesc'])) $data['VDesc'] = $input['VDesc'];
|
||||
if (isset($input['SiteID'])) $data['SiteID'] = $input['SiteID'];
|
||||
if (isset($input['VCategory'])) $data['VCategory'] = $input['VCategory'];
|
||||
|
||||
if (empty($data)) {
|
||||
return $this->respond([
|
||||
'status' => 'success',
|
||||
'message' => 'No changes to update',
|
||||
'data' => $existing
|
||||
], 200);
|
||||
}
|
||||
|
||||
try {
|
||||
$updated = $this->dbModel->update($id, $data);
|
||||
if (!$updated) {
|
||||
return $this->failValidationErrors($this->dbModel->errors());
|
||||
}
|
||||
|
||||
$newRow = $this->dbModel->getValueSet($id);
|
||||
return $this->respond([
|
||||
'status' => 'success',
|
||||
'message' => 'ValueSet item updated',
|
||||
'data' => $newRow
|
||||
], 200);
|
||||
} catch (\Exception $e) {
|
||||
return $this->failServerError('Failed to update: ' . $e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
public function delete($id = null)
|
||||
{
|
||||
$existing = $this->dbModel->getValueSet($id);
|
||||
if (!$existing) {
|
||||
return $this->failNotFound("ValueSet item not found: $id");
|
||||
}
|
||||
|
||||
try {
|
||||
$this->dbModel->delete($id);
|
||||
return $this->respond([
|
||||
'status' => 'success',
|
||||
'message' => 'ValueSet item deleted'
|
||||
], 200);
|
||||
} catch (\Exception $e) {
|
||||
return $this->failServerError('Failed to delete: ' . $e->getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
296
app/Controllers/ResultController.php
Executable file → Normal file
296
app/Controllers/ResultController.php
Executable file → Normal file
@ -1,280 +1,34 @@
|
||||
<?php
|
||||
|
||||
namespace App\Controllers;
|
||||
|
||||
use App\Traits\PatchValidationTrait;
|
||||
use App\Traits\ResponseTrait;
|
||||
<?php
|
||||
|
||||
namespace App\Controllers;
|
||||
|
||||
use CodeIgniter\API\ResponseTrait;
|
||||
use CodeIgniter\Controller;
|
||||
use App\Models\PatResultModel;
|
||||
use Config\Services;
|
||||
|
||||
|
||||
use Firebase\JWT\JWT;
|
||||
use Firebase\JWT\Key;
|
||||
use Firebase\JWT\ExpiredException;
|
||||
use Firebase\JWT\SignatureInvalidException;
|
||||
use Firebase\JWT\BeforeValidException;
|
||||
use CodeIgniter\Cookie\Cookie;
|
||||
|
||||
class ResultController extends Controller {
|
||||
use ResponseTrait;
|
||||
use PatchValidationTrait;
|
||||
|
||||
protected $model;
|
||||
|
||||
public function __construct() {
|
||||
$this->model = new PatResultModel();
|
||||
}
|
||||
|
||||
/**
|
||||
* List results with optional filters
|
||||
* GET /api/result
|
||||
*/
|
||||
public function index() {
|
||||
try {
|
||||
$orderID = $this->request->getGet('order_id');
|
||||
$patientID = $this->request->getGet('patient_id');
|
||||
|
||||
if ($orderID) {
|
||||
$results = $this->model->getByOrder((int)$orderID);
|
||||
} elseif ($patientID) {
|
||||
$results = $this->model->getByPatient((int)$patientID);
|
||||
} else {
|
||||
// Get all results with pagination
|
||||
$page = (int)($this->request->getGet('page') ?? 1);
|
||||
$perPage = (int)($this->request->getGet('per_page') ?? 20);
|
||||
|
||||
$results = $this->model
|
||||
->where('DelDate', null)
|
||||
->orderBy('ResultID', 'DESC')
|
||||
->paginate($perPage, 'default', $page);
|
||||
}
|
||||
|
||||
$results = is_array($results)
|
||||
? array_map([$this, 'hydrateResultPayload'], $results)
|
||||
: $results;
|
||||
public function index() {
|
||||
|
||||
return $this->respond([
|
||||
'status' => 'success',
|
||||
'message' => 'Results retrieved successfully',
|
||||
'data' => $results
|
||||
], 200);
|
||||
|
||||
} catch (\Exception $e) {
|
||||
log_message('error', 'ResultController::index error: ' . $e->getMessage());
|
||||
return $this->respond([
|
||||
'status' => 'failed',
|
||||
'message' => 'Failed to retrieve results',
|
||||
'data' => []
|
||||
], 500);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get single result
|
||||
* GET /api/result/{id}
|
||||
*/
|
||||
public function show($id) {
|
||||
try {
|
||||
$result = $this->model->getWithRelations((int)$id);
|
||||
$token = $this->request->getCookie('token');
|
||||
$key = getenv('JWT_SECRET');
|
||||
|
||||
if (!$result) {
|
||||
return $this->respond([
|
||||
'status' => 'failed',
|
||||
'message' => 'Result not found',
|
||||
'data' => []
|
||||
], 404);
|
||||
}
|
||||
// Decode Token dengan Key yg ada di .env
|
||||
$decodedPayload = JWT::decode($token, new Key($key, 'HS256'));
|
||||
|
||||
$result = $this->hydrateResultPayload($result);
|
||||
|
||||
return $this->respond([
|
||||
'status' => 'success',
|
||||
'message' => 'Result retrieved successfully',
|
||||
'data' => $result
|
||||
], 200);
|
||||
|
||||
} catch (\Exception $e) {
|
||||
log_message('error', 'ResultController::show error: ' . $e->getMessage());
|
||||
return $this->respond([
|
||||
'status' => 'failed',
|
||||
'message' => 'Failed to retrieve result',
|
||||
'data' => []
|
||||
], 500);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new result entry
|
||||
* POST /api/result
|
||||
*/
|
||||
public function create() {
|
||||
$payload = $this->request->getJSON(true);
|
||||
if (!is_array($payload) || empty($payload)) {
|
||||
return $this->respond([
|
||||
'status' => 'failed',
|
||||
'message' => 'No data provided',
|
||||
'data' => []
|
||||
], 400);
|
||||
}
|
||||
|
||||
if (isset($payload['ResultValue'])) {
|
||||
$payload['Result'] = $payload['ResultValue'];
|
||||
}
|
||||
|
||||
$dbPayload = $payload;
|
||||
unset($dbPayload['ResultValue'], $dbPayload['ResultCode']);
|
||||
|
||||
try {
|
||||
$resultId = $this->model->insert($dbPayload, true);
|
||||
|
||||
if (!$resultId) {
|
||||
return $this->respond([
|
||||
'status' => 'failed',
|
||||
'message' => 'Failed to create result',
|
||||
'data' => []
|
||||
], 500);
|
||||
}
|
||||
|
||||
$this->rememberResultCode($resultId, $payload['ResultCode'] ?? null);
|
||||
|
||||
return $this->respondCreated([
|
||||
'status' => 'success',
|
||||
'message' => 'Result created successfully',
|
||||
'data' => [
|
||||
'ResultID' => $resultId,
|
||||
'ResultValue' => $payload['ResultValue'] ?? ($payload['Result'] ?? null),
|
||||
'ResultCode' => $payload['ResultCode'] ?? null,
|
||||
]
|
||||
], 201);
|
||||
} catch (\Exception $e) {
|
||||
log_message('error', 'ResultController::create error: ' . $e->getMessage());
|
||||
return $this->respond([
|
||||
'status' => 'failed',
|
||||
'message' => 'Failed to create result',
|
||||
'data' => []
|
||||
], 500);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Update result with validation
|
||||
* PATCH /api/result/{id}
|
||||
*/
|
||||
public function update($id) {
|
||||
try {
|
||||
$data = $this->requirePatchPayload($this->request->getJSON(true));
|
||||
if ($data === null) {
|
||||
return;
|
||||
}
|
||||
|
||||
$validatedId = $this->requirePatchId($id, 'ResultID');
|
||||
if ($validatedId === null) {
|
||||
return;
|
||||
}
|
||||
|
||||
$existing = $this->model->find($validatedId);
|
||||
if (!$existing) {
|
||||
return $this->respond([
|
||||
'status' => 'failed',
|
||||
'message' => 'Result not found',
|
||||
'data' => []
|
||||
], 404);
|
||||
}
|
||||
|
||||
$resultCode = $data['ResultCode'] ?? null;
|
||||
$hasResultValue = array_key_exists('ResultValue', $data);
|
||||
|
||||
if ($hasResultValue) {
|
||||
$data['Result'] = $data['ResultValue'];
|
||||
}
|
||||
|
||||
unset($data['ResultValue'], $data['ResultCode']);
|
||||
|
||||
$shouldUpdateModel = $hasResultValue || !empty($data);
|
||||
|
||||
if ($shouldUpdateModel) {
|
||||
$result = $this->model->updateWithValidation($validatedId, $data);
|
||||
} else {
|
||||
$result = [
|
||||
'success' => true,
|
||||
'flag' => null,
|
||||
'message' => 'Result updated successfully'
|
||||
];
|
||||
}
|
||||
|
||||
if (!$result['success']) {
|
||||
return $this->respond([
|
||||
'status' => 'failed',
|
||||
'message' => $result['message'],
|
||||
'data' => []
|
||||
], 400);
|
||||
}
|
||||
|
||||
if ($resultCode !== null) {
|
||||
$this->rememberResultCode($validatedId, $resultCode);
|
||||
}
|
||||
|
||||
// Get updated result with relations
|
||||
$updatedResult = $this->model->getWithRelations($validatedId);
|
||||
|
||||
return $this->respond([
|
||||
'status' => 'success',
|
||||
'message' => $result['message'],
|
||||
'data' => [
|
||||
'result' => $updatedResult ? $this->hydrateResultPayload($updatedResult) : [],
|
||||
'flag' => $result['flag']
|
||||
]
|
||||
], 200);
|
||||
|
||||
} catch (\Exception $e) {
|
||||
log_message('error', 'ResultController::update error: ' . $e->getMessage());
|
||||
return $this->respond([
|
||||
'status' => 'failed',
|
||||
'message' => 'Failed to update result',
|
||||
'data' => []
|
||||
], 500);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Soft delete result
|
||||
* DELETE /api/result/{id}
|
||||
*/
|
||||
public function delete($id) {
|
||||
try {
|
||||
$result = $this->model->find((int)$id);
|
||||
|
||||
if (!$result) {
|
||||
return $this->respond([
|
||||
'status' => 'failed',
|
||||
'message' => 'Result not found',
|
||||
'data' => []
|
||||
], 404);
|
||||
}
|
||||
|
||||
$deleted = $this->model->softDelete((int)$id);
|
||||
|
||||
if (!$deleted) {
|
||||
return $this->respond([
|
||||
'status' => 'failed',
|
||||
'message' => 'Failed to delete result',
|
||||
'data' => []
|
||||
], 500);
|
||||
}
|
||||
|
||||
return $this->respond([
|
||||
'status' => 'success',
|
||||
'message' => 'Result deleted successfully',
|
||||
'data' => []
|
||||
], 200);
|
||||
|
||||
} catch (\Exception $e) {
|
||||
log_message('error', 'ResultController::delete error: ' . $e->getMessage());
|
||||
return $this->respond([
|
||||
'status' => 'failed',
|
||||
'message' => 'Failed to delete result',
|
||||
'data' => []
|
||||
], 500);
|
||||
}
|
||||
}
|
||||
|
||||
private function hydrateResultPayload(array $payload): array {
|
||||
if (!array_key_exists('ResultValue', $payload) && array_key_exists('Result', $payload)) {
|
||||
$payload['ResultValue'] = $payload['Result'];
|
||||
}
|
||||
return $payload;
|
||||
return $this->respond([
|
||||
'status' => 'success',
|
||||
'code' => 200,
|
||||
'message' => 'Authenticated',
|
||||
'data' => $decodedPayload
|
||||
], 200);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -1,372 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Controllers\Rule;
|
||||
|
||||
use App\Controllers\BaseController;
|
||||
use App\Models\Rule\RuleDefModel;
|
||||
use App\Models\Test\TestDefSiteModel;
|
||||
use App\Services\RuleExpressionService;
|
||||
use App\Traits\PatchValidationTrait;
|
||||
use App\Traits\ResponseTrait;
|
||||
|
||||
class RuleController extends BaseController
|
||||
{
|
||||
use ResponseTrait;
|
||||
use PatchValidationTrait;
|
||||
|
||||
protected RuleDefModel $ruleDefModel;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->ruleDefModel = new RuleDefModel();
|
||||
}
|
||||
|
||||
public function index()
|
||||
{
|
||||
try {
|
||||
$eventCode = $this->request->getGet('EventCode');
|
||||
$testSiteID = $this->request->getGet('TestSiteID');
|
||||
$search = $this->request->getGet('search');
|
||||
|
||||
$builder = $this->ruleDefModel->where('ruledef.EndDate', null);
|
||||
|
||||
if ($eventCode !== null && $eventCode !== '') {
|
||||
$builder->where('ruledef.EventCode', $eventCode);
|
||||
}
|
||||
if ($search !== null && $search !== '') {
|
||||
$builder->like('ruledef.RuleName', $search);
|
||||
}
|
||||
|
||||
// Filter by TestSiteID - join with mapping table
|
||||
if ($testSiteID !== null && $testSiteID !== '' && is_numeric($testSiteID)) {
|
||||
$builder->join('testrule', 'testrule.RuleID = ruledef.RuleID', 'inner');
|
||||
$builder->where('testrule.TestSiteID', (int) $testSiteID);
|
||||
$builder->where('testrule.EndDate IS NULL');
|
||||
}
|
||||
|
||||
$rows = $builder
|
||||
->orderBy('ruledef.RuleID', 'ASC')
|
||||
->findAll();
|
||||
|
||||
return $this->respond([
|
||||
'status' => 'success',
|
||||
'message' => 'fetch success',
|
||||
'data' => $rows,
|
||||
], 200);
|
||||
} catch (\Throwable $e) {
|
||||
log_message('error', 'RuleController::index error: ' . $e->getMessage());
|
||||
return $this->respond([
|
||||
'status' => 'failed',
|
||||
'message' => 'Failed to fetch rules',
|
||||
'data' => [],
|
||||
], 500);
|
||||
}
|
||||
}
|
||||
|
||||
public function show($id = null)
|
||||
{
|
||||
try {
|
||||
if (!$id || !is_numeric($id)) {
|
||||
return $this->failValidationErrors('RuleID is required');
|
||||
}
|
||||
|
||||
$rule = $this->ruleDefModel->where('EndDate', null)->find((int) $id);
|
||||
if (!$rule) {
|
||||
return $this->respond([
|
||||
'status' => 'failed',
|
||||
'message' => 'Rule not found',
|
||||
'data' => [],
|
||||
], 404);
|
||||
}
|
||||
|
||||
$linkedTests = $this->ruleDefModel->getLinkedTests((int) $id);
|
||||
|
||||
$rule['linkedTests'] = $linkedTests;
|
||||
|
||||
return $this->respond([
|
||||
'status' => 'success',
|
||||
'message' => 'fetch success',
|
||||
'data' => $rule,
|
||||
], 200);
|
||||
} catch (\Throwable $e) {
|
||||
log_message('error', 'RuleController::show error: ' . $e->getMessage());
|
||||
return $this->respond([
|
||||
'status' => 'failed',
|
||||
'message' => 'Failed to fetch rule',
|
||||
'data' => [],
|
||||
], 500);
|
||||
}
|
||||
}
|
||||
|
||||
public function create()
|
||||
{
|
||||
$input = $this->requirePatchPayload($this->request->getJSON(true) ?? []);
|
||||
if ($input === null) {
|
||||
return;
|
||||
}
|
||||
|
||||
$validation = service('validation');
|
||||
$validation->setRules([
|
||||
'RuleCode' => 'required|max_length[50]',
|
||||
'RuleName' => 'required|max_length[100]',
|
||||
'EventCode' => 'required|max_length[50]',
|
||||
'TestSiteIDs' => 'required',
|
||||
'TestSiteIDs.*' => 'is_natural_no_zero',
|
||||
'ConditionExpr' => 'permit_empty|max_length[1000]',
|
||||
]);
|
||||
|
||||
if (!$validation->run($input)) {
|
||||
return $this->failValidationErrors($validation->getErrors());
|
||||
}
|
||||
|
||||
$testSiteIDs = $input['TestSiteIDs'] ?? [];
|
||||
if (!is_array($testSiteIDs) || empty($testSiteIDs)) {
|
||||
return $this->failValidationErrors(['TestSiteIDs' => 'At least one TestSiteID is required']);
|
||||
}
|
||||
|
||||
// Validate all TestSiteIDs exist
|
||||
$testDef = new TestDefSiteModel();
|
||||
foreach ($testSiteIDs as $testSiteID) {
|
||||
$exists = $testDef->where('EndDate', null)->find((int) $testSiteID);
|
||||
if (!$exists) {
|
||||
return $this->failValidationErrors(['TestSiteIDs' => "TestSiteID {$testSiteID} not found"]);
|
||||
}
|
||||
}
|
||||
|
||||
$db = \Config\Database::connect();
|
||||
$db->transStart();
|
||||
|
||||
try {
|
||||
$ruleData = [
|
||||
'RuleCode' => $input['RuleCode'],
|
||||
'RuleName' => $input['RuleName'],
|
||||
'Description' => $input['Description'] ?? null,
|
||||
'EventCode' => $input['EventCode'],
|
||||
'ConditionExpr' => $input['ConditionExpr'] ?? null,
|
||||
'ConditionExprCompiled' => $input['ConditionExprCompiled'] ?? null,
|
||||
];
|
||||
|
||||
$ruleID = $this->ruleDefModel->insert($ruleData, true);
|
||||
if (!$ruleID) {
|
||||
throw new \Exception('Failed to create rule');
|
||||
}
|
||||
|
||||
// Link rule to test sites
|
||||
foreach ($testSiteIDs as $testSiteID) {
|
||||
$this->ruleDefModel->linkTest($ruleID, (int) $testSiteID);
|
||||
}
|
||||
|
||||
$db->transComplete();
|
||||
if ($db->transStatus() === false) {
|
||||
throw new \Exception('Transaction failed');
|
||||
}
|
||||
|
||||
return $this->respondCreated([
|
||||
'status' => 'success',
|
||||
'message' => 'Rule created successfully',
|
||||
'data' => ['RuleID' => $ruleID],
|
||||
], 201);
|
||||
} catch (\Throwable $e) {
|
||||
$db->transRollback();
|
||||
log_message('error', 'RuleController::create error: ' . $e->getMessage());
|
||||
return $this->failServerError('Something went wrong: ' . $e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
public function update($id = null)
|
||||
{
|
||||
$input = $this->request->getJSON(true) ?? [];
|
||||
|
||||
if (!$id || !is_numeric($id)) {
|
||||
$id = $input['RuleID'] ?? null;
|
||||
}
|
||||
if (!$id || !is_numeric($id)) {
|
||||
return $this->failValidationErrors('RuleID is required');
|
||||
}
|
||||
|
||||
$existing = $this->ruleDefModel->where('EndDate', null)->find((int) $id);
|
||||
if (!$existing) {
|
||||
return $this->respond([
|
||||
'status' => 'failed',
|
||||
'message' => 'Rule not found',
|
||||
'data' => [],
|
||||
], 404);
|
||||
}
|
||||
|
||||
$validation = service('validation');
|
||||
$validation->setRules([
|
||||
'RuleCode' => 'permit_empty|max_length[50]',
|
||||
'RuleName' => 'permit_empty|max_length[100]',
|
||||
'EventCode' => 'permit_empty|max_length[50]',
|
||||
'TestSiteIDs' => 'permit_empty',
|
||||
'TestSiteIDs.*' => 'is_natural_no_zero',
|
||||
'ConditionExpr' => 'permit_empty|max_length[1000]',
|
||||
]);
|
||||
|
||||
if (!$validation->run($input)) {
|
||||
return $this->failValidationErrors($validation->getErrors());
|
||||
}
|
||||
|
||||
$db = \Config\Database::connect();
|
||||
$db->transStart();
|
||||
|
||||
try {
|
||||
$updateData = [];
|
||||
foreach (['RuleCode', 'RuleName', 'Description', 'EventCode', 'ConditionExpr', 'ConditionExprCompiled'] as $field) {
|
||||
if (array_key_exists($field, $input)) {
|
||||
$updateData[$field] = $input[$field];
|
||||
}
|
||||
}
|
||||
|
||||
if (!empty($updateData)) {
|
||||
$this->ruleDefModel->update((int) $id, $updateData);
|
||||
}
|
||||
|
||||
// Update test site mappings if provided
|
||||
if (isset($input['TestSiteIDs']) && is_array($input['TestSiteIDs'])) {
|
||||
$testSiteIDs = $input['TestSiteIDs'];
|
||||
|
||||
// Validate all TestSiteIDs exist
|
||||
$testDef = new TestDefSiteModel();
|
||||
foreach ($testSiteIDs as $testSiteID) {
|
||||
$exists = $testDef->where('EndDate', null)->find((int) $testSiteID);
|
||||
if (!$exists) {
|
||||
throw new \Exception("TestSiteID {$testSiteID} not found");
|
||||
}
|
||||
}
|
||||
|
||||
// Get current linked tests
|
||||
$currentLinks = $this->ruleDefModel->getLinkedTests((int) $id);
|
||||
|
||||
// Unlink tests that are no longer in the list
|
||||
foreach ($currentLinks as $currentTestSiteID) {
|
||||
if (!in_array($currentTestSiteID, $testSiteIDs)) {
|
||||
$this->ruleDefModel->unlinkTest((int) $id, $currentTestSiteID);
|
||||
}
|
||||
}
|
||||
|
||||
// Link new tests
|
||||
foreach ($testSiteIDs as $testSiteID) {
|
||||
if (!in_array($testSiteID, $currentLinks)) {
|
||||
$this->ruleDefModel->linkTest((int) $id, (int) $testSiteID);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$db->transComplete();
|
||||
if ($db->transStatus() === false) {
|
||||
throw new \Exception('Transaction failed');
|
||||
}
|
||||
|
||||
return $this->respond([
|
||||
'status' => 'success',
|
||||
'message' => 'Rule updated successfully',
|
||||
'data' => ['RuleID' => (int) $id],
|
||||
], 200);
|
||||
} catch (\Throwable $e) {
|
||||
$db->transRollback();
|
||||
log_message('error', 'RuleController::update error: ' . $e->getMessage());
|
||||
return $this->failServerError('Something went wrong: ' . $e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
public function delete($id = null)
|
||||
{
|
||||
try {
|
||||
if (!$id || !is_numeric($id)) {
|
||||
return $this->failValidationErrors('RuleID is required');
|
||||
}
|
||||
|
||||
$existing = $this->ruleDefModel->where('EndDate', null)->find((int) $id);
|
||||
if (!$existing) {
|
||||
return $this->respond([
|
||||
'status' => 'failed',
|
||||
'message' => 'Rule not found',
|
||||
'data' => [],
|
||||
], 404);
|
||||
}
|
||||
|
||||
$this->ruleDefModel->delete((int) $id);
|
||||
|
||||
return $this->respondDeleted([
|
||||
'status' => 'success',
|
||||
'message' => 'Rule deleted successfully',
|
||||
'data' => ['RuleID' => (int) $id],
|
||||
]);
|
||||
} catch (\Throwable $e) {
|
||||
log_message('error', 'RuleController::delete error: ' . $e->getMessage());
|
||||
return $this->failServerError('Something went wrong: ' . $e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
public function validateExpr()
|
||||
{
|
||||
$input = $this->request->getJSON(true) ?? [];
|
||||
$expr = $input['expr'] ?? '';
|
||||
$context = $input['context'] ?? [];
|
||||
|
||||
if (!is_string($expr) || trim($expr) === '') {
|
||||
return $this->failValidationErrors(['expr' => 'expr is required']);
|
||||
}
|
||||
if (!is_array($context)) {
|
||||
return $this->failValidationErrors(['context' => 'context must be an object']);
|
||||
}
|
||||
|
||||
try {
|
||||
$svc = new RuleExpressionService();
|
||||
$result = $svc->evaluate($expr, $context);
|
||||
|
||||
return $this->respond([
|
||||
'status' => 'success',
|
||||
'data' => [
|
||||
'valid' => true,
|
||||
'result' => $result,
|
||||
],
|
||||
], 200);
|
||||
} catch (\Throwable $e) {
|
||||
return $this->respond([
|
||||
'status' => 'failed',
|
||||
'data' => [
|
||||
'valid' => false,
|
||||
'error' => $e->getMessage(),
|
||||
],
|
||||
], 200);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Compile DSL expression to engine-compatible structure.
|
||||
* Frontend calls this when user clicks "Compile" button.
|
||||
*/
|
||||
public function compile()
|
||||
{
|
||||
$input = $this->request->getJSON(true) ?? [];
|
||||
$expr = $input['expr'] ?? '';
|
||||
|
||||
if (!is_string($expr) || trim($expr) === '') {
|
||||
return $this->failValidationErrors(['expr' => 'Expression is required']);
|
||||
}
|
||||
|
||||
try {
|
||||
$svc = new RuleExpressionService();
|
||||
$compiled = $svc->compile($expr);
|
||||
|
||||
return $this->respond([
|
||||
'status' => 'success',
|
||||
'data' => [
|
||||
'raw' => $expr,
|
||||
'compiled' => $compiled,
|
||||
'conditionExprCompiled' => json_encode($compiled),
|
||||
],
|
||||
], 200);
|
||||
} catch (\Throwable $e) {
|
||||
return $this->respond([
|
||||
'status' => 'failed',
|
||||
'message' => 'Compilation failed',
|
||||
'data' => [
|
||||
'error' => $e->getMessage(),
|
||||
],
|
||||
], 400);
|
||||
}
|
||||
}
|
||||
}
|
||||
68
app/Controllers/SampleController.php
Executable file → Normal file
68
app/Controllers/SampleController.php
Executable file → Normal file
@ -1,34 +1,34 @@
|
||||
<?php
|
||||
|
||||
namespace App\Controllers;
|
||||
|
||||
use App\Traits\ResponseTrait;
|
||||
use CodeIgniter\Controller;
|
||||
|
||||
use Firebase\JWT\JWT;
|
||||
use Firebase\JWT\Key;
|
||||
use Firebase\JWT\ExpiredException;
|
||||
use Firebase\JWT\SignatureInvalidException;
|
||||
use Firebase\JWT\BeforeValidException;
|
||||
use CodeIgniter\Cookie\Cookie;
|
||||
|
||||
class SampleController extends Controller {
|
||||
use ResponseTrait;
|
||||
|
||||
public function index() {
|
||||
|
||||
$token = $this->request->getCookie('token');
|
||||
$key = getenv('JWT_SECRET');
|
||||
|
||||
// Decode Token dengan Key yg ada di .env
|
||||
$decodedPayload = JWT::decode($token, new Key($key, 'HS256'));
|
||||
|
||||
return $this->respond([
|
||||
'status' => 'success',
|
||||
'code' => 200,
|
||||
'message' => 'Authenticated',
|
||||
'data' => $decodedPayload
|
||||
], 200);
|
||||
}
|
||||
|
||||
}
|
||||
<?php
|
||||
|
||||
namespace App\Controllers;
|
||||
|
||||
use CodeIgniter\API\ResponseTrait;
|
||||
use CodeIgniter\Controller;
|
||||
|
||||
use Firebase\JWT\JWT;
|
||||
use Firebase\JWT\Key;
|
||||
use Firebase\JWT\ExpiredException;
|
||||
use Firebase\JWT\SignatureInvalidException;
|
||||
use Firebase\JWT\BeforeValidException;
|
||||
use CodeIgniter\Cookie\Cookie;
|
||||
|
||||
class SampleController extends Controller {
|
||||
use ResponseTrait;
|
||||
|
||||
public function index() {
|
||||
|
||||
$token = $this->request->getCookie('token');
|
||||
$key = getenv('JWT_SECRET');
|
||||
|
||||
// Decode Token dengan Key yg ada di .env
|
||||
$decodedPayload = JWT::decode($token, new Key($key, 'HS256'));
|
||||
|
||||
return $this->respond([
|
||||
'status' => 'success',
|
||||
'code' => 200,
|
||||
'message' => 'Authenticated',
|
||||
'data' => $decodedPayload
|
||||
], 200);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
147
app/Controllers/Specimen/ContainerDefController.php
Executable file → Normal file
147
app/Controllers/Specimen/ContainerDefController.php
Executable file → Normal file
@ -1,113 +1,72 @@
|
||||
<?php
|
||||
|
||||
namespace App\Controllers\Specimen;
|
||||
|
||||
use App\Traits\PatchValidationTrait;
|
||||
use App\Traits\ResponseTrait;
|
||||
<?php
|
||||
|
||||
namespace App\Controllers\Specimen;
|
||||
|
||||
use CodeIgniter\API\ResponseTrait;
|
||||
use App\Controllers\BaseController;
|
||||
use App\Libraries\ValueSet;
|
||||
use App\Models\Specimen\ContainerDefModel;
|
||||
|
||||
|
||||
class ContainerDefController extends BaseController {
|
||||
use ResponseTrait;
|
||||
use PatchValidationTrait;
|
||||
|
||||
|
||||
protected $db;
|
||||
protected $model;
|
||||
protected $rules;
|
||||
protected $patchRules;
|
||||
|
||||
public function __construct() {
|
||||
$this->db = \Config\Database::connect();
|
||||
|
||||
public function __construct() {
|
||||
$this->db = \Config\Database::connect();
|
||||
$this->model = new ContainerDefModel();
|
||||
$this->rules = [
|
||||
'ConCode' => 'required|max_length[50]',
|
||||
'ConName' => 'required|max_length[50]'
|
||||
];
|
||||
$this->patchRules = [
|
||||
'ConCode' => 'permit_empty|max_length[50]',
|
||||
'ConName' => 'permit_empty|max_length[50]'
|
||||
];
|
||||
}
|
||||
|
||||
public function index() {
|
||||
try {
|
||||
$filter = [
|
||||
'ConCode' => $this->request->getVar('ConCode'),
|
||||
'ConName' => $this->request->getVar('ConName')
|
||||
];
|
||||
$rows = $this->model->getContainers($filter);
|
||||
|
||||
$rows = ValueSet::transformLabels($rows, [
|
||||
'ConCategory' => 'container_class',
|
||||
'CapColor' => 'container_cap_color',
|
||||
'ConSize' => 'container_size',
|
||||
]);
|
||||
|
||||
return $this->respond([ 'status' => 'success', 'message'=> "data fetched successfully", 'data' => $rows ], 200);
|
||||
} catch (\Exception $e) {
|
||||
return $this->failServerError('Exception : '.$e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
public function show($ConDefID) {
|
||||
try {
|
||||
$row = $this->model->getContainer($ConDefID);
|
||||
if (empty($row)) {
|
||||
return $this->respond([ 'status' => 'success', 'message'=> "data not found", 'data' => null ], 200);
|
||||
}
|
||||
|
||||
$row = ValueSet::transformLabels([$row], [
|
||||
'ConCategory' => 'container_class',
|
||||
'CapColor' => 'container_cap_color',
|
||||
'ConSize' => 'container_size',
|
||||
])[0];
|
||||
|
||||
return $this->respond([ 'status' => 'success', 'message'=> "data fetched successfully", 'data' => $row ], 200);
|
||||
} catch (\Exception $e) {
|
||||
return $this->failServerError('Exception : '.$e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
public function create() {
|
||||
$input = $this->request->getJSON(true);
|
||||
if (!$this->validateData($input, $this->rules)) { return $this->failValidationErrors($this->validator->getErrors()); }
|
||||
try {
|
||||
$ConDefID = $this->model->insert($input);
|
||||
return $this->respondCreated([ 'status' => 'success', 'message' => "data $ConDefID created successfully", 'data' => $ConDefID ]);
|
||||
} catch (\Exception $e) {
|
||||
return $this->failServerError('Something went wrong: ' . $e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
public function update($ConDefID = null) {
|
||||
$input = $this->requirePatchPayload($this->request->getJSON(true));
|
||||
if ($input === null) {
|
||||
return;
|
||||
}
|
||||
|
||||
$id = $this->requirePatchId($ConDefID, 'ConDefID');
|
||||
if ($id === null) {
|
||||
return;
|
||||
}
|
||||
|
||||
$existing = $this->model->find($id);
|
||||
if (!$existing) {
|
||||
return $this->respond([ 'status' => 'failed', 'message' => 'Container definition not found', 'data' => [] ], 404);
|
||||
}
|
||||
|
||||
$validationInput = array_intersect_key($input, $this->patchRules);
|
||||
if (!empty($validationInput) && !$this->validateData($validationInput, $this->patchRules)) {
|
||||
return $this->failValidationErrors($this->validator->getErrors());
|
||||
}
|
||||
|
||||
$input['ConDefID'] = $id;
|
||||
public function index() {
|
||||
try {
|
||||
$this->model->update($id, $input);
|
||||
return $this->respondCreated([ 'status' => 'success', 'message' => 'data updated successfully', 'data' => $id ], 201);
|
||||
$filter = [
|
||||
'ConCode' => $this->request->getVar('ConCode'),
|
||||
'ConName' => $this->request->getVar('ConName')
|
||||
];
|
||||
$rows = $this->model->getContainers($filter);
|
||||
return $this->respond([ 'status' => 'success', 'message'=> "data fetched successfully", 'data' => $rows ], 200);
|
||||
} catch (\Exception $e) {
|
||||
return $this->failServerError('Exception : '.$e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
public function show($ConDefID) {
|
||||
try {
|
||||
$row = $this->model->getContainer($ConDefID);
|
||||
if (empty($row)) {
|
||||
return $this->respond([ 'status' => 'success', 'message'=> "data not found", 'data' => null ], 200);
|
||||
}
|
||||
return $this->respond([ 'status' => 'success', 'message'=> "data fetched successfully", 'data' => $row ], 200);
|
||||
} catch (\Exception $e) {
|
||||
return $this->failServerError('Exception : '.$e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
public function create() {
|
||||
$input = $this->request->getJSON(true);
|
||||
if (!$this->validateData($input, $this->rules)) { return $this->failValidationErrors($this->validator->getErrors()); }
|
||||
try {
|
||||
$ConDefID = $this->model->insert($input);
|
||||
return $this->respondCreated([ 'status' => 'success', 'message' => "data $ConDefID created successfully" ]);
|
||||
} catch (\Exception $e) {
|
||||
return $this->failServerError('Something went wrong: ' . $e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public function update() {
|
||||
$input = $this->request->getJSON(true);
|
||||
if (!$this->validateData($input, $this->rules)) { return $this->failValidationErrors($this->validator->getErrors()); }
|
||||
try {
|
||||
$ConDefID = $this->model->update($input['ConDefID'], $input);
|
||||
return $this->respondCreated([ 'status' => 'success', 'message' => "data $ConDefID updated successfully" ]);
|
||||
} catch (\Exception $e) {
|
||||
return $this->failServerError('Something went wrong: ' . $e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
140
app/Controllers/Specimen/SpecimenCollectionController.php
Executable file → Normal file
140
app/Controllers/Specimen/SpecimenCollectionController.php
Executable file → Normal file
@ -1,99 +1,65 @@
|
||||
<?php
|
||||
|
||||
namespace App\Controllers\Specimen;
|
||||
|
||||
use App\Traits\PatchValidationTrait;
|
||||
use App\Traits\ResponseTrait;
|
||||
<?php
|
||||
|
||||
namespace App\Controllers\Specimen;
|
||||
|
||||
use CodeIgniter\API\ResponseTrait;
|
||||
use App\Controllers\BaseController;
|
||||
use App\Libraries\ValueSet;
|
||||
use App\Models\Specimen\SpecimenCollectionModel;
|
||||
|
||||
|
||||
class SpecimenCollectionController extends BaseController {
|
||||
use ResponseTrait;
|
||||
use PatchValidationTrait;
|
||||
|
||||
protected $db;
|
||||
protected $model;
|
||||
protected $rules;
|
||||
|
||||
public function __construct() {
|
||||
$this->db = \Config\Database::connect();
|
||||
$this->model = new SpecimenCollectionModel();
|
||||
$this->rules = [];
|
||||
}
|
||||
|
||||
public function index() {
|
||||
try {
|
||||
$rows = $this->model->findAll();
|
||||
|
||||
$rows = ValueSet::transformLabels($rows, [
|
||||
'CollectionMethod' => 'collection_method',
|
||||
'Additive' => 'additive',
|
||||
'SpecimenRole' => 'specimen_role',
|
||||
]);
|
||||
|
||||
return $this->respond([ 'status' => 'success', 'message'=> "data fetched successfully", 'data' => $rows ], 200);
|
||||
} catch (\Exception $e) {
|
||||
return $this->failServerError('Exception : '.$e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
public function show($id) {
|
||||
try {
|
||||
$row = $this->model->where('SpcColID', $id)->first();
|
||||
if (empty($row)) {
|
||||
return $this->respond([ 'status' => 'success', 'message'=> "data not found", 'data' => null ], 200);
|
||||
}
|
||||
|
||||
$row = ValueSet::transformLabels([$row], [
|
||||
'CollectionMethod' => 'collection_method',
|
||||
'Additive' => 'additive',
|
||||
'SpecimenRole' => 'specimen_role',
|
||||
])[0];
|
||||
|
||||
return $this->respond([ 'status' => 'success', 'message'=> "data fetched successfully", 'data' => $row ], 200);
|
||||
} catch (\Exception $e) {
|
||||
return $this->failServerError('Exception : '.$e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
public function create() {
|
||||
$input = $this->request->getJSON(true);
|
||||
if (!$this->validateData($input, $this->rules)) { return $this->failValidationErrors($this->validator->getErrors()); }
|
||||
try {
|
||||
$id = $this->model->insert($input);
|
||||
return $this->respondCreated([ 'status' => 'success', 'message' => "data $id created successfully" ]);
|
||||
} catch (\Exception $e) {
|
||||
return $this->failServerError('Something went wrong: ' . $e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
public function update($SpcColID = null) {
|
||||
$input = $this->requirePatchPayload($this->request->getJSON(true));
|
||||
if ($input === null) {
|
||||
return;
|
||||
}
|
||||
|
||||
$id = $this->requirePatchId($SpcColID, 'SpcColID');
|
||||
if ($id === null) {
|
||||
return;
|
||||
}
|
||||
protected $db;
|
||||
protected $model;
|
||||
protected $rules;
|
||||
|
||||
$existing = $this->model->where('SpcColID', $id)->first();
|
||||
if (!$existing) {
|
||||
return $this->respond([ 'status' => 'failed', 'message' => 'Specimen collection not found', 'data' => [] ], 404);
|
||||
}
|
||||
public function __construct() {
|
||||
$this->db = \Config\Database::connect();
|
||||
$this->model = new SpecimenCollectionModel();
|
||||
$this->rules = [];
|
||||
}
|
||||
|
||||
$input['SpcColID'] = $id;
|
||||
if ($this->rules !== [] && !$this->validateData($input, $this->rules)) {
|
||||
return $this->failValidationErrors($this->validator->getErrors());
|
||||
}
|
||||
public function index() {
|
||||
try {
|
||||
$this->model->update($id, $input);
|
||||
return $this->respondCreated([ 'status' => 'success', 'message' => 'data updated successfully', 'data' => $id ], 201);
|
||||
$rows = $this->model->findAll();
|
||||
return $this->respond([ 'status' => 'success', 'message'=> "data fetched successfully", 'data' => $rows ], 200);
|
||||
} catch (\Exception $e) {
|
||||
return $this->failServerError('Exception : '.$e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
public function show($id) {
|
||||
try {
|
||||
$row = $this->model->where('SpcColID', $id)->first();
|
||||
if (empty($row)) {
|
||||
return $this->respond([ 'status' => 'success', 'message'=> "data not found", 'data' => null ], 200);
|
||||
}
|
||||
return $this->respond([ 'status' => 'success', 'message'=> "data fetched successfully", 'data' => $row ], 200);
|
||||
} catch (\Exception $e) {
|
||||
return $this->failServerError('Exception : '.$e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
public function create() {
|
||||
$input = $this->request->getJSON(true);
|
||||
if (!$this->validateData($input, $this->rules)) { return $this->failValidationErrors($this->validator->getErrors()); }
|
||||
try {
|
||||
$id = $this->model->insert($input);
|
||||
return $this->respondCreated([ 'status' => 'success', 'message' => "data $id created successfully" ]);
|
||||
} catch (\Exception $e) {
|
||||
return $this->failServerError('Something went wrong: ' . $e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public function update() {
|
||||
$input = $this->request->getJSON(true);
|
||||
if (!$this->validateData($input, $this->rules)) { return $this->failValidationErrors($this->validator->getErrors()); }
|
||||
try {
|
||||
$id = $this->model->update($input['SpcColID'], $input);
|
||||
return $this->respondCreated([ 'status' => 'success', 'message' => "data $id updated successfully" ]);
|
||||
} catch (\Exception $e) {
|
||||
return $this->failServerError('Something went wrong: ' . $e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
182
app/Controllers/Specimen/SpecimenController.php
Executable file → Normal file
182
app/Controllers/Specimen/SpecimenController.php
Executable file → Normal file
@ -1,143 +1,65 @@
|
||||
<?php
|
||||
|
||||
namespace App\Controllers\Specimen;
|
||||
|
||||
use App\Traits\PatchValidationTrait;
|
||||
use App\Traits\ResponseTrait;
|
||||
<?php
|
||||
|
||||
namespace App\Controllers\Specimen;
|
||||
|
||||
use CodeIgniter\API\ResponseTrait;
|
||||
use App\Controllers\BaseController;
|
||||
use App\Libraries\ValueSet;
|
||||
use App\Models\Specimen\SpecimenModel;
|
||||
|
||||
|
||||
class SpecimenController extends BaseController {
|
||||
use ResponseTrait;
|
||||
use PatchValidationTrait;
|
||||
|
||||
protected $db;
|
||||
protected $model;
|
||||
protected $rules;
|
||||
|
||||
public function __construct() {
|
||||
$this->db = \Config\Database::connect();
|
||||
$this->model = new SpecimenModel();
|
||||
$this->rules = [];
|
||||
}
|
||||
|
||||
public function index() {
|
||||
try {
|
||||
$rows = $this->model->findAll();
|
||||
|
||||
$rows = ValueSet::transformLabels($rows, [
|
||||
'SpecimenType' => 'specimen_type',
|
||||
'SpecimenStatus' => 'specimen_status',
|
||||
'BodySite' => 'body_site',
|
||||
]);
|
||||
|
||||
return $this->respond([ 'status' => 'success', 'message'=> "data fetched successfully", 'data' => $rows ], 200);
|
||||
} catch (\Exception $e) {
|
||||
return $this->failServerError('Exception : '.$e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
public function show($id) {
|
||||
try {
|
||||
$row = $this->model->where('SID',$id)->first();
|
||||
if (empty($row)) {
|
||||
return $this->respond([ 'status' => 'success', 'message'=> "data not found", 'data' => null ], 200);
|
||||
}
|
||||
|
||||
$row = ValueSet::transformLabels([$row], [
|
||||
'SpecimenType' => 'specimen_type',
|
||||
'SpecimenStatus' => 'specimen_status',
|
||||
'BodySite' => 'body_site',
|
||||
])[0];
|
||||
|
||||
return $this->respond([ 'status' => 'success', 'message'=> "data fetched successfully", 'data' => $row ], 200);
|
||||
} catch (\Exception $e) {
|
||||
return $this->failServerError('Exception : '.$e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
public function create() {
|
||||
$input = $this->request->getJSON(true);
|
||||
if (!$this->validateData($input, $this->rules)) { return $this->failValidationErrors($this->validator->getErrors()); }
|
||||
try {
|
||||
$id = $this->model->insert($input);
|
||||
return $this->respondCreated([ 'status' => 'success', 'message' => "data $id created successfully" ]);
|
||||
} catch (\Exception $e) {
|
||||
return $this->failServerError('Something went wrong: ' . $e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
public function update($SID = null) {
|
||||
$input = $this->requirePatchPayload($this->request->getJSON(true));
|
||||
if ($input === null) {
|
||||
return;
|
||||
}
|
||||
|
||||
$id = $this->requirePatchId($SID, 'SID');
|
||||
if ($id === null) {
|
||||
return;
|
||||
}
|
||||
protected $db;
|
||||
protected $model;
|
||||
protected $rules;
|
||||
|
||||
$existing = $this->model->where('SID', $id)->first();
|
||||
if (!$existing) {
|
||||
return $this->respond([ 'status' => 'failed', 'message' => 'Specimen not found', 'data' => [] ], 404);
|
||||
}
|
||||
public function __construct() {
|
||||
$this->db = \Config\Database::connect();
|
||||
$this->model = new SpecimenModel();
|
||||
$this->rules = [];
|
||||
}
|
||||
|
||||
$input['SID'] = $id;
|
||||
public function index() {
|
||||
try {
|
||||
$rows = $this->model->findAll();
|
||||
return $this->respond([ 'status' => 'success', 'message'=> "data fetched successfully", 'data' => $rows ], 200);
|
||||
} catch (\Exception $e) {
|
||||
return $this->failServerError('Exception : '.$e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
public function show($id) {
|
||||
try {
|
||||
$row = $this->model->where('SID',$id)->first();
|
||||
if (empty($row)) {
|
||||
return $this->respond([ 'status' => 'success', 'message'=> "data not found", 'data' => null ], 200);
|
||||
}
|
||||
return $this->respond([ 'status' => 'success', 'message'=> "data fetched successfully", 'data' => $row ], 200);
|
||||
} catch (\Exception $e) {
|
||||
return $this->failServerError('Exception : '.$e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
public function create() {
|
||||
$input = $this->request->getJSON(true);
|
||||
if (!$this->validateData($input, $this->rules)) { return $this->failValidationErrors($this->validator->getErrors()); }
|
||||
try {
|
||||
$this->model->update($id, $input);
|
||||
return $this->respond([ 'status' => 'success', 'message' => 'data updated successfully', 'data' => $id ], 200);
|
||||
$id = $this->model->insert($input);
|
||||
return $this->respondCreated([ 'status' => 'success', 'message' => "data $id created successfully" ]);
|
||||
} catch (\Exception $e) {
|
||||
return $this->failServerError('Something went wrong: ' . $e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete a specimen (soft delete)
|
||||
* DELETE /api/specimen/(:num)
|
||||
*/
|
||||
public function delete($id) {
|
||||
try {
|
||||
// Check if specimen exists
|
||||
$specimen = $this->model->where('SID', $id)->first();
|
||||
|
||||
if (empty($specimen)) {
|
||||
return $this->respond([
|
||||
'status' => 'failed',
|
||||
'message' => 'Specimen not found',
|
||||
'data' => null
|
||||
], 404);
|
||||
}
|
||||
|
||||
// Perform soft delete (set DelDate)
|
||||
$deleted = $this->model->update($id, [
|
||||
'DelDate' => date('Y-m-d H:i:s')
|
||||
]);
|
||||
|
||||
if (!$deleted) {
|
||||
return $this->respond([
|
||||
'status' => 'failed',
|
||||
'message' => 'Failed to delete specimen',
|
||||
'data' => null
|
||||
], 500);
|
||||
}
|
||||
|
||||
return $this->respond([
|
||||
'status' => 'success',
|
||||
'message' => 'Specimen deleted successfully',
|
||||
'data' => ['SID' => $id]
|
||||
], 200);
|
||||
|
||||
} catch (\Exception $e) {
|
||||
log_message('error', 'SpecimenController::delete error: ' . $e->getMessage());
|
||||
return $this->respond([
|
||||
'status' => 'failed',
|
||||
'message' => 'Failed to delete specimen',
|
||||
'data' => null
|
||||
], 500);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public function update() {
|
||||
$input = $this->request->getJSON(true);
|
||||
if (!$this->validateData($input, $this->rules)) { return $this->failValidationErrors($this->validator->getErrors()); }
|
||||
try {
|
||||
$id = $this->model->update($input['SID'], $input);
|
||||
return $this->respondCreated([ 'status' => 'success', 'message' => "data $id updated successfully" ]);
|
||||
} catch (\Exception $e) {
|
||||
return $this->failServerError('Something went wrong: ' . $e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
125
app/Controllers/Specimen/SpecimenPrepController.php
Executable file → Normal file
125
app/Controllers/Specimen/SpecimenPrepController.php
Executable file → Normal file
@ -1,84 +1,65 @@
|
||||
<?php
|
||||
|
||||
namespace App\Controllers\Specimen;
|
||||
|
||||
use App\Traits\PatchValidationTrait;
|
||||
use App\Traits\ResponseTrait;
|
||||
<?php
|
||||
|
||||
namespace App\Controllers\Specimen;
|
||||
|
||||
use CodeIgniter\API\ResponseTrait;
|
||||
use App\Controllers\BaseController;
|
||||
use App\Models\Specimen\SpecimenPrepModel;
|
||||
|
||||
|
||||
class SpecimenPrepController extends BaseController {
|
||||
use ResponseTrait;
|
||||
use PatchValidationTrait;
|
||||
|
||||
protected $db;
|
||||
protected $model;
|
||||
protected $rules;
|
||||
|
||||
public function __construct() {
|
||||
$this->db = \Config\Database::connect();
|
||||
$this->model = new SpecimenPrepModel();
|
||||
$this->rules = [];
|
||||
}
|
||||
|
||||
public function index() {
|
||||
try {
|
||||
$rows = $this->model->findAll();
|
||||
return $this->respond([ 'status' => 'success', 'message'=> "data fetched successfully", 'data' => $rows ], 200);
|
||||
} catch (\Exception $e) {
|
||||
return $this->failServerError('Exception : '.$e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
public function show($id) {
|
||||
try {
|
||||
$row = $this->model->where('SpcPrpID', $id)->first();
|
||||
if (empty($row)) {
|
||||
return $this->respond([ 'status' => 'success', 'message'=> "data not found", 'data' => null ], 200);
|
||||
}
|
||||
return $this->respond([ 'status' => 'success', 'message'=> "data fetched successfully", 'data' => $row ], 200);
|
||||
} catch (\Exception $e) {
|
||||
return $this->failServerError('Exception : '.$e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
public function create() {
|
||||
$input = $this->request->getJSON(true);
|
||||
if (!$this->validateData($input, $this->rules)) { return $this->failValidationErrors($this->validator->getErrors()); }
|
||||
try {
|
||||
$id = $this->model->insert($input);
|
||||
return $this->respondCreated([ 'status' => 'success', 'message' => "data $id created successfully" ]);
|
||||
} catch (\Exception $e) {
|
||||
return $this->failServerError('Something went wrong: ' . $e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
public function update($SpcPrpID = null) {
|
||||
$input = $this->requirePatchPayload($this->request->getJSON(true));
|
||||
if ($input === null) {
|
||||
return;
|
||||
}
|
||||
|
||||
$id = $this->requirePatchId($SpcPrpID, 'SpcPrpID');
|
||||
if ($id === null) {
|
||||
return;
|
||||
}
|
||||
protected $db;
|
||||
protected $model;
|
||||
protected $rules;
|
||||
|
||||
$existing = $this->model->where('SpcPrpID', $id)->first();
|
||||
if (!$existing) {
|
||||
return $this->respond([ 'status' => 'failed', 'message' => 'Specimen prep not found', 'data' => [] ], 404);
|
||||
}
|
||||
public function __construct() {
|
||||
$this->db = \Config\Database::connect();
|
||||
$this->model = new SpecimenPrepModel();
|
||||
$this->rules = [];
|
||||
}
|
||||
|
||||
$input['SpcPrpID'] = $id;
|
||||
if ($this->rules !== [] && !$this->validateData($input, $this->rules)) {
|
||||
return $this->failValidationErrors($this->validator->getErrors());
|
||||
}
|
||||
public function index() {
|
||||
try {
|
||||
$this->model->update($id, $input);
|
||||
return $this->respondCreated([ 'status' => 'success', 'message' => 'data updated successfully', 'data' => $id ], 201);
|
||||
$rows = $this->model->findAll();
|
||||
return $this->respond([ 'status' => 'success', 'message'=> "data fetched successfully", 'data' => $rows ], 200);
|
||||
} catch (\Exception $e) {
|
||||
return $this->failServerError('Exception : '.$e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
public function show($id) {
|
||||
try {
|
||||
$row = $this->model->where('SpcPrpID', $id)->first();
|
||||
if (empty($row)) {
|
||||
return $this->respond([ 'status' => 'success', 'message'=> "data not found", 'data' => null ], 200);
|
||||
}
|
||||
return $this->respond([ 'status' => 'success', 'message'=> "data fetched successfully", 'data' => $row ], 200);
|
||||
} catch (\Exception $e) {
|
||||
return $this->failServerError('Exception : '.$e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
public function create() {
|
||||
$input = $this->request->getJSON(true);
|
||||
if (!$this->validateData($input, $this->rules)) { return $this->failValidationErrors($this->validator->getErrors()); }
|
||||
try {
|
||||
$id = $this->model->insert($input);
|
||||
return $this->respondCreated([ 'status' => 'success', 'message' => "data $id created successfully" ]);
|
||||
} catch (\Exception $e) {
|
||||
return $this->failServerError('Something went wrong: ' . $e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public function update() {
|
||||
$input = $this->request->getJSON(true);
|
||||
if (!$this->validateData($input, $this->rules)) { return $this->failValidationErrors($this->validator->getErrors()); }
|
||||
try {
|
||||
$id = $this->model->update($input['SpcPrpID'], $input);
|
||||
return $this->respondCreated([ 'status' => 'success', 'message' => "data $id updated successfully" ]);
|
||||
} catch (\Exception $e) {
|
||||
return $this->failServerError('Something went wrong: ' . $e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
140
app/Controllers/Specimen/SpecimenStatusController.php
Executable file → Normal file
140
app/Controllers/Specimen/SpecimenStatusController.php
Executable file → Normal file
@ -1,97 +1,65 @@
|
||||
<?php
|
||||
|
||||
namespace App\Controllers\Specimen;
|
||||
|
||||
use App\Traits\PatchValidationTrait;
|
||||
use App\Traits\ResponseTrait;
|
||||
<?php
|
||||
|
||||
namespace App\Controllers\Specimen;
|
||||
|
||||
use CodeIgniter\API\ResponseTrait;
|
||||
use App\Controllers\BaseController;
|
||||
use App\Libraries\ValueSet;
|
||||
use App\Models\Specimen\SpecimenStatusModel;
|
||||
|
||||
class SpecimenStatusController extends BaseController {
|
||||
|
||||
class ContainerDef extends BaseController {
|
||||
use ResponseTrait;
|
||||
use PatchValidationTrait;
|
||||
|
||||
protected $db;
|
||||
protected $model;
|
||||
protected $rules;
|
||||
|
||||
public function __construct() {
|
||||
$this->db = \Config\Database::connect();
|
||||
$this->model = new SpecimenStatusModel();
|
||||
$this->rules = [];
|
||||
}
|
||||
|
||||
public function index() {
|
||||
try {
|
||||
$rows = $this->model->findAll();
|
||||
|
||||
$rows = ValueSet::transformLabels($rows, [
|
||||
'Status' => 'specimen_status',
|
||||
'Activity' => 'specimen_activity',
|
||||
]);
|
||||
|
||||
return $this->respond([ 'status' => 'success', 'message'=> "data fetched successfully", 'data' => $rows ], 200);
|
||||
} catch (\Exception $e) {
|
||||
return $this->failServerError('Exception : '.$e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
public function show($id) {
|
||||
try {
|
||||
$row = $this->model->where('SpcStaID', $id)->first();
|
||||
if (empty($row)) {
|
||||
return $this->respond([ 'status' => 'success', 'message'=> "data not found", 'data' => null ], 200);
|
||||
}
|
||||
|
||||
$row = ValueSet::transformLabels([$row], [
|
||||
'Status' => 'specimen_status',
|
||||
'Activity' => 'specimen_activity',
|
||||
])[0];
|
||||
|
||||
return $this->respond([ 'status' => 'success', 'message'=> "data fetched successfully", 'data' => $row ], 200);
|
||||
} catch (\Exception $e) {
|
||||
return $this->failServerError('Exception : '.$e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
public function create() {
|
||||
$input = $this->request->getJSON(true);
|
||||
if (!$this->validateData($input, $this->rules)) { return $this->failValidationErrors($this->validator->getErrors()); }
|
||||
try {
|
||||
$id = $this->model->insert($input);
|
||||
return $this->respondCreated([ 'status' => 'success', 'message' => "data $id created successfully" ]);
|
||||
} catch (\Exception $e) {
|
||||
return $this->failServerError('Something went wrong: ' . $e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
public function update($SpcStaID = null) {
|
||||
$input = $this->requirePatchPayload($this->request->getJSON(true));
|
||||
if ($input === null) {
|
||||
return;
|
||||
}
|
||||
|
||||
$id = $this->requirePatchId($SpcStaID, 'SpcStaID');
|
||||
if ($id === null) {
|
||||
return;
|
||||
}
|
||||
protected $db;
|
||||
protected $model;
|
||||
protected $rules;
|
||||
|
||||
$existing = $this->model->where('SpcStaID', $id)->first();
|
||||
if (!$existing) {
|
||||
return $this->respond([ 'status' => 'failed', 'message' => 'Specimen status not found', 'data' => [] ], 404);
|
||||
}
|
||||
public function __construct() {
|
||||
$this->db = \Config\Database::connect();
|
||||
$this->model = new SpecimenStatusModel();
|
||||
$this->rules = [];
|
||||
}
|
||||
|
||||
$input['SpcStaID'] = $id;
|
||||
if ($this->rules !== [] && !$this->validateData($input, $this->rules)) {
|
||||
return $this->failValidationErrors($this->validator->getErrors());
|
||||
}
|
||||
public function index() {
|
||||
try {
|
||||
$this->model->update($id, $input);
|
||||
return $this->respondCreated([ 'status' => 'success', 'message' => 'data updated successfully', 'data' => $id ], 201);
|
||||
$rows = $this->model->findAll();
|
||||
return $this->respond([ 'status' => 'success', 'message'=> "data fetched successfully", 'data' => $rows ], 200);
|
||||
} catch (\Exception $e) {
|
||||
return $this->failServerError('Exception : '.$e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
public function show($id) {
|
||||
try {
|
||||
$row = $this->model->where('SpcStaID', $id)->first();
|
||||
if (empty($row)) {
|
||||
return $this->respond([ 'status' => 'success', 'message'=> "data not found", 'data' => null ], 200);
|
||||
}
|
||||
return $this->respond([ 'status' => 'success', 'message'=> "data fetched successfully", 'data' => $row ], 200);
|
||||
} catch (\Exception $e) {
|
||||
return $this->failServerError('Exception : '.$e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
public function create() {
|
||||
$input = $this->request->getJSON(true);
|
||||
if (!$this->validateData($input, $this->rules)) { return $this->failValidationErrors($this->validator->getErrors()); }
|
||||
try {
|
||||
$id = $this->model->insert($input);
|
||||
return $this->respondCreated([ 'status' => 'success', 'message' => "data $id created successfully" ]);
|
||||
} catch (\Exception $e) {
|
||||
return $this->failServerError('Something went wrong: ' . $e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public function update() {
|
||||
$input = $this->request->getJSON(true);
|
||||
if (!$this->validateData($input, $this->rules)) { return $this->failValidationErrors($this->validator->getErrors()); }
|
||||
try {
|
||||
$id = $this->model->update($input['SpcStaID'], $input);
|
||||
return $this->respondCreated([ 'status' => 'success', 'message' => "data $id updated successfully" ]);
|
||||
} catch (\Exception $e) {
|
||||
return $this->failServerError('Something went wrong: ' . $e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
163
app/Controllers/Test/DemoOrderController.php
Executable file → Normal file
163
app/Controllers/Test/DemoOrderController.php
Executable file → Normal file
@ -1,85 +1,78 @@
|
||||
<?php
|
||||
namespace App\Controllers\Test;
|
||||
|
||||
use App\Traits\ResponseTrait;
|
||||
use CodeIgniter\Controller;
|
||||
use App\Libraries\ValueSet;
|
||||
use App\Models\Patient\PatientModel;
|
||||
use App\Models\OrderTestModel;
|
||||
|
||||
class DemoOrderController extends Controller {
|
||||
use ResponseTrait;
|
||||
|
||||
protected $db;
|
||||
protected $patientModel;
|
||||
protected $orderModel;
|
||||
|
||||
public function __construct() {
|
||||
$this->db = \Config\Database::connect();
|
||||
$this->patientModel = new PatientModel();
|
||||
$this->orderModel = new OrderTestModel();
|
||||
}
|
||||
|
||||
public function createDemoOrder() {
|
||||
$input = $this->request->getJSON(true);
|
||||
|
||||
$patientData = [
|
||||
'PatientID' => $input['PatientID'] ?? 'DEMO' . time(),
|
||||
'Gender' => $input['Gender'] ?? '1',
|
||||
'NameFirst' => $input['NameFirst'] ?? 'Demo',
|
||||
'NameLast' => $input['NameLast'] ?? 'Patient',
|
||||
'Birthdate' => $input['Birthdate'] ?? '1990-01-01'
|
||||
];
|
||||
|
||||
$patient = $this->patientModel->where('PatientID', $patientData['PatientID'])->findAll();
|
||||
if (empty($patient)) {
|
||||
$internalPID = $this->patientModel->createPatient($patientData);
|
||||
} else {
|
||||
$internalPID = $patient[0]['InternalPID'];
|
||||
}
|
||||
|
||||
$orderData = [
|
||||
'InternalPID' => $internalPID,
|
||||
'PatVisitID' => $input['PatVisitID'] ?? null,
|
||||
'Priority' => $input['Priority'] ?? 'R',
|
||||
'OrderingProvider' => $input['OrderingProvider'] ?? 'Dr. Demo',
|
||||
'DepartmentID' => $input['DepartmentID'] ?? 1,
|
||||
'Tests' => $input['Tests'] ?? []
|
||||
];
|
||||
|
||||
$orderID = $this->orderModel->createOrder($orderData);
|
||||
|
||||
return $this->respond([
|
||||
'status' => 'success',
|
||||
'message' => 'Demo order created successfully',
|
||||
'data' => [
|
||||
'PatientID' => $patientData['PatientID'],
|
||||
'InternalPID' => $internalPID,
|
||||
'OrderID' => $orderID,
|
||||
'OrderStatus' => 'ORD'
|
||||
]
|
||||
], 201);
|
||||
}
|
||||
|
||||
public function listDemoOrders() {
|
||||
$orders = $this->db->table('ordertest ot')
|
||||
->select('ot.OrderID, ot.InternalPID, p.PatientID, ot.OrderDateTime, ot.Priority, ot.OrderStatus')
|
||||
->join('patient p', 'p.InternalPID = ot.InternalPID')
|
||||
->where('ot.DelDate', null)
|
||||
->orderBy('ot.OrderDateTime', 'DESC')
|
||||
->limit(50)
|
||||
->get()
|
||||
->getResultArray();
|
||||
|
||||
$orders = ValueSet::transformLabels($orders, [
|
||||
'Priority' => 'order_priority',
|
||||
'OrderStatus' => 'order_status',
|
||||
]);
|
||||
|
||||
return $this->respond([
|
||||
'status' => 'success',
|
||||
'message' => 'Data fetched successfully',
|
||||
'data' => $orders
|
||||
], 200);
|
||||
}
|
||||
}
|
||||
<?php
|
||||
namespace App\Controllers\Test;
|
||||
|
||||
use CodeIgniter\API\ResponseTrait;
|
||||
use CodeIgniter\Controller;
|
||||
use App\Models\Patient\PatientModel;
|
||||
use App\Models\OrderTest\OrderTestModel;
|
||||
|
||||
class DemoOrderController extends Controller {
|
||||
use ResponseTrait;
|
||||
|
||||
protected $db;
|
||||
protected $patientModel;
|
||||
protected $orderModel;
|
||||
|
||||
public function __construct() {
|
||||
$this->db = \Config\Database::connect();
|
||||
$this->patientModel = new PatientModel();
|
||||
$this->orderModel = new OrderTestModel();
|
||||
}
|
||||
|
||||
public function createDemoOrder() {
|
||||
$input = $this->request->getJSON(true);
|
||||
|
||||
$patientData = [
|
||||
'PatientID' => $input['PatientID'] ?? 'DEMO' . time(),
|
||||
'Gender' => $input['Gender'] ?? '1',
|
||||
'NameFirst' => $input['NameFirst'] ?? 'Demo',
|
||||
'NameLast' => $input['NameLast'] ?? 'Patient',
|
||||
'Birthdate' => $input['Birthdate'] ?? '1990-01-01'
|
||||
];
|
||||
|
||||
$patient = $this->patientModel->where('PatientID', $patientData['PatientID'])->findAll();
|
||||
if (empty($patient)) {
|
||||
$internalPID = $this->patientModel->createPatient($patientData);
|
||||
} else {
|
||||
$internalPID = $patient[0]['InternalPID'];
|
||||
}
|
||||
|
||||
$orderData = [
|
||||
'InternalPID' => $internalPID,
|
||||
'PatVisitID' => $input['PatVisitID'] ?? null,
|
||||
'Priority' => $input['Priority'] ?? 'R',
|
||||
'OrderingProvider' => $input['OrderingProvider'] ?? 'Dr. Demo',
|
||||
'DepartmentID' => $input['DepartmentID'] ?? 1,
|
||||
];
|
||||
|
||||
$orderID = $this->orderModel->createOrder($orderData);
|
||||
|
||||
return $this->respond([
|
||||
'status' => 'success',
|
||||
'message' => 'Demo order created successfully',
|
||||
'data' => [
|
||||
'PatientID' => $patientData['PatientID'],
|
||||
'InternalPID' => $internalPID,
|
||||
'OrderID' => $orderID,
|
||||
'OrderStatus' => 'ORD'
|
||||
]
|
||||
], 201);
|
||||
}
|
||||
|
||||
public function listDemoOrders() {
|
||||
$orders = $this->db->table('ordertest ot')
|
||||
->select('ot.OrderID, ot.InternalPID, p.PatientID, ot.OrderDateTime, ot.Priority, ot.OrderStatus')
|
||||
->join('patient p', 'p.InternalPID = ot.InternalPID')
|
||||
->where('ot.DelDate', null)
|
||||
->orderBy('ot.OrderDateTime', 'DESC')
|
||||
->limit(50)
|
||||
->get()
|
||||
->getResultArray();
|
||||
|
||||
return $this->respond([
|
||||
'status' => 'success',
|
||||
'message' => 'Data fetched successfully',
|
||||
'data' => $orders
|
||||
], 200);
|
||||
}
|
||||
}
|
||||
|
||||
562
app/Controllers/Test/TestMapController.php
Executable file → Normal file
562
app/Controllers/Test/TestMapController.php
Executable file → Normal file
@ -1,570 +1,56 @@
|
||||
<?php
|
||||
namespace App\Controllers\Test;
|
||||
|
||||
use App\Traits\PatchValidationTrait;
|
||||
use App\Traits\ResponseTrait;
|
||||
<?php
|
||||
namespace App\Controllers\Test;
|
||||
|
||||
use CodeIgniter\API\ResponseTrait;
|
||||
use App\Controllers\BaseController;
|
||||
use App\Libraries\ValueSet;
|
||||
use App\Models\Test\TestMapModel;
|
||||
use App\Models\Test\TestMapDetailModel;
|
||||
|
||||
|
||||
class TestMapController extends BaseController {
|
||||
use ResponseTrait;
|
||||
use PatchValidationTrait;
|
||||
|
||||
|
||||
protected $db;
|
||||
protected $rules;
|
||||
protected $patchRules;
|
||||
protected $model;
|
||||
protected $modelDetail;
|
||||
protected array $headerFields = ['HostType', 'HostID', 'ClientType', 'ClientID'];
|
||||
protected array $detailFields = ['HostTestCode', 'HostTestName', 'ConDefID', 'ClientTestCode', 'ClientTestName'];
|
||||
protected array $detailRules;
|
||||
protected array $detailPatchRules;
|
||||
|
||||
public function __construct() {
|
||||
$this->db = \Config\Database::connect();
|
||||
|
||||
public function __construct() {
|
||||
$this->db = \Config\Database::connect();
|
||||
$this->model = new TestMapModel;
|
||||
$this->modelDetail = new TestMapDetailModel;
|
||||
$this->rules = [
|
||||
'HostID' => 'required|integer',
|
||||
'ClientID' => 'required|integer',
|
||||
];
|
||||
$this->patchRules = [
|
||||
'HostID' => 'permit_empty|integer',
|
||||
'ClientID' => 'permit_empty|integer',
|
||||
'HostType' => 'permit_empty|string',
|
||||
'ClientType' => 'permit_empty|string',
|
||||
];
|
||||
$this->detailRules = [
|
||||
'HostTestCode' => 'permit_empty|max_length[10]',
|
||||
'HostTestName' => 'permit_empty|max_length[100]',
|
||||
'ConDefID' => 'permit_empty|integer',
|
||||
'ClientTestCode' => 'permit_empty|max_length[10]',
|
||||
'ClientTestName' => 'permit_empty|max_length[100]',
|
||||
];
|
||||
$this->detailPatchRules = $this->detailRules;
|
||||
}
|
||||
|
||||
|
||||
public function index() {
|
||||
$rows = $this->model->getUniqueGroupings();
|
||||
$rows = $this->applyIndexFilters($rows);
|
||||
$rows = $this->model->findAll();
|
||||
if (empty($rows)) { return $this->respond([ 'status' => 'success', 'message' => "no Data.", 'data' => [] ], 200); }
|
||||
|
||||
$rows = ValueSet::transformLabels($rows, [
|
||||
'HostType' => 'entity_type',
|
||||
'ClientType' => 'entity_type',
|
||||
]);
|
||||
|
||||
$rows = array_map([$this, 'sanitizeTopLevelPayload'], $rows);
|
||||
|
||||
return $this->respond([ 'status' => 'success', 'message'=> "Data fetched successfully", 'data' => $rows ], 200);
|
||||
return $this->respond([ 'status' => 'success', 'message'=> "Data fetched successfully", 'data' => $rows ], 200);
|
||||
}
|
||||
|
||||
|
||||
public function show($id = null) {
|
||||
$row = $this->model->getByIdWithNames($id);
|
||||
$row = $this->model->where('TestMapID',$id)->first();
|
||||
if (empty($row)) { return $this->respond([ 'status' => 'success', 'message' => "no Data.", 'data' => null ], 200); }
|
||||
|
||||
$row = ValueSet::transformLabels([$row], [
|
||||
'HostType' => 'entity_type',
|
||||
'ClientType' => 'entity_type',
|
||||
])[0];
|
||||
return $this->respond([ 'status' => 'success', 'message'=> "Data fetched successfully", 'data' => $row ], 200);
|
||||
}
|
||||
|
||||
$row = $this->sanitizeTopLevelPayload($row);
|
||||
|
||||
// Include testmapdetail records
|
||||
$row['details'] = $this->modelDetail->getDetailsByTestMap($id);
|
||||
|
||||
return $this->respond([ 'status' => 'success', 'message'=> "Data fetched successfully", 'data' => $row ], 200);
|
||||
}
|
||||
|
||||
public function create() {
|
||||
$input = $this->request->getJSON(true);
|
||||
$detailsPayload = null;
|
||||
if (array_key_exists('details', $input)) {
|
||||
$detailsPayload = $this->resolveDetailOperations($input['details']);
|
||||
if ($detailsPayload === null) { return; }
|
||||
}
|
||||
|
||||
$headerInput = array_intersect_key($input, array_flip($this->headerFields));
|
||||
if (!$this->validateData($headerInput, $this->rules)) {
|
||||
log_message('error', 'TestMap create validation failed: ' . json_encode($this->validator->getErrors()));
|
||||
return $this->failValidationErrors($this->validator->getErrors());
|
||||
}
|
||||
|
||||
$this->db->transStart();
|
||||
if (!$this->validateData($input, $this->rules)) { return $this->failValidationErrors($this->validator->getErrors()); }
|
||||
try {
|
||||
$id = $this->model->insert($headerInput);
|
||||
|
||||
if ($detailsPayload !== null && !empty($detailsPayload['created'])) {
|
||||
if (!$this->insertDetailRows($id, $detailsPayload['created'])) {
|
||||
$this->db->transRollback();
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
$this->db->transComplete();
|
||||
if ($this->db->transStatus() === false) {
|
||||
return $this->failServerError('Something went wrong while saving the test map.');
|
||||
}
|
||||
|
||||
$id = $this->model->insert($input);
|
||||
return $this->respondCreated([ 'status' => 'success', 'message' => "data created successfully", 'data' => $id ]);
|
||||
} catch (\Exception $e) {
|
||||
$this->db->transRollback();
|
||||
return $this->failServerError('Something went wrong: ' . $e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
public function update($TestMapID = null) {
|
||||
$input = $this->requirePatchPayload($this->request->getJSON(true));
|
||||
if ($input === null) {
|
||||
return;
|
||||
}
|
||||
|
||||
$detailsPayload = null;
|
||||
if (array_key_exists('details', $input)) {
|
||||
$detailsPayload = $this->resolveDetailOperations($input['details']);
|
||||
if ($detailsPayload === null) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
$id = $this->requirePatchId($TestMapID, 'TestMapID');
|
||||
if ($id === null) {
|
||||
return;
|
||||
}
|
||||
|
||||
$existing = $this->model->where('TestMapID', $id)->where('EndDate', null)->first();
|
||||
if (!$existing) {
|
||||
return $this->respond([ 'status' => 'failed', 'message' => 'Test map not found', 'data' => [] ], 404);
|
||||
}
|
||||
|
||||
if (isset($input['TestMapID']) && (string) $input['TestMapID'] !== (string) $id) {
|
||||
return $this->failValidationErrors('TestMapID in URL does not match body.');
|
||||
}
|
||||
|
||||
$validationInput = array_intersect_key($headerInput = array_intersect_key($input, array_flip($this->headerFields)), $this->patchRules);
|
||||
if (!empty($validationInput) && !$this->validateData($validationInput, $this->patchRules)) {
|
||||
return $this->failValidationErrors($this->validator->getErrors());
|
||||
}
|
||||
|
||||
$input['TestMapID'] = $id;
|
||||
$this->db->transStart();
|
||||
try {
|
||||
if (!empty($headerInput)) {
|
||||
$this->model->update($id, $headerInput);
|
||||
}
|
||||
|
||||
if ($detailsPayload !== null && !$this->applyDetailOperations($id, $detailsPayload)) {
|
||||
$this->db->transRollback();
|
||||
return;
|
||||
}
|
||||
|
||||
$this->db->transComplete();
|
||||
if ($this->db->transStatus() === false) {
|
||||
return $this->failServerError('Something went wrong while updating the test map.');
|
||||
}
|
||||
|
||||
return $this->respond([ 'status' => 'success', 'message' => 'data updated successfully', 'data' => $id ], 200);
|
||||
} catch (\Exception $e) {
|
||||
$this->db->transRollback();
|
||||
return $this->failServerError('Something went wrong: ' . $e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
public function delete() {
|
||||
public function update() {
|
||||
$input = $this->request->getJSON(true);
|
||||
$id = $input["TestMapID"] ?? null;
|
||||
$id = $input["TestMapID"];
|
||||
if (!$id) { return $this->failValidationErrors('TestMapID is required.'); }
|
||||
|
||||
if (!$this->validateData($input, $this->rules)) { return $this->failValidationErrors( $this->validator->getErrors() ); }
|
||||
try {
|
||||
$row = $this->model->where('TestMapID', $id)->where('EndDate', null)->first();
|
||||
if (empty($row)) { return $this->respond([ 'status' => 'failed', 'message' => "Data not found or already deleted.", 'data' => null ], 404); }
|
||||
|
||||
$this->db->transStart();
|
||||
$timestamp = date('Y-m-d H:i:s');
|
||||
$this->model->update($id, ['EndDate' => $timestamp]);
|
||||
|
||||
$this->modelDetail->where('TestMapID', $id)
|
||||
->where('EndDate', null)
|
||||
->set('EndDate', $timestamp)
|
||||
->update();
|
||||
|
||||
$this->db->transComplete();
|
||||
|
||||
if ($this->db->transStatus() === false) {
|
||||
return $this->failServerError('Something went wrong while deleting the test map.');
|
||||
}
|
||||
|
||||
return $this->respond([ 'status' => 'success', 'message' => "data deleted successfully", 'data' => $id ], 200);
|
||||
$this->model->update($id,$input);
|
||||
return $this->respondCreated([ 'status' => 'success', 'message' => "data updated successfully", 'data' => $id ]);
|
||||
} catch (\Exception $e) {
|
||||
return $this->failServerError('Something went wrong: ' . $e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
public function showByTestCode($testCode = null) {
|
||||
if (!$testCode) { return $this->failValidationErrors('TestCode is required.'); }
|
||||
|
||||
$rows = $this->model->getMappingsByTestCode($testCode);
|
||||
if (empty($rows)) { return $this->respond([ 'status' => 'success', 'message' => "no Data.", 'data' => [] ], 200); }
|
||||
|
||||
$rows = ValueSet::transformLabels($rows, [
|
||||
'HostType' => 'entity_type',
|
||||
'ClientType' => 'entity_type',
|
||||
]);
|
||||
|
||||
$rows = array_map([$this, 'sanitizeTopLevelPayload'], $rows);
|
||||
|
||||
return $this->respond([ 'status' => 'success', 'message'=> "Data fetched successfully", 'data' => $rows ], 200);
|
||||
}
|
||||
|
||||
private function sanitizeTopLevelPayload(array $row): array
|
||||
{
|
||||
unset($row['TestCode'], $row['testcode']);
|
||||
return $row;
|
||||
}
|
||||
|
||||
private function applyIndexFilters(array $rows): array
|
||||
{
|
||||
$hostFilter = trim((string) $this->request->getGet('host'));
|
||||
$clientFilter = trim((string) $this->request->getGet('client'));
|
||||
|
||||
if ($hostFilter === '' && $clientFilter === '') {
|
||||
return $rows;
|
||||
}
|
||||
|
||||
return array_values(array_filter($rows, function (array $row) use ($hostFilter, $clientFilter): bool {
|
||||
if ($hostFilter !== '' && !$this->matchesSearch($row, 'Host', $hostFilter)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if ($clientFilter !== '' && !$this->matchesSearch($row, 'Client', $clientFilter)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}));
|
||||
}
|
||||
|
||||
private function matchesSearch(array $row, string $prefix, string $filter): bool
|
||||
{
|
||||
$haystacks = [
|
||||
(string) ($row[$prefix . 'Name'] ?? ''),
|
||||
(string) ($row[$prefix . 'ID'] ?? ''),
|
||||
(string) ($row[$prefix . 'Type'] ?? ''),
|
||||
];
|
||||
|
||||
$needle = strtolower($filter);
|
||||
|
||||
foreach ($haystacks as $value) {
|
||||
if ($value !== '' && str_contains(strtolower($value), $needle)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
private function resolveDetailOperations(mixed $detailsPayload): ?array
|
||||
{
|
||||
if ($detailsPayload === null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
if (!is_array($detailsPayload)) {
|
||||
$this->failValidationErrors('details must be an array or object.');
|
||||
return null;
|
||||
}
|
||||
|
||||
if ($this->isDetailOpsPayload($detailsPayload)) {
|
||||
$createdItems = $this->normalizeDetailList($detailsPayload['created'] ?? [], 'details.created');
|
||||
if ($createdItems === null) { return null; }
|
||||
$editedItems = $this->normalizeDetailList($detailsPayload['edited'] ?? [], 'details.edited');
|
||||
if ($editedItems === null) { return null; }
|
||||
$deletedIds = $this->normalizeDetailIds($detailsPayload['deleted'] ?? []);
|
||||
if ($deletedIds === null) { return null; }
|
||||
|
||||
return ['created' => $createdItems, 'edited' => $editedItems, 'deleted' => $deletedIds];
|
||||
}
|
||||
|
||||
if ($this->isListPayload($detailsPayload)) {
|
||||
$items = $this->normalizeDetailList($detailsPayload, 'details');
|
||||
if ($items === null) { return null; }
|
||||
return ['created' => $items, 'edited' => [], 'deleted' => []];
|
||||
}
|
||||
|
||||
if ($this->isAssocArray($detailsPayload)) {
|
||||
$items = $this->normalizeDetailList([$detailsPayload], 'details');
|
||||
if ($items === null) { return null; }
|
||||
return ['created' => $items, 'edited' => [], 'deleted' => []];
|
||||
}
|
||||
|
||||
$this->failValidationErrors('details must be an array of objects or contain created/edited/deleted arrays.');
|
||||
return null;
|
||||
}
|
||||
|
||||
private function applyDetailOperations(int $testMapID, array $operations): bool
|
||||
{
|
||||
if (!empty($operations['edited']) && !$this->updateDetails($testMapID, $operations['edited'])) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!empty($operations['deleted']) && !$this->softDeleteDetails($testMapID, $operations['deleted'])) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!empty($operations['created']) && !$this->insertDetailRows($testMapID, $operations['created'])) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
private function insertDetailRows(int $testMapID, array $items): bool
|
||||
{
|
||||
if (empty($items)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
$prepared = [];
|
||||
foreach ($items as $index => $item) {
|
||||
if (!$this->validateData($item, $this->detailRules)) {
|
||||
$this->failValidationErrors(['details.created' => $this->validator->getErrors()]);
|
||||
return false;
|
||||
}
|
||||
$prepared[] = array_merge(['TestMapID' => $testMapID], $item);
|
||||
}
|
||||
|
||||
$this->modelDetail->insertBatch($prepared);
|
||||
return true;
|
||||
}
|
||||
|
||||
private function updateDetails(int $testMapID, array $items): bool
|
||||
{
|
||||
foreach ($items as $index => $detail) {
|
||||
$detailID = $detail['TestMapDetailID'] ?? null;
|
||||
if (!$detailID || !ctype_digit((string) $detailID)) {
|
||||
$this->failValidationErrors("details.edited[{$index}].TestMapDetailID is required and must be an integer.");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (array_key_exists('TestMapID', $detail) && (int) $detail['TestMapID'] !== $testMapID) {
|
||||
$this->failValidationErrors("details.edited[{$index}] must belong to TestMap {$testMapID}.");
|
||||
return false;
|
||||
}
|
||||
|
||||
$existing = $this->modelDetail->where('TestMapDetailID', $detailID)
|
||||
->where('TestMapID', $testMapID)
|
||||
->where('EndDate', null)
|
||||
->first();
|
||||
|
||||
if (empty($existing)) {
|
||||
$this->failValidationErrors("Detail record {$detailID} not found for this test map.");
|
||||
return false;
|
||||
}
|
||||
|
||||
$updateData = array_intersect_key($detail, array_flip($this->detailFields));
|
||||
if ($updateData === []) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!$this->validateData($updateData, $this->detailPatchRules)) {
|
||||
$this->failValidationErrors($this->validator->getErrors());
|
||||
return false;
|
||||
}
|
||||
|
||||
$this->modelDetail->update($detailID, $updateData);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
private function softDeleteDetails(int $testMapID, array $ids): bool
|
||||
{
|
||||
if (empty($ids)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
$existing = $this->modelDetail->select('TestMapDetailID')
|
||||
->whereIn('TestMapDetailID', $ids)
|
||||
->where('TestMapID', $testMapID)
|
||||
->where('EndDate', null)
|
||||
->findAll();
|
||||
|
||||
$foundIds = array_column($existing, 'TestMapDetailID');
|
||||
$missing = array_diff($ids, $foundIds);
|
||||
if (!empty($missing)) {
|
||||
$this->failValidationErrors('Some detail IDs do not exist or belong to another test map: ' . implode(', ', $missing));
|
||||
return false;
|
||||
}
|
||||
|
||||
$this->modelDetail->whereIn('TestMapDetailID', $ids)
|
||||
->where('TestMapID', $testMapID)
|
||||
->where('EndDate', null)
|
||||
->set('EndDate', date('Y-m-d H:i:s'))
|
||||
->update();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
private function isDetailOpsPayload(array $payload): bool
|
||||
{
|
||||
return (bool) array_intersect(array_keys($payload), ['created', 'edited', 'deleted']);
|
||||
}
|
||||
|
||||
private function isListPayload(array $payload): bool
|
||||
{
|
||||
if ($payload === []) {
|
||||
return true;
|
||||
}
|
||||
return array_keys($payload) === range(0, count($payload) - 1);
|
||||
}
|
||||
|
||||
private function isAssocArray(array $payload): bool
|
||||
{
|
||||
if ($payload === []) {
|
||||
return false;
|
||||
}
|
||||
return array_keys($payload) !== range(0, count($payload) - 1);
|
||||
}
|
||||
|
||||
private function normalizeDetailList(mixed $value, string $fieldPath): ?array
|
||||
{
|
||||
if ($value === null) {
|
||||
return [];
|
||||
}
|
||||
|
||||
if (!is_array($value)) {
|
||||
$this->failValidationErrors("{$fieldPath} must be an array of objects.");
|
||||
return null;
|
||||
}
|
||||
|
||||
if ($value !== [] && $this->isAssocArray($value)) {
|
||||
$value = [$value];
|
||||
}
|
||||
|
||||
$results = [];
|
||||
foreach ($value as $index => $item) {
|
||||
if (!is_array($item)) {
|
||||
$this->failValidationErrors("{$fieldPath}[{$index}] must be an object.");
|
||||
return null;
|
||||
}
|
||||
$results[] = $item;
|
||||
}
|
||||
|
||||
return $results;
|
||||
}
|
||||
|
||||
private function normalizeDetailIds(mixed $value): ?array
|
||||
{
|
||||
if ($value === null) {
|
||||
return [];
|
||||
}
|
||||
|
||||
if (!is_array($value)) {
|
||||
$value = [$value];
|
||||
}
|
||||
|
||||
$results = [];
|
||||
foreach ($value as $index => $item) {
|
||||
if (!ctype_digit((string) $item)) {
|
||||
$this->failValidationErrors("details.deleted[{$index}] must be an integer.");
|
||||
return null;
|
||||
}
|
||||
$results[] = (int) $item;
|
||||
}
|
||||
|
||||
return array_values(array_unique($results));
|
||||
}
|
||||
|
||||
public function batchCreate() {
|
||||
$items = $this->request->getJSON(true);
|
||||
if (!is_array($items)) { return $this->failValidationErrors('Expected array of items'); }
|
||||
|
||||
$results = ['success' => [], 'failed' => []];
|
||||
$this->db->transStart();
|
||||
|
||||
foreach ($items as $index => $item) {
|
||||
if (!$this->validateData($item, $this->rules)) {
|
||||
$results['failed'][] = ['index' => $index, 'errors' => $this->validator->getErrors()];
|
||||
continue;
|
||||
}
|
||||
try {
|
||||
$id = $this->model->insert($item);
|
||||
$results['success'][] = ['index' => $index, 'TestMapID' => $id];
|
||||
} catch (\Exception $e) {
|
||||
$results['failed'][] = ['index' => $index, 'error' => $e->getMessage()];
|
||||
}
|
||||
}
|
||||
|
||||
$this->db->transComplete();
|
||||
return $this->respond([
|
||||
'status' => empty($results['failed']) ? 'success' : 'partial',
|
||||
'message' => 'Batch create completed',
|
||||
'data' => $results
|
||||
], 200);
|
||||
}
|
||||
|
||||
public function batchUpdate() {
|
||||
$items = $this->request->getJSON(true);
|
||||
if (!is_array($items)) { return $this->failValidationErrors('Expected array of items'); }
|
||||
|
||||
$results = ['success' => [], 'failed' => []];
|
||||
$this->db->transStart();
|
||||
|
||||
foreach ($items as $index => $item) {
|
||||
$id = $item['TestMapID'] ?? null;
|
||||
if (!$id) {
|
||||
$results['failed'][] = ['index' => $index, 'error' => 'TestMapID required'];
|
||||
continue;
|
||||
}
|
||||
if (!$this->validateData($item, $this->rules)) {
|
||||
$results['failed'][] = ['index' => $index, 'errors' => $this->validator->getErrors()];
|
||||
continue;
|
||||
}
|
||||
try {
|
||||
$this->model->update($id, $item);
|
||||
$results['success'][] = ['index' => $index, 'TestMapID' => $id];
|
||||
} catch (\Exception $e) {
|
||||
$results['failed'][] = ['index' => $index, 'error' => $e->getMessage()];
|
||||
}
|
||||
}
|
||||
|
||||
$this->db->transComplete();
|
||||
return $this->respond([
|
||||
'status' => empty($results['failed']) ? 'success' : 'partial',
|
||||
'message' => 'Batch update completed',
|
||||
'data' => $results
|
||||
], 200);
|
||||
}
|
||||
|
||||
public function batchDelete() {
|
||||
$ids = $this->request->getJSON(true);
|
||||
if (!is_array($ids)) { return $this->failValidationErrors('Expected array of TestMapIDs'); }
|
||||
|
||||
$results = ['success' => [], 'failed' => []];
|
||||
$this->db->transStart();
|
||||
|
||||
foreach ($ids as $id) {
|
||||
try {
|
||||
$row = $this->model->where('TestMapID', $id)->where('EndDate', null)->first();
|
||||
if (empty($row)) {
|
||||
$results['failed'][] = ['TestMapID' => $id, 'error' => 'Not found or already deleted'];
|
||||
continue;
|
||||
}
|
||||
$this->model->update($id, ['EndDate' => date('Y-m-d H:i:s')]);
|
||||
$results['success'][] = $id;
|
||||
} catch (\Exception $e) {
|
||||
$results['failed'][] = ['TestMapID' => $id, 'error' => $e->getMessage()];
|
||||
}
|
||||
}
|
||||
|
||||
$this->db->transComplete();
|
||||
return $this->respond([
|
||||
'status' => empty($results['failed']) ? 'success' : 'partial',
|
||||
'message' => 'Batch delete completed',
|
||||
'data' => $results
|
||||
], 200);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,286 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Controllers\Test;
|
||||
|
||||
use App\Controllers\BaseController;
|
||||
use App\Traits\PatchValidationTrait;
|
||||
use App\Traits\ResponseTrait;
|
||||
use App\Models\Test\TestMapDetailModel;
|
||||
|
||||
class TestMapDetailController extends BaseController {
|
||||
use ResponseTrait;
|
||||
use PatchValidationTrait;
|
||||
|
||||
protected $db;
|
||||
protected $rules;
|
||||
protected $patchRules;
|
||||
protected $model;
|
||||
|
||||
public function __construct() {
|
||||
$this->db = \Config\Database::connect();
|
||||
$this->model = new TestMapDetailModel;
|
||||
$this->rules = [
|
||||
'TestMapID' => 'required|integer',
|
||||
'HostTestCode' => 'permit_empty|max_length[10]',
|
||||
'HostTestName' => 'permit_empty|max_length[100]',
|
||||
'ConDefID' => 'permit_empty|integer',
|
||||
'ClientTestCode' => 'permit_empty|max_length[10]',
|
||||
'ClientTestName' => 'permit_empty|max_length[100]',
|
||||
];
|
||||
$this->patchRules = [
|
||||
'TestMapID' => 'permit_empty|integer',
|
||||
'HostTestCode' => 'permit_empty|max_length[10]',
|
||||
'HostTestName' => 'permit_empty|max_length[100]',
|
||||
'ConDefID' => 'permit_empty|integer',
|
||||
'ClientTestCode' => 'permit_empty|max_length[10]',
|
||||
'ClientTestName' => 'permit_empty|max_length[100]',
|
||||
];
|
||||
}
|
||||
|
||||
public function index() {
|
||||
$testMapID = $this->request->getGet('TestMapID');
|
||||
|
||||
if ($testMapID) {
|
||||
$rows = $this->model->getDetailsByTestMap($testMapID);
|
||||
} else {
|
||||
$rows = $this->model->where('EndDate', null)->findAll();
|
||||
}
|
||||
|
||||
if (empty($rows)) {
|
||||
return $this->respond([ 'status' => 'success', 'message' => "no Data.", 'data' => [] ], 200);
|
||||
}
|
||||
|
||||
return $this->respond([ 'status' => 'success', 'message'=> "Data fetched successfully", 'data' => $rows ], 200);
|
||||
}
|
||||
|
||||
public function show($id = null) {
|
||||
if (!$id) {
|
||||
return $this->failValidationErrors('TestMapDetailID is required.');
|
||||
}
|
||||
|
||||
$row = $this->model->where('TestMapDetailID', $id)->where('EndDate', null)->first();
|
||||
|
||||
if (empty($row)) {
|
||||
return $this->respond([ 'status' => 'success', 'message' => "no Data.", 'data' => null ], 200);
|
||||
}
|
||||
|
||||
return $this->respond([ 'status' => 'success', 'message'=> "Data fetched successfully", 'data' => $row ], 200);
|
||||
}
|
||||
|
||||
public function showByTestMap($testMapID = null) {
|
||||
if (!$testMapID) {
|
||||
return $this->failValidationErrors('TestMapID is required.');
|
||||
}
|
||||
|
||||
$rows = $this->model->getDetailsByTestMap($testMapID);
|
||||
|
||||
if (empty($rows)) {
|
||||
return $this->respond([ 'status' => 'success', 'message' => "no Data.", 'data' => [] ], 200);
|
||||
}
|
||||
|
||||
return $this->respond([ 'status' => 'success', 'message'=> "Data fetched successfully", 'data' => $rows ], 200);
|
||||
}
|
||||
|
||||
public function create() {
|
||||
$input = $this->request->getJSON(true);
|
||||
|
||||
if (!$this->validateData($input, $this->rules)) {
|
||||
return $this->failValidationErrors($this->validator->getErrors());
|
||||
}
|
||||
|
||||
try {
|
||||
$id = $this->model->insert($input);
|
||||
return $this->respondCreated([
|
||||
'status' => 'success',
|
||||
'message' => "data created successfully",
|
||||
'data' => $id
|
||||
]);
|
||||
} catch (\Exception $e) {
|
||||
return $this->failServerError('Something went wrong: ' . $e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
public function update($TestMapDetailID = null) {
|
||||
$input = $this->requirePatchPayload($this->request->getJSON(true));
|
||||
if ($input === null) {
|
||||
return;
|
||||
}
|
||||
|
||||
$id = $this->requirePatchId($TestMapDetailID, 'TestMapDetailID');
|
||||
if ($id === null) {
|
||||
return;
|
||||
}
|
||||
|
||||
$existing = $this->model->where('TestMapDetailID', $id)->where('EndDate', null)->first();
|
||||
if (!$existing) {
|
||||
return $this->respond([ 'status' => 'failed', 'message' => 'Test map detail not found', 'data' => [] ], 404);
|
||||
}
|
||||
|
||||
if (isset($input['TestMapDetailID']) && (string) $input['TestMapDetailID'] !== (string) $id) {
|
||||
return $this->failValidationErrors('TestMapDetailID in URL does not match body.');
|
||||
}
|
||||
|
||||
$input['TestMapDetailID'] = $id;
|
||||
$validationInput = array_intersect_key($input, $this->patchRules);
|
||||
if (!empty($validationInput) && !$this->validateData($validationInput, $this->patchRules)) {
|
||||
return $this->failValidationErrors($this->validator->getErrors());
|
||||
}
|
||||
|
||||
try {
|
||||
$this->model->update($id, $input);
|
||||
return $this->respond([
|
||||
'status' => 'success',
|
||||
'message' => 'data updated successfully',
|
||||
'data' => $id
|
||||
], 200);
|
||||
} catch (\Exception $e) {
|
||||
return $this->failServerError('Something went wrong: ' . $e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
public function delete() {
|
||||
$input = $this->request->getJSON(true);
|
||||
$id = $input["TestMapDetailID"] ?? null;
|
||||
|
||||
if (!$id) {
|
||||
return $this->failValidationErrors('TestMapDetailID is required.');
|
||||
}
|
||||
|
||||
try {
|
||||
$row = $this->model->where('TestMapDetailID', $id)->where('EndDate', null)->first();
|
||||
|
||||
if (empty($row)) {
|
||||
return $this->respond([
|
||||
'status' => 'failed',
|
||||
'message' => "Data not found or already deleted.",
|
||||
'data' => null
|
||||
], 404);
|
||||
}
|
||||
|
||||
$this->model->update($id, ['EndDate' => date('Y-m-d H:i:s')]);
|
||||
|
||||
return $this->respond([
|
||||
'status' => 'success',
|
||||
'message' => "data deleted successfully",
|
||||
'data' => $id
|
||||
], 200);
|
||||
} catch (\Exception $e) {
|
||||
return $this->failServerError('Something went wrong: ' . $e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
public function batchCreate() {
|
||||
$items = $this->request->getJSON(true);
|
||||
|
||||
if (!is_array($items)) {
|
||||
return $this->failValidationErrors('Expected array of items');
|
||||
}
|
||||
|
||||
$results = ['success' => [], 'failed' => []];
|
||||
$this->db->transStart();
|
||||
|
||||
foreach ($items as $index => $item) {
|
||||
if (!$this->validateData($item, $this->rules)) {
|
||||
$results['failed'][] = ['index' => $index, 'errors' => $this->validator->getErrors()];
|
||||
continue;
|
||||
}
|
||||
try {
|
||||
$id = $this->model->insert($item);
|
||||
$results['success'][] = ['index' => $index, 'TestMapDetailID' => $id];
|
||||
} catch (\Exception $e) {
|
||||
$results['failed'][] = ['index' => $index, 'error' => $e->getMessage()];
|
||||
}
|
||||
}
|
||||
|
||||
$this->db->transComplete();
|
||||
|
||||
return $this->respond([
|
||||
'status' => empty($results['failed']) ? 'success' : 'partial',
|
||||
'message' => 'Batch create completed',
|
||||
'data' => $results
|
||||
], 200);
|
||||
}
|
||||
|
||||
public function batchUpdate() {
|
||||
$items = $this->request->getJSON(true);
|
||||
|
||||
if (!is_array($items)) {
|
||||
return $this->failValidationErrors('Expected array of items');
|
||||
}
|
||||
|
||||
$results = ['success' => [], 'failed' => []];
|
||||
$this->db->transStart();
|
||||
|
||||
foreach ($items as $index => $item) {
|
||||
$id = $item['TestMapDetailID'] ?? null;
|
||||
|
||||
if (!$id) {
|
||||
$results['failed'][] = ['index' => $index, 'error' => 'TestMapDetailID required'];
|
||||
continue;
|
||||
}
|
||||
|
||||
$updateData = $item;
|
||||
unset($updateData['TestMapDetailID']);
|
||||
|
||||
if ($updateData === []) {
|
||||
$results['failed'][] = ['index' => $index, 'error' => 'No fields to update'];
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!$this->validateData($updateData, $this->patchRules)) {
|
||||
$results['failed'][] = ['index' => $index, 'errors' => $this->validator->getErrors()];
|
||||
continue;
|
||||
}
|
||||
|
||||
try {
|
||||
$this->model->update($id, $updateData);
|
||||
$results['success'][] = ['index' => $index, 'TestMapDetailID' => $id];
|
||||
} catch (\Exception $e) {
|
||||
$results['failed'][] = ['index' => $index, 'error' => $e->getMessage()];
|
||||
}
|
||||
}
|
||||
|
||||
$this->db->transComplete();
|
||||
|
||||
return $this->respond([
|
||||
'status' => empty($results['failed']) ? 'success' : 'partial',
|
||||
'message' => 'Batch update completed',
|
||||
'data' => $results
|
||||
], 200);
|
||||
}
|
||||
|
||||
public function batchDelete() {
|
||||
$ids = $this->request->getJSON(true);
|
||||
|
||||
if (!is_array($ids)) {
|
||||
return $this->failValidationErrors('Expected array of TestMapDetailIDs');
|
||||
}
|
||||
|
||||
$results = ['success' => [], 'failed' => []];
|
||||
$this->db->transStart();
|
||||
|
||||
foreach ($ids as $id) {
|
||||
try {
|
||||
$row = $this->model->where('TestMapDetailID', $id)->where('EndDate', null)->first();
|
||||
|
||||
if (empty($row)) {
|
||||
$results['failed'][] = ['TestMapDetailID' => $id, 'error' => 'Not found or already deleted'];
|
||||
continue;
|
||||
}
|
||||
|
||||
$this->model->update($id, ['EndDate' => date('Y-m-d H:i:s')]);
|
||||
$results['success'][] = $id;
|
||||
} catch (\Exception $e) {
|
||||
$results['failed'][] = ['TestMapDetailID' => $id, 'error' => $e->getMessage()];
|
||||
}
|
||||
}
|
||||
|
||||
$this->db->transComplete();
|
||||
|
||||
return $this->respond([
|
||||
'status' => empty($results['failed']) ? 'success' : 'partial',
|
||||
'message' => 'Batch delete completed',
|
||||
'data' => $results
|
||||
], 200);
|
||||
}
|
||||
}
|
||||
@ -1,735 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Controllers\Test;
|
||||
|
||||
use App\Controllers\BaseController;
|
||||
use App\Libraries\TestValidationService;
|
||||
use App\Libraries\ValueSet;
|
||||
use App\Traits\PatchValidationTrait;
|
||||
use App\Traits\ResponseTrait;
|
||||
|
||||
class TestsController extends BaseController
|
||||
{
|
||||
use ResponseTrait;
|
||||
use PatchValidationTrait;
|
||||
|
||||
protected $model;
|
||||
protected $modelCal;
|
||||
protected $modelGrp;
|
||||
protected $modelMap;
|
||||
protected $modelMapDetail;
|
||||
protected $modelRefNum;
|
||||
protected $modelRefTxt;
|
||||
protected $rules;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->model = new \App\Models\Test\TestDefSiteModel;
|
||||
$this->modelCal = new \App\Models\Test\TestDefCalModel;
|
||||
$this->modelGrp = new \App\Models\Test\TestDefGrpModel;
|
||||
$this->modelMap = new \App\Models\Test\TestMapModel;
|
||||
$this->modelMapDetail = new \App\Models\Test\TestMapDetailModel;
|
||||
$this->modelRefNum = new \App\Models\RefRange\RefNumModel;
|
||||
$this->modelRefTxt = new \App\Models\RefRange\RefTxtModel;
|
||||
|
||||
$this->rules = [
|
||||
'TestSiteCode' => 'required',
|
||||
'TestSiteName' => 'required',
|
||||
'TestType' => 'required',
|
||||
];
|
||||
}
|
||||
|
||||
public function index()
|
||||
{
|
||||
$search = $this->request->getGet('search');
|
||||
|
||||
$filters = [
|
||||
'SiteID' => $this->request->getGet('SiteID'),
|
||||
'TestType' => $this->request->getGet('TestType'),
|
||||
'isVisibleScr' => $this->request->getGet('isVisibleScr'),
|
||||
'isVisibleRpt' => $this->request->getGet('isVisibleRpt'),
|
||||
'TestSiteName' => $this->request->getGet('TestSiteName'),
|
||||
'TestSiteCode' => $this->request->getGet('TestSiteCode'),
|
||||
'search' => $search,
|
||||
];
|
||||
|
||||
$rows = $this->model->getTestsWithRelations($filters);
|
||||
|
||||
if (empty($rows)) {
|
||||
return $this->respond([
|
||||
'status' => 'success',
|
||||
'message' => 'No data.',
|
||||
'data' => [],
|
||||
], 200);
|
||||
}
|
||||
|
||||
$rows = ValueSet::transformLabels($rows, [
|
||||
'TestType' => 'test_type',
|
||||
]);
|
||||
|
||||
return $this->respond([
|
||||
'status' => 'success',
|
||||
'message' => 'Data fetched successfully',
|
||||
'data' => $rows,
|
||||
], 200);
|
||||
}
|
||||
|
||||
public function show($id = null)
|
||||
{
|
||||
if (!$id) {
|
||||
return $this->failValidationErrors('TestSiteID is required');
|
||||
}
|
||||
|
||||
$row = $this->model->getTestById($id);
|
||||
|
||||
if (!$row) {
|
||||
return $this->respond([
|
||||
'status' => 'success',
|
||||
'message' => 'No data.',
|
||||
'data' => null,
|
||||
], 200);
|
||||
}
|
||||
|
||||
$typeCode = $row['TestType'] ?? '';
|
||||
|
||||
if ($typeCode === 'CALC') {
|
||||
$row['testdefcal'] = $this->modelCal->getByTestSiteID($id);
|
||||
$row['testdefgrp'] = [
|
||||
'members' => $this->modelGrp->getGroupMembers($id),
|
||||
];
|
||||
} elseif ($typeCode === 'GROUP') {
|
||||
$row['testdefgrp'] = [
|
||||
'members' => $this->modelGrp->getGroupMembers($id),
|
||||
];
|
||||
} elseif ($typeCode !== 'TITLE') {
|
||||
$refType = $row['RefType'] ?? '';
|
||||
$resultType = $row['ResultType'] ?? '';
|
||||
|
||||
if (TestValidationService::usesRefNum($resultType, $refType)) {
|
||||
$row['refnum'] = $this->modelRefNum->getFormattedByTestSiteID($id);
|
||||
}
|
||||
|
||||
if (TestValidationService::usesRefTxt($resultType, $refType)) {
|
||||
$row['reftxt'] = $this->modelRefTxt->getFormattedByTestSiteID($id);
|
||||
}
|
||||
}
|
||||
|
||||
// Keep /api/test payload focused on test definition fields.
|
||||
unset($row['testmap']);
|
||||
|
||||
return $this->respond([
|
||||
'status' => 'success',
|
||||
'message' => 'Data fetched successfully',
|
||||
'data' => $row,
|
||||
], 200);
|
||||
}
|
||||
|
||||
public function create()
|
||||
{
|
||||
$input = $this->request->getJSON(true);
|
||||
|
||||
if (!$this->validateData($input, $this->rules)) {
|
||||
return $this->failValidationErrors($this->validator->getErrors());
|
||||
}
|
||||
|
||||
$testType = $input['TestType'] ?? '';
|
||||
$details = $input['details'] ?? $input;
|
||||
$resultType = $details['ResultType'] ?? '';
|
||||
$refType = $details['RefType'] ?? '';
|
||||
|
||||
if (TestValidationService::isCalc($testType)) {
|
||||
$resultType = 'NMRIC';
|
||||
$refType = $refType ?: 'RANGE';
|
||||
} elseif (TestValidationService::isGroup($testType) || TestValidationService::isTitle($testType)) {
|
||||
$resultType = 'NORES';
|
||||
$refType = 'NOREF';
|
||||
}
|
||||
|
||||
if ($resultType && $refType) {
|
||||
$validation = TestValidationService::validate($testType, $resultType, $refType);
|
||||
if (!$validation['valid']) {
|
||||
return $this->failValidationErrors(['type_validation' => $validation['error']]);
|
||||
}
|
||||
}
|
||||
|
||||
$db = \Config\Database::connect();
|
||||
$db->transStart();
|
||||
|
||||
try {
|
||||
$testSiteData = [
|
||||
'SiteID' => array_key_exists('SiteID', $input) ? $input['SiteID'] : null,
|
||||
'TestSiteCode'=> $input['TestSiteCode'],
|
||||
'TestSiteName'=> $input['TestSiteName'],
|
||||
'TestType' => $input['TestType'],
|
||||
'Description' => $input['Description'] ?? null,
|
||||
'SeqScr' => array_key_exists('SeqScr', $input) ? $input['SeqScr'] : null,
|
||||
'SeqRpt' => array_key_exists('SeqRpt', $input) ? $input['SeqRpt'] : null,
|
||||
'IndentLeft' => $input['IndentLeft'] ?? 0,
|
||||
'FontStyle' => $input['FontStyle'] ?? null,
|
||||
'isVisibleScr' => $input['isVisibleScr'] ?? 1,
|
||||
'isVisibleRpt' => $input['isVisibleRpt'] ?? 1,
|
||||
'isCountStat' => $input['isCountStat'] ?? 1,
|
||||
'isRequestable' => $input['isRequestable'] ?? 1,
|
||||
'StartDate' => $input['StartDate'] ?? date('Y-m-d H:i:s'),
|
||||
];
|
||||
|
||||
$id = $this->model->insert($testSiteData);
|
||||
if (!$id) {
|
||||
$dbError = $db->error();
|
||||
log_message('error', 'Test insert failed: ' . json_encode($dbError, JSON_UNESCAPED_SLASHES));
|
||||
$message = $dbError['message'] ?? 'Failed to insert main test definition';
|
||||
throw new \Exception('Failed to insert main test definition: ' . $message);
|
||||
}
|
||||
|
||||
$this->handleDetails($id, $input, 'insert');
|
||||
|
||||
$db->transComplete();
|
||||
|
||||
if ($db->transStatus() === false) {
|
||||
$dbError = $db->error();
|
||||
$lastQuery = $db->showLastQuery();
|
||||
log_message('error', 'TestController transaction failed: ' . json_encode([
|
||||
'error' => $dbError,
|
||||
'last_query' => $lastQuery,
|
||||
], JSON_UNESCAPED_SLASHES));
|
||||
return $this->failServerError('Transaction failed');
|
||||
}
|
||||
|
||||
return $this->respondCreated([
|
||||
'status' => 'success',
|
||||
'message' => 'Test created successfully',
|
||||
'data' => ['TestSiteId' => $id],
|
||||
]);
|
||||
} catch (\Exception $e) {
|
||||
$db->transRollback();
|
||||
|
||||
return $this->failServerError('Something went wrong: ' . $e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
public function update($id = null)
|
||||
{
|
||||
$input = $this->requirePatchPayload($this->request->getJSON(true));
|
||||
if ($input === null) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!$id && isset($input['TestSiteID'])) {
|
||||
$id = $input['TestSiteID'];
|
||||
}
|
||||
|
||||
$id = $this->requirePatchId($id, 'TestSiteID');
|
||||
if ($id === null) {
|
||||
return;
|
||||
}
|
||||
|
||||
$existing = $this->model->find($id);
|
||||
if (!$existing) {
|
||||
return $this->respond([
|
||||
'status' => 'failed',
|
||||
'message' => 'Test not found',
|
||||
'data' => []
|
||||
], 404);
|
||||
}
|
||||
|
||||
$testType = $input['TestType'] ?? $existing['TestType'] ?? '';
|
||||
$details = $input['details'] ?? $input;
|
||||
$resultType = $details['ResultType'] ?? $existing['ResultType'] ?? '';
|
||||
$refType = $details['RefType'] ?? $existing['RefType'] ?? '';
|
||||
|
||||
if (TestValidationService::isCalc($testType)) {
|
||||
$resultType = 'NMRIC';
|
||||
$refType = $refType ?: 'RANGE';
|
||||
} elseif (TestValidationService::isGroup($testType) || TestValidationService::isTitle($testType)) {
|
||||
$resultType = 'NORES';
|
||||
$refType = 'NOREF';
|
||||
}
|
||||
|
||||
if ($resultType && $refType) {
|
||||
$validation = TestValidationService::validate($testType, $resultType, $refType);
|
||||
if (!$validation['valid']) {
|
||||
return $this->failValidationErrors(['type_validation' => $validation['error']]);
|
||||
}
|
||||
}
|
||||
|
||||
$db = \Config\Database::connect();
|
||||
$db->transStart();
|
||||
|
||||
try {
|
||||
$testSiteData = [];
|
||||
$allowedUpdateFields = [
|
||||
'TestSiteCode',
|
||||
'TestSiteName',
|
||||
'TestType',
|
||||
'Description',
|
||||
'SeqScr',
|
||||
'SeqRpt',
|
||||
'IndentLeft',
|
||||
'FontStyle',
|
||||
'isVisibleScr',
|
||||
'isVisibleRpt',
|
||||
'isCountStat',
|
||||
'isRequestable',
|
||||
'StartDate',
|
||||
];
|
||||
|
||||
foreach ($allowedUpdateFields as $field) {
|
||||
if (array_key_exists($field, $input)) {
|
||||
$testSiteData[$field] = $input[$field];
|
||||
}
|
||||
}
|
||||
|
||||
if (!empty($testSiteData)) {
|
||||
$this->model->update($id, $testSiteData);
|
||||
}
|
||||
|
||||
$this->handleDetails($id, $input, 'update');
|
||||
|
||||
$db->transComplete();
|
||||
|
||||
if ($db->transStatus() === false) {
|
||||
return $this->failServerError('Transaction failed');
|
||||
}
|
||||
|
||||
return $this->respond([
|
||||
'status' => 'success',
|
||||
'message' => 'Test updated successfully',
|
||||
'data' => ['TestSiteId' => $id],
|
||||
]);
|
||||
} catch (\Exception $e) {
|
||||
$db->transRollback();
|
||||
|
||||
return $this->failServerError('Something went wrong: ' . $e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
public function delete($id = null)
|
||||
{
|
||||
$input = $this->request->getJSON(true);
|
||||
|
||||
if (!$id && isset($input['TestSiteID'])) {
|
||||
$id = $input['TestSiteID'];
|
||||
}
|
||||
if (!$id) {
|
||||
return $this->failValidationErrors('TestSiteID is required.');
|
||||
}
|
||||
|
||||
$existing = $this->model->find($id);
|
||||
if (!$existing) {
|
||||
return $this->failNotFound('Test not found');
|
||||
}
|
||||
|
||||
if (!empty($existing['EndDate'])) {
|
||||
return $this->failValidationErrors('Test is already disabled');
|
||||
}
|
||||
|
||||
$db = \Config\Database::connect();
|
||||
$db->transStart();
|
||||
|
||||
try {
|
||||
$now = date('Y-m-d H:i:s');
|
||||
|
||||
$this->model->update($id, ['EndDate' => $now]);
|
||||
|
||||
$testType = $existing['TestType'];
|
||||
$typeCode = $testType;
|
||||
|
||||
if (TestValidationService::isCalc($typeCode)) {
|
||||
$this->modelCal->disableByTestSiteID($id);
|
||||
$this->modelGrp->disableByTestSiteID($id);
|
||||
} elseif (TestValidationService::isGroup($typeCode)) {
|
||||
$this->modelGrp->disableByTestSiteID($id);
|
||||
} elseif (TestValidationService::isTechnicalTest($typeCode)) {
|
||||
$this->modelRefNum->disableByTestSiteID($id);
|
||||
$this->modelRefTxt->disableByTestSiteID($id);
|
||||
}
|
||||
|
||||
// Disable testmap by test code
|
||||
$testSiteCode = $existing['TestSiteCode'] ?? null;
|
||||
if ($testSiteCode) {
|
||||
$existingMaps = $this->modelMap->getMappingsByTestCode($testSiteCode);
|
||||
foreach ($existingMaps as $existingMap) {
|
||||
$this->modelMapDetail->disableByTestMapID($existingMap['TestMapID']);
|
||||
$this->modelMap->update($existingMap['TestMapID'], ['EndDate' => $now]);
|
||||
}
|
||||
}
|
||||
|
||||
$db->transComplete();
|
||||
|
||||
if ($db->transStatus() === false) {
|
||||
return $this->failServerError('Transaction failed');
|
||||
}
|
||||
|
||||
return $this->respond([
|
||||
'status' => 'success',
|
||||
'message' => 'Test disabled successfully',
|
||||
'data' => ['TestSiteId' => $id, 'EndDate' => $now],
|
||||
]);
|
||||
} catch (\Exception $e) {
|
||||
$db->transRollback();
|
||||
|
||||
return $this->failServerError('Something went wrong: ' . $e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
private function handleDetails($testSiteID, $input, $action)
|
||||
{
|
||||
$testTypeID = $input['TestType'] ?? null;
|
||||
$testSiteCode = null;
|
||||
|
||||
if (!$testTypeID && $action === 'update') {
|
||||
$existing = $this->model->find($testSiteID);
|
||||
$testTypeID = $existing['TestType'] ?? null;
|
||||
$testSiteCode = $existing['TestSiteCode'] ?? null;
|
||||
}
|
||||
|
||||
if (!$testTypeID) {
|
||||
return;
|
||||
}
|
||||
|
||||
$typeCode = $testTypeID;
|
||||
|
||||
$details = $input['details'] ?? $input;
|
||||
$details['TestSiteID'] = $testSiteID;
|
||||
$details['SiteID'] = array_key_exists('SiteID', $input) ? $input['SiteID'] : null;
|
||||
|
||||
switch ($typeCode) {
|
||||
case 'CALC':
|
||||
$this->saveCalcDetails($testSiteID, $details, $input, $action);
|
||||
|
||||
break;
|
||||
|
||||
case 'GROUP':
|
||||
$this->saveGroupDetails($testSiteID, $details, $input, $action);
|
||||
|
||||
break;
|
||||
|
||||
case 'TITLE':
|
||||
break;
|
||||
|
||||
case 'TEST':
|
||||
case 'PARAM':
|
||||
default:
|
||||
$this->saveTechDetails($testSiteID, $details, $action, $typeCode);
|
||||
|
||||
if (in_array($typeCode, ['TEST', 'PARAM']) && isset($details['RefType'])) {
|
||||
$refType = (string) $details['RefType'];
|
||||
$resultType = $details['ResultType'] ?? '';
|
||||
|
||||
if (TestValidationService::usesRefNum($resultType, $refType) && isset($input['refnum']) && is_array($input['refnum'])) {
|
||||
$this->saveRefNumRanges($testSiteID, $input['refnum'], $action, array_key_exists('SiteID', $input) ? $input['SiteID'] : null);
|
||||
}
|
||||
|
||||
if (TestValidationService::usesRefTxt($resultType, $refType) && isset($input['reftxt']) && is_array($input['reftxt'])) {
|
||||
$this->saveRefTxtRanges($testSiteID, $input['reftxt'], $action, array_key_exists('SiteID', $input) ? $input['SiteID'] : null);
|
||||
}
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private function saveTechDetails($testSiteID, $data, $action, $typeCode)
|
||||
{
|
||||
$allowedFields = [
|
||||
'DisciplineID',
|
||||
'DepartmentID',
|
||||
'ResultType',
|
||||
'RefType',
|
||||
'VSet',
|
||||
'ReqQty',
|
||||
'ReqQtyUnit',
|
||||
'Unit1',
|
||||
'Factor',
|
||||
'Unit2',
|
||||
'Decimal',
|
||||
'CollReq',
|
||||
'Method',
|
||||
'ExpectedTAT',
|
||||
];
|
||||
|
||||
$techData = [];
|
||||
foreach ($allowedFields as $field) {
|
||||
if (array_key_exists($field, $data)) {
|
||||
$techData[$field] = $data[$field];
|
||||
}
|
||||
}
|
||||
|
||||
if ($techData !== []) {
|
||||
$this->model->update($testSiteID, $techData);
|
||||
}
|
||||
}
|
||||
|
||||
private function saveRefNumRanges($testSiteID, $ranges, $action, $siteID)
|
||||
{
|
||||
if ($action === 'update') {
|
||||
$this->modelRefNum->disableByTestSiteID($testSiteID);
|
||||
}
|
||||
|
||||
$this->modelRefNum->batchInsert($testSiteID, $siteID, $ranges);
|
||||
}
|
||||
|
||||
private function saveRefTxtRanges($testSiteID, $ranges, $action, $siteID)
|
||||
{
|
||||
if ($action === 'update') {
|
||||
$this->modelRefTxt->disableByTestSiteID($testSiteID);
|
||||
}
|
||||
|
||||
$this->modelRefTxt->batchInsert($testSiteID, $siteID, $ranges);
|
||||
}
|
||||
|
||||
private function saveCalcDetails($testSiteID, $data, $input, $action)
|
||||
{
|
||||
$calcData = [];
|
||||
$fieldMap = [
|
||||
'DisciplineID' => 'DisciplineID',
|
||||
'DepartmentID' => 'DepartmentID',
|
||||
'Factor' => 'Factor',
|
||||
'Unit2' => 'Unit2',
|
||||
'Decimal' => 'Decimal',
|
||||
'Method' => 'Method',
|
||||
];
|
||||
|
||||
foreach ($fieldMap as $source => $target) {
|
||||
if (array_key_exists($source, $data)) {
|
||||
$calcData[$target] = $data[$source];
|
||||
}
|
||||
}
|
||||
|
||||
if (array_key_exists('FormulaCode', $data) || array_key_exists('Formula', $data)) {
|
||||
$calcData['FormulaCode'] = $data['FormulaCode'] ?? $data['Formula'] ?? null;
|
||||
}
|
||||
|
||||
if (array_key_exists('RefType', $data)) {
|
||||
$calcData['RefType'] = $data['RefType'];
|
||||
}
|
||||
|
||||
if (array_key_exists('Unit1', $data) || array_key_exists('ResultUnit', $data)) {
|
||||
$calcData['Unit1'] = $data['Unit1'] ?? $data['ResultUnit'] ?? null;
|
||||
}
|
||||
|
||||
$hasMemberPayload = isset($input['testdefgrp'])
|
||||
&& is_array($input['testdefgrp'])
|
||||
&& array_key_exists('members', $input['testdefgrp']);
|
||||
|
||||
if ($action === 'insert' && !array_key_exists('ResultType', $calcData)) {
|
||||
$calcData['ResultType'] = 'NMRIC';
|
||||
}
|
||||
|
||||
if ($action === 'insert' && !array_key_exists('RefType', $calcData)) {
|
||||
$calcData['RefType'] = 'RANGE';
|
||||
}
|
||||
|
||||
if ($calcData !== []) {
|
||||
$calcData['TestSiteID'] = $testSiteID;
|
||||
if ($action === 'update') {
|
||||
$exists = $this->modelCal->existsByTestSiteID($testSiteID);
|
||||
|
||||
if ($exists) {
|
||||
unset($calcData['TestSiteID']);
|
||||
$this->modelCal->update($exists['TestCalID'], $calcData);
|
||||
} else {
|
||||
if (!array_key_exists('ResultType', $calcData)) {
|
||||
$calcData['ResultType'] = 'NMRIC';
|
||||
}
|
||||
if (!array_key_exists('RefType', $calcData)) {
|
||||
$calcData['RefType'] = 'RANGE';
|
||||
}
|
||||
$this->modelCal->insert($calcData);
|
||||
}
|
||||
} else {
|
||||
$this->modelCal->insert($calcData);
|
||||
}
|
||||
}
|
||||
|
||||
if ($action === 'update' && !$hasMemberPayload) {
|
||||
return;
|
||||
}
|
||||
|
||||
if ($action === 'update') {
|
||||
$this->modelGrp->disableByTestSiteID($testSiteID);
|
||||
}
|
||||
|
||||
$memberIDs = $this->resolveMemberIDs($input);
|
||||
|
||||
$validation = $this->validateMemberIDs($memberIDs);
|
||||
if (!$validation['valid']) {
|
||||
throw new \Exception('Invalid member TestSiteID(s): ' . implode(', ', $validation['invalid']) . '. Make sure to use TestSiteID, not SeqScr or other values.');
|
||||
}
|
||||
|
||||
foreach ($memberIDs as $memberID) {
|
||||
$this->modelGrp->insert([
|
||||
'TestSiteID' => $testSiteID,
|
||||
'Member' => $memberID,
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
private function resolveMemberIDs(array $input): array
|
||||
{
|
||||
$memberIDs = [];
|
||||
|
||||
$rawMembers = $input['testdefgrp']['members'] ?? [];
|
||||
if (is_array($rawMembers)) {
|
||||
foreach ($rawMembers as $member) {
|
||||
if (is_array($member)) {
|
||||
$rawID = $member['TestSiteID'] ?? null;
|
||||
} else {
|
||||
$rawID = is_numeric($member) ? $member : null;
|
||||
}
|
||||
|
||||
if ($rawID !== null && is_numeric($rawID)) {
|
||||
$memberIDs[] = (int) $rawID;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$memberIDs = array_values(array_unique(array_filter($memberIDs)));
|
||||
|
||||
return $memberIDs;
|
||||
}
|
||||
|
||||
/**
|
||||
* Validate that member IDs exist in testdefsite table
|
||||
*
|
||||
* @param array $memberIDs Array of TestSiteID values to validate
|
||||
* @return array ['valid' => bool, 'invalid' => array]
|
||||
*/
|
||||
private function validateMemberIDs(array $memberIDs): array
|
||||
{
|
||||
if (empty($memberIDs)) {
|
||||
return ['valid' => true, 'invalid' => []];
|
||||
}
|
||||
|
||||
$existing = $this->model->whereIn('TestSiteID', $memberIDs)
|
||||
->where('EndDate IS NULL')
|
||||
->findAll();
|
||||
|
||||
$existingIDs = array_column($existing, 'TestSiteID');
|
||||
$invalidIDs = array_diff($memberIDs, $existingIDs);
|
||||
|
||||
return [
|
||||
'valid' => empty($invalidIDs),
|
||||
'invalid' => array_values($invalidIDs)
|
||||
];
|
||||
}
|
||||
|
||||
private function saveGroupDetails($testSiteID, $data, $input, $action)
|
||||
{
|
||||
$hasMemberPayload = isset($input['testdefgrp'])
|
||||
&& is_array($input['testdefgrp'])
|
||||
&& array_key_exists('members', $input['testdefgrp']);
|
||||
|
||||
if ($action === 'update' && !$hasMemberPayload) {
|
||||
return;
|
||||
}
|
||||
|
||||
if ($action === 'update') {
|
||||
$this->modelGrp->disableByTestSiteID($testSiteID);
|
||||
}
|
||||
|
||||
$memberIDs = $this->resolveMemberIDs($input);
|
||||
|
||||
// Validate member IDs before insertion
|
||||
$validation = $this->validateMemberIDs($memberIDs);
|
||||
if (!$validation['valid']) {
|
||||
throw new \Exception('Invalid member TestSiteID(s): ' . implode(', ', $validation['invalid']) . '. Make sure to use TestSiteID, not SeqScr or other values.');
|
||||
}
|
||||
|
||||
foreach ($memberIDs as $memberID) {
|
||||
$this->modelGrp->insert([
|
||||
'TestSiteID' => $testSiteID,
|
||||
'Member' => $memberID,
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
private function saveTestMap($testSiteID, $testSiteCode, $mappings, $action)
|
||||
{
|
||||
if ($action === 'update' && $testSiteCode) {
|
||||
// Find existing mappings by test code through testmapdetail
|
||||
$existingMaps = $this->modelMap->getMappingsByTestCode($testSiteCode);
|
||||
|
||||
foreach ($existingMaps as $existingMap) {
|
||||
$this->modelMapDetail->disableByTestMapID($existingMap['TestMapID']);
|
||||
}
|
||||
|
||||
// Soft delete the testmap headers
|
||||
foreach ($existingMaps as $existingMap) {
|
||||
$this->modelMap->update($existingMap['TestMapID'], ['EndDate' => date('Y-m-d H:i:s')]);
|
||||
}
|
||||
}
|
||||
|
||||
foreach ($this->normalizeTestMapPayload($mappings) as $map) {
|
||||
$mapData = [
|
||||
'HostType' => $map['HostType'] ?? null,
|
||||
'HostID' => $map['HostID'] ?? null,
|
||||
'ClientType' => $map['ClientType'] ?? null,
|
||||
'ClientID' => $map['ClientID'] ?? null,
|
||||
];
|
||||
|
||||
$testMapID = $this->modelMap->insert($mapData);
|
||||
if (!$testMapID) {
|
||||
continue;
|
||||
}
|
||||
|
||||
foreach ($this->extractTestMapDetails($map) as $detail) {
|
||||
$detailData = [
|
||||
'TestMapID' => $testMapID,
|
||||
'HostTestCode' => $detail['HostTestCode'] ?? null,
|
||||
'HostTestName' => $detail['HostTestName'] ?? null,
|
||||
'ConDefID' => $detail['ConDefID'] ?? null,
|
||||
'ClientTestCode' => $detail['ClientTestCode'] ?? null,
|
||||
'ClientTestName' => $detail['ClientTestName'] ?? null,
|
||||
];
|
||||
$this->modelMapDetail->insert($detailData);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private function normalizeTestMapPayload($mappings): array
|
||||
{
|
||||
if (!is_array($mappings)) {
|
||||
return [];
|
||||
}
|
||||
|
||||
if ($this->isAssoc($mappings)) {
|
||||
return [$mappings];
|
||||
}
|
||||
|
||||
return array_values(array_filter($mappings, static fn ($map) => is_array($map)));
|
||||
}
|
||||
|
||||
private function extractTestMapDetails(array $map): array
|
||||
{
|
||||
if (isset($map['details']) && is_array($map['details'])) {
|
||||
return array_values(array_filter($map['details'], static fn ($detail) => is_array($detail)));
|
||||
}
|
||||
|
||||
$flatDetail = [
|
||||
'HostTestCode' => $map['HostTestCode'] ?? null,
|
||||
'HostTestName' => $map['HostTestName'] ?? null,
|
||||
'ConDefID' => $map['ConDefID'] ?? null,
|
||||
'ClientTestCode' => $map['ClientTestCode'] ?? null,
|
||||
'ClientTestName' => $map['ClientTestName'] ?? null,
|
||||
];
|
||||
|
||||
foreach ($flatDetail as $value) {
|
||||
if ($value !== null && $value !== '') {
|
||||
return [$flatDetail];
|
||||
}
|
||||
}
|
||||
|
||||
return [];
|
||||
}
|
||||
|
||||
private function isAssoc(array $array): bool
|
||||
{
|
||||
if ($array === []) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return array_keys($array) !== range(0, count($array) - 1);
|
||||
}
|
||||
}
|
||||
619
app/Controllers/TestsController.php
Normal file
619
app/Controllers/TestsController.php
Normal file
@ -0,0 +1,619 @@
|
||||
<?php
|
||||
namespace App\Controllers;
|
||||
|
||||
use CodeIgniter\API\ResponseTrait;
|
||||
use App\Controllers\BaseController;
|
||||
use App\Libraries\ValueSet;
|
||||
|
||||
class TestsController extends BaseController
|
||||
{
|
||||
use ResponseTrait;
|
||||
|
||||
protected $db;
|
||||
protected $rules;
|
||||
protected $model;
|
||||
protected $modelCal;
|
||||
protected $modelTech;
|
||||
protected $modelGrp;
|
||||
protected $modelMap;
|
||||
protected $modelRefNum;
|
||||
protected $modelRefTxt;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->db = \Config\Database::connect();
|
||||
$this->model = new \App\Models\Test\TestDefSiteModel;
|
||||
$this->modelCal = new \App\Models\Test\TestDefCalModel;
|
||||
$this->modelTech = new \App\Models\Test\TestDefTechModel;
|
||||
$this->modelGrp = new \App\Models\Test\TestDefGrpModel;
|
||||
$this->modelMap = new \App\Models\Test\TestMapModel;
|
||||
$this->modelRefNum = new \App\Models\RefRange\RefNumModel;
|
||||
$this->modelRefTxt = new \App\Models\RefRange\RefTxtModel;
|
||||
|
||||
$this->rules = [
|
||||
'TestSiteCode' => 'required|min_length[3]|max_length[6]',
|
||||
'TestSiteName' => 'required',
|
||||
'TestType' => 'required',
|
||||
'SiteID' => 'required'
|
||||
];
|
||||
}
|
||||
|
||||
public function index()
|
||||
{
|
||||
$siteId = $this->request->getGet('SiteID');
|
||||
$testType = $this->request->getGet('TestType');
|
||||
$visibleScr = $this->request->getGet('VisibleScr');
|
||||
$visibleRpt = $this->request->getGet('VisibleRpt');
|
||||
$keyword = $this->request->getGet('TestSiteName');
|
||||
|
||||
$builder = $this->db->table('testdefsite')
|
||||
->select("testdefsite.TestSiteID, testdefsite.TestSiteCode, testdefsite.TestSiteName, testdefsite.TestType,
|
||||
testdefsite.SeqScr, testdefsite.SeqRpt, testdefsite.VisibleScr, testdefsite.VisibleRpt,
|
||||
testdefsite.CountStat, testdefsite.StartDate, testdefsite.EndDate")
|
||||
->where('testdefsite.EndDate IS NULL');
|
||||
|
||||
if ($siteId) {
|
||||
$builder->where('testdefsite.SiteID', $siteId);
|
||||
}
|
||||
|
||||
if ($testType) {
|
||||
$builder->where('testdefsite.TestType', $testType);
|
||||
}
|
||||
|
||||
if ($visibleScr !== null) {
|
||||
$builder->where('testdefsite.VisibleScr', $visibleScr);
|
||||
}
|
||||
|
||||
if ($visibleRpt !== null) {
|
||||
$builder->where('testdefsite.VisibleRpt', $visibleRpt);
|
||||
}
|
||||
|
||||
if ($keyword) {
|
||||
$builder->like('testdefsite.TestSiteName', $keyword);
|
||||
}
|
||||
|
||||
$rows = $builder->orderBy('testdefsite.SeqScr', 'ASC')->get()->getResultArray();
|
||||
|
||||
if (empty($rows)) {
|
||||
return $this->respond(['status' => 'success', 'message' => "No data.", 'data' => []], 200);
|
||||
}
|
||||
|
||||
$rows = ValueSet::transformLabels($rows, [
|
||||
'TestType' => 'test_type',
|
||||
]);
|
||||
|
||||
return $this->respond(['status' => 'success', 'message' => "Data fetched successfully", 'data' => $rows], 200);
|
||||
}
|
||||
|
||||
public function show($id = null)
|
||||
{
|
||||
if (!$id)
|
||||
return $this->failValidationErrors('TestSiteID is required');
|
||||
|
||||
$row = $this->model->select("testdefsite.*")
|
||||
->where("testdefsite.TestSiteID", $id)
|
||||
->find($id);
|
||||
|
||||
if (!$row) {
|
||||
return $this->respond(['status' => 'success', 'message' => "No data.", 'data' => null], 200);
|
||||
}
|
||||
|
||||
$row = ValueSet::transformLabels([$row], [
|
||||
'TestType' => 'test_type',
|
||||
])[0];
|
||||
|
||||
$typeCode = $row['TestType'] ?? '';
|
||||
|
||||
if ($typeCode === 'CALC') {
|
||||
$row['testdefcal'] = $this->db->table('testdefcal')
|
||||
->select('testdefcal.*, d.DisciplineName, dept.DepartmentName')
|
||||
->join('discipline d', 'd.DisciplineID=testdefcal.DisciplineID', 'left')
|
||||
->join('department dept', 'dept.DepartmentID=testdefcal.DepartmentID', 'left')
|
||||
->where('testdefcal.TestSiteID', $id)
|
||||
->where('testdefcal.EndDate IS NULL')
|
||||
->get()->getResultArray();
|
||||
|
||||
$row['testmap'] = $this->modelMap->where('TestSiteID', $id)->where('EndDate IS NULL')->findAll();
|
||||
|
||||
} elseif ($typeCode === 'GROUP') {
|
||||
$row['testdefgrp'] = $this->db->table('testdefgrp')
|
||||
->select('testdefgrp.*, t.TestSiteCode, t.TestSiteName, t.TestType')
|
||||
->join('testdefsite t', 't.TestSiteID=testdefgrp.Member', 'left')
|
||||
->where('testdefgrp.TestSiteID', $id)
|
||||
->where('testdefgrp.EndDate IS NULL')
|
||||
->orderBy('testdefgrp.TestGrpID', 'ASC')
|
||||
->get()->getResultArray();
|
||||
|
||||
$row['testdefgrp'] = ValueSet::transformLabels($row['testdefgrp'], [
|
||||
'TestType' => 'test_type',
|
||||
]);
|
||||
|
||||
$row['testmap'] = $this->modelMap->where('TestSiteID', $id)->where('EndDate IS NULL')->findAll();
|
||||
|
||||
} elseif ($typeCode === 'TITLE') {
|
||||
$row['testmap'] = $this->modelMap->where('TestSiteID', $id)->where('EndDate IS NULL')->findAll();
|
||||
|
||||
} else {
|
||||
$row['testdeftech'] = $this->db->table('testdeftech')
|
||||
->select('testdeftech.*, d.DisciplineName, dept.DepartmentName')
|
||||
->join('discipline d', 'd.DisciplineID=testdeftech.DisciplineID', 'left')
|
||||
->join('department dept', 'dept.DepartmentID=testdeftech.DepartmentID', 'left')
|
||||
->where('testdeftech.TestSiteID', $id)
|
||||
->where('testdeftech.EndDate IS NULL')
|
||||
->get()->getResultArray();
|
||||
|
||||
$row['testmap'] = $this->modelMap->where('TestSiteID', $id)->where('EndDate IS NULL')->findAll();
|
||||
|
||||
if (!empty($row['testdeftech'])) {
|
||||
$techData = $row['testdeftech'][0];
|
||||
$refType = $techData['RefType'];
|
||||
|
||||
if ($refType === '1') {
|
||||
$refnumData = $this->modelRefNum
|
||||
->where('TestSiteID', $id)
|
||||
->where('EndDate IS NULL')
|
||||
->orderBy('Display', 'ASC')
|
||||
->findAll();
|
||||
|
||||
$row['refnum'] = array_map(function ($r) {
|
||||
return [
|
||||
'RefNumID' => $r['RefNumID'],
|
||||
'NumRefType' => $r['NumRefType'],
|
||||
'NumRefTypeVValue' => ValueSet::getLabel('numeric_ref_type', $r['NumRefType']),
|
||||
'RangeTypeVValue' => ValueSet::getLabel('range_type', $r['RangeType']),
|
||||
'SexVValue' => ValueSet::getLabel('gender', $r['Sex']),
|
||||
'LowSignVValue' => ValueSet::getLabel('math_sign', $r['LowSign']),
|
||||
'HighSignVValue' => ValueSet::getLabel('math_sign', $r['HighSign']),
|
||||
'High' => $r['High'] !== null ? (int) $r['High'] : null,
|
||||
'Flag' => $r['Flag']
|
||||
];
|
||||
}, $refnumData ?? []);
|
||||
|
||||
// $row['numRefTypeOptions'] = ValueSet::getOptions('numeric_ref_type');
|
||||
$row['rangeTypeOptions'] = ValueSet::getOptions('range_type');
|
||||
}
|
||||
|
||||
if ($refType === '2') {
|
||||
$reftxtData = $this->modelRefTxt
|
||||
->where('TestSiteID', $id)
|
||||
->where('EndDate IS NULL')
|
||||
->orderBy('RefTxtID', 'ASC')
|
||||
->findAll();
|
||||
|
||||
$row['reftxt'] = array_map(function ($r) {
|
||||
return [
|
||||
'RefTxtID' => $r['RefTxtID'],
|
||||
'TxtRefType' => $r['TxtRefType'],
|
||||
'TxtRefTypeVValue' => ValueSet::getLabel('text_ref_type', $r['TxtRefType']),
|
||||
'Sex' => $r['Sex'],
|
||||
'SexVValue' => ValueSet::getLabel('gender', $r['Sex']),
|
||||
'AgeStart' => (int) $r['AgeStart'],
|
||||
'AgeEnd' => (int) $r['AgeEnd'],
|
||||
'RefTxt' => $r['RefTxt'],
|
||||
'Flag' => $r['Flag']
|
||||
];
|
||||
}, $reftxtData ?? []);
|
||||
|
||||
// $row['txtRefTypeOptions'] = ValueSet::getOptions('text_ref_type');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// $row['refTypeOptions'] = ValueSet::getOptions('reference_type');
|
||||
// $row['sexOptions'] = ValueSet::getOptions('gender');
|
||||
// $row['mathSignOptions'] = ValueSet::getOptions('math_sign');
|
||||
|
||||
return $this->respond(['status' => 'success', 'message' => "Data fetched successfully", 'data' => $row], 200);
|
||||
}
|
||||
|
||||
public function create()
|
||||
{
|
||||
$input = $this->request->getJSON(true);
|
||||
|
||||
if (!$this->validateData($input, $this->rules)) {
|
||||
return $this->failValidationErrors($this->validator->getErrors());
|
||||
}
|
||||
|
||||
$this->db->transStart();
|
||||
|
||||
try {
|
||||
$testSiteData = [
|
||||
'SiteID' => $input['SiteID'],
|
||||
'TestSiteCode' => $input['TestSiteCode'],
|
||||
'TestSiteName' => $input['TestSiteName'],
|
||||
'TestType' => $input['TestType'],
|
||||
'Description' => $input['Description'] ?? null,
|
||||
'SeqScr' => $input['SeqScr'] ?? 0,
|
||||
'SeqRpt' => $input['SeqRpt'] ?? 0,
|
||||
'IndentLeft' => $input['IndentLeft'] ?? 0,
|
||||
'FontStyle' => $input['FontStyle'] ?? null,
|
||||
'VisibleScr' => $input['VisibleScr'] ?? 1,
|
||||
'VisibleRpt' => $input['VisibleRpt'] ?? 1,
|
||||
'CountStat' => $input['CountStat'] ?? 1,
|
||||
'StartDate' => $input['StartDate'] ?? date('Y-m-d H:i:s')
|
||||
];
|
||||
|
||||
$id = $this->model->insert($testSiteData);
|
||||
if (!$id) {
|
||||
throw new \Exception("Failed to insert main test definition");
|
||||
}
|
||||
|
||||
$this->handleDetails($id, $input, 'insert');
|
||||
|
||||
$this->db->transComplete();
|
||||
|
||||
if ($this->db->transStatus() === false) {
|
||||
return $this->failServerError('Transaction failed');
|
||||
}
|
||||
|
||||
return $this->respondCreated([
|
||||
'status' => 'created',
|
||||
'message' => "Test created successfully",
|
||||
'data' => ['TestSiteId' => $id]
|
||||
]);
|
||||
} catch (\Exception $e) {
|
||||
$this->db->transRollback();
|
||||
return $this->failServerError('Something went wrong: ' . $e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
public function update($id = null)
|
||||
{
|
||||
$input = $this->request->getJSON(true);
|
||||
|
||||
if (!$id && isset($input["TestSiteID"])) {
|
||||
$id = $input["TestSiteID"];
|
||||
}
|
||||
if (!$id) {
|
||||
return $this->failValidationErrors('TestSiteID is required.');
|
||||
}
|
||||
|
||||
$existing = $this->model->find($id);
|
||||
if (!$existing) {
|
||||
return $this->failNotFound('Test not found');
|
||||
}
|
||||
|
||||
$this->db->transStart();
|
||||
|
||||
try {
|
||||
$testSiteData = [];
|
||||
$allowedUpdateFields = [
|
||||
'TestSiteCode',
|
||||
'TestSiteName',
|
||||
'TestType',
|
||||
'Description',
|
||||
'SeqScr',
|
||||
'SeqRpt',
|
||||
'IndentLeft',
|
||||
'FontStyle',
|
||||
'VisibleScr',
|
||||
'VisibleRpt',
|
||||
'CountStat',
|
||||
'StartDate'
|
||||
];
|
||||
|
||||
foreach ($allowedUpdateFields as $field) {
|
||||
if (isset($input[$field])) {
|
||||
$testSiteData[$field] = $input[$field];
|
||||
}
|
||||
}
|
||||
|
||||
if (!empty($testSiteData)) {
|
||||
$this->model->update($id, $testSiteData);
|
||||
}
|
||||
|
||||
$this->handleDetails($id, $input, 'update');
|
||||
|
||||
$this->db->transComplete();
|
||||
|
||||
if ($this->db->transStatus() === false) {
|
||||
return $this->failServerError('Transaction failed');
|
||||
}
|
||||
|
||||
return $this->respond([
|
||||
'status' => 'success',
|
||||
'message' => "Test updated successfully",
|
||||
'data' => ['TestSiteId' => $id]
|
||||
]);
|
||||
} catch (\Exception $e) {
|
||||
$this->db->transRollback();
|
||||
return $this->failServerError('Something went wrong: ' . $e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
public function delete($id = null)
|
||||
{
|
||||
$input = $this->request->getJSON(true);
|
||||
|
||||
if (!$id && isset($input["TestSiteID"])) {
|
||||
$id = $input["TestSiteID"];
|
||||
}
|
||||
if (!$id) {
|
||||
return $this->failValidationErrors('TestSiteID is required.');
|
||||
}
|
||||
|
||||
$existing = $this->model->find($id);
|
||||
if (!$existing) {
|
||||
return $this->failNotFound('Test not found');
|
||||
}
|
||||
|
||||
if (!empty($existing['EndDate'])) {
|
||||
return $this->failValidationErrors('Test is already disabled');
|
||||
}
|
||||
|
||||
$this->db->transStart();
|
||||
|
||||
try {
|
||||
$now = date('Y-m-d H:i:s');
|
||||
|
||||
$this->model->update($id, ['EndDate' => $now]);
|
||||
|
||||
$testType = $existing['TestType'];
|
||||
$typeCode = $testType;
|
||||
|
||||
if ($typeCode === 'CALC') {
|
||||
$this->db->table('testdefcal')
|
||||
->where('TestSiteID', $id)
|
||||
->update(['EndDate' => $now]);
|
||||
} elseif ($typeCode === 'GROUP') {
|
||||
$this->db->table('testdefgrp')
|
||||
->where('TestSiteID', $id)
|
||||
->update(['EndDate' => $now]);
|
||||
} elseif (in_array($typeCode, ['TEST', 'PARAM'])) {
|
||||
$this->db->table('testdeftech')
|
||||
->where('TestSiteID', $id)
|
||||
->update(['EndDate' => $now]);
|
||||
|
||||
$this->modelRefNum->where('TestSiteID', $id)->set('EndDate', $now)->update();
|
||||
$this->modelRefTxt->where('TestSiteID', $id)->set('EndDate', $now)->update();
|
||||
}
|
||||
|
||||
$this->db->table('testmap')
|
||||
->where('TestSiteID', $id)
|
||||
->update(['EndDate' => $now]);
|
||||
|
||||
$this->db->transComplete();
|
||||
|
||||
if ($this->db->transStatus() === false) {
|
||||
return $this->failServerError('Transaction failed');
|
||||
}
|
||||
|
||||
return $this->respond([
|
||||
'status' => 'success',
|
||||
'message' => "Test disabled successfully",
|
||||
'data' => ['TestSiteId' => $id, 'EndDate' => $now]
|
||||
]);
|
||||
} catch (\Exception $e) {
|
||||
$this->db->transRollback();
|
||||
return $this->failServerError('Something went wrong: ' . $e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
private function handleDetails($testSiteID, $input, $action)
|
||||
{
|
||||
$testTypeID = $input['TestType'] ?? null;
|
||||
|
||||
if (!$testTypeID && $action === 'update') {
|
||||
$existing = $this->model->find($testSiteID);
|
||||
$testTypeID = $existing['TestType'] ?? null;
|
||||
}
|
||||
|
||||
if (!$testTypeID)
|
||||
return;
|
||||
|
||||
$typeCode = $testTypeID;
|
||||
|
||||
$details = $input['details'] ?? $input;
|
||||
$details['TestSiteID'] = $testSiteID;
|
||||
$details['SiteID'] = $input['SiteID'] ?? 1;
|
||||
|
||||
switch ($typeCode) {
|
||||
case 'CALC':
|
||||
$this->saveCalcDetails($testSiteID, $details, $action);
|
||||
break;
|
||||
|
||||
case 'GROUP':
|
||||
$this->saveGroupDetails($testSiteID, $details, $input, $action);
|
||||
break;
|
||||
|
||||
case 'TITLE':
|
||||
if (isset($input['testmap']) && is_array($input['testmap'])) {
|
||||
$this->saveTestMap($testSiteID, $input['testmap'], $action);
|
||||
}
|
||||
break;
|
||||
|
||||
case 'TEST':
|
||||
case 'PARAM':
|
||||
default:
|
||||
$this->saveTechDetails($testSiteID, $details, $action, $typeCode);
|
||||
|
||||
if (in_array($typeCode, ['TEST', 'PARAM']) && isset($details['RefType'])) {
|
||||
$refType = $details['RefType'];
|
||||
|
||||
if ($refType === '1' && isset($input['refnum']) && is_array($input['refnum'])) {
|
||||
$this->saveRefNumRanges($testSiteID, $input['refnum'], $action, $input['SiteID'] ?? 1);
|
||||
}
|
||||
|
||||
if ($refType === '2' && isset($input['reftxt']) && is_array($input['reftxt'])) {
|
||||
$this->saveRefTxtRanges($testSiteID, $input['reftxt'], $action, $input['SiteID'] ?? 1);
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
if (in_array($typeCode, ['TEST', 'CALC']) && isset($input['testmap']) && is_array($input['testmap'])) {
|
||||
$this->saveTestMap($testSiteID, $input['testmap'], $action);
|
||||
}
|
||||
}
|
||||
|
||||
private function saveTechDetails($testSiteID, $data, $action, $typeCode)
|
||||
{
|
||||
$techData = [
|
||||
'TestSiteID' => $testSiteID,
|
||||
'DisciplineID' => $data['DisciplineID'] ?? null,
|
||||
'DepartmentID' => $data['DepartmentID'] ?? null,
|
||||
'ResultType' => $data['ResultType'] ?? null,
|
||||
'RefType' => $data['RefType'] ?? null,
|
||||
'VSet' => $data['VSet'] ?? null,
|
||||
'ReqQty' => $data['ReqQty'] ?? null,
|
||||
'ReqQtyUnit' => $data['ReqQtyUnit'] ?? null,
|
||||
'Unit1' => $data['Unit1'] ?? null,
|
||||
'Factor' => $data['Factor'] ?? null,
|
||||
'Unit2' => $data['Unit2'] ?? null,
|
||||
'Decimal' => $data['Decimal'] ?? 2,
|
||||
'CollReq' => $data['CollReq'] ?? null,
|
||||
'Method' => $data['Method'] ?? null,
|
||||
'ExpectedTAT' => $data['ExpectedTAT'] ?? null
|
||||
];
|
||||
|
||||
if ($action === 'update') {
|
||||
$exists = $this->db->table('testdeftech')
|
||||
->where('TestSiteID', $testSiteID)
|
||||
->where('EndDate IS NULL')
|
||||
->get()->getRowArray();
|
||||
|
||||
if ($exists) {
|
||||
$this->modelTech->update($exists['TestTechID'], $techData);
|
||||
} else {
|
||||
$this->modelTech->insert($techData);
|
||||
}
|
||||
} else {
|
||||
$this->modelTech->insert($techData);
|
||||
}
|
||||
}
|
||||
|
||||
private function saveRefNumRanges($testSiteID, $ranges, $action, $siteID)
|
||||
{
|
||||
if ($action === 'update') {
|
||||
$this->modelRefNum->where('TestSiteID', $testSiteID)
|
||||
->set('EndDate', date('Y-m-d H:i:s'))
|
||||
->update();
|
||||
}
|
||||
|
||||
foreach ($ranges as $index => $range) {
|
||||
$this->modelRefNum->insert([
|
||||
'TestSiteID' => $testSiteID,
|
||||
'SiteID' => $siteID,
|
||||
'NumRefType' => $range['NumRefType'],
|
||||
'RangeType' => $range['RangeType'],
|
||||
'Sex' => $range['Sex'],
|
||||
'AgeStart' => (int) ($range['AgeStart'] ?? 0),
|
||||
'AgeEnd' => (int) ($range['AgeEnd'] ?? 150),
|
||||
'LowSign' => !empty($range['LowSign']) ? $range['LowSign'] : null,
|
||||
'Low' => !empty($range['Low']) ? (int) $range['Low'] : null,
|
||||
'HighSign' => !empty($range['HighSign']) ? $range['HighSign'] : null,
|
||||
'High' => !empty($range['High']) ? (int) $range['High'] : null,
|
||||
'Flag' => $range['Flag'] ?? null,
|
||||
'Display' => $index,
|
||||
'CreateDate' => date('Y-m-d H:i:s')
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
private function saveRefTxtRanges($testSiteID, $ranges, $action, $siteID)
|
||||
{
|
||||
if ($action === 'update') {
|
||||
$this->modelRefTxt->where('TestSiteID', $testSiteID)
|
||||
->set('EndDate', date('Y-m-d H:i:s'))
|
||||
->update();
|
||||
}
|
||||
|
||||
foreach ($ranges as $range) {
|
||||
$this->modelRefTxt->insert([
|
||||
'TestSiteID' => $testSiteID,
|
||||
'SiteID' => $siteID,
|
||||
'TxtRefType' => $range['TxtRefType'],
|
||||
'Sex' => $range['Sex'],
|
||||
'AgeStart' => (int) ($range['AgeStart'] ?? 0),
|
||||
'AgeEnd' => (int) ($range['AgeEnd'] ?? 150),
|
||||
'RefTxt' => $range['RefTxt'] ?? '',
|
||||
'Flag' => $range['Flag'] ?? null,
|
||||
'CreateDate' => date('Y-m-d H:i:s')
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
private function saveCalcDetails($testSiteID, $data, $action)
|
||||
{
|
||||
$calcData = [
|
||||
'TestSiteID' => $testSiteID,
|
||||
'DisciplineID' => $data['DisciplineID'] ?? null,
|
||||
'DepartmentID' => $data['DepartmentID'] ?? null,
|
||||
'FormulaInput' => $data['FormulaInput'] ?? null,
|
||||
'FormulaCode' => $data['FormulaCode'] ?? $data['Formula'] ?? null,
|
||||
'RefType' => $data['RefType'] ?? 'NMRC',
|
||||
'Unit1' => $data['Unit1'] ?? $data['ResultUnit'] ?? null,
|
||||
'Factor' => $data['Factor'] ?? null,
|
||||
'Unit2' => $data['Unit2'] ?? null,
|
||||
'Decimal' => $data['Decimal'] ?? 2,
|
||||
'Method' => $data['Method'] ?? null
|
||||
];
|
||||
|
||||
if ($action === 'update') {
|
||||
$exists = $this->db->table('testdefcal')
|
||||
->where('TestSiteID', $testSiteID)
|
||||
->where('EndDate IS NULL')
|
||||
->get()->getRowArray();
|
||||
|
||||
if ($exists) {
|
||||
$this->modelCal->update($exists['TestCalID'], $calcData);
|
||||
} else {
|
||||
$this->modelCal->insert($calcData);
|
||||
}
|
||||
} else {
|
||||
$this->modelCal->insert($calcData);
|
||||
}
|
||||
}
|
||||
|
||||
private function saveGroupDetails($testSiteID, $data, $input, $action)
|
||||
{
|
||||
if ($action === 'update') {
|
||||
$this->db->table('testdefgrp')
|
||||
->where('TestSiteID', $testSiteID)
|
||||
->update(['EndDate' => date('Y-m-d H:i:s')]);
|
||||
}
|
||||
|
||||
$members = $data['members'] ?? ($input['Members'] ?? []);
|
||||
|
||||
if (is_array($members)) {
|
||||
foreach ($members as $m) {
|
||||
$memberID = is_array($m) ? ($m['Member'] ?? ($m['TestSiteID'] ?? null)) : $m;
|
||||
if ($memberID) {
|
||||
$this->modelGrp->insert([
|
||||
'TestSiteID' => $testSiteID,
|
||||
'Member' => $memberID
|
||||
]);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private function saveTestMap($testSiteID, $mappings, $action)
|
||||
{
|
||||
if ($action === 'update') {
|
||||
$this->db->table('testmap')
|
||||
->where('TestSiteID', $testSiteID)
|
||||
->update(['EndDate' => date('Y-m-d H:i:s')]);
|
||||
}
|
||||
|
||||
if (is_array($mappings)) {
|
||||
foreach ($mappings as $map) {
|
||||
$mapData = [
|
||||
'TestSiteID' => $testSiteID,
|
||||
'HostType' => $map['HostType'] ?? null,
|
||||
'HostID' => $map['HostID'] ?? null,
|
||||
'HostDataSource' => $map['HostDataSource'] ?? null,
|
||||
'HostTestCode' => $map['HostTestCode'] ?? null,
|
||||
'HostTestName' => $map['HostTestName'] ?? null,
|
||||
'ClientType' => $map['ClientType'] ?? null,
|
||||
'ClientID' => $map['ClientID'] ?? null,
|
||||
'ClientDataSource' => $map['ClientDataSource'] ?? null,
|
||||
'ConDefID' => $map['ConDefID'] ?? null,
|
||||
'ClientTestCode' => $map['ClientTestCode'] ?? null,
|
||||
'ClientTestName' => $map['ClientTestName'] ?? null
|
||||
];
|
||||
$this->modelMap->insert($mapData);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -1,306 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Controllers\User;
|
||||
|
||||
use App\Controllers\BaseController;
|
||||
use App\Models\User\UserModel;
|
||||
use App\Traits\PatchValidationTrait;
|
||||
use App\Traits\ResponseTrait;
|
||||
|
||||
/**
|
||||
* User Management Controller
|
||||
* Handles CRUD operations for users
|
||||
*/
|
||||
class UserController extends BaseController
|
||||
{
|
||||
use ResponseTrait;
|
||||
use PatchValidationTrait;
|
||||
|
||||
protected $model;
|
||||
protected $db;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->db = \Config\Database::connect();
|
||||
$this->model = new UserModel();
|
||||
}
|
||||
|
||||
/**
|
||||
* List users with pagination and search
|
||||
* GET /api/user?page=1&per_page=20&search=term
|
||||
*/
|
||||
public function index()
|
||||
{
|
||||
try {
|
||||
$page = (int)($this->request->getGet('page') ?? 1);
|
||||
$perPage = (int)($this->request->getGet('per_page') ?? 20);
|
||||
$search = $this->request->getGet('search');
|
||||
|
||||
// Build query
|
||||
$builder = $this->model->where('DelDate', null);
|
||||
|
||||
// Apply search if provided
|
||||
if ($search) {
|
||||
$builder->groupStart()
|
||||
->like('Username', $search)
|
||||
->orLike('Email', $search)
|
||||
->orLike('Name', $search)
|
||||
->groupEnd();
|
||||
}
|
||||
|
||||
// Get total count for pagination
|
||||
$total = $builder->countAllResults(false);
|
||||
|
||||
// Get paginated results
|
||||
$users = $builder
|
||||
->orderBy('UserID', 'DESC')
|
||||
->limit($perPage, ($page - 1) * $perPage)
|
||||
->findAll();
|
||||
|
||||
return $this->respond([
|
||||
'status' => 'success',
|
||||
'message' => 'Users retrieved successfully',
|
||||
'data' => [
|
||||
'users' => $users,
|
||||
'pagination' => [
|
||||
'current_page' => $page,
|
||||
'per_page' => $perPage,
|
||||
'total' => $total,
|
||||
'total_pages' => ceil($total / $perPage)
|
||||
]
|
||||
]
|
||||
], 200);
|
||||
|
||||
} catch (\Exception $e) {
|
||||
log_message('error', 'UserController::index error: ' . $e->getMessage());
|
||||
return $this->respond([
|
||||
'status' => 'failed',
|
||||
'message' => 'Failed to retrieve users',
|
||||
'data' => null
|
||||
], 500);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get single user by ID
|
||||
* GET /api/user/(:num)
|
||||
*/
|
||||
public function show($id)
|
||||
{
|
||||
try {
|
||||
$user = $this->model->where('UserID', $id)
|
||||
->where('DelDate', null)
|
||||
->first();
|
||||
|
||||
if (empty($user)) {
|
||||
return $this->respond([
|
||||
'status' => 'failed',
|
||||
'message' => 'User not found',
|
||||
'data' => null
|
||||
], 404);
|
||||
}
|
||||
|
||||
return $this->respond([
|
||||
'status' => 'success',
|
||||
'message' => 'User retrieved successfully',
|
||||
'data' => $user
|
||||
], 200);
|
||||
|
||||
} catch (\Exception $e) {
|
||||
log_message('error', 'UserController::show error: ' . $e->getMessage());
|
||||
return $this->respond([
|
||||
'status' => 'failed',
|
||||
'message' => 'Failed to retrieve user',
|
||||
'data' => null
|
||||
], 500);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Create new user
|
||||
* POST /api/user
|
||||
*/
|
||||
public function create()
|
||||
{
|
||||
try {
|
||||
$data = $this->request->getJSON(true);
|
||||
|
||||
// Validation rules
|
||||
$rules = [
|
||||
'Username' => 'required|min_length[3]|max_length[50]|is_unique[users.Username]',
|
||||
'Email' => 'required|valid_email|is_unique[users.Email]',
|
||||
];
|
||||
|
||||
if (!$this->validateData($data, $rules)) {
|
||||
return $this->respond([
|
||||
'status' => 'failed',
|
||||
'message' => 'Validation failed',
|
||||
'data' => $this->validator->getErrors()
|
||||
], 400);
|
||||
}
|
||||
|
||||
// Set default values
|
||||
$data['IsActive'] = $data['IsActive'] ?? true;
|
||||
$data['CreatedAt'] = date('Y-m-d H:i:s');
|
||||
|
||||
$userId = $this->model->insert($data);
|
||||
|
||||
if (!$userId) {
|
||||
return $this->respond([
|
||||
'status' => 'failed',
|
||||
'message' => 'Failed to create user',
|
||||
'data' => null
|
||||
], 500);
|
||||
}
|
||||
|
||||
return $this->respond([
|
||||
'status' => 'success',
|
||||
'message' => 'User created successfully',
|
||||
'data' => [
|
||||
'UserID' => $userId,
|
||||
'Username' => $data['Username'],
|
||||
'Email' => $data['Email']
|
||||
]
|
||||
], 201);
|
||||
|
||||
} catch (\Exception $e) {
|
||||
log_message('error', 'UserController::create error: ' . $e->getMessage());
|
||||
return $this->respond([
|
||||
'status' => 'failed',
|
||||
'message' => 'Failed to create user',
|
||||
'data' => null
|
||||
], 500);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Update existing user
|
||||
* PATCH /api/user/(:num)
|
||||
*/
|
||||
public function update($id)
|
||||
{
|
||||
try {
|
||||
$data = $this->requirePatchPayload($this->request->getJSON(true));
|
||||
if ($data === null) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (empty($id) || !ctype_digit((string) $id)) {
|
||||
return $this->respond([
|
||||
'status' => 'failed',
|
||||
'message' => 'UserID is required',
|
||||
'data' => null
|
||||
], 400);
|
||||
}
|
||||
|
||||
if (isset($data['UserID']) && (string) $data['UserID'] !== (string) $id) {
|
||||
return $this->respond([
|
||||
'status' => 'failed',
|
||||
'message' => 'UserID in URL does not match body',
|
||||
'data' => null
|
||||
], 400);
|
||||
}
|
||||
|
||||
$userId = (int) $id;
|
||||
|
||||
// Check if user exists
|
||||
$user = $this->model->where('UserID', $userId)
|
||||
->where('DelDate', null)
|
||||
->first();
|
||||
|
||||
if (empty($user)) {
|
||||
return $this->respond([
|
||||
'status' => 'failed',
|
||||
'message' => 'User not found',
|
||||
'data' => null
|
||||
], 404);
|
||||
}
|
||||
|
||||
// Remove UserID from data array
|
||||
unset($data['UserID']);
|
||||
|
||||
// Don't allow updating these fields
|
||||
unset($data['CreatedAt']);
|
||||
unset($data['Username']); // Username should not change
|
||||
|
||||
$data['UpdatedAt'] = date('Y-m-d H:i:s');
|
||||
|
||||
$updated = $this->model->update($userId, $data);
|
||||
|
||||
if (!$updated) {
|
||||
return $this->respond([
|
||||
'status' => 'failed',
|
||||
'message' => 'Failed to update user',
|
||||
'data' => null
|
||||
], 500);
|
||||
}
|
||||
|
||||
return $this->respond([
|
||||
'status' => 'success',
|
||||
'message' => 'User updated successfully',
|
||||
'data' => [
|
||||
'UserID' => $userId,
|
||||
'updated_fields' => array_keys($data)
|
||||
]
|
||||
], 200);
|
||||
|
||||
} catch (\Exception $e) {
|
||||
log_message('error', 'UserController::update error: ' . $e->getMessage());
|
||||
return $this->respond([
|
||||
'status' => 'failed',
|
||||
'message' => 'Failed to update user',
|
||||
'data' => null
|
||||
], 500);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete user (soft delete)
|
||||
* DELETE /api/user/(:num)
|
||||
*/
|
||||
public function delete($id)
|
||||
{
|
||||
try {
|
||||
// Check if user exists
|
||||
$user = $this->model->where('UserID', $id)
|
||||
->where('DelDate', null)
|
||||
->first();
|
||||
|
||||
if (empty($user)) {
|
||||
return $this->respond([
|
||||
'status' => 'failed',
|
||||
'message' => 'User not found',
|
||||
'data' => null
|
||||
], 404);
|
||||
}
|
||||
|
||||
// Soft delete by setting DelDate
|
||||
$deleted = $this->model->update($id, [
|
||||
'DelDate' => date('Y-m-d H:i:s'),
|
||||
'IsActive' => false
|
||||
]);
|
||||
|
||||
if (!$deleted) {
|
||||
return $this->respond([
|
||||
'status' => 'failed',
|
||||
'message' => 'Failed to delete user',
|
||||
'data' => null
|
||||
], 500);
|
||||
}
|
||||
|
||||
return $this->respond([
|
||||
'status' => 'success',
|
||||
'message' => 'User deleted successfully',
|
||||
'data' => ['UserID' => $id]
|
||||
], 200);
|
||||
|
||||
} catch (\Exception $e) {
|
||||
log_message('error', 'UserController::delete error: ' . $e->getMessage());
|
||||
return $this->respond([
|
||||
'status' => 'failed',
|
||||
'message' => 'Failed to delete user',
|
||||
'data' => null
|
||||
], 500);
|
||||
}
|
||||
}
|
||||
}
|
||||
376
app/Controllers/ValueSetController.php
Executable file → Normal file
376
app/Controllers/ValueSetController.php
Executable file → Normal file
@ -1,195 +1,181 @@
|
||||
<?php
|
||||
|
||||
namespace App\Controllers;
|
||||
|
||||
use App\Libraries\ValueSet;
|
||||
use App\Models\ValueSet\ValueSetModel;
|
||||
use App\Traits\ResponseTrait;
|
||||
|
||||
class ValueSetController extends \CodeIgniter\Controller
|
||||
{
|
||||
use ResponseTrait;
|
||||
|
||||
protected $dbModel;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->dbModel = new ValueSetModel();
|
||||
}
|
||||
|
||||
public function index(?string $lookupName = null)
|
||||
{
|
||||
$search = $this->request->getGet('search') ?? null;
|
||||
|
||||
if ($lookupName === null) {
|
||||
$all = ValueSet::getAll();
|
||||
$result = [];
|
||||
foreach ($all as $name => $entry) {
|
||||
if ($search) {
|
||||
$nameLower = strtolower($name);
|
||||
$labelLower = strtolower($entry['VSName'] ?? '');
|
||||
$searchLower = strtolower($search);
|
||||
if (strpos($nameLower, $searchLower) === false && strpos($labelLower, $searchLower) === false) {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
$count = count($entry['values'] ?? []);
|
||||
$result[] = [
|
||||
'value' => $name,
|
||||
'label' => $entry['VSName'] ?? '',
|
||||
'count' => $count
|
||||
];
|
||||
}
|
||||
return $this->respond([
|
||||
'status' => 'success',
|
||||
'data' => $result
|
||||
], 200);
|
||||
}
|
||||
|
||||
$data = ValueSet::get($lookupName);
|
||||
if (!$data) {
|
||||
return $this->respond([
|
||||
'status' => 'error',
|
||||
'message' => "ValueSet '$lookupName' not found"
|
||||
], 404);
|
||||
}
|
||||
|
||||
return $this->respond([
|
||||
'status' => 'success',
|
||||
'data' => $data
|
||||
], 200);
|
||||
}
|
||||
|
||||
public function refresh()
|
||||
{
|
||||
ValueSet::clearCache();
|
||||
return $this->respond([
|
||||
'status' => 'success',
|
||||
'message' => 'Cache cleared'
|
||||
], 200);
|
||||
}
|
||||
|
||||
public function items()
|
||||
{
|
||||
$search = $this->request->getGet('search') ?? $this->request->getGet('param') ?? null;
|
||||
$VSetID = $this->request->getGet('VSetID') ?? null;
|
||||
|
||||
$rows = $this->dbModel->getValueSets($search, $VSetID);
|
||||
|
||||
return $this->respond([
|
||||
'status' => 'success',
|
||||
'data' => $rows
|
||||
], 200);
|
||||
}
|
||||
|
||||
public function showItem($id = null)
|
||||
{
|
||||
$row = $this->dbModel->getValueSet($id);
|
||||
if (!$row) {
|
||||
return $this->failNotFound("ValueSet item not found: $id");
|
||||
}
|
||||
|
||||
return $this->respond([
|
||||
'status' => 'success',
|
||||
'data' => $row
|
||||
], 200);
|
||||
}
|
||||
|
||||
public function createItem()
|
||||
{
|
||||
$input = $this->request->getJSON(true);
|
||||
if (!$input) {
|
||||
return $this->failValidationErrors(['Invalid JSON input']);
|
||||
}
|
||||
|
||||
$data = [
|
||||
'SiteID' => $input['SiteID'] ?? 1,
|
||||
'VSetID' => $input['VSetID'] ?? null,
|
||||
'VOrder' => $input['VOrder'] ?? 0,
|
||||
'VValue' => $input['VValue'] ?? '',
|
||||
'VDesc' => $input['VDesc'] ?? ''
|
||||
];
|
||||
|
||||
if ($data['VSetID'] === null) {
|
||||
return $this->failValidationErrors(['VSetID is required']);
|
||||
}
|
||||
|
||||
try {
|
||||
$id = $this->dbModel->insert($data, true);
|
||||
if (!$id) {
|
||||
return $this->failValidationErrors($this->dbModel->errors());
|
||||
}
|
||||
|
||||
$newRow = $this->dbModel->getValueSet($id);
|
||||
return $this->respondCreated([
|
||||
'status' => 'success',
|
||||
'message' => 'ValueSet item created',
|
||||
'data' => $newRow
|
||||
]);
|
||||
} catch (\Exception $e) {
|
||||
return $this->failServerError('Failed to create: ' . $e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
public function updateItem($id = null)
|
||||
{
|
||||
$input = $this->request->getJSON(true);
|
||||
if (!$input) {
|
||||
return $this->failValidationErrors(['Invalid JSON input']);
|
||||
}
|
||||
|
||||
$existing = $this->dbModel->getValueSet($id);
|
||||
if (!$existing) {
|
||||
return $this->failNotFound("ValueSet item not found: $id");
|
||||
}
|
||||
|
||||
$data = [];
|
||||
if (isset($input['VSetID'])) $data['VSetID'] = $input['VSetID'];
|
||||
if (isset($input['VOrder'])) $data['VOrder'] = $input['VOrder'];
|
||||
if (isset($input['VValue'])) $data['VValue'] = $input['VValue'];
|
||||
if (isset($input['VDesc'])) $data['VDesc'] = $input['VDesc'];
|
||||
if (isset($input['SiteID'])) $data['SiteID'] = $input['SiteID'];
|
||||
|
||||
if (empty($data)) {
|
||||
return $this->respond([
|
||||
'status' => 'success',
|
||||
'message' => 'No changes to update',
|
||||
'data' => $existing
|
||||
], 200);
|
||||
}
|
||||
|
||||
try {
|
||||
$updated = $this->dbModel->update($id, $data);
|
||||
if (!$updated) {
|
||||
return $this->failValidationErrors($this->dbModel->errors());
|
||||
}
|
||||
|
||||
$newRow = $this->dbModel->getValueSet($id);
|
||||
return $this->respond([
|
||||
'status' => 'success',
|
||||
'message' => 'ValueSet item updated',
|
||||
'data' => $newRow
|
||||
], 200);
|
||||
} catch (\Exception $e) {
|
||||
return $this->failServerError('Failed to update: ' . $e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
public function deleteItem($id = null)
|
||||
{
|
||||
$existing = $this->dbModel->getValueSet($id);
|
||||
if (!$existing) {
|
||||
return $this->failNotFound("ValueSet item not found: $id");
|
||||
}
|
||||
|
||||
try {
|
||||
$this->dbModel->delete($id);
|
||||
return $this->respond([
|
||||
'status' => 'success',
|
||||
'message' => 'ValueSet item deleted'
|
||||
], 200);
|
||||
} catch (\Exception $e) {
|
||||
return $this->failServerError('Failed to delete: ' . $e->getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
<?php
|
||||
|
||||
namespace App\Controllers;
|
||||
|
||||
use App\Libraries\ValueSet;
|
||||
use App\Models\ValueSet\ValueSetModel;
|
||||
use CodeIgniter\API\ResponseTrait;
|
||||
|
||||
class ValueSetController extends \CodeIgniter\Controller
|
||||
{
|
||||
use ResponseTrait;
|
||||
|
||||
protected $dbModel;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->dbModel = new ValueSetModel();
|
||||
}
|
||||
|
||||
public function index(?string $lookupName = null)
|
||||
{
|
||||
if ($lookupName === null) {
|
||||
$all = ValueSet::getAll();
|
||||
$result = [];
|
||||
foreach ($all as $name => $entry) {
|
||||
$count = count($entry['values'] ?? []);
|
||||
$result[$name] = $count;
|
||||
}
|
||||
return $this->respond([
|
||||
'status' => 'success',
|
||||
'data' => $result
|
||||
], 200);
|
||||
}
|
||||
|
||||
$data = ValueSet::get($lookupName);
|
||||
if (!$data) {
|
||||
return $this->respond([
|
||||
'status' => 'error',
|
||||
'message' => "ValueSet '$lookupName' not found"
|
||||
], 404);
|
||||
}
|
||||
|
||||
return $this->respond([
|
||||
'status' => 'success',
|
||||
'data' => $data
|
||||
], 200);
|
||||
}
|
||||
|
||||
public function refresh()
|
||||
{
|
||||
ValueSet::clearCache();
|
||||
return $this->respond([
|
||||
'status' => 'success',
|
||||
'message' => 'Cache cleared'
|
||||
], 200);
|
||||
}
|
||||
|
||||
public function items()
|
||||
{
|
||||
$search = $this->request->getGet('search') ?? $this->request->getGet('param') ?? null;
|
||||
$VSetID = $this->request->getGet('VSetID') ?? null;
|
||||
|
||||
$rows = $this->dbModel->getValueSets($search, $VSetID);
|
||||
|
||||
return $this->respond([
|
||||
'status' => 'success',
|
||||
'data' => $rows
|
||||
], 200);
|
||||
}
|
||||
|
||||
public function showItem($id = null)
|
||||
{
|
||||
$row = $this->dbModel->getValueSet($id);
|
||||
if (!$row) {
|
||||
return $this->failNotFound("ValueSet item not found: $id");
|
||||
}
|
||||
|
||||
return $this->respond([
|
||||
'status' => 'success',
|
||||
'data' => $row
|
||||
], 200);
|
||||
}
|
||||
|
||||
public function createItem()
|
||||
{
|
||||
$input = $this->request->getJSON(true);
|
||||
if (!$input) {
|
||||
return $this->failValidationErrors(['Invalid JSON input']);
|
||||
}
|
||||
|
||||
$data = [
|
||||
'SiteID' => $input['SiteID'] ?? 1,
|
||||
'VSetID' => $input['VSetID'] ?? null,
|
||||
'VOrder' => $input['VOrder'] ?? 0,
|
||||
'VValue' => $input['VValue'] ?? '',
|
||||
'VDesc' => $input['VDesc'] ?? ''
|
||||
];
|
||||
|
||||
if ($data['VSetID'] === null) {
|
||||
return $this->failValidationErrors(['VSetID is required']);
|
||||
}
|
||||
|
||||
try {
|
||||
$id = $this->dbModel->insert($data, true);
|
||||
if (!$id) {
|
||||
return $this->failValidationErrors($this->dbModel->errors());
|
||||
}
|
||||
|
||||
$newRow = $this->dbModel->getValueSet($id);
|
||||
return $this->respondCreated([
|
||||
'status' => 'success',
|
||||
'message' => 'ValueSet item created',
|
||||
'data' => $newRow
|
||||
]);
|
||||
} catch (\Exception $e) {
|
||||
return $this->failServerError('Failed to create: ' . $e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
public function updateItem($id = null)
|
||||
{
|
||||
$input = $this->request->getJSON(true);
|
||||
if (!$input) {
|
||||
return $this->failValidationErrors(['Invalid JSON input']);
|
||||
}
|
||||
|
||||
$existing = $this->dbModel->getValueSet($id);
|
||||
if (!$existing) {
|
||||
return $this->failNotFound("ValueSet item not found: $id");
|
||||
}
|
||||
|
||||
$data = [];
|
||||
if (isset($input['VSetID'])) $data['VSetID'] = $input['VSetID'];
|
||||
if (isset($input['VOrder'])) $data['VOrder'] = $input['VOrder'];
|
||||
if (isset($input['VValue'])) $data['VValue'] = $input['VValue'];
|
||||
if (isset($input['VDesc'])) $data['VDesc'] = $input['VDesc'];
|
||||
if (isset($input['SiteID'])) $data['SiteID'] = $input['SiteID'];
|
||||
|
||||
if (empty($data)) {
|
||||
return $this->respond([
|
||||
'status' => 'success',
|
||||
'message' => 'No changes to update',
|
||||
'data' => $existing
|
||||
], 200);
|
||||
}
|
||||
|
||||
try {
|
||||
$updated = $this->dbModel->update($id, $data);
|
||||
if (!$updated) {
|
||||
return $this->failValidationErrors($this->dbModel->errors());
|
||||
}
|
||||
|
||||
$newRow = $this->dbModel->getValueSet($id);
|
||||
return $this->respond([
|
||||
'status' => 'success',
|
||||
'message' => 'ValueSet item updated',
|
||||
'data' => $newRow
|
||||
], 200);
|
||||
} catch (\Exception $e) {
|
||||
return $this->failServerError('Failed to update: ' . $e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
public function deleteItem($id = null)
|
||||
{
|
||||
$existing = $this->dbModel->getValueSet($id);
|
||||
if (!$existing) {
|
||||
return $this->failNotFound("ValueSet item not found: $id");
|
||||
}
|
||||
|
||||
try {
|
||||
$this->dbModel->delete($id);
|
||||
return $this->respond([
|
||||
'status' => 'success',
|
||||
'message' => 'ValueSet item deleted'
|
||||
], 200);
|
||||
} catch (\Exception $e) {
|
||||
return $this->failServerError('Failed to delete: ' . $e->getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
304
app/Controllers/ValueSetDefController.php
Executable file → Normal file
304
app/Controllers/ValueSetDefController.php
Executable file → Normal file
@ -1,152 +1,152 @@
|
||||
<?php
|
||||
|
||||
namespace App\Controllers;
|
||||
|
||||
use App\Models\ValueSet\ValueSetDefModel;
|
||||
use App\Traits\ResponseTrait;
|
||||
|
||||
class ValueSetDefController extends \CodeIgniter\Controller
|
||||
{
|
||||
use ResponseTrait;
|
||||
|
||||
protected $model;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->model = new ValueSetDefModel();
|
||||
}
|
||||
|
||||
public function index()
|
||||
{
|
||||
$search = $this->request->getGet('search') ?? null;
|
||||
$limit = (int) ($this->request->getGet('limit') ?? 100);
|
||||
$page = (int) ($this->request->getGet('page') ?? 1);
|
||||
$offset = ($page - 1) * $limit;
|
||||
|
||||
$rows = $this->model->getValueSetDefs($search);
|
||||
|
||||
$paged = array_slice($rows, $offset, $limit);
|
||||
|
||||
return $this->respond([
|
||||
'status' => 'success',
|
||||
'data' => $paged,
|
||||
'meta' => [
|
||||
'total' => count($rows),
|
||||
'page' => $page,
|
||||
'limit' => $limit
|
||||
]
|
||||
], 200);
|
||||
}
|
||||
|
||||
public function show($id = null)
|
||||
{
|
||||
$row = $this->model->find($id);
|
||||
if (!$row) {
|
||||
return $this->failNotFound("ValueSet definition not found: $id");
|
||||
}
|
||||
|
||||
$itemCount = $this->model->db->table('valueset')
|
||||
->select('COUNT(*) as ItemCount')
|
||||
->where('VSetID', $id)
|
||||
->where('EndDate IS NULL')
|
||||
->get()
|
||||
->getRowArray()['ItemCount'] ?? 0;
|
||||
|
||||
$row['ItemCount'] = (int) $itemCount;
|
||||
|
||||
return $this->respond([
|
||||
'status' => 'success',
|
||||
'data' => $row
|
||||
], 200);
|
||||
}
|
||||
|
||||
public function create()
|
||||
{
|
||||
$input = $this->request->getJSON(true);
|
||||
if (!$input) {
|
||||
return $this->failValidationErrors(['Invalid JSON input']);
|
||||
}
|
||||
|
||||
$data = [
|
||||
'SiteID' => $input['SiteID'] ?? 1,
|
||||
'VSName' => $input['VSName'] ?? '',
|
||||
'VSDesc' => $input['VSDesc'] ?? ''
|
||||
];
|
||||
|
||||
try {
|
||||
$id = $this->model->insert($data, true);
|
||||
if (!$id) {
|
||||
return $this->failValidationErrors($this->model->errors());
|
||||
}
|
||||
|
||||
$newRow = $this->model->find($id);
|
||||
return $this->respondCreated([
|
||||
'status' => 'success',
|
||||
'message' => 'ValueSet definition created',
|
||||
'data' => $newRow
|
||||
]);
|
||||
} catch (\Exception $e) {
|
||||
return $this->failServerError('Failed to create: ' . $e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
public function update($id = null)
|
||||
{
|
||||
$input = $this->request->getJSON(true);
|
||||
if (!$input) {
|
||||
return $this->failValidationErrors(['Invalid JSON input']);
|
||||
}
|
||||
|
||||
$existing = $this->model->find($id);
|
||||
if (!$existing) {
|
||||
return $this->failNotFound("ValueSet definition not found: $id");
|
||||
}
|
||||
|
||||
$data = [];
|
||||
if (isset($input['VSName'])) $data['VSName'] = $input['VSName'];
|
||||
if (isset($input['VSDesc'])) $data['VSDesc'] = $input['VSDesc'];
|
||||
if (isset($input['SiteID'])) $data['SiteID'] = $input['SiteID'];
|
||||
|
||||
if (empty($data)) {
|
||||
return $this->respond([
|
||||
'status' => 'success',
|
||||
'message' => 'No changes to update',
|
||||
'data' => $existing
|
||||
], 200);
|
||||
}
|
||||
|
||||
try {
|
||||
$updated = $this->model->update($id, $data);
|
||||
if (!$updated) {
|
||||
return $this->failValidationErrors($this->model->errors());
|
||||
}
|
||||
|
||||
$newRow = $this->model->find($id);
|
||||
return $this->respond([
|
||||
'status' => 'success',
|
||||
'message' => 'ValueSet definition updated',
|
||||
'data' => $newRow
|
||||
], 200);
|
||||
} catch (\Exception $e) {
|
||||
return $this->failServerError('Failed to update: ' . $e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
public function delete($id = null)
|
||||
{
|
||||
$existing = $this->model->find($id);
|
||||
if (!$existing) {
|
||||
return $this->failNotFound("ValueSet definition not found: $id");
|
||||
}
|
||||
|
||||
try {
|
||||
$this->model->delete($id);
|
||||
return $this->respond([
|
||||
'status' => 'success',
|
||||
'message' => 'ValueSet definition deleted'
|
||||
], 200);
|
||||
} catch (\Exception $e) {
|
||||
return $this->failServerError('Failed to delete: ' . $e->getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
<?php
|
||||
|
||||
namespace App\Controllers;
|
||||
|
||||
use App\Models\ValueSet\ValueSetDefModel;
|
||||
use CodeIgniter\API\ResponseTrait;
|
||||
|
||||
class ValueSetDefController extends \CodeIgniter\Controller
|
||||
{
|
||||
use ResponseTrait;
|
||||
|
||||
protected $model;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->model = new ValueSetDefModel();
|
||||
}
|
||||
|
||||
public function index()
|
||||
{
|
||||
$search = $this->request->getGet('search') ?? null;
|
||||
$limit = (int) ($this->request->getGet('limit') ?? 100);
|
||||
$page = (int) ($this->request->getGet('page') ?? 1);
|
||||
$offset = ($page - 1) * $limit;
|
||||
|
||||
$rows = $this->model->getValueSetDefs($search);
|
||||
|
||||
$paged = array_slice($rows, $offset, $limit);
|
||||
|
||||
return $this->respond([
|
||||
'status' => 'success',
|
||||
'data' => $paged,
|
||||
'meta' => [
|
||||
'total' => count($rows),
|
||||
'page' => $page,
|
||||
'limit' => $limit
|
||||
]
|
||||
], 200);
|
||||
}
|
||||
|
||||
public function show($id = null)
|
||||
{
|
||||
$row = $this->model->find($id);
|
||||
if (!$row) {
|
||||
return $this->failNotFound("ValueSet definition not found: $id");
|
||||
}
|
||||
|
||||
$itemCount = $this->model->db->table('valueset')
|
||||
->select('COUNT(*) as ItemCount')
|
||||
->where('VSetID', $id)
|
||||
->where('EndDate IS NULL')
|
||||
->get()
|
||||
->getRowArray()['ItemCount'] ?? 0;
|
||||
|
||||
$row['ItemCount'] = (int) $itemCount;
|
||||
|
||||
return $this->respond([
|
||||
'status' => 'success',
|
||||
'data' => $row
|
||||
], 200);
|
||||
}
|
||||
|
||||
public function create()
|
||||
{
|
||||
$input = $this->request->getJSON(true);
|
||||
if (!$input) {
|
||||
return $this->failValidationErrors(['Invalid JSON input']);
|
||||
}
|
||||
|
||||
$data = [
|
||||
'SiteID' => $input['SiteID'] ?? 1,
|
||||
'VSName' => $input['VSName'] ?? '',
|
||||
'VSDesc' => $input['VSDesc'] ?? ''
|
||||
];
|
||||
|
||||
try {
|
||||
$id = $this->model->insert($data, true);
|
||||
if (!$id) {
|
||||
return $this->failValidationErrors($this->model->errors());
|
||||
}
|
||||
|
||||
$newRow = $this->model->find($id);
|
||||
return $this->respondCreated([
|
||||
'status' => 'success',
|
||||
'message' => 'ValueSet definition created',
|
||||
'data' => $newRow
|
||||
]);
|
||||
} catch (\Exception $e) {
|
||||
return $this->failServerError('Failed to create: ' . $e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
public function update($id = null)
|
||||
{
|
||||
$input = $this->request->getJSON(true);
|
||||
if (!$input) {
|
||||
return $this->failValidationErrors(['Invalid JSON input']);
|
||||
}
|
||||
|
||||
$existing = $this->model->find($id);
|
||||
if (!$existing) {
|
||||
return $this->failNotFound("ValueSet definition not found: $id");
|
||||
}
|
||||
|
||||
$data = [];
|
||||
if (isset($input['VSName'])) $data['VSName'] = $input['VSName'];
|
||||
if (isset($input['VSDesc'])) $data['VSDesc'] = $input['VSDesc'];
|
||||
if (isset($input['SiteID'])) $data['SiteID'] = $input['SiteID'];
|
||||
|
||||
if (empty($data)) {
|
||||
return $this->respond([
|
||||
'status' => 'success',
|
||||
'message' => 'No changes to update',
|
||||
'data' => $existing
|
||||
], 200);
|
||||
}
|
||||
|
||||
try {
|
||||
$updated = $this->model->update($id, $data);
|
||||
if (!$updated) {
|
||||
return $this->failValidationErrors($this->model->errors());
|
||||
}
|
||||
|
||||
$newRow = $this->model->find($id);
|
||||
return $this->respond([
|
||||
'status' => 'success',
|
||||
'message' => 'ValueSet definition updated',
|
||||
'data' => $newRow
|
||||
], 200);
|
||||
} catch (\Exception $e) {
|
||||
return $this->failServerError('Failed to update: ' . $e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
public function delete($id = null)
|
||||
{
|
||||
$existing = $this->model->find($id);
|
||||
if (!$existing) {
|
||||
return $this->failNotFound("ValueSet definition not found: $id");
|
||||
}
|
||||
|
||||
try {
|
||||
$this->model->delete($id);
|
||||
return $this->respond([
|
||||
'status' => 'success',
|
||||
'message' => 'ValueSet definition deleted'
|
||||
], 200);
|
||||
} catch (\Exception $e) {
|
||||
return $this->failServerError('Failed to delete: ' . $e->getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
190
app/Controllers/ZonesController.php
Executable file → Normal file
190
app/Controllers/ZonesController.php
Executable file → Normal file
@ -1,95 +1,95 @@
|
||||
<?php
|
||||
/*
|
||||
namespace App\Controllers;
|
||||
|
||||
use App\Traits\ResponseTrait;
|
||||
use App\Controllers\BaseController;
|
||||
use App\Models\SyncCRM\ZonesModel;
|
||||
|
||||
class ZonesController extends BaseController {
|
||||
use ResponseTrait;
|
||||
|
||||
protected $model;
|
||||
|
||||
public function __construct() {
|
||||
$this->model = new ZonesModel();
|
||||
}
|
||||
|
||||
public function index() {
|
||||
try {
|
||||
$rows = $this->model->getZones();
|
||||
|
||||
if(empty($rows)){return $this->respond(['status'=>'success', 'message'=>"no data found.", 'data'=>$rows], 200);}
|
||||
return $this->respond(['status'=>'success', 'message'=>"data fetched successfully", 'data'=>$rows], 200);
|
||||
} catch (\Exception $e) {
|
||||
return $this->respond([ 'status' => 'error', 'message' => $e->getMessage() ], 200);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public function getProvinces() {
|
||||
$filters = [
|
||||
'zoneid' => $this->request->getVar('zoneid') ?? null,
|
||||
'zonename' => $this->request->getVar('zonename') ?? null
|
||||
];
|
||||
|
||||
$rows = $this->model->getProvinces();
|
||||
|
||||
if (empty($rows)) { return $this->respond([ 'status' => 'success', 'message' => "data not found", 'data' => [] ], 200); }
|
||||
return $this->respond([ 'status' => 'success', 'message'=> "Data fetched successfully", 'data' => $rows ], 200);
|
||||
}
|
||||
|
||||
public function getCities() {
|
||||
$filter = [
|
||||
'zoneid' => $this->request->getVar('zoneid') ?? null
|
||||
];
|
||||
|
||||
$rows = $this->model->getCities($filter);
|
||||
|
||||
if (empty($rows)) { return $this->respond([ 'status' => 'success', 'message' => "data not found", 'data' => [] ], 200); }
|
||||
return $this->respond([ 'status' => 'success', 'message'=> "Data fetched successfully", 'data' => $rows ], 200);
|
||||
}
|
||||
|
||||
public function synchronize() {
|
||||
$client = \Config\Services::curlrequest([
|
||||
'headers' => [
|
||||
'User-Agent' => 'Mozilla/5.0 (CI4 cURL Request)',
|
||||
'Accept' => 'application/json',
|
||||
],
|
||||
]);
|
||||
|
||||
try {
|
||||
// Ambil data dari API pusat (CRM)
|
||||
$response = $client->get('http://services-summit.my.id/api/zones'); // Prod
|
||||
// $response = $client->get('https://services-summit.my.id/api/zones'); // Dev
|
||||
$result = json_decode($response->getBody(), true);
|
||||
|
||||
if (!isset($result['data']) || !is_array($result['data'])) {
|
||||
return $this->response->setJSON([
|
||||
'status' => 'error',
|
||||
'message' => 'Invalid or empty response from CRM API'
|
||||
]);
|
||||
}
|
||||
|
||||
$record = $this->model->synchronize($result['data']);
|
||||
|
||||
return $this->response->setJSON([
|
||||
'status' => 'success',
|
||||
'message' => 'Zones synchronized successfully',
|
||||
'summary' => [
|
||||
'inserted' => $record['inserted'],
|
||||
'updated' => $record['updated'],
|
||||
'deleted' => $record['deleted'],
|
||||
'skipped' => $record['skipped']
|
||||
]
|
||||
]);
|
||||
} catch (\Exception $e) {
|
||||
return $this->response->setJSON([
|
||||
'status' => 'error',
|
||||
'message' => $e->getMessage()
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
*/
|
||||
<?php
|
||||
/*
|
||||
namespace App\Controllers;
|
||||
|
||||
use CodeIgniter\API\ResponseTrait;
|
||||
use App\Controllers\BaseController;
|
||||
use App\Models\SyncCRM\ZonesModel;
|
||||
|
||||
class ZonesController extends BaseController {
|
||||
use ResponseTrait;
|
||||
|
||||
protected $model;
|
||||
|
||||
public function __construct() {
|
||||
$this->model = new ZonesModel();
|
||||
}
|
||||
|
||||
public function index() {
|
||||
try {
|
||||
$rows = $this->model->getZones();
|
||||
|
||||
if(empty($rows)){return $this->respond(['status'=>'success', 'message'=>"no data found.", 'data'=>$rows], 200);}
|
||||
return $this->respond(['status'=>'success', 'message'=>"data fetched successfully", 'data'=>$rows], 200);
|
||||
} catch (\Exception $e) {
|
||||
return $this->respond([ 'status' => 'error', 'message' => $e->getMessage() ], 200);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public function getProvinces() {
|
||||
$filters = [
|
||||
'zoneid' => $this->request->getVar('zoneid') ?? null,
|
||||
'zonename' => $this->request->getVar('zonename') ?? null
|
||||
];
|
||||
|
||||
$rows = $this->model->getProvinces();
|
||||
|
||||
if (empty($rows)) { return $this->respond([ 'status' => 'success', 'message' => "data not found", 'data' => [] ], 200); }
|
||||
return $this->respond([ 'status' => 'success', 'message'=> "Data fetched successfully", 'data' => $rows ], 200);
|
||||
}
|
||||
|
||||
public function getCities() {
|
||||
$filter = [
|
||||
'zoneid' => $this->request->getVar('zoneid') ?? null
|
||||
];
|
||||
|
||||
$rows = $this->model->getCities($filter);
|
||||
|
||||
if (empty($rows)) { return $this->respond([ 'status' => 'success', 'message' => "data not found", 'data' => [] ], 200); }
|
||||
return $this->respond([ 'status' => 'success', 'message'=> "Data fetched successfully", 'data' => $rows ], 200);
|
||||
}
|
||||
|
||||
public function synchronize() {
|
||||
$client = \Config\Services::curlrequest([
|
||||
'headers' => [
|
||||
'User-Agent' => 'Mozilla/5.0 (CI4 cURL Request)',
|
||||
'Accept' => 'application/json',
|
||||
],
|
||||
]);
|
||||
|
||||
try {
|
||||
// Ambil data dari API pusat (CRM)
|
||||
$response = $client->get('http://services-summit.my.id/api/zones'); // Prod
|
||||
// $response = $client->get('https://services-summit.my.id/api/zones'); // Dev
|
||||
$result = json_decode($response->getBody(), true);
|
||||
|
||||
if (!isset($result['data']) || !is_array($result['data'])) {
|
||||
return $this->response->setJSON([
|
||||
'status' => 'error',
|
||||
'message' => 'Invalid or empty response from CRM API'
|
||||
]);
|
||||
}
|
||||
|
||||
$record = $this->model->synchronize($result['data']);
|
||||
|
||||
return $this->response->setJSON([
|
||||
'status' => 'success',
|
||||
'message' => 'Zones synchronized successfully',
|
||||
'summary' => [
|
||||
'inserted' => $record['inserted'],
|
||||
'updated' => $record['updated'],
|
||||
'deleted' => $record['deleted'],
|
||||
'skipped' => $record['skipped']
|
||||
]
|
||||
]);
|
||||
} catch (\Exception $e) {
|
||||
return $this->response->setJSON([
|
||||
'status' => 'error',
|
||||
'message' => $e->getMessage()
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
*/
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Loading…
x
Reference in New Issue
Block a user