Added contact page
This commit is contained in:
@@ -0,0 +1,21 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models\Loaders;
|
||||
|
||||
use App\Models\ORM\User;
|
||||
|
||||
class UsersLoader
|
||||
{
|
||||
public function getContacts(): array
|
||||
{
|
||||
$data = User::select(
|
||||
"users.id","users.login","users.firstName","users.lastName",
|
||||
"users.phone", "users.email", "users.vkcom as webPage",
|
||||
"users.img_large","users.img_small","contactRoles.name as role"
|
||||
)->join("contactRoles", "users.contactRole", "=", "contactRoles.id")
|
||||
->where("users.useAsContact", 1)
|
||||
->get();
|
||||
|
||||
return $data ? $data->toArray() : [];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models\Managers;
|
||||
|
||||
use App\Models\Loaders\UsersLoader;
|
||||
use App\Models\Objects\Contact;
|
||||
|
||||
class ContactManager
|
||||
{
|
||||
private string $imgDir;
|
||||
|
||||
public function __construct(
|
||||
private UsersLoader $usersLoader,
|
||||
) {
|
||||
$this->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;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models\ORM;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class User extends Model
|
||||
{
|
||||
protected $primaryKey = 'id';
|
||||
protected $table = 'users';
|
||||
}
|
||||
@@ -0,0 +1,141 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models\Objects;
|
||||
|
||||
class Contact
|
||||
{
|
||||
private ?int $id;
|
||||
private string $login;
|
||||
private string $firstName;
|
||||
private string $lastName;
|
||||
private string $phone;
|
||||
private string $email;
|
||||
private ?string $imgSmall;
|
||||
private ?string $imgLarge;
|
||||
private string $imgPath;
|
||||
private ?string $webPage;
|
||||
private ?string $role;
|
||||
|
||||
public function setImgPath(string $path): void
|
||||
{
|
||||
$this->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('#(?<!:)/+#', '/', $url);
|
||||
}
|
||||
|
||||
public function setImgSmall(string $imgSmall): void
|
||||
{
|
||||
$this->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;
|
||||
}
|
||||
}
|
||||
?>
|
||||
Reference in New Issue
Block a user