Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- global $wpdb;
- /**
- * making notes about the category
- */
- $cat_array = $cat_list[$cat_id];
- $bigmark = array();
- $sums = array();
- /**
- * taking some notes about the companies attached to this category
- */
- foreach ($cat_array['company'] as $comp_id => $comp_array) {
- //we're taking every company separated
- $company_data = array();
- $company_data = ao_get_company_mark($comp_id);
- if (isset($company_data) && $company_data != NULL) { //IF THE COMPANY HAS ANY MARKS AND THE DATABASE WAS MALADETZ
- /**
- * using the functions.php file
- */
- $bigmark[$comp_id] = array();
- $sums[$comp_id] = array();
- $bigmarks[$comp_id] = $company_data["bigmark"];
- $sums[$comp_id] = $company_data["count_otzivi"];
- //$companies[$comp_id]['bigmark'] = $bigmark;
- echo '<div class-"nicu" style="display:none;">';
- var_dump($comp_id);
- // var_dump($company_data["count_otzivi"]);
- // var_dump($company_data["bigmark"]);
- var_dump($sums);
- echo '</div>';
- }
- } // enf for FOREACH company
- //var_dump($companies);
- //var_dump($bigmarks);
- var_dump($sums);
- //var_dump($cat_array);
- /**
- * arrangin the categories, and grouping them
- */
- //sorting by marks, from hi to low
- foreach ($cat_array['company'] as $comp_id => $comp_array) {
- if (isset($bigmarks[$comp_id])) {
- $arranged_companies[$comp_id] = $bigmarks[$comp_id];
- } else {
- $arranged_companies[$comp_id] = 0.00;
- }
- }
- $nonzero = array();
- //cutting the zero values, if any
- foreach ($arranged_companies as $key => $value) {
- if ($arranged_companies[$key] != 0) {
- $nonzero[$key] = $value;
- }
- }
- //so here goes the top
- $arranged_companies = $nonzero;
- //var_dump($arranged_companies);
- //var_dump($cat_top);
- //var_dump($arranged_companies);
- $great_companies = array();
- $less_great_companies = array();
- $M = intval(get_option( 'formula_inputs', 7 ));
- //grouping the companies to more or less 7 feedbacks
- foreach ($arranged_companies as $key => $value) {
- if (isset($sums[$key]) && $sums[$key] != NULL){
- if (intval($sums[$key]) >= $M ) { //if there are more than 6 votes, so 7+
- $great_companies[$key] = $key;
- } else {
- $less_great_companies[$key] = $key;
- }
- }
- }
- //cuting the arrays to not more than the top
- $great_companies = array_slice($great_companies, 0, $cat_top, true); //first slice great_companies as they lead
- if (count($great_companies) < $cat_top) { //if the top X is not enough, take from 2nd array, to complete the set
- $x = $cat_top - count($great_companies);
- $less_great_companies = array_slice($less_great_companies, 0, $x, true);
- } else {
- $less_great_companies = array();
- }
- /**
- * calculations
- * $M = 7; //settings
- * $V = 11; //number of votes for the certain company
- * $R = 4.15; //big mark of the company. The mark.
- * $C = 3.918; //media la toate big mark-urile ce participa in top
- */
- //finding C
- if (count($great_companies) > 0) {
- $C = 0;
- foreach ($great_companies as $key => $value) {
- $C = $C + $bigmarks[$key];
- }
- $C = $C / count($great_companies);
- foreach ($great_companies as $comp_id => $value) {
- $V = $sums[$comp_id] -> cn;
- $R = $bigmarks[$comp_id];
- $rating = ($V / ($V+$M) ) * $R + ( $M / ($V + $M) ) * $C;
- $rating_array[$comp_id] = round($rating, 2);
- }
- ksort($rating_array);
- //var_dump($great_companies);
- //var_dump($less_great_companies);
- ob_start();
- ?>
- <div class="category-block-container">
- <h2 class="top-heading">Рейтинг <?php echo $cat_array['categ_name'];?></h2>
- <div class="category-block">
- <?php $i = 1;
- if (count($rating_array) > 0 ) {
- foreach ($rating_array as $comp_id => $comp_array) {
- ?>
- <!-- start row -->
- <div class="company-row">
- <div class="item-number">
- <span><?php echo $i; $i++;?>.</span>
- </div>
- <div class="company-name">
- <div class="comp-title">
- <a href="<?php echo get_page_link($companies[$comp_id] -> page_id);?>"><span class="company"><?php echo $companies[$comp_id] -> cname;?></span></a>
- </div>
- <div class="mark-number">
- <a href="<?php echo site_url() . '/' . $companies[$comp_id] -> custom_post_type . '/otzivi'; ?>"><span><?php echo $sums[$comp_id] -> cn;?> оценок</span></a>
- </div>
- </div>
- <div class="company-mark">
- <div><span><?php echo $rating_array[$comp_id];?></span></div>
- </div>
- </div>
- <!-- end row -->
- <?php }
- } else { ?>
- <h3 class="top-heading">Нет результатов</h3>
- <?php }?>
- </div>
- </div>
- <?php
- $many_feedbacks = ob_get_clean(); //the companies from the first category-block
- } else {
- $cat_title = '<h2 class="top-heading">Рейтинг ' . $cat_array['categ_name'].'</h2>';
- $many_feedbacks = $cat_title . '<h3 class="top-heading">Нет результатов</h3>';
- $i = 1;
- }
- ob_start();
- ?>
- <div class="category-block-container">
- <h2 class="top-heading bad">Не вошли в рейтинг, мало оценок</h2>
- <div class="category-block">
- <?php
- foreach ($less_great_companies as $comp_id => $comp_array) {
- ?>
- <!-- start row -->
- <div class="company-row">
- <div class="item-number">
- <span><?php echo $i; $i++;?>.</span>
- </div>
- <div class="company-name">
- <div class="comp-title">
- <a href="<?php echo get_page_link($companies[$comp_id] -> page_id);?>"><span class="company"><?php echo $companies[$comp_id] -> cname;?></span></a>
- </div>
- <div class="mark-number">
- <a href="<?php echo site_url() . '/' . $companies[$comp_id] -> custom_post_type . '/otzivi'; ?>"><span><?php echo $sums[$comp_id] -> cn;?> оценок</span></a>
- </div>
- </div>
- <!--
- <div class="company-mark">
- <div><span><?php echo $bigmarks[$comp_id];?></span></div>
- </div> -->
- </div>
- <!-- end row -->
- <?php } ?>
- </div>
- </div>
- <?php
- $few_feedbacks = ob_get_clean(); //companies from the second block - few feedbacks
- //if (count($get_results))
- if (count($less_great_companies) == 0 ) {
- $few_feedbacks = '';
- }
- $result = $many_feedbacks . $few_feedbacks;
- /*
- $M = 7; //settings
- $V = 11; //nmarul de voturi pe companie
- $R = 4.15; //big mark-ul companiei
- $C = 3.918; //media la toate big mark-urile ce participa in top
- $rating = ($V / ($V+$M) ) * $R + ( $M / ($V + $M) ) * $C;
- $rating = round($rating, 2);
- var_dump($rating);
- */
- ?>
Advertisement
Add Comment
Please, Sign In to add comment