function build_calendar($month, $year, $dateArray) { // Create array containing abbreviations of days of week. $daysOfWeek = array('S', 'M', 'T', 'W', 'T', 'F', 'S'); // What is the first day of the month in question? $firstDayOfMonth = mktime(0, 0, 0, $month, 1, $month == 0 ? $year + 1 : $year); // How many days does this month contain? $numberDays = date('t', $firstDayOfMonth); // Retrieve some information about the first day of the // month in question. $dateComponents = getdate($firstDayOfMonth); // What is the name of the month in question? $monthName = $dateComponents['month']; // What is the index value (0-6) of the first day of the // month in question. $dayOfWeek = $dateComponents['wday']; // Create the table tag opener and day headers $calendar = "<table class='calendar'>"; $calendar .= "<caption>{$monthName} {$year}</caption>"; $calendar .= "<tr>"; // Create the calendar headers foreach ($daysOfWeek as $day) { $calendar .= "<th class='header'>{$day}</th>"; } // Create the rest of the calendar // Initiate the day counter, starting with the 1st. $currentDay = 1; $calendar .= "</tr><tr>"; // The variable $dayOfWeek is used to // ensure that the calendar // display consists of exactly 7 columns. if ($dayOfWeek > 0) { $calendar .= "<td colspan='{$dayOfWeek}' class='calendar-buffer'> </td>"; } $month = str_pad($month, 2, "0", STR_PAD_LEFT); while ($currentDay <= $numberDays) { // Seventh column (Saturday) reached. Start a new row. if ($dayOfWeek == 7) { $dayOfWeek = 0; $calendar .= "</tr><tr>"; } $currentDayRel = str_pad($currentDay, 2, "0", STR_PAD_LEFT); if ($month == 00) { $month = 12; } $date = "{$year}-{$month}-{$currentDayRel}"; $refDate = new DateTime($month . "/" . $currentDay . "/" . $year); $gameClass = GameSession::where('date', $refDate)->exists() ? 'game-day' : ''; $calendar .= "<td class='day {$gameClass}' rel='{$date}'>{$currentDay}</td>"; // Increment counters $currentDay++; $dayOfWeek++; } // Complete the row of the last week in month, if necessary if ($dayOfWeek != 7) { $remainingDays = 7 - $dayOfWeek; $calendar .= "<td class='calendar-buffer' colspan='{$remainingDays}'> </td>"; } $calendar .= "</tr>"; $calendar .= "</table>"; return $calendar; }
public static function render($body) { //First off, look for tags. $matches = []; $body = preg_replace_callback("/\\[\\[([\\w\\W]+?)\\]\\]/", function ($match) { $arguments = explode("/", $match[1]); switch (strtolower($arguments[0])) { case "change": $id = intval($arguments[1]); $char = Character::find($id); if ($char && (Auth::user()->isStoryteller() || Auth::user()->id == $char->user_id) && sizeof($arguments) == 3) { return View::make('partials/changes', ['character' => $char, 'version' => $arguments[2]])->render(); } break; case "questionnaire": $id = intval($arguments[1]); $char = Character::find($id); if ($char && (Auth::user()->isStoryteller() || Auth::user()->id == $char->user_id)) { return View::make('partials/questionnaire', ['character' => $char])->render(); } break; case "handbook": return "<div class='handbook-page'>" . View::make('partials/handbookPage', ['title' => $arguments[1]])->render() . "</div>"; case 'influence': if (sizeof($arguments) == 2) { $capName = $arguments[1]; $cap = InfluenceCap::whereHas('definition', function ($q) use($capName) { $q->where('name', $capName); })->first(); if ($cap) { return $cap->capacityString(); } } break; case "character": $char = Auth::user()->activeCharacter(); if (sizeof($arguments) == 3 && $char) { $type = $arguments[1]; $value = $arguments[2]; switch (strtolower($type)) { case "background": return $char->getBackgroundDots($value); } } break; case "deadline": //Determine if we're past the deadline. $now = new DateTime(); $now->setTime(0, 0); $nextGame = GameSession::where('date', '>=', $now)->orderBy('date')->first(); if ($nextGame) { $date = new DateTime($nextGame->date); $date->setTimezone(new DateTimeZone("America/Chicago")); $date->modify("6 hours"); //Fix timezone offset $date->setTime(19, 00); $deadlineDate = new DateTime($nextGame->date); $deadlineDate->setTimezone(new DateTimeZone("America/Chicago")); $deadlineDate->modify('previous Wednesday, 6 PM CST'); if (new DateTime() > $deadlineDate) { return '<span class="past-deadline">No more changes can be submitted this cycle.</span>'; } return 'Changes can still be submitted.'; } return 'Could not find the next session'; break; } return $match[0]; }, $body); //Check for @mentions $body = preg_replace_callback("/(?<=^|(?<=[^a-zA-Z0-9-_\\.]))@([A-Za-z0-9!#\$%\\-^&*]+|{[A-Za-z]+[A-Za-z0-9 !#\$%\\-^&*]+})/", function ($match) { $username = $match[1]; if (strtolower($username) == "andrew") { $username = "******"; } if ($username[0] == "{") { $username = substr($username, 1, strlen($username) - 2); } $user = User::where('username', 'like', $username)->first(); if ($user) { return "<div class='mention'>@" . $user->mailtoLink() . "</div>"; } return $username; }, $body); return $body; }
public function gamesMissed() { $last_game = GameSessionCheckIn::where('character_id', $this->id)->join('sessions as session', 'session.id', '=', 'session_id')->orderBy('date', 'desc')->first(); if ($last_game) { return GameSession::where('date', '>', $last_game->date)->where('submitted', 1)->count(); } return -1; }