public function down()
 {
     $this->db->update('settings', array('description' => (string) ($this->migration_num - 1)), array('key' => 'current_migration'));
     foreach (AssessHelper::getNewFields() as $key => $value) {
         if ($this->db->field_exists($key, 'assess_results')) {
             $this->dbforge->drop_column('assess_results', $key);
         }
     }
 }
 public function up()
 {
     $this->load->helper('url');
     $is_currently_running = $this->db->where('key', 'current_migration')->where('description', (string) $this->migration_num)->get('settings')->num_rows();
     if (array_diff(array_keys($fields), $this->db->list_fields('assess_results')) && !$is_currently_running) {
         $this->db->update('settings', array('description' => (string) $this->migration_num), array('key' => 'current_migration'));
         $this->dbforge->add_column('assess_results', $this->fields);
         AssessHelper::runBackground(site_url('/crons/Fill_assess_results_new_fields/'));
     }
 }
コード例 #3
0
ファイル: rest_api.php プロジェクト: janladaking/CodeIgniter
 /**
  * Returns combined filters values High/Medium Priority for Insights filters
  *
  * @param int $brand_id
  * @param int $category_id
  * @param array $get_filters this parameter contain total count of SKU's which need to calculate percent value
  * @return array
  * @author Pavel Klyagin <*****@*****.**>
  */
 protected function getPriorityFiltersValues($brand_id = 0, $category_id = 0, $get_filters = array())
 {
     $this->load->model('settings_model');
     $this->load->model('filters_values');
     $this->load->model('product_category_model');
     $this->load->model('filters_to_result');
     $user_id = $this->ion_auth->get_user_id();
     $selected_filters = json_decode($this->input->post('filters'));
     $total_count = 1;
     if (isset($get_filters) && isset($get_filters['filters_values'])) {
         foreach ($get_filters['filters_values'] as $value) {
             if (isset($value->filter_id) && in_array($value->filter_id, array(63, 1))) {
                 $total_count = $value->dec_value;
                 break;
             }
         }
     }
     $noAjax = false;
     if ($brand_id == 0 && $category_id == 0) {
         $noAjax = true;
     }
     $priority_filters = AssessHelper::getPrioityFiltersList($user_id, true);
     $results = [];
     foreach ($selected_filters as $filter_id) {
         if (isset($priority_filters[$filter_id])) {
             $enabled_filters = $priority_filters[$filter_id];
             // save POST filters
             $selected_filters = $_POST['filters'];
             $_POST['filters'] = [];
             // get all batch filters
             $filters_values = $this->GetFilters_post($brand_id, $category_id, $noAjax);
             // restore POST filters
             $_POST['filters'] = $selected_filters;
             $total = 0;
             // get total issues from combined VAD enabled filters
             foreach ($filters_values['filters_values'] as $filter) {
                 if (in_array($filter->filter_id, $enabled_filters)) {
                     $total += (int) $filter->dec_value;
                 }
             }
             /** Count traffic data for unique filters (Priority SKUs and Issues) **/
             $filter_id_prefix = substr($filter_id, 0, 4);
             $visits = $this->GetTrafficData_get($enabled_filters, $brand_id, $category_id);
             /** @var  $unique_sku_count - Priority Unique SKUs **/
             $unique_sku_count = $this->VadGetUniqueSkusTotal_post($enabled_filters, $brand_id, $category_id);
             if ($filter_id_prefix == 'skus') {
                 $dec_value = $unique_sku_count;
             } else {
                 $dec_value = $total;
             }
             $results[] = (object) ['filter_id' => $filter_id, 'filter_name' => $filter_id, 'dec_value' => $dec_value, 'combination_id' => '', 'sign' => '', 'value' => '', 'percent_value' => round($unique_sku_count / $total_count * 100), 'data' => '', 'visit_number' => $visits->traffic_data_avg ? $visits->traffic_data_avg : 0];
         }
     }
     return $results;
 }
