You are here

public function InstapageCmsPluginPageModel::getPageStatsCache in Instapage plugin 8.3

Same name and namespace in other branches
  1. 7.3 core/models/InstapageCmsPluginPageModel.php \InstapageCmsPluginPageModel::getPageStatsCache()

Gets the cached statistics for pages.

Parameters

array $ids List of page IDs.:

Return value

array List of objects with stats cache informations.

File

core/models/InstapageCmsPluginPageModel.php, line 153

Class

InstapageCmsPluginPageModel
Class responsible for managing the landing pages.

Code

public function getPageStatsCache($ids) {
  if (!is_array($ids) || !count($ids)) {
    return null;
  }
  $db = InstapageCmsPluginDBModel::getInstance();
  foreach ($ids as &$item) {
    $item = intval($item);
  }
  $idsSet = implode(', ', $ids);
  $expireInSeconds = self::$statCacheDuration * 60;
  $sql = 'SELECT instapage_id, stats_cache FROM ' . $db->pagesTable . ' WHERE instapage_id IN(' . $idsSet . ') AND stats_cache_expires + ' . $expireInSeconds . ' > ' . time();
  $results = $db
    ->getResults($sql);
  $stats = array();
  if ($results) {
    foreach ($results as &$item) {
      $stats[$item->instapage_id] = json_decode($item->stats_cache);
    }
    return $stats;
  }
  return array();
}