TagScorer.php 1.3KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. <?php
  2. namespace Muzich\CoreBundle\lib;
  3. class TagScorer
  4. {
  5. public function scoreOrderedsTagsIds($ordered_tags)
  6. {
  7. $tags_ordered_by_score = array();
  8. $score_max = count($ordered_tags);
  9. foreach ($ordered_tags as $tag_id)
  10. {
  11. $tags_ordered_by_score[(int)$score_max] = $tag_id;
  12. $score_max -= 1;
  13. }
  14. return $tags_ordered_by_score;
  15. }
  16. public function scoreEntireOrderedTagsIds($ordereds_elements_tags_ids, $favoriteds_tags)
  17. {
  18. $tags_score = array();
  19. foreach ($ordereds_elements_tags_ids as $ordereds_tags_ids)
  20. {
  21. foreach ($ordereds_tags_ids as $score_tag => $tag_id)
  22. {
  23. if (!array_key_exists($tag_id, $tags_score))
  24. $tags_score[$tag_id] = 0;
  25. $tags_score[$tag_id] += $score_tag;
  26. }
  27. }
  28. foreach ($favoriteds_tags as $favorite_tag_id)
  29. {
  30. if (!array_key_exists($favorite_tag_id, $tags_score))
  31. $tags_score[$favorite_tag_id] = 0;
  32. $tags_score[$favorite_tag_id] += 5;
  33. }
  34. arsort($tags_score);
  35. $oredered_tags_ids_without_score = array();
  36. foreach ($tags_score as $tag_id => $tag_score)
  37. {
  38. $oredered_tags_ids_without_score[] = $tag_id;
  39. }
  40. return $oredered_tags_ids_without_score;
  41. }
  42. }