public function import($file, OutputInterface $output) { $csvFile = new CsvFile($file); $csv = $csvFile->getCsv(); $cpt = 0; $configuration = $this->dm->getRepository('AppBundle:Configuration')->findConfiguration(); if (!$configuration) { $configuration = new Configuration(); $configuration->setId(Configuration::PREFIX); } foreach ($csv as $data) { $produit = new Produit(); $produit->setIdentifiant(strtoupper(Transliterator::urlize(trim(preg_replace("/[ ]+/", " ", $data[self::CSV_NOM]))))); $produit->setNom(ucfirst(strtolower($data[self::CSV_NOM]))); $produit->setConditionnement($data[self::CSV_CONDITIONNEMENT]); $produit->setPrixHt($data[self::CSV_PRIX_HT]); $produit->setPrixPrestation($data[self::CSV_PRIX_PRESTATION]); $produit->setPrixVente($data[self::CSV_PRIX_VENTE]); if ($data[self::CSV_STATUT]) { $produit->setStatut(Produit::PRODUIT_ACTIF); } else { $produit->setStatut(Produit::PRODUIT_INACTIF); } $configuration->addProduit($produit); $this->dm->persist($configuration); } $this->dm->flush(); }
/** * Prepares a string so that it can be used in urls. * * @param string $value The value that should be urlised. * * @return string The urlised string. */ public static function getUrl($value) { // convert cyrlic, greek or other caracters to ASCII characters $value = Transliterator::transliterate($value); // make a clean url out of it return Transliterator::urlize($value); }
public function import($file, OutputInterface $output) { $csvFile = new CsvFile($file); $csv = $csvFile->getCsv(); $cpt = 0; $configuration = $this->dm->getRepository('AppBundle:Configuration')->findConfiguration(); if (!$configuration) { $configuration = new Configuration(); $configuration->setId(Configuration::PREFIX); $this->dm->persist($configuration); $this->dm->flush(); } foreach ($csv as $data) { $configuration = $this->dm->getRepository('AppBundle:Configuration')->findConfiguration(); $founded = false; foreach ($configuration->getPrestationsArray() as $prestaConf) { if ($prestaConf->getNom() == $data[self::CSV_NOM]) { $founded = true; } } if ($founded) { continue; } if ($data[self::CSV_ID]) { $prestation = new Prestation(); $prestation->setIdentifiant(strtoupper(Transliterator::urlize(trim(preg_replace("/[ ]+/", " ", $data[self::CSV_ID]))))); $prestation->setNom($data[self::CSV_NOM]); $prestation->setNomCourt($data[self::CSV_NOM_COURT]); $configuration->addPrestation($prestation); $this->dm->flush(); } } }
/** * Transforms a text (for example a node title) into a valid node name by removing invalid characters and * transliterating special characters if possible. * * @param string $name The possibly invalid node name * @return string A valid node name */ public static function renderValidNodeName($name) { // Check if name already match name pattern to prevent unnecessary transliteration if (preg_match(NodeInterface::MATCH_PATTERN_NAME, $name) === 1) { return $name; } // Transliterate (transform 北京 to 'Bei Jing') $name = Transliterator::transliterate($name); // Urlization (replace spaces with dash, special special characters) $name = Transliterator::urlize($name); // Ensure only allowed characters are left $name = preg_replace('/[^a-z0-9\\-]/', '', $name); return $name; }
public function hardSave($directory, $path) { $basePath = rtrim($this->settings->path, '/') . '/' . Transliterator::urlize($directory); $baseUrl = rtrim($this->settings->urlPath, '/') . '/' . Transliterator::urlize($directory); if (!file_exists($basePath)) { mkdir($basePath, 0755, true); } $savePath = $basePath . '/' . basename($path); $saveUrl = $baseUrl . '/' . basename($path); if (rename($path, $savePath)) { $this->savedFiles[$savePath] = $saveUrl; return true; } return false; }
/** * Generates a URI path segment for a given node taking it's language dimension into account * * @param NodeInterface $node Optional node to determine language dimension * @param string $text Optional text * @return string */ public function generateUriPathSegment(NodeInterface $node = null, $text = null) { if ($node) { $text = $text ?: $node->getLabel() ?: $node->getName(); $dimensions = $node->getContext()->getDimensions(); if (array_key_exists('language', $dimensions) && $dimensions['language'] !== array()) { $locale = new Locale($dimensions['language'][0]); $language = $locale->getLanguage(); } } elseif (strlen($text) === 0) { throw new Exception('Given text was empty.', 1457591815); } $text = $this->transliterationService->transliterate($text, isset($language) ? $language : null); return Transliterator::urlize($text); }
public function import($file, OutputInterface $output) { $csvFile = new CsvFile($file); $progress = new ProgressBar($output, 100); $progress->start(); $csv = $csvFile->getCsv(); $configuration = $this->dm->getRepository('AppBundle:Configuration')->findConfiguration(); $prestationsArray = $configuration->getPrestationsArray(); $i = 0; $cptTotal = 0; foreach ($csv as $data) { $contrat = $this->cm->getRepository()->findOneByIdentifiantReprise($data[self::CSV_OLD_ID_CONTRAT]); if (!$contrat) { $i++; $cptTotal++; continue; } $prestationNom = strtoupper(Transliterator::urlize(str_replace('#', '', $data[self::CSV_PRESTATION]))); if (!array_key_exists($prestationNom, $prestationsArray)) { $i++; $cptTotal++; $output->writeln(sprintf("<comment>La prestation '%s' du contrat %s n'existe pas en base!</comment>", $prestationNom, $contrat->getId())); continue; } $prestationConf = $prestationsArray[$prestationNom]; $prestation = clone $prestationConf; $prestation->setNbPassages(0); $contrat->addPrestation($prestation); $i++; $cptTotal++; if ($cptTotal % (count($csv) / 100) == 0) { $progress->advance(); } if ($i >= 1000) { $this->dm->flush(); $this->dm->clear(); gc_collect_cycles(); $i = 0; } } $this->dm->flush(); $progress->finish(); }
/** * @dataProvider provideUrlizationCases */ public function testUrlization($input, $expected) { $this->assertSame($expected, Transliterator::urlize($input)); }
/** * Set nom * * @param string $nom * @return self */ public function setNom($nom) { $this->nom = $nom; $this->setIdentifiant(strtoupper(Transliterator::urlize($nom))); return $this; }
/** * @Route("/passage/pdf-missions-massif", name="passage_pdf_missions_massif") */ public function pdfMissionsMassifAction(Request $request) { $fm = $this->get('facture.manager'); $pm = $this->get('passage.manager'); $dm = $this->get('doctrine_mongodb')->getManager(); if ($request->get('technicien')) { $technicien = $dm->getRepository('AppBundle:Compte')->findOneById($request->get('technicien')); $passages = $pm->getRepository()->findAllPlanifieByPeriodeAndIdentifiantTechnicien($request->get('dateDebut'), $request->get('dateFin'), $technicien); $filename = sprintf("suivis_client_%s_%s_%s.pdf", $request->get('dateDebut'), $request->get('dateFin'), strtoupper(Transliterator::urlize($technicien->getIdentite()))); } else { $passages = $pm->getRepository()->findAllPlanifieByPeriode($request->get('dateDebut'), $request->get('dateFin')); $filename = sprintf("suivis_client_%s_%s.pdf", $request->get('dateDebut'), $request->get('dateFin')); } $passagesHistories = array(); foreach ($passages as $passage) { $passagesHistories[$passage->getId()] = $pm->getRepository()->findHistoriqueByEtablissementAndPrestationsAndNumeroContrat($passage->getContrat(), $passage->getEtablissement(), $passage->getPrestations()); } $html = $this->renderView('passage/pdfMissionsMassif.html.twig', array('passages' => $passages, 'passagesHistories' => $passagesHistories)); if ($request->get('output') == 'html') { return new Response($html, 200); } return new Response($this->get('knp_snappy.pdf')->getOutputFromHtml($html, $this->getPdfGenerationOptions()), 200, array('Content-Type' => 'application/pdf', 'Content-Disposition' => 'attachment; filename="' . $filename . '"')); }
/** * @param string $name */ public function setName($name) { $this->name = Transliterator::urlize($name) . '_' . sha1($name); }
/** * Slugify string. * * @param string $text Text string to slugify * @param string $separator Character used to separate each word * @return string $slugified Slugified string * * @since 3.1.0 */ public static function urlize($text, $separator = '-') { return Transliterator::urlize($text, $separator); }
public function getPaiementUniqueParLibelle() { $paiementsUnique = array(); foreach ($this->getPaiement() as $paiement) { if (!$paiement->getLibelle() || $paiement->getLibelle() == "") { $key = md5(microtime() . rand()); $paiementsUnique[$key] = clone $paiement; } else { $key = Transliterator::urlize($paiement->getMoyenPaiement() . '-' . $paiement->getLibelle()); if (!array_key_exists($key, $paiementsUnique)) { $paiementsUnique[$key] = clone $paiement; $paiementsUnique[$key]->setMontantTemporaire($paiement->getMontant()); } else { $paiementsUnique[$key]->addMontantTemporaire($paiement->getMontant()); } $paiementsUnique[$key]->addFactureTemporaire($paiement->getFacture()); } } return $paiementsUnique; }
/** * @param string $type * @param Route $route * @param string|null $value * @param array|null $data * * @return string */ private function routeRegexpCapture(string $type, Route $route, string $value = null, array $data = null) : string { $begin = substr($value, 0, strpos($value, '<')); $variable = substr($value, strpos($value, '<') + 1, strpos($value, '>') - strpos($value, '<') - 1); $capture = substr($value, strpos($value, '>') + 1); if (empty($capture)) { $capture = '[^/]+'; } if (!is_null($data)) { if (!array_key_exists($variable, $data) && ($type == 'C' || $type == 'S')) { throw new \InvalidArgumentException(sprintf("Missing variable route '%s' to generate route '%s'", $variable, $route->getName())); } if (isset($data[$variable])) { if ($route->getOption(AbstractRoute::OPTIONS_URLIZE) === false) { $dest = $data[$variable]; } else { $dest = Transliterator::urlize($data[$variable]); } } } else { $dest = '('; if ($begin) { $dest .= '(?:' . $begin . ')'; } if ($type == 'S') { $dest .= '(?:' . $capture . ')'; } else { $dest .= '(?<' . $variable . '>' . $capture . ')'; } $dest .= ')'; if ($type == 'O') { $dest .= '?'; } } return $dest; }
private function importSubjects($languageCode) { if (empty($this->settings[$languageCode]['categories'])) { return array(); } $subjects = []; $categoryIds = unserialize($this->settings[$languageCode]['categories']); if (!is_array($categoryIds)) { return []; } foreach ($categoryIds as $categoryId) { $categorySql = "SELECT locale, setting_value FROM " . "controlled_vocab_entry_settings WHERE " . "controlled_vocab_entry_id = :categoryId"; $categoryStatement = $this->dbalConnection->prepare($categorySql); $categoryStatement->bindValue('categoryId', $categoryId); $categoryStatement->execute(); $pkpCategorySettings = $categoryStatement->fetchAll(); $categorySettings = []; foreach ($pkpCategorySettings as $pkpSetting) { $locale = !empty($pkpSetting['locale']) ? $pkpSetting['locale'] : $languageCode; $value = $pkpSetting['setting_value']; $categorySettings[$locale] = $value; } $slug = Transliterator::urlize(array_values($categorySettings)[0]); $tags = str_replace(' ', ', ', strtolower(array_values($categorySettings)[0])); $subject = $this->em->getRepository('OjsJournalBundle:Subject')->findOneBy(['slug' => $slug]); if (!$subject) { $subject = new Subject(); $subject->setSlug($slug); $subject->setTags($tags); foreach ($categorySettings as $locale => $value) { $subject->setCurrentLocale(mb_substr($locale, 0, 2, 'UTF-8')); $subject->setSubject($value); $this->em->persist($subject); $this->em->flush(); } } $subjects[] = $subject; } return $subjects; }
/** * Sets the value of title. * * @param string $title the title * * @return self */ public function setTitle($title) { $this->title = $title; $this->setSlug(Transliterator::urlize($this->title)); return $this; }
public function import($file, OutputInterface $output) { $csvFile = new CsvFile($file); $csv = $csvFile->getCsv(); $i = 0; $cptTotal = 0; $progress = new ProgressBar($output, 100); $progress->start(); $configuration = $this->dm->getRepository('AppBundle:Configuration')->findConfiguration(); $produitsArray = $configuration->getProduitsArray(); $prestationsType = $this->dm->getRepository('AppBundle:Configuration')->findConfiguration()->getPrestationsArray(); foreach ($csv as $data) { if ($data[self::CSV_ETABLISSEMENT_ID] == "000000") { continue; } if (!preg_match('/^[0-9]+$/', $data[self::CSV_ETABLISSEMENT_ID])) { $output->writeln(sprintf("<error>établissement dont le numéro %s n'est pas correct</error>", $data[self::CSV_ETABLISSEMENT_ID])); continue; } $etablissement = $this->em->getRepository()->findOneByIdentifiantReprise($data[self::CSV_ETABLISSEMENT_ID]); if (!$etablissement) { $output->writeln(sprintf("<error>L'établissement %s n'existe pas</error>", $data[self::CSV_ETABLISSEMENT_ID])); continue; } $passage = new Passage(); $passage->setEtablissement($etablissement); if (!$data[self::CSV_DATE_PREVISION]) { $output->writeln(sprintf("<error>Le passage %s ne possède aucune date de prévision!</error>", $data[self::CSV_OLD_ID])); continue; } $passage->setDatePrevision(new \DateTime($data[self::CSV_DATE_PREVISION])); $passage->setIdentifiantReprise($data[self::CSV_OLD_ID]); $passage->setNumeroArchive($data[self::CSV_OLD_ID]); $contrat = $this->cm->getRepository()->findOneByIdentifiantReprise($data[self::CSV_CONTRAT_ID]); if (!$contrat) { //$output->writeln(sprintf("<error>Le contrat %s n'existe pas</error>", $data[self::CSV_CONTRAT_ID])); continue; } $this->dm->persist($passage); $doublonPassage = $this->pm->getRepository()->findOneById($passage->getId()); if ($doublonPassage) { $output->writeln(sprintf("<comment>Le passage d'id %s existe déjà en base (%s)!</comment>", $passage->getId(), $data[self::CSV_OLD_ID])); } $resultStatut = $this->generateStatut($data, $passage, $output); $passage->updateStatut(); if (!$resultStatut) { $output->writeln(sprintf("<error>Aucun statut déterminable pour le passage d'id %s (%s)!</error>", $passage->getId(), $data[self::CSV_OLD_ID])); continue; } $passage->setLibelle($data[self::CSV_LIBELLE]); $passage->setTypePassage($data[self::CSV_TYPE_PASSAGE]); $passage->setDescription(str_replace('#', "\n", $data[self::CSV_DESCRIPTION])); if (!preg_match('/^[0-9]+$/', $data[self::CSV_CONTRAT_ID])) { $output->writeln(sprintf("<error>Passage dont le numéro %s n'est pas correct</error>", $data[self::CSV_CONTRAT_ID])); continue; } if ($data[self::CSV_PRESTATIONS]) { $prestations = explode('#', $data[self::CSV_PRESTATIONS]); foreach ($prestations as $prestationNom) { if (trim($prestationNom) != "") { $prestationIdentifiant = strtoupper(Transliterator::urlize($prestationNom)); if (!array_key_exists($prestationIdentifiant, $prestationsType)) { $output->writeln(sprintf("<comment>La prestation : %s n'existe pas dans la configuration </comment>", $prestationIdentifiant)); continue; } $prestation = $prestationsType[$prestationIdentifiant]; $passage->addPrestation($prestation); $this->dm->persist($passage); } } } else { $output->writeln(sprintf("<comment>Le passage : %s n'a aucune presta </comment>", $data[self::CSV_OLD_ID])); } $identifiantRepriseTechnicien = $data[self::CSV_TECHNICIEN]; if (!is_null($identifiantRepriseTechnicien)) { $compte = $this->um->getRepository()->findOneByIdentifiantReprise($identifiantRepriseTechnicien); if (!is_null($compte)) { $passage->addTechnicien($compte); } } $passage->setContrat($contrat); $passage->setNumeroContratArchive($contrat->getNumeroArchive()); $produits = explode('#', $data[self::CSV_PRODUITS]); foreach ($produits as $produitStr) { if ($produitStr) { $produitdetail = explode('~', $produitStr); $produitQte = 0; $produitLib = $produitdetail[0]; if (count($produitdetail) > 1) { $produitQte = $produitdetail[1]; } if ($produitLib) { $produitToAdd = clone $produitsArray[strtoupper(Transliterator::urlize($produitLib))]; $produitToAdd->setNbUtilisePassage(0); $produitToAdd->setNbTotalContrat(null); $produitToAdd->setNbUtilisePassage($produitQte); $passage->addProduit($produitToAdd); $this->dm->persist($passage); } } } $contrat->addEtablissement($etablissement); $contrat->addPassage($etablissement, $passage); $i++; $cptTotal++; if ($cptTotal % (count($csv) / 100) == 0) { $progress->advance(); } if ($i >= 2000) { $this->dm->flush(); $this->dm->clear(); gc_collect_cycles(); $i = 0; } } $this->dm->flush(); $progress->finish(); }
public function import($file, OutputInterface $output) { $csvFile = new CsvFile($file); $progress = new ProgressBar($output, 100); $progress->start(); $csv = $csvFile->getCsv(); $configuration = $this->dm->getRepository('AppBundle:Configuration')->findConfiguration(); $produitsArray = $configuration->getProduitsArray(); $i = 0; $cptTotal = 0; foreach ($csv as $data) { $societe = $this->sm->getRepository()->findOneBy(array('identifiantReprise' => $data[self::CSV_ID_SOCIETE])); if (!$societe) { $output->writeln(sprintf("<error>La societe %s n'existe pas</error>", $data[self::CSV_ID_SOCIETE])); continue; } $contrat = $this->cm->getRepository()->findOneBy(array('identifiantReprise', $data[self::CSV_ID_CONTRAT])); if (!$contrat) { $contrat = new Contrat(); } else { $output->writeln(sprintf("<error>Le contrat : %s existe déjà en base?</error>", $data[self::CSV_ID_CONTRAT])); } $contrat->setDateCreation(new \DateTime($data[self::CSV_DATE_CREATION])); $contrat->setSociete($societe); $contrat->setTvaReduite(boolval($data[self::CSV_TVA_REDUITE])); $type_contrat = ContratManager::$types_contrat_import_index[$data[self::CSV_TYPE_CONTRAT]]; $contrat->setTypeContrat($type_contrat); $contrat->setReconduit(false); if ($data[self::CSV_DATE_DEBUT]) { $contrat->setDateDebut(new \DateTime($data[self::CSV_DATE_DEBUT])); } if ($data[self::CSV_DATE_ACCEPTATION]) { $contrat->setDateAcceptation(new \DateTime($data[self::CSV_DATE_ACCEPTATION])); $contrat->setStatut(ContratManager::STATUT_EN_COURS); } else { $contrat->setStatut(ContratManager::STATUT_EN_ATTENTE_ACCEPTATION); } if (!preg_match("/^[0-9+]+\$/", $data[self::CSV_DUREE])) { $output->writeln(sprintf("<error>La durée du contrat %s n'est pas correct : %s</error>", $data[self::CSV_ID_CONTRAT], $data[self::CSV_DUREE])); continue; } $contrat->setDuree($data[self::CSV_DUREE]); $contrat->setDureeGarantie($data[self::CSV_GARANTIE]); $contrat->setDateDebut(new \DateTime($data[self::CSV_DATE_DEBUT])); $dateFin = clone $contrat->getDateDebut(); $dateFin->modify("+ " . $contrat->getDuree() . " month"); $contrat->setDateFin($dateFin); $contrat->setNomenclature(str_replace('#', "\n", $data[self::CSV_NOMENCLATURE])); $contrat->setPrixHt($data[self::CSV_PRIXHT]); $contrat->setIdentifiantReprise($data[self::CSV_ID_CONTRAT]); if (is_integer($data[self::CSV_ARCHIVAGE])) { $contrat->setNumeroArchive(0); } $contrat->setNumeroArchive($data[self::CSV_ARCHIVAGE]); if ($data[self::CSV_ID_COMMERCIAL]) { $commercial = $this->um->getRepository()->findOneByIdentifiantReprise($data[self::CSV_ID_COMMERCIAL]); if ($commercial) { $contrat->setCommercial($commercial); } } if ($data[self::CSV_ID_TECHNICIEN]) { $technicien = $this->um->getRepository()->findOneByIdentifiantReprise($data[self::CSV_ID_TECHNICIEN]); if ($technicien) { $contrat->setTechnicien($technicien); } } if ($data[self::CSV_DATE_RESILIATION]) { $contrat->setDateResiliation(new \DateTime($data[self::CSV_DATE_RESILIATION])); $contrat->setStatut(ContratManager::STATUT_RESILIE); } $produits = explode('#', $data[self::CSV_PRODUITS]); foreach ($produits as $produitStr) { if ($produitStr) { $produitdetail = explode('~', $produitStr); $produitQte = 0; $produitLib = $produitdetail[0]; if (count($produitdetail) > 1) { $produitQte = $produitdetail[1]; } if ($produitLib) { $produitToAdd = clone $produitsArray[strtoupper(Transliterator::urlize($produitLib))]; $produitToAdd->setNbTotalContrat(0); $produitToAdd->setNbTotalContrat($produitQte); $contrat->addProduit($produitToAdd); } } } $this->dm->persist($contrat); $i++; $cptTotal++; if ($cptTotal % (count($csv) / 100) == 0) { $progress->advance(); } if ($i >= 1000) { $this->dm->flush(); $this->dm->clear(); gc_collect_cycles(); $i = 0; } } $this->dm->flush(); $progress->finish(); }
/** * {@inheritdoc} */ public function setSlug($slug) { $this->slug = Transliterator::urlize($slug); }
/** * Set filename * * @param mixed $value * @param bool $overwrite [optional] Default overwrite is true * @param string $separator [optional] Default separator is an underscore '_' * @return void */ public function setFilename($value, $overwrite = true, $separator = '_') { // recast to string if $value is array if (is_array($value)) { $value = implode($separator, $value); } // trim unneeded values $value = trim($value, $separator); // remove all spaces $value = preg_replace('/\\s+/', $separator, $value); // if value is empty, stop here if (empty($value)) { return; } // decode value + lowercase the string $value = strtolower($this->decode($value)); // urlize this part $value = Transliterator::urlize($value); // overwrite filename or add to filename using a prefix in between $this->filename = $overwrite ? $value : $this->filename . $separator . $value; }
public function setName($name) { $this->name = $name; $this->slug = Transliterator::urlize($name); return $this; }
/** * @param string $name */ public function __construct($name) { $this->name = Transliterator::urlize($name); $this->threshold = []; $this->excludeCategories = []; $this->excludeQuestions = []; $this->initialized(); }
/** * Build all elements */ protected function build() { $this->header->clear(); $active = false; /** @var Tab $element */ foreach ($this->body->getElements() as $element) { $active = $element->isActive() ? true : $active; if (!$element->getHref()) { $id = Transliterator::urlize($element->getTitle()); $element->setHref('#' . $id); } } if ($this->activateFirst && $active == false && isset($this->body->getElements()[0])) { $this->body->getElements()[0]->setActive(); } foreach ($this->body->getElements() as $element) { $this->header->add($element->getHeader()); } }