コード例 #4
0
ファイル: crons.php プロジェクト: janladaking/CodeIgniter
 private function prepareDataForCompare($similar_items = array(), $customer_name = '', $batch2 = 0, $default_statistics_model_object = 'statistics_new_model', &$row, &$parsed_attributes_unserialize)
 {
     $has_similar_items = FALSE;
     if (!is_array($similar_items) || !$batch2) {
         return $has_similar_items;
     }
     $this->load->model($default_statistics_model_object);
     //check each item for comparsing
     foreach ($similar_items as $key => $item) {
         $tsp = '';
         //find secondary item
         if (!empty($customer_name) && !empty($item['customer']) && $this->{$default_statistics_model_object}->if_url_in_batch($item['imported_data_id'], $batch2)) {
             $parsed_anchors_unserialize_val = '';
             $parsed_meta_keywords_unserialize_val = '';
             $title_seo_prases = array();
             $column_external_content = '';
             //get data of secondary item
             $cmpare = $this->{$default_statistics_model_object}->get_compare_item($item['imported_data_id']);
             //get anchors
             if (isset($cmpare->anchors)) {
                 $parsed_anchors_unserialize = unserialize($cmpare->anchors);
             }
             //get serialized items parsed by crawler
             if (isset($cmpare->parsed_attributes)) {
                 $parsed_attributes_unserialize = unserialize($cmpare->parsed_attributes);
                 if (!$parsed_attributes_unserialize) {
                     $cmpare->parsed_attributes = iconv('UTF-8', 'ASCII//TRANSLIT', $cmpare->parsed_attributes);
                     $parsed_attributes_unserialize = unserialize($cmpare->parsed_attributes);
                     if (!$parsed_attributes_unserialize) {
                         $cmpare->parsed_attributes = preg_replace('!s:(\\d+):"(.*?)";!e', "'s:'.strlen('\$2').':\"\$2\";'", $cmpare->parsed_attributes);
                         $parsed_attributes_unserialize = unserialize($cmpare->parsed_attributes);
                     }
                 }
             }
             //get title keywords
             if (trim($cmpare->title_keywords) && $cmpare->title_keywords != 'None') {
                 $title_seo_prases = unserialize($cmpare->title_keywords);
             }
             //get title seo phrases
             if (!empty($title_seo_prases)) {
                 $str_title_long_seo = '<div class="table_keywords_long">';
                 foreach ($title_seo_prases as $pras) {
                     $str_title_long_seo .= '<p>' . $pras['ph'] . '<span class = "phr-frequency"> - ' . $pras['frq'] . ' </span></p>';
                 }
                 $tsp = $str_title_long_seo . '</div>';
             }
             //get H tags
             $HTags = unserialize($cmpare->htags);
             $buildedH1Field = AssessHelper::buildHField($HTags, 'h1');
             $buildedH2Field = AssessHelper::buildHField($HTags, 'h2');
             // Review count calculation
             if (isset($parsed_attributes_unserialize['review_count_diff']) && preg_match("|Normal crawl: (\\d+) Special Crawl|i", $parsed_attributes_unserialize['review_count_diff'], $matches)) {
                 $parsed_column_reviews_unserialize_val = $matches[1];
             } elseif (isset($parsed_attributes_unserialize['review_count'])) {
                 $parsed_column_reviews_unserialize_val = $parsed_attributes_unserialize['review_count'];
             } else {
                 $parsed_column_reviews_unserialize_val = 0;
             }
             //get external content
             if (isset($parsed_attributes_unserialize['cnetcontent']) || isset($parsed_attributes_unserialize['webcollage'])) {
                 $column_external_content = $this->column_external_content($parsed_attributes_unserialize['cnetcontent'], $parsed_attributes_unserialize['webcollage']);
             }
             //get meta data
             $parsed_meta_unserialize = unserialize($cmpare->parsed_meta);
             //get meta description
             if ($parsed_meta_unserialize['description']) {
                 $parsed_meta_unserialize_val = $parsed_meta_unserialize['description'];
                 $parsed_meta_unserialize_val_c = count(preg_split('/\\s+/', $parsed_meta_unserialize['description']));
                 if ($parsed_meta_unserialize_val_c < 1) {
                     $parsed_meta_unserialize_val_count = $parsed_meta_unserialize_val_c;
                 }
             } else {
                 if ($parsed_meta_unserialize['Description']) {
                     $parsed_meta_unserialize_val = $parsed_meta_unserialize['Description'];
                     $parsed_meta_unserialize_val_c = count(preg_split('/\\s+/', $parsed_meta_unserialize['Description']));
                     if ($parsed_meta_unserialize_val_c != 1) {
                         $parsed_meta_unserialize_val_count = $parsed_meta_unserialize_val_c;
                     }
                 }
             }
             //get meta keywords
             if (isset($parsed_meta_unserialize['keywords']) && !empty($parsed_meta_unserialize['keywords'])) {
                 $Meta_Keywords_un = "<table class='table_keywords_long'>";
                 $cnt_meta_un = explode(',', $parsed_meta_unserialize['keywords']);
                 $cnt_meta_count_un = count($cnt_meta_un);
                 foreach ($cnt_meta_un as $key => $cnt_m_un) {
                     $_count_meta_un = 0;
                     $cnt_m_un = trim($cnt_m_un);
                     if (!$cnt_m_un) {
                         continue;
                     }
                     if ($sim_items[$it]->long_description || $sim_items[$it]->short_description) {
                         $_count_meta_un = $this->keywords_appearence($sim_items[$it]->long_description . $sim_items[$it]->short_description, $cnt_m_un);
                         $_count_meta_num_un = (double) round($_count_meta_un * $cnt_meta_count_un / ($sim_items[$it]->long_description_wc + $sim_items[$it]->short_description_wc) * 100, 2);
                         $batch2_meta_percents[$row_key][$key] = $_count_meta_num_un;
                         $_count_meta_num_un_proc = $_count_meta_num_un . "%";
                         $Meta_Keywords_un .= "<tr><td>" . $cnt_m_un . "</td><td>" . $_count_meta_num_un_proc . "</td></tr>";
                         if ($it == 1 && !$meta_key_gap) {
                             $metta_prc = round($_count_meta_un * $cnt_meta_count_un / ($row->long_description_wc + $row->short_description_wc) * 100, 2);
                             if ($metta_prc >= 2) {
                                 $meta_key_gap = $metta_prc;
                             }
                         }
                     }
                 }
                 $Meta_Keywords_un .= "</table>";
                 $parsed_meta_keywords_unserialize_val = $Meta_Keywords_un;
             }
             //variables for comparing
             $row->snap1 = $cmpare->snap !== false ? '<span style="cursor:pointer;"><img src="' . base_url() . 'webshoots/' . $cmpare->snap . '" /></snap>' : '-';
             $row->imp_data_id1 = $item['imported_data_id'] ? $item['imported_data_id'] : '';
             $row->product_name1 = $cmpare->product_name ? $cmpare->product_name : '-';
             $row->item_id1 = isset($parsed_attributes_unserialize['item_id']) ? $parsed_attributes_unserialize['item_id'] : '';
             $row->model1 = isset($parsed_attributes_unserialize['model']) ? $parsed_attributes_unserialize['model'] : '';
             $row->url1 = $cmpare->url !== false ? "<span class='res_url'><a target='_blank' href='" . $cmpare->url . "'>" . $cmpare->url . "</a></span>" : "-";
             $row->confidence1 = isset($cmpare->confidence) ? $cmpare->confidence : 0;
             $row->Page_Load_Time1 = isset($parsed_attributes_unserialize['loaded_in_seconds']) ? $parsed_attributes_unserialize['loaded_in_seconds'] : '';
             $row->Short_Description1 = $cmpare->short_description;
             $row->short_description_wc1 = $cmpare->short_description_wc;
             $row->Meta_Keywords1 = $parsed_meta_keywords_unserialize_row;
             $row->Long_Description1 = $cmpare->long_description;
             $row->long_description_wc1 = $cmpare->long_description_wc;
             $row->Meta_Description1 = $parsed_meta_unserialize_val;
             $row->Meta_Description_Count1 = $parsed_meta_unserialize_val_count;
             $row->column_external_content1 = $column_external_content;
             $row->H1_Tags1 = isset($buildedH1Field['rowue']) ? $buildedH1Field['rowue'] : (isset($buildedH1Field['value']) ? $buildedH1Field['value'] : '');
             $row->H1_Tags_Count1 = $buildedH1Field['count'];
             $row->H2_Tags1 = isset($buildedH2Field['rowue']) ? $buildedH2Field['rowue'] : (isset($buildedH2Field['value']) ? $buildedH2Field['value'] : '');
             $row->H2_Tags_Count1 = $buildedH2Field['count'];
             $row->column_reviews1 = $parsed_column_reviews_unserialize_val;
             $row->average_review1 = isset($parsed_attributes_unserialize['average_review']) ? $parsed_attributes_unserialize['average_review'] : '';
             $row->column_features1 = isset($parsed_attributes_unserialize['feature_count']) ? $parsed_attributes_unserialize['feature_count'] : 0;
             $row->title_seo_phrases1 = trim($tsp) ? $tsp : 'None';
             $row->images_cmp1 = isset($parsed_attributes_unserialize['product_images']) ? $parsed_attributes_unserialize['product_images'] : 'None';
             $row->video_count1 = isset($parsed_attributes_unserialize['video_count']) ? $parsed_attributes_unserialize['video_count'] : 'None';
             $row->title_pa1 = isset($parsed_attributes_unserialize['title']) ? $parsed_attributes_unserialize['title'] : 'None';
             $row->links_count1 = isset($parsed_anchors_unserialize['quantity']) ? $parsed_anchors_unserialize['quantity'] : 'None';
             $row->total_description_wc1 = $row->short_description_wc1 + $row->long_description_wc1;
             $row->brand_id1 = $cmpare->brand_id;
             $row->priority = $item['priority'];
             $row->priority_internal1 = $cmpare->priority_internal;
             ++$this->counters[0][0]['batch2_items_count'];
             if ($row->category_id > 0) {
                 //caclculate total items of batch2 by category
                 ++$this->counters[0][$row->category_id]['batch2_items_count'];
             }
             if ($this->brand_id > 0) {
                 //caclculate total items of batch2 by brand
                 ++$this->counters[0][$this->brand_id]['batch2_items_count'];
             }
             $similar_items_data[] = $cmpare;
             $row->similar_items = $similar_items_data;
             $has_similar_items = true;
             break;
         }
     }
     return $has_similar_items;
 }
 public function up()
 {
     $this->load->helper('url');
     AssessHelper::runBackground(site_url('/crons/Fill_assess_results_new_fields/'));
 }
