Example #1
0
 private function calcTextBlob($result_row = array(), $filterConfigValue, $suffix = '')
 {
     $pattern = '/<(div|p|ul|ol|li|address|blockquote|center|form|h1|h2|h3|h4|h5|h6|hr|pre|[\\n\\r]|(br ?\\/?))+>/';
     if (!empty($suffix)) {
         $longDesc = preg_replace($pattern, "\n", $result_row->long_description1);
     } else {
         $longDesc = preg_replace($pattern, "\n", $result_row->long_description);
     }
     $paragraphs = preg_split('/[\\n]+/', $longDesc);
     $this->load->helper('functions');
     foreach ($paragraphs as $paragraph) {
         $words = count_words_in_html($paragraph);
         if ($words[1] > $filterConfigValue->config) {
             $this->filterBySummaryCriteria('skus_more_100_product_content' . $suffix);
             $result_row->{'text_blob' . ($suffix == '' ? '' : '1')} = true;
             return true;
         }
     }
     $result_row->{'text_blob' . ($suffix == '' ? '' : '1')} = false;
 }
 /**
  * Calculate and insert stats data to statistics_new table
  */
 public function do_stat_create($data_arr, $additionalSimilar = 0)
 {
     if (!$this->sitesList) {
         $this->sitesList = $this->getSiteList();
     }
     $this->CI->load->model('customers_model');
     $this->CI->load->model('ranking_model');
     $this->CI->load->model('statistics_new_model');
     if (!$this->customersList) {
         $this->customersList = $this->CI->customers_model->getCustomersList();
     }
     $this->CI->load->helper('functions');
     //end of list creating script
     $usedBatches = array();
     //Start analize each item
     $ins = array();
     $rm = array();
     foreach ($data_arr as $obj) {
         $obj = array_to_object($obj);
         $batch_id = isset($obj->batch_id) && $obj->batch_id ? $obj->batch_id : 0;
         //Prepare description field
         // Calculate the number of words in the short description of the product
         list($short_description, $short_description_wc) = count_words_in_html($obj->description);
         // Calculate the number of words in the long description of the product
         list($long_description, $long_description_wc) = count_words_in_html($obj->long_description);
         //Prepare manufacturer info
         $manufacturerInfo = '';
         if (!empty($obj->manufacturer_url)) {
             $manufacturerInfo = serialize(array('url' => $obj->manufacturer_url, 'images' => $obj->manufacturer_images, 'videos' => $obj->manufacturer_videos));
         }
         // Generate Title Keywords
         $title_keywords = $this->title_keywords($obj->product_name, $short_description, $long_description);
         $ranking = $title_keywords ? $this->keywordsRanking($title_keywords, $obj->url) : array('keyword_rankings' => '', 'keyword_rankings_with_keywords' => '');
         //If parsed attributes are exist, finding similar items and price diff
         $sm_prod_price = $this->getSimilarProductsAndPrices($obj, $this->sitesList, $this->customersList, $additionalSimilar);
         $items_priced_higher_than_competitors = $sm_prod_price['items_priced_higher_than_competitors'];
         $own_price = $sm_prod_price['own_price'];
         $competitors_prices = $sm_prod_price['competitors_prices'];
         $price_diff = $sm_prod_price['price_diff'];
         $similar_products_competitors = $sm_prod_price['similar_products_competitors'];
         //WC Short
         if ($batch_id) {
             $research_and_batch_ids = array('research_data_id' => $obj->research_data_id, 'batch_id' => $batch_id, 'category_id' => $obj->category_id, 'category_new_id' => $obj->category_new_id, 'brand_id' => $obj->brand_id);
         } else {
             $rdandbatchesres = $this->getResearchDataAndBatchID($obj, 0, $usedBatches);
             $research_and_batch_ids = $rdandbatchesres['research_and_batch_ids'];
             $usedBatches = $rdandbatchesres['usedBatches'];
         }
         $page_score = $this->getPageScore($obj, $title_keywords, $short_description_wc + $long_description_wc);
         if (!in_array($obj->imported_data_id, $rm[$batch_id])) {
             $ins[] = $this->CI->statistics_new_model->prepareStatistic(array('imported_data_id' => $obj->imported_data_id, 'revision' => $obj->revision, 'short_description_wc' => $short_description_wc, 'long_description_wc' => $long_description_wc, 'title_keywords' => $title_keywords, 'own_price' => $own_price, 'price_diff' => serialize($price_diff), 'competitors_prices' => serialize($competitors_prices), 'items_priced_higher_than_competitors' => $items_priced_higher_than_competitors, 'similar_products_competitors' => serialize($similar_products_competitors), 'research_and_batch_ids' => $research_and_batch_ids, 'manufacturerInfo' => $manufacturerInfo, 'page_score' => $page_score, 'ranking' => $ranking, 'priority_internal' => $this->compareDescriptions($obj->description, $obj->long_description), 'traffic_data' => $this->CI->ranking_model->getTrafficData($obj->product_url_id), 'batch_id' => $batch_id));
             $rm[$batch_id][] = $obj->imported_data_id;
         }
     }
     //end foreach
     if (count($rm) > 0) {
         foreach ($rm as $batch_id => $data) {
             $this->CI->statistics_new_model->deleteItemsByBatchId($data, $batch_id);
         }
     }
     $this->CI->statistics_new_model->multipleInsert($ins);
     return $usedBatches;
 }