/** * Get and return utilities for zip. * * @return Response */ public function getUtilities() { $input = Input::get('zip'); $zip_code = Zip::find($input); $utilities = $zip_code->utilities(); return Response::make($utilities->get(['utility_zip.utility', 'utilities.name'])); }
public static function zipOneDay(Carbon $date) { $begin = $date->copy()->setTime(0, 0, 0); $end = $date->copy()->setTime(23, 59, 59); $deleteLocs = []; $videoLocs = []; $videos = Video::where('state', '=', 'downloaded')->where('updated_at', '>=', $begin->toDateTimeString())->where('updated_at', '<=', $end->toDateTimeString())->get(); foreach ($videos as $video) { $deleteLocs[] = $video->location; $videoLocs[] = storage_path('app/' . $video->location); $video->state = 'zipped'; $video->save(); } $imageLocs = []; $images = Image::where('state', '=', 'downloaded')->where('updated_at', '>=', $begin->toDateTimeString())->where('updated_at', '<=', $end->toDateTimeString())->get(); foreach ($images as $image) { $deleteLocs[] = $image->location; $imageLocs[] = storage_path('app/' . $image->location); $image->state = 'zipped'; $image->save(); } $locs = array_merge($videoLocs, $imageLocs); if (count($locs) == 0) { Log::info('TumblrZip : no file to be ziped.'); return; } $zipName = $begin->toDateString() . '.zip'; $zipLocs = 'zips/' . $zipName; $zippy = Zippy::load(); $zippy->create(storage_path('app/' . $zipLocs), $locs); $zip = new Zip(); $zip->state = 'ziped'; $zip->error = ''; $zip->name = $zipName; $zip->date = $begin->toDateString(); $zip->size = number_format(Storage::size($zipLocs) / 1024.0 / 1024.0, 2) . 'MB'; $zip->imageSize = count($imageLocs); $zip->videoSize = count($videoLocs); $zip->location = $zipLocs; $zip->save(); Storage::delete($deleteLocs); }