Skip to content

Commit

Permalink
prepare for new release
Browse files Browse the repository at this point in the history
  • Loading branch information
glpzzz committed Sep 4, 2020
1 parent 1164f67 commit 4590ace
Show file tree
Hide file tree
Showing 12 changed files with 141 additions and 35 deletions.
5 changes: 3 additions & 2 deletions controllers/backend/PageController.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,14 +36,15 @@ public function actionIndex($parent_id = null)
if ($parent) {
$module = $this->module->id;
$dataProvider->query = $parent->getPages();
$dataProvider->query->orderBy($parent->type->sort_by);
$dataProvider->pagination->route = "/$module/page/update";
$dataProvider->pagination->pageParam = "subpages-{$parent->id}";
$dataProvider->pagination->pageSizeParam = "per-page-{$parent->id}";
} else {
$dataProvider->query = Yii::$app->website->getRootPages();
$dataProvider->query->orderBy('position');
}

$dataProvider->query->orderBy('position');

$renderMethod = isset($parent) ? 'renderPartial' : 'render';
$renderView = isset($parent)
? file_exists(Yii::getAlias("@daxslab/website/views/backend/page/_list-{$parent->type->name}.php"))
Expand Down
2 changes: 1 addition & 1 deletion controllers/frontend/BlockController.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public function actionView(array $params = [])
$dataProvider = new ArrayDataProvider([
'allModels' => $model->getPages()
->byStatus(Page::STATUS_POST_PUBLISHED)
->orderBy('created_at DESC')
->orderBy($model->type->sort_by)
->limit(isset($params['limit']) ? $params['limit'] : 3)
->all()
]);
Expand Down
6 changes: 3 additions & 3 deletions controllers/frontend/PageController.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public function actionHome($_lang = null)

$homePage = Yii::$app->website->getRootPages()->byLanguage($_lang)->orderBy('position')->one();
if (!$homePage) {
throw new NotFoundHttpException(Yii::t('website','The requested page does not exist.'));
throw new NotFoundHttpException(Yii::t('website', 'The requested page does not exist.'));
}
return $this->actionView($homePage->slug, $_lang);
}
Expand All @@ -44,7 +44,7 @@ public function actionView($slug, $_lang)
$dataProvider = new ActiveDataProvider([
'query' => $model->getPages()
->byStatus(Page::STATUS_POST_PUBLISHED)
->orderBy('created_at DESC')
->orderBy($model->type->sort_by),
]);

return $this->render($this->getViewFile($model), [
Expand All @@ -53,4 +53,4 @@ public function actionView($slug, $_lang)
]);
}

}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?php

namespace daxslab\website\migrations;

