diff --git a/src/Domain/PlanningDomain.php b/src/Domain/PlanningDomain.php index ff8df790..92dcc50d 100644 --- a/src/Domain/PlanningDomain.php +++ b/src/Domain/PlanningDomain.php @@ -99,10 +99,10 @@ public function generateAvailabilities(array $filters, \DatePeriod $datePeriod): $users = $filters['hideUsers'] ?? false ? [] : $this->userRepository->findByFilters($filters, false); $assets = $filters['hideAssets'] ?? false ? [] : $this->assetRepository->findByFilters($filters, false); - return $this->splitAvailabilities( - $this->prepareAvailabilities($this->userAvailabilityRepository, $users, $datePeriod), - $this->prepareAvailabilities($this->assetAvailabilityRepository, $assets, $datePeriod) - ); + return [ + 'assets' => $this->splitAssets($this->prepareAvailabilities($this->assetAvailabilityRepository, $assets, $datePeriod)), + 'users' => $this->splitUsers($this->prepareAvailabilities($this->userAvailabilityRepository, $users, $datePeriod)), + ]; } public function generateLastUpdateAndCount(array $filters): array @@ -184,7 +184,7 @@ protected function parseRawSlots(array $rawSlots): array return $slots; } - protected function splitAvailabilities(array $usersAvailabilities, array $assetsAvailabilities): array + protected function splitAssets(array $assetsAvailabilities): array { $result = []; // Ordered associative array @@ -198,6 +198,13 @@ protected function splitAvailabilities(array $usersAvailabilities, array $assets $result[$item['entity']->type][] = $item; } + return array_filter($result); + } + + protected function splitUsers(array $usersAvailabilities): array + { + $result = []; // Ordered associative array + // Users $importantSkills = $this->skillSetDomain->getImportantSkills(); diff --git a/src/Migrations/Version20200414132415.php b/src/Migrations/Version20200414132415.php index 064df0e8..e03cdc4f 100644 --- a/src/Migrations/Version20200414132415.php +++ b/src/Migrations/Version20200414132415.php @@ -12,23 +12,23 @@ */ final class Version20200414132415 extends AbstractMigration { - public function getDescription() : string + public function getDescription(): string { - return ''; + return 'Add "license_plate" and "comments" fields to "commissionable_asset"'; } - public function up(Schema $schema) : void + public function up(Schema $schema): void { // this up() migration is auto-generated, please modify it to your needs - $this->abortIf($this->connection->getDatabasePlatform()->getName() !== 'postgresql', 'Migration can only be executed safely on \'postgresql\'.'); + $this->abortIf('postgresql' !== $this->connection->getDatabasePlatform()->getName(), 'Migration can only be executed safely on \'postgresql\'.'); $this->addSql('ALTER TABLE commissionable_asset ADD license_plate VARCHAR(255) DEFAULT NULL, ADD comments TEXT DEFAULT NULL'); } - public function down(Schema $schema) : void + public function down(Schema $schema): void { // this down() migration is auto-generated, please modify it to your needs - $this->abortIf($this->connection->getDatabasePlatform()->getName() !== 'postgresql', 'Migration can only be executed safely on \'postgresql\'.'); + $this->abortIf('postgresql' !== $this->connection->getDatabasePlatform()->getName(), 'Migration can only be executed safely on \'postgresql\'.'); $this->addSql('ALTER TABLE commissionable_asset DROP license_plate, DROP comments'); } diff --git a/templates/organization/planning/_availabilities_assets.html.twig b/templates/organization/planning/_availabilities_assets.html.twig new file mode 100644 index 00000000..d246913f --- /dev/null +++ b/templates/organization/planning/_availabilities_assets.html.twig @@ -0,0 +1,22 @@ +{% extends 'organization/planning/_availabilities_base.html.twig' %} + +{% block type %}{{ type }}{% endblock type %} + +{# columns number of blocks itemDataHeader and itemDataDetails should be the same than in _availabilities_users.html.twig #} +{% block itemDataHeader %} + Radio mobile? + Kit de premiers soins? + Contact + Lieu de stationnement + Places + Immatriculation +{% endblock itemDataHeader %} + +{% block itemDataDetails %} + {{ item.entity.hasMobileRadio ? 'Oui' : '-' }} + {{ item.entity.hasFirstAidKit ? 'Oui' : '-' }} + {{ item.entity.contact }} + {{ item.entity.parkingLocation }} + {{ item.entity.seatingCapacity }} + {{ item.entity.licensePlate }} +{% endblock itemDataDetails %} diff --git a/templates/organization/planning/_availabilities_base.html.twig b/templates/organization/planning/_availabilities_base.html.twig new file mode 100644 index 00000000..5d83d61a --- /dev/null +++ b/templates/organization/planning/_availabilities_base.html.twig @@ -0,0 +1,50 @@ + + + + {{ 'common.informations' | trans }} + {% for item in periodCalculator.days %} + + {{ item.date|format_date(pattern="eeee dd MMMM") }} + + {% endfor %} + + + {% block itemDataHeader %}{% endblock itemDataHeader %} + + {% for item in periodCalculator.slots %} + + {{ item|format_date(pattern="HH") }} + + {% endfor %} + + + +{% for type, list in availabilities %} + + + + {% block type %}{% endblock type %} + ({{ list|length }}) + + + + + + + {% for item in list %} + + + {{ item.entity }} + {% block importantSkills %}{% endblock importantSkills %} + + + {% block itemDataDetails %}{% endblock itemDataDetails %} + + {% autoescape false %} + {# Table td are rendered in php in order to avoid twig performance issue #} + {{ renderPlanningTable(item.availabilities, displayActions) }} + {% endautoescape %} + + {% endfor %} + +{% endfor %} diff --git a/templates/organization/planning/_availabilities_users.html.twig b/templates/organization/planning/_availabilities_users.html.twig new file mode 100644 index 00000000..bf1d48ed --- /dev/null +++ b/templates/organization/planning/_availabilities_users.html.twig @@ -0,0 +1,35 @@ +{% extends 'organization/planning/_availabilities_base.html.twig' %} + +{% block type %}{{ usersSkills[type] | default('organization.users' | trans) }}{% endblock type %} + +{# columns number of blocks itemDataHeader and itemDataDetails should be the same than in _availabilities_assets.html.twig #} +{% block itemDataHeader %} + {{ 'user.identificationNumber' | trans }} + {{ 'common.phoneNumberShort' | trans }} + {{ 'user.email' | trans }} + {{ 'common.occupation' | trans }} + {{ 'common.manager' | trans }} + {{ 'user.skills' | trans }} + {{ 'user.uniform' | trans }} + {{ 'user.detail.vulnerable.label' | trans }} +{% endblock itemDataHeader %} + +{% block importantSkills %} + {{ item.entity.skillSet | filter(skill => skill != type and skill in importantSkillsToDisplay) | map(skill => '' ~skill~ '') | join | raw }} +{% endblock importantSkills %} + +{% block itemDataDetails %} + {{ item.entity.identificationNumber }} + {{ item.entity.phoneNumber }} + {{ item.entity.emailAddress }} + {{ item.entity.occupation }} + {{ item.entity.organizationOccupation }} + + {% for skill in item.entity.skillSet -%} + {{ skill }} + {%- endfor %} + + {{ item.entity.fullyEquipped ? 'common.yes' | trans : '-' }} + {{ item.entity.vulnerable ? 'common.yes' | trans : '-' }} +{% endblock itemDataDetails %} diff --git a/templates/organization/planning/_results.html.twig b/templates/organization/planning/_results.html.twig index 83d8acf3..93de7ff1 100644 --- a/templates/organization/planning/_results.html.twig +++ b/templates/organization/planning/_results.html.twig @@ -54,82 +54,8 @@ {% set availabilities = getAvailabilities(periodCalculator, filters) %}
- - - - - {% for item in periodCalculator.days %} - - {% endfor %} - - - - - - - - - - - {% for item in periodCalculator.slots %} - - {% endfor %} - - - {% for type, list in availabilities %} - {% set isAsset = type in (assetsTypes|keys) %} - {% set entityType = isAsset ? 'assets' : 'users' %} - - - - - - - - - {% for item in list %} - - - {% if not isAsset %} - - - - - - - - - {% else %} - - {% endif %} - {% autoescape false %} - {# Table td are rendered in php in order to avoid twig performance issue #} - {{ renderPlanningTable(item.availabilities, displayActions) }} - {% endautoescape %} - - {% endfor %} - - {% endfor %} + {% include 'organization/planning/_availabilities_assets.html.twig' with {availabilities: availabilities.assets, entityType: 'assets'} %} + {% include 'organization/planning/_availabilities_users.html.twig' with {availabilities: availabilities.users, entityType: 'users'} %}