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') + +| {{ $contact->getFullName() }} | +|
| {{ $contact->getPhone() }} | +|
| + {{ $contact->getEmail() }} + | +|
| + {{ $contact->getWebpage() }} + | +