-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
b0284c8
commit cfef863
Showing
6 changed files
with
77 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace App\Controllers; | ||
|
||
use PDO; | ||
use Psr\Container\ContainerInterface; | ||
use Psr\Http\Message\RequestInterface as Request; | ||
use Psr\Http\Message\ResponseInterface as Response; | ||
use Slim\Views\Twig; | ||
|
||
final class HomeController | ||
{ | ||
private PDO $db; | ||
private Twig $view; | ||
|
||
public function __construct(ContainerInterface $container) | ||
{ | ||
$this->db = $container->get('db'); | ||
$this->view = $container->get('view'); | ||
} | ||
|
||
public function __invoke(Request $request, Response $response, array $args): Response | ||
{ | ||
$stmt = $this->db->prepare(trim(" | ||
select count(*) as total_urls from urls | ||
union all | ||
select count(*) as total_clicks from urls_logs | ||
")); | ||
|
||
$stmt->execute(); | ||
|
||
[$totalUrls, $totalClicks] = $stmt->fetchAll(PDO::FETCH_COLUMN); | ||
|
||
return $this->view->render($response, 'index.html.twig', [ | ||
'totalUrls' => ceil($totalUrls), | ||
'totalClicks' => ceil($totalClicks) | ||
]); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters