/** * Get user's mcq * @param Team $team * @param User $user * @return mcq's id list */ public static function getMcqList($team, $user) { $mcqs = array(); $teamMcqs = array(); $userMcqs = array(); $diff = array(); $temp = array(); //Get Mcq's id in team to insert into a temp list foreach ($team->getMcqs() as $mcq) { //Insert Mcq's id in temporary list array_push($teamMcqs, $mcq->getId()); } //Get Mcq's id in user to insert into a temp list foreach ($user->getMcqs() as $mcq) { array_push($userMcqs, $mcq->getId()); } //Return list id mcqs for the User $temp = array_merge($userMcqs, $teamMcqs); $diff = array_unique($temp); //Add mcq in tempo list /*foreach ($diff as $mcq_id){ $tempMcq = $this->getDoctrine()->getRepository('IIAWebServiceBundle:Mcq')->findOneById($mcq_id); array_push($mcqs, $tempMcq); }*/ //return $mcqs; return $diff; }
/** * Remove duplicate mcq before to send user's json flow * @param User $user * @return $userWithoutDuplicate */ public function RemoveDuplicateMcq($user) { $mcqUser = array(); $mcqTeam = array(); $diff = array(); $team = new Team(); $team = $user->getTeam(); if ($team != null) { //Get Mcq's id in team's user foreach ($team->getMcqs() as $mcq) { //Insert Mcq's id in team's user in array array_push($mcqTeam, $mcq->getId()); } //Get Mcq's id in team's user foreach ($user->getMcqs() as $mcq) { array_push($mcqUser, $mcq->getId()); } /*Manage difference between two arrays*/ //Return list mcq's id missing in mcqUser Array $diff = array_diff($mcqTeam, $mcqUser); //Add Mcq in user foreach ($diff as $mcq_id) { $user->AddMcq($this->getDoctrine()->getRepository('IIAWebServiceBundle:Mcq')->findOneById($mcq_id)); } } return $user; }