From 5ddc0e7a53b390b6e176798b65afdab7ab5ade13 Mon Sep 17 00:00:00 2001 From: Pol Dellaiera Date: Tue, 22 Jun 2021 15:31:49 +0200 Subject: [PATCH 01/52] Simplify loading of Symfony commands. --- .../Command/ChillPersonMoveCommand.php | 71 +-- .../Command/ImportPeopleFromCSVCommand.php | 484 ++++++++---------- .../ChillPersonExtension.php | 1 - .../ChillPersonBundle/config/services.yaml | 7 + .../config/services/command.yaml | 19 - 5 files changed, 246 insertions(+), 336 deletions(-) delete mode 100644 src/Bundle/ChillPersonBundle/config/services/command.yaml diff --git a/src/Bundle/ChillPersonBundle/Command/ChillPersonMoveCommand.php b/src/Bundle/ChillPersonBundle/Command/ChillPersonMoveCommand.php index 4f2b2098a..b68997ed6 100644 --- a/src/Bundle/ChillPersonBundle/Command/ChillPersonMoveCommand.php +++ b/src/Bundle/ChillPersonBundle/Command/ChillPersonMoveCommand.php @@ -1,25 +1,7 @@ - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . - */ namespace Chill\PersonBundle\Command; -use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand; -use Symfony\Component\Console\Input\InputArgument; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Input\InputOption; use Symfony\Component\Console\Output\OutputInterface; @@ -28,39 +10,28 @@ use Doctrine\ORM\EntityManagerInterface; use Chill\PersonBundle\Entity\Person; use Symfony\Component\Console\Exception\RuntimeException; use Psr\Log\LoggerInterface; +use Symfony\Component\Console\Command\Command; -class ChillPersonMoveCommand extends ContainerAwareCommand +final class ChillPersonMoveCommand extends Command { - /** - * - * @var PersonMove - */ - protected $mover; - - /** - * - * @var EntityManagerInterface - */ - protected $em; - - /** - * - * @var LoggerInterface - */ - protected $chillLogger; - + private PersonMove $mover; + + private EntityManagerInterface $em; + + private LoggerInterface $chillLogger; + public function __construct( - PersonMove $mover, + PersonMove $mover, EntityManagerInterface $em, LoggerInterface $chillLogger ) { parent::__construct('chill:person:move'); - + $this->mover = $mover; $this->em = $em; $this->chillLogger = $chillLogger; } - + protected function configure() { $this @@ -73,14 +44,14 @@ class ChillPersonMoveCommand extends ContainerAwareCommand ->addOption('delete-entity', null, InputOption::VALUE_REQUIRED|InputOption::VALUE_IS_ARRAY, "entity to delete", []) ; } - + protected function interact(InputInterface $input, OutputInterface $output) { if (FALSE === $input->hasOption('dump-sql') && FALSE === $input->hasOption('force')) { $msg = "You must use \"--dump-sql\" or \"--force\""; throw new RuntimeException($msg); } - + foreach (["from", "to"] as $name) { if (empty($input->getOption($name))) { throw new RuntimeException("You must set a \"$name\" option"); @@ -90,7 +61,7 @@ class ChillPersonMoveCommand extends ContainerAwareCommand throw new RuntimeException("The id in \"$name\" field does not contains " . "only digits: $id"); } - } + } } protected function execute(InputInterface $input, OutputInterface $output) @@ -99,16 +70,16 @@ class ChillPersonMoveCommand extends ContainerAwareCommand $from = $repository->find($input->getOption('from')); $to = $repository->find($input->getOption('to')); $deleteEntities = $input->getOption('delete-entity'); - + if ($from === NULL) { throw new RuntimeException(sprintf("Person \"from\" with id %d not found", $input->getOption('from'))); } if ($to === NULL) { throw new RuntimeException(sprintf("Person \"to\" with id %d not found", $input->getOption('to'))); } - + $sqls = $this->mover->getSQL($from, $to, $deleteEntities); - + if ($input->getOption('dump-sql')) { foreach($sqls as $sql) { $output->writeln($sql); @@ -125,25 +96,25 @@ class ChillPersonMoveCommand extends ContainerAwareCommand $connection->executeQuery($sql); } $connection->commit(); - + $this->chillLogger->notice("Move a person from command line succeeded", $ctxt); } } - + protected function buildLoggingContext(Person $from, Person $to, $deleteEntities, $sqls) { $ctxt = [ 'from' => $from->getId(), 'to' => $to->getId() ]; - + foreach ($deleteEntities as $key => $de) { $ctxt['delete_entity_'.$key] = $de; } foreach ($sqls as $key => $sql) { $ctxt['sql_'.$key] = $sql; } - + return $ctxt; } diff --git a/src/Bundle/ChillPersonBundle/Command/ImportPeopleFromCSVCommand.php b/src/Bundle/ChillPersonBundle/Command/ImportPeopleFromCSVCommand.php index d5e4c597c..35f596295 100644 --- a/src/Bundle/ChillPersonBundle/Command/ImportPeopleFromCSVCommand.php +++ b/src/Bundle/ChillPersonBundle/Command/ImportPeopleFromCSVCommand.php @@ -1,22 +1,5 @@ - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . - */ - namespace Chill\PersonBundle\Command; use Chill\MainBundle\Templating\TranslatableStringHelper; @@ -40,65 +23,37 @@ use Symfony\Component\Console\Question\ConfirmationQuestion; use Symfony\Component\EventDispatcher\EventDispatcherInterface; use Symfony\Component\EventDispatcher\Event; use Symfony\Component\Form\FormFactory; +use Symfony\Component\Form\FormFactoryInterface; -/** - * Class ImportPeopleFromCSVCommand - * - * @package Chill\PersonBundle\Command - * @author Julien Fastré - */ -class ImportPeopleFromCSVCommand extends Command +final class ImportPeopleFromCSVCommand extends Command { + private InputInterface $input; + + private OutputInterface $output; + + private LoggerInterface $logger; + + private TranslatableStringHelper $helper; + + private EntityManagerInterface $em; + + private EventDispatcherInterface $eventDispatcher; + /** - * @var InputInterface + * The line currently read */ - protected $input; - + private int $line; + /** - * @var OutputInterface + * Where key are column names, and value the custom field slug */ - protected $output; - - /** - * @var \Psr\Log\LoggerInterface - */ - protected $logger; - - /** - * @var \Chill\MainBundle\Templating\TranslatableStringHelper - */ - protected $helper; - - /** - * @var \Doctrine\Persistence\ObjectManager - */ - protected $em; - - /** - * @var EventDispatcherInterface - */ - protected $eventDispatcher; - - /** - * the line currently read - * - * @var int - */ - protected $line; - - /** - * @var array where key are column names, and value the custom field slug - */ - protected $customFieldMapping = array(); - - /** - * @var CustomFieldProvider - */ - protected $customFieldProvider; - + private array $customFieldMapping = []; + + private CustomFieldProvider $customFieldProvider; + /** * Contains an array of information searched in the file. - * + * * position 0: the information key (which will be used in this process) * position 1: the helper * position 2: the default value @@ -121,19 +76,16 @@ class ImportPeopleFromCSVCommand extends Command ['locality', 'The column header for locality', 'locality'], ['center', 'The column header for center', 'center'] ); - + /** * Different possible format to interpret a date * * @var string */ protected static $defaultDateInterpreter = "%d/%m/%Y|%e/%m/%y|%d/%m/%Y|%e/%m/%Y"; - - /** - * @var FormFactory - */ - protected $formFactory; - + + private FormFactoryInterface $formFactory; + /** * ImportPeopleFromCSVCommand constructor. * @@ -150,7 +102,7 @@ class ImportPeopleFromCSVCommand extends Command EntityManagerInterface $em, CustomFieldProvider $customFieldProvider, EventDispatcherInterface $eventDispatcher, - FormFactory $formFactory + FormFactoryInterface $formFactory ) { $this->logger = $logger; $this->helper = $helper; @@ -158,10 +110,10 @@ class ImportPeopleFromCSVCommand extends Command $this->customFieldProvider = $customFieldProvider; $this->eventDispatcher = $eventDispatcher; $this->formFactory = $formFactory; - + parent::__construct('chill:person:import'); } - + /** * */ @@ -171,10 +123,10 @@ class ImportPeopleFromCSVCommand extends Command ->addArgument('csv_file', InputArgument::REQUIRED, "The CSV file to import") ->setDescription("Import people from a csv file") ->setHelp(<<addArgument('locale', InputArgument::REQUIRED, + ->addArgument('locale', InputArgument::REQUIRED, "The locale to use in displaying translatable strings from entities") ->addOption( - 'force-center', - null, + 'force-center', + null, InputOption::VALUE_REQUIRED, "The id of the center" ) @@ -197,10 +149,10 @@ EOF "Persist people in the database (default is not to persist people)" ) ->addOption( - 'delimiter', - 'd', - InputOption::VALUE_OPTIONAL, - "The delimiter character of the csv file", + 'delimiter', + 'd', + InputOption::VALUE_OPTIONAL, + "The delimiter character of the csv file", ",") ->addOption( 'enclosure', @@ -236,33 +188,33 @@ EOF "The path of the file to load the matching between label in CSV and answers" ) ; - + // mapping columns foreach (self::$mapping as $m) { $this->addOptionShortcut($m[0], $m[1], $m[2]); } - + // other information $this->addOptionShortcut('birthdate_format', 'Format preference for ' - . 'birthdate. See help for date formats preferences.', + . 'birthdate. See help for date formats preferences.', self::$defaultDateInterpreter); $this->addOptionShortcut('opening_date_format', 'Format preference for ' . 'opening date. See help for date formats preferences.', self::$defaultDateInterpreter); $this->addOptionShortcut('closing_date_format', 'Format preference for ' - . 'closing date. See help for date formats preferences.', + . 'closing date. See help for date formats preferences.', self::$defaultDateInterpreter); - + // mapping column to custom fields - $this->addOption('custom-field', NULL, InputOption::VALUE_REQUIRED | InputOption::VALUE_IS_ARRAY, + $this->addOption('custom-field', NULL, InputOption::VALUE_REQUIRED | InputOption::VALUE_IS_ARRAY, "Mapping a column to a custom fields key. Example: 1=cf_slug"); $this->addOption('skip-interactive-field-mapping', null, InputOption::VALUE_NONE, "Do not ask for interactive mapping"); } - + /** * This function is a shortcut to addOption. - * + * * @param string $name * @param string $description * @param string $default @@ -271,10 +223,10 @@ EOF protected function addOptionShortcut($name, $description, $default) { $this->addOption($name, null, InputOption::VALUE_OPTIONAL, $description, $default); - + return $this; } - + /** * @param InputInterface $input * @param OutputInterface $output @@ -285,17 +237,17 @@ EOF $this->input = $input; $this->output = $output; $this->logger = new ConsoleLogger($output); - + $csv = $this->openCSV(); - + // getting the first row if (($row = fgetcsv( - $csv, - $input->getOption('length'), - $input->getOption('delimiter'), - $input->getOption('enclosure'), + $csv, + $input->getOption('length'), + $input->getOption('delimiter'), + $input->getOption('enclosure'), $input->getOption('escape'))) !== false) { - + try { $this->matchColumnToCustomField($row); } finally { @@ -303,33 +255,33 @@ EOF fclose($csv); } } - + // load the matching between csv and label $this->loadAnswerMatching(); } - + /** * @param $row */ protected function matchColumnToCustomField($row) { - + $cfMappingsOptions = $this->input->getOption('custom-field'); /* @var $em \Doctrine\Persistence\ObjectManager */ $em = $this->em; - + foreach($cfMappingsOptions as $cfMappingStringOption) { list($rowNumber, $cfSlug) = preg_split('|=|', $cfMappingStringOption); - + // check that the column exists, getting the column name $column = $row[$rowNumber]; - + if (empty($column)) { $message = "The column with row $rowNumber is empty."; $this->logger->error($message); throw new \RuntimeException($message); } - + // check a custom field exists try { $customField = $em->createQuery("SELECT cf " @@ -357,15 +309,15 @@ EOF . "Stopping this command."); throw new \RuntimeException("The custom field with slug $cfSlug could not be found. " . "Stopping this command."); - } - + } + $this->logger->notice(sprintf("Matched custom field %s (question : '%s') on column %d (displayed in the file as '%s')", $customField->getSlug(), $this->helper->localize($customField->getName()), $rowNumber, $column)); - + $this->customFieldMapping[$rowNumber] = $customField; } } - + /** * Load the mapping between answer in CSV and value in choices from a json file */ @@ -383,7 +335,7 @@ EOF } } } - + /** * */ @@ -392,14 +344,14 @@ EOF if ($this->input->hasOption('dump-choice-matching') && !empty($this->input->getOption('dump-choice-matching'))) { $this->logger->debug("Dump the matching between answer and choices"); $str = json_encode($this->cacheAnswersMapping, JSON_PRETTY_PRINT); - + $fs = new Filesystem(); $filename = $this->input->getOption('dump-choice-matching'); - + $fs->dumpFile($filename, $str); } } - + /** * @param InputInterface $input * @param OutputInterface $output @@ -410,22 +362,22 @@ EOF { $this->input = $input; $this->output = $output; - + $this->logger->debug("Setting locale to ".$input->getArgument('locale')); setlocale(LC_TIME, $input->getArgument('locale')); - + // opening csv as resource $csv = $this->openCSV(); - + $num = 0; $line = $this->line = 1; - + try { while (($row = fgetcsv( - $csv, - $input->getOption('length'), - $input->getOption('delimiter'), - $input->getOption('enclosure'), + $csv, + $input->getOption('length'), + $input->getOption('delimiter'), + $input->getOption('enclosure'), $input->getOption('escape'))) !== false) { $this->logger->debug("Processing line ".$this->line); if ($line === 1 ) { @@ -434,11 +386,11 @@ EOF $headers = $this->processingHeaders($row); } else { $person = $this->createPerson($row, $headers); - + if (count($this->customFieldMapping) > 0) { $this->processingCustomFields($person, $row); } - + $event = new Event(); $event->person = $person; $event->rawHeaders = $rawHeaders; @@ -449,21 +401,21 @@ EOF $event->input = $this->input; $event->output = $this->output; $event->helperSet = $this->getHelperSet(); - + $this->eventDispatcher->dispatch('chill_person.person_import', $event); - - if ($this->input->getOption('force') === TRUE + + if ($this->input->getOption('force') === TRUE && $event->skipPerson === false) { $this->em->persist($person); } - + $num ++; } $line ++; $this->line++; } - + if ($this->input->getOption('force') === true) { $this->logger->debug('persisting entitites'); $this->em->flush(); @@ -475,9 +427,9 @@ EOF $this->dumpAnswerMatching(); } } - + /** - * + * * @return resource * @throws \RuntimeException */ @@ -485,23 +437,23 @@ EOF { $fs = new Filesystem(); $filename = $this->input->getArgument('csv_file'); - + if (!$fs->exists($filename)) { throw new \RuntimeException("The file does not exists or you do not " . "have the right to read it."); } - + $resource = fopen($filename, 'r'); - + if ($resource == FALSE) { throw new \RuntimeException("The file '$filename' could not be opened."); } - + return $resource; } - + /** - * + * * @param type $firstRow * @return array where keys are column number, and value is information mapped */ @@ -510,11 +462,11 @@ EOF $availableOptions = array_map(function($m) { return $m[0]; }, self::$mapping); $matchedColumnHeaders = array(); $headers = array(); - + foreach($availableOptions as $option) { $matchedColumnHeaders[$option] = $this->input->getOption($option); } - + foreach($firstRow as $key => $content) { $content = trim($content); if (in_array($content, $matchedColumnHeaders)) { @@ -524,11 +476,11 @@ EOF } else { $this->logger->notice("Column with content '$content' is ignored"); } - } - + } + return $headers; } - + /** * * @param array $row @@ -541,21 +493,21 @@ EOF // trying to get the opening date $openingDateString = trim($row[array_search('opening_date', $headers)]); $openingDate = $this->processDate($openingDateString, $this->input->getOption('opening_date_format')); - + $person = $openingDate instanceof \DateTime ? new Person($openingDate) : new Person(); // add the center $center = $this->getCenter($row, $headers); - + if ($center === null) { throw new \Exception("center not found"); } - + $person->setCenter($center); - + foreach($headers as $column => $info) { - + $value = trim($row[$column]); - + switch($info) { case 'firstname': $person->setFirstName($value); @@ -582,12 +534,12 @@ EOF $person->setEmail($value); break; case 'phonenumber': - $person->setPhonenumber($value); + $person->setPhonenumber($value); break; case 'mobilenumber': $person->setMobilenumber($value); break; - + // we just keep the column number for those data case 'postalcode': $postalCodeValue = $value; @@ -600,33 +552,33 @@ EOF break; } } - + // handle address if (\in_array('postalcode', $headers)) { - + if (! empty($postalCodeValue)) { - + $address = new Address(); $postalCode = $this->guessPostalCode($postalCodeValue, $localityValue ?? ''); - + if ($postalCode === null) { throw new \Exception("The locality is not found"); } - + $address->setPostcode($postalCode); - + if (\in_array('street1', $headers)) { $address->setStreetAddress1($street1Value); } $address->setValidFrom(new \DateTime('today')); - + $person->addAddress($address); } } - + return $person; } - + /** * @param $row * @param $headers @@ -640,7 +592,7 @@ EOF } else { $columnCenter = \array_search('center', $headers); $centerName = \trim($row[$columnCenter]); - + try { return $this->em->createQuery('SELECT c FROM ChillMainBundle:Center c ' . 'WHERE c.name = :center_name') @@ -654,7 +606,7 @@ EOF } } } - + /** * @param $centerName * @return Center|mixed|null|object @@ -664,68 +616,68 @@ EOF if (!\array_key_exists('_center_picked', $this->cacheAnswersMapping)) { $this->cacheAnswersMapping['_center_picked'] = []; } - + if (\array_key_exists($centerName, $this->cacheAnswersMapping['_center_picked'])) { $id = $this->cacheAnswersMapping['_center_picked'][$centerName]; - + return $this->em->getRepository(Center::class) ->find($id); } - + $centers = $this->em->createQuery("SELECT c FROM ChillMainBundle:Center c " . "ORDER BY SIMILARITY(c.name, :center_name) DESC") ->setParameter('center_name', $centerName) ->setMaxResults(10) ->getResult() ; - + if (count($centers) > 1) { if (\strtolower($centers[0]->getName()) === \strtolower($centerName)) { return $centers[0]; } } - + $centersByName = []; - $names = \array_map(function(Center $c) use (&$centersByName) { + $names = \array_map(function(Center $c) use (&$centersByName) { $n = $c->getName(); $centersByName[$n] = $c; return $n; - + }, $centers); $names[] = "none of them"; - + $helper = $this->getHelper('question'); - $question = new ChoiceQuestion(sprintf("Which center match the name \"%s\" ? (default to \"%s\")", $centerName, $names[0]), + $question = new ChoiceQuestion(sprintf("Which center match the name \"%s\" ? (default to \"%s\")", $centerName, $names[0]), $names, 0); - + $answer = $helper->ask($this->input, $this->output, $question); - + if ($answer === 'none of them') { $questionCreate = new ConfirmationQuestion("Would you like to create it ?", false); $create = $helper->ask($this->input, $this->output, $questionCreate); - + if ($create) { $center = (new Center()) ->setName($centerName) ; - + if ($this->input->getOption('force') === TRUE) { $this->em->persist($center); $this->em->flush(); } - + return $center; } } - + $center = $centersByName[$answer]; - + $this->cacheAnswersMapping['_center_picked'][$centerName] = $center->getId(); - + return $center; } - + /** * @param $postalCode * @param $locality @@ -736,15 +688,15 @@ EOF if (!\array_key_exists('_postal_code_picked', $this->cacheAnswersMapping)) { $this->cacheAnswersMapping['_postal_code_picked'] = []; } - + if (\array_key_exists($postalCode, $this->cacheAnswersMapping['_postal_code_picked'])) { if (\array_key_exists($locality, $this->cacheAnswersMapping['_postal_code_picked'][$postalCode])) { $id = $this->cacheAnswersMapping['_postal_code_picked'][$postalCode][$locality]; - + return $this->em->getRepository(PostalCode::class)->find($id); } } - + $postalCodes = $this->em->createQuery("SELECT pc FROM ".PostalCode::class." pc " . "WHERE pc.code = :postal_code " . "ORDER BY SIMILARITY(pc.name, :locality) DESC " @@ -754,48 +706,48 @@ EOF ->setParameter('locality', $locality) ->getResult() ; - + if (count($postalCodes) >= 1) { - if ($postalCodes[0]->getCode() === $postalCode + if ($postalCodes[0]->getCode() === $postalCode && $postalCodes[0]->getName() === $locality) { return $postalCodes[0]; } } - + if (count($postalCodes) === 0) { return null; } - + $postalCodeByName = []; $names = \array_map(function(PostalCode $pc) use (&$postalCodeByName) { $n = $pc->getName(); $postalCodeByName[$n] = $pc; - + return $n; }, $postalCodes); $names[] = 'none of them'; - + $helper = $this->getHelper('question'); $question = new ChoiceQuestion(sprintf("Which postal code match the " - . "name \"%s\" with postal code \"%s\" ? (default to \"%s\")", - $locality, $postalCode, $names[0]), + . "name \"%s\" with postal code \"%s\" ? (default to \"%s\")", + $locality, $postalCode, $names[0]), $names, 0); - + $answer = $helper->ask($this->input, $this->output, $question); - + if ($answer === 'none of them') { return null; } - + $pc = $postalCodeByName[$answer]; - - $this->cacheAnswersMapping['_postal_code_picked'][$postalCode][$locality] = + + $this->cacheAnswersMapping['_postal_code_picked'][$postalCode][$locality] = $pc->getId(); - + return $pc; } - + /** * @param Person $person * @param $value @@ -804,29 +756,29 @@ EOF protected function processBirthdate(Person $person, $value) { if (empty($value)) { return; } - + $date = $this->processDate($value, $this->input->getOption('birthdate_format')); - + if ($date instanceof \DateTime) { // we correct birthdate if the date is in the future // the most common error is to set date 100 years to late (ex. 2063 instead of 1963) if ($date > new \DateTime('yesterday')) { $date = $date->sub(new \DateInterval('P100Y')); } - + $person->setBirthdate($date); - + return; } - + // if we arrive here, we could not process the date $this->logger->warning(sprintf( "Line %d : the birthdate could not be interpreted. Was %s.", $this->line, $value)); - + } - + /** * @param Person $person * @param $value @@ -835,39 +787,39 @@ EOF protected function processClosingDate(Person $person, $value) { if (empty($value)) { return; } - + // we skip if the opening date is now (or after yesterday) /* @var $period \Chill\PersonBundle\Entity\AccompanyingPeriod */ $period = $person->getCurrentAccompanyingPeriod(); - + if ($period->getOpeningDate() > new \DateTime('yesterday')) { $this->logger->debug(sprintf("skipping a closing date because opening date is after yesterday (%s)", $period->getOpeningDate()->format('Y-m-d'))); return; } - - + + $date = $this->processDate($value, $this->input->getOption('closing_date_format')); - + if ($date instanceof \DateTime) { // we correct birthdate if the date is in the future // the most common error is to set date 100 years to late (ex. 2063 instead of 1963) if ($date > new \DateTime('yesterday')) { $date = $date->sub(new \DateInterval('P100Y')); } - + $period->setClosingDate($date); $person->close(); return; } - + // if we arrive here, we could not process the date $this->logger->warning(sprintf( "Line %d : the closing date could not be interpreted. Was %s.", $this->line, $value)); } - + /** * @param Person $person * @param $row @@ -875,27 +827,27 @@ EOF */ protected function processingCustomFields(Person $person, $row) { - + /* @var $cfProvider \Chill\CustomFieldsBundle\Service\CustomFieldProvider */ $cfProvider = $this->customFieldProvider; $cfData = array(); - + /* @var $$customField \Chill\CustomFieldsBundle\Entity\CustomField */ foreach($this->customFieldMapping as $rowNumber => $customField) { $builder = $this->formFactory->createBuilder(); $cfProvider->getCustomFieldByType($customField->getType()) ->buildForm($builder, $customField); $form = $builder->getForm(); - + // get the type of the form $type = get_class($form->get($customField->getSlug()) ->getConfig()->getType()->getInnerType()); - $this->logger->debug(sprintf("Processing a form of type %s", + $this->logger->debug(sprintf("Processing a form of type %s", $type)); switch ($type) { case \Symfony\Component\Form\Extension\Core\Type\TextType::class: - $cfData[$customField->getSlug()] = + $cfData[$customField->getSlug()] = $this->processTextType($row[$rowNumber], $form, $customField); break; case \Symfony\Component\Form\Extension\Core\Type\ChoiceType::class: @@ -903,12 +855,12 @@ EOF $cfData[$customField->getSlug()] = $this->processChoiceType($row[$rowNumber], $form, $customField); } - + } - + $person->setCFData($cfData); } - + /** * Process a text type on a custom field * @@ -917,24 +869,24 @@ EOF * @return type */ protected function processTextType( - $value, - \Symfony\Component\Form\FormInterface $form, + $value, + \Symfony\Component\Form\FormInterface $form, \Chill\CustomFieldsBundle\Entity\CustomField $cf ) { $form->submit(array($cf->getSlug() => $value)); - + $value = $form->getData()[$cf->getSlug()]; - + $this->logger->debug(sprintf("Found value : %s for custom field with question " . "'%s'", $value, $this->helper->localize($cf->getName()))); - + return $value; } - + protected $cacheAnswersMapping = array(); - - + + /** * Process a custom field choice. * @@ -949,14 +901,14 @@ EOF */ protected function processChoiceType( $value, - \Symfony\Component\Form\FormInterface $form, + \Symfony\Component\Form\FormInterface $form, \Chill\CustomFieldsBundle\Entity\CustomField $cf ) { // getting the possible answer and their value : $view = $form->get($cf->getSlug())->createView(); $answers = $this->collectChoicesAnswers($view->vars['choices']); - + // if we do not have any answer on the question, throw an error. if (count($answers) === 0) { $message = sprintf( @@ -964,34 +916,34 @@ EOF $this->helper->localize($cf->getName()), $cf->getSlug() ); - + $this->logger->error($message, array( 'method' => __METHOD__, 'slug' => $cf->getSlug(), 'question' => $this->helper->localize($cf->getName()) )); - + throw new \RuntimeException($message); } - + if ($view->vars['required'] === false) { $answers[null] = '** no answer'; } - + // the answer does not exists in cache. Try to find it, or asks the user if (!isset($this->cacheAnswersMapping[$cf->getSlug()][$value])) { - + // try to find the answer (with array_keys and a search value $values = array_keys( - array_map(function($label) { return trim(strtolower($label)); }, $answers), + array_map(function($label) { return trim(strtolower($label)); }, $answers), trim(strtolower($value)), true ); - + if (count($values) === 1) { // we could guess an answer ! $this->logger->info("This question accept multiple answers"); - $this->cacheAnswersMapping[$cf->getSlug()][$value] = + $this->cacheAnswersMapping[$cf->getSlug()][$value] = $view->vars['multiple'] == false ? $values[0] : array($values[0]); $this->logger->info(sprintf("Guessed that value '%s' match with key '%s' " . "because the CSV and the label are equals.", @@ -1021,20 +973,20 @@ EOF array_keys($matchingTableRowAnswer) ); $question->setErrorMessage("This choice is not possible"); - + if ($view->vars['multiple']) { $this->logger->debug("this question is multiple"); $question->setMultiselect(true); } - + $selected = $this->getHelper('question')->ask($this->input, $this->output, $question); - $this->output->writeln(sprintf('You have selected "%s"', - is_array($answers[$matchingTableRowAnswer[$selected]]) ? + $this->output->writeln(sprintf('You have selected "%s"', + is_array($answers[$matchingTableRowAnswer[$selected]]) ? implode(',', $answers[$matchingTableRowAnswer[$selected]]) : $answers[$matchingTableRowAnswer[$selected]]) ); - + // recording value in cache $this->cacheAnswersMapping[$cf->getSlug()][$value] = $matchingTableRowAnswer[$selected]; $this->logger->debug(sprintf("Setting the value '%s' in cache for customfield '%s' and answer '%s'", @@ -1045,19 +997,19 @@ EOF $value)); } } - + $form->submit(array($cf->getSlug() => $this->cacheAnswersMapping[$cf->getSlug()][$value])); $value = $form->getData()[$cf->getSlug()]; - + $this->logger->debug(sprintf( - "Found value : %s for custom field with question '%s'", - is_array($value) ? implode(',', $value) : $value, + "Found value : %s for custom field with question '%s'", + is_array($value) ? implode(',', $value) : $value, $this->helper->localize($cf->getName())) ); - + return $value; } - + /** * Recursive method to collect the possibles answer from a ChoiceType (or * its inherited types). @@ -1069,7 +1021,7 @@ EOF private function collectChoicesAnswers($choices) { $answers = array(); - + /* @var $choice \Symfony\Component\Form\ChoiceList\View\ChoiceView */ foreach($choices as $choice) { if ($choice instanceof \Symfony\Component\Form\ChoiceList\View\ChoiceView) { @@ -1085,10 +1037,10 @@ EOF )); } } - + return $answers; } - + /** * @param $value * @param $formats @@ -1097,13 +1049,13 @@ EOF protected function processDate($value, $formats) { $possibleFormats = explode("|", $formats); - + foreach($possibleFormats as $format) { $this->logger->debug("Trying format $format", array(__METHOD__)); $dateR = strptime($value, $format); - + if (is_array($dateR) && $dateR['unparsed'] === '') { - $string = sprintf("%04d-%02d-%02d %02d:%02d:%02d", + $string = sprintf("%04d-%02d-%02d %02d:%02d:%02d", ($dateR['tm_year']+1900), ($dateR['tm_mon']+1), ($dateR['tm_mday']), @@ -1112,19 +1064,19 @@ EOF ($dateR['tm_sec'])); $date = \DateTime::createFromFormat("Y-m-d H:i:s", $string); $this->logger->debug(sprintf("Interpreting %s as date %s", $value, $date->format("Y-m-d H:i:s"))); - + return $date; } } - + // if we arrive here, we could not process the date $this->logger->debug(sprintf( "Line %d : a date could not be interpreted. Was %s.", $this->line, $value)); - + return false; } - - + + } diff --git a/src/Bundle/ChillPersonBundle/DependencyInjection/ChillPersonExtension.php b/src/Bundle/ChillPersonBundle/DependencyInjection/ChillPersonExtension.php index 79dae3255..f52564cfa 100644 --- a/src/Bundle/ChillPersonBundle/DependencyInjection/ChillPersonExtension.php +++ b/src/Bundle/ChillPersonBundle/DependencyInjection/ChillPersonExtension.php @@ -69,7 +69,6 @@ class ChillPersonExtension extends Extension implements PrependExtensionInterfac $loader->load('services/search.yaml'); $loader->load('services/menu.yaml'); $loader->load('services/privacyEvent.yaml'); - $loader->load('services/command.yaml'); $loader->load('services/actions.yaml'); $loader->load('services/form.yaml'); $loader->load('services/alt_names.yaml'); diff --git a/src/Bundle/ChillPersonBundle/config/services.yaml b/src/Bundle/ChillPersonBundle/config/services.yaml index 7f70a02dd..463ad0141 100644 --- a/src/Bundle/ChillPersonBundle/config/services.yaml +++ b/src/Bundle/ChillPersonBundle/config/services.yaml @@ -12,6 +12,13 @@ services: tags: - { name: 'serializer.normalizer', priority: 64 } + Chill\PersonBundle\Command\: + resource: '../Command/' + autowire: true + autoconfigure: true + tags: + - { name: console.command } + chill.person.form.type.select2maritalstatus: class: Chill\PersonBundle\Form\Type\Select2MaritalStatusType arguments: diff --git a/src/Bundle/ChillPersonBundle/config/services/command.yaml b/src/Bundle/ChillPersonBundle/config/services/command.yaml deleted file mode 100644 index 685a348dd..000000000 --- a/src/Bundle/ChillPersonBundle/config/services/command.yaml +++ /dev/null @@ -1,19 +0,0 @@ -services: - Chill\PersonBundle\Command\ChillPersonMoveCommand: - arguments: - $em: '@Doctrine\ORM\EntityManagerInterface' - $mover: '@Chill\PersonBundle\Actions\Remove\PersonMove' - $chillLogger: '@chill.main.logger' - tags: - - { name: console.command } - - Chill\PersonBundle\Command\ImportPeopleFromCSVCommand: - arguments: - $logger: '@logger' - $helper: '@Chill\MainBundle\Templating\TranslatableStringHelper' - $em: '@Doctrine\ORM\EntityManagerInterface' - $customFieldProvider: '@Chill\CustomFieldsBundle\Service\CustomFieldProvider' - $eventDispatcher: '@Symfony\Component\EventDispatcher\EventDispatcherInterface' - $formFactory: '@form.factory' - tags: - - { name: console.command } From 2667867bd042167863e1a49fbade006bfacfb985 Mon Sep 17 00:00:00 2001 From: Pol Dellaiera Date: Wed, 23 Jun 2021 22:28:05 +0200 Subject: [PATCH 02/52] Update composer - Bump league/php. --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index fb0d2dcd1..b5af76421 100644 --- a/composer.json +++ b/composer.json @@ -52,7 +52,7 @@ "knplabs/knp-time-bundle": "^1.12", "symfony/intl": "4.*", "symfony/swiftmailer-bundle": "^3.5", - "league/csv": "^9.6", + "league/csv": "^9.7.1", "phpoffice/phpspreadsheet": "^1.16", "symfony/browser-kit": "^5.2", "symfony/css-selector": "^5.2", From dc26ca7e7708e5ccb42ba800c06d57bc7f82e1ac Mon Sep 17 00:00:00 2001 From: Pol Dellaiera Date: Wed, 23 Jun 2021 16:39:40 +0200 Subject: [PATCH 03/52] Add missing getId() method. --- src/Bundle/ChillPersonBundle/Entity/SocialWork/Goal.php | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/Bundle/ChillPersonBundle/Entity/SocialWork/Goal.php b/src/Bundle/ChillPersonBundle/Entity/SocialWork/Goal.php index 996fcf3eb..633df147c 100644 --- a/src/Bundle/ChillPersonBundle/Entity/SocialWork/Goal.php +++ b/src/Bundle/ChillPersonBundle/Entity/SocialWork/Goal.php @@ -46,6 +46,11 @@ class Goal $this->results = new ArrayCollection(); } + public function getId(): int + { + return $this->id; + } + public function getTitle(): array { return $this->title; From df1f44d81453f1a60b3a46d9fa32f5264ec9fe7b Mon Sep 17 00:00:00 2001 From: Pol Dellaiera Date: Wed, 23 Jun 2021 16:40:04 +0200 Subject: [PATCH 04/52] Let SocialAction::defaultNotificationDelay be nullable. --- .../Entity/SocialWork/SocialAction.php | 2 +- .../migrations/Version20210623142046.php | 29 +++++++++++++++++++ 2 files changed, 30 insertions(+), 1 deletion(-) create mode 100644 src/Bundle/ChillPersonBundle/migrations/Version20210623142046.php diff --git a/src/Bundle/ChillPersonBundle/Entity/SocialWork/SocialAction.php b/src/Bundle/ChillPersonBundle/Entity/SocialWork/SocialAction.php index 35abe392f..506a736d8 100644 --- a/src/Bundle/ChillPersonBundle/Entity/SocialWork/SocialAction.php +++ b/src/Bundle/ChillPersonBundle/Entity/SocialWork/SocialAction.php @@ -47,7 +47,7 @@ class SocialAction private $children; /** - * @ORM\Column(type="dateinterval") + * @ORM\Column(type="dateinterval", nullable=true) */ private $defaultNotificationDelay; diff --git a/src/Bundle/ChillPersonBundle/migrations/Version20210623142046.php b/src/Bundle/ChillPersonBundle/migrations/Version20210623142046.php new file mode 100644 index 000000000..8baffb867 --- /dev/null +++ b/src/Bundle/ChillPersonBundle/migrations/Version20210623142046.php @@ -0,0 +1,29 @@ +addSql('ALTER TABLE chill_person_social_action ALTER defaultnotificationdelay DROP NOT NULL'); + } + + public function down(Schema $schema): void + { + $this->addSql('ALTER TABLE chill_person_social_action ALTER defaultNotificationDelay SET NOT NULL'); + } +} From 6e37e7feacd22f0c7721cc934274f0c57b287f04 Mon Sep 17 00:00:00 2001 From: Pol Dellaiera Date: Wed, 23 Jun 2021 16:40:43 +0200 Subject: [PATCH 05/52] Let repositories implements ObjectRepository. --- .../SocialWork/EvaluationRepository.php | 39 ++++++++++++++++++- .../Repository/SocialWork/GoalRepository.php | 38 +++++++++++++++++- .../SocialWork/ResultRepository.php | 38 +++++++++++++++++- .../SocialWork/SocialActionRepository.php | 37 +++++++++++++++++- .../SocialWork/SocialIssueRepository.php | 29 ++++++-------- 5 files changed, 160 insertions(+), 21 deletions(-) diff --git a/src/Bundle/ChillPersonBundle/Repository/SocialWork/EvaluationRepository.php b/src/Bundle/ChillPersonBundle/Repository/SocialWork/EvaluationRepository.php index f554e4e8c..d0f11c2d3 100644 --- a/src/Bundle/ChillPersonBundle/Repository/SocialWork/EvaluationRepository.php +++ b/src/Bundle/ChillPersonBundle/Repository/SocialWork/EvaluationRepository.php @@ -5,8 +5,9 @@ namespace Chill\PersonBundle\Repository\SocialWork; use Chill\PersonBundle\Entity\SocialWork\Evaluation; use Doctrine\ORM\EntityManagerInterface; use Doctrine\ORM\EntityRepository; +use Doctrine\Persistence\ObjectRepository; -final class EvaluationRepository +final class EvaluationRepository implements ObjectRepository { private EntityRepository $repository; @@ -14,4 +15,40 @@ final class EvaluationRepository { $this->repository = $entityManager->getRepository(Evaluation::class); } + + public function find($id, ?int $lockMode = null, ?int $lockVersion = null): ?Evaluation + { + return $this->repository->find($id, $lockMode, $lockVersion); + } + + /** + * @return array + */ + public function findAll(): array + { + return $this->repository->findAll(); + } + + /** + * @return array + */ + public function findBy(array $criteria, ?array $orderBy = null, $limit = null, $offset = null): array + { + return $this->repository->findBy($criteria, $orderBy, $limit, $offset); + } + + public function findOneBy(array $criteria, ?array $orderBy = null): ?Evaluation + { + return $this->repository->findOneBy($criteria, $orderBy); + } + + /** + * @return class-string + */ + public function getClassName(): string + { + return Evaluation::class; + } + + } diff --git a/src/Bundle/ChillPersonBundle/Repository/SocialWork/GoalRepository.php b/src/Bundle/ChillPersonBundle/Repository/SocialWork/GoalRepository.php index bd7c6a738..cb2815d89 100644 --- a/src/Bundle/ChillPersonBundle/Repository/SocialWork/GoalRepository.php +++ b/src/Bundle/ChillPersonBundle/Repository/SocialWork/GoalRepository.php @@ -5,8 +5,9 @@ namespace Chill\PersonBundle\Repository\SocialWork; use Chill\PersonBundle\Entity\SocialWork\Goal; use Doctrine\ORM\EntityManagerInterface; use Doctrine\ORM\EntityRepository; +use Doctrine\Persistence\ObjectRepository; -final class GoalRepository +final class GoalRepository implements ObjectRepository { private EntityRepository $repository; @@ -14,4 +15,39 @@ final class GoalRepository { $this->repository = $entityManager->getRepository(Goal::class); } + + public function find($id, ?int $lockMode = null, ?int $lockVersion = null): ?Goal + { + return $this->repository->find($id, $lockMode, $lockVersion); + } + + /** + * @return array + */ + public function findAll(): array + { + return $this->repository->findAll(); + } + + /** + * @return array + */ + public function findBy(array $criteria, ?array $orderBy = null, $limit = null, $offset = null): array + { + return $this->repository->findBy($criteria, $orderBy, $limit, $offset); + } + + public function findOneBy(array $criteria, ?array $orderBy = null): ?Goal + { + return $this->repository->findOneBy($criteria, $orderBy); + } + + /** + * @return class-string + */ + public function getClassName(): string + { + return Goal::class; + } + } diff --git a/src/Bundle/ChillPersonBundle/Repository/SocialWork/ResultRepository.php b/src/Bundle/ChillPersonBundle/Repository/SocialWork/ResultRepository.php index 1c4d8d013..047e4325f 100644 --- a/src/Bundle/ChillPersonBundle/Repository/SocialWork/ResultRepository.php +++ b/src/Bundle/ChillPersonBundle/Repository/SocialWork/ResultRepository.php @@ -5,8 +5,9 @@ namespace Chill\PersonBundle\Repository\SocialWork; use Chill\PersonBundle\Entity\SocialWork\Result; use Doctrine\ORM\EntityManagerInterface; use Doctrine\ORM\EntityRepository; +use Doctrine\Persistence\ObjectRepository; -final class ResultRepository +final class ResultRepository implements ObjectRepository { private EntityRepository $repository; @@ -14,4 +15,39 @@ final class ResultRepository { $this->repository = $entityManager->getRepository(Result::class); } + + public function find($id, ?int $lockMode = null, ?int $lockVersion = null): ?Result + { + return $this->repository->find($id, $lockMode, $lockVersion); + } + + /** + * @return array + */ + public function findAll(): array + { + return $this->repository->findAll(); + } + + /** + * @return array + */ + public function findBy(array $criteria, ?array $orderBy = null, $limit = null, $offset = null): array + { + return $this->repository->findBy($criteria, $orderBy, $limit, $offset); + } + + public function findOneBy(array $criteria, ?array $orderBy = null): ?Result + { + return $this->repository->findOneBy($criteria, $orderBy); + } + + /** + * @return class-string + */ + public function getClassName(): string + { + return Result::class; + } + } diff --git a/src/Bundle/ChillPersonBundle/Repository/SocialWork/SocialActionRepository.php b/src/Bundle/ChillPersonBundle/Repository/SocialWork/SocialActionRepository.php index 3c86d2397..a81789c0a 100644 --- a/src/Bundle/ChillPersonBundle/Repository/SocialWork/SocialActionRepository.php +++ b/src/Bundle/ChillPersonBundle/Repository/SocialWork/SocialActionRepository.php @@ -5,8 +5,9 @@ namespace Chill\PersonBundle\Repository\SocialWork; use Chill\PersonBundle\Entity\SocialWork\SocialAction; use Doctrine\ORM\EntityManagerInterface; use Doctrine\ORM\EntityRepository; +use Doctrine\Persistence\ObjectRepository; -final class SocialActionRepository +final class SocialActionRepository implements ObjectRepository { private EntityRepository $repository; @@ -14,4 +15,38 @@ final class SocialActionRepository { $this->repository = $entityManager->getRepository(SocialAction::class); } + + public function find($id, ?int $lockMode = null, ?int $lockVersion = null): ?SocialAction + { + return $this->repository->find($id, $lockMode, $lockVersion); + } + + /** + * @return array + */ + public function findAll(): array + { + return $this->repository->findAll(); + } + + /** + * @return array + */ + public function findBy(array $criteria, ?array $orderBy = null, $limit = null, $offset = null): array + { + return $this->repository->findBy($criteria, $orderBy, $limit, $offset); + } + + public function findOneBy(array $criteria, ?array $orderBy = null): ?SocialAction + { + return $this->repository->findOneBy($criteria, $orderBy); + } + + /** + * @return class-string + */ + public function getClassName(): string + { + return SocialAction::class; + } } diff --git a/src/Bundle/ChillPersonBundle/Repository/SocialWork/SocialIssueRepository.php b/src/Bundle/ChillPersonBundle/Repository/SocialWork/SocialIssueRepository.php index 4dc5ecc67..b0324ba33 100644 --- a/src/Bundle/ChillPersonBundle/Repository/SocialWork/SocialIssueRepository.php +++ b/src/Bundle/ChillPersonBundle/Repository/SocialWork/SocialIssueRepository.php @@ -1,9 +1,10 @@ repository = $entityManager->getRepository(SocialIssue::class); } - /** - * {@inheritDoc} - */ - public function find($id) + public function find($id, ?int $lockMode = null, ?int $lockVersion = null): ?SocialIssue { - return $this->repository->find($id); + return $this->repository->find($id, $lockMode, $lockVersion); } /** - * {@inheritDoc} + * @return array */ - public function findAll() + public function findAll(): array { return $this->repository->findAll(); } /** - * {@inheritDoc} + * @return array */ - public function findBy(array $criteria, ?array $orderBy = null, $limit = null, $offset = null) + public function findBy(array $criteria, ?array $orderBy = null, $limit = null, $offset = null): array { return $this->repository->findBy($criteria, $orderBy, $limit, $offset); } - /** - * {@inheritDoc} - */ - public function findOneBy(array $criteria) + public function findOneBy(array $criteria, ?array $orderBy = null): ?SocialIssue { - return $this->findOneBy($criteria); + return $this->repository->findOneBy($criteria, $orderBy); } /** - * {@inheritDoc} + * @return class-string */ - public function getClassName() + public function getClassName(): string { return SocialIssue::class; } From 141aabcddccd1a80f731ccae8d125a20ff5a8ef8 Mon Sep 17 00:00:00 2001 From: Pol Dellaiera Date: Tue, 22 Jun 2021 15:40:49 +0200 Subject: [PATCH 06/52] feat: Add new command. --- .../Command/ImportSocialWorkMetadata.php | 63 ++++ .../Service/Import/ChillImporter.php | 10 + .../Service/Import/SocialWorkMetadata.php | 289 ++++++++++++++++++ .../Import/SocialWorkMetadataInterface.php | 9 + .../ChillPersonBundle/config/services.yaml | 7 +- 5 files changed, 377 insertions(+), 1 deletion(-) create mode 100644 src/Bundle/ChillPersonBundle/Command/ImportSocialWorkMetadata.php create mode 100644 src/Bundle/ChillPersonBundle/Service/Import/ChillImporter.php create mode 100644 src/Bundle/ChillPersonBundle/Service/Import/SocialWorkMetadata.php create mode 100644 src/Bundle/ChillPersonBundle/Service/Import/SocialWorkMetadataInterface.php diff --git a/src/Bundle/ChillPersonBundle/Command/ImportSocialWorkMetadata.php b/src/Bundle/ChillPersonBundle/Command/ImportSocialWorkMetadata.php new file mode 100644 index 000000000..e42f0ef26 --- /dev/null +++ b/src/Bundle/ChillPersonBundle/Command/ImportSocialWorkMetadata.php @@ -0,0 +1,63 @@ +importer = $socialWorkMetadata; + } + + protected function configure() + { + $this + ->setName('chill:person:import-socialwork') + ->addOption('filepath', 'f', InputOption::VALUE_REQUIRED, 'The file to import.') + ->addOption('language', 'l', InputOption::VALUE_OPTIONAL, 'The default language'); + } + + protected function execute(InputInterface $input, OutputInterface $output) + { + $filepath = $input->getOption('filepath'); + + try { + $csv = Reader::createFromPath($filepath); + } catch (Throwable $e) { + throw new Exception('Error while loading CSV.',0, $e); + } + + $csv->setDelimiter(';'); + + return true === $this->importer->import($csv) ? + 0: + 1; + } +} diff --git a/src/Bundle/ChillPersonBundle/Service/Import/ChillImporter.php b/src/Bundle/ChillPersonBundle/Service/Import/ChillImporter.php new file mode 100644 index 000000000..4360a7cfa --- /dev/null +++ b/src/Bundle/ChillPersonBundle/Service/Import/ChillImporter.php @@ -0,0 +1,10 @@ +socialIssueRepository = $socialIssueRepository; + $this->socialActionRepository = $socialActionRepository; + $this->goalRepository = $goalRepository; + $this->resultRepository = $resultRepository; + $this->evaluationRepository = $evaluationRepository; + $this->entityManager = $entityManager; + } + + public function import(iterable $dataset): bool + { + foreach ($dataset as $row) { + $this->import1( + array_map( + static fn (string $column): ?string => '' === $column ? null : $column, + array_map('trim', $row) + ) + ); + } + + return true; + } + + private function import1(array $row): void + { + // Structure: + // Index 0: SocialIssue + // Index 1: SocialIssue.children + // Index 2: SocialAction + // Index 3: SocialAction.children + // Index 4: Goal + // Index 5: Result + // Index 6: Evaluation + + $socialIssue = $this->handleSocialIssue($row[0], $row[1]); + + $socialAction = $this->handleSocialAction($row[2], $row[3], $socialIssue); + + $goal = $this->handleGoal($row[4], $socialAction); + + $result = $this->handleResult($row[5], $socialAction, $goal); + + $eval = $this->handleEvaluation($row[6], $socialAction); + + $this->entityManager->flush(); + } + + private function handleSocialIssue(?string $socialIssueTitle = null, ?string $socialIssueChildrenTitle = null): SocialIssue + { + if (null !== $socialIssueChildrenTitle) { + /** @var SocialIssue $socialIssueChildren */ + $socialIssueChildren = $this->getOrCreateEntity($this->socialIssueRepository, 'title', ['fr' => $socialIssueChildrenTitle]); + $socialIssueChildren->setTitle(['fr' => $socialIssueChildrenTitle]); + + $this->entityManager->persist($socialIssueChildren); + } + + /** @var SocialIssue $socialIssue */ + $socialIssue = $this->getOrCreateEntity($this->socialIssueRepository, 'title', ['fr' => $socialIssueTitle]); + $socialIssue->setTitle(['fr' => $socialIssueTitle]); + + if (null !== $socialIssueChildrenTitle) { + $socialIssue->addChild($socialIssueChildren); + } + + $this->entityManager->persist($socialIssue); + + return null === $socialIssueChildrenTitle ? $socialIssue : $socialIssueChildren; + } + + private function handleSocialAction(?string $socialActionTitle, ?string $socialActionChildrenTitle, SocialIssue $socialIssue): SocialAction + { + if (null !== $socialActionChildrenTitle) { + /** @var SocialAction $socialActionChildren */ + $socialActionChildren = $this->getOrCreateEntity($this->socialActionRepository, 'title', ['fr' => $socialActionChildrenTitle]); + $socialActionChildren->setTitle(['fr' => $socialActionChildrenTitle]); + + $this->entityManager->persist($socialActionChildren); + } + + /** @var SocialIssue $socialIssue */ + $socialAction = $this->getOrCreateEntity($this->socialActionRepository, 'title', ['fr' => $socialActionTitle]); + $socialAction->setTitle(['fr' => $socialActionTitle]); + + if (null !== $socialActionChildrenTitle) { + $socialActionChildren->setIssue($socialIssue); + $this->entityManager->persist($socialActionChildren); + + $socialAction->addChild($socialActionChildren); + } else { + $socialAction->setIssue($socialIssue); + } + + $this->entityManager->persist($socialAction); + + return null === $socialActionChildrenTitle ? $socialAction : $socialActionChildren; + } + + private function handleGoal(?string $goalTitle = null, ?SocialAction $socialAction = null): ?Goal + { + if (null === $goalTitle) { + return null; + } + + /** @var Goal $goal */ + $goal = $this->getOrCreateEntity($this->goalRepository, 'title', ['fr' => $goalTitle]); + $goal->setTitle(['fr' => $goalTitle]); + + if (null !== $socialAction) { + $goal->addSocialAction($socialAction); + } + + $this->entityManager->persist($goal); + + return $goal; + } + + private function handleResult(?string $resultTitle = null, SocialAction $socialAction, ?Goal $goal = null): ?Result + { + if (null === $resultTitle) { + return null; + } + + /** @var Result $result */ + $result = $this->getOrCreateEntity($this->resultRepository, 'title', ['fr' => $resultTitle]); + $result->setTitle(['fr' => $resultTitle]); + + if (null !== $goal) { + $result->addGoal($goal); + } + + // Why this cannot be found from the Goal entity? + $result->addSocialAction($socialAction); + + $this->entityManager->persist($result); + + return $result; + } + + private function handleEvaluation(?string $evaluationTitle, SocialAction $socialAction): ?Evaluation + { + if (null === $evaluationTitle) { + return null; + } + + /** @var Evaluation $eval */ + $eval = $this->getOrCreateEntity($this->evaluationRepository, 'title', ['fr' => $evaluationTitle]); + $eval->setTitle(['fr' => $evaluationTitle]); + $eval->setSocialAction($socialAction); + + $this->entityManager->persist($eval); + + return $eval; + } + + private function findByJson(ObjectRepository $repository, string $field, array $jsonCriterias): array + { + $qb = $this + ->entityManager + ->createQueryBuilder() + ->select('s') + ->from($repository->getClassName(), 's'); + + $expr = $qb->expr(); + + $temporaryJsonCriterias = $jsonParameters = []; + + foreach ($jsonCriterias as $key => $value) { + $temporaryJsonCriterias[] = [$field, $key, $value, sprintf(':placeholder_%s_%s', $field, $key)]; + } + + $jsonParameters = array_reduce( + $temporaryJsonCriterias, + static function (array $carry, array $row): array + { + [,, $value, $placeholder] = $row; + + return array_merge( + $carry, + [ + $placeholder => sprintf('"%s"', $value), + ] + ); + }, + [] + ); + + $jsonPredicates = array_map( + static function (array $row) use ($expr): Comparison + { + [$field, $key,, $placeholder] = $row; + + $left = sprintf( + "GET_JSON_FIELD_BY_KEY(s.%s, '%s')", + $field, + $key + ); + + return $expr + ->eq( + $left, + $placeholder + ); + }, + $temporaryJsonCriterias + ); + + $query = $qb + ->select('s') + ->where(...$jsonPredicates) + ->setParameters($jsonParameters) + ->getQuery(); + + return $query->getResult(); + } + + private function getOrCreateEntity(ObjectRepository $repository, string $field, array $jsonCriterias = []) + { + $results = $this + ->findByJson( + $repository, + $field, + $jsonCriterias + ); + + switch (true) { + case count($results) === 0: + $entity = $repository->getClassName(); + $entity = new $entity(); + break; + case count($results) === 1; + $entity = current($results); + break; + case count($results) > 1; + throw new Exception( + sprintf( + 'More than one entity(%s) found.', + $repository->getClassName() + ) + ); + } + + return $entity; + } + + +} diff --git a/src/Bundle/ChillPersonBundle/Service/Import/SocialWorkMetadataInterface.php b/src/Bundle/ChillPersonBundle/Service/Import/SocialWorkMetadataInterface.php new file mode 100644 index 000000000..015ef7485 --- /dev/null +++ b/src/Bundle/ChillPersonBundle/Service/Import/SocialWorkMetadataInterface.php @@ -0,0 +1,9 @@ + Date: Thu, 24 Jun 2021 15:24:14 +0200 Subject: [PATCH 07/52] (to rebase/fixup later) Fields must be nullable for import to success. --- .../Entity/SocialWork/Evaluation.php | 2 +- .../migrations/Version20210624131722.php | 29 +++++++++++++++++++ .../migrations/Version20210624131723.php | 29 +++++++++++++++++++ 3 files changed, 59 insertions(+), 1 deletion(-) create mode 100644 src/Bundle/ChillPersonBundle/migrations/Version20210624131722.php create mode 100644 src/Bundle/ChillPersonBundle/migrations/Version20210624131723.php diff --git a/src/Bundle/ChillPersonBundle/Entity/SocialWork/Evaluation.php b/src/Bundle/ChillPersonBundle/Entity/SocialWork/Evaluation.php index 5a877e264..e08a6de77 100644 --- a/src/Bundle/ChillPersonBundle/Entity/SocialWork/Evaluation.php +++ b/src/Bundle/ChillPersonBundle/Entity/SocialWork/Evaluation.php @@ -23,7 +23,7 @@ class Evaluation private $title = []; /** - * @ORM\Column(type="dateinterval") + * @ORM\Column(type="dateinterval", nullable=true) */ private $delay; diff --git a/src/Bundle/ChillPersonBundle/migrations/Version20210624131722.php b/src/Bundle/ChillPersonBundle/migrations/Version20210624131722.php new file mode 100644 index 000000000..ebeb33e50 --- /dev/null +++ b/src/Bundle/ChillPersonBundle/migrations/Version20210624131722.php @@ -0,0 +1,29 @@ +addSql('ALTER TABLE chill_person_social_work_evaluation ALTER delay DROP NOT NULL'); + } + + public function down(Schema $schema): void + { + $this->addSql('ALTER TABLE chill_person_social_work_evaluation ALTER delay SET NOT NULL'); + } +} diff --git a/src/Bundle/ChillPersonBundle/migrations/Version20210624131723.php b/src/Bundle/ChillPersonBundle/migrations/Version20210624131723.php new file mode 100644 index 000000000..d36d23733 --- /dev/null +++ b/src/Bundle/ChillPersonBundle/migrations/Version20210624131723.php @@ -0,0 +1,29 @@ +addSql('ALTER TABLE chill_person_social_work_evaluation ALTER notificationdelay DROP NOT NULL'); + } + + public function down(Schema $schema): void + { + $this->addSql('ALTER TABLE chill_person_social_work_evaluation ALTER notificationdelay SET NOT NULL'); + } +} From 18d0ad67d6fb41d05bb8d07bc504e721bc3b83d1 Mon Sep 17 00:00:00 2001 From: Pol Dellaiera Date: Thu, 24 Jun 2021 15:24:29 +0200 Subject: [PATCH 08/52] (to rebase/fixup later) Update command based on feedback. --- .../ChillPersonBundle/Service/Import/SocialWorkMetadata.php | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/Bundle/ChillPersonBundle/Service/Import/SocialWorkMetadata.php b/src/Bundle/ChillPersonBundle/Service/Import/SocialWorkMetadata.php index 0fff36d0f..b5ade864c 100644 --- a/src/Bundle/ChillPersonBundle/Service/Import/SocialWorkMetadata.php +++ b/src/Bundle/ChillPersonBundle/Service/Import/SocialWorkMetadata.php @@ -149,7 +149,10 @@ final class SocialWorkMetadata implements SocialWorkMetadataInterface $goal->setTitle(['fr' => $goalTitle]); if (null !== $socialAction) { + $socialAction->addGoal($goal); $goal->addSocialAction($socialAction); + + $this->entityManager->persist($socialAction); } $this->entityManager->persist($goal); From 3b5ef53b9b2e176dc08e9eea65315a5d1256063e Mon Sep 17 00:00:00 2001 From: Pol Dellaiera Date: Thu, 24 Jun 2021 15:46:04 +0200 Subject: [PATCH 09/52] (to rebase/fixup later) Let Result be associated to a SocialAction. --- .../Service/Import/SocialWorkMetadata.php | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/Bundle/ChillPersonBundle/Service/Import/SocialWorkMetadata.php b/src/Bundle/ChillPersonBundle/Service/Import/SocialWorkMetadata.php index b5ade864c..48dff99bc 100644 --- a/src/Bundle/ChillPersonBundle/Service/Import/SocialWorkMetadata.php +++ b/src/Bundle/ChillPersonBundle/Service/Import/SocialWorkMetadata.php @@ -160,7 +160,7 @@ final class SocialWorkMetadata implements SocialWorkMetadataInterface return $goal; } - private function handleResult(?string $resultTitle = null, SocialAction $socialAction, ?Goal $goal = null): ?Result + private function handleResult(?string $resultTitle = null, ?SocialAction $socialAction = null, ?Goal $goal = null): ?Result { if (null === $resultTitle) { return null; @@ -172,12 +172,15 @@ final class SocialWorkMetadata implements SocialWorkMetadataInterface if (null !== $goal) { $result->addGoal($goal); + } else { + $result->addSocialAction($socialAction); } - // Why this cannot be found from the Goal entity? $result->addSocialAction($socialAction); + $socialAction->addResult($result); $this->entityManager->persist($result); + $this->entityManager->persist($socialAction); return $result; } From 4a2ada784a97d7a867d83070e00be6c8934adc17 Mon Sep 17 00:00:00 2001 From: Pol Dellaiera Date: Thu, 24 Jun 2021 15:57:03 +0200 Subject: [PATCH 10/52] (to rebase/fixup later) Let Goal be associated to a Result. --- .../ChillPersonBundle/Service/Import/SocialWorkMetadata.php | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/Bundle/ChillPersonBundle/Service/Import/SocialWorkMetadata.php b/src/Bundle/ChillPersonBundle/Service/Import/SocialWorkMetadata.php index 48dff99bc..0896021f1 100644 --- a/src/Bundle/ChillPersonBundle/Service/Import/SocialWorkMetadata.php +++ b/src/Bundle/ChillPersonBundle/Service/Import/SocialWorkMetadata.php @@ -172,6 +172,9 @@ final class SocialWorkMetadata implements SocialWorkMetadataInterface if (null !== $goal) { $result->addGoal($goal); + $goal->addResult($result); + + $this->entityManager->persist($goal); } else { $result->addSocialAction($socialAction); } From d71c3f310e8b93fd1afabd55052d30927c53c984 Mon Sep 17 00:00:00 2001 From: Pol Dellaiera Date: Thu, 24 Jun 2021 16:01:41 +0200 Subject: [PATCH 11/52] (to rebase/fixup later) Fix documentation. --- .../Service/Import/SocialWorkMetadata.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/Bundle/ChillPersonBundle/Service/Import/SocialWorkMetadata.php b/src/Bundle/ChillPersonBundle/Service/Import/SocialWorkMetadata.php index 0896021f1..4683344dd 100644 --- a/src/Bundle/ChillPersonBundle/Service/Import/SocialWorkMetadata.php +++ b/src/Bundle/ChillPersonBundle/Service/Import/SocialWorkMetadata.php @@ -66,10 +66,10 @@ final class SocialWorkMetadata implements SocialWorkMetadataInterface private function import1(array $row): void { // Structure: - // Index 0: SocialIssue - // Index 1: SocialIssue.children - // Index 2: SocialAction - // Index 3: SocialAction.children + // Index 0: SocialIssue.parent + // Index 1: SocialIssue + // Index 2: SocialAction.parent + // Index 3: SocialAction // Index 4: Goal // Index 5: Result // Index 6: Evaluation From 2699d485331a4ec938ca83785b4bb9429cd3a216 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julien=20Fastr=C3=A9?= Date: Thu, 22 Jul 2021 15:20:45 +0000 Subject: [PATCH 12/52] Fix tests after introduction of bootstrap --- .../Resources/views/layout.html.twig | 2 +- .../views/layoutWithVerticalMenu.html.twig | 2 +- .../translations/messages+intl-icu.fr.yaml | 6 +++++ .../ChillPersonBundle/Entity/Person.php | 8 +++++-- .../Resources/views/Person/banner.html.twig | 6 ++--- .../AccompanyingPeriodControllerTest.php | 24 +++++++++---------- .../Controller/PersonControllerUpdateTest.php | 5 ++-- 7 files changed, 31 insertions(+), 22 deletions(-) create mode 100644 src/Bundle/ChillMainBundle/translations/messages+intl-icu.fr.yaml diff --git a/src/Bundle/ChillMainBundle/Resources/views/layout.html.twig b/src/Bundle/ChillMainBundle/Resources/views/layout.html.twig index b06d7db90..75b6831de 100644 --- a/src/Bundle/ChillMainBundle/Resources/views/layout.html.twig +++ b/src/Bundle/ChillMainBundle/Resources/views/layout.html.twig @@ -50,7 +50,7 @@
{# Flash messages ! #} - {% if app.session.flashbag.all()|length > 0 %} + {% if app.session.flashbag.keys()|length > 0 %}
{% for flashMessage in app.session.flashbag.get('success') %} diff --git a/src/Bundle/ChillMainBundle/Resources/views/layoutWithVerticalMenu.html.twig b/src/Bundle/ChillMainBundle/Resources/views/layoutWithVerticalMenu.html.twig index 21a56b027..cfbc16f4f 100644 --- a/src/Bundle/ChillMainBundle/Resources/views/layoutWithVerticalMenu.html.twig +++ b/src/Bundle/ChillMainBundle/Resources/views/layoutWithVerticalMenu.html.twig @@ -29,7 +29,7 @@
{# Flash messages ! #} - {% if app.session.flashbag.all()|length > 0 %} + {% if app.session.flashbag.keys()|length > 0 %}
{% for flashMessage in app.session.flashbag.get('success') %} diff --git a/src/Bundle/ChillMainBundle/translations/messages+intl-icu.fr.yaml b/src/Bundle/ChillMainBundle/translations/messages+intl-icu.fr.yaml new file mode 100644 index 000000000..d5dedbb9f --- /dev/null +++ b/src/Bundle/ChillMainBundle/translations/messages+intl-icu.fr.yaml @@ -0,0 +1,6 @@ +years_old: >- + {age, plural, + one {# an} + many {# ans} + other {# ans} + } diff --git a/src/Bundle/ChillPersonBundle/Entity/Person.php b/src/Bundle/ChillPersonBundle/Entity/Person.php index c4b36a348..7f9805f52 100644 --- a/src/Bundle/ChillPersonBundle/Entity/Person.php +++ b/src/Bundle/ChillPersonBundle/Entity/Person.php @@ -734,9 +734,13 @@ class Person implements HasCenterInterface, TrackCreationInterface, TrackUpdateI return $this->birthdate; } - public function getAge(): int + public function getAge(): ?int { - return date_diff($this->birthdate, date_create('now'))->format("%y"); + if ($this->birthdate instanceof \DateTimeInterface) { + return date_diff($this->birthdate, date_create('now'))->format("%y"); + } + + return null; } /** diff --git a/src/Bundle/ChillPersonBundle/Resources/views/Person/banner.html.twig b/src/Bundle/ChillPersonBundle/Resources/views/Person/banner.html.twig index dd136014e..6fb12847d 100644 --- a/src/Bundle/ChillPersonBundle/Resources/views/Person/banner.html.twig +++ b/src/Bundle/ChillPersonBundle/Resources/views/Person/banner.html.twig @@ -76,10 +76,10 @@ {{ 'Unknown date of birth'|trans }} {% else %} {{ person.birthdate|format_date('short') }} + + {{ 'years_old'|trans({ 'age': person.age }) }} + {% endif %} - - {{ person.age ~ ((person.age > 1) ? ' ans' : ' an') }} -
{%- if chill_person.fields.nationality == 'visible' -%} diff --git a/src/Bundle/ChillPersonBundle/Tests/Controller/AccompanyingPeriodControllerTest.php b/src/Bundle/ChillPersonBundle/Tests/Controller/AccompanyingPeriodControllerTest.php index 425b00b6c..e841f2615 100644 --- a/src/Bundle/ChillPersonBundle/Tests/Controller/AccompanyingPeriodControllerTest.php +++ b/src/Bundle/ChillPersonBundle/Tests/Controller/AccompanyingPeriodControllerTest.php @@ -152,7 +152,7 @@ class AccompanyingPeriodControllerTest extends WebTestCase * with : dateClosing: 2015-02-01 * with : the last closing motive in list * Then the response should redirect to period view - * And the next page should have a `.error` element present in page + * And the next page should have a `.alert-danger` element present in page * * @todo */ @@ -174,7 +174,7 @@ class AccompanyingPeriodControllerTest extends WebTestCase '/fr/person/'.$this->person->getId().'/accompanying-period'), 'the server redirects to /accompanying-period page'); $this->assertGreaterThan(0, $this->client->followRedirect() - ->filter('.success')->count(), + ->filter('.alert-success')->count(), "a 'success' element is shown"); } @@ -186,7 +186,7 @@ class AccompanyingPeriodControllerTest extends WebTestCase * with : dateClosing: 2014-01-01 * with : the last closing motive in list * Then the response should redirect to period view - * And the next page should have a `.error` element present in page + * And the next page should have a `.alert-danger` element present in page * * @todo */ @@ -207,8 +207,8 @@ class AccompanyingPeriodControllerTest extends WebTestCase $this->assertFalse($this->client->getResponse()->isRedirect(), 'the server stays on the /close page'); $this->assertGreaterThan(0, $crawlerResponse - ->filter('.error')->count(), - "an '.error' element is shown"); + ->filter('.alert-danger')->count(), + "an '.alert-danger' element is shown"); } /** @@ -240,7 +240,7 @@ class AccompanyingPeriodControllerTest extends WebTestCase '/fr/person/'.$this->person->getId().'/accompanying-period'), 'the server redirects to /accompanying-period page'); $this->assertGreaterThan(0, $this->client->followRedirect() - ->filter('.success')->count(), + ->filter('.alert-success')->count(), "a 'success' element is shown"); } @@ -275,7 +275,7 @@ class AccompanyingPeriodControllerTest extends WebTestCase $this->assertFalse($this->client->getResponse()->isRedirect(), 'the server stay on form page'); - $this->assertGreaterThan(0, $crawler->filter('.error')->count(), + $this->assertGreaterThan(0, $crawler->filter('.alert-danger')->count(), "an 'error' element is shown"); } @@ -310,7 +310,7 @@ class AccompanyingPeriodControllerTest extends WebTestCase $this->assertFalse($this->client->getResponse()->isRedirect(), 'the server stay on form page'); - $this->assertGreaterThan(0, $crawler->filter('.error')->count(), + $this->assertGreaterThan(0, $crawler->filter('.alert-danger')->count(), "an 'error' element is shown"); } @@ -351,7 +351,7 @@ class AccompanyingPeriodControllerTest extends WebTestCase $this->assertFalse($this->client->getResponse()->isRedirect(), 'the server stay on form page'); - $this->assertGreaterThan(0, $crawlerResponse->filter('.error')->count(), + $this->assertGreaterThan(0, $crawlerResponse->filter('.alert-danger')->count(), "an 'error' element is shown"); } @@ -382,7 +382,7 @@ class AccompanyingPeriodControllerTest extends WebTestCase $this->assertFalse($this->client->getResponse()->isRedirect(), 'the server stay on form page'); - $this->assertGreaterThan(0, $crawler->filter('.error')->count(), + $this->assertGreaterThan(0, $crawler->filter('.alert-danger')->count(), "an 'error' element is shown"); } @@ -424,7 +424,7 @@ class AccompanyingPeriodControllerTest extends WebTestCase $this->assertFalse($this->client->getResponse()->isRedirect(), 'the server stay on form page'); - $this->assertGreaterThan(0, $crawlerResponse->filter('.error')->count(), + $this->assertGreaterThan(0, $crawlerResponse->filter('.alert-danger')->count(), "an 'error' element is shown"); } @@ -465,7 +465,7 @@ class AccompanyingPeriodControllerTest extends WebTestCase $this->assertFalse($this->client->getResponse()->isRedirect(), 'the server stay on form page'); - $this->assertGreaterThan(0, $crawlerResponse->filter('.error')->count(), + $this->assertGreaterThan(0, $crawlerResponse->filter('.alert-danger')->count(), "an 'error' element is shown"); } diff --git a/src/Bundle/ChillPersonBundle/Tests/Controller/PersonControllerUpdateTest.php b/src/Bundle/ChillPersonBundle/Tests/Controller/PersonControllerUpdateTest.php index ffdd65f35..8a8c04538 100644 --- a/src/Bundle/ChillPersonBundle/Tests/Controller/PersonControllerUpdateTest.php +++ b/src/Bundle/ChillPersonBundle/Tests/Controller/PersonControllerUpdateTest.php @@ -102,7 +102,6 @@ class PersonControllerUpdateTest extends WebTestCase public function testHiddenFielsArePresent() { $crawler = $this->client->request('GET', $this->editUrl); - $configurables = array('placeOfBirth', 'phonenumber', 'email', 'countryOfBirth', 'nationality', 'spokenLanguages', 'maritalStatus'); $form = $crawler->selectButton('Enregistrer')->form(); //; @@ -190,7 +189,7 @@ class PersonControllerUpdateTest extends WebTestCase 'the value '.$field.' is updated in db'); $crawler = $this->client->followRedirect(); - $this->assertGreaterThan(0, $crawler->filter('.success')->count(), + $this->assertGreaterThan(0, $crawler->filter('.alert-success')->count(), 'a element .success is shown'); if($field == 'birthdate' or $field == 'memo' or $field == 'countryOfBirth' or $field == 'nationality' @@ -245,7 +244,7 @@ class PersonControllerUpdateTest extends WebTestCase $this->assertFalse($this->client->getResponse()->isRedirect(), 'the page is not redirected to /general'); - $this->assertGreaterThan(0, $crawler->filter('.error')->count(), + $this->assertGreaterThan(0, $crawler->filter('.alert-danger')->count(), 'a element .error is shown'); } From 18ab10dd45cd0250f83377133fff8b4d4841669c Mon Sep 17 00:00:00 2001 From: Marc Ducobu Date: Fri, 18 Jun 2021 17:18:07 +0200 Subject: [PATCH 13/52] Add center a_social to an activityNotif feature --- .../DataFixtures/ORM/LoadActivityNotifications.php | 1 + 1 file changed, 1 insertion(+) diff --git a/src/Bundle/ChillActivityBundle/DataFixtures/ORM/LoadActivityNotifications.php b/src/Bundle/ChillActivityBundle/DataFixtures/ORM/LoadActivityNotifications.php index 7835a0db4..9ef67a7ac 100644 --- a/src/Bundle/ChillActivityBundle/DataFixtures/ORM/LoadActivityNotifications.php +++ b/src/Bundle/ChillActivityBundle/DataFixtures/ORM/LoadActivityNotifications.php @@ -22,6 +22,7 @@ class LoadActivityNotifications extends AbstractFixture implements DependentFixt 'entityRef' => 'activity_gerard depardieu', 'sender' => 'center a_social', 'addressees' => [ + 'center a_social', 'center a_administrative', 'center a_direction', 'multi_center' From bdf691a063c43f8acdcc16d2469be9404b8bf648 Mon Sep 17 00:00:00 2001 From: Marc Ducobu Date: Fri, 18 Jun 2021 17:19:39 +0200 Subject: [PATCH 14/52] Add findAllForAttendee method in NotificationRepository --- .../Repository/NotificationRepository.php | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/src/Bundle/ChillMainBundle/Repository/NotificationRepository.php b/src/Bundle/ChillMainBundle/Repository/NotificationRepository.php index 844459f8b..d52817164 100644 --- a/src/Bundle/ChillMainBundle/Repository/NotificationRepository.php +++ b/src/Bundle/ChillMainBundle/Repository/NotificationRepository.php @@ -23,6 +23,7 @@ use Chill\MainBundle\Entity\Notification; use Doctrine\ORM\EntityManagerInterface; use Doctrine\ORM\EntityRepository; use Doctrine\Persistence\ObjectRepository; +use Chill\MainBundle\Entity\User; final class NotificationRepository implements ObjectRepository { @@ -59,8 +60,24 @@ final class NotificationRepository implements ObjectRepository return $this->repository->findBy($criteria, $orderBy, $limit, $offset); } + /** + * @return Notification[] + */ + public function findAllForAttendee(User $addressee) // TODO passer à attendees avec S + { + $qb = $this->repository->createQueryBuilder('n'); + + $qb + ->select('n') + ->join('n.addressees', 'a') + ->where('a = :addressee') + ->setParameter('addressee', $addressee); + + $query = $qb->getQuery(); + return $qb->getQuery()->getResult(); + } + public function getClassName() { return Notification::class; } - } From 282db51f06b6136c227fb7297f38c89c2880a6a6 Mon Sep 17 00:00:00 2001 From: Marc Ducobu Date: Fri, 18 Jun 2021 18:05:02 +0200 Subject: [PATCH 15/52] Display notification using services (draft) --- .../ChillActivityExtension.php | 1 + .../ActivityNotificationRenderer.php | 24 ++++++++++ .../Activity/showInNotification.html.twig | 4 ++ .../config/services/notification.yaml | 3 ++ .../Controller/NotificationController.php | 42 ++++++++++++++++++ .../Notification/NotificationRenderer.php | 44 +++++++++++++++++++ .../views/Notification/show.html.twig | 42 ++++++++++++++++++ src/Bundle/ChillMainBundle/config/routes.yaml | 4 ++ .../config/routes/notification.yaml | 3 ++ .../config/services/controller.yaml | 5 +++ .../config/services/notification.yaml | 6 ++- .../ChillPersonExtension.php | 1 + ...AccompanyingPeriodNotificationRenderer.php | 24 ++++++++++ .../showInNotification.html.twig | 3 ++ .../config/services/notification.yaml | 3 ++ 15 files changed, 208 insertions(+), 1 deletion(-) create mode 100644 src/Bundle/ChillActivityBundle/Notification/ActivityNotificationRenderer.php create mode 100644 src/Bundle/ChillActivityBundle/Resources/views/Activity/showInNotification.html.twig create mode 100644 src/Bundle/ChillActivityBundle/config/services/notification.yaml create mode 100644 src/Bundle/ChillMainBundle/Controller/NotificationController.php create mode 100644 src/Bundle/ChillMainBundle/Notification/NotificationRenderer.php create mode 100644 src/Bundle/ChillMainBundle/Resources/views/Notification/show.html.twig create mode 100644 src/Bundle/ChillMainBundle/config/routes/notification.yaml create mode 100644 src/Bundle/ChillPersonBundle/Notification/AccompanyingPeriodNotificationRenderer.php create mode 100644 src/Bundle/ChillPersonBundle/Resources/views/AccompanyingPeriod/showInNotification.html.twig create mode 100644 src/Bundle/ChillPersonBundle/config/services/notification.yaml diff --git a/src/Bundle/ChillActivityBundle/DependencyInjection/ChillActivityExtension.php b/src/Bundle/ChillActivityBundle/DependencyInjection/ChillActivityExtension.php index 61354c7c8..e240bf17c 100644 --- a/src/Bundle/ChillActivityBundle/DependencyInjection/ChillActivityExtension.php +++ b/src/Bundle/ChillActivityBundle/DependencyInjection/ChillActivityExtension.php @@ -55,6 +55,7 @@ class ChillActivityExtension extends Extension implements PrependExtensionInterf $loader->load('services/controller.yaml'); $loader->load('services/form.yaml'); $loader->load('services/templating.yaml'); + $loader->load('services/notification.yaml'); } public function prepend(ContainerBuilder $container) diff --git a/src/Bundle/ChillActivityBundle/Notification/ActivityNotificationRenderer.php b/src/Bundle/ChillActivityBundle/Notification/ActivityNotificationRenderer.php new file mode 100644 index 000000000..f1134d421 --- /dev/null +++ b/src/Bundle/ChillActivityBundle/Notification/ActivityNotificationRenderer.php @@ -0,0 +1,24 @@ +getRelatedEntityClass() == Activity::class; + } + + public function getTemplate() + { + return 'ChillActivityBundle:Activity:showInNotification.html.twig'; + } + + public function getTemplateData(Notification $notification) + { + return ['notification' => $notification]; + } +} diff --git a/src/Bundle/ChillActivityBundle/Resources/views/Activity/showInNotification.html.twig b/src/Bundle/ChillActivityBundle/Resources/views/Activity/showInNotification.html.twig new file mode 100644 index 000000000..5128e9a64 --- /dev/null +++ b/src/Bundle/ChillActivityBundle/Resources/views/Activity/showInNotification.html.twig @@ -0,0 +1,4 @@ + +{{ dump(notification) }} + +Go to Activity diff --git a/src/Bundle/ChillActivityBundle/config/services/notification.yaml b/src/Bundle/ChillActivityBundle/config/services/notification.yaml new file mode 100644 index 000000000..e3667550c --- /dev/null +++ b/src/Bundle/ChillActivityBundle/config/services/notification.yaml @@ -0,0 +1,3 @@ +services: + Chill\ActivityBundle\Notification\ActivityNotificationRenderer: + autowire: true diff --git a/src/Bundle/ChillMainBundle/Controller/NotificationController.php b/src/Bundle/ChillMainBundle/Controller/NotificationController.php new file mode 100644 index 000000000..83b77d7b6 --- /dev/null +++ b/src/Bundle/ChillMainBundle/Controller/NotificationController.php @@ -0,0 +1,42 @@ +security = $security; + } + + public function showAction(NotificationRepository $notificationRepository, NotificationRenderer $notificationRenderer) + { + $currentUser = $this->security->getUser(); + + $notifications = $notificationRepository->findAllForAttendee($currentUser); + + $templateData = array(); + foreach ($notifications as $notification) { + $data = [ + 'template' => $notificationRenderer->getTemplate($notification), + 'template_data' => $notificationRenderer->getTemplateData($notification), + 'notification' => $notification + ]; + $templateData[] = $data; + } + + return $this->render('ChillMainBundle:Notification:show.html.twig', [ + 'datas' => $templateData, + 'notifications' => $notifications, + ]); + } +} diff --git a/src/Bundle/ChillMainBundle/Notification/NotificationRenderer.php b/src/Bundle/ChillMainBundle/Notification/NotificationRenderer.php new file mode 100644 index 000000000..d6f383b73 --- /dev/null +++ b/src/Bundle/ChillMainBundle/Notification/NotificationRenderer.php @@ -0,0 +1,44 @@ +renderers[] = $accompanyingPeriodNotificationRenderer; + $this->renderers[] = $activityNotificationRenderer; + } + + private function getRenderer(Notification $notification) + { + foreach ($this->renderers as $renderer) { + if($renderer->supports($notification)) { + return $renderer; + } + } + + throw new \Exception('No renderer for '. $notification); + } + + public function getTemplate(Notification $notification) + { + return $this->getRenderer($notification)->getTemplate(); + } + + public function getTemplateData(Notification $notification) + { + return $this->getRenderer($notification)->getTemplateData($notification); + } +} diff --git a/src/Bundle/ChillMainBundle/Resources/views/Notification/show.html.twig b/src/Bundle/ChillMainBundle/Resources/views/Notification/show.html.twig new file mode 100644 index 000000000..34aeee049 --- /dev/null +++ b/src/Bundle/ChillMainBundle/Resources/views/Notification/show.html.twig @@ -0,0 +1,42 @@ +{% extends "@ChillMain/layout.html.twig" %} + +{% block content %} +
+
+

{{ "Notifications list" | trans }}

+ + + {%for data in datas %} + {% set notification = data.notification %} + +
+
{{ 'Message'|trans }}
+
{{ notification.message }}
+
+ +
+
{{ 'Date'|trans }}
+
{{ notification.date | date('long') }}
+
+ + +
+
{{ 'Sender'|trans }}
+
{{ notification.sender }}
+
+ +
+
{{ 'Addressees'|trans }}
+
{{ notification.addressees |join(', ') }}
+
+ +
+
{{ 'Entity'|trans }}
+
+ {% include data.template with data.template_data %} +
+
+ {% endfor %} +
+
+{% endblock content %} diff --git a/src/Bundle/ChillMainBundle/config/routes.yaml b/src/Bundle/ChillMainBundle/config/routes.yaml index 240a44590..697ec8ec0 100644 --- a/src/Bundle/ChillMainBundle/config/routes.yaml +++ b/src/Bundle/ChillMainBundle/config/routes.yaml @@ -34,6 +34,10 @@ chill_password_recover: resource: "@ChillMainBundle/config/routes/password_recover.yaml" prefix: "public/{_locale}/password" +chill_main_notification: + resource: "@ChillMainBundle/config/routes/notification.yaml" + prefix: "{_locale}/notification" + chill_crud: resource: "@ChillMainBundle" type: CRUD diff --git a/src/Bundle/ChillMainBundle/config/routes/notification.yaml b/src/Bundle/ChillMainBundle/config/routes/notification.yaml new file mode 100644 index 000000000..2112f882f --- /dev/null +++ b/src/Bundle/ChillMainBundle/config/routes/notification.yaml @@ -0,0 +1,3 @@ +chill_main_notification_show: + path: /show + controller: Chill\MainBundle\Controller\NotificationController::showAction diff --git a/src/Bundle/ChillMainBundle/config/services/controller.yaml b/src/Bundle/ChillMainBundle/config/services/controller.yaml index 6021e3d72..11a9bc274 100644 --- a/src/Bundle/ChillMainBundle/config/services/controller.yaml +++ b/src/Bundle/ChillMainBundle/config/services/controller.yaml @@ -33,3 +33,8 @@ services: $logger: '@Psr\Log\LoggerInterface' $validator: '@Symfony\Component\Validator\Validator\ValidatorInterface' tags: ['controller.service_arguments'] + + Chill\MainBundle\Controller\NotificationController: + arguments: + $security: '@Symfony\Component\Security\Core\Security' + tags: ['controller.service_arguments'] diff --git a/src/Bundle/ChillMainBundle/config/services/notification.yaml b/src/Bundle/ChillMainBundle/config/services/notification.yaml index fa4fa15c6..c8d970c5d 100644 --- a/src/Bundle/ChillMainBundle/config/services/notification.yaml +++ b/src/Bundle/ChillMainBundle/config/services/notification.yaml @@ -4,7 +4,11 @@ services: $logger: '@Psr\Log\LoggerInterface' $twig: '@Twig\Environment' $mailer: '@swiftmailer.mailer.default' - # $mailerTransporter: '@swiftmailer.transport' + # $mailerTransporter: '@swiftmailer.transport' $router: '@Symfony\Component\Routing\RouterInterface' $translator: '@Symfony\Component\Translation\TranslatorInterface' $routeParameters: '%chill_main.notifications%' + + Chill\MainBundle\Notification\NotificationRenderer: + autoconfigure: true + autowire: true diff --git a/src/Bundle/ChillPersonBundle/DependencyInjection/ChillPersonExtension.php b/src/Bundle/ChillPersonBundle/DependencyInjection/ChillPersonExtension.php index 03b05bbc8..1b22018a2 100644 --- a/src/Bundle/ChillPersonBundle/DependencyInjection/ChillPersonExtension.php +++ b/src/Bundle/ChillPersonBundle/DependencyInjection/ChillPersonExtension.php @@ -74,6 +74,7 @@ class ChillPersonExtension extends Extension implements PrependExtensionInterfac $loader->load('services/form.yaml'); $loader->load('services/alt_names.yaml'); $loader->load('services/household.yaml'); + $loader->load('services/notification.yaml'); // We can get rid of this file when the service 'chill.person.repository.person' is no more used. // We should use the PersonRepository service instead of a custom service name. $loader->load('services/repository.yaml'); diff --git a/src/Bundle/ChillPersonBundle/Notification/AccompanyingPeriodNotificationRenderer.php b/src/Bundle/ChillPersonBundle/Notification/AccompanyingPeriodNotificationRenderer.php new file mode 100644 index 000000000..ca76fbd5c --- /dev/null +++ b/src/Bundle/ChillPersonBundle/Notification/AccompanyingPeriodNotificationRenderer.php @@ -0,0 +1,24 @@ +getRelatedEntityClass() == AccompanyingPeriod::class; + } + + public function getTemplate() + { + return 'ChillPersonBundle:AccompanyingPeriod:showInNotification.html.twig'; + } + + public function getTemplateData(Notification $notification) + { + return ['notification' => $notification]; + } +} diff --git a/src/Bundle/ChillPersonBundle/Resources/views/AccompanyingPeriod/showInNotification.html.twig b/src/Bundle/ChillPersonBundle/Resources/views/AccompanyingPeriod/showInNotification.html.twig new file mode 100644 index 000000000..d92de8cba --- /dev/null +++ b/src/Bundle/ChillPersonBundle/Resources/views/AccompanyingPeriod/showInNotification.html.twig @@ -0,0 +1,3 @@ + + Go to Acc. period. + diff --git a/src/Bundle/ChillPersonBundle/config/services/notification.yaml b/src/Bundle/ChillPersonBundle/config/services/notification.yaml new file mode 100644 index 000000000..58187defb --- /dev/null +++ b/src/Bundle/ChillPersonBundle/config/services/notification.yaml @@ -0,0 +1,3 @@ +services: + Chill\PersonBundle\Notification\AccompanyingPeriodNotificationRenderer: + autowire: true From 673a4761e9e873e2af57c21452f20cae8f86220a Mon Sep 17 00:00:00 2001 From: Marc Ducobu Date: Fri, 18 Jun 2021 18:05:27 +0200 Subject: [PATCH 16/52] Adding feature for AccompanyingPeriodNotif --- .../LoadAccompanyingPeriodNotifications.php | 39 +++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 src/Bundle/ChillPersonBundle/DataFixtures/ORM/LoadAccompanyingPeriodNotifications.php diff --git a/src/Bundle/ChillPersonBundle/DataFixtures/ORM/LoadAccompanyingPeriodNotifications.php b/src/Bundle/ChillPersonBundle/DataFixtures/ORM/LoadAccompanyingPeriodNotifications.php new file mode 100644 index 000000000..d1c6f4da7 --- /dev/null +++ b/src/Bundle/ChillPersonBundle/DataFixtures/ORM/LoadAccompanyingPeriodNotifications.php @@ -0,0 +1,39 @@ + 'Hello !', + 'entityClass' => AccompanyingPeriod::class, + 'entityRef' => LoadAccompanyingPeriod::ACCOMPANYING_PERIOD, + 'sender' => 'center a_social', + 'addressees' => [ + 'center a_social', + 'center a_administrative', + 'center a_direction', + 'multi_center' + ], + ] + ]; + + public function getDependencies() + { + return [ + LoadAccompanyingPeriod::class, + ]; + } +} From 0907ae16020dfd1a97bdd493cfded327fcec832d Mon Sep 17 00:00:00 2001 From: Marc Ducobu Date: Wed, 30 Jun 2021 11:33:19 +0200 Subject: [PATCH 17/52] Rmq Julien & Pol --- .../Notification/ActivityNotificationRenderer.php | 4 ++-- .../ChillActivityBundle/config/services/notification.yaml | 1 + 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/src/Bundle/ChillActivityBundle/Notification/ActivityNotificationRenderer.php b/src/Bundle/ChillActivityBundle/Notification/ActivityNotificationRenderer.php index f1134d421..1836f599b 100644 --- a/src/Bundle/ChillActivityBundle/Notification/ActivityNotificationRenderer.php +++ b/src/Bundle/ChillActivityBundle/Notification/ActivityNotificationRenderer.php @@ -7,14 +7,14 @@ use Chill\ActivityBundle\Entity\Activity; final class ActivityNotificationRenderer { - public function supports(Notification $notification) + public function supports(Notification $notification, array $options = []): bool { return $notification->getRelatedEntityClass() == Activity::class; } public function getTemplate() { - return 'ChillActivityBundle:Activity:showInNotification.html.twig'; + return '@ChillActivity/Activity/showInNotification.html.twig'; } public function getTemplateData(Notification $notification) diff --git a/src/Bundle/ChillActivityBundle/config/services/notification.yaml b/src/Bundle/ChillActivityBundle/config/services/notification.yaml index e3667550c..3db168ecd 100644 --- a/src/Bundle/ChillActivityBundle/config/services/notification.yaml +++ b/src/Bundle/ChillActivityBundle/config/services/notification.yaml @@ -1,3 +1,4 @@ services: Chill\ActivityBundle\Notification\ActivityNotificationRenderer: + autoconfigure: true autowire: true From 50a4df3d0f7a1e7aa8d89bf4f763b057c62ea73d Mon Sep 17 00:00:00 2001 From: Marc Ducobu Date: Wed, 30 Jun 2021 12:02:18 +0200 Subject: [PATCH 18/52] Notification with paginitation --- .../Controller/NotificationController.php | 29 +++++++++--- .../Repository/NotificationRepository.php | 45 ++++++++++++++++--- .../config/routes/notification.yaml | 3 -- .../config/services/pagination.yaml | 4 +- 4 files changed, 64 insertions(+), 17 deletions(-) diff --git a/src/Bundle/ChillMainBundle/Controller/NotificationController.php b/src/Bundle/ChillMainBundle/Controller/NotificationController.php index 83b77d7b6..c76e19d9e 100644 --- a/src/Bundle/ChillMainBundle/Controller/NotificationController.php +++ b/src/Bundle/ChillMainBundle/Controller/NotificationController.php @@ -3,12 +3,16 @@ namespace Chill\MainBundle\Controller; use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; -use Chill\MainBundle\Entity\User; use Chill\MainBundle\Repository\NotificationRepository; use Chill\MainBundle\Notification\NotificationRenderer; -use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface; use Symfony\Component\Security\Core\Security; +use Symfony\Component\Routing\Annotation\Route; +use Chill\MainBundle\Pagination\PaginatorFactory; + +/** + * @Route("/{_locale}/notification") + */ class NotificationController extends AbstractController { private $security; @@ -18,11 +22,23 @@ class NotificationController extends AbstractController $this->security = $security; } - public function showAction(NotificationRepository $notificationRepository, NotificationRenderer $notificationRenderer) + + /** + * @Route("/show", name="chill_main_notification_show") + */ + public function showAction( + NotificationRepository $notificationRepository, NotificationRenderer $notificationRenderer, + PaginatorFactory $paginatorFactory) { $currentUser = $this->security->getUser(); - $notifications = $notificationRepository->findAllForAttendee($currentUser); + $notificationsNbr = $notificationRepository->countAllForAttendee(($currentUser)); + $paginator = $paginatorFactory->create($notificationsNbr); + + $notifications = $notificationRepository->findAllForAttendee( + $currentUser, + $limit=$paginator->getItemsPerPage(), + $offset= $paginator->getCurrentPage()->getFirstItemNumber()); $templateData = array(); foreach ($notifications as $notification) { @@ -34,9 +50,10 @@ class NotificationController extends AbstractController $templateData[] = $data; } - return $this->render('ChillMainBundle:Notification:show.html.twig', [ + return $this->render('@ChillMain/Notification/show.html.twig', [ 'datas' => $templateData, - 'notifications' => $notifications, + 'notifications' => $notifications, + 'paginator' => $paginator, ]); } } diff --git a/src/Bundle/ChillMainBundle/Repository/NotificationRepository.php b/src/Bundle/ChillMainBundle/Repository/NotificationRepository.php index d52817164..5ffda75dc 100644 --- a/src/Bundle/ChillMainBundle/Repository/NotificationRepository.php +++ b/src/Bundle/ChillMainBundle/Repository/NotificationRepository.php @@ -24,6 +24,7 @@ use Doctrine\ORM\EntityManagerInterface; use Doctrine\ORM\EntityRepository; use Doctrine\Persistence\ObjectRepository; use Chill\MainBundle\Entity\User; +use Doctrine\ORM\Query; final class NotificationRepository implements ObjectRepository { @@ -60,21 +61,51 @@ final class NotificationRepository implements ObjectRepository return $this->repository->findBy($criteria, $orderBy, $limit, $offset); } - /** - * @return Notification[] - */ - public function findAllForAttendee(User $addressee) // TODO passer à attendees avec S + private function queryAllForAttendee(User $addressee, bool $countQuery=False): Query { $qb = $this->repository->createQueryBuilder('n'); + $select = 'n'; + if($countQuery) { + $select = 'count(n)'; + } + $qb - ->select('n') + ->select($select) ->join('n.addressees', 'a') ->where('a = :addressee') ->setParameter('addressee', $addressee); - $query = $qb->getQuery(); - return $qb->getQuery()->getResult(); + return $qb->getQuery(); + } + + /** + * @return int + */ + public function countAllForAttendee(User $addressee): int // TODO passer à attendees avec S + { + $query = $this->queryAllForAttendee($addressee, $countQuery=True); + + return $query->getSingleScalarResult(); + } + + + /** + * @return Notification[] + */ + public function findAllForAttendee(User $addressee, $limit = null, $offset = null): array // TODO passer à attendees avec S + { + $query = $this->queryAllForAttendee($addressee); + + if($limit) { + $query = $query->setMaxResults($limit); + } + + if($offset) { + $query = $query->setFirstResult($offset); + } + + return $query->getResult(); } public function getClassName() { diff --git a/src/Bundle/ChillMainBundle/config/routes/notification.yaml b/src/Bundle/ChillMainBundle/config/routes/notification.yaml index 2112f882f..e69de29bb 100644 --- a/src/Bundle/ChillMainBundle/config/routes/notification.yaml +++ b/src/Bundle/ChillMainBundle/config/routes/notification.yaml @@ -1,3 +0,0 @@ -chill_main_notification_show: - path: /show - controller: Chill\MainBundle\Controller\NotificationController::showAction diff --git a/src/Bundle/ChillMainBundle/config/services/pagination.yaml b/src/Bundle/ChillMainBundle/config/services/pagination.yaml index f6282a39f..e85352728 100644 --- a/src/Bundle/ChillMainBundle/config/services/pagination.yaml +++ b/src/Bundle/ChillMainBundle/config/services/pagination.yaml @@ -2,13 +2,15 @@ services: chill_main.paginator_factory: class: Chill\MainBundle\Pagination\PaginatorFactory public: true + autowire: true + autoconfigure: true arguments: - "@request_stack" - "@router" - "%chill_main.pagination.item_per_page%" Chill\MainBundle\Pagination\PaginatorFactory: '@chill_main.paginator_factory' - + chill_main.paginator.twig_extensions: class: Chill\MainBundle\Pagination\ChillPaginationTwig tags: From 8030792eb65300aa37e892a636d0ba3d606735ba Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julien=20Fastr=C3=A9?= Date: Thu, 22 Jul 2021 15:36:36 +0000 Subject: [PATCH 19/52] Remove creation of AccompanyingPeriod on person creation --- .../Controller/PersonController.php | 13 ----- .../DataFixtures/ORM/LoadPeople.php | 8 +++ .../ChillPersonBundle/Entity/Person.php | 13 +---- .../Form/CreationPersonType.php | 18 ++---- .../Resources/views/Person/create.html.twig | 5 +- .../views/Person/create_review.html.twig | 16 ++++-- .../Controller/PersonControllerCreateTest.php | 6 -- .../Tests/Entity/PersonTest.php | 17 ++++-- .../TimelineAccompanyingPeriodTest.php | 57 ++++++++++++++----- 9 files changed, 78 insertions(+), 75 deletions(-) diff --git a/src/Bundle/ChillPersonBundle/Controller/PersonController.php b/src/Bundle/ChillPersonBundle/Controller/PersonController.php index 747299e59..f33e9cce8 100644 --- a/src/Bundle/ChillPersonBundle/Controller/PersonController.php +++ b/src/Bundle/ChillPersonBundle/Controller/PersonController.php @@ -252,18 +252,6 @@ final class PersonController extends AbstractController */ $person = $form->getData(); - $periods = $person->getAccompanyingPeriodsOrdered(); - $period = $periods[0]; - $period->setOpeningDate($form['creation_date']->getData()); -// $person = new Person($form['creation_date']->getData()); -// -// $person->setFirstName($form['firstName']->getData()) -// ->setLastName($form['lastName']->getData()) -// ->setGender($form['gender']->getData()) -// ->setBirthdate($form['birthdate']->getData()) -// ->setCenter($form['center']->getData()) -// ; - return $person; } @@ -364,7 +352,6 @@ final class PersonController extends AbstractController 'lastName' => $form['lastName']->getData(), 'birthdate' => $form['birthdate']->getData(), 'gender' => $form['gender']->getData(), - 'creation_date' => $form['creation_date']->getData(), 'form' => $form->createView())); } diff --git a/src/Bundle/ChillPersonBundle/DataFixtures/ORM/LoadPeople.php b/src/Bundle/ChillPersonBundle/DataFixtures/ORM/LoadPeople.php index e8697ff28..556d832c1 100644 --- a/src/Bundle/ChillPersonBundle/DataFixtures/ORM/LoadPeople.php +++ b/src/Bundle/ChillPersonBundle/DataFixtures/ORM/LoadPeople.php @@ -183,6 +183,14 @@ class LoadPeople extends AbstractFixture implements OrderedFixtureInterface, Con private function addAPerson(array $person, ObjectManager $manager) { $p = new Person(); + $p->addAccompanyingPeriod( + new AccompanyingPeriod( + (new \DateTime()) + ->sub( + new \DateInterval('P'.\random_int(0, 180).'D') + ) + ) + ); foreach ($person as $key => $value) { switch ($key) { diff --git a/src/Bundle/ChillPersonBundle/Entity/Person.php b/src/Bundle/ChillPersonBundle/Entity/Person.php index 7f9805f52..695970bfa 100644 --- a/src/Bundle/ChillPersonBundle/Entity/Person.php +++ b/src/Bundle/ChillPersonBundle/Entity/Person.php @@ -379,12 +379,7 @@ class Person implements HasCenterInterface, TrackCreationInterface, TrackUpdateI */ private Collection $householdAddresses; - /** - * Person constructor. - * - * @param \DateTime|null $opening - */ - public function __construct(\DateTime $opening = null) + public function __construct() { $this->accompanyingPeriodParticipations = new ArrayCollection(); $this->spokenLanguages = new ArrayCollection(); @@ -393,12 +388,6 @@ class Person implements HasCenterInterface, TrackCreationInterface, TrackUpdateI $this->otherPhoneNumbers = new ArrayCollection(); $this->householdParticipations = new ArrayCollection(); $this->householdAddresses = new ArrayCollection(); - - if ($opening === null) { - $opening = new \DateTime(); - } - - $this->open(new AccompanyingPeriod($opening)); $this->genderComment = new CommentEmbeddable(); $this->maritalStatusComment = new CommentEmbeddable(); } diff --git a/src/Bundle/ChillPersonBundle/Form/CreationPersonType.php b/src/Bundle/ChillPersonBundle/Form/CreationPersonType.php index e3583071f..c001185ca 100644 --- a/src/Bundle/ChillPersonBundle/Form/CreationPersonType.php +++ b/src/Bundle/ChillPersonBundle/Form/CreationPersonType.php @@ -26,7 +26,7 @@ use Symfony\Component\Form\FormBuilderInterface; use Symfony\Component\OptionsResolver\OptionsResolver; use Symfony\Component\Form\Extension\Core\DataTransformer\DateTimeToStringTransformer; use Symfony\Component\Form\Extension\Core\Type\HiddenType; -use Symfony\Component\Form\Extension\Core\Type\DateType; +use Chill\MainBundle\Form\Type\ChillDateType; use Chill\MainBundle\Form\Type\CenterType; use Chill\PersonBundle\Form\Type\GenderType; use Chill\MainBundle\Form\Type\DataTransformer\CenterTransformer; @@ -80,9 +80,6 @@ final class CreationPersonType extends AbstractType 'property_path' => 'birthdate' )) ->add('gender', HiddenType::class) - ->add('creation_date', HiddenType::class, array( - 'mapped' => false - )) ->add('form_status', HiddenType::class, array( 'mapped' => false, 'data' => $options['form_status'] @@ -99,25 +96,18 @@ final class CreationPersonType extends AbstractType $builder->get('birthdate') ->addModelTransformer($dateToStringTransformer); - $builder->get('creation_date') - ->addModelTransformer($dateToStringTransformer); $builder->get('center') ->addModelTransformer($this->centerTransformer); } else { $builder ->add('firstName') ->add('lastName') - ->add('birthdate', DateType::class, array('required' => false, - 'widget' => 'single_text', 'format' => 'dd-MM-yyyy')) + ->add('birthdate', ChillDateType::class, [ + 'required' => false, + ]) ->add('gender', GenderType::class, array( 'required' => true, 'placeholder' => null )) - ->add('creation_date', DateType::class, array( - 'required' => true, - 'widget' => 'single_text', - 'format' => 'dd-MM-yyyy', - 'mapped' => false, - 'data' => new \DateTime())) ->add('form_status', HiddenType::class, array( 'data' => $options['form_status'], 'mapped' => false diff --git a/src/Bundle/ChillPersonBundle/Resources/views/Person/create.html.twig b/src/Bundle/ChillPersonBundle/Resources/views/Person/create.html.twig index 9d17cba9d..e7a6fb4a6 100644 --- a/src/Bundle/ChillPersonBundle/Resources/views/Person/create.html.twig +++ b/src/Bundle/ChillPersonBundle/Resources/views/Person/create.html.twig @@ -1,7 +1,6 @@ {# * Copyright (C) 2014, Champs Libres Cooperative SCRLFS, - * - * This program is free software: you can redistribute it and/or modify + * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as * published by the Free Software Foundation, either version 3 of the * License, or (at your option) any later version. @@ -38,8 +37,6 @@ {{ form_row(form.birthdate, { 'label' : 'Date of birth'|trans }) }} {{ form_row(form.gender, { 'label' : 'Gender'|trans }) }} - - {{ form_row(form.creation_date, { 'label' : 'Creation date'|trans }) }} {{ form_rest(form) }} diff --git a/src/Bundle/ChillPersonBundle/Resources/views/Person/create_review.html.twig b/src/Bundle/ChillPersonBundle/Resources/views/Person/create_review.html.twig index 8c5b6eb35..cd32c180c 100644 --- a/src/Bundle/ChillPersonBundle/Resources/views/Person/create_review.html.twig +++ b/src/Bundle/ChillPersonBundle/Resources/views/Person/create_review.html.twig @@ -71,14 +71,15 @@
{{ person|chill_entity_render_string }}
{{ 'Date of birth'|trans }}
-
{{ birthdate|format_date('long')|default( 'Unknown date of birth'|trans ) }}
+ {% if birthdate is empty %} +
{{ 'Unknown date of birth'|trans }}
+ {% else %} +
{{ birthdate|format_date('long') }}
+ {% endif %}
{{ 'Gender'|trans }}
{{ gender|trans }}
-
{{ 'Creation date'|trans }}
-
{{ creation_date|format_date('long') }}
- {% if form.altNames is defined %} {# mark as rendered #} {{ form_widget(form.altNames) }} @@ -86,10 +87,13 @@ {{ form_rest(form) }} - +
    +
  • + +
  • +
{{ form_end(form) }}
-
diff --git a/src/Bundle/ChillPersonBundle/Tests/Controller/PersonControllerCreateTest.php b/src/Bundle/ChillPersonBundle/Tests/Controller/PersonControllerCreateTest.php index 57444dfaa..f7dd055c6 100644 --- a/src/Bundle/ChillPersonBundle/Tests/Controller/PersonControllerCreateTest.php +++ b/src/Bundle/ChillPersonBundle/Tests/Controller/PersonControllerCreateTest.php @@ -93,8 +93,6 @@ class PersonControllerCreateTest extends WebTestCase 'The page contains a "gender" input'); $this->assertTrue($form->has(self::BIRTHDATE_INPUT), 'The page has a "date of birth" input'); - $this->assertTrue($form->has(self::CREATEDATE_INPUT), - 'The page contains a "creation date" input'); $genderType = $form->get(self::GENDER_INPUT); $this->assertEquals('radio', $genderType->getType(), @@ -107,10 +105,6 @@ class PersonControllerCreateTest extends WebTestCase 'gender has "femme" option'); $this->assertFalse($genderType->hasValue(), 'The gender input is not checked'); - $today = new \DateTime(); - $this->assertEquals($today->format('d-m-Y'), $form->get(self::CREATEDATE_INPUT) - ->getValue(), 'The creation date input has the current date by default'); - return $form; } diff --git a/src/Bundle/ChillPersonBundle/Tests/Entity/PersonTest.php b/src/Bundle/ChillPersonBundle/Tests/Entity/PersonTest.php index 7e9337d14..dbef739d1 100644 --- a/src/Bundle/ChillPersonBundle/Tests/Entity/PersonTest.php +++ b/src/Bundle/ChillPersonBundle/Tests/Entity/PersonTest.php @@ -45,11 +45,12 @@ class PersonTest extends \PHPUnit\Framework\TestCase public function testGetCurrentAccompanyingPeriod() { $d = new \DateTime('yesterday'); - $p = new Person($d); + $p = new Person(); + $p->addAccompanyingPeriod(new AccompanyingPeriod($d)); $period = $p->getCurrentAccompanyingPeriod(); - $this->assertInstanceOf('Chill\PersonBundle\Entity\AccompanyingPeriod', $period); + $this->assertInstanceOf(AccompanyingPeriod::class, $period); $this->assertTrue($period->isOpen()); $this->assertEquals($d, $period->getOpeningDate()); @@ -67,7 +68,8 @@ class PersonTest extends \PHPUnit\Framework\TestCase public function testAccompanyingPeriodOrderWithUnorderedAccompanyingPeriod() { $d = new \DateTime("2013/2/1"); - $p = new Person($d); + $p = new Person(); + $p->addAccompanyingPeriod(new AccompanyingPeriod($d)); $e = new \DateTime("2013/3/1"); $period = $p->getCurrentAccompanyingPeriod()->setClosingDate($e); @@ -93,7 +95,8 @@ class PersonTest extends \PHPUnit\Framework\TestCase */ public function testAccompanyingPeriodOrderSameDateOpening() { $d = new \DateTime("2013/2/1"); - $p = new Person($d); + $p = new Person(); + $p->addAccompanyingPeriod(new AccompanyingPeriod($d)); $g = new \DateTime("2013/4/1"); $period = $p->getCurrentAccompanyingPeriod()->setClosingDate($g); @@ -120,7 +123,8 @@ class PersonTest extends \PHPUnit\Framework\TestCase */ public function testDateCoveringWithCoveringAccompanyingPeriod() { $d = new \DateTime("2013/2/1"); - $p = new Person($d); + $p = new Person(); + $p->addAccompanyingPeriod(new AccompanyingPeriod($d)); $e = new \DateTime("2013/3/1"); $period = $p->getCurrentAccompanyingPeriod()->setClosingDate($e); @@ -145,7 +149,8 @@ class PersonTest extends \PHPUnit\Framework\TestCase */ public function testNotOpenAFileReOpenedLater() { $d = new \DateTime("2013/2/1"); - $p = new Person($d); + $p = new Person(); + $p->addAccompanyingPeriod(new AccompanyingPeriod($d)); $e = new \DateTime("2013/3/1"); $period = $p->getCurrentAccompanyingPeriod()->setClosingDate($e); diff --git a/src/Bundle/ChillPersonBundle/Tests/Timeline/TimelineAccompanyingPeriodTest.php b/src/Bundle/ChillPersonBundle/Tests/Timeline/TimelineAccompanyingPeriodTest.php index 4fb3c7f06..9b2a32c85 100644 --- a/src/Bundle/ChillPersonBundle/Tests/Timeline/TimelineAccompanyingPeriodTest.php +++ b/src/Bundle/ChillPersonBundle/Tests/Timeline/TimelineAccompanyingPeriodTest.php @@ -20,9 +20,11 @@ namespace Chill\PersonBundle\Tests\Timeline; -use Symfony\Bundle\SecurityBundle\Tests\Functional\WebTestCase; +use Symfony\Bundle\FrameworkBundle\Test\WebTestCase; use Chill\PersonBundle\Entity\Person; use Chill\PersonBundle\Entity\AccompanyingPeriod; +use Doctrine\ORM\EntityManagerInterface; +use Chill\MainBundle\Test\PrepareClientTrait; /** * This class tests entries are shown for closing and opening @@ -31,22 +33,20 @@ use Chill\PersonBundle\Entity\AccompanyingPeriod; * @author Julien Fastré * @author Champs Libres */ -class TimelineAccompanyingPeriodTest extends \Chill\PersonBundle\Tests\Controller\AccompanyingPeriodControllerTest +class TimelineAccompanyingPeriodTest extends WebTestCase { - public function testEntriesAreShown() + use PrepareClientTrait; + + /** + * @dataProvider provideDataPersonWithAccompanyingPeriod + */ + public function testEntriesAreShown($personId) { - $this->generatePeriods(array( - [ - 'openingDate' => '2014-01-01', - 'closingDate' => '2014-12-31', - 'closingMotive' => $this->getRandomClosingMotive() - ] - )); + $client = $this->getClientAuthenticated(); + + $crawler = $client->request('GET', "/en/person/{$personId}/timeline"); - $crawler = $this->client->request('GET', '/en/person/' - .$this->person->getId().'/timeline'); - - $this->assertTrue($this->client->getResponse()->isSuccessful(), + $this->assertTrue($client->getResponse()->isSuccessful(), "the timeline page loads sucessfully"); $this->assertGreaterThan(0, $crawler->filter('.timeline div')->count(), "the timeline page contains multiple div inside a .timeline element"); @@ -57,5 +57,34 @@ class TimelineAccompanyingPeriodTest extends \Chill\PersonBundle\Tests\Controlle $crawler->Filter('.timeline')->text(), "the text 'Une période d'accompagnement a été fermée' is present"); } + + public function provideDataPersonWithAccompanyingPeriod() + { + self::bootKernel(); + + $qb = self::$container->get(EntityManagerInterface::class) + ->createQueryBuilder() + ; + $personIds = $qb + ->from(Person::class, 'p') + ->join('p.accompanyingPeriodParticipations', 'part') + ->join('part.accompanyingPeriod', 'period') + ->join('p.center', 'center') + ->select('p.id') + ->where($qb->expr()->isNotNull('period.closingDate')) + ->andWhere($qb->expr()->eq('center.name', ':center')) + ->setParameter('center', 'Center A') + ->setMaxResults(1000) + ->getQuery() + ->getResult() + ; + + \shuffle($personIds); + + yield [ \array_pop($personIds)['id'] ]; + yield [ \array_pop($personIds)['id'] ]; + yield [ \array_pop($personIds)['id'] ]; + + } } From 0fd9485de5e0a14c717723356099b22b20237a35 Mon Sep 17 00:00:00 2001 From: Marc Ducobu Date: Thu, 22 Jul 2021 18:15:57 +0200 Subject: [PATCH 20/52] Avoid creation of services/notification.yaml --- .../DependencyInjection/ChillActivityExtension.php | 1 - src/Bundle/ChillActivityBundle/config/services.yaml | 13 +++++++++---- .../config/services/notification.yaml | 4 ---- 3 files changed, 9 insertions(+), 9 deletions(-) delete mode 100644 src/Bundle/ChillActivityBundle/config/services/notification.yaml diff --git a/src/Bundle/ChillActivityBundle/DependencyInjection/ChillActivityExtension.php b/src/Bundle/ChillActivityBundle/DependencyInjection/ChillActivityExtension.php index e240bf17c..61354c7c8 100644 --- a/src/Bundle/ChillActivityBundle/DependencyInjection/ChillActivityExtension.php +++ b/src/Bundle/ChillActivityBundle/DependencyInjection/ChillActivityExtension.php @@ -55,7 +55,6 @@ class ChillActivityExtension extends Extension implements PrependExtensionInterf $loader->load('services/controller.yaml'); $loader->load('services/form.yaml'); $loader->load('services/templating.yaml'); - $loader->load('services/notification.yaml'); } public function prepend(ContainerBuilder $container) diff --git a/src/Bundle/ChillActivityBundle/config/services.yaml b/src/Bundle/ChillActivityBundle/config/services.yaml index 411ad1b5a..86168101a 100644 --- a/src/Bundle/ChillActivityBundle/config/services.yaml +++ b/src/Bundle/ChillActivityBundle/config/services.yaml @@ -1,4 +1,4 @@ -services: +services: chill.activity.security.authorization.activity_voter: class: Chill\ActivityBundle\Security\Authorization\ActivityVoter arguments: @@ -6,7 +6,7 @@ services: tags: - { name: security.voter } - { name: chill.role } - + chill.activity.security.authorization.activity_stats_voter: class: Chill\ActivityBundle\Security\Authorization\ActivityStatsVoter arguments: @@ -14,8 +14,8 @@ services: tags: - { name: security.voter } - { name: chill.role } - - + + chill.activity.timeline: class: Chill\ActivityBundle\Timeline\TimelineActivityProvider arguments: @@ -33,3 +33,8 @@ services: autoconfigure: true resource: '../Menu/' tags: ['chill.menu_builder'] + + Chill\ActivityBundle\Notification\: + autowire: true + autoconfigure: true + resource: '../Notification' diff --git a/src/Bundle/ChillActivityBundle/config/services/notification.yaml b/src/Bundle/ChillActivityBundle/config/services/notification.yaml deleted file mode 100644 index 3db168ecd..000000000 --- a/src/Bundle/ChillActivityBundle/config/services/notification.yaml +++ /dev/null @@ -1,4 +0,0 @@ -services: - Chill\ActivityBundle\Notification\ActivityNotificationRenderer: - autoconfigure: true - autowire: true From 4646795c2cd8ca3871d9b70984bf813d4385be0e Mon Sep 17 00:00:00 2001 From: Marc Ducobu Date: Fri, 23 Jul 2021 10:18:04 +0200 Subject: [PATCH 21/52] Automatic styling correction --- .../Test/Export/AbstractExportTest.php | 168 +++++++++--------- 1 file changed, 84 insertions(+), 84 deletions(-) diff --git a/src/Bundle/ChillMainBundle/Test/Export/AbstractExportTest.php b/src/Bundle/ChillMainBundle/Test/Export/AbstractExportTest.php index e480ab145..9909a683b 100644 --- a/src/Bundle/ChillMainBundle/Test/Export/AbstractExportTest.php +++ b/src/Bundle/ChillMainBundle/Test/Export/AbstractExportTest.php @@ -26,7 +26,7 @@ use Symfony\Component\HttpFoundation\Request; /** * This class provide a set of tests for exports. - * + * * The tests provided by this class will check basic things, like * the type of value are conform to the expected, etc. * @@ -34,45 +34,45 @@ use Symfony\Component\HttpFoundation\Request; */ abstract class AbstractExportTest extends WebTestCase { - + use PrepareClientTrait; - + /** * Create an instance of the report to test - * + * * @return \Chill\MainBundle\Export\ExportInterface an instance of the export to test */ public abstract function getExport(); - + /** * Create possible combinaison of data (produced by the form). - * + * * This data will be used to generate data providers using this data. - * + * * @return array an array of data. Example : `array( array(), array('fields' => array(1,2,3), ...)` where an empty array and `array(1,2,3)` are possible values */ public abstract function getFormData(); - + /** - * get the possible modifiers which could apply in combination to this + * get the possible modifiers which could apply in combination to this * export. - * . - * - * @return array of string[] an array which contains an array of possible modifiers. Example : `array( array('modifier_1', 'modifier_2'), array('modifier_1'), ...)` + * . + * + * @return array of string[] an array which contains an array of possible modifiers. Example : `array( array('modifier_1', 'modifier_2'), array('modifier_1'), ...)` */ abstract public function getModifiersCombination(); - + /** * Return an array usable as ACL - * + * * If this method is overridden, the returned result must be an array * with this form : - * + * * ``` * array( - * array( - * 'center' => //center instance + * array( + * 'center' => //center instance * 'circles' => array(// array of circles instances ) * ) * ); @@ -84,15 +84,15 @@ abstract class AbstractExportTest extends WebTestCase if (static::$kernel === null) { static::bootKernel(); } - + $em = static::$kernel->getContainer() ->get('doctrine.orm.entity_manager'); - + $centers = $em->getRepository('ChillMainBundle:Center') ->findAll(); $circles = $em->getRepository('ChillMainBundle:Scope') ->findAll(); - + if (count($centers) === 0) { throw new \RuntimeException("No center found. Did you forget to " . "run `doctrine:fixtures:load` command before ?"); @@ -101,7 +101,7 @@ abstract class AbstractExportTest extends WebTestCase throw new \RuntimeException("No circle found. Did you forget to " . "run `doctrine:fixtures:load` command before ?"); } - + return array([ 'center' => $centers[0], 'circles' => [ @@ -115,204 +115,204 @@ abstract class AbstractExportTest extends WebTestCase public function testGetType() { $export = $this->getExport(); - - $this->assertInternalType('string', $export->getType(), + + $this->assertInternalType('string', $export->getType(), "Assert that the `getType` method return a string"); $this->assertNotEmpty($export->getType(), "Assert that the `getType` method" . " does not return an empty string."); } - + /** * Test that the description is not empty */ public function testGetDescription() { $export = $this->getExport(); - - $this->assertInternalType('string', $export->getDescription(), + + $this->assertInternalType('string', $export->getDescription(), "Assert that the `getDescription` method return a string"); - $this->assertNotEmpty($export->getDescription(), + $this->assertNotEmpty($export->getDescription(), "Assert that the `getDescription` method does not return an empty " . "string."); } - + /** * create data for `ìnitiateQuery` method */ public function dataProviderInitiateQuery() { $acl = $this->getAcl(); - + foreach($this->getModifiersCombination() as $modifiers) { - + foreach($this->getFormData() as $data) { - + yield array($modifiers, $acl, $data); } } } - + public function dataProviderGetQueryKeys() { foreach($this->getFormData() as $data) { yield array($data); } } - + /** - * + * * test that the query returned is a QueryBuilder or a NativeQuery. - * + * * If the query is a QueryBuilder, test that select and from is not empty. - * - * If the query is a native sql, test the query is not empty (length is + * + * If the query is a native sql, test the query is not empty (length is * > 0). - * + * * @dataProvider dataProviderInitiateQuery */ public function testInitiateQuery($modifiers, $acl, $data) { var_dump($data); $query = $this->getExport()->initiateQuery($modifiers, $acl, $data); - + $this->assertTrue($query instanceof QueryBuilder || $query instanceof NativeQuery, - sprintf("Assert that the returned query is an instance of %s or %s", + sprintf("Assert that the returned query is an instance of %s or %s", QueryBuilder::class, Query::class)); - + if ($query instanceof QueryBuilder) { - + $this->assertGreaterThanOrEqual(1, count($query->getDQLPart('select')), "assert there is at least one 'select' part"); - + $this->assertGreaterThanOrEqual(1, count($query->getDQLPart('from')), "assert there is at least one 'from' part"); - + } elseif ($query instanceof NativeQuery) { - $this->assertNotEmpty($query->getSQL(), + $this->assertNotEmpty($query->getSQL(), "check that the SQL query is not empty"); } } - + /** * Test that supportsModifier return : - * + * * - an array of string, if the query is a QueryBuilder ; * - nothing, if the query is a native SQL - * + * * @dataProvider dataProviderInitiateQuery */ public function testSupportsModifier($modifiers, $acl, $data) { $export = $this->getExport(); $query = $export->initiateQuery($modifiers, $acl, $data); - + if ($query instanceof QueryBuilder) { $this->assertContainsOnly('string', $export->supportsModifiers(), "Test that the `supportsModifiers` method returns only strings"); } elseif ($query instanceof NativeQuery) { - $this->assertTrue($export->supportsModifiers() === null || + $this->assertTrue($export->supportsModifiers() === null || count($export->supportsModifiers()) === 0, "Test that the `supportsModifier` methods returns null or an empty array"); } } - + /** * Test required role is an instance of Role */ public function testRequiredRole() { $role = $this->getExport()->requiredRole(); - - $this->assertInstanceOf(Role::class, $role, + + $this->assertInstanceOf(Role::class, $role, sprintf("test that the returned value of `requiredRole` is an instance " . "of %s", Role::class)); } - + /** * Test the formatters type are string */ public function testGetAllowedFormattersType() { $formattersTypes = $this->getExport()->getAllowedFormattersTypes(); - + $this->assertContainsOnly("string", $formattersTypes, "Test that the method `getAllowedFormattersTypes` returns an array of string"); } - + /** * Test that the query keys are strings - * + * * @param array $data * @dataProvider dataProviderGetQueryKeys */ public function testGetQueryKeys(array $data) { $queryKeys = $this->getExport()->getQueryKeys($data); - + $this->assertContainsOnly("string", $queryKeys, "test that the query keys returned by `getQueryKeys` are only strings"); $this->assertGreaterThanOrEqual(1, count($queryKeys), "test that there are at least one query key returned"); } - + /** - * - * Test that - * + * + * Test that + * * - the results have a correct form (are arrays or traversable) * - each key in a row are present in getQueryKeys ; * - each returned object of the `getLabels` method is callable * - each result can be converted to string using this callable * - each of this callable can provide a string for '_header' - * + * * @param string[] $modifiers * @param array $acl * @param array $data - * + * * @dataProvider dataProviderInitiateQuery */ public function testGetResultsAndLabels($modifiers, $acl, array $data) { // it is more convenient to group the `getResult` and `getLabels` test // due to the fact that testing both methods use the same tools. - + $queryKeys = $this->getExport()->getQueryKeys($data); $query = $this->getExport()->initiateQuery($modifiers, $acl, $data); - + // limit the result for the query for performance reason (only for QueryBuilder, // not possible in NativeQuery) if ($query instanceof QueryBuilder) { $query->setMaxResults(1); - } - + } + $results = $this->getExport()->getResult($query, $data); - - $this->assertInternalType('array', $results, + + $this->assertInternalType('array', $results, "assert that the returned result is an array"); - + if (count($results) === 0) { $this->markTestIncomplete("The result is empty. We cannot process tests " . "on results"); } - + // testing the result $result = $results[0]; - + $this->assertTrue( $result instanceof \Traversable || is_array($result), "test that each row in the result is traversable or an array"); - + foreach ($result as $key => $value) { $this->assertContains($key, $queryKeys, "test that each key is present in `getQueryKeys`"); - + $closure = $this->getExport()->getLabels($key, array($value), $data); - + $this->assertTrue(is_callable($closure, false), "test that the `getLabels` for key is a callable"); $this->assertTrue(is_string((string) call_user_func($closure, $value)), sprintf("test that the callable return by `getLabels` for key %s " . "is a string or an be converted to a string", $key)); - + $this->assertTrue( // conditions is_string((string) call_user_func($closure, '_header')) @@ -322,13 +322,13 @@ abstract class AbstractExportTest extends WebTestCase sprintf("Test that the callable return by `getLabels` for key %s " . "can provide an header", $key) ); - } - + } + } - + /** - * Test that the translated title of the export is present the list, + * Test that the translated title of the export is present the list, * and that the list of exports (under `/fr/exports/`) is still successfull */ public function testListExportPage() @@ -338,17 +338,17 @@ abstract class AbstractExportTest extends WebTestCase $export = $this->getExport(); $prophet= new \Prophecy\Prophet; $container = static::$kernel->getContainer(); - + // store the locale in a request $request = new Request(); $request->setLocale('fr'); $container->get('request_stack')->push($request); // translate the title $title = $container->get('translator')->trans($export->getTitle()); - + // performs the request to /fr/exports $crawler = $client->request('GET', '/fr/exports/'); - + // and finally make tests $this->assertTrue($client->getResponse()->isSuccessful(), "test that the response of /fr/exports/ is successful"); From 9d478c0f0103b6a67ea114344cef02e88b8d3597 Mon Sep 17 00:00:00 2001 From: Marc Ducobu Date: Fri, 23 Jul 2021 10:18:41 +0200 Subject: [PATCH 22/52] Removing var_dump --- src/Bundle/ChillMainBundle/Test/Export/AbstractExportTest.php | 1 - 1 file changed, 1 deletion(-) diff --git a/src/Bundle/ChillMainBundle/Test/Export/AbstractExportTest.php b/src/Bundle/ChillMainBundle/Test/Export/AbstractExportTest.php index 9909a683b..fcf82fca9 100644 --- a/src/Bundle/ChillMainBundle/Test/Export/AbstractExportTest.php +++ b/src/Bundle/ChillMainBundle/Test/Export/AbstractExportTest.php @@ -172,7 +172,6 @@ abstract class AbstractExportTest extends WebTestCase */ public function testInitiateQuery($modifiers, $acl, $data) { - var_dump($data); $query = $this->getExport()->initiateQuery($modifiers, $acl, $data); $this->assertTrue($query instanceof QueryBuilder || $query instanceof NativeQuery, From 376d8df55e92bea83b7d361e89c241ec88e3672a Mon Sep 17 00:00:00 2001 From: Mathieu Jaumotte Date: Mon, 26 Jul 2021 17:56:44 +0200 Subject: [PATCH 23/52] fix bug with bootstrap form theme textarea (horizontal layout mode) cfr issue https://gitlab.com/champs-libres/departement-de-la-vendee/chill/-/issues/182 + make chill fields theme more responsive --- .../views/Event/listByPerson.html.twig | 4 +- .../Participation/new-multiple.html.twig | 18 ++++---- .../bootstrap_5_horizontal_layout.html.twig | 22 ++++++--- .../Resources/views/Form/fields.html.twig | 46 +++++++++---------- 4 files changed, 47 insertions(+), 43 deletions(-) diff --git a/src/Bundle/ChillEventBundle/Resources/views/Event/listByPerson.html.twig b/src/Bundle/ChillEventBundle/Resources/views/Event/listByPerson.html.twig index 36ef66af3..e9f9a0270 100644 --- a/src/Bundle/ChillEventBundle/Resources/views/Event/listByPerson.html.twig +++ b/src/Bundle/ChillEventBundle/Resources/views/Event/listByPerson.html.twig @@ -108,8 +108,6 @@ {{ chill_pagination(paginator) }} {% endif %} -{% form_theme form_add_event_participation_by_person 'bootstrap_4_layout.html.twig' %} -
{{ form_start(form_add_event_participation_by_person) }} {# @@ -137,4 +135,4 @@
-{% endblock %} \ No newline at end of file +{% endblock %} diff --git a/src/Bundle/ChillEventBundle/Resources/views/Participation/new-multiple.html.twig b/src/Bundle/ChillEventBundle/Resources/views/Participation/new-multiple.html.twig index 2e7dd6cdb..a0551ff1a 100644 --- a/src/Bundle/ChillEventBundle/Resources/views/Participation/new-multiple.html.twig +++ b/src/Bundle/ChillEventBundle/Resources/views/Participation/new-multiple.html.twig @@ -3,9 +3,7 @@ {% import 'ChillPersonBundle:Person:macro.html.twig' as person_macro %} {% block title 'Participation creation'|trans %} - - {% form_theme form _self %} - + {% block _collection_row %} @@ -28,10 +26,10 @@ - + {% include 'ChillEventBundle:Participation:_ignored_participations.html.twig' with ignored_participations %} - - {{ form_start(form) }} + + {{ form_start(form) }} @@ -47,10 +45,10 @@ - {% endfor %} + {% endfor %}
{{ form_widget(participationField.role) }} {{ form_widget(participationField.status) }}
- + - + {{ form_end(form) }} - + {% endblock %} diff --git a/src/Bundle/ChillMainBundle/Resources/views/Form/bootstrap5/bootstrap_5_horizontal_layout.html.twig b/src/Bundle/ChillMainBundle/Resources/views/Form/bootstrap5/bootstrap_5_horizontal_layout.html.twig index f38c94ef3..e0c43629e 100644 --- a/src/Bundle/ChillMainBundle/Resources/views/Form/bootstrap5/bootstrap_5_horizontal_layout.html.twig +++ b/src/Bundle/ChillMainBundle/Resources/views/Form/bootstrap5/bootstrap_5_horizontal_layout.html.twig @@ -60,14 +60,22 @@ {{- form_errors(form) -}} {%- else -%} - {{- form_label(form) -}} -
- {{- form_widget(form, widget_attr) -}} - {{- form_help(form) -}} - {{- form_errors(form) -}} -
+ {% if form.vars.hideLabel is not defined or form.vars.hideLabel == false %} + {{- form_label(form) -}} +
+ {{- form_widget(form, widget_attr) -}} + {{- form_help(form) -}} + {{- form_errors(form) -}} +
+ {% else %} +
+ {{- form_widget(form, widget_attr) -}} + {{- form_help(form) -}} + {{- form_errors(form) -}} +
+ {% endif %} {%- endif -%} - {##} + {%- endif -%} {%- endblock form_row %} diff --git a/src/Bundle/ChillMainBundle/Resources/views/Form/fields.html.twig b/src/Bundle/ChillMainBundle/Resources/views/Form/fields.html.twig index 9cc35966a..90729c22d 100644 --- a/src/Bundle/ChillMainBundle/Resources/views/Form/fields.html.twig +++ b/src/Bundle/ChillMainBundle/Resources/views/Form/fields.html.twig @@ -1,5 +1,5 @@ {# - * Copyright (C) 2014-2015, Champs Libres Cooperative SCRLFS, + * Copyright (C) 2014-2015, Champs Libres Cooperative SCRLFS, / * * This program is free software: you can redistribute it and/or modify @@ -23,11 +23,11 @@
{% if attr.class is not defined or ('cf-title' not in attr.class and 'cf-fields' not in attr.class ) %} @@ -36,13 +36,13 @@
{{ form_widget(form) }} @@ -55,7 +55,7 @@ {% endif %} {% endapply %} {% endblock form_row %} - + {% block choice_widget_expanded %} {% apply spaceless %}
@@ -125,7 +125,7 @@
{%- endif -%} {%- endblock time_widget -%} - + {% block form_errors %} {% apply spaceless %} {% if errors|length > 0 %} @@ -140,27 +140,27 @@ {% block _formatter__aggregator_placement_csv_formatter_row %}

{{ form_label(form) }}

- + {{ form_row(form.order) }} - + {{ form_row(form.position) }} - + {% endblock %} {% block _formatter__aggregator_placement_spreadsheet_formatter_row %}

{{ form_label(form) }}

- + {{ form_row(form.order) }} - + {% endblock %} {% block chill_collection_widget %}
-
    {% for entry in form %}
  • @@ -172,14 +172,14 @@
{% if form.vars.allow_add == 1 %} - {% endif %} - +
{% endblock %} From 4b3f4edcc192636b2dc7fa2b68a38ac118d759e5 Mon Sep 17 00:00:00 2001 From: Mathieu Jaumotte Date: Mon, 26 Jul 2021 18:08:33 +0200 Subject: [PATCH 24/52] oups --- .../ChillMainBundle/Resources/views/Form/fields.html.twig | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Bundle/ChillMainBundle/Resources/views/Form/fields.html.twig b/src/Bundle/ChillMainBundle/Resources/views/Form/fields.html.twig index 90729c22d..1e2bf713f 100644 --- a/src/Bundle/ChillMainBundle/Resources/views/Form/fields.html.twig +++ b/src/Bundle/ChillMainBundle/Resources/views/Form/fields.html.twig @@ -19,7 +19,7 @@ {% block form_row %} {% apply spaceless %} {% if form.vars.hideLabel is not defined or form.vars.hideLabel == false %} -
+
{% endblock %} - -{% block css %} - {{ parent() }} - {{ encore_entry_link_tags('vue_accourse_work_list') }} -{% endblock %} From 9e9a459a20e3f2c04abca1b441fd2da631a846aa Mon Sep 17 00:00:00 2001 From: Marc Ducobu Date: Tue, 27 Jul 2021 15:59:03 +0200 Subject: [PATCH 26/52] Replace chill_main.paginator_factory by PaginatorFactory::class --- src/Bundle/ChillMainBundle/CRUD/Controller/CRUDController.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Bundle/ChillMainBundle/CRUD/Controller/CRUDController.php b/src/Bundle/ChillMainBundle/CRUD/Controller/CRUDController.php index 25b7e5860..ca28b1d14 100644 --- a/src/Bundle/ChillMainBundle/CRUD/Controller/CRUDController.php +++ b/src/Bundle/ChillMainBundle/CRUD/Controller/CRUDController.php @@ -1141,7 +1141,7 @@ class CRUDController extends AbstractController */ protected function getPaginatorFactory(): PaginatorFactory { - return $this->container->get('chill_main.paginator_factory'); + return $this->container->get(PaginatorFactory::class); } /** From df3d32c6530f521baea46242dc3e6d9367d156ff Mon Sep 17 00:00:00 2001 From: Mathieu Jaumotte Date: Tue, 27 Jul 2021 23:15:52 +0200 Subject: [PATCH 27/52] wip render box person thirdparty display bloc --- .../Resources/public/chill/chillmain.scss | 3 + .../Resources/public/chill/index.js | 1 + .../public/chill/scss/person_with_period.scss | 26 ++-- .../public/chill/scss/render_box.scss | 20 +++ .../views/AccompanyingCourse/index.html.twig | 97 ++----------- .../Resources/views/Entity/person.html.twig | 128 +++++++++++++++-- .../views/Person/list_with_period.html.twig | 41 +++--- .../Templating/Entity/PersonRender.php | 23 ++-- .../Resources/public/chill/thirdparty.scss | 126 ++++++++++------- .../views/Entity/thirdparty.html.twig | 130 ++++++++++++++++++ .../views/ThirdParty/_render.html.twig | 52 ------- .../Templating/Entity/ThirdPartyRender.php | 29 ++-- 12 files changed, 412 insertions(+), 264 deletions(-) create mode 100644 src/Bundle/ChillPersonBundle/Resources/public/chill/scss/render_box.scss create mode 100644 src/Bundle/ChillThirdPartyBundle/Resources/views/Entity/thirdparty.html.twig delete mode 100644 src/Bundle/ChillThirdPartyBundle/Resources/views/ThirdParty/_render.html.twig diff --git a/src/Bundle/ChillMainBundle/Resources/public/chill/chillmain.scss b/src/Bundle/ChillMainBundle/Resources/public/chill/chillmain.scss index ed432a7e4..3fcdb9da1 100644 --- a/src/Bundle/ChillMainBundle/Resources/public/chill/chillmain.scss +++ b/src/Bundle/ChillMainBundle/Resources/public/chill/chillmain.scss @@ -84,6 +84,7 @@ div.flex-table { /* * Bloc appearance */ +/* div.flex-bloc { box-sizing: border-box; display: flex; @@ -134,6 +135,8 @@ div.flex-bloc { margin: auto 0; } } + */ + /* * Table appearance diff --git a/src/Bundle/ChillPersonBundle/Resources/public/chill/index.js b/src/Bundle/ChillPersonBundle/Resources/public/chill/index.js index 7ad042e2c..69e589bab 100644 --- a/src/Bundle/ChillPersonBundle/Resources/public/chill/index.js +++ b/src/Bundle/ChillPersonBundle/Resources/public/chill/index.js @@ -7,6 +7,7 @@ require('./scss/person_with_period.scss'); require('./scss/household_banner.scss'); require('./scss/accompanying_period_work.scss'); require('./scss/person_by_phonenumber.scss'); +require('./scss/render_box.scss'); require('./svg/phone-alt-solid.svg'); require('./svg/mobile-alt-solid.svg'); diff --git a/src/Bundle/ChillPersonBundle/Resources/public/chill/scss/person_with_period.scss b/src/Bundle/ChillPersonBundle/Resources/public/chill/scss/person_with_period.scss index 9e3ff8f6e..6be613ea3 100644 --- a/src/Bundle/ChillPersonBundle/Resources/public/chill/scss/person_with_period.scss +++ b/src/Bundle/ChillPersonBundle/Resources/public/chill/scss/person_with_period.scss @@ -2,24 +2,11 @@ div.list-with-period, div.list-household-members { - .chill-entity__person { - .chill-entity__person__first-name, - .chill-entity__person__last-name { - font-size: 1.3em; - font-weight: 700; - } - } - - .chill_denomination { - font-size: 1.3em; - font-weight: 700; - } - div.comment { // for the comment for household-members } div.periods { - div.header, + div.header, div.list-content { width: calc(100% - 40px); margin-left: 40px; @@ -28,17 +15,17 @@ div.list-household-members { position: relative; a.sc-button { position: absolute; - width: 30px; + width: 30px; height: 30px; - top: 10px; + top: 10px; left: -40px; padding: 0; i { padding: 5px; } } - abbr.referrer { - font-size: 70%; + abbr.referrer { + font-size: 70%; } span.user { margin-left: 1em; @@ -51,3 +38,6 @@ div.list-household-members { } } } + + + diff --git a/src/Bundle/ChillPersonBundle/Resources/public/chill/scss/render_box.scss b/src/Bundle/ChillPersonBundle/Resources/public/chill/scss/render_box.scss new file mode 100644 index 000000000..7f1773710 --- /dev/null +++ b/src/Bundle/ChillPersonBundle/Resources/public/chill/scss/render_box.scss @@ -0,0 +1,20 @@ +div.chill-entity { + &.person { + &.label { + h3.denomination { + font-size: 1.3em; + font-weight: 700; + a { + text-decoration: none; + } + span.firstname, span.lastname, span.altname {} + span.badge { + margin-left: 0.3em; + } + } + p.moreinfo {} + } + &.row {} + &.bloc {} + } +} diff --git a/src/Bundle/ChillPersonBundle/Resources/views/AccompanyingCourse/index.html.twig b/src/Bundle/ChillPersonBundle/Resources/views/AccompanyingCourse/index.html.twig index 7461c2767..03f5bb379 100644 --- a/src/Bundle/ChillPersonBundle/Resources/views/AccompanyingCourse/index.html.twig +++ b/src/Bundle/ChillPersonBundle/Resources/views/AccompanyingCourse/index.html.twig @@ -222,103 +222,28 @@

{{ 'Resources'|trans }}

{% if accompanyingCourse.resources|length == 0 %} -

{{ 'Any resource for this accompanying course'|trans }}

+

{{ 'Any resource for this accompanying course'|trans }}

{% else %} -
- {% for r in accompanyingCourse.resources %} +
+ {% for r in accompanyingCourse.resources %}
{% if r.person %} - + {{ r.person|chill_entity_render_box({ + 'display': 'bloc', 'addLink': true, 'addEntity': true, 'addInfo': true + }) }} {% endif %} {% if r.thirdParty %} -
-
-

- {{ r.thirdParty.name }} - {{ 'Tiers' }} -

-
-
- -
    -
  • - -
  • -
-
-
+ {{ r.thirdParty|chill_entity_render_box({ + 'display': 'bloc', 'addLink': true, 'addEntity': true, 'addInfo': true + }) }} {% endif %}
- {% endfor %} -
+ {% endfor %} +
{% endif %}

{{ 'Social actions'|trans }}

diff --git a/src/Bundle/ChillPersonBundle/Resources/views/Entity/person.html.twig b/src/Bundle/ChillPersonBundle/Resources/views/Entity/person.html.twig index 24afd7bf3..a7ffc1775 100644 --- a/src/Bundle/ChillPersonBundle/Resources/views/Entity/person.html.twig +++ b/src/Bundle/ChillPersonBundle/Resources/views/Entity/person.html.twig @@ -1,17 +1,115 @@ - - {%- if addLink and is_granted('CHILL_PERSON_SEE', person) -%} - {%- set showLink = true -%}{%- endif -%} - {{ person.firstName }} - {{ person.lastName }} +{# + Template to render a person + OPTIONS + * display [raw|label|row|bloc] + * addAltNames bool + * addLink bool + * addEntity bool + * addInfo bool +#} +{% macro raw(person, addAltNames) %} + {{ person.firstName }} + {{ person.lastName }} {%- if addAltNames -%} - {%- for n in person.altNames -%} - {%- if loop.first -%}({% else %} {%- endif -%} - - {{- n.label -}} - - {%- if loop.last -%}) {%- endif -%} - {%- endfor -%} + {%- for n in person.altNames -%} + {%- if loop.first -%}({% else %} {%- endif -%} + + {{- n.label -}} + + {%- if loop.last -%}){%- endif -%} + {%- endfor -%} {%- endif -%} - {%- if showLink is defined -%}{%- endif -%} -{#- tricks to remove easily whitespace after template -#} -{%- if true -%}{%- endif -%} +{% endmacro raw %} + +{% macro label(person, addLink, addAltNames, addEntity, addInfo) %} +
+

+ {%- if addLink and is_granted('CHILL_PERSON_SEE', person) -%} + + {{ _self.raw(person, addAltNames) }} + + {%- else -%} + {{ _self.raw(person, addAltNames) }} + {%- endif -%} + {%- if addEntity -%} + {{ 'Person'|trans }} + {%- endif -%} +

+ {%- if addInfo -%} + {% set born = (person.gender == 'woman') ? 'née le ': 'né le ' %} + {% set gender = (person.gender == 'woman') ? 'fa-venus' : + (person.gender == 'man') ? 'fa-mars' : 'fa-neuter' %} + {% set genderTitle = (person.gender == 'woman') ? 'woman' : + (person.gender == 'man') ? 'man' : 'neuter' %} +

+ + {{ born|trans }} + + {# TODO + {{ 'Born the %date%'|transchoice(person.genderNumeric, { + '%date%': person.birthdate|format_date("medium") }) }} + #} +

+ {%- endif -%} + {#- tricks to remove easily whitespace after template -#} + {%- if true -%}
{%- endif -%} +{% endmacro label %} + + +{%- if display == 'raw' -%} + {{ _self.raw(person, addAltNames) }} +{%- endif -%} + +{%- if display == 'label' -%} + {{ _self.label(person, addLink, addAltNames, addEntity, addInfo) }} +{%- endif -%} + +{%- if display == 'row' -%} +
+ {{ _self.label(person, addLink, addAltNames, addEntity, addInfo) }} +
+{%- endif -%} + +{%- if display == 'bloc' -%} +
+
+
+ {{ _self.label(person, addLink, addAltNames, addEntity, addInfo) }} +
+
+
    +
  • + {% if person.mobilenumber %} + {{ person.mobilenumber }} + {% else %} + + {% if person.phonenumber %} + {{ person.phonenumber }} + {% else %} + {{ 'No data given'|trans }} + {% endif %} + {% endif %} +
  • +
  • + + {%- if person.lastAddress is not empty -%} + {{ person.getLastAddress|chill_entity_render_box({'with_valid_from': false}) }} + {%- else -%} + {{ 'No address given'|trans }} + {%- endif -%} +
  • +
+ {%- if is_granted('CHILL_PERSON_SEE', person) -%} +
    +
  • +
  • +
+ {%- endif -%} +
+
+
+{%- endif -%} + diff --git a/src/Bundle/ChillPersonBundle/Resources/views/Person/list_with_period.html.twig b/src/Bundle/ChillPersonBundle/Resources/views/Person/list_with_period.html.twig index ab88c81ef..91a905cc1 100644 --- a/src/Bundle/ChillPersonBundle/Resources/views/Person/list_with_period.html.twig +++ b/src/Bundle/ChillPersonBundle/Resources/views/Person/list_with_period.html.twig @@ -39,21 +39,24 @@
{% for person in persons %} - +
- +
-
{{ person|chill_entity_render_box({'addLink': true}) }}
-
{{ 'Born the %date%'|transchoice(person.genderNumeric, { '%date%': person.birthdate|format_date("medium") }) }}
+
+ {{ person|chill_entity_render_box({ + 'display': 'label', 'addLink': true, 'addInfo': true + }) }} +
- +
  • {{ person.center }}
  • - +
  • {% if person.mobilenumber is not empty %} {{ person.mobilenumber|chill_format_phonenumber }} @@ -66,7 +69,7 @@ {% endif %} {% endif %}
  • - +
  • {% if person.getLastAddress is not null %} @@ -75,7 +78,7 @@ {{ 'No address'|trans }} {% endif %}
  • - +
  • @@ -89,7 +92,7 @@
- +
{#- 'apps' is for AccompanyingPeriodParticipationS #} @@ -100,40 +103,40 @@ {%- set apps = apps|merge([app]) %} {%- endif %} {%- endfor %} - + {% if apps|length > 0 %} {% for app in apps %}
- +
- {{ 'Since %date%'|trans({'%date%': app.startDate|format_date('medium') }) }} {% if app.accompanyingPeriod.user is not null %} - ref: + ref: {{ app.accompanyingPeriod.user|chill_entity_render_box }} {% endif %}
- +
{% for issue in app.accompanyingPeriod.socialIssues|slice(0,2) %} {{ issue|chill_entity_render_box }} {% endfor %} - + {% if app.accompanyingPeriod.socialIssues|length > 2 %} {{ 'and %number% other'|transchoice(app.accompanyingPeriod.socialIssues|length-2) }} {% endif %}
- +
{% endfor %} - + {% endif %} - +
{% endfor %} @@ -162,7 +165,7 @@ {% endif %} - + {% else %}
  • diff --git a/src/Bundle/ChillPersonBundle/Templating/Entity/PersonRender.php b/src/Bundle/ChillPersonBundle/Templating/Entity/PersonRender.php index 717ee4fc6..353d05ecf 100644 --- a/src/Bundle/ChillPersonBundle/Templating/Entity/PersonRender.php +++ b/src/Bundle/ChillPersonBundle/Templating/Entity/PersonRender.php @@ -2,7 +2,7 @@ /* * Chill is a software for social workers * - * Copyright (C) 2014-2019, Champs Libres Cooperative SCRLFS, + * Copyright (C) 2014-2019, Champs Libres Cooperative SCRLFS, * * * This program is free software: you can redistribute it and/or modify @@ -35,7 +35,7 @@ class PersonRender extends AbstractChillEntityRender private ConfigPersonAltNamesHelper $configAltNamesHelper; private EngineInterface $engine; - + public function __construct( ConfigPersonAltNamesHelper $configAltNamesHelper, EngineInterface $engine @@ -43,9 +43,9 @@ class PersonRender extends AbstractChillEntityRender $this->configAltNamesHelper = $configAltNamesHelper; $this->engine = $engine; } - + /** - * + * * @param Person $person * @param array $options * @return string @@ -56,13 +56,16 @@ class PersonRender extends AbstractChillEntityRender [ 'person' => $person, 'addAltNames' => $this->configAltNamesHelper->hasAltNames(), - 'addLink' => $options['addLink'] ?? false + 'addLink' => $options['addLink'] ?? false, + 'addEntity' => $options['addEntity'] ?? false, + 'addInfo' => $options['addInfo'] ?? false, + 'display' => $options['display'] ?? 'raw' ] ); } /** - * + * * @param Person $person * @param array $options * @return string @@ -76,7 +79,7 @@ class PersonRender extends AbstractChillEntityRender protected function addAltNames(Person $person, bool $addSpan) { $str = ''; - + if ($this->configAltNamesHelper->hasAltNames()) { $altNames = $this->configAltNamesHelper->getChoices(); $isFirst = true; @@ -94,18 +97,18 @@ class PersonRender extends AbstractChillEntityRender $str .= ''; } $str .= $altName->getLabel(); - + if ($addSpan) { $str .= ""; } } } - + if (!$isFirst) { $str .= ")"; } } - + return $str; } diff --git a/src/Bundle/ChillThirdPartyBundle/Resources/public/chill/thirdparty.scss b/src/Bundle/ChillThirdPartyBundle/Resources/public/chill/thirdparty.scss index 952b011ec..2efe06c5e 100644 --- a/src/Bundle/ChillThirdPartyBundle/Resources/public/chill/thirdparty.scss +++ b/src/Bundle/ChillThirdPartyBundle/Resources/public/chill/thirdparty.scss @@ -1,51 +1,79 @@ +div.chill-entity { + &.thirdparty { + &.label { + h3.denomination { + font-size: 1.3em; + font-weight: 700; + a { + text-decoration: none; + } + span.name {} + span.badge { + margin-left: 0.3em; + } + } + p.moreinfo {} + } + &.row {} + &.bloc {} + + +/* + border: 1px solid black; + background-color: rgba(255, 255, 255, 0.65); + padding: 1em; + margin: 1em 0; + max-width: 500px; + + div.name { + font-variant: small-caps; + } + + div.category { + margin: 0.5em 0; + font-size: 85%; + + span.category { + font-style: italic; + } + span::before { + margin-left: 0.5em; + margin-right: 0.5em; + font-family: 'ForkAwesome'; + content: '\f02e'; + font-style: normal; + } + } + + div.comment { + font-size: 85%; + font-style: italic; + } + + div.chill_address { + div.chill_address_address::before { + margin-left: 0.5em; + margin-right: 0.5em; + font-family: 'ForkAwesome'; + content: '\f015'; + } + } + + div.contact { + font-variant: small-caps; + span::before { + margin-left: 0.5em; + margin-right: 0.5em; + font-family: 'ForkAwesome'; + } + span.email::before { + content: '\f1fa'; + } + span.telephone::before { + content: '\f095'; + } + } + */ -div.chill_contact { - border: 1px solid black; - background-color: rgba(255, 255, 255, 0.65); - padding: 1em; - margin: 1em 0; - max-width: 500px; - div.chill_contact_name { - font-variant: small-caps; - } - div.chill_contact_category { - margin: 0.5em 0; - font-size: 85%; - span.category { - font-style: italic; } - span::before { - margin-left: 0.5em; - margin-right: 0.5em; - font-family: 'ForkAwesome'; - content: '\f02e'; - font-style: normal; - } - } - div.chill_contact_comment { - font-size: 85%; - font-style: italic; - } - div.chill_address { - div.chill_address_address::before { - margin-left: 0.5em; - margin-right: 0.5em; - font-family: 'ForkAwesome'; - content: '\f015'; - } - } - div.chill_contact_contact { - font-variant: small-caps; - span::before { - margin-left: 0.5em; - margin-right: 0.5em; - font-family: 'ForkAwesome'; - } - span.email::before { - content: '\f1fa'; - } - span.telephone::before { - content: '\f095'; - } - } -} \ No newline at end of file +} diff --git a/src/Bundle/ChillThirdPartyBundle/Resources/views/Entity/thirdparty.html.twig b/src/Bundle/ChillThirdPartyBundle/Resources/views/Entity/thirdparty.html.twig new file mode 100644 index 000000000..3f665aa26 --- /dev/null +++ b/src/Bundle/ChillThirdPartyBundle/Resources/views/Entity/thirdparty.html.twig @@ -0,0 +1,130 @@ +{# + Template to render a thirdparty + OPTIONS + * display [raw|label|row|bloc] + * with_valid_from bool + * addAltNames bool + * addLink bool + * addEntity bool + * addInfo bool +#} +{% macro raw(thirdparty) %} + {{ thirdparty.name }} +{% endmacro raw %} + +{% macro label(thirdparty, addLink, addEntity, addInfo, options) %} +
    + +

    + {%- if addLink and is_granted('CHILL_3PARTY_3PARTY_SHOW', thirdparty) -%} + + {{ _self.raw(thirdparty) }} + + {%- else -%} + {{ _self.raw(thirdparty) }} + {%- endif -%} + {%- if addEntity -%} + {{ 'Third party'|trans }} + {%- endif -%} +

    + + {# AVANT +
    + {{ _self.raw(thirdparty) }} +
    +
    + {% for type in thirdparty.type %} + + {{ ('chill_3party.key_label.'~type)|trans }} + + {% endfor %} +
    + {% if thirdparty.comment is not empty %} +
    + {{ thirdparty.comment }} +
    + {% endif %} + {% if thirdparty.address %} +
    +
    + + {% if thirdparty.address.streetAddress1 %}

    {{ thirdparty.address.streetAddress1 }}

    {% endif %} + {% if thirdparty.address.streetAddress2 is not empty %}

    {{ thirdparty.address.streetAddress2 }}

    {% endif %} + {% if thirdparty.address.postCode is not empty %} +

    {{ thirdparty.address.postCode.code }} {{ thirdparty.address.postCode.name }}

    +

    {{ thirdparty.address.postCode.country.name|localize_translatable_string }}

    + {% endif %} +
    + + {%- if options['with_valid_from'] is defined and options['with_valid_from'] == true -%} + {{ 'Since %date%'|trans( { '%date%' : thirdparty.address.validFrom|format_date('long') } ) }} + {%- endif -%} +
    + {% endif %} + {% if thirdparty.email or thirdparty.telephone is not empty %} + + {% endif %} + #} + + {#- tricks to remove easily whitespace after template -#} + {%- if true -%}
    {%- endif -%} +{% endmacro label %} + +{%- if display == 'raw' -%} + {{ _self.raw(thirdparty) }} +{%- endif -%} + +{%- if display == 'label' -%} + {{ _self.label(thirdparty, addLink, addEntity, addInfo, options) }} +{%- endif -%} + +{%- if display == 'row' -%} +
    + {{ _self.label(thirdparty, addLink, addEntity, addInfo, options) }} +
    +{%- endif -%} + +{%- if display == 'bloc' -%} +
    +
    +
    + {{ _self.label(thirdparty, addLink, addEntity, addInfo, options) }} +
    +
    + +
      +
    • + +
    • +
    +
    +
    +
    +{%- endif -%} diff --git a/src/Bundle/ChillThirdPartyBundle/Resources/views/ThirdParty/_render.html.twig b/src/Bundle/ChillThirdPartyBundle/Resources/views/ThirdParty/_render.html.twig deleted file mode 100644 index 626b556ee..000000000 --- a/src/Bundle/ChillThirdPartyBundle/Resources/views/ThirdParty/_render.html.twig +++ /dev/null @@ -1,52 +0,0 @@ -{# template to render a person #} -{%- if options['only_denomination'] == true -%} -
    - {{ contact.name }} -
    - -{%- else -%} -
    - -
    - {{ contact.name }} -
    -
    - {% for type in contact.type %} - - {{ ('chill_3party.key_label.'~type)|trans }} - - {% endfor %} -
    - {% if contact.comment is not empty %} -
    - {{ contact.comment }} -
    - {% endif %} - {% if contact.address %} -
    -
    - - {% if contact.address.streetAddress1 %}

    {{ contact.address.streetAddress1 }}

    {% endif %} - {% if contact.address.streetAddress2 is not empty %}

    {{ contact.address.streetAddress2 }}

    {% endif %} - {% if contact.address.postCode is not empty %} -

    {{ contact.address.postCode.code }} {{ contact.address.postCode.name }}

    -

    {{ contact.address.postCode.country.name|localize_translatable_string }}

    - {% endif %} -
    - {%- if options['with_valid_from'] == true -%} - {{ 'Since %date%'|trans( { '%date%' : contact.address.validFrom|format_date('long') } ) }} - {%- endif -%} -
    - {% endif %} - {% if contact.email or contact.telephone is not empty %} - - {% endif %} -
    -{%- endif -%} diff --git a/src/Bundle/ChillThirdPartyBundle/Templating/Entity/ThirdPartyRender.php b/src/Bundle/ChillThirdPartyBundle/Templating/Entity/ThirdPartyRender.php index be2f82cb5..aea8cd45a 100644 --- a/src/Bundle/ChillThirdPartyBundle/Templating/Entity/ThirdPartyRender.php +++ b/src/Bundle/ChillThirdPartyBundle/Templating/Entity/ThirdPartyRender.php @@ -2,7 +2,7 @@ /* * Chill is a software for social workers * - * Copyright (C) 2014-2020 , Champs Libres Cooperative SCRLFS, + * Copyright (C) 2014-2020 , Champs Libres Cooperative SCRLFS, * * * This program is free software: you can redistribute it and/or modify @@ -25,7 +25,7 @@ use Chill\ThirdPartyBundle\Entity\ThirdParty; use Symfony\Bridge\Twig\TwigEngine; /** - * + * * */ class ThirdPartyRender extends AbstractChillEntityRender @@ -35,37 +35,36 @@ class ThirdPartyRender extends AbstractChillEntityRender * @var TwigEngine */ protected $templating; - + public function __construct(TwigEngine $templating) { $this->templating = $templating; } - + /** - * + * * @param ThirdParty $entity * @param array $options * @return string */ public function renderBox($entity, array $options): string { - $params = \array_merge( - [ 'with_valid_from' => true ], - $options - ); - return $this->getDefaultOpeningBox('_3party'). - $this->templating->render('@ChillThirdParty/ThirdParty/_render.html.twig', [ - 'contact' => $entity, - 'options' => $params + $this->templating->render('@ChillThirdParty/Entity/thirdparty.html.twig', [ + 'thirdparty' => $entity, + 'with_valid_from' => $options['with_valid_from'] ?? true, + 'addLink' => $options['addLink'] ?? false, + 'addEntity' => $options['addEntity'] ?? false, + 'addInfo' => $options['addInfo'] ?? false, + 'display' => $options['display'] ?? 'raw', + 'options' => $options ]). $this->getDefaultClosingBox(); - } /** - * + * * @param ThirdParty $entity * @param array $options * @return string From 57a8b49f49fb7b430f89a44462accff71c2f20c6 Mon Sep 17 00:00:00 2001 From: Mathieu Jaumotte Date: Wed, 28 Jul 2021 11:39:27 +0200 Subject: [PATCH 28/52] entity render: options, html classes, corrections note: span.chill-entity tag is replaced by section.chill-entity tag. because some cases are not valid html : * span.chill-entity > div * span.badge > div.chill-entity --- .../Entity/AbstractChillEntityRender.php | 4 +- .../public/chill/scss/render_box.scss | 21 ++++--- .../views/AccompanyingCourse/index.html.twig | 32 ++++++---- .../Resources/views/Entity/person.html.twig | 63 +++++++++---------- .../views/Person/list_with_period.html.twig | 2 +- .../Templating/Entity/PersonRender.php | 24 ++++--- .../Resources/public/chill/thirdparty.scss | 22 ++++--- .../views/Entity/thirdparty.html.twig | 50 ++++++++------- .../Templating/Entity/ThirdPartyRender.php | 35 ++++++----- 9 files changed, 141 insertions(+), 112 deletions(-) diff --git a/src/Bundle/ChillMainBundle/Templating/Entity/AbstractChillEntityRender.php b/src/Bundle/ChillMainBundle/Templating/Entity/AbstractChillEntityRender.php index d88c4b86f..c9b06a883 100644 --- a/src/Bundle/ChillMainBundle/Templating/Entity/AbstractChillEntityRender.php +++ b/src/Bundle/ChillMainBundle/Templating/Entity/AbstractChillEntityRender.php @@ -28,11 +28,11 @@ abstract class AbstractChillEntityRender implements ChillEntityRenderInterface { protected function getDefaultOpeningBox($classSuffix): string { - return ''; + return '
    '; } protected function getDefaultClosingBox(): string { - return ''; + return '
    '; } } diff --git a/src/Bundle/ChillPersonBundle/Resources/public/chill/scss/render_box.scss b/src/Bundle/ChillPersonBundle/Resources/public/chill/scss/render_box.scss index 7f1773710..078f96253 100644 --- a/src/Bundle/ChillPersonBundle/Resources/public/chill/scss/render_box.scss +++ b/src/Bundle/ChillPersonBundle/Resources/public/chill/scss/render_box.scss @@ -1,9 +1,14 @@ -div.chill-entity { - &.person { - &.label { - h3.denomination { - font-size: 1.3em; - font-weight: 700; +section.chill-entity { + // have no effect for render label, row, bloc + display: inline; + + &.entity-person { + div.entity-label { + div.denomination { + &.h3 { + font-size: 1.3em; + font-weight: 700; + } a { text-decoration: none; } @@ -14,7 +19,7 @@ div.chill-entity { } p.moreinfo {} } - &.row {} - &.bloc {} + div.entity-row {} + div.entity-bloc {} } } diff --git a/src/Bundle/ChillPersonBundle/Resources/views/AccompanyingCourse/index.html.twig b/src/Bundle/ChillPersonBundle/Resources/views/AccompanyingCourse/index.html.twig index 03f5bb379..ce1dbe56d 100644 --- a/src/Bundle/ChillPersonBundle/Resources/views/AccompanyingCourse/index.html.twig +++ b/src/Bundle/ChillPersonBundle/Resources/views/AccompanyingCourse/index.html.twig @@ -226,22 +226,30 @@ {% else %}
    {% for r in accompanyingCourse.resources %} -
    - {% if r.person %} - {{ r.person|chill_entity_render_box({ - 'display': 'bloc', 'addLink': true, 'addEntity': true, 'addInfo': true - }) }} + {# TEST + {{ r.person|chill_entity_render_box({ + 'render': 'label', 'addLink': true, 'addInfo': true, 'hLevel': '1' + }) }} - {% endif %} - {% if r.thirdParty %} + + {{ r.person|chill_entity_render_box({'render': 'raw'}) }} + + #} - {{ r.thirdParty|chill_entity_render_box({ - 'display': 'bloc', 'addLink': true, 'addEntity': true, 'addInfo': true - }) }} +
    + {% if r.person %} + {{ r.person|chill_entity_render_box({ + 'render': 'bloc', 'addLink': true, 'addEntity': true, 'addInfo': true + }) }} + {% endif %} + {% if r.thirdParty %} + {{ r.thirdParty|chill_entity_render_box({ + 'render': 'bloc', 'addLink': true, 'addEntity': true, 'addInfo': true + }) }} + {% endif %} +
    - {% endif %} -
    {% endfor %}
    {% endif %} diff --git a/src/Bundle/ChillPersonBundle/Resources/views/Entity/person.html.twig b/src/Bundle/ChillPersonBundle/Resources/views/Entity/person.html.twig index a7ffc1775..3368d91af 100644 --- a/src/Bundle/ChillPersonBundle/Resources/views/Entity/person.html.twig +++ b/src/Bundle/ChillPersonBundle/Resources/views/Entity/person.html.twig @@ -1,56 +1,53 @@ {# Template to render a person + * render [raw|label|row|bloc] OPTIONS - * display [raw|label|row|bloc] * addAltNames bool * addLink bool * addEntity bool * addInfo bool + * hLevel integer #} -{% macro raw(person, addAltNames) %} +{% macro raw(person, options) %} {{ person.firstName }} {{ person.lastName }} - {%- if addAltNames -%} + {%- if options['addAltNames'] -%} {%- for n in person.altNames -%} {%- if loop.first -%}({% else %} {%- endif -%} - - {{- n.label -}} - + + {{- n.label -}} + {%- if loop.last -%}){%- endif -%} {%- endfor -%} {%- endif -%} {% endmacro raw %} -{% macro label(person, addLink, addAltNames, addEntity, addInfo) %} -
    -

    - {%- if addLink and is_granted('CHILL_PERSON_SEE', person) -%} +{% macro label(person, options) %} +
    + +
    + {%- if options['addLink'] and is_granted('CHILL_PERSON_SEE', person) -%} - {{ _self.raw(person, addAltNames) }} + {{ _self.raw(person, options) }} {%- else -%} - {{ _self.raw(person, addAltNames) }} + {{ _self.raw(person, options) }} {%- endif -%} - {%- if addEntity -%} + {%- if options['addEntity'] -%} {{ 'Person'|trans }} {%- endif -%} -

    - {%- if addInfo -%} - {% set born = (person.gender == 'woman') ? 'née le ': 'né le ' %} +
    + {%- if options['addInfo'] -%} {% set gender = (person.gender == 'woman') ? 'fa-venus' : (person.gender == 'man') ? 'fa-mars' : 'fa-neuter' %} {% set genderTitle = (person.gender == 'woman') ? 'woman' : (person.gender == 'man') ? 'man' : 'neuter' %}

    - {{ born|trans }} -

    {%- endif -%} {#- tricks to remove easily whitespace after template -#} @@ -58,25 +55,25 @@ {% endmacro label %} -{%- if display == 'raw' -%} - {{ _self.raw(person, addAltNames) }} +{%- if render == 'raw' -%} + {{ _self.raw(person, options) }} {%- endif -%} -{%- if display == 'label' -%} - {{ _self.label(person, addLink, addAltNames, addEntity, addInfo) }} +{%- if render == 'label' -%} + {{ _self.label(person, options) }} {%- endif -%} -{%- if display == 'row' -%} -
    - {{ _self.label(person, addLink, addAltNames, addEntity, addInfo) }} +{%- if render == 'row' -%} +
    + {{ _self.label(person, options) }}
    {%- endif -%} -{%- if display == 'bloc' -%} -
    +{%- if render == 'bloc' -%} +
    - {{ _self.label(person, addLink, addAltNames, addEntity, addInfo) }} + {{ _self.label(person, options) }}
      diff --git a/src/Bundle/ChillPersonBundle/Resources/views/Person/list_with_period.html.twig b/src/Bundle/ChillPersonBundle/Resources/views/Person/list_with_period.html.twig index 91a905cc1..5c0d7da78 100644 --- a/src/Bundle/ChillPersonBundle/Resources/views/Person/list_with_period.html.twig +++ b/src/Bundle/ChillPersonBundle/Resources/views/Person/list_with_period.html.twig @@ -46,7 +46,7 @@
      {{ person|chill_entity_render_box({ - 'display': 'label', 'addLink': true, 'addInfo': true + 'render': 'label', 'addLink': true, 'addInfo': true }) }}
      diff --git a/src/Bundle/ChillPersonBundle/Templating/Entity/PersonRender.php b/src/Bundle/ChillPersonBundle/Templating/Entity/PersonRender.php index 353d05ecf..1eea36cdf 100644 --- a/src/Bundle/ChillPersonBundle/Templating/Entity/PersonRender.php +++ b/src/Bundle/ChillPersonBundle/Templating/Entity/PersonRender.php @@ -52,16 +52,22 @@ class PersonRender extends AbstractChillEntityRender */ public function renderBox($person, array $options): string { - return $this->engine->render('@ChillPerson/Entity/person.html.twig', - [ + $params = [ + 'addAltNames' => $this->configAltNamesHelper->hasAltNames(), + 'addLink' => $options['addLink'] ?? false, + 'addEntity' => $options['addEntity'] ?? false, + 'addInfo' => $options['addInfo'] ?? false, + 'hLevel' => $options['hLevel'] ?? 3, + ]; + dump($params); + return + $this->getDefaultOpeningBox('person') . + $this->engine->render('@ChillPerson/Entity/person.html.twig', [ 'person' => $person, - 'addAltNames' => $this->configAltNamesHelper->hasAltNames(), - 'addLink' => $options['addLink'] ?? false, - 'addEntity' => $options['addEntity'] ?? false, - 'addInfo' => $options['addInfo'] ?? false, - 'display' => $options['display'] ?? 'raw' - ] - ); + 'render' => $options['render'] ?? 'raw', + 'options' => $params + ]) . + $this->getDefaultClosingBox(); } /** diff --git a/src/Bundle/ChillThirdPartyBundle/Resources/public/chill/thirdparty.scss b/src/Bundle/ChillThirdPartyBundle/Resources/public/chill/thirdparty.scss index 2efe06c5e..454a5b106 100644 --- a/src/Bundle/ChillThirdPartyBundle/Resources/public/chill/thirdparty.scss +++ b/src/Bundle/ChillThirdPartyBundle/Resources/public/chill/thirdparty.scss @@ -1,9 +1,11 @@ -div.chill-entity { - &.thirdparty { - &.label { - h3.denomination { - font-size: 1.3em; - font-weight: 700; +section.chill-entity { + &.entity-thirdparty { + div.entity-label { + div.denomination { + &.h3 { + font-size: 1.3em; + font-weight: 700; + } a { text-decoration: none; } @@ -12,10 +14,12 @@ div.chill-entity { margin-left: 0.3em; } } - p.moreinfo {} + p.moreinfo { + span.company, span.acronym {} + } } - &.row {} - &.bloc {} + div.entity-row {} + div.entity-bloc {} /* diff --git a/src/Bundle/ChillThirdPartyBundle/Resources/views/Entity/thirdparty.html.twig b/src/Bundle/ChillThirdPartyBundle/Resources/views/Entity/thirdparty.html.twig index 3f665aa26..cdcf53a0b 100644 --- a/src/Bundle/ChillThirdPartyBundle/Resources/views/Entity/thirdparty.html.twig +++ b/src/Bundle/ChillThirdPartyBundle/Resources/views/Entity/thirdparty.html.twig @@ -1,36 +1,44 @@ {# Template to render a thirdparty + * render [raw|label|row|bloc] OPTIONS - * display [raw|label|row|bloc] * with_valid_from bool * addAltNames bool * addLink bool * addEntity bool * addInfo bool + * hLevel integer #} -{% macro raw(thirdparty) %} +{% macro raw(thirdparty, options) %} {{ thirdparty.name }} {% endmacro raw %} -{% macro label(thirdparty, addLink, addEntity, addInfo, options) %} -
      +{% macro label(thirdparty, options) %} +
      -

      - {%- if addLink and is_granted('CHILL_3PARTY_3PARTY_SHOW', thirdparty) -%} +
      + {%- if options['addLink'] and is_granted('CHILL_3PARTY_3PARTY_SHOW', thirdparty) -%} - {{ _self.raw(thirdparty) }} + {{ _self.raw(thirdparty, options) }} {%- else -%} - {{ _self.raw(thirdparty) }} + {{ _self.raw(thirdparty, options) }} {%- endif -%} - {%- if addEntity -%} + {%- if options['addEntity'] -%} {{ 'Third party'|trans }} {%- endif -%} -

      +
      + {%- if options['addInfo'] -%} +

      {# + {{ thirdparty.nameCompany }} + {{ thirdparty.acronym }} + #} plus d'infos +

      + {%- endif -%} {# AVANT
      - {{ _self.raw(thirdparty) }} + {{ _self.raw(thirdparty, options) }}
      {% for type in thirdparty.type %} @@ -77,25 +85,25 @@ {%- if true -%}
      {%- endif -%} {% endmacro label %} -{%- if display == 'raw' -%} - {{ _self.raw(thirdparty) }} +{%- if render == 'raw' -%} + {{ _self.raw(thirdparty, options) }} {%- endif -%} -{%- if display == 'label' -%} - {{ _self.label(thirdparty, addLink, addEntity, addInfo, options) }} +{%- if render == 'label' -%} + {{ _self.label(thirdparty, options) }} {%- endif -%} -{%- if display == 'row' -%} -
      - {{ _self.label(thirdparty, addLink, addEntity, addInfo, options) }} +{%- if render == 'row' -%} +
      + {{ _self.label(thirdparty, options) }}
      {%- endif -%} -{%- if display == 'bloc' -%} -
      +{%- if render == 'bloc' -%} +
      - {{ _self.label(thirdparty, addLink, addEntity, addInfo, options) }} + {{ _self.label(thirdparty, options) }}
        diff --git a/src/Bundle/ChillThirdPartyBundle/Templating/Entity/ThirdPartyRender.php b/src/Bundle/ChillThirdPartyBundle/Templating/Entity/ThirdPartyRender.php index aea8cd45a..00f7effd3 100644 --- a/src/Bundle/ChillThirdPartyBundle/Templating/Entity/ThirdPartyRender.php +++ b/src/Bundle/ChillThirdPartyBundle/Templating/Entity/ThirdPartyRender.php @@ -22,7 +22,7 @@ namespace Chill\ThirdPartyBundle\Templating\Entity; use Chill\MainBundle\Templating\Entity\AbstractChillEntityRender; use Chill\ThirdPartyBundle\Entity\ThirdParty; -use Symfony\Bridge\Twig\TwigEngine; +use Symfony\Component\Templating\EngineInterface; /** * @@ -30,15 +30,12 @@ use Symfony\Bridge\Twig\TwigEngine; */ class ThirdPartyRender extends AbstractChillEntityRender { - /** - * - * @var TwigEngine - */ - protected $templating; - public function __construct(TwigEngine $templating) + protected EngineInterface $engine; + + public function __construct(EngineInterface $engine) { - $this->templating = $templating; + $this->engine = $engine; } /** @@ -49,17 +46,21 @@ class ThirdPartyRender extends AbstractChillEntityRender */ public function renderBox($entity, array $options): string { + $params = [ + 'with_valid_from' => $options['with_valid_from'] ?? true, + 'addLink' => $options['addLink'] ?? false, + 'addEntity' => $options['addEntity'] ?? false, + 'addInfo' => $options['addInfo'] ?? false, + 'hLevel' => $options['hLevel'] ?? 3, + ]; + return - $this->getDefaultOpeningBox('_3party'). - $this->templating->render('@ChillThirdParty/Entity/thirdparty.html.twig', [ + $this->getDefaultOpeningBox('thirdparty') . + $this->engine->render('@ChillThirdParty/Entity/thirdparty.html.twig', [ 'thirdparty' => $entity, - 'with_valid_from' => $options['with_valid_from'] ?? true, - 'addLink' => $options['addLink'] ?? false, - 'addEntity' => $options['addEntity'] ?? false, - 'addInfo' => $options['addInfo'] ?? false, - 'display' => $options['display'] ?? 'raw', - 'options' => $options - ]). + 'render' => $options['render'] ?? 'raw', + 'options' => $params + ]) . $this->getDefaultClosingBox(); } From 50e9a06e4959b8e14d9eab82aa2974d16269667a Mon Sep 17 00:00:00 2001 From: Mathieu Jaumotte Date: Wed, 28 Jul 2021 12:59:03 +0200 Subject: [PATCH 29/52] adding a responsive breakpoints debug flag --- .../public/module/bootstrap/bootstrap.scss | 1 + .../module/bootstrap/custom/_debug.scss | 19 +++++++++++++++++++ .../Resources/views/Layout/_debug.html.twig | 1 + .../Resources/views/layout.html.twig | 3 +++ .../Templating/Entity/PersonRender.php | 2 +- 5 files changed, 25 insertions(+), 1 deletion(-) create mode 100644 src/Bundle/ChillMainBundle/Resources/public/module/bootstrap/custom/_debug.scss create mode 100644 src/Bundle/ChillMainBundle/Resources/views/Layout/_debug.html.twig diff --git a/src/Bundle/ChillMainBundle/Resources/public/module/bootstrap/bootstrap.scss b/src/Bundle/ChillMainBundle/Resources/public/module/bootstrap/bootstrap.scss index 30182b1f2..19da697bd 100644 --- a/src/Bundle/ChillMainBundle/Resources/public/module/bootstrap/bootstrap.scss +++ b/src/Bundle/ChillMainBundle/Resources/public/module/bootstrap/bootstrap.scss @@ -59,3 +59,4 @@ // CHILL custom @import "custom"; +@import "custom/_debug"; diff --git a/src/Bundle/ChillMainBundle/Resources/public/module/bootstrap/custom/_debug.scss b/src/Bundle/ChillMainBundle/Resources/public/module/bootstrap/custom/_debug.scss new file mode 100644 index 000000000..61d66e53d --- /dev/null +++ b/src/Bundle/ChillMainBundle/Resources/public/module/bootstrap/custom/_debug.scss @@ -0,0 +1,19 @@ +body { + position: relative; + div.responsive { + position: fixed; + top: 0; + left: 50%; + background-color: #4a4d50; + color: white; + padding: 0.5em; + z-index: 10000; + + @media (max-width: 576px) { &::after { content: 'XS'; }} + @media (min-width: 576px) { &::after { content: 'SM'; }} + @media (min-width: 768px) { &::after { content: 'MD'; }} + @media (min-width: 992px) { &::after { content: 'LG'; }} + @media (min-width: 1200px) { &::after { content: 'XL'; }} + @media (min-width: 1400px) { &::after { content: 'XXL'; }} + } +} diff --git a/src/Bundle/ChillMainBundle/Resources/views/Layout/_debug.html.twig b/src/Bundle/ChillMainBundle/Resources/views/Layout/_debug.html.twig new file mode 100644 index 000000000..b0d7729cd --- /dev/null +++ b/src/Bundle/ChillMainBundle/Resources/views/Layout/_debug.html.twig @@ -0,0 +1 @@ +
        diff --git a/src/Bundle/ChillMainBundle/Resources/views/layout.html.twig b/src/Bundle/ChillMainBundle/Resources/views/layout.html.twig index e495eae96..23be470e0 100644 --- a/src/Bundle/ChillMainBundle/Resources/views/layout.html.twig +++ b/src/Bundle/ChillMainBundle/Resources/views/layout.html.twig @@ -38,6 +38,9 @@ + {# + {{ include('@ChillMain/Layout/_debug.html.twig') }} + #} {{ include('@ChillMain/Layout/_header.html.twig') }} {% block top_banner %}{# diff --git a/src/Bundle/ChillPersonBundle/Templating/Entity/PersonRender.php b/src/Bundle/ChillPersonBundle/Templating/Entity/PersonRender.php index 1eea36cdf..320d78d7a 100644 --- a/src/Bundle/ChillPersonBundle/Templating/Entity/PersonRender.php +++ b/src/Bundle/ChillPersonBundle/Templating/Entity/PersonRender.php @@ -59,7 +59,7 @@ class PersonRender extends AbstractChillEntityRender 'addInfo' => $options['addInfo'] ?? false, 'hLevel' => $options['hLevel'] ?? 3, ]; - dump($params); + return $this->getDefaultOpeningBox('person') . $this->engine->render('@ChillPerson/Entity/person.html.twig', [ From 81752befcf0b6d13490791070545bf1a6e6b23a9 Mon Sep 17 00:00:00 2001 From: Mathieu Jaumotte Date: Wed, 28 Jul 2021 14:15:27 +0200 Subject: [PATCH 30/52] render_box with 'bloc' use bootstrap responsive breakpoints for columns, mixed with flex-bloc cascade for growing and vertical align blocs. --- .../views/Activity/concernedGroups.html.twig | 2 +- .../Resources/public/chill/chillmain.scss | 35 ++-------- .../Resources/public/chill/scss/mixins.scss | 14 ++++ .../public/chill/scss/render_box.scss | 10 +++ .../views/AccompanyingCourse/index.html.twig | 54 ++++++--------- .../Resources/views/Entity/person.html.twig | 67 +++++++++---------- .../Resources/public/chill/thirdparty.scss | 2 + .../views/Entity/thirdparty.html.twig | 65 +++++++++--------- 8 files changed, 121 insertions(+), 128 deletions(-) create mode 100644 src/Bundle/ChillMainBundle/Resources/public/chill/scss/mixins.scss diff --git a/src/Bundle/ChillActivityBundle/Resources/views/Activity/concernedGroups.html.twig b/src/Bundle/ChillActivityBundle/Resources/views/Activity/concernedGroups.html.twig index 4985ea1f7..92b1b3ff4 100644 --- a/src/Bundle/ChillActivityBundle/Resources/views/Activity/concernedGroups.html.twig +++ b/src/Bundle/ChillActivityBundle/Resources/views/Activity/concernedGroups.html.twig @@ -60,7 +60,7 @@
      • - {{ item|chill_entity_render_box({'only_denomination': true}) }} + {{ item|chill_entity_render_box({'render': 'raw'}) }}
      • diff --git a/src/Bundle/ChillMainBundle/Resources/public/chill/chillmain.scss b/src/Bundle/ChillMainBundle/Resources/public/chill/chillmain.scss index 3fcdb9da1..a42d1dae0 100644 --- a/src/Bundle/ChillMainBundle/Resources/public/chill/chillmain.scss +++ b/src/Bundle/ChillMainBundle/Resources/public/chill/chillmain.scss @@ -1,13 +1,9 @@ -/* - * NOTE 2021.04 - * scss/chillmain.scss is the main sass file for the new chill.2 - * scratch will be replaced by bootstrap, please avoid to edit in modules/scratch/_custom.scss - * - * when possible, try to use bootstrap html class -*/ - +// Need to access bootstrap variables @import '~ChillMainAssets/module/bootstrap/bootstrap'; +// Chill mixins +@import './scss/mixins'; + /* * Specific rules */ @@ -68,23 +64,13 @@ div.flex-table { color: var(--bs-chill-blue); } div.item-bloc { - // We use box-shadow instead of border - // to avoid to manage border double-width - // when blocs are resized for small screen ! - // Then we can simulate border-collapse: collapse (table) - box-shadow: - 1px 0 0 0 var(--bs-dark), - 0 1px 0 0 var(--bs-dark), - 1px 1px 0 0 var(--bs-dark), /* fix the corner */ - 1px 0 0 0 var(--bs-dark) inset, - 0 1px 0 0 var(--bs-dark) inset; + @include border-collapse; } } /* * Bloc appearance */ -/* div.flex-bloc { box-sizing: border-box; display: flex; @@ -94,7 +80,7 @@ div.flex-bloc { align-content: stretch; div.item-bloc { - flex-grow: 0; flex-shrink: 1; flex-basis: 33%; + flex-grow: 0; flex-shrink: 1; flex-basis: auto; margin: 0; padding: 1em; display: flex; @@ -127,15 +113,8 @@ div.flex-bloc { } } } - @media only screen and (max-width: 945px) { margin: auto -0.2em; } - @media only screen and (max-width: 935px) { margin: auto -0.5em; } - @media only screen and (max-width: 920px) { margin: auto -0.9em; } - @media only screen and (max-width: 900px) { - flex-direction: column; - margin: auto 0; - } } - */ + /* diff --git a/src/Bundle/ChillMainBundle/Resources/public/chill/scss/mixins.scss b/src/Bundle/ChillMainBundle/Resources/public/chill/scss/mixins.scss new file mode 100644 index 000000000..22e1d310e --- /dev/null +++ b/src/Bundle/ChillMainBundle/Resources/public/chill/scss/mixins.scss @@ -0,0 +1,14 @@ + +// We use box-shadow instead of border +// to avoid to manage border double-width +// Then we can simulate border-collapse: collapse (table) + +@mixin border-collapse { + box-shadow: + 1px 0 0 0 var(--bs-dark), + 0 1px 0 0 var(--bs-dark), + 1px 1px 0 0 var(--bs-dark), /* fix the corner */ + 1px 0 0 0 var(--bs-dark) inset, + 0 1px 0 0 var(--bs-dark) inset; +} + diff --git a/src/Bundle/ChillPersonBundle/Resources/public/chill/scss/render_box.scss b/src/Bundle/ChillPersonBundle/Resources/public/chill/scss/render_box.scss index 078f96253..2ea115517 100644 --- a/src/Bundle/ChillPersonBundle/Resources/public/chill/scss/render_box.scss +++ b/src/Bundle/ChillPersonBundle/Resources/public/chill/scss/render_box.scss @@ -1,3 +1,6 @@ +@import '~ChillMainAssets/module/bootstrap/bootstrap'; +@import '~ChillMainAssets/chill/scss/mixins'; + section.chill-entity { // have no effect for render label, row, bloc display: inline; @@ -22,4 +25,11 @@ section.chill-entity { div.entity-row {} div.entity-bloc {} } + + // don't break flex cascade with section tag + div.flex-bloc & { + display: flex; + flex-grow: 1; flex-shrink: 1; flex-basis: auto; + } } + diff --git a/src/Bundle/ChillPersonBundle/Resources/views/AccompanyingCourse/index.html.twig b/src/Bundle/ChillPersonBundle/Resources/views/AccompanyingCourse/index.html.twig index ce1dbe56d..ccce0df55 100644 --- a/src/Bundle/ChillPersonBundle/Resources/views/AccompanyingCourse/index.html.twig +++ b/src/Bundle/ChillPersonBundle/Resources/views/AccompanyingCourse/index.html.twig @@ -219,40 +219,30 @@
      {% endif %} -

      {{ 'Resources'|trans }}

      - {% if accompanyingCourse.resources|length == 0 %} -

      {{ 'Any resource for this accompanying course'|trans }}

      - {% else %} -
      - {% for r in accompanyingCourse.resources %} - - {# TEST - {{ r.person|chill_entity_render_box({ - 'render': 'label', 'addLink': true, 'addInfo': true, 'hLevel': '1' - }) }} - - - {{ r.person|chill_entity_render_box({'render': 'raw'}) }} - - #} - -
      - {% if r.person %} - {{ r.person|chill_entity_render_box({ - 'render': 'bloc', 'addLink': true, 'addEntity': true, 'addInfo': true - }) }} - {% endif %} - {% if r.thirdParty %} - {{ r.thirdParty|chill_entity_render_box({ - 'render': 'bloc', 'addLink': true, 'addEntity': true, 'addInfo': true - }) }} - {% endif %} +
      +

      {{ 'Resources'|trans }}

      + {% if accompanyingCourse.resources|length == 0 %} +

      {{ 'Any resource for this accompanying course'|trans }}

      + {% else %} +
      + {% for r in accompanyingCourse.resources %} +
      + {% if r.person %} + {{ r.person|chill_entity_render_box({ + 'render': 'bloc', 'addLink': true, 'addEntity': true, 'addInfo': true + }) }} + {% endif %} + {% if r.thirdParty %} + {{ r.thirdParty|chill_entity_render_box({ + 'render': 'bloc', 'addLink': true, 'addEntity': true, 'addInfo': true + }) }} + {% endif %} +
      + {% endfor %}
      - - {% endfor %} -
      - {% endif %} + {% endif %} +

      {{ 'Social actions'|trans }}

      diff --git a/src/Bundle/ChillPersonBundle/Resources/views/Entity/person.html.twig b/src/Bundle/ChillPersonBundle/Resources/views/Entity/person.html.twig index 3368d91af..9cf37c8ac 100644 --- a/src/Bundle/ChillPersonBundle/Resources/views/Entity/person.html.twig +++ b/src/Bundle/ChillPersonBundle/Resources/views/Entity/person.html.twig @@ -8,6 +8,7 @@ * addInfo bool * hLevel integer #} + {% macro raw(person, options) %} {{ person.firstName }} {{ person.lastName }} @@ -70,42 +71,40 @@ {%- endif -%} {%- if render == 'bloc' -%} -
      -
      -
      - {{ _self.label(person, options) }} -
      -
      -
        -
      • - {% if person.mobilenumber %} - {{ person.mobilenumber }} +
        +
        + {{ _self.label(person, options) }} +
        +
        +
          +
        • + {% if person.mobilenumber %} + {{ person.mobilenumber }} + {% else %} + + {% if person.phonenumber %} + {{ person.phonenumber }} {% else %} - - {% if person.phonenumber %} - {{ person.phonenumber }} - {% else %} - {{ 'No data given'|trans }} - {% endif %} + {{ 'No data given'|trans }} {% endif %} -
        • -
        • - - {%- if person.lastAddress is not empty -%} - {{ person.getLastAddress|chill_entity_render_box({'with_valid_from': false}) }} - {%- else -%} - {{ 'No address given'|trans }} - {%- endif -%} -
        • -
        - {%- if is_granted('CHILL_PERSON_SEE', person) -%} -
          -
        • -
        • -
        - {%- endif -%} -
        + {% endif %} +
      • +
      • + + {%- if person.lastAddress is not empty -%} + {{ person.getLastAddress|chill_entity_render_box({'with_valid_from': false}) }} + {%- else -%} + {{ 'No address given'|trans }} + {%- endif -%} +
      • +
      + {%- if is_granted('CHILL_PERSON_SEE', person) -%} +
        +
      • +
      • +
      + {%- endif -%}
      {%- endif -%} diff --git a/src/Bundle/ChillThirdPartyBundle/Resources/public/chill/thirdparty.scss b/src/Bundle/ChillThirdPartyBundle/Resources/public/chill/thirdparty.scss index 454a5b106..67cb9a995 100644 --- a/src/Bundle/ChillThirdPartyBundle/Resources/public/chill/thirdparty.scss +++ b/src/Bundle/ChillThirdPartyBundle/Resources/public/chill/thirdparty.scss @@ -1,3 +1,5 @@ +@import '~ChillMainAssets/chill/scss/mixins'; + section.chill-entity { &.entity-thirdparty { div.entity-label { diff --git a/src/Bundle/ChillThirdPartyBundle/Resources/views/Entity/thirdparty.html.twig b/src/Bundle/ChillThirdPartyBundle/Resources/views/Entity/thirdparty.html.twig index cdcf53a0b..361ddc96b 100644 --- a/src/Bundle/ChillThirdPartyBundle/Resources/views/Entity/thirdparty.html.twig +++ b/src/Bundle/ChillThirdPartyBundle/Resources/views/Entity/thirdparty.html.twig @@ -9,6 +9,7 @@ * addInfo bool * hLevel integer #} + {% macro raw(thirdparty, options) %} {{ thirdparty.name }} {% endmacro raw %} @@ -100,39 +101,37 @@ {%- endif -%} {%- if render == 'bloc' -%} -
      -
      -
      - {{ _self.label(thirdparty, options) }} -
      -
      - -
        -
      • - -
      • -
      -
      +
      +
      + {{ _self.label(thirdparty, options) }} +
      +
      + +
        +
      • + +
      • +
      {%- endif -%} From 42784cf584187f60773a55b2d8e425bb7f2bc6b7 Mon Sep 17 00:00:00 2001 From: Mathieu Jaumotte Date: Wed, 28 Jul 2021 16:33:36 +0200 Subject: [PATCH 31/52] split sass sheets, move style cascades --- .../Resources/public/chill/chillmain.scss | 137 +----------------- .../public/chill/scss/flex_table.scss | 127 ++++++++++++++++ .../public/chill/scss/render_box.scss | 13 ++ .../public/chill/scss/render_box.scss | 45 ++---- .../Resources/public/chill/thirdparty.scss | 46 +++--- 5 files changed, 184 insertions(+), 184 deletions(-) create mode 100644 src/Bundle/ChillMainBundle/Resources/public/chill/scss/flex_table.scss create mode 100644 src/Bundle/ChillMainBundle/Resources/public/chill/scss/render_box.scss diff --git a/src/Bundle/ChillMainBundle/Resources/public/chill/chillmain.scss b/src/Bundle/ChillMainBundle/Resources/public/chill/chillmain.scss index a42d1dae0..09f1ee84a 100644 --- a/src/Bundle/ChillMainBundle/Resources/public/chill/chillmain.scss +++ b/src/Bundle/ChillMainBundle/Resources/public/chill/chillmain.scss @@ -1,9 +1,16 @@ // Need to access bootstrap variables +// TO CHECK: load all bootstrap in chill entrypoint ??! @import '~ChillMainAssets/module/bootstrap/bootstrap'; // Chill mixins @import './scss/mixins'; +// Chill entity render box system +@import './scss/render_box'; + +// Chill flex responsive table/block presentation +@import './scss/flex_table'; + /* * Specific rules */ @@ -51,133 +58,3 @@ div.banner { } } } - -/* -* FLEX RESPONSIVE TABLE/BLOCK PRESENTATION -*/ -div.flex-bloc, -div.flex-table { - h2, h3, h4, dl, p { - margin: 0; - } - h2, h3, h4 { - color: var(--bs-chill-blue); - } - div.item-bloc { - @include border-collapse; - } -} - -/* -* Bloc appearance -*/ -div.flex-bloc { - box-sizing: border-box; - display: flex; - flex-direction: row; - flex-wrap: wrap; - align-items: stretch; - align-content: stretch; - - div.item-bloc { - flex-grow: 0; flex-shrink: 1; flex-basis: auto; - margin: 0; - padding: 1em; - display: flex; - flex-direction: column; - - div.item-row { - flex-grow: 1; flex-shrink: 1; flex-basis: auto; - display: flex; - flex-direction: column; - - div.item-col { - &:first-child { - flex-grow: 0; flex-shrink: 0; flex-basis: auto; - } - &:last-child { - flex-grow: 1; flex-shrink: 1; flex-basis: auto; - display: flex; - - .list-content { // ul, dl, or div - } - ul.record_actions { - margin: 0; - align-self: flex-end; - flex-grow: 1; flex-shrink: 0; flex-basis: auto; - li { - margin-right: 5px; - } - } - } - } - } - } -} - - - -/* -* Table appearance -*/ -div.flex-table { - display: flex; - flex-direction: column; - align-items: stretch; - align-content: stretch; - - div.item-bloc { - display: flex; - flex-direction: column; - padding: 1em; - &:nth-child(even) { - background-color: #e6e6e6; - } - - div.item-row { - display: flex; - flex-direction: row; - &:not(:first-child) { - margin-top: 0.5em; - border-top: 1px dotted #0000004f; - padding-top: 0.5em; - flex-direction: column; - } - - div.item-col { - &:first-child { - flex-grow: 0; flex-shrink: 0; flex-basis: 33%; - } - &:last-child { - flex-grow: 1; flex-shrink: 1; flex-basis: auto; - display: flex; - justify-content: flex-end; - - .list-content { // ul, dl, or div - } - ul.record_actions { - margin: 0; - align-self: flex-start; - flex-grow: 1; flex-shrink: 0; flex-basis: auto; - li { - margin-right: 5px; - } - } - } - } - @media only screen and (max-width: 900px) { - flex-direction: column; - div.item-col { - &:last-child { - ul.record_actions { - align-self: flex-end; - } - } - } - } - - // neutralize - div.chill_address div.chill_address_address p { text-indent: 0; } - } - } -} diff --git a/src/Bundle/ChillMainBundle/Resources/public/chill/scss/flex_table.scss b/src/Bundle/ChillMainBundle/Resources/public/chill/scss/flex_table.scss new file mode 100644 index 000000000..3e6cc1fc1 --- /dev/null +++ b/src/Bundle/ChillMainBundle/Resources/public/chill/scss/flex_table.scss @@ -0,0 +1,127 @@ +/* +* FLEX RESPONSIVE TABLE/BLOCK PRESENTATION +*/ +div.flex-bloc, +div.flex-table { + h2, h3, h4, dl, p { + margin: 0; + } + h2, h3, h4 { + color: var(--bs-chill-blue); + } + div.item-bloc { + @include border-collapse; + } +} + +/* +* Bloc appearance +*/ +div.flex-bloc { + box-sizing: border-box; + display: flex; + flex-direction: row; + flex-wrap: wrap; + align-items: stretch; + align-content: stretch; + + div.item-bloc { + flex-grow: 0; flex-shrink: 1; flex-basis: auto; + margin: 0; + padding: 1em; + display: flex; + flex-direction: column; + + div.item-row { + flex-grow: 1; flex-shrink: 1; flex-basis: auto; + display: flex; + flex-direction: column; + + div.item-col { + &:first-child { + flex-grow: 0; flex-shrink: 0; flex-basis: auto; + } + &:last-child { + flex-grow: 1; flex-shrink: 1; flex-basis: auto; + display: flex; + + .list-content { // ul, dl, or div + } + ul.record_actions { + margin: 0; + align-self: flex-end; + flex-grow: 1; flex-shrink: 0; flex-basis: auto; + li { + margin-right: 5px; + } + } + } + } + } + } +} + +/* +* Table appearance +*/ +div.flex-table { + display: flex; + flex-direction: column; + align-items: stretch; + align-content: stretch; + + div.item-bloc { + display: flex; + flex-direction: column; + padding: 1em; + &:nth-child(even) { + background-color: $gray-200; + } + + div.item-row { + display: flex; + flex-direction: row; + &:not(:first-child) { + margin-top: 0.5em; + border-top: 1px dotted #0000004f; + padding-top: 0.5em; + flex-direction: column; + } + + div.item-col { + &:first-child { + flex-grow: 0; flex-shrink: 0; flex-basis: 33%; + } + &:last-child { + flex-grow: 1; flex-shrink: 1; flex-basis: auto; + display: flex; + justify-content: flex-end; + + .list-content { // ul, dl, or div + } + ul.record_actions { + margin: 0; + align-self: flex-start; + flex-grow: 1; flex-shrink: 0; flex-basis: auto; + li { + margin-right: 5px; + } + } + } + } + @media only screen and (max-width: 900px) { + flex-direction: column; + div.item-col { + &:last-child { + ul.record_actions { + align-self: flex-end; + } + } + } + } + + // neutralize + div.chill_address div.chill_address_address p { text-indent: 0; } + } + } +} diff --git a/src/Bundle/ChillMainBundle/Resources/public/chill/scss/render_box.scss b/src/Bundle/ChillMainBundle/Resources/public/chill/scss/render_box.scss new file mode 100644 index 000000000..b26cfbc4a --- /dev/null +++ b/src/Bundle/ChillMainBundle/Resources/public/chill/scss/render_box.scss @@ -0,0 +1,13 @@ +// generic rules +section.chill-entity { + + // display inline for render raw + // have no effect for render label, row, bloc ! + display: inline; + + // don't break flex cascade with section tag + div.flex-bloc & { + display: flex; + flex-grow: 1; flex-shrink: 1; flex-basis: auto; + } +} diff --git a/src/Bundle/ChillPersonBundle/Resources/public/chill/scss/render_box.scss b/src/Bundle/ChillPersonBundle/Resources/public/chill/scss/render_box.scss index 2ea115517..a68b10c0b 100644 --- a/src/Bundle/ChillPersonBundle/Resources/public/chill/scss/render_box.scss +++ b/src/Bundle/ChillPersonBundle/Resources/public/chill/scss/render_box.scss @@ -1,35 +1,22 @@ -@import '~ChillMainAssets/module/bootstrap/bootstrap'; -@import '~ChillMainAssets/chill/scss/mixins'; -section.chill-entity { - // have no effect for render label, row, bloc - display: inline; - - &.entity-person { - div.entity-label { - div.denomination { - &.h3 { - font-size: 1.3em; - font-weight: 700; - } - a { - text-decoration: none; - } - span.firstname, span.lastname, span.altname {} - span.badge { - margin-left: 0.3em; - } +section.chill-entity.entity-person { + div.entity-label { + div.denomination { + &.h3 { + font-size: 1.3em; + font-weight: 700; + } + a { + text-decoration: none; + } + span.firstname, span.lastname, span.altname {} + span.badge { + margin-left: 0.3em; } - p.moreinfo {} } - div.entity-row {} - div.entity-bloc {} - } - - // don't break flex cascade with section tag - div.flex-bloc & { - display: flex; - flex-grow: 1; flex-shrink: 1; flex-basis: auto; + p.moreinfo {} } + div.entity-row {} + div.entity-bloc {} } diff --git a/src/Bundle/ChillThirdPartyBundle/Resources/public/chill/thirdparty.scss b/src/Bundle/ChillThirdPartyBundle/Resources/public/chill/thirdparty.scss index 67cb9a995..b744f7edc 100644 --- a/src/Bundle/ChillThirdPartyBundle/Resources/public/chill/thirdparty.scss +++ b/src/Bundle/ChillThirdPartyBundle/Resources/public/chill/thirdparty.scss @@ -1,30 +1,29 @@ -@import '~ChillMainAssets/chill/scss/mixins'; -section.chill-entity { - &.entity-thirdparty { - div.entity-label { - div.denomination { - &.h3 { - font-size: 1.3em; - font-weight: 700; - } - a { - text-decoration: none; - } - span.name {} - span.badge { - margin-left: 0.3em; - } +/// render_box +section.chill-entity.entity-thirdparty { + div.entity-label { + div.denomination { + &.h3 { + font-size: 1.3em; + font-weight: 700; } - p.moreinfo { - span.company, span.acronym {} + a { + text-decoration: none; + } + span.name {} + span.badge { + margin-left: 0.3em; } } - div.entity-row {} - div.entity-bloc {} + p.moreinfo { + span.company, span.acronym {} + } + } + div.entity-row {} + div.entity-bloc {} +} - -/* +/* AVANT border: 1px solid black; background-color: rgba(255, 255, 255, 0.65); padding: 1em; @@ -80,6 +79,3 @@ section.chill-entity { } } */ - - } -} From 2893b9c726811906b75a025f7ce5b09d02adf6e1 Mon Sep 17 00:00:00 2001 From: Mathieu Jaumotte Date: Wed, 28 Jul 2021 16:48:50 +0200 Subject: [PATCH 32/52] re-indent file --- .../views/AccompanyingCourse/index.html.twig | 276 +++++++++--------- 1 file changed, 135 insertions(+), 141 deletions(-) diff --git a/src/Bundle/ChillPersonBundle/Resources/views/AccompanyingCourse/index.html.twig b/src/Bundle/ChillPersonBundle/Resources/views/AccompanyingCourse/index.html.twig index ccce0df55..13a39b6bc 100644 --- a/src/Bundle/ChillPersonBundle/Resources/views/AccompanyingCourse/index.html.twig +++ b/src/Bundle/ChillPersonBundle/Resources/views/AccompanyingCourse/index.html.twig @@ -21,43 +21,42 @@ {% endif %} {% if withoutHousehold|length > 0 %} -
      -
      - {{ 'Some peoples does not belong to any household currently. Add them to an household soon'|trans }} -
      -
        -
      • - -
      • -
      -
      - -
      -
      - -

      {{ 'household.Select people to move'|trans }}

      -
        - {% for p in withoutHousehold %} -
      • - - {{ p|chill_entity_render_box }} -
      • - {% endfor %} -
      - - - - +
      +
      + {{ 'Some peoples does not belong to any household currently. Add them to an household soon'|trans }} +
        -
      • - -
      • +
      • + +
      - +
      +
      +
      + +

      {{ 'household.Select people to move'|trans }}

      +
        + {% for p in withoutHousehold %} +
      • + + {{ p|chill_entity_render_box }} +
      • + {% endfor %} +
      + + + +
        +
      • + +
      • +
      +
      {% endif %} @@ -129,97 +128,96 @@

      {{ 'Requestor'|trans }}

      {% if accompanyingCourse.requestor == null %} -

      {{ 'Any requestor to this accompanying course'|trans }}

      +

      {{ 'Any requestor to this accompanying course'|trans }}

      {% elseif accompanyingCourse.requestorPerson is not empty %} - {% set r = accompanyingCourse.requestorPerson %} -
      -
      -

      - {{ r.firstname ~ ' ' ~ r.lastname }} - {{ 'Usager' }} -

      -

      - {% set born = (r.gender == 'woman') ? 'née': 'né' %} - {% set gender = (r.gender == 'woman') ? 'fa-venus' : - (r.gender == 'man') ? 'fa-mars' : 'fa-neuter' %} - {% set genderTitle = (r.gender == 'woman') ? 'femme' : - (r.gender == 'homme') ? 'fa-mars' : 'neutre' %} - {{ born ~ ' le ' ~ r.birthdate|format_date('short') }} -

      -
      -
      - -
        + {% set r = accompanyingCourse.requestorPerson %} +
        +
        +

        + {{ r.firstname ~ ' ' ~ r.lastname }} + {{ 'Usager' }} +

        +

        + {% set born = (r.gender == 'woman') ? 'née': 'né' %} + {% set gender = (r.gender == 'woman') ? 'fa-venus' : + (r.gender == 'man') ? 'fa-mars' : 'fa-neuter' %} + {% set genderTitle = (r.gender == 'woman') ? 'femme' : + (r.gender == 'homme') ? 'fa-mars' : 'neutre' %} + {{ born ~ ' le ' ~ r.birthdate|format_date('short') }} +

        +
        +
        + +
        • -
        -
        -
        +
      +
      +
      - {% elseif accompanyingCourse.requestorThirdParty is not empty %} - {% set r = accompanyingCourse.requestorThirdParty %} -
      -
      -

      + {% elseif accompanyingCourse.requestorThirdParty is not empty %} + {% set r = accompanyingCourse.requestorThirdParty %} +
      +
      +

      {{ r.name }} {{ 'Tiers' }} -

      -
      -
      - -
        -
      • - -
      • -
      -
      -
      +

      +
      +
      + +
        +
      • + +
      • +
      +
      +
      {% endif %} -

      {{ 'Resources'|trans }}

      {% if accompanyingCourse.resources|length == 0 %} @@ -247,37 +245,33 @@

      {{ 'Social actions'|trans }}

      - {% for w in works %} -
      -
      -

      {{ 'accompanying_course_work.action'|trans }}

      -

      - {{ w.socialAction|chill_entity_render_box({ 'no-badge': false }) }} -

      -
      + {% for w in works %} +
      +
      +

      {{ 'accompanying_course_work.action'|trans }}

      +

      + {{ w.socialAction|chill_entity_render_box({ 'no-badge': false }) }} +

      +
      -
      - +
      + +
      -
      - {% else %} -

      {{ 'accompanying_course_work.Any work'|trans }}

      - {% endfor %} + {% else %} +

      {{ 'accompanying_course_work.Any work'|trans }}

      + {% endfor %}
      {% block contentActivity %} {% set person = null %} - {% include 'ChillActivityBundle:Activity:list.html.twig' with {'context': 'accompanyingCourse', 'context': 'accompanyingCourse'} %} + {% include 'ChillActivityBundle:Activity:list.html.twig' with { 'context': 'accompanyingCourse' } %} {% endblock %} - {# ==> insert accompanyingCourse vue component #} -
      -
      {% endblock %} From 3637ae6aee1acd021d34ead3d9b7a7abe1112f2a Mon Sep 17 00:00:00 2001 From: Mathieu Jaumotte Date: Wed, 28 Jul 2021 23:41:10 +0200 Subject: [PATCH 33/52] renderbox person and thirdparty on resume accompanyingcourse, flex-bloc and flex-table --- .../Resources/public/chill/chillactivity.scss | 2 +- .../Resources/views/Activity/list.html.twig | 83 +++--- .../_join_household.html.twig | 38 +++ .../views/AccompanyingCourse/index.html.twig | 248 ++++-------------- .../Resources/views/Entity/person.html.twig | 8 +- .../views/Entity/thirdparty.html.twig | 53 +--- 6 files changed, 128 insertions(+), 304 deletions(-) create mode 100644 src/Bundle/ChillPersonBundle/Resources/views/AccompanyingCourse/_join_household.html.twig diff --git a/src/Bundle/ChillActivityBundle/Resources/public/chill/chillactivity.scss b/src/Bundle/ChillActivityBundle/Resources/public/chill/chillactivity.scss index bd67b58ca..3518d1751 100644 --- a/src/Bundle/ChillActivityBundle/Resources/public/chill/chillactivity.scss +++ b/src/Bundle/ChillActivityBundle/Resources/public/chill/chillactivity.scss @@ -6,7 +6,7 @@ //} .activity { - color: $chill-green; + //color: $chill-green; } // exceptions for flex-bloc in concerned-groups diff --git a/src/Bundle/ChillActivityBundle/Resources/views/Activity/list.html.twig b/src/Bundle/ChillActivityBundle/Resources/views/Activity/list.html.twig index ef82a5f4a..f7c0d12b2 100644 --- a/src/Bundle/ChillActivityBundle/Resources/views/Activity/list.html.twig +++ b/src/Bundle/ChillActivityBundle/Resources/views/Activity/list.html.twig @@ -18,57 +18,44 @@ {% else %}
      - + {% for activity in activities %} {% set t = activity.type %}
      - + {% if activity.date %}

      {{ activity.date|format_date('long') }}

      {% endif %} - +
      - {% if t.durationTimeVisible > 0 %} -

      - - {{ activity.durationTime|date('H:i') }} -

      - {% endif %} - + {% if t.durationTimeVisible > 0 %} +

      + + {{ activity.durationTime|date('H:i') }} +

      + {% endif %} {% if activity.travelTime and t.travelTimeVisible %} -

      - - {{ activity.travelTime|date('H:i') }} -

      +

      + + {{ activity.travelTime|date('H:i') }} +

      {% endif %}
      {% if context == 'person' and activity.accompanyingPeriod is not empty %} - {% endif %} - +
        @@ -77,19 +64,19 @@ {{ 'by'|trans }}{{ activity.user.usernameCanonical }} {% endif %} - +
      • {{ activity.type.name | localize_translatable_string }} - + {% if activity.attendee is not null and t.attendeeVisible %} {% if activity.attendee %} - {{ '→ ' ~ 'present'|trans|capitalize }} - {% else %} + {{ '→ ' ~ 'present'|trans|capitalize }} + {% else %} {{ '→ ' ~ 'not present'|trans|capitalize }} {% endif %} {% endif %}
      • - +
      • {{ 'location'|trans ~ ': ' }} Domicile de l'usager @@ -97,7 +84,7 @@ {% if activity.location %}{{ activity.location }}{% endif %} #}
      • - + {%- if t.reasonsVisible -%}
      • {%- if activity.reasons is empty -%} @@ -121,7 +108,7 @@ {%- endif -%}
      • {% endif %} - + {%- if t.socialActionsVisible -%} {% endif %} - +
      • @@ -159,19 +146,19 @@
      - - {% + + {% if activity.comment.comment is not empty or activity.persons|length > 0 or activity.thirdParties|length > 0 - or activity.users|length > 0 + or activity.users|length > 0 %}
      {% include 'ChillActivityBundle:Activity:concernedGroups.html.twig' with {'context': context, 'with_display': 'row', 'entity': activity } %}
      - + {% if activity.comment.comment is not empty %}
      {{ activity.comment|chill_entity_render_box( { 'limit_lines': 3, 'metadata': false } ) }} @@ -179,7 +166,7 @@ {% endif %}
      {% endif %} - +
      {% endfor %}
      diff --git a/src/Bundle/ChillPersonBundle/Resources/views/AccompanyingCourse/_join_household.html.twig b/src/Bundle/ChillPersonBundle/Resources/views/AccompanyingCourse/_join_household.html.twig new file mode 100644 index 000000000..fd0cf373d --- /dev/null +++ b/src/Bundle/ChillPersonBundle/Resources/views/AccompanyingCourse/_join_household.html.twig @@ -0,0 +1,38 @@ +
      +
      + {{ 'Some peoples does not belong to any household currently. Add them to an household soon'|trans }} +
      +
        +
      • + +
      • +
      +
      + +
      +
      + +

      {{ 'household.Select people to move'|trans }}

      +
        + {% for p in withoutHousehold %} +
      • + + {{ p|chill_entity_render_box }} +
      • + {% endfor %} +
      + + + +
        +
      • + +
      • +
      +
      +
      diff --git a/src/Bundle/ChillPersonBundle/Resources/views/AccompanyingCourse/index.html.twig b/src/Bundle/ChillPersonBundle/Resources/views/AccompanyingCourse/index.html.twig index 13a39b6bc..b88f93928 100644 --- a/src/Bundle/ChillPersonBundle/Resources/views/AccompanyingCourse/index.html.twig +++ b/src/Bundle/ChillPersonBundle/Resources/views/AccompanyingCourse/index.html.twig @@ -7,10 +7,10 @@ {% endblock %} {% block content %} -
      +
      {% if 'DRAFT' == accompanyingCourse.step %} -
      +
      {{ 'This accompanying course is still a draft'|trans }} @@ -20,205 +20,61 @@
      {% endif %} - {% if withoutHousehold|length > 0 %} -
      -
      - {{ 'Some peoples does not belong to any household currently. Add them to an household soon'|trans }} -
      -
        -
      • - -
      • -
      -
      -
      -
      - -

      {{ 'household.Select people to move'|trans }}

      -
        - {% for p in withoutHousehold %} -
      • - - {{ p|chill_entity_render_box }} -
      • - {% endfor %} -
      - - - +
      - {% endif %} - -

      {{ 'Associated peoples'|trans }}

      - -
      - {% for p in accompanyingCourse.participations %} - {% if p.enddate is null %} -
      -
      -
      -

      {{ p.person.firstname ~ ' ' ~ p.person.lastname }}

      -

      - {% set born = (p.person.gender == 'woman') ? 'née': 'né' %} - {% set gender = (p.person.gender == 'woman') ? 'fa-venus' : - (p.person.gender == 'man') ? 'fa-mars' : 'fa-neuter' %} - {% set genderTitle = (p.person.gender == 'woman') ? 'femme' : - (p.person.gender == 'man') ? 'homme' : 'neutre' %} - {{ born ~ ' le ' ~ p.person.birthdate|format_date('short') }} -

      -
      -
      - - -
      +
      +

      {{ 'Requestor'|trans }}

      + {% if accompanyingCourse.requestorPerson is not empty %} + {% set requestor = accompanyingCourse.requestorPerson %} + {% set info = true %} + {% elseif accompanyingCourse.requestor is not empty %} + {% set requestor = accompanyingCourse.requestorThirdParty %} + {% set info = false %} + {% endif %} + {% if accompanyingCourse.requestor == null %} +

      {{ 'Any requestor to this accompanying course'|trans }}

      + {% else %} +
      +
      + {{ requestor|chill_entity_render_box({ + 'render': 'bloc', 'addLink': false, 'addEntity': true, 'addInfo': info + }) }}
      {% endif %} - {% endfor %}
      -

      {{ 'Requestor'|trans }}

      - - {% if accompanyingCourse.requestor == null %} -

      {{ 'Any requestor to this accompanying course'|trans }}

      - {% elseif accompanyingCourse.requestorPerson is not empty %} - {% set r = accompanyingCourse.requestorPerson %} -
      -
      -

      - {{ r.firstname ~ ' ' ~ r.lastname }} - {{ 'Usager' }} -

      -

      - {% set born = (r.gender == 'woman') ? 'née': 'né' %} - {% set gender = (r.gender == 'woman') ? 'fa-venus' : - (r.gender == 'man') ? 'fa-mars' : 'fa-neuter' %} - {% set genderTitle = (r.gender == 'woman') ? 'femme' : - (r.gender == 'homme') ? 'fa-mars' : 'neutre' %} - {{ born ~ ' le ' ~ r.birthdate|format_date('short') }} -

      -
      -
      - -
        -
      • - -
      • -
      -
      -
      - - {% elseif accompanyingCourse.requestorThirdParty is not empty %} - {% set r = accompanyingCourse.requestorThirdParty %} -
      -
      -

      - {{ r.name }} - {{ 'Tiers' }} -

      -
      -
      - -
        -
      • - -
      • -
      -
      -
      - {% endif %} - -
      +

      {{ 'Resources'|trans }}

      {% if accompanyingCourse.resources|length == 0 %}

      {{ 'Any resource for this accompanying course'|trans }}

      @@ -228,12 +84,12 @@
      {% if r.person %} {{ r.person|chill_entity_render_box({ - 'render': 'bloc', 'addLink': true, 'addEntity': true, 'addInfo': true + 'render': 'bloc', 'addLink': false, 'addEntity': true, 'addInfo': true }) }} {% endif %} {% if r.thirdParty %} {{ r.thirdParty|chill_entity_render_box({ - 'render': 'bloc', 'addLink': true, 'addEntity': true, 'addInfo': true + 'render': 'bloc', 'addLink': false, 'addEntity': true, 'addInfo': false }) }} {% endif %}
      @@ -242,9 +98,8 @@ {% endif %}
      -

      {{ 'Social actions'|trans }}

      - -
      +
    - {%- if is_granted('CHILL_PERSON_SEE', person) -%}
      -
    • -
    • + {%- if is_granted('CHILL_PERSON_SEE', person) -%} +
    • + +
    • + {%- endif -%} + {% if options['customButtons'] %} + {{ options['customButtons'] }} + {% endif %}
    - {%- endif -%}
    {%- endif -%} diff --git a/src/Bundle/ChillPersonBundle/Templating/Entity/PersonRender.php b/src/Bundle/ChillPersonBundle/Templating/Entity/PersonRender.php index 320d78d7a..d0ea40b72 100644 --- a/src/Bundle/ChillPersonBundle/Templating/Entity/PersonRender.php +++ b/src/Bundle/ChillPersonBundle/Templating/Entity/PersonRender.php @@ -58,6 +58,7 @@ class PersonRender extends AbstractChillEntityRender 'addEntity' => $options['addEntity'] ?? false, 'addInfo' => $options['addInfo'] ?? false, 'hLevel' => $options['hLevel'] ?? 3, + 'customButtons' => $options['customButtons'] ?? null, ]; return diff --git a/src/Bundle/ChillThirdPartyBundle/Resources/views/Entity/thirdparty.html.twig b/src/Bundle/ChillThirdPartyBundle/Resources/views/Entity/thirdparty.html.twig index 7813c0cbc..294e03f4b 100644 --- a/src/Bundle/ChillThirdPartyBundle/Resources/views/Entity/thirdparty.html.twig +++ b/src/Bundle/ChillThirdPartyBundle/Resources/views/Entity/thirdparty.html.twig @@ -8,6 +8,7 @@ * addEntity bool * addInfo bool * hLevel integer + * customButtons Twig\Markup (html) #} {% macro raw(thirdparty, options) %} @@ -77,9 +78,15 @@
    -
  • - -
  • + {%- if is_granted('CHILL_3PARTY_3PARTY_SHOW', thirdparty) -%} +
  • + +
  • + {% endif %} + {% if options['customButtons'] %} + {{ options['customButtons'] }} + {% endif %}
diff --git a/src/Bundle/ChillThirdPartyBundle/Templating/Entity/ThirdPartyRender.php b/src/Bundle/ChillThirdPartyBundle/Templating/Entity/ThirdPartyRender.php index 00f7effd3..2433ba7e0 100644 --- a/src/Bundle/ChillThirdPartyBundle/Templating/Entity/ThirdPartyRender.php +++ b/src/Bundle/ChillThirdPartyBundle/Templating/Entity/ThirdPartyRender.php @@ -52,6 +52,7 @@ class ThirdPartyRender extends AbstractChillEntityRender 'addEntity' => $options['addEntity'] ?? false, 'addInfo' => $options['addInfo'] ?? false, 'hLevel' => $options['hLevel'] ?? 3, + 'customButtons' => $options['customButtons'] ?? null, ]; return From 39f6f14467c439a743d3cb65b53e834cb75f5b99 Mon Sep 17 00:00:00 2001 From: Mathieu Jaumotte Date: Thu, 29 Jul 2021 14:06:00 +0200 Subject: [PATCH 36/52] render box, custom buttons before, after or remplacing default --- .../views/AccompanyingCourse/index.html.twig | 7 ++-- .../Resources/views/Entity/person.html.twig | 33 ++++++++++++------ .../Templating/Entity/PersonRender.php | 2 +- .../translations/messages.fr.yml | 2 ++ .../views/Entity/thirdparty.html.twig | 34 ++++++++++++------- .../Templating/Entity/ThirdPartyRender.php | 2 +- .../config/services/templating.yaml | 4 +-- .../translations/messages.fr.yml | 4 +-- 8 files changed, 55 insertions(+), 33 deletions(-) diff --git a/src/Bundle/ChillPersonBundle/Resources/views/AccompanyingCourse/index.html.twig b/src/Bundle/ChillPersonBundle/Resources/views/AccompanyingCourse/index.html.twig index 43f5be76e..ac1d1748b 100644 --- a/src/Bundle/ChillPersonBundle/Resources/views/AccompanyingCourse/index.html.twig +++ b/src/Bundle/ChillPersonBundle/Resources/views/AccompanyingCourse/index.html.twig @@ -10,10 +10,8 @@ {% if person.isSharingHousehold %}
  • + class="btn btn-chill-pink" title="{{ 'Show household'|trans ~ ' n° ' ~ person.getCurrentHousehold.id }}"> - n°  - {{ person.getCurrentHousehold.id }}
  • {% endif %} @@ -40,7 +38,8 @@ {% if participation.enddate is null %}
    {{ participation.person|chill_entity_render_box({ - 'render': 'bloc', 'addLink': false, 'addInfo': true, 'customButtons': _self.button_person(participation.person) + 'render': 'bloc', 'addLink': false, 'addInfo': true, + 'customButtons': { 'before': _self.button_person(participation.person) } }) }}
    {% endif %} diff --git a/src/Bundle/ChillPersonBundle/Resources/views/Entity/person.html.twig b/src/Bundle/ChillPersonBundle/Resources/views/Entity/person.html.twig index a5c433e90..3d00fe0ea 100644 --- a/src/Bundle/ChillPersonBundle/Resources/views/Entity/person.html.twig +++ b/src/Bundle/ChillPersonBundle/Resources/views/Entity/person.html.twig @@ -1,13 +1,17 @@ {# Template to render a person - * render [raw|label|bloc] + * render string ['raw'|'label'|'bloc'] OPTIONS - * addAltNames bool - * addLink bool - * addEntity bool - * addInfo bool - * hLevel integer - * customButtons Twig\Markup (html) + * addAltNames bool + * addLink bool + * addEntity bool + * addInfo bool + * hLevel integer + * customButtons [ + 'before' Twig\Markup, (injected with macro) + 'replace' Twig\Markup, + 'after' Twig\Markup + ] #} {% macro raw(person, options) %} @@ -94,14 +98,21 @@
      - {%- if is_granted('CHILL_PERSON_SEE', person) -%} + {% if options['customButtons']['before'] is defined %} + {{ options['customButtons']['before'] }} + {% endif %} + + {%- if options['customButtons']['replace'] is not defined and is_granted('CHILL_PERSON_SEE', person) -%}
    • -
    • + {%- else -%} + {{ options['customButtons']['replace'] }} {%- endif -%} - {% if options['customButtons'] %} - {{ options['customButtons'] }} + + {% if options['customButtons']['after'] is defined %} + {{ options['customButtons']['after'] }} {% endif %}
    diff --git a/src/Bundle/ChillPersonBundle/Templating/Entity/PersonRender.php b/src/Bundle/ChillPersonBundle/Templating/Entity/PersonRender.php index d0ea40b72..8a54e4d38 100644 --- a/src/Bundle/ChillPersonBundle/Templating/Entity/PersonRender.php +++ b/src/Bundle/ChillPersonBundle/Templating/Entity/PersonRender.php @@ -58,7 +58,7 @@ class PersonRender extends AbstractChillEntityRender 'addEntity' => $options['addEntity'] ?? false, 'addInfo' => $options['addInfo'] ?? false, 'hLevel' => $options['hLevel'] ?? 3, - 'customButtons' => $options['customButtons'] ?? null, + 'customButtons' => $options['customButtons'] ?? [], ]; return diff --git a/src/Bundle/ChillPersonBundle/translations/messages.fr.yml b/src/Bundle/ChillPersonBundle/translations/messages.fr.yml index 96dd17357..be834632d 100644 --- a/src/Bundle/ChillPersonBundle/translations/messages.fr.yml +++ b/src/Bundle/ChillPersonBundle/translations/messages.fr.yml @@ -119,6 +119,7 @@ address_country_code: Code pays 'Alreay existing person': 'Dossiers déjà encodés' 'Add the person': 'Ajouter la personne' +Show person: Voir le dossier de la personne 'Confirm the creation': 'Confirmer la création' 'You will create this person': 'Vous allez créer le dossier suivant' Return: Retour @@ -351,6 +352,7 @@ Addresses history for household: Historique des adresses Household accompanying period: Parcours d'accompagnement du ménage Household summary: Résumé du ménage Edit household address: Modifier l'adresse du ménage +Show household: Voir le ménage # accompanying course work Accompanying Course Actions: Actions d'accompagnements diff --git a/src/Bundle/ChillThirdPartyBundle/Resources/views/Entity/thirdparty.html.twig b/src/Bundle/ChillThirdPartyBundle/Resources/views/Entity/thirdparty.html.twig index 294e03f4b..49299bfaf 100644 --- a/src/Bundle/ChillThirdPartyBundle/Resources/views/Entity/thirdparty.html.twig +++ b/src/Bundle/ChillThirdPartyBundle/Resources/views/Entity/thirdparty.html.twig @@ -1,14 +1,17 @@ {# Template to render a thirdparty - * render [raw|label|bloc] + * render string ['raw'|'label'|'bloc'] OPTIONS * with_valid_from bool - * addAltNames bool - * addLink bool - * addEntity bool - * addInfo bool - * hLevel integer - * customButtons Twig\Markup (html) + * addLink bool + * addEntity bool + * addInfo bool + * hLevel integer + * customButtons [ + 'before' Twig\Markup, (injected with macro) + 'replace' Twig\Markup, + 'after' Twig\Markup + ] #} {% macro raw(thirdparty, options) %} @@ -78,14 +81,21 @@
      - {%- if is_granted('CHILL_3PARTY_3PARTY_SHOW', thirdparty) -%} + {% if options['customButtons']['before'] is defined %} + {{ options['customButtons']['before'] }} + {% endif %} + + {%- if options['customButtons']['replace'] is not defined and is_granted('CHILL_3PARTY_3PARTY_SHOW', thirdparty) -%}
    • -
    • - {% endif %} - {% if options['customButtons'] %} - {{ options['customButtons'] }} + {%- else -%} + {{ options['customButtons']['replace'] }} + {%- endif -%} + + {% if options['customButtons']['after'] is defined %} + {{ options['customButtons']['after'] }} {% endif %}
    diff --git a/src/Bundle/ChillThirdPartyBundle/Templating/Entity/ThirdPartyRender.php b/src/Bundle/ChillThirdPartyBundle/Templating/Entity/ThirdPartyRender.php index 2433ba7e0..346c4dcc3 100644 --- a/src/Bundle/ChillThirdPartyBundle/Templating/Entity/ThirdPartyRender.php +++ b/src/Bundle/ChillThirdPartyBundle/Templating/Entity/ThirdPartyRender.php @@ -52,7 +52,7 @@ class ThirdPartyRender extends AbstractChillEntityRender 'addEntity' => $options['addEntity'] ?? false, 'addInfo' => $options['addInfo'] ?? false, 'hLevel' => $options['hLevel'] ?? 3, - 'customButtons' => $options['customButtons'] ?? null, + 'customButtons' => $options['customButtons'] ?? [], ]; return diff --git a/src/Bundle/ChillThirdPartyBundle/config/services/templating.yaml b/src/Bundle/ChillThirdPartyBundle/config/services/templating.yaml index 690f6008d..6b12d3aa0 100644 --- a/src/Bundle/ChillThirdPartyBundle/config/services/templating.yaml +++ b/src/Bundle/ChillThirdPartyBundle/config/services/templating.yaml @@ -1,6 +1,6 @@ services: Chill\ThirdPartyBundle\Templating\Entity\ThirdPartyRender: arguments: - $templating: '@templating.engine.twig' + $engine: '@Symfony\Component\Templating\EngineInterface' tags: - - 'chill.render_entity' \ No newline at end of file + - 'chill.render_entity' diff --git a/src/Bundle/ChillThirdPartyBundle/translations/messages.fr.yml b/src/Bundle/ChillThirdPartyBundle/translations/messages.fr.yml index 5ca560f88..d7cc22eb5 100644 --- a/src/Bundle/ChillThirdPartyBundle/translations/messages.fr.yml +++ b/src/Bundle/ChillThirdPartyBundle/translations/messages.fr.yml @@ -20,7 +20,7 @@ Third party updated: Le tiers a été mis à jour Third party created: Le tiers a été créé Active, shown to users: Actif, visible par les utilisateurs Inactive, not shown to users: Inactif, invisible par les utilisateurs - +Show thirdparty: Voir le tiers The party is visible in those centers: Le tiers est visible dans ces centres No third parties: Aucun tiers @@ -28,4 +28,4 @@ No third parties: Aucun tiers # ROLES CHILL_3PARTY_3PARTY_CREATE: Ajouter un Tiers CHILL_3PARTY_3PARTY_SHOW: Voir un Tiers -CHILL_3PARTY_3PARTY_UPDATE: Modifier un Tiers \ No newline at end of file +CHILL_3PARTY_3PARTY_UPDATE: Modifier un Tiers From 87a7e0de00ee770089560d22f71a82aca6f854bd Mon Sep 17 00:00:00 2001 From: Mathieu Jaumotte Date: Thu, 29 Jul 2021 14:35:14 +0200 Subject: [PATCH 37/52] household alert dropdown style --- .../_join_household.html.twig | 66 ++++++++++--------- 1 file changed, 34 insertions(+), 32 deletions(-) diff --git a/src/Bundle/ChillPersonBundle/Resources/views/AccompanyingCourse/_join_household.html.twig b/src/Bundle/ChillPersonBundle/Resources/views/AccompanyingCourse/_join_household.html.twig index fd0cf373d..600430b31 100644 --- a/src/Bundle/ChillPersonBundle/Resources/views/AccompanyingCourse/_join_household.html.twig +++ b/src/Bundle/ChillPersonBundle/Resources/views/AccompanyingCourse/_join_household.html.twig @@ -1,38 +1,40 @@ -
    -
    - {{ 'Some peoples does not belong to any household currently. Add them to an household soon'|trans }} -
    -
      -
    • - -
    • -
    -
    - -
    -
    - -

    {{ 'household.Select people to move'|trans }}

    -
      - {% for p in withoutHousehold %} -
    • - - {{ p|chill_entity_render_box }} -
    • - {% endfor %} -
    - - - +
    +
    +
    + {{ 'Some peoples does not belong to any household currently. Add them to an household soon'|trans }} +
    • -
    - +
    + +
    +
    + +

    {{ 'household.Select people to move'|trans }}

    +
      + {% for p in withoutHousehold %} +
    • + + {{ p|chill_entity_render_box }} +
    • + {% endfor %} +
    + + + +
      +
    • + +
    • +
    +
    +
    From 55ac730c18d87e675b7faa986f876b06f7fcb93a Mon Sep 17 00:00:00 2001 From: Mathieu Jaumotte Date: Thu, 29 Jul 2021 15:23:28 +0200 Subject: [PATCH 38/52] notification pill appearance --- .../Resources/views/UI/notification_user_counter.html.twig | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Bundle/ChillMainBundle/Resources/views/UI/notification_user_counter.html.twig b/src/Bundle/ChillMainBundle/Resources/views/UI/notification_user_counter.html.twig index e4e899ba6..8f2db0eef 100644 --- a/src/Bundle/ChillMainBundle/Resources/views/UI/notification_user_counter.html.twig +++ b/src/Bundle/ChillMainBundle/Resources/views/UI/notification_user_counter.html.twig @@ -1 +1 @@ -{% if nb > 0 %}{{ nb }}{% endif %} \ No newline at end of file +{% if nb > 0 %}{{ nb }}{% endif %} From 6dac13084485e7d244bc4e9c8720949e4decae9f Mon Sep 17 00:00:00 2001 From: Mathieu Jaumotte Date: Thu, 29 Jul 2021 16:51:46 +0200 Subject: [PATCH 39/52] render box address, remove macro address, refactoring (wip) --- .../public/chill/scss/render_box.scss | 35 ++++ .../views/Address/entity_render.html.twig | 44 +++-- .../Resources/views/Address/macro.html.twig | 21 --- .../views/AccompanyingCourse/index.html.twig | 2 - .../Resources/views/Address/list.html.twig | 176 ++++++++---------- .../Resources/views/Person/view.html.twig | 4 +- .../views/PersonDuplicate/_sidepane.html.twig | 8 +- .../Templating/Entity/PersonRender.php | 5 +- .../Resources/views/ThirdParty/show.html.twig | 4 +- 9 files changed, 155 insertions(+), 144 deletions(-) delete mode 100644 src/Bundle/ChillMainBundle/Resources/views/Address/macro.html.twig diff --git a/src/Bundle/ChillMainBundle/Resources/public/chill/scss/render_box.scss b/src/Bundle/ChillMainBundle/Resources/public/chill/scss/render_box.scss index b26cfbc4a..5e221507e 100644 --- a/src/Bundle/ChillMainBundle/Resources/public/chill/scss/render_box.scss +++ b/src/Bundle/ChillMainBundle/Resources/public/chill/scss/render_box.scss @@ -11,3 +11,38 @@ section.chill-entity { flex-grow: 1; flex-shrink: 1; flex-basis: auto; } } + +// specific rules +// address render_box +div.chill-entity { + &.entity-address { + div.noaddress {} + div.address { + margin: 0.7em 0; + font-size: 98%; + font-variant: small-caps; + + &.multiline { + p { + display: block; + } + } + p { + display: inline-block; + margin: 0 0 0 1.5em; + text-indent: -1.5em; + + &.street { + &.street1 {} + &.street2, &.streetnumber {} + } + &.postalcode { + span.code {} + span.name {} + } + &.country {} + } + } + span.address-since {} + } +} diff --git a/src/Bundle/ChillMainBundle/Resources/views/Address/entity_render.html.twig b/src/Bundle/ChillMainBundle/Resources/views/Address/entity_render.html.twig index fa7a13645..5fb0d1b4e 100644 --- a/src/Bundle/ChillMainBundle/Resources/views/Address/entity_render.html.twig +++ b/src/Bundle/ChillMainBundle/Resources/views/Address/entity_render.html.twig @@ -1,16 +1,36 @@ -
    +{# + Template to render an address + OPTIONS + * has_no_address bool + * multiline bool + * with_valid_from bool +#} +
    {% if options['has_no_address'] == true and address.isNoAddress == true %} -
    {{ 'address.consider homeless'|trans }}
    - {% endif %} -
    - {% if address.street is not empty %}

    {{ address.street }}

    {% endif %} - {% if address.streetNumber is not empty %}

    {{ address.streetNumber }}

    {% endif %} - {% if address.postCode is not empty %} -

    {{ address.postCode.code }} {{ address.postCode.name }}

    -

    {{ address.postCode.country.name|localize_translatable_string }}

    +
    + {{ 'address.consider homeless'|trans }} +
    {% endif %} + +
    + {% if address.street is not empty %} +

    {{ address.street }}

    + {% endif %} + {% if address.streetNumber is not empty %} +

    {{ address.streetNumber }}

    + {% endif %} + {% if address.postCode is not empty %} +

    + {{ address.postCode.code }} + {{ address.postCode.name }} +

    +

    {{ address.postCode.country.name|localize_translatable_string }}

    + {% endif %}
    -{%- if options['with_valid_from'] == true -%} -{{ 'Since %date%'|trans( { '%date%' : address.validFrom|format_date('long') } ) }} -{%- endif -%} + + {%- if options['with_valid_from'] == true -%} + + {{ 'Since %date%'|trans( { '%date%' : address.validFrom|format_date('long') } ) }} + + {%- endif -%}
    diff --git a/src/Bundle/ChillMainBundle/Resources/views/Address/macro.html.twig b/src/Bundle/ChillMainBundle/Resources/views/Address/macro.html.twig deleted file mode 100644 index 990dbc043..000000000 --- a/src/Bundle/ChillMainBundle/Resources/views/Address/macro.html.twig +++ /dev/null @@ -1,21 +0,0 @@ -{%- macro _render(address, options) -%} - {%- set options = { 'with_valid_from' : true }|merge(options|default({})) -%} - {%- set options = { 'has_no_address' : false }|merge(options|default({})) -%} - {%- set options = { 'with_icon' : false }|merge(options|default({})) -%} -
    - {% if options['has_no_address'] == true and address.isNoAddress == true %} -
    {{ 'address.consider homeless'|trans }}
    - {% endif %} -
    {% if options['with_icon'] == true %}{% endif %} - {% if address.street is not empty %}

    {{ address.street }}

    {% endif %} - {% if address.streetNumber is not empty %}

    {{ address.streetNumber }}

    {% endif %} - {% if address.postCode is not empty %} -

    {{ address.postCode.code }} {{ address.postCode.name }}

    -

    {{ address.postCode.country.name|localize_translatable_string }}

    - {% endif %} -
    - {%- if options['with_valid_from'] == true -%} - {{ 'Since %date%'|trans( { '%date%' : address.validFrom|format_date('long') } ) }} - {%- endif -%} -
    -{%- endmacro -%} diff --git a/src/Bundle/ChillPersonBundle/Resources/views/AccompanyingCourse/index.html.twig b/src/Bundle/ChillPersonBundle/Resources/views/AccompanyingCourse/index.html.twig index ac1d1748b..bb42a390a 100644 --- a/src/Bundle/ChillPersonBundle/Resources/views/AccompanyingCourse/index.html.twig +++ b/src/Bundle/ChillPersonBundle/Resources/views/AccompanyingCourse/index.html.twig @@ -1,7 +1,5 @@ {% extends '@ChillPerson/AccompanyingCourse/layout.html.twig' %} -{% import '@ChillMain/Address/macro.html.twig' as address %} - {% block title %} {{ 'Resume Accompanying Course'|trans }} {% endblock %} diff --git a/src/Bundle/ChillPersonBundle/Resources/views/Address/list.html.twig b/src/Bundle/ChillPersonBundle/Resources/views/Address/list.html.twig index 6f6a90d81..80f68a84e 100644 --- a/src/Bundle/ChillPersonBundle/Resources/views/Address/list.html.twig +++ b/src/Bundle/ChillPersonBundle/Resources/views/Address/list.html.twig @@ -16,110 +16,94 @@ #} {% extends "@ChillPerson/Person/layout.html.twig" %} -{% import '@ChillMain/Address/macro.html.twig' as address_macros %} - {% set activeRouteKey = '' %} {% block title %}{{ 'Addresses history for %name%'|trans({ '%name%': person.firstName ~ ' ' ~ person.lastName } ) }}{% endblock %} {% block personcontent %}
    - -

    {{ 'Addresses history'|trans }}

    - -
    - - {% if person.addresses|length == 0 %} - {{ 'No address given'|trans }} - {% else %} -
    - {% endif %} - - {% for address in person.addresses %} - - {# if person address #} -
    -
    - {% if address.isNoAddress == true %} -
    {{ 'address.consider homeless'|trans }}
    - {% else %} - - {% if address.street is not empty %} -
    - {{ address.street }} - {% if address.streetNumber is not empty %} - , {{ address.streetNumber }} - {% endif %} -
    - {% endif %} - - {% if address.postCode is not empty %} -
    - {{ address.postCode.code }} {{ address.postCode.name }} - ({{ address.postCode.country.name|localize_translatable_string }}) -
    - {% endif %} - - {% endif %} - -
      -
    • - -
    • -
    -
    -
    - {# endif #} - -
    - - {# if household address #}{# -
    -
    ...
    -
    - #}{# endif #} - -
    - {% if address.validFrom is not empty %} - {{ address.validFrom|format_date('long') }} - {% endif %} -
    - - {% endfor %} - - {# TEST HOUSEHOLD POSITION - #} -
    -
    -
    -
    - 549, chemin De Sousa - , 45, boulevard Aurore Roux -
    -
    - 10850 Nanterre (France) -
    -
    -
    + +

    {{ 'Addresses history'|trans }}

    + +
    + + {% if person.addresses|length == 0 %} + {{ 'No address given'|trans }} + {% else %} +
    + {% endif %} + + {% for address in person.addresses %} + + {# if person address #} +
    +
    + {% if address.isNoAddress == true %} +
    {{ 'address.consider homeless'|trans }}
    + {% else %} + {{ address|chill_entity_render_box({ + 'multiline': false, 'with_valid_from': false + }) }} + {% endif %} + +
      +
    • + +
    • +
    -
    01 janvier 1970
    - {# END TEST #} - +
    + {# endif #} + +
    + + {# if household address #}{# +
    +
    ...
    +
    + #}{# endif #} + +
    + {% if address.validFrom is not empty %} + {{ address.validFrom|format_date('long') }} + {% endif %}
    - - + {% endfor %} + + {# TEST HOUSEHOLD POSITION + #} +
    +
    +
    +
    + 549, chemin De Sousa + , 45, boulevard Aurore Roux +
    +
    + 10850 Nanterre (France) +
    +
    +
    +
    +
    01 janvier 1970
    + {# END TEST #} + +
    + + +
    {% endblock %} diff --git a/src/Bundle/ChillPersonBundle/Resources/views/Person/view.html.twig b/src/Bundle/ChillPersonBundle/Resources/views/Person/view.html.twig index 3a51e8939..93c9c0904 100644 --- a/src/Bundle/ChillPersonBundle/Resources/views/Person/view.html.twig +++ b/src/Bundle/ChillPersonBundle/Resources/views/Person/view.html.twig @@ -16,8 +16,6 @@ #} {% extends "@ChillPerson/Person/layout.html.twig" %} -{% import '@ChillMain/Address/macro.html.twig' as address %} - {% set activeRouteKey = 'chill_person_view' %} {# @@ -171,7 +169,7 @@ This view should receive those arguments:
    {{ 'Address'|trans }}
    {%- if person.lastAddress is not empty -%} - {{ address._render(person.lastAddress, {'has_no_address': true}) }} + {{ person.lastAddress|chill_entity_render_box({'has_no_address': true}) }}
    • diff --git a/src/Bundle/ChillPersonBundle/Resources/views/PersonDuplicate/_sidepane.html.twig b/src/Bundle/ChillPersonBundle/Resources/views/PersonDuplicate/_sidepane.html.twig index 098737aaf..f7fef7f93 100644 --- a/src/Bundle/ChillPersonBundle/Resources/views/PersonDuplicate/_sidepane.html.twig +++ b/src/Bundle/ChillPersonBundle/Resources/views/PersonDuplicate/_sidepane.html.twig @@ -1,7 +1,5 @@ {%- macro details(person, options) -%} -{% import '@ChillMain/Address/macro.html.twig' as address %} -
      • {{ 'gender'|trans }}: {{ person.gender|trans }}
      • @@ -24,7 +22,9 @@
      • {{ 'memo'|trans }}: {{ person.memo }}
      • {{ 'address'|trans }}: - {%- if person.lastAddress is not empty -%}{{ address._render(person.lastAddress, {'with_valid_from': false}) }}{% endif %}
      • + {%- if person.lastAddress is not empty -%} + {{ person.lastAddress|chill_entity_render_box({'with_valid_from': false}) }} + {% endif %}
      • {{ 'spokenLanguages'|trans }}: {% for lang in person.spokenLanguages %}{{ lang.name|localize_translatable_string }}{% if not loop.last %},{% endif %}{% endfor %}
      • {{ 'contactInfo'|trans }}: @@ -43,4 +43,4 @@
      • {{ person.counters.nb_addresses }} {{ (person.counters.nb_addresses > 1)? 'adresses' : 'adresse' }}
      -{% endmacro %} \ No newline at end of file +{% endmacro %} diff --git a/src/Bundle/ChillPersonBundle/Templating/Entity/PersonRender.php b/src/Bundle/ChillPersonBundle/Templating/Entity/PersonRender.php index 8a54e4d38..603aa91ee 100644 --- a/src/Bundle/ChillPersonBundle/Templating/Entity/PersonRender.php +++ b/src/Bundle/ChillPersonBundle/Templating/Entity/PersonRender.php @@ -25,7 +25,6 @@ use Chill\PersonBundle\Entity\Person; use Chill\PersonBundle\Config\ConfigPersonAltNamesHelper; use Symfony\Component\Templating\EngineInterface; - /** * Render a Person * @@ -83,7 +82,7 @@ class PersonRender extends AbstractChillEntityRender .$this->addAltNames($person, false); } - protected function addAltNames(Person $person, bool $addSpan) + protected function addAltNames(Person $person, bool $addSpan): string { $str = ''; @@ -101,7 +100,7 @@ class PersonRender extends AbstractChillEntityRender $str.= " "; } if ($addSpan) { - $str .= ''; + $str .= ''; } $str .= $altName->getLabel(); diff --git a/src/Bundle/ChillThirdPartyBundle/Resources/views/ThirdParty/show.html.twig b/src/Bundle/ChillThirdPartyBundle/Resources/views/ThirdParty/show.html.twig index 19956d2ce..a691605eb 100644 --- a/src/Bundle/ChillThirdPartyBundle/Resources/views/ThirdParty/show.html.twig +++ b/src/Bundle/ChillThirdPartyBundle/Resources/views/ThirdParty/show.html.twig @@ -1,7 +1,5 @@ {% extends "@ChillMain/layout.html.twig" %} -{% import '@ChillMain/Address/macro.html.twig' as address %} - {% set title_ = 'Show third party %name%'|trans({'%name%' : thirdParty.name }) %} {% block title title_ %} @@ -38,7 +36,7 @@ {% if thirdParty.address == null %} {{ 'No address given'|trans }} {% else %} - {{ address._render(thirdParty.address, {'with_valid_from': false }) }} + {{ thirdParty.address|chill_entity_render_box({'with_valid_from': false }) }} {% endif %}
    From 4cac5f9a4ad7141110114f9cc1a8dded4a446557 Mon Sep 17 00:00:00 2001 From: Mathieu Jaumotte Date: Fri, 30 Jul 2021 10:46:16 +0200 Subject: [PATCH 40/52] render_box: adding option addId + styles more generic, less specific --- .../Resources/public/chill/chillmain.scss | 7 +--- .../public/chill/scss/render_box.scss | 36 ++++++++++++++++-- .../public/chill/scss/render_box.scss | 24 +++--------- .../Resources/views/Entity/person.html.twig | 6 +++ .../Resources/views/Person/banner.html.twig | 37 +++++++------------ .../Templating/Entity/PersonRender.php | 1 + .../{thirdparty.scss => chillthirdparty.scss} | 23 ++---------- .../Resources/public/chill/index.js | 2 +- .../views/Entity/thirdparty.html.twig | 6 +++ .../Templating/Entity/ThirdPartyRender.php | 1 + 10 files changed, 71 insertions(+), 72 deletions(-) rename src/Bundle/ChillThirdPartyBundle/Resources/public/chill/{thirdparty.scss => chillthirdparty.scss} (74%) diff --git a/src/Bundle/ChillMainBundle/Resources/public/chill/chillmain.scss b/src/Bundle/ChillMainBundle/Resources/public/chill/chillmain.scss index 70c4d3c0f..455b7a590 100644 --- a/src/Bundle/ChillMainBundle/Resources/public/chill/chillmain.scss +++ b/src/Bundle/ChillMainBundle/Resources/public/chill/chillmain.scss @@ -21,12 +21,7 @@ // styles communs pour tous les bandeaux div.banner { - .id-number { - font-weight: lighter; - font-size: 50%; - &:before { content: '(n°'; } - &:after { content: ')'; } - } + a.phone, a.email { color: white; diff --git a/src/Bundle/ChillMainBundle/Resources/public/chill/scss/render_box.scss b/src/Bundle/ChillMainBundle/Resources/public/chill/scss/render_box.scss index 5e221507e..b2b15447b 100644 --- a/src/Bundle/ChillMainBundle/Resources/public/chill/scss/render_box.scss +++ b/src/Bundle/ChillMainBundle/Resources/public/chill/scss/render_box.scss @@ -2,7 +2,7 @@ section.chill-entity { // display inline for render raw - // have no effect for render label, row, bloc ! + // have no effect for render label, bloc ! display: inline; // don't break flex cascade with section tag @@ -13,8 +13,38 @@ section.chill-entity { } // specific rules -// address render_box -div.chill-entity { +.chill-entity { + + // used for: entity-person, entity-thirdparty + &.entity-person, + &.entity-thirdparty { + + div.entity-label { + div.denomination { + &.h3 { + font-size: 1.3em; + font-weight: 700; + } + a { + text-decoration: none; + } + span.badge { + margin-left: 0.3em; + } + span.id-number { + font-weight: lighter; + font-size: 50%; + margin-left: 0.5em; + &:before { content: '(n°'; } + &:after { content: ')'; } + } + } + p.moreinfo {} + } + div.entity-bloc {} + } + + // address render_box &.entity-address { div.noaddress {} div.address { diff --git a/src/Bundle/ChillPersonBundle/Resources/public/chill/scss/render_box.scss b/src/Bundle/ChillPersonBundle/Resources/public/chill/scss/render_box.scss index a68b10c0b..657129644 100644 --- a/src/Bundle/ChillPersonBundle/Resources/public/chill/scss/render_box.scss +++ b/src/Bundle/ChillPersonBundle/Resources/public/chill/scss/render_box.scss @@ -1,22 +1,8 @@ - -section.chill-entity.entity-person { - div.entity-label { - div.denomination { - &.h3 { - font-size: 1.3em; - font-weight: 700; - } - a { - text-decoration: none; - } - span.firstname, span.lastname, span.altname {} - span.badge { - margin-left: 0.3em; - } - } - p.moreinfo {} +section.chill-entity { + &.entity-person { + span.firstname, + span.lastname, + span.altname {} } - div.entity-row {} - div.entity-bloc {} } diff --git a/src/Bundle/ChillPersonBundle/Resources/views/Entity/person.html.twig b/src/Bundle/ChillPersonBundle/Resources/views/Entity/person.html.twig index 3d00fe0ea..4bda7db4d 100644 --- a/src/Bundle/ChillPersonBundle/Resources/views/Entity/person.html.twig +++ b/src/Bundle/ChillPersonBundle/Resources/views/Entity/person.html.twig @@ -5,6 +5,7 @@ * addAltNames bool * addLink bool * addEntity bool + * addId bool * addInfo bool * hLevel integer * customButtons [ @@ -42,6 +43,11 @@ {%- if options['addEntity'] -%} {{ 'Person'|trans }} {%- endif -%} + {%- if options['addId'] -%} + + {{ person.id|upper }} + + {%- endif -%}
    {%- if options['addInfo'] -%} {% set gender = (person.gender == 'woman') ? 'fa-venus' : diff --git a/src/Bundle/ChillPersonBundle/Resources/views/Person/banner.html.twig b/src/Bundle/ChillPersonBundle/Resources/views/Person/banner.html.twig index dd136014e..5389edb85 100644 --- a/src/Bundle/ChillPersonBundle/Resources/views/Person/banner.html.twig +++ b/src/Bundle/ChillPersonBundle/Resources/views/Person/banner.html.twig @@ -2,26 +2,17 @@
    - +
    -

    - {% set gender = - (person.gender == "woman") ? 'female' : - (person.gender == "both") ? 'neuter' : 'male' - %} - - - {{ person|chill_entity_render_string }} - - - {{ person.id|upper }} - -

    + {{ person|chill_entity_render_box({ + 'render': 'label', 'addInfo': true, 'addId': true, 'hLevel': 1 + }) }} +
    - +
    • - -
      -
        - {%- if person.currentHouseholdAddress is not empty -%} -
      • - - {{ person.currentHouseholdAddress|chill_entity_render_box({'multiline': false, 'with_valid_from': false}) }} -
      • - {%- elseif person.lastAddress is not empty -%} -
      • - - {{ person.lastAddress|chill_entity_render_box({'multiline': false, 'with_valid_from': false}) }} -
      • - {%- endif -%} -
      +
      + {{ include('@ChillPerson/Person/banner_custom.html.twig') }}
      @@ -58,38 +19,43 @@
      -
      - - {{ 'Birthdate'|trans|upper }}   : - - {% if person.birthdate == null %} - {{ 'Unknown date of birth'|trans }} - {% else %} - {{ person.birthdate|format_date('short') }} +
      + {% if person.phonenumber %} + + + + {{ person.phonenumber|chill_format_phonenumber }} + {% endif %} -
      - - {%- if chill_person.fields.nationality == 'visible' -%} -
      - - {{ 'Nationality'|trans|upper}}   : - - {% if person.nationality is not null %} - {{ person.nationality.name|localize_translatable_string }} - {% else %} - {% trans %}Without nationality{% endtrans %} + {% if person.mobilenumber %} + + + + {{ person.mobilenumber|chill_format_phonenumber }} + + {% endif %} + {% if person.email %} + {% endif %} -
      - {%- endif -%} - {%- if chill_person.fields.spoken_languages == 'visible' -%} -
      - - {{ 'Center'|trans|upper}}   : - - {{ person.center.name|upper }} + {%- if person.currentHouseholdAddress is not empty -%} + {% set address = person.currentHouseholdAddress %} + {%- elseif person.lastAddress is not empty -%} + {% set address = person.lastAddress %} + {%- endif -%} + {%- if address -%} + + {{ address|chill_entity_render_box({ + 'render': 'inline', 'multiline': false, 'with_picto': true, 'with_delimiter': true + }) }} + + {%- endif -%}
      - {%- endif -%}
      diff --git a/src/Bundle/ChillPersonBundle/Resources/views/Person/banner_custom.html.twig b/src/Bundle/ChillPersonBundle/Resources/views/Person/banner_custom.html.twig new file mode 100644 index 000000000..d61762a16 --- /dev/null +++ b/src/Bundle/ChillPersonBundle/Resources/views/Person/banner_custom.html.twig @@ -0,0 +1,27 @@ +{# + Overwrite this file to display client specific datas in custom area +#} + From e8e4dbef1f95a39f586def839526d5faa584b35a Mon Sep 17 00:00:00 2001 From: Mathieu Jaumotte Date: Fri, 30 Jul 2021 15:39:22 +0200 Subject: [PATCH 46/52] banner household, new responsive design --- .../Resources/public/chill/chillmain.scss | 18 +--- .../Resources/public/chill/chillperson.scss | 23 +++++ .../Resources/views/Entity/person.html.twig | 22 +++-- .../views/Household/banner.html.twig | 91 ++++++++++--------- .../views/Person/banner_custom.html.twig | 2 +- 5 files changed, 86 insertions(+), 70 deletions(-) diff --git a/src/Bundle/ChillMainBundle/Resources/public/chill/chillmain.scss b/src/Bundle/ChillMainBundle/Resources/public/chill/chillmain.scss index 5c125f4c0..97c5e3cc9 100644 --- a/src/Bundle/ChillMainBundle/Resources/public/chill/chillmain.scss +++ b/src/Bundle/ChillMainBundle/Resources/public/chill/chillmain.scss @@ -40,21 +40,5 @@ div.banner { &:before { content: '('; } &:after { content: ')'; } } - div.members { - display: flex; - flex-direction: row; - span.badge-member { - border: 1px solid #ffffff3b; - color: #ffffff; - padding: 0.4em 0.8em; - margin-right: 0.3em; - border-radius: 8px; - &.holder { - order: -1; - } - &.child { - order: 2; - } - } - } + } diff --git a/src/Bundle/ChillPersonBundle/Resources/public/chill/chillperson.scss b/src/Bundle/ChillPersonBundle/Resources/public/chill/chillperson.scss index 7c14ffc0c..5b747da62 100644 --- a/src/Bundle/ChillPersonBundle/Resources/public/chill/chillperson.scss +++ b/src/Bundle/ChillPersonBundle/Resources/public/chill/chillperson.scss @@ -114,6 +114,7 @@ div#header-accompanying_course-details { div#header-household-name { background: none repeat scroll 0 0 #929d69; //#b97a7a; color: #FFF; + h1 { margin: 0.4em 0; } @@ -136,6 +137,28 @@ div#header-household-details { } } +div.household-members { + display: flex; + flex-direction: row; + flex-wrap: wrap; + //justify-content: flex-end; + span.badge-member { + flex-shrink: 0; flex-grow: 0; flex-basis: auto; + border: 1px solid #ffffff3b; + color: #ffffff; + padding: 0.4em 0.8em; + margin-bottom: 0.2em; + margin-right: 0.3em; + border-radius: 8px; + &.holder { + order: -1; + } + &.child { + order: 2; + } + } +} + /* * ADDRESS HISTORY * context person / household diff --git a/src/Bundle/ChillPersonBundle/Resources/views/Entity/person.html.twig b/src/Bundle/ChillPersonBundle/Resources/views/Entity/person.html.twig index dfe703c01..cc79d1a82 100644 --- a/src/Bundle/ChillPersonBundle/Resources/views/Entity/person.html.twig +++ b/src/Bundle/ChillPersonBundle/Resources/views/Entity/person.html.twig @@ -88,26 +88,28 @@
        {% if options['customButtons']['before'] is defined %} diff --git a/src/Bundle/ChillPersonBundle/Resources/views/Household/banner.html.twig b/src/Bundle/ChillPersonBundle/Resources/views/Household/banner.html.twig index c0ca3318e..18bc6f663 100644 --- a/src/Bundle/ChillPersonBundle/Resources/views/Household/banner.html.twig +++ b/src/Bundle/ChillPersonBundle/Resources/views/Household/banner.html.twig @@ -2,8 +2,8 @@
        - -
        + +

        {{ 'household.Household'|trans }} @@ -11,56 +11,63 @@

        -
        -
          -
        • - {% set address = household.currentAddress %} - - {% if address is empty %} -

          {{ 'household.Household does not have any address currently'|trans }}

          - {% else %} - {{ address|chill_entity_render_box({'multiline': false, 'with_valid_from': false}) }} +
          +
          + {%- set members = household.getCurrentMembersOrdered() -%} + {%- if members|length > 0 -%} + + + {%- for m in members|slice(0, 5) -%} + + {%- if m.holder %} + + {{ 'household.holder'|trans }} + + {% endif -%} + {{- m.person|chill_entity_render_box({'addLink': false}) -}} + + {%- endfor -%} + + {% if members|length > 5 %} + + {{ 'household.and x other persons'|trans({'x': members|length-5}) }} + {% endif %} -
        • -
        + {%- endif -%} +
        - + + + +
        - -
        diff --git a/src/Bundle/ChillPersonBundle/Resources/views/Person/banner_custom.html.twig b/src/Bundle/ChillPersonBundle/Resources/views/Person/banner_custom.html.twig index d61762a16..d01a53c22 100644 --- a/src/Bundle/ChillPersonBundle/Resources/views/Person/banner_custom.html.twig +++ b/src/Bundle/ChillPersonBundle/Resources/views/Person/banner_custom.html.twig @@ -1,7 +1,7 @@ {# Overwrite this file to display client specific datas in custom area #} -
      -
      {% endblock %} diff --git a/src/Bundle/ChillPersonBundle/Resources/views/Household/addresses.html.twig b/src/Bundle/ChillPersonBundle/Resources/views/Household/addresses.html.twig index d4f9df535..2f66447f8 100644 --- a/src/Bundle/ChillPersonBundle/Resources/views/Household/addresses.html.twig +++ b/src/Bundle/ChillPersonBundle/Resources/views/Household/addresses.html.twig @@ -5,68 +5,83 @@ {% block content %}
      -

      {{ block('title') }}

      +

      {{ block('title') }}

      -
      + - {% if household.addresses|length == 0 %} - {{ 'No address given'|trans }} - {% else %} -
      - {% endif %} +
      - {% for address in household.addresses %} + {% if household.addresses|length == 0 %} + {{ 'No address given'|trans }} + {% else %} +
      + {% endif %} -
      + {% set row = 0 %} + {% set previousRowFrom = null %} -
      -
      - {% if address.isNoAddress == true %} -
      {{ 'address.consider homeless'|trans }}
      - {% else %} - {% if address.street is not empty %} -
      - {{ address.street }} - {% if address.streetNumber is not empty %} - , {{ address.streetNumber }} - {% endif %} -
      - {% endif %} - {% if address.postCode is not empty %} -
      - {{ address.postCode.code }} {{ address.postCode.name }} - ({{ address.postCode.country.name|localize_translatable_string }}) -
      + {% for address in household.addresses %} + + {% set row = row + 1 %} + {% if address.validTo is not empty and address.validTo < previousRowFrom %} + +
      + +
      + {% if address.validTo is not empty %} + {{ address.validTo|format_date('short') }} {% endif %} +
      + {% set row = row + 1 %} + {% endif %} + +
      +
      + {{ address|chill_entity_render_box({ + 'render': 'bloc', + 'multiline': true, + 'extended_infos': true, + 'has_no_address': true + }) }} +
        +
      • + +
      • +
      +
      + +
      + {% if address.validFrom is not empty %} + {{ address.validFrom|format_date('short') }} {% endif %}
      -
        -
      • - -
      • -
      -
      + {% set previousRowFrom = address.validFrom %} + {% endfor %} +
      -
      - {% if address.validFrom is not empty %} - {{ address.validFrom|format_date('long') }} - {% endif %} -
      - - {% endfor %} - -
      - - +
      {% endblock %} diff --git a/src/Bundle/ChillPersonBundle/translations/messages.fr.yml b/src/Bundle/ChillPersonBundle/translations/messages.fr.yml index be834632d..57b051d68 100644 --- a/src/Bundle/ChillPersonBundle/translations/messages.fr.yml +++ b/src/Bundle/ChillPersonBundle/translations/messages.fr.yml @@ -353,6 +353,7 @@ Household accompanying period: Parcours d'accompagnement du ménage Household summary: Résumé du ménage Edit household address: Modifier l'adresse du ménage Show household: Voir le ménage +Back to household: Revenir au ménage # accompanying course work Accompanying Course Actions: Actions d'accompagnements @@ -370,3 +371,8 @@ accompanying_course_work: results: Résultats - orientations goal: Objectif - motif - dispositif Any work: Aucune action d'accompagnement + +# +Person addresses: Adresses de résidence +Household addresses: Adresses de domicile +Insert an address: Insérer une adresse diff --git a/src/Bundle/ChillThirdPartyBundle/Resources/views/Entity/thirdparty.html.twig b/src/Bundle/ChillThirdPartyBundle/Resources/views/Entity/thirdparty.html.twig index 057be85c8..ed7bb73bd 100644 --- a/src/Bundle/ChillThirdPartyBundle/Resources/views/Entity/thirdparty.html.twig +++ b/src/Bundle/ChillThirdPartyBundle/Resources/views/Entity/thirdparty.html.twig @@ -66,11 +66,12 @@
        From f9735823c7dbba5ffc190f4b62862d8a23a98a53 Mon Sep 17 00:00:00 2001 From: Mathieu Jaumotte Date: Fri, 30 Jul 2021 18:39:57 +0200 Subject: [PATCH 48/52] minor class renaming --- .../Resources/public/chill/scss/render_box.scss | 8 +++++--- .../Resources/views/Entity/address.html.twig | 6 +++--- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/src/Bundle/ChillMainBundle/Resources/public/chill/scss/render_box.scss b/src/Bundle/ChillMainBundle/Resources/public/chill/scss/render_box.scss index 2afd59fcb..dd1dc12c5 100644 --- a/src/Bundle/ChillMainBundle/Resources/public/chill/scss/render_box.scss +++ b/src/Bundle/ChillMainBundle/Resources/public/chill/scss/render_box.scss @@ -75,7 +75,7 @@ section.chill-entity { &::before { content: ", "; } } } - &.postalcode { + &.postcode { span.code {} span.name {} } @@ -87,7 +87,9 @@ section.chill-entity { font-style: italic; } - span.address-since, - span.address-until {} + span.address-valid { + &.address-since {} + &.address-until {} + } } } diff --git a/src/Bundle/ChillMainBundle/Resources/views/Entity/address.html.twig b/src/Bundle/ChillMainBundle/Resources/views/Entity/address.html.twig index 95692aca1..7e1c47da4 100644 --- a/src/Bundle/ChillMainBundle/Resources/views/Entity/address.html.twig +++ b/src/Bundle/ChillMainBundle/Resources/views/Entity/address.html.twig @@ -24,7 +24,7 @@ {{ _self.extended(address, options) }} {% endif %} {% if address.postCode is not empty %} -

        +

        {{ address.postCode.code }} {{ address.postCode.name }}

        @@ -71,12 +71,12 @@ {% macro validity(address, options) %} {%- if options['with_valid_from'] == true -%} - + {{ 'Since %date%'|trans( { '%date%' : address.validFrom|format_date('long') } ) }} {%- endif -%} {%- if options['with_valid_to'] == true -%} - + {{ 'Until %date%'|trans( { '%date%' : address.validTo|format_date('long') } ) }} {%- endif -%} From 51216b90c5695ad0701a87e1558a23d1b859b17f Mon Sep 17 00:00:00 2001 From: Mathieu Jaumotte Date: Fri, 30 Jul 2021 19:56:01 +0200 Subject: [PATCH 49/52] banner accompanyingcourse, new responsive design --- .../AccompanyingCourse/components/Banner.vue | 32 ++++---- .../components/Banner/ToggleFlags.vue | 34 ++++----- .../views/AccompanyingCourse/banner.html.twig | 10 +-- .../views/Household/banner.html.twig | 3 - .../Resources/views/Person/banner.html.twig | 73 ++++++++++--------- 5 files changed, 73 insertions(+), 79 deletions(-) diff --git a/src/Bundle/ChillPersonBundle/Resources/public/vuejs/AccompanyingCourse/components/Banner.vue b/src/Bundle/ChillPersonBundle/Resources/public/vuejs/AccompanyingCourse/components/Banner.vue index b03d2fdc7..eda06b285 100644 --- a/src/Bundle/ChillPersonBundle/Resources/public/vuejs/AccompanyingCourse/components/Banner.vue +++ b/src/Bundle/ChillPersonBundle/Resources/public/vuejs/AccompanyingCourse/components/Banner.vue @@ -1,33 +1,32 @@