public function remove($id) { if (!empty($id)) { \Veer\Models\Download::where('id', '=', $id)->update(['elements_id' => 0, 'elements_type' => '']); } return $this; }
/** * Show Downloads */ public function getDownloads($paginateItems = 50) { $items = $this->query()->paginate($paginateItems); $items['regrouped'] = $this->regroupByName($items); $items['index'] = array_flip(array_keys($items['regrouped'])); app('veer')->loadedComponents['temporary'] = \Veer\Models\Download::where('original', '=', 0)->count(); app('veer')->loadedComponents['counted'] = \Veer\Models\Download::count(\Illuminate\Support\Facades\DB::raw('DISTINCT fname')); return $items; }
/** * Display a listing of the resource. * * @return Response */ public function download($lnk = null) { $reRouting = false; if (\Session::has('downloadlink')) { if (\Session::get('downloadlink', null) == $lnk) { $lnk = \Session::get('downloadlinkR', null); $reRouting = true; \Session::forget('downloadlink'); } } $denyDownload = true; $checkLink = \Veer\Models\Download::where('secret', '=', $lnk)->first(); if (is_object($checkLink)) { if ($checkLink->expires == false) { $denyDownload = false; } else { $expired_times = false; $expired_day = false; if ($checkLink->expiration_times > 0 && $checkLink->downloads >= $checkLink->expiration_times) { $expired_times = true; } if ($checkLink->expiration_day > \Carbon\Carbon::create(2000) && now() > $checkLink->expiration_day) { $expired_day = true; } if ($expired_times == false && $expired_day == false) { $denyDownload = false; } } } if ($denyDownload == true) { return Redirect::route('index'); } else { if ($reRouting == true) { $checkLink->increment('downloads'); return $this->downloadingLocalOrCloudFiles($checkLink->fname); } $newLink = "sessionLink" . str_random(64); \Session::put('downloadlink', $newLink); \Session::put('downloadlinkR', $lnk); return Redirect::route('download.link', $newLink); } }
/** * Delete file * */ protected function deleteFile($id) { $f = \Veer\Models\Download::find($id); if (!is_object($f)) { return false; } $allCopies = \Veer\Models\Download::where('fname', '=', $f->fname)->get(); if (count($allCopies) <= 1) { // last one $this->deletingLocalOrCloudFiles('files', $f->fname, config("veer.downloads_path"), storage_path() . '/app/'); } $f->delete(); return true; }
/** * Detach from Entity. * * @helper Model detach|update * @param string $type * @param mixed $id * @param boolean $strict * @return \Veer\Services\Administration\Elements\Entity */ public function detach($type, $id = null, $strict = false) { $relation = $this->relationAliases($type); if ($this->isAllowedRelation($relation)) { if ($relation == 'files') { if (empty($id) && !$strict) { \Veer\Models\Download::where('elements_id', '=', $this->id)->where('elements_type', '=', $this->className)->update(['elements_id' => 0, 'elements_type' => '']); } elseif (!empty($id)) { \Veer\Models\Download::where('id', '=', $id)->update(['elements_id' => 0, 'elements_type' => '']); } } else { if (empty($id) && !$strict) { $this->entity->{$relation}()->detach(); } elseif (!empty($id)) { $this->entity->{$relation}()->detach($id); } } event('veer.message.center', trans('veeradmin.' . $this->type . '.' . $relation . '.detach')); } return $this; }