/** * Add company_has_user * * @author Hrayr Shahbazyan * @param array $data * @return array */ public function addCompanyHasUser(array $data) { //Get entity manager $em = $this->getEntityManager(); if (isset($data['company_team_id'])) { $companyTeam = $this->getCompanyTeamInArrayByCompanyAndGroup($data['company_id'], $data['company_team_id']); //@todo make global logic for group id } else { $companyTeam = $this->getCompanyTeamInArrayByCompanyAndGroup($data['company_id'], 3); //@todo make global logic for group id } //Input filters $inputFilter = new \Company\InputFilter\CompanyHasUser(); $customFilter = $inputFilter->addCompanyHasUser($this->getCompanyRepo(), $this->getUsersRepo()); $inputFilter->setInputFilter($customFilter); $filter = $inputFilter->getInputFilter(); $filter->setData($data); if ($filter->isValid()) { $companyHasUser = new \Company\Entity\CompanyHasUser(); $companyHasUser->setCompany($this->getCompanyRepo()->find($data['company_id']))->setUser($this->getUsersRepo()->find($data['user_id']))->setTeam($this->getTeamsRepo()->find($companyTeam[0]['id'])); $em->persist($companyHasUser); $em->flush(); $result = array(); $result['status_code'] = 201; $result['company_has_user_id'] = $companyHasUser->getId(); return $result; } else { return $this->getErrorMessages($filter); } }
/** * Edit invitation * * @author Stoyan Rangelov * @param integer $id * @param array $data * @return array */ public function editInvitation($id, $data) { $data['id'] = $id; $em = $this->getEntityManager(); $status = 0; $invitation = $this->getInvitationById($id); if ($data['status'] == 1) { $invitation->setIsAccepted($data['status']); $companyTeam = $this->getCompanyTeamInArrayByCompanyAndGroup($invitation->getCompany()->getId(), 3); //@todo make global logic for group id $companyHasUser = new \Company\Entity\CompanyHasUser(); $companyHasUser->setCompany($this->getCompanyRepo()->find($invitation->getCompany()->getId()))->setUser($this->getUsersRepo()->find($data['user_id']))->setTeam($this->getTeamsRepo()->find($companyTeam[0]['id'])); $em->persist($companyHasUser); $em->flush(); $status = 1; } else { $invitation->setIsDeclined($data['status']); $status = 0; } $invitation->setUpdatedAt(new \DateTime()); $em->merge($invitation); $em->flush(); $result = array(); $result['status_code'] = 200; $result['status'] = $status; $result['company_id'] = $invitation->getCompany()->getId(); return $result; }