/**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $query = Tourtype::find();
     $dataProvider = new ActiveDataProvider(['query' => $query]);
     $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;
     }
     $query->andFilterWhere(['id' => $this->id]);
     $query->andFilterWhere(['like', 'name', $this->name])->andFilterWhere(['like', 'parent', $this->parent])->andFilterWhere(['like', 'description', $this->description])->andFilterWhere(['like', 'icon', $this->icon]);
     return $dataProvider;
 }
 public function actionShowDetail($id)
 {
     $this->layout = "main";
     $model = $this->findModel($id);
     $tourtype = Tourtype::findOne($model->id_tourtype);
     $related = $tourtype->getTours()->orderBy(['regdate' => SORT_DESC])->limit(4)->all();
     return $this->render('show-detail', ['model' => $model, 'related' => $related]);
 }
Example #3
0
 public function getTourtype()
 {
     return $this->hasOne(Tourtype::className(), ['id' => 'id_tourtype']);
 }
Example #4
0
                <option value=" ">All</option>
                <option value="1" selected="selected">Active</option>
                <option value="0">Deactive</option>
            </select>
        </li>
    </ul>

    <?php 
Pjax::begin();
?>
    <?php 
echo GridView::widget(['dataProvider' => $dataProvider, 'filterModel' => $searchModel, 'options' => ['width' => '10%'], 'columns' => [['class' => 'yii\\grid\\SerialColumn'], ['class' => 'yii\\grid\\CheckboxColumn', 'headerOptions' => ['class' => 'sr-only']], ['attribute' => 'code', 'options' => ['width' => '5%']], ['attribute' => 'smallimg', 'format' => 'image', 'options' => ['width' => '100px', 'height' => '100px'], 'value' => function ($model) {
    return '@web/images/' . $model->smallimg;
}], ['attribute' => 'name', 'format' => 'html', 'value' => function ($model) {
    return Html::a('' . $model->name, ['tour/show-detail/' . $model->id]);
}], ['attribute' => 'id_tourtype', 'value' => 'tourtype.name', 'filter' => \yii\helpers\ArrayHelper::map(\app\models\Tourtype::find()->all(), 'id', 'name'), 'options' => ['width' => '200px']], ['attribute' => 'length', 'options' => ['width' => '3%']], 'startfrom', 'keyword', ['attribute' => 'status', 'value' => 'status', 'contentOptions' => ['class' => 'sr-only'], 'label' => '', 'headerOptions' => ['class' => 'sr-only'], 'filterOptions' => ['class' => 'sr-only']], ['attribute' => 'hot', 'value' => function ($model) {
    $hot = ['0' => 'No', '1' => 'Top Position', '2' => 'Bottom Position'];
    return $hot[$model->hot];
}], ['class' => 'yii\\grid\\ActionColumn', 'urlCreator' => function ($action, $model, $key, $index) {
    if ($action === 'view') {
        $url = '/tour/show-detail/' . $model->id;
        return $url;
    } elseif ($action === 'update') {
        $url = '/tour/update/' . $model->id;
        return $url;
    } else {
        $url = '/tour/delete/' . $model->id;
        return $url;
    }
}]]]);
?>
Example #5
0
/* @var $model app\models\Article */
/* @var $form yii\widgets\ActiveForm */
?>

<div class="article-form">

    <?php 
$form = ActiveForm::begin(['layout' => 'horizontal', 'fieldConfig' => ['template' => "{label}\n{beginWrapper}\n{input}\n{hint}\n{error}\n{endWrapper}", 'horizontalCssClasses' => ['label' => 'col-sm-1', 'offset' => 'col-sm-offset-1', 'wrapper' => 'col-sm-10', 'error' => '', 'hint' => '']]]);
?>

    <?php 
echo $form->field($model, 'title')->textInput(['maxlength' => true]);
?>

    <?php 
echo $form->field($model, 'type')->dropDownList(\yii\helpers\ArrayHelper::map(\app\models\Tourtype::find()->all(), 'id', 'name'), ['prompt' => '-- Choose a tourtype --']);
?>

    <?php 
echo $form->field($model, 'regdate', ['options' => ['class' => 'sr-only']])->textInput(['value' => date('Y-m-d')]);
?>

    <?php 
