Esempio n. 1
0
 /**
  * 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;
 }
 /**
  * @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]);
 }
 /**
  * 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.'));
     }
 }
Esempio n. 4
0
<?php

use pavlinter\admpages2\Module;
use yii\helpers\Html;
/* @var $this yii\web\View */
/* @var $model pavlinter\admpages2\models\Page */
/* @var $id_parent integer */
Yii::$app->i18n->disableDot();
$this->title = Module::t('', 'Create Page');
$this->params['breadcrumbs'] = [];
$model::breadcrumbsTree($this->params['breadcrumbs'], $id_parent, ['lastLink' => true]);
array_unshift($this->params['breadcrumbs'], ['label' => Module::t('', 'Pages'), 'url' => ['index', 'id_parent' => 0]]);
$this->params['breadcrumbs'][] = $this->title;
Yii::$app->i18n->resetDot();
?>
<div class="page-create">

    <h1><?php 
echo Html::encode($this->title);
?>
</h1>

    <?php 
echo $this->render('_form', ['model' => $model, 'id_parent' => $id_parent]);
?>

</div>
Esempio n. 5
0
?>

    <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 
Esempio n. 6
0
    $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::getInstance()->files[$model->type])) {
        return null;
    }
    return Html::a('<span class="fa fa-cloud-download"></span>', ['files', 'id' => $model->id], ['title' => Module::t('title', 'Files', ['dot' => false]), 'data-pjax' => '0']);
}]]]]);
?>

</div>
Esempio n. 7
0
 /**
  * @return \yii\db\ActiveQuery
  */
 public function getTranslations()
 {
     $module = Module::getInst();
     return $this->hasMany($module->manager->pageLangClass, ['page_id' => 'id'])->indexBy('language_id');
 }
Esempio n. 8
0
 /**
  * @return \yii\db\ActiveQuery
  */
 public function getPage()
 {
     $module = Module::getInst();
     return $this->hasOne($module->manager->pageClass, ['id' => 'page_id']);
 }
Esempio n. 9
0
Assets::addLangFile(Yii::$app->language, $this);
$this->registerJs('
    var btn = $.fn.button.noConflict();
    $.fn.btn = btn;
    $("#elfinder").elfinder({
        url  : "' . Url::to(ArrayHelper::merge(['/adm/elfinder/connect', 'startPath' => $startPath], $elfinderData)) . '",
        lang : "' . Yii::$app->language . '",
        customData: {"' . Yii::$app->request->csrfParam . '":"' . Yii::$app->request->csrfToken . '"},
        rememberLastDir : false,
    });
');
?>
<div class="admpages-files">

    <h1><?php 
echo Html::encode($this->title);
?>
</h1>

    <p>
        <?php 
echo Html::a(Module::t('', 'Update'), ['update', 'id' => $model->id, 'id_parent' => $id_parent], ['class' => 'btn btn-primary']);
?>
        <?php 
echo Html::a(Module::t('', 'Delete'), ['delete', 'id' => $model->id, 'id_parent' => $id_parent], ['class' => 'btn btn-danger', 'data' => ['confirm' => Module::t('', 'Are you sure you want to delete this item?', ['dot' => false]), 'method' => 'post']]);
?>
    </p>

    <div id="elfinder"></div>
</div>