<?php
/**
 * Funkcja ktora zamienia ocene na obrazki
 * @param $str string
 * @return string
 */
function smarty_modifier_showgrade($str){
	$zerostar = 'star0.gif';
	$halfstar = 'star05.gif';
	$fullstar = 'star1.gif';
	
	$grade = floatval($str);
	$gradeGround = floor($grade);
	$gradeAddon = false;
	if($gradeGround < $grade)$gradeAddon = true;
	$gradeArray = array();
	for($i = 1; $i <=5; $i++){
		if($i <= $gradeGround){
			$gradeArray[] = $fullstar;
		}elseif($gradeAddon){
			$gradeArray[] = $halfstar;
			$gradeAddon = false;
		}else{
			$gradeArray[] = $zerostar;
		}
	}
	$ret = '';
	foreach($gradeArray AS $item){
		$ret .= '<img src="'.URL_STATIC_CONTENT.'/image/'.$item.'" alt="" />';
	}
	
	return $ret;
}
?>