Example #1
0
 public function __construct(Project $project, $locale = "")
 {
     $this->project = $project;
     $this->locales = $project->getManagedLocales();
     $this->locale = $locale;
     $this->bundle_file = false;
 }
Example #2
0
 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);
 }
Example #3
0
 protected function validateRequest(Request $request, Project $project)
 {
     $content = $request->getContent();
     $params = json_decode($content, true);
     if (!isset($params['key']) || !isset($params['secret'])) {
         return false;
     }
     return $params['key'] == $project->getApiKey() && $params['secret'] == $project->getApiSecret();
 }
Example #4
0
 /**
  * @param $buffer
  *
  * @return bool
  */
 protected function validateRequest($buffer)
 {
     $this->project = null;
     $data = json_decode($buffer, true);
     $projectId = isset($data['project_id']) ? $data['project_id'] : 0;
     if (!$projectId) {
         $this->exception('invalid credentials');
         return false;
     }
     $key = $data['auth.key'];
     $secret = $data['auth.secret'];
     $this->project = $this->getProjectRepository()->find($projectId);
     if (!$this->project) {
         $this->exception('invalid project');
         return false;
     }
     return $key == $this->project->getApiKey() && $secret == $this->project->getApiSecret();
 }
Example #5
0
 public function execute(InputInterface $input, OutputInterface $output)
 {
     $container = $this->getContainer();
     /** @var EntityManager $em */
     $em = $container->get('doctrine')->getManager();
     // Create first user
     $user = new User();
     $user->setEmail('*****@*****.**');
     $user->setName('Admin Tradukoj');
     $user->setActive(true);
     $user->addRole(User::ROLE_ADMIN);
     $user->setPassword('Tradukoj$1234');
     /** @var EncoderFactory $encoderFactory */
     $encoderFactory = $container->get('security.encoder_factory');
     $encoder = $encoderFactory->getEncoder($user);
     $user->setPassword($encoder->encodePassword($user->getPassword(), $user->getSalt()));
     $em->persist($user);
     $em->flush();
     $usersColl = new ArrayCollection();
     $usersColl->add($user);
     // create first project
     $project = new Project();
     $project->setName('tradukoj');
     $project->setApiKey('tradukoj.com');
     $project->setApiSecret('Tradukoj$1234');
     $project->setManagedLocales('en,es');
     $project->setProject('tradukoj');
     //$project->setUsers($usersColl);
     $permission = new Permission();
     $permission->setUser($user);
     $permission->setProject($project);
     $permission->addPermission(Permission::OWNER);
     // Give permission to write in all languages
     $permission->addPermission(Permission::WRITE_PERM, '*');
     $em->persist($permission);
     $em->persist($project);
     $em->flush();
     $output->writeln(" done!");
 }
 /**
  * @Given /^Database is clear$/
  */
 public function databaseIsClear()
 {
     $this->initializeDatabase();
     $project = new Project();
     $project->setProject('project ' . $this->project_id);
     $project->setName('project ' . $this->project_id);
     $this->em->persist($project);
     $this->project = $project;
 }
Example #7
0
 /**
  * @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));
 }
Example #8
0
 protected function allLanguageCodes()
 {
     $managed_locales = explode(",", $this->project->getManagedLocales());
     $managed_locales[] = self::WILD_KEY;
     return $managed_locales;
 }
Example #9
0
 /**
  *
  * $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));
 }
Example #10
0
 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);
 }