2020-06-12 20:41:09 +00:00
|
|
|
<?php
|
2020-08-04 11:25:22 +00:00
|
|
|
|
2020-06-12 20:41:09 +00:00
|
|
|
/**
|
2020-10-08 14:45:46 +00:00
|
|
|
* Class AnalyticsPodcastByPlayerModel
|
2020-06-12 20:41:09 +00:00
|
|
|
* Model for analytics_podcasts_by_player table in database
|
|
|
|
* @copyright 2020 Podlibre
|
|
|
|
* @license https://www.gnu.org/licenses/agpl-3.0.en.html AGPL3
|
|
|
|
* @link https://castopod.org/
|
|
|
|
*/
|
2020-08-04 11:25:22 +00:00
|
|
|
|
2020-06-12 20:41:09 +00:00
|
|
|
namespace App\Models;
|
|
|
|
|
|
|
|
use CodeIgniter\Model;
|
|
|
|
|
2020-10-08 14:45:46 +00:00
|
|
|
class AnalyticsPodcastByPlayerModel extends Model
|
2020-06-12 20:41:09 +00:00
|
|
|
{
|
|
|
|
protected $table = 'analytics_podcasts_by_player';
|
|
|
|
|
|
|
|
protected $allowedFields = [];
|
|
|
|
|
2020-08-04 11:25:22 +00:00
|
|
|
protected $returnType = \App\Entities\AnalyticsPodcastsByPlayer::class;
|
2020-06-12 20:41:09 +00:00
|
|
|
protected $useSoftDeletes = false;
|
|
|
|
|
|
|
|
protected $useTimestamps = false;
|
2020-10-06 15:39:27 +00:00
|
|
|
|
|
|
|
/**
|
2020-10-08 14:45:46 +00:00
|
|
|
* Gets player data for a podcast
|
2020-10-06 15:39:27 +00:00
|
|
|
*
|
|
|
|
* @param int $podcastId
|
|
|
|
*
|
|
|
|
* @return array
|
|
|
|
*/
|
2020-10-14 10:38:48 +00:00
|
|
|
public function getDataByAppWeekly(int $podcastId): array
|
2020-10-06 15:39:27 +00:00
|
|
|
{
|
|
|
|
if (
|
|
|
|
!($found = cache(
|
2020-10-14 10:38:48 +00:00
|
|
|
"{$podcastId}_analytics_podcasts_by_player_by_app_weekly"
|
2020-10-06 15:39:27 +00:00
|
|
|
))
|
|
|
|
) {
|
|
|
|
$found = $this->select('`app` as `labels`')
|
|
|
|
->selectSum('`hits`', '`values`')
|
|
|
|
->where([
|
|
|
|
'`podcast_id`' => $podcastId,
|
2020-10-08 14:45:46 +00:00
|
|
|
'`app` !=' => '',
|
2020-10-06 15:39:27 +00:00
|
|
|
'`bot`' => 0,
|
|
|
|
'`date` >' => date('Y-m-d', strtotime('-1 week')),
|
|
|
|
])
|
|
|
|
->groupBy('`labels`')
|
2020-10-08 14:45:46 +00:00
|
|
|
->orderBy('`values`', 'DESC')
|
2020-10-06 15:39:27 +00:00
|
|
|
->findAll(10);
|
|
|
|
|
|
|
|
cache()->save(
|
2020-10-14 10:38:48 +00:00
|
|
|
"{$podcastId}_analytics_podcasts_by_player_by_app_weekly",
|
2020-10-06 15:39:27 +00:00
|
|
|
$found,
|
2020-10-08 14:45:46 +00:00
|
|
|
600
|
2020-10-06 15:39:27 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
return $found;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2020-10-14 10:38:48 +00:00
|
|
|
* Gets player data for a podcast
|
2020-10-06 15:39:27 +00:00
|
|
|
*
|
|
|
|
* @param int $podcastId
|
|
|
|
*
|
|
|
|
* @return array
|
|
|
|
*/
|
2020-10-14 10:38:48 +00:00
|
|
|
public function getDataByAppYearly(int $podcastId): array
|
2020-10-06 15:39:27 +00:00
|
|
|
{
|
|
|
|
if (
|
|
|
|
!($found = cache(
|
2020-10-14 10:38:48 +00:00
|
|
|
"{$podcastId}_analytics_podcasts_by_player_by_app_yearly"
|
2020-10-06 15:39:27 +00:00
|
|
|
))
|
|
|
|
) {
|
2020-10-14 10:38:48 +00:00
|
|
|
$found = $this->select('`app` as `labels`')
|
2020-10-06 15:39:27 +00:00
|
|
|
->selectSum('`hits`', '`values`')
|
|
|
|
->where([
|
|
|
|
'`podcast_id`' => $podcastId,
|
2020-10-14 10:38:48 +00:00
|
|
|
'`app` !=' => '',
|
2020-10-06 15:39:27 +00:00
|
|
|
'`bot`' => 0,
|
2020-10-14 10:38:48 +00:00
|
|
|
'`date` >' => date('Y-m-d', strtotime('-1 year')),
|
2020-10-06 15:39:27 +00:00
|
|
|
])
|
2020-10-14 10:38:48 +00:00
|
|
|
->groupBy('`labels`')
|
2020-10-08 14:45:46 +00:00
|
|
|
->orderBy('`values`', 'DESC')
|
2020-10-14 10:38:48 +00:00
|
|
|
->findAll(10);
|
2020-10-06 15:39:27 +00:00
|
|
|
|
2020-10-14 10:38:48 +00:00
|
|
|
cache()->save(
|
|
|
|
"{$podcastId}_analytics_podcasts_by_player_by_app_yearly",
|
|
|
|
$found,
|
|
|
|
600
|
|
|
|
);
|
|
|
|
}
|
|
|
|
return $found;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Gets os data for a podcast
|
|
|
|
*
|
|
|
|
* @param int $podcastId
|
|
|
|
*
|
|
|
|
* @return array
|
|
|
|
*/
|
|
|
|
public function getDataByOsWeekly(int $podcastId): array
|
|
|
|
{
|
|
|
|
if (
|
|
|
|
!($found = cache(
|
|
|
|
"{$podcastId}_analytics_podcasts_by_player_by_os_weekly"
|
|
|
|
))
|
|
|
|
) {
|
|
|
|
$found = $this->select('`os` as `labels`')
|
2020-10-06 15:39:27 +00:00
|
|
|
->selectSum('`hits`', '`values`')
|
|
|
|
->where([
|
|
|
|
'`podcast_id`' => $podcastId,
|
2020-10-14 10:38:48 +00:00
|
|
|
'`app` !=' => '',
|
2020-10-19 16:47:22 +00:00
|
|
|
'`os` !=' => '',
|
2020-10-06 15:39:27 +00:00
|
|
|
'`bot`' => 0,
|
|
|
|
'`date` >' => date('Y-m-d', strtotime('-1 week')),
|
|
|
|
])
|
2020-10-14 10:38:48 +00:00
|
|
|
->groupBy('`labels`')
|
2020-10-08 14:45:46 +00:00
|
|
|
->orderBy('`values`', 'DESC')
|
2020-10-14 10:38:48 +00:00
|
|
|
->findAll(10);
|
|
|
|
|
|
|
|
cache()->save(
|
|
|
|
"{$podcastId}_analytics_podcasts_by_player_by_os_weekly",
|
|
|
|
$found,
|
|
|
|
600
|
|
|
|
);
|
|
|
|
}
|
|
|
|
return $found;
|
|
|
|
}
|
2020-10-06 15:39:27 +00:00
|
|
|
|
2020-10-14 10:38:48 +00:00
|
|
|
/**
|
|
|
|
* Gets player data for a podcast
|
|
|
|
*
|
|
|
|
* @param int $podcastId
|
|
|
|
*
|
|
|
|
* @return array
|
|
|
|
*/
|
|
|
|
public function getDataByDeviceWeekly(int $podcastId): array
|
|
|
|
{
|
|
|
|
if (
|
|
|
|
!($found = cache(
|
|
|
|
"{$podcastId}_analytics_podcasts_by_player_by_device_weekly"
|
|
|
|
))
|
|
|
|
) {
|
|
|
|
$found = $this->select('`device` as `labels`')
|
2020-10-06 15:39:27 +00:00
|
|
|
->selectSum('`hits`', '`values`')
|
|
|
|
->where([
|
|
|
|
'`podcast_id`' => $podcastId,
|
2020-10-14 10:38:48 +00:00
|
|
|
'`device` !=' => '',
|
2020-10-06 15:39:27 +00:00
|
|
|
'`bot`' => 0,
|
|
|
|
'`date` >' => date('Y-m-d', strtotime('-1 week')),
|
|
|
|
])
|
2020-10-14 10:38:48 +00:00
|
|
|
->groupBy('`labels`')
|
2020-10-08 14:45:46 +00:00
|
|
|
->orderBy('`values`', 'DESC')
|
2020-10-14 10:38:48 +00:00
|
|
|
->findAll(10);
|
|
|
|
|
|
|
|
cache()->save(
|
|
|
|
"{$podcastId}_analytics_podcasts_by_player_by_device_weekly",
|
|
|
|
$found,
|
|
|
|
600
|
|
|
|
);
|
|
|
|
}
|
|
|
|
return $found;
|
|
|
|
}
|
2020-10-06 15:39:27 +00:00
|
|
|
|
2020-10-14 10:38:48 +00:00
|
|
|
/**
|
|
|
|
* Gets bots data for a podcast
|
|
|
|
*
|
|
|
|
* @param int $podcastId
|
|
|
|
*
|
|
|
|
* @return array
|
|
|
|
*/
|
|
|
|
public function getDataBots(int $podcastId): array
|
|
|
|
{
|
|
|
|
if (
|
|
|
|
!($found = cache("{$podcastId}_analytics_podcasts_by_player_bots"))
|
|
|
|
) {
|
|
|
|
$found = $this->select('DATE_FORMAT(`date`,"%Y-%m-01") as `labels`')
|
2020-10-06 15:39:27 +00:00
|
|
|
->selectSum('`hits`', '`values`')
|
|
|
|
->where([
|
|
|
|
'`podcast_id`' => $podcastId,
|
|
|
|
'`bot`' => 1,
|
2020-10-14 10:38:48 +00:00
|
|
|
'`date` >' => date('Y-m-d', strtotime('-1 year')),
|
2020-10-06 15:39:27 +00:00
|
|
|
])
|
2020-10-14 10:38:48 +00:00
|
|
|
->groupBy('`labels`')
|
|
|
|
->orderBy('`labels`', 'ASC')
|
|
|
|
->findAll(10);
|
2020-10-06 15:39:27 +00:00
|
|
|
|
|
|
|
cache()->save(
|
2020-10-14 10:38:48 +00:00
|
|
|
"{$podcastId}_analytics_podcasts_by_player_bots",
|
2020-10-06 15:39:27 +00:00
|
|
|
$found,
|
2020-10-08 14:45:46 +00:00
|
|
|
600
|
2020-10-06 15:39:27 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
return $found;
|
|
|
|
}
|
2020-06-12 20:41:09 +00:00
|
|
|
}
|