コード例 #1
0
 public function fire()
 {
     //fetch all users
     $getusers = DB::table('users')->select(array('users.*'))->where('users.userstatus', '=', 'approved')->orderBy('created_at', 'DESC')->get();
     //process for the records found
     if (!empty($getusers)) {
         $queryOfferHelp = array();
         foreach ($getusers as $user_info) {
             $diffDate = KarmaHelper::dateDiff(date("Y-m-d H:i:s"), $user_info->created_at);
             if ($diffDate->days > -1) {
                 $user_id = $user_info->id;
                 $location = $user_info->location;
                 /*$myKarmaDataOfInCompleteState= DB::select(DB::raw("SELECT COUNT( * ) AS AGGREGATE FROM  `users_mykarma` WHERE  `status` =  'completed' AND  `user_id` =".$user_id." AND  created_at > DATE_SUB(NOW(), INTERVAL 1 DAY)"));
                 		$myKarmaDataOfInCompleteState= DB::select(DB::raw("SELECT COUNT( * ) AS AGGREGATE FROM  `users_mykarma` WHERE  `status` !=  'completed' AND  `user_id` =".$user_id." AND  created_at > DATE_SUB(NOW(), INTERVAL 1 DAY)"));*/
                 $myKarmaDataOfCompleteState = Mykarma::where('status', '=', 'completed')->where('user_id', '=', $user_id)->where('unread_flag', '=', 'true')->where('created_at', '>=', Carbon::now()->subDay(1))->count();
                 $myKarmaDataOfInCompleteState = Mykarma::where('status', '!=', 'completed')->where('user_id', '=', $user_id)->where('entry_type', '=', 'Meeting')->where('unread_flag', '=', 'true')->where('created_at', '>=', Carbon::now()->subDay(1))->count();
                 $myKarmaDataOfQuery = Mykarma::where('user_id', '=', $user_id)->where('entry_type', '=', 'Query')->get();
                 foreach ($myKarmaDataOfQuery as $key => $value) {
                     $allQuery[] = $value->entry_id;
                 }
                 if (!empty($allQuery)) {
                     $queryOfferHelp = Mykarma::whereIn('entry_id', $allQuery)->where('users_role', '=', 'OfferedHelp')->where('unread_flag', '=', 'true')->where('created_at', '>=', Carbon::now()->subDay(1))->count();
                 }
                 // fetch user connections on KC
                 $getUserConnection = KarmaHelper::getUserConnection($user_id, $location);
                 $user_connection_onkc = 0;
                 if (!empty($getUserConnection)) {
                     foreach ($getUserConnection as $key => $value) {
                         if (isset($value->con_user_id)) {
                             $user_connection_onkc++;
                         }
                     }
                 }
                 // fetch pending karmanote requests
                 $totalPendingRequest = 0;
                 $PendingRequest = array();
                 $PendingRequest = KarmaHelper::getPendingKarmaNotes($user_info->id);
                 if (!empty($PendingRequest)) {
                     $totalPendingRequest = count($PendingRequest);
                 }
                 //fetch pending KM requests only received no read no unread
                 $totalReceivedRequest = 0;
                 $GiverInMeeting = User::find($user_info->id)->Giver()->where('status', 'pending')->orderBy('updated_at', 'DESC')->get();
                 if (!empty($GiverInMeeting)) {
                     $totalReceivedRequest = count($GiverInMeeting);
                 }
                 //fetch pending karma intros
                 $totalintroductionInitiated = 0;
                 $IntroducerInitiated = User::find($user_info->id)->Introducer;
                 if (!empty($IntroducerInitiated)) {
                     foreach ($IntroducerInitiated as $key => $value) {
                         $value['user_id_receiver'] = User::find($value['user_id_receiver'])->toArray();
                         if (!empty($value['user_id_giver'])) {
                             $value['user_id_giver'] = User::find($value['user_id_giver'])->toArray();
                         } else {
                             $value['user_id_giver'] = Connection::find($value['connection_id_giver'])->toArray();
                         }
                         if ($value->status == 'pending') {
                             $totalintroductionInitiated++;
                         }
                     }
                 }
                 // fetch queries that have been posted in the last 7 days within common groups including both public & private.
                 $Usergroup = User::find($user_info->id)->Groups;
                 $All_groups = '';
                 $group_question = 0;
                 $totagroupquestion = 0;
                 $yesterday = Carbon::now()->subDays(1);
                 $one_week_ago = Carbon::now()->subWeeks(1);
                 if (!$Usergroup->isEmpty()) {
                     foreach ($Usergroup as $key => $value) {
                         $All_groups[] = $value->id;
                     }
                     if (!empty($All_groups)) {
                         $group_question = DB::table('group_questions')->join('questions', 'group_questions.question_id', '=', 'questions.id')->select(array('questions.id'))->whereIn('group_questions.group_id', $All_groups)->where('questions.user_id', '!=', $user_info->id)->where('questions.queryStatus', '=', 'open')->where('questions.created_at', '>=', $one_week_ago)->where('questions.created_at', '<=', $yesterday)->orderBy('questions.created_at', 'DESC')->groupBy('question_id')->get();
                         if (!empty($group_question)) {
                             $totagroupquestion = count($group_question);
                         }
                     }
                 }
                 // fetch weekly suggestion option value set from admin
                 $weekly_suggestion = "KarmaNote";
                 $weekly_suggestion = Adminoption::Where("option_name", "=", "Weekly Suggestion")->select("option_value")->first();
                 if (!empty($weekly_suggestion)) {
                     $weekly_suggestion = $weekly_suggestion->option_value;
                 }
                 $getkcUser = $getsuggestion = array();
                 if ($weekly_suggestion == "KarmaMeeting") {
                     // fetch a random users on KC platform with a common group of logged in user
                     $getkcUser = KarmaHelper::fetchUserGroup($user_id);
                     if (!empty($getkcUser)) {
                         $getkcUser = $getkcUser[0];
                     }
                 } else {
                     // fetch a user connection either KC or NON KC
                     $getsuggestion = KarmaHelper::getUserConnection($user_id, $location);
                     //get test users id
                     $getUser = KarmaHelper::getTestUsers();
                     if (!empty($getsuggestion)) {
                         foreach ($getsuggestion as $key => $value) {
                             $test_match = in_array($value->con_user_id, $getUser);
                             if ($value->con_user_id != "" && $test_match != 1) {
                                 $getKc = DB::table('users as u')->select(array('u.userstatus', 'u.id', 'u.fname', 'u.lname', 'u.linkedinurl', 'u.piclink', 'u.headline', 'u.email', 'u.karmascore', 'u.location'))->where('u.id', '=', $value->con_user_id)->where('u.userstatus', '=', 'approved')->get();
                                 if (!empty($getKc)) {
                                     $value->networkid = $getKc;
                                 }
                             }
                         }
                         $getsuggestion = $getsuggestion[array_rand($getsuggestion)];
                     }
                 }
                 //fetch random 5 unique notes
                 $getKarmanote = "";
                 $getKarmanote = KarmaHelper::getKarmanote();
                 $type = 19;
                 $meetingIncomplete = $myKarmaDataOfInCompleteState;
                 $meetingComplete = $myKarmaDataOfCompleteState;
                 $offeredHelp = $queryOfferHelp;
                 $user_id = $user_id;
                 $user_connection_onkc = $user_connection_onkc;
                 $totalPendingRequest = $totalPendingRequest;
                 $totalReceivedRequest = $totalReceivedRequest;
                 $totalintroductionInitiated = $totalintroductionInitiated;
                 $totagroupquestion = $totagroupquestion;
                 $getsuggestion = $getsuggestion;
                 $getkcUser = $getkcUser;
                 $getKarmanote = $getKarmanote;
                 // call a function to send email
                 if ($meetingIncomplete > 0 || $meetingComplete > 0 || $offeredHelp > 0) {
                     $sendLinkedinMessage = MessageHelper::dailyUpdateMykarmaScreen($type, $user_id, $meetingIncomplete, $meetingComplete, $offeredHelp, $user_connection_onkc, $totalPendingRequest, $totalReceivedRequest, $totalintroductionInitiated, $totagroupquestion, $getsuggestion, $getkcUser, $getKarmanote);
                 }
                 /*Queue::push('MessageSender@MyKarmaDailyUpdateScreen',array('type' =>19,'meetingIncomplete'=>$myKarmaDataOfInCompleteState,'meetingComplete'=>$myKarmaDataOfCompleteState,'offeredHelp'=>$queryOfferHelp,'user_id' => $user_id,'user_connection_onkc'=>$user_connection_onkc,'totalPendingRequest' => $totalPendingRequest,'totalReceivedRequest'=>$totalReceivedRequest,'totalintroductionInitiated'=>$totalintroductionInitiated,'totagroupquestion'=>$totagroupquestion,'getsuggestion'=>$getsuggestion,'getkcUser'=>$getkcUser,'getKarmanote'=>$getKarmanote));*/
             }
         }
         //endforeach
     }
     // endif
     Log::alert('Executed Daily Cron Job');
 }
