/** * @param $userId * @param Blueprint $blueprint * @param Collection $collection * * @return $this */ public function uploads($userId, Blueprint $blueprint, Collection $collection) { $allBlueprints = $blueprint->where(['user_id' => $userId])->with('mods')->select('id', 'name', 'author_name', 'bc_version', 'version', 'screenshot', 'survival_creative', 'sizeX', 'sizeY', 'sizeZ', 'description', 'uploaded_at')->orderBy('uploaded_at', 'desc')->paginate(4); $collections = $collection->where(['user_id' => $userId])->select('id', 'name')->get()->toArray(); if (!$allBlueprints->isEmpty()) { return view('buildcraft.user.uploads')->with(['allBlueprints' => $allBlueprints, 'user_id' => $userId, 'collections' => $collections]); } return view('buildcraft.user.uploads')->with(['noUploads' => true]); }
/** * @param $userId * @param Blueprint $blueprint * @param Collection $collection * * @return $this|\Illuminate\Contracts\View\Factory|\Illuminate\View\View */ public function getProfile($userId, Blueprint $blueprint, Collection $collection) { $latestUpload = $blueprint->where('user_id', $userId)->select(['id', 'screenshot'])->orderBy('uploaded_at', 'desc')->limit(4)->get(); $blueprintCollections = $collection->where('user_id', $userId)->get(); if (!$latestUpload->isEmpty()) { return view('general.user.profile')->with(['latestUpload' => $latestUpload->toArray(), 'userId' => $userId, 'blueprintCollections' => $blueprintCollections->toArray()]); } return view('general.user.profile')->with('userId', $userId); }
public function postEditCollection($userId, $collectionId, Zipper $zipper, PathBuilder $pathBuilder, PostEditCollectionRequest $request, BlueprintCollection $blueprintCollection, Collection $collection, Filesystem $file, Repository $repository, Blueprint $blueprint) { $input = $request->get('collection'); // Check if there's anything to remove if (isset($input['remove'])) { // Archive default storage path $buildcraftArchiveStoragePath = $pathBuilder->create()->fromPublicPath($repository->get('blueprint.paths.storage.buildcraft.archives')); // get an array of ids to remove foreach ($input['remove'] as $key => $value) { $remove[] = $key; } // Remove the ids $blueprintCollection->destroy($remove); //Rebuild the archive // Get the current archive and delete it $currentArchive = $collection->where(['id' => $collectionId])->select('archive_name')->first()->toArray(); if ($file->exists($buildcraftArchiveStoragePath . $currentArchive['archive_name'])) { $file->delete($buildcraftArchiveStoragePath . $currentArchive['archive_name']); } // Get the ids that are still there $rebuild = $blueprintCollection->where(['collection_id' => $collectionId])->select('blueprint_id')->get()->toArray(); $filesToRearchive = $blueprint->select('archive_name')->whereIn('id', array_flatten($rebuild))->get()->toArray(); // Create a random name for the collection archive $collectionArchiveName = str_replace(' ', '', $input['name']) . '_' . getRandomId() . '_collection' . '.zip'; // Start creating the archive $zipper->make($buildcraftArchiveStoragePath . $collectionArchiveName); foreach ($filesToRearchive as $key => $value) { // Add each archive to the the newly created archive $zipper->add($buildcraftArchiveStoragePath . $value['archive_name']); } //Clean up $zipper->close(); $input['archive_name'] = $collectionArchiveName; } // Don't bother checking if anything has changed // just update the whole thing $collection->find($collectionId)->update($input); // Send the user back return redirect()->back()->with('collectionUpdateSuccess', true); }
/** * Sweet baby jesus hashtag2 * * @param $userId * @param $blueprintId * @param PathBuilder $pathBuilder * @param Blueprint $blueprintModel * @param BlueprintCollection $blueprintCollection * @param Filesystem $file * @param Repository $repository * * @return \Illuminate\Http\RedirectResponse */ public function postDeleteBlueprint($userId, $blueprintId, PathBuilder $pathBuilder, Blueprint $blueprintModel, BlueprintCollection $blueprintCollection, Filesystem $file, Repository $repository) { $blueprint = $blueprintModel->where(['id' => $blueprintId])->first()->toArray(); $blueprintScreenshootRequired = $pathBuilder->create()->fromPublicPath($repository->get('blueprint.paths.storage.buildcraft.images')) . $blueprint['screenshot']; // append the archive name name to the default storage path $blueprintArchive = $pathBuilder->create()->fromPublicPath($repository->get('blueprint.paths.storage.buildcraft.archives')) . $blueprint['archive_name']; // append the screenshoot name to the default storage path if ($file->exists($blueprintScreenshootRequired)) { $file->delete($blueprintScreenshootRequired); } if ($file->exists($blueprintArchive)) { $file->delete($blueprintArchive); } if (null !== $blueprint['screenshot_optional_0']) { $blueprintScreenshootOptiona_0 = $pathBuilder->create()->fromPublicPath($repository->get('blueprint.paths.storage.buildcraft.images')) . $blueprint['screenshot_optional_0']; // append the screenshoot name to the default storage path if ($file->exists($blueprintScreenshootOptiona_0)) { $file->delete($blueprintScreenshootOptiona_0); } } if (null !== $blueprint['screenshot_optional_1']) { $blueprintScreenshootOptiona_1 = $pathBuilder->create()->fromPublicPath($repository->get('blueprint.paths.storage.buildcraft.images')) . $blueprint['screenshot_optional_1']; // append the screenshoot name to the default storage path if ($file->exists($blueprintScreenshootOptiona_1)) { $file->delete($blueprintScreenshootOptiona_1); } } // Delete any association of this blueprint with any collection $blueprintCollection->where(['blueprint_id' => $blueprintId])->delete(); if ($blueprintModel->destroy($blueprintId)) { return redirect()->route('buildcraft::user::uploads', ['user_id' => $userId])->with('blueprintDeleteSuccess', true); } return redirect()->route('buildcraft::user::uploads', ['user_id' => $userId])->with('blueprintDeleteSuccess', false); }