2020-10-06 15:39:27 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @copyright 2020 Podlibre
|
|
|
|
* @license https://www.gnu.org/licenses/agpl-3.0.en.html AGPL3
|
|
|
|
* @link https://castopod.org/
|
|
|
|
*/
|
|
|
|
|
|
|
|
namespace App\Controllers\Admin;
|
|
|
|
|
|
|
|
use App\Models\PodcastModel;
|
|
|
|
use App\Models\EpisodeModel;
|
|
|
|
|
|
|
|
class AnalyticsData extends BaseController
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* @var \App\Entities\Podcast|null
|
|
|
|
*/
|
|
|
|
protected $podcast;
|
|
|
|
protected $className;
|
|
|
|
protected $methodName;
|
|
|
|
protected $episode;
|
|
|
|
|
|
|
|
public function _remap($method, ...$params)
|
|
|
|
{
|
2020-10-08 14:45:46 +00:00
|
|
|
if (count($params) > 1) {
|
2020-10-06 15:39:27 +00:00
|
|
|
if (!($this->podcast = (new PodcastModel())->find($params[0]))) {
|
|
|
|
throw \CodeIgniter\Exceptions\PageNotFoundException::forPageNotFound(
|
|
|
|
'Podcast not found: ' . $params[0]
|
|
|
|
);
|
|
|
|
}
|
|
|
|
$this->className = '\App\Models\Analytics' . $params[1] . 'Model';
|
2020-10-08 14:45:46 +00:00
|
|
|
$this->methodName =
|
|
|
|
'getData' . (empty($params[2]) ? '' : $params[2]);
|
2020-10-06 15:39:27 +00:00
|
|
|
if (count($params) > 3) {
|
|
|
|
if (
|
|
|
|
!($this->episode = (new EpisodeModel())
|
|
|
|
->where([
|
|
|
|
'podcast_id' => $this->podcast->id,
|
|
|
|
'id' => $params[3],
|
|
|
|
])
|
|
|
|
->first())
|
|
|
|
) {
|
|
|
|
throw \CodeIgniter\Exceptions\PageNotFoundException::forPageNotFound(
|
|
|
|
'Episode not found: ' . $params[3]
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return $this->$method();
|
|
|
|
}
|
|
|
|
public function getData()
|
|
|
|
{
|
|
|
|
$analytics_model = new $this->className();
|
|
|
|
$methodName = $this->methodName;
|
|
|
|
if ($this->episode) {
|
|
|
|
return $this->response->setJSON(
|
|
|
|
$analytics_model->$methodName(
|
|
|
|
$this->podcast->id,
|
|
|
|
$this->episode->id
|
|
|
|
)
|
|
|
|
);
|
|
|
|
} else {
|
|
|
|
return $this->response->setJSON(
|
|
|
|
$analytics_model->$methodName($this->podcast->id)
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|