71 lines
1.6 KiB
PHP
71 lines
1.6 KiB
PHP
<?php namespace Tps\Reklama\Models;
|
|
|
|
use Carbon\Carbon;
|
|
use Model;
|
|
|
|
/**
|
|
* Model
|
|
*/
|
|
class Reklama extends Model
|
|
{
|
|
use \October\Rain\Database\Traits\Validation;
|
|
|
|
/*
|
|
* 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';
|
|
|
|
/**
|
|
* @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 '-';
|
|
}
|
|
}
|