示例#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;
 }
示例#2
0
 public function assign()
 {
     $keys = array('id', 'assigneeid');
     if (!Req::haspost($keys)) {
         return $this->fail('Insufficient data.');
     }
     $identifier = Lib::cookie(Lib::hash(Config::$userkey));
     $user = Lib::table('user');
     $isLoggedIn = !empty($identifier) && $user->load(array('identifier' => $identifier));
     if (!$isLoggedIn) {
         return $this->fail('You are not authorized.');
     }
     $post = Req::post($keys);
     $reportTable = Lib::table('report');
     if (!$reportTable->load($post['id'])) {
         return $this->fail('No such report.');
     }
     $reportTable->assignee_id = $post['assigneeid'];
     $reportTable->store();
     if (!empty($post['assigneeid']) && $post['assigneeid'] != $user->id) {
         $projectTable = Lib::table('project');
         $projectTable->load($reportTable->project_id);
         $targetUser = Lib::table('user');
         $targetUser->load($post['assigneeid']);
         $targetUserSettings = $targetUser->getSettings($projectTable)->getData();
         if ($targetUserSettings['assign']) {
             $notificationData = ['to' => $targetUser->email, 'text' => $user->nick . ' assigned you a report ticket.', 'username' => 'Project Report Assignment', 'icon_emoji' => ':gift:', 'attachments' => [['fallback' => '<' . $reportTable->getLink() . '|Report ticket ID ' . $reportTable->id . '>.', 'color' => '#00bcd4', 'title' => $projectTable->name, 'title_link' => $reportTable->getLink(), 'text' => $reportTable->content]]];
             Lib::load('helper/notification');
             NotificationHelper::send($notificationData);
             // $slackMessage = Lib::helper('slack')->newMessage();
             // $slackMessage->to($post['assigneeid']);
             // $slackMessage->message($user->nick . ' assigned you a report ticket.');
             // $slackMessage->username = '******';
             // $slackMessage->icon_emoji = ':gift:';
             // $attachment = $slackMessage->newAttachment();
             // $attachment->fallback = '<' . $reportTable->getLink() . '|Report ticket ID ' . $reportTable->id . '>.';
             // $attachment->color = '#00bcd4';
             // $attachment->title = $projectTable->name;
             // $attachment->title_link = $reportTable->getLink();
             // $attachment->text = $reportTable->content;
             // $slackMessage->send();
         }
     }
     return $this->success();
 }
示例#3
0
 public function submit()
 {
     $keys = array('id', 'content');
     if (!Req::haspost($keys)) {
         return $this->fail('Insufficient data.');
     }
     $identifier = Lib::cookie(Lib::hash(Config::$userkey));
     $user = Lib::table('user');
     $isLoggedIn = !empty($identifier) && $user->load(array('identifier' => $identifier));
     if (!$isLoggedIn) {
         return $this->fail('You are not authorized.');
     }
     $post = Req::post($keys);
     $commentTable = Lib::table('comment');
     $commentTable->link($user);
     $commentTable->report_id = $post['id'];
     $commentTable->content = $post['content'];
     $commentTable->store();
     $files = Req::file();
     if (!empty($files)) {
         foreach ($files as $key => $file) {
             $commentTable->attach($key, $file);
         }
     }
     $commentModel = Lib::model('comment');
     $recipients = $commentModel->getUsersByReportId($post['id']);
     $reportTable = Lib::table('report');
     $reportTable->load($post['id']);
     $projectTable = Lib::table('project');
     $projectTable->load($reportTable->project_id);
     if (!in_array($reportTable->user_id, $recipients)) {
         $recipients[] = $reportTable->user_id;
     }
     if (!in_array($reportTable->assignee_id, $recipients)) {
         $recipients[] = $reportTable->assignee_id;
     }
     $userSettingsModel = Lib::model('user_settings');
     $userProjectsSettings = $userSettingsModel->getSettings(array('project_id' => $projectTable->id, 'user_id' => $recipients));
     $userProjectsSettings = $userSettingsModel->assignByKey($userProjectsSettings, 'user_id');
     $userAllSettings = $userSettingsModel->getSettings(array('project_id' => 0, 'user_id' => array_diff($recipients, array_keys($userProjectsSettings))));
     $userAllSettings = $userSettingsModel->assignByKey($userAllSettings, 'user_id');
     $defaultSettings = unserialize(USER_SETTINGS);
     $ownerSettings = isset($userProjectsSettings[$reportTable->user_id]) ? $userProjectSettings : (isset($userAllSettings[$reportTable->user_id]) ? $userAllSettings : $defaultSettings);
     if (!$ownerSettings['comment-owner']) {
         $recipients = array_diff($recipients, array($reportTable->user_id));
     }
     foreach ($recipients as $userid) {
         if ($userid == $user->id) {
             continue;
         }
         $settings = isset($userProjectsSettings[$userid]) ? $userProjectSettings : (isset($userAllSettings[$userid]) ? $userAllSettings : $defaultSettings);
         // If is owner, the fact that we reach here means the owner wants notification
         // Or if not owner, then check for settings
         if ($reportTable->user_id == $userid || $settings['comment-participant']) {
             $notificationFields = ['Comment' => $post['content']];
             if (!empty($files)) {
                 foreach ($files as $key => $file) {
                     $notificationFields[$file['name']] = Config::getHTMLBase() . Config::$attachmentFolder . '/' . $key . '-' . $file['name'];
                 }
             }
             $targetUser = Lib::table('user');
             $targetUser->load($userid);
             $notificationData = ['to' => $targetUser->email, 'text' => $user->nick . ' posted a new comment.', 'username' => 'Project Report Comment', 'icon_emoji' => ':speech_balloon', 'attachments' => [['fallback' => 'New comment in <' . $reportTable->getLink() . '|Report ticket ID ' . $reportTable->id . '>.', 'color' => '#FFEB3B', 'title' => $projectTable->name, 'title_link' => $reportTable->getLink(), 'text' => $reportTable->content, 'fields' => $notificationFields]]];
             Lib::load('helper/notification');
             NotificationHelper::send($notificationData);
             // $slackMessage = Lib::helper('slack')->newMessage();
             // $slackMessage->to($userid);
             // $slackMessage->message($user->nick . ' posted a new comment.');
             // $slackMessage->username = '******';
             // $slackMessage->icon_emoji = ':speech_balloon:';
             // $attachment = $slackMessage->newAttachment();
             // $attachment->fallback = 'New comment in <' . $reportTable->getLink() . '|Report ticket ID ' . $reportTable->id . '>.';
             // $attachment->color = '#FFEB3B';
             // $attachment->title = $projectTable->name;
             // $attachment->title_link = $reportTable->getLink();
             // $attachment->text = $reportTable->content;
             // $attachment->newField('Comment', $post['content']);
             // if (!empty($files)) {
             // 	foreach ($files as $key => $file) {
             // 		$attachment->newField($file['name'], Config::getHTMLBase() . Config::$attachmentFolder . '/' . $key . '-' . $file['name']);
             // 	}
             // }
             // $slackMessage->send();
         }
     }
     return $this->success($commentTable->id);
 }