public function addNotification($userid, $type, $sourceid, $message) { $user = Auth::user(); // get target user status $userStatus = DB::table('users')->where('id', $userid)->pluck('suspended'); if ($userStatus == '0') { $notification = new Notification(); $notification->user_id = $userid; if (Session::get('source_user_id')) { $notification->source_user_id = Session::get('source_user_id'); } else { $notification->source_user_id = $user['id']; } ////////// //file_get_content(http://rf.php) ///////// $notification->type = $type; $notification->source_id = $sourceid; $notification->message = $message; $notification->save(); $notification->id; // get the server host name and protocol if ($_SERVER['SERVER_PORT'] == '80') { $protocol = 'http://'; } else { $protocol = 'https://'; } $domainName = $_SERVER['HTTP_HOST']; //echo $protocol.$domainName; //////////////// SPECIFY THE TYPE OF NOTIFICATIONS $desUrl = ""; // set the destination URL here if ($type == "newgroupmessage") { $msg = "sent you a message"; $desUrl .= "/#/message/view/" . $sourceid; } if ($type == "message") { $msg = "sent you a message"; $desUrl .= "/#/message/" . $notification->source_user_id; } if ($type == "newlike") { $msg = "likes your post"; // set the destination URL here $desUrl .= "/#/wall/" . $notification->source_id; } if ($type == "newcomment") { $msg = "has commented on your post"; // set the destination URL here $desUrl .= "/#/wall/" . $notification->source_id; } if ($type == "newcommentother") { $msg = "has commented on a post you commented on"; // set the destination URL here $desUrl .= "/#/wall/" . $notification->source_id; } if ($type == "newgroupmember") { $msg = "has joined your team"; } if ($type == "missionpending") { $msg = "have one mission pending"; } $userArray = User::where('id', '=', $notification->source_user_id)->get(); //print_r($desUrl); $value = Session::get('notificationMessage'); if (isset($value)) { $notificationMessage = $value; } else { $notificationMessage = ""; } // set the destination url // dont send newgroupmember push notification if ($type != "newgroupmember") { $user = User::where('id', '=', $userid)->get(); // check if target user allows sending push notification //print_r ($user[0]); if ($user[0]->push_notification == '1') { //echo "yes"; // init the notification object $pushNotificationObject = new PushNotificationController(); $pushNotificationObject->sendPushNotification(SITE_URL . $desUrl, $userArray[0]['firstname'] . " " . $msg . "\n \n" . $notificationMessage, "mobile", $userid); } } //print_r($userArray[0]['firstname']); Session::forget('notificationMessage'); /////////////// } return true; }
/** * this function is to sending out email to the user if | they are not completed the task after during the time frame | * @return number of email sending out */ public function suspendEmailWarningCron() { // init PushNotification $pushNotificationObject = new PushNotificationController(); $userObj = new stdClass(); // read user data from the database $users = DB::table('users')->where('suspend_after', 1)->where('suspended', 0)->where('warning_email_sent', 0)->get(array('id', 'username', 'firstname', 'lastname', 'email', 'created_at')); if (sizeof($users) < 1) { print_r('no users found<br/>'); } // loop thru all the users with email_notification enable print '**suspendEmailWarningCron** <br>'; foreach ($users as $user) { // init role assignment to check wether the user is admin or normal user $role_assignments = DB::table('role_assignments')->where('user_id', $user->id)->where('role_id', 1)->get(); //print_r($role_assignments); if (count($role_assignments) > 0) { continue; } $userObj->id = $user->id; $userObj->username = $user->username; $userObj->firstname = $user->firstname; $userObj->lastname = $user->lastname; $userObj->email = $user->email; $userObj->created_at = $user->created_at; // get the current group $groupid = DB::table('group_users')->where('user_id', $userObj->id)->pluck('group_id'); $group = DB::table('groups')->where('id', $groupid)->get(); $userObj->groupid = $group[0]->id; $userObj->groupname = $group[0]->name; $userTaskObj = new UserTask(); $totaltasks = $userTaskObj->totalTasks($userObj->groupid); // check the number of day passed if (count($group) > 0) { $timeStartDate = $userObj->created_at; $dayPassed = daysDiff(new DateTime($timeStartDate), new DateTime('now')) + 1; // compare the number of day passed and total mission print 'dayPassed: ' . $dayPassed . '<br>'; print 'totaltasks: ' . $totaltasks . '<br>'; if ($dayPassed == $totaltasks) { // send out email $warningEmailBody['name'] = $userObj->firstname; $warningEmailBody['email'] = $userObj->email; $this->notificationEmail($userObj->email, $warningEmailBody, "OAR21 Your account...", "", "warningnotification"); print 'warningEmailBody: If you have not yet completed all your missions you have 5 days left to complete your goal!<br>'; // send out push notification $pushNotificationObject->sendPushNotification(SITE_URL . "/#/journal", "If you have not yet completed all your missions you have 5 days left to complete your goal!", "mobile", $userObj->id); $user = User::find($userObj->id); $user->warning_email_sent = 1; $user->save(); } } } return "OK - Task Done"; }