Vsch\TranslationManager\Manager::zipTranslations PHP Method

zipTranslations() public method

public zipTranslations ( $groups )
    public function zipTranslations($groups)
    {
        $zip_name = tempnam("Translations_" . time(), "zip");
        // Zip name
        $this->zipExporting = new ZipArchive();
        $this->zipExporting->open($zip_name, ZipArchive::OVERWRITE);
        if (!is_array($groups)) {
            if ($groups === '*') {
                $groups = $this->translation->whereNotNull('value')->select(DB::raw('DISTINCT `group`'))->get('group');
                foreach ($groups as $group) {
                    // Stuff with content
                    $this->exportTranslations($group->group, 0);
                }
            } else {
                // Stuff with content
                $this->exportTranslations($groups, 0);
            }
        } else {
            foreach ($groups as $group) {
                // Stuff with content
                $this->exportTranslations($group, 0);
            }
        }
        $this->zipExporting->close();
        $this->zipExporting = null;
        return $zip_name;
    }

Usage Example

 public function getZippedTranslations($group = null)
 {
     // disable gzip compression of this page, this causes wrapping of the zip file in gzip format
     // does not work the zip is still gzip compressed
     if (ini_get('zlib.output_compression')) {
         ini_set('zlib.output_compression', 'Off');
         \Log::info("after turning off zlib.compression current setting " . ini_get('zlib.output_compression'));
     }
     $file = $this->manager->zipTranslations($group);
     if ($group && $group !== '*') {
         $zip_name = "Translations_{$group}_";
         // Zip name
     } else {
         $zip_name = "Translations_";
         // Zip name
     }
     header('Content-Type: application/zip');
     header('Content-Length: ' . filesize($file));
     header('Content-Disposition: attachment; filename="' . $zip_name . date('Ymd-His') . '.zip"');
     header('Content-Transfer-Encoding: binary');
     ob_clean();
     flush();
     readfile($file);
     unlink($file);
     \Log::info("sending file, zlib.compression current setting " . ini_get('zlib.output_compression'));
 }
All Usage Examples Of Vsch\TranslationManager\Manager::zipTranslations