Пример #1
0
 public function __construct($name = null)
 {
     parent::__construct('announcement');
     $this->add(['name' => 'title', 'type' => 'text', 'attributes' => ['id' => 'title', 'required' => true], 'options' => ['label' => 'Title']]);
     $this->add(['name' => 'content', 'type' => 'textarea', 'attributes' => ['id' => 'content', 'required' => true], 'options' => ['label' => 'Announcement', 'bootstrap' => ['help' => ['style' => 'block', 'content' => 'You can use <a href="http://daringfireball.net/projects/markdown/basics" target="_blank">markdown</a> to format your text.</a>']]]]);
     $this->add(['name' => 'lowrank', 'type' => 'select', 'attributes' => ['id' => 'lowrank', 'required' => true, 'value' => \NightsWatch\Entity\User::RANK_PRIVATE], 'options' => ['label' => 'Rank', 'value_options' => \NightsWatch\Entity\User::getRankNames(), 'bootstrap' => ['help' => ['style' => 'block', 'content' => 'The lowest rank that\'s allowed to view this announcement']]]]);
     $this->add(['name' => 'preview', 'type' => 'hidden', 'attributes' => ['value' => 0]]);
     $this->add(['name' => 'submit', 'type' => 'submit', 'attributes' => ['value' => 'Preview', 'id' => 'submit-announcement', 'class' => 'btn btn-primary']]);
 }
Пример #2
0
 public function __construct($name = null, $includeEmailCheckbox = false)
 {
     parent::__construct('event');
     $this->add(['name' => 'id', 'type' => 'hidden', 'attributes' => ['id' => 'id', 'required' => false], 'options' => ['label' => 'ID']]);
     $this->add(['name' => 'name', 'type' => 'text', 'attributes' => ['id' => 'name', 'required' => true], 'options' => ['label' => 'Name']]);
     $this->add(['name' => 'leader', 'type' => 'text', 'attributes' => ['id' => 'leader', 'required' => false], 'options' => ['label' => 'Leader', 'bootstrap' => ['help' => ['style' => 'block', 'content' => 'If left blank, you will be defaulted to the Leader of the Event.']]], 'validators' => [['name' => UsernameExists::class, 'options' => ['entityManager' => $this->getEntityManager()]]]]);
     $this->add(['name' => 'absolutetime', 'type' => 'hidden', 'attributes' => ['id' => 'absolutetime', 'required' => false]]);
     $this->add(['name' => 'date', 'type' => 'text', 'attributes' => ['id' => 'date', 'required' => true, 'class' => 'datepicker'], 'options' => ['label' => 'Date', 'bootstrap' => ['help' => ['style' => 'block', 'content' => 'Local Time.  Events that take place in the past will not be emailed.']]]]);
     $this->add(['name' => 'time', 'type' => Time::class, 'attributes' => ['id' => 'time', 'required' => true, 'min' => '00:00', 'max' => '23:59', 'step' => 60], 'options' => ['label' => 'Time (local)', 'format' => 'H:i', 'bootstrap' => ['help' => ['style' => 'block', 'content' => 'Local Time']]]]);
     $this->add(['name' => 'offset', 'type' => 'text', 'attributes' => ['id' => 'offset', 'required' => true, 'readonly' => true, 'class' => 'jsoffset disabled'], 'options' => ['label' => 'GMT Offset', 'bootstrap' => ['help' => ['style' => 'block', 'content' => 'This is your offset from GMT in seconds']]]]);
     $this->add(['name' => 'region', 'type' => 'select', 'attributes' => ['id' => 'region', 'required' => true], 'options' => ['label' => 'Region Instance', 'value_options' => Event::getRegionNames(), 'bootstrap' => ['help' => ['style' => 'block', 'content' => 'The region the event will take place on.  (For differing database instances)']]]]);
     $this->add(['name' => 'description', 'type' => 'textarea', 'attributes' => ['id' => 'description', 'required' => true], 'options' => ['label' => 'Description', 'bootstrap' => ['help' => ['style' => 'block', 'content' => 'You can use <a href="http://daringfireball.net/projects/markdown/basics" target="_blank">markdown</a> to format your text.</a>']]]]);
     $this->add(['name' => 'eventtype', 'type' => 'select', 'attributes' => ['id' => 'eventtype', 'required' => true, 'value' => \NightsWatch\Entity\Event::EVENT_RANGING], 'options' => ['label' => 'Event Type', 'value_options' => Event::getTypeNames()]]);
     $this->add(['name' => 'lowrank', 'type' => 'select', 'attributes' => ['id' => 'lowrank', 'required' => true, 'value' => \NightsWatch\Entity\User::RANK_PRIVATE], 'options' => ['label' => 'Rank', 'value_options' => \NightsWatch\Entity\User::getRankNames(), 'bootstrap' => ['help' => ['style' => 'block', 'content' => 'The lowest rank that\'s allowed to attend this event']]]]);
     $this->add(['name' => 'preview', 'type' => 'hidden', 'attributes' => ['value' => 0]]);
     if ($includeEmailCheckbox) {
         $this->add(['name' => 'sendemail', 'type' => 'checkbox', 'attributes' => ['checked_value' => 1, 'unchecked_value' => 0], 'options' => ['label' => 'Major Changes', 'bootstrap' => ['help' => ['style' => 'block', 'content' => 'Sends email.  Check if you have changed time, region, or other important information.  Do not check if you have fixed typos.']]]]);
     }
     $this->add(['name' => 'submit', 'type' => 'submit', 'attributes' => ['value' => 'Preview', 'id' => 'submit-event', 'class' => 'btn btn-primary']]);
 }
