public function createcontestmobile()
 {
     $inputdetails = Input::except(array('_token', 'themephoto', 'sponsor', 'sponsorphoto', 'sponsorname', 'interest_id'));
     $conteststartdate = Input::get('conteststartdate');
     $timezone = Input::get('timezone');
     $inputdetails['conteststartdate'] = timezoneModel::convert(Input::get('conteststartdate'), $timezone, 'UTC', 'Y-m-d H:i:s');
     $inputdetails['contestenddate'] = timezoneModel::convert(Input::get('contestenddate'), $timezone, 'UTC', 'Y-m-d H:i:s');
     $inputdetails['votingstartdate'] = timezoneModel::convert(Input::get('votingstartdate'), $timezone, 'UTC', 'Y-m-d H:i:s');
     $inputdetails['votingenddate'] = timezoneModel::convert(Input::get('votingenddate'), $timezone, 'UTC', 'Y-m-d H:i:s');
     if (Input::file('themephoto') != '') {
         $destinationPath = 'public/assets/upload/contest_theme_photo';
         $filename = Input::file('themephoto')->getClientOriginalName();
         $Image = str_random(8) . '_' . $filename;
         $inputdetails['themephoto'] = $Image;
     }
     if (Input::get('userid')) {
         $inputdetails['createdby'] = Input::get('userid');
     }
     $inputdetails['contestcode'] = str_random(8);
     $currentdate = Carbon::now();
     $inputdetails['createddate'] = $currentdate;
     $inputdetails['visibility'] = 'p';
     $inputdetails['status'] = 1;
     $validation = Validator::make($inputdetails, contestModel::$rules);
     if ($validation->passes()) {
         $file = Input::file('themephoto');
         $uploadSuccess = $file->move($destinationPath, $Image);
         $contestcreate = contestModel::create($inputdetails);
         if ($contestcreate) {
             $private_cont['contest_id'] = contestModel::max('ID');
             $private_cont['user_id'] = Input::get('userid');
             $private_cont['requesteddate'] = date('Y-m-d H:i:s');
             $private_cont['status'] = 1;
             privateusercontestModel::create($private_cont);
         }
         $interest_id = Input::get('interest_id');
         $interestid = explode(',', $interest_id);
         $interestidcount = count($interestid);
         $maxcontestid = contestModel::max('ID');
         $interest['contest_id'] = "{$maxcontestid}";
         for ($i = 0; $i < $interestidcount; $i++) {
             $interest['category_id'] = $interestid[$i];
             //return $interest;
             $validationinterest = Validator::make($interest, contestinterestModel::$rules);
             if ($validationinterest->passes()) {
                 $userregister = contestinterestModel::create($interest);
             }
         }
         $Response = array('success' => '1', 'message' => 'Record Added Successfully', 'msgcode' => "c107");
         $final = array("response" => $Response, "contest_id" => $maxcontestid);
         return json_encode($final);
     } else {
         $Response = array('success' => '0', 'message' => $validation->messages()->first(), 'msgcode' => "c112");
         $final = array("response" => $Response);
         return json_encode($final);
     }
 }
