コード例 #1
0
ファイル: EmailController.php プロジェクト: bix0r/Stjornvisi
 /**
  * Send mail
  *
  * @return array|ViewModel
  */
 public function sendAction()
 {
     $sm = $this->getServiceLocator();
     $userService = $sm->get('Stjornvisi\\Service\\User');
     //AUTHENTICATION
     //  get authentication service
     $auth = new AuthenticationService();
     $access = $userService->getTypeByGroup($auth->hasIdentity() ? $auth->getIdentity()->id : null, null);
     //ACCESS
     //  user has access
     if ($access->is_admin) {
         //POST
         //  post request
         if ($this->request->isPost()) {
             $post = $this->getRequest()->getPost();
             /** @var $post \ArrayObject */
             $form = new GroupEmail();
             $form->setData($post);
             $form->setAttribute('action', $this->url()->fromRoute('email/send', ['type' => $this->params()->fromRoute('type', 'allir')]));
             //VALID
             //  form is valid
             if ($form->isValid()) {
                 //TEST
                 //  send out test e-mail
                 if ($post->offsetGet('test')) {
                     $this->getEventManager()->trigger('notify', $this, ['action' => 'Stjornvisi\\Notify\\All', 'data' => (object) array('recipients' => $this->params()->fromRoute('type', 'allir'), 'test' => true, 'subject' => $form->get('subject')->getValue(), 'body' => $form->get('body')->getValue(), 'sender_id' => (int) $auth->getIdentity()->id)]);
                     return new ViewModel(array('form' => $form, 'msg' => "Prufupóstur hefur verið sendur á {$auth->getIdentity()->email}"));
                     //SEND
                     //  send out full e-mail
                 } else {
                     $this->getEventManager()->trigger('notify', $this, ['action' => 'Stjornvisi\\Notify\\All', 'data' => (object) array('recipients' => $this->params()->fromRoute('type', 'allir'), 'test' => false, 'subject' => $form->get('subject')->getValue(), 'body' => $form->get('body')->getValue(), 'sender_id' => (int) $auth->getIdentity()->id)]);
                     return new ViewModel(array('form' => null, 'msg' => 'Póstur sendur'));
                 }
                 //INVALID
                 // the form is invalid
             } else {
                 return new ViewModel(array('form' => $form, 'msg' => ''));
             }
             //QUERY
             //  get request
         } else {
             $from = new GroupEmail();
             $from->setAttribute('action', $this->url()->fromRoute('email/send', ['type' => $this->params()->fromRoute('type', 'allir')]));
             return new ViewModel(array('form' => $from));
         }
         //NO ACCESS
     } else {
         $this->getResponse()->setStatusCode(401);
         $model = new ViewModel();
         $model->setTemplate('error/401');
         return $model;
     }
 }
コード例 #2
0
ファイル: EventController.php プロジェクト: bix0r/Stjornvisi
 /**
  * Send mail to members of group(s) of events.
  *
  * @return ViewModel
  */
 public function sendMailAction()
 {
     $sm = $this->getServiceLocator();
     $userService = $sm->get('Stjornvisi\\Service\\User');
     $eventService = $sm->get('Stjornvisi\\Service\\Event');
     $authService = $sm->get('AuthenticationService');
     //EVENT FOUND
     //  an event with this ID was found
     if (($event = $eventService->get($this->params()->fromRoute('id', 0))) != false) {
         $groupIds = $this->extractGroupIds($event->groups);
         $access = $userService->getTypeByGroup($authService->hasIdentity() ? $authService->getIdentity()->id : null, $groupIds);
         //ACCESS GRANTED
         //  user has access
         if ($access->is_admin || $access->type >= 1) {
             $form = new Email();
             $form->setAttribute('action', $this->url()->fromRoute('vidburdir/send-mail', ['id' => $event->id, 'type' => $this->params()->fromRoute('type', 'allir')]));
             //POST
             //	post request
             if ($this->request->isPost()) {
                 $form->setData($this->request->getPost());
                 //VALID
                 //	valid form
                 if ($form->isValid()) {
                     $this->getEventManager()->trigger('notify', $this, ['action' => 'Stjornvisi\\Notify\\Event', 'data' => (object) ['event_id' => $event->id, 'recipients' => $this->params()->fromRoute('type', 'allir'), 'test' => (bool) $this->params()->fromPost('test', false), 'subject' => $form->get('subject')->getValue(), 'body' => $form->get('body')->getValue(), 'user_id' => $authService->getIdentity()->id]]);
                     return new ViewModel(['event' => $event, 'form' => $form, 'msg' => $this->params()->fromPost('test', false) ? 'Prufupóstur sendur' : 'Póstur sendur']);
                     //INVALID
                     //	invalid form
                 } else {
                     return new ViewModel(['event' => $event, 'form' => $form, 'msg' => false]);
                 }
                 //QUERY
                 //	get request
             } else {
                 return new ViewModel(['event' => $event, 'form' => $form, 'msg' => false]);
             }
             //ACCESS DENIED
             //	403
         } else {
             $this->getResponse()->setStatusCode(401);
             $model = new ViewModel();
             $model->setTemplate('error/401');
             return $model;
         }
     }
 }