/** * @inheritdoc */ public function matchUser(Job $job) { //Create Neo4j query return $this->getListByQuery(sprintf('MATCH (j:Job)-[r1:REQUIRE_SKILL]->(s:Skill) ,(s)<-[e2:HAS_SKILL]-(u:User) WHERE ID(j) = %s AND (e2.score / e2.count) > 0.5 RETURN u, SUM(e2.score / e2.count) / COUNT(e2.score / e2.count) AS point, COUNT(e2) AS number_of_skill ORDER BY number_of_skill DESC, point DESC LIMIT 50', $job->getId())); }
/** * @param Job $job * @param User $user * @param array $friends * @return array */ public function insertNew(Job $job, User $user, $friends) { $result = array(); $company = $job->getCompany(); /** @var FacebookUser $friend */ foreach ($friends as $friend) { $jobSkill = array(); $idJobMatch = $job->getId() . '-' . $user->getId() . '-' . $friend->getId(); /** @var Skill $skill */ foreach ($job->getSkills() as $skill) { $jobSkill[] = array('id' => $skill->getId(), 'name' => $skill->getName()); } $jobMatch = new JobMatch(); $jobMatch->setId($idJobMatch); $jobMatch->setJobId($job->getId()); $jobMatch->setJob(array('id' => $job->getId(), 'name' => $job->getName(), 'skill' => $jobSkill)); if (!empty($company)) { $jobMatch->setCompanyId($company->getId()); $jobMatch->setCompany(array('id' => $company->getId(), 'name' => $company->getName())); } $jobMatch->setUser1Id($user->getId()); $jobMatch->setUser1(array('id' => $user->getId(), 'name' => $user->getName(), 'avatar' => $user->getAvatar(), 'email' => $user->getEmail())); $jobMatch->setUser2Id($friend->getId()); $jobMatch->setUser2(array('id' => $friend->getId(), 'name' => $friend->getName(), 'email' => $friend->getEmail())); try { $this->entityManager->persist($jobMatch); $this->entityManager->flush(); } catch (\Exception $ex) { } } return $result; }
/** * @param Job $entity * @return Job */ protected function persist($entity) { $companyId = $entity->getCompanyId(); $company = $this->getCompanyManager()->find($companyId); $skills = $this->getSkillManager()->findByArrayId($entity->getSkillIds()); $entity->setCompany($company); $entity->setSkills($skills); return $entity; }