Exemplo n.º 1
0
 protected function _finish()
 {
     $id = $this->input->post('id');
     try {
         $selected = array();
         if ($s = $this->input->post('selected_influencers')) {
             $selected = explode(',', $s);
         }
         if (!$selected) {
             throw new \Exception('At least one influencer must be selected');
         }
         foreach ($selected as &$s) {
             $s = new \MongoId($s);
         }
         $campaign = new Campaign($id);
         $cinfo = $campaign->filter_one(array('_id' => $campaign->id, 'state' => array('$in' => array('pending', 'rejected'))));
         if (!$cinfo) {
             throw new \Exception('Invalid Campaign');
         }
         $campaign->update(array('state' => 'active', 'influencers_select' => $selected, 'points' => (int) $this->input->post('points'), 'global' => (bool) $this->input->post('global')));
         Alert::once('success', 'Campaign is now active', Url::base('admin/campaign/view/' . $id));
     } catch (\Exception $e) {
         Alert::once('error', $e->getMessage(), Url::base('admin/campaign/view/' . $id));
     }
 }
Exemplo n.º 2
0
 protected function _channel_influencer()
 {
     try {
         $id = $this->input->post('id');
         $campaign = new Campaign($id);
         $cinfo = $campaign->get();
         if (!$cinfo) {
             throw new \Exception('Invalid campaign');
         }
         if (!($influencer = $this->input->post('influencer'))) {
             throw new \Exception('Invalid influencer');
         }
         $comment = $this->input->post('comment');
         if (empty($comment)) {
             throw new \Exception('Comment must not be empty');
         }
         $comments = MongoDoc::get($cinfo, 'comments.brand_influencer', array());
         if (!isset($comments[$influencer])) {
             $comments[$influencer] = array();
         }
         $comments[$influencer][] = array('from' => UserSession::get('user._id'), 'from_username' => UserSession::get('user.username'), 'user' => 'brand', 'created_at' => time(), 'text' => $comment);
         $comments[$influencer] = array_slice($comments[$influencer], -20);
         $campaign->update(array('comments.brand_influencer' => $comments));
         Alert::once('success', 'Comment added', Url::referrer());
     } catch (\Exception $e) {
         Alert::once('error', $e->getMessage(), Url::referrer());
     }
 }
Exemplo n.º 3
0
 public function get($id)
 {
     $campaign = new Campaign($id);
     $cinfo = $campaign->get();
     if (!$cinfo) {
         $this->_404('Invalid campaign');
     }
     $this->_display->view(array('main/app/admin/campaign/view.php'), array('campaign' => $cinfo));
 }
 /**
  * Rellena una Campaña (modelo) con los datos del formulario
  * 
  * @param CampaignModel $model
  * 
  * @return CampaignModel
  */
 public function fill(CampaignModel $model)
 {
     $request_values = $this->all();
     foreach ($model->getFillable() as $property) {
         $key = sprintf('campaign-%s', $property);
         if (isset($request_values[$key])) {
             $model->{$property} = $request_values[$key];
         }
     }
     return $model;
 }
Exemplo n.º 5
0
 public function post()
 {
     try {
         $campaign = new Campaign(null);
         $cinfo = $campaign->find_modify_one(array('_id' => new \MongoId($this->input->post('id')), 'state' => array('$in' => array('pending', 'active'))), array('$set' => array('state' => 'rejected')));
         if (!$cinfo) {
             $this->_403();
         }
         Alert::once('success', 'Campaign has been removed', Url::base('admin/campaign/pending'));
     } catch (\Exception $e) {
         Alert::once('error', $e->getMessage(), Url::referrer());
     }
 }
Exemplo n.º 6
0
 public function post()
 {
     try {
         $campaign = new Campaign(null);
         $cinfo = $campaign->find_modify_one(array('_id' => new \MongoId($this->input->post('id')), 'brand' => UserSession::get('user._id'), 'state' => 'pending'), array('$set' => array('state' => 'rejected')));
         if (!$cinfo) {
             $this->_403();
         }
         Json::success('Campaign removed');
     } catch (\Exception $e) {
         Json::error($e->getMessage());
     }
 }
Exemplo n.º 7
0
 public function post()
 {
     try {
         $brand = new Brand(UserSession::get('user._id'));
         $binfo = $brand->get();
         $data = $this->_get_data($binfo);
         $campaign = new Campaign(null);
         $id = $campaign->create($data);
         (new NotifyBrandCampaign())->create($id);
         Alert::once('success', 'Campaign queued for admin approval', Url::current());
     } catch (\Exception $e) {
         Alert::once('error', $e->getMessage(), Url::current());
     }
 }
Exemplo n.º 8
0
 /**
  * Displays the index (home) page.
  * Use it in case your home page contains static content.
  *
  * @return string
  */
 public function actionIndex()
 {
     $searchModel = new ServiceSearch();
     $searchModel->promo = true;
     $dataProvider = $searchModel->search(Yii::$app->request->queryParams);
     return $this->render('tempindex', ['cat' => Category::find()->orderBy('name_pt')->all(), 'serv' => Service::find()->orderBy('title_pt')->all(), 'modelImg' => Campaign::find()->one(), 'dataProvider' => $dataProvider]);
 }
 public function updateCampaign($parameters)
 {
     try {
         $id = $parameters['id'];
         $campaign = Campaign::find($id);
         $columns = array_intersect_key($parameters, array_flip($campaign->getFillableColumns()));
         if (!empty($columns)) {
             $campaign->update($columns);
         }
         $relationships = array_intersect_key($parameters, array_flip(Campaign::$relationshipsAllowedToUpdate));
         if (!empty($relationships)) {
             foreach ($relationships as $relationshipType => $relationshipValue) {
                 if (!empty($relationshipValue)) {
                     if (!is_array($relationshipValue)) {
                         $relationshipValue = explode(',', $relationshipValue);
                     }
                     $campaign->{$relationshipType}()->sync($relationshipValue);
                 }
             }
         }
         return $campaign;
     } catch (\Exception $e) {
         throw $e;
     }
 }
 /**
  * Run the database seeds.
  *
  * @return void
  */
 public function run()
 {
     DB::table('campaign')->truncate();
     $campaigns = json_decode(File::get('database/migrations/jsondata/campaigns.json'));
     foreach ($campaigns as $campaign) {
         Campaign::create(array('id' => $campaign->id, 'name' => $campaign->name));
     }
 }
 public function index(Request $request)
 {
     $limit = $request->input('limit') ? $request->input('limit') : 10;
     $dataCampaigns = Campaign::paginate($limit);
     if ($request->input('limit')) {
         $dataCampaigns->appends('limit', $request->input('limit'));
     }
     return $dataCampaigns;
 }
 public function index(Request $request)
 {
     $limit = $request->input('limit') ? $request->input('limit') : 10;
     $page = $request->input('page') ? $request->input('page') : 1;
     $offset = ($page - 1) * $limit;
     $total = Campaign::count();
     $dataCampaigns = Campaign::take($limit)->offset($offset)->get();
     $data = ['meta' => ['page' => (int) $page, 'current_total' => count($dataCampaigns), 'total' => $total], 'campaigns' => $dataCampaigns];
     return $data;
 }
