Exemplo n.º 1
0
 protected function standardize()
 {
     $CI =& get_instance();
     $this->store_id = $CI->store_id;
     $CI->load->model('crawl_data_m', 'Crawl');
     $this->merchants = ensure_array($this->merchants);
     $this->api_type = ensure_array($this->api_type);
     $this->flagDates24 = $this->date_from === $this->date_to;
     // get the last crawl data
     $this->last_crawl = $CI->Crawl->last_crawl();
     $this->crawl_range = $CI->Crawl->last_crawl_range();
     if ($this->time_frame) {
         // This report's dates are the last x many days
         $tF = getTimeFrame($this->time_frame);
         $this->date_from = $tF['date_from'];
         $this->date_to = $tF['date_to'];
     }
     switch ($this->report_type) {
         case 'violationoverview':
             $this->time_frame = 24;
             break;
         case 'pricingoverview':
             $this->time_frame = 24;
             break;
         case 'pricingviolation':
             break;
         case 'whois':
             break;
     }
     $this->set_filename();
 }
Exemplo n.º 2
0
 protected function _prep_report()
 {
     if ($this->submit) {
         if (!empty($this->data->products[0])) {
             $this->data->competitor_store_id = false;
             if ($this->data->report === 'bycompetition') {
                 // this is a competitor's product
                 $this->data->competitor_products = $this->Product->getProductsById(null, $this->data->products);
                 $this->data->competitor_store_id = array();
                 for ($i = 0, $n = count($this->data->competitor_products); $i < $n; $i++) {
                     $this->data->competitor_store_id[] = $this->data->competitor_products[$i]['store_id'];
                 }
                 $this->data->competitor_store_id = array_unique($this->data->competitor_store_id);
                 $this->data->proMerchants = getProductMerchant($this->data->competitor_store_id);
                 if ($this->data->show_comparison) {
                     // and it's a comparison
                     $competitor_map = $this->Store->getCompetitorMap($this->store_id, $this->data->products);
                     $this->data->competitor_store_id[] = $this->store_id;
                     $products_wo_comparisons = $this->data->products;
                     $this->data->competitor_map = array();
                     foreach ($competitor_map as $bpp) {
                         $this->data->products[] = $bpp['owner_brand_product'];
                         $owned_product = $this->Product->getProductsById(null, $bpp['owner_brand_product']);
                         if (!empty($owned_product[0]['id'])) {
                             $this->data->competitor_map[$bpp['competitor_brand_product']] = $owned_product[0];
                         }
                     }
                     $products_w_comparisons = $this->data->products;
                 }
             }
         }
         if ($this->data->date_from !== 'Start' && $this->data->date_to !== 'Stop') {
             // TODO: set this to last crawl?
             $this->data->date_from = strtotime($this->data->date_from . " 00:00:00");
             $this->data->date_to = strtotime($this->data->date_to . " 23:59:59");
         } else {
             $tF = getTimeFrame($this->data->time_frame);
             $this->data->date_from = $tF['date_from'];
             $this->data->date_to = $tF['date_to'];
         }
         //			$lookup_markets = $this->data->markets;
         //			if ( ! $this->data->all_markets AND $this->data->all_retailers)
         //				$lookup_markets = array_merge($lookup_markets, $this->data->retailerArr);
         //			elseif ( ! $this->data->all_retailers AND $this->data->all_markets)
         //				$lookup_markets = array_merge($lookup_markets, $this->data->marketplaceArr);
         $lookup_markets = array_merge($this->data->marketplaceArr, $this->data->retailerArr);
         $this->data->report_where = array('report_type' => $this->data->report_type, 'api_type' => $lookup_markets, 'time_frame' => $this->data->time_frame, 'date_from' => $this->data->date_from, 'date_to' => $this->data->date_to, 'cron_ids' => '', 'product_ids' => $this->data->products, 'merchants' => $this->data->merchants, 'store_id' => $this->store_id, 'competitor_store_id' => $this->data->competitor_store_id, 'violation' => true);
         //get cronIds for 24 hour scatter
         if ($this->data->time_frame == 24 || $this->data->flagDates24) {
             $this->data->report_where['cron_ids'] = getLast24HoursCronIds($this->data->flagDates24 ? $this->data->date_from : '', '', $this->data->report_where['api_type']);
         }
         $response = $this->Violations->searchProductPricingViolations($this->data->report_where);
         //log_message('info', '_prep_report violation bymerchant data: '. print_r($response,true));
         $this->data->Data = $response;
         $this->data->gData = $this->Chart->prepGoogleData($response, $this->data->report_where, $this->data->report_chart);
     }
     if ($this->data->show_comparison and isset($products_wo_comparisons)) {
         // don't populate product fields with the compared
         $this->data->products = $products_wo_comparisons;
     }
     $this->data->searchProducts = array();
     for ($i = 0, $n = sizeof($this->data->products); $i < $n; $i++) {
         $this->data->searchProducts[$this->data->products[$i]] = $this->data->productNames[$i];
     }
     //display data
     $this->data->dateStartField = !$this->submit || $this->submit && $this->data->time_frame != '' ? 'Start' : $this->data->date_from;
     $this->data->dateEndField = !$this->submit || $this->submit && $this->data->time_frame != '' ? 'Stop' : $this->data->date_to;
     $this->data->time_frame = $this->submit ? $this->data->time_frame : '';
     $this->data->submitted = (bool) $this->submit;
     //
     // Set retailer/marketplace information
     //
     $this->data->marketRetailer = array();
     $this->data->retailersExist = array();
     $this->data->marketplacesExist = array();
     if ($this->data->report_chart === 'scatter') {
         foreach ($this->data->Data as $prodId => $productData) {
             for ($i = 0, $n = count($productData); $i < $n; $i++) {
                 $marketName = strtolower($productData[$i]['marketplace']);
                 if (!isset($this->data->marketRetailer[$marketName])) {
                     $this->data->marketRetailer[$marketName] = $this->Marketplace->is_retailer($marketName);
                 }
                 if ($this->data->marketRetailer[$marketName]) {
                     $this->data->retailersExist[$prodId] = true;
                 } else {
                     $this->data->marketplacesExist[$prodId] = true;
                 }
             }
         }
     }
     //
     // Set up map between competitor product data and user product data
     //
     $this->data->comparison_data = array();
     if ($this->data->show_comparison) {
         $color_index = 0;
         $this->data->color_index = array();
         if (!empty($this->data->competitor_map)) {
             //
             // If this is a scatter chart we need to add the crawl id for all the data
             //
             if ($this->data->report_chart === 'scatter') {
                 foreach ($this->data->Data as $prodId => $productData) {
                     for ($i = 0, $n = count($productData); $i < $n; $i++) {
                         if (isset($productData[$i]['marketplace'])) {
                             $api_type = explode('.', $productData[$i]['marketplace']);
                             $api_type = $api_type[0];
                             $crawl = $this->Crawl->get_crawl_by_time($productData[$i]['timestamp'], $api_type, 'id');
                             $this->data->Data[$prodId][$i]['crawl_id'] = isset($crawl['id']) ? $crawl['id'] : false;
                         }
                     }
                 }
             }
             //
             // Now loop through and set the comparison data
             //
             foreach ($products_w_comparisons as $prodId) {
                 $this->data->color_index[$prodId] = $color_index++;
                 //
                 // Check if this competitor product is associated with user product
                 //
                 $comparison_id = false;
                 if (isset($this->data->competitor_map[$prodId])) {
                     $comparison_id = $this->data->competitor_map[$prodId]['id'];
                 }
                 if ($comparison_id and isset($this->data->Data[$comparison_id])) {
                     $comparison_data = $this->data->Data[$comparison_id];
                     //
                     // Map values via productid->marketplace->crawltime
                     //
                     if (!empty($comparison_data)) {
                         if ($this->data->report_chart === 'line') {
                             foreach ($comparison_data as $market => $market_prod_data) {
                                 for ($i = 0, $n = count($market_prod_data); $i < $n; $i++) {
                                     if (isset($market_prod_data[$i]['dt'])) {
                                         $this->data->comparison_data[$prodId][$market][$market_prod_data[$i]['dt']] = $market_prod_data[$i];
                                     }
                                 }
                             }
                         } elseif ($this->data->report_chart === 'scatter') {
                             for ($i = 0, $n = count($comparison_data); $i < $n; $i++) {
                                 if (isset($comparison_data[$i]['marketplace'])) {
                                     $market = strtolower($comparison_data[$i]['marketplace']);
                                     $merchant_id = $comparison_data[$i]['merchant_id'];
                                     $crawl_id = $comparison_data[$i]['crawl_id'];
                                     $this->data->comparison_data[$prodId][$market][$crawl_id][$merchant_id] = $comparison_data[$i];
                                 }
                             }
                         }
                     }
                     unset($this->data->Data[$comparison_id]);
                 }
             }
         }
     }
     //log_message('info', '_prep_report final data: '. print_r($this->data,true));
 }
