Index: google_analytics_reports_views/google_analytics_reports_views.info IDEA additional info: Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP <+>UTF-8 =================================================================== --- google_analytics_reports_views/google_analytics_reports_views.info (revision e50321ee171ac47d07b977eadf94f7941ccd3f69) +++ google_analytics_reports_views/google_analytics_reports_views.info (revision ) @@ -12,3 +12,4 @@ files[] = handlers/google_analytics_reports_views_handler_filter_numeric.inc files[] = handlers/google_analytics_reports_views_handler_field.inc files[] = handlers/google_analytics_reports_views_handler_argument.inc +files[] = handlers/google_analytics_reports_views_plugin_argument.inc Index: google_analytics_reports_views/google_analytics_reports_views.views.inc IDEA additional info: Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP <+>UTF-8 =================================================================== --- google_analytics_reports_views/google_analytics_reports_views.views.inc (revision e50321ee171ac47d07b977eadf94f7941ccd3f69) +++ google_analytics_reports_views/google_analytics_reports_views.views.inc (revision ) @@ -117,5 +117,12 @@ 'handler' => 'google_analytics_reports_views_plugin_query_google_analytics', ), ), + 'argument default' => array( + 'google_analytics_reports_views_argument' => array( + 'title' => t("Google Analytics"), + 'handler' => 'google_analytics_reports_views_plugin_argument', + 'path' => drupal_get_path('module', 'google_analytics_reports_views') . '/views/handlers' + ) + ) ); } Index: google_analytics_reports_views/handlers/google_analytics_reports_views_plugin_argument.inc IDEA additional info: Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP <+>UTF-8 =================================================================== --- google_analytics_reports_views/handlers/google_analytics_reports_views_plugin_argument.inc (revision ) +++ google_analytics_reports_views/handlers/google_analytics_reports_views_plugin_argument.inc (revision ) @@ -0,0 +1,127 @@ + ''); + $options['dimensions'] = array('default' => ''); + $options['filters'] = array('default' => ''); + $options['start_date'] = array('default' => ''); + $options['end_date'] = array('default' => ''); + $options['sort_metric'] = array('default' => ''); + $options['start_index'] = array('default' => '1'); + $options['max_results'] = array('default' => '50'); + $options['entity'] = array('default' => 'node'); + + return $options; + } + + function options_form(&$form, &$form_state) { + $form['metrics'] = array( + '#type' => 'textarea', + '#title' => t('Metrics'), + '#description' => t('Enter one title per line.'), + '#default_value' => $this->options['metrics'], + ); + $form['dimensions'] = array( + '#type' => 'textarea', + '#title' => t('Dimensions'), + '#description' => t('Enter one title per line.'), + '#default_value' => $this->options['dimensions'], + ); + $form['filters'] = array( + '#type' => 'textarea', + '#title' => t('Filters'), + '#description' => t('Use , for OR and ; for AND operators.'), + '#default_value' => $this->options['filters'], + ); + $form['start_date'] = array( + '#type' => 'textfield', + '#title' => t('Start Date'), + '#description' => t('Enter Date or relative time (e.g. -2 Days).'), + '#default_value' => $this->options['start_date'], + ); + $form['end_date'] = array( + '#type' => 'textfield', + '#title' => t('End Date'), + '#description' => t('Enter Date or relative time (e.g. now).'), + '#default_value' => $this->options['end_date'], + ); + $form['sort_metric'] = array( + '#type' => 'textarea', + '#title' => t('Sort Metric'), + '#description' => t('Enter one title per line.'), + '#default_value' => $this->options['sort_metric'], + ); + $form['start_index'] = array( + '#type' => 'textfield', + '#title' => t('Start'), + '#description' => t('First Result.'), + '#default_value' => $this->options['start_index'], + ); + $form['max_results'] = array( + '#type' => 'textfield', + '#title' => t('Max Results'), + '#description' => t('Maximum Results.'), + '#default_value' => $this->options['max_results'], + ); + $form['entity'] = array( + '#type' => 'radios', + '#title' => t('Results'), + '#default_value'=> $this->options['entity'], + '#options' => array( + 'node' => t('Node IDs'), + 'term' => t('Taxonomy Term IDs'), + ), + ); + } + + function get_argument() { + $params['metrics'] = array_filter(array_map('trim', explode(PHP_EOL, $this->options['metrics'])), 'strlen'); + $params['dimensions'] = array_filter(array_map('trim', explode(PHP_EOL, $this->options['dimensions'])), 'strlen'); + $params['filters'] = array_filter(array_map('trim', explode(PHP_EOL, $this->options['filters'])), 'strlen'); + $params['sort_metric'] = array_filter(array_map('trim', explode(PHP_EOL, $this->options['sort_metric'])), 'strlen'); + $params['start_date'] = strtotime($this->options['start_date']); + $params['end_date'] = strtotime($this->options['end_date']); + $params['start_index'] = $this->options['start_index']; + $params['max_results'] = $this->options['max_results']; + + $feed = google_analytics_reports_api_report_data($params); + if ($feed->error) { + return FALSE; + } + + $nids = array(); + $tids = array(); + + foreach ($feed->results->rows as $row) { + $path = drupal_get_normal_path(trim($row['pagePath'], '/')); + $path_parts = explode('/', $path); + if ($path_parts[0] == 'node') { + $nids[] = $path_parts[1]; + } + else if ($path_parts[0] == 'taxonomy' && $path_parts[1] == 'term') { + $tids[] = $path_parts[2]; + } + } + if ($this->options['entity'] == 'node') { + return implode('+', $nids); + } + elseif ($this->options['entity'] == 'term') { + return implode('+', $tids); + } + else { + return NULL; + } + } +}