コード例 #1
0
ファイル: PageSearch.php プロジェクト: pavlinter/yii2-adm-app
 /**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search($params, $id_parent)
 {
     $module = Module::getInst();
     $pageTable = static::tableName();
     $pageLangTable = forward_static_call(array($module->manager->pageLangClass, 'tableName'));
     $query = static::find()->from(['p' => $pageTable])->innerJoin(['l' => $pageLangTable], 'l.page_id=p.id AND l.language_id=:language_id', [':language_id' => Yii::$app->getI18n()->getId()]);
     $loadParams = $this->load($params);
     if ($this->id_parent) {
         $query->innerJoin(['l2' => $pageLangTable], 'l2.page_id=p.id_parent AND l2.language_id=:language_id', [':language_id' => Yii::$app->getI18n()->getId()]);
     }
     $query->with(['parent', 'translations']);
     $dataProvider = new ActiveDataProvider(['query' => $query, 'sort' => ['defaultOrder' => ['weight' => SORT_ASC]]]);
     if ($id_parent !== false) {
         if (empty($id_parent)) {
             $query->where(['id_parent' => null]);
         } else {
             $query->where(['id_parent' => $id_parent]);
         }
     }
     if (!($loadParams && $this->validate())) {
         return $dataProvider;
     }
     $dataProvider->sort->attributes['name']['asc'] = ['l.name' => SORT_ASC];
     $dataProvider->sort->attributes['name']['desc'] = ['l.name' => SORT_DESC];
     $dataProvider->sort->attributes['title']['asc'] = ['l.title' => SORT_ASC];
     $dataProvider->sort->attributes['title']['desc'] = ['l.title' => SORT_DESC];
     $dataProvider->sort->attributes['alias']['asc'] = ['l.alias' => SORT_ASC];
     $dataProvider->sort->attributes['alias']['desc'] = ['l.alias' => SORT_DESC];
     $query->andFilterWhere(['p.id' => $this->id, 'p.weight' => $this->weight, 'p.layout' => $this->layout, 'p.type' => $this->type, 'p.visible' => $this->visible, 'p.active' => $this->active]);
     $query->andFilterWhere(['like', 'l.name', $this->name])->andFilterWhere(['like', 'l.title', $this->title])->andFilterWhere(['like', 'l.alias', $this->alias]);
     if ($this->id_parent) {
         $query->andFilterWhere(['like', 'l2.name', $this->id_parent]);
     }
     return $dataProvider;
 }
コード例 #2
0
 /**
  * @return string
  * @throws NotFoundHttpException
  */
 public function actionMain()
 {
     /* @var $module \pavlinter\admpages2\Module */
     $module = Module::getInst();
     $module->layout = $module->pageLayout;
     /* @var $model \pavlinter\admpages2\models\Page */
     $model = $module->manager->createPageQuery('getPage', null, ['where' => ['type' => 'main'], 'orderBy' => ['weight' => SORT_ASC]]);
     $module::$modelPage = $model;
     if (isset($module->pageRedirect[$model->layout])) {
         $params = $module->pageRedirect[$model->layout];
         if ($params instanceof \Closure) {
             $params = call_user_func($params, $model, $module);
         }
         $route = ArrayHelper::remove($params, 0);
         $parts = Yii::$app->createController($route);
         if (is_array($parts)) {
             /* @var $controller Controller */
             list($controller, $actionID) = $parts;
             $result = $controller->runAction($actionID, $params);
         } else {
             $id = Yii::$app->getUniqueId();
             throw new InvalidRouteException('Unable to resolve the request "' . ($id === '' ? $route : $id . '/' . $route) . '".');
         }
         if ($result instanceof \yii\web\Response) {
             return $result;
         } else {
             $response = Yii::$app->getResponse();
             if ($result !== null) {
                 $response->data = $result;
             }
             return $response;
         }
     }
     return $this->render('@vendor/pavlinter/yii2-adm-pages2/admpages2/views/default/' . $model->layout, ['model' => $model]);
 }
コード例 #3
0
 /**
  * Finds the Page model based on its primary key value.
  * If the model is not found, a 404 HTTP exception will be thrown.
  * @param string $id
  * @return \pavlinter\admpages2\models\Page the loaded model
  * @throws NotFoundHttpException if the model cannot be found
  */
 protected function findModel($id)
 {
     $model = Module::getInst()->manager->createPageQuery('find')->with(['translations'])->where(['id' => $id])->one();
     if ($model !== null) {
         return $model;
     } else {
         throw new NotFoundHttpException(Yii::t('yii', 'Page not found.'));
     }
 }
