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-06-09 16:08:24 +00:00
|
|
|
use Config\Services;
|
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-06-10 13:18:58 +00:00
|
|
|
$db = db_connect();
|
2021-06-10 14:13:36 +00:00
|
|
|
if ($db->getDatabase() === '' || ! $db->tableExists('podcasts')) {
|
|
|
|
// Database connection has not been set or could not find the podcasts table
|
2021-05-26 11:37:41 +00:00
|
|
|
// Redirecting to install page because it is likely that Castopod Host has not been installed yet.
|
2021-06-09 16:08:24 +00:00
|
|
|
// NB: as base_url wouldn't have been defined here, redirect to install wizard manually
|
|
|
|
$route = Services::routes()->reverseRoute('install');
|
|
|
|
return redirect()->to(rtrim(host_url(), '/') . $route);
|
2021-05-26 11:37:41 +00:00
|
|
|
}
|
2020-06-26 14:34:52 +00:00
|
|
|
|
2021-06-10 13:18:58 +00:00
|
|
|
$allPodcasts = (new PodcastModel())->findAll();
|
|
|
|
|
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
|
|
|
}
|