Пример #1
0
 /**
  * @param \Zend\Mvc\MvcEvent $event
  * @return void
  */
 public function preDispatch(MvcEvent $event)
 {
     parent::preDispatch($event);
     $action = $event->getRouteMatch()->getParam('action');
     if ($action != 'index' && $action != 'add') {
         $this->groupId = $event->getRouteMatch()->getParam('id');
         if (empty($this->groupId) || !is_numeric($this->groupId)) {
             return $this->redirect()->toRoute('secretary/group');
         }
         $this->groupRecord = $this->groupService->fetchGroup($this->groupId);
         if (empty($this->groupRecord)) {
             return $this->redirect()->toRoute('secretary/group');
         }
     }
     if ($action == 'index' || $action == 'members' || $action == 'edit') {
         $this->msg = false;
         $messages = $this->flashMessenger()->getCurrentErrorMessages();
         if (!empty($messages)) {
             $this->msg = array('error', $messages[0]);
         } else {
             $messages = $this->flashMessenger()->getCurrentSuccessMessages();
             $this->msg = false;
             if (!empty($messages)) {
                 $this->msg = array('success', $messages[0]);
             }
         }
         $this->flashMessenger()->clearMessages();
     }
     $this->translator->addTranslationFilePattern('gettext', __DIR__ . '/../../../language', 'group-%s.mo');
 }
Пример #2
0
 /**
  * Process add form
  *
  * @return \Zend\View\Model\ViewModel
  */
 public function addAction()
 {
     $noteRecord = new NoteEntity();
     $form = $this->getNoteForm($noteRecord);
     $groupForm = $this->getGroupForm();
     $viewVars = array('noteFormLegend' => 'Create Note', 'noteForm' => $form, 'groupForm' => $groupForm);
     if (!$this->getRequest()->isPost()) {
         return new ViewModel($viewVars);
     }
     if ($this->getRequest()->isPost()) {
         $viewVars['msg'] = array('error', 'An error occurred');
         $form->setData($this->getRequest()->getPost());
         if ($form->isValid()) {
             if ($this->getRequest()->getPost('private') == 0) {
                 $groupId = $this->getRequest()->getPost('groupHidden');
                 if (empty($groupId) || !is_numeric($groupId)) {
                     // @todo log stuff here?
                     $viewVars['msg'] = array('error', 'You need to select a group');
                     return new ViewModel($viewVars);
                 }
                 $groupMemberCheck = $this->groupService->checkGroupMembership($groupId, $this->identity->getId());
                 if (false === $groupMemberCheck) {
                     $this->events->trigger('logViolation', __METHOD__ . '::l42', array('message' => sprintf('User: %s wants to add note for GroupID: %s', $this->identity->getEmail(), $groupId)));
                     return new ViewModel($viewVars);
                 }
             }
             if ($this->getRequest()->getPost('private') == 0) {
                 $members = $this->getRequest()->getPost('members');
                 if (empty($members)) {
                     $viewVars['msg'] = array('error', 'Please select a group member to share note with');
                     return new ViewModel($viewVars);
                 }
                 $noteRecord->setGroup($this->groupService->fetchGroup($groupId));
                 $this->noteService->saveGroupNote($this->identity, $form->getData(), $groupId, $members);
             } else {
                 $this->noteService->saveUserNote($this->identity, $form->getData());
             }
             $this->flashMessenger()->addSuccessMessage($this->translator->translate('Note was created successfully'));
             return $this->redirect()->toRoute('secretary/note');
         }
     }
     return new ViewModel($viewVars);
 }