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 {
$query = $this->model->query()->orderBy('id', 'desc');
$query = $this->model->query()->orderBy('published_at', 'desc');
$user = Auth::user();
if (!($user->isAdmin ?? null)) $query->where(['is_published' => true]);
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;
protected $dates = [
'published_at'
];
protected $fillable = [
@ -30,7 +31,8 @@ class Publication extends Model {
'name',
'excerpt',
'params',
'is_published'
'published_at',
'is_published',
];
protected $hidden = [

View File

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

View File

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

View File

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

View File

@ -13,6 +13,7 @@ use App\Transformers\Publications\PublicationTransformer;
use Illuminate\Http\JsonResponse;
use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Str;
use stringEncode\Encode;
class PublicationVideoForms
extends FormsService {
@ -31,6 +32,13 @@ class PublicationVideoForms
$params = $model->parsedParams ?? null;
$fields = [
[
'name' => 'published_at',
'title' => 'Дата публикации',
'type' => FieldType::DATE,
'value' => $model->published_at ?? null,
'required' => true,
],
[
'name' => 'url',
'title' => 'Ссылка на видео',
@ -58,9 +66,10 @@ class PublicationVideoForms
$pub['excerpt'] = $data['excerpt'];
$pub['author_id'] = Auth::user()->id;
$pub['type'] = PublicationType::VIDEO;
$pub['published_at'] = $data['published_at'];
if (!empty($data['url'])) {
$pub['params'] = json_encode([
'url' => $data['url']
'url' => $this->formatUrl($data['url'])
]);
}
$model = Publication::create($pub, true);
@ -74,11 +83,30 @@ class PublicationVideoForms
}
if (!empty($data['url'])) {
$pub['params'] = json_encode([
'url' => $data['url']
'url' => $this->formatUrl($data['url'])
]);
}
$pub['published_at'] = $data['published_at'];
$model = Publication::byUuid($id)->firstOrFail();
$model->update($pub);
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,
'excerpt' => $model->excerpt,
'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,
'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('params')->nullable();
$table->boolean('is_published')->index()->default(0);
$table->timestamp('published_at')->nullable();
$table->timestamps();
$table->softDeletes();
});

View File

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

View File

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

View File

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