Esempio n. 1
0
 /**
  * Store a newly created resource in storage.
  *
  * @return Response
  */
 public function store(Banner $banner, BannerRequest $request)
 {
     $imageModel = ImageUploadFacade::attachmentUpload($request->file('upl'), new Attachment(), 'banners');
     $banner->attachment_id = $imageModel->id;
     $banner->paid = $request->paid == 'on' ? 1 : 0;
     $banner->fill($request->all());
     $banner->save();
     return redirect()->route('admin.banner.index');
 }
Esempio n. 2
0
 /**
  * Creates a new Banner model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  * @return mixed
  */
 public function actionCreate()
 {
     $model = new Banner();
     if ($model->load(Yii::$app->request->post()) && $model->save()) {
         return $this->redirect(['view', 'id' => $model->banner_id]);
     } else {
         return $this->render('create', ['model' => $model]);
     }
 }
Esempio n. 3
0
 /**
  * Creates a new Banner model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  * @return mixed
  */
 public function actionCreate()
 {
     $model = new Banner();
     if ($model->load(Yii::$app->request->post()) && $model->save()) {
         foreach (Property::getLanguages() as $lang) {
             $file = UploadedFile::getInstanceByName('image_' . $lang);
             if (!is_null($file)) {
                 ImageManager::addBannerImage($model->id, $file, $lang);
             }
         }
         return $this->redirect(['view', 'id' => $model->id]);
     } else {
         return $this->render('create', ['model' => $model]);
     }
 }
Esempio n. 4
0
 public function store(Request $request)
 {
     $validation = Validator::make($request->all(), ['titulo' => 'required|string', 'texto' => 'required|string', 'link' => 'string', 'data' => 'date', 'imagem' => 'image|mimes:jpeg,bmp,png,jpg']);
     if ($validation->fails()) {
         return redirect('admin/banners/novo')->withErrors($validation)->withInput();
     } else {
         try {
             $banner = new Banner();
             $banner->titulo = $request->titulo;
             $banner->texto = $request->texto;
             $banner->link = $request->link;
             $banner->data_inicio = date('Y-m-d');
             $banner->save();
             if ($request->hasFile('imagem')) {
                 Midia::uploadUnico($this->tipo_midia, $banner->id_banner);
             }
             session()->flash('flash_message', 'Banners cadastrada com sucesso!');
         } catch (\Exception $e) {
             LogR::exception($banner, $e);
             session()->flash('flash_message', 'Ops!! Ocorreu algum problema!. ' . $e->getMessage());
         }
         return Redirect::back();
     }
 }
Esempio n. 5
0
 public static function trackBanner(Banner $banner, Stream $stream, StreamTimelog $streamTimelog)
 {
     $price = $streamTimelog->price();
     $duration = $streamTimelog->duration();
     $pivotBannerStream = BannerStream::whereBannerId($banner->id)->whereStreamId($stream->id)->first();
     $pivotBannerStream->minutes = $pivotBannerStream->minutes + $duration;
     $pivotBannerStream->viewers = $pivotBannerStream->viewers + $streamTimelog->viewers;
     $pivotBannerStream->amount = $pivotBannerStream->amount + $price;
     $pivotBannerStream->save();
     $client = $banner->client;
     $client->balance_blocked = $client->balance_blocked + $price;
     $client->save();
     $usedAmount = BannerStream::whereBannerId($banner->id)->sum('amount');
     if ($banner->amount_limit <= $usedAmount) {
         $banner->is_active = 0;
         $banner->status = 'finished';
         $banner->save();
         NotificationMapper::bannerFinished($banner);
     }
     if ($client->availableBalance() <= 0) {
         $banner->is_active = 0;
         $banner->status = 'finished';
         $banner->save();
         NotificationMapper::emptyBalance($banner);
     }
     return $pivotBannerStream;
 }