コード例 #1
0
 public function load(ObjectManager $manager)
 {
     // UserSkill : 1
     $repository = $manager->getRepository('AppBundle:UserSkill');
     $userSkillEntity = $repository->find(1);
     // UserTeam : 1
     $repository = $manager->getRepository('AppBundle:UserTeam');
     $userTeamEntity = $repository->find(1);
     $userSkillTeamEntity = new UserSkillTeam();
     $userSkillTeamEntity->setUserSkill($userSkillEntity);
     $userSkillTeamEntity->setUserTeam($userTeamEntity);
     $manager->persist($userSkillTeamEntity);
     $manager->flush();
 }
コード例 #2
0
 /**
  * @Route("/userteam/", name="add_user_team", options={"expose"=true})
  * Method("POST")
  */
 public function addUserTeamAction(Request $request)
 {
     $skills = $request->get('skills');
     $teams = $request->get('userteams');
     $em = $this->getDoctrine()->getManager();
     // UserTeams
     $jsonStringUserTeam = json_encode($teams);
     $jsonUserTeamObject = json_decode($jsonStringUserTeam);
     // Create UserTeam foreach team selected
     foreach ($jsonUserTeamObject as $userTeamObject) {
         // $usersIds[] = $userTeamObject->idUser;
         // $teamsIds[] = $userTeamObject->idTeam;
         $userId = $userTeamObject->idUser;
         $teamId = $userTeamObject->idTeam;
         $team = $em->getRepository('AppBundle:Team')->find($teamId);
         $user = $em->getRepository('AppBundle:User')->find($userId);
         $userTeam = new UserTeam();
         $userTeam->setUser($user);
         $userTeam->setTeam($team);
         $em->persist($userTeam);
         $em->flush();
         $userTeamId = $userTeam->getUserTeamId();
         //  Skills
         $jsonstring = json_encode($skills);
         $jsonUserSkillObject = json_decode($jsonstring);
         // Put each UserSkill selected in UserTeam
         foreach ($jsonUserSkillObject as $userSkillObject) {
             $userSkillId = $userSkillObject->idUserSkill;
             $userTeam = $em->getRepository('AppBundle:UserTeam')->find($userTeamId);
             $userSkill = $em->getRepository('AppBundle:UserSkill')->find($userSkillId);
             $userSkillTeam = new UserSkillTeam();
             $userSkillTeam->setUserSkill($userSkill);
             $userSkillTeam->setUserTeam($userTeam);
             $em->persist($userSkillTeam);
             $em->flush();
             $result = true;
         }
     }
     $response = new Response();
     //$response->setContent(json_encode(array('UserTeamId'=>$userTeamId, 'userIds' => $usersIds,'teamsIds' => $teamsIds, 'skillsIds' => $skillsIds)));
     $response->setContent(json_encode(array('result' => $result)));
     return $response;
 }