/** * Admin: Start stream countdown. * @return \Illuminate\Http\RedirectResponse */ public function postStartCountdown($stream) { $counter = AnnouncementCounter::getByStream($stream); $name = Input::get('name'); $endTime = new Carbon(); $endTime->addMinutes(10); $counter->ends_at = $endTime; $counter->save(); $this->broadcast(array('stream' => $stream, 'type' => 'notify', 'text' => $name, 'expires' => $endTime->timestamp)); Flash::success('Отчет завершится в ' . $endTime->format('H:i:s')); }
/** * Run the database seeds. * * @return void */ public function run() { Model::unguard(); for ($i = 0; $i < $this->usersCount; $i++) { $date = new Carbon(); $date->subMinute(rand(1, 60 * 24 * 30)); $username = $i === 0 ? 'martiros.aghajanyan' : strtolower($this->faker->userName) . rand(100000, 200000); $user = User::create(['username' => $username, 'email' => $username . '@gmail.com', 'password' => Hash::make('test123'), 'show_status' => User::STATUS_ACTIVE, 'created_at' => $date, 'updated_at' => $date]); $ip = $this->faker->ipv4; $date->addMinutes(rand(1, 60)); $user->userInfo()->create(['confirmation_code' => rand(100000, 999999), 'confirmation_ip' => $ip, 'reg_ip' => $ip, 'confirmation_date' => $date]); } }
public function store() { $errors = false; /* @var $user \User */ $user = User::where('email', '=', Input::get('email'))->first(); // Check previous session for users. if ($user && $user->role == User::ROLE_USER) { if (!empty($user->session) && Session::getId() != $user->session && !$user->session_expires->isPast()) { $errors = true; } } if (!$errors) { $credentials = Input::only('email', 'password'); $credentials['registration_status'] = 1; if (Auth::attempt($credentials)) { if (Auth::user()->role == "1") { return Redirect::to('/user/admin/transactions/all'); } else { // Set user's session. Will expire in 5 min. $user->session = Session::getId(); $sessionExpires = new Carbon(); $sessionExpires->addMinutes(5); $user->session_expires = $sessionExpires; $user->save(); // Redirect to user's profile when logged in first time. if (!empty(Auth::user()->first_login)) { return Redirect::to('/user/edit'); } else { // Redirect to user's transactions. return Redirect::to('/user/transactions'); } } } } Auth::logout(); // TODO: Localize error message. return Redirect::to('/')->with('errorTitle', 'Login failed.')->with('error', 'Incorrect credentials. <a href="' . action('RemindersController@getRemind') . '">Forgot your password?</a>'); // Message in popup. }
public function storeSchedule() { $input['json'] = '{ "user": "******", "event": "1", "time_slots": [ { "start": 1411239474, "end": 1411539474, "weighting": "5" }, { "start": 1411269474, "end": 1411549474, "weighting": "5" } ] }'; $decoded = json_decode($input['json']); $user_id = $decoded->user; $occasion_id = $decoded->event; // Get the occasion tied to the user $occasion = User::find($user_id)->occasions->find($occasion_id); if ($occasion == null) { return null; } $time_slots = $decoded->time_slots; $insert = array(); for ($i = 0; $i < count($time_slots); $i++) { $start = $time_slots[$i]->start; $ts_start = Carbon::createFromTimeStamp($start); $end = $time_slots[$i]->end; $ts_end = Carbon::createFromTimeStamp($end); $insert[] = array('start' => $ts_start->toDateTimeString(), 'end' => $ts_end->toDateTimeString(), 'weighting' => $time_slots[$i]->weighting, 'user_id' => $user_id, 'occasion_id' => $occasion_id); } //dd($insert); Timeslot::insert($insert); $occasion->pivot->complete = 1; $occasion->pivot->save(); $num_incomplete_occasions = Occasion::find($occasion_id)->users()->wherePivot('complete', 0)->count(); if ($num_incomplete_occasions != 0) { return $occasion; } // The events are done - push $occasion = Occasion::find($occasion_id); $host_start = new Carbon($occasion->start); $host_end = new Carbon($occasion->end); $diff = $host_start->diffInMinutes($host_end); $num_users = $occasion->users->count(); $score = array(); $score = array_fill(0, 10000, 0); //$score[0] = 'test'; //$score = 0; $k = 0; $previous = new Carbon($occasion->start); // implement eager loading for ($i = 0; $i < $diff; $i += 15) { for ($j = 0; $j < $num_users; $j++) { $start = new Carbon($occasion->start); $start->addMinutes($i); $timeslot = Timeslot::where('user_id', '=', $j)->where('start', '<=', $previous->toDateTimeString())->where('end', '>=', $start->toDateTimeString())->first(); if ($timeslot != null) { //dd($timeslot); //$score = array_add($score, $i, $timeslot->weighting); $score[$i] += $timeslot->weighting; //$score[$i] += $timeslot->weighting; //$score[] = array($timeslot->weighting); //$k++; //var_dump($score); } } $previous = $start; } $score = array_filter($score); //dd($score); rsort($score); $top3 = array_reverse(array_slice($score, 0, 3)); $users = Occasion::find($occasion_id)->users()->get(); $data = array('temp'); $users = $users->each(function ($user) use($data) { \Mail::send('emails.invite', $data, function ($message) use($user) { $message->to($user->email, $user->name)->subject('Your event has been scheduled!'); }); \Twilio::message($user->phone, 'An event has finished scheduling! Open up Calendr to learn more.'); }); $app_id = 'jVmr9Q4ItzKs2abze4T2mRvECJ8AxMwCKT5G8anC'; $rest_key = 'hNv7GwawFKdvpyb6B6u8sLqlSQMW3YWWRQeKVll7'; $master_key = 'wzwEOPsb5w45qWQQVJSCqTtL6yvD82Y90SiVDh4y'; ParseClient::initialize($app_id, $rest_key, $master_key); $data = array("alert" => "An event has finished scheduling! Press here to learn more."); ParsePush::send(array("channels" => ["PHPFans"], "data" => $data)); $query = ParseInstallation::query(); $query->equalTo("design", "rad"); ParsePush::send(array("where" => $query, "data" => $data)); // dd($score); }
/** * Run the database seeds. * * @return void */ public function run() { $date = new Carbon(); //Create 500 new data points factory(App\Models\BanchoStats::class, 500)->make()->each(function ($stat) use($date) { $stat->date = $date; $stat->save(); //Increment the dates by 5 each time $date->addMinutes(5); }); }
/** * * @param Item $item * @param Carbon $notBeforeTime * @return Carbon */ private function calculateNotBeforeTime(Item $item, Carbon $notBeforeTime) { switch ($item->recurring_unit) { case "minute": $notBeforeTime->addMinutes($item->recurring_frequency); break; case "hour": $notBeforeTime->addHours($item->recurring_frequency); break; case "day": $notBeforeTime->addDays($item->recurring_frequency); break; case "week": $notBeforeTime->addWeeks($item->recurring_frequency); break; case "month": $notBeforeTime->addMonths($item->recurring_frequency); break; case "year": $notBeforeTime->addYears($item->recurring_frequency); break; } return $notBeforeTime; }