Exemple #1
0
 public function exportZeroReviews()
 {
     $this->load->model('ranking_model');
     $this->load->model('sites_model');
     $data = array();
     $sites = $this->input->get('sites');
     $searchTerms = $this->input->get('searchTerms');
     $searchTermsKeywords = $this->input->get('searchTermsKeywords');
     $brands = $this->input->get('brands');
     $dates = $this->input->get('dates');
     $productList = $this->input->get('productList');
     $brands = Ranking_model::getBrandIdsFromSelectedGroups($brands, $searchTermsKeywords);
     $filter = array('date_of_upload' => $dates, 'term_id' => $searchTerms, 'site_id' => $sites, 'brand_id' => $brands, 'product_lists' => $productList != 'null' ? $productList : null);
     $result = $this->ranking_model->getZeroReviews($filter);
     $data[] = array('Product', 'UPC', 'URL', 'Retailer', '# of Reviews');
     if (!empty($result)) {
         foreach ($result as $product) {
             $data[] = array($product['title'], empty($product['upc']) ? 'N/A' : $product['upc'], $product['product_url'], $product['retailer'], $product['total_reviews'] . ' Reviews');
         }
     }
     $output = array_to_csv($data);
     $fileName = 'NoReviews- ' . date('Y-m-d') . '.csv';
     //  Output CSV File
     $this->output->set_output($output)->set_content_type('application/octet-stream')->set_header("Content-Disposition: attachment; filename={$fileName}")->set_header('Content-Length: ' . strlen($output));
 }
Exemple #2
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;
 }
Exemple #3
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))));
     }
 }
