/** * Run the database seeds. * * @return void */ public function run() { Calendar::create(array('name' => 'Brenda', 'color' => '0, 153, 255', 'user_id' => 1)); Calendar::create(array('name' => 'one day', 'color' => '255, 102, 153', 'user_id' => 1)); Calendar::create(array('name' => 'long events', 'color' => '255, 153, 102', 'user_id' => 1)); Calendar::create(array('name' => 'single repeats', 'color' => '0, 102, 0', 'user_id' => 1)); Calendar::create(array('name' => 'long repeats', 'color' => '0, 51, 153', 'user_id' => 1)); Calendar::create(array('name' => 'banana', 'color' => '204, 204, 0', 'user_id' => 1)); }
public function store(Request $request) { $name = Input::get('name'); $color = Input::get('color'); $user_id = Auth::id(); Calendar::create(array('name' => $name, 'color' => $color, 'user_id' => $user_id)); $addedCalendarId = DB::table('calendars')->where('name', '=', $name)->value('id'); return Response::json(['name' => $name, 'color' => $color, 'id' => $addedCalendarId]); }
/** * Create a new user instance after a valid registration. * * @param array $data * @return User */ protected function create(array $data) { $user = User::create(['first_name' => $data['first_name'], 'last_name' => $data['last_name'], 'email' => $data['email'], 'dob' => $data['dob'], 'gender' => $data['gender'], 'password' => bcrypt($data['password'])]); $name = $data['first_name']; $email = $data['email']; $user_id = $user->id; Calendar::create(array('name' => $name, 'color' => '51, 153, 255', 'user_id' => $user_id)); Todolist::create(array('name' => 'To Do', 'color' => '0, 0, 102', 'user_id' => $user_id)); Style::create(array('theme_name' => 'default', 'body_backgroundColor' => '218, 173, 134', 'buttons_backgroundColor' => '117, 168, 202', 'buttons_borderColor' => '89, 105, 114', 'navBar_backgroundColor' => '201, 216, 197', 'menuModal_backgroundColor' => '255, 246, 253', 'user_id' => $user_id)); $emaildata = array('name' => $name); Mail::send('emails.welcome', $emaildata, function ($message) use($email) { $message->from('*****@*****.**', 'gmPlanner'); $message->to($email)->subject('Welcome to gmPlanner'); }); return $user; }
/** * Execute the console command. * * @return mixed */ public function handle() { // Get all calendar entries that are due in two hours. $now = date('Y-m-d H:i:s'); $events = Calendar::where('Reminded', '=', false)->where('Start', '<=', date('Y-m-d H:i:s', strtotime($now) + 7200))->get(); // Now remind each user. foreach ($events as $event) { $user = User::where('TypeId', '=', $event->WorkerId)->first(); $notification = Notification::create(array('UserId' => $user->Id, 'Created' => $now, 'Reason' => 'Recordatorio de Evento: ' . $event->Title, 'Url' => '/calendar/' . $event->Id, 'Seen' => false)); // Update event. $event->Reminded = true; $event->save(); // Now check if this event should be rescheduled. switch ($event->Type) { case 2: // Add event next week. Calendar::create(array('Start' => date('Y-m-d H:i:s', strtotime($event->Start) + 604800), 'End' => date('Y-m-d H:i:s', strtotime($event->End) + 604800), 'WorkerId' => $event->WorkerId, 'Title' => $event->Title, 'AllDay' => $event->AllDay, 'Type' => $event->Type)); break; case 3: // Add event next Month. Calendar::create(array('Start' => date('Y-m-d H:i:s', strtotime($event->Start) + 2419200), 'End' => date('Y-m-d H:i:s', strtotime($event->End) + 2419200), 'WorkerId' => $event->WorkerId, 'Title' => $event->Title, 'AllDay' => $event->AllDay, 'Type' => $event->Type)); break; case 4: // Add event next Year. Calendar::create(array('Start' => date('Y-m-d H:i:s', strtotime($event->Start) + 29030400), 'End' => date('Y-m-d H:i:s', strtotime($event->End) + 29030400), 'WorkerId' => $event->WorkerId, 'Title' => $event->Title, 'AllDay' => $event->AllDay, 'Type' => $event->Type)); break; } } // Check for provider payments. $events = Calendar::where('Type', '=', 5)->where('Start', '<=', date('Y-m-d H:i:s', strtotime($now) + 172800))->get(); // Now remind each user. foreach ($events as $event) { $user = User::where('TypeId', '=', $event->WorkerId)->first(); $notification = Notification::create(array('UserId' => $user->Id, 'Created' => $now, 'Reason' => 'Dentro de dos dias se deberia pagar: ' . $event->Title, 'Url' => '/calendar/' . $event->Id, 'Seen' => false)); // Update event. $event->Reminded = true; $event->save(); } }
/** * Function that adds an event to a worker's calendar. * * @return Response */ public function addEvent() { // Validate Input. $validator = Validator::make(Input::all(), array('formData' => 'required')); if ($validator->fails()) { return response()->json(['error' => 'Informacion incompleta!']); } // Check that user is part of authorized staff. if (Auth::user()->Type != 1) { // If they are unauthorized no point in returning anything. return response()->json(array()); } // Get the worker. $worker = Worker::find(Auth::user()->TypeId); $start = date('Y-m-d H:i:s', strtotime(Input::get('formData')['startEvent'])); $end = date('Y-m-d H:i:s', strtotime(Input::get('formData')['endEvent'])); $allDay = Input::get('formData')['allDayEvent'] == 'true' ? true : false; $title = Input::get('formData')['eventTitle']; // Create the event. $calendar = Calendar::create(array('Start' => $start, 'End' => $end, 'WorkerId' => $worker->Id, 'Title' => $title, 'AllDay' => $allDay, 'Type' => Input::get('formData')['typeEvent'])); // Return response. $response['state'] = 'Success'; $response['message'] = 'Evento agregado!'; return response()->json($response); }
/** * Store a newly created resource in storage. * * @param \Illuminate\Http\Request $request * @return \Illuminate\Http\Response */ public function store(Request $calendarRequest) { // dd($calendarRequest->input()); $calendar = Calendar::create($calendarRequest->input()); return redirect()->action('CalendarsController@index'); }