src/Entity/TelegramBotNavigation.php line 11

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use App\Repository\TelegramBotNavigationRepository;
  4. use Doctrine\ORM\Mapping as ORM;
  5. /**
  6.  * @ORM\Entity(repositoryClass=TelegramBotNavigationRepository::class)
  7.  */
  8. class TelegramBotNavigation
  9. {
  10.     /**
  11.      * @ORM\Id
  12.      * @ORM\GeneratedValue
  13.      * @ORM\Column(type="integer")
  14.      */
  15.     private $id;
  16.     /**
  17.      * @ORM\Column(type="text", nullable=true)
  18.      */
  19.     private $data;
  20.     /**
  21.      * @ORM\Column(type="string", length=255)
  22.      */
  23.     private $botId;
  24.     /**
  25.      * @ORM\Column(type="text", nullable=true)
  26.      */
  27.     private $selectedData;
  28.     /**
  29.      * @ORM\ManyToOne(targetEntity=TelegramUser::class)
  30.      * @ORM\JoinColumn(nullable=false)
  31.      */
  32.     private $user;
  33.     /**
  34.      * @ORM\Column(type="text", nullable=true)
  35.      */
  36.     private $editableMessages;
  37.     public function getId(): ?int
  38.     {
  39.         return $this->id;
  40.     }
  41.     public function getData(): ?array
  42.     {
  43.         return json_decode($this->data ?? "{}"true);
  44.     }
  45.     public function setData(?array $data): self
  46.     {
  47.         if ($data === null) {
  48.             $this->data null;
  49.             return $this;
  50.         }
  51.         $this->data json_encode($dataJSON_UNESCAPED_SLASHES JSON_UNESCAPED_UNICODE);
  52.         return $this;
  53.     }
  54.     public function setNavigationGroupData(string $groupId, ?array $data): self
  55.     {
  56.         $allData $this->getData() ?? [];
  57.         if ($data === null) {
  58.             unset($allData[$groupId]);
  59.         } else {
  60.             $allData[$groupId] = $data;
  61.         }
  62.         $this->setData($allData);
  63.         return $this;
  64.     }
  65.     public function getNavigationGroupData(string $groupId): ?array
  66.     {
  67.         $allData $this->getData() ?? [];
  68.         return $allData[$groupId] ?? null;
  69.     }
  70.     public function getBotId(): ?string
  71.     {
  72.         return $this->botId;
  73.     }
  74.     public function setBotId(string $botId): self
  75.     {
  76.         $this->botId $botId;
  77.         return $this;
  78.     }
  79.     public function getSelectedData(): ?array
  80.     {
  81.         return json_decode($this->selectedData ?? "{}"true);
  82.     }
  83.     public function setSelectedData(?array $selectedData): self
  84.     {
  85.         $this->selectedData json_encode($selectedDataJSON_UNESCAPED_SLASHES JSON_UNESCAPED_UNICODE);
  86.         return $this;
  87.     }
  88.     public function getSelectedItem(string $groupId)
  89.     {
  90.         $allData $this->getSelectedData() ?? [];
  91.         $itemId $allData[$groupId] ?? null;
  92.         $groupData $this->getNavigationGroupData($groupId);
  93.         if ($groupData && $itemId && isset($groupData[$itemId])) {
  94.             return $groupData[$itemId];
  95.         }
  96.     }
  97.     public function setSelectedItemId(string $groupId, ?string $itemId): self
  98.     {
  99.         $allData $this->getSelectedData() ?? [];
  100.         $allData[$groupId] = $itemId;
  101.         $this->setSelectedData($allData);
  102.         return $this;
  103.     }
  104.     public function getUser(): ?TelegramUser
  105.     {
  106.         return $this->user;
  107.     }
  108.     public function setUser(?TelegramUser $user): self
  109.     {
  110.         $this->user $user;
  111.         return $this;
  112.     }
  113.     public function getEditableMessages(): ?array
  114.     {
  115.         return json_decode($this->editableMessages ?? "[]"true);
  116.     }
  117.     public function setEditableMessages(?array $editableMessages): self
  118.     {
  119.         $this->editableMessages json_encode($editableMessagesJSON_UNESCAPED_SLASHES JSON_UNESCAPED_UNICODE);
  120.         return $this;
  121.     }
  122.     public function setEditableMessageId(string $messageId, ?string $telegramMessageId): self
  123.     {
  124.         $allMessages $this->getEditableMessages() ?? [];
  125.         $allMessages[$messageId] = $telegramMessageId;
  126.         $this->setEditableMessages($allMessages);
  127.         return $this;
  128.     }
  129.     public function getEditableMessageId(string $messageId): ?string
  130.     {
  131.         $allMessages $this->getEditableMessages() ?? [];
  132.         return $allMessages[$messageId] ?? null;
  133.     }
  134. }