Exemple #1
0
 public function setSearchRecord($data, $searched)
 {
     $search = new Search();
     $search->setDate(new \DateTime());
     $search->setType($searched);
     $em = $this->em;
     if ('opportunity' === $searched && !array_key_exists('focuses', $data) && !array_key_exists('skills', $data)) {
         $focus = $em->getRepository('TruckeeMatchBundle:Focus')->findOneBy(['focus' => 'All']);
         $search->setFocus($focus);
         $skill = $em->getRepository('TruckeeMatchBundle:Skill')->findOneBy(['skill' => 'All']);
         $search->setSkill($skill);
         $search->setType($searched);
         $em->persist($search);
     } else {
         if (array_key_exists('organization', $data) && '' != $data['organization']['organization']) {
             $orgId = $data['organization']['organization'];
             $organization = $em->getRepository('TruckeeMatchBundle:Organization')->find($orgId);
             $search->setOrganization($organization);
         }
         if (array_key_exists('opportunity', $data)) {
             $search->setOpportunity($data['opportunity']);
         }
         if (array_key_exists('focuses', $data)) {
             foreach ($data['focuses'] as $focusId) {
                 $searchClone = clone $search;
                 $focus = $em->getRepository('TruckeeMatchBundle:Focus')->find($focusId);
                 $searchClone->setFocus($focus);
                 $em->persist($searchClone);
             }
         }
         if (array_key_exists('skills', $data)) {
             foreach ($data['skills'] as $skillId) {
                 $skill = $em->getRepository('TruckeeMatchBundle:Skill')->find($skillId);
                 $searchClone = clone $search;
                 $searchClone->setSkill($skill);
                 $searchClone->setType($searched);
                 $em->persist($searchClone);
             }
         }
     }
     $em->flush();
 }