Example #1
0
 public function getAudit($id, $entity_id = null)
 {
     if (Auth::check()) {
         $query = '1';
         switch ($id) {
             case 'user':
                 if (!is_null($entity_id)) {
                     $query .= " and (entity_type = 'user' and entity_id = '" . $entity_id . "')";
                 } else {
                     $query .= " and (entity_type = 'user')";
                 }
                 break;
             case 'company':
                 if (!is_null($entity_id)) {
                     $query .= " and (entity_type = 'company' and entity_id = '" . $entity_id . "')";
                 } else {
                     $query .= " and (entity_type = 'company')";
                 }
                 break;
             case 'inventory':
                 if (!is_null($entity_id)) {
                     $query .= " and (entity_type = 'inventory' and entity_id = '" . $entity_id . "')";
                 } else {
                     $query .= " and (entity_type = 'inventory')";
                 }
                 break;
             case 'client':
                 if (!is_null($entity_id)) {
                     $query .= " and (entity_type = 'client' and entity_id = '" . $entity_id . "')";
                 } else {
                     $query .= " and (entity_type = 'client')";
                 }
                 break;
             case 'advertiser':
                 if (!is_null($entity_id)) {
                     $query .= " and ((entity_type = 'advertiser' and entity_id = '" . $entity_id . "') or (entity_type = 'advertiser_model_map' and after_value = '" . $entity_id . "')) ";
                 } else {
                     $query .= " and (entity_type = 'advertiser' or entity_type = 'advertiser_model_map')";
                 }
                 break;
             case 'campaign':
                 if (!is_null($entity_id)) {
                     $query .= " and (entity_type = 'campaign' and entity_id = '" . $entity_id . "')";
                 } else {
                     $query .= " and (entity_type = 'campaign')";
                 }
                 break;
             case 'creative':
                 if (!is_null($entity_id)) {
                     $query .= " and (entity_type = 'creative' and entity_id = '" . $entity_id . "')";
                 } else {
                     $query .= " and (entity_type = 'creative')";
                 }
                 break;
             case 'offer':
                 if (!is_null($entity_id)) {
                     $query .= " and ((entity_type = 'offer' and entity_id = '" . $entity_id . "') or (entity_type = 'offer_pixel_map' and after_value = '" . $entity_id . "')) ";
                 } else {
                     $query .= " and (entity_type = 'offer' or entity_type = 'offer_pixel_map')";
                 }
                 break;
             case 'pixel':
                 if (!is_null($entity_id)) {
                     $query .= " and (entity_type = 'pixel' and entity_id = '" . $entity_id . "')";
                 } else {
                     $query .= " and (entity_type = 'pixel')";
                 }
                 break;
             case 'targetgroup':
                 if (!is_null($entity_id)) {
                     $query .= " and ((entity_type = 'targetgroup' and entity_id = '" . $entity_id . "')\n                        or (entity_type = 'targetgroup_creative_map' and after_value='" . $entity_id . "' )\n                        or (entity_type = 'targetgroup_geolocation_map' and after_value='" . $entity_id . "' )\n                        or (entity_type = 'targetgroup_segment_map' and after_value='" . $entity_id . "' )\n                        or (entity_type = 'targetgroup_geosegment_map' and after_value='" . $entity_id . "' )\n                        or (entity_type = 'targetgroup_bwlist_map' and after_value='" . $entity_id . "' )\n                        or (entity_type = 'targetgroup_bidprofile_map' and after_value='" . $entity_id . "' ))";
                 } else {
                     $query .= " and (entity_type = 'targetgroup')";
                 }
                 break;
             case 'geosegment':
                 if (!is_null($entity_id)) {
                     $query .= " and ((entity_type = 'geosegment' and entity_id = '" . $entity_id . "') or (entity_type = 'geosegmententrie' and after_value ='" . $entity_id . "') )";
                 } else {
                     $query .= " and (entity_type = 'geosegment')";
                 }
                 break;
             case 'bwlist':
                 if (!is_null($entity_id)) {
                     $query .= " and ((entity_type = 'bwlist' and entity_id = '" . $entity_id . "') or (entity_type = 'bwlistentrie' and after_value = '" . $entity_id . "')) ";
                 } else {
                     $query .= " and (entity_type = 'bwlist' or entity_type = 'bwlistentrie')";
                 }
                 break;
             case 'bid_profile':
                 if (!is_null($entity_id)) {
                     $query .= " and ((entity_type = 'bid_profile' and entity_id = '" . $entity_id . "') or (entity_type = 'bid_profile_entry' and after_value = '" . $entity_id . "')) ";
                 } else {
                     $query .= " and (entity_type = 'bid_profile' or entity_type = 'bid_profile_entry')";
                 }
                 break;
             case 'model':
                 if (!is_null($entity_id)) {
                     $query .= " and ((entity_type = 'modelTable' and entity_id = '" . $entity_id . "') or (entity_type = 'negative_offer_model' and after_value = '" . $entity_id . "') or (entity_type = 'positive_offer_model' and after_value = '" . $entity_id . "')) ";
                 } else {
                     $query .= " and (entity_type = 'modelTable' or entity_type = 'negative_offer_model' or entity_type = 'positive_offer_model')";
                 }
                 break;
             case 'user_id':
                 $user_id = Auth::user()->id;
                 $query .= " and (user_id = '" . $user_id . "')";
                 break;
         }
         if (User::isSuperAdmin()) {
             $audit = Audits::with('getUser')->whereRaw($query)->orderBy('created_at', 'DESC')->get();
         } else {
             $usr_comp = $this->user_company();
             $audit = Audits::with('getUser')->whereIn('user_id', $usr_comp)->whereRaw($query)->whereIn('user_id', $usr_comp)->orderBy('created_at', 'DESC')->get();
         }
         $audit_obj = array();
         if ($audit) {
             $sub = new AuditsController();
             $audit_obj = $sub->SubAudit($audit);
         }
         return view('audit.template.all_audits')->with('audit_obj', $audit_obj);
     }
     return 'check ur login';
 }