public function invitegroupmemberforcontest() { $groupmemberlist = Input::get('groupmemberid'); $groupid = Input::get('group_id'); $contest_id = Input::get('contest_id'); $groupmemberlistid = explode(',', $groupmemberlist); $curdate = date('Y-m-d H:i:s'); /// Contest Details ///////////// $contest_det = contestModel::where("ID", $contest_id)->first(); if ($contest_det->firstname != '') { $inviter = $contest_det->firstname . " " . $contest_det->lastname; } else { $inviter = $contest_det->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; $contestimage = $contest_det->themephoto; $conteststartdate = $contest_det->conteststartdate; $contestenddate = $contest_det->contestenddate; $contestcreatedby = User::find($contest_det->createdby); if ($contestcreatedby['firstname'] != '') { $contestcreatedby = $contestcreatedby['firstname'] . '' . $contestcreatedby['lastname']; } else { $contestcreatedby = $contestcreatedby['username']; } $groupdetails = groupModel::where('ID', $groupid)->first(); $groupname = $groupdetails['groupname']; $inv_suc_message = 0; for ($i = 0; $i < count($groupmemberlistid); $i++) { $groupmemberid = groupmemberModel::where('id', $groupmemberlistid[$i])->first(); $invited = invitegroupforcontestModel::where('group_id', $groupid)->where('contest_id', $contest_id)->where('user_id', $groupmemberid->user_id)->count(); if ($invited == 0) { $invited_member = privateusercontestModel::where("contest_id", $contest_id)->where('user_id', $groupmemberid['user_id'])->count(); if ($contest_det->visibility == "p" && $invited_member == 0) { $privat_user['user_id'] = $groupmemberid['user_id']; $privat_user['contest_id'] = $contest_id; $privat_user['requesteddate'] = date('Y-m-d H:i:s'); $privat_user['status'] = 1; privateusercontestModel::create($privat_user); unset($privat_user); } if ($invited_member == 0) { $input_details['group_id'] = $groupid; $input_details['contest_id'] = $contest_id; $input_details['invitedetail'] = 1; $input_details['inviteddate'] = $curdate; $input_details['user_id'] = $groupmemberid['user_id']; invitegroupforcontestModel::create($input_details); $user = ProfileModel::where('ID', $groupmemberid['user_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 ($gcmid != '' && $device_type == 'A') { $Message['user_id'] = $groupmemberid['user_id']; $Message['title'] = 'Ding Datt'; $Message['message'] = 'You are invited for the Contest :' . $contestname; $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 = $groupmemberid['user_id'] . '*You are invited for the Contest :' . $contestname; $Message = str_replace(" ", "_", $Message); $this->PushNotificationIos($DeviceId, $Message); } else { $this->invitegroupmemberforcontestmail($email, $contestcreatedby, $contesttype, $contestname, $contest_id, $groupname, $contestimage, $conteststartdate, $contestenddate); } } //// //$inv_suc_message = 'Invitation sent successfully.'; $inv_suc_message = 1; } } } if ($inv_suc_message == 1) { $Response = array('success' => '1', 'message' => 'Invited Successfully', 'msgcode' => "c166"); $final = array("response" => $Response); return json_encode($final); } else { $Response = array('success' => '0', 'message' => 'No members to invite', 'msgcode' => "c167"); $final = array("response" => $Response); return json_encode($final); } }
public function inviteall_group() { $group_ids = Input::get("group_list"); $contest_id = Input::get("contest_id"); $group_ids = explode(',', $group_ids); $groupcount = count($group_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']; $inv_suc_message = ''; if ($groupcount > 0) { for ($i = 0; $i < $groupcount; $i++) { $group_members = groupmemberModel::where("group_id", $group_ids[$i])->get(); for ($j = 0; $j < count($group_members); $j++) { $invited = invitegroupforcontestModel::where('group_id', $group_ids[$i])->where('contest_id', $contest_id)->where('user_id', $group_members[$j]['user_id'])->count(); if ($invited == 0) { $invited_member = privateusercontestModel::where("contest_id", $contest_id)->where('user_id', $group_members[$j]['user_id'])->count(); if ($contest_det['contesttype'] == "p" && $invited_member == 0) { $privat_user['user_id'] = $group_members[$j]['user_id']; $privat_user['contest_id'] = $contest_id; $privat_user['requesteddate'] = date('Y-m-d H:i:s'); $privat_user['status'] = 1; privateusercontestModel::create($privat_user); unset($privat_user); } // Email Notification for invitation if ($invited_member == 0) { $user = ProfileModel::where('ID', $group_members[$j]['user_id'])->first(); if ($user['firstname'] != '') { $name = $user['firstname'] . ' ' . $user['lastname']; } else { $name = $user['username']; } $email = $user['email']; Mail::send([], array('name' => $name, 'email' => $email, 'inviter' => $inviter, 'contesttype' => $contesttype, 'contestname' => $contestname), function ($message) use($name, $email, $inviter, $contesttype, $contestname) { $mail_body = '<body style="padding:0px;margin: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="dislay:block;padding:25px;margin:0px; text-align:center; min-height:50px;"> <div style="height:15px; width:100%; margin:0px;"> </div> <a href="' . URL::to('assets/inner/img/DingDatt_logo_web1.png') . '" 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 style="height:15px; width:100%; padding:0px;"> </div> </div> <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>' . $inviter . '</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> <div style="padding:0; margin:15px;"> <p style="padding:0px; font-weight: bold;">Thanks,</p> DingDatt</div> </div> <div style="height:25px; width:100%;"> </div> </div> </body>'; $mail_body = str_replace("{name}", $name, $mail_body); $mail_body = str_replace("{inviter}", $inviter, $mail_body); $mail_body = str_replace("{contesttype}", $contesttype, $mail_body); $mail_body = str_replace("{contestname}", $contestname, $mail_body); $message->setBody($mail_body, 'text/html'); $message->to($email); $message->subject('Dingdatt-Invitation for join the contest'); }); } //-------------------------- $input_details['group_id'] = $group_ids[$i]; $input_details['contest_id'] = $contest_id; $input_details['invitedetail'] = 1; $input_details['inviteddate'] = $curdate; $input_details['user_id'] = $group_members[$j]['user_id']; $added = invitegroupforcontestModel::create($input_details); unset($input_details); if ($added) { $inv_suc_message = 'Invitation sent successfully.'; } } } } return 1; } else { return 0; } }
public function invitegroupsforcontest() { //invitegroupsforcontest $inpudetails['invitedetail'] = 1; $inpudetails['group_id'] = Input::get('group_id'); $inpudetails['contest_id'] = Input::get('contest_id'); $curdate = date('Y-m-d h:i:s'); $inpudetails['inviteddate'] = $curdate; $invite_type = Input::get('invite_type'); /////// Contest info ///// //Input::get('contest_id'); $contestinfo = contestModel::select('contest_name', 'contesttype', 'createdby', 'visibility')->where('ID', Input::get('contest_id'))->get(); $contestname = $contestinfo[0]['contest_name']; $contesttype = $contestinfo[0]['contesttype']; //return $contestinfo[0]['visibility']; if ($contesttype == 'p') { $contesttype = "Photo"; } else { if ($contesttype == 'v') { $contesttype = "Video"; } else { if ($contesttype == 't') { $contesttype = "Topic"; } } } //return $contestinfo[0]['createdby']; $contest_id = Input::get('contest_id'); $contestcreatedby = User::find($contestinfo[0]['createdby']); if ($contestcreatedby['firstname'] != '') { $contestcreatedby = $contestcreatedby['firstname'] . '' . $contestcreatedby['lastname']; } else { $contestcreatedby = $contestcreatedby['username']; } if ($invite_type == 'All') { $invitedlis = invitegroupforcontestModel::where('contest_id', $inpudetails['contest_id'])->lists('group_id'); $invitedcnt = count($invitedlis); if ($invitedcnt) { //$uninvitedgroup = groupModel::whereNotIn('id', $invitedlis)->lists('id'); $uninvitedgroup = groupmemberModel::select('group.id')->leftJoin('group', 'group.ID', '=', 'group_members.group_id')->LeftJoin('user', 'user.ID', '=', 'group.createdby')->where('group_members.user_id', Input::get('user_id'))->whereNotIn('group.id', $invitedlis)->get()->toArray(); } else { //$uninvitedgroup =groupModel::lists('id'); $uninvitedgroup = groupmemberModel::select('group.id')->leftJoin('group', 'group.ID', '=', 'group_members.group_id')->LeftJoin('user', 'user.ID', '=', 'group.createdby')->where('group_members.user_id', Input::get('user_id'))->get()->toArray(); } if (count($uninvitedgroup)) { for ($i = 0; $i < count($uninvitedgroup); $i++) { $inpudetails['group_id'] = $uninvitedgroup[$i]['id']; if ($uninvitedgroup[$i]['id'] != '') { $groupowner = groupModel::select('user.firstname', 'user.lastname', 'user.username', 'group.grouptype', 'group.groupname')->where('group.ID', $uninvitedgroup[$i]['id'])->LeftJoin('user', 'user.ID', '=', 'group.createdby')->get(); if ($groupowner[0]['firstname'] != '') { $inviter = $groupowner[0]['firstname'] . " " . $groupowner[0]['lastname']; } else { $inviter = $groupowner[0]['username']; } } invitegroupforcontestModel::create($inpudetails); $groupname = $groupowner[0]['groupname']; /******** Here want to set the Notification for Group Members ***/ $groupmemberlist = groupmemberModel::where('group_id', $uninvitedgroup[$i]['id'])->lists('user_id'); for ($j = 0; $j < count($groupmemberlist); $j++) { //////Notification//////////////////// if ($contestinfo[0]['createdby'] != $groupmemberlist[$j]) { $user_id = User::find($groupmemberlist[$j]); $gcmid = $user_id['gcm_id']; $email = $user_id['email']; if ($contestinfo[0]['visibility'] == 'p') { $privat_user['user_id'] = $groupmemberlist[$j]; $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', $groupmemberlist[$j])->where('contest_id', $contest_id)->get()->count(); if ($privatecontestcnt == 0) { privateusercontestModel::create($privat_user); } } /////// if ($gcmid != '') { $Message['user_id'] = $groupmemberlist[$j]; $Message['title'] = 'Ding Datt'; $Message['message'] = 'You are invited for the Contest :' . $contestname; $Message['contest_id'] = $inpudetails['contest_id']; $Message = array("notification" => $Message); $DeviceId = array($gcmid); $Message = array("notification" => $Message); $this->PushNotification($DeviceId, $Message); } else { $email = $user_id['email']; Mail::send([], array('email' => $email, 'contestcreatedby' => $contestcreatedby, 'contesttype' => $contesttype, 'contestname' => $contestname, 'contest_id' => $contest_id, '$groupname' => $groupname), function ($message) use($email, $contestcreatedby, $contesttype, $contestname, $contest_id, $groupname) { $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:15px;"><span style="font-weight:bold; width:150px; float:left; display:inline-block;">Group Name by:</span>' . $groupname . '</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%;"> </div> </div> </body>'; $message->setBody($mail_body, 'text/html'); $message->to($email); $message->subject('Dingdatt-Invitation for join the contest'); }); } } //////Notification End ////////////// } } $Response = array('success' => '1', 'message' => 'Invited Successfully'); $final = array("response" => $Response); return json_encode($final); } else { $Response = array('success' => '0', 'message' => 'Already Invited these Groups'); $final = array("response" => $Response); return json_encode($final); } } else { $validator = Validator::make($inpudetails, invitegroupforcontestModel::$rules); if ($validator->passes()) { $invite = invitegroupforcontestModel::create($inpudetails); $inpudetails['group_id'] = Input::get('group_id'); if (Input::get('group_id') != '') { $groupowner = groupModel::select('user.firstname', 'user.lastname', 'user.username', 'group.grouptype', 'group.groupname')->where('group.ID', Input::get('group_id'))->LeftJoin('user', 'user.ID', '=', 'group.createdby')->get(); if ($groupowner[0]['firstname'] != '') { $inviter = $groupowner[0]['firstname'] . " " . $groupowner[0]['lastname']; } else { $inviter = $groupowner[0]['username']; } } //invitegroupforcontestModel::create($inpudetails); /******** Here want to set the Notification for Group Members ***/ $groupname = $groupowner[0]['groupname']; $groupmemberlist = groupmemberModel::where('group_id', Input::get('group_id'))->lists('user_id'); //return $contestinfo[0]['createdby']; //return $groupmemberlist[0]; $temp = array(); for ($j = 0; $j < count($groupmemberlist); $j++) { //////Notification//////////////////// //return (int)$groupmemberlist[$j].'s'.$contestinfo[0]['createdby'].'ad'; $groupid1 = (int) $groupmemberlist[$j]; $contstcreated = (int) $contestinfo[0]['createdby']; $temp[$j] = "no"; if ($groupid1 != $contstcreated) { $temp[$j] = "yes"; //return "ABdgdfgdf"; $user_id = User::find($groupmemberlist[$j]); $gcmid = $user_id['gcm_id']; $email = $user_id['email']; if ($contestinfo[0]['visibility'] == 'p') { $privat_user['user_id'] = $groupmemberlist[$j]; $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', $groupmemberlist[$j])->where('contest_id', $contest_id)->get()->count(); if ($privatecontestcnt == 0) { privateusercontestModel::create($privat_user); } } if ($gcmid != '') { $Message['user_id'] = $groupmemberlist[$j]; $Message['title'] = 'Ding Datt'; $Message['message'] = 'You are invited for the Contest :' . $contestname; $Message['contest_id'] = $inpudetails['contest_id']; $Message = array("notification" => $Message); $DeviceId = array($gcmid); $Message = array("notification" => $Message); $this->PushNotification($DeviceId, $Message); } else { $email = $user_id['email']; Mail::send([], array('email' => $email, 'contestcreatedby' => $contestcreatedby, 'contesttype' => $contesttype, 'contestname' => $contestname, 'contest_id' => $contest_id, 'groupname' => $groupname), function ($message) use($email, $contestcreatedby, $contesttype, $contestname, $contest_id, $groupname) { $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:15px;"><span style="font-weight:bold; width:150px; float:left; display:inline-block;">Group Name by:</span>' . $groupname . '</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%;"> </div> </div> </body>'; $message->setBody($mail_body, 'text/html'); $message->to($email); $message->subject('Dingdatt-Invitation for join the contest'); }); } } //////Notification End ////////////// } //return $temp; ////// $Response = array('success' => '1', 'message' => 'You are Invited That group Successfully'); $final = array("response" => $Response); return json_encode($final); } else { $Response = array('success' => '0', 'message' => 'Required Details are Missing'); $final = array("response" => $Response); return json_encode($final); } } }