Пример #3
0
    public function previewAction()
    {
        $this->updateLayoutWithIdentity();
        if ($this->disallowRankLessThan(User::RANK_CORPORAL)) {
            return false;
        }
        $session = new SessionContainer('NightsWatch\\Event\\Create');
        if (empty($session->name)) {
            $this->redirect()->toRoute('home', ['contoller' => 'event', 'action' => 'create']);
            return false;
        }
        $userRepo = $this->getEntityManager()->getRepository('NightsWatch\\Entity\\User');
        $eventRepo = $this->getEntityManager()->getRepository('NightsWatch\\Entity\\Event');
        $leader = $session->leader;
        if (!empty($leader)) {
            $leader = $userRepo->findOneBy(['username' => $leader]);
        }
        if (empty($leader)) {
            $leader = $this->getIdentityEntity();
        }
        $newEvent = false;
        if (isset($session->id) && $session->id != false) {
            $event = $eventRepo->find($session->id);
            if (is_null($event)) {
                throw new Exception('No such event found');
            }
        } else {
            $newEvent = true;
            $event = new Event();
        }
        $event->name = $session->name;
        $event->description = $session->description;
        if ($newEvent) {
            $event->user = $this->getIdentityEntity();
        }
        $event->start = new \DateTime($session->date . ' ' . $session->time);
        $event->region = $session->region;
        $event->leader = $leader;
        $event->type = $session->type;
        $offset = $session->offset + date('Z');
        $add = $offset > 0 ? true : false;
        $offset = abs($offset);
        $interval = new \DateInterval('PT' . $offset . 'S');
        if ($add) {
            $event->start->add($interval);
        } else {
            $event->start->sub($interval);
        }
        $event->lowestViewableRank = $session->rank;
        if ($this->getRequest()->isPost()) {
            $this->getEntityManager()->persist($event);
            $this->getEntityManager()->flush();
            $event->user = $this->getIdentityEntity();
            $session->name = '';
            // Send out the Emails
            $sendSpecified = isset($session->sendemail) && (bool) $session->sendemail;
            $sendEmails = $newEvent || $sendSpecified;
            if ($sendEmails) {
                $criteria = Criteria::create()->where(Criteria::expr()->gte('rank', $event->lowestViewableRank));
                /** @var User[] $users */
                $users = $userRepo->matching($criteria);
                $mail = new \Zend\Mail\Message();
                $mail->setSubject('[NightsWatch] Event: ' . $event->name);
                $mail->setFrom(new Address('*****@*****.**', $event->user->username));
                $mail->setTo(new Address('*****@*****.**', 'Members'));
                $headers = $mail->getHeaders();
                if ($newEvent) {
                    $headers->addHeaderLine('Message-Id', '<event-' . $event->id . '@threads.minez-nightswatch.com>');
                } else {
                    $headers->addHeaderLine('References', '<event-' . $event->id . '@threads.minez-nightswatch.com>');
                    $headers->addHeaderLine('In-Reply-To', '<event-' . $event->id . '@threads.minez-nightswatch.com>');
                }
                $headers->addHeaderLine('Threading-Id', '<event-' . $event->id . '@threads.minez-nightswatch.com>');
                $mail->setEncoding('UTF-8');
                $url = $this->url()->fromRoute('id', ['controller' => 'event', 'action' => 'view', 'id' => $event->id], ['force_canonical' => true]);
                $niceDate = $event->start->format('M j, Y');
                $niceTime = $event->start->format('H:i T');
                $region = $event->getRegionName();
                // Create a signature
                $title = trim($event->user->getTitleOrRank());
                if ($newEvent) {
                    $lead = 'A new event has been posted to the calendar.';
                } else {
                    $lead = 'An event on the calendar has been updated with new, important information.';
                }
                $event->description = "{$lead}  All information concerning this event " . 'is classified and only available to members of rank ' . User::getRankName($event->lowestViewableRank) . " and up.\n\n" . 'You can read the details of this event at https://minez-nightswatch.com/event/' . $event->id . "\n\nEvent Details:  \nDate: {$niceDate}  \nTime: {$niceTime}  \nRSVP: [{$url}]({$url})  " . ($event->region > 0 ? "\nRegion: {$region}" : '') . "\n\n" . "{$event->user->username}  \n*{$title}*";
                // Event Stuff
                // Not Yet Working.  Not sure why.
                $start = clone $event->start;
                $start->setTimezone(new \DateTimeZone('UTC'));
                $dtstart = $start->format('Ymd\\THis\\Z');
                $eventRaw = <<<CALENDAR
BEGIN:VCALENDAR
PRODID:-//NightsWatch//Nights Watch Event Creator//EN
VERSION:2.0
CALSCALE:GREGORIAN
METHOD:REQUEST
BEGIN:VEVENT
UID:event-{$event->id}@minez-nightswatch.com
DTSTART:{$dtstart}
ORGANIZER;CN=Night's Watch:noreply@minez-nightswatch.com
SUMMARY:{$event->name}
END:VEVENT
END:VCALENDAR
CALENDAR;
                $body = new MimeBody();
                $bodyHtml = new MimePart($event->getParsedDescription());
                $bodyHtml->type = Mime::TYPE_HTML;
                $bodyText = new MimePart($event->description);
                $bodyText->type = Mime::TYPE_TEXT;
                $bodyEvent = new MimePart($eventRaw);
                $bodyEvent->type = 'text/calendar';
                $bodyEvent->disposition = Mime::DISPOSITION_INLINE;
                $bodyEvent->encoding = Mime::ENCODING_8BIT;
                $bodyEvent->filename = 'calendar.ics';
                $body->setParts([$bodyHtml, $bodyText, $bodyEvent]);
                $mail->setBody($body);
                foreach ($users as $user) {
                    if ($user->emailNotifications & User::EMAIL_ANNOUNCEMENT > 0) {
                        $mail->addBcc(new Address($user->email, $user->username));
                    }
                }
                $transport = new Sendmail();
                $transport->send($mail);
            }
            $this->redirect()->toRoute('id', ['controller' => 'event', 'id' => $event->id]);
            return false;
        }
        return new ViewModel(['event' => $event, 'user' => $this->getIdentityEntity()]);
    }