<?php if ($data['content']['comment_count']) { ?> <?php if ($data['polls']['total']) { ?> <?php foreach ($data['polls']['list'] as $index => $value) { ?> <div class="progress"> <?php $percentage = $value['count'] / $data['content']['comment_count'] * 100; ?> <div class="progress-bar progress-bar-striped progress-bar-<?php echo bar_color($index); ?> " role="progressbar" aria-valuenow="60" aria-valuemin="0" aria-valuemax="100" style="width:<?php echo $percentage; ?> %;"> <?php echo $value['title']; ?> : <?php echo $value['count']; ?> / <?php echo $percentage; ?> %
/** * Render a progress bar * @param $num - str or array * @param bool $title - str or array * @param bool $class * @param bool $height * @param bool $reverse * @param bool $as_percent * @param bool $disabled * @return string */ function progress_bar($num, $title = FALSE, $class = FALSE, $height = FALSE, $reverse = FALSE, $as_percent = TRUE, $disabled = FALSE) { $height = $height ? $height : '20px'; if (!function_exists('bar_color')) { function bar_color($num, $reverse) { $auto_class = $reverse ? "progress-bar-success" : "progress-bar-danger"; if ($num > 71) { $auto_class = $reverse ? 'progress-bar-danger' : 'progress-bar-success'; } elseif ($num > 55) { $auto_class = $reverse ? 'progress-bar-warning' : 'progress-bar-info'; } elseif ($num > 25) { $auto_class = $reverse ? 'progress-bar-info' : 'progress-bar-warning'; } elseif ($num < 25) { $auto_class = $reverse ? 'progress-bar-success' : 'progress-bar-danger'; } return $auto_class; } } $_barcolor = array('progress-bar-success', 'progress-bar-info', 'progress-bar-warning', 'progress-bar-danger'); $_barcolor_reverse = array('progress-bar-success', 'progress-bar-info', 'progress-bar-warning', 'progress-bar-danger'); $html = ''; if (is_array($num)) { $i = 0; $chtml = ""; $cTitle = ""; $cNum = ""; foreach ($num as $value) { $int = intval($num); if ($disabled == TRUE) { $value = "∞"; } else { $value = $value > 0 ? $value . ' ' : '0 '; $value .= $as_percent ? '%' : ''; } $c2Title = ""; if (is_array($title)) { $c2Title = $title[$i]; } else { $cTitle = $title; } $auto_class = $reverse ? $_barcolor_reverse[$i] : $_barcolor[$i]; $classes = is_array($class) ? $class[$i] : $auto_class; $cNum .= "\n <div class='progress display-inline-block m-0' style='width:20px; height: 10px; '>\n <span class='progress-bar " . $classes . "' style='width:100%'></span></div>\n <div class='display-inline-block m-r-5'>" . $c2Title . " " . $value . "</div>\n"; $chtml .= "<div title='" . $title . "' class='progress-bar " . $classes . "' role='progressbar' aria-valuenow='{$value}' aria-valuemin='0' aria-valuemax='100' style='width: {$int}%'>\n"; $chtml .= "</div>\n"; $i++; } $html .= "<div class='text-right m-b-10'><span class='pull-left'>{$cTitle}</span><span class='clearfix'>{$cNum} </span></div>\n"; $html .= "<div class='progress m-b-10' style='height: " . $height . "'>\n"; $html .= $chtml; $html .= "</div>\n"; $html .= "</div>\n"; } else { $int = intval($num); if ($disabled == TRUE) { $num = "∞"; } else { $num = $num > 0 ? $num . ' ' : '0 '; $num .= $as_percent ? '%' : ''; } $auto_class = bar_color($int, $reverse); $class = !$class ? $auto_class : $class; $html .= "<div class='text-right m-b-10'><span class='pull-left'>{$title}</span><span class='clearfix'>{$num}</span></div>\n"; $html .= "<div class='progress m-b-10' style='height: " . $height . "'>\n"; $html .= "<div class='progress-bar " . $class . "' role='progressbar' aria-valuenow='{$num}' aria-valuemin='0' aria-valuemax='100' style='width: {$int}%'>\n"; $html .= "</div></div>\n"; } return $html; }