Exemplo n.º 1
0
 public function exportAction()
 {
     $this->checkPermission("translations");
     $admin = $this->getParam("admin");
     // clear translation cache
     Translation\AbstractTranslation::clearDependentCache();
     if ($admin) {
         $list = new Translation\Admin\Listing();
     } else {
         $list = new Translation\Website\Listing();
     }
     $list->setOrder("asc");
     $list->setOrderKey("key");
     $condition = $this->getGridFilterCondition();
     if ($condition) {
         $list->setCondition($condition);
     }
     $list->load();
     $translations = array();
     $translationObjects = $list->getTranslations();
     // fill with one dummy translation if the store is empty
     if (empty($translationObjects)) {
         if ($admin) {
             $t = new Translation\Admin();
             $languages = Tool\Admin::getLanguages();
         } else {
             $t = new Translation\Website();
             $languages = Tool::getValidLanguages();
         }
         foreach ($languages as $language) {
             $t->addTranslation($language, "");
         }
         $translationObjects[] = $t;
     }
     foreach ($translationObjects as $t) {
         $translations[] = array_merge(array("key" => $t->getKey(), "creationDate" => $t->getCreationDate(), "modificationDate" => $t->getModificationDate()), $t->getTranslations());
     }
     //header column
     $columns = array_keys($translations[0]);
     if ($admin) {
         $languages = Tool\Admin::getLanguages();
     } else {
         $languages = Tool::getValidLanguages();
     }
     //add language columns which have no translations yet
     foreach ($languages as $l) {
         if (!in_array($l, $columns)) {
             $columns[] = $l;
         }
     }
     $headerRow = array();
     foreach ($columns as $key => $value) {
         $headerRow[] = '"' . $value . '"';
     }
     $csv = implode(";", $headerRow) . "\r\n";
     foreach ($translations as $t) {
         $tempRow = array();
         foreach ($columns as $key) {
             $value = $t[$key];
             //clean value of evil stuff such as " and linebreaks
             if (is_string($value)) {
                 $value = Tool\Text::removeLineBreaks($value);
                 $value = str_replace('"', '"', $value);
                 $tempRow[$key] = '"' . $value . '"';
             } else {
                 $tempRow[$key] = $value;
             }
         }
         $csv .= implode(";", $tempRow) . "\r\n";
     }
     $suffix = $admin ? "admin" : "website";
     header('Content-type: text/csv; charset=UTF-8');
     header("Content-Disposition: attachment; filename=\"export_ " . $suffix . "_translations.csv\"");
     ini_set('display_errors', false);
     //to prevent warning messages in csv
     echo $csv;
     die;
 }
Exemplo n.º 2
0
 public function exportAction()
 {
     $this->checkPermission("translations");
     $admin = $this->getParam("admin");
     if ($admin) {
         $class = "\\Pimcore\\Model\\Translation\\Admin";
     } else {
         $class = "\\Pimcore\\Model\\Translation\\Website";
     }
     $tableName = call_user_func($class . "\\Dao::getTableName");
     // clear translation cache
     Translation\AbstractTranslation::clearDependentCache();
     if ($admin) {
         $list = new Translation\Admin\Listing();
     } else {
         $list = new Translation\Website\Listing();
     }
     $joins = [];
     $list->setOrder("asc");
     $list->setOrderKey($tableName . ".key", false);
     $condition = $this->getGridFilterCondition($tableName);
     if ($condition) {
         $list->setCondition($condition);
     }
     $filters = $this->getGridFilterCondition($tableName, true);
     if ($filters) {
         $joins = array_merge($joins, $filters["joins"]);
     }
     $this->extendTranslationQuery($joins, $list, $tableName, $filters);
     $list->load();
     $translations = [];
     $translationObjects = $list->getTranslations();
     // fill with one dummy translation if the store is empty
     if (empty($translationObjects)) {
         if ($admin) {
             $t = new Translation\Admin();
             $languages = Tool\Admin::getLanguages();
         } else {
             $t = new Translation\Website();
             $languages = $this->getUser()->getAllowedLanguagesForViewingWebsiteTranslations();
         }
         foreach ($languages as $language) {
             $t->addTranslation($language, "");
         }
         $translationObjects[] = $t;
     }
     foreach ($translationObjects as $t) {
         $translations[] = array_merge(["key" => $t->getKey(), "creationDate" => $t->getCreationDate(), "modificationDate" => $t->getModificationDate()], $t->getTranslations());
     }
     //header column
     $columns = array_keys($translations[0]);
     if ($admin) {
         $languages = Tool\Admin::getLanguages();
     } else {
         $languages = $this->getUser()->getAllowedLanguagesForViewingWebsiteTranslations();
     }
     //add language columns which have no translations yet
     foreach ($languages as $l) {
         if (!in_array($l, $columns)) {
             $columns[] = $l;
         }
     }
     //remove invalid languages
     foreach ($columns as $key => $column) {
         if (strtolower(trim($column)) != 'key' && !in_array($column, $languages)) {
             unset($columns[$key]);
         }
     }
     $columns = array_values($columns);
     $headerRow = [];
     foreach ($columns as $key => $value) {
         $headerRow[] = '"' . $value . '"';
     }
     $csv = implode(";", $headerRow) . "\r\n";
     foreach ($translations as $t) {
         $tempRow = [];
         foreach ($columns as $key) {
             $value = $t[$key];
             //clean value of evil stuff such as " and linebreaks
             if (is_string($value)) {
                 $value = Tool\Text::removeLineBreaks($value);
                 $value = str_replace('"', '"', $value);
                 $tempRow[$key] = '"' . $value . '"';
             } else {
                 $tempRow[$key] = $value;
             }
         }
         $csv .= implode(";", $tempRow) . "\r\n";
     }
     $suffix = $admin ? "admin" : "website";
     header('Content-Encoding: UTF-8');
     header('Content-type: text/csv; charset=UTF-8');
     header("Content-Disposition: attachment; filename=\"export_ " . $suffix . "_translations.csv\"");
     ini_set('display_errors', false);
     //to prevent warning messages in csv
     echo "";
     echo $csv;
     die;
 }