diff ad.admin.inc @ 1:948362c2a207 ad

update advertisement
author pierre
date Thu, 02 Apr 2009 15:28:21 +0000
parents d8a3998dac8e
children 416ea999ed76
line wrap: on
line diff
--- a/ad.admin.inc	Fri Feb 20 14:04:09 2009 +0000
+++ b/ad.admin.inc	Thu Apr 02 15:28:21 2009 +0000
@@ -1,5 +1,5 @@
 <?php
-// $Id: ad.admin.inc,v 1.1.2.9 2009/02/17 19:22:45 jeremy Exp $
+// $Id: ad.admin.inc,v 1.1.2.9.2.2 2009/03/02 07:31:23 jeremy Exp $
 
 /**
  * @file
@@ -89,11 +89,6 @@
       'callback' => 'ad_operations_callback',
       'callback arguments' => array('offline'),
     ),
-    'unpublished' => array(
-      'label' => t('Mark as unpublished'),
-      'callback' => 'ad_operations_callback',
-      'callback arguments' => array('unpublished'),
-    ),
     'denied' => array(
       'label' => t('Mark as denied'),
       'callback' => 'ad_operations_callback',
@@ -234,6 +229,7 @@
     call_user_func_array($function, $args);
 
     cache_clear_all();
+    ad_rebuild_cache(TRUE);
     drupal_set_message(t('The update has been performed.'));
   }
 }
@@ -262,6 +258,20 @@
         break;
       case 'type':
         $where[] = "a.adtype = '%s'";
+      default:
+        $return = module_invoke_all('adapi', 'admin_filter_query', $filter);
+        foreach ($return as $module => $funcs) {
+          if (isset($funcs['where'])) {
+            $where[] = $funcs['where'];
+          }
+          if (isset($funcs['join'])) {
+            $join .= $funcs['join'];
+          }
+          if (isset($funcs['value'])) {
+            $value = $funcs['value'];
+          }
+        }
+        break;
     }
     $args[] = $value;
   }
@@ -283,14 +293,12 @@
     'approved-1' => t('approved'),
     'active-1' => t('active'),
     'offline-1' => t('offline'),
-    'unpublished-1' => t('unpublished'),
     'expired-1' => t('expired'),
     'denied-1' => t('denied'),
     'pending-0' => t('not pending'),
     'approved-0' => t('not approved'),
     'active-0' => t('not active'),
     'offline-0' => t('not offline'),
-    'unpublished-0' => t('not unpublished'),
     'expired-0' => t('not expired'),
     'denied-0' => t('not denied')
   );
@@ -315,6 +323,7 @@
     $filters['group'] = array('title' => t('group'), 'options' => $options);
   }
 
+  $filters = array_merge($filters, module_invoke_all('adapi', 'admin_filters', array()));
   return $filters;
 }
 
@@ -470,104 +479,6 @@
   }
 }
 
-
-/**
- *
- */
-function ad_admin_statistics($form_state) {
-  $groups = ad_groups_list(TRUE);
-  foreach ($groups as $tid => $group) {
-    if ($tid) {
-      $ads = db_result(db_query("SELECT count(aid) FROM {ads} a JOIN {term_node} t ON a.aid = t.nid WHERE t.tid = %d AND adstatus = 'active'", $tid));
-      $filter = "= ". $tid;
-    }
-    else {
-      $ads = db_result(db_query("SELECT count(aid) FROM {ads} a LEFT JOIN {term_node} t ON a.aid = t.nid WHERE t.tid IS NULL AND adstatus = 'active'"));
-      $filter = "IS NULL";
-    }
-    if (!$ads) {
-      continue;
-    }
-
-    $form[$group->name] = array(
-      '#type' => 'fieldset',
-      '#title' => check_plain($group->name),
-      '#collapsible' => TRUE,
-    );
-
-    // Get overall global statistics.
-    $statistics['global']['views'] = (int)db_result(db_query("SELECT SUM(s.count) FROM {ad_statistics} s LEFT JOIN {ads} a ON s.aid = a.aid LEFT JOIN {term_node} n ON a.aid = n.nid WHERE action = 'view' AND n.tid %s", $filter));
-    $statistics['global']['clicks'] = (int)db_result(db_query("SELECT SUM(s.count) FROM {ad_statistics} s LEFT JOIN {ads} a ON s.aid = a.aid LEFT JOIN {term_node} n ON a.aid = n.nid WHERE action = 'click' AND n.tid %s", $filter));
-
-    // Get overall statistics for this year and last year.
-    $this_year = date('Y000000');
-    $last_year = date('Y') - 1 .'000000';
-    $statistics['last_year']['views'] = (int)db_result(db_query("SELECT SUM(s.count) FROM {ad_statistics} s LEFT JOIN {ads} a ON s.aid = a.aid LEFT JOIN {term_node} n ON a.aid = n.nid WHERE action = 'view' AND date >= %d AND date <= %d AND n.tid %s", $last_year, $this_year, $filter));
-    $statistics['last_year']['clicks'] = (int)db_result(db_query("SELECT SUM(s.count) FROM {ad_statistics} s LEFT JOIN {ads} a ON s.aid = a.aid LEFT JOIN {term_node} n ON a.aid = n.nid WHERE action = 'click' AND date >= %d AND date <= %d AND n.tid %s", $last_year, $this_year, $filter));
-    $statistics['this_year']['views'] = (int)db_result(db_query("SELECT SUM(s.count) FROM {ad_statistics} s LEFT JOIN {ads} a ON s.aid = a.aid LEFT JOIN {term_node} n ON a.aid = n.nid WHERE action = 'view' AND date >= %d AND n.tid %s", $this_year, $filter));
-    $statistics['this_year']['clicks'] = (int)db_result(db_query("SELECT SUM(s.count) FROM {ad_statistics} s LEFT JOIN {ads} a ON s.aid = a.aid LEFT JOIN {term_node} n ON a.aid = n.nid WHERE action = 'click' AND date >= %d AND n.tid %s", $this_year, $filter));
-
-    // Get statistics for this month and last month.
-    $this_month = date('Ym0000');
-    $last_month = date('m') - 1;
-    if ($last_month == 0) {
-      $last_month = date('Y') - 1 .'120000';
-    }
-    else {
-      $last_month = date('Y') . ($last_month < 10 ? '0' : '') . $last_month .'0000';
-    }
-    $statistics['last_month']['views'] = (int)db_result(db_query("SELECT SUM(s.count) FROM {ad_statistics} s LEFT JOIN {ads} a ON s.aid = a.aid LEFT JOIN {term_node} n ON a.aid = n.nid WHERE action = 'view' AND date >= %d AND date <= %d AND n.tid %s", $last_month, $this_month, $filter));
-    $statistics['last_month']['clicks'] = (int)db_result(db_query("SELECT SUM(s.count) FROM {ad_statistics} s LEFT JOIN {ads} a ON s.aid = a.aid LEFT JOIN {term_node} n ON a.aid = n.nid WHERE action = 'click' AND date >= %d AND date <= %d AND n.tid %s", $last_month, $this_month, $filter));
-    $statistics['this_month']['views'] = (int)db_result(db_query("SELECT SUM(s.count) FROM {ad_statistics} s LEFT JOIN {ads} a ON s.aid = a.aid LEFT JOIN {term_node} n ON a.aid = n.nid WHERE action = 'view' AND date >= %d AND n.tid %s", $this_month, $filter));
-    $statistics['this_month']['clicks'] = (int)db_result(db_query("SELECT SUM(s.count) FROM {ad_statistics} s LEFT JOIN {ads} a ON s.aid = a.aid LEFT JOIN {term_node} n ON a.aid = n.nid WHERE action = 'click' AND date >= %d AND n.tid %s", $this_month, $filter));
-
-    // Get statistics for this week.
-    $this_week_start = date('Ymd00', time() - 60*60*24*6);
-    $statistics['this_week']['views'] = (int)db_result(db_query("SELECT SUM(s.count) FROM {ad_statistics} s LEFT JOIN {ads} a ON s.aid = a.aid LEFT JOIN {term_node} n ON a.aid = n.nid WHERE action = 'view' AND date >= %d AND n.tid %s", $this_week_start, $filter));
-    $statistics['this_week']['clicks'] = (int)db_result(db_query("SELECT SUM(s.count) FROM {ad_statistics} s LEFT JOIN {ads} a ON s.aid = a.aid LEFT JOIN {term_node} n ON a.aid = n.nid WHERE action = 'click' AND date >= %d AND n.tid %s", $this_week_start, $filter));
-
-    // Get statistics for yesterday and today.
-    $yesterday_start = date('Ymd00', time() - 60*60*24);
-    $yesterday_end = date('Ymd24', time() - 60*60*24);
-    $today_start = date('Ymd00', time());
-    $statistics['yesterday']['views'] = (int)db_result(db_query("SELECT SUM(s.count) FROM {ad_statistics} s LEFT JOIN {ads} a ON s.aid = a.aid LEFT JOIN {term_node} n ON a.aid = n.nid WHERE action = 'view' AND date >= %d AND date <= %d AND n.tid %s", $yesterday_start, $yesterday_end, $filter));
-    $statistics['yesterday']['clicks'] = (int)db_result(db_query("SELECT SUM(s.count) FROM {ad_statistics} s LEFT JOIN {ads} a ON s.aid = a.aid LEFT JOIN {term_node} n ON a.aid = n.nid WHERE action = 'click' AND date >= %d AND date <= %d AND n.tid %s", $yesterday_start, $yesterday_end, $filter));
-    $statistics['today']['views'] = (int)db_result(db_query("SELECT SUM(s.count) FROM {ad_statistics} s LEFT JOIN {ads} a ON s.aid = a.aid LEFT JOIN {term_node} n ON a.aid = n.nid WHERE action = 'view' AND date >= %d AND n.tid %s", $today_start, $filter));
-    $statistics['today']['clicks'] = (int)db_result(db_query("SELECT SUM(s.count) FROM {ad_statistics} s LEFT JOIN {ads} a ON s.aid = a.aid LEFT JOIN {term_node} n ON a.aid = n.nid WHERE action = 'click' AND date >= %d AND n.tid %s", $today_start, $filter));
-
-    // Get statistics for this hour and the last hour.
-    $last_hour = date('YmdH', time() - 60*60);
-    $this_hour = date('YmdH', time());
-    $statistics['last_hour']['views'] = (int)db_result(db_query("SELECT SUM(s.count) FROM {ad_statistics} s LEFT JOIN {ads} a ON s.aid = a.aid LEFT JOIN {term_node} n ON a.aid = n.nid WHERE action = 'view' AND date = %d AND n.tid %s", $last_hour, $filter));
-    $statistics['last_hour']['clicks'] = (int)db_result(db_query("SELECT SUM(s.count) FROM {ad_statistics} s LEFT JOIN {ads} a ON s.aid = a.aid LEFT JOIN {term_node} n ON a.aid = n.nid WHERE action = 'click' AND date = %d AND n.tid %s", $last_hour, $filter));
-    $statistics['this_hour']['views'] = (int)db_result(db_query("SELECT SUM(s.count) FROM {ad_statistics} s LEFT JOIN {ads} a ON s.aid = a.aid LEFT JOIN {term_node} n ON a.aid = n.nid WHERE action = 'view' AND date = %d AND n.tid %s", $this_hour, $filter));
-    $statistics['this_hour']['clicks'] = (int)db_result(db_query("SELECT SUM(s.count) FROM {ad_statistics} s LEFT JOIN {ads} a ON s.aid = a.aid LEFT JOIN {term_node} n ON a.aid = n.nid WHERE action = 'click' AND date = %d AND n.tid %s", $this_hour, $filter));
-
-    // TODO: Create this view and remove the && FALSE to enable this code.
-    if (module_exists('views') && FALSE) {
-      $form[$group->name]['statistics'] = array(
-        '#type' => 'markup',
-        '#value' => '<p>'. format_plural($ads, 'There is <a href="!url">1 active ad</a> in this group.', 'There are <a href="!url">%count</a> active ads in this group.', array('!url' => url('ad/'. $group->tid .'/group'))) .'</p>'. theme('ad_statistics_display', $statistics),
-      );
-    }
-    else {
-      $form[$group->name]['statistics'] = array(
-        '#type' => 'markup',
-        '#value' => '<p>'. format_plural($ads, 'There is 1 active ad in this group.', 'There are @count active ads in this group.') .'</p>'. theme('ad_statistics_display', $statistics),
-      );
-    }
-  }
-
-  if (!isset($form) || count($form) == 0) {
-    $form['header'] = array(
-      '#type' => 'markup',
-      '#value' => '<p>'. t('There are no active ads.') .'</p>',
-    );
-  }
-
-  return $form;
-}
-
 /**
  * Display a form for the ad module settings.
  */