78 lines
2.1 KiB
PHP
78 lines
2.1 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace KupShop\SalesmanBundle\Twig\Components;
|
|
|
|
use KupShop\ComponentsBundle\Attributes\Component;
|
|
use KupShop\ComponentsBundle\Attributes\Version;
|
|
use KupShop\ComponentsBundle\Entity\Thumbnail;
|
|
use KupShop\ComponentsBundle\Twig\BaseComponent;
|
|
use KupShop\KupShopBundle\Context\UserContext;
|
|
use KupShop\KupShopBundle\Util\Contexts;
|
|
use Query\Operator;
|
|
use Symfony\UX\TwigComponent\Attribute\AsTwigComponent;
|
|
use Symfony\UX\TwigComponent\Attribute\PostMount;
|
|
|
|
#[AsTwigComponent(template: '@Salesman/components/Salesman/Salesman.1.html.twig')]
|
|
#[Component(1, [
|
|
new Version(1, newJs: null),
|
|
])]
|
|
class Salesman extends BaseComponent
|
|
{
|
|
public ?int $id_user;
|
|
protected ?array $salesman;
|
|
public bool $show_picture = true;
|
|
|
|
#[PostMount]
|
|
public function setUserId(): void
|
|
{
|
|
if (!isset($this->id_user)) {
|
|
$this->id_user = Contexts::get(UserContext::class)->getActiveId();
|
|
}
|
|
}
|
|
|
|
public function getSalesman(): ?array
|
|
{
|
|
if (isset($this->salesman)) {
|
|
return $this->salesman;
|
|
}
|
|
|
|
if (!$this->id_user) {
|
|
return null;
|
|
}
|
|
|
|
$salesmanId = sqlQueryBuilder()
|
|
->select('id_salesman')
|
|
->from('users')
|
|
->andWhere(Operator::equals(['id' => $this->id_user]))
|
|
->execute()->fetchOne();
|
|
|
|
if (!$salesmanId) {
|
|
return null;
|
|
}
|
|
|
|
$this->salesman = sqlQueryBuilder()
|
|
->select('sm.*, ph.descr photo_descr, ph.date_update photo_date_update')
|
|
->from('salesman', 'sm')
|
|
->leftJoin('sm', 'photos', 'ph', 'ph.id = sm.id_photo')
|
|
->where(Operator::equals(['sm.id' => $salesmanId]))
|
|
->execute()->fetchAssociative();
|
|
|
|
return $this->salesman ?: null;
|
|
}
|
|
|
|
public function getThumbnail(): ?Thumbnail
|
|
{
|
|
if (!empty($this->salesman['id_photo'])) {
|
|
return new Thumbnail(
|
|
(string) $this->salesman['id_photo'],
|
|
$this->salesman['photo_descr'],
|
|
(string) $this->salesman['photo_date_update']
|
|
);
|
|
}
|
|
|
|
return null;
|
|
}
|
|
}
|