コード例 #2
0
 public static function saveDataInMyKarma($receiverId, $giverId, $meetingId, $meetingStatus, $connectionGiverId, $updatedDate)
 {
     $checkKarmaData = Mykarma::where('entry_id', '=', $meetingId)->count();
     if ($checkKarmaData < 1) {
         if ($receiverId != '' || $receiverId != null) {
             if ($giverId != 'null') {
                 $giverData = User::where('id', '=', $giverId)->first();
             } else {
                 $giverData = Connection::where('id', '=', $connectionGiverId)->first();
             }
             $saveDataForReceiver = new MyKarma();
             $saveDataForReceiver->user_id = $receiverId;
             $saveDataForReceiver->entry_type = 'Meeting';
             $saveDataForReceiver->entry_id = $meetingId;
             $saveDataForReceiver->users_role = 'Receiver';
             if (!empty($giverData)) {
                 $saveDataForReceiver->fname = $giverData->fname;
                 $saveDataForReceiver->lname = $giverData->lname;
                 $saveDataForReceiver->piclink = $giverData->piclink;
             } else {
                 $saveDataForReceiver->fname = 'null';
                 $saveDataForReceiver->lname = 'null';
                 $saveDataForReceiver->piclink = 'null';
             }
             $saveDataForReceiver->status = $meetingStatus;
             if ($meetingStatus == 'responded' || $meetingStatus == 'scheduled' || $meetingStatus == 'over' || $meetingStatus == 'happened') {
                 $saveDataForReceiver->unread_flag = 'true';
                 $saveDataForReceiver->no_of_unread_items = '1';
             } else {
                 $saveDataForReceiver->unread_flag = 'false';
                 $saveDataForReceiver->no_of_unread_items = '0';
             }
             $saveDataForReceiver->entry_updated_on = $updatedDate;
             $saveDataForReceiver->created_at = Carbon::now();
             $saveDataForReceiver->updated_at = Carbon::now();
             $saveDataForReceiver->save();
         }
         if ($giverId != 'null') {
             $receiverData = User::where('id', '=', $receiverId)->first();
             $saveDataForGiver = new MyKarma();
             $saveDataForGiver->user_id = $giverId;
             $saveDataForGiver->entry_type = 'Meeting';
             $saveDataForGiver->entry_id = $meetingId;
             $saveDataForGiver->users_role = 'Giver';
             if (!empty($receiverData)) {
                 $saveDataForGiver->fname = $receiverData->fname;
                 $saveDataForGiver->lname = $receiverData->lname;
                 $saveDataForGiver->piclink = $receiverData->piclink;
             } else {
                 $saveDataForGiver->fname = 'null';
                 $saveDataForGiver->lname = 'null';
                 $saveDataForGiver->piclink = 'null';
             }
             $saveDataForGiver->status = $meetingStatus;
             if ($meetingStatus == 'responded' || $meetingStatus == 'pending' || $meetingStatus == 'confirmed' || $meetingStatus == 'over') {
                 $saveDataForGiver->unread_flag = 'true';
                 $saveDataForGiver->no_of_unread_items = '1';
             } else {
                 $saveDataForGiver->unread_flag = 'false';
                 $saveDataForGiver->no_of_unread_items = '0';
             }
             $saveDataForGiver->entry_updated_on = $updatedDate;
             $saveDataForGiver->created_at = Carbon::now();
             $saveDataForGiver->updated_at = Carbon::now();
             $saveDataForGiver->save();
         } else {
             $receiverData = User::where('id', '=', $receiverId)->first();
             $saveDataForGiver = new MyKarma();
             $saveDataForGiver->user_id = '0';
             $saveDataForGiver->connection_id = $connectionGiverId;
             $saveDataForGiver->entry_type = 'Meeting';
             $saveDataForGiver->entry_id = $meetingId;
             $saveDataForGiver->users_role = 'Giver';
             if (!empty($receiverData)) {
                 $saveDataForGiver->fname = $receiverData->fname;
                 $saveDataForGiver->lname = $receiverData->lname;
                 $saveDataForGiver->piclink = $receiverData->piclink;
             } else {
                 $saveDataForGiver->fname = 'null';
                 $saveDataForGiver->lname = 'null';
                 $saveDataForGiver->piclink = 'null';
             }
             $saveDataForGiver->status = $meetingStatus;
             if ($meetingStatus == 'responded' || $meetingStatus == 'pending' || $meetingStatus == 'confirmed' || $meetingStatus == 'over') {
                 $saveDataForGiver->unread_flag = 'true';
                 $saveDataForGiver->no_of_unread_items = '1';
             } else {
                 $saveDataForGiver->unread_flag = 'false';
                 $saveDataForGiver->no_of_unread_items = '0';
             }
             $saveDataForGiver->entry_updated_on = $updatedDate;
             $saveDataForGiver->created_at = Carbon::now();
             $saveDataForGiver->updated_at = Carbon::now();
             $saveDataForGiver->save();
         }
     }
     return true;
 }
