You are on page 1of 6

model:

public function filter($params) {


//$conditions = array('User.account_type' => array('Free','Pro'));
$params = Set::filter($params);
foreach($params as $key => $value) {
if (!is_array($value)) {
$value = trim($value);
}
switch($key) {
case 'company':
$conditions['OR'] = array (
'PromoCode.company' => "$value",
);
break;
case 'refund':
if ($value != '') {
$conditions['AND'] = array (
'PromoCode.refund' => "$value",
);
} else {
$conditions['OR'] = array (
'PromoCode.refund' => "$value",
);
}
break;
case 'code':
$conditions['OR'] = array (
'PromoCode.code' => "$value",
);
break;
case 'member':
$conditions['OR'] = array (
'PromoCode.member_email' => "$value",

);
break;
}
}
return $conditions;
}
controller:
function status() {
$this->paginate = array(
'PromoCode' => array(
'contain' => array('PromoCode' => array(
'order' => array('PromoCode.id' => 'DESC'),
'limit' => 1
)),
'order' => array('PromoCode.id' => 'DESC'),
'limit' => 10
),
);
$this->set('promoCodes', $this->paginate('PromoCode',$this->PromoCode>filter($this->params['url'])));
}

---------------view-------<div class="promoCodes index">


<div id="sidebar" style="width: 15%">
<h2>Codes Status</h2>
<?php echo $this->Form->create('PromoCode',array('url' => Router::url(),'type' =>
'get')); ?>

<br>
By Code:
<input type="text" size="18" name="code" <? if ($_GET['code'] != '') { echo
'value = ' . $_GET['code']; } ?> >
<br><br><br>
By Member:
<input type="text" size="18" name="member" <? if ($_GET['member'] != '')
{ echo 'value = ' . $_GET['member']; } ?>>
<br><br><br>
By Company:
<br>
<select name="company">
<? if ($_GET['company'] == 'All') { ?>
<option value="" selected>All</option>
<? } else { ?>
<option value="">All</option>
<? } ?>
<? if ($_GET['company'] == 'GOOGLE') { ?>
<option value="GOOGLE" selected>Google</option>
<? } else { ?>
<option value="GOOGLE">Google</option>
<? } ?>
<? if ($_GET['company'] == 'NA') { ?>
<option value="NA" selected>Na</option>
<? } else { ?>
<option value="NA">Na</option>
<? } ?>
</select>
<br><br>
Refund:
<br>
<select name="refund">
<? if ($_GET['refund'] == 'All') { ?>
<option value="" selected>All</option>

<? } else { ?>


<option value="">All</option>
<? } ?>
<? if ($_GET['refund'] == 'YES') { ?>
<option value="YES" selected>Yes</option>
<? } else { ?>
<option value="YES">Yes</option>
<? } ?>
<? if ($_GET['refund'] == 'NO') { ?>
<option value="NO" selected>No</option>
<? } else { ?>
<option value="NO">No</option>
<? } ?>
</select>
<br><br>
<?php echo $this->Form->end('Filter'); ?>
</div>
<div id="inner_content" style="width: 80%">
<h2><?php __('Promo Codes');?><?php echo $this->Html->link(__('+ add', true),
array('action' => 'add'),array('class' => 'right')); ?></h2>
<?php e($this->element('pagination/results', array('results' => $promoCodes))); ?>
<table cellpadding="0" cellspacing="0">
<tr>
<th><?php echo $this->Paginator->sort('id');?></th>
<th><?php echo $this->Paginator->sort('code');?></th>
<th><?php echo $this->Paginator->sort('free');?></th>
<th><?php echo $this->Paginator->sort('free_period');?></th>
<th><?php echo $this->Paginator->sort('membership_type');?></th>
<th><?php echo $this->Paginator->sort('discount');?></th>
<th><?php echo $this->Paginator->sort('price');?></th>

<th><?php echo $this->Paginator->sort('active');?></th>


<th><?php echo $this->Paginator->sort('company');?></th>
<th><?php echo $this->Paginator->sort('refund');?></th>
<th><?php echo $this->Paginator->sort('member');?></th>
<th class="actions"><?php __('Actions');?></th>
</tr>
<?php
$i = 0;
foreach ($promoCodes as $promoCode):
$class = null;
if ($i++ % 2 == 0) {
$class = ' class="altrow"';
}
?>
<tr<?php echo $class;?>>
<td><?php echo $promoCode['PromoCode']['id']; ?>&nbsp;</td>
<td><?php echo $promoCode['PromoCode']['code']; ?>&nbsp;</td>
<td><?php echo $promoCode['PromoCode']['free']; ?>&nbsp;</td>
<td><?php echo $promoCode['PromoCode']['free_period']; ?>&nbsp;</td>
<td><?php echo $promoCode['PromoCode']['membership_type']; ?
>&nbsp;</td>
<td><?php echo $promoCode['PromoCode']['discount']; ?>&nbsp;</td>
<td><?php echo $promoCode['PromoCode']['price']; ?>&nbsp;</td>
<td><?php echo $promoCode['PromoCode']['active']; ?>&nbsp;</td>
<td><?php echo $promoCode['PromoCode']['company']; ?>&nbsp;</td>
<td><?php echo $promoCode['PromoCode']['refund']; ?>&nbsp;</td>
<td><?php echo $promoCode['PromoCode']['member_email']; ?
>&nbsp;</td>
<td class="actions">
<?php if ($promoCode['PromoCode']['active']): ?>
<?php echo $this->Html->link('Active','/change-statusinactive/model:PromoCode/field:active/foreing_key:'.$promoCode['PromoCode']['id']); ?
>
<?php else: ?>
<?php echo $this->Html->link('Inactive','/change-statusactive/model:PromoCode/field:active/foreing_key:'.$promoCode['PromoCode']['id']); ?>

<?php endif; ?>


<?php echo $this->Html->link(__('Edit', true), array('action' => 'edit',
$promoCode['PromoCode']['id'])); ?>
<?php echo $this->Html->link(__('Delete', true), array('action' => 'delete',
$promoCode['PromoCode']['id']), null, sprintf(__('Are you sure you want to delete #
%s?', true), $promoCode['PromoCode']['id'])); ?>
</td>
</tr>
<?php endforeach; ?>
</table>
<?php e($this->element('pagination/pages', array('results' => $promoCodes))); ?>
</div>
</div>