private function _default_report() { $this->data->report_name = ''; $this->data->report_type = $this->data->my = 'pricingviolation'; $this->data->icon = 'ico-report'; $this->data->widget = 'mv-report'; $this->data->displayBookmark = true; //almost all of the controller functions use the same basic data $this->data->report_chart = NULL; $this->data->Data = NULL; $this->data->graphDataType = 'chart'; $this->data->products = $this->data->productNames = $this->data->merchants = $this->data->markets = $this->data->proMerchants = array(); $this->data->markertArr = getMarketArray(); $this->data->marketplaceArr = getMarketplaceArray(); $this->data->retailerArr = getRetailerArray(false, $this->store_id); $this->data->all_markets = (bool) $this->input->post('all_markets'); $this->data->all_retailers = ((bool) $this->input->post('all_retailers') and !empty($this->subscriber_retailer_addons)); $this->data->show_comparison = (bool) $this->input->post('show_comparison'); $this->submit = $this->input->post('formSubmit'); $this->data->report_where = array(); if ($this->submit) { $this->data->report = $this->input->post('report'); $this->data->date_from = $this->input->post('date_from'); $this->data->date_to = $this->input->post('date_to'); $this->data->time_frame = $this->input->post('time_frame'); $this->data->merchants = $this->input->post('merchants'); $this->data->markets = $this->input->post('markets'); $this->data->flagDates24 = $this->data->date_from == $this->data->date_to ? true : false; $this->data->report_chart = 'scatter'; $this->data->graphImageName = ''; $this->data->productNames = array(); if ($this->input->post('product_name')) { $this->data->productNames = $this->input->post('product_name'); } $this->data->products = array(); if ($this->input->post('products')) { $this->data->products = $this->input->post('products'); } elseif ($this->input->post('group_id')) { $this->data->selected_group_id = $this->input->post('group_id'); $this->data->product_groups = $this->Product->getGroups($this->store_id); $group_prods = $this->Product->getProductsByGroupId((int) $this->input->post('group_id')); if (!empty($group_prods)) { foreach ($group_prods as $prod) { $prod = $this->Product->getProductsByID($this->store_id, $prod['product_id']); $this->data->products[] = $prod[0]['id']; $this->data->productNames[] = $prod[0]['title']; } } } } $this->data->noRecord = $this->config->item('no_record'); //log_message('info', 'violations data: '. print_r($this->data,true)); $this->_prep_report(); }
/** * * @todo fix this function so that it always returns one data type - Chris (??) * @author unknown, Chris * @param unknown_type $type * @param unknown_type $days * @return multitype:unknown */ public function last_crawl($type = 'all', $days = 2) { $date = date('Y-m-d', strtotime("-{$days} days")); // from midnight so we can cache result $ret = array(); switch ($type) { // warning: returns array case 'all-deprecated': $types = array_to_lower(getMarketArray(TRUE)); foreach ($types as $t) { $res = $this->last_crawl($t); if (!empty($res)) { $ret[$t] = $res; } } break; // make this more performant, using IN() statement and RAM cache // make this more performant, using IN() statement and RAM cache case 'all': if ($this->last_crawl_cache_all_flag) { $ret = $this->last_crawl_cache; } else { if (!empty($this->store_id)) { $types = get_marketplaces_by_storeid_using_categories($this->store_id); $api_list = "'" . implode("','", $types) . "'"; } else { $api_list = "SELECT distinct name FROM marketplaces where is_active='1'"; } // SQL_CACHE and SQL_NO_CACHE in subquery are no longer permitted in MySQL 5.5.3 // http://stackoverflow.com/questions/24320137/mysql-syntax-error-after-upgrade $sql = "select SQL_CACHE x.* \n\t\t\t\t\t\tfrom (\n\t\t\t\t\t\t SELECT c.id, c.api_type, c.start_datetime, c.end_datetime\n\t\t\t\t\t\t\tFROM cron_log c\n\t\t\t\t\t\t\tWHERE c.api_type is not null\n\t\t\t\t\t\t\tAND\tc.start_datetime > '{$date}'\n\t\t\t\t\t\t\tAND c.api_type IN ({$api_list})\n\t\t\t\t\t\t\tAND c.tasks = ''\n\t\t\t\t\t\t\tORDER BY c.end_datetime desc, c.api_type\n\t\t\t\t\t\t) x\n\t\t\t\t\t\tGROUP BY x.api_type \n\t\t\t\t\t"; $cron_logs = $this->db->query($sql)->result_object(); foreach ($cron_logs as $t) { $ret[$t->api_type] = $t; } $this->last_crawl_cache = $ret; $this->last_crawl_cache_flag = TRUE; } break; // warning: returns object // warning: returns object default: if (isset($this->last_crawl_cache[$type])) { $ret = $this->last_crawl_cache[$type]; } else { $sql = "SELECT SQL_CACHE\n\t\t\t\t\t\t\t\tid, start_datetime, end_datetime, api_type\n\t\t\t\t\t\t\tFROM\n\t\t\t\t\t\t\t\t{$this->_table_cron_log}\n\t\t\t\t\t\t\tWHERE\n\t\t\t\t\t\t\t\tapi_type=?\n\t\t\t\t\t\t AND tasks = ''\n\t\t\t\t\t\t AND start_datetime > '{$date}'\n\t\t\t\t\t\t\tORDER BY\n\t\t\t\t\t\t\t\tdatetime desc\n\t\t\t\t\t\t\tLIMIT 1"; $variables = array($type); $ret = $this->db->query($sql, $variables)->row(); $this->last_crawl_cache[$type] = $ret; } } return $ret; }
private function _prep_violation_overview() { $this->data->my = 'violationoverview'; $this->data->report_chart = 'na'; // Get the last crawl data $this->data->last_crawl = $this->crawl_data_m->last_crawl(); $this->crawl_range = $this->crawl_data_m->last_crawl_range(); // Get market/merchant/product violations $this->data->priceViolators = $this->Violator->_countPriceViolations(); foreach ($this->data->priceViolators as $id => $vals) { $crowl_merchant = $this->merchant_products_m->getMerchantDetailsById($id); $this->data->priceViolators[$id]['crowl_merchant'] = $crowl_merchant; } $this->data->violatedProducts = $this->Violator->getViolatedProducts($this->report_info->store_id); // Calculate the overview statistics $this->data->products_monitored = $this->Product->getProductsMonitoredCount($this->report_info->store_id); $this->data->total_violations = count($this->data->violatedProducts); $this->data->marketplace_products = array(); $this->data->market_violations = array(); $markets = array_to_lower(getMarketArray()); foreach ($markets as $market) { $crawl_info = !empty($this->data->last_crawl[$market]) ? $this->data->last_crawl[$market] : FALSE; if ($crawl_info) { $from = $crawl_info->start_datetime; $to = $crawl_info->end_datetime; $marketplace_products = $this->merchant_products_m->getCountByMarketplace($this->report_info->store_id, $market, $from, $to); if (!empty($marketplace_products)) { $market_violations = $this->Violator->getViolatedMarkets($this->report_info->store_id, '', $market, $from, $to); $this->data->marketplace_products[] = $marketplace_products[0]; $this->data->market_violations[$market] = $market_violations[$market]; } } } $this->data->request_info = array('fromDate' => strtotime($this->crawl_range['from']), 'toDate' => strtotime($this->crawl_range['to']), 'time_frame' => 1, 'product_ids' => array()); $this->data->gData = array('type' => 'pie', 'width' => '220', 'height' => '150', 'googleData' => array(array('State', 'Count'), array('Non Violation', (int) max($this->data->products_monitored - $this->data->total_violations, 0)), array('Violation', (int) $this->data->total_violations))); // Separate marketplaces from retailers $this->data->marketplaces = array(); $this->data->retailers = array(); $this->data->violatedMarketplaces = array(); $this->data->violatedRetailers = array(); for ($i = 0, $n = count($this->data->marketplace_products); $i < $n; $i++) { $name = $this->data->marketplace_products[$i]['marketplace']; if ($this->data->marketplace_products[$i]['is_retailer'] === '1') { $merchant = $this->merchant_products_m->getMerchantDetailsByMarketplace($this->data->marketplace_products[$i]['marketplace']); if (isset($merchant[0]['id'])) { $this->data->retailers[] = $this->data->marketplace_products[$i]; $this->data->marketplace_products[$i] = array_merge($this->data->marketplace_products[$i], $merchant[0]); if (!empty($this->data->market_violations[$name])) { $this->data->violatedRetailers[$name] = TRUE; } } } else { $this->data->marketplaces[] = $this->data->marketplace_products[$i]; if (!empty($this->data->market_violations[$name])) { $this->data->violatedMarketplaces[$name] = TRUE; } } } // variable instantiation is out of sequence. We ensure it here. // TODO: refactor? $this->data->Data->violatedMarketplaces = $this->data->market_violations; $this->data->Data->violatedRetailers = $this->data->violatedRetailers; $this->data->Data->priceViolators = $this->data->priceViolators; $this->data->Data->violatedProducts = $this->data->violatedProducts; $this->data->Data->retailers = $this->data->retailers; $this->data->Data->marketplaces = $this->data->marketplaces; $this->data->Data->market_violations = $this->data->market_violations; }
/** * * @author unknown * @param unknown_type $id * @param unknown_type $whois_switch */ private function setDefaultValues($id = 0, $whois_switch = 'marketplace') { $this->session->set_userdata("report_type", "whois"); $this->data->productArr = getProductsDrp($this->store_id); $this->data->proMerchants = getProductMerchant($this->store_id); $this->data->markertArr = getMarketArray(); $this->data->is_report = false; $this->data->report = 'default'; $this->data->is_post = false; $this->data->my = "whois"; $this->data->merchantReport = ''; $this->data->report_id = 0; $this->data->date_from = 'Start'; $this->data->date_to = 'Stop'; $this->data->time_frame = ''; $this->data->products_ids = $this->data->markets = $this->data->merchants = array(); $this->data->whoisSwitch = $whois_switch; if ($id == 0) { $post = array('report_type' => 'whois', 'report' => 'default', 'date_from' => 'Start', 'date_to' => 'Stop', 'time_frame' => '', 'products_ids' => array(), 'merchants' => array(), 'markets' => array(), 'whoisSwitch' => $whois_switch); $data = $this->input->post_default($post); foreach ($data as $key => $value) { $this->data->{$key} = $value; } } else { $this->data->report_id = $id; $this->data->report_info = $this->Report->get_save_report_by_id($id); $report_where = json_decode($this->data->report_info['report_where'], true); if (!empty($report_where)) { foreach ($report_where as $key => $value) { $this->data->{$key} = $value; } } if ($this->data->date_from !== 'Start') { $this->data->date_from = date('Y-m-d', $this->data->date_from); } if ($this->data->date_to !== 'Stop') { $this->data->date_to = date('Y-m-d', $this->data->date_to); } } $this->data->marketplace_keys = array(); $tempProducts = array(); if (!empty($this->data->products_ids)) { foreach ($this->data->products_ids as $indexKey => $nV) { if ($nV == '') { unset($this->data->products_ids[$indexKey]); } else { $tempProducts[] = $nV; } } $this->data->is_post = true; } $this->data->product_ids = $tempProducts; $this->data->product_data = array(); $this->data->report_where = array('date_from' => $this->data->date_from, 'date_to' => $this->data->date_to, 'api_type' => empty($this->data->api_type) ? array('all') : $this->data->api_type, 'product_ids' => $this->data->product_ids, 'merchants' => $this->data->merchants, 'time_frame' => 1, 'report_type' => $this->data->report_type, 'cron_ids' => array(), 'whoisSwitch' => $this->data->whoisSwitch, 'isoverview' => true, 'is_retailer' => false); }