public function index() { $streams = StreamMapper::byClient($this->user); $orders = BannerMapper::activeClient($this->user); $inactiveBanners = BannerMapper::inactiveClient($this->user); return view('app.pages.user.client.stream.index', compact('streams', 'orders', 'inactiveBanners')); }
public function addStreams() { $twitchers = User::whereType('twitcher')->get(); $faker = $this->faker; $i = 0; foreach ($twitchers as $t) { try { $bannerTypes = $t->bannerTypes; if (count($bannerTypes) == 0) { continue; } $bannerType = $bannerTypes->random(); $banners = BannerMapper::activeTwitcher($t, $bannerType->id); if (count($banners) == 0) { continue; } $streamDate = \Carbon\Carbon::createFromTimestamp($faker->dateTimeBetween($t->created_at)->getTimestamp()); $stream = Stream::create(['user_id' => $t->id, 'time_start' => $streamDate]); BannerMapper::bannersToStream($stream, $banners); LogMapper::log('stream_start', $stream->id); foreach ($banners as $b) { NotificationMapper::bannerStream($b, $stream); } $maxMinutes = rand(3, 30); for ($m = 0; $m < $maxMinutes; $m++) { $startTime = $streamDate->getTimestamp(); $endTime = $streamDate->addMinutes(10)->getTimestamp(); $startTime = \Carbon\Carbon::createFromTimestamp($startTime); $endTime = \Carbon\Carbon::createFromTimestamp($endTime); $streamDate = $endTime; $status = rand(0, 1); if ($status == 1) { //$uploadDir = '/assets/app/upload/t/'; $screenshot = $faker->imageUrl(640, 360); //$screenshot = $uploadDir.basename($screenshot); $viewers = rand(0, 100); $response = (object) ['stream' => (object) ['viewers' => $viewers, 'preview' => (object) ['medium' => $faker->imageUrl(640, 360)]]]; $streamTimelog = StreamTimelog::create(['stream_id' => $stream->id, 'timeslot_start' => $startTime, 'timeslot_end' => $endTime, 'viewers' => $viewers, 'status' => 'live', 'screenshot' => $screenshot, 'response' => $response]); $streamTimelog->calcAmount(); foreach ($banners as $b) { BannerMapper::trackBanner($b, $stream, $streamTimelog); } } else { $streamTimelog = StreamTimelog::create(['stream_id' => $stream->id, 'timeslot_start' => $startTime, 'timeslot_end' => $endTime, 'viewers' => 0, 'status' => 'died', 'screenshot' => '', 'response' => (object) []]); } } $stream->time_end = $streamDate; $stream->save(); $i++; } catch (\Exception $e) { dd($e->getTraceAsString()); } } }
public function show($userId) { $user = User::find($userId); if (!$user) { return Redirect::back()->withErrors(['user' => 'No such user']); } $banners = []; if ($user->type == 'client') { $banners = BannerMapper::activeClient($user); } if ($user->type == 'twitcher') { $banners = BannerMapper::activeTwitcher($user); } return view('admin.pages.user.show', compact('user', 'banners')); }
public function index() { $this->updateStatistics(); $banners = []; $bannerTypes = $this->user->bannerTypes; $notifications = NotificationMapper::fresh($this->user, 10); $waitingBanners = BannerMapper::waitingTwitcher($this->user); foreach ($bannerTypes as $bt) { $banners[$bt->id] = BannerMapper::activeTwitcher($this->user, $bt->id); } $activeBanners = BannerMapper::activeTwitcher($this->user); $showWelcome = $this->user->is_welcomed == 0; if ($showWelcome) { $this->user->is_welcomed = 1; $this->user->save(); } return view('app.pages.user.twitcher.index', compact('banners', 'bannerTypes', 'notifications', 'waitingBanners', 'activeBanners', 'showWelcome')); }
public function addBanners($limit = 2000) { $clients = User::whereType('client')->get(); $twitchers = User::whereType('twitcher')->get(); $bannerTypes = $this->data['bannerTypes']; $faker = $this->faker; $i = 0; foreach ($clients as $c) { try { $bannerCounts = rand(0, 4); if ($i > $limit) { //continue; } for ($i = 0; $i < $bannerCounts; $i++) { $bannerType = $bannerTypes->random(); $twitcher = $twitchers->random(); if (BannerMapper::twitcherFree($twitcher, $bannerType->id)) { $limit = rand(0, $c->balance); if ($limit > 0) { $requiredSizes = explode('*', $bannerType->title); $w = $requiredSizes[0]; $h = $requiredSizes[1]; $file = $faker->imageUrl($w, $h); $banner = BannerMapper::addForTwitcher($twitcher, $c, $bannerType, $file, $limit); NotificationMapper::bannerAdd($banner); LogMapper::log('banner_add', $banner->id); $accept = rand(0, 10); $i++; if ($accept != 0) { BannerMapper::acceptBanner($banner); } else { BannerMapper::declineBanner($banner); } } } } } catch (\Exception $e) { dd($e->getTraceAsString()); } } }
public function stream($userId) { $user = User::findOrFail($userId); $banners = BannerMapper::activeTwitcher($user); if (count($banners) == 0) { echo 'no banners'; die; } $faker = FakerFactory::create(); $streamDate = \Carbon\Carbon::createFromTimestamp($faker->dateTimeBetween($user->created_at)->getTimestamp()); $stream = Stream::create(['user_id' => $user->id, 'time_start' => $streamDate]); BannerMapper::bannersToStream($stream, $banners); LogMapper::log('stream_start', $stream->id); foreach ($banners as $b) { NotificationMapper::bannerStream($b, $stream); } $maxMinutes = rand(3, 30); for ($m = 0; $m < $maxMinutes; $m++) { $startTime = $streamDate->getTimestamp(); $endTime = $streamDate->addMinutes(10)->getTimestamp(); $startTime = \Carbon\Carbon::createFromTimestamp($startTime); $endTime = \Carbon\Carbon::createFromTimestamp($endTime); $streamDate = $endTime; $status = rand(0, 1); if ($status == 1) { $screenshot = $faker->imageUrl(640, 360); $viewers = rand(0, 100); $response = (object) ['stream' => (object) ['viewers' => $viewers, 'preview' => (object) ['medium' => $faker->imageUrl(640, 360)]]]; $streamTimelog = StreamTimelog::create(['stream_id' => $stream->id, 'timeslot_start' => $startTime, 'timeslot_end' => $endTime, 'viewers' => $viewers, 'status' => 'live', 'screenshot' => $screenshot, 'response' => $response]); foreach ($banners as $b) { BannerMapper::trackBanner($b, $stream, $streamTimelog); } } else { $streamTimelog = StreamTimelog::create(['stream_id' => $stream->id, 'timeslot_start' => $startTime, 'timeslot_end' => $endTime, 'viewers' => 0, 'status' => 'died', 'screenshot' => '', 'response' => (object) []]); } } $stream->time_end = $streamDate; $stream->save(); }
public function show($bannerType) { $bannerType = Ref::findOrFail($bannerType); if ($bannerType->type != 'banner_type') { return redirect('/user/twitcher'); } $banners = BannerMapper::activeTwitcher($this->user, $bannerType->id); $requiredSizes = explode('*', $bannerType->title); return view('app.pages.user.twitcher.banner.show', compact('banners', 'bannerType', 'requiredSizes')); }