function _simpleads_campaign_listing in SimpleAds 7
Menu callback. Campaigns listing page.
1 string reference to '_simpleads_campaign_listing'
- simpleads_campaigns_menu in modules/
simpleads_campaigns/ simpleads_campaigns.module - Implements hook_menu().
File
- modules/
simpleads_campaigns/ campaigns.admin.inc, line 20 - SimpleAds Campaigns menu callbacks.
Code
function _simpleads_campaign_listing() {
drupal_set_title(t('Advertisement Campaigns'));
$header = array(
array(
'data' => '',
),
array(
'data' => t('Campaign'),
),
array(
'data' => t('Start Date'),
),
array(
'data' => t('Impressions'),
),
array(
'data' => t('Clicks'),
),
array(
'data' => t('Days'),
),
array(
'data' => t('Active'),
),
array(
'data' => t('Operations'),
),
);
$query = db_select('node', 'n')
->extend('PagerDefault')
->limit(15);
$query
->fields('n', array(
'nid',
));
$query
->condition('n.type', 'simpleads_campaign');
$query
->orderBy('n.changed', 'DESC');
$results = $query
->execute();
$rows = array();
foreach ($results as $i => $record) {
$query = db_select('node', 'n');
$query
->join('field_data_field_adcamp_list', 'l', 'l.entity_id = n.nid AND l.revision_id = n.vid');
$query
->fields('n', array(
'nid',
));
$query
->fields('l', array(
'field_adcamp_list_value',
));
$query
->condition('n.type', 'simpleads');
$query
->condition('l.field_adcamp_list_value', $record->nid);
$query
->addTag('node_access');
$count = $query
->countQuery()
->execute()
->fetchField();
$node = node_load($record->nid);
if ($node) {
$impressions = '-';
if (isset($node->field_adcamp_impression[$node->language]) && $node->field_adcamp_impression[$node->language][0]['value'] == 1) {
if (isset($node->field_adcamp_impressions[$node->language]) && !empty($node->field_adcamp_impressions[$node->language][0]['safe_value'])) {
$impressions = $node->field_adcamp_impressions[$node->language][0]['safe_value'];
}
}
$clicks = '-';
if (isset($node->field_adcamp_click[$node->language]) && $node->field_adcamp_click[$node->language][0]['value'] == 1) {
if (isset($node->field_adcamp_clicks[$node->language]) && !empty($node->field_adcamp_clicks[$node->language][0]['safe_value'])) {
$clicks = $node->field_adcamp_clicks[$node->language][0]['safe_value'];
}
}
$days = '-';
if (isset($node->field_adcamp_day[$node->language]) && $node->field_adcamp_day[$node->language][0]['value'] == 1) {
if (isset($node->field_adcamp_days[$node->language]) && !empty($node->field_adcamp_days[$node->language][0]['safe_value'])) {
$days = $node->field_adcamp_days[$node->language][0]['safe_value'];
}
}
$start_date = '-';
if (isset($node->field_adcamp_start[$node->language]) && !empty($node->field_adcamp_start[$node->language][0]['value'])) {
if (isset($node->field_adcamp_start[$node->language]) && !empty($node->field_adcamp_start[$node->language][0]['safe_value'])) {
$start_date = $node->field_adcamp_start[$node->language][0]['safe_value'];
}
}
$is_active = t('No');
if ($node->status == 1) {
$is_active = t('Yes');
}
$rows[] = array(
array(
'data' => $i + 1,
),
array(
'data' => l($node->title, 'admin/content/simpleads_campaigns/' . $node->nid) . ' (' . $count . ')',
),
array(
'data' => $start_date,
),
array(
'data' => $impressions,
),
array(
'data' => $clicks,
),
array(
'data' => $days,
),
array(
'data' => $is_active,
),
array(
'data' => l(t('View'), 'admin/content/simpleads_campaigns/' . $node->nid, array(
'query' => array(
'destination' => 'admin/content/simpleads_campaigns',
),
)) . ' ' . l(t('Edit'), 'node/' . $node->nid . '/edit', array(
'query' => array(
'destination' => 'admin/content/simpleads_campaigns',
),
)) . ' ' . l(t('Delete'), 'node/' . $node->nid . '/delete', array(
'query' => array(
'destination' => 'admin/content/simpleads_campaigns',
),
)) . ' ',
),
);
}
}
return theme('table', array(
'header' => $header,
'rows' => $rows,
'empty' => t('There are no Campaigns'),
)) . theme('pager');
}