예제 #1
0
 public function GetKeywordsAndBrandsByItsGroups($group_id, $type)
 {
     $this->load->model('ranking_model');
     if ($type == 'keyword') {
         $return = $this->ranking_model->getTermsIdsByGroupId($group_id);
     } else {
         if ($type == 'brand') {
             $return = $this->ranking_model->getRankingBrandsByGroupId($group_id);
         } else {
             $return = false;
         }
     }
     $this->output->set_content_type('application/json')->set_output(json_encode($return));
 }
예제 #2
0
 /**
  * @param $new_summary_data_array
  * @param $siteIds
  * @param $dates
  * @param $terms
  * @param $brandIds
  * @param $plistIds
  *
  * @return mixed
  */
 private function populateShareOfShelfData(&$new_summary_data_array, $siteIds, $dates, $terms, $brandIds, $plistIds)
 {
     $termIds = [];
     foreach ($terms as $term) {
         $termIds[] = $term->id;
         if (!in_array($term->id, $new_summary_data_array['all_results_for_body']['search_terms_list'])) {
             $new_summary_data_array['all_results_for_body']['search_terms_list'][] = $term;
         }
     }
     foreach ($siteIds as $site) {
         $all_results_for_body = array();
         $data_prepared = $this->ranking_model->getProductsByTerm($site, $dates, $termIds, 'rsri.ranking', 'asc', $brandIds, 0, false, $plistIds);
         $new_summary_data_array['curr_group_terms_count'] += Ranking_model::get_ofp_total_count($data_prepared, $all_results_for_body);
         foreach (['terms', 'brands', 'brand_terms'] as $fieldKey) {
             if (!empty($all_results_for_body[$fieldKey])) {
                 foreach ($all_results_for_body[$fieldKey] as $key => $arfb) {
                     if (!array_key_exists($key, $new_summary_data_array['all_results_for_body'][$fieldKey])) {
                         $new_summary_data_array['all_results_for_body'][$fieldKey][$key] = 0;
                     }
                     $new_summary_data_array['all_results_for_body'][$fieldKey][$key] += $arfb;
                 }
             }
         }
         foreach ($terms as $cur_term) {
             $group_name = !empty($cur_term->title) ? $cur_term->title : '';
             $ofp_count = $this->ranking_model->getOfpCountByTerm($site, $dates, $cur_term->id, array(), $plistIds);
             if (!array_key_exists($group_name, $new_summary_data_array['all_results_for_body']['serch_terms_ofp'])) {
                 $new_summary_data_array['all_results_for_body']['serch_terms_ofp'][$group_name] = 0;
             }
             $new_summary_data_array['all_results_for_body']['serch_terms_ofp'][$group_name] += $ofp_count;
             $new_summary_data_array['all_results_for_body']['serch_terms_ofp']['summary_ofp_count'] += $ofp_count;
         }
     }
     return $new_summary_data_array;
 }
예제 #3
0
 private function calculate_findable_score($params)
 {
     $this->load->model('ranking_model');
     $findable = 0;
     $all_results_for_body = array();
     $data_prepared = $this->ranking_model->getProductsByTerm($params['rank_sites'], $params['rank_date'], $params['rank_terms'], 'rsri.ranking', 'asc', $params['rank_brand']);
     $summary_data = Ranking_model::get_ofp_total_count($data_prepared, $all_results_for_body);
     $possible_spot = 0;
     foreach ($params['rank_sites'] as $site) {
         foreach ($params['rank_terms'] as $cur_term) {
             $possible_spot += $this->ranking_model->getOfpCountByTerm($site, $params['rank_date'], $cur_term, array());
         }
     }
     if (!empty($possible_spot)) {
         $findable = round($summary_data / $possible_spot * 100);
     }
     return $findable;
 }
예제 #4
0
 protected function amazon_urls_unification()
 {
     $this->load->model('ranking_model');
     $time_started = gmdate('Y-m-d H:i:s');
     $time_total_begin = microtime(true);
     $stats = array('rsri_urls_limit' => 0, 'rsri_urls_selected' => 0, 'rsri_urls_selected_unique' => 0, 'product_urls_exists' => 0, 'rsri_urls_updated' => 0, 'time_started' => $time_started, 'time_select_rsri' => 0, 'time_select_product_url' => 0, 'time_update_rsri' => 0, 'time_total' => 0);
     $settings = $this->db->where('key', 'amazon_urls_unification_limit')->get('settings')->row();
     $rsri_urls_limit = 1000;
     if (!empty($settings->id)) {
         $rsri_urls_limit = intval($settings->description);
     } else {
         $this->db->insert('settings', array('key' => 'amazon_urls_unification_limit', 'description' => $rsri_urls_limit));
     }
     $stats['rsri_urls_limit'] = $rsri_urls_limit;
     $result = array();
     if ($rsri_urls_limit > 0) {
         $time_begin = microtime(true);
         $result = $this->db->select('id, url')->from('ranking_search_results_items')->where("url ~ 'https?://(?:www\\.)?amazon\\.c(?:om|o\\.uk|a)/(?:.*?/)?dp/.+?/.*'")->limit($rsri_urls_limit)->get()->result();
         $stats['time_select_rsri'] = number_format(microtime(true) - $time_begin, 2);
         $stats['rsri_urls_selected'] = count($result);
         $urls = array();
         foreach ($result as $rsri) {
             $good_url = MY_Model::unifyAmazonUrl($rsri->url);
             if (!empty($good_url)) {
                 if (!array_key_exists($good_url, $urls)) {
                     $urls[$good_url] = array('rsri_ids' => array(), 'product_url_id' => null);
                 }
                 $urls[$good_url]['rsri_ids'][] = $rsri->id;
             }
         }
         $stats['rsri_urls_selected_unique'] = count($urls);
         // get product_url ids for $good_urls
         $product_urls_exists = 0;
         if (!empty($urls)) {
             $time_begin = microtime(true);
             $result = $this->db->select('id, url')->from('product_url')->where_in('url', array_keys($urls))->get()->result();
             $stats['time_select_product_url'] = number_format(microtime(true) - $time_begin, 2);
             foreach ($result as $product_url) {
                 if (array_key_exists($product_url->url, $urls) && empty($urls[$product_url->url]['product_url_id'])) {
                     $urls[$product_url->url]['product_url_id'] = $product_url->id;
                     $product_urls_exists++;
                 }
             }
         }
         $stats['product_urls_exists'] = $product_urls_exists;
         // update ranking_search_results_items
         $rsri_urls_updated = 0;
         $time_begin = microtime(true);
         foreach ($urls as $good_url => $url_data) {
             if (!empty($good_url)) {
                 if (empty($url_data['product_url_id'])) {
                     // create product_url
                     $product_url_data = array('url' => $good_url);
                     $url_data['product_url_id'] = $this->ranking_model->create_('product_url', $product_url_data);
                 }
                 if (!empty($url_data['product_url_id']) && !empty($url_data['rsri_ids'])) {
                     $rsri_data = array('url' => $good_url, 'url_id' => $url_data['product_url_id']);
                     $rsri_where = array('id' => $url_data['rsri_ids']);
                     if ($result = $this->ranking_model->update_('ranking_search_results_items', $rsri_data, $rsri_where)) {
                         $rsri_urls_updated++;
                     }
                 }
             }
         }
         $stats['rsri_urls_updated'] = $rsri_urls_updated;
         $stats['time_update_rsri'] = number_format(microtime(true) - $time_begin, 2);
         $stats['time_total'] = number_format(microtime(true) - $time_total_begin, 2);
         // save stats
         $settings = $this->db->where('key', 'amazon_urls_unification_stats')->get('settings')->row();
         $settings_id = null;
         if (!empty($settings->id)) {
             $settings_id = $settings->id;
         } else {
             $this->db->insert('settings', array('key' => 'amazon_urls_unification_stats', 'description' => ''));
             $settings_id = $this->db->insert_id();
         }
         if (!empty($settings_id)) {
             $data = array('setting_id' => $settings_id, 'user_id' => -1, 'value' => json_encode($stats));
             $this->db->insert('setting_values', $data);
         }
     }
 }
