"app/Resources/git@code.castopod.org:PatrykMis/castopod.git" did not exist on "90533be0298249e5527870c01329fce5f94ec2dc"
Newer
Older

Yassine Doghri
committed

Yassine Doghri
committed
declare(strict_types=1);
* Class AnalyticsWebsiteByRefererModel Model for analytics_website_by_referer table in database
*
* @copyright 2020 Ad Aures
* @license https://www.gnu.org/licenses/agpl-3.0.en.html AGPL3
* @link https://castopod.org/
*/

Yassine Doghri
committed

Yassine Doghri
committed
namespace Modules\Analytics\Models;

Yassine Doghri
committed
use Modules\Analytics\Entities\AnalyticsWebsiteByReferer;
class AnalyticsWebsiteByRefererModel extends Model
{

Yassine Doghri
committed
/**
* @var string
*/
protected $table = 'analytics_website_by_referer';

Yassine Doghri
committed
/**
* @var string
*/
protected $returnType = AnalyticsWebsiteByReferer::class;

Yassine Doghri
committed
/**
* @var bool
*/
protected $useSoftDeletes = false;

Yassine Doghri
committed
/**
* @var bool
*/
protected $useTimestamps = false;
/**
* Gets referer data for a podcast
*

Yassine Doghri
committed
* @return AnalyticsWebsiteByReferer[]
*/
public function getData(int $podcastId): array
{
if (! ($found = cache("{$podcastId}_analytics_website_by_referer"))) {

Benjamin Bellamy
committed
$oneWeekAgo = date('Y-m-d', strtotime('-1 week'));
$found = $this->select('referer_url as labels')
->selectSum('hits', 'values')
'podcast_id' => $podcastId,
'date >' => $oneWeekAgo,
->groupBy('labels')
->orderBy('values', 'DESC')

Benjamin Bellamy
committed
->findAll();
cache()

Yassine Doghri
committed
->save("{$podcastId}_analytics_website_by_referer", $found, 600);

Yassine Doghri
committed
return $found;
}
/**
* Gets domain data for a podcast
*

Yassine Doghri
committed
* @return AnalyticsWebsiteByReferer[]

Benjamin Bellamy
committed
public function getDataByDomainWeekly(int $podcastId): array

Benjamin Bellamy
committed
if (
! ($found = cache("{$podcastId}_analytics_website_by_domain_weekly"))

Benjamin Bellamy
committed
) {

Benjamin Bellamy
committed
$oneWeekAgo = date('Y-m-d', strtotime('-1 week'));
$found = $this->select('domain as labels')
->selectSum('hits', 'values')
'podcast_id' => $podcastId,
'date >' => $oneWeekAgo,
->groupBy('labels')
->orderBy('values', 'DESC')

Benjamin Bellamy
committed
->findAll();
cache()

Yassine Doghri
committed
->save("{$podcastId}_analytics_website_by_domain_weekly", $found, 600);

Benjamin Bellamy
committed
}

Yassine Doghri
committed

Benjamin Bellamy
committed
return $found;
}
/**
* Gets domain data for a podcast
*

Yassine Doghri
committed
* @return AnalyticsWebsiteByReferer[]

Benjamin Bellamy
committed
*/
public function getDataByDomainYearly(int $podcastId): array
{
if (
! ($found = cache("{$podcastId}_analytics_website_by_domain_yearly"))

Benjamin Bellamy
committed
) {

Benjamin Bellamy
committed
$oneYearAgo = date('Y-m-d', strtotime('-1 year'));
$found = $this->select('domain as labels')
->selectSum('hits', 'values')

Benjamin Bellamy
committed
->where([
'podcast_id' => $podcastId,
'date >' => $oneYearAgo,

Benjamin Bellamy
committed
])
->groupBy('labels')
->orderBy('values', 'DESC')

Benjamin Bellamy
committed
->findAll();
cache()

Yassine Doghri
committed
->save("{$podcastId}_analytics_website_by_domain_yearly", $found, 600);

Yassine Doghri
committed