Sequenzia/app/models/Advertisement.php

45 lines
1.2 KiB
PHP
Raw Normal View History

2013-11-18 05:33:10 +01:00
<?php
class Advertisement extends Rails\ActiveRecord\Base
{
2013-11-21 20:08:11 +01:00
protected function validations()
{
return [
'ad_type' => [
'inclusion' => ['in' => ['horizontal', 'vertical']]
],
'image_url' => [ 'presence' => true ],
'referral_url' => [ 'presence' => true ],
'ad_type' => [ 'presence' => true ],
'status' => [ 'presence' => true ],
'width' => [ 'presence' => true ],
'height' => [ 'presence' => true ]
];
}
2013-11-18 05:33:10 +01:00
2013-11-21 20:08:11 +01:00
static public function random($type = 'vertical')
{
return self::where(['ad_type' => $type, 'status' => 'active'])->order('RAND()')->first();
}
static public function reset_hit_count($ids)
{
foreach (self::where('id IN (?)', $ids)->take() as $ad) {
$ad->updateAttribute('hit_count', 0);
}
}
# virtual method for resetting hit count in view
public function setResetHitCount($is_reset)
{
if ($is_reset) {
$this->hit_count = 0;
}
}
# virtual method for no-reset default in view's form
public function getResetHitCount()
{
return '0';
}
2013-11-18 05:33:10 +01:00
}