Version 1.0.0
This commit is contained in:
119
app/Http/Controllers/Api/ArticleController.php
Normal file
119
app/Http/Controllers/Api/ArticleController.php
Normal file
@@ -0,0 +1,119 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Api;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Models\Article;
|
||||
use App\Models\Location;
|
||||
use App\Models\Attachment;
|
||||
use App\Models\Photo;
|
||||
use DOMDocument;
|
||||
use DOMXPath;
|
||||
|
||||
class ArticleController extends Controller
|
||||
{
|
||||
private function cleanFileInfo(?string $html): ?string
|
||||
{
|
||||
if (!$html) {
|
||||
return $html;
|
||||
}
|
||||
|
||||
$dom = new DOMDocument();
|
||||
libxml_use_internal_errors(true);
|
||||
$dom->loadHTML(mb_convert_encoding($html, 'HTML-ENTITIES', 'UTF-8'), LIBXML_HTML_NOIMPLIED | LIBXML_HTML_NODEFDTD);
|
||||
libxml_clear_errors();
|
||||
|
||||
$xpath = new DOMXPath($dom);
|
||||
|
||||
$figcaptions = $xpath->query('//figcaption');
|
||||
foreach ($figcaptions as $figcaption) {
|
||||
$figcaption->parentNode->removeChild($figcaption);
|
||||
}
|
||||
|
||||
$imageLinks = $xpath->query('//a[.//img]');
|
||||
foreach ($imageLinks as $link) {
|
||||
$images = $xpath->query('.//img', $link);
|
||||
$parent = $link->parentNode;
|
||||
|
||||
foreach ($images as $img) {
|
||||
$link->removeChild($img);
|
||||
$parent->insertBefore($img, $link);
|
||||
}
|
||||
|
||||
$parent->removeChild($link);
|
||||
}
|
||||
|
||||
return $dom->saveHTML();
|
||||
}
|
||||
|
||||
public function index()
|
||||
{
|
||||
$slug = request('slug');
|
||||
$query = Article::query();
|
||||
|
||||
$query->where('type', '!=', 'link')
|
||||
->where('active', true);
|
||||
|
||||
if ($slug) {
|
||||
$query->where('slug', $slug)->with(['photos', 'attachments', 'categories']);
|
||||
}
|
||||
|
||||
$articles = $query->orderBy('published_at', 'desc')->get()->map(function ($item) {
|
||||
if ($item->thumbnail && !str_starts_with($item->thumbnail, '/storage/')) {
|
||||
$item->thumbnail = '/storage/' . ltrim($item->thumbnail, '/');
|
||||
}
|
||||
|
||||
if ($item->photos) {
|
||||
$item->photos->transform(function ($photo) {
|
||||
if ($photo->image_path && !str_starts_with($photo->image_path, '/storage/')) {
|
||||
$photo->image_path = '/storage/' . ltrim($photo->image_path, '/');
|
||||
}
|
||||
return $photo;
|
||||
});
|
||||
}
|
||||
|
||||
if ($item->attachments) {
|
||||
$item->attachments->transform(function ($attachment) {
|
||||
if ($attachment->file_path && !str_starts_with($attachment->file_path, '/storage/')) {
|
||||
$attachment->file_path = '/storage/' . ltrim($attachment->file_path, '/');
|
||||
}
|
||||
return $attachment;
|
||||
});
|
||||
}
|
||||
|
||||
if ($item->type === 'article-with-map') {
|
||||
$location = Location::first();
|
||||
|
||||
if ($location && $location->photo_id) {
|
||||
$mapPhoto = Photo::where('id', $location->photo_id)->first();
|
||||
|
||||
if ($mapPhoto) {
|
||||
if ($mapPhoto->image_path && !str_starts_with($mapPhoto->image_path, '/storage/')) {
|
||||
$mapPhoto->image_path = '/storage/' . ltrim($mapPhoto->image_path, '/');
|
||||
}
|
||||
|
||||
$item->map_photo = $mapPhoto;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ($item->body) {
|
||||
$item->body = $this->cleanFileInfo($item->body);
|
||||
}
|
||||
|
||||
if ($item->additional_body) {
|
||||
$item->additional_body = $this->cleanFileInfo($item->additional_body);
|
||||
}
|
||||
|
||||
if ($item->map_body) {
|
||||
$item->map_body = $this->cleanFileInfo($item->map_body);
|
||||
}
|
||||
|
||||
return $item;
|
||||
});
|
||||
|
||||
return response()->json([
|
||||
'articles' => $articles,
|
||||
]);
|
||||
}
|
||||
}
|
||||
114
app/Http/Controllers/Api/ArticleNewsController.php
Normal file
114
app/Http/Controllers/Api/ArticleNewsController.php
Normal file
@@ -0,0 +1,114 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Api;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Models\ArticleNews;
|
||||
use DOMDocument;
|
||||
use DOMXPath;
|
||||
|
||||
class ArticleNewsController extends Controller
|
||||
{
|
||||
private function cleanFileInfo(?string $html): ?string
|
||||
{
|
||||
if (!$html) {
|
||||
return $html;
|
||||
}
|
||||
|
||||
$dom = new DOMDocument();
|
||||
libxml_use_internal_errors(true);
|
||||
$dom->loadHTML(mb_convert_encoding($html, 'HTML-ENTITIES', 'UTF-8'), LIBXML_HTML_NOIMPLIED | LIBXML_HTML_NODEFDTD);
|
||||
libxml_clear_errors();
|
||||
|
||||
$xpath = new DOMXPath($dom);
|
||||
|
||||
$figcaptions = $xpath->query('//figcaption');
|
||||
foreach ($figcaptions as $figcaption) {
|
||||
$figcaption->parentNode->removeChild($figcaption);
|
||||
}
|
||||
|
||||
$imageLinks = $xpath->query('//a[.//img]');
|
||||
foreach ($imageLinks as $link) {
|
||||
$images = $xpath->query('.//img', $link);
|
||||
$parent = $link->parentNode;
|
||||
|
||||
foreach ($images as $img) {
|
||||
$link->removeChild($img);
|
||||
$parent->insertBefore($img, $link);
|
||||
}
|
||||
|
||||
$parent->removeChild($link);
|
||||
}
|
||||
|
||||
return $dom->saveHTML();
|
||||
}
|
||||
|
||||
public function index()
|
||||
{
|
||||
$slug = request('slug');
|
||||
$page = request('page', 1);
|
||||
$perPage = request('per_page', 10);
|
||||
|
||||
$query = ArticleNews::query()->where('active', true);
|
||||
|
||||
if ($slug) {
|
||||
$query->where('slug', $slug)->with(['photos', 'attachments']);
|
||||
|
||||
$articleNews = $query->orderBy('published_at', 'desc')->get()->map(function ($item) {
|
||||
if ($item->thumbnail && !str_starts_with($item->thumbnail, '/storage/')) {
|
||||
$item->thumbnail = '/storage/' . ltrim($item->thumbnail, '/');
|
||||
}
|
||||
|
||||
if ($item->photos) {
|
||||
$item->photos->transform(function ($photo) {
|
||||
if ($photo->image_path && !str_starts_with($photo->image_path, '/storage/')) {
|
||||
$photo->image_path = '/storage/' . ltrim($photo->image_path, '/');
|
||||
}
|
||||
return $photo;
|
||||
});
|
||||
}
|
||||
|
||||
if ($item->attachments) {
|
||||
$item->attachments->transform(function ($attachment) {
|
||||
if ($attachment->file_path && !str_starts_with($attachment->file_path, '/storage/')) {
|
||||
$attachment->file_path = '/storage/' . ltrim($attachment->file_path, '/');
|
||||
}
|
||||
return $attachment;
|
||||
});
|
||||
}
|
||||
|
||||
if ($item->body) {
|
||||
$item->body = $this->cleanFileInfo($item->body);
|
||||
}
|
||||
|
||||
return $item;
|
||||
});
|
||||
|
||||
return response()->json([
|
||||
'articleNews' => $articleNews,
|
||||
]);
|
||||
} else {
|
||||
$total = $query->count();
|
||||
$articleNews = $query->orderBy('published_at', 'desc')
|
||||
->skip(($page - 1) * $perPage)
|
||||
->take($perPage)
|
||||
->get()
|
||||
->map(function ($item) {
|
||||
if ($item->thumbnail && !str_starts_with($item->thumbnail, '/storage/')) {
|
||||
$item->thumbnail = '/storage/' . ltrim($item->thumbnail, '/');
|
||||
}
|
||||
return $item;
|
||||
});
|
||||
|
||||
return response()->json([
|
||||
'articleNews' => $articleNews,
|
||||
'pagination' => [
|
||||
'total' => $total,
|
||||
'per_page' => $perPage,
|
||||
'current_page' => $page,
|
||||
'last_page' => ceil($total / $perPage),
|
||||
],
|
||||
]);
|
||||
}
|
||||
}
|
||||
}
|
||||
84
app/Http/Controllers/Api/ContactController.php
Normal file
84
app/Http/Controllers/Api/ContactController.php
Normal file
@@ -0,0 +1,84 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Api;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Models\Contact;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Mail;
|
||||
use Illuminate\Support\Facades\Validator;
|
||||
|
||||
class ContactController extends Controller
|
||||
{
|
||||
public function index()
|
||||
{
|
||||
$contact = Contact::first();
|
||||
|
||||
if (!$contact) {
|
||||
return response()->json([
|
||||
'message' => 'Nie znaleziono danych kontaktowych',
|
||||
], 404);
|
||||
}
|
||||
|
||||
return response()->json([
|
||||
'contact' => $contact,
|
||||
]);
|
||||
}
|
||||
|
||||
public function sendMessage(Request $request)
|
||||
{
|
||||
$validator = Validator::make($request->all(), [
|
||||
'name' => 'required|string|max:255',
|
||||
'email' => 'required|email|max:255',
|
||||
'subject' => 'required|string|max:255',
|
||||
'message' => 'required|string',
|
||||
'phone' => 'nullable|string|max:20',
|
||||
'agreement' => 'required|boolean',
|
||||
]);
|
||||
|
||||
if ($validator->fails()) {
|
||||
if ($request->expectsJson() || $request->ajax() || $request->wantsJson()) {
|
||||
return response()->json([
|
||||
'message' => 'Błąd walidacji',
|
||||
'errors' => $validator->errors(),
|
||||
], 422);
|
||||
}
|
||||
|
||||
return redirect()->back()->withErrors($validator)->withInput();
|
||||
}
|
||||
|
||||
$contact = Contact::first();
|
||||
$recipientEmail = $contact ? $contact->system_email : config('mail.from.address');
|
||||
|
||||
try {
|
||||
Mail::to($recipientEmail)->send(new \App\Mail\ContactFormMail(
|
||||
$request->name,
|
||||
$request->email,
|
||||
$request->subject,
|
||||
$request->message,
|
||||
$request->phone ?? null
|
||||
));
|
||||
|
||||
$successMessage = 'Wiadomość została wysłana pomyślnie';
|
||||
|
||||
if ($request->expectsJson() || $request->ajax() || $request->wantsJson()) {
|
||||
return response()->json([
|
||||
'message' => $successMessage,
|
||||
], 200);
|
||||
}
|
||||
|
||||
return redirect()->route('contact')->with('success', $successMessage);
|
||||
} catch (\Exception $e) {
|
||||
$errorMessage = 'Wystąpił błąd podczas wysyłania wiadomości';
|
||||
|
||||
if ($request->expectsJson() || $request->ajax() || $request->wantsJson()) {
|
||||
return response()->json([
|
||||
'message' => $errorMessage,
|
||||
'error' => $e->getMessage(),
|
||||
], 500);
|
||||
}
|
||||
|
||||
return redirect()->back()->with('error', $errorMessage)->withInput();
|
||||
}
|
||||
}
|
||||
}
|
||||
52
app/Http/Controllers/Api/DietController.php
Normal file
52
app/Http/Controllers/Api/DietController.php
Normal file
@@ -0,0 +1,52 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Api;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Models\Diet;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Storage;
|
||||
|
||||
class DietController extends Controller
|
||||
{
|
||||
public function index()
|
||||
{
|
||||
$page = request('page', 1);
|
||||
$perPage = request('per_page', 7);
|
||||
|
||||
$query = Diet::query()->where('active', true);
|
||||
|
||||
$total = $query->count();
|
||||
$diets = $query->orderBy('published_at', 'desc')
|
||||
->skip(($page - 1) * $perPage)
|
||||
->take($perPage)
|
||||
->get()
|
||||
->map(function ($diet) {
|
||||
return $this->transformDiet($diet);
|
||||
});
|
||||
|
||||
return response()->json([
|
||||
'diets' => $diets,
|
||||
'pagination' => [
|
||||
'total' => $total,
|
||||
'per_page' => (int)$perPage,
|
||||
'current_page' => (int)$page,
|
||||
'last_page' => ceil($total / $perPage),
|
||||
],
|
||||
]);
|
||||
}
|
||||
|
||||
private function transformDiet($diet)
|
||||
{
|
||||
return [
|
||||
'id' => $diet->id,
|
||||
'name' => $diet->name,
|
||||
'breakfast_photo' => $diet->breakfast_photo ? Storage::url($diet->breakfast_photo) : null,
|
||||
'lunch_photo' => $diet->lunch_photo ? Storage::url($diet->lunch_photo) : null,
|
||||
'breakfast_body' => $diet->breakfast_body,
|
||||
'lunch_body' => $diet->lunch_body,
|
||||
'published_at' => $diet->published_at,
|
||||
'diet_attachment' => $diet->diet_attachment ? Storage::url($diet->diet_attachment) : null,
|
||||
];
|
||||
}
|
||||
}
|
||||
64
app/Http/Controllers/Api/EmployeeController.php
Normal file
64
app/Http/Controllers/Api/EmployeeController.php
Normal file
@@ -0,0 +1,64 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Api;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Models\Employee;
|
||||
|
||||
class EmployeeController extends Controller
|
||||
{
|
||||
public function index()
|
||||
{
|
||||
$slug = request('slug');
|
||||
|
||||
$query = Employee::query();
|
||||
if ($slug) {
|
||||
$query->where('slug', $slug);
|
||||
}
|
||||
$employees = $query->orderBy('sort_order')->get();
|
||||
|
||||
$mainSections = [];
|
||||
$extraSections = [];
|
||||
|
||||
foreach ($employees as $employee) {
|
||||
foreach ($employee->employees as $person) {
|
||||
$targetSection = $person['data']['other-section'] ?? null;
|
||||
if ($targetSection) {
|
||||
if (!isset($extraSections[$targetSection])) {
|
||||
$extraSections[$targetSection] = [
|
||||
'name' => $targetSection,
|
||||
'slug' => $employee->slug,
|
||||
'sort_order' => $employee->sort_order,
|
||||
'employees' => [],
|
||||
];
|
||||
}
|
||||
$extraSections[$targetSection]['employees'][] = $person;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
foreach ($employees as $employee) {
|
||||
$mainPersons = array_filter($employee->employees, function($person) {
|
||||
return empty($person['data']['other-section']);
|
||||
});
|
||||
if (count($mainPersons) === 0) continue;
|
||||
$sectionName = $employee->section;
|
||||
if (!isset($mainSections[$sectionName])) {
|
||||
$mainSections[$sectionName] = [
|
||||
'name' => $sectionName,
|
||||
'slug' => $employee->slug,
|
||||
'sort_order' => $employee->sort_order,
|
||||
'employees' => [],
|
||||
];
|
||||
}
|
||||
foreach ($mainPersons as $person) {
|
||||
$mainSections[$sectionName]['employees'][] = $person;
|
||||
}
|
||||
}
|
||||
|
||||
return response()->json([
|
||||
'main' => $mainSections,
|
||||
'extra' => $extraSections,
|
||||
]);
|
||||
}
|
||||
}
|
||||
68
app/Http/Controllers/Api/FooterController.php
Normal file
68
app/Http/Controllers/Api/FooterController.php
Normal file
@@ -0,0 +1,68 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Api;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Models\Footer;
|
||||
use App\Models\Article;
|
||||
|
||||
class FooterController extends Controller
|
||||
{
|
||||
public function index()
|
||||
{
|
||||
$footer = Footer::first();
|
||||
$links = collect($footer?->links ?? [])
|
||||
->filter(function ($item) {
|
||||
return $item['type'] === 'link' && !empty($item['data']);
|
||||
})
|
||||
->map(function ($item) {
|
||||
return [
|
||||
'name' => $item['data']['name'] ?? '',
|
||||
'url' => $item['data']['url'] ?? '#',
|
||||
'external' => $item['data']['external'] ?? false,
|
||||
];
|
||||
})
|
||||
->filter(function ($link) {
|
||||
return !empty($link['name']) && !empty($link['url']);
|
||||
})
|
||||
->values()
|
||||
->all();
|
||||
|
||||
$registration_hours = collect($footer?->registration_hours ?? [])
|
||||
->filter(function ($item) {
|
||||
return $item['type'] === 'registration_hour' && !empty($item['data']);
|
||||
})
|
||||
->map(function ($item) {
|
||||
return [
|
||||
'day' => $item['data']['day'] ?? '',
|
||||
'hours' => $item['data']['hours'] ?? '',
|
||||
];
|
||||
})
|
||||
->filter(function ($registration_hour) {
|
||||
return !empty($registration_hour['day']) && !empty($registration_hour['hours']);
|
||||
})
|
||||
->values()
|
||||
->all();
|
||||
|
||||
$wospArticleId = $footer?->wosp_link;
|
||||
$wospArticleSlug = null;
|
||||
|
||||
if ($wospArticleId) {
|
||||
$article = Article::with('categories')->find($wospArticleId);
|
||||
if ($article) {
|
||||
if ($article->categories->count() > 0) {
|
||||
$firstCategory = $article->categories->first();
|
||||
$wospArticleSlug = '/informacje/' . $firstCategory->slug . '/' . $article->slug;
|
||||
} else {
|
||||
$wospArticleSlug = '/informacje/' . $article->slug;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return response()->json([
|
||||
'wosp_link' => $wospArticleSlug,
|
||||
'registration_hours' => $registration_hours,
|
||||
'links' => $links,
|
||||
]);
|
||||
}
|
||||
}
|
||||
41
app/Http/Controllers/Api/HeaderController.php
Normal file
41
app/Http/Controllers/Api/HeaderController.php
Normal file
@@ -0,0 +1,41 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Api;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Models\Header;
|
||||
|
||||
class HeaderController extends Controller
|
||||
{
|
||||
public function index()
|
||||
{
|
||||
$header = Header::first();
|
||||
$links = collect($header?->links ?? [])
|
||||
->filter(function ($item) {
|
||||
return $item['type'] === 'link' && !empty($item['data']);
|
||||
})
|
||||
->map(function ($item) {
|
||||
return [
|
||||
'name' => $item['data']['name'] ?? '',
|
||||
'icon' => $item['data']['icon'] ?? null,
|
||||
'icon-alt' => $item['data']['icon-alt'] ?? null,
|
||||
'url' => $item['data']['url'] ?? '#',
|
||||
'external' => $item['data']['external'] ?? false,
|
||||
];
|
||||
})
|
||||
->filter(function ($link) {
|
||||
return !empty($link['name']) && !empty($link['url']);
|
||||
})
|
||||
->values()
|
||||
->all();
|
||||
|
||||
return response()->json([
|
||||
'title1' => $header?->title1,
|
||||
'title2' => $header?->title2,
|
||||
'subtitle' => $header?->subtitle,
|
||||
'logo' => $header?->logo ? '/storage/' . $header->logo : null,
|
||||
'telephone' => $header?->telephone,
|
||||
'links' => $links,
|
||||
]);
|
||||
}
|
||||
}
|
||||
99
app/Http/Controllers/Api/HomepageController.php
Normal file
99
app/Http/Controllers/Api/HomepageController.php
Normal file
@@ -0,0 +1,99 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Api;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Models\Homepage;
|
||||
use DOMDocument;
|
||||
use DOMXPath;
|
||||
|
||||
class HomepageController extends Controller
|
||||
{
|
||||
private function cleanFileInfo(?string $html): ?string
|
||||
{
|
||||
if (!$html) {
|
||||
return $html;
|
||||
}
|
||||
|
||||
try {
|
||||
$dom = new DOMDocument();
|
||||
libxml_use_internal_errors(true);
|
||||
$dom->loadHTML(mb_convert_encoding($html, 'HTML-ENTITIES', 'UTF-8'), LIBXML_HTML_NOIMPLIED | LIBXML_HTML_NODEFDTD);
|
||||
libxml_clear_errors();
|
||||
|
||||
$xpath = new DOMXPath($dom);
|
||||
|
||||
$figcaptions = $xpath->query('//figcaption');
|
||||
if ($figcaptions) {
|
||||
foreach ($figcaptions as $figcaption) {
|
||||
if ($figcaption && $figcaption->parentNode) {
|
||||
$figcaption->parentNode->removeChild($figcaption);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$imageLinks = $xpath->query('//a[.//img]');
|
||||
if ($imageLinks) {
|
||||
foreach ($imageLinks as $link) {
|
||||
if (!$link || !$link->parentNode) continue;
|
||||
|
||||
$images = $xpath->query('.//img', $link);
|
||||
if (!$images) continue;
|
||||
|
||||
$parent = $link->parentNode;
|
||||
|
||||
foreach ($images as $img) {
|
||||
if ($img) {
|
||||
$link->removeChild($img);
|
||||
$parent->insertBefore($img, $link);
|
||||
}
|
||||
}
|
||||
|
||||
$parent->removeChild($link);
|
||||
}
|
||||
}
|
||||
|
||||
return $dom->saveHTML();
|
||||
} catch (\Exception $e) {
|
||||
return $html;
|
||||
}
|
||||
}
|
||||
public function index()
|
||||
{
|
||||
$homepage = Homepage::first();
|
||||
$carouselPhotos = collect($homepage?->carousel_photos ?? [])
|
||||
->filter(function ($item) {
|
||||
return $item['type'] === 'carousel_photo' && !empty($item['data']);
|
||||
})
|
||||
->map(function ($item) {
|
||||
return [
|
||||
'name' => $item['data']['name'] ?? '',
|
||||
'photo' => '/storage/' . $item['data']['photo'] ?? null,
|
||||
'description' => $item['data']['description'] ?? null,
|
||||
'url' => $item['data']['url'] ?? '#',
|
||||
'external' => $item['data']['external'] ?? false,
|
||||
];
|
||||
})
|
||||
->filter(function ($carousel_photo) {
|
||||
return !empty($carousel_photo['name']) && !empty($carousel_photo['url']) && !empty($carousel_photo['photo']) && !empty($carousel_photo['description']);
|
||||
})
|
||||
->values()
|
||||
->all();
|
||||
|
||||
$content = null;
|
||||
if ($homepage && $homepage->content) {
|
||||
try {
|
||||
$content = $this->cleanFileInfo($homepage->content);
|
||||
} catch (\Exception $e) {
|
||||
$content = $homepage->content;
|
||||
}
|
||||
}
|
||||
|
||||
return response()->json([
|
||||
'title' => $homepage?->title,
|
||||
'content' => $content,
|
||||
'photo' => $homepage?->photo ? '/storage/' . $homepage->photo : null,
|
||||
'carouselPhotos' => $carouselPhotos,
|
||||
]);
|
||||
}
|
||||
}
|
||||
111
app/Http/Controllers/Api/JobOffersController.php
Normal file
111
app/Http/Controllers/Api/JobOffersController.php
Normal file
@@ -0,0 +1,111 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Api;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Models\JobOffers;
|
||||
use DOMDocument;
|
||||
use DOMXPath;
|
||||
|
||||
class JobOffersController extends Controller
|
||||
{
|
||||
private function cleanFileInfo(?string $html): ?string
|
||||
{
|
||||
if (!$html) {
|
||||
return $html;
|
||||
}
|
||||
|
||||
try {
|
||||
$dom = new DOMDocument();
|
||||
libxml_use_internal_errors(true);
|
||||
$dom->loadHTML(mb_convert_encoding($html, 'HTML-ENTITIES', 'UTF-8'), LIBXML_HTML_NOIMPLIED | LIBXML_HTML_NODEFDTD);
|
||||
libxml_clear_errors();
|
||||
|
||||
$xpath = new DOMXPath($dom);
|
||||
|
||||
$figcaptions = $xpath->query('//figcaption');
|
||||
if ($figcaptions) {
|
||||
foreach ($figcaptions as $figcaption) {
|
||||
if ($figcaption && $figcaption->parentNode) {
|
||||
$figcaption->parentNode->removeChild($figcaption);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$imageLinks = $xpath->query('//a[.//img]');
|
||||
if ($imageLinks) {
|
||||
foreach ($imageLinks as $link) {
|
||||
if (!$link || !$link->parentNode) continue;
|
||||
|
||||
$images = $xpath->query('.//img', $link);
|
||||
if (!$images) continue;
|
||||
|
||||
$parent = $link->parentNode;
|
||||
|
||||
foreach ($images as $img) {
|
||||
if ($img) {
|
||||
$link->removeChild($img);
|
||||
$parent->insertBefore($img, $link);
|
||||
}
|
||||
}
|
||||
|
||||
$parent->removeChild($link);
|
||||
}
|
||||
}
|
||||
|
||||
return $dom->saveHTML();
|
||||
} catch (\Exception $e) {
|
||||
return $html;
|
||||
}
|
||||
}
|
||||
|
||||
public function index()
|
||||
{
|
||||
$slug = request('slug');
|
||||
|
||||
$query = JobOffers::query()->where('active', true);
|
||||
|
||||
if ($slug) {
|
||||
$query->where('slug', $slug);
|
||||
}
|
||||
|
||||
$query->with(['photos', 'attachments']);
|
||||
|
||||
$jobOffers = $query->orderBy('published_at', 'desc')->get()->map(function ($item) {
|
||||
if ($item->thumbnail && !str_starts_with($item->thumbnail, '/storage/')) {
|
||||
$item->thumbnail = '/storage/' . ltrim($item->thumbnail, '/');
|
||||
}
|
||||
|
||||
if ($item->photos) {
|
||||
$item->photos->transform(function ($photo) {
|
||||
if ($photo->image_path && !str_starts_with($photo->image_path, '/storage/')) {
|
||||
$photo->image_path = '/storage/' . ltrim($photo->image_path, '/');
|
||||
}
|
||||
return $photo;
|
||||
});
|
||||
}
|
||||
|
||||
if ($item->attachments) {
|
||||
$item->attachments->transform(function ($attachment) {
|
||||
if ($attachment->file_path && !str_starts_with($attachment->file_path, '/storage/')) {
|
||||
$attachment->file_path = '/storage/' . ltrim($attachment->file_path, '/');
|
||||
}
|
||||
return $attachment;
|
||||
});
|
||||
}
|
||||
|
||||
if ($item->body) {
|
||||
$item->body = $this->cleanFileInfo($item->body);
|
||||
}
|
||||
if ($item->additional_information) {
|
||||
$item->additional_information = $this->cleanFileInfo($item->additional_information);
|
||||
}
|
||||
|
||||
return $item;
|
||||
});
|
||||
|
||||
return response()->json([
|
||||
'jobOffers' => $jobOffers
|
||||
]);
|
||||
}
|
||||
}
|
||||
68
app/Http/Controllers/Api/NavigationItemController.php
Normal file
68
app/Http/Controllers/Api/NavigationItemController.php
Normal file
@@ -0,0 +1,68 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Api;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use Illuminate\Http\Request;
|
||||
use App\Models\NavigationItem;
|
||||
use App\Models\Category;
|
||||
use App\Models\Article;
|
||||
|
||||
class NavigationItemController extends Controller
|
||||
{
|
||||
public function index()
|
||||
{
|
||||
$items = NavigationItem::orderBy('sort_order')->get();
|
||||
$result = $items->map(function ($item) {
|
||||
|
||||
$type = $item->navigable_type;
|
||||
if ($type === 'Article') {
|
||||
$article = Article::find($item->navigable_id);
|
||||
$name = $item->name ?? ($article ? $article->title : null);
|
||||
if ($article && $article->type !== 'link' && $article->slug) {
|
||||
$articleWithCategories = Article::with('categories')->find($article->id);
|
||||
|
||||
if ($articleWithCategories->categories->count() > 0) {
|
||||
$firstCategory = $articleWithCategories->categories->first();
|
||||
$article->slug = '/informacje/' . $firstCategory->slug . '/' . ltrim($article->slug, '/');
|
||||
} else {
|
||||
$article->slug = '/informacje/' . ltrim($article->slug, '/');
|
||||
}
|
||||
}
|
||||
return [
|
||||
'id' => $item->id,
|
||||
'name' => $name,
|
||||
'sort_order' => $item->sort_order,
|
||||
'type' => 'article',
|
||||
'article' => $article,
|
||||
];
|
||||
} elseif ($type === 'Category') {
|
||||
$category = Category::find($item->navigable_id);
|
||||
$articles = $category
|
||||
? $category->articles()->orderBy('category_article.sort_order')->get()->map(function($article) use ($category) {
|
||||
if ($article->type !== 'link' && $article->slug) {
|
||||
$article->slug = '/informacje/' . $category->slug . '/' . ltrim($article->slug, '/');
|
||||
}
|
||||
return $article;
|
||||
})
|
||||
: [];
|
||||
$name = $item->name ?? ($category ? $category->title : null);
|
||||
return [
|
||||
'id' => $item->id,
|
||||
'name' => $name,
|
||||
'sort_order' => $item->sort_order,
|
||||
'type' => 'category',
|
||||
'articles' => $articles,
|
||||
];
|
||||
} else {
|
||||
return [
|
||||
'id' => $item->id,
|
||||
'name' => $item->name,
|
||||
'sort_order' => $item->sort_order,
|
||||
'type' => $type
|
||||
];
|
||||
}
|
||||
});
|
||||
return response()->json($result);
|
||||
}
|
||||
}
|
||||
47
app/Http/Controllers/Api/PriceController.php
Normal file
47
app/Http/Controllers/Api/PriceController.php
Normal file
@@ -0,0 +1,47 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Api;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Models\Attachment;
|
||||
use App\Models\Price;
|
||||
use App\Models\Article;
|
||||
|
||||
class PriceController extends Controller
|
||||
{
|
||||
public function index()
|
||||
{
|
||||
$price = Price::first();
|
||||
$attachment = null;
|
||||
$categoryTitle = null;
|
||||
|
||||
if ($price && $price->attachment_id) {
|
||||
$attachment = Attachment::find($price->attachment_id);
|
||||
|
||||
if ($attachment && $attachment->file_path && !str_starts_with($attachment->file_path, '/storage/')) {
|
||||
$attachment->file_path = '/storage/' . ltrim($attachment->file_path, '/');
|
||||
}
|
||||
}
|
||||
|
||||
$priceArticle = Article::where('type', 'link')
|
||||
->where(function($query) {
|
||||
$query->where('slug', 'like', '/cennik-badan');
|
||||
})
|
||||
->first();
|
||||
|
||||
if ($priceArticle) {
|
||||
$categories = $priceArticle->categories;
|
||||
|
||||
if ($categories && $categories->count() > 0) {
|
||||
$categoryTitle = $categories->first()->title;
|
||||
} else {
|
||||
$categoryTitle = null;
|
||||
}
|
||||
}
|
||||
|
||||
return response()->json([
|
||||
'attachment' => $attachment,
|
||||
'category' => $categoryTitle
|
||||
]);
|
||||
}
|
||||
}
|
||||
156
app/Http/Controllers/Api/ProjectController.php
Normal file
156
app/Http/Controllers/Api/ProjectController.php
Normal file
@@ -0,0 +1,156 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Api;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Models\ProjectArticle;
|
||||
use App\Models\ProjectType;
|
||||
use Illuminate\Http\Request;
|
||||
use DOMDocument;
|
||||
use DOMXPath;
|
||||
|
||||
class ProjectController extends Controller
|
||||
{
|
||||
private function cleanFileInfo(?string $html): ?string
|
||||
{
|
||||
if (!$html) {
|
||||
return $html;
|
||||
}
|
||||
|
||||
$dom = new DOMDocument();
|
||||
libxml_use_internal_errors(true);
|
||||
$dom->loadHTML(mb_convert_encoding($html, 'HTML-ENTITIES', 'UTF-8'), LIBXML_HTML_NOIMPLIED | LIBXML_HTML_NODEFDTD);
|
||||
libxml_clear_errors();
|
||||
|
||||
$xpath = new DOMXPath($dom);
|
||||
|
||||
$figcaptions = $xpath->query('//figcaption');
|
||||
foreach ($figcaptions as $figcaption) {
|
||||
$figcaption->parentNode->removeChild($figcaption);
|
||||
}
|
||||
|
||||
$imageLinks = $xpath->query('//a[.//img]');
|
||||
foreach ($imageLinks as $link) {
|
||||
$images = $xpath->query('.//img', $link);
|
||||
$parent = $link->parentNode;
|
||||
|
||||
foreach ($images as $img) {
|
||||
$link->removeChild($img);
|
||||
$parent->insertBefore($img, $link);
|
||||
}
|
||||
|
||||
$parent->removeChild($link);
|
||||
}
|
||||
|
||||
return $dom->saveHTML();
|
||||
}
|
||||
public function index(Request $request, $typeSlug = null)
|
||||
{
|
||||
$query = ProjectArticle::query()
|
||||
->where('active', true)
|
||||
->with(['projectTypes', 'photos', 'attachments']);
|
||||
|
||||
if ($typeSlug) {
|
||||
$projectType = ProjectType::where('slug', $typeSlug)->first();
|
||||
|
||||
if ($projectType) {
|
||||
$query->whereHas('projectTypes', function ($q) use ($projectType) {
|
||||
$q->where('project_types.id', $projectType->id);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
$projects = $query->orderBy('published_at', 'desc')
|
||||
->get()
|
||||
->map(function ($item) {
|
||||
if ($item->logo && !str_starts_with($item->logo, '/storage/')) {
|
||||
$item->logo = '/storage/' . ltrim($item->logo, '/');
|
||||
}
|
||||
|
||||
if ($item->photos) {
|
||||
$item->photos->transform(function ($photo) {
|
||||
if ($photo->image_path && !str_starts_with($photo->image_path, '/storage/')) {
|
||||
$photo->image_path = '/storage/' . ltrim($photo->image_path, '/');
|
||||
}
|
||||
return $photo;
|
||||
});
|
||||
}
|
||||
|
||||
if ($item->attachments) {
|
||||
$item->attachments->transform(function ($attachment) {
|
||||
if ($attachment->file_path && !str_starts_with($attachment->file_path, '/storage/')) {
|
||||
$attachment->file_path = '/storage/' . ltrim($attachment->file_path, '/');
|
||||
}
|
||||
return $attachment;
|
||||
});
|
||||
}
|
||||
|
||||
if ($item->body) {
|
||||
$item->body = $this->cleanFileInfo($item->body);
|
||||
}
|
||||
|
||||
return $item;
|
||||
});
|
||||
|
||||
return response()->json([
|
||||
'projects' => $projects,
|
||||
'projectType' => $typeSlug ? ProjectType::where('slug', $typeSlug)->first() : null
|
||||
]);
|
||||
}
|
||||
|
||||
public function show(Request $request, $typeSlug, $projectSlug)
|
||||
{
|
||||
$projectType = ProjectType::where('slug', $typeSlug)->first();
|
||||
|
||||
if (!$projectType) {
|
||||
return response()->json([
|
||||
'error' => 'Nie znaleziono typu projektu'
|
||||
], 404);
|
||||
}
|
||||
|
||||
$project = ProjectArticle::where('slug', $projectSlug)
|
||||
->where('active', true)
|
||||
->whereHas('projectTypes', function ($query) use ($projectType) {
|
||||
$query->where('project_types.id', $projectType->id);
|
||||
})
|
||||
->with(['projectTypes', 'photos', 'attachments'])
|
||||
->first();
|
||||
|
||||
if (!$project) {
|
||||
return response()->json([
|
||||
'error' => 'Nie znaleziono projektu'
|
||||
], 404);
|
||||
}
|
||||
|
||||
if ($project->logo && !str_starts_with($project->logo, '/storage/')) {
|
||||
$project->logo = '/storage/' . ltrim($project->logo, '/');
|
||||
}
|
||||
|
||||
if ($project->photos) {
|
||||
$project->photos->transform(function ($photo) {
|
||||
if ($photo->image_path && !str_starts_with($photo->image_path, '/storage/')) {
|
||||
$photo->image_path = '/storage/' . ltrim($photo->image_path, '/');
|
||||
}
|
||||
return $photo;
|
||||
});
|
||||
}
|
||||
|
||||
if ($project->attachments) {
|
||||
$project->attachments->transform(function ($attachment) {
|
||||
if ($attachment->file_path && !str_starts_with($attachment->file_path, '/storage/')) {
|
||||
$attachment->file_path = '/storage/' . ltrim($attachment->file_path, '/');
|
||||
}
|
||||
return $attachment;
|
||||
});
|
||||
}
|
||||
|
||||
if ($project->body) {
|
||||
$project->body = $this->cleanFileInfo($project->body);
|
||||
}
|
||||
|
||||
return response()->json([
|
||||
'project' => $project,
|
||||
'projectType' => $projectType
|
||||
]);
|
||||
}
|
||||
}
|
||||
19
app/Http/Controllers/Api/TelephoneController.php
Normal file
19
app/Http/Controllers/Api/TelephoneController.php
Normal file
@@ -0,0 +1,19 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Api;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Models\Telephone;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
class TelephoneController extends Controller
|
||||
{
|
||||
public function index()
|
||||
{
|
||||
$telephones = Telephone::orderBy('sort_order', 'asc')->get();
|
||||
|
||||
return response()->json([
|
||||
'telephones' => $telephones,
|
||||
]);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user