public function invitefollowesforcontest()
 {
     //invitefollowerforcontestModel
     $invite_type = Input::get('invite_type');
     $contest_id = Input::get('contest_id');
     $curdate = date('Y-m-d h:i:s');
     $inpudetails['contest_id'] = $contest_id;
     $inpudetails['invitedate'] = $curdate;
     $contestdetails = contestModel::select('contest.createdby', 'contest.visibility', 'contest.contest_name', 'contest.contesttype', 'user.firstname', 'user.lastname', 'user.username', 'contest.conteststartdate', 'contest.contestenddate', 'contest.themephoto')->LeftJoin('user', 'user.ID', '=', 'contest.createdby')->where('contest.ID', $contest_id)->get();
     $userid = $contestdetails[0]['createdby'];
     if ($contestdetails[0]['firstname'] != '') {
         $contestcreatedby = $contestdetails[0]['firstname'] . ' ' . $contestdetails[0]['lastname'];
     } else {
         $contestcreatedby = $contestdetails[0]['username'];
     }
     $conteststartdate = $contestdetails[0]['conteststartdate'];
     $contestenddate = $contestdetails[0]['contestenddate'];
     $contesttype = $contestdetails[0]['contesttype'];
     if ($contesttype == 'p') {
         $contesttype = "Photo";
     } else {
         if ($contesttype == 'v') {
             $contesttype = "Video";
         } else {
             if ($contesttype == 't') {
                 $contesttype = "Topic";
             }
         }
     }
     $contestname = $contestdetails[0]['contest_name'];
     $contestimage = $contestdetails[0]['themephoto'];
     //$userid = Input::get('user_id');
     if ($invite_type == 'All') {
         $invitedlis = invitefollowerforcontestModel::where('contest_id', $contest_id)->lists('follower_id');
         $invitedcnt = count($invitedlis);
         if ($invitedcnt) {
             $uninvitedfollower = followModel::where('userid', Input::get('user_id'))->whereNotIn('id', $invitedlis)->lists('id');
         } else {
             $uninvitedfollower = followModel::where('userid', Input::get('user_id'))->lists('id');
         }
         if (count($uninvitedfollower)) {
             for ($i = 0; $i < count($uninvitedfollower); $i++) {
                 $inpudetails['follower_id'] = $uninvitedfollower[$i];
                 invitefollowerforcontestModel::create($inpudetails);
                 /******** Here want to set the Notification for Group Members *********/
                 //return $uninvitedfollower[$i];
                 //$folloerdetails = followModel::select('user.firstname','user.lastname','user.username','user.ID as follower_user_id','user.gcm_id','user.email','user.device_type')->LeftJoin('user','user.ID','=','followers.followerid')->where('followers.id',$uninvitedfollower[$i])->get();
                 $folloerdetails = ProfileModel::where('ID', $followerid)->get();
                 $gcmid = $folloerdetails[0]['gcm_id'];
                 $device_type = $folloerdetails[0]['device_type'];
                 $email = $folloerdetails[0]['email'];
                 if ($folloerdetails[0]['firstname'] != '') {
                     $name = $folloerdetails[0]['firstname'] . ' ' . $folloerdetails[0]['lastname'];
                 } else {
                     $name = $folloerdetails[0]['username'];
                 }
                 if ($contestdetails[0]['visibility'] == 'p') {
                     $privat_user['user_id'] = $folloerdetails[0]['follower_user_id'];
                     $privat_user['contest_id'] = $contest_id;
                     $privat_user['requesteddate'] = date('Y-m-d H:i:s');
                     $privat_user['status'] = 1;
                     $privatecontestcnt = privateusercontestModel::where('user_id', $folloerdetails[0]['follower_user_id'])->where('contest_id', $contest_id)->get()->count();
                     if ($privatecontestcnt == 0) {
                         privateusercontestModel::create($privat_user);
                     }
                 }
                 if ($gcmid != '' && $device_type == 'A') {
                     $Message['user_id'] = $folloerdetails[0]['follower_user_id'];
                     $Message['title'] = 'Ding Datt';
                     $Message['message'] = 'You are invited for the Contest :' . $contestdetails[0]['contest_name'];
                     $Message['contest_id'] = $contest_id;
                     $Message = array("notification" => $Message);
                     $DeviceId = array($gcmid);
                     $Message = array("notification" => $Message);
                     $this->PushNotification($DeviceId, $Message);
                 } else {
                     if ($gcmid != '' && $device_type == 'I') {
                         $DeviceId = $gcmid;
                         $Message = $folloerdetails[0]['follower_user_id'] . '*You are invited for the Contest :' . $contestname;
                         $Message = str_replace(" ", "_", $Message);
                         $this->PushNotificationIos($DeviceId, $Message);
                     } else {
                         //$contestcreatedby= User::find($contestdetails[0]['createdby']);
                         $this->invitefollowerforcontestmail($name, $email, $contestcreatedby, $contesttype, $contestname, $contest_id, $conteststartdate, $contestenddate, $contestimage);
                     }
                 }
             }
             $Response = array('success' => '1', 'message' => 'Invited Successfully', 'msgcode' => "c166");
             $final = array("response" => $Response);
             return json_encode($final);
         } else {
             $Response = array('success' => '0', 'message' => 'Already Invited All Followers', 'msgcode' => "171");
             $final = array("response" => $Response);
             return json_encode($final);
         }
     } else {
         $ok = 0;
         $user_id = Input::get('user_id');
         $follower_id = Input::get('follower_id');
         $inpudetails['follower_id'] = $follower_id;
         /*$invitefollowcnt = invitefollowerforcontestModel::where('follower_id',$follower_id)->where('contest_id',$contest_id)->get()->count();
         	 if($invitefollowcnt==0)
         	 {*/
         invitefollowerforcontestModel::create($inpudetails);
         $ok = 1;
         /******** Here want to set the Notification for Group Members *********/
         $groupmemberlist = followModel::select('id')->where('userid', $follower_id)->where('followerid', $user_id)->get();
         //return $groupmemberlist[0]['id'];
         ///
         /*$folloerdetails = followModel::select('user.firstname','user.lastname','user.username','user.ID as follower_user_id','user.gcm_id','user.email')->LeftJoin('user','user.ID','=','followers.followerid')->where('followers.id',$groupmemberlist[0]['id'])->get();
         		
         		if($folloerdetails[0]['firstname']!=''){ $name =$folloerdetails[0]['firstname'].' '.$folloerdetails[0]['lastname']; }else{ $name =$folloerdetails[0]['username'];} 
         		
         		  $gcmid = $folloerdetails[0]['gcm_id'];
         		  $email = $folloerdetails[0]['email']; */
         $user = ProfileModel::where('ID', $follower_id)->first();
         if ($user['firstname'] != '') {
             $name = $user['firstname'] . ' ' . $user['lastname'];
         } else {
             $name = $user['username'];
         }
         $email = $user['email'];
         $gcmid = $user['gcm_id'];
         $device_type = $user['device_type'];
         if ($contestdetails[0]['visibility'] == 'p') {
             $privat_user['user_id'] = $follower_id;
             $privat_user['contest_id'] = $contest_id;
             $privat_user['requesteddate'] = date('Y-m-d H:i:s');
             $privat_user['status'] = 1;
             $privatecontestcnt = privateusercontestModel::where('user_id', $follower_id)->where('contest_id', $contest_id)->get()->count();
             if ($privatecontestcnt == 0) {
                 privateusercontestModel::create($privat_user);
             }
         }
         if ($gcmid != '' && $device_type == 'A') {
             $Message['user_id'] = $follower_id;
             $Message['title'] = 'Ding Datt';
             $Message['message'] = 'You are invited for the Contest :' . $contestdetails[0]['contest_name'];
             $Message['contest_id'] = $contest_id;
             $Message = array("notification" => $Message);
             $DeviceId = array($gcmid);
             $Message = array("notification" => $Message);
             $this->PushNotification($DeviceId, $Message);
         } else {
             if ($gcmid != '' && $device_type == 'I') {
                 $DeviceId = $gcmid;
                 $Message = $follower_id . '*You are invited for the Contest :' . $contestname;
                 $Message = str_replace(" ", "_", $Message);
                 $this->PushNotificationIos($DeviceId, $Message);
             } else {
                 //$contestcreatedby= User::find($contestdetails[0]['createdby']);
                 $this->invitefollowerforcontestmail($name, $email, $contestcreatedby, $contesttype, $contestname, $contest_id, $conteststartdate, $contestenddate, $contestimage);
             }
         }
         //}else{$ok=2;}
         ////
         if ($ok == 1) {
             $Response = array('success' => '1', 'message' => 'Invited Successfully', 'msgcode' => "c166");
             $final = array("response" => $Response);
             return json_encode($final);
         } else {
             if ($ok == 2) {
                 $Response = array('success' => '0', 'message' => 'Already Invited this Followers', 'msgcode' => "171");
                 $final = array("response" => $Response);
                 return json_encode($final);
             }
         }
     }
 }