/**
* Handles adding columns to table `{{%page_type}}`.
*/
class m200815_224355_add_allow_subpages_column_to_page_type_table extends Migration
{
/**
* {@inheritdoc}
*/
public function safeUp()
{
$this->addColumn('{{%page_type}}', 'allow_subpages', $this->boolean()->notNull()->defaultValue(1)->after('name'));
}

/**
* {@inheritdoc}
*/
public function safeDown()
{
$this->dropColumn('{{%page_type}}', 'allow_subpages');
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?php

namespace daxslab\website\migrations;

/**
* Handles adding columns to table `{{%page_type}}`.
*/
class m200818_121205_add_sort_by_column_to_page_type_table extends Migration
{
/**
* {@inheritdoc}
*/
public function safeUp()
{
$this->addColumn('{{%page_type}}', 'sort_by', $this->string()->notNull()->defaultValue('created_at DESC'));
}

/**
* {@inheritdoc}
*/
public function safeDown()
{
$this->dropColumn('{{%page_type}}', 'sort_by');
}
}
4 changes: 2 additions & 2 deletions models/Page.php
Original file line number Diff line number Diff line change
Expand Up @@ -167,12 +167,12 @@ public function getWebsite()

public function getAuthor()
{
return $this->hasOne(User::class, ['id' => 'created_by'])->inverseOf('createdPages');
return $this->hasOne(User::class, ['id' => 'created_by']);
}

public function getEditor()
{
return $this->hasOne(User::class, ['id' => 'updated_by'])->inverseOf('updatedPages');
return $this->hasOne(User::class, ['id' => 'updated_by']);
}

public function getIsPost()
Expand Down
45 changes: 31 additions & 14 deletions models/PageType.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
*
* @property int $id
* @property string $name
* @property boolean $allow_subpages
* @property string $sort_by
* @property int $created_at
* @property int $updated_at
* @property int $created_by
Expand All @@ -21,9 +23,17 @@
*/
class PageType extends ActiveRecord
{
const TYPE_POST = 'post';
const TYPE_HOME = 'home';
const TYPE_PAGE = 'page';
const TYPE_LANDING = 'landing';
const TYPE_GALLERY = 'gallery';
const TYPE_LIST = 'list';

const TYPE_SORT_CREATE_DATE_INVERSE = 'created_at DESC';
const TYPE_SORT_CREATE_DATE = 'created_at';
const TYPE_SORT_UPDATE_DATE_INVERSE = 'updated_at DESC';
const TYPE_SORT_UPDATE_DATE = 'updated_at';
const TYPE_SORT_POSITION_INVERSE = 'position DESC';
const TYPE_SORT_POSITION = 'position';

/**
* {@inheritdoc}
Expand All @@ -39,7 +49,11 @@ public static function tableName()
public function rules()
{
return [
[['name', 'website_id'], 'required'],
[['name', 'website_id', 'allow_subpages'], 'required'],
[['allow_subpages'], 'boolean'],
[['sort_by'], 'string'],
[['sort_by'], 'default', 'value' => 'created_at DESC'],
[['sort_by'], 'in', 'range' => [self::TYPE_SORT_CREATE_DATE_INVERSE, self::TYPE_SORT_CREATE_DATE, self::TYPE_SORT_UPDATE_DATE_INVERSE, self::TYPE_SORT_UPDATE_DATE, self::TYPE_SORT_POSITION, self::TYPE_SORT_POSITION_INVERSE]],
[['website_id'], 'integer'],
[['name'], 'string', 'max' => 255],
[['website_id'], 'exist', 'skipOnError' => true, 'targetClass' => Website::className(), 'targetAttribute' => ['website_id' => 'id']],
Expand All @@ -52,13 +66,15 @@ public function rules()
public function attributeLabels()
{
return [
'id' => Yii::t('website','ID'),
'name' => Yii::t('website','Name'),
'created_at' => Yii::t('website','Created At'),
'updated_at' => Yii::t('website','Updated At'),
'created_by' => Yii::t('website','Created By'),
'updated_by' => Yii::t('website','Updated By'),
'website_id' => Yii::t('website','Website ID'),
'id' => Yii::t('website', 'ID'),
'name' => Yii::t('website', 'Name'),
'allow_subpages' => Yii::t('website', 'Allow Subpages'),
'sort_by' => Yii::t('website', 'Sort Subpages by'),
'created_at' => Yii::t('website', 'Created At'),
'updated_at' => Yii::t('website', 'Updated At'),
'created_by' => Yii::t('website', 'Created By'),
'updated_by' => Yii::t('website', 'Updated By'),
'website_id' => Yii::t('website', 'Website ID'),
];
}

Expand Down Expand Up @@ -88,17 +104,18 @@ public function getWebsite()

public static function defaultPageTypes()
{
return ['home', 'post', 'gallery'];
return [self::TYPE_LANDING, self::TYPE_PAGE, self::TYPE_GALLERY, self::TYPE_LIST];
}

public function getIsDefault(){
public function getIsDefault()
{
return in_array($this->name, self::defaultPageTypes());
}

public function beforeDelete()
{
if (in_array($this->name, self::defaultPageTypes())) {
throw new ErrorException(Yii::t('website',"You can't delete one of the default page types."));
if ($this->isDefault) {
throw new ErrorException(Yii::t('website', "You can't delete one of the default page types."));
}

return parent::beforeDelete();
Expand Down
2 changes: 2 additions & 0 deletions models/Website.php
Original file line number Diff line number Diff line change
Expand Up @@ -188,10 +188,12 @@ public function afterSave($insert, $changedAttributes)
$types[] = new PageType([
'name' => 'landing',
'website_id' => $this->id,
'allow_subpages' => 0,
]);
$types[] = new PageType([
'name' => 'page',
'website_id' => $this->id,
'allow_subpages' => 0,
]);
$types[] = new PageType([
'name' => 'list',
Expand Down
25 changes: 24 additions & 1 deletion views/backend/page-type/_form.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
use yii\helpers\Html;
use yii\widgets\ActiveForm;
use daxslab\website\components\Lookup;
use daxslab\website\models\PageType;

/* @var $this yii\web\View */
/* @var $model daxslab\website\models\PageType */
Expand All @@ -13,7 +14,29 @@

<?php $form = ActiveForm::begin(); ?>

<?= $form->field($model, 'name')->textInput(['maxlength' => true]) ?>
<div class="row">
<div class="col-md-6">
<?= $form->field($model, 'name')->textInput(['maxlength' => true]) ?>
</div>
<div class="col-md-2">
<?= $form->field($model, 'allow_subpages')->widget(\kartik\switchinput\SwitchInput::class, [
'pluginOptions' => [
'onText' => Yii::t('website', 'Yes'),
'offText' => Yii::t('app', 'No'),
],
]) ?>
</div>
<div class="col-md-4">
<?= $form->field($model, 'sort_by')->dropDownList([
PageType::TYPE_SORT_CREATE_DATE_INVERSE => Yii::t('app', 'Creation Date Inverse'),
PageType::TYPE_SORT_CREATE_DATE => Yii::t('app', 'Creation Date'),
PageType::TYPE_SORT_UPDATE_DATE_INVERSE => Yii::t('app', 'Update Date Inverse'),
PageType::TYPE_SORT_UPDATE_DATE => Yii::t('app', 'Update Date'),
PageType::TYPE_SORT_POSITION_INVERSE => Yii::t('app', 'Position on List Inverse'),
PageType::TYPE_SORT_POSITION => Yii::t('app', 'Position on List'),
]) ?>
</div>
</div>

<?= Html::activeHiddenInput($model, 'website_id') ?>

Expand Down
22 changes: 13 additions & 9 deletions views/backend/page/_form.php
Original file line number Diff line number Diff line change
Expand Up @@ -164,14 +164,18 @@

<?php ActiveForm::end(); ?>

<h2><?= Yii::t('website', 'Subpages') ?></h2>

<?= $model->id == null
? Html::tag('div', Yii::t('website', 'You must save this page before adding subpages'), ['class' => 'alert alert-info'])
: Yii::$app->runAction("/{$module}/page/index", [
'parent_id' => $model->id,
'language' => $model->language,
]) ?>

<?php if ($model->type->allow_subpages): ?>
<section>
<header>
<h2><?= Yii::t('website', 'Subpages') ?></h2>
</header>
<?= $model->id == null
? Html::tag('div', Yii::t('website', 'You must save this page before adding subpages'), ['class' => 'alert alert-info'])
: Yii::$app->runAction("/{$module}/page/index", [
'parent_id' => $model->id,
'language' => $model->language,
]) ?>
</section>
<?php endif; ?>

</div><!-- _form -->
3 changes: 3 additions & 0 deletions views/backend/page/_list.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,9 @@
]) . "\n{pager}",
'itemView' => '_view',
'itemOptions' => ['tag' => false],
'pager' => [
'class' => 'yii\bootstrap4\LinkPager',
]
]) ?>

