/** * Signs user up. * * @return User|null the saved model or null if saving fails */ public function signup() { if ($this->validate()) { $user = new User(); $user->username = $this->username; $user->email = $this->email; $user->setPassword($this->password); $user->generateAuthKey(); $user->status = 0; if ($user->save()) { $notification = new Notification(); $notification->title = 'user'; $notification->message = 'new user, username:'******'model' => 'User', 'id' => $user->id]); if ($notification->save()) { $this->sendEmail($this->email); } else { print_r($notification->getErrors()); exit(0); } return $user; } else { return $user->getErrors(); } } return null; }
/** * @param string $description ---> enter the title or entry of model * @param object $model ---> enter lastest saved model * @param object $user ---> creater of the notification record (mostly current user model) * @param string $type ---> current controller name or a manualy hard coded string for comments (comment,journal,mood,event,photo,activity) * @param string $shared_with ---> shared_with values if latest saved model has a column named shared_with, else need to enter customized values */ public function notify($description, $model, $user, $type, $shared_with = null) { //create notification record - DTR $sharedWith = array(); if ($shared_with != null) { if ($shared_with == '*') { $sharedWith = yii\helpers\ArrayHelper::getColumn($user->others, 'id'); } else { $sharedWith = explode(',', $shared_with); } } else { $sharedWith = yii\helpers\ArrayHelper::getColumn($user->findParents()->all(), 'id'); } foreach ($sharedWith as $shared_id) { $notify = new Notification(); $notify->date = date("Y-m-d h:i:s"); $notify->shared_id = (int) $shared_id; $notify->type_id = $model->id; $notify->description = $description; $notify->type = $type; $notify->user_id = $user->id; $notify->status = 0; $notify->save(); } //end of notification record entry }
/** * Run the database seeds. * * @return void */ public function run() { $notification = new Notification(); $notification->from = 1; $notification->to = 1; $notification->type = 1; $notification->save(); }
/** * Creates a new Notification model. * If creation is successful, the browser will be redirected to the 'view' page. * @return mixed */ public function actionCreate() { $model = new Notification(); if ($model->load(Yii::$app->request->post()) && $model->save()) { return $this->redirect(['view', 'id' => $model->id]); } else { return $this->render('create', ['model' => $model]); } }
/** * Creates a new Notification model. * If creation is successful, the browser will be redirected to the 'view' page. * @return mixed */ public function actionCreate() { $model = new Notification(); if ($model->loadWithFiles(Yii::$app->request->post()) && $model->save()) { Yii::$app->session->setFlash('success', 'Well done! successfully to save data! '); return $this->redirect(['view', 'id' => $model->id]); } else { return $this->render('create', ['model' => $model]); } }
/** * Create post * * @param Request $request * @return \Illuminate\Contracts\View\Factory|\Illuminate\Http\RedirectResponse|\Illuminate\View\View */ public function create(Request $request) { if ($request->isMethod("post")) { $rules = ["title" => "required", "alias" => "required|unique:posts,alias", "content" => "required", 'image' => 'mimes:jpeg,jpg,png']; Validator::make($request->all(), $rules)->validate(); $post = new Post(); $post->title = $request->input("title"); $post->alias = $request->input("alias"); $post->content = $request->input("content"); $post->meta_keys = $request->input("meta_keys"); $post->meta_desc = $request->input("meta_desc"); if (!empty($request->file("image"))) { $generated_string = str_random(32); $file = $request->file("image")->store('uploads'); $new_file = $generated_string . '.' . $request->file("image")->getClientOriginalExtension(); Storage::move($file, 'uploads/' . $new_file); $img = Image::make($request->file('image')); $img->crop(200, 200); $img->save(storage_path('app/public/uploads/' . $new_file)); $img = Image::make($request->file('image')); $img->resize(600, 315); $img->save(storage_path('app/public/uploads/fb-' . $new_file)); $post->image = $new_file; } if ($request->has("category")) { $post->category_id = $request->input("category"); } $post->publish = $request->has("publish"); $post->author_id = Auth::user()->id; $post->save(); if ($request->has("tags")) { foreach ($request->input("tags") as $tag) { $post_tag = new PostTag(); $post_tag->post_id = $post->id; $post_tag->tag_id = $tag; $post_tag->save(); } } $admins = User::getAdmins(); foreach ($admins as $admin) { if ($admin->id != Auth::user()->id) { $notification = new Notification(); $notification->from = Auth::user()->id; $notification->to = $admin->id; $notification->type = 3; $notification->save(); } } return redirect()->route('posts'); } else { $categories = Category::getCategoriesByPublish(); $tags = Tag::getTags(); return view("site.post.create", compact("categories", "tags", "post")); } }
public function actionSendUpdateNotifi() { $sender = $_POST['owner']; $typeid = $_POST['agendaID']; $type = $_POST['type']; $followmodel = new Follow(); $recive = array(); $recive = $followmodel->getfollowing($sender); for ($i = 0; $i < sizeof($recive); $i++) { $notificationModel = new Notification(); $notificationModel->sender = $sender; $notificationModel->postID = $typeid; $notificationModel->type = $type; $notificationModel->seen = "0 "; $notificationModel->notified = $recive["studentID"][$i]; $notificationModel->save(); } $value = array('status' => "ok"); return json_encode($value); }
public function postIndex() { $input = Input::all(); $rules = array("message" => "required|min:10|max:90"); $validation = Validator::make($input, $rules); if ($validation->fails()) { return Redirect::to('admin/notifications')->withErrors($validation)->withInput(); } else { $data = new Notification(); $data->message = Input::get('message'); $data->coupon_id = Input::get('coupon'); $data->finished = 0; $data->save(); $tokens = Token::where("os", "=", "ios")->get(); foreach ($tokens as $token) { //$this->_ios_notification($token->token, Input::get('message'), Input::get('coupon')); } return Redirect::to('admin/notifications')->with("message", "Notificación agregada!"); } }
/** * User activation * * @param $token * @return \Illuminate\Http\RedirectResponse */ public function activation($token) { $user = User::getUserByActivationToken($token); if (!empty($user)) { $user->approve = 1; $user->activation_token = ""; $user->save(); $admins = User::getAdmins(); foreach ($admins as $admin) { $notification = new Notification(); $notification->from = $user->id; $notification->to = $admin->id; $notification->type = 2; $notification->save(); } $notification = new Notification(); $notification->from = 1; $notification->to = $user->id; $notification->type = 4; $notification->save(); } return redirect()->route('home'); }
/** * API PUT Route to update a user's notification settings. * * @param User $user * * @return Response::json * * @todo There has to be a more efficient way to do this... We should probably only send changes from Angular. We can also separate the array matching into helper functions */ public function putNotifications(User $user) { if (Auth::user()->id !== $user->id) { return Response::json($this->growlMessage("You do not have permissions to edit this user's notification settings", "error")); } //Grab notification array $notifications = Input::get('notifications'); //Retrieve valid notification events $validNotifications = Notification::getUserNotifications(); $events = array_keys($validNotifications); //Loop through each notification foreach ($notifications as $notification) { //Ensure this is a known user event. if (!in_array($notification['event'], $events)) { return Response::json($this->growlMessage("Unable to save settings. Unknown event: " . $notification['event'], "error")); } //Grab this notification from the database $model = Notification::where('user_id', '=', $user->id)->where('event', '=', $notification['event'])->first(); //If we don't want that notification (and it exists), delete it if ($notification['selected'] === false) { if (isset($model)) { $model->delete(); } } else { //If the entry doesn't already exist, create it. //Otherwise, ignore ( there was no change ) if (!isset($model)) { $model = new Notification(); $model->user_id = $user->id; $model->event = $notification['event']; $model->type = "email"; $model->save(); } } } return Response::json($this->growlMessage("Settings saved successfully.", "success")); }
/** * Stop the timer (update it). * Return all the projects, * as well as the project that is currently displaying in the project popup * @param Request $request * @return mixed */ public function stopProjectTimer(Request $request) { // Fetch the required data $project = Project::find($request->get('project_id')); $last_timer_id = Timer::where('project_id', $project->id)->max('id'); $timer = Timer::find($last_timer_id); // Update the data (Price will be zero if time is less than 30 seconds) $timer->finish = Carbon::now()->toDateTimeString(); $timer->save(); $timer->calculatePrice(); $message = Auth::user()->name . ' has stopped the timer on the project ' . $project->description . '.'; //Create a notification in the database for the payer, in case they are not currently logged in $notification = new Notification(['message' => $message]); $notification->user()->associate($project->payer->id); $notification->save(); //Pusher $pusher = new Pusher(env('PUSHER_PUBLIC_KEY'), env('PUSHER_SECRET_KEY'), env('PUSHER_APP_ID')); $data = ['payer_id' => $project->payer_id, 'notification' => $notification]; $pusher->trigger('channel', 'stopTimer', $data); // Create the fractal manager // @TODO: You could extract the next two lines to a ServiceProvider $fractal = new Manager(); $fractal->setSerializer(new ArraySerializer()); // Create an item with fractal $resource = new Item($timer, new StopProjectTimerTransformer()); // $this->createItem(Model, transofrmer) // $this->createCollection(Model, transofrmer) // Send a response return response()->json($fractal->createData($resource)->toArray()); // return $this->responseOk($timer); }
/** * Update the project. * Set confirmed to 1. * @param $id * @return mixed */ public function update($id) { $project = Project::find($id); $project->status = 'confirmed'; $project->save(); $message = $project->payer->name . ' has confirmed your project ' . $project->description . '!'; //Create a notification in the database for the payee, in case they are not currently logged in $notification = new Notification(['message' => $message]); $notification->user()->associate($project->payee->id); $notification->save(); //Pusher $pusher = new Pusher(env('PUSHER_PUBLIC_KEY'), env('PUSHER_SECRET_KEY'), env('PUSHER_APP_ID')); $data = ['payee_id' => $project->payee->id, 'notification' => $notification, 'project' => $project]; $pusher->trigger('channel', 'confirmProject', $data); return $project; }
/** * Disapprove post * * @param $id * @return \Illuminate\Http\RedirectResponse */ public function disapprove($id) { $post = Post::getPostById($id); if ($post) { $post->approve = 0; $post->save(); if ($post->author_id != Auth::user()->id) { $notification = new Notification(); $notification->from = Auth::user()->id; $notification->to = $post->author_id; $notification->type = 6; $notification->save(); } } return redirect()->route('admin_posts'); }
public static function reviewed(Notification $notification) { $notification->seen_at = \Carbon\Carbon::now(); return $notification->save(); }
public static function addNotify($text, $user_id) { $notification = new Notification(); $notification->load(array("user_id" => $user_id, "title" => $text, "text" => $text, "status" => "new"), ''); $notification->save(); }
/** * Edit user * * @param Request $request * @param $id * @return \Illuminate\Contracts\View\Factory|\Illuminate\Http\RedirectResponse|\Illuminate\View\View */ public function edit(Request $request, $id) { $user = User::getUserById($id); if (!empty($user)) { if ($request->isMethod('post')) { $rules = ['first_name' => 'required', 'last_name' => 'required', 'position' => 'required', 'type' => 'required', 'phone' => 'phone:AM', 'username' => 'required|unique:users,username,' . $id, 'email' => 'required|email|unique:users,email,' . $id, 'pass' => 'min:6|max:12', 'pass_confirmation' => 'min:6|max:12|same:pass', 'image' => 'mimes:jpeg,jpg,png']; Validator::make($request->all(), $rules)->validate(); $user->first_name = $request->input('first_name'); $user->last_name = $request->input('last_name'); $user->position = $request->input('position'); $user->role_id = $request->input('type'); if ($request->has('phone')) { $user->phone = $request->input('phone'); } if (!empty($request->file("image"))) { if (!empty($user->image)) { if (Storage::exists('uploads/' . $user->image)) { Storage::delete('uploads/' . $user->image); } } $generated_string = str_random(32); $file = $request->file("image")->store('uploads'); $new_file = $generated_string . '.' . $request->file("image")->getClientOriginalExtension(); Storage::move($file, 'uploads/' . $new_file); $img = Image::make($request->file('image')); $img->crop(200, 200); $img->save(storage_path('app/public/uploads/' . $new_file)); $user->image = $new_file; } $user->username = $request->input('username'); $user->email = $request->input('email'); $user->notification = $request->has('notification'); if ($request->has('pass')) { $user->password = Hash::make($request->input('pass')); } $user->approve = 1; $user->save(); $notifications = Notification::getNotificationBySenderId($user->id); foreach ($notifications as $notification) { $notification->delete(); } $notifications = Notification::getNotificationByReaderId($user->id); foreach ($notifications as $notification) { $notification->delete(); } if ($user->role_id == 1) { $notification = new Notification(); $notification->from = 1; $notification->to = $user->id; $notification->type = 1; $notification->save(); } return redirect()->route('approved_users'); } else { $user_roles = UserRole::getRoles(); return view('admin.user.edit', compact('user', 'user_roles')); } } else { return redirect()->back(); } }