Пример #1
0
<?php

use yii\helpers\Html;
use app\components\grid\GridView;
use yii\widgets\Pjax;
use yii\helpers\Url;
use yii\helpers\ArrayHelper;
use app\models\Organizer;
/**
 * @var yii\web\View $this
 * @var yii\data\ActiveDataProvider $dataProvider
 * @var app\models\search\PollSearch $searchModel
 */
$columns = [['class' => 'app\\components\\grid\\ActionColumn'], 'title', 'question:ntext', 'membersCount', 'start_time:datetime', 'end_time:datetime', ['class' => 'kartik\\grid\\EditableColumn', 'attribute' => 'locked', 'format' => 'boolean', 'visible' => \Yii::$app->user->isAdmin(), 'refreshGrid' => true, 'editableOptions' => ['header' => \Yii::t('app', 'locked') . ' (admin only)', 'size' => 'md', 'data' => array(0 => 'Open', 1 => 'Locked'), 'inputType' => \kartik\editable\Editable::INPUT_DROPDOWN_LIST, 'formOptions' => ['action' => Url::to(['ajax-update'])], 'displayValueConfig' => [0 => 'Open', 1 => 'Locked'], 'containerOptions' => ['style' => 'text-align: center; display:block;']]], ['attribute' => 'organizer_id', 'width' => '180px', 'format' => 'raw', 'visible' => \Yii::$app->user->isAdmin(), 'filterType' => GridView::FILTER_SELECT2, 'filter' => ArrayHelper::map(Organizer::find()->orderBy('name')->asArray()->all(), 'id', 'name'), 'filterWidgetOptions' => ['pluginOptions' => ['allowClear' => true]], 'filterInputOptions' => ['placeholder' => \Yii::t('app', 'Any Organizer')], 'value' => function ($data, $key, $index, $widget) {
    return $this->render('//system/columnviews/_organizer', ['data' => $data->organizer]);
}]];
echo GridView::widget(['dataProvider' => $dataProvider, 'filterModel' => $searchModel, 'columns' => $columns, 'id' => 'poll_grid']);
Пример #2
0
// render Import modal window
echo $this->render('_import_modal', ['poll' => $model, 'target' => 'importModal']);
// render Email modal window
echo $this->render('_email_modal', ['model' => $model, 'target' => 'emailModal']);
if (\Yii::$app->user->isAdmin()) {
    echo $this->render('_contact_emails_modal', ['model' => $model, 'target' => 'contactEmailsModal']);
}
$demoCodes = Html::beginTag('ul', ['class' => 'list-unstyled']);
$demoCodes .= Html::tag('li', Html::tag('span', 'Invalid Code', Code::getInvalidHTMLOptions()));
$demoCodes .= Html::tag('li', Html::tag('span', 'Unused Code', Code::getUnusedHTMLOptions()));
$demoCodes .= Html::tag('li', Html::tag('span', 'Used Code', Code::getUsedHTMLOptions()));
$demoCodes .= Html::endTag('ul');
echo GridView::widget(['id' => 'members-gridview', 'dataProvider' => $memberDataProvider, 'filterModel' => $memberSearchModel, 'showFooter' => true, 'columns' => [['class' => 'app\\components\\grid\\ActionColumn', 'urlCreator' => function ($action, $model, $key, $index) {
    //return Yii::$app->controller->createUrl([$action, 'id'=>$key]);
    return PollUrl::toRoute(["member/{$action}", 'id' => $key, 'poll_id' => $model->poll_id]);
}], ['attribute' => 'name', 'format' => 'raw', 'value' => function ($data) {
    return Html::a(Html::encode($data->name), PollUrl::toRoute(['member/view', 'id' => $data->id, 'poll_id' => $data->poll_id]));
}], 'group', 'ContactsCount', ['attribute' => 'codes.code_status', 'label' => Yii::t('app', 'Voting Code'), 'format' => 'raw', 'footer' => $demoCodes, 'filter' => [Code::CODE_STATUS_INVALID_UNUSED => 'Invalid Code', Code::CODE_STATUS_UNUSED => 'Unused Code', Code::CODE_STATUS_USED => 'Used Code'], 'value' => function ($data) {
    $codes = $data->codes;
    // Display the invalid tokens before the valid ones.
    usort($codes, function ($a, $b) {
        return $a->code_status > $b->code_status;
    });
    $str = Html::beginTag('ul', ['class' => 'list-unstyled']);
    foreach ($codes as $code) {
        $options = $code->getHTMLOptions();
        $str .= Html::tag('li', Html::tag('span', $code, $options));
    }
    $str .= Html::endTag('ul');
    return $str;
}]]]);
Пример #3
0
if ($model->hasStarted()) {
    $this->registerJsFile('@web/js/reflowChart.js', ['depends' => \yii\web\JqueryAsset::className(), 'depends' => miloschuman\highcharts\HighchartsAsset::className()]);
    echo Highcharts::widget(['htmlOptions' => ['id' => 'chartcontainer'], 'options' => ['title' => ['text' => $model->question], 'chart' => ['type' => 'column'], 'plotOptions' => ['column' => ['colorByPoint' => true]], 'colors' => ['#0044CC', '#0088CC', '#51A351', '#F89406', '#BD362F'], 'credits' => ['enabled' => false], 'xAxis' => ['categories' => ArrayHelper::getColumn($dataProvider->getModels(), 'text')], 'yAxis' => ['title' => ['text' => 'Votes'], 'allowDecimals' => false], 'series' => [['name' => 'Votes', 'data' => ArrayHelper::getColumn($dataProvider->getModels(), function ($option) {
        return intval($option->getValidVotesCount());
    }), 'showInLegend' => false]]]]);
}
// Overview table.
$used = $model->getUsedCodesCount();
$unused = $model->getUnusedCodesCount();
$total = $model->getValidCodesCount();
$membersCount = $model->getMembersCount();
$contactsCount = $model->getContactsCount();
$show_total_percentage_columns = false;
if ($model->select_min == 1 && $model->select_max == 1) {
    $show_total_percentage_columns = true;
}
echo Html::tag('h2', Yii::t('app', 'Overview'));
echo DetailView::widget(['model' => $model, 'attributes' => [['label' => Yii::t('app', 'Total Number of Voters'), 'value' => $total], ['label' => Yii::t('app', 'Votes Submitted'), 'value' => $used], ['label' => Yii::t('app', 'Votes Not Yet Submitted'), 'value' => $unused], ['label' => Yii::t('app', 'Total Members Count'), 'value' => $membersCount], ['label' => Yii::t('app', 'Total Contacts Count'), 'value' => $contactsCount], ['label' => Yii::t('app', 'Participation'), 'format' => ['percent', '2'], 'value' => $total > 0 ? $used / $total : 0]]]);
// Votes.
echo Html::tag('h2', Yii::t('app', 'Votes'));
echo GridView::widget(['pjax' => false, 'options' => ['id' => 'results_gridview'], 'dataProvider' => $dataProvider, 'columns' => [['attribute' => 'id', 'label' => Yii::t('app', 'No.'), 'headerOptions' => ['class' => 'sort-numerical', 'style' => 'width: 30px; white-space: nowrap;'], 'value' => function ($data, $key, $index, $widget) {
    global $optionIDs;
    return array_search($data->id, $optionIDs) + 1;
}], 'text', ['attribute' => 'validVotesCount', 'headerOptions' => ['class' => 'sort-numerical'], 'label' => Yii::t('app', 'Votes')], ['attribute' => 'validVotesCount', 'label' => Yii::t('app', 'Percentage of Used Votes'), 'format' => ['percent', '2'], 'visible' => $show_total_percentage_columns, 'value' => function ($data, $key, $index, $widget) {
    global $used;
    return $used > 0 ? $data->validVotesCount / $used : 0;
}], ['attribute' => 'validVotesCount', 'label' => Yii::t('app', 'Percentage of Total Votes'), 'format' => ['percent', '2'], 'visible' => $show_total_percentage_columns, 'value' => function ($data, $key, $index, $widget) {
    global $total;
    return $total > 0 ? $data->validVotesCount / $total : 0;
}]]]);
Pjax::end();
Пример #4
0
<?php

use yii\helpers\Html;
use app\components\grid\GridView;
use yii\widgets\Pjax;
/**
 * @var yii\web\View $this
 * @var yii\data\ActiveDataProvider $dataProvider
 * @var app\models\search\MemberSearch $searchModel
 */
$columns = [['class' => 'app\\components\\grid\\ActionColumn', 'urlCreator' => function ($action, $model, $key, $index) {
    return Yii::$app->controller->createUrl([$action, 'id' => $key]);
}], 'name', 'group'];
echo GridView::widget(['id' => 'members-grid', 'dataProvider' => $dataProvider, 'filterModel' => $searchModel, 'columns' => $columns]);