예제 #5
0
 /**
  * Import ranking data received from scraper
  * @param array $ranking_data Ranking data (array of json encoded items)
  * @param object $ranking_data_job ranking_data_jobs record
  * @return bool result
  */
 public function import_ranking_data($ranking_data, $ranking_data_job)
 {
     $this->load->model('ranking_model');
     $this->load->model('sites_model');
     $this->load->library('price');
     $this->load->library('variant');
     $this->load->library('SalesEstimator/AmazonFba');
     $this->load->library('reseller');
     $find_entity = function (&$entites, $by) {
         if (is_array($entites)) {
             foreach ($entites as $entity) {
                 $it_is = null;
                 foreach ($by as $key => $value) {
                     $hit = false;
                     if (property_exists($entity, $key)) {
                         $hit = is_null($value) ? $entity->{$key} === $value : $entity->{$key} == $value;
                     }
                     $it_is = (is_null($it_is) ? true : $it_is) && $hit;
                 }
                 if ($it_is) {
                     return $entity;
                 }
             }
         }
         return null;
     };
     $imported_count = 0;
     // json decode results
     $is_single_result = false;
     $ranking_data = array_values(array_filter(array_map(function ($ranking_data_item) use(&$is_single_result, $ranking_data_job) {
         $result = null;
         if (!empty($ranking_data_item)) {
             $result = $ranking_data_item;
             if (empty($result->brand)) {
                 // see http://bugzilla.contentanalyticsinc.com/show_bug.cgi?id=901
                 $result->brand = "No brand";
             }
             if (empty($result->title) || empty($result->brand)) {
                 $result = null;
             } elseif (empty($result->is_single_result) && (empty($result->url) || empty($ranking_data_job->search_term))) {
                 // not is_single_result
                 $result = null;
             } else {
                 foreach ($result as $key => &$result_val) {
                     if (is_string($result_val)) {
                         $result_val = trim($result_val);
                     }
                     if ($key === 'url') {
                         $result_val = Ranking_model::unifyAmazonUrl($result_val);
                     }
                 }
                 $is_single_result = !empty($result->is_single_result);
             }
         }
         return $result;
     }, $ranking_data)));
     $is_single_result = $is_single_result && count($ranking_data) === 1;
     if (count($ranking_data) === 0) {
         return $imported_count;
     }
     $site_id = $ranking_data_job->site_id;
     $date_of_upload = empty($ranking_data_job->created_at) ? gmdate('Y-m-d') : date('Y-m-d', strtotime($ranking_data_job->created_at));
     $brand_names = array();
     $urls = array();
     $prices = array();
     foreach ($ranking_data as $product_key => &$results_item) {
         if (!empty($results_item->brand) && !in_array($results_item->brand, $brand_names)) {
             $brand_names[] = $results_item->brand;
         }
         if ($is_single_result) {
             $results_item->url = $ranking_data_job->url;
         }
         if (!empty($results_item->url) && !in_array($results_item->url, $urls)) {
             $urls[] = $results_item->url;
         }
         if (empty($site_id)) {
             if (!empty($results_item->site) || !empty($results_item->url)) {
                 // get id of site by site name from current item. example: "site": "walmart.com" or "url": "http://www.walmart.com/ip/16609038"
                 $url_to_use = empty($results_item->site) ? $results_item->url : $results_item->site;
                 $name_fragment = empty($results_item->is_mobile_agent) ? null : 'iphone';
                 // @to-do: remove 'iphone' hardcode
                 $site_id = $this->sites_model->get_id_by_url_new($url_to_use, $name_fragment);
             }
         }
         if (!$is_single_result && !empty($results_item->price)) {
             $price_arr = $this->price->parsePrice($results_item->price);
             if (!empty($price_arr['price'])) {
                 $prices[$product_key] = array('price' => (double) $price_arr['price'], 'ranking' => (int) empty($results_item->ranking) ? 999 : $results_item->ranking);
             }
         }
     }
     // sort by price & ranking
     uasort($prices, function ($a, $b) {
         if (!empty($a['price']) && !empty($a['ranking']) && !empty($b['price']) && !empty($b['ranking'])) {
             if ($a['price'] != $b['price']) {
                 return $a['price'] > $b['price'] ? 1 : -1;
             } elseif ($a['ranking'] != $b['ranking']) {
                 return $a['ranking'] > $b['ranking'] ? 1 : -1;
             }
         }
         return 0;
     });
     // get ranking_by_price per each product (product_key => ranking_by_price)
     $ranking_by_price = array();
     $ranking_by_price_key = 1;
     foreach ($prices as $product_key => $price_and_ranking) {
         $ranking_by_price[$ranking_by_price_key++] = $product_key;
         // ranking_by_price => product_key
     }
     $ranking_by_price = array_flip($ranking_by_price);
     ksort($ranking_by_price);
     $search_terms = array();
     if (!empty($ranking_data_job->search_term) && !empty($ranking_data_job->search_term_group_id)) {
         $search_terms = $this->ranking_model->get_('search_terms', array('title' => $ranking_data_job->search_term, 'group_id' => $ranking_data_job->search_term_group_id));
     }
     $search_term_ids = array_map(function ($search_term) {
         return $search_term->id;
     }, $search_terms);
     $ranking_brands = array();
     if (!empty($brand_names)) {
         $ranking_brands = $this->ranking_model->get_('ranking_brands', array('name' => $brand_names));
     }
     $ranking_brand_ids = array_map(function ($ranking_brand) {
         return $ranking_brand->id;
     }, $ranking_brands);
     $search_terms_brands_relations = array();
     if (($is_single_result || !empty($search_term_ids)) && !empty($ranking_brand_ids)) {
         $search_terms_brands_relations_where = array();
         if (!$is_single_result) {
             $search_terms_brands_relations_where['search_term_id'] = $search_term_ids;
         } else {
             $search_terms_brands_relations_where['search_term_id IS NULL'] = null;
         }
         $search_terms_brands_relations_where['brand_id'] = $ranking_brand_ids;
         $search_terms_brands_relations = $this->ranking_model->get_('search_terms_brands_relation', $search_terms_brands_relations_where);
     }
     $search_terms_brands_relation_ids = array_map(function ($search_terms_brands_relation) {
         return $search_terms_brands_relation->id;
     }, $search_terms_brands_relations);
     $product_urls = array();
     if (!empty($urls)) {
         $product_urls_result = $this->ranking_model->get_('product_url', array('url' => $urls));
         foreach ($product_urls_result as $product_url_result) {
             $product_urls[$product_url_result->url] = $product_url_result->id;
             // url => id
         }
     }
     $ranking_search_results_items_summary_where = array_filter(array('site_id' => $site_id, 'search_items_brands_relation_id' => $search_terms_brands_relation_ids, 'date_of_upload' => $date_of_upload));
     $ranking_search_results_items_summary = $this->ranking_model->get_('ranking_search_results_items_summary', $ranking_search_results_items_summary_where);
     $ranking_search_results_items_where = array_filter(array('site_id' => $site_id, 'search_items_brands_relation_id' => $search_terms_brands_relation_ids, 'date_of_upload' => $date_of_upload, 'url_id' => array_values($product_urls)));
     $ranking_search_results_items = $this->ranking_model->get_('ranking_search_results_items', $ranking_search_results_items_where);
     $ranking_search_results_items_ids = array_map(function ($ranking_search_results_item) {
         return $ranking_search_results_item->id;
     }, $ranking_search_results_items);
     $ranking_buyers_reviews = array();
     if (!empty($ranking_search_results_items_ids)) {
         $ranking_buyers_reviews = $this->ranking_model->get_('ranking_buyers_review_info', array('rsri_id' => $ranking_search_results_items_ids));
     }
     $total_results = 0;
     $brand_results = array();
     $on_first_page = array();
     $results_per_page = array();
     foreach ($ranking_data as $product_key => $ranking_data_item) {
         if (empty($ranking_data_item->title) || empty($ranking_data_item->brand) || empty($site_id) || empty($ranking_data_item->url)) {
             continue;
         }
         if (!$is_single_result && empty($ranking_data_job->search_term)) {
             // not is_single_result
             continue;
         }
         // get search_term_id
         $search_term_id = null;
         if (!$is_single_result) {
             if ($search_term = $find_entity($search_terms, array('title' => $ranking_data_job->search_term))) {
                 $search_term_id = $search_term->id;
             }
             // we don't need to create new search term
             if (empty($search_term_id)) {
                 continue;
             }
         }
         // get brand_id
         $brand_id = null;
         if ($brand = $find_entity($ranking_brands, array('name' => $ranking_data_item->brand))) {
             $brand_id = $brand->id;
         } else {
             // create new ranking_brand
             $new_ranking_brand_data = array('name' => $ranking_data_item->brand);
             $brand_id = $this->ranking_model->create_('ranking_brands', $new_ranking_brand_data);
             if ($brand_id) {
                 $ranking_brands[] = (object) array_merge(array('id' => $brand_id), $new_ranking_brand_data);
             }
         }
         if (empty($brand_id)) {
             continue;
         }
         // search_items_brands_relation_id
         $search_terms_brands_relation_id = null;
         $search_terms_brands_relation_data = array('search_term_id' => $search_term_id, 'brand_id' => $brand_id);
         $search_terms_brands_relation = $find_entity($search_terms_brands_relations, $search_terms_brands_relation_data);
         if (!empty($search_terms_brands_relation)) {
             $search_terms_brands_relation_id = $search_terms_brands_relation->id;
         } else {
             // create new search_terms_brands_relation
             $search_terms_brands_relation_id = $this->ranking_model->create_('search_terms_brands_relation', $search_terms_brands_relation_data);
             if ($search_terms_brands_relation_id) {
                 $search_terms_brands_relations[] = (object) array_merge(array('id' => $search_terms_brands_relation_id), $search_terms_brands_relation_data);
             }
         }
         if (empty($search_terms_brands_relation_id)) {
             continue;
         }
         if (empty($product_urls[$ranking_data_item->url])) {
             $productId = $this->reseller->getProductIdOrCreateByResellerIdAndSiteId($this->reseller->getIdFromUrl($ranking_data_item->url), $site_id);
             $product_url_id = $this->ranking_model->create_('product_url', array('url' => $ranking_data_item->url, 'product_id' => $productId));
             if ($product_url_id) {
                 $product_urls[$ranking_data_item->url] = $product_url_id;
             }
         }
         $url_id = empty($product_urls[$ranking_data_item->url]) ? null : $product_urls[$ranking_data_item->url];
         if (empty($url_id)) {
             continue;
         }
         // compose $new_rsri_data
         $description = null;
         if (!empty($ranking_data_item->description)) {
             $description = is_array($ranking_data_item->description) ? reset($ranking_data_item->description) : $ranking_data_item->description;
             $description = html_entity_decode($description);
         }
         $search_term_in_title = null;
         if (!empty($ranking_data_item->search_term_in_title_exactly)) {
             $search_term_in_title = 'exact';
         } elseif (!empty($ranking_data_item->search_term_in_title_interleaved)) {
             $search_term_in_title = 'interleaved';
         } elseif (!empty($ranking_data_item->search_term_in_title_partial)) {
             $search_term_in_title = 'partial';
         }
         $price = $this->price->parsePrice(empty($ranking_data_item->price) ? '' : $ranking_data_item->price);
         //  Tomorrow Jun 10 2015 scrapper will be refactored expected values (Bool)
         //  and this code should be replaced with one line
         $shipping = null;
         if (isset($ranking_data_item->shipping)) {
             if (!empty($ranking_data_item->shipping)) {
                 if (in_array($ranking_data_item->shipping, array('Available', 'Not Available'))) {
                     $shipping = $ranking_data_item->shipping == 'Available' ? 't' : 'f';
                 } else {
                     $shipping = 't';
                 }
             } else {
                 $shipping = 'f';
             }
         }
         $new_rsri_data = array('site_id' => $site_id, 'search_items_brands_relation_id' => $search_terms_brands_relation_id, 'ranking' => empty($ranking_data_item->ranking) ? null : $ranking_data_item->ranking, 'url' => $ranking_data_item->url, 'image_url' => empty($ranking_data_item->image_url) ? null : $ranking_data_item->image_url, 'title' => html_entity_decode($ranking_data_item->title), 'description' => $description, 'model' => empty($ranking_data_item->model) ? null : $ranking_data_item->model, 'upc' => empty($ranking_data_item->upc) ? null : $ranking_data_item->upc, 'locale' => empty($ranking_data_item->locale) ? null : $ranking_data_item->locale, 'date_of_upload' => $date_of_upload, 'best_seller_ranking' => !empty($ranking_data_item->best_seller_ranking) ? (int) $ranking_data_item->best_seller_ranking : (!empty($ranking_data_item->bestseller_rank) ? (int) $ranking_data_item->bestseller_rank : null), 'search_term_in_title' => $search_term_in_title, 'is_out_of_stock' => empty($ranking_data_item->is_out_of_stock) ? 'f' : 't', 'is_in_store_only' => empty($ranking_data_item->is_in_store_only) ? 'f' : 't', 'price' => empty($price['price']) ? null : number_format($price['price'], 2, '.', ''), 'currency' => $price['priceCurrency'], 'search_term' => empty($ranking_data_job->search_term) ? null : $ranking_data_job->search_term, 'results_per_page' => empty($ranking_data_item->results_per_page) ? null : (int) $ranking_data_item->results_per_page, 'url_id' => $url_id, 'ranking_by_price' => empty($ranking_by_price[$product_key]) ? null : $ranking_by_price[$product_key], 'prime' => !empty($ranking_data_item->prime) && in_array($ranking_data_item->prime, array('Prime', 'PrimePantry')) ? $ranking_data_item->prime : null, 'seller_category_id' => empty($ranking_data_item->department) ? null : $this->amazonfba->getCategoryIdByName($ranking_data_item->department), 'pickup_only' => empty($ranking_data_item->is_pickup_only) ? 'f' : 't', 'shipping' => $shipping);
         $this->setQuestionAnswer($ranking_data_item, $url_id);
         // check whether product exists already, if so - update it, otherwise - insert
         $rsri_search_keys = array('site_id', 'search_items_brands_relation_id', 'date_of_upload', 'url_id');
         $rsri_where = array_intersect_key($new_rsri_data, array_flip($rsri_search_keys));
         if ($ranking_search_results_item = $find_entity($ranking_search_results_items, $rsri_where)) {
             // update $ranking_search_results_item
             $rsri_id = $ranking_search_results_item->id;
             $update_rsri_data = array_diff_assoc($new_rsri_data, (array) $ranking_search_results_item);
             if (!empty($update_rsri_data)) {
                 $this->ranking_model->update_('ranking_search_results_items', $update_rsri_data, array('id' => $rsri_id));
             }
         } else {
             // insert into ranking_search_results_items
             $rsri_id = $this->ranking_model->create_('ranking_search_results_items', $new_rsri_data);
             $ranking_search_results_items[] = (object) array_merge(array('id' => $rsri_id), $new_rsri_data);
         }
         $imported_count++;
         // no matter insert or update - we count it as imported
         // Market Place
         if (!empty($ranking_data_item->marketplace)) {
             $insertMarketplaceBatch = array();
             // Prepare Insert Batch
             foreach ($ranking_data_item->marketplace as $marketplace) {
                 $insertMarketplaceBatch[] = array('rsri_id' => $rsri_id, 'name' => !empty($marketplace->name) ? $marketplace->name : null, 'price' => !empty($marketplace->price) ? $marketplace->price : null, 'currency' => !empty($marketplace->currency) ? $marketplace->currency : null);
             }
             if (!empty($insertMarketplaceBatch)) {
                 $this->ranking_model->create_batch_('product_marketplace', $insertMarketplaceBatch);
             }
         }
         //  Save Variants
         if (!empty($ranking_data_item->variants)) {
             $this->variant->save($ranking_data_item->variants, $rsri_id, $url_id);
         }
         // Save Google Shopping Sellers
         if (!empty($ranking_data_item->google_source_site)) {
             $sellersArray = json_decode($ranking_data_item->google_source_site);
             $jsonError = json_last_error();
             if (!$jsonError) {
                 $insertSellersBatch = array();
                 //  Prepare Insert Batch
                 foreach ($sellersArray as $sellerName => $seller) {
                     if (empty($sellerName)) {
                         continue;
                     }
                     $insertSellersBatch[] = array('rsri_id' => $rsri_id, 'seller_name' => !empty($sellerName) ? $sellerName : null, 'price' => !empty($seller->price) ? $seller->price : null, 'currency' => !empty($seller->currency) ? $seller->currency : null);
                 }
                 $this->ranking_model->create_batch_('google_shopping_sellers', $insertSellersBatch);
             }
         }
         // save buyer reviews
         if (!empty($ranking_data_item->buyer_reviews) && (is_array($ranking_data_item->buyer_reviews) || is_object($ranking_data_item->buyer_reviews))) {
             $buyer_reviews_data = array();
             if (is_array($ranking_data_item->buyer_reviews)) {
                 $buyer_reviews_data['total_count'] = empty($ranking_data_item->buyer_reviews[0]) ? 0 : (int) $ranking_data_item->buyer_reviews[0];
                 $buyer_reviews_data['average_num'] = empty($ranking_data_item->buyer_reviews[1]) ? 0 : (double) $ranking_data_item->buyer_reviews[1];
                 $raitings_by_stars = empty($ranking_data_item->buyer_reviews[2]) ? new stdClass() : $ranking_data_item->buyer_reviews[2];
             } else {
                 $buyer_reviews_data['total_count'] = empty($ranking_data_item->buyer_reviews->num_of_reviews) ? 0 : (int) $ranking_data_item->buyer_reviews->num_of_reviews;
                 $buyer_reviews_data['average_num'] = empty($ranking_data_item->buyer_reviews->average_rating) ? 0 : (double) $ranking_data_item->buyer_reviews->average_rating;
                 $raitings_by_stars = empty($ranking_data_item->buyer_reviews->rating_by_star) ? new stdClass() : $ranking_data_item->buyer_reviews->rating_by_star;
             }
             $buyer_reviews_data['one_star'] = empty($raitings_by_stars->{1}) ? 0 : $raitings_by_stars->{1};
             $buyer_reviews_data['two_star'] = empty($raitings_by_stars->{2}) ? 0 : $raitings_by_stars->{2};
             $buyer_reviews_data['three_star'] = empty($raitings_by_stars->{3}) ? 0 : $raitings_by_stars->{3};
             $buyer_reviews_data['four_star'] = empty($raitings_by_stars->{4}) ? 0 : $raitings_by_stars->{4};
             $buyer_reviews_data['five_star'] = empty($raitings_by_stars->{5}) ? 0 : $raitings_by_stars->{5};
             if (($ranking_buyers_review = $find_entity($ranking_buyers_reviews, array('rsri_id' => $rsri_id))) && !empty($ranking_buyers_review->id)) {
                 $update_buyer_reviews = array_diff_assoc($buyer_reviews_data, (array) $ranking_buyers_review);
                 if (!empty($update_buyer_reviews)) {
                     $this->ranking_model->update_('ranking_buyers_review_info', $update_buyer_reviews, array('id' => $ranking_buyers_review->id));
                 }
             } else {
                 $buyer_reviews_data['rsri_id'] = $rsri_id;
                 $ranking_buyers_review_info_id = $this->ranking_model->create_('ranking_buyers_review_info', $buyer_reviews_data);
                 $ranking_buyers_reviews[] = (object) array_merge(array('id' => $ranking_buyers_review_info_id), $buyer_reviews_data);
             }
         }
         // Save Sponsored Links
         if (!empty($ranking_data_item->sponsored_links)) {
             $insertSponsoredLinksBatch = array();
             foreach ($ranking_data_item->sponsored_links as $link) {
                 $insertSponsoredLinksBatch[] = array('product_id' => $rsri_id, 'ad_title' => $link->ad_title, 'ad_text' => $link->ad_text, 'visible_url' => $link->visible_url, 'actual_url' => $link->actual_url);
             }
             $this->ranking_model->create_batch_('product_sponsored_links', $insertSponsoredLinksBatch);
         }
         // collect data for ranking_search_results_items_summary
         if ($total_results === 0 && !empty($ranking_data_item->total_matches)) {
             $total_results = $ranking_data_item->total_matches;
         }
         if (!array_key_exists($search_terms_brands_relation_id, $brand_results)) {
             $brand_results[$search_terms_brands_relation_id] = 0;
         }
         if (!array_key_exists($search_terms_brands_relation_id, $on_first_page)) {
             $on_first_page[$search_terms_brands_relation_id] = 0;
         }
         if (!array_key_exists($search_terms_brands_relation_id, $results_per_page)) {
             $results_per_page[$search_terms_brands_relation_id] = 0;
         }
         if (!empty($ranking_data_item->ranking)) {
             $brand_results[$search_terms_brands_relation_id]++;
             if (!empty($ranking_data_item->results_per_page)) {
                 if ((int) $ranking_data_item->ranking <= (int) $ranking_data_item->results_per_page) {
                     $on_first_page[$search_terms_brands_relation_id]++;
                 }
                 $results_per_page[$search_terms_brands_relation_id] = $ranking_data_item->results_per_page;
             }
         }
     }
     // foreach ($ranking_data as $ranking_data_item)
     if (!empty($urls)) {
         $this->ranking_model->updateAndGetUniqueProductUrls($urls, $product_urls);
     }
     // create or update summary data in ranking_search_results_items_summary table
     foreach ($brand_results as $stbr_id => $brand_result) {
         // compose on_first_page string as number_of_res_on_1st_page/results_per_page
         $on_first_page_str = empty($on_first_page[$stbr_id]) ? 0 : $on_first_page[$stbr_id];
         $on_first_page_str .= empty($results_per_page[$stbr_id]) ? '' : "/{$results_per_page[$stbr_id]}";
         $new_rsris_data = array('site_id' => $site_id, 'total_results' => $total_results, 'brand_results' => $brand_result, 'search_items_brands_relation_id' => $stbr_id, 'date_of_upload' => $date_of_upload, 'on_first_page' => $on_first_page_str);
         $rsris_search_keys = array('site_id', 'search_items_brands_relation_id', 'date_of_upload');
         $rsris_where = array_intersect_key($new_rsris_data, array_flip($rsris_search_keys));
         if ($rsris = $find_entity($ranking_search_results_items_summary, $rsris_where)) {
             $update_rsris_data = array_diff_assoc($new_rsris_data, (array) $rsris);
             if (!empty($update_rsris_data)) {
                 $this->ranking_model->update_('ranking_search_results_items_summary', $update_rsris_data, array('id' => $rsris->id));
             }
         } else {
             // create new ranking_search_results_items_summary
             $rsris_id = $this->ranking_model->create_('ranking_search_results_items_summary', $new_rsris_data);
             if ($rsris_id) {
                 $ranking_search_results_items_summary[] = (object) array_merge(array('id' => $rsris_id), $new_rsris_data);
             }
         }
     }
     return $imported_count;
 }
