Skip to content

Commit

Permalink
chore: fix use of session
Browse files Browse the repository at this point in the history
Make sure we use the session from container
  • Loading branch information
dfranco committed Oct 7, 2023
1 parent c412f9c commit a63f09d
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions application/Controller/DirectorController.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
use Core\Exception\ConfigFileException;
use Core\Utils\CUtils;
use Odan\Session\PhpSession;
use Odan\Session\SessionInterface;
use Psr\Http\Message\ServerRequestInterface as Request;
use Slim\Views\Twig;
use GuzzleHttp\Psr7\Response;
Expand All @@ -45,10 +46,12 @@
class DirectorController
{
private Twig $view;
private SessionInterface $session;

public function __construct(Twig $view)
public function __construct(Twig $view, SessionInterface $session)
{
$this->view = $view;
$this->session = $session;
}

/**
Expand All @@ -71,21 +74,18 @@ public function index(Request $request, Response $response): Response
NOW
];

// TODO: Session must be started by middleware, and binding must be configured in container
$session = new PhpSession();

$directors = [];

// Save catalog_id from user session
$prev_catalog_id = $session->get('catalog_id') ?? 0;
$prev_catalog_id = $this->session->get('catalog_id') ?? 0;

FileConfig::open(CONFIG_FILE);
$directors_count = FileConfig::count_Catalogs();

$tplData['directors_count'] = $directors_count;

for ($d = 0; $d < $directors_count; $d++) {
$session->set('catalog_id', $d);
$this->session->set('catalog_id', $d);

$clients = new ClientTable(DatabaseFactory::getDatabase($d));
$jobs = new JobTable(DatabaseFactory::getDatabase($d));
Expand Down Expand Up @@ -124,7 +124,7 @@ public function index(Request $request, Response $response): Response
}

// Set previous catalog_id in user session
$session->set('catalog_id', $prev_catalog_id);
$this->session->set('catalog_id', $prev_catalog_id);

$tplData['directors'] = $directors;

Expand Down

0 comments on commit a63f09d

Please sign in to comment.