master
sergeybodin 2023-07-18 12:53:19 +03:00
parent 386872a1cd
commit 562690e6f7
12 changed files with 81 additions and 7 deletions

View File

@ -25,7 +25,7 @@ class PublicationsController extends Controller {
} }
public function index(Request $request): JsonResponse { public function index(Request $request): JsonResponse {
$query = $this->model->query()->orderBy('id', 'desc'); $query = $this->model->query()->orderBy('published_at', 'desc');
$user = Auth::user(); $user = Auth::user();
if (!($user->isAdmin ?? null)) $query->where(['is_published' => true]); if (!($user->isAdmin ?? null)) $query->where(['is_published' => true]);
if ($page = Page::byUuid($request->get('page_id'))->first()) $query->where(['page_id' => $page->id]); if ($page = Page::byUuid($request->get('page_id'))->first()) $query->where(['page_id' => $page->id]);

View File

@ -18,6 +18,7 @@ class Publication extends Model {
use UuidScopeTrait, SoftDeletes, HasObjectsTrait, RelationValuesTrait; use UuidScopeTrait, SoftDeletes, HasObjectsTrait, RelationValuesTrait;
protected $dates = [ protected $dates = [
'published_at'
]; ];
protected $fillable = [ protected $fillable = [
@ -30,7 +31,8 @@ class Publication extends Model {
'name', 'name',
'excerpt', 'excerpt',
'params', 'params',
'is_published' 'published_at',
'is_published',
]; ];
protected $hidden = [ protected $hidden = [

View File

@ -27,11 +27,20 @@ class PublicationNewsForms extends FormsService {
public function commonGroupFields(?Publication $model): array { public function commonGroupFields(?Publication $model): array {
$fields = [ $fields = [
[
'name' => 'published_at',
'title' => 'Дата публикации',
'type' => FieldType::DATE,
'value' => $model->published_at ?? null,
'required' => true,
],
[ [
'name' => 'name', 'name' => 'name',
'title' => 'Название', 'title' => 'Название',
'type' => FieldType::STRING, 'type' => FieldType::STRING,
'required' => true, 'required' => true,
'max_length' => 127,
'value' => $model->name ?? null 'value' => $model->name ?? null
], ],
[ [
@ -52,7 +61,6 @@ class PublicationNewsForms extends FormsService {
} }
public function store(array $data): ?JsonResponse { public function store(array $data): ?JsonResponse {
if (!empty($data['attach']['page_id'])) { if (!empty($data['attach']['page_id'])) {
$page = Page::byUuid($data['attach']['page_id'])->first(); $page = Page::byUuid($data['attach']['page_id'])->first();

View File

@ -38,11 +38,19 @@ class PublicationPhotosForms
} }
$fields = [ $fields = [
[
'name' => 'published_at',
'title' => 'Дата публикации',
'type' => FieldType::DATE,
'value' => $model->published_at ?? null,
'required' => true,
],
[ [
'name' => 'name', 'name' => 'name',
'title' => 'Название', 'title' => 'Название',
'type' => FieldType::STRING, 'type' => FieldType::STRING,
'required' => true, 'required' => true,
'max_length' => 127,
'value' => $model->name ?? null 'value' => $model->name ?? null
], ],
[ [
@ -66,6 +74,7 @@ class PublicationPhotosForms
$pub['author_id'] = Auth::user()->id; $pub['author_id'] = Auth::user()->id;
$pub['type'] = PublicationType::PHOTOS; $pub['type'] = PublicationType::PHOTOS;
$pub['name'] = $data['name']; $pub['name'] = $data['name'];
$pub['published_at'] = $data['published_at'];
if (!empty($data['assets'])) { if (!empty($data['assets'])) {
$pub['params'] = json_encode([ $pub['params'] = json_encode([
'assets' => $data['assets'] 'assets' => $data['assets']
@ -87,6 +96,7 @@ class PublicationPhotosForms
'assets' => $data['assets'] 'assets' => $data['assets']
]); ]);
} }
$pub['published_at'] = $data['published_at'];
$model->update($pub); $model->update($pub);
return fractal($model, new PublicationTransformer())->respond(); return fractal($model, new PublicationTransformer())->respond();

View File

@ -31,11 +31,19 @@ class PublicationSmiForms
$params = $model->parsedParams ?? null; $params = $model->parsedParams ?? null;
$fields = [ $fields = [
[
'name' => 'published_at',
'title' => 'Дата публикации',
'type' => FieldType::DATE,
'value' => $model->published_at ?? null,
'required' => true,
],
[ [
'name' => 'name', 'name' => 'name',
'title' => 'Название', 'title' => 'Название',
'type' => FieldType::STRING, 'type' => FieldType::STRING,
'required' => true, 'required' => true,
'max_length' => 127,
'value' => $model->name ?? null 'value' => $model->name ?? null
], ],
[ [
@ -80,6 +88,7 @@ class PublicationSmiForms
$pub['type'] = PublicationType::SMI; $pub['type'] = PublicationType::SMI;
$pub['name'] = $data['name']; $pub['name'] = $data['name'];
$pub['excerpt'] = $data['excerpt']; $pub['excerpt'] = $data['excerpt'];
$pub['published_at'] = $data['published_at'];
if (empty($data['poster_id'])) { if (empty($data['poster_id'])) {
$pub['poster_id'] = null; $pub['poster_id'] = null;
} else { } else {
@ -129,6 +138,7 @@ class PublicationSmiForms
if (count($params) > 0) { if (count($params) > 0) {
$pub['params'] = json_encode($params); $pub['params'] = json_encode($params);
} }
$pub['published_at'] = $data['published_at'];
$model->update($pub); $model->update($pub);
return fractal($model->fresh(), new PublicationTransformer())->respond(); return fractal($model->fresh(), new PublicationTransformer())->respond();
} }

View File

@ -13,6 +13,7 @@ use App\Transformers\Publications\PublicationTransformer;
use Illuminate\Http\JsonResponse; use Illuminate\Http\JsonResponse;
use Illuminate\Support\Facades\Auth; use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Str; use Illuminate\Support\Str;
use stringEncode\Encode;
class PublicationVideoForms class PublicationVideoForms
extends FormsService { extends FormsService {
@ -31,6 +32,13 @@ class PublicationVideoForms
$params = $model->parsedParams ?? null; $params = $model->parsedParams ?? null;
$fields = [ $fields = [
[
'name' => 'published_at',
'title' => 'Дата публикации',
'type' => FieldType::DATE,
'value' => $model->published_at ?? null,
'required' => true,
],
[ [
'name' => 'url', 'name' => 'url',
'title' => 'Ссылка на видео', 'title' => 'Ссылка на видео',
@ -58,9 +66,10 @@ class PublicationVideoForms
$pub['excerpt'] = $data['excerpt']; $pub['excerpt'] = $data['excerpt'];
$pub['author_id'] = Auth::user()->id; $pub['author_id'] = Auth::user()->id;
$pub['type'] = PublicationType::VIDEO; $pub['type'] = PublicationType::VIDEO;
$pub['published_at'] = $data['published_at'];
if (!empty($data['url'])) { if (!empty($data['url'])) {
$pub['params'] = json_encode([ $pub['params'] = json_encode([
'url' => $data['url'] 'url' => $this->formatUrl($data['url'])
]); ]);
} }
$model = Publication::create($pub, true); $model = Publication::create($pub, true);
@ -74,11 +83,30 @@ class PublicationVideoForms
} }
if (!empty($data['url'])) { if (!empty($data['url'])) {
$pub['params'] = json_encode([ $pub['params'] = json_encode([
'url' => $data['url'] 'url' => $this->formatUrl($data['url'])
]); ]);
} }
$pub['published_at'] = $data['published_at'];
$model = Publication::byUuid($id)->firstOrFail(); $model = Publication::byUuid($id)->firstOrFail();
$model->update($pub); $model->update($pub);
return fractal($model->fresh(), new PublicationTransformer())->respond(); return fractal($model->fresh(), new PublicationTransformer())->respond();
} }
public function formatUrl($url): string {
$videoId = '';
$videoUrl = '';
switch (true) {
case str_contains($url, $mask = 'https://youtu.be/'):
case str_contains($url, $mask = 'https://www.youtube.com/watch?v='):
$videoId = str_replace($mask, '', $url);
break;
default:
$videoUrl = $url;
break;
}
if ($videoId != '') {
$videoUrl = "https://www.youtube.com/embed/$videoId";
}
return $videoUrl;
}
} }

View File

@ -38,6 +38,7 @@ class PublicationTransformer extends TransformerAbstract {
'name' => $model->name, 'name' => $model->name,
'excerpt' => $model->excerpt, 'excerpt' => $model->excerpt,
'is_published' => boolval($model->is_published), 'is_published' => boolval($model->is_published),
'published_at' => $model->published_at ? $model->published_at->toIso8601String() : null,
'created_at' => $model->created_at ? $model->created_at->toIso8601String() : null, 'created_at' => $model->created_at ? $model->created_at->toIso8601String() : null,
'updated_at' => $model->updated_at ? $model->updated_at->toIso8601String() : null 'updated_at' => $model->updated_at ? $model->updated_at->toIso8601String() : null
]; ];

View File

@ -25,6 +25,7 @@ class CreatePublicationsTable extends Migration
$table->text('excerpt')->nullable(); $table->text('excerpt')->nullable();
$table->text('params')->nullable(); $table->text('params')->nullable();
$table->boolean('is_published')->index()->default(0); $table->boolean('is_published')->index()->default(0);
$table->timestamp('published_at')->nullable();
$table->timestamps(); $table->timestamps();
$table->softDeletes(); $table->softDeletes();
}); });

View File

@ -219,7 +219,13 @@ class FieldsTableSeeder extends Seeder {
'developer' => [ 'developer' => [
'title' => 'Разработчик', 'title' => 'Разработчик',
'type' => FieldType::STRING 'type' => FieldType::STRING
] ],
'maps-url' => [
'title' => 'Адрес карты',
'type' => FieldType::STRING,
'required' => true,
],
]; ];
public function run() { public function run() {

View File

@ -65,6 +65,11 @@ class ObjectTypeFieldsTableSeeder extends Seeder {
'fields' => ['feedback-support-email', 'feedback-form-type'] 'fields' => ['feedback-support-email', 'feedback-form-type']
] ]
], ],
'page-section-maps' => [
'common' => [
'fields' => ['maps-url']
]
],
'feedback-form-support' => [ 'feedback-form-support' => [
'common' => [ 'common' => [
'fields' => ['feedback-email', 'feedback-name', 'feedback-type', 'feedback-message'] 'fields' => ['feedback-email', 'feedback-name', 'feedback-type', 'feedback-message']

View File

@ -43,6 +43,9 @@ class ObjectTypesTableSeeder extends Seeder {
], ],
'page-section-feedback' => [ 'page-section-feedback' => [
'title' => 'Форма обратной связи' 'title' => 'Форма обратной связи'
],
'page-section-maps' => [
'title' => 'Карта'
] ]
] ]
], ],

View File

@ -75,4 +75,4 @@ Route::group(['middleware' => ['auth:api']], function() {
Route::put('publications/published/{id}', 'Api\Publications\PublicationsController@published'); Route::put('publications/published/{id}', 'Api\Publications\PublicationsController@published');
Route::delete('publications/{id}', 'Api\Publications\PublicationsController@destroy'); Route::delete('publications/{id}', 'Api\Publications\PublicationsController@destroy');
}); });