Esempio n. 2
0
 public function inviteall_follower()
 {
     $follower_ids = Input::get("follower_list");
     $contest_id = Input::get("contest_id");
     $follower_ids = explode(',', $follower_ids);
     $followercount = count($follower_ids);
     $curdate = date('Y-m-d H:i:s');
     $contest_det = contestModel::where("ID", $contest_id)->first();
     if (Auth::user()->firstname != '') {
         $inviter = Auth::user()->firstname . " " . Auth::user()->lastname;
     } else {
         $inviter = Auth::user()->username;
     }
     if ($contest_det['contesttype'] == "p") {
         $contesttype = "Photo";
     } else {
         if ($contest_det['contesttype'] == "v") {
             $contesttype = "Video";
         } else {
             if ($contest_det['contesttype'] == "t") {
                 $contesttype = "Topic";
             }
         }
     }
     $contestname = $contest_det['contest_name'];
     if ($followercount > 0) {
         for ($i = 0; $i < $followercount; $i++) {
             $invited = invitefollowerforcontestModel::where('follower_id', $follower_ids[$i])->where('contest_id', $contest_id)->count();
             if ($invited == 0) {
                 $input_details['follower_id'] = $follower_ids[$i];
                 $input_details['contest_id'] = $contest_id;
                 $input_details['invitedate'] = $curdate;
                 invitefollowerforcontestModel::create($input_details);
                 $invited_member = privateusercontestModel::where("contest_id", $contest_id)->where('user_id', $follower_ids[$i])->count();
                 if ($contest_det['visibility'] == "p" && $invited_member == 0) {
                     $privat_user['user_id'] = $follower_ids[$i];
                     $privat_user['contest_id'] = $contest_id;
                     $privat_user['requesteddate'] = date('Y-m-d H:i:s');
                     $privat_user['status'] = 1;
                     privateusercontestModel::create($privat_user);
                 }
                 if ($invited_member == 0) {
                     $user = ProfileModel::where('ID', $followerid)->first();
                     if ($user['firstname'] != '') {
                         $name = $user['firstname'] . ' ' . $user['lastname'];
                     } else {
                         $name = $user['username'];
                     }
                     $email = $user['email'];
                     $this->invitefollowerforcontestmail($name, $email, $inviter, $contesttype, $contestname, $contest_id);
                 }
             }
         }
         return 1;
     } else {
         return 0;
     }
 }
    public function invitefollowesforcontest()
    {
        //invitefollowerforcontestModel
        $invite_type = Input::get('invite_type');
        $contest_id = Input::get('contest_id');
        $curdate = date('Y-m-d h:i:s');
        $inpudetails['contest_id'] = $contest_id;
        $inpudetails['invitedate'] = $curdate;
        $contestdetails = contestModel::select('contest.createdby', 'contest.visibility', 'contest.contest_name', 'contest.contesttype', 'user.firstname', 'user.lastname', 'user.username')->LeftJoin('user', 'user.ID', '=', 'contest.createdby')->where('contest.ID', $contest_id)->get();
        $userid = $contestdetails[0]['createdby'];
        if ($contestdetails[0]['firstname'] != '') {
            $contestcreatedby = $contestdetails[0]['firstname'] . ' ' . $contestdetails[0]['lastname'];
        } else {
            $contestcreatedby = $contestdetails[0]['username'];
        }
        $contesttype = $contestdetails[0]['contesttype'];
        if ($contesttype == 'p') {
            $contesttype = "Photo";
        } else {
            if ($contesttype == 'v') {
                $contesttype = "Video";
            } else {
                if ($contesttype == 't') {
                    $contesttype = "Topic";
                }
            }
        }
        $contestname = $contestdetails[0]['contest_name'];
        //$userid = Input::get('user_id');
        if ($invite_type == 'All') {
            $invitedlis = invitefollowerforcontestModel::where('contest_id', $contest_id)->lists('follower_id');
            $invitedcnt = count($invitedlis);
            if ($invitedcnt) {
                $uninvitedfollower = followModel::where('userid', Input::get('user_id'))->whereNotIn('id', $invitedlis)->lists('id');
            } else {
                $uninvitedfollower = followModel::where('userid', Input::get('user_id'))->lists('id');
            }
            if (count($uninvitedfollower)) {
                for ($i = 0; $i < count($uninvitedfollower); $i++) {
                    $inpudetails['follower_id'] = $uninvitedfollower[$i];
                    invitefollowerforcontestModel::create($inpudetails);
                    /******** Here want to set the Notification for Group Members *********/
                    //return $uninvitedfollower[$i];
                    $folloerdetails = followModel::select('user.firstname', 'user.lastname', 'user.username', 'user.ID as follower_user_id', 'user.gcm_id', 'user.email')->LeftJoin('user', 'user.ID', '=', 'followers.followerid')->where('followers.id', $uninvitedfollower[$i])->get();
                    $gcmid = $folloerdetails[0]['gcm_id'];
                    $email = $folloerdetails[0]['email'];
                    if ($contestdetails[0]['visibility'] == 'p') {
                        $privat_user['user_id'] = $folloerdetails[0]['follower_user_id'];
                        $privat_user['contest_id'] = $contest_id;
                        $privat_user['requesteddate'] = date('Y-m-d H:i:s');
                        $privat_user['status'] = 1;
                        $privatecontestcnt = privateusercontestModel::where('user_id', $folloerdetails[0]['follower_user_id'])->where('contest_id', $contest_id)->get()->count();
                        if ($privatecontestcnt == 0) {
                            privateusercontestModel::create($privat_user);
                        }
                    }
                    if ($gcmid != '') {
                        $Message['user_id'] = $folloerdetails[0]['follower_user_id'];
                        $Message['title'] = 'Ding Datt';
                        $Message['message'] = 'You are invited for the Contest :' . $contestdetails[0]['contest_name'];
                        $Message['contest_id'] = $contest_id;
                        $Message = array("notification" => $Message);
                        $DeviceId = array($gcmid);
                        $Message = array("notification" => $Message);
                        $this->PushNotification($DeviceId, $Message);
                    } else {
                        //$contestcreatedby= User::find($contestdetails[0]['createdby']);
                        Mail::send([], array('email' => $email, 'contestcreatedby' => $contestcreatedby, 'contesttype' => $contesttype, 'contestname' => $contestname, 'contest_id' => $contest_id), function ($message) use($email, $contestcreatedby, $contesttype, $contestname, $contest_id) {
                            $mail_body = '<body style="padding:0px;margin:-20px 0 0 0px; font-family: Arial, Helvetica, sans-serif; color: #222222; font-size:12px;">
						<div style="width:550px;height:auto; border:1px solid #d5d5d5;padding:0px;margin:0px;overflow:hidden;">
						
						<div style="display:block; margin:25px; overflow:hidden;">
						<div style="display:block; padding: 10px; border: 1px solid #e5e5e5; margin:10px 0px;">
							<span style="padding:0px;margin:0px;font-weight:bold;">Invitation for join the contest.</span>
						</div>
						<div style="display: block; margin: 15px;">
							 <h4 style="padding:0px;margin:0; font-size:14px;color:#d33030;">Contest Details:</h4>
						</div>
						<p style="margin:15px;"><span style="font-weight:bold; width:150px; float:left; display:inline-block;"> Contest Name:</span>' . $contestname . '</p>
						<p style="margin:15px;"><span style="font-weight:bold; width:150px; float:left; display:inline-block;">Contest Type:</span>' . $contesttype . '</p>
						<p style="margin:15px;"><span style="font-weight:bold; width:150px; float:left; display:inline-block;">Created by:</span>' . $contestcreatedby . '</p>
						<p style="margin-top:25px; font-size:11px; color: #999999; margin-left:15px;">This is auto generate email so please do not reply to this email.</p>
						<p style="margin-top:25px; font-size:11px; color: #999999; margin-left:15px;"><a href="' . URL::to('contest_info/' . $contest_id) . '" style="dislay:block;outline: none; padding:25px;margin:25px; min-height:110px; width:100%; overflow:hidden;">' . URL::to('contest_info/' . $contest_id) . '</a> </p>
						<div style="padding:0; margin:15px;">
						<p style="padding:0px; font-weight: bold;">Thanks,</p>
						DingDatt</div>
						<a href="' . URL::to('contest_info/' . $contest_id) . '" style="dislay:block;outline: none; padding:25px;margin:25px; min-height:110px; width:100%; overflow:hidden;">
						<img src="' . URL::to('assets/inner/img/DingDatt_logo_web1.png') . '" width="110" height="86" style="width:110px; padding:0px; margin:0px;" alt="DingDatt"/>
						</a>
						</div>
						<div style="height:25px; width:100%;">&nbsp;</div>
						</div>
						</body>';
                            $message->setBody($mail_body, 'text/html');
                            $message->to($email);
                            $message->subject('Dingdatt-Invitation for join the contest');
                        });
                    }
                }
                $Response = array('success' => '1', 'message' => 'Invited Successfully');
                $final = array("response" => $Response);
                return json_encode($final);
            } else {
                $Response = array('success' => '0', 'message' => 'Already Invited All Followers');
                $final = array("response" => $Response);
                return json_encode($final);
            }
        } else {
            $user_id = Input::get('user_id');
            $follower_id = Input::get('follower_id');
            $inpudetails['follower_id'] = $follower_id;
            invitefollowerforcontestModel::create($inpudetails);
            /******** Here want to set the Notification for Group Members *********/
            $groupmemberlist = followModel::select('id')->where('userid', $user_id)->where('followerid', $follower_id)->get();
            //return $groupmemberlist[0]['id'];
            ///
            $folloerdetails = followModel::select('user.firstname', 'user.lastname', 'user.username', 'user.ID as follower_user_id', 'user.gcm_id', 'user.email')->LeftJoin('user', 'user.ID', '=', 'followers.followerid')->where('followers.id', $groupmemberlist[0]['id'])->get();
            $gcmid = $folloerdetails[0]['gcm_id'];
            $email = $folloerdetails[0]['email'];
            if ($contestdetails[0]['visibility'] == 'p') {
                $privat_user['user_id'] = $folloerdetails[0]['follower_user_id'];
                $privat_user['contest_id'] = $contest_id;
                $privat_user['requesteddate'] = date('Y-m-d H:i:s');
                $privat_user['status'] = 1;
                $privatecontestcnt = privateusercontestModel::where('user_id', $folloerdetails[0]['follower_user_id'])->where('contest_id', $contest_id)->get()->count();
                if ($privatecontestcnt == 0) {
                    privateusercontestModel::create($privat_user);
                }
            }
            if ($gcmid != '') {
                $Message['user_id'] = $folloerdetails[0]['follower_user_id'];
                $Message['title'] = 'Ding Datt';
                $Message['message'] = 'You are invited for the Contest :' . $contestdetails[0]['contest_name'];
                $Message['contest_id'] = $contest_id;
                $Message = array("notification" => $Message);
                $DeviceId = array($gcmid);
                $Message = array("notification" => $Message);
                $this->PushNotification($DeviceId, $Message);
            } else {
                //$contestcreatedby= User::find($contestdetails[0]['createdby']);
                Mail::send([], array('email' => $email, 'contestcreatedby' => $contestcreatedby, 'contesttype' => $contesttype, 'contestname' => $contestname, 'contest_id' => $contest_id), function ($message) use($email, $contestcreatedby, $contesttype, $contestname, $contest_id) {
                    $mail_body = '<body style="padding:0px;margin:-20px 0 0 0px; font-family: Arial, Helvetica, sans-serif; color: #222222; font-size:12px;">
						<div style="width:550px;height:auto; border:1px solid #d5d5d5;padding:0px;margin:0px;overflow:hidden;">
						
						<div style="display:block; margin:25px; overflow:hidden;">
						<div style="display:block; padding: 10px; border: 1px solid #e5e5e5; margin:10px 0px;">
							<span style="padding:0px;margin:0px;font-weight:bold;">Invitation for join the contest.</span>
						</div>
						<div style="display: block; margin: 15px;">
							 <h4 style="padding:0px;margin:0; font-size:14px;color:#d33030;">Contest Details:</h4>
						</div>
						<p style="margin:15px;"><span style="font-weight:bold; width:150px; float:left; display:inline-block;"> Contest Name:</span>' . $contestname . '</p>
						<p style="margin:15px;"><span style="font-weight:bold; width:150px; float:left; display:inline-block;">Contest Type:</span>' . $contesttype . '</p>
						<p style="margin:15px;"><span style="font-weight:bold; width:150px; float:left; display:inline-block;">Created by:</span>' . $contestcreatedby . '</p>
						<p style="margin-top:25px; font-size:11px; color: #999999; margin-left:15px;">This is auto generate email so please do not reply to this email.</p>
						<p style="margin-top:25px; font-size:11px; color: #999999; margin-left:15px;"><a href="' . URL::to('contest_info/' . $contest_id) . '" style="dislay:block;outline: none; padding:25px;margin:25px; min-height:110px; width:100%; overflow:hidden;">' . URL::to('contest_info/' . $contest_id) . '</a> </p>
						<div style="padding:0; margin:15px;">
						<p style="padding:0px; font-weight: bold;">Thanks,</p>
						DingDatt</div>
						<a href="' . URL::to('contest_info/' . $contest_id) . '" style="dislay:block;outline: none; padding:25px;margin:25px; min-height:110px; width:100%; overflow:hidden;">
						<img src="' . URL::to('assets/inner/img/DingDatt_logo_web1.png') . '" width="110" height="86" style="width:110px; padding:0px; margin:0px;" alt="DingDatt"/>
						</a>
						</div>
						<div style="height:25px; width:100%;">&nbsp;</div>
						</div>
						</body>';
                    $message->setBody($mail_body, 'text/html');
                    $message->to($email);
                    $message->subject('Dingdatt-Invitation for join the contest');
                });
            }
            ////
            $Response = array('success' => '1', 'message' => 'Invited Successfully');
            $final = array("response" => $Response);
            return json_encode($final);
        }
    }