示例#1
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;
 }
 public function jqgrid(Request $request)
 {
     // TODO: must be in inventory
     //        return dd($request->all());
     if (Auth::check()) {
         if (in_array('ADD_EDIT_BIDPROFILE', $this->permission)) {
             //permission goes here
             $rules = array('domain' => 'required', 'bid_strategy' => 'required');
             if ($request->input('oper') == 'edit' or $request->input('oper') == 'del') {
                 $rules['bid_value'] = 'required';
             } else {
                 if ($request->input('bid_strategy') == 'Absolute' or $request->input('bid_strategy') == 1) {
                     $rules['bid_value'] = 'required';
                 } else {
                     $rules["bid_value1"] = 'required';
                 }
             }
             $validate = \Validator::make($request->all(), $rules);
             if ($validate->passes()) {
                 //                    return dd($request->input('parent_id'));
                 if (User::isSuperAdmin()) {
                     $bid_profile_obj = Bid_Profile::find($request->input('parent_id'));
                 } else {
                     $usr_company = $this->user_company();
                     $bid_profile_obj = Bid_Profile::whereHas('getAdvertiser', function ($q) use($usr_company) {
                         $q->whereHas('GetClientID', function ($p) use($usr_company) {
                             $p->whereIn('user_id', $usr_company);
                         });
                     })->find($request->input('parent_id'));
                     if (!$bid_profile_obj) {
                         return Redirect::back()->withErrors(['success' => false, 'msg' => 'please Select your Client'])->withInput();
                     }
                 }
                 if ($bid_profile_obj) {
                     if (preg_match($this->pattern, $request->input('domain'))) {
                         //                            return dd($request->all());
                         $audit = new AuditsController();
                         switch ($request->input('oper')) {
                             case 'add':
                                 $chk = Bid_Profile_Entry::where('bid_profile_id', $request->input('parent_id'))->get();
                                 foreach ($chk as $index) {
                                     if ($index->domain == $request->input('domain')) {
                                         return Redirect::back()->withErrors(['success' => false, 'msg' => 'this name already existed !!!'])->withInput();
                                     }
                                 }
                                 $bid_profile_entry = new Bid_Profile_Entry();
                                 $bid_profile_entry->domain = $request->input('domain');
                                 $bid_profile_entry->bid_strategy = $request->input('bid_strategy');
                                 $bid_profile_entry->bid_profile_id = $request->input('parent_id');
                                 $bid_profile_entry->bid_value = $request->has('bid_value') ? $request->input('bid_value') : $request->input('bid_value1');
                                 $bid_profile_entry->save();
                                 $audit->store('bid_profile_entry', $bid_profile_entry->id, $request->input('parent_id'), 'add');
                                 return $msg = ['success' => true, 'msg' => "your Entry has been Added"];
                                 break;
                             case 'edit':
                                 $bid_profile_entry = Bid_Profile_Entry::where('bid_profile_id', $request->input('parent_id'))->where('id', $request->input('id'))->first();
                                 if ($bid_profile_entry) {
                                     $data = array();
                                     if ($bid_profile_entry->domain != $request->input('domain')) {
                                         array_push($data, 'Domain');
                                         array_push($data, $bid_profile_entry->domain);
                                         array_push($data, $request->input('domain'));
                                         $bid_profile_entry->domain = $request->input('domain');
                                     }
                                     $bid_strategy = $request->input('bid_strategy') == 1 ? 'Absolute' : 'Percentage';
                                     //                                        return dd($bid_strategy);
                                     if ($bid_profile_entry->bid_strategy != $bid_strategy) {
                                         array_push($data, 'Bid Strategy');
                                         array_push($data, $bid_profile_entry->bid_strategy);
                                         array_push($data, $bid_strategy);
                                         $bid_profile_entry->bid_strategy = $bid_strategy;
                                     }
                                     if ($bid_profile_entry->bid_value != $request->input('bid_value')) {
                                         array_push($data, 'Bid Value');
                                         array_push($data, $bid_profile_entry->bid_value);
                                         array_push($data, $request->input('bid_value'));
                                         $bid_profile_entry->bid_value = $request->input('bid_value');
                                     }
                                     $audit->store('bid_profile_entry', $request->input('id'), $data, 'edit');
                                     $bid_profile_entry->save();
                                     return $msg = ['success' => true, 'msg' => "your Entry has been Edited"];
                                 }
                                 return 'some things went wrong!';
                                 break;
                             case 'del':
                                 $audit = new AuditsController();
                                 $d = array($request->input('id'), $request->input('parent_id'));
                                 $audit->store('bid_profile_entry', $request->input('id'), $d, 'del');
                                 Bid_Profile_Entry::where('id', $request->input('id'))->where('bid_profile_id', $request->input('parent_id'))->delete();
                                 return $msg = ['success' => true, 'msg' => "your Entry has been Deleted"];
                                 break;
                         }
                     }
                     return $msg = ['success' => false, 'msg' => "PLZ enter valid Web site domain"];
                 }
                 return $msg = ['success' => false, 'msg' => "please select correct Bid Profile!"];
             }
             //return print_r($validate->messages());
             return $msg = ['success' => false, 'msg' => "please Check your fields"];
         }
     }
     return Redirect::to(url('/user/login'));
 }