<?php
namespace App\Entity;
use App\Enum\ProductType;
use App\Enum\Role;
use App\Repository\MissionRepository;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\Serializer\Annotation\Groups;
use Symfony\Component\Uid\Uuid;
use Symfony\Component\Validator\Constraints as Assert;
#[ORM\Entity(repositoryClass: MissionRepository::class)]
#[ORM\Table(name: 'missions')]
class Mission
{
#[ORM\Id]
#[ORM\Column(type: 'string', length: 22, unique: true)]
#[Groups(['campaign', 'mission_list', 'mission_read'])]
private string $id;
#[ORM\Column(type: 'integer', nullable: true)]
#[Groups(['mission_list', 'mission_read'])]
private ?int $reference = null;
#[ORM\Column(type: 'integer', nullable: true)]
private ?int $positionOrder = null;
#[ORM\Column(type: 'string', length: 255, nullable: true)]
#[Groups(['mission_list'])]
private ?string $stateClient;
#[ORM\Column(type: 'string', length: 255, nullable: true)]
#[Groups(['mission_list'])]
private ?string $stateProvider;
#[ORM\Column(type: 'datetime', nullable: true)]
#[Groups(['mission_read'])]
private ?\DateTimeInterface $createdAt = null;
#[ORM\Column(type: 'date', nullable: true)]
#[Groups(['mission_read'])]
private ?\DateTimeInterface $desiredDelivery = null;
#[ORM\ManyToOne(targetEntity: Campaign::class, inversedBy: 'missions')]
#[Groups(['mission_list', 'mission_read'])]
private Campaign $campaign;
#[ORM\OneToMany(mappedBy: 'mission', targetEntity: InfoMission::class, cascade: ["persist", "remove"], orphanRemoval: true)]
private ?Collection $infoMissions;
#[ORM\OneToMany(mappedBy: 'mission', targetEntity: FileMission::class, cascade: ["persist", "remove"], orphanRemoval: true)]
private ?Collection $fileMissions;
#[ORM\ManyToOne(targetEntity: User::class, inversedBy: 'missions')]
private ?User $contact;
#[ORM\OneToMany(mappedBy: 'mission', targetEntity: Historique::class, cascade: ["persist", "remove"], orphanRemoval: true)]
#[ORM\OrderBy(['createdAt' => 'DESC'])]
private ?Collection $historiques;
#[ORM\Column(type: 'text', nullable: true)]
private ?string $initialBriefing = '';
#[ORM\ManyToOne(targetEntity: Product::class)]
#[ORM\JoinColumn(nullable: false)]
#[Groups(['mission_list', 'mission_read'])]
private Product $product;
#[ORM\OneToMany(mappedBy: 'mission', targetEntity: MissionParticipant::class, cascade: ['persist', 'remove'], orphanRemoval: true)]
#[Groups(['campaign','mission_list', 'mission_read'])]
private ?Collection $participants;
#[ORM\OneToOne(inversedBy: 'mission', targetEntity: Workflow::class, cascade: ['persist', 'remove'])]
#[Groups(['mission_read'])]
private ?Workflow $workflow = null;
#[ORM\Column(type: 'string', length: 255, nullable: true)]
#[Groups(['mission_read'])]
private ?string $guideStep;
#[ORM\Column(type: 'integer')]
private int $quantity;
#[ORM\Column(type: 'decimal', precision: 10, scale: 2, nullable: true)]
#[Groups(['mission_list', 'mission_read'])]
private ?float $price = null;
#[ORM\Column(type: 'decimal', precision: 10, scale: 2, nullable: true)]
#[Groups(['mission_list', 'mission_read'])]
private ?float $priceWithMargeMyFlow = null;
#[ORM\Column(type: 'decimal', precision: 10, scale: 2, nullable: true)]
#[Groups(['mission_list', 'mission_read'])]
private ?float $margeMyFlow = null;
#[ORM\Column(type: 'decimal', precision: 10, scale: 2, nullable: true)]
private ?float $priceSale = null;
#[ORM\Column(type: 'string')]
#[Groups(['mission_list', 'mission_read'])]
private string $state = 'provisional';
#[ORM\Column(type: 'text', nullable: true)]
private ?string $cancelReason = null;
#[ORM\Column(type: 'text', nullable: true)]
private ?string $libelleCustom = null;
#[ORM\Column(type: 'string', nullable: true)]
#[Groups(['mission_list', 'mission_read'])]
private ?string $initialTime = null;
#[ORM\Column(type: 'string', nullable: true)]
private ?string $realTime = null;
#[ORM\Column(type: 'date', length: 255, nullable: true)]
private ?\DateTimeInterface $preActivatedAt = null;
#[ORM\Column(type: 'string', nullable: true)]
private ?string $adminTime = null;
#[ORM\Column(type: 'string', nullable: true)]
private ?string $adminIncome = null;
#[ORM\Column(type: 'integer', nullable: true)]
private $discountForCompany;
#[ORM\Column(type: 'integer', nullable: true)]
private $originalPrice;
#[ORM\Column(type: 'string', length: 255, nullable: true)]
private $oldCommand;
#[ORM\OneToMany(mappedBy: 'mission', targetEntity: Message::class)]
private $messages;
#[ORM\Column(type: 'string', length: 255, nullable: true)]
private $lastState;
#[ORM\Column(type: 'boolean', nullable: true)]
private $canInvoiced;
#[ORM\OneToMany(mappedBy: 'mission', targetEntity: BalanceTransactions::class)]
private $balanceTransactions;
#[ORM\Column(type: 'boolean', nullable: true)]
private $evaluate;
#[ORM\Column(type: 'boolean', nullable: true)]
private $canSendEmailDaily;
#[ORM\Column(type: 'boolean', nullable: true)]
private $canSendEmailMonthly;
#[ORM\Column(type: 'boolean', nullable: true)]
private $canSendEmailWeekly;
/**
* only use for api message
*/
#[Groups(['mission_list','mission_read'])]
private int $messageUnreadApi = 0;
#[Groups(['mission_list','mission_read'])]
private bool $confidential = false;
#[Groups(['mission_list','mission_read'])]
private bool $alreadyAcceptConfidentialityContract = false;
#[Groups(['mission_list','mission_read'])]
private array $responsable = [];
#[Groups(['mission_list','mission_read'])]
private $remainDays;
#[Groups(['mission_list','mission_read'])]
private $campaignAmount;
#[Groups(['mission_list','mission_read'])]
private ?bool $canActivate = false;
#[Groups(['mission_list','mission_read'])]
private ?bool $canValidate = false;
#[Groups(['mission_list','mission_read'])]
private $planningAdditionalInformation;
#[Groups(['mission_list','mission_read'])]
private $campaignStateApi ;
#[Groups(['mission_list','mission_read'])]
private $priceApi;
#[Groups(['mission_list','mission_read'])]
private $timeApi;
#[Groups(['mission_list','mission_read'])]
private $campaignStateHtml;
#[Groups(['mission_list','mission_read'])]
private $tempId;
/************************ */
public function __construct()
{
$this->id = Uuid::v4()->toBase58();
$this->createdAt = new \DateTime();
$this->infoMissions = new ArrayCollection();
$this->fileMissions = new ArrayCollection();
$this->historiques = new ArrayCollection();
$this->participants = new ArrayCollection();
$this->desiredDelivery = new \DateTime();
$this->messages = new ArrayCollection();
$this->canInvoiced = false;
$this->balanceTransactions = new ArrayCollection();
}
public function getId(): ?string
{
return $this->id;
}
public function getTempId(): ?string
{
return $this->tempId;
}
public function setTempId(string $tempId)
{
$this->tempId = $tempId ;
}
public function __clone()
{
$this->id = Uuid::v4()->toBase58();
$participants = new ArrayCollection();
if($this->workflow !=null){
$this->workflow = clone $this->workflow;
}
$fileMissions = new ArrayCollection();
$historiques = new ArrayCollection();
foreach ($this->historiques as $historique) {
$cloneHistorique = clone $historique;
$historiques->add($cloneHistorique);
$cloneHistorique->setMission($this);
}
$this->historiques = new ArrayCollection($historiques->toArray());
// foreach ($this->fileMissions as $fileMission) {
// $cloneFileMission = clone $fileMission;
// $cloneFileMission->setMission($this);
// $fileMissions->add($cloneFileMission);
// }
foreach ($this->participants as $participant) {
$clonedParticipant = clone $participant;
$clonedParticipant->setMission($this);
$participants->add($clonedParticipant);
}
$this->participants = $participants ;
$this->fileMissions = $fileMissions;
$this->balanceTransactions = new ArrayCollection();
$this->messages = new ArrayCollection();
}
public function getReference(): ?string
{
if (empty($this->reference)) {
return null;
}
return str_pad($this->reference, 5, 0, STR_PAD_LEFT);
}
public function setReference(?int $reference): self
{
$this->reference = $reference;
return $this;
}
public function getStateClient(): ?string
{
return $this->stateClient;
}
public function setStateClient(?string $stateClient): self
{
$this->stateClient = $stateClient;
return $this;
}
public function getStateProvider(): ?string
{
return $this->stateProvider;
}
public function setStateProvider(?string $stateProvider): self
{
$this->stateProvider = $stateProvider;
return $this;
}
/**
* @return \DateTimeInterface|null
*/
public function getCreatedAt(): ?\DateTimeInterface
{
return $this->createdAt;
}
/**
* @param \DateTimeInterface|null $createdAt
* @return Mission
*/
public function setCreatedAt(?\DateTimeInterface $createdAt): Mission
{
$this->createdAt = $createdAt;
return $this;
}
public function getDesiredDelivery(): ?\DateTimeInterface
{
return $this->desiredDelivery;
}
public function setDesiredDelivery(?\DateTimeInterface $desiredDelivery): self
{
$this->desiredDelivery = $desiredDelivery;
return $this;
}
public function getCampaign(): ?Campaign
{
return $this->campaign;
}
public function setCampaign(?Campaign $campaign): self
{
$this->campaign = $campaign;
return $this;
}
/**
* @return Collection|InfoMission[]
*/
public function getInfoMissions(): Collection
{
return $this->infoMissions;
}
public function addInfoMission(InfoMission $infoMission): self
{
if (!$this->infoMissions->contains($infoMission)) {
$this->infoMissions[] = $infoMission;
$infoMission->setMission($this);
}
return $this;
}
public function removeInfoMission(InfoMission $infoMission): self
{
if ($this->infoMissions->removeElement($infoMission)) {
// set the owning side to null (unless already changed)
if ($infoMission->getMission() === $this) {
$infoMission->setMission(null);
}
}
return $this;
}
/**
* @return Collection|FileMission[]
*/
public function getFileMissions(): Collection
{
return $this->fileMissions;
}
public function addFileMission(FileMission $fileMission): self
{
if (!$this->fileMissions->contains($fileMission)) {
$this->fileMissions[] = $fileMission;
$fileMission->setMission($this);
}
return $this;
}
public function removeFileMission(FileMission $fileMission): self
{
if ($this->fileMissions->removeElement($fileMission)) {
// set the owning side to null (unless already changed)
if ($fileMission->getMission() === $this) {
$fileMission->setMission(null);
}
}
return $this;
}
public function getContact(): ?User
{
return $this->contact;
}
public function setContact(?User $contact): self
{
$this->contact = $contact;
return $this;
}
/**
* @return Collection|Historique[]
*/
public function getHistoriques(): Collection
{
return $this->historiques;
}
public function addHistorique(Historique $historique): self
{
if (!$this->historiques->contains($historique)) {
$this->historiques[] = $historique;
$historique->setMission($this);
}
return $this;
}
public function removeHistorique(Historique $historique): self
{
if ($this->historiques->removeElement($historique)) {
// set the owning side to null (unless already changed)
if ($historique->getMission() === $this) {
$historique->setMission(null);
}
}
return $this;
}
public function getInitialBriefing(): ?string
{
return $this->initialBriefing;
}
public function setInitialBriefing(?string $initialBriefing, bool $isAddMission=true): self
{
if($isAddMission){
// $pattern="/https?:\/\/(www\.)?[-a-zA-Z0-9@:%._\+~#=]{1,256}\.[a-zA-Z0-9()]{1,6}\b([-a-zA-Z0-9()@:%_\+.~#?&\/\/=]*)/";
// $this->initialBriefing = preg_replace_callback($pattern, function ($matches) {
// $url = $matches[0];
// return "<a href='$url' target='_blank'> . {$url} . '</a>";
// }, $initialBriefing );
}
else{
// $initialBriefing = preg_replace('/<a\s+(?:[^>]*?\s+)?href="([^"]*)"/i', '<a href="$1" target="_blank"', $initialBriefing);
// $this->initialBriefing = $initialBriefing;
}
$this->initialBriefing = $initialBriefing;
return $this;
}
public function getProduct(): ?Product
{
return $this->product;
}
public function setProduct(?Product $product): self
{
$this->product = $product;
return $this;
}
/**
* @return Collection|MissionParticipant[]
*/
public function getParticipants(): Collection
{
$participants = $this->participants;
return $participants;
}
/**
* @return Collection|MissionParticipant[]
*/
public function getParticipantsWithoutDoublon(): Collection
{
$participants = $this->participants;
$n = count($participants);
for ($i = 0; $i < $n - 1; $i++) {
for ($j = 0; $j < $n - $i - 1; $j++) {
$participant1 = $participants[$j];
$participant2 = $participants[$j + 1];
$income1 = $participant1->getEstimatedIncome();
$income2 = $participant2->getEstimatedIncome();
if ((is_null($income1) && !is_null($income2)) ||
(!is_null($income1) && !is_null($income2) && $income1 > $income2)) {
$participants[$j] = $participant2;
$participants[$j + 1] = $participant1;
}
}
}
return $participants;
}
public function addParticipant(MissionParticipant $participant): self
{
if (!$this->participants->contains($participant)) {
$this->participants[] = $participant;
$participant->setMission($this);
}
return $this;
}
public function removeParticipant(MissionParticipant $participant): self
{
if ($this->participants->removeElement($participant)) {
// set the owning side to null (unless already changed)
if ($participant->getMission() === $this) {
$participant->setMission(null);
}
}
return $this;
}
public function getWorkflow(): ?Workflow
{
return $this->workflow;
}
public function setWorkflow(?Workflow $workflow): self
{
if ($workflow != null) {
foreach ($workflow->getSteps() as $step) {
$step->setActive(false);
}
}
$this->workflow = $workflow;
return $this;
}
public function getGuideStep(): ?string
{
return $this->guideStep;
}
public function setGuideStep(?string $guideStep): self
{
$this->guideStep = $guideStep;
return $this;
}
public function getQuantity(): ?int
{
return $this->quantity;
}
public function setQuantity(int $quantity): self
{
$this->quantity = $quantity;
return $this;
}
public function getPrice(): ?float
{
return $this->price;
}
public function setPrice(?float $price): self
{
$this->price = $price;
return $this;
}
public function getState(): string
{
return $this->state;
}
public function setState(string $state): self
{
$this->canSendEmailDaily = true;
$this->canSendEmailWeekly = true;
$this->canSendEmailMonthly= true;
$this->lastState = $this->state;
$this->state = $state;
return $this;
}
/**
* @return string|null
*/
public function getCancelReason(): ?string
{
return $this->cancelReason;
}
/**
* @param string|null $cancelReason
*/
public function setCancelReason(?string $cancelReason): void
{
$this->cancelReason = $cancelReason;
}
/**
* @return string|null
*/
public function getLibelleCustom(): ?string
{
return $this->libelleCustom;
}
/**
* @param string|null $libelleCustom
*/
public function setLibelleCustom(?string $libelleCustom): void
{
$this->libelleCustom = $libelleCustom;
}
/**
* @return string|null
*/
public function getInitialTime(): ?string
{
return $this->initialTime;
}
/**
* @param string|null $initialTime
*/
public function setInitialTime(?string $initialTime): void
{
$this->initialTime = $initialTime;
}
/**
* @return string|null
*/
public function getRealTime(): ?string
{
return $this->realTime;
}
/**
* @param string|null $realTime
*/
public function setRealTime(?string $realTime): void
{
$this->realTime = $realTime;
}
/**
* @return \DateTimeInterface|null
*/
public function getPreActivatedAt(): ?\DateTimeInterface
{
return $this->preActivatedAt;
}
/**
* @param \DateTimeInterface|null $preActivatedAt
*/
public function setPreActivatedAt(?\DateTimeInterface $preActivatedAt): void
{
$this->preActivatedAt = $preActivatedAt;
}
public function subcontractorNotActivatedMission(){
$result = [];
if ($this->getProduct()->getType() === ProductType::AU_FORFAIT or $this->getProduct()->getType() === ProductType::AU_TEMPS_PASSE) {
foreach ($this->getParticipants() as $participant) {
if ($participant->getRole() === Role::ROLE_SUBCONTRACTOR){
if (!$participant->isActivated()) {
$result [] = [$participant->getUser()];
}
}
}
}
return $result;
}
public function oneOfSubcontractorIsEvaluated(){
$evaluated = false;
foreach ($this->getParticipants() as $participant) {
if (!is_null($participant->getEstimatedIncomeAdmin()) and $participant->getEstimatedIncomeAdmin() != 0) {
$evaluated = true;
}
}
return $evaluated;
}
public function allOfSubcontractorIsEvaluated(){
$nombreSubcontractorEvaluated =0 ;
$nombreSubcontractor =0 ;
foreach ($this->getParticipants() as $participant) {
if ($participant->getRole() === Role::ROLE_SUBCONTRACTOR){
$nombreSubcontractor++;
if (!is_null($participant->getEstimatedIncomeAdmin()) and $participant->getEstimatedIncomeAdmin() != 0) {
$nombreSubcontractorEvaluated++;
}
}
}
return $nombreSubcontractorEvaluated == $nombreSubcontractor ? true : false;
}
public function determineMissionIsActivated(){
$activated = true;
foreach ($this->getParticipants() as $participant) {
if ($participant->getRole() === Role::ROLE_SUBCONTRACTOR)
{
if (!$participant->isActivated()) {
$activated = false;
}
}
}
return $activated;
}
public function canActivate(): bool
{
$count = 0;
$activated = 0;
foreach ($this->getParticipants() as $participant) {
if (
$participant->getRole() === Role::ROLE_SUBCONTRACTOR and
!in_array('ROLE_BOT',$participant->getUser()->getRoles())
) {
$count++;
if ($participant->isActivated()) {
$activated++;
}
}
}
if ($count === 0 || $count === $activated) {
return false;
}
if ($this->getProduct()->getType() === ProductType::A_EVALUER) {
foreach ($this->getParticipants() as $participant) {
if ($participant->getRole() === Role::ROLE_SUBCONTRACTOR && empty($participant->getInitialTime())) {
return false;
}
}
}else{
// foreach ($this->getCampaign()->getMissions() as $mission){
// if ($mission->getProduct()->getStatut() === ProductType::A_EVALUER){
// if ($mission->getStateProvider() == 'A évaluer'){
// return false;
// }
// }
// }
}
if (null !== $this->getWorkflow()) {
foreach ($this->getWorkflow()->getSteps() as $step) {
if ($step->isActive()) {
return false;
}
}
}
return true;
}
/**
* @return string|null
*/
public function getAdminTime(): ?string
{
return $this->adminTime;
}
/**
* @param string|null $adminTime
*/
public function setAdminTime(?string $adminTime): void
{
$this->adminTime = $adminTime;
}
/**
* @return string|null
*/
public function getAdminIncome(): ?string
{
return $this->adminIncome;
}
/**
* @param string|null $adminIncome
*/
public function setAdminIncome(?string $adminIncome): void
{
$this->adminIncome = $adminIncome;
}
public function getDiscountForCompany(): ?int
{
return $this->discountForCompany;
}
public function setDiscountForCompany(?int $discountForCompany): self
{
$this->discountForCompany = $discountForCompany;
return $this;
}
public function getOriginalPrice(): ?int
{
return $this->originalPrice;
}
public function setOriginalPrice(?int $originalPrice): self
{
$this->originalPrice = $originalPrice;
return $this;
}
public function getTotalIncomeAdmin(){
$total = 0;
foreach ($this->getParticipants() as $participant) {
if ($participant->getRole() === Role::ROLE_SUBCONTRACTOR) {
if( is_null($participant->getEstimatedIncomeAdmin()) ){
$total += $participant->getIncomeAdmin();
}else{
$total += $participant->getEstimatedIncomeAdmin();
}
}
}
return $total;
}
public function getTotalInitialTimeAdmin(){
$total = 0;
foreach ($this->getParticipants() as $participant) {
if ($participant->getRole() === Role::ROLE_SUBCONTRACTOR) {
if( is_null($participant->getInitialTimeAdmin()) ){
$total += $participant->getTimeAdmin();
}else{
$total+= $participant->getInitialTimeAdmin();
}
}
}
return $total;
}
public function nbParticipant(){
$nb = 0;
foreach ($this->getParticipants() as $participant) {
if ($participant->getRole() === Role::ROLE_SUBCONTRACTOR) {
$nb++;
}
}
return $nb;
}
public function onlySubcontractorInMission(){
if (($this->nbParticipant()) == 1) {
foreach ($this->getParticipants() as $participant) {
if ($participant->getRole() === Role::ROLE_SUBCONTRACTOR) {
return $participant;
}
}
}
return null;
}
public function getTvaForOnlyOneParticipant(){
foreach ($this->getParticipants() as $participant) {
if ($participant->getRole() === Role::ROLE_SUBCONTRACTOR) {
if (!is_null($participant->getUser()->getUserData())) {
return $participant->getUser()->getUserData()->getTva();
}
}
}
return 0;
}
/**
* get $quatity,$price, $idProduct, $timestamp of shape "quatity-price-idProduct-timestamp"
*
* timestamp is the timestamp or datedesired delivery
*
* @return string|null
*/
public function getOldCommand(): ?string
{
return $this->oldCommand;
}
/**
* @param string|null $oldCommand
*
* @return self
*/
public function setOldCommand(?string $oldCommand): self
{
$this->oldCommand = $oldCommand;
return $this;
}
/**
* Get All participant by Type subcontractror and observer and validator
*
* @return array
*/
public function getParticipantsByType():array
{
$participantListByType= [
'subcontractor' => [],
'observer' => [],
'validateur'=> []
];
$idSubcontractorList = [];
foreach ($this->getParticipants() as $participant) {
if( !in_array("ROLE_BOT",$participant->getUser()->getRoles())){
if($participant->getRole()== Role::ROLE_SUBCONTRACTOR){
if (!in_array($participant->getUser()->getId(),$idSubcontractorList)) {
$participantListByType['subcontractor']=[...$participantListByType['subcontractor'],$participant];
}
$idSubcontractorList[] = $participant->getUser()->getId();
}
if($participant->getRole()== Role::ROLE_OBSERVER){
$participantListByType['observer']=[...$participantListByType['observer'],$participant];
}
if($participant->getRole()== Role::ROLE_VALIDATOR){
$participantListByType['validateur']=[...$participantListByType['validateur'],$participant];
}
}
}
return $participantListByType;
}
/**
* @return Collection|Message[]
*/
public function getMessages(): Collection
{
return $this->messages;
}
public function addMessage(Message $message): self
{
if (!$this->messages->contains($message)) {
$this->messages[] = $message;
$message->setMission($this);
}
return $this;
}
public function removeMessage(Message $message): self
{
if ($this->messages->removeElement($message)) {
// set the owning side to null (unless already changed)
if ($message->getMission() === $this) {
$message->setMission(null);
}
}
return $this;
}
public function getLastState(): ?string
{
return $this->lastState;
}
public function setLastState(?string $lastState): self
{
$this->lastState = $lastState;
return $this;
}
public function lastStepIsActive(){
if (!is_null($this->workflow) && sizeof($this->workflow->getSteps()) > 0) {
return $this->workflow->getSteps()->last()->isActive();
}
return false;
}
/**
* return list of participant who doesnt have time and price in product type 3 (temp passé)
* @return Array
*/
public function subcontractorIsReady(){
$participants = $this->getParticipants();
$listParticipantOk = [];
$dataParticpantNotOK = [];
if ($this->getProduct()->getType() === ProductType::AU_TEMPS_PASSE) {
//All participant is ready
foreach ($participants as $participant) {
if ( !is_null($participant->getEstimatedIncome()) and $participant->getEstimatedIncome() != 0 and $participant->getRole() === Role::ROLE_SUBCONTRACTOR
) {
$listParticipantOk [] = $participant->getUser()->getId();
}
}
foreach ($participants as $participant) {
if ((is_null($participant->getEstimatedIncome()) or is_null($participant->getInitialTime()) or $participant->getEstimatedIncome() == 0 or ($participant->getInitialTime()) == 0) and $participant->getRole() === Role::ROLE_SUBCONTRACTOR
and !in_array($participant->getUser()->getId(),$listParticipantOk)
) {
$dataParticpantNotOK[] = [
'id' => $participant->getId(),
'firstname' => $participant->getUser()->getFirstname(),
'lastname' => $participant->getUser()->getLastname(),
'email' => $participant->getUser()->getEmail(),
'picture' => $participant->getUser()->getPictureName(),
'user' => $participant->getUser()
];
}
}
}
return ($dataParticpantNotOK);
}
public function getCanInvoiced(): ?bool
{
return $this->canInvoiced;
}
public function setCanInvoiced(?bool $canInvoiced): self
{
$this->canInvoiced = $canInvoiced;
return $this;
}
/**
* @return Collection|BalanceTransactions[]
*/
public function getBalanceTransactions(): Collection
{
return $this->balanceTransactions;
}
public function addBalanceTransaction(BalanceTransactions $balanceTransaction): self
{
if (!$this->balanceTransactions->contains($balanceTransaction)) {
$this->balanceTransactions[] = $balanceTransaction;
$balanceTransaction->setMission($this);
}
return $this;
}
public function removeBalanceTransaction(BalanceTransactions $balanceTransaction): self
{
if ($this->balanceTransactions->removeElement($balanceTransaction)) {
// set the owning side to null (unless already changed)
if ($balanceTransaction->getMission() === $this) {
$balanceTransaction->setMission(null);
}
}
return $this;
}
public function isEvaluate(): ?bool
{
return $this->evaluate;
}
public function setEvaluate(?bool $evaluate): self
{
$this->evaluate = $evaluate;
return $this;
}
public function getCanSendEmailDaily(): ?bool
{
return $this->canSendEmailDaily;
}
public function setCanSendEmailDaily(?bool $canSendEmailDaily): self
{
$this->canSendEmailDaily = $canSendEmailDaily;
return $this;
}
public function getCanSendEmailMonthly(): ?bool
{
return $this->canSendEmailMonthly;
}
public function setCanSendEmailMonthly(?bool $canSendEmailMonthly): self
{
$this->canSendEmailMonthly = $canSendEmailMonthly;
return $this;
}
public function getCanSendEmailWeekly(): ?bool
{
return $this->canSendEmailWeekly;
}
public function setCanSendEmailWeekly(?bool $canSendEmailWeekly): self
{
$this->canSendEmailWeekly = $canSendEmailWeekly;
return $this;
}
// for Api only
public function getCampaignStateHtml():string|null{
return $this->campaignStateHtml;
}
public function setCampaignStateHtml(?string $campaignStateHtml):self{
$this->campaignStateHtml = $campaignStateHtml;
return $this;
}
public function getCampaignStateApi():array|null{
return $this->campaignStateApi;
}
public function setCampaignStateApi(?array $campaignStateApi):self{
$this->campaignStateApi = $campaignStateApi;
return $this;
}
public function getMessageUnreadApi():int{
return $this->messageUnreadApi;
}
public function setMessageUnreadApi(?int $messageUnreadApi):self{
$this->messageUnreadApi = $messageUnreadApi;
return $this;
}
public function getCanActivate(){
return $this->canActivate;
}
public function setCanActivateApi(?bool $canActivate):self{
$this->canActivate = $canActivate;
return $this;
}
public function getCampaignAmount(){
return $this->campaignAmount;
}
public function setCampaignAmountApi($campaignAmount){
$this->campaignAmount = $campaignAmount;
}
public function getCanValidate(){
return $this->canValidate;
}
public function setCanValidateApi(?bool $canValidate):self{
$this->canValidate = $canValidate;
return $this;
}
public function getRemainDays(): ?float
{
return $this->remainDays;
}
public function setRemainDays(float $remainDays): self
{
$this->remainDays = $remainDays;
return $this;
}
public function getResponsable(): ?array
{
return $this->responsable;
}
public function setResponsable(array $responsable): self
{
$this->responsable = $responsable;
return $this;
}
public function getPlanningAdditionalInformation(){
return $this->planningAdditionalInformation;
}
public function setPlanningAdditionalInformation($planningAdditionalInformation){
$this->planningAdditionalInformation = $planningAdditionalInformation;
return $this;
}
///////////////////
public function getEvaluate(): ?bool
{
return $this->evaluate;
}
public function getPositionOrder(): ?int
{
return $this->positionOrder;
}
public function setPositionOrder(?int $positionOrder): self
{
$this->positionOrder = $positionOrder;
return $this;
}
public function getPriceSale(): ?string
{
return $this->priceSale;
}
public function setPriceSale(?string $priceSale): self
{
$this->priceSale = $priceSale;
return $this;
}
public function canStart(){
$canStart = ['state'=>true,'ListOfMissions'=>''];
$matriceStatus = ['in_progress'];
$campaign = $this->getCampaign();
foreach ($campaign->getMissions() as $mission) {
if ($mission->getPositionOrder() < $this->getPositionOrder() and in_array($mission->getState(),$matriceStatus) and !is_null($mission->getPositionOrder())) {
$canStart['state'] = false;
$canStart['ListOfMissions'] .= $mission->getProduct()->getName()." et ";
}
}
if (strrpos($canStart['ListOfMissions'], "et") !== false) {
// Extraire la partie de la chaîne avant la dernière occurrence de "et"
$canStart['ListOfMissions'] = substr($canStart['ListOfMissions'], 0, strrpos($canStart['ListOfMissions'], "et"));
}
return $canStart;
}
public function getPriceApi(): ?float
{
return $this->priceApi;
}
public function setPriceApi(?float $priceApi): self
{
$this->priceApi = $priceApi;
return $this;
}
public function getTimeApi(): ?float
{
return $this->timeApi;
}
public function setTimeApi(?float $timeApi): self
{
$this->timeApi = $timeApi;
return $this;
}
public function getPriceWithMargeMyFlow(): ?string
{
return $this->priceWithMargeMyFlow;
}
public function setPriceWithMargeMyFlow(?string $priceWithMargeMyFlow): self
{
$this->priceWithMargeMyFlow = $priceWithMargeMyFlow;
return $this;
}
public function getMargeMyFlow(): ?string
{
return $this->margeMyFlow;
}
public function setMargeMyFlow(?string $margeMyFlow): self
{
$this->margeMyFlow = $margeMyFlow;
return $this;
}
public function getConfidential(): ?bool
{
return $this->confidential;
}
public function setConfidential($confidential): self
{
$this->confidential = $confidential;
return $this;
}
public function getAlreadyAcceptConfidentialityContract(): ?bool
{
return $this->alreadyAcceptConfidentialityContract;
}
public function setAlreadyAcceptConfidentialityContract($alreadyAcceptConfidentialityContract): self
{
$this->alreadyAcceptConfidentialityContract = $alreadyAcceptConfidentialityContract;
return $this;
}
}