예제 #6
0
 private function get_brands_ofp_string($data, $sorting = 0, &$num_ofp = 0)
 {
     $brands_ofp = array();
     $sum_ofp = 0;
     if (!empty($data)) {
         foreach ($data as $product) {
             if (!empty($product) && !empty($product->ofp_by_ranking) && $product->ofp_by_ranking == 't') {
                 $brand = strip_slashes($product->brand_name);
                 if (array_key_exists($brand, $brands_ofp)) {
                     ++$brands_ofp[$brand];
                 } else {
                     $brands_ofp[$brand] = 1;
                 }
                 ++$sum_ofp;
             }
         }
     }
     if ($sorting == 1) {
         $sorting = '<span class="brand-ofp-sorting-ico-down"></span>';
         arsort($brands_ofp);
     } elseif ($sorting == 2) {
         $sorting = '<span class="brand-ofp-sorting-ico-up"></span>';
         asort($brands_ofp);
     } else {
         $sorting = '<span class="brand-ofp-sorting-ico-down"></span>';
         ksort($brands_ofp);
     }
     $this->load->model('ranking_model');
     $brand_id = $this->input->post('brand_id');
     $all_checked_brand_checkboxes = $this->input->post('all_checked_brand_checkboxes');
     $brand_id = Ranking_model::getBrandIdsFromSelectedGroups($brand_id, $all_checked_brand_checkboxes);
     if (empty($brand_id) || !is_array($brand_id) || count($brand_id) != 1) {
         $brands_str = 'First Page Rankings: <span class="all-brands-sorting">All Selected Brands - ' . $sum_ofp . ' ' . $sorting . '</span>';
         foreach ($brands_ofp as $key => $value) {
             $brands_str .= ' | ' . $key . ' - ' . $value;
         }
     } else {
         $brands_str = 'First Page Rankings: ' . $sum_ofp;
     }
     $num_ofp = $sum_ofp;
     return $brands_str;
 }
예제 #7
0
 protected function getSummaryResultsTable($alert, $dashboard = false)
 {
     $site_id = !empty($this->options['rank_site']) ? $this->options['rank_site'] : array();
     $brand_id = !empty($this->options['rank_brand']) ? $this->options['rank_brand'] : array();
     $term_id = !empty($this->options['rank_term']) ? $this->options['rank_term'] : array();
     $productList = !empty($alert->options_array['product_list']) ? $alert->options_array['product_list'] : false;
     $date_of_upload = is_array($this->getDateNew()) ? $this->getDateNew() : array($this->getDateNew());
     //  DashBoard
     if ($dashboard) {
         $date_of_upload = $this->date_from;
     }
     $tbl_body = '';
     if (!empty($site_id) && !empty($brand_id) && !empty($term_id)) {
         $all_brands = $this->getRankingModel()->getBrandByIdsArray($brand_id);
         $summary_data = array('curr_group_terms_count' => 0, 'curr_group_terms' => array(), 'all_results_for_body' => array('brands' => array(), 'terms' => array(), 'brand_terms' => array()));
         $summary_data['curr_group_terms'] = $this->getRankingModel()->getKeywordsNamesByIds($term_id);
         foreach ($site_id as $site) {
             $all_results_for_body = array();
             $data_prepared = $this->getRankingModel()->getProductsByTerm($site, $date_of_upload, $term_id, 'rsri.ranking', 'asc', $brand_id, 0, false, $productList);
             $summary_data['curr_group_terms_count'] += \Ranking_model::get_ofp_total_count($data_prepared, $all_results_for_body);
             if (!empty($all_results_for_body['terms'])) {
                 foreach ($all_results_for_body['terms'] as $key => $arfb) {
                     if (!array_key_exists($key, $summary_data['all_results_for_body']['terms'])) {
                         $summary_data['all_results_for_body']['terms'][$key] = 0;
                     }
                     $summary_data['all_results_for_body']['terms'][$key] += $arfb;
                 }
             }
             if (!empty($all_results_for_body['brands'])) {
                 foreach ($all_results_for_body['brands'] as $key => $arfb) {
                     if (!array_key_exists($key, $summary_data['all_results_for_body']['brands'])) {
                         $summary_data['all_results_for_body']['brands'][$key] = 0;
                     }
                     $summary_data['all_results_for_body']['brands'][$key] += $arfb;
                 }
             }
             if (!empty($all_results_for_body['brand_terms'])) {
                 foreach ($all_results_for_body['brand_terms'] as $key => $arfb) {
                     if (!array_key_exists($key, $summary_data['all_results_for_body']['brand_terms'])) {
                         $summary_data['all_results_for_body']['brand_terms'][$key] = 0;
                     }
                     $summary_data['all_results_for_body']['brand_terms'][$key] += $arfb;
                 }
             }
         }
         //selected brand
         $new_all_brands = array();
         if (!empty($all_brands)) {
             $selected_key = -1;
             foreach ($all_brands as $key => $brand) {
                 if (isset($alert->selected_brand) && $alert->selected_brand == $brand->id) {
                     $selected_key = $key;
                     $new_all_brands[] = $brand;
                     break;
                 }
             }
             if ($selected_key == -1) {
                 $new_all_brands[] = $all_brands[0];
                 $selected_key = 0;
             }
             unset($all_brands[$selected_key]);
         }
         //get compare brand
         if (!empty($all_brands) && !empty($all_results_for_body['brands'])) {
             $max_percent_brand = 0;
             foreach ($all_brands as $key => $brand) {
                 if (!empty($all_results_for_body['brands'][$brand->name])) {
                     if (empty($all_brands[$max_percent_brand]) || empty($all_results_for_body['brands'][$all_brands[$max_percent_brand]->name]) || $all_results_for_body['brands'][$all_brands[$max_percent_brand]->name] < $all_results_for_body['brands'][$brand->name]) {
                         $max_percent_brand = $key;
                     }
                 }
             }
             if (isset($all_brands[$max_percent_brand])) {
                 $new_all_brands[] = $all_brands[$max_percent_brand];
             }
         }
         $this->getCI()->load->library('RankingTable');
         // mobile friendly alert templates issue#6157
         //$columns = array('Search Terms'=>'true', 'Pg1 Results'=>'true', 'Brand Name'=>'true', 'Other'=>'true');
         $columns = array('Search Terms' => 'true');
         if (!empty($summary_data['curr_group_terms'])) {
             $summary_data['all_results_for_body']['search_terms_list'] = $summary_data['curr_group_terms'];
             // mobile friendly alert templates issue#6157
             //$tbl_body .= '<tr>' . $this->getCI()->rankingtable->getHeader($columns, '1ssv', $date_of_upload, '', '', '', $new_all_brands, $summary_data['all_results_for_body'], true) . '</tr>';
             $i = 0;
             $summary_data['all_results_for_body']['serch_terms_ofp'] = array('summary_ofp_count' => 0);
             foreach ($site_id as $site) {
                 foreach ($summary_data['curr_group_terms'] as $cur_term) {
                     if (in_array($cur_term->id, $term_id)) {
                         $group_name = !empty($cur_term->title) ? $cur_term->title : '';
                         $ofp_count = $this->getCI()->ranking_model->getOfpCountByTerm($site, $date_of_upload, $cur_term->id, array());
                         if (!array_key_exists($group_name, $summary_data['all_results_for_body']['serch_terms_ofp'])) {
                             $summary_data['all_results_for_body']['serch_terms_ofp'][$group_name] = 0;
                         }
                         $summary_data['all_results_for_body']['serch_terms_ofp'][$group_name] += $ofp_count;
                         $summary_data['all_results_for_body']['serch_terms_ofp']['summary_ofp_count'] += $ofp_count;
                     }
                 }
             }
             $possible_spot = $summary_data['all_results_for_body']['serch_terms_ofp']['summary_ofp_count'];
             foreach ($new_all_brands as $key => &$value) {
                 if (!empty($summary_data['all_results_for_body']['brands'])) {
                     if (array_key_exists($value->name, $summary_data['all_results_for_body']['brands'])) {
                         $res = round($summary_data['all_results_for_body']['brands'][$value->name] / $possible_spot * 100);
                     } else {
                         $res = 0;
                     }
                 } else {
                     $res = 0;
                 }
                 $value->percent = $res;
             }
             //  DashBoard
             if ($dashboard) {
                 return $summary_data;
             }
             foreach ($summary_data['curr_group_terms'] as $cur_term) {
                 if (in_array($cur_term->id, $term_id)) {
                     $get_add_row = !$i;
                     ++$i;
                     $group_name = !empty($cur_term->title) ? $cur_term->title : '';
                     $row = $this->getCI()->rankingtable->getBody($columns, '1ssv', array(), $site_id, '', $date_of_upload, '', '', '', '', '', count($brand_id), $summary_data['all_results_for_body'], $group_name, $new_all_brands, $cur_term->id, true, $get_add_row);
                     $tbl_body .= $row;
                 }
             }
         }
     }
     return array('table' => $tbl_body, 'brands' => $new_all_brands);
 }
