2021-04-14 15:58:40 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @copyright 2020 Podlibre
|
|
|
|
* @license https://www.gnu.org/licenses/agpl-3.0.en.html AGPL3
|
|
|
|
* @link https://castopod.org/
|
|
|
|
*/
|
|
|
|
|
|
|
|
namespace Analytics\Controllers;
|
|
|
|
|
2021-05-06 14:00:48 +00:00
|
|
|
use CodeIgniter\HTTP\ResponseInterface;
|
|
|
|
use CodeIgniter\Exceptions\PageNotFoundException;
|
2021-04-14 15:58:40 +00:00
|
|
|
use CodeIgniter\Controller;
|
|
|
|
|
|
|
|
class AnalyticsController extends Controller
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* @var string
|
|
|
|
*/
|
|
|
|
protected $className;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @var string
|
|
|
|
*/
|
|
|
|
protected $methodName;
|
|
|
|
|
2021-05-14 17:59:35 +00:00
|
|
|
public function _remap(string $method, string ...$params): mixed
|
2021-04-14 15:58:40 +00:00
|
|
|
{
|
|
|
|
if (!isset($params[1])) {
|
2021-05-06 14:00:48 +00:00
|
|
|
throw PageNotFoundException::forPageNotFound();
|
2021-04-14 15:58:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
$this->className = model('Analytics' . $params[1] . 'Model');
|
|
|
|
$this->methodName = 'getData' . (empty($params[2]) ? '' : $params[2]);
|
|
|
|
|
|
|
|
return $this->$method(
|
|
|
|
$params[0],
|
|
|
|
isset($params[3]) ? $params[3] : null,
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2021-05-17 17:11:23 +00:00
|
|
|
public function getData(
|
|
|
|
int $podcastId,
|
|
|
|
?int $episodeId = null
|
|
|
|
): ResponseInterface {
|
|
|
|
$analyticsModel = new $this->className();
|
2021-04-14 15:58:40 +00:00
|
|
|
$methodName = $this->methodName;
|
2021-05-17 17:11:23 +00:00
|
|
|
|
|
|
|
if ($episodeId === null) {
|
2021-04-14 15:58:40 +00:00
|
|
|
return $this->response->setJSON(
|
2021-05-17 17:11:23 +00:00
|
|
|
$analyticsModel->$methodName($podcastId),
|
2021-04-14 15:58:40 +00:00
|
|
|
);
|
|
|
|
}
|
2021-05-06 14:00:48 +00:00
|
|
|
|
|
|
|
return $this->response->setJSON(
|
2021-05-17 17:11:23 +00:00
|
|
|
$analyticsModel->$methodName($podcastId, $episodeId),
|
2021-05-06 14:00:48 +00:00
|
|
|
);
|
2021-04-14 15:58:40 +00:00
|
|
|
}
|
|
|
|
}
|