Ejemplo n.º 1
0
 /**
  * Processes the project to send
  *
  * @param array $result Result from the catchers
  *
  * @return void
  */
 protected function processProject($result)
 {
     /** @var \App\Models\Project $project */
     $project = $result['project'];
     $conditions = $project->conditions;
     foreach ($conditions as $condition) {
         $pipeline = new Pipeline();
         $stream = new Stream();
         $stream->project()->associate($project);
         $stream->pipeable()->associate($condition);
         $stream->save();
         $traveler = new Traveler($stream);
         $traveler->bag->give($result);
         $pipeline->send($traveler)->flow($stream);
     }
 }
Ejemplo n.º 2
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());
         }
     }
 }
Ejemplo n.º 3
0
 public static function byTwitcher(User $user, $filters = [], $limit = 50)
 {
     //$streams = $user->streams();
     $streams = Stream::whereUserId($user->id);
     $streams->orderBy('time_start', 'desc')->distinct();
     if (count($filters) > 0) {
         if (isset($filters['active'])) {
             if ($filters['active'] == 1) {
                 $streams->where('streams.time_end', null);
             }
             if ($filters['active'] == 0) {
                 $streams->where('streams.time_end', '<', \DB::raw('NOW()'));
             }
         }
     }
     $streams = $streams->paginate($limit);
     return $streams;
 }
Ejemplo n.º 4
0
 public function complainDeclineSave($streamId, $bannerId, Request $request)
 {
     $stream = Stream::findOrFail($streamId);
     $banner = Banner::findOrFail($bannerId);
     if ($stream->user_id != $this->user->id) {
         return Redirect::to('/user/twitcher/streams')->withErrors('You have no rights for this');
     }
     $pivot = StreamMapper::getPivot($banner, $stream);
     if ($pivot->status != 'declining') {
         return Redirect::to('/user/twitcher/stream/' . $stream->id)->withErrors('Stream is not declining');
     }
     $this->validate($request, ['comment' => 'required|min:5']);
     $comment = $request->get('comment');
     $pivot->status = 'complain';
     $pivot->twitcher_comment = $comment;
     $pivot->save();
     LogMapper::log('banner_complained', $banner->id, $stream->id);
     NotificationMapper::bannerPayComplained($banner, $stream, $pivot->amount);
     return Redirect::to('/user/twitcher/stream/' . $stream->id)->with(['success' => 'You complained about banner declined']);
 }
Ejemplo n.º 5
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();
 }
Ejemplo n.º 6
0
 public function declineSave($streamId, $bannerId, Request $request)
 {
     $stream = Stream::findOrFail($streamId);
     $banner = Banner::findOrFail($bannerId);
     if (!StreamMapper::checkOwner($this->user, $banner, $stream)) {
         return Redirect::to('/user/client/streams')->withErrors('You have no rights for this');
     }
     if ($stream->time_end == null) {
         return Redirect::to('/user/client/stream/' . $stream->id)->withErrors('Stream is still live');
     }
     $pivot = StreamMapper::getPivot($banner, $stream);
     if ($pivot->status != 'waiting') {
         return Redirect::to('/user/client/stream/' . $stream->id)->withErrors('Stream is not for paying');
     }
     $isFinished = $this->isStreamFinished($stream);
     if (!$isFinished) {
         return Redirect::to('/user/client/stream/' . $stream->id)->withErrors('Stream is still alive');
     }
     $this->validate($request, ['comment' => 'required|min:5']);
     $comment = $request->get('comment');
     $pivot->status = 'declining';
     $pivot->client_comment = $comment;
     $pivot->save();
     LogMapper::log('banner_declining', $banner->id, $stream->id);
     NotificationMapper::bannerPayDeclining($banner, $stream, $pivot->amount);
     return Redirect::to('/user/client/stream/' . $stream->id)->with(['success' => 'You declined to pay the banner in this stream']);
 }
Ejemplo n.º 7
0
 /**
  * @param User $user
  * @param $banners
  * @return Stream
  */
 public static function getStream(User $user, $banners)
 {
     $streamId = Session::get('stream_id', false);
     if (!$streamId) {
         $stream = Stream::create(['user_id' => $user->id, 'time_start' => \Carbon\Carbon::now()]);
         self::bannersToStream($stream, $banners);
         Session::set('stream_id', $stream->id);
         LogMapper::log('stream_start', $stream->id);
         foreach ($banners as $b) {
             NotificationMapper::bannerStream($b, $stream);
         }
     } else {
         $stream = Stream::findOrFail($streamId);
     }
     return $stream;
 }