<?php
Expand Down
12 changes: 9 additions & 3 deletions views/backend/page/_view.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,13 @@
? Yii::$app->thumbnailer->get($model->image, 75, 75)
: Yii::$app->thumbnailer->get(Yii::getAlias('@web/images/no-image.png'), 75, 75);

$handleClass = $model->parent_id == null || ($model->parent_id !== null && $model->parent->type->sort_by === 'position')
? 'handle'
: '';

?>

<li id="<?= $model->id ?>" class="media mb-2 handle">
<li id="<?= $model->id ?>" class="media mb-2 <?= $handleClass ?>">

<?= Html:: img($thumbnailUrl, ['class' => 'mr-3']) ?>

Expand All @@ -18,8 +22,10 @@
<small class="text-muted text-uppercase">[<?= Html::encode($model->type->name) ?>]</small>
</h2>
<ul class="list-unstyled">
<li><strong><?= Yii::t('website','Preview')?>: </strong> <?= Html::a($model->url, $model->url, ['target' => '_blank']) ?></li>
<li><strong><?= Yii::t('website','Updated')?>: </strong> <?= $model->updated_at ?> <strong><?= Yii::t('website','by')?>: </strong> <?= $model->editor->name ?></li>
<li><strong><?= Yii::t('website', 'Preview') ?>
: </strong> <?= Html::a($model->url, $model->url, ['target' => '_blank']) ?></li>
<li><strong><?= Yii::t('website', 'Updated') ?>: </strong> <?= $model->updated_at ?>
<strong><?= Yii::t('website', 'by') ?>: </strong> <?= $model->editor->name ?></li>
</ul>
</div>
</li>

0 comments on commit 4590ace

Please sign in to comment.