Skip to main content

Yii Cheat Sheet

Grid View

'attribute' => 'no_answered',
'label' => '#vragen',
'enableSorting' => false,
'filter' => false,
'headerOptions' => ['style' => 'width:60px;'],
'contentOptions' => function ($model, $key, $index, $column) {
  if ( ! $model->finished )return ['style' => ""];
    $score = $model->no_questions > 0 ? round(($model->no_correct / $model->no_questions) * 100, 0) : 0;
  if ( $model->no_answered ) {
    $backgroundColor = $score < 55 ? 'lightcoral' : 'lightgreen';
  } else {
    $backgroundColor = "";
  }
   return ['style' => "background-color: $backgroundColor;"];
},
'format' => 'raw',
'value' => function ($model) {
  return Html::a($model->no_answered.'/'.$model->no_questions, ['submission/update', 'id' => $model->id]);
  return $model->no_answered.'/'.$model->no_questions;
},