Exemplo n.º 1
0
 public function isAdmin($user, CalendarInterface $calendar)
 {
     if (!$user instanceof UserInterface) {
         return false;
     }
     return $user->equals($calendar->getOwner());
 }
 public function blame(CalendarInterface $calendar)
 {
     $token = $this->securityContext->getToken();
     if (null === $token) {
         throw new \RuntimeException('You must configure a firewall for this route');
     }
     if ($this->securityContext->isGranted('IS_AUTHENTICATED_REMEMBERED')) {
         $calendar->setOwner($token->getUser());
     }
 }
Exemplo n.º 3
0
 public function calendarMonth(CalendarInterface $calendar, $month, $year)
 {
     $time = mktime(0, 0, 0, $month, 1, $year);
     $daysInMonth = date('t', $time);
     $daysInPreviousMonth = $this->getDaysInPreviousMonth($month, $year);
     $runningDay = date('w', $time);
     $daysInWeek = 1;
     $dayCounter = 0;
     $rows = '<tr>';
     for ($i = 0; $i < $runningDay; $i++) {
         $day = $daysInPreviousMonth - ($runningDay - $i);
         $rows .= '<td class="calendar-day-disabled">' . $day . '</td>';
     }
     for ($day = 1; $day <= $daysInMonth; $day++) {
         $rows .= '<td class="calendar-day">';
         $rows .= '<div class="day-number">' . $day . '</div>';
         // @todo Find events from the given calendar falling on this day.
         $dateTime = \DateTime::createFromFormat('Y-m-d', sprintf('%d-%d-%d', $year, $month, $day));
         foreach ($calendar->getEventsOnDay($dateTime) as $event) {
             $rows .= $event->getTitle() . ' &amp; ';
         }
         $rows .= '</td>';
         if (6 == $runningDay) {
             $rows .= '</tr>';
             if ($dayCounter + 1 != $daysInMonth) {
                 $rows .= '<tr>';
             }
             $runningDay = -1;
             $daysInWeek = 0;
         }
         $daysInWeek++;
         $runningDay++;
         $dayCounter++;
     }
     if ($daysInWeek < 8) {
         for ($i = 1, $n = 8 - $daysInWeek; $i <= $n; $i++) {
             $rows .= '<td class="calendar-day-disabled">' . $i . '</td>';
         }
     }
     $rows .= '</tr>';
     return sprintf('<table class="calendar">
             <tr class="calendar-header">
                 <th>Sunday</th>
                 <th>Monday</th>
                 <th>Tuesday</th>
                 <th>Wednesday</th>
                 <th>Thursday</th>
                 <th>Friday</th>
                 <th>Saturday</th>
             </tr>
             %s
         </table>', $rows);
 }
Exemplo n.º 4
0
 protected function canView(TokenInterface $token, CalendarInterface $calendar)
 {
     return $calendar->isPublic() || $this->calendarManager->isAdmin($token->getUser(), $calendar);
 }