Esempio n. 2
0
 public function savecontest()
 {
     $conteststart = Input::get('conteststartdate');
     $contestenddate = Input::get('contestenddate');
     $votingstartdate = Input::get('votingstartdate');
     $votingenddate = Input::get('votingenddate');
     $a = 0;
     //if($conteststart<$contestenddate && $contestenddate<=$votingstartdate && $votingstartdate<$votingenddate){}else{  return "S"; }
     if ($conteststart > $contestenddate) {
         $a = 1;
         $er_data['contestenddate'] = 'Contest end date should be greater than contest start date';
     } elseif (strtotime($contestenddate) > strtotime($votingstartdate)) {
         $a = 1;
         $er_data['votingstartdate'] = 'Voting start date should be greater than or equal to contest end date';
     } elseif ($votingstartdate > $votingenddate) {
         $a = 1;
         $er_data['votingenddate'] = 'Voting end date should be greater than voting start date';
     }
     if ($a == 1) {
         return Redirect::to('/contest')->withInput()->with('er_data', $er_data);
     }
     $inputdetails = Input::except(array('_token', 'themephoto', 'sponsor', 'sponsorphoto', 'sponsorname'));
     if (Input::file('themephoto') != '') {
         $destinationPath_them = 'public/assets/upload/contest_theme_photo';
         $filename_them = Input::file('themephoto')->getClientOriginalName();
         $Image_them = str_random(8) . '_' . $filename_them;
         $inputdetails['themephoto'] = $Image_them;
     }
     if (Auth::user()->ID == 1) {
         $inputdetails['sponsorname'] = Input::get('sponsorname');
         if (Input::file('sponsorphoto') != '') {
             $destinationPath_spons = 'public/assets/upload/sponsor_photo';
             $filename_spons = Input::file('sponsorphoto')->getClientOriginalName();
             $Image_spons = str_random(8) . '_' . $filename_spons;
             $inputdetails['sponsorphoto'] = $Image_spons;
         }
     }
     $lantyp = Session::get('language');
     if ($lantyp == "") {
         $lantyp = "value_en";
     }
     $validation = Validator::make($inputdetails, contestModel::$rules);
     if ($validation->passes()) {
         if (Auth::user()->ID == 1) {
             $admintimezone = User::where('ID', 1)->get()->first();
             $inputdetails['conteststartdate'] = timezoneModel::convert(date('Y-m-d H:i:s', strtotime($inputdetails['conteststartdate'])), $admintimezone->timezone, 'UTC', 'Y-m-d H:i:s');
             $inputdetails['contestenddate'] = timezoneModel::convert(date('Y-m-d H:i:s', strtotime($inputdetails['contestenddate'])), $admintimezone->timezone, 'UTC', 'Y-m-d H:i:s');
             $inputdetails['votingstartdate'] = timezoneModel::convert(date('Y-m-d H:i:s', strtotime($inputdetails['votingstartdate'])), $admintimezone->timezone, 'UTC', 'Y-m-d H:i:s');
             $inputdetails['votingenddate'] = timezoneModel::convert(date('Y-m-d H:i:s', strtotime($inputdetails['votingenddate'])), $admintimezone->timezone, 'UTC', 'Y-m-d H:i:s');
         } else {
             $inputdetails['conteststartdate'] = timezoneModel::convert(date('Y-m-d H:i:s', strtotime($inputdetails['conteststartdate'])), Auth::user()->timezone, 'UTC', 'Y-m-d H:i:s');
             $inputdetails['contestenddate'] = timezoneModel::convert(date('Y-m-d H:i:s', strtotime($inputdetails['contestenddate'])), Auth::user()->timezone, 'UTC', 'Y-m-d H:i:s');
             $inputdetails['votingstartdate'] = timezoneModel::convert(date('Y-m-d H:i:s', strtotime($inputdetails['votingstartdate'])), Auth::user()->timezone, 'UTC', 'Y-m-d H:i:s');
             $inputdetails['votingenddate'] = timezoneModel::convert(date('Y-m-d H:i:s', strtotime($inputdetails['votingenddate'])), Auth::user()->timezone, 'UTC', 'Y-m-d H:i:s');
         }
         $inputdetails['createdby'] = Auth::user()->ID;
         if (Auth::user()->ID == 1) {
             $inputdetails['visibility'] = Input::get('visibility');
         } else {
             $inputdetails['visibility'] = "p";
         }
         $inputdetails['status'] = 1;
         $inputdetails['createddate'] = $inputdetails['updateddate'] = date('Y-m-d H:i:s');
         $file_them = Input::file('themephoto');
         $file_spons = Input::file('sponsorphoto');
         if (isset($inputdetails['sponsorphoto'])) {
             $uploadSuccess_spons = $file_spons->move($destinationPath_spons, $Image_spons);
         }
         if (isset($inputdetails['themephoto'])) {
             $uploadSuccess_them = $file_them->move($destinationPath_them, $Image_them);
         }
         $product = contestModel::create($inputdetails);
         $contest_id = $product->ID;
         $interest = Input::get('interest');
         $interest_length = sizeof(Input::get('interest'));
         if ($interest_length > 0) {
             contestinterestModel::whereNotIn('category_id', $interest)->where('contest_id', '=', $contest_id)->delete();
             for ($i = 0; $i < $interest_length; $i++) {
                 $interes['contest_id'] = $contest_id;
                 $interes['category_id'] = $interest[$i];
                 $userInterest = contestinterestModel::where('contest_id', $contest_id)->where('category_id', $interest[$i])->lists('category_id');
                 if (count($userInterest) < 1) {
                     contestinterestModel::create($interes);
                     /// Vew enhanchment for interest send push notification to appropriate user ////
                     $pushnotificationdetail = userinterestModel::select('user.firstname', 'user.lastname', 'user.username', 'user.ID', 'user.email', 'user.gcm_id', 'user.device_type', 'user.timezone')->LeftJoin('user', 'user.ID', '=', 'user_interest.user_id')->where('interest_id', $interest[$i])->get();
                     for ($j = 0; $j < count($pushnotificationdetail); $j++) {
                         if (Auth::user()->ID == 1) {
                             if ($pushnotificationdetail[$j]['firstname'] != '') {
                                 $name = $pushnotificationdetail[$j]['firstname'] . ' ' . $pushnotificationdetail[$j]['lastname'];
                             } else {
                                 $name = $pushnotificationdetail[$j]['username'];
                             }
                             $email = $pushnotificationdetail[$j]['email'];
                             $gcm_id = $pushnotificationdetail[$j]['gcm_id'];
                             $device_type = $pushnotificationdetail[$j]['device_type'];
                             $uid = $pushnotificationdetail[$j]['ID'];
                             $contestname = Input::get('contest_name');
                             $contesttype = Input::get('contesttype');
                             $contestimage = $Image_them;
                             $conteststartdate = timezoneModel::convert($inputdetails['conteststartdate'], 'UTC', $pushnotificationdetail[$j]['timezone'], 'd-m-Y h:i:s');
                             $contestenddate = timezoneModel::convert($inputdetails['contestenddate'], 'UTC', $pushnotificationdetail[$j]['timezone'], 'd-m-Y h:i:s');
                             $this->Inviteforcontestintest($name, $email, $gcm_id, $device_type, $uid, $interest[$i], $contestname, $contest_id, $contesttype, $contestimage, $conteststartdate, $contestenddate);
                         }
                     }
                     //
                     //$interest[$i]
                 }
                 unset($interes);
             }
         }
         $private_cont['contest_id'] = $contest_id;
         $private_cont['user_id'] = Auth::user()->ID;
         $private_cont['requesteddate'] = date('Y-m-d H:i:s');
         $private_cont['status'] = 1;
         if (Auth::user()->ID == 1) {
             if (Input::get('visibility') == 'p') {
                 privateusercontestModel::create($private_cont);
             }
         } else {
             privateusercontestModel::create($private_cont);
         }
         return Redirect::to('contest_info/' . $product->ID);
     } else {
         if ($validation->messages()->first('contest_name') == "The contest name field is required.") {
             $er_msg_con_name = "The Contest Name field is required.";
         } else {
             $er_msg_con_name = $validation->messages()->first('contest_name');
         }
         if ($validation->messages()->first('conteststartdate') == "The conteststartdate field is required.") {
             $er_msg_con_start = "The Contest Start Date field is required.";
         } else {
             $er_msg_con_start = $validation->messages()->first('conteststartdate');
         }
         if ($validation->messages()->first('contestenddate') == "The contestenddate field is required.") {
             $er_msg_con_end = "The Contest End Date field is required.";
         } else {
             $er_msg_con_end = $validation->messages()->first('contestenddate');
         }
         if ($validation->messages()->first('votingstartdate') == "The votingstartdate field is required.") {
             $er_msg_vote_start = "The Voting Start Date field is required.";
         } else {
             $er_msg_vote_start = $validation->messages()->first('votingstartdate');
         }
         if ($validation->messages()->first('votingenddate') == "The votingenddate field is required.") {
             $er_msg_vote_end = "The Voting End Date field is required.";
         } else {
             $er_msg_vote_end = $validation->messages()->first('votingenddate');
         }
         if ($validation->messages()->first('noofparticipant') == "The noofparticipant field is required.") {
             $er_msg_noof_part = "The No of Participant field is required.";
         } else {
             $er_msg_noof_part = $validation->messages()->first('noofparticipant');
         }
         if ($validation->messages()->first('contesttype') == "The contesttype field is required.") {
             $er_msg_con_type = "The Contest Type field is required.";
         } else {
             $er_msg_con_type = $validation->messages()->first('contesttype');
         }
         if ($validation->messages()->first('themephoto') == "The themephoto field is required.") {
             $er_msg_them = "The Contest Image field is required.";
         } else {
             $er_msg_them = $validation->messages()->first('themephoto');
         }
         $languageDetails = languageModel::select($lantyp, 'ctrlCaptionId')->whereIn('value_en', [$er_msg_con_name, $er_msg_con_start, $er_msg_con_end, $er_msg_vote_start, $er_msg_vote_end, $er_msg_noof_part, $er_msg_con_type, $er_msg_them])->get()->toArray();
         //return $validation->messages();
         foreach ($languageDetails as $key => $val) {
             if (in_array($val['ctrlCaptionId'], ['alert_entercontestname', 'alert_alreadycontestname'])) {
                 $er_data['contest_name'] = "<span id='" . $val['ctrlCaptionId'] . "'>" . $val[$lantyp] . "</span>";
             } elseif (in_array($val['ctrlCaptionId'], ['alert_enterconteststartdate'])) {
                 $er_data['conteststartdate'] = "<span id='" . $val['ctrlCaptionId'] . "'>" . $val[$lantyp] . "</span>";
             } elseif (in_array($val['ctrlCaptionId'], ['alert_contestenddate'])) {
                 $er_data['contestenddate'] = "<span id='" . $val['ctrlCaptionId'] . "'>" . $val[$lantyp] . "</span>";
             } elseif (in_array($val['ctrlCaptionId'], ['alert_votingstartdate'])) {
                 $er_data['votingstartdate'] = "<span id='" . $val['ctrlCaptionId'] . "'>" . $val[$lantyp] . "</span>";
             } elseif (in_array($val['ctrlCaptionId'], ['alert_votingenddate'])) {
                 $er_data['votingenddate'] = "<span id='" . $val['ctrlCaptionId'] . "'>" . $val[$lantyp] . "</span>";
             } elseif (in_array($val['ctrlCaptionId'], ['alert_enternoofpartis'])) {
                 $er_data['noofparticipant'] = "<span id='" . $val['ctrlCaptionId'] . "'>" . $val[$lantyp] . "</span>";
             } elseif (in_array($val['ctrlCaptionId'], ['alert_entercontesttype'])) {
                 $er_data['contesttype'] = "<span id='" . $val['ctrlCaptionId'] . "'>" . $val[$lantyp] . "</span>";
             } elseif (in_array($val['ctrlCaptionId'], ['alert_themephoto'])) {
                 $er_data['themephoto'] = "<span id='" . $val['ctrlCaptionId'] . "'>" . $val[$lantyp] . "</span>";
             }
         }
         return Redirect::to('/contest')->withInput()->with('er_data', $er_data);
     }
 }