예제 #8
0
 public function getPricingReportChartData()
 {
     $this->load->model('ranking_model');
     $this->load->model('product_model');
     $data = array();
     $sites = $this->input->get('sites');
     $terms = $this->input->get('searchTerms');
     $brands = $this->input->get('brands');
     $dates = $this->input->get('dates');
     $productList = $this->input->get('productList');
     $graphItUrlIds = $this->input->get('graphItUrlIds');
     $sitesCount = count($sites);
     foreach (array_reverse($dates) as $date) {
         $dateObj = new \DateTime($date);
         $data['daysRange'][] = $dateObj->format('F d');
     }
     $filters = ['product_lists' => $productList, 'urlIds' => $graphItUrlIds, 'site_id' => $sites, 'brand_id' => $brands, 'term_id' => $terms, 'date_of_upload' => $dates];
     $dataResult = $this->ranking_model->getPricingReport($filters);
     $total = count($dataResult);
     $products = [];
     //  Update Selected Variants, run each time because variants selection could be changed during the day.
     $this->product_model->updateVariantsForSelectedProducts($filters);
     //  Get Available variants by filter, later this variants are attached to products.
     $variants = $this->product_model->getVariantsByParams($filters);
     foreach ($dataResult as $items) {
         $product = (object) $items;
         if (!empty($variants[$product->product_id])) {
             foreach ($variants[$product->product_id] as $variant) {
                 if (!empty($variant['variant_price']) && $variant['variant_selected'] == 't') {
                     $product->price = $variant['variant_price'];
                 }
             }
         }
         $associatedProducts = $this->ranking_model->getAssociatedProducts($product);
         foreach ($associatedProducts as $product) {
             $product = (array) $product;
             $site = ucfirst($product['site']);
             $logo = ($logo = Ranking_model::getSiteLogoByName($product['site'])) ? '/img/site_logos/' . $logo : null;
             foreach ($variants[$product['product_id']] as $variant) {
                 if (!empty($variant['variant_price']) && $variant['variant_selected'] == 't') {
                     $product['price'] = $variant['variant_price'];
                 }
             }
             if (false === in_array($product['site_id'], $sites)) {
                 continue;
             }
             $products[$site][$product['title']] = ['image' => $product['image_url'], 'currency' => '$'];
             if (false === isset($pData[$site]['products'][$product['url_id']][$product['date_of_upload']])) {
                 $pData[$site]['products'][$product['url_id']][$product['date_of_upload']] = true;
                 $data['output'][$site]['products'][$product['url_id']]['productName'] = $product['title'];
                 $data['output'][$site]['products'][$product['url_id']]['image_url'] = $product['image_url'];
                 $data['output'][$site]['products'][$product['url_id']]['logo'] = $logo;
                 $data['output'][$site]['products'][$product['url_id']]['pricing'][$product['date_of_upload']] = empty($product['price']) ? null : (double) $product['price'];
             }
             $sites[$site] = ['name' => $site, 'logo' => $logo];
         }
     }
     foreach ($data['output'] as $retailerName => $retailer) {
         $data['retailers'][] = $retailerName;
         foreach ($retailer['products'] as $productDetails) {
             foreach ($dates as $date) {
                 if (empty($productDetails['pricing'][$date])) {
                     $productDetails['pricing'][$date] = null;
                 }
             }
             ksort($productDetails['pricing']);
             $productDetails['pricing'] = array_values($productDetails['pricing']);
             $name = count($graphItUrlIds) == 1 && $sitesCount > 1 ? $retailerName : $productDetails['productName'];
             $data['series'][$retailerName][] = ['name' => $name, 'data' => $productDetails['pricing'], 'product_name' => $productDetails['productName'], 'image_url' => $productDetails['image_url'], 'logo' => !empty($productDetails['logo']) ? base_url() . $productDetails['logo'] : null];
         }
     }
     $data['sites'] = $sites;
     $data['products'] = $products;
     $data['sitesCount'] = $sitesCount;
     $data['graphItUrlIds'] = $graphItUrlIds;
     return $this->jsonResponse(array('data' => $data, 'date_of_upload' => $dates, 'total' => $total));
 }
예제 #9
0
 /**
  * Return alert edit form with data
  * @return json
  * @author Pavel Klyagin
  */
 public function edit()
 {
     $this->load->model('ranking_model');
     $this->load->model('alert_model');
     $this->lang->load('alert');
     $alert_id = $this->input->post('id');
     $user_id = $this->ion_auth->get_user_id();
     $brands_selected = array();
     $all_checked_brand_checkboxes = array();
     $errors = array();
     if ($alert_id && $user_id) {
         $types = array();
         if ($types = $this->input->post('type')) {
             $types = is_array($types) ? $types : explode('|', $types);
         }
         if ($this->ion_auth->is_admin()) {
             $data = $this->alert_model->getAlertByIdAndUserId($alert_id, null);
         } else {
             $data = $this->alert_model->getAlertByIdAndUserId($alert_id, $user_id);
         }
         if ($data) {
             if (isset($data->options)) {
                 $options = unserialize($data->options);
                 if (isset($options['rank_brand']) && isset($options['rank_brand']['rank_brand'])) {
                     $brands_selected = $options['rank_brand']['rank_brand'];
                 }
                 if (isset($options['rank_brand']) && isset($options['rank_brand']['all_checked_brand_checkboxes'])) {
                     $all_checked_brand_checkboxes = $options['rank_brand']['all_checked_brand_checkboxes'];
                 }
                 $brands_selected = Ranking_model::getBrandIdsFromSelectedGroups($brands_selected, $all_checked_brand_checkboxes);
             }
             // get alert associated data (sites, brands, keywords), format it for output
             $data->associated = array();
             if (isset($options['rank_site'], $options['rank_site']['rank_site_text'])) {
                 $data->associated['sites'] = $options['rank_site']['rank_site_text'];
             }
             if (isset($options['rank_brand'], $options['rank_brand']['rank_brand_text'])) {
                 $data->associated['brands_text'] = $options['rank_brand']['rank_brand_text'];
             }
             if (isset($options['rank_term'], $options['rank_term']['all_checked_checkboxes']) && is_array($options['rank_term']['all_checked_checkboxes'])) {
                 $data->associated['keywords'] = array();
                 foreach ($options['rank_term']['all_checked_checkboxes'] as $checked_checkbox) {
                     if (isset($checked_checkbox['selected_keywords_array']) && is_array($checked_checkbox['selected_keywords_array'])) {
                         $data->associated['keywords'] = array_merge($data->associated['keywords'], $checked_checkbox['selected_keywords_array']);
                     }
                 }
                 $data->associated['keywords'] = array_map('trim', array_values($data->associated['keywords']));
             }
             $data->associated = array_filter($data->associated);
         } else {
             $errors[] = 'Wrong Alert ID: ' . $alert_id;
         }
         $user = $this->ion_auth->get_user_data();
         $this->_checkUserInRecipientsList();
         $user_email = '';
         if (!empty($user['email'])) {
             $user_email = $user['email'];
         }
         $alert_recipients = $this->_getRecipientsListByRole();
         $alert_recipients_groups = $this->_getRecipientGroupsListByRole();
         $selected_recipients = $this->alert_model->getRecipientsByAlertId($alert_id);
         $selected_recipients_ids = array();
         if (!empty($selected_recipients)) {
             foreach ($selected_recipients as $recipient) {
                 $selected_recipients_ids[] = $recipient->id;
             }
         }
         $selectedGroups = [];
         $selectedGroupsArray = $this->alert_model->getGroupsByAlertId($alert_id);
         foreach ($selectedGroupsArray as $group) {
             $selectedGroups[] = $group->group_id;
         }
         $this->output->set_content_type('application/json')->set_output(json_encode(array('result' => !empty($data) ? 1 : 0, 'errors' => $errors, 'html' => $this->load->view('alert/add-form-new', array('brand_options' => Alert_model::getBrandsOptions($brands_selected), 'edit_mode' => true, 'data' => $data, 'type_options' => Alert_model::getTypeOptions('scorecard'), 'frequency_options' => Alert_model::getFrequencyOptions(true), 'weekday_options' => Alert_model::getWeekdaysOptions(), 'monthday_options' => Alert_model::getMonthDaysOptions(), 'hour_options' => $this->alert_model->getHoursOptions(), 'hourly_options' => $this->alert_model->getHourlyOptions(), 'user_email' => $user_email, 'alert_recipients' => $alert_recipients, 'selectedGroups' => $selectedGroups, 'alert_recipients_groups' => $alert_recipients_groups, 'selected_recipients_ids' => $selected_recipients_ids), true))));
     }
 }
