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']); }
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']); }
/** * @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; }