コード例 #1
0
ファイル: InitializeJob.php プロジェクト: utrenkner/YAWIK
 /**
  * @param Params $params
  * @param bool   $allowDraft
  *
  * @return \Jobs\Entity\Job|object
  * @throws \Doctrine\ODM\MongoDB\LockException
  */
 public function get(Params $params, $allowDraft = false)
 {
     /* @var \Jobs\Repository\Job $jobRepository */
     $jobRepository = $this->repositoryService->get('Jobs/Job');
     $idFromRoute = $params('id', 0);
     $idFromQuery = $params->fromQuery('id', 0);
     $idFromSubForm = $params->fromPost('job', 0);
     $id = empty($idFromRoute) ? empty($idFromQuery) ? $idFromSubForm : $idFromQuery : $idFromRoute;
     if (empty($id) && $allowDraft) {
         $this->acl->__invoke('Jobs/Manage', 'new');
         $user = $this->auth->getUser();
         /** @var \Jobs\Entity\Job $job */
         $job = $jobRepository->findDraft($user);
         if (empty($job)) {
             $job = $jobRepository->create();
             $job->setIsDraft(true);
             $job->setUser($user);
             $this->repositoryService->store($job);
         }
         return $job;
     }
     $job = $jobRepository->find($id);
     if (!$job) {
         throw new \RuntimeException('No job found with id "' . $id . '"');
     }
     return $job;
 }
コード例 #2
0
ファイル: PasswordController.php プロジェクト: vfulco/YAWIK
 public function indexAction()
 {
     if (!($user = $this->authenticationService->getUser())) {
         throw new UnauthorizedAccessException('You must be logged in.');
     }
     /** @var Request $request */
     $request = $this->getRequest();
     $this->form->bind($user);
     if ($request->isPost()) {
         $this->form->setData($request->getPost()->toArray());
         if ($this->form->isValid()) {
             $this->repositoryService->store($user);
             $vars = array('valid' => true);
             $this->notification()->success('Password successfully changed');
         } else {
             // form is invalid
             $vars = array('valid' => false);
             // @TODO the messages are distributed to the hierarchy of the subElements, either we reduce that to flat plain text, or we make a message handling in JS
             $messages = $this->form->getMessages();
             $this->notification()->error('Password could not be changed');
         }
     }
     $vars['form'] = $this->form;
     if ($request->isXmlHttpRequest()) {
         return new JsonModel($vars);
     }
     return $vars;
 }
コード例 #3
0
 public function indexAction()
 {
     $user = $this->auth->getUser();
     $error = false;
     if ($this->params()->fromPost('confirm')) {
         if ($this->dependencies->removeItems($user)) {
             $this->auth->clearIdentity();
             $user->setStatus(Status::INACTIVE);
             return $this->redirect()->toRoute('lang');
         } else {
             $error = true;
         }
     }
     return ['lists' => $this->dependencies->getLists(), 'user' => $user, 'limit' => 20, 'error' => $error];
 }
コード例 #4
0
 /**
  * @param Params $params
  * @param bool   $allowDraft
  *
  * @return object|\Organizations\Entity\Organization
  * @throws UnauthorizedAccessException
  * @throws \Doctrine\ODM\MongoDB\LockException
  * @throws NotFoundException
  */
 public function process(Params $params, $allowDraft = true)
 {
     $repositories = $this->repositoryService;
     /* @var \Organizations\Repository\Organization $organizationRepository */
     $organizationRepository = $this->repositoryService->get('Organizations/Organization');
     $idFromRoute = $params('id', 0);
     $idFromSubForm = $params()->fromPost('id', 0);
     $user = $this->auth->getUser();
     /* @var $user \Auth\Entity\UserInterface */
     /* @var $organizationId string */
     $organizationId = empty($idFromRoute) ? $idFromSubForm : $idFromRoute;
     $editOwnOrganization = '__my__' === $organizationId;
     if ($editOwnOrganization) {
         /* @var $userOrg \Organizations\Entity\OrganizationReference */
         $userOrg = $user->getOrganization();
         if ($userOrg->hasAssociation() && !$userOrg->isOwner()) {
             throw new UnauthorizedAccessException('You may not edit this organization as you are only employer.');
         }
         $organizationId = $userOrg->hasAssociation() ? $userOrg->getId() : 0;
     }
     if (empty($organizationId) && $allowDraft) {
         /* @var $organization \Organizations\Entity\Organization */
         $organization = $organizationRepository->findDraft($user);
         if (empty($organization)) {
             $organization = $organizationRepository->create();
             $organization->setIsDraft(true);
             $organization->setUser($user);
             if (!$editOwnOrganization) {
                 /* @var $parent \Organizations\Entity\OrganizationReference */
                 $parent = $user->getOrganization();
                 if (!$parent->hasAssociation()) {
                     throw new MissingParentOrganizationException('You cannot create organizations, because you do not belong to a parent organization. Use "User menu -> create my organization" first.');
                 }
                 $organization->setParent($parent->getOrganization());
             }
             $repositories->store($organization);
         }
         return $organization;
     }
     $organization = $organizationRepository->find($organizationId);
     if (!$organization) {
         throw new NotFoundException($organizationId);
     }
     $this->acl->check($organization, 'edit');
     return $organization;
 }
コード例 #5
0
ファイル: ManageController.php プロジェクト: utrenkner/YAWIK
 /**
  * Deactivate a job posting
  *
  * @return null|ViewModel
  */
 public function deactivateAction()
 {
     $user = $this->auth->getUser();
     $jobEntity = $this->initializeJob()->get($this->params());
     try {
         $jobEntity->changeStatus(Status::INACTIVE, sprintf("Job was deactivated by %s", $user->getInfo()->getDisplayName()));
         $this->notification()->success('Job has been deactivated');
     } catch (\Exception $e) {
         $this->notification()->danger('Job could not be deactivated');
     }
     return $this->save(array('page' => 2));
 }
コード例 #6
0
ファイル: Auth.php プロジェクト: cross-solution/yawik
 /**
  * Checks, if a user is an Admin
  *
  * @return bool
  */
 public function isAdmin()
 {
     return $this->authenticationService->getUser()->getRole() == User::ROLE_ADMIN;
 }