/** * Creates data provider instance with search query applied * * @param array $params * * @return ActiveDataProvider */ public function search($params, $aDop = []) { $query = Doclad::find(); $aWith = []; if (isset($aDop['with'])) { $aWith = $aDop['with']; unset($aDop['with']); } $query->with(Yii::$app->user->can(User::USER_GROUP_MODERATOR) ? array_merge(['section', 'section.conference', 'files'], $aWith) : array_merge(['section', 'section.conference', 'files'], $aWith)); $query->joinWith(['section', 'section.conference']); $dataProvider = new ActiveDataProvider(['query' => $query]); $sFormname = $this->formName(); if (!isset($params[$sFormname])) { $params[$sFormname] = []; } $params[$sFormname] = array_merge($params[$sFormname], $aDop); $this->load($params); if (!$this->validate()) { // uncomment the following line if you do not want to return any records when validation fails // $query->where('0=1'); return $dataProvider; } $aFilters = ['doc_id' => $this->doc_id, 'doc_sec_id' => $this->doc_sec_id, 'doc_created' => $this->doc_created, 'ekis_id' => $this->ekis_id, 'doc_state' => $this->doc_state, 'doc_format' => $this->doc_format]; if (!Yii::$app->user->can(User::USER_GROUP_MODERATOR)) { $aFilters['doc_us_id'] = Yii::$app->user->getId(); } else { /** @var User $obUser */ if (empty($this->conferenceid)) { // этот if тут для того, чтобы модераторы секций могли выгрузить вообще все доклады из конференции // потому что из-за их изголяния с разделением на персональных участников и от организаций, и разделением секций // по этому признаку, ранее зарегистрированные доклады перехолдят в другие секции и их невоможно увидеть в нужной секции // в контроллере я сюда ($this->conferenceid) загружаю конференции, в которых юзер главный модератор $obUser = Yii::$app->user->identity; if (!empty($obUser->sectionids)) { $aFilters = ['doc_sec_id' => $obUser->sectionids]; } } } if ($this->conferenceid) { $query->andFilterWhere([Conference::tableName() . '.cnf_id' => $this->conferenceid]); } $query->andFilterWhere($aFilters); if (!empty($this->doc_lider_fam)) { $query->andFilterWhere(['like', 'doc_lider_fam', $this->doc_lider_fam])->andFilterWhere(['like', 'doc_lider_name', $this->doc_lider_name])->andFilterWhere(['like', 'doc_lider_otch', $this->doc_lider_otch])->andFilterWhere(['like', 'doc_lider_email', $this->doc_lider_email])->andFilterWhere(['like', 'doc_lider_phone', $this->doc_lider_phone]); } $query->andFilterWhere(['like', 'doc_type', $this->doc_type])->andFilterWhere(['like', 'doc_subject', $this->doc_subject])->andFilterWhere(['like', 'doc_description', $this->doc_description])->andFilterWhere(['like', 'doc_lider_org', $this->doc_lider_org])->andFilterWhere(['like', 'doc_lider_group', $this->doc_lider_group])->andFilterWhere(['like', 'doc_lider_position', $this->doc_lider_position])->andFilterWhere(['like', 'doc_lider_lesson', $this->doc_lider_lesson]); return $dataProvider; }
/** * @return \yii\db\ActiveQuery */ public function getDoclads() { return $this->hasMany(Doclad::className(), ['doc_sec_id' => 'sec_id']); }
} EOT; $this->registerCss($sCss); /* @var $this yii\web\View */ /* @var $model app\models\Doclad */ /* @var $form yii\widgets\ActiveForm */ // <div class="doclad-form"> // </div> ?> <?php $form = ActiveForm::begin(['id' => 'doclad-form', 'options' => ['class' => 'form-horizontal', 'enctype' => 'multipart/form-data'], 'fieldConfig' => ['template' => '{label}{input}{error}', 'options' => ['class' => '']], 'enableAjaxValidation' => true, 'enableClientValidation' => false, 'validateOnBlur' => false, 'validateOnChange' => false, 'validateOnType' => false, 'validateOnSubmit' => true]); ?> <?php $aFormats = Doclad::getAllFormats(); $sIdFormat = Html::getInputId($model, 'doc_format'); $aButtons = []; $aButtons = []; foreach ($aFormats as $k => $v) { if ($k == 0) { continue; } $aButtons[] = Html::button($v, ['class' => 'btn ' . ($model->doc_format == $k ? 'btn-success' : 'btn-default') . ' buttonformat', 'data-formatval' => $k]); } $sJs = <<<EOT var aStatusButtons = jQuery(".buttonformat"), oState = jQuery("#{$sIdFormat}"), nState = oState.val(); aStatusButtons.on(
/** * Finds the Doclad model based on its primary key value. * If the model is not found, a 404 HTTP exception will be thrown. * @param integer $id * @return Doclad the loaded model * @throws NotFoundHttpException if the model cannot be found */ protected function findModel($id) { if (($model = Doclad::findOne($id)) !== null) { return $model; } else { throw new NotFoundHttpException('The requested page does not exist.'); } }
} EOT; $this->registerCss($sCss); /* @var $this yii\web\View */ /* @var $model app\models\Doclad */ /* @var $form yii\widgets\ActiveForm */ // <div class="doclad-form"> // </div> ?> <?php $form = ActiveForm::begin(['id' => 'doclad-form', 'options' => ['class' => 'form-horizontal', 'enctype' => 'multipart/form-data'], 'fieldConfig' => ['template' => '{label}{input}{error}', 'options' => ['class' => '']], 'enableAjaxValidation' => true, 'enableClientValidation' => false, 'validateOnBlur' => false, 'validateOnChange' => false, 'validateOnType' => false, 'validateOnSubmit' => true]); ?> <?php $aStatus = Doclad::getAllStatuses(); $sIdState = Html::getInputId($model, 'doc_state'); $aButtons = []; foreach ($aStatus as $k => $v) { if ($k == 0) { continue; } $aButtons[] = Html::button($v, ['class' => 'btn ' . ($model->doc_state == $k ? 'btn-success' : 'btn-default') . ' buttonstatus', 'data-statusval' => $k, 'data-showcomment' => $k != Doclad::DOC_STATUS_APPROVE ? 1 : 0]); } $sJs = <<<EOT var aStatusButtons = jQuery(".buttonstatus"), oComment = jQuery(".commentarea"), oState = jQuery("#{$sIdState}"), nState = oState.val(); oComment.hide();
<?php use yii\helpers\Html; use yii\grid\GridView; use app\models\Conference; use app\models\Doclad; /* @var $this yii\web\View */ /* @var $searchModel app\models\SectionSearch */ /* @var $dataProvider yii\data\ActiveDataProvider */ $this->title = 'Секции'; $this->params['breadcrumbs'][] = $this->title; $aDocladTypes = Doclad::getAllTypes(); ?> <div class="section-index"> <!-- h1><?php echo Html::encode($this->title); ?> </h1 --> <?php // echo $this->render('_search', ['model' => $searchModel]); ?> <p> <?php echo Html::a('Добавить секцию', ['create'], ['class' => 'btn btn-success']); ?> </p> <?php echo GridView::widget(['dataProvider' => $dataProvider, 'filterModel' => $searchModel, 'columns' => ['sec_title', ['attribute' => 'sec_cnf_id', 'class' => 'yii\\grid\\DataColumn', 'filter' => Conference::getList(), 'value' => function ($model, $key, $index, $column) {
/** * Отношение к докладу * * @return \yii\db\ActiveQuery */ public function getDoclad() { return $this->hasOne(Doclad::className(), ['doc_id' => 'prs_doc_id']); }
return $model->section !== null ? Html::encode($model->section->conference->cnf_title) . '<br />' . Html::encode($model->section->sec_title) : ''; }], ['class' => 'yii\\grid\\DataColumn', 'attribute' => 'doc_subject', 'format' => 'raw', 'value' => function ($model, $key, $index, $column) { $sFiles = ''; $aFiles = $model->files; if (count($aFiles) > 0) { $sFiles = array_reduce($aFiles, function ($sRes, $item) { /** @var File $item */ return '<br />' . Html::a($item->file_orig_name, str_replace(DIRECTORY_SEPARATOR, '/', $item->file_name)) . $sRes; }, ''); } /** @var $model app\models\Doclad */ return Html::encode($model->doc_subject) . (Yii::$app->user->identity->isMainModerator($model) ? ' <span class="glyphicon glyphicon-star"></span>' : '') . ($sFiles != '' ? '<br />' : '') . $sFiles . '<br />' . '<br />' . $model->getFullState(); }], ['class' => 'yii\\grid\\DataColumn', 'attribute' => 'doc_type', 'filter' => Doclad::getAllTypes(), 'format' => 'raw', 'value' => function ($model, $key, $index, $column) { /** @var $model app\models\Doclad */ return Html::encode($model->typeTitle()) . ($model->doc_format != Doclad::DOC_FORMAT_NOFORMAT ? '<br />' . Html::encode($model->getFormat()) : ''); }], ['class' => 'yii\\grid\\DataColumn', 'attribute' => 'doc_state', 'filter' => Doclad::getAllStatuses(), 'format' => 'raw', 'value' => function ($model, $key, $index, $column) { /** @var $model app\models\Doclad */ $a = [Doclad::DOC_STATUS_NEW => '', Doclad::DOC_STATUS_APPROVE => 'ok', Doclad::DOC_STATUS_NOT_APPROVE => 'remove', Doclad::DOC_STATUS_REVISION => 'refresh']; return $a[$model->doc_state] != '' ? '<span class="glyphicon glyphicon-' . $a[$model->doc_state] . '"></span>' : ''; }], ['class' => 'yii\\grid\\DataColumn', 'attribute' => 'doc_lider_fam', 'format' => 'raw', 'value' => function ($model, $key, $index, $column) { /** @var $model app\models\Doclad */ return Html::encode($model->getLeadername(false)) . '<br />' . Yii::$app->formatter->asEmail($model->doc_lider_email) . ', ' . Html::a(str_replace(['(', ')'], [' (', ') '], $model->doc_lider_phone), 'tel:+' . preg_replace('|[^\\d]|', '', $model->doc_lider_phone)); }], ['class' => 'yii\\grid\\ActionColumn', 'template' => '{view} {filedownload}', 'buttons' => ['view' => function ($url, $model, $key) { /** @var Doclad $model */ $options = []; $sIcon = 'pencil'; if ($model->doc_state == Doclad::DOC_STATUS_APPROVE) { $sIcon = 'eye-open'; if (count($model->files) > 0 && $model->doc_format == Doclad::DOC_FORMAT_NOFORMAT) { $sIcon = 'info-sign'; }
<div class="section-form"> <?php $form = ActiveForm::begin(); ?> <?php echo $form->field($model, 'sec_title')->textInput(['maxlength' => true]); ?> <?php echo $form->field($model, 'sec_cnf_id')->dropDownList(Conference::getList()); ?> <?php echo $form->field($model, 'sec_doclad_type')->dropDownList(array_merge(['' => ''], Doclad::getAllTypes())); ?> <?php echo ''; ?> <div class="form-group"> <?php echo Html::submitButton($model->isNewRecord ? 'Создать' : 'Сохранить', ['class' => 'btn btn-success']); ?> </div> <?php ActiveForm::end(); ?>