public function hydrate(array $data, $object) { /** @var Entity\Job $object */ $object = parent::hydrate($data, $object); /** @var Organization $organization */ if ($organization = $this->organizationRepository->find($data['companyId'])) { $object->setOrganization($organization); } else { $object->setOrganization(null); } return $object; }
/** */ public function testAction() { $queryName = uniqid('query'); list($data, $expected) = $this->prepareDataAndExpected(); $user = UserEntityProvider::createEntityWithRandomData(); $request = new Request(); $request->setMethod(Request::METHOD_GET); $request->setQuery(new Parameters(array('q' => $queryName))); $this->authControllerPluginMock->expects($this->once())->method('__invoke')->with(null)->will($this->returnSelf()); $this->authControllerPluginMock->expects($this->once())->method('getUser')->willReturn($user); $this->organizationRepoMock->expects($this->once())->method('getTypeAheadResults')->with($queryName, $user)->willReturn($data); /** @var JsonModel $result */ $result = $this->controller->dispatch($request); $this->assertResponseStatusCode(Response::STATUS_CODE_200); $this->assertSame($expected, $result->getVariables()); }
/** * Gets the organization entity. * * @param bool $allowDraft * * @return \Organizations\Entity\Organization * @throws \RuntimeException */ protected function getOrganization($allowDraft = true) { $services = $this->getServiceLocator(); $repositories = $services->get('repositories'); // @TODO three different method to obtain the job-id ?, simplify this $id_fromRoute = $this->params('id', 0); $id_fromSubForm = $this->params()->fromPost('id', 0); $user = $this->auth()->getUser(); /* @var $user \Auth\Entity\UserInterface */ /* @var $organizationId string */ $organizationId = empty($id_fromRoute) ? $id_fromSubForm : $id_fromRoute; $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 = $this->repository->findDraft($user); if (empty($organization)) { $organization = $this->repository->create(); $organization->setIsDraft(true); $organization->setUser($user); if (!$editOwnOrganization) { /* @var $parent \Organizations\Entity\OrganizationReference */ $parent = $user->getOrganization(); if (!$parent->hasAssociation()) { throw new \RuntimeException('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 = $this->repository->find($organizationId); if (!$organization) { throw new \RuntimeException('No Organization found with id "' . $organizationId . '"'); } return $organization; }
/** * Loads the organization from the database and sets the reference type. */ protected function load() { if (null !== $this->_type) { return; } // Is the user the owner of the referenced organization? $org = $this->_repository->findByUser($this->_userId); if ($org) { $this->_type = self::TYPE_OWNER; $this->_organization = $org; return; } // Is the user employed by the referenced organization? $org = $this->_repository->findByEmployee($this->_userId); if ($org) { $this->_type = self::TYPE_EMPLOYEE; $this->_organization = $org; return; } // It seems the user is not associated with an organization. $this->_type = self::TYPE_NONE; }
/** * @see \Auth\Dependency\ListInterface::getEntities() */ public function getEntities(User $user) { return $this->repository->getUserOrganizations($user->getId()); }