Yii:如何在视图页面上显示动态引导进度条


Yii: How to show dynamic bootstrap progress bars on view page

我是一个yiibie。我的视图页面上有前5名非政府组织(每个月前5名),同一页面上还有年底前5名的非政府组织。现在我想在每个ngo面前展示引导程序进度条。例如,如果一月是该月,它显示了该月的前5个非政府组织,我想在所有这5个非营利组织之前显示一个进度条,我希望每个月都显示。年底也是如此。就像第一个ngo进度条将是100%,第二个ngo将少于100%等等。请帮助我做这件事,谢谢。这是我的控制器的代码,它具有查看文件功能

           public function actionNgostats()
{
    $this->layout='main';
    $myCurrYear = date("Y");
    $userYear=UserRateReviewNgo::model()->findAll(array(
        'condition' => 'YEAR(date_created)=:year',
        'params' => array(':year'=>$myCurrYear),
        'select'=>'DISTINCT rate,ngo_id',
        'order'=>'rate DESC',
        'limit' =>  5
     ));  
    $this->render('ngostats', array("userYear"=>$userYear));
}

这是我的视图文件(ngostats)

    <div>
    <?php
    for($month = 1 ; $month <=date('m') ; $month++) 
    {
     $user=UserRateReviewNgo::model()->findAll(array(
            'condition' => 'YEAR(date_created)=:year and MONTH(date_created)=:month',
            'params' => array(':year'=>2015, ':month'=>$month),
            'select'=>'DISTINCT rate,ngo_id',
        'order'=>'rate DESC',
        'limit' =>  5
         )); 
     foreach($user as $show) {
            $model = Ngo::model()->findByAttributes(array('id'=>$show->ngo_id,));
            if (isset($model)) {
?>
<div><h4><?php echo $model->ngo_name?></h4></div>
 <div class="progress">
  <div class="progress-bar progress-bar-striped active" role="progressbar"
  aria-valuenow="40" aria-valuemin="0" aria-valuemax="100" style="width:40%">
    40%
  </div>
</div>
<?php
    }}}
?>
   </div> 

<h3>This is for the year's top 5 Ngo's</h3>
<div>   
    <?php // the for the year 
        foreach($userYear as $show) {
            $model = Ngo::model()->findByAttributes(array('id'=>$show->ngo_id,));
            if (isset($model)) {
            ?>
    <div><h4><?php echo $model->ngo_name?></h4></div>
 <div class="progress">
  <div class="progress-bar progress-bar-success progress-bar-striped active" role="progressbar"
  aria-valuenow="40" aria-valuemin="0" aria-valuemax="100" style="width:40%">
    40% Complete (success)
  </div>
</div>
    <?php
            }
        }
    ?>
</div>

这是我希望你能适应的月份

一开始很简单,var$val被设置为100,这个值被分配到需要的地方,然后递减20,循环重复

 <div>
    <?php
    for($month = 1 ; $month <=date('m') ; $month++) 
    {
        $dateObj   = DateTime::createFromFormat('!m', $month);
        $monthName = $dateObj->format('F'); 
        echo "<h3> " . $monthName . "</h3>"; 
        $user=UserRateReviewNgo::model()->findAll(array(
            'condition' => 'YEAR(date_created)=:year and MONTH(date_created)=:month',
            'params' => array(':year'=>2015, ':month'=>$month),
            'select'=>'DISTINCT rate,ngo_id',
        'order'=>'rate DESC',
        'limit' =>  5
         )); 
        $val = 100;
        foreach($user as $show) {
            $model = Ngo::model()->findByAttributes(array('id'=>$show->ngo_id,));
            if (isset($model)) {
                echo "<div><h4>" . $model->ngo_name ."</h4></div>
                    <div class='progress'>
                    <div class='progress-bar progress-bar-striped active' role='progressbar'
                    aria-valuenow='" . $val ."' aria-valuemin='0' aria-valuemax='100' style='width: ". $val ."%;'>" .  $val .
                    "</div>
                    </div>";
                    $val = $val -20;
    }}}
    ?>
</div>