diff --git a/app/Http/Controllers/ContactsController.php b/app/Http/Controllers/ContactsController.php new file mode 100644 index 0000000..71d6ced --- /dev/null +++ b/app/Http/Controllers/ContactsController.php @@ -0,0 +1,22 @@ +addCssFile('contacts.css'); + } + + public function index() + { + $contacts = $this->contactManager->getContacts(); + + return $this->render('contacts') + ->with(compact('contacts')); + } +} diff --git a/app/Models/Loaders/UsersLoader.php b/app/Models/Loaders/UsersLoader.php new file mode 100644 index 0000000..19efed2 --- /dev/null +++ b/app/Models/Loaders/UsersLoader.php @@ -0,0 +1,21 @@ +join("contactRoles", "users.contactRole", "=", "contactRoles.id") + ->where("users.useAsContact", 1) + ->get(); + + return $data ? $data->toArray() : []; + } +} diff --git a/app/Models/Managers/ContactManager.php b/app/Models/Managers/ContactManager.php new file mode 100644 index 0000000..e5311d6 --- /dev/null +++ b/app/Models/Managers/ContactManager.php @@ -0,0 +1,32 @@ +imgDir = config('directories.images'); + } + + public function getContacts(): array + { + $data = $this->usersLoader->getContacts(); + + $contacts = []; + foreach($data as $row) { + $contact = new Contact(); + $contact->setImgPath($this->imgDir); + $contact->setAttributes($row); + $contacts[] = $contact; + } + + return $contacts; + } +} diff --git a/app/Models/ORM/User.php b/app/Models/ORM/User.php new file mode 100644 index 0000000..07c57e2 --- /dev/null +++ b/app/Models/ORM/User.php @@ -0,0 +1,11 @@ +imgPath = $path; + } + + public function __construct(array $data = []) + { + if($data) { + $this->setAttributes($data); + } + } + + public function getFullName(): string + { + return sprintf("%s %s", $this->firstName, $this->lastName); + } + + public function toArray(): array + { + return [ + 'id' => $this->id, + 'login' => $this->login, + 'firstName' => $this->firstName, + 'lastName' => $this->lastName, + 'phone' => $this->phone, + 'email' => $this->email, + 'imgSmall' => $this->imgSmall, + 'imgLarge' => $this->imgLarge, + 'role' => $this->role, + ]; + } + + public function setAttributes(array $attributes = []):void + { + $this->id = $attributes['id'] ?? null; + $this->login = $attributes['login']; + $this->firstName = $attributes['firstName']; + $this->lastName = $attributes['lastName']; + $this->phone = $attributes['phone']; + $this->email = $attributes['email']; + $this->webPage = $attributes['webPage'] ?? null; + $this->role = $attributes['role'] ?? null; + $this->imgSmall = $this->setImagePath($attributes['img_small']) ?? null; + $this->imgLarge = $this->setImagePath($attributes['img_large']) ?? null; + } + + private function setImagePath(string $path = null): string + { + return $this->imgPath ? + $this->cleanURL($this->imgPath."/".$path) : $path; + } + + private function cleanURL(string $url): string + { + return preg_replace('#(?imgSmall = $imgSmall; + } + + public function setImgLarge(string $imgLarge): void + { + $this->imgLarge = $imgLarge; + } + + public function getId(): ?int + { + return $this->id; + } + + public function getLogin(): string + { + return $this->login; + } + + public function getFirstName(): string + { + return $this->firstName; + } + + public function getLastName(): string + { + return $this->lastName; + } + + public function getPhone(): string + { + return $this->phone; + } + + public function getEmail(): string + { + return $this->email; + } + + public function getImgSmall(): ?string + { + return $this->imgSmall; + } + + public function getImgLarge(): ?string + { + return $this->imgLarge; + } + + public function getImgPath(): string + { + return $this->imgPath; + } + + public function getWebpage(): ?string + { + return $this->webPage; + } + + public function getRole(): ?string + { + return $this->role; + } +} +?> diff --git a/config/directories.php b/config/directories.php new file mode 100644 index 0000000..eb0df93 --- /dev/null +++ b/config/directories.php @@ -0,0 +1,4 @@ + "/img/contacts/" +]; diff --git a/config/menu.php b/config/menu.php index b6966c9..7796530 100644 --- a/config/menu.php +++ b/config/menu.php @@ -13,6 +13,6 @@ return [ "band" => [ "name"=>"Состав","url"=>"band","visible"=>1 ] ], ], - "media" => ["name"=>"Медиа","url"=>"media","visible"=> 1], + "media" => ["name"=>"Медиа","url"=>"media","visible"=> 0], "contacts" => ["name"=>"Контакты","url"=>"contacts","visible"=> 1] ]; diff --git a/resources/views/band.blade.php b/resources/views/band.blade.php index 3973cdb..ed78512 100644 --- a/resources/views/band.blade.php +++ b/resources/views/band.blade.php @@ -24,6 +24,7 @@ @section('breadcrump') @endsection diff --git a/resources/views/contacts.blade.php b/resources/views/contacts.blade.php new file mode 100644 index 0000000..ffee672 --- /dev/null +++ b/resources/views/contacts.blade.php @@ -0,0 +1,48 @@ +@extends('main') +@section('title', 'Контакты') +@section('content') + +
+ +
+ + + @foreach($contacts as $contact) +
+
+

{{ $contact->getRole() }}

+
+ + + + + + + + + + + + + + +
{{ $contact->getFullName() }}
{{ $contact->getPhone() }}
+ {{ $contact->getEmail() }} +
+ +
+
+
+
+ @endforeach +
+ +
+ +@endsection + +@section('breadcrump') + +@endsection diff --git a/resources/views/main.blade.php b/resources/views/main.blade.php index 4ea3870..c10e14f 100644 --- a/resources/views/main.blade.php +++ b/resources/views/main.blade.php @@ -23,7 +23,7 @@
@include('include.menu')
@yield('content')
-
@include('include.footer')
content +
@include('include.footer')
@foreach($js_files as $js) diff --git a/resources/views/playlist.blade.php b/resources/views/playlist.blade.php index 46acbf2..092f831 100644 --- a/resources/views/playlist.blade.php +++ b/resources/views/playlist.blade.php @@ -55,6 +55,7 @@ @section('breadcrump') @endsection diff --git a/resources/views/rider.blade.php b/resources/views/rider.blade.php index 5d882f1..6641c79 100644 --- a/resources/views/rider.blade.php +++ b/resources/views/rider.blade.php @@ -88,6 +88,7 @@ @section('breadcrump') @endsection diff --git a/routes/web.php b/routes/web.php index 47013c5..48966d8 100755 --- a/routes/web.php +++ b/routes/web.php @@ -7,6 +7,7 @@ use App\Http\Controllers\PlaylistController; use App\Http\Controllers\BandController; use App\Http\Controllers\GigsController; use App\Http\Controllers\NewsController; +use App\Http\Controllers\ContactsController; Route::get('/', [MainController::class, 'index']); Route::get('/rider', [RiderController::class, 'index']); @@ -14,8 +15,9 @@ Route::get('/playlist', [PlaylistController::class, 'index']); Route::get('/band', [BandController::class, 'index']); Route::get('/gigs', [GigsController::class, 'index']); Route::get('/news', [NewsController::class, 'index']); +Route::get('/contacts', [ContactsController::class, 'index']); + /** - * Доделать остальные маршруты - * и сотальные страницы требуют ... + * Доделать остальные маршруты.. */