ActivityType add new fields

This commit is contained in:
Jean-Francois Monfort 2021-04-08 16:10:04 +02:00
parent 580dc71218
commit 37b395ee52
6 changed files with 658 additions and 40 deletions

View File

@ -32,6 +32,10 @@ use Doctrine\ORM\Mapping as ORM;
*/
class ActivityType
{
const FIELD_INVISIBLE = 0;
const FIELD_OPTIONAL = 1;
const FIELD_REQUIRED = 2;
/**
* @var integer
*
@ -39,38 +43,185 @@ class ActivityType
* @ORM\Column(name="id", type="integer")
* @ORM\GeneratedValue(strategy="AUTO")
*/
private $id;
private ?int $id;
/**
* @var array
* @ORM\Column(type="json_array")
*/
private $name;
private array $name = [];
/**
* @var bool
* @ORM\Column(type="boolean")
*/
private $active = true;
private bool $active = true;
/**
* ORM\ManyToOne(targetEntity="Chill\ActivityBundle\Entity\ActivityTypeCategory")
*/
private ?ActivityTypeCategory $category = null;
/**
* @ORM\Column(type="smallint", nullable=false, options={"default"=2})
*/
private int $personVisible = self::FIELD_REQUIRED;
/**
* @ORM\Column(type="string", nullable=false, options={"default"=""})
*/
private string $personLabel = '';
/**
* @ORM\Column(type="smallint", nullable=false, options={"default"=2})
*/
private int $userVisible = self::FIELD_REQUIRED;
/**
* @ORM\Column(type="string", nullable=false, options={"default"=""})
*/
private string $userLabel = '';
/**
* @ORM\Column(type="smallint", nullable=false, options={"default"=2})
*/
private int $dateVisible = self::FIELD_REQUIRED;
/**
* @ORM\Column(type="string", nullable=false, options={"default"=""})
*/
private string $dateLabel = '';
/**
* @ORM\Column(type="smallint", nullable=false, options={"default"=1})
*/
private int $placeVisible = self::FIELD_OPTIONAL;
/**
* @ORM\Column(type="string", nullable=false, options={"default"=""})
*/
private string $placeLabel = '';
/**
* @ORM\Column(type="smallint", nullable=false, options={"default"=1})
*/
private int $personsVisible = self::FIELD_OPTIONAL;
/**
* @ORM\Column(type="string", nullable=false, options={"default"=""})
*/
private string $personsLabel = '';
/**
* @ORM\Column(type="smallint", nullable=false, options={"default"=1})
*/
private int $thirdpartyVisible = self::FIELD_INVISIBLE;
/**
* @ORM\Column(type="string", nullable=false, options={"default"=""})
*/
private string $thirdpartyLabel = '';
/**
* @ORM\Column(type="smallint", nullable=false, options={"default"=1})
*/
private int $durationTimeVisible = self::FIELD_OPTIONAL;
/**
* @ORM\Column(type="string", nullable=false, options={"default"=""})
*/
private string $durationTimeLabel = '';
/**
* @ORM\Column(type="smallint", nullable=false, options={"default"=1})
*/
private int $attendeeVisible = self::FIELD_OPTIONAL;
/**
* @ORM\Column(type="string", nullable=false, options={"default"=""})
*/
private string $attendeeLabel = '';
/**
* @ORM\Column(type="smallint", nullable=false, options={"default"=1})
*/
private int $reasonsVisible = self::FIELD_OPTIONAL;
/**
* @ORM\Column(type="string", nullable=false, options={"default"=""})
*/
private string $reasonsLabel = '';
/**
* @ORM\Column(type="smallint", nullable=false, options={"default"=1})
*/
private int $commentVisible = self::FIELD_OPTIONAL;
/**
* @ORM\Column(type="string", nullable=false, options={"default"=""})
*/
private string $commentLabel = '';
/**
* @ORM\Column(type="smallint", nullable=false, options={"default"=1})
*/
private int $sentReceivedVisible = self::FIELD_OPTIONAL;
/**
* @ORM\Column(type="string", nullable=false, options={"default"=""})
*/
private string $sentReceivedLabel = '';
/**
* @ORM\Column(type="smallint", nullable=false, options={"default"=1})
*/
private int $documentVisible = self::FIELD_OPTIONAL;
/**
* @ORM\Column(type="string", nullable=false, options={"default"=""})
*/
private string $documentLabel = '';
/**
* @ORM\Column(type="smallint", nullable=false, options={"default"=1})
*/
private int $emergencyVisible = self::FIELD_INVISIBLE;
/**
* @ORM\Column(type="string", nullable=false, options={"default"=""})
*/
private string $emergencyLabel = '';
/**
* @ORM\Column(type="smallint", nullable=false, options={"default"=1})
*/
private int $accompanyingPeriodVisible = self::FIELD_INVISIBLE;
/**
* @ORM\Column(type="string", nullable=false, options={"default"=""})
*/
private string $accompanyingPeriodLabel = '';
/**
* @ORM\Column(type="smallint", nullable=false, options={"default"=1})
*/
private int $socialDataVisible = self::FIELD_INVISIBLE;
/**
* @ORM\Column(type="string", nullable=false, options={"default"=""})
*/
private string $socialDataLabel = '';
/**
* Get id
*
* @return integer
*/
public function getId()
public function getId(): int
{
return $this->id;
}
/**
* Set name
*
* @param array $name
* @return ActivityType
*/
public function setName($name)
public function setName(string $name): self
{
$this->name = $name;
@ -82,7 +233,7 @@ class ActivityType
*
* @return array | string
*/
public function getName($locale = null)
public function getName(?string $locale = null)
{
if ($locale) {
if (isset($this->name[$locale])) {
@ -103,34 +254,339 @@ class ActivityType
/**
* Get active
* return true if the type is active.
*
* @return boolean
*/
public function getActive() {
public function getActive(): bool
{
return $this->active;
}
/**
* Is active
* return true if the type is active
*
* @return boolean
*/
public function isActive() {
public function isActive(): bool
{
return $this->getActive();
}
/**
* Set active
* set to true if the type is active
*
* @param boolean $active
* @return ActivityType
*/
public function setActive($active) {
public function setActive(bool $active): self
{
$this->active = $active;
return $this;
}
}
public function getCategory(): ?ActivityTypeCategory
{
return $this->category;
}
public function setCategory(?ActivityTypeCategory $category): void
{
$this->category = $category;
}
public function getPersonVisible(): int
{
return $this->personVisible;
}
public function setPersonVisible(int $personVisible): void
{
$this->personVisible = $personVisible;
}
public function getPersonLabel(): string
{
return $this->personLabel;
}
public function setPersonLabel(string $personLabel): void
{
$this->personLabel = $personLabel;
}
public function getUserVisible(): int
{
return $this->userVisible;
}
public function setUserVisible(int $userVisible): void
{
$this->userVisible = $userVisible;
}
public function getUserLabel(): string
{
return $this->userLabel;
}
public function setUserLabel(string $userLabel): void
{
$this->userLabel = $userLabel;
}
public function getDateVisible(): int
{
return $this->dateVisible;
}
public function setDateVisible(int $dateVisible): void
{
$this->dateVisible = $dateVisible;
}
public function getDateLabel(): string
{
return $this->dateLabel;
}
public function setDateLabel(string $dateLabel): void
{
$this->dateLabel = $dateLabel;
}
public function getPlaceVisible(): int
{
return $this->placeVisible;
}
public function setPlaceVisible(int $placeVisible): void
{
$this->placeVisible = $placeVisible;
}
public function getPlaceLabel(): string
{
return $this->placeLabel;
}
public function setPlaceLabel(string $placeLabel): void
{
$this->placeLabel = $placeLabel;
}
public function getPersonsVisible(): int
{
return $this->personsVisible;
}
public function setPersonsVisible(int $personsVisible): void
{
$this->personsVisible = $personsVisible;
}
public function getPersonsLabel(): string
{
return $this->personsLabel;
}
public function setPersonsLabel(string $personsLabel): void
{
$this->personsLabel = $personsLabel;
}
public function getThirdpartyVisible(): int
{
return $this->thirdpartyVisible;
}
public function setThirdpartyVisible(int $thirdpartyVisible): void
{
$this->thirdpartyVisible = $thirdpartyVisible;
}
public function getThirdpartyLabel(): string
{
return $this->thirdpartyLabel;
}
public function setThirdpartyLabel(string $thirdpartyLabel): void
{
$this->thirdpartyLabel = $thirdpartyLabel;
}
public function getDurationTimeVisible(): int
{
return $this->durationTimeVisible;
}
public function setDurationTimeVisible(int $durationTimeVisible): void
{
$this->durationTimeVisible = $durationTimeVisible;
}
public function getDurationTimeLabel(): string
{
return $this->durationTimeLabel;
}
public function setDurationTimeLabel(string $durationTimeLabel): void
{
$this->durationTimeLabel = $durationTimeLabel;
}
public function getAttendeeVisible(): int
{
return $this->attendeeVisible;
}
public function setAttendeeVisible(int $attendeeVisible): void
{
$this->attendeeVisible = $attendeeVisible;
}
public function getAttendeeLabel(): string
{
return $this->attendeeLabel;
}
public function setAttendeeLabel(string $attendeeLabel): void
{
$this->attendeeLabel = $attendeeLabel;
}
public function getReasonsVisible(): int
{
return $this->reasonsVisible;
}
public function setReasonsVisible(int $reasonsVisible): void
{
$this->reasonsVisible = $reasonsVisible;
}
public function getReasonsLabel(): string
{
return $this->reasonsLabel;
}
public function setReasonsLabel(string $reasonsLabel): void
{
$this->reasonsLabel = $reasonsLabel;
}
public function getCommentVisible(): int
{
return $this->commentVisible;
}
public function setCommentVisible(int $commentVisible): void
{
$this->commentVisible = $commentVisible;
}
public function getCommentLabel(): string
{
return $this->commentLabel;
}
public function setCommentLabel(string $commentLabel): void
{
$this->commentLabel = $commentLabel;
}
public function getSentReceivedVisible(): int
{
return $this->sentReceivedVisible;
}
public function setSentReceivedVisible(int $sentReceivedVisible): void
{
$this->sentReceivedVisible = $sentReceivedVisible;
}
public function getSentReceivedLabel(): string
{
return $this->sentReceivedLabel;
}
public function setSentReceivedLabel(string $sentReceivedLabel): void
{
$this->sentReceivedLabel = $sentReceivedLabel;
}
public function getDocumentVisible(): int
{
return $this->documentVisible;
}
public function setDocumentVisible(int $documentVisible): void
{
$this->documentVisible = $documentVisible;
}
public function getDocumentLabel(): string
{
return $this->documentLabel;
}
public function setDocumentLabel(string $documentLabel): void
{
$this->documentLabel = $documentLabel;
}
public function getEmergencyVisible(): int
{
return $this->emergencyVisible;
}
public function setEmergencyVisible(int $emergencyVisible): void
{
$this->emergencyVisible = $emergencyVisible;
}
public function getEmergencyLabel(): string
{
return $this->emergencyLabel;
}
public function setEmergencyLabel(string $emergencyLabel): void
{
$this->emergencyLabel = $emergencyLabel;
}
public function getAccompanyingPeriodVisible(): int
{
return $this->accompanyingPeriodVisible;
}
public function setAccompanyingPeriodVisible(int $accompanyingPeriodVisible): void
{
$this->accompanyingPeriodVisible = $accompanyingPeriodVisible;
}
public function getAccompanyingPeriodLabel(): string
{
return $this->accompanyingPeriodLabel;
}
public function setAccompanyingPeriodLabel(string $accompanyingPeriodLabel): void
{
$this->accompanyingPeriodLabel = $accompanyingPeriodLabel;
}
public function getSocialDataVisible(): int
{
return $this->socialDataVisible;
}
public function setSocialDataVisible(int $socialDataVisible): void
{
$this->socialDataVisible = $socialDataVisible;
}
public function getSocialDataLabel(): string
{
return $this->socialDataLabel;
}
public function setSocialDataLabel(string $socialDataLabel): void
{
$this->socialDataLabel = $socialDataLabel;
}
}

View File

@ -51,8 +51,6 @@ class ActivityTypeCategory
/**
* Get id
*
* @return integer
*/
public function getId(): int
{

View File

@ -2,7 +2,12 @@
namespace Chill\ActivityBundle\Form;
use Chill\ActivityBundle\Entity\ActivityTypeCategory;
use Chill\ActivityBundle\Form\Type\ActivityFieldPresence;
use Chill\MainBundle\Templating\TranslatableStringHelper;
use Symfony\Bridge\Doctrine\Form\Type\EntityType;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\Extension\Core\Type\TextType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\OptionsResolver\OptionsResolver;
use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
@ -10,6 +15,13 @@ use Chill\MainBundle\Form\Type\TranslatableStringFormType;
class ActivityTypeType extends AbstractType
{
private TranslatableStringHelper $translatableStringHelper;
public function __construct(TranslatableStringHelper $translatableStringHelper)
{
$this->translatableStringHelper = $translatableStringHelper;
}
/**
* @param FormBuilderInterface $builder
* @param array $options
@ -18,13 +30,36 @@ class ActivityTypeType extends AbstractType
{
$builder
->add('name', TranslatableStringFormType::class)
->add('active', ChoiceType::class, array(
'choices' => array(
->add('active', ChoiceType::class, [
'choices' => [
'Yes' => true,
'No' => false
),
],
'expanded' => true
));
])
->add('category', EntityType::class, [
'class' => ActivityTypeCategory::class,
'choice_label' => function (ActivityTypeCategory $activityTypeCategory) {
return $this->translatableStringHelper->localize($activityTypeCategory->getName());
},
])
;
$fields = [
'person', 'user', 'date', 'place', 'persons',
'thirdparty', 'durationTime', 'attendee',
'reasons', 'comment', 'sentReceived', 'document',
'emergency', 'accompanyingPeriod', 'socialData'
];
foreach ($fields as $field) {
$builder
->add($field.'Visible', ActivityFieldPresence::class)
->add($field.'Label', TextType::class, [
'required' => false,
'empty_data' => '',
]);
}
}
/**

View File

@ -0,0 +1,29 @@
<?php
namespace Chill\ActivityBundle\Form\Type;
use Chill\ActivityBundle\Entity\ActivityType;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
use Symfony\Component\OptionsResolver\OptionsResolver;
class ActivityFieldPresence extends AbstractType
{
public function getParent()
{
return ChoiceType::class;
}
public function configureOptions(OptionsResolver $resolver)
{
$resolver->setDefaults(
array(
'choices' => [
'Invisible' => ActivityType::FIELD_INVISIBLE,
'Optional' => ActivityType::FIELD_OPTIONAL,
'Required' => ActivityType::FIELD_REQUIRED,
],
)
);
}
}

View File

@ -33,3 +33,10 @@ services:
- "%chill_activity.form.time_duration%"
tags:
- { name: form.type, alias: chill_activitybundle_activity }
chill.activity.form.type.activityTypeType:
class: Chill\ActivityBundle\Form\ActivityTypeType
arguments:
- "@chill.main.helper.translatable_string"
tags:
- { name: form.type, alias: translatable_activity_type }

View File

@ -0,0 +1,93 @@
<?php
declare(strict_types=1);
namespace Chill\Migrations\Activity;
use Doctrine\DBAL\Schema\Schema;
use Doctrine\Migrations\AbstractMigration;
/**
* Auto-generated Migration: Please modify to your needs!
*/
final class Version20210408122329 extends AbstractMigration
{
public function getDescription() : string
{
return '';
}
public function up(Schema $schema) : void
{
$this->addSql('ALTER TABLE activitytype ADD personVisible SMALLINT DEFAULT 2 NOT NULL');
$this->addSql('ALTER TABLE activitytype ADD personLabel VARCHAR(255) DEFAULT \'\' NOT NULL');
$this->addSql('ALTER TABLE activitytype ADD userVisible SMALLINT DEFAULT 2 NOT NULL');
$this->addSql('ALTER TABLE activitytype ADD userLabel VARCHAR(255) DEFAULT \'\' NOT NULL');
$this->addSql('ALTER TABLE activitytype ADD dateVisible SMALLINT DEFAULT 2 NOT NULL');
$this->addSql('ALTER TABLE activitytype ADD dateLabel VARCHAR(255) DEFAULT \'\' NOT NULL');
$this->addSql('ALTER TABLE activitytype ADD placeVisible SMALLINT DEFAULT 1 NOT NULL');
$this->addSql('ALTER TABLE activitytype ADD placeLabel VARCHAR(255) DEFAULT \'\' NOT NULL');
$this->addSql('ALTER TABLE activitytype ADD personsVisible SMALLINT DEFAULT 1 NOT NULL');
$this->addSql('ALTER TABLE activitytype ADD personsLabel VARCHAR(255) DEFAULT \'\' NOT NULL');
$this->addSql('ALTER TABLE activitytype ADD thirdpartyVisible SMALLINT DEFAULT 1 NOT NULL');
$this->addSql('ALTER TABLE activitytype ADD thirdpartyLabel VARCHAR(255) DEFAULT \'\' NOT NULL');
$this->addSql('ALTER TABLE activitytype ADD durationTimeVisible SMALLINT DEFAULT 1 NOT NULL');
$this->addSql('ALTER TABLE activitytype ADD durationTimeLabel VARCHAR(255) DEFAULT \'\' NOT NULL');
$this->addSql('ALTER TABLE activitytype ADD attendeeVisible SMALLINT DEFAULT 1 NOT NULL');
$this->addSql('ALTER TABLE activitytype ADD attendeeLabel VARCHAR(255) DEFAULT \'\' NOT NULL');
$this->addSql('ALTER TABLE activitytype ADD reasonsVisible SMALLINT DEFAULT 1 NOT NULL');
$this->addSql('ALTER TABLE activitytype ADD reasonsLabel VARCHAR(255) DEFAULT \'\' NOT NULL');
$this->addSql('ALTER TABLE activitytype ADD commentVisible SMALLINT DEFAULT 1 NOT NULL');
$this->addSql('ALTER TABLE activitytype ADD commentLabel VARCHAR(255) DEFAULT \'\' NOT NULL');
$this->addSql('ALTER TABLE activitytype ADD sentReceivedVisible SMALLINT DEFAULT 1 NOT NULL');
$this->addSql('ALTER TABLE activitytype ADD sentReceivedLabel VARCHAR(255) DEFAULT \'\' NOT NULL');
$this->addSql('ALTER TABLE activitytype ADD documentVisible SMALLINT DEFAULT 1 NOT NULL');
$this->addSql('ALTER TABLE activitytype ADD documentLabel VARCHAR(255) DEFAULT \'\' NOT NULL');
$this->addSql('ALTER TABLE activitytype ADD emergencyVisible SMALLINT DEFAULT 1 NOT NULL');
$this->addSql('ALTER TABLE activitytype ADD emergencyLabel VARCHAR(255) DEFAULT \'\' NOT NULL');
$this->addSql('ALTER TABLE activitytype ADD accompanyingPeriodVisible SMALLINT DEFAULT 1 NOT NULL');
$this->addSql('ALTER TABLE activitytype ADD accompanyingPeriodLabel VARCHAR(255) DEFAULT \'\' NOT NULL');
$this->addSql('ALTER TABLE activitytype ADD socialDataVisible SMALLINT DEFAULT 1 NOT NULL');
$this->addSql('ALTER TABLE activitytype ADD socialDataLabel VARCHAR(255) DEFAULT \'\' NOT NULL');
$this->addSql('ALTER TABLE activitytype ALTER name SET NOT NULL');
$this->addSql('ALTER TABLE activitytype ALTER active DROP DEFAULT');
$this->addSql('COMMENT ON COLUMN activitytype.name IS \'(DC2Type:json_array)\'');
}
public function down(Schema $schema) : void
{
$this->addSql('ALTER TABLE activitytype DROP personVisible');
$this->addSql('ALTER TABLE activitytype DROP personLabel');
$this->addSql('ALTER TABLE activitytype DROP userVisible');
$this->addSql('ALTER TABLE activitytype DROP userLabel');
$this->addSql('ALTER TABLE activitytype DROP dateVisible');
$this->addSql('ALTER TABLE activitytype DROP dateLabel');
$this->addSql('ALTER TABLE activitytype DROP placeVisible');
$this->addSql('ALTER TABLE activitytype DROP placeLabel');
$this->addSql('ALTER TABLE activitytype DROP personsVisible');
$this->addSql('ALTER TABLE activitytype DROP personsLabel');
$this->addSql('ALTER TABLE activitytype DROP thirdpartyVisible');
$this->addSql('ALTER TABLE activitytype DROP thirdpartyLabel');
$this->addSql('ALTER TABLE activitytype DROP durationTimeVisible');
$this->addSql('ALTER TABLE activitytype DROP durationTimeLabel');
$this->addSql('ALTER TABLE activitytype DROP attendeeVisible');
$this->addSql('ALTER TABLE activitytype DROP attendeeLabel');
$this->addSql('ALTER TABLE activitytype DROP reasonsVisible');
$this->addSql('ALTER TABLE activitytype DROP reasonsLabel');
$this->addSql('ALTER TABLE activitytype DROP commentVisible');
$this->addSql('ALTER TABLE activitytype DROP commentLabel');
$this->addSql('ALTER TABLE activitytype DROP sentReceivedVisible');
$this->addSql('ALTER TABLE activitytype DROP sentReceivedLabel');
$this->addSql('ALTER TABLE activitytype DROP documentVisible');
$this->addSql('ALTER TABLE activitytype DROP documentLabel');
$this->addSql('ALTER TABLE activitytype DROP emergencyVisible');
$this->addSql('ALTER TABLE activitytype DROP emergencyLabel');
$this->addSql('ALTER TABLE activitytype DROP accompanyingPeriodVisible');
$this->addSql('ALTER TABLE activitytype DROP accompanyingPeriodLabel');
$this->addSql('ALTER TABLE activitytype DROP socialDataVisible');
$this->addSql('ALTER TABLE activitytype DROP socialDataLabel');
$this->addSql('ALTER TABLE activitytype ALTER name DROP NOT NULL');
$this->addSql('ALTER TABLE activitytype ALTER active SET DEFAULT \'true\'');
$this->addSql('COMMENT ON COLUMN activitytype.name IS NULL');
}
}