Some fixes

This commit is contained in:
Thomas 2024-05-09 17:11:05 +02:00
parent f9172b14f6
commit 470dc8c714
5 changed files with 54 additions and 59 deletions

View file

@ -143,11 +143,12 @@ class FediPlanController extends AbstractController
$pollOption1 = new PollOption(); $pollOption1 = new PollOption();
$pollOption1->setTitle(""); $pollOption1->setTitle("");
$compose->getPollOptions()->add($pollOption1); $options = $compose->getPollOptions();
$options[] = $pollOption1;
$pollOption2 = new PollOption(); $pollOption2 = new PollOption();
$pollOption2->setTitle(""); $pollOption2->setTitle("");
$compose->getPollOptions()->add($pollOption2); $options[] = $pollOption2;
/* @var $user MastodonAccount */ $compose->setPollOptions($options);
$user = $this->getUser(); $user = $this->getUser();
$form = $this->createForm(ComposeType::class, $compose, ['user' => $user]); $form = $this->createForm(ComposeType::class, $compose, ['user' => $user]);
$form->handleRequest($request); $form->handleRequest($request);
@ -231,10 +232,12 @@ class FediPlanController extends AbstractController
$compose = new Compose(); $compose = new Compose();
$pollOption1 = new PollOption(); $pollOption1 = new PollOption();
$pollOption1->setTitle(""); $pollOption1->setTitle("");
$compose->getPollOptions()->add($pollOption1); $options = $compose->getPollOptions();
$options[] = $pollOption1;
$pollOption2 = new PollOption(); $pollOption2 = new PollOption();
$pollOption2->setTitle(""); $pollOption2->setTitle("");
$compose->getPollOptions()->add($pollOption2); $options[] = $pollOption2;
$compose->setPollOptions($options);
$session->getFlashBag()->add( $session->getFlashBag()->add(
'Success', 'Success',
$translator->trans('common.schedule_success', [], 'fediplan', 'en') $translator->trans('common.schedule_success', [], 'fediplan', 'en')

View file

@ -5,59 +5,58 @@ namespace App\Security;
use App\SocialEntity\Client; use App\SocialEntity\Client;
use App\SocialEntity\CustomField; use App\SocialEntity\CustomField;
use App\SocialEntity\Emoji; use App\SocialEntity\Emoji;
use Doctrine\Common\Collections\Collection;
use Symfony\Component\Security\Core\User\UserInterface; use Symfony\Component\Security\Core\User\UserInterface;
class MastodonAccount implements UserInterface class MastodonAccount implements UserInterface
{ {
private $acct; private string $acct;
private $id; private string $id;
private $account_id; private string $account_id;
private $username; private string $username;
private $display_name; private string $display_name;
private $locked; private bool $locked;
private $created_at; private \DateTime $created_at;
private $followers_count; private int $followers_count;
private $following_count; private int $following_count;
private $statuses_count; private int $statuses_count;
private $note; private string $note;
private $url; private string $url;
private $avatar; private string $avatar;
private $avatar_static; private string $avatar_static;
private $header; private string $header;
private $header_static; private string $header_static;
private $moved; private MastodonAccount $moved;
private $bot; private bool $bot;
private $instance; private string $instance;
private $client; private Client $client;
private $token; private string $token;
private $Fields; private array $Fields;
/** @var Emoji[] */
private array $Emojis;
private $Emojis; private string $default_sensitivity;
private $default_sensitivity; private string $default_visibility;
private $default_visibility;
public function __construct() public function __construct()
@ -323,59 +322,52 @@ class MastodonAccount implements UserInterface
return $this; return $this;
} }
/**
* @return Collection|CustomField[] public function getFields(): array
*/
public function getFields(): Collection
{ {
return $this->Fields; return $this->Fields;
} }
public function addField(CustomField $field): self public function addField(CustomField $field): self
{ {
if (!$this->Fields->contains($field)) { if (in_array($field, $this->Fields) !== false) {
$this->Fields[] = $field; $this->Fields[] = $field;
$field->setMastodonAccount($this); $field->setMastodonAccount($this);
} }
return $this; return $this;
} }
public function removeField(CustomField $field): self public function removeField(CustomField $field): self
{ {
if ($this->Fields->contains($field)) {
$this->Fields->removeElement($field); if (($key = array_search($field, $this->Fields)) !== false) {
unset($this->Fields[$key]);
// set the owning side to null (unless already changed) // set the owning side to null (unless already changed)
if ($field->getMastodonAccount() === $this) { if ($field->getMastodonAccount() === $this) {
$field->setMastodonAccount(null); $field->setMastodonAccount(null);
} }
} }
return $this; return $this;
} }
/** public function getEmojis(): array
* @return Collection|Emoji[]
*/
public function getEmojis(): Collection
{ {
return $this->Emojis; return $this->Emojis;
} }
public function addEmoji(Emoji $emoji): self public function addEmoji(Emoji $emoji): self
{ {
if (!$this->Emojis->contains($emoji)) { if (in_array($emoji, $this->Emojis) !== false) {
$this->Emojis[] = $emoji; $this->Emojis[] = $emoji;
$emoji->setMastodonAccount($this); $emoji->setMastodonAccount($this);
} }
return $this; return $this;
} }
public function removeEmoji(Emoji $emoji): self public function removeEmoji(Emoji $emoji): self
{ {
if ($this->Emojis->contains($emoji)) { if (($key = array_search($emoji, $this->Emojis)) !== false) {
$this->Emojis->removeElement($emoji); unset($this->Emojis[$key]);
// set the owning side to null (unless already changed) // set the owning side to null (unless already changed)
if ($emoji->getMastodonAccount() === $this) { if ($emoji->getMastodonAccount() === $this) {
$emoji->setMastodonAccount(null); $emoji->setMastodonAccount(null);
@ -389,7 +381,7 @@ class MastodonAccount implements UserInterface
/** /**
* @return mixed * @return mixed
*/ */
public function getDefaultSensitivity() public function getDefaultSensitivity(): mixed
{ {
return $this->default_sensitivity; return $this->default_sensitivity;
} }

View file

@ -1241,7 +1241,7 @@ class Mastodon_api
return $MastodonAccount; return $MastodonAccount;
} }
public function stringToDate(string $string_date): DateTime public function stringToDate(?string $string_date): DateTime
{ {
try { try {
return new DateTime($string_date); return new DateTime($string_date);

View file

@ -10,21 +10,21 @@ class Compose
{ {
private string $id; private string $id;
private string $content_warning; private ?string $content_warning = null;
private string $content; private ?string $content = null;
private string $visibility; private string $visibility;
private DateTime $created_at; private DateTime $created_at;
private DateTime $scheduled_at; private DateTime $scheduled_at;
private DateTime $sent_at; private DateTime $sent_at;
private bool $sensitive; private bool $sensitive;
private string $in_reply_to_id; private ?string $in_reply_to_id = null;
private string $timeZone; private string $timeZone;
/** @var PollOption[] */ /** @var PollOption[] */
private array $poll_options; private ?array $poll_options = null;
private int $poll_expires_at; private ?int $poll_expires_at = null;
private bool $poll_multiple; private ?bool $poll_multiple = null;
public function __construct() public function __construct()
{ {

View file

@ -6,8 +6,8 @@ namespace App\SocialEntity;
class PollOption class PollOption
{ {
private string $title; private ?string $title = null;
private int $votes_count; private ?int $votes_count = null;
public function getTitle(): ?string public function getTitle(): ?string