コード例 #3
0
 public function submitQueryForm()
 {
     $shareOnLinkedin = '';
     if (!empty(Input::get('shareOnLinkedin'))) {
         $shareOnLinkedin = Input::get('shareOnLinkedin');
     }
     if (!empty(Input::get('subject'))) {
         $subject = Input::get('subject');
     }
     if (!empty(Input::get('description'))) {
         $description = Input::get('description');
     }
     if (!empty(Input::get('skillTags'))) {
         $skills = Input::get('skillTags');
     }
     if (!empty(Input::get('privacysetting'))) {
         $privacysetting = Input::get('privacysetting');
     }
     if (!empty(Input::get('receiver_id'))) {
         $receiver_id = Input::get('receiver_id');
     }
     if (!empty(Input::get('user_groups'))) {
         $user_groups = Input::get('user_groups');
     }
     $url_subject = $subject;
     $url_subject = strtolower($url_subject);
     //Make alphanumeric (removes all other characters)
     $url_subject = preg_replace("/[^a-z0-9_\\s-]/", "", $url_subject);
     $url_subject = trim($url_subject);
     //Clean up multiple dashes or whitespaces
     $url_subject = preg_replace("/[\\s-]+/", " ", $url_subject);
     //Convert whitespaces and underscore to dash
     $url_subject = preg_replace("/[\\s_]/", "-", $url_subject);
     if (!empty($receiver_id)) {
         $Question = new Question();
         $Question->user_id = $receiver_id;
         $Question->subject = strip_tags($subject);
         $Question->description = strip_tags($description);
         if (!empty($skills)) {
             $Question->skills = implode(',', $skills);
         } else {
             $Question->skills = '';
         }
         $Question->access = $privacysetting;
         $Question->question_url = strtolower($url_subject);
         $Question->save();
         $questionId = $Question->id;
         $getUser = User::where('id', '=', $receiver_id)->first();
         //Add data on users_mykarma table for query
         $myKarmaDataQuery = new Mykarma();
         $myKarmaDataQuery->entry_id = $questionId;
         $myKarmaDataQuery->user_id = $receiver_id;
         $myKarmaDataQuery->fname = $getUser->fname;
         $myKarmaDataQuery->lname = $getUser->lname;
         $myKarmaDataQuery->piclink = $getUser->piclink;
         $myKarmaDataQuery->entry_type = 'Query';
         $myKarmaDataQuery->users_role = 'PostedQuery';
         $myKarmaDataQuery->status = 'Open';
         $myKarmaDataQuery->unread_flag = 'false';
         $myKarmaDataQuery->no_of_unread_items = '0';
         $myKarmaDataQuery->entry_updated_on = Carbon::now();
         $myKarmaDataQuery->save();
         $user_id_giver = 'null';
         $feedType = 'KarmaQuery';
         KarmaHelper::storeKarmacirclesfeed($user_id_giver, $receiver_id, $feedType, $questionId);
         if (!empty($user_groups)) {
             $user_groups = explode(',', $user_groups);
             foreach ($user_groups as $key => $value) {
                 $Groupquestion = new Groupquestion();
                 $Groupquestion->question_id = $Question->id;
                 $Groupquestion->group_id = $value;
                 $Groupquestion->user_id = $Question->user_id;
                 $Groupquestion->save();
             }
         }
         //echo "<pre>";print_r($_POST);echo "</pre>";die();
         if ($shareOnLinkedin == '1' && $privacysetting == 'public') {
             Queue::push('MessageSender@shareQuestionOnLinkedin', array('type' => '9', 'question_id' => $Question->id));
         }
         return Redirect::to('/karma-queries');
     }
 }
コード例 #4
0
 public function scriptForDeletingIndividualMyKarma()
 {
     $userId = 114;
     $mykarmaData = Mykarma::where('user_id', '=', $userId)->select('entry_id')->get();
     foreach ($mykarmaData as $key => $value) {
         $id = $value->entry_id;
         $deleteMykarma = Mykarma::where('entry_id', '=', $id)->delete();
     }
     echo 'success';
 }
コード例 #5
0
 public function deletequery()
 {
     $id = Input::get('queryId');
     $deleteQuestionwillingtohelp = Questionwillingtohelp::where('question_id', '=', $id)->delete();
     $deleteGroupQuestion = Groupquestion::where('question_id', '=', $id)->delete();
     $deleteQuestion = Question::where('id', '=', $id)->delete();
     $deleteKarmafeed = Karmafeed::where('id_type', '=', $id)->whereIn('message_type', array('KarmaQuery', 'OfferHelpTo'))->delete();
     $deleteMykarma = Mykarma::where('entry_id', '=', $id)->whereIn('users_role', array('PostedQuery', 'OfferedHelp'))->delete();
     echo "Question " . $id . " deleted";
 }