You are here

function kwresearch_save_keyword_record_stats in Keyword Research 6

Same name and namespace in other branches
  1. 7 includes/stats.inc \kwresearch_save_keyword_record_stats()

Saves keyword stats data to site keywords table

Parameters

$keywords_data:

$params:

1 call to kwresearch_save_keyword_record_stats()
kwresearch_get_keyword_stats_data in includes/stats.inc
Generates analysis data for keyword stats report. Data is generated by

File

includes/stats.inc, line 121
Functions for generating data for keyword stats reports. Implements a kwresearch_sources API.

Code

function kwresearch_save_keyword_record_stats($keywords_data, $params) {
  if (is_array($keywords_data)) {
    foreach ($keywords_data as $k => $data) {
      if (substr($k, 0, 1) == '_') {
        continue;
      }
      $kw_obj = kwresearch_load_site_keyword($data['term']);
      if (!$kw_obj) {
        $kid = kwresearch_save_site_keyword($data['term']);
        $kw_obj = kwresearch_load_site_keyword($kid);
      }
      else {
        $kid = $kw_obj->kid;
      }
      $keywords_data[$k]['kid'] = (int) $kw_obj->kid;
      $keywords_data[$k]['priority'] = (int) $kw_obj->priority;
      $keywords_data[$k]['value'] = (double) $kw_obj->value;
      $keywords_data[$k]['page_count'] = (int) $kw_obj->page_count;
      $sql = '
        UPDATE {kwresearch_keyword}
        SET
          stats_update = %d,
          daily_volume = %d,
          competition = %d,
          bid = %f
        WHERE kid = "%d"
      ';
      db_query($sql, time(), $data['_searches'], $data['_competition'], $data['_bid'], $kid);
    }
  }
  return $keywords_data;
}