Exemplo n.º 13
0
 /**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $query = Campaign::find();
     $dataProvider = new ActiveDataProvider(['query' => $query]);
     $this->load($params);
     if (!$this->validate()) {
         // uncomment the following line if you do not want to return any records when validation fails
         // $query->where('0=1');
         return $dataProvider;
     }
     $query->andFilterWhere(['id' => $this->id, 'created_at' => $this->created_at, 'updated_at' => $this->updated_at]);
     $query->andFilterWhere(['like', 'name_en', $this->name_en])->andFilterWhere(['like', 'name_pt', $this->name_pt])->andFilterWhere(['like', 'intro_en', $this->intro_en])->andFilterWhere(['like', 'intro_pt', $this->intro_pt]);
     return $dataProvider;
 }
Exemplo n.º 14
0
 public function update($userType, $id, Request $req)
 {
     $temp = null;
     if ($userType == 'founder') {
         Founder::findOrNew($id)->update($req->all());
         $temp = Founder::findOrNew($id);
     } elseif ($userType == 'investor') {
         Investor::findOrNew($id)->update($req->all());
         $temp = Investor::findOrNew($id);
     } elseif ($userType == 'campaign') {
         Campaign::findOrNew($id)->update($req->all());
         $temp = Campaign::findOrNew($id);
     }
     flash()->success($userType . ' Updated');
     return view('admin.edit', [$userType => $temp, 'userType' => $this->getUserType($userType)]);
 }
 protected function validateCampaign($attribute, $value)
 {
     if (!is_array($value)) {
         $value = array($value);
     }
     foreach ($value as $campaignId) {
         if (!Campaign::find($campaignId)) {
             $this->invalidCampaignIds[] = $campaignId;
         }
     }
     if (empty($this->invalidCampaignIds)) {
         return true;
     }
     $this->customValidatorMessages['custom'] = 'Campaign id(s) ' . implode(', ', $this->invalidCampaignIds) . ' are invalid';
     $this->setCustomMessages($this->customValidatorMessages);
     return false;
 }
 /**
  * Run the database seeds.
  *
  * @return void
  */
 public function run()
 {
     $faker = Faker::create();
     $investorIds = App\Models\Investor::all()->lists('id');
     //echo('Investor Ids ');
     //var_dump($investorIds);
     $campaignIds = App\Models\Campaign::all()->lists('id');
     //echo('Campaign Ids ');
     //var_dump($campaignIds);
     $numberInvstPerCmpg = 3;
     foreach ($investorIds as $invtId) {
         foreach ($campaignIds as $cmpgnId) {
             DB::table('campaign_investor')->insert(['campaign_id' => $cmpgnId, 'investor_id' => $invtId, 'invst_label' => $faker->sentence(), 'invst_amount' => $faker->randomFloat($nbMaxDecimals = 2, $min = 10.0, $max = 500.0), 'created_at' => \Carbon\Carbon::now(), 'updated_at' => \Carbon\Carbon::now()]);
             //$numberInvstPerCmpg--;
         }
     }
     //var_dump($pivots);
     //DB::table('campaign_investor')->insert($pivots);
 }
 /**
  * @param integer $id
  *
  * @return \App\Models\Campaign
  *
  * @throw Illuminate\Database\Eloquent\ModelNotFoundException
  */
 public static function getCampaignById($id)
 {
     return Campaign::findOrFail($id);
 }
