Inheritance: extends Gc\Db\AbstractTable
Example #1
0
 /**
  * Insert translations into database
  *
  * @param array $session Session array
  *
  * @return void
  */
 protected function insertTranslations($session)
 {
     if (empty($session['copy_translations'])) {
         return;
     }
     //Save all languages in database
     $languagesFilename = glob(GC_APPLICATION_PATH . '/data/install/translation/*.php');
     $translator = new Core\Translator();
     foreach ($languagesFilename as $language) {
         $langConfig = (include $language);
         $locale = basename($language, '.php');
         foreach ($langConfig as $source => $destination) {
             $translator->setValue($source, array(array('locale' => $locale, 'value' => $destination)));
         }
         copy($language, GC_APPLICATION_PATH . '/data/translation/' . basename($language));
     }
 }
 /**
  * Test
  *
  * @return void
  */
 public function testDownloadActionWithEmptyContent()
 {
     $translator = new Translator();
     $translator->delete('1 = 1');
     $this->dispatch('/admin/content/translation/download');
     $this->assertResponseStatusCode(302);
     $this->assertModuleName('GcContent');
     $this->assertControllerName('TranslationController');
     $this->assertControllerClass('TranslationController');
     $this->assertMatchedRouteName('content/translation/download');
 }
Example #3
0
 /**
  * Send a file to the browser
  *
  * @return \Zend\Stdlib\ResponseInterface
  */
 public function downloadAction()
 {
     $translator = new Translator();
     $values = $translator->getValues();
     $zip = new ZipArchive();
     $tmpFilename = tempnam(sys_get_temp_dir(), 'zip');
     $res = $zip->open($tmpFilename, ZipArchive::CREATE);
     if ($res === true) {
         $locales = array();
         foreach ($values as $value) {
             if (!isset($locales[$value['locale']])) {
                 $locales[$value['locale']] = array();
             }
             $locales[$value['locale']][] = sprintf('"%s","%s"', str_replace('"', '"""', $value['source']), str_replace('"', '"""', $value['destination']));
         }
         foreach ($locales as $locale => $content) {
             $zip->addFromString($locale . '.csv', implode(PHP_EOL, $content));
         }
         $zip->close();
         $content = file_get_contents($tmpFilename);
         $filename = 'translations.zip';
         unlink($tmpFilename);
     }
     if (empty($content) or empty($filename)) {
         $this->flashMessenger()->addErrorMessage('Can not save translations');
         return $this->redirect()->toRoute('content/translation');
     }
     $headers = new Headers();
     $headers->addHeaderLine('Pragma', 'public')->addHeaderLine('Cache-control', 'must-revalidate, post-check=0, pre-check=0')->addHeaderLine('Cache-control', 'private')->addHeaderLine('Expires', -1)->addHeaderLine('Content-Type', 'application/octet-stream')->addHeaderLine('Content-Transfer-Encoding', 'binary')->addHeaderLine('Content-Length', strlen($content))->addHeaderLine('Content-Disposition', 'attachment; filename=' . $filename);
     $response = $this->getResponse();
     $response->setHeaders($headers);
     $response->setContent($content);
     return $response;
 }