This commit is contained in:
Kerim 2023-01-10 15:27:42 +05:00
parent 23f1ccb372
commit 4806e4d8a9
24 changed files with 494 additions and 21 deletions

View File

@ -104,21 +104,21 @@ class Plugin extends PluginBase
'label' => 'Tags ru',
'mode' => 'relation',
'dependsOn' => 'locale',
'tab' => 'rainlab.blog::lang.post.tab_categories',
'tab' => 'Language and Tag',
'type' => 'taglist'
],
'tags_en' => [
'label' => 'Tags en',
'mode' => 'relation',
'dependsOn' => 'locale',
'tab' => 'rainlab.blog::lang.post.tab_categories',
'tab' => 'Language and Tag',
'type' => 'taglist'
],
'tags_tm' => [
'label' => 'Tags tm',
'mode' => 'relation',
'dependsOn' => 'locale',
'tab' => 'rainlab.blog::lang.post.tab_categories',
'tab' => 'Language and Tag',
'type' => 'taglist'
]
]);

View File

@ -12,6 +12,7 @@ use Markdown;
use BackendAuth;
use Carbon\Carbon;
use Backend\Models\User;
use Tps\Tps\Models\Authors;
use Cms\Classes\Page as CmsPage;
use Cms\Classes\Theme;
use Cms\Classes\Controller;
@ -35,14 +36,15 @@ class Post extends Model
* Validation
*/
public $rules = [
'title' => 'required',
'title' => ['required', 'unique:rainlab_blog_posts'],
'slug' => ['required', 'regex:/^[a-z0-9\/\:_\-\*\[\]\+\?\|]*$/i', 'unique:rainlab_blog_posts'],
'content' => 'required',
'powerseo_title' => 'required',
'powerseo_description' => 'required',
'powerseo_keywords' => 'required',
'excerpt' => 'required',
// 'type_post' => 'required',
'category_groups' => 'required',
'awtor' => 'required',
];
/**
@ -89,6 +91,10 @@ class Post extends Model
*/
public $belongsTo = [
'user' => ['Backend\Models\User'],
'awtor' => ['Tps\Tps\Models\Authors',
'key' => 'author_id',
'table' => 'tps_tps_authors'
],
];
public $belongsToMany = [
@ -170,6 +176,18 @@ class Post extends Model
public function filterFields($fields, $context = null)
{
if($this->awtor){
if($this->awtor->type == 'other'){
$fields->author_name->hidden = false;
}else{
$fields->author_name->value = null;
$fields->author_name->hidden = true;
}
}else{
$fields->author_name->value = null;
$fields->author_name->hidden = true;
}
if(isset($fields->category_groups)){
if($this->category_groups->where('type', 'news')->count()){
$fields->type_post->hidden = false;
@ -177,12 +195,6 @@ class Post extends Model
$fields->type_post->hidden = true;
}
// if($this->category_groups->where('type', 'media')->count()){
// $fields->video_file->hidden = false;
// }else{
// $fields->video_file->hidden = true;
// }
if($this->category_groups->where('type', 'afisha')->count()){
$fields->afisha_phone->hidden = false;
$fields->afisha_address->hidden = false;
@ -191,6 +203,7 @@ class Post extends Model
$fields->afisha_address->hidden = true;
}
}
if(isset($fields->locale)){
if($this->locale == 'en')
{

View File

@ -1,19 +1,22 @@
fields:
title:
label: 'rainlab.blog::lang.post.title'
span: full
placeholder: 'rainlab.blog::lang.post.title_placeholder'
type: text
slug:
label: 'rainlab.blog::lang.post.slug'
span: full
placeholder: 'rainlab.blog::lang.post.slug_placeholder'
preset:
field: title
type: slug
type: text
toolbar:
type: partial
path: post_toolbar
span: full
cssClass: collapse-visible
path: post_toolbar
type: partial
secondaryTabs:
fields:
content:
@ -32,37 +35,45 @@ secondaryTabs:
span: left
default: 'rainlab.blog::lang.ru'
type: dropdown
tab: 'rainlab.blog::lang.post.tab_categories'
tab: 'Language and Tag'
id_en:
label: 'Translated Post ID En'
span: right
dependsOn:
- locale
type: number
tab: 'rainlab.blog::lang.post.tab_categories'
tab: 'Language and Tag'
id_tm:
label: 'Translated Post ID Tm'
span: right
dependsOn:
- locale
type: number
tab: 'rainlab.blog::lang.post.tab_categories'
tab: 'Language and Tag'
id_ru:
label: 'Translated Post ID Ru'
span: right
dependsOn:
- locale
type: number
tab: 'rainlab.blog::lang.post.tab_categories'
author:
label: 'Post author'
tab: 'Language and Tag'
awtor:
label: Authors
nameFrom: name
descriptionFrom: description
span: auto
default: 'ORIENT news'
type: relation
tab: 'rainlab.blog::lang.post.tab_manage'
author_name:
label: 'Author Name'
span: auto
dependsOn:
- awtor
type: text
tab: 'rainlab.blog::lang.post.tab_manage'
featured:
label: 'показать в слайдере на главной странице'
span: auto
span: right
type: checkbox
comment: 'не отмечать если не нужно выставлять на слайдере'
tab: 'rainlab.blog::lang.post.tab_manage'

View File

@ -0,0 +1,23 @@
<?php namespace RainLab\Blog\Updates;
use Schema;
use October\Rain\Database\Updates\Migration;
class BuilderTableUpdateRainlabBlogPosts14 extends Migration
{
public function up()
{
Schema::table('rainlab_blog_posts', function($table)
{
$table->integer('author_id')->nullable();
});
}
public function down()
{
Schema::table('rainlab_blog_posts', function($table)
{
$table->dropColumn('author_id');
});
}
}

View File

@ -0,0 +1,23 @@
<?php namespace RainLab\Blog\Updates;
use Schema;
use October\Rain\Database\Updates\Migration;
class BuilderTableUpdateRainlabBlogPosts15 extends Migration
{
public function up()
{
Schema::table('rainlab_blog_posts', function($table)
{
$table->string('author_name')->nullable();
});
}
public function down()
{
Schema::table('rainlab_blog_posts', function($table)
{
$table->dropColumn('author_name');
});
}
}

View File

@ -0,0 +1,23 @@
<?php namespace RainLab\Blog\Updates;
use Schema;
use October\Rain\Database\Updates\Migration;
class BuilderTableUpdateRainlabBlogPosts16 extends Migration
{
public function up()
{
Schema::table('rainlab_blog_posts', function($table)
{
$table->integer('author_id')->unsigned()->change();
});
}
public function down()
{
Schema::table('rainlab_blog_posts', function($table)
{
$table->integer('author_id')->unsigned(false)->change();
});
}
}

View File

@ -0,0 +1,23 @@
<?php namespace RainLab\Blog\Updates;
use Schema;
use October\Rain\Database\Updates\Migration;
class BuilderTableUpdateRainlabBlogPosts17 extends Migration
{
public function up()
{
Schema::table('rainlab_blog_posts', function($table)
{
$table->integer('author_id')->unsigned(false)->change();
});
}
public function down()
{
Schema::table('rainlab_blog_posts', function($table)
{
$table->integer('author_id')->unsigned()->change();
});
}
}

View File

@ -159,3 +159,15 @@
1.5.33:
- 'Updated table rainlab_blog_posts'
- builder_table_update_rainlab_blog_posts_13.php
1.5.34:
- 'Updated table rainlab_blog_posts'
- builder_table_update_rainlab_blog_posts_14.php
1.5.35:
- 'Updated table rainlab_blog_posts'
- builder_table_update_rainlab_blog_posts_15.php
1.5.36:
- 'Updated table rainlab_blog_posts'
- builder_table_update_rainlab_blog_posts_16.php
1.5.37:
- 'Updated table rainlab_blog_posts'
- builder_table_update_rainlab_blog_posts_17.php

View File

@ -0,0 +1,18 @@
<?php namespace Tps\Tps\Controllers;
use Backend\Classes\Controller;
use BackendMenu;
class Authors extends Controller
{
public $implement = [ 'Backend\Behaviors\ListController', 'Backend\Behaviors\FormController' ];
public $listConfig = 'config_list.yaml';
public $formConfig = 'config_form.yaml';
public function __construct()
{
parent::__construct();
BackendMenu::setContext('Tps.Tps', 'main-menu-item', 'side-menu-item');
}
}

View File

@ -0,0 +1,18 @@
<div data-control="toolbar">
<a href="<?= Backend::url('tps/tps/authors/create') ?>" class="btn btn-primary oc-icon-plus"><?= e(trans('backend::lang.form.create')) ?></a>
<button
class="btn btn-default oc-icon-trash-o"
disabled="disabled"
onclick="$(this).data('request-data', {
checked: $('.control-list').listWidget('getChecked')
})"
data-request="onDelete"
data-request-confirm="<?= e(trans('backend::lang.list.delete_selected_confirm')) ?>"
data-trigger-action="enable"
data-trigger=".control-list input[type=checkbox]"
data-trigger-condition="checked"
data-request-success="$(this).prop('disabled', true)"
data-stripe-load-indicator>
<?= e(trans('backend::lang.list.delete_selected')) ?>
</button>
</div>

View File

@ -0,0 +1,10 @@
name: Authors
form: $/tps/tps/models/authors/fields.yaml
modelClass: Tps\Tps\Models\Authors
defaultRedirect: tps/tps/authors
create:
redirect: 'tps/tps/authors/update/:id'
redirectClose: tps/tps/authors
update:
redirect: tps/tps/authors
redirectClose: tps/tps/authors

View File

@ -0,0 +1,12 @@
list: $/tps/tps/models/authors/columns.yaml
modelClass: Tps\Tps\Models\Authors
title: Authors
noRecordsMessage: 'backend::lang.list.no_records'
showSetup: true
showCheckboxes: true
recordsPerPage: 20
toolbar:
buttons: list_toolbar
search:
prompt: 'backend::lang.list.search_prompt'
recordUrl: 'tps/tps/authors/update/:id'

View File

@ -0,0 +1,46 @@
<?php Block::put('breadcrumb') ?>
<ul>
<li><a href="<?= Backend::url('tps/tps/authors') ?>">Authors</a></li>
<li><?= e($this->pageTitle) ?></li>
</ul>
<?php Block::endPut() ?>
<?php if (!$this->fatalError): ?>
<?= Form::open(['class' => 'layout']) ?>
<div class="layout-row">
<?= $this->formRender() ?>
</div>
<div class="form-buttons">
<div class="loading-indicator-container">
<button
type="submit"
data-request="onSave"
data-hotkey="ctrl+s, cmd+s"
data-load-indicator="<?= e(trans('backend::lang.form.saving')) ?>"
class="btn btn-primary">
<?= e(trans('backend::lang.form.create')) ?>
</button>
<button
type="button"
data-request="onSave"
data-request-data="close:1"
data-hotkey="ctrl+enter, cmd+enter"
data-load-indicator="<?= e(trans('backend::lang.form.saving')) ?>"
class="btn btn-default">
<?= e(trans('backend::lang.form.create_and_close')) ?>
</button>
<span class="btn-text">
<?= e(trans('backend::lang.form.or')) ?> <a href="<?= Backend::url('tps/tps/authors') ?>"><?= e(trans('backend::lang.form.cancel')) ?></a>
</span>
</div>
</div>
<?= Form::close() ?>
<?php else: ?>
<p class="flash-message static error"><?= e(trans($this->fatalError)) ?></p>
<p><a href="<?= Backend::url('tps/tps/authors') ?>" class="btn btn-default"><?= e(trans('backend::lang.form.return_to_list')) ?></a></p>
<?php endif ?>

View File

@ -0,0 +1 @@
<?= $this->listRender() ?>

View File

@ -0,0 +1,22 @@
<?php Block::put('breadcrumb') ?>
<ul>
<li><a href="<?= Backend::url('tps/tps/authors') ?>">Authors</a></li>
<li><?= e($this->pageTitle) ?></li>
</ul>
<?php Block::endPut() ?>
<?php if (!$this->fatalError): ?>
<div class="form-preview">
<?= $this->formRenderPreview() ?>
</div>
<?php else: ?>
<p class="flash-message static error"><?= e($this->fatalError) ?></p>
<?php endif ?>
<p>
<a href="<?= Backend::url('tps/tps/authors') ?>" class="btn btn-default oc-icon-chevron-left">
<?= e(trans('backend::lang.form.return_to_list')) ?>
</a>
</p>

View File

@ -0,0 +1,54 @@
<?php Block::put('breadcrumb') ?>
<ul>
<li><a href="<?= Backend::url('tps/tps/authors') ?>">Authors</a></li>
<li><?= e($this->pageTitle) ?></li>
</ul>
<?php Block::endPut() ?>
<?php if (!$this->fatalError): ?>
<?= Form::open(['class' => 'layout']) ?>
<div class="layout-row">
<?= $this->formRender() ?>
</div>
<div class="form-buttons">
<div class="loading-indicator-container">
<button
type="submit"
data-request="onSave"
data-request-data="redirect:0"
data-hotkey="ctrl+s, cmd+s"
data-load-indicator="<?= e(trans('backend::lang.form.saving')) ?>"
class="btn btn-primary">
<?= e(trans('backend::lang.form.save')) ?>
</button>
<button
type="button"
data-request="onSave"
data-request-data="close:1"
data-hotkey="ctrl+enter, cmd+enter"
data-load-indicator="<?= e(trans('backend::lang.form.saving')) ?>"
class="btn btn-default">
<?= e(trans('backend::lang.form.save_and_close')) ?>
</button>
<button
type="button"
class="oc-icon-trash-o btn-icon danger pull-right"
data-request="onDelete"
data-load-indicator="<?= e(trans('backend::lang.form.deleting')) ?>"
data-request-confirm="<?= e(trans('backend::lang.form.confirm_delete')) ?>">
</button>
<span class="btn-text">
<?= e(trans('backend::lang.form.or')) ?> <a href="<?= Backend::url('tps/tps/authors') ?>"><?= e(trans('backend::lang.form.cancel')) ?></a>
</span>
</div>
</div>
<?= Form::close() ?>
<?php else: ?>
<p class="flash-message static error"><?= e(trans($this->fatalError)) ?></p>
<p><a href="<?= Backend::url('tps/tps/authors') ?>" class="btn btn-default"><?= e(trans('backend::lang.form.return_to_list')) ?></a></p>
<?php endif ?>

View File

@ -0,0 +1,35 @@
<?php namespace Tps\Tps\Models;
use Model;
use ValidationException;
/**
* Model
*/
class Authors extends Model
{
use \October\Rain\Database\Traits\Validation;
use \October\Rain\Database\Traits\SoftDelete;
protected $dates = ['deleted_at'];
/**
* @var string The database table used by the model.
*/
public $table = 'tps_tps_authors';
public $hasMany = [
'post' => [
'RainLab\Blog\Models\Post'
],
];
/**
* @var array Validation rules
*/
public $rules = [
'name' => 'required',
];
}

View File

@ -0,0 +1,24 @@
columns:
id:
label: id
type: number
name:
label: name
type: text
searchable: true
sortable: true
note:
label: note
type: text
searchable: true
sortable: true
created_at:
label: created_at
type: datetime
searchable: true
sortable: true
type:
label: type
type: text
searchable: true
sortable: true

View File

@ -0,0 +1,19 @@
fields:
name:
label: Name
span: auto
required: 1
type: text
note:
label: Note
size: ''
span: auto
type: textarea
type:
label: 'Author Type'
options:
author: Author
other: Other
span: auto
default: author
type: balloon-selector

View File

@ -9,3 +9,8 @@ navigation:
label: 'Media Category'
url: tps/tps/media
icon: icon-film
sideMenu:
side-menu-item:
label: Authors
url: tps/tps/authors
icon: icon-users

View File

@ -0,0 +1,26 @@
<?php namespace Tps\Tps\Updates;
use Schema;
use October\Rain\Database\Updates\Migration;
class BuilderTableCreateTpsTpsAuthors extends Migration
{
public function up()
{
Schema::create('tps_tps_authors', function($table)
{
$table->engine = 'InnoDB';
$table->increments('id')->unsigned();
$table->string('name');
$table->text('note');
$table->timestamp('created_at')->nullable();
$table->timestamp('updated_at')->nullable();
$table->timestamp('deleted_at')->nullable();
});
}
public function down()
{
Schema::dropIfExists('tps_tps_authors');
}
}

View File

@ -0,0 +1,23 @@
<?php namespace Tps\Tps\Updates;
use Schema;
use October\Rain\Database\Updates\Migration;
class BuilderTableUpdateTpsTpsAuthors extends Migration
{
public function up()
{
Schema::table('tps_tps_authors', function($table)
{
$table->string('type');
});
}
public function down()
{
Schema::table('tps_tps_authors', function($table)
{
$table->dropColumn('type');
});
}
}

View File

@ -0,0 +1,23 @@
<?php namespace Tps\Tps\Updates;
use Schema;
use October\Rain\Database\Updates\Migration;
class BuilderTableUpdateTpsTpsAuthors2 extends Migration
{
public function up()
{
Schema::table('tps_tps_authors', function($table)
{
$table->string('type', 191)->default('author')->change();
});
}
public function down()
{
Schema::table('tps_tps_authors', function($table)
{
$table->string('type', 191)->default(null)->change();
});
}
}

View File

@ -6,3 +6,12 @@
1.0.3:
- 'Created table tps_tps_media'
- builder_table_create_tps_tps_media.php
1.0.4:
- 'Created table tps_tps_authors'
- builder_table_create_tps_tps_authors.php
1.0.5:
- 'Updated table tps_tps_authors'
- builder_table_update_tps_tps_authors.php
1.0.6:
- 'Updated table tps_tps_authors'
- builder_table_update_tps_tps_authors_2.php