Skip to content

Commit

Permalink
Add random method
Browse files Browse the repository at this point in the history
  • Loading branch information
Kevin Carter committed Oct 1, 2009
1 parent 1e0d69c commit 02d0d83
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 7 deletions.
5 changes: 3 additions & 2 deletions controllers/ads_controller.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,9 @@ function beforeFilter() {
$this->Auth->allow('get');
}

function get($id) {
$this->data = $this->Ad->pullAd($id);
function get($id, $random = false) {
$random = (bool)$random;
$this->data = $this->Ad->pullAd($id, $random);

if (isset($this->params['requested'])) {
return $this->data;
Expand Down
6 changes: 4 additions & 2 deletions models/ad.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,16 @@ class Ad extends AdsAppModel {
'Ads.AdPosition',
);

function pullAd($position_id) {
function pullAd($position_id, $random = false) {
$order = 'created';
if ( $random ) $order = 'RAND()';
$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'
'order' => $order,
));
return $ad;
}
Expand Down
22 changes: 19 additions & 3 deletions views/helpers/adhelper.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?php
class AdhelperHelper extends AppHelper {

var $helpers = array('Html');
var $helpers = array('Html', 'UploadPack.Upload');

function show($id, $options = array()) {
$options = array_merge(array(
Expand Down Expand Up @@ -32,8 +32,8 @@ function show($id, $options = array()) {
// echo $view->element('content_cached', $options);

$out = '';
if ( !empty($data['Ad']['src']['path']) ) {
$out.= $this->Html->image($data['Ad']['src']['path'], array(
if ( !empty($data['Ad']['image_file_name']) ) {
$out.= $this->Upload->image($data, 'Ad.image', 'original', array(
'url' => $data['Ad']['url'],
));
}
Expand All @@ -44,5 +44,21 @@ function show($id, $options = array()) {
return $out;
}

function random($id, $options = array()) {
$options = array_merge(array(
'imageOptions' => array(),
), $options);
$data = $this->requestAction('/ads/get/'.$id.'/random');

$out = '';
if ( !empty($data['Ad']['image_file_name']) ) {
$out.= $this->Upload->image($data, 'Ad.image', 'original', array_merge(array(
'url' => $data['Ad']['url'],
), $options['imageOptions'])
);
}
return $out;
}

}
?>

0 comments on commit 02d0d83

Please sign in to comment.