<?php
namespace App\Entity\Slave;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\DBAL\Types\Types;
use Doctrine\ORM\Mapping as ORM;
/**
* @ORM\Table(name="eposm_s_operation")
* @ORM\Entity(repositoryClass="App\Repository\Slave\OperationRepository")
*/
class Operation
{
public function __toString(){
return $this->getSupplier().' - '.$this->getValue();
}
public function displayActive($type)
{
$html = '';
switch($this->isActive()){
case '0': $color = 'color_r'; $title = 'Disattivo'; break;
case '1': $color = 'color_gr'; $title = 'Attivo'; break;
default: break;
}
switch($type){
case 'icon': return '<i class="icon-circle cursor_p '.$color.'" data-bs-toggle="tooltip" title="'.$title.'"></i>'; break;
case 'string': return '<i class="icon-circle cursor_p '.$color.'"></i> '.$title; break;
}
}
public function displayEmailParameters($parameter)
{
$result = '';
if($this->getEmailParams() != null){
$params = json_decode($this->getEmailParams(), true);
switch($parameter){
case 'address': $result = $params['emailAddress']; break;
case 'host': $result = $params['emailHost']; break;
case 'port': $result = $params['emailPort']; break;
case 'encryption': $result = $params['emailEncryption']; break;
case 'user': $result = $params['emailUser']; break;
case 'password': $result = $params['emailPassword']; break;
case 'all': $result = '<table class="table table-sm b_none m_b_none"><tr><th style="padding: 0.1rem 0.1rem !important">Indirizzo</th><td style="padding: 0.1rem 0.1rem !important">'.$params['emailAddress'].'</td></tr><tr><th style="padding: 0.1rem 0.1rem !important">Host</th><td style="padding: 0.1rem 0.1rem !important">'.$params['emailHost'].'</td></tr><tr><th style="padding: 0.1rem 0.1rem !important">Porta</th><td style="padding: 0.1rem 0.1rem !important">'.$params['emailPort'].'</td></tr><tr><th style="padding: 0.1rem 0.1rem !important">Metodo crittografico</th><td style="padding: 0.1rem 0.1rem !important">'.$params['emailEncryption'].'</td></tr><tr><th style="padding: 0.1rem 0.1rem !important">Utente</th><td style="padding: 0.1rem 0.1rem !important">'.$params['emailUser'].'</td></tr><tr><th style="padding: 0.1rem 0.1rem !important">Password</th><td style="padding: 0.1rem 0.1rem !important">'.$params['emailPassword'].'</td></tr></table>'; break;
default: break;
}
}
return $result;
}
public function displaySupplierAndValue()
{
return $this->getSupplier().' - '.$this->getValue();
}
public function getKeyTicketNumber()
{
foreach($this->getKeyMappings() as $key){
if($key->isTicketNumber())
return $key;
}
return false;
}
public function getKeyTermid()
{
foreach($this->getKeyMappings() as $key){
if($key->isTermid())
return $key;
}
return false;
}
public function getKeyValueByValue($value)
{
foreach($this->getKeyMappings() as $key){
if($key->getTicketColumn() == $value){
return $key->getMappingValue();
}
}
return false;
}
public function getKeyByValue($value)
{
foreach($this->getKeyMappings() as $key){
if($key->getTicketColumn() == $value){
return $key;
}
}
return false;
}
/**
* @ORM\Column(name="id", type="bigint")
* @ORM\Id
* @ORM\GeneratedValue(strategy="AUTO")
*/
protected $id;
/**
* @ORM\Column(name="value", type="string", length=191, nullable=true)
*/
protected $value;
/**
* @ORM\Column(name="slug_master", type="string", length=191)
*/
protected $slugMaster;
/**
* @ORM\Column(name="code_client", type="string", length=191, nullable=true)
*/
protected $codeClient;
/**
* @ORM\Column(name="identifier_regex", type="text", nullable=true)
*/
protected $identifierRegex;
/**
* @ORM\Column(name="is_uav", type="boolean")
*/
protected $uav = false;
/**
* @ORM\Column(name="active", type="boolean")
*/
protected $active = false;
// ManyToOne
/**
* @ORM\ManyToOne(targetEntity="App\Entity\Slave\Supplier", inversedBy="operations")
* @ORM\JoinColumn(name="supplier_id", referencedColumnName="id")
*/
private $supplier;
/**
* @ORM\ManyToOne(targetEntity="App\Entity\Slave\OperationGroup", inversedBy="operations")
* @ORM\JoinColumn(name="group_id", referencedColumnName="id")
*/
private $group;
//
// OneToMany
/**
* @ORM\OneToMany(targetEntity="App\Entity\Slave\OperationTariff", mappedBy="operation")
*/
private $tariffs;
/**
* @ORM\OneToMany(targetEntity="App\Entity\Slave\Ticket", mappedBy="operation")
*/
private $tickets;
/**
* @ORM\OneToMany(targetEntity="App\Entity\Slave\OperationKeyMapping", mappedBy="operation")
* @ORM\OrderBy({"priority" = "ASC"})
*/
private $keyMappings;
/**
* @ORM\OneToMany(targetEntity="App\Entity\Slave\OperationSubjectMapping", mappedBy="operation")
*/
private $subjectMappings;
/**
* @ORM\OneToMany(targetEntity="App\Entity\Slave\OperationAlgorithm", mappedBy="operation")
*/
private $algorithms;
public function __construct()
{
$this->tariffs = new ArrayCollection();
$this->tickets = new ArrayCollection();
$this->keyMappings = new ArrayCollection();
$this->subjectMappings = new ArrayCollection();
$this->algorithms = new ArrayCollection();
}
//
public function getId(): ?string
{
return $this->id;
}
public function getValue(): ?string
{
return $this->value;
}
public function setValue(?string $value): self
{
$this->value = $value;
return $this;
}
public function getSlugMaster(): ?string
{
return $this->slugMaster;
}
public function setSlugMaster(string $slugMaster): self
{
$this->slugMaster = $slugMaster;
return $this;
}
public function getCodeClient(): ?string
{
return $this->codeClient;
}
public function setCodeClient(?string $codeClient): self
{
$this->codeClient = $codeClient;
return $this;
}
public function getIdentifierRegex(): ?string
{
return $this->identifierRegex;
}
public function setIdentifierRegex(?string $identifierRegex): self
{
$this->identifierRegex = $identifierRegex;
return $this;
}
public function isUav(): ?bool
{
return $this->uav;
}
public function setUav(bool $uav): self
{
$this->uav = $uav;
return $this;
}
public function isActive(): ?bool
{
return $this->active;
}
public function setActive(bool $active): self
{
$this->active = $active;
return $this;
}
public function getSupplier(): ?Supplier
{
return $this->supplier;
}
public function setSupplier(?Supplier $supplier): self
{
$this->supplier = $supplier;
return $this;
}
public function getGroup(): ?OperationGroup
{
return $this->group;
}
public function setGroup(?OperationGroup $group): self
{
$this->group = $group;
return $this;
}
/**
* @return Collection<int, OperationTariff>
*/
public function getTariffs(): Collection
{
return $this->tariffs;
}
public function addTariff(OperationTariff $tariff): self
{
if (!$this->tariffs->contains($tariff)) {
$this->tariffs->add($tariff);
$tariff->setOperation($this);
}
return $this;
}
public function removeTariff(OperationTariff $tariff): self
{
if ($this->tariffs->removeElement($tariff)) {
// set the owning side to null (unless already changed)
if ($tariff->getOperation() === $this) {
$tariff->setOperation(null);
}
}
return $this;
}
/**
* @return Collection<int, Ticket>
*/
public function getTickets(): Collection
{
return $this->tickets;
}
public function addTicket(Ticket $ticket): self
{
if (!$this->tickets->contains($ticket)) {
$this->tickets->add($ticket);
$ticket->setOperation($this);
}
return $this;
}
public function removeTicket(Ticket $ticket): self
{
if ($this->tickets->removeElement($ticket)) {
// set the owning side to null (unless already changed)
if ($ticket->getOperation() === $this) {
$ticket->setOperation(null);
}
}
return $this;
}
/**
* @return Collection<int, OperationKeyMapping>
*/
public function getKeyMappings(): Collection
{
return $this->keyMappings;
}
public function addKeyMapping(OperationKeyMapping $keyMapping): self
{
if (!$this->keyMappings->contains($keyMapping)) {
$this->keyMappings->add($keyMapping);
$keyMapping->setOperation($this);
}
return $this;
}
public function removeKeyMapping(OperationKeyMapping $keyMapping): self
{
if ($this->keyMappings->removeElement($keyMapping)) {
// set the owning side to null (unless already changed)
if ($keyMapping->getOperation() === $this) {
$keyMapping->setOperation(null);
}
}
return $this;
}
/**
* @return Collection<int, OperationSubjectMapping>
*/
public function getSubjectMappings(): Collection
{
return $this->subjectMappings;
}
public function addSubjectMapping(OperationSubjectMapping $subjectMapping): self
{
if (!$this->subjectMappings->contains($subjectMapping)) {
$this->subjectMappings->add($subjectMapping);
$subjectMapping->setOperation($this);
}
return $this;
}
public function removeSubjectMapping(OperationSubjectMapping $subjectMapping): self
{
if ($this->subjectMappings->removeElement($subjectMapping)) {
// set the owning side to null (unless already changed)
if ($subjectMapping->getOperation() === $this) {
$subjectMapping->setOperation(null);
}
}
return $this;
}
/**
* @return Collection<int, OperationAlgorithm>
*/
public function getAlgorithms(): Collection
{
return $this->algorithms;
}
public function addAlgorithm(OperationAlgorithm $algorithm): self
{
if (!$this->algorithms->contains($algorithm)) {
$this->algorithms->add($algorithm);
$algorithm->setOperation($this);
}
return $this;
}
public function removeAlgorithm(OperationAlgorithm $algorithm): self
{
if ($this->algorithms->removeElement($algorithm)) {
// set the owning side to null (unless already changed)
if ($algorithm->getOperation() === $this) {
$algorithm->setOperation(null);
}
}
return $this;
}
}