Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
Kevin Carter committed Oct 1, 2009
0 parents commit f6b2532
Show file tree
Hide file tree
Showing 18 changed files with 425 additions and 0 deletions.
7 changes: 7 additions & 0 deletions ads_app_controller.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<?php

class AdsAppController extends AppController {

}

?>
7 changes: 7 additions & 0 deletions ads_app_model.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<?php

class AdsAppModel extends AppModel {

}

?>
5 changes: 5 additions & 0 deletions controllers/ad_positions_controller.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<?php
class AdPositionsController extends AdsAppController {
var $name = 'AdPositions';
}
?>
5 changes: 5 additions & 0 deletions controllers/ad_rules_controller.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<?php
class AdRulesController extends AdsAppController {
var $name = 'AdRules';
}
?>
42 changes: 42 additions & 0 deletions controllers/ads_controller.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
<?php
class AdsController extends AdsAppController {
var $name = 'Ads';

function beforeFilter() {
parent::beforeFilter();
$this->Auth->allow('get');
}

function get($id) {
$this->data = $this->Ad->pullAd($id);

if (isset($this->params['requested'])) {
return $this->data;
}
}

function admin_add( ) {
parent::admin_add( );
$this->_setAdSizes( );
}

function admin_edit($id) {
parent::admin_edit($id);
$this->_setAdSizes($this->data['Ad']['ad_position_id']);
}

function _setAdSizes($position_id = null) {
$options['contain'] = 'AdRule';
if ($position_id) {
$position = $this->Ad->AdPosition->read(null, $position_id);
$options['conditions'] = array('AdRule.id' => $position['AdPosition']['ad_rule_id']);
}
$options['order'] = 'AdPosition.name';
$adPositions = $this->Ad->AdPosition->find('all', $options);
$sizes = Set::combine($adPositions, '/AdPosition/id', array('%s &times; %s', '/AdRule/width', '/AdRule/height'));
$adPositions = Set::combine($adPositions, '/AdPosition/id', array('%s (%sx%s)', '/AdPosition/name', '/AdRule/width', '/AdRule/height'));
$this->set(compact('sizes', 'adPositions'));
}

}
?>
38 changes: 38 additions & 0 deletions models/ad.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<?php
class Ad extends AdsAppModel {

var $name = 'Ad';
var $validate = array(
'name' => array('notempty'),
'ad_position_id' => array('numeric'),
'active' => array('numeric')
);

var $actsAs = array(
'Image' => array(
'fields' => array(
'src' => array(
'resize' => false,
),
),
),
);

var $belongsTo = array(
'Ads.AdPosition',
);

function pullAd($position_id) {
$ad = $this->find('first', array(
'conditions' => array(
'ad_position_id' => $position_id,
'active' => 1,
'NOW() BETWEEN Ad.start_date AND Ad.end_date',
),
'order' => 'created'
));
return $ad;
}

}
?>
19 changes: 19 additions & 0 deletions models/ad_position.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?php
class AdPosition extends AdsAppModel {

var $name = 'AdPosition';
var $validate = array(
'name' => array('notempty'),
'ad_rule_id' => array('numeric')
);

var $belongsTo = array(
'Ads.AdRule'
);

var $hasMany = array(
'Ads.Ad'
);

}
?>
16 changes: 16 additions & 0 deletions models/ad_rule.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?php
class AdRule extends AdsAppModel {

var $name = 'AdRule';
var $validate = array(
'name' => array('notempty'),
'width' => array('numeric'),
'height' => array('numeric')
);

var $hasMany = array(
'Ads.AdPosition',
);

}
?>
20 changes: 20 additions & 0 deletions views/ad_positions/admin_edit.ctp
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?php /* SVN FILE: $Id$ */
if ($data) {
extract($data);
}
$action = in_array($this->action, array('add', 'admin_add'))?'Add':'Edit';
$action = Inflector::humanize($action);
$name = isset($this->data[$modelClass]['name'])?$this->data[$modelClass]['name']:' new';
?>
<h1><?php echo $this->name . ' - ' . $action . ' ' . $name ?></h1>
<div class="form-container">
<?php
echo $form->create(null, array('type' => 'file'));
echo $form->inputs(array(
'legend' => false,
'id',
'name',
'ad_rule_id' => array('empty' => true),
));
echo $form->end('Submit');
?></div>
28 changes: 28 additions & 0 deletions views/ad_positions/admin_index.ctp
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?php /* SVN FILE: $Id$ */ ?>
<h1>Ad Positions</h1>
<div class="container">
<?php
$pass = $this->passedArgs;
$pass['action'] = str_replace(Configure::read('Routing.admin') . '_', '', $this->action); // temp
$paginator->options(array('url' => $pass));
?>
<table>
<?php
$th = array(
$paginator->sort('Id', 'id'),
$paginator->sort('Name', 'name'),
$paginator->sort('Ad Rule', 'AdRule.name'),
);
echo $html->tableHeaders($th);
foreach ($data as $row) {
extract($row);
$tr = array(
$html->link($AdPosition['id'], array('action' => 'view', $AdPosition['id'])),
$AdPosition['name'],
$AdRule?$AdRule['name']:'',
);
echo $html->tableCells($tr, array('class' => 'odd'), array('class' => 'even'));
}
?>
</table>
<?php echo $this->element('paging'); ?></div>
17 changes: 17 additions & 0 deletions views/ad_positions/admin_view.ctp
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?php /* SVN FILE: $Id$ */
extract($data); ?>
<h1><?php echo $AdPosition['name'] ?></h1>
<div class="container">
<table>
<?php
extract($data);
echo $html->tableCells(array('id',$AdPosition['id']));
echo $html->tableCells(array('name',$AdPosition['name']));
echo $html->tableCells(array('Ad Rule', $AdRule?$AdRule['name']:''));
?>
</table>
</div>
<?php
$menu->addm('View', array(
array('title' => $AdRule['name'], 'url' => array('controller' => 'ad_rules', 'action' => 'view', $AdPosition['ad_rule_id'])),
));
21 changes: 21 additions & 0 deletions views/ad_rules/admin_edit.ctp
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?php /* SVN FILE: $Id$ */
if ($data) {
extract($data);
}
$action = in_array($this->action, array('add', 'admin_add'))?'Add':'Edit';
$action = Inflector::humanize($action);
$name = isset($this->data[$modelClass]['name'])?$this->data[$modelClass]['name']:' new';
?>
<h1><?php echo $this->name . ' - ' . $action . ' ' . $name ?></h1>
<div class="form-container">
<?php
echo $form->create(null, array('type' => 'file'));
echo $form->inputs(array(
'legend' => false,
'id',
'name',
'width',
'height',
));
echo $form->end('Submit');
?></div>
30 changes: 30 additions & 0 deletions views/ad_rules/admin_index.ctp
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<?php /* SVN FILE: $Id$ */ ?>
<h1>Ad Rules</h1>
<div class="container">
<?php
$pass = $this->passedArgs;
$pass['action'] = str_replace(Configure::read('Routing.admin') . '_', '', $this->action); // temp
$paginator->options(array('url' => $pass));
?>
<table>
<?php
$th = array(
$paginator->sort('Id', 'id'),
$paginator->sort('Name', 'name'),
$paginator->sort('Width', 'width'),
$paginator->sort('Height', 'height'),
);
echo $html->tableHeaders($th);
foreach ($data as $row) {
extract($row);
$tr = array(
$html->link($AdRule['id'], array('action' => 'view', $AdRule['id'])),
$AdRule['name'],
$AdRule['width'],
$AdRule['height'],
);
echo $html->tableCells($tr, array('class' => 'odd'), array('class' => 'even'));
}
?>
</table>
<?php echo $this->element('paging'); ?></div>
17 changes: 17 additions & 0 deletions views/ad_rules/admin_view.ctp
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?php /* SVN FILE: $Id$ */
extract($data); ?>
<h1><?php echo $AdRule['name'] ?></h1>
<div class="container">
<table>
<?php
extract($data);
echo $html->tableCells(array('id',$AdRule['id']));
echo $html->tableCells(array('name',$AdRule['name']));
echo $html->tableCells(array('width',$AdRule['width']));
echo $html->tableCells(array('height',$AdRule['height']));
?>
</table>
</div>
<?php
$menu->addm('View', array(
));
35 changes: 35 additions & 0 deletions views/ads/admin_edit.ctp
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<?php /* SVN FILE: $Id$ */
if ($data) {
extract($data);
}
$image = null;
if ( !empty($this->data['Ad']['src']['path']) ) {
$image = $html->image($this->data['Ad']['src']['path']);

$pathBase = WWW_ROOT.'img'.DS;
if (file_exists($pathBase.$this->data['Ad']['src']['path'])) {
list($width, $height) = @getimagesize($pathBase.$this->data['Ad']['src']['path']);
$image .= "<br /><br /><b>Image Size:</b> ({$width}px &times; {$height}px)";
}
}
$action = in_array($this->action, array('add', 'admin_add'))?'Add':'Edit';
$action = Inflector::humanize($action);
$name = isset($this->data[$modelClass]['name'])?$this->data[$modelClass]['name']:' new';
?>
<h1><?php echo $this->name . ' - ' . $action . ' ' . $name ?></h1>
<div class="form-container">
<?php
echo $form->create(null, array('type' => 'file'));
echo $form->inputs(array(
'legend' => false,
'id',
'ad_position_id' => array('empty' => true),
'name',
'src' => array('type' => 'file', 'label' => 'Src<br />&nbsp;&nbsp;', 'after' => '<br/>'. $image),
'active',
'url',
'start_date',
'end_date',
));
echo $form->end('Submit');
?></div>
36 changes: 36 additions & 0 deletions views/ads/admin_index.ctp
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<?php /* SVN FILE: $Id$ */ ?>
<h1>Ads</h1>
<div class="container">
<?php
$pass = $this->passedArgs;
$pass['action'] = str_replace(Configure::read('Routing.admin') . '_', '', $this->action); // temp
$paginator->options(array('url' => $pass));
?>
<table>
<?php
$th = array(
$paginator->sort('Id', 'id'),
$paginator->sort('Ad Position', 'AdPosition.name'),
$paginator->sort('Name', 'name'),
$paginator->sort('Active', 'active'),
$paginator->sort('Url', 'url'),
$paginator->sort('Start Date', 'start_date'),
$paginator->sort('End Date', 'end_date'),
);
echo $html->tableHeaders($th);
foreach ($data as $row) {
extract($row);
$tr = array(
$html->link($Ad['id'], array('action' => 'view', $Ad['id'])),
$AdPosition?$AdPosition['name']:'',
$Ad['name'],
$Ad['active'],
$Ad['url'],
$Ad['start_date'],
$Ad['end_date'],
);
echo $html->tableCells($tr, array('class' => 'odd'), array('class' => 'even'));
}
?>
</table>
<?php echo $this->element('paging'); ?></div>
34 changes: 34 additions & 0 deletions views/ads/admin_view.ctp
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<?php /* SVN FILE: $Id$ */
extract($data); ?>
<h1><?php echo $Ad['name'] ?></h1>
<div class="container">
<table>
<?php
extract($data);

