Add documents to archive

@param \Thelia\ImportExport\Export\AbstractExport $export   An export instance
@param \Thelia\Core\Archiver\ArchiverInterface    $archiver
167854
protected function processExportDocuments(AbstractExport $export, ArchiverInterface $archiver)
    {
        foreach ($export->getDocumentsPaths() as $documentPath) {
            $archiver->add($documentPath);
        }
    }
242625
@Override
    public ZipImporter importFrom(InputStream stream, Filter<ArchivePath> filter) throws ArchiveImportException {
        Validate.notNull(stream, "Stream must be specified");
        Validate.notNull(filter, "Filter must be specified");

        try {
            // Wrap in ZipInputStream if we haven't been given one
            final ZipInputStream zipStream = new ZipInputStream(stream);

            ZipEntry entry;
            while ((entry = zipStream.getNextEntry()) != null) {
                // Get the name
                final String entryName = entry.getName();

                if(!filter.include(ArchivePaths.create(entryName))) {
                    zipStream.closeEntry();
                    continue;
                }

                // Get the archive
                final Archive<?> archive = this.getArchive();

                // Handle directories separately
                if (entry.isDirectory()) {
                    archive.addAsDirectory(entryName);
                    continue;
                }

                final ByteArrayOutputStream output = new ByteArrayOutputStream(8192);
                IOUtil.copy(zipStream, output);
                archive.add(new ByteArrayAsset(output.toByteArray()), entryName);
                zipStream.closeEntry();
            }
        } catch (IOException e) {
            throw new ArchiveImportException("Could not import stream", e);
        }
        return this;
    }
1312485
protected static function expandFileList($archiveFiles, $files)
    {
        $newFiles = [];
        foreach ($files as $file) {
            foreach ($archiveFiles as $archiveFile) {
                if (fnmatch($file.'*', $archiveFile))
                    $newFiles[] = $archiveFile;
            }
        }
        return $newFiles;
    }
846812
public function export($export, string $writerType): TemporaryFile
    {
        $this->open($export);

        $sheetExports = [$export];
        if ($export instanceof WithMultipleSheets) {
            $sheetExports = $export->sheets();
        }

        foreach ($sheetExports as $sheetExport) {
            $this->addNewSheet()->export($sheetExport);
        }

        return $this->write($export, $this->temporaryFileFactory->makeLocal(), $writerType);
    }
198621
@Override
    public final void exportTo(final File target, final boolean overwrite) throws ArchiveExportException,
        FileExistsException {
        // Get stream and perform precondition checks
        final OutputStream out = this.getOutputStreamToFile(target, overwrite);

        try {
            // Write out
            this.exportTo(out);
        } finally {
            // Close
            try {
                out.close();
            } catch (final IOException ioe) {
                // Just log
                log.warning("Could not close " + out + ": " + ioe);
            }
        }
    }
457842
public function addExportCsv(
		$text,
		$csv_file_name,
		$output_encoding = null,
		$delimiter = null,
		$include_bom = false
	) {
		return $this->addToExports(new Export\ExportCsv(
			$this,
			$text,
			$csv_file_name,
			false,
			$output_encoding,
			$delimiter,
			$include_bom
		));
	}
189295
public function add($file, $entry_name = null)
    {
        $result = $this->tar->addModify($file, '', dirname($file));
        if ($result === false) {
            throw new ArchiveException('Error adding file ' . $file);
        }

        return $this;
    }
1373489
public function addFiles($fileOrFiles)
    {
        $files_list = self::createFilesList($fileOrFiles);
        if (empty($files_list))
            throw new InvalidArgumentException('Files list is empty!');
        $result = $this->archive->addFiles($files_list);
        $this->scanArchive();
        return $result;
    }
