Exemplo n.º 1
0
 /**
  * @inheritdoc
  */
 public function init()
 {
     parent::init();
     if ($this->className() == Category::className()) {
         $this->visible = 1;
     }
 }
Exemplo n.º 2
0
 /**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $query = Category::find()->joinWith('translations');
     $dataProvider = new ActiveDataProvider(['query' => $query, 'pagination' => ['pageSize' => Yii::$app->request->cookies->getValue('_grid_page_size', 20)], 'sort' => ['defaultOrder' => ['id' => SORT_DESC]]]);
     $this->load($params);
     if (!$this->validate()) {
         return $dataProvider;
     }
     $query->andFilterWhere(['id' => $this->id, 'visible' => $this->visible, 'created_by' => $this->created_by, 'updated_by' => $this->updated_by, 'created_at' => $this->created_at, 'updated_at' => $this->updated_at]);
     $query->andFilterWhere(['like', 'slug', $this->slug])->andFilterWhere(['like', 'title', $this->title])->andFilterWhere(['like', 'description', $this->description]);
     return $dataProvider;
 }
Exemplo n.º 3
0
 /**
  * Return all albums.
  *
  * @param bool $asArray return array
  * @param bool $withCategories Two-dimensional array with albums categories
  *
  * @return static[]
  */
 public static function getAlbums($asArray = false, $withCategories = false)
 {
     if (!$withCategories) {
         $result = static::find()->all();
         return $asArray ? ArrayHelper::map($result, 'id', 'title') : $result;
     } else {
         $result = [];
         $categories = Category::find()->all();
         foreach ($categories as $category) {
             $result[$category->title] = ArrayHelper::map($category->albums, 'id', 'title');
         }
         return $result;
     }
 }
Exemplo n.º 4
0
    <div class="panel panel-default">
        <div class="panel-body">

            <div class="row">
                <div class="col-sm-12 text-right">
                    <?php 
echo GridPageSize::widget(['pjaxId' => 'album-grid-pjax']);
?>
                </div>
            </div>

            <?php 
Pjax::begin(['id' => 'album-grid-pjax']);
?>

            <?php 
echo GridView::widget(['id' => 'album-grid', 'dataProvider' => $dataProvider, 'filterModel' => $searchModel, 'bulkActionOptions' => ['gridId' => 'album-grid', 'actions' => [Url::to(['bulk-delete']) => Yii::t('yee', 'Delete')]], 'columns' => [['class' => 'yeesoft\\grid\\CheckboxColumn', 'options' => ['style' => 'width:10px']], ['class' => 'yeesoft\\grid\\columns\\TitleActionColumn', 'controller' => '/media/album', 'title' => function (Album $model) {
    return Html::a($model->title, ['/media/album/update', 'id' => $model->id], ['data-pjax' => 0]);
}, 'buttonsTemplate' => '{update} {delete}'], 'description:ntext', ['attribute' => 'category_id', 'filter' => Category::getCategories(true), 'value' => function (Album $model) {
    return $model->category instanceof Category ? $model->category->title : Yii::t('yii', '(not set)');
}, 'format' => 'raw'], ['class' => 'yeesoft\\grid\\columns\\StatusColumn', 'attribute' => 'visible']]]);
?>

            <?php 
Pjax::end();
?>
        </div>
    </div>
</div>
Exemplo n.º 5
0
                    <?php 
echo $form->field($model, 'description')->textarea(['rows' => 6]);
?>

                </div>

            </div>
        </div>

        <div class="col-md-3">

            <div class="panel panel-default">
                <div class="panel-body">
                    <div class="record-info">
                        <?php 
echo $form->field($model, 'category_id')->dropDownList(Category::getCategories(true), ['prompt' => '']);
?>

                        <?php 
echo $form->field($model, 'visible')->checkbox();
?>

                        <div class="form-group">
                            <?php 
if ($model->isNewRecord) {
    ?>
                                <?php 
    echo Html::submitButton(Yii::t('yee', 'Create'), ['class' => 'btn btn-primary']);
    ?>
                                <?php 
    echo Html::a(Yii::t('yee', 'Cancel'), ['/media/album/index'], ['class' => 'btn btn-default']);