nlozovan

Untitled

Jun 16th, 2014
247
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.48 KB | None | 0 0
  1. <?php
  2. global $wpdb;
  3. /**
  4. * making notes about the category
  5. */
  6.  
  7.  
  8. $cat_array = $cat_list[$cat_id];
  9. $bigmark = array();
  10. $sums = array();
  11.  
  12. /**
  13. * taking some notes about the companies attached to this category
  14. */
  15. foreach ($cat_array['company'] as $comp_id => $comp_array) {
  16. //we're taking every company separated
  17.  
  18.  
  19. $company_data = array();
  20. $company_data = ao_get_company_mark($comp_id);
  21.  
  22. if (isset($company_data) && $company_data != NULL) { //IF THE COMPANY HAS ANY MARKS AND THE DATABASE WAS MALADETZ
  23.  
  24. /**
  25. * using the functions.php file
  26. */
  27.  
  28. $bigmark[$comp_id] = array();
  29. $sums[$comp_id] = array();
  30.  
  31. $bigmarks[$comp_id] = $company_data["bigmark"];
  32. $sums[$comp_id] = $company_data["count_otzivi"];
  33. //$companies[$comp_id]['bigmark'] = $bigmark;
  34.  
  35. echo '<div class-"nicu" style="display:none;">';
  36. var_dump($comp_id);
  37. // var_dump($company_data["count_otzivi"]);
  38. // var_dump($company_data["bigmark"]);
  39. var_dump($sums);
  40. echo '</div>';
  41. }
  42.  
  43. } // enf for FOREACH company
  44.  
  45. //var_dump($companies);
  46. //var_dump($bigmarks);
  47. var_dump($sums);
  48. //var_dump($cat_array);
  49.  
  50. /**
  51. * arrangin the categories, and grouping them
  52. */
  53.  
  54. //sorting by marks, from hi to low
  55. foreach ($cat_array['company'] as $comp_id => $comp_array) {
  56. if (isset($bigmarks[$comp_id])) {
  57. $arranged_companies[$comp_id] = $bigmarks[$comp_id];
  58. } else {
  59. $arranged_companies[$comp_id] = 0.00;
  60. }
  61. }
  62.  
  63.  
  64. $nonzero = array();
  65. //cutting the zero values, if any
  66. foreach ($arranged_companies as $key => $value) {
  67. if ($arranged_companies[$key] != 0) {
  68. $nonzero[$key] = $value;
  69. }
  70. }
  71. //so here goes the top
  72. $arranged_companies = $nonzero;
  73. //var_dump($arranged_companies);
  74. //var_dump($cat_top);
  75. //var_dump($arranged_companies);
  76.  
  77. $great_companies = array();
  78. $less_great_companies = array();
  79.  
  80. $M = intval(get_option( 'formula_inputs', 7 ));
  81.  
  82. //grouping the companies to more or less 7 feedbacks
  83. foreach ($arranged_companies as $key => $value) {
  84. if (isset($sums[$key]) && $sums[$key] != NULL){
  85. if (intval($sums[$key]) >= $M ) { //if there are more than 6 votes, so 7+
  86.  
  87. $great_companies[$key] = $key;
  88.  
  89. } else {
  90. $less_great_companies[$key] = $key;
  91. }
  92. }
  93. }
  94.  
  95.  
  96. //cuting the arrays to not more than the top
  97.  
  98. $great_companies = array_slice($great_companies, 0, $cat_top, true); //first slice great_companies as they lead
  99.  
  100. if (count($great_companies) < $cat_top) { //if the top X is not enough, take from 2nd array, to complete the set
  101. $x = $cat_top - count($great_companies);
  102. $less_great_companies = array_slice($less_great_companies, 0, $x, true);
  103. } else {
  104. $less_great_companies = array();
  105. }
  106.  
  107. /**
  108. * calculations
  109. * $M = 7; //settings
  110. * $V = 11; //number of votes for the certain company
  111. * $R = 4.15; //big mark of the company. The mark.
  112. * $C = 3.918; //media la toate big mark-urile ce participa in top
  113. */
  114.  
  115. //finding C
  116. if (count($great_companies) > 0) {
  117.  
  118. $C = 0;
  119. foreach ($great_companies as $key => $value) {
  120. $C = $C + $bigmarks[$key];
  121. }
  122.  
  123. $C = $C / count($great_companies);
  124.  
  125. foreach ($great_companies as $comp_id => $value) {
  126. $V = $sums[$comp_id] -> cn;
  127. $R = $bigmarks[$comp_id];
  128. $rating = ($V / ($V+$M) ) * $R + ( $M / ($V + $M) ) * $C;
  129. $rating_array[$comp_id] = round($rating, 2);
  130. }
  131.  
  132.  
  133. ksort($rating_array);
  134.  
  135. //var_dump($great_companies);
  136. //var_dump($less_great_companies);
  137.  
  138. ob_start();
  139. ?>
  140. <div class="category-block-container">
  141. <h2 class="top-heading">Рейтинг <?php echo $cat_array['categ_name'];?></h2>
  142. <div class="category-block">
  143.  
  144. <?php $i = 1;
  145. if (count($rating_array) > 0 ) {
  146. foreach ($rating_array as $comp_id => $comp_array) {
  147.  
  148. ?>
  149. <!-- start row -->
  150. <div class="company-row">
  151. <div class="item-number">
  152. <span><?php echo $i; $i++;?>.</span>
  153. </div>
  154.  
  155. <div class="company-name">
  156.  
  157. <div class="comp-title">
  158. <a href="<?php echo get_page_link($companies[$comp_id] -> page_id);?>"><span class="company"><?php echo $companies[$comp_id] -> cname;?></span></a>
  159. </div>
  160.  
  161. <div class="mark-number">
  162. <a href="<?php echo site_url() . '/' . $companies[$comp_id] -> custom_post_type . '/otzivi'; ?>"><span><?php echo $sums[$comp_id] -> cn;?> оценок</span></a>
  163. </div>
  164.  
  165. </div>
  166.  
  167. <div class="company-mark">
  168. <div><span><?php echo $rating_array[$comp_id];?></span></div>
  169. </div>
  170. </div>
  171. <!-- end row -->
  172. <?php }
  173. } else { ?>
  174. <h3 class="top-heading">Нет результатов</h3>
  175. <?php }?>
  176. </div>
  177. </div>
  178. <?php
  179. $many_feedbacks = ob_get_clean(); //the companies from the first category-block
  180. } else {
  181. $cat_title = '<h2 class="top-heading">Рейтинг ' . $cat_array['categ_name'].'</h2>';
  182. $many_feedbacks = $cat_title . '<h3 class="top-heading">Нет результатов</h3>';
  183. $i = 1;
  184. }
  185.  
  186. ob_start();
  187. ?>
  188. <div class="category-block-container">
  189. <h2 class="top-heading bad">Не вошли в рейтинг, мало оценок</h2>
  190. <div class="category-block">
  191.  
  192. <?php
  193. foreach ($less_great_companies as $comp_id => $comp_array) {
  194.  
  195. ?>
  196. <!-- start row -->
  197. <div class="company-row">
  198. <div class="item-number">
  199. <span><?php echo $i; $i++;?>.</span>
  200. </div>
  201.  
  202. <div class="company-name">
  203.  
  204. <div class="comp-title">
  205. <a href="<?php echo get_page_link($companies[$comp_id] -> page_id);?>"><span class="company"><?php echo $companies[$comp_id] -> cname;?></span></a>
  206. </div>
  207.  
  208. <div class="mark-number">
  209. <a href="<?php echo site_url() . '/' . $companies[$comp_id] -> custom_post_type . '/otzivi'; ?>"><span><?php echo $sums[$comp_id] -> cn;?> оценок</span></a>
  210. </div>
  211.  
  212. </div>
  213. <!--
  214. <div class="company-mark">
  215. <div><span><?php echo $bigmarks[$comp_id];?></span></div>
  216. </div> -->
  217. </div>
  218. <!-- end row -->
  219. <?php } ?>
  220. </div>
  221. </div>
  222. <?php
  223. $few_feedbacks = ob_get_clean(); //companies from the second block - few feedbacks
  224.  
  225. //if (count($get_results))
  226. if (count($less_great_companies) == 0 ) {
  227. $few_feedbacks = '';
  228. }
  229.  
  230. $result = $many_feedbacks . $few_feedbacks;
  231. /*
  232. $M = 7; //settings
  233. $V = 11; //nmarul de voturi pe companie
  234. $R = 4.15; //big mark-ul companiei
  235. $C = 3.918; //media la toate big mark-urile ce participa in top
  236.  
  237.  
  238. $rating = ($V / ($V+$M) ) * $R + ( $M / ($V + $M) ) * $C;
  239. $rating = round($rating, 2);
  240. var_dump($rating);
  241. */
  242. ?>
Advertisement
Add Comment
Please, Sign In to add comment