903378
protected function _packAndWriteCurrentFile()
    {
        $archiveWriter = $this->_getWriter();
        $archiveWriter->write($this->_composeHeader());

        $currentFile = $this->_getCurrentFile();

        $fileSize = 0;

        if (is_file($currentFile) && !is_link($currentFile)) {
            $fileReader = new Mage_Archive_Helper_File($currentFile);
            $fileReader->open('r');

            while (!$fileReader->eof()) {
                $archiveWriter->write($fileReader->read());
            }

            $fileReader->close();

            $fileSize = filesize($currentFile);
        }

        $appendZerosCount = (self::TAR_BLOCK_SIZE - $fileSize % self::TAR_BLOCK_SIZE) % self::TAR_BLOCK_SIZE;
        $archiveWriter->write(str_repeat("\0", $appendZerosCount));
    }
126708
public function maybeCreateExportFolders()
    {
        if (!is_writable($this->exportFolder)) {
            trigger_error('The export folder (' . $this->exportFolder .') is not writable. Exports will not be saved.', E_USER_ERROR);
        }

        if (!file_exists($this->exportFolder . 'json')) {
            mkdir($this->exportFolder . 'json');
            chmod($this->exportFolder . 'json', 0777);
        }

        if (!file_exists($this->exportFolder . 'php')) {
            mkdir($this->exportFolder . 'php');
            chmod($this->exportFolder . 'php', 0777);
        }
    }
1360559
public function addExportToBulkAction($observer)
    {
        $block = $observer->getBlock();
        if (
            $block instanceof Mage_Adminhtml_Block_Sales_Order_Grid &&
            Mage::helper('australia/clickandsend')->isClickAndSendEnabled()
        ) {
            $block->getMassactionBlock()->addItem('clickandsendexport', array(
                'label' => $block->__('Export to CSV (Click & Send)'),
                'url'   => $block->getUrl('*/australia_clickandsend/export')
            ));
        }
    }
1087186
public function addRowWithCount($row, $writer, $rowNumber)
    {
        $exportRow   = $this->filterRow($row);
        $labeledCols = $this->getLabeledColumns();
        $exportRow   = array_replace(array_flip($labeledCols), $exportRow);
        $writer->startElement('o');
        $writer->writeAttribute('num', $rowNumber);

        if ($this->batch) {
            $stringSizes = $this->batch->getSessionVariable('stringSizes');
        } else {
            $stringSizes = $this->_session->stringSizes;
        }

        foreach($labeledCols as $columnName) {

            $variableName = $this->model->get($columnName, 'variableName');
            $type = $this->model->get($columnName, 'type');

            if (($type == \MUtil_Model::TYPE_DATE || $type == \MUtil_Model::TYPE_DATETIME) && $exportRow[$columnName] !== null) {

                if (!empty($exportRow[$columnName])) {
                    if ($exportRow[$columnName] instanceof \Zend_Date) {
                        if ($type == \MUtil_Model::TYPE_DATE) {
                            $exportRow[$columnName] = floor(($exportRow[$columnName]->getTimestamp() + 315619200) / 86400);
                        } else {
                            $exportRow[$columnName] = ($exportRow[$columnName]->getTimestamp() + 315619200) * 1000;
                        }

                    } else {
                        if ($type == \MUtil_Model::TYPE_DATE) {
                            $exportRow[$columnName] = floor((strtotime($exportRow[$columnName] . ' GMT') + 315619200) / 86400);
                        } else {
                            $exportRow[$columnName] = (strtotime($exportRow[$columnName] . ' GMT') + 315619200) * 1000 ;
                        }
                    }
                }
            }
            if ($type == \MUtil_Model::TYPE_STRING && !$this->model->get($columnName, 'multiOptions')) {
                $size = strlen($exportRow[$columnName]);

                if ((!isset($stringSizes[$variableName]) || ($stringSizes[$variableName] < $size)) && $size > 0) {
                    $stringSizes[$variableName] = $size;

                    if ($this->batch) {
                        $this->batch->setSessionVariable('stringSizes', $stringSizes);
                    } else {
                        $this->_session->stringSizes = $stringSizes;
                    }
                }
            }

            if ($multiOptions = $this->model->get($columnName, 'multiOptions')) {
                if ($exportRow[$columnName] !== null) {

                    $numeric = true;
                    $newValue = 0;
                    $i=0;



                    foreach($multiOptions as $key=>$value) {
                        if (!is_numeric($key)) {
                            $numeric = false;
                        }
                        if ($key == $exportRow[$columnName]) {
                            $newValue = $i;
                        }
                    }

                    if($numeric) {

                        $newValue = $exportRow[$columnName];
                        $exportRow[$columnName] = $newValue;
                    } else {
                        $newMultiOptions = array_keys($multiOptions);
                        $newValue = array_search($exportRow[$columnName], $newMultiOptions);
                        $exportRow[$columnName] = $newValue;
                    }

                }
            }

            $writer->startElement('v');
            $writer->writeAttribute('varname', $variableName);
            if (is_array($exportRow[$columnName])) {
                $exportRow[$columnName] = join(', ', $exportRow[$columnName]);
            }
            $writer->text($exportRow[$columnName]);
            // End v
            $writer->endElement();

        }
        // End o
        $writer->endElement();

    }