$size = '';
if (!empty($Ad['src']['path'])) {
$pathBase = WWW_ROOT.'img'.DS;

if (file_exists($pathBase.$Ad['src']['path'])) {
list($width, $height) = @getimagesize($pathBase.$Ad['src']['path']);
$size = "<br /><br /><b>Image Size:</b> ({$width}px &times; {$height}px)";
}
}
echo $html->tableCells(array('id',$Ad['id']));
echo $html->tableCells(array('Ad Position', $AdPosition?$AdPosition['name']:''));
echo $html->tableCells(array('name',$Ad['name']));
echo $html->tableCells(array('src', $html->image($Ad['src']['path']).$size));
echo $html->tableCells(array('created',$Ad['created']));
echo $html->tableCells(array('modified',$Ad['modified']));
echo $html->tableCells(array('active',$Ad['active']));
echo $html->tableCells(array('url',$Ad['url']));
echo $html->tableCells(array('start_date',$Ad['start_date']));
echo $html->tableCells(array('end_date',$Ad['end_date']));
?>
</table>
</div>
<?php
$menu->addm('View', array(
array('title' => $AdPosition['name'], 'url' => array('controller' => 'ad_positions', 'action' => 'view', $Ad['ad_position_id'])),
));
Loading

0 comments on commit f6b2532

Please sign in to comment.