Exemplo n.º 3
0
function get24ReportTitleAndDate($request_info, $year_format = 'y')
{
    $rptInfo = array('title' => '', 'date' => '');
    $tF = getTimeFrame($request_info['time_frame']);
    $rptInfo['date'] = date('n/j/' . $year_format, $tF['date_from']) . ' - ' . date('n/j/' . $year_format, $tF['date_to']);
    $timeText = 'Last 24 hours ' . date('n/j/' . $year_format . ' h:i:A', $request_info['fromDate']) . ' - ' . date('n/j/' . $year_format . ' h:i:A', $request_info['toDate']);
    $rptInfo['title'] = $request_info['title'] . ' ' . $timeText;
    return $rptInfo;
}
Exemplo n.º 4
0
 function market($market, $prodId, $dateStart, $dateEnd = NULL, $report_type = NULL, $id = false)
 {
     $this->data->by_which = $report_type ? $report_type : 'bymarket';
     $this->data->competitor_store_id = false;
     if ($this->data->by_which === 'bycompetition') {
         // this is a competitor's product
         $this->data->competitor_product = $this->Product->get_by('id', $prodId);
         $this->data->competitor_store_id = $this->data->competitor_product->store_id;
         $this->data->proMerchants = getProductMerchant($this->data->competitor_store_id);
         $lookup_id = $this->data->competitor_store_id;
     } else {
         $lookup_id = $this->store_id;
     }
     $searchProduct = $this->Product->getProductsById($lookup_id, $prodId);
     if (!isset($searchProduct[0])) {
         redirect('reports');
     }
     $this->layout = 'frontend_inner';
     $this->data->time_frame = '24';
     if (!$dateEnd) {
         $this->data->flagDates24 = true;
     }
     $this->data->my = 'productpricing';
     $this->data->productArr = getProductsDrp($this->store_id);
     $this->data->proMerchants = getProductMerchant($this->store_id);
     //$this->data->markertArr = getMarketArray();
     $this->data->product_ids = array($prodId);
     $this->data->searchProducts = array($prodId => $searchProduct[0]['title']);
     $this->data->date_from = $dateStart;
     $this->data->date_to = $dateEnd ? $dateEnd : $dateStart;
     $this->data->submitted = true;
     $this->data->all_markets = false;
     $this->data->all_retailers = false;
     if ($this->data->date_from !== 'Start' && $this->data->date_to !== 'Stop') {
         $this->data->dateStartField = $this->data->date_from;
         $this->data->dateEndField = $this->data->date_to;
         $this->data->date_from = strtotime($this->data->date_from);
         $this->data->date_to = !$dateEnd ? strtotime($this->data->date_to . ' 23:59:59') : strtotime($this->data->date_to);
         $this->data->time_frame = '';
         if ($this->data->date_from == $this->data->date_to) {
             $this->data->flagDates24 = true;
             $this->data->time_frame = '24';
         }
     } else {
         $tF = getTimeFrame($this->data->time_frame);
         $this->data->date_from = $tF['date_from'];
         $this->data->date_to = $tF['date_to'];
     }
     //the saved report Id
     if ($id) {
         $this->data->report_id = $this->input->post('report_id');
     }
     if ($product_name = $this->input->post('product_name')) {
         if (is_array($product_name)) {
             for ($i = 0, $n = sizeof($product_name); $i < $n; $i++) {
                 $this->data->report_name .= $product_name[$i] . ' ';
             }
             $this->data->report_name .= 'Product Pricing';
         }
         $this->data->file_name = str_replace(' ', '_', $this->data->report_name . ' ' . date('Y-m-d'));
         $this->data->productNames = $this->input->post('product_name');
     }
     $this->data->merchants = $this->input->post('merchants') ? $this->input->post('merchants') : array();
     $this->data->markets = array(ucfirst($market));
     $this->data->show_comparison = false;
     $this->data->report_where = array('date_from' => $this->data->date_from, 'date_to' => $this->data->date_to, 'api_type' => $this->data->markets, 'product_ids' => $this->data->product_ids, 'merchants' => $this->data->merchants, 'time_frame' => $this->data->time_frame, 'store_id' => $this->store_id, 'competitor_store_id' => array($this->data->competitor_store_id), 'show_comparison' => $this->data->show_comparison);
     //get cron_ids for 24 hour scatter
     $this->data->report_chart = 'scatter';
     if ($this->data->flagDates24) {
         $this->data->report_where['cron_ids'] = getLast24HoursCronIds($this->data->date_from, '', $this->data->report_where['api_type']);
     } else {
         $this->data->report_where['cron_ids'] = getLast24HoursCronIds('', '', $this->data->report_where['api_type']);
     }
     $response = $this->Report->productPricingReport24($this->data->report_where);
     $this->data->Data = $response['data'];
     $this->data->gData = $this->Chart->prepGoogleData($response['data'], $this->data->report_where, $this->data->report_chart);
     $this->data->submitted = true;
     $this->session->set_userdata('report_where', $this->data->report_where);
     $this->data->graphDataType = 'chart';
     //
     // Set retailer/marketplace information
     //
     $this->data->marketRetailer = array();
     $this->data->retailersExist = array();
     $this->data->marketplacesExist = array();
     if ($this->data->report_chart === 'line') {
         foreach ($this->data->Data as $prodId => $marketArr) {
             foreach ($marketArr as $marketName => $productData) {
                 if (!isset($this->data->marketRetailer[$marketName])) {
                     $this->data->marketRetailer[$marketName] = $this->Marketplace->is_retailer($marketName);
                 }
                 if ($this->data->marketRetailer[$marketName]) {
                     $this->data->retailersExist[$prodId] = true;
                 } else {
                     $this->data->marketplacesExist[$prodId] = true;
                 }
             }
         }
     } elseif ($this->data->report_chart === 'scatter') {
         foreach ($this->data->Data as $prodId => $productData) {
             for ($i = 0, $n = count($productData); $i < $n; $i++) {
                 $marketName = strtolower($productData[$i]['marketplace']);
                 if (!isset($this->data->marketRetailer[$marketName])) {
                     $this->data->marketRetailer[$marketName] = $this->Marketplace->is_retailer($marketName);
                 }
                 if ($this->data->marketRetailer[$marketName]) {
                     $this->data->retailersExist[$prodId] = true;
                 } else {
                     $this->data->marketplacesExist[$prodId] = true;
                 }
             }
         }
     }
     $this->_build_options_array($this->data->by_which);
     //$this->data->headerHTML = $this->load->view("front/reports_new_header", $this->data, true);
 }