ORIENT/plugins/tps/reklama/models/Reklama.php

77 lines
1.8 KiB
PHP

<?php namespace Tps\Reklama\Models;
use Carbon\Carbon;
use Model;
/**
* Model
*/
class Reklama extends Model
{
use \October\Rain\Database\Traits\Validation;
public $implement = ['@RainLab.Translate.Behaviors.TranslatableModel'];
/*
* Disable timestamps by default.
* Remove this line if timestamps are defined in the database table.
*/
public $timestamps = false;
/**
* @var string The database table used by the model.
*/
public $table = 'tps_reklama_item';
public $translatable = [
'media',
'media_mobile',
'web_media_mobile',
];
/**
* @var array Validation rules
*/
public $rules = [
];
public $belongsTo = [
'group' => ['Tps\Reklama\Models\Group',
'table' => 'tps_reklama_group',
'order' => 'name'
],
];
public $hasMany = [
'stats' => [
'Tps\Reklama\Models\Statistika',
'table' => 'tps_reklama_statistika',
'key' => 'item_id'
]
];
public function scopeUnExpiered($query){
return $query->where('active',1)
->where(function ($q) {
$q->where('end_date', '>', Carbon::now(config('app.timezone')))
->orWhereNull('end_date');
})
->where(function ($q) {
$q->where('start_date', '<', Carbon::now(config('app.timezone')))
->orWhereNull('start_date');
});
}
public function getViewsAttribute(){
if($this->enable_stats)
return $this->stats->sum('view');
return '-';
}
public function getClicksAttribute(){
if($this->enable_stats)
return $this->stats->sum('click');
return '-';
}
}