Пример #1
0
 /**
  * @param null $category
  *
  * @return \yii\db\ActiveQuery
  */
 public function getCategory($category = null)
 {
     if (!$category) {
         $category = $this->category_id ? $this->category_id : 1;
     }
     return WorkCategory::findOne($category);
 }
 /**
  * Finds the WorkCategory model based on its primary key value.
  * If the model is not found, a 404 HTTP exception will be thrown.
  * @param integer $id
  * @return WorkCategory the loaded model
  * @throws NotFoundHttpException if the model cannot be found
  */
 protected function findModel($id)
 {
     if (($model = WorkCategory::findOne($id)) !== null) {
         return $model;
     } else {
         throw new NotFoundHttpException('The requested page does not exist.');
     }
 }
Пример #3
0
 /**
  * @return \yii\db\ActiveQuery
  */
 public function getCategories()
 {
     return $this->hasMany(WorkCategory::className(), ['id' => 'category_id'])->viaTable('jury_category', ['jury_id' => 'id']);
 }
Пример #4
0
 /**
  * @return array
  */
 public function getCategories()
 {
     $models = WorkCategory::find()->asArray()->all();
     return ArrayHelper::map($models, 'id', 'title');
 }
Пример #5
0
<div class="work-form">
    <?php 
$form = ActiveForm::begin(['options' => ['enctype' => 'multipart/form-data']]);
?>
    <?php 
if (Yii::$app->user->can('editWork')) {
    ?>
        <?php 
    echo $form->field($model, 'user_id')->dropDownList(ArrayHelper::map(\app\models\Participant::find()->asArray()->all(), 'user_id', 'name'));
    ?>
    <?php 
}
?>

    <?php 
echo $form->field($model, 'category_id')->dropDownList(ArrayHelper::map(\app\models\WorkCategory::find()->asArray()->all(), 'id', 'title'), ['onchange' => '
                $.post( "' . Yii::$app->urlManager->createUrl('work/get-file-info?id=') . '"+$(this).val(), function( data ) {
                  $( "#fileInfoHint" ).html( data );
                });
            ']);
?>

    <?php 
echo $form->field($model, 'file')->fileInput()->hint($this->context->actionGetFileInfo($model->category_id), ['id' => 'fileInfoHint']);
?>

    <?php 
echo $form->field($model, 'title')->textInput();
?>

    <?php 
Пример #6
0
 /**
  * Generates hint for file input field depending on selected category
  *
  * @param $id
  *
  * @return string
  */
 public function actionGetFileInfo($id = null)
 {
     if (!$id) {
         $id = 1;
     }
     $cat = WorkCategory::findOne($id);
     return $this->renderPartial('_file-info', ['size' => $cat->max_file_size, 'exts' => $cat->file_extensions, 'additional' => $cat->file_text]);
 }