2013-10-27 01:06:58 +02:00
|
|
|
<?php
|
|
|
|
class AdvertisementsHelper extends Rails\ActionView\Helper
|
|
|
|
{
|
2013-12-05 20:56:41 +01:00
|
|
|
public function print_advertisement($ad_type, $position = null, $center = false)
|
2013-10-27 01:06:58 +02:00
|
|
|
{
|
2013-12-05 20:56:41 +01:00
|
|
|
$ad = Advertisement::random($ad_type, substr($position, 0, 1));
|
|
|
|
|
|
|
|
if ($ad) {
|
|
|
|
if ($ad->html) {
|
|
|
|
$contents = $ad->html;
|
|
|
|
} else {
|
|
|
|
$contents = $this->linkTo(
|
|
|
|
$this->imageTag(
|
|
|
|
$ad->image_url,
|
|
|
|
['alt' => "Advertisement", 'width' => $ad->width, 'height' => $ad->height]
|
|
|
|
),
|
|
|
|
$this->redirectAdvertisementPath($ad),
|
|
|
|
['target' => '_blank']
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($center) {
|
|
|
|
return $this->contentTag('div', $contents, ['style' => 'margin:0 auto;width:' . $ad->width . 'px;height:' . $ad->height . 'px;']);
|
|
|
|
} else {
|
|
|
|
return $contents;
|
2013-11-21 20:08:11 +01:00
|
|
|
}
|
2013-10-27 01:06:58 +02:00
|
|
|
}
|
|
|
|
}
|
2013-12-04 21:19:11 +01:00
|
|
|
}
|