Exemplo n.º 18
0
 public function campaign_bulk(Request $request)
 {
     //        return dd($request->all());
     if (Auth::check()) {
         if (in_array('ADD_EDIT_CAMPAIGN', $this->permission)) {
             $validate = $this->validation($request);
             if ($validate->passes()) {
                 $usr_company = $this->user_company();
                 $audit = new AuditsController();
                 $audit_key = $audit->generateRandomString();
                 if ($request->input('advertiser_id') == 'all' and !$request->has('campaign_list')) {
                     if ($request->input('client_id') == 'all') {
                         if (User::isSuperAdmin()) {
                             $campaign_list = Campaign::get(['id'])->toArray();
                         } else {
                             $campaign_list = Campaign::whereHas('getAdvertiser', function ($q) use($usr_company) {
                                 $q->whereHas('GetClientID', function ($p) use($usr_company) {
                                     $p->whereIn('user_id', $usr_company);
                                 });
                             })->get(['id'])->toArray();
                         }
                     } elseif ($request->input('client_id') != 'all') {
                         if (User::isSuperAdmin()) {
                             $campaign_list = Campaign::whereHas('getAdvertiser', function ($q) use($request) {
                                 $q->where('client_id', $request->input('client_id'));
                             })->get(['id'])->toArray();
                         } else {
                             ////////////////////////
                             $campaign_list = Campaign::whereHas('getAdvertiser', function ($q) use($usr_company, $request) {
                                 $q->whereHas('GetClientID', function ($p) use($usr_company, $request) {
                                     $p->where('id', $request->input('client_id'))->whereIn('user_id', $usr_company);
                                 });
                             })->get(['id'])->toArray();
                         }
                     }
                 } elseif ($request->input('advertiser_id') != 'all' and !$request->has('campaign_list')) {
                     if (User::isSuperAdmin()) {
                         $campaign_list = Campaign::whereHas('getAdvertiser', function ($q) use($request) {
                             $q->where('id', $request->input('advertiser_id'));
                         })->get(['id'])->toArray();
                     } else {
                         ////////////////////////
                         $campaign_list = Campaign::whereHas('getAdvertiser', function ($q) use($usr_company, $request) {
                             $q->where('id', $request->input('advertiser_id'))->whereHas('GetClientID', function ($p) use($usr_company, $request) {
                                 $p->whereIn('user_id', $usr_company);
                             });
                         })->get(['id'])->toArray();
                     }
                 } else {
                     $campaign_list = explode(',', $request->input('campaign_list'));
                 }
                 if (count($campaign_list) > 0) {
                     foreach ($campaign_list as $index) {
                         $data = array();
                         if (!$request->has('campaign_list')) {
                             $campaign_id = $index['id'];
                             $campaign = Campaign::find($campaign_id);
                         } else {
                             $campaign_id = $index;
                             if (User::isSuperAdmin()) {
                                 $campaign = Campaign::find($campaign_id);
                             } else {
                                 $usr_company = $this->user_company();
                                 $campaign = Campaign::whereHas('getAdvertiser', function ($q) use($usr_company) {
                                     $q->whereHas('GetClientID', function ($p) use($usr_company) {
                                         $p->whereIn('user_id', $usr_company);
                                     });
                                 })->find($campaign_id);
                             }
                         }
                         if ($campaign) {
                             if ($request->has('date_range')) {
                                 $check_date = $this->date_validation($request->input('date_range'));
                                 if (!$check_date) {
                                     return Redirect::back()->withErrors(['success' => false, 'msg' => 'please check your date range!']);
                                 }
                                 $date_range = explode('-', $request->input('date_range'));
                                 $start_date = Carbon::createFromFormat('m/d/Y', str_replace(' ', '', $date_range[0]))->toDateString();
                                 $end_date = Carbon::createFromFormat('m/d/Y', str_replace(' ', '', $date_range[1]))->toDateString();
                             }
                             if ($request->has('name')) {
                                 array_push($data, 'Name');
                                 array_push($data, $request->input('name'));
                                 $campaign->name = $request->input('name');
                             }
                             if ($request->has('active')) {
                                 $active = 'Inactive';
                                 if ($request->input('active') == 'on') {
                                     $active = 'Active';
                                 }
                                 array_push($data, 'Status');
                                 array_push($data, $active);
                                 $campaign->status = $active;
                             }
                             if ($request->has('max_impression')) {
                                 array_push($data, 'Max Imps');
                                 array_push($data, $request->input('max_impression'));
                                 $campaign->max_impression = $request->input('max_impression');
                             }
                             if ($request->has('daily_max_impression')) {
                                 array_push($data, 'Daily Max Imps');
                                 array_push($data, $request->input('daily_max_impression'));
                                 $campaign->daily_max_impression = $request->input('daily_max_impression');
                             }
                             if ($request->has('max_budget')) {
                                 array_push($data, 'Max Budget');
                                 array_push($data, $request->input('max_budget'));
                                 $campaign->max_budget = $request->input('max_budget');
                             }
                             if ($request->has('daily_max_budget')) {
                                 array_push($data, 'Daily Max Budget');
                                 array_push($data, $request->input('daily_max_budget'));
                                 $campaign->daily_max_budget = $request->input('daily_max_budget');
                             }
                             if ($request->has('cpm')) {
                                 array_push($data, 'CPM');
                                 array_push($data, $request->input('cpm'));
                                 $campaign->cpm = $request->input('cpm');
                             }
                             if ($request->has('advertiser_domain_name')) {
                                 array_push($data, 'Domain Name');
                                 array_push($data, $request->input('advertiser_domain_name'));
                                 $campaign->advertiser_domain_name = $request->input('advertiser_domain_name');
                             }
                             if ($request->has('description')) {
                                 array_push($data, 'Description');
                                 array_push($data, $request->input('description'));
                                 $campaign->description = $request->input('description');
                             }
                             if (isset($start_date)) {
                                 array_push($data, 'Start Date');
                                 array_push($data, $start_date);
                                 $campaign->start_date = $start_date;
                             }
                             if (isset($end_date)) {
                                 array_push($data, 'End Date');
                                 array_push($data, $end_date);
                                 $campaign->end_date = $end_date;
                             }
                             $audit->store('campaign', $campaign_id, $data, 'bulk_edit', $audit_key);
                             $campaign->save();
                         }
                     }
                     return Redirect::back()->withErrors(['success' => true, 'msg' => 'Campaigns Edited Successfully']);
                 }
             }
             return Redirect::back()->withErrors(['success' => false, 'msg' => $validate->messages()->all()])->withInput();
         }
         return Redirect::back()->withErrors(['success' => false, 'msg' => 'don\'t have Edit Permission']);
     }
     return Redirect::to(url('/user/login'));
 }
Exemplo n.º 19
0
 public function UploadCampaign(Request $request)
 {
     if (Auth::check()) {
         if (in_array('ADD_EDIT_CAMPAIGN', $this->permission)) {
             if ($request->hasFile('upload')) {
                 if (User::isSuperAdmin()) {
                     $advertiser_obj = Advertiser::with('GetClientID')->find($request->input('advertiser_id'));
                 } else {
                     $usr_company = $this->user_company();
                     $advertiser_obj = Advertiser::whereHas('GetClientID', function ($p) use($usr_company) {
                         $p->whereIn('user_id', $usr_company);
                     })->find($request->input('advertiser_id'));
                     if (!$advertiser_obj) {
                         return Redirect::back()->withErrors(['success' => false, 'msg' => 'please Select your Client'])->withInput();
                     }
                 }
                 if ($advertiser_obj) {
                     $destpath = public_path();
                     $extension = $request->file('upload')->getClientOriginalExtension();
                     // getting image extension
                     $fileName = str_random(32) . '.' . $extension;
                     $request->file('upload')->move($destpath . '/cdn/test/', $fileName);
                     Config::set('excel.import.startRow', 12);
                     $upload = Excel::load('public/cdn/test/' . $fileName, function ($reader) {
                     })->get();
                     $t = array();
                     foreach ($upload[0] as $key => $value) {
                         array_push($t, $key);
                     }
                     if ($t[1] != 'name' or $t[2] != 'max_impression' or $t[3] != 'daily_max_impression' or $t[4] != 'max_budget' or $t[5] != 'daily_max_budget' or $t[6] != 'cpm' or $t[7] != 'advertiser_domain_name' or $t[8] != 'status' or $t[9] != 'start_date' or $t[10] != 'end_date') {
                         File::delete($destpath . '/cdn/test/' . $fileName);
                         return Redirect::back()->withErrors(['success' => false, 'msg' => 'please be sure that file is correct'])->withInput();
                     }
                     $bad_input = array();
                     $count = 0;
                     //                        return dd();
                     foreach ($upload as $test) {
                         $flg = 0;
                         $campaign = new Campaign();
                         if ($test['name'] == '' or $test['max_impression'] == '' or $test['daily_max_impression'] == '' or $test['max_budget'] == '' or $test['daily_max_budget'] == '' or $test['cpm'] == '' or $test['advertiser_domain_name'] == '' or $test['status'] == '' or $test['status'] == '' or $test['end_date'] == '') {
                             array_push($bad_input, $test['name']);
                             continue;
                         }
                         if (!is_numeric($test['max_impression']) or !is_numeric($test['daily_max_impression']) or !is_numeric($test['max_budget']) or !is_numeric($test['daily_max_budget']) or !is_numeric($test['cpm'])) {
                             array_push($bad_input, $test['name']);
                             continue;
                         }
                         if (strcasecmp($test['status'], 'active') != 0 and strcasecmp($test['status'], 'inactive') != 0) {
                             array_push($bad_input, $test['name']);
                             continue;
                         }
                         $campaign->name = $test['name'];
                         $campaign->max_impression = $test['max_impression'];
                         $campaign->daily_max_impression = $test['daily_max_impression'];
                         $campaign->max_budget = $test['max_budget'];
                         $campaign->daily_max_budget = $test['daily_max_budget'];
                         $campaign->cpm = $test['cpm'];
                         $campaign->start_date = $test['start_date'];
                         $campaign->end_date = $test['end_date'];
                         $campaign->advertiser_domain_name = $test['advertiser_domain_name'];
                         $campaign->status = ucwords(strtolower($test['status']));
                         $campaign->advertiser_id = $request->input('advertiser_id');
                         //                            return dd('dd1');
                         $count++;
                         $campaign->save();
                     }
                     $audit = new AuditsController();
                     $audit->store('campaign', 0, $count, 'bulk_add');
                     $msg = "Campaigns added successfully";
                     if (count($bad_input) > 0) {
                         $msg .= " exept: ";
                         foreach ($bad_input as $index) {
                             $msg .= $index . ',';
                         }
                     }
                     return Redirect::back()->withErrors(['success' => true, 'msg' => $msg]);
                 }
                 return Redirect::back()->withErrors(['success' => false, 'msg' => 'please Select Advertiser First'])->withInput();
             }
             return Redirect::back()->withErrors(['success' => false, 'msg' => 'please Select a file'])->withInput();
         }
         return Redirect::back()->withErrors(['success' => false, 'msg' => "You don't have permission"]);
     }
     return Redirect::to(url('/user/login'));
 }