echo $form->field($model, 'editdate', ['options' => ['class' => 'sr-only']])->textInput(['value' => date('Y-m-d')]);
?>

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

    <?php 
 private function ul($model)
 {
     $parent = "<ul>";
     foreach ($model as $tourType) {
         foreach ($tourType as $key => $value) {
             //$id = 0;
             if ($key == 'id') {
                 $id = $value;
                 $view = Url::to(['tourtype/view', 'id' => $id]);
                 $update = Url::to(['tourtype/update', 'id' => $id]);
                 $delete = Url::to(['tourtype/delete', 'id' => $id]);
             }
             if ($key == 'name') {
                 $parent .= "<li value='" . $value . "'>" . $value . ' ( ' . Yii::$app->db->createCommand('select count(id) from tour where id_tourtype = ' . $id)->queryAll()[0]['count(id)'] . ' )';
                 $parent .= "<div class='action sr-only'>\n    <a href='{$update}' data-method='post' class='text-success'>\n        <span class='glyphicon glyphicon-pencil'></span>\n    </a>\n    <a href='{$delete}' data-confirm='Are you sure you want to delete this item?' data-method='post' class='text-danger'>\n        <span class='glyphicon glyphicon-trash'></span>\n    </a>\n</div>";
                 $child = \app\models\Tourtype::find()->where(['parent' => $value])->all();
                 if (count($child)) {
                     $ul = $this->ul($child);
                     $parent .= $ul;
                 }
                 $parent .= "</li>";
             }
         }
     }
     $parent .= "</ul>";
     return $parent;
 }
Example #7
0
    <p>
        <?php 
echo Html::a('Create Article', ['create'], ['class' => 'btn btn-success']);
?>
        <?php 
echo Html::button('Delete Article', ['class' => 'btn btn-danger', 'id' => 'delete_article']);
?>
    </p>

    <?php 
echo GridView::widget(['dataProvider' => $dataProvider, 'filterModel' => $searchModel, 'columns' => [['class' => 'yii\\grid\\SerialColumn'], ['class' => 'yii\\grid\\CheckboxColumn', 'headerOptions' => ['class' => 'sr-only']], ['attribute' => 'smallimg', 'content' => function ($model) {
    $img = \yii\helpers\Html::img('@web/images/' . $model->smallimg);
    return $img;
}, 'format' => 'image', 'options' => ['width' => '17%']], ['attribute' => 'title', 'content' => function ($model) {
    return Html::a('' . $model->title, ['/article/' . implode('-', explode(' ', $model->title))]);
}, 'options' => ['width' => '20%']], ['attribute' => 'type', 'value' => 'tourtype.name', 'options' => ['width' => '15%'], 'filter' => \yii\helpers\ArrayHelper::map(\app\models\Tourtype::find()->all(), 'id', 'name')], 'briefinfo:ntext', ['attribute' => 'status', 'options' => ['width' => '150px'], 'value' => function ($model) {
    return $model->status ? "Active" : "Deactive";
}, 'filter' => ['1' => 'Active', '0' => 'Deactive']], ['attribute' => 'hot', 'options' => ['width' => '7%'], 'value' => function ($model) {
    return $model->hot == 1 ? 'Hot' : '';
}], ['class' => 'yii\\grid\\ActionColumn', 'options' => ['width' => '7%']]]]);
?>

</div>
<?php 
$js = <<<JS
\$(document).ready(function(){
    var keys,
        deleteArticle = function deleteArticle(){
        \$.post('/article/delete-multi-article', {keys: keys}, function(data, status){
            if(status){
                for(var iKey = 0; iKey < keys.length; iKey++){
Example #8
0
/* @var $model app\models\Tourtype */
/* @var $form yii\widgets\ActiveForm */
?>

<div class="tourtype-form">

    <?php 
$form = ActiveForm::begin(['layout' => 'horizontal', 'fieldConfig' => ['template' => "{label}\n{beginWrapper}\n{input}\n{hint}\n{error}\n{endWrapper}", 'horizontalCssClasses' => ['label' => 'col-sm-2', 'wrapper' => 'col-sm-10', 'error' => '', 'hint' => '']]]);
?>

    <?php 
echo $form->field($model, 'name')->textInput(['maxlength' => true]);
?>

    <?php 
echo $form->field($model, 'parent')->dropDownList(\yii\helpers\ArrayHelper::map(\app\models\Tourtype::find()->where(['<>', 'parent', 'article'])->all(), 'parent', 'parent'), ['prompt' => '--Choose parent--']);
?>
    <?php 
echo $form->field($model, 'description')->textInput(['maxlength' => true]);
?>

    <?php 
echo $form->field($model, 'icon', ['options' => ['class' => 'sr-only']])->textInput(['maxlength' => true, 'readonly' => true]);
?>
    <?php 
echo $form->field($model, 'simg')->label('Smallimg')->widget(FileInput::classname(), ['options' => ['accept' => 'image/*', 'name' => 'smallimg'], 'pluginOptions' => ['uploadUrl' => \yii\helpers\Url::to(['/file-upload/upload']), 'maxFileCount' => 1, 'autoReplace' => true], 'pluginEvents' => ['fileuploaded' => 'function(event, data, previewId, index){
                var fileName = data.files[index].name.replace(" ", "_");

                $("#tourtype-icon").val(fileName);
            }', 'filesuccessremove' => 'function(event, id){
                var name = $("#" + id + " img").attr("title"),