/** * @return \Carbon\Carbon */ function next_weekly() { static $date; if (!$date) { $date = carbon('this tuesday 9:00 AM Z'); if ($date->isPast()) { $date = carbon('next tuesday 9:00 AM Z'); } } return $date; }
/** * Return the current status of Supervisor workers. * * @return mixed */ public function getSupervisorProcesses() { if (app('supervisor')->checkConnection()) { $processes = collect(app('supervisor')->getProcesses())->filter(function ($process) { // Only return processes in the SeAT Group return $process->getGroup() == config('web.supervisor.group'); })->map(function ($process) { $process_info = $process->getProcessInfo(); return collect(['name' => $process_info['name'], 'pid' => $process_info['pid'], 'statename' => $process_info['statename'], 'spawnerr' => $process_info['spawnerr'], 'start' => carbon()->createFromTimestamp($process_info['start'])->toDateTimeString(), 'log' => $process_info['logfile']]); }); } return Datatables::of($processes ?? collect())->make(true); }
/** * The required method to handle the Alert. * * @return mixed */ protected function getData() : Collection { // Get the corporations we know about. $corporation_ids = Starbase::select('corporationID')->groupBy('corporationID')->pluck('corporationID'); // Prepare the return collection. $low_feul = collect(); // Go over each corporation ... $corporation_ids->each(function ($corporation_id) use(&$low_feul) { // .. and check the details of each starbase $this->getCorporationStarbases($corporation_id)->each(function ($starbase) use($corporation_id, &$low_feul) { $info = ['corporation_id' => $corporation_id, 'type' => $starbase->starbaseTypeName, 'name' => $starbase->starbaseName, 'location' => $starbase->moonName, 'hours_left' => carbon('now')->diffInHours(carbon('now')->addHours($starbase->fuelBlocks / ceil($starbase->baseFuelUsage * ($starbase->inSovSystem ? 0.75 : 1)))), 'fuel_blocks' => $starbase->fuelBlocks, 'estimated_offline' => carbon('now')->addHours($starbase->fuelBlocks / ceil($starbase->baseFuelUsage * ($starbase->inSovSystem ? 0.75 : 1)))->diffForHumans()]; // If the fuel is low, add it to the collection! if ($info['hours_left'] < 24) { $low_feul->push($info); } }); }); return $low_feul; }
/** * Get the array representation of the notification. * * @param mixed $notifiable * * @return array */ public function toArray($notifiable) { return ['player_count' => $this->player_count->onlinePlayers, 'calculated' => carbon($this->player_count->currentTime)->diffForHumans()]; }
/** * @return mixed */ public function listAllData() { $keys = ApiKeyModel::with('info'); if (!auth()->user()->has('apikey.list', false)) { $keys = $keys->where('user_id', auth()->user()->id); } // Return data that datatables can understand return Datatables::of($keys)->editColumn('info.expired', function ($column) { // Format dates for expired for sorting reasons return carbon($column->expires)->format('d/m/y'); })->addColumn('characters', function ($row) { // Include a view to show characters on a key return view('web::api.partial.character', compact('row'))->render(); })->addColumn('actions', function ($row) { // Detail & Delete buttons return view('web::api.partial.actions', compact('row'))->render(); })->filter(function ($query) { // Define the filter() method so on fields // where it makes sense. Unfortunately this had // to be done because of the way the characters // are incuded on a key. $query->whereHas('characters', function ($filter) { $filter->where('characterName', 'like', '%' . request()->input('search')['value'] . '%'); })->orWhereHas('info', function ($filter) { $filter->where('type', 'like', '%' . request()->input('search')['value'] . '%'); }); })->setRowClass(function ($row) { // Make disabled keys red. if (!$row->enabled) { return 'danger'; } })->removeColumn('v_code')->make(true); }
/** * The required method to handle the Alert. * * @return mixed */ protected function getData() : Collection { return MailMessage::with('body')->where('sentDate', '>', carbon('now')->subMonth())->get(); }
protected function gDailyChapterResetDate($value) { return carbon($value); }
public function __construct(Character $character, array $activities, array $pves, array $stats) { $this->character = $character; $this->dateActivityStarted = carbon($activities['dateActivityStarted']); $lastReset = last_weekly(); $nextReset = next_weekly(); // raid, arena and nightfall completion status $raidsCompleted = []; $arenasCompleted = []; $activitiesCompleted = []; // need advisors to identify daily $this->dailyChapter = destiny()->advisors()->daily; foreach ($pves as $pve) { $activityHash = (string) $pve['activityDetails']['referenceId']; $activity = manifest()->activity($activityHash); $activityId = sha1($activity->activityName); $activityType = $activity->activityType; $completed = (bool) array_get($pve, 'values.completed.basic.value', false); $date = carbon($pve['period']); if ($activityType->isRaid()) { $activityLevel = $activity->activityLevel; if (!isset($raidsCompleted[$activityId])) { $raidsCompleted[$activityId] = null; } if ($completed && $date > $lastReset && $date < $nextReset) { if ($activityLevel > $raidsCompleted[$activityId]) { $raidsCompleted[$activityId] = $activityLevel; } } } if ($activityType->isArena()) { if (!array_key_exists($activityHash, $arenasCompleted)) { $arenasCompleted[$activityHash] = false; } if ($completed && $date > $lastReset && $date < $nextReset) { $arenasCompleted[$activityHash] = $completed; } } if ($activityType->isNightfall()) { $nightfallHash = $activity->activityType->activityTypeHash; if (!array_key_exists($nightfallHash, $activitiesCompleted)) { $activitiesCompleted[$nightfallHash] = false; } if ($completed && $date > $lastReset && $date < $nextReset) { $activitiesCompleted[$nightfallHash] = $completed; } } if ($activityHash == $this->dailyChapter->activityHash) { if (!array_key_exists($activityHash, $activitiesCompleted)) { $activitiesCompleted[$activityHash] = false; } if ($completed && $date > last_daily() && $date < next_daily()) { $activitiesCompleted[$activityHash] = $completed; } } } // stats grouped by activity hash $statsArray = []; foreach ($stats as $k => $stat) { $activityHash = (string) $stat['activityHash']; $statsArray[$activityHash] = new StatisticsCollection($stat['values']); } // build ActivityCollection foreach ($activities['available'] as $activity) { $activityHash = (string) $activity['activityHash']; $activityStats = array_get($statsArray, $activityHash); $activity = new Activity($character, $activity, $activityStats); $activityId = sha1($activity->activityName); if ($activity->isCompleted && $activity->isWeekly()) { $activity->isCompleted = $character->dateLastPlayed > last_weekly(); } $this->put($activityHash, $activity); if ($activity->isRaid()) { $activity->isCompleted = false; $activityLevelCompleted = array_get($raidsCompleted, $activityId); if (!$activityLevelCompleted) { continue; } if ($activity->activityLevel <= $activityLevelCompleted) { $activity->isCompleted = true; } } if ($activity->isArena()) { $activity->isCompleted = array_get($arenasCompleted, $activityHash, false); } if ($activity->isNightfall()) { $activity->isCompleted = array_get($activitiesCompleted, $activity->activityType->activityTypeHash, false); } if ($activityHash == $this->dailyChapter->activityHash) { $activity->isCompleted = array_get($activitiesCompleted, $activityHash, false); } } }
protected function gStartDate($value) { return carbon($value); }
protected function gDateLastPlayed($value) { return carbon($value); }
protected function gStartDate() { return carbon($this->properties['startDate']); }
/** * Return the time difference from now in a * format that humans can read * * @param $time * * @return string */ function human_diff($time) { return carbon($time)->diffForHumans(); }
/** * @param $column * * @return null|string */ protected function getHumanTimestampAttribute($column) { if ($this->attributes[$column]) { return carbon($this->attributes[$column])->diffForHumans(); } }
/** * @param \Illuminate\Http\Request $request * * @return mixed */ public function getSearchApiKeyData(Request $request) { $keys = $this->doSearchApiKey($request->input('search.value')); if (!auth()->user()->has('apikey.list', false)) { $keys = $keys->where('user_id', auth()->user()->id); } // Return data that datatables can understand return Datatables::of($keys)->editColumn('info.expired', function ($column) { // Format dates for expired for sorting reasons return carbon($column->expires)->format('d/m/y'); })->addColumn('characters', function ($row) { // Include a view to show characters on a key return view('web::api.partial.character', compact('row'))->render(); })->addColumn('actions', function ($row) { // Detail & Delete buttons return view('web::api.partial.actions', compact('row'))->render(); })->setRowClass(function ($row) { // Make disabled keys red. if (!$row->enabled) { return 'danger'; } })->removeColumn('v_code')->make(true); }
/** * Attempt to 'thread' evemails based on the seperator * that is automatically added using the eve client. * * @param $message * * @return array */ function evemail_threads($message) { // Explode the messages based on the delimiter added // by the EVE Online Client. $delimiter = '--------------------------------<br>'; return collect(explode($delimiter, $message))->map(function ($thread) { // Message headers array. $headers = ['subject' => null, 'from' => null, 'sent' => null, 'to' => null, 'message' => null, 'headers_ok' => false]; // Start by setting the full message first. $headers['message'] = $thread; // Next, parse the headers. // // Example header: // Re: Assistance // From: Some Character // Sent: 2016.11.22 20:38 // To: qu1ckkkk // // Example raw header: // Re: Assistance<br>From: Some Character<br>Sent: 2016.11.22 20:38<br>To: qu1ckkkk, <br> // Cleanup the message first: $thread = clean_ccp_html($thread, '<br>'); // Explode on the <br> characters to get an array. $thread = explode('<br>', $thread, 5); // Ensure the message got 4 parts if (count($thread) < 4) { return $headers; } // Check and extract the headers. // // First the subject. $headers['subject'] = $thread[0]; // And then the From characterName $headers['from'] = strpos($thread[1], 'From') !== false ? ltrim($thread[1], 'From: ') : null; // Next the sent date. // We make this a carbon object too while we at it. try { $time = carbon()->createFromFormat('Y.m.d H:i', ltrim($thread[2], 'Sent: ')); $headers['sent'] = strpos($thread[2], 'Sent') !== false ? $time : null; } catch (InvalidArgumentException $e) { } // Lasty the To characterName. We need to trim a trailing // comma (,) here too. $to = ltrim($thread[3], 'To: '); $to = rtrim($to, ', '); $headers['to'] = strpos($thread[3], 'To') !== false ? $to : null; // Ensure that all of the headers resolved. if (!is_null($headers['from']) && !is_null($headers['sent']) && !is_null($headers['to'])) { $headers['headers_ok'] = true; } return $headers; }); }
public function __construct(Character $character, array $activities, array $raids, array $arenas, array $stats) { $this->character = $character; $this->dateActivityStarted = carbon($activities['dateActivityStarted']); $lastReset = last_weekly(); $nextReset = next_weekly(); // raid completion status $raidsCompleted = []; foreach ($raids as $raid) { $activityHash = (string) $raid['activityDetails']['referenceId']; $activity = manifest()->activity($activityHash); $activityId = sha1($activity->activityName); $activityLevel = $activity->activityLevel; $completed = (bool) array_get($raid, 'values.completed.basic.value', false); $date = carbon($raid['period']); if (!isset($raidsCompleted[$activityId])) { $raidsCompleted[$activityId] = null; } if ($completed && $date > $lastReset && $date < $nextReset) { if ($activityLevel > $raidsCompleted[$activityId]) { $raidsCompleted[$activityId] = $activityLevel; } } } // arena completion status $arenasCompleted = []; foreach ($arenas as $arena) { $activityHash = (string) $arena['activityDetails']['referenceId']; $completed = (bool) array_get($arena, 'values.completed.basic.value', false); $date = carbon($arena['period']); if (!array_key_exists($activityHash, $arenasCompleted)) { $arenasCompleted[$activityHash] = false; } if ($completed && $date > $lastReset && $date < $nextReset) { $arenasCompleted[$activityHash] = $completed; } } // stats grouped by activity hash $statsArray = []; foreach ($stats as $k => $stat) { $activityHash = (string) $stat['activityHash']; $statsArray[$activityHash] = new StatisticsCollection($stat['values']); } // build ActivityCollection foreach ($activities['available'] as $activity) { $activityHash = (string) $activity['activityHash']; $activityStats = array_get($statsArray, $activityHash); $activity = new Activity($character, $activity, $activityStats); $activityId = sha1($activity->activityName); if ($activity->isCompleted && ($activity->isWeekly() || $activity->isDaily())) { $lastReset = $activity->isWeekly() ? last_weekly() : last_daily(); $activity->isCompleted = $character->dateLastPlayed > $lastReset; } $this->put($activityHash, $activity); if ($activity->isRaid()) { $activity->isCompleted = false; $activityLevelCompleted = array_get($raidsCompleted, $activityId); if (!$activityLevelCompleted) { continue; } if ($activity->activityLevel <= $activityLevelCompleted) { $activity->isCompleted = true; } } if ($activity->isArena()) { $activity->isCompleted = array_get($arenasCompleted, $activityHash, false); } } }