mirror of
https://github.com/ad-aures/castopod.git
synced 2026-04-11 10:46:43 +02:00
refactor(modules): extract castopod parts into a modules/ folder for a scalable HMVC structure
- create Admin, Analytics, Auth, Fediverse and Install modules in the root modules/ folder - rename ActivityPub to Fediverse
This commit is contained in:
parent
94872f2338
commit
5083cd2fda
268 changed files with 4221 additions and 2186 deletions
64
modules/Analytics/Models/AnalyticsPodcastByHourModel.php
Normal file
64
modules/Analytics/Models/AnalyticsPodcastByHourModel.php
Normal file
|
|
@ -0,0 +1,64 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
/**
|
||||
* Class AnalyticsPodcastByHour Model for analytics_podcasts_by_hour table in database
|
||||
*
|
||||
* @copyright 2020 Podlibre
|
||||
* @license https://www.gnu.org/licenses/agpl-3.0.en.html AGPL3
|
||||
* @link https://castopod.org/
|
||||
*/
|
||||
|
||||
namespace Modules\Analytics\Models;
|
||||
|
||||
use CodeIgniter\Model;
|
||||
use Modules\Analytics\Entities\AnalyticsPodcastsByHour;
|
||||
|
||||
class AnalyticsPodcastByHourModel extends Model
|
||||
{
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
protected $table = 'analytics_podcasts_by_hour';
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
protected $returnType = AnalyticsPodcastsByHour::class;
|
||||
|
||||
/**
|
||||
* @var bool
|
||||
*/
|
||||
protected $useSoftDeletes = false;
|
||||
|
||||
/**
|
||||
* @var bool
|
||||
*/
|
||||
protected $useTimestamps = false;
|
||||
|
||||
/**
|
||||
* Gets hits data for a podcast
|
||||
*
|
||||
* @return AnalyticsPodcastsByHour[]
|
||||
*/
|
||||
public function getData(int $podcastId): array
|
||||
{
|
||||
if (! ($found = cache("{$podcastId}_analytics_podcasts_by_hour"))) {
|
||||
$found = $this->select("right(concat('0',hour,'h'),3) as labels")
|
||||
->selectSum('hits', 'values')
|
||||
->where([
|
||||
'podcast_id' => $podcastId,
|
||||
'date >' => date('Y-m-d', strtotime('-60 days')),
|
||||
])
|
||||
->groupBy('labels')
|
||||
->orderBy('labels', 'ASC')
|
||||
->findAll();
|
||||
|
||||
cache()
|
||||
->save("{$podcastId}_analytics_podcasts_by_hour", $found, 600);
|
||||
}
|
||||
|
||||
return $found;
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue