public function getZipFile()
{
if (!$this->compressed_file) {
// need to generate zip file, and store it with this collection
$pfile = ProtectedFile::createForWriting($this->name . '.zip');
$zip = new ZipArchive();
if (!$zip->open($pfile->getPath(), ZIPARCHIVE::OVERWRITE)) {
throw new Exception('cannot create zip file');
}
foreach ($this->files as $pf) {
$zip->addFile($pf->getPath(), $pf->name);
}
$zip->close();
$pfile->save();
// set up relation
$this->compressed_file = $pfile;
$this->zipfile_id = $pfile->id;
$this->save();
}
return $this->compressed_file;
}