Exemplo n.º 1
0
 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());
         }
     }
 }
Exemplo n.º 2
0
 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'));
 }
Exemplo n.º 3
0
 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'));
 }
Exemplo n.º 4
0
 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();
 }
Exemplo n.º 5
0
 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'));
 }