/** * @return ArrayList */ public function getDownloads() { $downloads = new ArrayList(); foreach ($this->owner->Items() as $item) { $buyable = $item->Buyable(); if ($buyable && $buyable->exists() && $buyable->hasExtension('Downloadable') && $buyable->HasDownloads()) { foreach ($buyable->getDownloads() as $file) { $downloads->push(new ArrayData(array('Product' => $buyable, 'File' => $file, 'Order' => $this->owner, 'Filename' => $file->Name, 'PurchaseDate' => $this->owner->Placed, 'Size' => $file->getAbsoluteSize(), 'Link' => DownloadLink::find_or_make($file->ID, $this->owner->ID)))); } } } return $downloads; }
/** * @param int|File $file * @param int|Order $order * @return DownloadLink */ public static function find_or_make($file, $order) { $rec = DownloadLink::get()->filter(array('FileID' => is_object($file) ? $file->ID : $file, 'OrderID' => is_object($order) ? $order->ID : $order))->first(); return $rec && $rec->exists() ? $rec : self::generate($file, $order); }
/** * @param SS_HTTPRequest $req * @return HTMLText */ public function download(SS_HTTPRequest $req) { // find the download link $hash = $req->param('Hash'); if (empty($hash)) { $this->httpError(400); } // bad request $link = DownloadLink::get_by_hash($hash); if (!$link || !$link->exists()) { $this->httpError(403); } // access denied // check that the order exists and is valid $order = $link->Order(); if (!$order || !$order->exists() || !$order->DownloadsAvailable()) { $this->httpError(403); } // check the the file still exists $file = $link->File(); if (!$file || !$file->exists()) { $this->httpError(404); } // if the file is under the "small file" tipping point, just pass it through $smallSize = File::ini2bytes(Config::inst()->get('Downloadable', 'small_file_size')); $fileSize = $file->getAbsoluteSize(); if ($fileSize < $smallSize) { $this->addToLog($order->ID, $file); $this->sendFile($file); } else { return $this->initiateOfflineProcessing(array($file), $order->ID); } }
<?php if (!isset($unit)) { return; } if ($unit != '_') { $is_result_published = DB::table('units')->where('unit', $unit)->pluck('is_result_published'); if (empty($is_result_published)) { echo 'Result not yet published'; return; } } $all_unit_downloads = DownloadLink::whereRaw('unit = ? and is_dead = 0', array($unit))->get(); if ($all_unit_downloads->count() > 0) { echo '<ul class="list-group">'; foreach ($all_unit_downloads as $dl) { echo '<li class="list-group-item">'; echo '<span class="badge">' . $dl->subtitle . '</span>'; echo '<a class="result_download_link" target = "blank" href="' . $dl->link . '" link_id="' . $dl->link_id . '" >' . $dl->title . '</a>'; echo '</li>'; } echo '</ul>'; } else { echo 'No Downloads'; }
/** * Returns a more user-friendly filename for use when forcing a download. * For single files it uses the original file's name. * For zip files it uses 'order<NUM>-<COUNT>files-YYYY-mm-dd' * @return string */ public function getFriendlyName() { $files = $this->SourceFiles(); if ($files->count() == 1) { return $files->first()->Name; } else { $name = array(); $links = DownloadLink::get()->filter('FileID', $this->ID); if ($links->count() == 1 && $links->first()->OrderID > 0) { $name[] = 'order' . $links->first()->Order()->Reference; } $name[] = $files->count() . 'files'; $name[] = date('Y-m-d'); $name[] = date('H:i:s'); return implode('_', $name) . '.zip'; } }