<?php
namespace App\Model\ViewOrderInfo;
use App\Form\CustomerConstraints\IsExtendedCustomerConstraintBuilder;
use App\Model\Field\Field;
use App\Model\FieldType\FieldType;
use App\Model\Traits\ImportableObjectTrait;
use App\Model\ViewOrder\ViewOrder;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Symfony\Component\Serializer\Annotation\Groups;
use Symfony\Component\Serializer\Annotation\MaxDepth;
class ViewOrderInfo
{
const FIELD_KEY_VIEW_BY_FIELD_KEY = [
'updateBy' => 'updatedByRealName',
'tva' => 'tva.value',
'taskType' => 'taskType.name',
'structureType' => 'structureType.value',
'status' => 'status.name',
'service' => 'service.value',
'prospectType' => 'prospectType.value',
'type' => 'prospectType.value',
'prospectId' => 'prospectFullName',
'origin' => 'origin.value',
'managedBy' => 'managedByRealName',
'legalForm' => 'legalForm.value',
'createdBy' => 'createdByRealName',
'contacts' => 'contactsFormatted',
'contactId' => 'contactIdRealName',
'contact_civility' => 'contact.civility.value',
'company_workforce' => 'company.workforce.value',
'company_structureType' => 'company.structureType.value',
'company_naf' => 'company.naf.label',
'company_legalForm' => 'company.legalForm.value',
'civility' => 'civility.value',
];
const VALUE_TYPE_RICH_TEXT = 'html';
use ImportableObjectTrait;
/**
* @var string|null
* @Groups({"list_view_order", "show_view_order", "new_view_order"})
*/
private $id;
/**
* @var string|null
* @Groups({"list_view_order", "show_view_order", "new_view_order", "ViewOrder:create", "ViewOrder:update"})
*/
private $viewOrderType;
/**
* @var bool|null
* @Groups({"list_view_order", "show_view_order", "new_view_order", "ViewOrder:create", "ViewOrder:update"})
*/
private $groupe = false;
/**
* @var string|null
* @Groups({"list_view_order", "show_view_order", "new_view_order", "ViewOrder:create", "ViewOrder:update"})
*/
private $type;
/**
* @var string|null
* @Groups({"list_view_order", "show_view_order", "new_view_order", "ViewOrder:create", "ViewOrder:update"})
*/
private $displayWidth;
/**
* @var string|null
* @Groups({"list_view_order", "show_view_order", "new_view_order", "ViewOrder:create", "ViewOrder:update"})
*/
private $displayLabel;
/**
* @var string|null
* @Groups({"list_view_order", "show_view_order", "new_view_order", "ViewOrder:create", "ViewOrder:update"})
*/
private $ordre;
/**
* @var bool|null
* @Groups({"list_view_order", "show_view_order", "new_view_order", "ViewOrder:create", "ViewOrder:update"})
*/
private $isRequired = false;
/**
* @var bool|null
* @Groups({"list_view_order", "show_view_order", "new_view_order", "ViewOrder:create", "ViewOrder:update"})
*/
private $isUnique = false;
/**
* @var bool|null
* @Groups({"list_view_order", "show_view_order", "new_view_order", "ViewOrder:create", "ViewOrder:update"})
*/
private $isReadOnly = false;
/**
* @var bool|null
* @Groups({"list_view_order", "show_view_order", "new_view_order", "ViewOrder:create", "ViewOrder:update"})
*/
private $isEmail = false;
/**
* @var bool|null
* @Groups({"list_view_order", "show_view_order", "new_view_order", "ViewOrder:create", "ViewOrder:update"})
*/
private $isHidden = false;
/**
* @var bool|null
* @Groups({"list_view_order", "show_view_order", "new_view_order", "ViewOrder:create", "ViewOrder:update"})
*/
private $hasPersonnalData = false;
/**
* @var string|null
* @Groups({"list_view_order", "show_view_order", "new_view_order", "ViewOrder:create", "ViewOrder:update"})
*/
private $fieldKey;
/**
* @var Field|null
* @Groups({"list_view_order", "show_view_order", "new_view_order", "ViewOrder:create", "ViewOrder:update"})
*/
private $specificField;
/**
* @var string|null
* @Groups({"list_view_order", "show_view_order", "new_view_order", "ViewOrder:create", "ViewOrder:update"})
*/
private $fieldKeyView;
/**
* @var string|null
* @Groups({"list_view_order", "show_view_order", "new_view_order", "ViewOrder:create", "ViewOrder:update"})
*/
private $valueType;
/**
* @var ViewOrder|null
* @MaxDepth(1)
* @Groups({"list_view_order", "show_view_order", "new_view_order", "ViewOrder:update"})
*/
private $viewOrder;
/**
* @var ViewOrderInfo|null
* @MaxDepth(1)
* @Groups({"list_view_order", "show_view_order", "new_view_order", "ViewOrder:create", "ViewOrder:update"})
*/
private $parent;
/**
* @var bool|null
* @Groups({"list_view_order", "show_view_order", "new_view_order", "ViewOrder:create", "ViewOrder:update"})
*/
private $isSpecificField = false;
/**
* @var ViewOrderInfo[]|Collection|null
* @MaxDepth(1)
* @Groups({"list_view_order", "show_view_order", "new_view_order", "ViewOrder:create", "ViewOrder:update"})
*/
private $viewOrderInfos;
/**
* @var bool
* @Groups({"list_view_order", "show_view_order", "new_view_order", "ViewOrder:create", "ViewOrder:update"})
*/
private $isExtended = false;
/**
* @var string|null
* @Groups({"list_view_order", "show_view_order", "new_view_order"})
*/
private $conditionField;
/**
* @var string|null
* @Groups({"list_view_order", "show_view_order", "new_view_order"})
*/
private $conditionValue;
/**
* @var bool
* @Groups({"list_view_order", "show_view_order", "new_view_order", "ViewOrder:create", "ViewOrder:update"})
*/
private $isParentField = false;
/**
* ViewOrderInfo constructor.
*/
public function __construct()
{
$this->viewOrderInfos = new ArrayCollection();
}
/**
* @return array
*/
public function format(): array
{
$commonFormat = [
'id' => $this->getId(),
'label' => $this->getDisplayLabel(),
'width' => $this->getDisplayWidth(),
'order' => $this->getOrdre(),
'key' => $this->getFieldKey(),
'hasPersonnalData' => $this->getHasPersonnalData(),
'isRequired' => $this->getIsRequired(),
'isReadOnly' => $this->isReadOnly(),
IsExtendedCustomerConstraintBuilder::IS_EXTENDED => $this->isExtended(),
'isEmail' => $this->isEmail(),
'isSpecificField' => $this->getIsSpecificField(),
'specificFieldType' => $this->getSpecificField() instanceof Field
&& $this->getSpecificField()->getFieldType() instanceof FieldType ?
$this->getSpecificField()->getFieldType()->getType() : null,
'isUnique' => $this->getIsUnique(),
'isHidden' => $this->getIsHidden(),
'type' => $this->getType(),
'viewKey' => $this->getFieldKeyView(),
'valueType' => $this->getValueType(),
'isGroup' => $this->getGroupe(),
'fields' => $this->getViewOrderInfos()->map(function (ViewOrderInfo $viewOrderInfo) {
return $viewOrderInfo->format();
})->toArray(),
'conditionField' => $this->getConditionField(),
'conditionValue' => $this->getConditionValue(),
'isParentField' => $this->isParentField(),
];
if (empty($commonFormat['viewKey'])) {
unset($commonFormat['viewKey']);
}
if (empty($commonFormat['key'])) {
unset($commonFormat['key']);
}
if (empty($commonFormat['type'])) {
unset($commonFormat['type']);
}
if (empty($commonFormat['valueType'])) {
unset($commonFormat['valueType']);
}
if (!$commonFormat['isGroup']) {
unset($commonFormat['fields']);
}
return $commonFormat;
}
/**
* @param array $data
* @param string $type
*
* @return ViewOrderInfo
*/
public function buildFromArray(array $data, string $type): ViewOrderInfo
{
$this
->setId(empty($data['isNew']) ? $data['id'] ?? null : null)
->setDisplayLabel($data['label'] ?? null)
->setDisplayWidth($data['width'])
->setOrdre($data['order'])
->setIsRequired(boolval($data['isRequired'] ?? false))
->setIsReadOnly(boolval($data['isReadOnly'] ?? false))
->setIsExtended(boolval($data[IsExtendedCustomerConstraintBuilder::IS_EXTENDED] ?? false))
->setIsEmail(boolval($data['isEmail'] ?? false))
->setIsSpecificField(boolval($data['isSpecificField'] ?? false))
->setHasPersonnalData(boolval($data['hasPersonnalData'] ?? false))
->setIsUnique(boolval($data['isUnique'] ?? false))
->setIsHidden(boolval($data['isHidden'] ?? false))
->setFieldKey($data['key'] ?? null)
->setType($data['type'] ?? null)
->setFieldKeyView($data['viewKey'] ?? null)
->setValueType($data['valueType'] ?? null)
->setViewOrderType($type)
->setConditionField($data['conditionField'] ?? null)
->setConditionValue($data['conditionValue'] ?? null)
->setIsParentField($data['isParentField'] ?? false)
->setGroupe($data['isGroup'] ?? $this->getGroupe())
;
if (key_exists('fields', $data)) {
foreach ($data['fields'] as $field) {
$this->addViewOrderInfo((new ViewOrderInfo())->buildFromArray($field, $type));
}
}
return $this;
}
/**
* @return string
*/
public function getId()
{
return $this->id;
}
/**
* @param string $id
*
* @return ViewOrderInfo
*/
public function setId($id)
{
$this->id = $id;
return $this;
}
/**
* @return string|null
*/
public function getViewOrderType(): ?string
{
return $this->viewOrderType;
}
/**
* @param string|null $viewOrderType
*
* @return ViewOrderInfo
*/
public function setViewOrderType(?string $viewOrderType): ViewOrderInfo
{
$this->viewOrderType = $viewOrderType;
return $this;
}
/**
* @return bool|null
*/
public function getGroupe(): ?bool
{
return $this->groupe;
}
/**
* @param bool|null $group
*
* @return ViewOrderInfo
*/
public function setGroupe(?bool $group): ViewOrderInfo
{
$this->groupe = $group;
return $this;
}
/**
* @return string|null
*/
public function getDisplayWidth(): ?string
{
return $this->displayWidth;
}
/**
* @param string|null $displayWidth
*
* @return ViewOrderInfo
*/
public function setDisplayWidth(?string $displayWidth): ViewOrderInfo
{
$this->displayWidth = $displayWidth;
return $this;
}
/**
* @return string|null
*/
public function getDisplayLabel(): ?string
{
return $this->displayLabel;
}
/**
* @param string|null $displayLabel
*
* @return ViewOrderInfo
*/
public function setDisplayLabel(?string $displayLabel): ViewOrderInfo
{
$this->displayLabel = $displayLabel;
return $this;
}
/**
* @return string|null
*/
public function getFieldKey(): ?string
{
return $this->fieldKey;
}
/**
* @param string|null $fieldKey
*
* @return ViewOrderInfo
*/
public function setFieldKey(?string $fieldKey): ViewOrderInfo
{
$this->fieldKey = $fieldKey;
return $this;
}
/**
* @return ViewOrder|null
*/
public function getViewOrder(): ?ViewOrder
{
return $this->viewOrder;
}
/**
* @param ViewOrder|null $viewOrder
*
* @return ViewOrderInfo
*/
public function setViewOrder($viewOrder): ViewOrderInfo
{
$this->viewOrder = $viewOrder;
return $this;
}
/**
* @return ViewOrderInfo|null
*/
public function getParent(): ?ViewOrderInfo
{
return $this->parent;
}
/**
* @param ViewOrderInfo|null $parent
*
* @return ViewOrderInfo
*/
public function setParent(?ViewOrderInfo $parent): ViewOrderInfo
{
$this->parent = $parent;
return $this;
}
/**
* @return ViewOrderInfo[]|Collection|null
*/
public function getViewOrderInfos(): ?Collection
{
return $this->viewOrderInfos;
}
/**
* Add a children viewOrderInfo object.
*
* @param ViewOrderInfo $children
*/
public function addViewOrderInfo(ViewOrderInfo $children)
{
if (!$this->getViewOrderInfos()->contains($children)) {
$children->setParent($this);
$this->getViewOrderInfos()->add($children);
}
}
/**
* Remove a children viewOrderInfo object.
*
* @param ViewOrderInfo $children
*/
public function removeViewOrderInfo(ViewOrderInfo $children)
{
if ($this->getViewOrderInfos()->contains($children)) {
$children->setParent(null);
$this->getViewOrderInfos()->removeElement($children);
}
}
/**
* @param $viewOrderInfos
*
* @return $this
*/
public function setViewOrderInfos($viewOrderInfos): self
{
$this->viewOrderInfos = $viewOrderInfos;
return $this;
}
/**
* @return string|null
*/
public function getOrdre(): ?string
{
return $this->ordre;
}
/**
* @param string|null $ordre
*
* @return ViewOrderInfo
*/
public function setOrdre(?string $ordre): ViewOrderInfo
{
$this->ordre = $ordre;
return $this;
}
/**
* @return string|null
*/
public function getType(): ?string
{
return $this->type;
}
/**
* @param string|null $type
*
* @return ViewOrderInfo
*/
public function setType(?string $type): ViewOrderInfo
{
$this->type = $type;
return $this;
}
/**
* @return string|null
*/
public function getFieldKeyView(): ?string
{
if (null === $this->fieldKeyView
&& null !== $this->getFieldKey()
&& isset(self::FIELD_KEY_VIEW_BY_FIELD_KEY[$this->getFieldKey()])
) {
return self::FIELD_KEY_VIEW_BY_FIELD_KEY[$this->getFieldKey()];
}
return $this->fieldKeyView;
}
/**
* @param string|null $fieldKeyView
*
* @return ViewOrderInfo
*/
public function setFieldKeyView(?string $fieldKeyView): ViewOrderInfo
{
$this->fieldKeyView = $fieldKeyView;
return $this;
}
/**
* @return string|null
*/
public function getValueType(): ?string
{
return $this->valueType;
}
/**
* @param string|null $valueType
*
* @return ViewOrderInfo
*/
public function setValueType(?string $valueType): ViewOrderInfo
{
$this->valueType = $valueType;
return $this;
}
/**
* @return bool|null
*/
public function getIsRequired(): ?bool
{
return $this->isRequired;
}
/**
* @param bool|null $isRequired
*
* @return ViewOrderInfo
*/
public function setIsRequired(?bool $isRequired): ViewOrderInfo
{
$this->isRequired = $isRequired;
return $this;
}
/**
* @return bool|null
*/
public function getIsUnique(): ?bool
{
return $this->isUnique;
}
/**
* @param bool|null $isUnique
*
* @return ViewOrderInfo
*/
public function setIsUnique(?bool $isUnique): ViewOrderInfo
{
$this->isUnique = $isUnique;
return $this;
}
/**
* @return string|null
*/
public function isSpecificField(): ?bool
{
return $this->isSpecificField || $this->getSpecificField() instanceof Field;
}
/**
* @return string|null
*/
public function getIsSpecificField(): ?bool
{
return $this->isSpecificField;
}
/**
* @param bool|null $isSpecificField
*
* @return ViewOrderInfo
*/
public function setIsSpecificField(?bool $isSpecificField): ViewOrderInfo
{
$this->isSpecificField = $isSpecificField;
return $this;
}
/**
* @return Field|null
*/
public function getSpecificField(): ?Field
{
return $this->specificField;
}
/**
* @param Field|null $specificField
*
* @return ViewOrderInfo
*/
public function setSpecificField(?Field $specificField): ViewOrderInfo
{
$this->specificField = $specificField;
return $this;
}
/**
* @return bool|null
*/
public function getIsHidden(): ?bool
{
return $this->isHidden;
}
/**
* @param bool|null $isHidden
*
* @return ViewOrderInfo
*/
public function setIsHidden(?bool $isHidden): ViewOrderInfo
{
$this->isHidden = $isHidden;
return $this;
}
/**
* @return bool|null
*/
public function getHasPersonnalData(): ?bool
{
return $this->hasPersonnalData;
}
/**
* @param bool|null $hasPersonnalData
*
* @return ViewOrderInfo
*/
public function setHasPersonnalData(?bool $hasPersonnalData): ViewOrderInfo
{
$this->hasPersonnalData = $hasPersonnalData;
return $this;
}
/**
* @return bool|null
*/
public function isReadOnly(): ?bool
{
return $this->isReadOnly;
}
/**
* @param bool|null $isReadOnly
*
* @return ViewOrderInfo
*/
public function setIsReadOnly(?bool $isReadOnly): ViewOrderInfo
{
$this->isReadOnly = $isReadOnly;
return $this;
}
/**
* @return bool|null
*/
public function isEmail(): ?bool
{
return $this->isEmail;
}
/**
* @param bool|null $isEmail
*
* @return ViewOrderInfo
*/
public function setIsEmail(?bool $isEmail): self
{
$this->isEmail = $isEmail;
return $this;
}
/**
* @return bool
*/
public function isExtended(): bool
{
return $this->isExtended;
}
/**
* @param bool $isExtended
*
* @return ViewOrderInfo
*/
public function setIsExtended(bool $isExtended): self
{
$this->isExtended = $isExtended;
return $this;
}
/**
* @return string|null
*/
public function getConditionField(): ?string
{
return $this->conditionField;
}
/**
* @param string|null $conditionField
*
* @return ViewOrderInfo
*/
public function setConditionField(?string $conditionField): self
{
$this->conditionField = $conditionField;
return $this;
}
/**
* @return string|null
*/
public function getConditionValue(): ?string
{
return $this->conditionValue;
}
/**
* @param string|null $conditionValue
*
* @return ViewOrderInfo
*/
public function setConditionValue(?string $conditionValue): self
{
$this->conditionValue = $conditionValue;
return $this;
}
/**
* @return bool
*/
public function isParentField(): bool
{
return $this->isParentField;
}
/**
* @param bool $isParentField
*
* @return ViewOrderInfo
*/
public function setIsParentField(bool $isParentField): self
{
$this->isParentField = $isParentField;
return $this;
}
}