'Advertisements', 'description' => 'Reklamajyklar' ]; } public function defineProperties(){ return [ 'code' => [ 'title' => 'Group', 'description' => 'Choose advertisement group', 'type' => 'dropdown', 'required' => 'required', 'validationMessage' => 'Please select group' ], 'type' => [ 'title' => 'Display type', 'description' => 'Choose display type group', 'type' => 'dropdown', 'default' => 'single', 'required' => 'required', 'validationMessage' => 'Please select type' ], 'random' => [ 'title' => 'Random', 'description' => 'Random order', 'type' => 'checkbox', 'default' => 0, ], 'width' =>[ 'title' => 'Item width', 'type' => 'string', ], 'height' => [ 'title' => 'Item height', 'type' => 'string', ] ]; } public function getCodeOptions() { return Group::all()->pluck('name','code')->toArray(); } public function getTypeOptions() { return [ 'single'=>'Single', 'slider'=>'Slider', 'carousel'=>'Carousel', ]; } public function onRun() { $this->tayyarla($this->property('random')); } private function tayyarla($random){ $this->group = Group::where('code',$this->property('code')) ->with(['adds' => function ($query) use ($random){ if($random) $query->inRandomOrder(); else $query->orderBy('order'); }]) ->first(); // dd($group->adds); $this->page['css_class'] = input('css_class','blat'); if ($this->group && $this->group->adds){ try { DB::beginTransaction(); foreach ($this->group->adds as $adv){ if($adv->enable_stats){ $statistika = Statistika::firstOrCreate(['item_id' => $adv->id,'date' => Carbon::today()]); $statistika->increment('view'); } } DB::commit(); }catch (Exception $ex){ DB::rollback(); } } } public function onShow(){ $random = input('random'); $this->tayyarla($random); return [ '#'.$this->alias => $this->renderPartial('@'.$this->property('type')), ]; } public function onRedirect(){ $data = post(); if($data && $data['id']){ $statistika = Statistika::firstOrCreate(['item_id' => $data['id'],'date' => Carbon::today()]); $statistika->increment('click'); } if($data['url']){ $this->page['url'] = $data['url']; return [ '@#'.$this->alias => $this->renderPartial('@redirect'), ]; } } }