Exemplo n.º 20
0
 protected function _get_campaigns($find = array())
 {
     $campaign = new Campaign(null);
     return $campaign->filter($find);
 }
Exemplo n.º 21
0
 /**
  * Finds the Campaign model based on its primary key value.
  * If the model is not found, a 404 HTTP exception will be thrown.
  * @param integer $id
  * @return Campaign the loaded model
  * @throws NotFoundHttpException if the model cannot be found
  */
 protected function findModel($id)
 {
     if (($model = Campaign::findOne($id)) !== null) {
         return $model;
     } else {
         throw new NotFoundHttpException('The requested page does not exist.');
     }
 }
Exemplo n.º 22
0
 /**
  * boot
  * observing model
  *
  */
 public static function boot()
 {
     parent::boot();
     Voucher::observe(new VoucherObserver());
 }
Exemplo n.º 23
0
 public function getSpotCampaignIdsForSelectFilter()
 {
     $localCampaign = $this->getUserCampaignIds();
     $spotCampaign = $this->getSpotUserCampaignIds();
     if (count($localCampaign) != count($spotCampaign)) {
         unset($spotCampaign[0]);
         foreach ($spotCampaign as $campaignId => $name) {
             $flag = 0;
             foreach ($localCampaign as $lcampaign) {
                 if ($lcampaign['id'] == $campaignId) {
                     $flag = 1;
                 }
                 $filterValues[$lcampaign['id']] = $lcampaign['name'];
             }
             if ($flag == 0) {
                 $campaign = new Campaign();
                 $campaign->name = $name;
                 $campaign->id = $campaignId;
                 $campaign->save();
             }
         }
     }
     $returnString = '';
     foreach ($spotCampaign as $campaignId => $name) {
         $returnString .= ";{$campaignId}:{$name}";
     }
     return $returnString;
 }
Exemplo n.º 24
0
 public function carousel()
 {
     $campaigns = Campaign::all();
     return response()->json($campaigns);
 }
Exemplo n.º 25
0
 public function SubAudit($audit)
 {
     $audit_obj = array();
     foreach ($audit as $index) {
         $entity_obj = null;
         switch ($index->entity_type) {
             case 'user':
                 if (in_array('VIEW_USER', $this->permission)) {
                     $entity_obj = User::find($index->entity_id);
                 }
                 break;
             case 'company':
                 if (User::isSuperAdmin()) {
                     $entity_obj = \App\Models\Company::find($index->entity_id);
                 }
                 break;
             case 'inventory':
                 if (User::isSuperAdmin()) {
                     $entity_obj = Inventory::find($index->entity_id);
                 }
                 break;
             case 'client':
                 if (in_array('VIEW_CLIENT', $this->permission)) {
                     $entity_obj = Client::find($index->entity_id);
                 }
                 break;
             case 'advertiser':
                 if (in_array('VIEW_ADVERTISER', $this->permission)) {
                     $entity_obj = Advertiser::with('GetClientID')->find($index->entity_id);
                 }
                 break;
             case 'creative':
                 if (in_array('VIEW_CREATIVE', $this->permission)) {
                     $entity_obj = Creative::with(['getAdvertiser' => function ($q) {
                         $q->with('GetClientID');
                     }])->find($index->entity_id);
                 }
                 break;
             case 'campaign':
                 if (in_array('VIEW_CAMPAIGN', $this->permission)) {
                     $entity_obj = Campaign::with(['getAdvertiser' => function ($q) {
                         $q->with('GetClientID');
                     }])->find($index->entity_id);
                 }
                 break;
             case 'offer':
                 if (in_array('VIEW_OFFER', $this->permission)) {
                     $entity_obj = Offer::with(['getAdvertiser' => function ($q) {
                         $q->with('GetClientID');
                     }])->find($index->entity_id);
                 }
                 break;
             case 'pixel':
                 if (in_array('VIEW_PIXEL', $this->permission)) {
                     $entity_obj = Pixel::with(['getAdvertiser' => function ($q) {
                         $q->with('GetClientID');
                     }])->find($index->entity_id);
                 }
                 break;
             case 'targetgroup':
                 if (in_array('VIEW_TARGETGROUP', $this->permission)) {
                     $entity_obj = Targetgroup::find($index->entity_id);
                 }
                 break;
             case 'targetgroup_geolocation_map':
                 if (in_array('VIEW_TARGETGROUP', $this->permission)) {
                     if ($index->audit_type == 'del') {
                         $entity_obj = Geolocation::find($index->after_value);
                     } else {
                         $entity_obj = Geolocation::find($index->entity_id);
                     }
                 }
                 break;
             case 'targetgroup_creative_map':
                 if (in_array('VIEW_TARGETGROUP', $this->permission)) {
                     if ($index->audit_type == 'del') {
                         $entity_obj = Creative::find($index->after_value);
                     } else {
                         $entity_obj = Creative::find($index->entity_id);
                     }
                 }
                 break;
             case 'targetgroup_segment_map':
                 if (in_array('VIEW_TARGETGROUP', $this->permission)) {
                     if ($index->audit_type == 'del') {
                         $entity_obj = Segment::find($index->after_value);
                     } else {
                         $entity_obj = Segment::find($index->entity_id);
                     }
                 }
                 break;
             case 'targetgroup_geosegment_map':
                 if (in_array('VIEW_TARGETGROUP', $this->permission)) {
                     if ($index->audit_type == 'del') {
                         $entity_obj = GeoSegmentList::find($index->after_value);
                     } else {
                         $entity_obj = GeoSegmentList::find($index->entity_id);
                     }
                 }
                 break;
             case 'targetgroup_bwlist_map':
                 if (in_array('VIEW_TARGETGROUP', $this->permission)) {
                     if ($index->audit_type == 'del') {
                         $entity_obj = BWList::find($index->after_value);
                     } else {
                         $entity_obj = BWList::find($index->entity_id);
                     }
                 }
                 break;
             case 'targetgroup_bidprofile_map':
                 if (in_array('VIEW_TARGETGROUP', $this->permission)) {
                     if ($index->audit_type == 'del') {
                         $entity_obj = Bid_Profile::find($index->after_value);
                     } else {
                         $entity_obj = Bid_Profile::find($index->entity_id);
                     }
                 }
                 break;
             case 'geosegment':
                 if (in_array('VIEW_GEOSEGMENTLIST', $this->permission)) {
                     $entity_obj = GeoSegmentList::with(['getAdvertiser' => function ($q) {
                         $q->with('GetClientID');
                     }])->find($index->entity_id);
                 }
                 break;
             case 'geosegmententrie':
                 if (in_array('VIEW_GEOSEGMENTLIST', $this->permission)) {
                     if ($index->audit_type == 'del') {
                         $entity_obj = GeoSegment::find($index->after_value);
                     } else {
                         $entity_obj = GeoSegment::find($index->entity_id);
                     }
                 }
                 break;
             case 'bwlist':
                 if (in_array('VIEW_BWLIST', $this->permission)) {
                     $entity_obj = BWList::with(['getAdvertiser' => function ($q) {
                         $q->with('GetClientID');
                     }])->find($index->entity_id);
                 }
                 break;
             case 'bwlistentrie':
                 if (in_array('VIEW_BWLIST', $this->permission)) {
                     if ($index->audit_type == 'del') {
                         $entity_obj = BWEntries::find($index->after_value);
                     } else {
                         $entity_obj = BWEntries::find($index->entity_id);
                     }
                 }
                 break;
             case 'bid_profile':
                 if (in_array('VIEW_BIDPROFILE', $this->permission)) {
                     $entity_obj = Bid_Profile::with(['getAdvertiser' => function ($q) {
                         $q->with('GetClientID');
                     }])->find($index->entity_id);
                 }
                 break;
             case 'bid_profile_entry':
                 if (in_array('VIEW_BIDPROFILE', $this->permission)) {
                     if ($index->audit_type == 'del') {
                         $entity_obj = Bid_Profile::where('id', $index->after_value)->first();
                     } else {
                         $entity_obj = Bid_Profile_Entry::with('getParent')->find($index->entity_id);
                     }
                 }
                 break;
             case 'modelTable':
                 if (in_array('VIEW_MODEL', $this->permission)) {
                     if ($index->audit_type == 'del') {
                         $entity_obj = BWList::where('id', $index->after_value)->first();
                     } else {
                         $entity_obj = ModelTable::with(['getAdvertiser' => function ($q) {
                             $q->with('GetClientID');
                         }])->find($index->entity_id);
                     }
                 }
                 break;
             case 'offer_pixel_map':
                 if (in_array('VIEW_OFFER', $this->permission)) {
                     $entity_obj = Pixel::with(['getAdvertiser' => function ($q) {
                         $q->with('GetClientID');
                     }])->find($index->entity_id);
                 }
                 break;
             case 'advertiser_model_map':
                 if (in_array('VIEW_ADVERTISER', $this->permission)) {
                     $entity_obj = ModelTable::with(['getAdvertiser' => function ($q) {
                         $q->with('GetClientID');
                     }])->find($index->entity_id);
                 }
                 break;
             case 'positive_offer_model':
                 if (in_array('VIEW_MODEL', $this->permission)) {
                     $entity_obj = Offer::with(['getAdvertiser' => function ($q) {
                         $q->with('GetClientID');
                     }])->find($index->entity_id);
                 }
                 break;
             case 'negative_offer_model':
                 if (in_array('VIEW_MODEL', $this->permission)) {
                     $entity_obj = Offer::with(['getAdvertiser' => function ($q) {
                         $q->with('GetClientID');
                     }])->find($index->entity_id);
                 }
                 break;
         }
         if (!is_null($entity_obj)) {
             array_push($audit_obj, $index);
             array_push($audit_obj, $entity_obj);
         }
     }
     return $audit_obj;
 }
Exemplo n.º 26
0
 public function get($id)
 {
     $campaign = new Campaign($id);
     $this->_display->view(array('main/app/influencer/campaign/view.php'), array('campaign' => $campaign->get()));
 }
Exemplo n.º 27
0
 public function ChangeState(Request $request)
 {
     //        return dd($request->all());
     if (Auth::check()) {
         if (in_array('VIEW_ADVERTISER', $this->permission)) {
             //TODO: set report permission
             $type = $request->input('type');
             $arr = array();
             array_push($arr, $type);
             $time = '';
             $client = '';
             $advertiser = '';
             $creative = '';
             $geosegment = '';
             $campaign = '';
             $targetgroup = '';
             if (User::isSuperAdmin()) {
                 $clientArry = Client::get(['id'])->toArray();
                 $advertiserArry = Advertiser::get(['id'])->toArray();
                 $query = "1 = 1 ";
                 if ($request->has('client')) {
                     $query .= " and impression.client_id=" . $request->input('client');
                 }
                 if ($request->has('advertiser')) {
                     $query .= " and impression.advertiser_id=" . $request->input('advertiser');
                 }
                 if ($request->has('creative')) {
                     $query .= " and impression.creative_id=" . $request->input('creative');
                 }
                 if ($request->has('geosegment')) {
                     $query .= " and impression.geosegment_id=" . $request->input('geosegment');
                 }
                 if ($request->has('campaign')) {
                     $query .= " and impression.campaign_id=" . $request->input('campaign');
                 }
                 if ($request->has('targetgroup')) {
                     $query .= " and impression.targetgroup_id=" . $request->input('targetgroup');
                 }
                 if ($request->input('report_type') == 'today') {
                     $time = "between '" . date('Y-m-d H:i:s', time() - 60 * 60 * 24) . "' and '" . date('Y-m-d H:i:s', time() + 60 * 30 * 10) . "'";
                     $interval = 300;
                     $query .= " and impression.created_at " . $time;
                 }
                 if ($request->input('report_type') == '10m') {
                     $time = "between '" . date('Y-m-d H:i:s', time() - 600) . "' and '" . date('Y-m-d H:i:s') . "'";
                     $query .= " and impression.created_at " . $time;
                     $interval = 10;
                 }
                 if ($request->input('report_type') == '1h') {
                     $time = "between '" . date('Y-m-d H:i:s', time() - 60 * 60) . "' and '" . date('Y-m-d H:i:s') . "'";
                     $query .= " and impression.created_at " . $time;
                     $interval = 30;
                 }
                 if ($request->input('report_type') == '3h') {
                     $time = "between '" . date('Y-m-d H:i:s', time() - 60 * 60 * 3) . "' and '" . date('Y-m-d H:i:s') . "'";
                     $query .= " and impression.created_at " . $time;
                     $interval = 60;
                 }
                 if ($request->input('report_type') == '6h') {
                     $time = "between '" . date('Y-m-d H:i:s', time() - 60 * 60 * 6) . "' and '" . date('Y-m-d H:i:s') . "'";
                     $query .= " and impression.created_at " . $time;
                     $interval = 120;
                 }
                 if ($request->input('report_type') == '1D') {
                     $time = "between '" . date('Y-m-d H:i:s', time() - 60 * 60 * 24) . "' and '" . date('Y-m-d H:i:s') . "'";
                     $query .= " and impression.created_at " . $time;
                     $interval = 300;
                 }
                 if ($request->input('report_type') == '1M') {
                     $time = "between '" . date('Y-m-d H:i:s', time() - 60 * 60 * 24 * 30) . "' and '" . date('Y-m-d H:i:s') . "'";
                     $query .= " and impression.created_at " . $time;
                     $interval = 60 * 60;
                 }
                 if ($request->input('report_type') == 'rang') {
                     //todo: 120 noghte
                     if ($this->report_date_validation($request->input('date_range'))) {
                         $date_range = explode('&', $request->input('date_range'));
                         $start_date = explode('T', $date_range[0]);
                         $end_date = explode('T', $date_range[1]);
                         $time = "between '" . $start_date[0] . ' ' . $start_date[1] . "' and '" . $end_date[0] . ' ' . $end_date[1] . "'";
                         $query .= " and impression.created_at " . $time;
                         $interval = 24 * 60 * 60;
                     }
                 }
                 switch ($type) {
                     case 'client':
                         $client = DB::table('impression')->join('client', 'impression.client_id', '=', 'client.id')->select(DB::raw('count(impression.client_id) as imps, impression.client_id as id , client.name'))->whereRaw($query)->groupBy('impression.client_id')->orderBy('imps', 'DESC')->get();
                         if ($request->input('advertiser') == '') {
                             $advertiser = DB::table('impression')->join('advertiser', 'impression.advertiser_id', '=', 'advertiser.id')->select(DB::raw('count(impression.advertiser_id) as imps, impression.advertiser_id as id , advertiser.name'))->whereRaw($query)->groupBy('impression.advertiser_id')->orderBy('imps', 'DESC')->get();
                         }
                         break;
                     case 'report_type':
                         $client = DB::table('impression')->join('client', 'impression.client_id', '=', 'client.id')->select(DB::raw('count(impression.client_id) as imps, impression.client_id as id , client.name'))->whereRaw($query)->groupBy('impression.client_id')->orderBy('imps', 'DESC')->get();
                         $advertiser = DB::table('impression')->join('advertiser', 'impression.advertiser_id', '=', 'advertiser.id')->select(DB::raw('count(impression.advertiser_id) as imps, impression.advertiser_id as id , advertiser.name'))->whereRaw($query)->groupBy('impression.advertiser_id')->orderBy('imps', 'DESC')->get();
                         $campaign = DB::table('impression')->join('campaign', 'impression.campaign_id', '=', 'campaign.id')->select(DB::raw('count(impression.campaign_id) as imps, impression.campaign_id as id , campaign.name'))->whereRaw($query)->groupBy('impression.campaign_id')->orderBy('imps', 'DESC')->get();
                         $targetgroup = DB::table('impression')->join('targetgroup', 'impression.targetgroup_id', '=', 'targetgroup.id')->select(DB::raw('count(impression.targetgroup_id) as imps, impression.targetgroup_id as id , targetgroup.name'))->whereRaw($query)->groupBy('impression.targetgroup_id')->orderBy('imps', 'DESC')->get();
                         $creative = DB::table('impression')->join('creative', 'impression.creative_id', '=', 'creative.id')->select(DB::raw('count(impression.creative_id) as imps, impression.creative_id as id , creative.name'))->whereRaw($query)->groupBy('impression.creative_id')->orderBy('imps', 'DESC')->get();
                         $geosegment = DB::table('impression')->join('geosegmentlist', 'impression.geosegment_id', '=', 'geosegmentlist.id')->select(DB::raw('count(impression.geosegment_id) as imps, impression.geosegment_id as id , geosegmentlist.name'))->whereRaw($query)->groupBy('impression.geosegment_id')->orderBy('imps', 'DESC')->get();
                         break;
                     case 'campaign':
                         $campaign_client_advertiser = Campaign::with(['getAdvertiser' => function ($q) {
                             $q->with('GetClientID');
                         }])->find($request->input('campaign'));
                         if ($request->input('client') == '') {
                             $client = DB::table('impression')->join('client', 'impression.client_id', '=', 'client.id')->select(DB::raw('count(impression.client_id) as imps, impression.client_id as id , client.name'))->whereRaw($query)->where('impression.client_id', $campaign_client_advertiser->getAdvertiser->GetClientID->id)->groupBy('impression.client_id')->orderBy('imps', 'DESC')->get();
                         }
                         if ($request->input('advertiser') == '') {
                             $advertiser = DB::table('impression')->join('advertiser', 'impression.advertiser_id', '=', 'advertiser.id')->select(DB::raw('count(impression.advertiser_id) as imps, impression.advertiser_id as id , advertiser.name'))->whereRaw($query)->where('impression.advertiser_id', $campaign_client_advertiser->getAdvertiser->id)->groupBy('impression.advertiser_id')->orderBy('imps', 'DESC')->get();
                         }
                         $campaign = DB::table('impression')->join('campaign', 'impression.campaign_id', '=', 'campaign.id')->select(DB::raw('count(impression.campaign_id) as imps, impression.campaign_id as id , campaign.name'))->whereRaw($query)->groupBy('impression.campaign_id')->orderBy('imps', 'DESC')->get();
                         break;
                     case 'targetgroup':
                         $targetgroup_client_advertiser = Targetgroup::with(['getCampaign' => function ($q) {
                             $q->with(['getAdvertiser' => function ($p) {
                                 $p->with('GetClientID');
                             }]);
                         }])->find($request->input('targetgroup'));
                         if ($request->input('client') == '') {
                             $client = DB::table('impression')->join('client', 'impression.client_id', '=', 'client.id')->select(DB::raw('count(impression.client_id) as imps, impression.client_id as id , client.name'))->whereRaw($query)->where('impression.client_id', $targetgroup_client_advertiser->getCampaign->getAdvertiser->GetClientID->id)->groupBy('impression.client_id')->orderBy('imps', 'DESC')->get();
                         }
                         if ($request->input('advertiser') == '') {
                             $advertiser = DB::table('impression')->join('advertiser', 'impression.advertiser_id', '=', 'advertiser.id')->select(DB::raw('count(impression.advertiser_id) as imps, impression.advertiser_id as id , advertiser.name'))->whereRaw($query)->where('impression.advertiser_id', $targetgroup_client_advertiser->getCampaign->getAdvertiser->id)->groupBy('impression.advertiser_id')->orderBy('imps', 'DESC')->get();
                         }
                         if ($request->input('campaign') == '') {
                             $campaign = DB::table('impression')->join('campaign', 'impression.campaign_id', '=', 'campaign.id')->select(DB::raw('count(impression.campaign_id) as imps, impression.campaign_id as id , campaign.name'))->where('impression.campaign_id', $targetgroup_client_advertiser->getCampaign->id)->groupBy('impression.campaign_id')->orderBy('imps', 'DESC')->get();
                         }
                         $targetgroup = DB::table('impression')->join('targetgroup', 'impression.targetgroup_id', '=', 'targetgroup.id')->select(DB::raw('count(impression.targetgroup_id) as imps, impression.targetgroup_id as id , targetgroup.name'))->whereRaw($query)->groupBy('impression.targetgroup_id')->orderBy('imps', 'DESC')->get();
                         break;
                     case 'advertiser':
                         if ($request->input('client') == '') {
                             $client = DB::table('impression')->join('client', 'impression.client_id', '=', 'client.id')->select(DB::raw('count(impression.client_id) as imps, impression.client_id as id , client.name'))->where('impression.advertiser_id', $request->input('advertiser'))->groupBy('impression.client_id')->orderBy('imps', 'DESC')->get();
                         }
                         $advertiser = DB::table('impression')->join('advertiser', 'impression.advertiser_id', '=', 'advertiser.id')->select(DB::raw('count(impression.advertiser_id) as imps, impression.advertiser_id as id , advertiser.name'))->whereRaw($query)->groupBy('impression.advertiser_id')->orderBy('imps', 'DESC')->get();
                         break;
                     case 'creative':
                         $creativ_client_advertiser = Creative::with(['getAdvertiser' => function ($q) {
                             $q->with('GetClientID');
                         }])->find($request->input('creative'));
                         if ($request->input('client') == '') {
                             $client = DB::table('impression')->join('client', 'impression.client_id', '=', 'client.id')->select(DB::raw('count(impression.client_id) as imps, impression.client_id as id , client.name'))->whereRaw($query)->where('impression.client_id', $creativ_client_advertiser->getAdvertiser->GetClientID->id)->groupBy('impression.client_id')->orderBy('imps', 'DESC')->get();
                         }
                         if ($request->input('advertiser') == '') {
                             $advertiser = DB::table('impression')->join('advertiser', 'impression.advertiser_id', '=', 'advertiser.id')->select(DB::raw('count(impression.advertiser_id) as imps, impression.advertiser_id as id , advertiser.name'))->whereRaw($query)->where('impression.advertiser_id', $creativ_client_advertiser->getAdvertiser->id)->groupBy('impression.advertiser_id')->orderBy('imps', 'DESC')->get();
                         }
                         $creative = DB::table('impression')->join('creative', 'impression.creative_id', '=', 'creative.id')->select(DB::raw('count(impression.creative_id) as imps, impression.creative_id as id , creative.name'))->whereRaw($query)->groupBy('impression.creative_id')->orderBy('imps', 'DESC')->get();
                         break;
                     case 'geosegment':
                         $geosegment_client_advertiser = GeoSegmentList::with(['getAdvertiser' => function ($q) {
                             $q->with('GetClientID');
                         }])->find($request->input('geosegment'));
                         //                            return dd($geosegment_client_advertiser->getAdvertiser);
                         if ($request->input('client') == '') {
                             $client = DB::table('impression')->join('client', 'impression.client_id', '=', 'client.id')->select(DB::raw('count(impression.client_id) as imps, impression.client_id as id , client.name'))->whereRaw($query)->where('impression.client_id', $geosegment_client_advertiser->getAdvertiser->GetClientID->id)->groupBy('impression.client_id')->orderBy('imps', 'DESC')->get();
                         }
                         if ($request->input('advertiser') == '') {
                             $advertiser = DB::table('impression')->join('advertiser', 'impression.advertiser_id', '=', 'advertiser.id')->select(DB::raw('count(impression.advertiser_id) as imps, impression.advertiser_id as id , advertiser.name'))->whereRaw($query)->where('impression.advertiser_id', $geosegment_client_advertiser->getAdvertiser->id)->groupBy('impression.advertiser_id')->orderBy('imps', 'DESC')->get();
                         }
                         $geosegment = DB::table('impression')->join('geosegmentlist', 'impression.geosegment_id', '=', 'geosegmentlist.id')->select(DB::raw('count(impression.geosegment_id) as imps, impression.geosegment_id as id , geosegmentlist.name'))->whereRaw($query)->groupBy('impression.geosegment_id')->orderBy('imps', 'DESC')->get();
                         break;
                     case 'client_unfilter':
                         $client = DB::table('impression')->join('client', 'impression.client_id', '=', 'client.id')->select(DB::raw('count(impression.client_id) as imps, impression.client_id as id , client.name'))->whereIn('impression.advertiser_id', $advertiserArry)->whereIn('impression.client_id', $clientArry)->groupBy('impression.client_id')->orderBy('imps', 'DESC')->get();
                         $advertiser = DB::table('impression')->join('advertiser', 'impression.advertiser_id', '=', 'advertiser.id')->select(DB::raw('count(impression.advertiser_id) as imps, impression.advertiser_id as id , advertiser.name'))->whereIn('impression.advertiser_id', $advertiserArry)->whereIn('impression.client_id', $clientArry)->groupBy('impression.advertiser_id')->orderBy('imps', 'DESC')->get();
                         $campaign = DB::table('impression')->join('campaign', 'impression.campaign_id', '=', 'campaign.id')->select(DB::raw('count(impression.campaign_id) as imps, impression.campaign_id as id , campaign.name'))->whereIn('impression.advertiser_id', $advertiserArry)->whereIn('impression.client_id', $clientArry)->groupBy('impression.campaign_id')->orderBy('imps', 'DESC')->get();
                         $targetgroup = DB::table('impression')->join('targetgroup', 'impression.targetgroup_id', '=', 'targetgroup.id')->select(DB::raw('count(impression.targetgroup_id) as imps, impression.targetgroup_id as id , targetgroup.name'))->whereIn('impression.advertiser_id', $advertiserArry)->whereIn('impression.client_id', $clientArry)->groupBy('impression.targetgroup_id')->orderBy('imps', 'DESC')->get();
                         $creative = DB::table('impression')->join('creative', 'impression.creative_id', '=', 'creative.id')->select(DB::raw('count(impression.creative_id) as imps, impression.creative_id as id , creative.name'))->whereIn('impression.advertiser_id', $advertiserArry)->whereIn('impression.client_id', $clientArry)->groupBy('impression.creative_id')->orderBy('imps', 'DESC')->get();
                         $geosegment = DB::table('impression')->join('geosegmentlist', 'impression.geosegment_id', '=', 'geosegmentlist.id')->select(DB::raw('count(impression.geosegment_id) as imps, impression.geosegment_id as id , geosegmentlist.name'))->whereIn('impression.advertiser_id', $advertiserArry)->whereIn('impression.client_id', $clientArry)->groupBy('impression.geosegment_id')->orderBy('imps', 'DESC')->get();
                         break;
                 }
                 if ($request->input('client') == '' and $client == '') {
                     $client = DB::table('impression')->join('client', 'impression.client_id', '=', 'client.id')->select(DB::raw('count(impression.client_id) as imps, impression.client_id as id , client.name'))->whereRaw($query)->groupBy('impression.client_id')->orderBy('imps', 'DESC')->get();
                 }
                 if ($request->input('advertiser') == '' and $advertiser == '') {
                     $advertiser = DB::table('impression')->join('advertiser', 'impression.advertiser_id', '=', 'advertiser.id')->select(DB::raw('count(impression.advertiser_id) as imps, impression.advertiser_id as id , advertiser.name'))->whereRaw($query)->groupBy('impression.advertiser_id')->orderBy('imps', 'DESC')->get();
                 }
                 if ($request->input('campaign') == '' and $campaign == '') {
                     $campaign = DB::table('impression')->join('campaign', 'impression.campaign_id', '=', 'campaign.id')->select(DB::raw('count(impression.campaign_id) as imps, impression.campaign_id as id , campaign.name'))->whereRaw($query)->groupBy('impression.campaign_id')->orderBy('imps', 'DESC')->get();
                 }
                 if ($request->input('targetgroup') == '') {
                     $targetgroup = DB::table('impression')->join('targetgroup', 'impression.targetgroup_id', '=', 'targetgroup.id')->select(DB::raw('count(impression.targetgroup_id) as imps, impression.targetgroup_id as id , targetgroup.name'))->whereRaw($query)->groupBy('impression.targetgroup_id')->orderBy('imps', 'DESC')->get();
                 }
                 if ($request->input('creative') == '') {
                     $creative = DB::table('impression')->join('creative', 'impression.creative_id', '=', 'creative.id')->select(DB::raw('count(impression.creative_id) as imps, impression.creative_id as id , creative.name'))->whereRaw($query)->groupBy('impression.creative_id')->orderBy('imps', 'DESC')->get();
                 }
                 if ($request->input('geosegmentlist') == '') {
                     $geosegment = DB::table('impression')->join('geosegmentlist', 'impression.geosegment_id', '=', 'geosegmentlist.id')->select(DB::raw('count(impression.geosegment_id) as imps, impression.geosegment_id as id , geosegmentlist.name'))->whereRaw($query)->groupBy('impression.geosegment_id')->orderBy('imps', 'DESC')->get();
                 }
                 //                    return dd($query);
                 if ($time != '') {
                     $impChart = Impression::where('event_type', 'impression')->whereRaw($query)->whereRaw('created_at ' . $time)->orderBy('created_at', 'ASC')->get();
                     $imps = 1;
                     $flg = 0;
                     //                        return dd($impChart);
                     $impsString = "Date,Imps\n";
                     if ($impChart) {
                         foreach ($impChart as $key => $index) {
                             if ($flg == 0) {
                                 $timeToShow = $index->created_at;
                                 $firstHop = strtotime($index->created_at);
                                 $nextHop = $firstHop + $interval;
                                 $flg = 1;
                             }
                             if (isset($impChart[$key + 1]) and strtotime($impChart[$key + 1]->created_at) >= $nextHop) {
                                 $impsString .= $timeToShow . ",0;" . $imps . ";0\n";
                                 $flg = 0;
                                 $imps = 0;
                             }
                             if (!isset($impChart[$key + 1])) {
                             }
                             $imps++;
                         }
                     }
                     //                        return dd($impsString);
                     $clkChart = Impression::where('event_type', 'click')->whereRaw($query)->whereRaw('created_at ' . $time)->orderBy('created_at', 'ASC')->get();
                     $imps = 1;
                     $flg = 0;
                     $clkString = "Date,Clicks\n";
                     foreach ($clkChart as $key => $index) {
                         if ($flg == 0) {
                             $timeToShow = $index->created_at;
                             $firstHop = strtotime($index->created_at);
                             $nextHop = $firstHop + $interval;
                             $flg = 1;
                         }
                         if (isset($clkChart[$key + 1]) and strtotime($clkChart[$key + 1]->created_at) >= $nextHop) {
                             $clkString .= $timeToShow . ",0;" . $imps . ";0\n";
                             $flg = 0;
                             $imps = 0;
                         }
                         if (!isset($clkChart[$key + 1])) {
                         }
                         $imps++;
                     }
                     $cnvChart = Impression::where('event_type', 'conversion')->whereRaw($query)->whereRaw('created_at ' . $time)->orderBy('created_at', 'ASC')->get();
                     $imps = 1;
                     $flg = 0;
                     $cnvString = "Date,Conversion\n";
                     foreach ($cnvChart as $key => $index) {
                         if ($flg == 0) {
                             $timeToShow = $index->created_at;
                             $firstHop = strtotime($index->created_at);
                             $nextHop = $firstHop + $interval;
                             $flg = 1;
                         }
                         if (isset($cnvChart[$key + 1]) and strtotime($cnvChart[$key + 1]->created_at) >= $nextHop) {
                             $cnvString .= $timeToShow . ",0;" . $imps . ";0\n";
                             $flg = 0;
                             $imps = 0;
                         }
                         if (!isset($cnvChart[$key + 1])) {
                         }
                         $imps++;
                     }
                     array_push($arr, $client);
                     array_push($arr, $advertiser);
                     array_push($arr, $creative);
                     array_push($arr, $geosegment);
                     array_push($arr, $campaign);
                     array_push($arr, $targetgroup);
                     array_push($arr, $impsString);
                     array_push($arr, $clkString);
                     array_push($arr, $cnvString);
                 }
                 return json_encode($arr);
                 $clients = Client::get();
                 $advertiser = Advertiser::get();
                 //                    $advertiser = Advertiser::with(['Campaign' => function ($q) {
                 //                        $q->select(DB::raw('*,count(advertiser_id) as advertiser_count'))->groupBy('advertiser_id');
                 //                    }])->with('GetClientID')->get();
             } else {
                 $usr_company = User::where('company_id', Auth::user()->company_id)->get(['id'])->toArray();
                 $clients = Client::whereIn('user_id', $usr_company)->get();
                 $advertiser = Advertiser::with(['GetClientID' => function ($p) use($usr_company) {
                     $p->whereIn('user_id', $usr_company);
                 }])->get();
             }
             //                return dd($advertiser);
             return view('report.report')->with('clients', $clients)->with('advertiser', $advertiser);
         }
         return Redirect::back()->withErrors(['success' => false, 'msg' => "You don't have permission"]);
     }
     return Redirect::to(url('user/login'));
 }
Exemplo n.º 28
0
 /**
  * Display a listing of the resource.
  *
  * @return \Illuminate\Http\Response
  */
 public function index()
 {
     $campaigns = Campaign::all();
     return $campaigns;
 }