<?php
class tags {
public $tags;
public $tagscount;
public $prior;
public $fsizes;
public $cache;
function __construct( $tags, $fsizes ) {
$this->tags = $tags;
$this->tagscount = $this->getAllTagsCount( $tags );
$this->fsizes = $fsizes;
}
function getAllTagsCount( $tags ) {
$count = 0;
foreach( $tags as $tag ) {
$count += $tag[key( $tag )]['count']; }
return $count;
}
function definePrior() {
foreach( $this->tags as $tag ) {
$temp[key( $tag )] = round( ( $tag[key( $tag )]['count'] * 100
) / $this->tagscount ); }
$this->prior = $temp;
}
function defineSizes() {
$i = 0;
foreach( $this->tags as $tag ) {
array_push( $this->tags[$i][key( $tag )], $this->sizeByPrior( $this->prior[key( $tag )] ) ); $i++;
}
}
function sizeByPrior( $prior ) {
foreach( $sizes as $size ) {
if( $prior > $size ) {
$ca[] = $this->fsizes[$size]['size'];
}
else if( $prior == $size ) {
return $this->fsizes[$size]['size'];
}
}
return count( $ca ) > 0 ?
max( $ca ) : false; }
function convertArray() {
foreach( $this->tags as $tag ) {
$new[key( $tag )] = array( 'size' => $tag[key( $tag )][0
] ); }
return $new;
}
function genTagSizes() {
$this->definePrior();
$this->defineSizes();
return $this->convertArray();
}
}
?>
użycie
<?php
/**
* Może być to np wyciąg z bazy danych
*/
/**
* Najniższą wartością musi być 1 bo inaczej będzie zwracało puste wyniki ( wielkości czcionek )
*/
$font_sizes = array( '1' => array( 'size' => 10 ), '60' => array( 'size' => 20
) );
$tags = new tags( $tag_list, $font_sizes );
$smarty->assign( 'TAGS', $tags->genTagSizes() );
?>
taka klasa zwraca np tablice
Kod
Array
(
[balon] => Array
(
[size] => 10
)
[jagiełło] => Array
(
[size] => 20
)
[krzysiek] => Array
(
[size] => 10
)
[master] => Array
(
[size] => 10
)
)
wiem ze nakombinowane jest ile tylko mozna, ale pogubilem sie w polowie i zamieszałem troche (IMG:
http://forum.php.pl/style_emoticons/default/winksmiley.jpg) ale działać działą a to najwazniejsze
prosze o oceny