added html option to advertisements
This commit is contained in:
parent
ae5952fc8c
commit
bfd9978032
@ -6,17 +6,21 @@ class AdvertisementsHelper extends Rails\ActionView\Helper
|
|||||||
if (CONFIG()->can_see_ads(current_user())) {
|
if (CONFIG()->can_see_ads(current_user())) {
|
||||||
$ad = Advertisement::random($ad_type);
|
$ad = Advertisement::random($ad_type);
|
||||||
if ($ad) {
|
if ($ad) {
|
||||||
return $this->contentTag("div",
|
if ($ad->html) {
|
||||||
$this->linkTo(
|
return $ad->html;
|
||||||
$this->imageTag(
|
} else {
|
||||||
$ad->image_url,
|
return $this->contentTag("div",
|
||||||
['alt' => "Advertisement", 'width' => $ad->width, 'height' => $ad->height]
|
$this->linkTo(
|
||||||
|
$this->imageTag(
|
||||||
|
$ad->image_url,
|
||||||
|
['alt' => "Advertisement", 'width' => $ad->width, 'height' => $ad->height]
|
||||||
|
),
|
||||||
|
$this->redirectAdvertisementPath($ad),
|
||||||
|
['target' => '_blank']
|
||||||
),
|
),
|
||||||
$this->redirectAdvertisementPath($ad),
|
['style' => "margin-bottom: 1em;"]
|
||||||
['target' => '_blank']
|
);
|
||||||
),
|
}
|
||||||
['style' => "margin-bottom: 1em;"]
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -7,12 +7,9 @@ class Advertisement extends Rails\ActiveRecord\Base
|
|||||||
'ad_type' => [
|
'ad_type' => [
|
||||||
'inclusion' => ['in' => ['horizontal', 'vertical']]
|
'inclusion' => ['in' => ['horizontal', 'vertical']]
|
||||||
],
|
],
|
||||||
'image_url' => [ 'presence' => true ],
|
'ad_type' => [ 'presence' => true ],
|
||||||
'referral_url' => [ 'presence' => true ],
|
'status' => [ 'presence' => true ],
|
||||||
'ad_type' => [ 'presence' => true ],
|
'validateType'
|
||||||
'status' => [ 'presence' => true ],
|
|
||||||
'width' => [ 'presence' => true ],
|
|
||||||
'height' => [ 'presence' => true ]
|
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -41,4 +38,33 @@ class Advertisement extends Rails\ActiveRecord\Base
|
|||||||
{
|
{
|
||||||
return '0';
|
return '0';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected function validateType()
|
||||||
|
{
|
||||||
|
if ($this->html) {
|
||||||
|
$this->image_url = null;
|
||||||
|
$this->referral_url = null;
|
||||||
|
$this->width = null;
|
||||||
|
$this->height = null;
|
||||||
|
} else {
|
||||||
|
$attr = '';
|
||||||
|
|
||||||
|
if (!$this->image_url) {
|
||||||
|
$attr = 'image_url';
|
||||||
|
} elseif (!$this->referral_url) {
|
||||||
|
$attr = 'referral_url';
|
||||||
|
} elseif (!$this->width) {
|
||||||
|
$attr = 'width';
|
||||||
|
} elseif (!$this->height) {
|
||||||
|
$attr = 'height';
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($attr) {
|
||||||
|
$this->errors()->add($attr, "can't be blank");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->html = null;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,37 +1,98 @@
|
|||||||
<?= $this->formFor($this->ad, function($f) { ?>
|
<?= $this->formFor($this->ad, function($f) { ?>
|
||||||
|
<?php $action = $this->request()->action() ?>
|
||||||
<?= $this->partial('shared/error_messages', ['object' => $f->object()]) ?>
|
<?= $this->partial('shared/error_messages', ['object' => $f->object()]) ?>
|
||||||
|
|
||||||
<div>
|
<table class="form">
|
||||||
<?= $f->label('image_url') ?>
|
<tbody>
|
||||||
<?= $f->textField('image_url') ?>
|
<tr>
|
||||||
</div>
|
<th width="150px;">Type</th>
|
||||||
<div>
|
|
||||||
<?= $f->label('width') ?>
|
<td>
|
||||||
<?= $f->textField('width') ?>
|
<label for="type-image">Image</label>
|
||||||
</div>
|
<input type="radio" name="type" id="type-image" checked />
|
||||||
<div>
|
|
||||||
<?= $f->label('height') ?>
|
<label for="type-html">Html</label>
|
||||||
<?= $f->textField('height') ?>
|
<input type="radio" name="type" id="type-html" />
|
||||||
</div>
|
|
||||||
<div>
|
<script>
|
||||||
<?= $f->label('referral_url') ?>
|
jQuery(function(){
|
||||||
<?= $f->textField('referral_url') ?>
|
var $ = jQuery;
|
||||||
</div>
|
$('#type-image').on('click', function() {
|
||||||
<div>
|
if ($(this).is(':checked')) {
|
||||||
<?= $f->label('ad_type') ?>
|
$('.type-fields').hide();
|
||||||
<?= $f->select('ad_type', ['Horizontal' => 'horizontal', 'Vertical' => 'vertical']) ?>
|
$('.type-image').show();
|
||||||
</div>
|
}
|
||||||
<div>
|
});
|
||||||
<?= $f->label('status') ?>
|
$('#type-html').on('click', function() {
|
||||||
<?= $f->textField('status') ?>
|
if ($(this).is(':checked')) {
|
||||||
</div>
|
$('.type-fields').hide();
|
||||||
<?php if ($this->request()->action() == 'edit') : ?>
|
$('.type-html').show();
|
||||||
<div>
|
}
|
||||||
<?= $f->label('reset_hit_count') ?>
|
});
|
||||||
<?= $f->checkBox('reset_hit_count') ?>
|
});
|
||||||
</div>
|
</script>
|
||||||
<?php endif ?>
|
</td>
|
||||||
<div>
|
</tr>
|
||||||
<?= $f->submit() ?>
|
</tbody>
|
||||||
</div>
|
|
||||||
|
<tbody>
|
||||||
|
<tr>
|
||||||
|
<th><?= $f->label('ad_type') ?></th>
|
||||||
|
<td><?= $f->select('ad_type', ['Horizontal' => 'horizontal', 'Vertical' => 'vertical']) ?></td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<th><?= $f->label('status') ?></th>
|
||||||
|
<td><?= $f->select('status', ['Active' => 'active', 'Disabled' => 'disabled']) ?></td>
|
||||||
|
</tr>
|
||||||
|
|
||||||
|
<?php if ($action == 'edit') : ?>
|
||||||
|
<tr>
|
||||||
|
<th><?= $f->label('reset_hit_count') ?></th>
|
||||||
|
<td><?= $f->checkBox('reset_hit_count') ?></td>
|
||||||
|
</tr>
|
||||||
|
<?php endif ?>
|
||||||
|
</tbody>
|
||||||
|
|
||||||
|
<tbody class="type-fields type-image<?php if ($action != 'blank' || $f->object()->html) echo ' hide' ?>">
|
||||||
|
<tr>
|
||||||
|
<th><?= $f->label('image_url') ?></th>
|
||||||
|
<td><?= $f->textField('image_url') ?></td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<th><?= $f->label('referral_url') ?></th>
|
||||||
|
<td><?= $f->textField('referral_url') ?></td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<th><?= $f->label('width') ?></th>
|
||||||
|
<td><?= $f->textField('width') ?></td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<th><?= $f->label('height') ?></th>
|
||||||
|
<td><?= $f->textField('height') ?></td>
|
||||||
|
</tr>
|
||||||
|
</tbody>
|
||||||
|
|
||||||
|
<tbody class="type-fields type-html<?php if ($action == 'blank' || !$f->object()->html) echo ' hide' ?>">
|
||||||
|
<tr>
|
||||||
|
<th><?= $f->label('html') ?></th>
|
||||||
|
<td><?= $f->textArea('html', ['style' => 'height: 300px;']) ?></td>
|
||||||
|
</tr>
|
||||||
|
</tbody>
|
||||||
|
|
||||||
|
<tbody>
|
||||||
|
<tr>
|
||||||
|
<td colspan="2"><?= $f->submit() ?></td>
|
||||||
|
</tr>
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
<?php }) ?>
|
<?php }) ?>
|
||||||
|
|
||||||
|
<style>
|
||||||
|
table.form [type=text], table.form textarea{
|
||||||
|
width: 100%;
|
||||||
|
box-sizing: border-box;
|
||||||
|
}
|
||||||
|
table.form tbody.hide {
|
||||||
|
display:none;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
|
@ -2,4 +2,4 @@
|
|||||||
|
|
||||||
<?= $this->partial('form', ['ad' => $this->ad]) ?>
|
<?= $this->partial('form', ['ad' => $this->ad]) ?>
|
||||||
|
|
||||||
<?= $this->linkTo($this->t('buttons.back'), $this->ad) ?>
|
<?= $this->linkTo($this->t('buttons.back'), '#index') ?>
|
||||||
|
@ -7,7 +7,7 @@
|
|||||||
<tr>
|
<tr>
|
||||||
<th class="center"><?= $this->checkBoxTag('check_all', 'check_all', false, ['onClick' => "checkbox_toggle(this, 'advertisement_ids[]');"]) ?></th>
|
<th class="center"><?= $this->checkBoxTag('check_all', 'check_all', false, ['onClick' => "checkbox_toggle(this, 'advertisement_ids[]');"]) ?></th>
|
||||||
<th>#</th>
|
<th>#</th>
|
||||||
<th><?= $this->humanize('image_url') ?></th>
|
<th>Image URL/Html</th>
|
||||||
<th><?= $this->humanize('referral_url') ?></th>
|
<th><?= $this->humanize('referral_url') ?></th>
|
||||||
<th><?= $this->humanize('width') ?></th>
|
<th><?= $this->humanize('width') ?></th>
|
||||||
<th><?= $this->humanize('height') ?></th>
|
<th><?= $this->humanize('height') ?></th>
|
||||||
@ -23,7 +23,13 @@
|
|||||||
<tr>
|
<tr>
|
||||||
<td class="center"><?= $this->checkBoxTag('advertisement_ids[]', $ad->id) ?></td>
|
<td class="center"><?= $this->checkBoxTag('advertisement_ids[]', $ad->id) ?></td>
|
||||||
<td><?= $this->linkTo($ad->id, $ad) ?></td>
|
<td><?= $this->linkTo($ad->id, $ad) ?></td>
|
||||||
<td><?= $this->linkTo($ad->image_url, $ad->image_url) ?></td>
|
<td><?php
|
||||||
|
if (!$ad->html) {
|
||||||
|
echo $this->linkTo($ad->image_url, $ad->image_url);
|
||||||
|
} else {
|
||||||
|
echo '<pre style="font-size:1.15em;margin:0px;">' . substr($this->h($ad->html), 0, 100) . '...</pre>';
|
||||||
|
}
|
||||||
|
?></td>
|
||||||
<td><?= $this->linkTo($ad->referral_url, $ad->referral_url) ?></td>
|
<td><?= $this->linkTo($ad->referral_url, $ad->referral_url) ?></td>
|
||||||
<td><?= $ad->width ?></td>
|
<td><?= $ad->width ?></td>
|
||||||
<td><?= $ad->height ?></td>
|
<td><?= $ad->height ?></td>
|
||||||
|
@ -4,6 +4,26 @@
|
|||||||
<label><?= $this->humanize('id') ?></label>
|
<label><?= $this->humanize('id') ?></label>
|
||||||
<?= $this->ad->id ?>
|
<?= $this->ad->id ?>
|
||||||
</div>
|
</div>
|
||||||
|
<div>
|
||||||
|
<label><?= $this->humanize('ad_type') ?></label>
|
||||||
|
<?= $this->ad->ad_type ?>
|
||||||
|
</div>
|
||||||
|
<div>
|
||||||
|
<label><?= $this->humanize('status') ?></label>
|
||||||
|
<?= $this->ad->status ?>
|
||||||
|
</div>
|
||||||
|
<div>
|
||||||
|
<label><?= $this->humanize('hit_count') ?></label>
|
||||||
|
<?= $this->ad->hit_count ?>
|
||||||
|
</div>
|
||||||
|
<?php if ($this->ad->html) : ?>
|
||||||
|
<div>
|
||||||
|
<label>Html</label>
|
||||||
|
<pre style="font-size:1.15em;margin:0px;">
|
||||||
|
<?= $this->h($this->ad->html) ?>
|
||||||
|
</pre>
|
||||||
|
</div>
|
||||||
|
<?php else: ?>
|
||||||
<div>
|
<div>
|
||||||
<label><?= $this->humanize('image_url') ?></label>
|
<label><?= $this->humanize('image_url') ?></label>
|
||||||
<?= $this->ad->image_url ?>
|
<?= $this->ad->image_url ?>
|
||||||
@ -20,18 +40,7 @@
|
|||||||
<label><?= $this->humanize('height') ?></label>
|
<label><?= $this->humanize('height') ?></label>
|
||||||
<?= $this->ad->height ?>
|
<?= $this->ad->height ?>
|
||||||
</div>
|
</div>
|
||||||
<div>
|
<?php endif ?>
|
||||||
<label><?= $this->humanize('ad_type') ?></label>
|
|
||||||
<?= $this->ad->ad_type ?>
|
|
||||||
</div>
|
|
||||||
<div>
|
|
||||||
<label><?= $this->humanize('status') ?></label>
|
|
||||||
<?= $this->ad->status ?>
|
|
||||||
</div>
|
|
||||||
<div>
|
|
||||||
<label><?= $this->humanize('hit_count') ?></label>
|
|
||||||
<?= $this->ad->hit_count ?>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<?= $this->linkTo($this->t('buttons.edit'), $this->editAdvertisementPath($this->ad)) ?>
|
<?= $this->linkTo($this->t('buttons.edit'), $this->editAdvertisementPath($this->ad)) ?>
|
||||||
<?= $this->linkTo($this->t('buttons.delete'), $this->ad, ['data' => ['confirm' => $this->t('confirmations.is_sure')], 'method' => 'delete']) ?>
|
<?= $this->linkTo($this->t('buttons.delete'), $this->ad, ['data' => ['confirm' => $this->t('confirmations.is_sure')], 'method' => 'delete']) ?>
|
||||||
|
12
db/migrate/20131201031201_add_html_to_advertisements.php
Executable file
12
db/migrate/20131201031201_add_html_to_advertisements.php
Executable file
@ -0,0 +1,12 @@
|
|||||||
|
<?php
|
||||||
|
class AddHtmlToAdvertisements extends Rails\ActiveRecord\Migration\Base
|
||||||
|
{
|
||||||
|
public function up()
|
||||||
|
{
|
||||||
|
$this->addColumn('advertisements', 'html', 'text', ['null' => true]);
|
||||||
|
$this->changeColumn('advertisements', 'image_url', 'string', ['null' => true]);
|
||||||
|
$this->changeColumn('advertisements', 'referral_url', 'string', ['null' => true]);
|
||||||
|
$this->changeColumn('advertisements', 'width', 'integer', ['null' => true]);
|
||||||
|
$this->changeColumn('advertisements', 'height', 'integer', ['null' => true]);
|
||||||
|
}
|
||||||
|
}
|
Reference in New Issue
Block a user