This repository has been archived on 2024-10-25. You can view files and clone it, but cannot push or open issues or pull requests.
Sequenzia/app/models/Advertisement.php
2013-11-21 14:08:11 -05:00

45 lines
1.2 KiB
PHP
Executable File

<?php
class Advertisement extends Rails\ActiveRecord\Base
{
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 ]
];
}
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';
}
}