コード例 #6
0
ファイル: assess.php プロジェクト: janladaking/CodeIgniter
 /**
  * Creating files for each brand/category and filter pair. Returning link to zip file
  */
 public function exportBrandsAndFilters()
 {
     $this->load->model('products_filters');
     $chronicle_str = $this->input->post('chronicle');
     $superFilter = $this->input->post('super_filter');
     $filters = $this->input->post('filters');
     sort($filters);
     $filters_str = implode(',', $filters);
     // If chronicle or filters are empty - returning failure
     if (empty($chronicle_str) || empty($filters)) {
         return $this->output->set_content_type('application/json')->set_output(json_encode(array('success' => FALSE, 'message' => 'Not initialized')));
     }
     $brands = $this->input->post('brands');
     // Brands should be only numeric
     foreach ($brands as $i => &$val) {
         if (!is_numeric($val)) {
             unset($brands[$i]);
         }
     }
     sort($brands);
     $categories = $this->input->post('categories');
     // Categories should be only numeric
     foreach ($categories as $i => &$val) {
         if (!is_numeric($val)) {
             unset($categories[$i]);
         }
     }
     sort($categories);
     // If we don't have category and brands - returning failure
     if (empty($brands) && empty($categories)) {
         $this->output->set_content_type('application/json')->set_output(json_encode(array('success' => FALSE, 'message' => 'Empty data')));
     }
     // Initial data
     $result = array('success' => FALSE);
     $prority_filters = array();
     if ($this->session->userdata['dateformat'] == 1) {
         $date = date('m-d-Y_H-i');
     } elseif ($this->session->userdata['dateformat'] == 2) {
         $date = date('d-m-Y_H-i');
     }
     $path = 'webroot/temp/';
     // Getting name for each filter_id. Instead of 'skus_fewer_50_product_content' we use 'skusFewer50ProductContent'
     $filter_names = array();
     $this->load->model('filters_values');
     foreach ($filters as $filter_key => &$filter_id) {
         if ($filter_id == 'medium_priority_filter' || $filter_id == 'high_priority_filter' || $filter_id == 'skus_medium_priority_filter' || $filter_id == 'skus_high_priority_filter') {
             unset($filters[$filter_key]);
             $prority_filters[$filter_id] = array();
             $filter_name = str_replace(array('skus_', '_filter'), '', $filter_id);
         } else {
             $filter_id = (int) $filter_id;
             $filter_name = $this->products_filters->get_filter_name_by_filter_id($filter_id);
         }
         $filter_names[$filter_id] = str_replace(' ', '', ucwords(str_replace('_', ' ', $filter_name)));
     }
     if (count($prority_filters)) {
         $prority_filters = array_intersect_key(AssessHelper::getPrioityFiltersList($this->ion_auth->get_user_id(), true), $prority_filters);
     }
     // Getting batch information
     $this->load->model('batches_model');
     $batch = $this->batches_model->getBatchByChronicle($chronicle_str);
     // Decoding chronicle if that was json string
     $chronicle = json_decode($chronicle_str);
     sort($chronicle);
     if (is_int($chronicle)) {
         $chronicle = (string) $chronicle;
     }
     // Checking if we have category or brands filters
     $result = array('success' => TRUE);
     $this->load->model('assess_results');
     $this->load->library('zip');
     $this->load->helper('csv');
     $this->load->helper('assess');
     if ($categories || $brands) {
         // Getting URLs for all pairs
         $data = $this->assess_results->getExportBrandsCategoriesFilters($chronicle, $brands, $categories, $filters, $superFilter, $prority_filters);
         // Loading helper with functions "toAscii" and "getUniqueFilename"
         // Creating in memory zip files for each pair
         foreach ($data as $brand => &$val) {
             $datas_for_csv = array();
             $columns_for_csv = array();
             $max_length = 0;
             // In zip russian symbols looks ok in CP866 encoding
             $name = str_replace(array(' ', '_', '-'), '_', iconv('UTF-8', 'CP866', $batch->title) . '_' . $brand . '.csv');
             foreach ($val as $filter_id => &$rows) {
                 array_unshift($rows, $filter_names[$filter_id]);
                 if (count($rows) > $max_length) {
                     $max_length = count($rows);
                 }
                 $columns_for_csv[] = $rows;
             }
             foreach ($columns_for_csv as $key => $value) {
                 for ($i = 0; $i < $max_length; ++$i) {
                     if (!isset($datas_for_csv[$i])) {
                         $datas_for_csv[$i] = array();
                     }
                     $v = isset($value[$i]) ? $value[$i] : '';
                     array_push($datas_for_csv[$i], $v);
                 }
             }
             $this->zip->add_data(iconv('UTF-8', 'CP866', $name), array_to_csv($datas_for_csv, '', false));
         }
     }
     /**
      *for bug 1661
      *@author Hermine Hakobyan
      **/
     $batch_all_data = $this->assess_results->getExportBrandsCategoriesFilters($chronicle, array(), array(), $filters, $superFilter, $prority_filters);
     foreach ($batch_all_data as $brand => &$val) {
         $datas_for_csv = array();
         $columns_for_csv = array();
         $max_length = 0;
         // In zip russian symbols looks ok in CP866 encoding
         $name = str_replace(array(' ', '_', '-'), '_', iconv('UTF-8', 'CP866', $batch->title) . '.csv');
         foreach ($val as $filter_id => &$rows) {
             array_unshift($rows, $filter_names[$filter_id]);
             if (count($rows) > $max_length) {
                 $max_length = count($rows);
             }
             $columns_for_csv[] = $rows;
         }
         foreach ($columns_for_csv as $key => $value) {
             for ($i = 0; $i < $max_length; ++$i) {
                 if (!isset($datas_for_csv[$i])) {
                     $datas_for_csv[$i] = array();
                 }
                 $v = isset($value[$i]) ? $value[$i] : '';
                 array_push($datas_for_csv[$i], $v);
             }
         }
         $this->zip->add_data(iconv('UTF-8', 'CP866', $name), array_to_csv($datas_for_csv, '', false));
     }
     //End of bug 1661
     $zip_file = $path . getUniqueFilename($path, $batch->title . '_' . $date, 'zip');
     // Saving zip on disk
     $this->zip->archive($zip_file);
     // Getting current user data
     $user = $this->ion_auth->get_user_data();
     // Sending email
     $this->load->library('email');
     $this->email->from('*****@*****.**', 'Administrator');
     $this->email->to($user['email']);
     $this->email->subject('Export completed');
     $this->email->message('Your export was completed succesfully. You can download it here ' . base_url($zip_file));
     $this->email->send();
     // Adding zip fullpath to result
     $result['link'] = base_url($zip_file);
     // Zipping files
     $this->output->set_content_type('application/json')->set_output(json_encode($result));
 }