Esempio n. 1
0
 public static function saveMeetingDataForMyKarma($meetingId, $userId, $giverId)
 {
     $getGiverData = User::where('id', '=', $giverId)->first();
     $getUser = User::where('id', '=', $userId)->first();
     $getMeetingData = Meetingrequest::where('id', '=', $meetingId)->first();
     //Add data on users_mykarma table for receiver
     $myKarmaDataReceiver = new Mykarma();
     $myKarmaDataReceiver->entry_id = $meetingId;
     $myKarmaDataReceiver->user_id = $userId;
     $myKarmaDataReceiver->fname = $getGiverData->fname;
     $myKarmaDataReceiver->lname = $getGiverData->lname;
     $myKarmaDataReceiver->piclink = $getGiverData->piclink;
     $myKarmaDataReceiver->entry_type = 'Meeting';
     $myKarmaDataReceiver->users_role = 'Receiver';
     $myKarmaDataReceiver->status = 'pending';
     $myKarmaDataReceiver->unread_flag = 'false';
     $myKarmaDataReceiver->no_of_unread_items = '0';
     $myKarmaDataReceiver->entry_updated_on = Carbon::now();
     $myKarmaDataReceiver->save();
     //Add data on users_mykarma table for giver
     $myKarmaDataGiver = new Mykarma();
     $myKarmaDataGiver->entry_id = $meetingId;
     $myKarmaDataGiver->user_id = $giverId;
     $myKarmaDataGiver->fname = $getUser->fname;
     $myKarmaDataGiver->lname = $getUser->lname;
     $myKarmaDataGiver->piclink = $getUser->piclink;
     $myKarmaDataGiver->entry_type = 'Meeting';
     $myKarmaDataGiver->users_role = 'Giver';
     $myKarmaDataGiver->status = 'pending';
     $myKarmaDataGiver->unread_flag = 'true';
     $myKarmaDataGiver->no_of_unread_items = '1';
     $myKarmaDataGiver->entry_updated_on = Carbon::now();
     $myKarmaDataGiver->save();
     $token = $getGiverData->deviceToken;
     $pushNotificationStatus = NotificationHelper::androidPushNotification($token);
     //Add message in requests_messages table
     $messageData = new Message();
     $messageData->request_id = $meetingId;
     $messageData->sender_id = $userId;
     $messageData->giver_id = $giverId;
     $messageData->receiver_id = $userId;
     $messageText = $getUser->fname . ' ' . $getUser->lname . ' has sent a meeting request.';
     $messageData->messageText = $messageText;
     $messageData->save();
     $messageDataSecond = new Message();
     $messageDataSecond->message_type = 'user';
     $messageDataSecond->request_id = $meetingId;
     $messageDataSecond->sender_id = $userId;
     $messageDataSecond->giver_id = $giverId;
     $messageDataSecond->receiver_id = $userId;
     $messageDataSecond->messageText = $getMeetingData->notes;
     $messageDataSecond->save();
     $gratitudeText = 'In gratitude, I will do the following -';
     // Add regular messages in request_messages table.
     if ($getMeetingData->payitforward == '1') {
         $payitforwardText = "I'll pay it forward";
     } else {
         $payitforwardText = "";
     }
     if ($getMeetingData->buyyoucoffee == '1') {
         $buyyoucoffeeText = "I'll buy you coffee (in-person meetings only)";
     } else {
         $buyyoucoffeeText = "";
     }
     if ($getMeetingData->sendKarmaNote == '1') {
         $sendKarmaNoteText = "I'll send you a KarmaNote";
     } else {
         $sendKarmaNoteText = "";
     }
     if ($getMeetingData->sendKarmaNote == '1') {
         $messageGratituteText = $gratitudeText . "\n" . $sendKarmaNoteText . ".\n" . $payitforwardText . ".";
     } else {
         $messageGratituteText = $gratitudeText . "\n" . $payitforwardText . ".";
     }
     if (substr($messageGratituteText, 0, 1) === '.') {
         $messageGratituteText = substr($messageGratituteText, 1);
     }
     if ($getMeetingData->payitforward == '1' || $getMeetingData->sendKarmaNote == '1' || $getMeetingData->buyyoucoffee == '1') {
         $messageDataSecond = new Message();
         $messageDataSecond->message_type = 'user';
         $messageDataSecond->request_id = $meetingId;
         $messageDataSecond->sender_id = $userId;
         $messageDataSecond->giver_id = $giverId;
         $messageDataSecond->receiver_id = $userId;
         $messageDataSecond->messageText = $messageGratituteText;
         $messageDataSecond->save();
     }
     return true;
 }
 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');
     }
 }