<?php
namespace Modules\Documents\BulkDownload; class Model extends \App\Mvc\ModelAbstract { protected $documentIdList; public function __construct($documentIdList) { $this->documentIdList = $documentIdList; } public function createDocumentsArchive() { if (!$this->documentIdList) { throw new \App\MessagesException($this->lang['model']['msgs']['documentsList']['invalid']); } $uid = time(); $pathDestination = \Engine\Dir::tempnam(sprintf('%s-%s', __CLASS__, $uid)); $pathDestinationZip = \Engine\File::tempnam(sprintf('%s-%s.zip', __CLASS__, $uid)); \Engine\Dir::create($pathDestination); foreach ($this->documentIdList as $documentId) { $documentEntity = \Entity\Document::select($documentId); \Engine\File::copy($documentEntity->docFileNameWithPath, $pathDestination.$documentEntity->docFile); } $zip = new \App\Archive\Compress\Zip(); $zip->open($pathDestination) ->setCompressionLevel(\App\Archive\Compress\Zip::COMPRESS_MEDIUM) ->compressTo($pathDestinationZip) ->close(); \Engine\Dir::delete($pathDestination); return $pathDestinationZip; } }