public function actionDownloadTranslations($id, $hash) { $project = $this->projectFacade->find($id); $verifyHash = hash_hmac('sha256', $id, $project->getKey()); if ($hash === $verifyHash) { $this->buildFiles($project); } else { $this->sendResponse(new \Nette\Application\Responses\JsonResponse(['error' => 'true', 'message' => 'Bad request. Hash does not match.'])); } $this->terminate(); }
public function formNewProjectSubmitted(Form $form) { $values = $form->getValues(); if ($this->user->identity->canAddProject()) { try { $project = $this->projectFacade->createProject($values, $this->me); $this->log($project, Activity::CREATE_PROJECT); $this->redirect('Project:', array('id' => $project->getId())); } catch (ExistingProjectException $e) { $this->flash($e->getMessage(), 'error'); } } else { $this->flash('You cannot add more projects.', 'error'); $this->redirect('this'); } }
public function importTemplate($data, \Project $project) { $translations = $project->getTranslations(); if ($translations->count() === 0) { return 0; } $imported = 0; $singleTranslation = $this->prepareTranslationsArray(1); $translationsData = []; foreach ($translations as $translation) { $pluralsCount = Langs::getPluralsCount($translation->getLang()); $translationsData[$translation->getLang()] = array('pluralsCount' => $pluralsCount, 'translations' => $this->prepareTranslationsArray($pluralsCount)); } foreach ($translations as $translation) { $translationData = $translationsData[$translation->getLang()]; foreach ($data['messages'] as $messageId => $messageData) { $project->addTemplateMessage($messageId, $messageData); $message = $this->prepareMessage($messageData, $translationData['translations'], $singleTranslation, $translationData['pluralsCount']); $added = $translation->addMessage($messageId, $message); if ($added) { $this->dm->persist($message); $imported++; } } $this->dm->persist($translation); } $this->dm->persist($project); $this->dm->flush(); return $imported; }