You are here

function kwresearch_save_keyword_record_stats in Keyword Research 7

Same name and namespace in other branches
  1. 6 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 132
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 = :stats_update,
          daily_volume = :daily_volume,
          competition = :competition,
          bid = :bid
        WHERE kid = :kid
      ';
      $args = array(
        ':stats_update' => time(),
        ':daily_volume' => $data['_searches'],
        ':competition' => isset($data['_competition']) ? $data['_competition'] : -1,
        ':bid' => isset($data['_bid']) ? $data['_bid'] : -1,
        ':kid' => $kid,
      );
      db_query($sql, $args);
    }
  }
  return $keywords_data;
}