Gc\Core\Translator::getValues PHP Method

getValues() public method

Return all values from core_config_data
public getValues ( string $locale = null, integer $limit = null ) : array
$locale string Locale
$limit integer Limit
return array
    public function getValues($locale = null, $limit = null)
    {
        $select = new Select();
        $select->from('core_translate')->columns(array('src_id' => 'id', 'source'))->join('core_translate_locale', 'core_translate.id = core_translate_locale.core_translate_id', array('dst_id' => 'id', 'destination', 'locale'), Select::JOIN_INNER);
        if (!empty($locale)) {
            $select->where->equalTo('core_translate_locale.locale', $locale);
        }
        if (!empty($limit)) {
            $select->limit($limit);
        }
        $select->order('core_translate.source ASC');
        return $this->fetchAll($select);
    }

Usage Example

Example #1
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;
 }