1130031
@Override
    public ZipImporter importFrom(final File file) throws ArchiveImportException {
        return importFrom(file, Filters.includeAll());
    }
848609
public function addExportField($name, $header, $template = null, FieldAlias $alias = null)
    {
        $this->exportFields[] = new Field($name, $header, false, $template, $alias);

        return $this;
    }
608223
@Override
    public T addAsLibraries(final Collection<? extends Archive<?>> archives) throws IllegalArgumentException {
        Validate.notNull(archives, "Archives must be specified");
        return this.addAsLibraries(archives.toArray(new Archive<?>[archives.size()]));
    }
1249062
@Override
    public T addAsLibrary(final Archive<?> archive) throws IllegalArgumentException {
        Validate.notNull(archive, "Archive must be specified");
        // Libraries are JARs, so add as ZIP
        return add(archive, getLibraryPath(), ZipExporter.class);
    }
585935
private function exportUsers($exporter, array $extra)
    {
        $dontExport = ['password', 'description', 'salt', 'plainPassword'];

        if (isset($extra['workspace'])) {
            $users = $this->om->getRepository('ClarolineCoreBundle:User')
                ->findAllWithFacetsByWorkspace($extra['workspace']);
        } else {
            $users = $this->om->getRepository('ClarolineCoreBundle:User')
                ->findAllWithFacets();
        }

        $fieldsFacets = $this->om->getRepository('ClarolineCoreBundle:Facet\FieldFacet')->findAll();
        $fields = $this->getExportableFields('Claroline\CoreBundle\Entity\User');

        foreach ($fields as $field) {
            if (in_array($field, $dontExport)) {
                unset($fields[array_search($field, $fields)]);
            }
        }

        $data = [];
        $fieldFacetsName = [];

        foreach ($fieldsFacets as $fieldsFacet) {
            $fieldFacetsName[] = $fieldsFacet->getName();
        }

        foreach ($users as $user) {
            $data[$user->getId()] = [];
            foreach ($fields as $field) {
                $data[$user->getId()][$field] = $this->formatValue($this->getValueFromObject($user, $field));
            }

            foreach ($fieldFacetsName as $fieldFacetName) {
                $found = false;
                foreach ($user->getFieldsFacetValue() as $fieldFacetValue) {
                    if ($fieldFacetValue->getFieldFacet()->getName() === $fieldFacetName) {
                        $found = true;
                        $data[$user->getId()][$fieldFacetName] = $this->formatValue($fieldFacetValue->getValue());
                    }
                }

                if (!$found) {
                    $data[$user->getId()][$fieldFacetName] = null;
                }
            }
        }

        foreach ($fieldFacetsName as $fieldFacetName) {
            $fields[] = $fieldFacetName;
        }

        return $exporter->export($fields, $data);
    }