예제 #10
0
    /**
     * Return header column string
     * @param string $view
     * @param string $column
     * @param array $dates_of_upload
     * @param string $sort_dir
     * @param string $sort_by
     * @param string $site
     * @param int $columns_count
     * @param array $brand_arr
     * @param array $data
     * @param int $sort_by_num
     * @return string
     * @author Ruslan Ushakov
     */
    protected function get_column_header($view, $column, $dates_of_upload = array(), $sort_dir = '', $sort_by = '', $site = '', $columns_count = 0, $brand_arr = array(), $data = array(), $sort_by_num = -1)
    {
        $res = '';
        $dateformat = 1;
        if (isset($this->CI->session->userdata['dateformat'])) {
            $dateformat = $this->CI->session->userdata['dateformat'];
        }
        if ($view == '1s1b') {
            switch ($column) {
                case 'Brand':
                    $res = '<th style="width: 16%; min-width:160px" class="brand-image" ><strong>Brand</strong></th>';
                    break;
                case 'Search Terms':
                    $res = '<th class="sort-table-by" data-sort="title"><strong>Search Terms</strong><span class="pull-right sorting ' . ($sort_dir == 'desc' && $sort_by == 'stq.title' ? 'sorting-ico-down' : 'sorting-ico-up') . '"></span></th>';
                    break;
                case 'Total Results':
                    $res = '<th style="width: 13%" class="sort-table-by" data-sort="total_results"><strong>Total Results</strong><span class="pull-right sorting ' . ($sort_dir == 'desc' && $sort_by == 'rsris.total_results' ? 'sorting-ico-down' : 'sorting-ico-up') . '"></span></th>';
                    break;
                case 'Brand Results':
                    $res = '<th class="sort-table-by" data-sort="brand_results"><strong>Brand Results</strong><span class="pull-right sorting ' . ($sort_dir == 'desc' && $sort_by == 'rsris.brand_results' ? 'sorting-ico-down' : 'sorting-ico-up') . '"></span></th>';
                    break;
                case '#SKUs on First Page':
                    $res = '<th class="sort-table-by" data-sort="on_first_page"><strong>#SKUs on First Page</strong><span class="pull-right sorting ' . ($sort_dir == 'desc' && $sort_by == 'rsris.on_first_page' ? 'sorting-ico-down' : 'sorting-ico-up') . '"></span></th>';
                    break;
                case 'Rankings':
                    $res = '<th class="sort-table-by" data-sort="number_in_results"><strong>Rankings</strong><span class="pull-right sorting ' . ($sort_dir == 'desc' && $sort_by == 'r.number_in_results' ? 'sorting-ico-down' : 'sorting-ico-up') . '"></span></th>';
                    break;
                default:
                    $res = '<th></th>';
            }
        } elseif ($view == '2s1b') {
            switch ($column) {
                case 'Brand':
                    $res = '<th class="brand-image columns_2s1b"><strong>Brand</strong></th>';
                    break;
                case 'Search Terms':
                    $res = '<th class="sort-table-by text-left" data-sort="title" style="width: 20%"><nobr><strong>Search Terms</strong><span class="pull-right sorting ' . ($sort_dir == 'desc' && $sort_by == 'stq.title' ? 'sorting-ico-down' : 'sorting-ico-up') . '"></span></nobr></th>';
                    break;
                case 'Total Results':
                    $res = '<th colspan="2" class="columns_2s1b sort-table-by" data-sort="total_results"><strong>Total Results</strong><span class="pull-right sorting ' . ($sort_dir == 'desc' && $sort_by == 'rsris.total_results' ? 'sorting-ico-down' : 'sorting-ico-up') . '"></span></th>';
                    break;
                case 'Brand Results':
                    $res = '<th colspan="2" class="columns_2s1b sort-table-by" data-sort="brand_results"><strong>Brand Results</strong><span class="pull-right sorting ' . ($sort_dir == 'desc' && $sort_by == 'rsris.brand_results' ? 'sorting-ico-down' : 'sorting-ico-up') . '"></span></th>';
                    break;
                case '#SKUs on First Page':
                    $res = '<th colspan="2" class="columns_2s1b sort-table-by" data-sort="on_first_page"><strong>#SKUs on First Page</strong><span class="pull-right sorting ' . ($sort_dir == 'desc' && $sort_by == 'rsris.on_first_page' ? 'sorting-ico-down' : 'sorting-ico-up') . '"></span></th>';
                    break;
                case 'Rankings':
                    $res = '<th colspan="2" class="columns_2s1b sort-table-by" data-sort="number_in_results"><strong>Rankings</strong><span class="pull-right sorting ' . ($sort_dir == 'desc' && $sort_by == 'r.number_in_results' ? 'sorting-ico-down' : 'sorting-ico-up') . '"></span></th>';
                    break;
                default:
                    $res = '<th></th>';
            }
        } elseif ($view == '1ssv') {
            switch ($column) {
                case 'Search Terms':
                    $res = '<th style="' . (count($brand_arr) > 3 ? 'width:60%;' : '') . '">Search Terms</th>';
                    break;
                case 'Total Page 1 Results':
                    $res = '<th style="width: 16%; min-width: 100px;">Total Page 1 Results</th>';
                    break;
                case 'Other':
                    if (true == $this->CI->reportsettings->getSetting($view . '_sort', 'isEnabledOther')) {
                        $res = '<th style="width: 16%; min-width: 100px;">Other</th>';
                    }
                    break;
                case 'Brand Name':
                    if (count($brand_arr) < 4) {
                        foreach ($brand_arr as $key => $value) {
                            $res .= '<th style="text-align: center !important; min-width:100px;"><nobr>' . $value->name . '</nobr></th>';
                        }
                    } else {
                        $rowspan = !empty($data['search_terms_list']) ? count($data['search_terms_list']) + 3 : 1;
                        $res = '<th rowspan="' . $rowspan . '" style="padding: 0;border-top:0;border-left:0;">
                        <div style="position: relative">
                            <div class="scroll-pane" id="scroll-summary">
                                <table class="inner-table" style="border-top:0;">
                                    <tr style="height:38px;border-top:0;" class="dark-row" >';
                        foreach ($brand_arr as $key => $value) {
                            $res .= '<th style="text-align: center !important;border-top:0; min-width:160px;"><nobr>' . $value->name . '</nobr></th>';
                        }
                        $res .= '</tr>';
                        $possible_spot = !empty($data['serch_terms_ofp']['summary_ofp_count']) ? $data['serch_terms_ofp']['summary_ofp_count'] : 0;
                        $res .= '<tr class="blue-row" style="height: 60px">';
                        foreach ($brand_arr as $key => $value) {
                            if (!empty($data['brands'])) {
                                if (array_key_exists($value->name, $data['brands'])) {
                                    $percent = round($data['brands'][$value->name] / $possible_spot * 100, 0);
                                    $percent_width = 140 * $percent / 100;
                                    /*if($percent>40){
                                          $res .= '<td class=""  ><div class="indicator-div"><div class="indicator-div-left" style="width: ' .$percent_width . 'px;"> <span>'.$percent .' %</span></div><div class="indicator-div-right" style="width: ' .(140 - $percent_width ). 'px;">&nbsp;</div></div></td>';
                                      }else{
                                          $res .= '<td class=""  ><div class="indicator-div"><div class="indicator-div-left" style="width: ' .$percent_width . 'px;">&nbsp;</div><div class="indicator-div-right" style="width: ' .(140 - $percent_width ). 'px;"> <span>'.$percent .' %</span></div></div></td>';
                                      }*/
                                    $res .= '<td class=""  ><div class="indicator-div"><div class="indicator-div-left" style="width: ' . $percent_width . 'px;">&nbsp;</div><div class="indicator-div-right" style="width: ' . (140 - $percent_width) . 'px;">&nbsp;</div><div class="indicator-text">' . $percent . '%</div></div></td>';
                                } else {
                                    $res .= '<td><div class="indicator-div"><div class="indicator-div-right" style="width:140px;">&nbsp;</div><div class="indicator-text">0%</div></div></td>';
                                }
                            } else {
                                $res .= '<td><div class="indicator-div"><div class="indicator-div-right" style="width:140px;">&nbsp;</div><div class="indicator-text">0%</div></div></td>';
                            }
                        }
                        $res .= '</tr>';
                        $rowcount_for_1ssv = 0;
                        foreach ($data['search_terms_list'] as $search_term) {
                            $group_name = !empty($search_term->title) ? $search_term->title : '';
                            $ofp_count = !empty($data['serch_terms_ofp'][$group_name]) ? $data['serch_terms_ofp'][$group_name] : 0;
                            $tr_class = '';
                            if ($rowcount_for_1ssv % 2 == 1) {
                                $tr_class = 'trhover';
                            }
                            ++$rowcount_for_1ssv;
                            $res .= '<tr style="height: 40px;" class="' . $tr_class . '">';
                            foreach ($brand_arr as $key => $value) {
                                if (!empty($data['brand_terms'])) {
                                    if (array_key_exists($group_name . '_' . $value->name, $data['brand_terms'])) {
                                        $res .= '<td class="summary-brand-term-results"  data-term="' . $search_term->id . '" data-brand="' . $value->id . '">' . $data['brand_terms'][$group_name . '_' . $value->name] . '</td>';
                                    } else {
                                        $res .= '<td>0</td>';
                                    }
                                } else {
                                    $res .= '<td>0</td>';
                                }
                            }
                            $res .= '</tr>';
                        }
                        $res .= '<tr height="30" style="height: 30px;background-color: #fff;">';
                        foreach ($brand_arr as $key => $value) {
                            $res .= '<td style="border: 0;border-top: 1px solid #ddd;height:30px;border-left:0;" ></td>';
                        }
                        $res .= '</tr>';
                        $res .= '</table>
                                        <script>
                                            setTimeout(function(){
                                                var border_height = $(".compr-border-shadow").css("height", "100%").height();
                                                $(".compr-border-shadow").height(border_height - 47);
                                                var jspElement = $("#scroll-summary").bind(
                                                    "jsp-scroll-x",
                                                    function(event, scrollPositionX, isAtLeft, isAtRight)
                                                    {
                                                        if(isAtLeft){
                                                            $(".compr-border-shadow").addClass("hidden");
                                                        }else{
                                                            $(".compr-border-shadow").removeClass("hidden");
                                                        }
                                                    }
                                                    ).jScrollPane()
                                                }, 1000);
                                        </script>
                                </div>
                                <div class="compr-border-shadow hidden"></div>
                                <div class="border-right-hidden"></div>
                                </div>
                                </th>';
                    }
                    break;
                default:
                    $res = '<th></th>';
            }
        } elseif ($view == 'ComPr') {
            switch ($column) {
                case 'Product Name':
                    $res = '<th class="text-left rating-table-title" style="width: 50%;min-width:200px;height: 50px;"><strong>Product Name</strong></th>';
                    break;
                case 'Sites':
                    if (!empty($site)) {
                        $col_count = count($dates_of_upload) * count($site);
                        if ($col_count < 5) {
                            $sites_list = $this->sites_model->getSitesByIds($site);
                            $res = '';
                            $date_count = 0;
                            foreach ($dates_of_upload as $date) {
                                $site_count = 0;
                                foreach ($sites_list as $s_obj) {
                                    $site_logo = Ranking_model::getSiteLogoByName($s_obj->name);
                                    if (!empty($site_logo)) {
                                        $res .= '<th style="width:115px;" class="' . (!empty($this->sites_products_count[$s_obj->id]) ? 'sort-table-by' : '') . ' ' . ($sort_by == 'price' && isset($sort_by_num['site']) && $sort_by_num['site'] == $site_count && isset($sort_by_num['date']) && $sort_by_num['date'] == $date_count ? 'sorting-column' : '') . '" data-sort="price ' . $site_count . ' ' . $date_count . '"><img style="min-width:90px;max-height: 30px;max-width: 90px;" src="' . base_url('/img/site_logos/' . $site_logo) . '" />' . (!empty($this->sites_products_count[$s_obj->id]) ? '<span class="pull-right sorting ' . ($sort_dir == 'desc' && $sort_by == 'price' ? 'sorting-ico-down' : 'sorting-ico-up') . '"></span>' : '') . '</th>';
                                    } else {
                                        $site_name = $s_obj->name;
                                        if (strlen($site_name) > 10) {
                                            $site_name = substr($site_name, 0, 7) . '...';
                                        }
                                        $res .= '<th style="width:115px;max-width:115px;" class="inline-text ' . (!empty($this->sites_products_count[$s_obj->id]) ? 'sort-table-by' : '') . ' ' . ($sort_by == 'price' && isset($sort_by_num['site']) && $sort_by_num['site'] == $site_count && isset($sort_by_num['date']) && $sort_by_num['date'] == $date_count ? 'sorting-column' : '') . '" data-sort="price ' . $site_count . ' ' . $date_count . '"><strong title="' . ucfirst($s_obj->name) . '">' . ucfirst($site_name) . '</strong>' . (!empty($this->sites_products_count[$s_obj->id]) ? '<span class="pull-right sorting ' . ($sort_dir == 'desc' && $sort_by == 'price' ? 'sorting-ico-down' : 'sorting-ico-up') . '"></span>' : '') . '</th>';
                                    }
                                    ++$site_count;
                                }
                                ++$date_count;
                            }
                        } else {
                            $i = 0;
                            $res = '<th rowspan="18" style="padding: 0;border-left: 0;border-bottom: 0;">
                        <div style="position: relative">
                            <div class="scroll-pane" style="max-width: 549px;overflow: hidden;height: 100%;">
                                <table>
                                    <tr style="height: 48px;">';
                            $sites_list = $this->sites_model->getSitesByIds($site);
                            $date_count = 0;
                            foreach ($dates_of_upload as $date) {
                                $site_count = 0;
                                foreach ($sites_list as $s_obj) {
                                    $site_logo = Ranking_model::getSiteLogoByName($s_obj->name);
                                    if (!empty($site_logo)) {
                                        $res .= '<th style="width:115px;" class="' . (!empty($this->sites_products_count[$s_obj->id]) ? 'sort-table-by' : '') . ' ' . ($sort_by == 'price' && isset($sort_by_num['site']) && $sort_by_num['site'] == $site_count && isset($sort_by_num['date']) && $sort_by_num['date'] == $date_count ? 'sorting-column' : '') . '" data-sort="price ' . $site_count . ' ' . $date_count . '"><img style="min-width:90px;max-height: 30px;max-width: 90px;" src="' . base_url('/img/site_logos/' . $site_logo) . '" />' . (!empty($this->sites_products_count[$s_obj->id]) ? '<span class="pull-right sorting ' . ($sort_dir == 'desc' && $sort_by == 'price' ? 'sorting-ico-down' : 'sorting-ico-up') . '"></span>' : '') . '</th>';
                                    } else {
                                        $site_name = $s_obj->name;
                                        if (strlen($site_name) > 10) {
                                            $site_name = substr($site_name, 0, 7) . '...';
                                        }
                                        $res .= '<th style="width:115px;max-width:115px;" class="inline-text ' . (!empty($this->sites_products_count[$s_obj->id]) ? 'sort-table-by' : '') . ' ' . ($sort_by == 'price' && isset($sort_by_num['site']) && $sort_by_num['site'] == $site_count && isset($sort_by_num['date']) && $sort_by_num['date'] == $date_count ? 'sorting-column' : '') . '" data-sort="price ' . $site_count . ' ' . $date_count . '"><strong title="' . ucfirst($s_obj->name) . '">' . ucfirst($site_name) . '</strong>' . (!empty($this->sites_products_count[$s_obj->id]) ? '<span class="pull-right sorting ' . ($sort_dir == 'desc' && $sort_by == 'price' ? 'sorting-ico-down' : 'sorting-ico-up') . '"></span>' : '') . '</th>';
                                    }
                                    ++$site_count;
                                }
                                ++$date_count;
                            }
                            $res .= '</tr>';
                            //add row
                            $res .= '<tr class="blue-row">';
                            foreach ($dates_of_upload as $date) {
                                //$date_formated = date($dateformat == 2 ? "d/m/Y" : "m/d/Y", strtotime($date));
                                $date_formated = date('M d, Y', strtotime($date));
                                $colspan = !empty($site) && count($site) > 1 ? 'colspan="' . count($site) . '"' : '';
                                $res .= '<td ' . $colspan . ' class="text-center" style="height: 60px;">' . $date_formated . '</td>';
                            }
                            $res .= '</tr>';
                            $row_count = 0;
                            foreach ($data as $item) {
                                $tr_class = '';
                                if ($row_count % 2 == 1) {
                                    $tr_class = 'trhover';
                                }
                                $res .= '<tr class="' . $tr_class . '" height="60" style="height: 60px;background-color: #fff;">';
                                foreach ($dates_of_upload as $date) {
                                    if (!empty($item['prices'][$date])) {
                                        foreach ($sites_list as $s_obj) {
                                            if (!empty($item['prices'][$date][$s_obj->name])) {
                                                $out_of_stock_class = '';
                                                if (!empty($item['prices'][$date][$s_obj->name]->out_of_stock) && $item['prices'][$date][$s_obj->name]->out_of_stock == 't') {
                                                    $out_of_stock_class = 'com-pr-out-of-stock-td ranking-tooltip-compr';
                                                }
                                                if (!empty($item['prices'][$date][$s_obj->name]->price)) {
                                                    $price = $item['prices'][$date][$s_obj->name]->price;
                                                    if (!empty($item['prices'][$date][$s_obj->name]->price_formatted)) {
                                                        $price = $item['prices'][$date][$s_obj->name]->price_formatted;
                                                    } elseif ($item['prices'][$date][$s_obj->name]->currency) {
                                                        $price .= ' ' . $item['prices'][$date][$s_obj->name]->currency;
                                                    }
                                                    $res .= '<td style="width:135px;min-width:135px;" class="' . $out_of_stock_class . '" ' . (!empty($out_of_stock_class) ? 'data-tooltip="Out of Stock"' : '') . '><div style="position:relative;"><a href="' . $item['prices'][$date][$s_obj->name]->url . '" target="_blank">' . $price . '</a>' . (!empty($out_of_stock_class) ? '<span class="out-of-stock-td-ico"></span><br>out of stock' : '') . '</div></td>';
                                                } else {
                                                    $res .= '<td style="width:135px;min-width:135px;" class="' . $out_of_stock_class . '" ' . (!empty($out_of_stock_class) ? 'data-tooltip="Out of Stock"' : '') . '><div style="position:relative;"><a href="' . $item['prices'][$date][$s_obj->name]->url . '" target="_blank">' . (!empty($out_of_stock_class) ? 'out of stock<span class="out-of-stock-td-ico"></span><br>' : '') . 'Not Sold Online</a></div></td>';
                                                }
                                            } else {
                                                $res .= '<td style="width:135px;min-width:135px;" ></td>';
                                            }
                                        }
                                    } else {
                                        foreach ($sites_list as $s_obj) {
                                            $res .= '<td style="width:135px;min-width:135px;" ></td>';
                                        }
                                    }
                                }
                                $res .= '</tr>';
                                ++$row_count;
                            }
                            $res .= '<tr height="30" style="height: 30px;background-color: #fff;">';
                            foreach ($dates_of_upload as $date) {
                                foreach ($sites_list as $s_obj) {
                                    $res .= '<td style="width:135px;min-width:135px;border: 0;" ></td>';
                                }
                            }
                            $res .= '</tr>';
                            $percent = 1;
                            $col_position = $sort_by_num['site'] + count($site) * $sort_by_num['date'];
                            if ($col_position) {
                                $col_position++;
                            }
                            if ($col_position / (count($site) * count($dates_of_upload)) < 1 && $sort_by == 'price') {
                                $percent = round($col_position / (count($site) * count($dates_of_upload)), 2);
                            }
                            $res .= '</table>
                                        <script>
                                            setTimeout(function(){
                                            var border_height = $(".compr-border-shadow").height();
                                            $(".compr-border-shadow").height(border_height - 30);
                                                var jspElement = $(".scroll-pane").bind(
                                                    "jsp-scroll-x",
                                                    function(event, scrollPositionX, isAtLeft, isAtRight)
                                                    {
                                                        if(isAtLeft){
                                                            $(".compr-border-shadow").addClass("hidden");
                                                        }else{
                                                            $(".compr-border-shadow").removeClass("hidden");
                                                        }
                                                    }
                                                    ).jScrollPane()
var jspApi = jspElement.data("jsp");
jspApi.scrollToPercentX(' . $percent . ', false );
$(".jspHorizontalBar .jspDrag").addClass("ranking-tooltip-compr").attr("data-tooltip", "Scroll to the right to view all dates and retailers included in your report.");
setComPrTooltips();
$(".jspHorizontalBar .jspDrag").qtip("show");
setTimeout(function(){
$(".jspHorizontalBar .jspDrag").qtip("hide");
},3000);
}, 1000);
</script>
</div>
<div class="compr-border-shadow"></div>
</div>
</th>';
                        }
                    } else {
                        $res = '<th class="no-width"><strong>Sites</strong></th>';
                    }
                    break;
                default:
                    $res = '<th></th>';
            }
        } elseif ($view == '1s1t') {
            switch ($column) {
                case 'Brand':
                    $res = '<th class="sort-table-by text-left" data-sort="name"><strong>Brand</strong><span class="pull-right sorting ' . ($sort_dir == 'desc' && $sort_by == 'b.name' ? 'sorting-ico-down' : 'sorting-ico-up') . '"></span></th>';
                    break;
                case 'Brand Results':
                    $res = '<th style="width:120px" class="sort-table-by" data-sort="brand_results"><strong>Brand Results</strong><span class="pull-right sorting ' . ($sort_dir == 'desc' && $sort_by == 'rsris.brand_results' ? 'sorting-ico-down' : 'sorting-ico-up') . '"></span></th>';
                    break;
                case '#SKUs on First Page':
                    $res = ' <th style="width:155px" class="sort-table-by" data-sort="on_first_page"><strong>#SKUs on First Page</strong><span class="pull-right sorting ' . ($sort_dir == 'desc' && $sort_by == 'rsris.on_first_page' ? 'sorting-ico-down' : 'sorting-ico-up') . '"></span></th>';
                    break;
                case 'Best Match Rankings':
                    $res = '<th style="width:25%" class="sort-table-by" data-sort="number_in_results"><strong>Best Match Rankings</strong><span class="pull-right sorting ' . ($sort_dir == 'desc' && $sort_by == 'r.number_in_results' ? 'sorting-ico-down' : 'sorting-ico-up') . '"></span></th>';
                    break;
                default:
                    $res = '<th></th>';
            }
        } elseif ($view == '1srv' || $view == 'p2hp') {
            switch ($column) {
                case 'Best Match Rank':
                    $res = '<th class="sort-table-by ' . ($sort_by == 'rsri.ranking' ? 'sorting-column' : '') . '" data-sort="ranking" style="width: 10%;"><div><strong>Best Match Rank</strong><span class="pull-right sorting ' . ($sort_dir == 'desc' && $sort_by == 'rsri.ranking' ? 'sorting-ico-down' : 'sorting-ico-up') . '"></span></div></th>';
                    break;
                case 'Search Terms':
                    $res = '<th class="sort-table-by no-width ' . ($sort_by == 'st.title' ? 'sorting-column' : '') . '" data-sort="keyword" style="width: 20%;"><div><strong>Search Terms</strong><span class="pull-right sorting ' . ($sort_dir == 'desc' && $sort_by == 'st.title' ? 'sorting-ico-down' : 'sorting-ico-up') . '"></span></div></th>';
                    break;
                case 'Product Name':
                    $res = '<th class="sort-table-by no-width text-left ' . ($sort_by == 'rsri.title' ? 'sorting-column' : '') . '" data-sort="title"><div><strong>Product Name</strong><span class="pull-right sorting ' . ($sort_dir == 'desc' && $sort_by == 'rsri.title' ? 'sorting-ico-down' : 'sorting-ico-up') . '"></span></div></th>';
                    break;
                case 'Best Seller Rank':
                    $res = '<th class="sort-table-by ' . ($sort_by == 'rsri.best_seller_ranking' ? 'sorting-column' : '') . '" style="width: 10%;" data-sort="best_seller_ranking"><div><strong>Best Seller Rank</strong><span class="pull-right sorting ' . ($sort_dir == 'desc' && $sort_by == 'rsri.best_seller_ranking' ? 'sorting-ico-down' : 'sorting-ico-up') . '"></span></div></th>';
                    break;
                case 'Site':
                    $res = '<th class="sort-table-by no-width ' . ($sort_by == 'site' ? 'sorting-column' : '') . '" data-sort="site" style="width: 10%;"><div><strong>Site</strong><span class="pull-right sorting ' . ($sort_dir == 'desc' && $sort_by == 'site' ? 'sorting-ico-down' : 'sorting-ico-up') . '"></span></div></th>';
                    break;
                case 'In Stock':
                    $res = '<th class="sort-table-by no-width ' . ($sort_by == 'out_of_stock' ? 'sorting-column' : '') . '" data-sort="out_of_stock" style="width: 10%;"><div><strong>In Stock</strong><span class="pull-right sorting ' . ($sort_dir == 'desc' && $sort_by == 'out_of_stock' ? 'sorting-ico-down' : 'sorting-ico-up') . '"></span></div></th>';
                    break;
                case 'In Store Only':
                    $res = '<th class="sort-table-by no-width ' . ($sort_by == 'in_store_only' ? 'sorting-column' : '') . '" data-sort="in_store_only" style="width: 10%;"><div><strong>In Store Only</strong><span class="pull-right sorting ' . ($sort_dir == 'desc' && $sort_by == 'in_store_only' ? 'sorting-ico-down' : 'sorting-ico-up') . '"></span></div></th>';
                    break;
                case 'Price':
                    $res = '<th class="sort-table-by no-width ' . ($sort_by == 'price' ? 'sorting-column' : '') . '" data-sort="price" style="width: 10%;"><div><strong>Price</strong><span class="pull-right sorting ' . ($sort_dir == 'desc' && $sort_by == 'price' ? 'sorting-ico-down' : 'sorting-ico-up') . '"></span></div></th>';
                    break;
                case 'Brand':
                    $res = '<th class="sort-table-by no-width ' . ($sort_by == 'brand_name' ? 'sorting-column' : '') . '" data-sort="brand_name" style="width: 10%;"><div><strong>Brand</strong><span class="pull-right sorting ' . ($sort_dir == 'desc' && $sort_by == 'brand_name' ? 'sorting-ico-down' : 'sorting-ico-up') . '"></span></div></th>';
                    break;
                case 'Visits':
                    $res = '<th class="sort-table-by no-width" data-sort="page_visits" style="width: 10%;"><div><strong>Visits</strong><span class="pull-right sorting ' . ($sort_dir == 'desc' && $sort_by == 'page_visits' ? 'sorting-ico-down' : 'sorting-ico-up') . '"></span></div></th>';
                    break;
                case 'Sales (One Day Avg)':
                    $res = '<th><div><strong>Sales (One Day Avg)</strong></div></th>';
                    break;
                case 'Sales (30 Day Avg)':
                    $res = '<th><div><strong>Sales (30 Day Avg)</strong></div></th>';
                    break;
                case 'Amazon Type':
                    $res = '<th class="sort-table-by ' . ($sort_by == 'prime' ? 'sorting-column' : '') . '" data-sort="prime"><div><strong>Amazon Type</strong></div><span class="pull-right sorting ' . ($sort_dir == 'desc' && $sort_by == 'prime' ? 'sorting-ico-down' : 'sorting-ico-up') . '"></span></th>';
                    break;
                case 'UPC':
                    $res = '<th><div><strong>UPC</strong></div></th>';
                    break;
                default:
                    $res = '<th></th>';
            }
        } elseif ($view == '1sro') {
            switch ($column) {
                case 'Product':
                    $res = '<th class="sort-table-by no-width" data-sort="title"><strong>Product</strong><span class="pull-right sorting ' . ($sort_dir == 'desc' && $sort_by == 'title' ? 'sorting-ico-down' : 'sorting-ico-up') . '"></span></th>';
                    break;
                case 'Brand':
                    $res = '<th class="sort-table-by width80" data-sort="brand_name"><strong>Brand</strong><span class="pull-right sorting ' . ($sort_dir == 'desc' && $sort_by == 'brand_name' ? 'sorting-ico-down' : 'sorting-ico-up') . '"></span></th>';
                    break;
                case 'Site':
                    $res = '<th class="sort-table-by width80" data-sort="site_name"><strong>Site</strong><span class="pull-right sorting ' . ($sort_dir == 'desc' && $sort_by == 'site_name' ? 'sorting-ico-down' : 'sorting-ico-up') . '"></span></th>';
                    break;
                case '5 stars':
                    $avg = !empty($data[5]) ? "({$data['5']})" : "";
                    $res = '<th class="sort-table-by no-width" data-sort="five_star">
                        <span class="star-ico five-star-ico"></span>
                        <span style="white-space: nowrap">' . $avg . '</span>
                        <span class="pull-right sorting ' . ($sort_dir == 'desc' && $sort_by == 'five_star' ? 'sorting-ico-down' : 'sorting-ico-up') . '"></span>
                    </th>';
                    break;
                case '4 stars':
                    $avg = !empty($data[4]) ? "({$data['4']})" : "";
                    $res = '<th class="sort-table-by no-width" data-sort="four_star">
                        <span class="star-ico four-star-ico"></span>
                        <span style="white-space: nowrap">' . $avg . '</span>
                        <span class="pull-right sorting ' . ($sort_dir == 'desc' && $sort_by == 'four_star' ? 'sorting-ico-down' : 'sorting-ico-up') . '"></span>
                    </th>';
                    break;
                case '3 stars':
                    $avg = !empty($data[3]) ? "({$data['3']})" : "";
                    $res = '<th class="sort-table-by no-width" data-sort="three_star">
                        <span class="star-ico three-star-ico"></span>
                        <span style="white-space: nowrap">' . $avg . '</span>
                        <span class="pull-right sorting ' . ($sort_dir == 'desc' && $sort_by == 'three_star' ? 'sorting-ico-down' : 'sorting-ico-up') . '"></span>
                    </th>';
                    break;
                case '2 stars':
                    $avg = !empty($data[2]) ? "({$data['2']})" : "";
                    $res = '<th class="sort-table-by no-width" data-sort="two_star">
                        <span class="star-ico two-star-ico"></span>
                        <span style="white-space: nowrap">' . $avg . '</span>
                        <span class="pull-right sorting ' . ($sort_dir == 'desc' && $sort_by == 'two_star' ? 'sorting-ico-down' : 'sorting-ico-up') . '"></span>
                    </th>';
                    break;
                case '1 star':
                    $avg = !empty($data[1]) ? "({$data['1']})" : "";
                    $res = '<th class="sort-table-by no-width" data-sort="one_star">
                        <span class="star-ico one-star-ico"></span>
                        <span style="white-space: nowrap">' . $avg . '</span>
                        <span class="pull-right sorting ' . ($sort_dir == 'desc' && $sort_by == 'one_star' ? 'sorting-ico-down' : 'sorting-ico-up') . '"></span>
                    </th>';
                    break;
                case 'Average':
                    $avg = !empty($data['average']) ? "(" . $data['average'] . ")" : "";
                    $res = '<th class="sort-table-by no-width" data-sort="average_num">
                        <strong>Average</strong>
                        <span style="white-space: nowrap">' . $avg . '</span>
                        <span class="pull-right sorting ' . ($sort_dir == 'desc' && $sort_by == 'average_num' ? 'sorting-ico-down' : 'sorting-ico-up') . '"></span>
                    </th>';
                    break;
                default:
                    $res = '<th></th>';
            }
        } elseif ($view == '1srobp') {
            switch ($column) {
                case 'Rating':
                    $res = '<th class="no-width">Rating</th>';
                    break;
                case 'Dates':
                    foreach ($dates_of_upload as $date) {
                        $res .= '<th class="date-title width71">' . $date . '</th>';
                    }
                    break;
                default:
                    $res = '<th></th>';
            }
        } elseif ($view == '1srvbs') {
            switch ($column) {
                case 'Product':
                    $res = '<th style="width:245px;" >Product</th>';
                    break;
                case 'Search Term':
                    $res = '<th style="min-width:86px;">Search Term</th>';
                    break;
                case 'Last Week':
                    $res = '<th class="width71">Last Wk</th>';
                    break;
                case 'Yesterday':
                    $res .= '<th class="width71">Yest</th>';
                    break;
                case 'Today':
                    $res .= '<th class="width71">Today</th>';
                    break;
                default:
                    $res = '<th></th>';
            }
        } elseif ($view == '1s1b1r') {
            switch ($column) {
                case 'Brand':
                    $res = '<th class="brand-image text-left" style="width: 16%"><strong>Brand</strong></th>';
                    break;
                case 'Rank':
                    $res = '<th class="sort-table-by no-width text-left" data-sort="ranking" style="width: 7%;"><strong>Rank</strong><span class="pull-right sorting ' . ($sort_dir == 'desc' && $sort_by == 'rsri.ranking' ? 'sorting-ico-down' : 'sorting-ico-up') . '"></span></th>';
                    break;
                case 'Product Name':
                    $res = '<th class="sort-table-by no-width text-left" data-sort="title" style="width:24%"><strong>Product Name</strong><span class="pull-right sorting ' . ($sort_dir == 'desc' && $sort_by == 'rsri.title' ? 'sorting-ico-down' : 'sorting-ico-up') . '"></span></th>';
                    break;
                case 'Best Seller Rank':
                    $res = '<th class="sort-table-by" data-sort="best_seller_ranking" style="width: 15%"><nobr><strong>Best Seller Rank</strong><span class="pull-right sorting ' . ($sort_dir == 'desc' && $sort_by == 'rsri.best_seller_ranking' ? 'sorting-ico-down' : 'sorting-ico-up') . '"></span></nobr></th>';
                    break;
                case 'Search Term In Title':
                    //<span data-content="<div style="font-weight: 400" id="popover_span_class">Exact: The exact search query appears in the name of the product.<br><br> Interleaved: All of the words from the search query appear in the product name.<br><br> Partial: Some words from the search query appear in the product name.</div>" data-html="true"  data-original-title="<span id="popover_span_class">Explanation</span><a class="popover_close_btn" href="#" onclick="close_popover(this); return false;">X</a>"  title=""  data-placement="left" class="question_mark_brand_report_ranking"></span>
                    //$res = '<th class="sort-table-by" data-sort="search_term_in_title"><strong>Search Term In Title</strong><span class="pull-right ' . ( $sort_dir == 'desc' && $sort_by == 'rsri.search_term_in_title' ? 'sorting-ico-down' : 'sorting-ico-up' ) . '"></span></th>';
                    $res = '<th class="sort-table-by min_width_last_tds" data-sort="search_term_in_title"><strong>Search Term In Title</strong><span data-content="<div style=\'font-weight: 400; text-align:left;\' id=\'popover_span_class\' >Exact Match: The exact search query appears in the product name.<br><br> Broad Match: Some of the search query words appear in the product name.<br><br> No Match: The search query words do not appear in the product name.</div>" data-html="true"  data-original-title="<span id=\'popover_span_class\'>Explanation</span><a class=\'popover_close_btn\' href=\'#\' onclick=\'close_popover(this); return false;\'></a>"  title=""  data-placement="left" class="question_mark_brand_report_ranking"></span><span class="pull-right sorting ' . ($sort_dir == 'desc' && $sort_by == 'rsri.search_term_in_title' ? 'sorting-ico-down' : 'sorting-ico-up') . '"></span></th>';
                    break;
                case 'Promo Opportunities':
                    $res = '<th class="sort-table-by"><strong>Promo Opportunities</strong></th>';
                    break;
                default:
                    $res = '<th></th>';
            }
        } elseif ($view == '1s1b1r_md') {
            $col_width = $columns_count ? 98 / (int) $columns_count : 0;
            $col_px_width = $columns_count ? 990 / (int) $columns_count : 0;
            switch ($column) {
                case 'Brand':
                    $res = '<th class="brand-image text-left" style="width: ' . $col_width . '%;"><strong>Brand</strong></th>';
                    break;
                case 'Product Name':
                    $res = '<th class="sort-table-by no-width text-left" data-sort="title" style="width:' . $col_width . '%"><strong>Product Name</strong><span class="pull-right sorting ' . ($sort_dir == "desc" && $sort_by == "rsri.title" ? "sorting-ico-down" : "sorting-ico-up") . '"></span></th>';
                    break;
                case 'Product Details':
                    $res = '<th class="text-left" style="width: ' . $col_width . '%;"><strong>Product Details</strong></th>';
                    break;
                case 'Product Data':
                    $res = '';
                    foreach ($dates_of_upload as $date) {
                        if ($dateformat == 1) {
                            $date = date('m/d/Y', strtotime($date));
                        } elseif ($dateformat == 2) {
                            $date = date('d/m/Y', strtotime($date));
                        }
                        $res .= '<th style="width: ' . $col_width . '%;"><strong>' . $date . '</strong></th>';
                    }
                    break;
                default:
                    $res = '<th></th>';
            }
            if (!$this->rowcountrow) {
                $res .= '<style type="text/css">
                    #ranking-table .promo-opportunities p{
    width: ' . ($col_px_width - 40) . 'px;
}
</style>';
            }
            ++$this->rowcountrow;
        } elseif ($view == '1s1bpn') {
            switch ($column) {
                case 'Product Name':
                    $res = '<th class="sort-table-by no-width text-left" data-sort="title"><strong>Product Name</strong><span class="pull-right sorting ' . ($sort_dir == 'desc' && $sort_by == 'rsri.title' ? 'sorting-ico-down' : 'sorting-ico-up') . '"></span></th>';
                    break;
                case 'Site':
                    $res = '<th class="no-width text-left" style="width:20%"><strong>Site</strong></th>';
                    break;
                case 'Search Terms':
                    $res = '<th class="no-width text-left" style="width:20%"><strong>Search Term</strong></th>';
                    break;
                case 'Search Term In Title':
                    $res = '<th class="sort-table-by min_width_last_tds" data-sort="search_term_in_title"><strong>Search Term In Title</strong><span data-content="<div style=\'font-weight: 400; text-align:left; color:black;\' id=\'popover_span_class\' >Exact Match: The exact search query appears in the product name.<br><br> Broad Match: Some of the search query words appear in the product name.<br><br> No Match: The search query words do not appear in the product name.</div>" data-html="true"  data-original-title="<span id=\'popover_span_class\'>Explanation</span><a class=\'popover_close_btn\' href=\'#\' onclick=\'close_popover(this); return false;\'></a>"  title=""  data-placement="left" class="question_mark_brand_report_ranking"></span><span class="pull-right sorting ' . ($sort_dir == 'desc' && $sort_by == 'rsri.search_term_in_title' ? 'sorting-ico-down' : 'sorting-ico-up') . '"></span></th>';
                    break;
                default:
                    $res = '<th></th>';
            }
        } elseif ($view == '1s1bpn_md') {
            switch ($column) {
                case 'Product Name':
                    $res = '<th class="sort-table-by no-width text-left" data-sort="title" style="width:20%"><strong>Product Name</strong><span class="pull-right sorting ' . ($sort_dir == "desc" && $sort_by == "rsri.title" ? "sorting-ico-down" : "sorting-ico-up") . '"></span></th>';
                    break;
                case 'Site':
                    $res = '<th class="no-width text-left" style="width:20%"><strong>Site</strong></th>';
                    break;
                case 'Search Terms':
                    $res = '<th class="no-width text-left" style="width:20%"><strong>Search Term</strong></th>';
                    break;
                case 'Product Details':
                    $res = '<th class="text-left"><strong>Product Details</strong></th>';
                    break;
                case 'Product Data':
                    $res = '';
                    foreach ($dates_of_upload as $date) {
                        if ($dateformat == 1) {
                            $date = date('m/d/Y', strtotime($date));
                        } elseif ($dateformat == 2) {
                            $date = date('d/m/Y', strtotime($date));
                        }
                        $res .= '<th><strong>' . $date . '</strong></th>';
                    }
                    break;
                default:
                    $res = '<th></th>';
            }
        } elseif ($view == '1srv_md' || $view == 'p2hp_md') {
            switch ($column) {
                case 'Product Name':
                    $res = '<th class="sort-table-by text-left ' . ($sort_by == 'rsri.title' ? 'sorting-column' : '') . '" data-sort="title" style="width:48%"><strong>Product Name</strong><span class="pull-right sorting ' . ($sort_dir == 'desc' && $sort_by == 'rsri.title' ? 'sorting-ico-down' : 'sorting-ico-up') . '"></span></th>';
                    break;
                case 'Best Match Rank':
                    $columns_count = 7 - $this->visible_columns_count;
                    if (count($dates_of_upload) <= $columns_count) {
                        $i = 0;
                        $res = '';
                        foreach ($dates_of_upload as $date) {
                            $timestamp = strtotime($date);
                            $res .= '<th class="text-center width100 sort-table-by ' . ($sort_by_num == $i && $sort_by == 'rsri.ranking' ? 'sorting-column' : '') . '" data-sort="ranking ' . (int) $i . '" >' . date('M d/y', $timestamp) . '<span class="pull-right sorting ' . ($sort_dir == 'desc' && $sort_by == 'rsri.ranking' && $sort_by_num == $i ? 'sorting-ico-down' : 'sorting-ico-up') . '"></span></th>';
                            ++$i;
                        }
                    } else {
                        $width = 115 * $columns_count;
                        $i = 0;
                        $res = '<th rowspan="' . (count($data) + 1) . '" style="padding: 0;">
                    <div class="scroll-pane" style="max-width: ' . $width . 'px;overflow: hidden;height: 100%;">
                        <table class="inner-table">
                            <tr>';
                        foreach ($dates_of_upload as $date) {
                            $timestamp = strtotime($date);
                            $res .= '<th class="text-center width100 sort-table-by ' . ($sort_by_num == $i && $sort_by == 'rsri.ranking' ? 'sorting-column' : '') . '" data-sort="ranking ' . (int) $i . '" >' . date('M d/y', $timestamp) . '<span class="pull-right sorting ' . ($sort_dir == 'desc' && $sort_by == 'rsri.ranking' && $sort_by_num == $i ? 'sorting-ico-down' : 'sorting-ico-up') . '"></span></th>';
                            ++$i;
                        }
                        $res .= '</tr>';
                        foreach ($data as $item) {
                            $first_page_class = '';
                            $tr_class = '';
                            if (!empty($dates_of_upload[$sort_by_num]) && !empty($item[$dates_of_upload[$sort_by_num]]) && !empty($item[$dates_of_upload[$sort_by_num]]->ofp_by_ranking) && $item[$dates_of_upload[$sort_by_num]]->ofp_by_ranking == 't') {
                                $tr_class = 'first-page-item-row';
                                $first_page_class = ' class="first-page-item"';
                            }
                            $res .= '<tr class="' . $tr_class . '">';
                            $prev_value = 0;
                            foreach ($dates_of_upload as $date) {
                                $res .= '<td  style="height:40px; " ' . $first_page_class . '>';
                                $res .= '<div class="text-center" style="margin: 0 auto; width: 100px;display: inline-block;position: relative;">';
                                if (!empty($item[$date]) && !empty($item[$date]->ranking)) {
                                    if ($prev_value != '') {
                                        if ($prev_value > $item[$date]->ranking) {
                                            $dif = abs($item[$date]->ranking - $prev_value);
                                            $res .= '<div style="float: right;right: -33px;background-color: #e6f3d9;border-radius: 5px;padding-right: 5px;color:#4fb724;"><img src="' . base_url('img/percent-arrow-increase.png') . '" style="position: relative;left: -5px;bottom:2px;">' . $dif . '</div>';
                                        } elseif ($prev_value < $item[$date]->ranking) {
                                            $dif = abs($item[$date]->ranking - $prev_value);
                                            $res .= '<div style="float: right;right: -33px;background-color: #f6d7d2;border-radius: 5px;padding-right: 5px;color:#f40000;"><img src="' . base_url('img/percent-arrow-decrease.png') . '" style="position: relative;left: -5px;bottom:2px;">' . $dif . '</div>';
                                        }
                                    }
                                    $res .= '<span style="width: 40px; text-align: center;">' . $item[$date]->ranking . '</span>';
                                    $prev_value = $item[$date]->ranking;
                                }
                                $res .= '</td>';
                            }
                            $res .= '</tr>';
                        }
                        $res .= '</table>
                                <script>
                                    setTimeout(function(){
                                        var jspElement = $(".scroll-pane").bind(
                                            "jsp-scroll-x",
                                            function(event, scrollPositionX, isAtLeft, isAtRight)
                                            {
                                                var sumAllDAy = 0;
                                                $(".date-tags").each(function(index) {
                                                    var daynum = $(\'tbody tr.dark-row td[data-id="\' + $(this).text() + \'"]\').length;
                                                    var scrollWidth = daynum*87;
                                                    if(scrollPositionX >= sumAllDAy && scrollPositionX <= sumAllDAy + scrollWidth - 50) {
                                                        $(this).css("left",scrollPositionX-sumAllDAy);
                                                    }
                                                    sumAllDAy += scrollWidth;
                                                });
                                            //var dateTags = $(".date-tags");
                                            //$(dateTags[0]).css("left",scrollPositionX);

                                            //$(".date-tags").css("left",scrollPositionX);
}
).jScrollPane();
var jspApi = jspElement.data("jsp"); ';
                        //scroll table to the right
                        if ($sort_by_num >= count($dates_of_upload) - 2) {
                            $res .= 'jspApi.scrollToPercentX(100, false );';
                        }
                        $res .= '}, 1000);
</script>
</div>
</th>';
                    }
                    break;
                case 'Search Terms':
                    $res = '<th class="sort-table-by text-left no-width ' . ($sort_by == 'st.title' ? 'sorting-column' : '') . '" data-sort="keyword" style="width: 16%;min-width:130px;"><strong>Search Terms</strong><span class="pull-right sorting ' . ($sort_dir == 'desc' && $sort_by == 'st.title' ? 'sorting-ico-down' : 'sorting-ico-up') . '"></span></th>';
                    break;
                case 'Site':
                    $res = '<th class="sort-table-by text-left no-width ' . ($sort_by == 'site' ? 'sorting-column' : '') . '" data-sort="site" style="width: 16%;min-width:100px;"><strong>Site</strong><span class="pull-right sorting ' . ($sort_dir == 'desc' && $sort_by == 'site' ? 'sorting-ico-down' : 'sorting-ico-up') . '"></span></th>';
                    break;
                case 'Average Ranking':
                    $res = '<th class="sort-table-by text-left no-width ' . ($sort_by == 'avg_ranking' ? 'sorting-column' : '') . '" data-sort="avg_ranking" style="width: 20%;min-width:100px;"><strong>Avg Ranking</strong><span class="pull-right sorting ' . ($sort_dir == 'desc' && $sort_by == 'avg_ranking' ? 'sorting-ico-down' : 'sorting-ico-up') . '"></span></th>';
                    break;
                default:
                    $res = '<th></th>';
            }
        }
        return $res;
    }
예제 #11
0
<div class="tip-content">
    <div>LAST PRICE CHANGES</div>
    <table class="tbl" style="width:100%">
        <thead>
        <tr>
            <td>Date</td>
            <td>Price</td>
        </tr>
        </thead>
        <tbody>
        <?php foreach ($result as $item) : ?>
            <tr>
                <?php $date = new \DateTime($item['date_of_upload']); ?>
                <td><?php echo $date->format("F d, Y"); ?></td>
                <td><?php echo Ranking_model::getCurrencySymbol($item['currency']) . $item['price']; ?></td>
            </tr>
        <?php endforeach; ?>
        </tbody>
    </table>
</div>
<style>
    .tip-content {
        width:100%;
        font-size:14px;
        line-height:25px;
        padding:5px 7px;
    }
    .tbl, .tbl tbody {
        border-top: 1px solid #888888;
    }
    .tbl td {
예제 #12
0
 /**
  * Return data for table view Price Sensitivity
  * @return json
  * @author Ruslan Ushakov
  */
 public function getPriceSensitivity()
 {
     $this->load->model('ranking_model');
     $this->load->model('sites_model');
     $this->load->model('product_model');
     $site_id = $this->input->post('site_id');
     $term_id = $this->input->post('term_id');
     $brand_id = $this->input->post('brand_id');
     $date_of_upload = $this->input->post('date_of_upload');
     $view = $this->input->post('view');
     $sort_by = $this->input->post('sort_by');
     $sort_dir = $this->input->post('sort_dir');
     $all_checked_checkboxes = $this->input->post('all_checked_checkboxes');
     $all_checked_brand_checkboxes = $this->input->post('all_checked_brand_checkboxes');
     $brand_id = Ranking_model::getBrandIdsFromSelectedGroups($brand_id, $all_checked_brand_checkboxes);
     $data = array();
     $product_lists = $this->input->post('product_lists');
     $userId = $this->ion_auth->get_user_id();
     $hasAssociations = $this->product_model->hasAssociations($userId);
     if ($hasAssociations && !empty($site_id) && (!empty($term_id) || !empty($product_lists)) && !empty($date_of_upload)) {
         if (is_array($date_of_upload)) {
             $date_of_upload = $date_of_upload[0];
         }
         $data_prepared = array();
         $titles_list = $this->ranking_model->getAssociatedProductsByParams($site_id, $date_of_upload, $term_id, $brand_id, $product_lists);
         foreach ($titles_list as $product) {
             $title = htmlspecialchars($product->title);
             $title_hash = sha1($title);
             if (!array_key_exists($title_hash, $data_prepared)) {
                 $data_prepared[$title_hash] = array();
                 $data_prepared[$title_hash]['title'] = $title;
                 $data_prepared[$title_hash]['image_url'] = $product->image_url;
                 $data_prepared[$title_hash]['prices'] = array();
             }
             if (!array_key_exists($product->site, $data_prepared[$title_hash]['prices'])) {
                 $data_prepared[$title_hash]['prices'][$product->site] = array();
                 $data_prepared[$title_hash]['prices'][$product->site]['price'] = $product->price;
                 $data_prepared[$title_hash]['prices'][$product->site]['currency'] = $product->currency;
                 $data_prepared[$title_hash]['prices'][$product->site]['url'] = $product->url;
                 $currency_symbol = Ranking_model::getCurrencySymbol($product->currency);
                 if (!empty($currency_symbol)) {
                     $data_prepared[$title_hash]['prices'][$product->site]['price_formatted'] = $currency_symbol . $product->price;
                 } else {
                     $data_prepared[$title_hash]['prices'][$product->site]['price_formatted'] = '';
                 }
             }
         }
         foreach ($data_prepared as $hash => $product) {
             if (!empty($product['prices'])) {
                 $data[$hash] = $product;
                 $price_arr = $product['prices'];
                 $sum = 0;
                 $product_currency = '';
                 foreach ($price_arr as $price_obj) {
                     if (!empty($price_obj['price'])) {
                         $sum += $price_obj['price'];
                     }
                     if (empty($product_currency)) {
                         $product_currency = $price_obj['currency'];
                     }
                 }
                 $average = number_format($sum / count($price_arr), 2, '.', '');
                 $price_arr['average'] = array();
                 $price_arr['average']['price'] = $average;
                 $price_arr['average']['currency'] = $product_currency;
                 $currency_symbol = Ranking_model::getCurrencySymbol($product_currency);
                 if (!empty($currency_symbol)) {
                     $price_arr['average']['price_formatted'] = $currency_symbol . $price_arr['average']['price'];
                 } else {
                     $price_arr['average']['price_formatted'] = '';
                 }
                 uasort($price_arr, 'userSortByPriceDesc');
                 $data[$hash]['prices'] = $price_arr;
             }
         }
         $pager = $this->getPager(count($data), 8);
         $products = array_slice($data, $pager['offset'], $pager['length']);
         $pager_str = $this->load->view('elements/pager', array('pager' => $pager), true);
         $responseTemplate = $this->load->view('assess/scorecard/content/report-templates/PrSen.php', array('products' => $products), true);
         $table = utf8_encode($responseTemplate);
     }
     /*if (empty($products)) {
           $table = $this->load->view('assess/scorecard/content/report-templates/prod_association_req', array(), true);
       }*/
     $this->jsonResponse(array('table' => $table, 'pager' => $pager_str, 'productCount' => count($products)));
 }
                 <?php endif;?>
             </th>
             <th rowspan="18" style="width:60%;padding: 0;border-left: 0;border-bottom: 0;">
                 <div style="position: relative">
                     <div class="google-scroll-pane" style="overflow: hidden;height: 100%;">
                         <table>
                             <tr style="height: 48px;">
                                 <?php foreach($searchTermArray['sellers'] as $sellerName => $sellerInfo) { ?>
                                     <th style="width:115px;" class="sort-table-by sorting-column" data-sort="price 0 0"><?php echo !empty($sellerName) ? $sellerName : '' ; ?></th>
                                 <?php } ?>
                             </tr>
                             <tr class="" height="60" style="height: 60px;background-color: #fff;">
                                 <?php foreach($searchTermArray['sellers'] as $sellerName => $sellerInfo) { ?>
                                     <td style="width:135px;min-width:135px;" class="">
                                         <div style="position:relative;">
                                             <?php echo (!empty($sellerInfo->price)) ? $sellerInfo->price : ''; ?> <?php echo !empty($sellerInfo->currency) ? Ranking_model::getCurrencySymbol($sellerInfo->currency) : '';?>
                                         </div>
                                     </td>
                                 <?php } ?>
                             </tr>
                         </table>
                     </div>
                 </div>
             </th>
         </tr>
         </tbody>
     </table>
 <?php } ?>
 <?php } ?>
     <div class="row-fluid ranking-pager-container" id="ranking-pager"></div>
     <script>