Esempio n. 1
0
 /**
  * @param  \Zend\ServiceManager\ServiceLocatorInterface $sl
  * @return \Secretary\Service\Note
  */
 public function createService(ServiceLocatorInterface $sl)
 {
     $service = new Note();
     /* @var \Doctrine\Orm\EntityManager $em */
     $em = $sl->get('doctrine.entitymanager.orm_default');
     /* @var Crypt $cryptService */
     $cryptService = $sl->get('crypt-service');
     $service->setEntityManager($em);
     $service->setCryptService($cryptService);
     return $service;
 }
Esempio n. 2
0
 /**
  * @return \Zend\View\Model\ViewModel
  */
 public function indexAction()
 {
     if (!$this->zfcUserAuthentication()->hasIdentity()) {
         return new ViewModel();
     }
     $userArray = $this->identity->toArray();
     if ($this->zfcUserAuthentication()->hasIdentity() && $userArray['role'] == 'user') {
         return new ViewModel();
     }
     $this->translator->addTranslationFilePattern('gettext', __DIR__ . '/../../../language', 'note-%s.mo');
     $privateNotes = $this->noteService->fetchUserNotesDashboard($this->identity->getId());
     $groupNotes = $this->noteService->fetchGroupNotesDashboard($this->identity->getId());
     return new ViewModel(array('privateNotes' => $privateNotes, 'groupNotes' => $groupNotes));
 }
Esempio n. 3
0
 /**
  * Remove member from group
  *
  * @return \Zend\View\Model\ViewModel
  */
 public function removeAction()
 {
     $userId = (int) $this->getRequest()->getQuery('user');
     if ($this->groupRecord->getOwner() != $this->identity->getId()) {
         return $this->redirect()->toRoute('secretary/group');
     }
     if (empty($userId) || $userId == $this->identity->getId()) {
         return $this->redirect()->toRoute('secretary/group', array('action' => 'members', 'id' => $this->groupRecord->getId()));
     }
     $membershipCheck = $this->groupService->checkGroupMembership($this->groupRecord->getId(), $userId);
     if (false === $membershipCheck) {
         return $this->redirect()->toRoute('secretary/group', array('action' => 'members', 'id' => $this->groupRecord->getId()));
     }
     // Delete User from Group / Delete Group
     try {
         $groupName = $this->groupRecord->getName();
         $userRecord = $this->userService->getUserById($userId);
         $this->noteService->deleteUserFromGroupNotes($userRecord, $this->groupRecord);
         $this->groupService->removeUserFromGroup($userRecord, $this->groupRecord);
         $this->flashMessenger()->addSuccessMessage(sprintf($this->translator->translate('User "%s" was successfully removed from group "%s"'), $userRecord->getDisplayName(), $groupName));
         return $this->redirect()->toRoute('secretary/group', array('action' => 'members', 'id' => $this->groupRecord->getId()));
     } catch (\Exception $e) {
         $this->flashMessenger()->addErrorMessage('An error occurred: ' . $e->getMessage());
         return $this->redirect()->toRoute('secretary/group', array('action' => 'members', 'id' => $this->groupRecord->getId()));
     }
 }
Esempio n. 4
0
 /**
  * @param DoctrineResourceEvent $e
  * @return \ZF\ApiProblem\ApiProblem
  */
 public function patch(DoctrineResourceEvent $e)
 {
     /** @var Note $note */
     $note = $e->getEntity();
     $user = $this->getUser($e, $this->userService);
     $editCheck = $this->noteService->checkNoteEditPermission($user->getId(), $note->getId());
     if ($editCheck === false) {
         return new ApiProblem(403, 'User is not allowed to edit note');
     }
 }
Esempio n. 5
0
 /**
  * @param  int    $id
  * @param  string $action
  * @return \Secretary\Form\KeyRequest
  */
 protected function getKeyRequestForm($id, $action = 'view')
 {
     $formUrl = $this->url()->fromRoute('secretary/note', array('action' => $action, 'id' => $id));
     return $this->noteService->getKeyRequestForm($formUrl);
 }