Created
October 16, 2010 15:41
-
-
Save Svel/629920 to your computer and use it in GitHub Desktop.
Logarithm Tag weights
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Logarithm tag weights | |
* | |
* @see http://zhekanax.ru/2009/06/25/tag-cloud-logarithm/ | |
* @see http://habrahabr.ru/blogs/webdev/30543/ | |
*/ | |
class Tag | |
{ | |
/** | |
* | |
* @param array $options массив с максимальным (max), минимальным (min) значением | |
* и колчиеством градаций (levels) | |
* @return int [1,levels] | |
*/ | |
public function getWeight(array $options) | |
{ | |
if (!isset($this->nb_posts) || !isset($options['max']) || !isset($options['min']) || !isset($options['levels'])) { | |
return 1; | |
} else { | |
$options['min'] = log($options['min'] + 1); | |
$options['max'] = log($options['max'] + 1); | |
return round( | |
1 | |
+ (log($this->nb_posts + 1) - $options['min']) | |
* ($options['levels'] - 1) | |
/ ($options['max'] - $options['min'] ) | |
); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment