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; }
public function UploadBidProfile(Request $request) { // return dd($request->all()); if (Auth::check()) { if (in_array('ADD_EDIT_BIDPROFILE', $this->permission)) { $validate = \Validator::make($request->all(), ['name' => 'required']); if ($request->hasFile('upload_bid_profile') and $validate->passes()) { 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_bid_profile')->getClientOriginalExtension(); // getting image extension $fileName = str_random(32) . '.' . $extension; $request->file('upload_bid_profile')->move($destpath . '/cdn/test/', $fileName); $upload = Excel::load('public/cdn/test/' . $fileName, function ($reader) { })->get(); // return dd($upload); $t = array(); foreach ($upload[0] as $key => $value) { array_push($t, $key); } if ($t[0] != 'domain' or $t[1] != 'bid_strategy' or $t[2] != 'bid_value') { File::delete($destpath . '/cdn/test/' . $fileName); return Redirect::back()->withErrors(['success' => false, 'msg' => 'please be sure that file is correct'])->withInput(); } $chk = Bid_Profile::where('advertiser_id', $request->input('advertiser_id'))->get(); foreach ($chk as $index) { if ($index->name == $request->input('name')) { File::delete($destpath . '/cdn/test/' . $fileName); return Redirect::back()->withErrors(['success' => false, 'msg' => 'this name already existed !!!'])->withInput(); } } $bid_profile = new Bid_Profile(); $bid_profile->name = $request->input('name'); $bid_profile->advertiser_id = $request->input('advertiser_id'); $bid_profile->status = 'Active'; $bid_profile->save(); foreach ($upload as $test) { $flg = 0; if ($test['bid_strategy'] == 'Absolute') { if ($test['bid_value'] < 0 and $test['bid_value'] > 10) { $flg = 1; } } elseif ($test['bid_strategy'] == 'Percentage') { if ($test['bid_value'] < 0 and $test['bid_value'] > 100) { $flg = 1; } } elseif (!preg_match($this->pattern, $test['domain'])) { $flg = 1; } if ($flg == 0) { $bid_profile_entry = new Bid_Profile_Entry(); $bid_profile_entry->domain = $test['domain']; $bid_profile_entry->bid_strategy = $test['bid_strategy']; $bid_profile_entry->bid_value = $test['bid_value']; $bid_profile_entry->bid_profile_id = $bid_profile->id; $bid_profile_entry->save(); } } $msg = "Bid Profile added successfully"; return Redirect::back()->withErrors(['success' => true, 'msg' => $msg]); } return Redirect::back()->withErrors(['success' => false, 'msg' => 'please Select your Client'])->withInput(); } return Redirect::back()->withErrors(['success' => false, 'msg' => 'please Select a file or fill name '])->withInput(); } return Redirect::back()->withErrors(['success' => false, 'msg' => "You don't have permission"]); } return Redirect::to(url('/user/login')); }