2020-06-05 13:54:40 +00:00
|
|
|
<?php
|
2020-08-04 11:25:22 +00:00
|
|
|
|
2021-06-08 09:52:11 +00:00
|
|
|
declare(strict_types=1);
|
|
|
|
|
2020-06-10 15:00:12 +00:00
|
|
|
/**
|
|
|
|
* @copyright 2020 Podlibre
|
|
|
|
* @license https://www.gnu.org/licenses/agpl-3.0.en.html AGPL3
|
|
|
|
* @link https://castopod.org/
|
|
|
|
*/
|
2020-06-05 13:54:40 +00:00
|
|
|
|
|
|
|
namespace App\Controllers;
|
|
|
|
|
|
|
|
use App\Models\PodcastModel;
|
2021-05-14 17:59:35 +00:00
|
|
|
use CodeIgniter\HTTP\RedirectResponse;
|
2021-05-26 11:37:41 +00:00
|
|
|
use mysqli_sql_exception;
|
2020-06-05 13:54:40 +00:00
|
|
|
|
2021-05-12 14:00:25 +00:00
|
|
|
class HomeController extends BaseController
|
2020-06-05 13:54:40 +00:00
|
|
|
{
|
2021-05-19 16:35:13 +00:00
|
|
|
public function index(): RedirectResponse | string
|
2020-06-10 15:00:12 +00:00
|
|
|
{
|
2021-05-26 11:37:41 +00:00
|
|
|
try {
|
|
|
|
$allPodcasts = (new PodcastModel())->findAll();
|
|
|
|
} catch (mysqli_sql_exception) {
|
|
|
|
// An error was caught when retrieving the podcasts from the database.
|
|
|
|
// Redirecting to install page because it is likely that Castopod Host has not been installed yet.
|
|
|
|
return redirect()->route('install');
|
|
|
|
}
|
2020-06-26 14:34:52 +00:00
|
|
|
|
|
|
|
// check if there's only one podcast to redirect user to it
|
2021-05-14 17:59:35 +00:00
|
|
|
if (count($allPodcasts) === 1) {
|
2021-05-19 16:35:13 +00:00
|
|
|
return redirect()->route('podcast-activity', [$allPodcasts[0]->name]);
|
2020-06-26 14:34:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// default behavior: list all podcasts on home page
|
2021-05-19 16:35:13 +00:00
|
|
|
$data = [
|
|
|
|
'podcasts' => $allPodcasts,
|
|
|
|
];
|
2020-06-10 15:00:12 +00:00
|
|
|
return view('home', $data);
|
|
|
|
}
|
2020-06-05 13:54:40 +00:00
|
|
|
}
|