Exemple #4
0
 /**
  * Return data for ranking charts
  * @return json
  * @author Ruslan Ushakov
  */
 public function get_raking_chart_data()
 {
     $this->load->model('ranking_model');
     $this->load->model('product_model');
     $this->load->model('sites_model');
     $site_id = $this->input->post('site_id');
     $group_id = (int) $this->input->post('group_id');
     $term_id = $this->input->post('term_id');
     $brand_id = $this->input->post('brand_id');
     $brand_id = array_filter($brand_id);
     if (empty($brand_id)) {
         $this->load->model('scorecard_model');
         $selected_brands = $this->scorecard_model->get_brands_by_search_terms($term_id, $site_id);
         foreach ($selected_brands as $val) {
             $brand_id[] = $val->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)) $brand_id = $brand_id[0];
     $view = $this->input->post('view');
     $date_of_upload = $this->input->post('date_of_upload');
     $chart_type = $this->input->post('chart_type');
     $selected_products = $this->input->post('selected_products');
     $compare_site_id = $this->input->post('compare_site_id');
     $compare_date_of_upload = $this->input->post('compare_date_of_upload');
     /*get sorting params*/
     $sort_by = $this->input->post('sort_by');
     $sort_dir = $this->input->post('sort_dir');
     $all_checked_checkboxes = $this->input->post('all_checked_checkboxes');
     $product_lists = $this->input->post('product_lists');
     $term_arr = array();
     if ($view == '1s1b' && !$term_id && $chart_type == 'on_first_page_chart') {
         $term_arr = $this->ranking_model->getSearchTerms($brand_id);
     }
     /*check sorting params*/
     if ($sort_dir != 'asc') {
         //$sort_dir = 'desc';
     }
     if ($chart_type == 'on_first_page_chart') {
         $view = '1s1t';
     }
     $sort_by = $this->getSortingField($sort_by, $view);
     if (empty($sort_by)) {
         $sort_by = 'rsri.ranking';
     }
     /*Chart pagination vars*/
     $total = 0;
     $limit = 5;
     $page = (int) $this->input->post('page');
     /*End chart pagination vars*/
     $main_search_result = 'ok';
     $count = 0;
     $data = array();
     if ($chart_type == 'on_first_page_chart') {
         if (!$term_id && !empty($term_arr)) {
             $data['multiple_terms'] = array();
             foreach ($term_arr as $term) {
                 $result = $this->ranking_model->getRankingByTerm($site_id, $date_of_upload, $term->search_term_id, $sort_by, $sort_dir, true);
                 $data_prepared = $this->ranking_model->prepareOnFirstPageRanking($result);
                 $data['multiple_terms'][$term->title] = $data_prepared;
                 if (empty($data_prepared)) {
                     $count++;
                 }
             }
             if ($count == count($term_arr)) {
                 $main_search_result = '0';
             }
         } elseif ($term_id) {
             if (is_array($date_of_upload)) {
                 $date_of_upload = $date_of_upload[0];
             }
             if (!empty($group_id)) {
                 $result = $this->ranking_model->getRankingByTerm($site_id, $date_of_upload, $term_id, $sort_by, $sort_dir, false, $group_id);
             } else {
                 $result = $this->ranking_model->getRankingByTerm($site_id, $date_of_upload, $term_id, $sort_by, $sort_dir, true);
             }
             $data = $this->ranking_model->prepareOnFirstPageRanking($result);
         } else {
             $data = $this->ranking_model->getOnFirstPageRanking($site_id, $date_of_upload, $term_id, $sort_by, $sort_dir, true);
         }
     } elseif ($chart_type == 'product_rankings_chart' && is_array($date_of_upload) && count($date_of_upload) > 1) {
         foreach ($selected_products as &$prod) {
             $prod = str_replace('& ', '&amp; ', $prod);
         }
         if (empty($selected_products)) {
             $offset = $page * $limit;
             $offset_product_names = $this->ranking_model->getChartLimitProductNames($site_id, $date_of_upload, $brand_id, $term_id, $limit, $offset);
             foreach ($offset_product_names as $name) {
                 $selected_products[] = $name->title;
             }
             $total = $this->ranking_model->getChartProductNamesTotal($site_id, $date_of_upload, $brand_id, $term_id);
         }
         $res = $this->ranking_model->getRankingInfoForCharts($selected_products, $date_of_upload, $brand_id, $term_id, $site_id);
         /*sorting received data*/
         foreach ($res as $val) {
             if (!array_key_exists($val->title, $data)) {
                 $data[$val->title] = array();
             }
             $data[$val->title][$val->date_of_upload] = $val->ranking;
         }
         /*checking for all dates data was selected*/
         /*foreach($data as &$dval){
         		foreach($date_of_upload as $date){
         		if(!isset($dval[$date])){
         		$dval[$date] = 0;
         		}
         		}
         		ksort($dval);
         		}*/
     } elseif ($chart_type == 'product_name_view_chart') {
         $pnv_chart_view = $this->input->post('pnv_chart_view');
         if (!empty($date_of_upload) && is_array($date_of_upload)) {
             $data = array();
             if (count($date_of_upload) > 1) {
                 foreach ($date_of_upload as $date) {
                     $res = $this->ranking_model->getQueryProductMatch($site_id, $date, $term_id, $brand_id, $pnv_chart_view);
                     if ($res == '0') {
                         $main_search_result = '0';
                     } else {
                         $data[$date] = $res;
                     }
                 }
             } else {
                 $res = $this->ranking_model->getQueryProductMatch($site_id, $date_of_upload, $term_id, $brand_id, $pnv_chart_view);
                 if ($res == '0') {
                     $main_search_result = '0';
                 } else {
                     $data = $res;
                 }
             }
         } else {
             $res = $this->ranking_model->getQueryProductMatch($site_id, $date_of_upload, $term_id, $brand_id, $pnv_chart_view);
             if ($res == '0') {
                 $main_search_result = '0';
             } else {
                 $data = $res;
             }
         }
     } elseif ($chart_type == 'summary_view_chart') {
         $brand_res = array();
         $brand_res_by_site = array();
         $categories = array();
         foreach ($all_checked_checkboxes as $key => $value) {
             if (!array_key_exists('id', $value)) {
                 unset($all_checked_checkboxes[$key]);
             }
         }
         $all_results_for_body = array('brands' => array(), 'terms' => array());
         foreach ($all_checked_checkboxes as $key => $value) {
             $curr_group_terms = $this->ranking_model->getTermsIdsByGroupId($key);
             $current_group_ids = array();
             foreach ($curr_group_terms as $term) {
                 if (in_array($term->id, $term_id)) {
                     $current_group_ids[] = $term->id;
                 }
             }
             $gr_id = $key;
             if (!empty($value['id'])) {
                 $curr_group_terms_count = 0;
                 if (!is_array($site_id)) {
                     $site_id = array($site_id);
                 }
                 foreach ($site_id as $site) {
                     $site_obj = $this->sites_model->getSite($site);
                     if (!empty($site_obj[0])) {
                         $site_obj = $site_obj[0];
                     }
                     $tmp_all_results_for_body = array();
                     $data_prepared = $this->ranking_model->getProductsByTerm($site, $date_of_upload, $current_group_ids, 'rsri.ranking', 'asc', $brand_id);
                     $curr_group_terms_count = Ranking_model::get_ofp_total_count($data_prepared, $tmp_all_results_for_body);
                     if (!empty($site_obj['name']) && !array_key_exists($site_obj['name'], $brand_res_by_site)) {
                         $brand_res_by_site[$site_obj['name']] = array();
                     }
                     if (!empty($tmp_all_results_for_body['brands'])) {
                         foreach ($tmp_all_results_for_body['brands'] as $key => $arfb) {
                             if (!array_key_exists($key, $all_results_for_body['brands'])) {
                                 $all_results_for_body['brands'][$key] = 0;
                             }
                             $all_results_for_body['brands'][$key] += $arfb;
                             if (!array_key_exists($key, $brand_res_by_site[$site_obj['name']])) {
                                 $brand_res_by_site[$site_obj['name']][$key] = 0;
                             }
                             $brand_res_by_site[$site_obj['name']][$key] += $arfb;
                         }
                     }
                 }
             }
         }
         $column_data = array();
         $brands_count_by_site = array();
         $brand_res = array();
         if (!empty($brand_id)) {
             foreach ($brand_id as $bid) {
                 $brand = $this->ranking_model->getBrandNameByBrandId($bid);
                 if (!empty($brand->name)) {
                     if (array_key_exists($brand->name, $all_results_for_body['brands'])) {
                         $brand_res[] = array($brand->name, $all_results_for_body['brands'][$brand->name]);
                         unset($all_results_for_body['brands'][$brand->name]);
                     } else {
                         $brand_res[] = array($brand->name, 0);
                     }
                     foreach ($site_id as $site) {
                         $site_obj = $this->sites_model->getSite($site);
                         if (!empty($site_obj[0])) {
                             $site_obj = $site_obj[0];
                         }
                         if (!empty($site_obj['name']) && !in_array($site_obj['name'], $categories)) {
                             $categories[] = $site_obj['name'];
                         }
                         if (!array_key_exists($brand->name, $column_data)) {
                             $column_data[$brand->name] = array();
                         }
                         if (!empty($brand_res_by_site[$site_obj['name']][$brand->name])) {
                             $column_data[$brand->name][] = $brand_res_by_site[$site_obj['name']][$brand->name];
                         } else {
                             $column_data[$brand->name][] = 0;
                         }
                         //count all products on first page by site
                         if (!array_key_exists($site_obj['name'], $brands_count_by_site)) {
                             $brands_count_by_site[$site_obj['name']] = 0;
                         }
                         if (!empty($brand_res_by_site[$site_obj['name']][$brand->name])) {
                             $brands_count_by_site[$site_obj['name']] += $brand_res_by_site[$site_obj['name']][$brand->name];
                         }
                     }
                 }
             }
             if ($this->reportsettings->getSetting('1ssv_sort', 'isEnabledOther')) {
                 //Count other values
                 $sum_other_count = 0;
                 $column_data['Other'] = array();
                 if (!empty($site_id)) {
                     foreach ($site_id as $siteId) {
                         /**
                          * For now this is the fastest solution to fix swap bug.
                          * In future there should be site validation and common function that will return sites
                          * in normal order.
                          */
                         $site = $this->sites_model->getSite($siteId);
                         //No comments... Why people use result_array() instead of row_array() ?!!!!
                         $site = array_shift($site);
                         $possible_spot = 0;
                         foreach ($term_id as $cur_term) {
                             $possible_spot += $this->ranking_model->getOfpCountByTerm($site['id'], $date_of_upload, $cur_term);
                         }
                         $brands_count = !empty($brands_count_by_site[$site['name']]) ? $brands_count_by_site[$site['name']] : 0;
                         $other_count = $possible_spot - $brands_count;
                         $column_data['Other'][] = $other_count;
                         $sum_other_count += $other_count;
                     }
                 }
                 $brand_res[] = array('Other', $sum_other_count);
             }
         }
         $data['brand_res'] = $brand_res;
         $data['categories'] = $categories;
         $data['column_data'] = $column_data;
         if (empty($brand_res)) {
             $main_search_result = '0';
         } else {
             $total = 1;
         }
     } elseif ($chart_type == 'pricing_view_chart') {
         $data = array();
         $total = 1;
         foreach ($date_of_upload as $date) {
             $data[$date] = array();
             $data[$date]['date_str'] = date('F j, Y', strtotime($date));
             $categories = array();
             $series = array();
             $data_prepared = array();
             $userData = array('sites' => array());
             $currencies = array();
             if (!empty($site_id) && count($site_id) > 1) {
                 foreach ($site_id as $site) {
                     $titles_list = $this->ranking_model->getAssociatedProductsByParams($site, $date, $term_id, $brand_id, $product_lists, $sort_by, $sort_dir, $selected_products);
                     $site_obj = $this->sites_model->getSite($site);
                     if (!empty($site_obj[0])) {
                         $site_obj = $site_obj[0];
                     }
                     if (!empty($site_obj['name']) && !in_array($site_obj['name'], $categories)) {
                         $categories[] = $site_obj['name'];
                         $img = Ranking_model::getSiteLogoByName($site_obj['name']);
                         $site_logo = '';
                         if (!empty($img)) {
                             $site_logo = base_url('/img/site_logos/' . $img);
                         }
                         $userData['sites'][$site_obj['name']] = $site_logo;
                         foreach ($titles_list as $product) {
                             if (!empty($product->title) && !array_key_exists($product->title, $data_prepared)) {
                                 $data_prepared[$product->title] = array();
                                 $data_prepared[$product->title]['name'] = $product->title;
                                 $data_prepared[$product->title]['data'] = array();
                             }
                             if (!array_key_exists($site_obj['name'], $data_prepared[$product->title]['data'][$site_obj['name']])) {
                                 $data_prepared[$product->title]['data'][$site_obj['name']] = $product;
                             }
                             $associatedProducts = $this->ranking_model->getAssociatedProducts($product);
                             if (!empty($associatedProducts)) {
                                 $data_prepared[$product->title]['data'] = array_merge($data_prepared[$product->title]['data'], $associatedProducts);
                             }
                         }
                     }
                 }
             }
             $series_count = 0;
             foreach ($data_prepared as $dp) {
                 $series[$series_count] = array('name' => $dp['name'], 'data' => array());
                 foreach ($categories as $key => $category) {
                     if (!empty($dp['data'][$category])) {
                         $series[$series_count]['data'][$key]['y'] = (double) $dp['data'][$category]->price;
                         $series[$series_count]['data'][$key]['image_url'] = $dp['data'][$category]->image_url;
                         $currency_symbol = Ranking_model::getCurrencySymbol($dp['data'][$category]->currency);
                         if (empty($currency_symbol)) {
                             $currency_symbol = '$';
                         }
                         if (!in_array($currency_symbol, $currencies)) {
                             $currencies[] = $currency_symbol;
                         }
                         $series[$series_count]['data'][$key]['currency_symbol'] = $currency_symbol;
                     } else {
                         $series[$series_count]['data'][$key] = array('y' => 0, 'image_url' => '');
                     }
                 }
                 ++$series_count;
             }
             $userData['currency_str'] = !empty($currencies) ? implode('/', $currencies) : '$';
             $userData['counts'] = $series_count * count($site_id);
             $data[$date]['categories'] = $categories;
             $data[$date]['series'] = $series;
             $data[$date]['userData'] = $userData;
         }
     }
     if (empty($data) || $total == 0) {
         $main_search_result = '0';
     }
     $this->output->set_content_type('application/json')->set_output(json_encode(array('result' => $main_search_result, 'data' => $data, 'date_of_upload' => $date_of_upload, 'total' => $total, 'page' => $page)));
 }
 /**
  * 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)));
 }