Esempio n. 1
0
 public function creategroupinweb()
 {
     $userid = Auth::user()->ID;
     $curdate = date('Y-m-d h:i:s');
     $inputdetails['groupname'] = Input::get('groupname');
     $inputdetails['createdby'] = $userid;
     $inputdetails['createddate'] = $curdate;
     $inputdetails['grouptype'] = Input::get('grouptype');
     $inputdetails['status'] = 1;
     if (Input::file('groupimage')) {
         $inputdetails['groupimage'] = Input::file('groupimage');
         $destinationPath = 'public/assets/upload/group';
         $filename = Input::file('groupimage')->getClientOriginalName();
         $Image = str_random(8) . '_' . $filename;
         $inputdetails['groupimage'] = $Image;
     }
     $lantyp = Session::get('language');
     if ($lantyp == "") {
         $lantyp = "value_en";
     }
     $validation = Validator::make($inputdetails, groupModel::$rules);
     if ($validation->passes()) {
         if (Input::file('groupimage')) {
             $file = Input::file('groupimage');
             $uploadSuccess = $file->move($destinationPath, $Image);
         }
         $savegroup = groupModel::create($inputdetails);
         $group_id = groupModel::max('id');
         //// Group Owner add in the group member table////
         $inputgroupmember['group_id'] = $group_id;
         $inputgroupmember['user_id'] = $userid;
         $inputgroupmember['createddate'] = $curdate;
         $groupmember = groupmemberModel::create($inputgroupmember);
         ///if Followers or following checked And the group Private //////////
         ////////////
         if ($inputdetails['grouptype'] == 'private') {
             //return Input::get('follower');
             if (Input::get('follower')) {
                 $follower = followModel::select('followerid as id')->where('userid', $userid)->get();
             }
             if (Input::get('following')) {
                 $following = followModel::select('userid as id')->where('followerid', $userid)->get();
             }
             if (Input::get('follower') || Input::get('following')) {
                 if (Input::get('follower')) {
                     for ($i = 0; $i < count($follower); $i++) {
                         $id[$i] = $follower[$i]['id'];
                     }
                 }
                 if (Input::get('following')) {
                     for ($j = 0; $j < count($following); $j++) {
                         $id1[$j] = $following[$j]['id'];
                     }
                 }
                 if (Input::get('follower') != 0 && count($follower) >= 1 && Input::get('following') != 0 && count($following) >= 1) {
                     $id = array_values(array_unique(array_merge($id, $id1)));
                 } elseif (Input::get('following') != 0 && count($following) >= 1) {
                     $id = $id1;
                 } elseif (Input::get('follower') != 0 && count($follower) >= 1) {
                     $id = $id;
                 } else {
                     $id = 0;
                 }
                 $inviteinputdetails['inviteddate'] = $curdate;
                 $inviteinputdetails['group_id'] = $group_id;
                 if ($id != 0) {
                     for ($i = 0; $i < count($id); $i++) {
                         $inviteinputdetails['user_id'] = $id[$i];
                         $inviteinputdetails['invitetype'] = 'm';
                         $invite = invitememberforgroupModel::create($inviteinputdetails);
                         if ($invite) {
                             // HERE SET THE NOTIFIATION //
                         }
                     }
                 }
             }
         }
         ///////////
         if ($savegroup) {
             $languageDetails = languageModel::select($lantyp, 'ctrlCaptionId')->whereIn('value_en', ['Group Details Added successfully'])->get()->toArray();
             foreach ($languageDetails as $key => $val) {
                 $er_data['messagesave'] = "<span id='" . $val['ctrlCaptionId'] . "'>" . $val[$lantyp] . "</span>";
             }
             return Redirect::to("group")->withInput()->with('er_data', $er_data)->with('tab', 'creategroup');
         }
     } else {
         $languageDetails = languageModel::select($lantyp, 'ctrlCaptionId')->whereIn('value_en', [$validation->messages()->first('groupname')])->get()->toArray();
         foreach ($languageDetails as $key => $val) {
             $er_data['groupname'] = "<span id='" . $val['ctrlCaptionId'] . "'>" . $val[$lantyp] . "</span>";
         }
         return Redirect::to("group")->with('er_data', $er_data)->with('tab', 'creategroup');
     }
 }
 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);
             }
         }
     }
 }
    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);
        }
    }