public function sendInvitationMessage(User $user, User $userThatInvits, Project $project) { $subject = 'Invitation for new user to ' . self::SELF_NAME; $template = $this->templateName('invitationUser.html.twig'); $parameters = array('user' => $user, 'invites' => $userThatInvits, 'subject' => $subject, 'project' => $project, 'urls' => array('homePage' => $this->router->generate('home', array('invited' => $userThatInvits->getId(), 'project' => $project->getId()), true))); $emailTo = $user->getEmail(); return $this->sendMail($subject, $emailTo, $template, $parameters); }
/** * @Route("/save-document/{projectId}", name="save_document") * @Method("POST") * @ParamConverter("project", class="TranslationsBundle:Project", options={"id" = "projectId"}) */ public function saveDocumentAction(Request $request, Project $project) { $this->init(); $bundle = $request->get('bundle'); $locale = $request->get('locale'); $key = $request->get('key'); $message = str_replace("\\'", "'", $request->get('message')); //@TODO: comprobar que el usuario que esta logado tiene permiso para hacer esto if (!$bundle || !$locale || !$key || !$message) { die('validation exception, request content = ' . $request->getContent()); } $transDocRepository = $this->getTranslatableDocumentRepository(); /** @var TranslatableDocument $translation */ $translation = $transDocRepository->findOneBy(array('projectId' => $project->getId(), 'bundle' => $bundle, 'key' => $key)); if (!$translation) { return $this->printResult(array('result' => false, 'reason' => 'document not found')); } /** @var File[] $translations */ $files = $translation->getFiles(); $found = false; foreach ($files as $file) { if ($file->getLocale() == $locale) { $found = true; break; } } if (!$found) { return $this->printResult(array('result' => false, 'reason' => 'locale not found')); } $file->setMessage($message); $this->dm->persist($translation); $this->dm->flush(); $this->translationsManager->saveLog($translation->getId(), $locale, $message, TranslationLog::TRANSLATE, $this->user, TranslationLog::DOCUMENTS_GROUP); $this->printResult(array('result' => true, 'message' => $message)); }
/** * * $data[key][locale] * { * message, * updatedAt * } * */ protected function sendKeys(Project $project, $catalog) { if (!$project || !$catalog) { return $this->exception("Validation exceptions, missing parameters project={$project->getId()}, catalog={$catalog}"); } /** @var Translation[] $messages */ $messages = $this->getTranslationRepository()->findBy(array('projectId' => $project->getId(), 'catalog' => $catalog, 'deleted' => false), array('key' => 'ASC')); if ($this->debug) { echo sprintf("found %d in translations\n", count($messages)); } $data = array(); $bundles = array(); foreach ($messages as $message) { $key = $message->getKey(); $data[$key] = $message->getTranslations(); $bundles[$key] = $message->getBundle(); } return $this->resultOk(array('data' => $data, 'bundles' => $bundles)); }
public function getStatistics(Project $project) { $bundleData = array(); $catalogData = array(); $bundles = array(); $catalogs = array(); /** @var Translation[] $translations */ $translations = $this->getTranslationRepository()->findBy(array('projectId' => $project->getId())); foreach ($translations as $translation) { $key = $translation->getKey(); $transArray = $translation->getTranslations(); $bundle = $translation->getBundle(); $catalog = $translation->getCatalog(); $bundles[$bundle] = true; $catalogs[$catalog] = true; foreach ($transArray as $locale => $data) { $message = $data['message']; $numWords = count(preg_split('~[^\\p{L}\\p{N}\']+~u', $message)); if (!isset($bundleData[$bundle][$locale])) { $bundleData[$bundle][$locale] = 0; } $bundleData[$bundle][$locale] += $numWords; if (!isset($catalogData[$catalog][$locale])) { $catalogData[$catalog][$locale] = 0; } $catalogData[$catalog][$locale] += $numWords; } } return array('result' => true, 'bundles' => array_keys($bundles), 'catalogs' => array_keys($catalogs), 'bundleData' => $bundleData, 'catalogData' => $catalogData); }