diff --git a/app/DAL/Studies/AdminStudyLister.php b/app/DAL/Studies/AdminStudyLister.php index a8e63ad..8d9a5a4 100644 --- a/app/DAL/Studies/AdminStudyLister.php +++ b/app/DAL/Studies/AdminStudyLister.php @@ -3,11 +3,11 @@ namespace App\DAL\Studies; use App\Models\Study; -use Illuminate\Database\Query\Builder; +use Illuminate\Contracts\Database\Eloquent\Builder; class AdminStudyLister extends UserStudyListerBase { - protected static function defaultQuery(?int $user_id = null): Builder + protected function buildQuery(?int $user_id = null): Builder { return self::defaultSortQuery(Study::active()); } diff --git a/app/DAL/Studies/RadiologistStudyLister.php b/app/DAL/Studies/RadiologistStudyLister.php index cac00bb..413c6d5 100644 --- a/app/DAL/Studies/RadiologistStudyLister.php +++ b/app/DAL/Studies/RadiologistStudyLister.php @@ -3,11 +3,11 @@ namespace App\DAL\Studies; use App\Models\Study; -use Illuminate\Database\Query\Builder; +use Illuminate\Contracts\Database\Eloquent\Builder; class RadiologistStudyLister extends UserStudyListerBase { - protected static function defaultQuery(?int $user_id = null): Builder + protected function buildQuery(?int $user_id = null): Builder { $user_id = (int) ($user_id ?? auth()->id()); diff --git a/app/DAL/Studies/TechnicianStudyLister.php b/app/DAL/Studies/TechnicianStudyLister.php index d69fd10..e0a09cc 100644 --- a/app/DAL/Studies/TechnicianStudyLister.php +++ b/app/DAL/Studies/TechnicianStudyLister.php @@ -3,11 +3,11 @@ namespace App\DAL\Studies; use App\Models\Study; -use Illuminate\Database\Query\Builder; +use Illuminate\Contracts\Database\Eloquent\Builder; class TechnicianStudyLister extends UserStudyListerBase { - protected static function defaultQuery(?int $user_id = null): Builder + protected function buildQuery(?int $user_id = null): Builder { $query = Study::active(); $facility_id = auth()->user()->facility_id; diff --git a/app/DAL/Studies/UserStudyListerBase.php b/app/DAL/Studies/UserStudyListerBase.php index 8fd6649..e60e6e1 100644 --- a/app/DAL/Studies/UserStudyListerBase.php +++ b/app/DAL/Studies/UserStudyListerBase.php @@ -3,8 +3,8 @@ namespace App\DAL\Studies; use App\Models\Enums\ReportStatus; +use Illuminate\Contracts\Database\Eloquent\Builder; use Illuminate\Contracts\Pagination\LengthAwarePaginator; -use Illuminate\Database\Query\Builder; abstract class UserStudyListerBase implements IUserStudyLister { @@ -25,23 +25,23 @@ protected static function reportPendingQuery(Builder $query): Builder return $query->where('report_status', '<', ReportStatus::Finalized->value); } - abstract protected static function defaultQuery(?int $user_id = null): Builder; + abstract protected function buildQuery(?int $user_id = null): Builder; public function all(?int $user_id = null): LengthAwarePaginator { - return self::defaultQuery($user_id) + return $this->buildQuery($user_id) ->paginate(user_per_page($user_id)); } public function pending(?int $user_id = null): LengthAwarePaginator { - return self::reportPendingQuery(self::defaultQuery($user_id)) + return self::reportPendingQuery(self::buildQuery($user_id)) ->paginate(user_per_page($user_id)); } public function completed(?int $user_id = null): LengthAwarePaginator { - return self::reportCompleteQuery(self::defaultQuery($user_id)) + return self::reportCompleteQuery(self::buildQuery($user_id)) ->paginate(user_per_page($user_id)); } } diff --git a/app/Http/Controllers/Staff/StudiesController.php b/app/Http/Controllers/Staff/StudiesController.php index 2462c51..0f960ca 100644 --- a/app/Http/Controllers/Staff/StudiesController.php +++ b/app/Http/Controllers/Staff/StudiesController.php @@ -2,6 +2,7 @@ namespace App\Http\Controllers\Staff; +use App\DAL\Studies\UserStudyListerFactory; use App\Http\Controllers\HashidControllerBase; use App\Models\Study; use App\Services\AuditTrail\Activity; @@ -10,9 +11,7 @@ class StudiesController extends HashidControllerBase { public function index() { - $studies = Study::active() - ->orderBy('study_date', 'desc') - ->paginate(15); + $studies = UserStudyListerFactory::getLister()->all(); return view('staff.studies.index', compact('studies')); } diff --git a/config/settings.php b/config/settings.php new file mode 100644 index 0000000..686df5a --- /dev/null +++ b/config/settings.php @@ -0,0 +1,208 @@ + 'settings', + + /* + |-------------------------------------------------------------------------- + | Caching + |-------------------------------------------------------------------------- + | + | If enabled, all settings are cached after accessing them. + | + */ + 'cache' => true, + + /* + |-------------------------------------------------------------------------- + | Cache Key Prefix + |-------------------------------------------------------------------------- + | + | Specify a prefix to prepend to any setting key being cached. + | + */ + 'cache_key_prefix' => 'settings.', + + /* + |-------------------------------------------------------------------------- + | Encryption + |-------------------------------------------------------------------------- + | + | If enabled, all values are encrypted and decrypted. + | + */ + 'encryption' => true, + + /* + |-------------------------------------------------------------------------- + | Driver + |-------------------------------------------------------------------------- + | + | The driver to use to store and retrieve settings from. You are free + | to add more drivers in the `drivers` configuration below. + | + */ + 'driver' => env('SETTINGS_DRIVER', 'eloquent'), + + /* + |-------------------------------------------------------------------------- + | Drivers + |-------------------------------------------------------------------------- + | + | Here you may configure the driver information for each repository that + | is used by your application. A default configuration has been added + | for each back-end shipped with this package. You are free to add more. + | + | Each driver you add must implement the \Rawilk\Settings\Contracts\Driver interface. + | + */ + 'drivers' => [ + 'database' => [ + 'driver' => 'database', + 'connection' => env('DB_CONNECTION', 'mysql'), + ], + 'eloquent' => [ + 'driver' => 'eloquent', + + /* + * You can use any model you like for the setting, but it needs to implement + * the \Rawilk\Settings\Contracts\Setting interface. + */ + 'model' => \Rawilk\Settings\Models\Setting::class, + ], + ], + + /* + |-------------------------------------------------------------------------- + | Teams + |-------------------------------------------------------------------------- + | + | When set to true the package implements teams using the `team_foreign_key`. + | + | If you want the migrations to register the `team_foreign_key`, you must + | set this to true before running the migration. + | + | If you already ran the migrations, then you must make a new migration to + | add the `team_foreign_key` column to the settings table, and update the + | unique constraint on the table. See the `add_settings_team_field` migration + | for how to do this. + | + */ + 'teams' => false, + + /* + |-------------------------------------------------------------------------- + | Team Foreign Key + |-------------------------------------------------------------------------- + | + | When teams is set to true, our database/eloquent drivers will use this + | column as a team foreign key to scope queries to. + | + | The team id will also be included in a cache key when caching is enabled. + | + */ + 'team_foreign_key' => 'team_id', + + /* + |-------------------------------------------------------------------------- + | Context Serializer + |-------------------------------------------------------------------------- + | + | The context serializer is responsible for converting a Context object + | into a string, which gets appended to a setting key in the database. + | + | Any custom serializer you use must implement the + | \Rawilk\Settings\Contracts\ContextSerializer interface. + | + | Supported: + | - \Rawilk\Settings\Support\ContextSerializers\ContextSerializer (default) + | - \Rawilk\Settings\Support\ContextSerializers\DotNotationContextSerializer + | + */ + 'context_serializer' => \Rawilk\Settings\Support\ContextSerializers\ContextSerializer::class, + + /* + |-------------------------------------------------------------------------- + | Key Generator + |-------------------------------------------------------------------------- + | + | The key generator is responsible for generating a suitable key for a + | setting. + | + | Any custom key generator you use must implement the + | \Rawilk\Settings\Contracts\KeyGenerator interface. + | + | Supported: + | - \Rawilk\Settings\Support\KeyGenerators\ReadableKeyGenerator + | - \Rawilk\Settings\Support\KeyGenerators\Md5KeyGenerator (default) + | - \Rawilk\Settings\Support\KeyGenerators\HashKeyGenerator + | + */ + 'key_generator' => \Rawilk\Settings\Support\KeyGenerators\Md5KeyGenerator::class, + + /* + |-------------------------------------------------------------------------- + | Value Serializer + |-------------------------------------------------------------------------- + | + | By default, we use php's serialize() and unserialize() functions to + | prepare the setting values for storage. You may use the `JsonValueSerializer` + | instead if you want to store the values as json instead. + | + | Any custom value serializer you use must implement the + | \Rawilk\Settings\Contracts\ValueSerializer interface. + | + */ + 'value_serializer' => \Rawilk\Settings\Support\ValueSerializers\ValueSerializer::class, + + /* + |-------------------------------------------------------------------------- + | Cache Default Value + |-------------------------------------------------------------------------- + | + | When a setting is not persisted, we will cache the passed in default value + | if this is set to true. This may not always be desirable, so you can + | disable it here if needed. + | + */ + 'cache_default_value' => true, + + /* + |-------------------------------------------------------------------------- + | Unserialize Safelist + |-------------------------------------------------------------------------- + | + | When using the default value serializer class from this package, we + | will only unserialize objects that have their classes safelisted here. + | Any other objects will be unserialized to something like: + | __PHP_Incomplete_Class(App\Models\User) {...} + | + | To prevent any objects from being unserialized, simply set this to + | an empty array. + */ + 'unserialize_safelist' => [ + \Carbon\Carbon::class, + \Carbon\CarbonImmutable::class, + \Illuminate\Support\Carbon::class, + ], + + /* + |-------------------------------------------------------------------------- + | Hash Algorithm + |-------------------------------------------------------------------------- + | + | The hashing algorithm to use for the HashKeyGenerator. + | + */ + 'hash_algorithm' => 'xxh128', +]; diff --git a/database/migrations/2024_12_31_102417_create_settings_table.php b/database/migrations/2024_12_31_102417_create_settings_table.php new file mode 100644 index 0000000..b06322a --- /dev/null +++ b/database/migrations/2024_12_31_102417_create_settings_table.php @@ -0,0 +1,17 @@ +bigIncrements('id'); + $table->string('key')->unique()->index(); + $table->longText('value')->nullable(); + }); + } +}; diff --git a/database/migrations/2024_12_31_102418_add_settings_team_field.php b/database/migrations/2024_12_31_102418_add_settings_team_field.php new file mode 100644 index 0000000..3dc64ee --- /dev/null +++ b/database/migrations/2024_12_31_102418_add_settings_team_field.php @@ -0,0 +1,29 @@ +unsignedBigInteger(config('settings.team_foreign_key'))->nullable()->after('id'); + $table->index(config('settings.team_foreign_key'), 'settings_team_id_index'); + + $table->dropUnique('settings_key_unique'); + + $table->unique([ + 'key', + config('settings.team_foreign_key'), + ], 'settings_key_team_id_unique'); + }); + } +};