Loading module/Oscar/src/Oscar/Controller/ConventionModeleEtapeAdministrationController.php +1 −3 Original line number Diff line number Diff line Loading @@ -81,8 +81,6 @@ class ConventionModeleEtapeAdministrationController extends AbstractOscarControl } else if ($this->params()->fromPost('action') == "téléverser_fichier") { $originalFilename = $_FILES['file']['name']; $slugify = new \Cocur\Slugify\Slugify(); $renamed = sprintf( Loading module/Oscar/src/Oscar/Controller/ConventionModeleInstanceController.php +130 −2 Original line number Diff line number Diff line Loading @@ -8,6 +8,8 @@ class ConventionModeleInstanceController extends AbstractOscarController impleme /** @var \Oscar\Service\ConventionModeleInstanceService */ public $conventionModeleInstanceService; /** @var \Oscar\Service\ProjectGrantService */ public $activityService; public function afficherAction() { Loading @@ -27,7 +29,7 @@ class ConventionModeleInstanceController extends AbstractOscarController impleme if ($conventionModeleInstance->conventionModeleEtapeEnCours->conventionModeleEtapeSuivante != NULL) { $conventionModeleInstance->conventionModeleEtapeEnCours = $conventionModeleInstance->conventionModeleEtapeEnCours->conventionModeleEtapeSuivante; } else { $this->créerActivité($conventionModeleInstance->conventionModeleEtapeEnCours); $this->créerActivité($conventionModeleInstance->conventionModeleEtapeEnCours, $conventionModeleInstance); $conventionModeleInstance->conventionModeleEtapeEnCours = NULL; } Loading @@ -39,7 +41,7 @@ class ConventionModeleInstanceController extends AbstractOscarController impleme return $this->redirect()->toRoute('conventionModeleInstances/afficher', ['id' => $conventionModeleInstance->id]); } private function créerActivité(\Oscar\Entity\ConventionModeleEtape $conventionModeleEtape) { private function créerActivité(\Oscar\Entity\ConventionModeleEtape $conventionModeleEtape, \Oscar\Entity\ConventionModeleInstance $conventionModeleInstance) { $newActivity = new \Oscar\Entity\Activity(); $newActivity->setCurrency($this->getEntityManager()->getRepository(\Oscar\Entity\Currency::class)->findAll()[0]); $newActivity->setPcruValidPoleCompetitivite(false); Loading @@ -47,6 +49,13 @@ class ConventionModeleInstanceController extends AbstractOscarController impleme $newActivity->setMotscles([]); $this->getEntityManager()->persist($newActivity); // Mise à jour de l'index de recherche try { $this->activityService->jobSearchUpdate($newActivity); } catch (Exception $e) { $this->getLoggerService()->error($e->getMessage()); } if (mb_strlen(trim($conventionModeleEtape->fichier)) > 0) { // Copie du fichier Loading @@ -67,7 +76,45 @@ class ConventionModeleInstanceController extends AbstractOscarController impleme ) . ".odt"; $newDocumentPath = $destination . DIRECTORY_SEPARATOR . $renamed; //copy($documentPath, $newDocumentPath); $conventionModeleFileContent = file_get_contents('zip://' . $documentPath . "#content.xml"); $conventionModeleFileContentReplaced = $conventionModeleFileContent; // $conventionModeleFileContentReplaced = replace_in_xml($conventionModeleFileContentReplaced, "MES_CONVENTIONS_REMPLACER[La mise à disposition s'inscrit-elle dans le cadre d'une convention actuellement en vigueur ?]", "Oui"); foreach ($conventionModeleInstance->reponses as $key => $value) { $conventionModeleFileContentReplaced = replace_in_xml($conventionModeleFileContentReplaced, "MES_CONVENTIONS_REMPLACER[" . $key . "]", $value); } $slugify = new \Cocur\Slugify\Slugify(); $tmp_location = sprintf("/tmp/oscar-conventions-%s-%s", $slugify->slugify((new \DateTime())->format(\DateTime::ATOM)), $slugify->slugify($conventionModeleEtape->fichier) ); file_put_contents($tmp_location, $conventionModeleFileContentReplaced); copy($documentPath, $newDocumentPath); $za = new \ZipArchive(); $za->open($newDocumentPath); $i = 0; for ($i=0; $i<$za->numFiles;$i++) { if ($za->statIndex($i)['name'] == "content.xml") { $za->replaceFile($tmp_location, $i); break; } } $za->close(); $fileSize = filesize($newDocumentPath); $tabDocuments = $this->getEntityManager()->getRepository(\Oscar\Entity\TabDocument::class)->findBy([], ['label' => 'ASC']); Loading Loading @@ -122,3 +169,84 @@ class ConventionModeleInstanceController extends AbstractOscarController impleme } } function replace_in_xml(string $xmlString, string $lookingFor, string $replaceWith) : string { $xmlStringSplitPerCharacters = mb_str_split($xmlString, 1, "UTF-8"); $xmlStringSplitPerCharactersLength = count($xmlStringSplitPerCharacters); if ($xmlStringSplitPerCharactersLength == 0) { return $xmlString; } $lookingFor = str_replace("'", "'", $lookingFor); $lookingForSplitPerCharacters = mb_str_split($lookingFor, 1, "UTF-8"); $lookingForSplitPerCharactersLength = count($lookingForSplitPerCharacters); if ($lookingForSplitPerCharactersLength == 0) { return $xmlString; } //implode("", array_slice($xmlStringSplitPerCharacters, $currentPosition - 10, $currentPosition + 10)); $lookingForCurrentCharacterIndex = 0; $resultString = ""; $notYetTotallyFoundBuffer = ""; $currentPosition = 0; $startIgnoringTagPositionFirstOfAll = -1; $startIgnoringTagPosition = -1; for ($currentPosition = 0; $currentPosition < $xmlStringSplitPerCharactersLength; $currentPosition++) { // We are ignoring xml tag if ($startIgnoringTagPosition != -1) { if ($xmlStringSplitPerCharacters[$currentPosition] == '>') { $startIgnoringTagPosition = -1; } // We found the character we are looking for } else if ($xmlStringSplitPerCharacters[$currentPosition] == $lookingForSplitPerCharacters[$lookingForCurrentCharacterIndex]) { $lookingForCurrentCharacterIndex++; // Whole match found if ($lookingForCurrentCharacterIndex == $lookingForSplitPerCharactersLength) { $resultString .= $replaceWith; $notYetTotallyFoundBuffer = ""; $lookingForCurrentCharacterIndex = 0; $startIgnoringTagPositionFirstOfAll = -1; $startIgnoringTagPosition = -1; } else { // Partial match $notYetTotallyFoundBuffer .= $xmlStringSplitPerCharacters[$currentPosition]; } } else if ($lookingForCurrentCharacterIndex != 0 && $xmlStringSplitPerCharacters[$currentPosition] == '<') { if ($startIgnoringTagPositionFirstOfAll == -1) { $startIgnoringTagPositionFirstOfAll = $currentPosition; } $startIgnoringTagPosition = $currentPosition; // We didn't find the character we were expecting } else if ($startIgnoringTagPositionFirstOfAll != -1) { $currentPosition = $startIgnoringTagPositionFirstOfAll; $startIgnoringTagPositionFirstOfAll = -1; $startIgnoringTagPosition = -1; $notYetTotallyFoundBuffer = ""; $lookingForCurrentCharacterIndex = 0; } else if ($lookingForCurrentCharacterIndex != 0) { // If we were in the middle of a potential match, restore what was already read $resultString .= $notYetTotallyFoundBuffer; $notYetTotallyFoundBuffer = ""; $lookingForCurrentCharacterIndex = 0; $currentPosition--; // Reconsidere current character, because it could be the start of the match } else { // Just add the character to the result string $resultString .= $xmlStringSplitPerCharacters[$currentPosition]; } } return $resultString; } module/Oscar/src/Oscar/Controller/ConventionModeleInstanceControllerFactory.php +1 −0 Original line number Diff line number Diff line Loading @@ -16,6 +16,7 @@ class ConventionModeleInstanceControllerFactory implements FactoryInterface $c->setOscarUserContextService($container->get(OscarUserContext::class)); $c->setOscarConfigurationService($container->get(\Oscar\Service\OscarConfigurationService::class)); $c->conventionModeleInstanceService = $container->get(\Oscar\Service\ConventionModeleInstanceService::class); $c->activityService = $container->get(\Oscar\Service\ProjectGrantService::class); return $c; } } module/Oscar/view/oscar/public/index.phtml +13 −0 Original line number Diff line number Diff line Loading @@ -168,6 +168,19 @@ if (file_exists(__DIR__ . '/../../../../../data/home.html')): </div> <?php endif; ?> <div class="row"> <div class="col-md-12"> <div style="margin-top: 3rem; background: white; padding: 2rem; border-radius: 1rem;"> <h3>Créer une nouvelle demande de convention</h3> <ul style="font-size: larger; font-weight: bolder;"> <?php foreach($conventionModeles as $conventionModele): ?> <li><a href="<?= $this->url('conventionModeles/instance/instancier', ['id' => $conventionModele->id]) ?>"><?= $conventionModele->nom ?></a></li> <?php endforeach; ?> </ul> </div> </div> </div> <?php if( $sectionTodo ): ?> <div class="col-md-<?= 12/$cols ?>"> <?= $sectionTodo ?> Loading Loading
module/Oscar/src/Oscar/Controller/ConventionModeleEtapeAdministrationController.php +1 −3 Original line number Diff line number Diff line Loading @@ -81,8 +81,6 @@ class ConventionModeleEtapeAdministrationController extends AbstractOscarControl } else if ($this->params()->fromPost('action') == "téléverser_fichier") { $originalFilename = $_FILES['file']['name']; $slugify = new \Cocur\Slugify\Slugify(); $renamed = sprintf( Loading
module/Oscar/src/Oscar/Controller/ConventionModeleInstanceController.php +130 −2 Original line number Diff line number Diff line Loading @@ -8,6 +8,8 @@ class ConventionModeleInstanceController extends AbstractOscarController impleme /** @var \Oscar\Service\ConventionModeleInstanceService */ public $conventionModeleInstanceService; /** @var \Oscar\Service\ProjectGrantService */ public $activityService; public function afficherAction() { Loading @@ -27,7 +29,7 @@ class ConventionModeleInstanceController extends AbstractOscarController impleme if ($conventionModeleInstance->conventionModeleEtapeEnCours->conventionModeleEtapeSuivante != NULL) { $conventionModeleInstance->conventionModeleEtapeEnCours = $conventionModeleInstance->conventionModeleEtapeEnCours->conventionModeleEtapeSuivante; } else { $this->créerActivité($conventionModeleInstance->conventionModeleEtapeEnCours); $this->créerActivité($conventionModeleInstance->conventionModeleEtapeEnCours, $conventionModeleInstance); $conventionModeleInstance->conventionModeleEtapeEnCours = NULL; } Loading @@ -39,7 +41,7 @@ class ConventionModeleInstanceController extends AbstractOscarController impleme return $this->redirect()->toRoute('conventionModeleInstances/afficher', ['id' => $conventionModeleInstance->id]); } private function créerActivité(\Oscar\Entity\ConventionModeleEtape $conventionModeleEtape) { private function créerActivité(\Oscar\Entity\ConventionModeleEtape $conventionModeleEtape, \Oscar\Entity\ConventionModeleInstance $conventionModeleInstance) { $newActivity = new \Oscar\Entity\Activity(); $newActivity->setCurrency($this->getEntityManager()->getRepository(\Oscar\Entity\Currency::class)->findAll()[0]); $newActivity->setPcruValidPoleCompetitivite(false); Loading @@ -47,6 +49,13 @@ class ConventionModeleInstanceController extends AbstractOscarController impleme $newActivity->setMotscles([]); $this->getEntityManager()->persist($newActivity); // Mise à jour de l'index de recherche try { $this->activityService->jobSearchUpdate($newActivity); } catch (Exception $e) { $this->getLoggerService()->error($e->getMessage()); } if (mb_strlen(trim($conventionModeleEtape->fichier)) > 0) { // Copie du fichier Loading @@ -67,7 +76,45 @@ class ConventionModeleInstanceController extends AbstractOscarController impleme ) . ".odt"; $newDocumentPath = $destination . DIRECTORY_SEPARATOR . $renamed; //copy($documentPath, $newDocumentPath); $conventionModeleFileContent = file_get_contents('zip://' . $documentPath . "#content.xml"); $conventionModeleFileContentReplaced = $conventionModeleFileContent; // $conventionModeleFileContentReplaced = replace_in_xml($conventionModeleFileContentReplaced, "MES_CONVENTIONS_REMPLACER[La mise à disposition s'inscrit-elle dans le cadre d'une convention actuellement en vigueur ?]", "Oui"); foreach ($conventionModeleInstance->reponses as $key => $value) { $conventionModeleFileContentReplaced = replace_in_xml($conventionModeleFileContentReplaced, "MES_CONVENTIONS_REMPLACER[" . $key . "]", $value); } $slugify = new \Cocur\Slugify\Slugify(); $tmp_location = sprintf("/tmp/oscar-conventions-%s-%s", $slugify->slugify((new \DateTime())->format(\DateTime::ATOM)), $slugify->slugify($conventionModeleEtape->fichier) ); file_put_contents($tmp_location, $conventionModeleFileContentReplaced); copy($documentPath, $newDocumentPath); $za = new \ZipArchive(); $za->open($newDocumentPath); $i = 0; for ($i=0; $i<$za->numFiles;$i++) { if ($za->statIndex($i)['name'] == "content.xml") { $za->replaceFile($tmp_location, $i); break; } } $za->close(); $fileSize = filesize($newDocumentPath); $tabDocuments = $this->getEntityManager()->getRepository(\Oscar\Entity\TabDocument::class)->findBy([], ['label' => 'ASC']); Loading Loading @@ -122,3 +169,84 @@ class ConventionModeleInstanceController extends AbstractOscarController impleme } } function replace_in_xml(string $xmlString, string $lookingFor, string $replaceWith) : string { $xmlStringSplitPerCharacters = mb_str_split($xmlString, 1, "UTF-8"); $xmlStringSplitPerCharactersLength = count($xmlStringSplitPerCharacters); if ($xmlStringSplitPerCharactersLength == 0) { return $xmlString; } $lookingFor = str_replace("'", "'", $lookingFor); $lookingForSplitPerCharacters = mb_str_split($lookingFor, 1, "UTF-8"); $lookingForSplitPerCharactersLength = count($lookingForSplitPerCharacters); if ($lookingForSplitPerCharactersLength == 0) { return $xmlString; } //implode("", array_slice($xmlStringSplitPerCharacters, $currentPosition - 10, $currentPosition + 10)); $lookingForCurrentCharacterIndex = 0; $resultString = ""; $notYetTotallyFoundBuffer = ""; $currentPosition = 0; $startIgnoringTagPositionFirstOfAll = -1; $startIgnoringTagPosition = -1; for ($currentPosition = 0; $currentPosition < $xmlStringSplitPerCharactersLength; $currentPosition++) { // We are ignoring xml tag if ($startIgnoringTagPosition != -1) { if ($xmlStringSplitPerCharacters[$currentPosition] == '>') { $startIgnoringTagPosition = -1; } // We found the character we are looking for } else if ($xmlStringSplitPerCharacters[$currentPosition] == $lookingForSplitPerCharacters[$lookingForCurrentCharacterIndex]) { $lookingForCurrentCharacterIndex++; // Whole match found if ($lookingForCurrentCharacterIndex == $lookingForSplitPerCharactersLength) { $resultString .= $replaceWith; $notYetTotallyFoundBuffer = ""; $lookingForCurrentCharacterIndex = 0; $startIgnoringTagPositionFirstOfAll = -1; $startIgnoringTagPosition = -1; } else { // Partial match $notYetTotallyFoundBuffer .= $xmlStringSplitPerCharacters[$currentPosition]; } } else if ($lookingForCurrentCharacterIndex != 0 && $xmlStringSplitPerCharacters[$currentPosition] == '<') { if ($startIgnoringTagPositionFirstOfAll == -1) { $startIgnoringTagPositionFirstOfAll = $currentPosition; } $startIgnoringTagPosition = $currentPosition; // We didn't find the character we were expecting } else if ($startIgnoringTagPositionFirstOfAll != -1) { $currentPosition = $startIgnoringTagPositionFirstOfAll; $startIgnoringTagPositionFirstOfAll = -1; $startIgnoringTagPosition = -1; $notYetTotallyFoundBuffer = ""; $lookingForCurrentCharacterIndex = 0; } else if ($lookingForCurrentCharacterIndex != 0) { // If we were in the middle of a potential match, restore what was already read $resultString .= $notYetTotallyFoundBuffer; $notYetTotallyFoundBuffer = ""; $lookingForCurrentCharacterIndex = 0; $currentPosition--; // Reconsidere current character, because it could be the start of the match } else { // Just add the character to the result string $resultString .= $xmlStringSplitPerCharacters[$currentPosition]; } } return $resultString; }
module/Oscar/src/Oscar/Controller/ConventionModeleInstanceControllerFactory.php +1 −0 Original line number Diff line number Diff line Loading @@ -16,6 +16,7 @@ class ConventionModeleInstanceControllerFactory implements FactoryInterface $c->setOscarUserContextService($container->get(OscarUserContext::class)); $c->setOscarConfigurationService($container->get(\Oscar\Service\OscarConfigurationService::class)); $c->conventionModeleInstanceService = $container->get(\Oscar\Service\ConventionModeleInstanceService::class); $c->activityService = $container->get(\Oscar\Service\ProjectGrantService::class); return $c; } }
module/Oscar/view/oscar/public/index.phtml +13 −0 Original line number Diff line number Diff line Loading @@ -168,6 +168,19 @@ if (file_exists(__DIR__ . '/../../../../../data/home.html')): </div> <?php endif; ?> <div class="row"> <div class="col-md-12"> <div style="margin-top: 3rem; background: white; padding: 2rem; border-radius: 1rem;"> <h3>Créer une nouvelle demande de convention</h3> <ul style="font-size: larger; font-weight: bolder;"> <?php foreach($conventionModeles as $conventionModele): ?> <li><a href="<?= $this->url('conventionModeles/instance/instancier', ['id' => $conventionModele->id]) ?>"><?= $conventionModele->nom ?></a></li> <?php endforeach; ?> </ul> </div> </div> </div> <?php if( $sectionTodo ): ?> <div class="col-md-<?= 12/$cols ?>"> <?= $sectionTodo ?> Loading