/** * For an shared interaction whith me, know if it's linked with response and if I can modify it. * * * @param Doctrine EntityManager $em * @param \UJM\ExoBundle\Entity\Share $shared * * @return array */ public function getActionShared($shared) { $em = $this->doctrine->getEntityManager(); $question = $shared->getQuestion(); $sharedWithMe[$shared->getQuestion()->getId()] = $question; $shareRight[$question->getId()] = $shared->getAllowToModify(); $response = $em->getRepository('UJMExoBundle:Response')->findOneByQuestion($question); if ($question) { $questionWithResponse[$question->getId()] = 1; } else { $questionWithResponse[$question->getId()] = 0; } $actionsS[0] = $sharedWithMe; $actionsS[1] = $shareRight; $actionsS[2] = $questionWithResponse; return $actionsS; }
/** * For an shared interaction whith me, know if it's linked with response and if I can modify it * * @access public * * @param Doctrine EntityManager $em * @param \UJM\ExoBundle\Entity\Share $shared * * @return array */ public function getActionShared($em, $shared) { $inter = $em->getRepository('UJMExoBundle:Interaction')->findOneBy(array('question' => $shared->getQuestion()->getId())); $sharedWithMe[$shared->getQuestion()->getId()] = $inter; $shareRight[$inter->getId()] = $shared->getAllowToModify(); $response = $em->getRepository('UJMExoBundle:Response')->findBy(array('interaction' => $inter->getId())); if (count($response) > 0) { $questionWithResponse[$inter->getId()] = 1; } else { $questionWithResponse[$inter->getId()] = 0; } $actionsS[0] = $sharedWithMe; $actionsS[1] = $shareRight; $actionsS[2] = $questionWithResponse; return $actionsS; }
/** * If question already shared with a given user * * @access public * * @param \UJM\ExoBundle\Entity\Share $toShare * @param Doctrine Entity Manager $em * * @return \Symfony\Component\HttpFoundation\Response */ public function alreadySharedAction($toShare, $em) { $alreadyShared = $em->getRepository('UJMExoBundle:Share')->findAll(); $already = false; $end = count($alreadyShared); for ($i = 0; $i < $end; $i++) { if ($alreadyShared[$i]->getUser() == $toShare->getUser() && $alreadyShared[$i]->getQuestion() == $toShare->getQuestion()) { $already = true; break; } } if ($already == true) { return true; } else { return false; } }
/** * To share question with other users. * * @EXT\Route("/shareQuestionUser", name="ujm_question_shareQuestionUser") * @EXT\Method("POST") * * @return \Symfony\Component\HttpFoundation\Response */ public function shareQuestionUserAction() { $request = $this->container->get('request'); if ($request->isXmlHttpRequest()) { $questionID = $request->request->get('questionID'); // Which question is shared $uid = $request->request->get('uid'); $allowToModify = $request->request->get('allowToModify'); $em = $this->getDoctrine()->getManager(); $question = $em->getRepository('UJMExoBundle:Question')->findOneBy(array('id' => $questionID)); $user = $em->getRepository('ClarolineCoreBundle:User')->find($uid); $share = $em->getRepository('UJMExoBundle:Share')->findOneBy(array('user' => $user, 'question' => $question)); if (!$share) { $share = new Share($user, $question); } $share->setAllowToModify($allowToModify); $em->persist($share); $em->flush(); return new \Symfony\Component\HttpFoundation\Response('no;' . $this->generateUrl('ujm_question_index')); } }