findBy(array( 'course' => $course, 'idSession' => $sessionId, 'toGroupId' => $groupId )); return $items;*/ $qb = $this->createQueryBuilder('i') ->select('i'); $wherePart = $qb->expr()->andx(); //Selecting courses for users $qb->innerJoin('i.user', 'u'); $wherePart->add($qb->expr()->eq('i.tool', $qb->expr()->literal($tool))); $wherePart->add($qb->expr()->eq('i.lasteditType', $qb->expr()->literal('LearnpathSubscription'))); $wherePart->add($qb->expr()->eq('i.ref', $itemId)); $wherePart->add($qb->expr()->eq('i.cId', $course->getId())); $wherePart->add($qb->expr()->eq('i.idSession', $sessionId)); $wherePart->add($qb->expr()->eq('i.toGroupId', $groupId)); $qb->where($wherePart); $q = $qb->getQuery(); return $q->execute(); } public function SubscribedUsersToItem($tool, \Entity\EntityCourse $course, $sessionId, $lpId, $newUserList = array()) { $em = $this->getEntityManager(); $user = $em->getRepository('Entity\EntityUser'); $courseRepo = $em->getRepository('Entity\EntityCourse'); $usersSubscribedToItem = $this->getUsersSubscribedToItem($tool, $lpId, $course, $sessionId); $users = $courseRepo->getSubscribedStudents($course); $alreadyAddedUsers = array(); if ($usersSubscribedToItem) { foreach ($usersSubscribedToItem as $itemProperty) { $alreadyAddedUsers[] = $itemProperty->getToUserId(); } } $usersToDelete = $alreadyAddedUsers; if (!empty($newUserList)) { $usersToDelete = array_diff($alreadyAddedUsers, $newUserList); } if ($usersToDelete) { foreach ($usersToDelete as $userToDelete) { $item = $this->findOneBy(array( 'tool' => $tool, 'idSession' => $sessionId, 'ref' => $lpId, 'toUserId' => $userToDelete )); if ($item) { $em->remove($item); } } } foreach ($newUserList as $userId) { $userObj = $user->find($userId); if (!in_array($userId, $alreadyAddedUsers)) { $item = new \Entity\EntityCItemProperty($userObj, $course); $item->setTool($tool); $item->setRef($lpId); $item->setIdSession($sessionId); $item->setToGroupId(0); $item->setLasteditType('LearnpathSubscription'); $item->setVisibility('1'); $em->persist($item); //$em is an instance of EntityManager } } $em->flush(); } }