コード例 #4
0
ファイル: _form.php プロジェクト: pavlinter/yii2-adm-pages2
?>

    <div class="row">
        <div class="col-xs-12 col-sm-6 col-md-3">
            <?php 
echo $form->field($model, 'id_parent')->widget(\kartik\widgets\Select2::classname(), ['data' => $parentsData, 'options' => ['placeholder' => Module::t('', 'Select ...', ['dot' => false])], 'pluginOptions' => ['allowClear' => true]]);
?>
        </div>
        <div class="col-xs-12 col-sm-6 col-md-3">
        <?php 
echo $form->field($model, 'layout')->widget(\kartik\widgets\Select2::classname(), ['data' => Module::getInst()->pageLayouts]);
?>
        </div>
        <div class="col-xs-12 col-sm-6 col-md-3">
            <?php 
echo $form->field($model, 'type')->widget(\kartik\widgets\Select2::classname(), ['data' => Module::getInst()->pageTypes]);
?>
        </div>

        <div class="col-xs-12 col-sm-6 col-md-3">
            <?php 
echo $form->field($model, 'date')->widget(\kartik\datetime\DateTimePicker::classname(), ['pluginOptions' => ['todayHighlight' => true, 'todayBtn' => true, 'autoclose' => true, 'minuteStep' => 1, 'format' => 'yyyy-mm-dd hh:ii:00']]);
?>
        </div>

    </div>

    <section class="panel adm-langs-panel">
        <header class="panel-heading bg-light">
            <ul class="nav nav-tabs nav-justified text-uc">
                <?php 
コード例 #5
0
ファイル: Page.php プロジェクト: pavlinter/yii2-adm-pages2
 /**
  * @return \yii\db\ActiveQuery
  */
 public function getTranslations()
 {
     $module = Module::getInst();
     return $this->hasMany($module->manager->pageLangClass, ['page_id' => 'id'])->indexBy('language_id');
 }
コード例 #6
0
 /**
  * @return \yii\db\ActiveQuery
  */
 public function getPage()
 {
     $module = Module::getInst();
     return $this->hasOne($module->manager->pageClass, ['id' => 'page_id']);
 }
コード例 #7
0
ファイル: index.php プロジェクト: pavlinter/yii2-adm-pages2
    $url = ['delete', 'id' => $model->id];
    if ($model->id_parent) {
        $url['id_parent'] = $model->id_parent;
    } else {
        $url['id_parent'] = 0;
    }
    return Html::a('<span class="glyphicon glyphicon-trash"></span>', $url, ['title' => Module::t('title', 'Delete', ['dot' => false]), 'data-confirm' => Module::t('', 'Are you sure you want to delete this item?', ['dot' => false]), 'data-method' => 'post', 'data-pjax' => '0']);
}, 'view' => function ($url, $model) {
    if ($model->alias) {
        return Html::a('<span class="glyphicon glyphicon-eye-open"></span>', $model->url(), ['title' => Module::t('title', 'View', ['dot' => false]), 'data-pjax' => '0', 'target' => '_blank']);
    }
}, 'copy' => function ($url, $model) {
    $url = ['create', 'id' => $model->id];
    if ($model->id_parent) {
        $url['id_parent'] = $model->id_parent;
    } else {
        $url['id_parent'] = 0;
    }
    return Html::a('<span class="fa fa-copy"></span>', $url, ['title' => Module::t('title', 'Copy', ['dot' => false]), 'data-pjax' => '0']);
}, 'subpages' => function ($url, $model) {
    return Html::a('<span class="fa fa-plus-circle"></span>', ['', 'id_parent' => $model->id], ['title' => Module::t('title', 'Sub pages', ['dot' => false]), 'data-pjax' => '0']);
}, 'files' => function ($url, $model) {
    if (!isset(Module::getInst()->files[$model->type])) {
        return null;
    }
    return Html::a('<span class="fa fa-cloud-download"></span>', ['files', 'id' => $model->id, 'id_parent' => $model->id], ['title' => Module::t('title', 'Files', ['dot' => false]), 'data-pjax' => '0']);
}]]]]);
?>

</div>