Refactor Scontainers management
- Removed legacy Scontainers controller and view files, transitioning to a new controller structure. - Introduced ScontainersController to handle CRUD operations with improved dependency injection. - Created ScontainersRepository for database interactions, encapsulating logic for container management. - Updated container edit and list views to utilize new templating system. - Added unit tests for ScontainersRepository and ScontainersController to ensure functionality. - Enhanced form handling for container editing, including validation and error management.
This commit is contained in:
@@ -3,7 +3,7 @@ namespace front\factory;
|
||||
|
||||
class Scontainers
|
||||
{
|
||||
public static function scontainer_details( $scontainer_id )
|
||||
public static function scontainer_details($scontainer_id)
|
||||
{
|
||||
global $mdb, $lang;
|
||||
|
||||
@@ -11,21 +11,29 @@ class Scontainers
|
||||
$cacheKey = "\front\factory\Scontainers::scontainer_details:$scontainer_id";
|
||||
|
||||
$objectData = $cacheHandler->get($cacheKey);
|
||||
|
||||
if ( !$objectData )
|
||||
{
|
||||
$scontainer = $mdb -> get( 'pp_scontainers', '*', [ 'id' => (int)$scontainer_id ] );
|
||||
$results = $mdb -> select( 'pp_scontainers_langs', '*', [ 'AND' => [ 'container_id' => (int)$scontainer_id, 'lang_id' => $lang[0] ] ] );
|
||||
if ( is_array( $results ) ) foreach ( $results as $row )
|
||||
$scontainer['languages'] = $row;
|
||||
|
||||
$cacheHandler -> set( $cacheKey, $scontainer );
|
||||
}
|
||||
else
|
||||
{
|
||||
if ($objectData) {
|
||||
return unserialize($objectData);
|
||||
}
|
||||
|
||||
$repository = new \Domain\Scontainers\ScontainersRepository($mdb);
|
||||
$langId = (string)($lang[0] ?? 'pl');
|
||||
$scontainer = $repository->detailsForLanguage((int)$scontainer_id, $langId);
|
||||
|
||||
if (!is_array($scontainer)) {
|
||||
$scontainer = [
|
||||
'id' => (int)$scontainer_id,
|
||||
'status' => 0,
|
||||
'show_title' => 0,
|
||||
'languages' => [
|
||||
'lang_id' => $langId,
|
||||
'title' => '',
|
||||
'text' => '',
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
$cacheHandler->set($cacheKey, $scontainer);
|
||||
|
||||
return $scontainer;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user