public function countMessagesForSubject(Subject $subject)
 {
     $dql = "\n            SELECT Count(m) FROM Claroline\\ForumBundle\\Entity\\Message m\n            JOIN m.subject s\n            WHERE s.id = :subjectId";
     $query = $this->_em->createQuery($dql);
     $query->setParameter('subjectId', $subject->getId());
     return $query->getSingleScalarResult();
 }
示例#2
0
 public function import(array $data)
 {
     $forum = new Forum();
     $repo = $this->om->getRepository('ClarolineCoreBundle:User');
     if (isset($data['data'])) {
         foreach ($data['data'] as $category) {
             $entityCategory = new Category();
             $entityCategory->setForum($forum);
             $entityCategory->setName($category['category']['name']);
             foreach ($category['category']['subjects'] as $subject) {
                 $subjectEntity = new Subject();
                 $subjectEntity->setTitle($subject['subject']['name']);
                 $creator = null;
                 if ($subject['subject']['creator'] !== null) {
                     $creator = $repo->findOneByUsername($subject['subject']['creator']);
                 }
                 if ($creator === null) {
                     $creator = $this->container->get('security.context')->getToken()->getUser();
                 }
                 $subjectEntity->setCreator($creator);
                 $subjectEntity->setCategory($entityCategory);
                 foreach ($subject['subject']['messages'] as $message) {
                     $messageEntity = new Message();
                     $content = file_get_contents($this->getRootPath() . DIRECTORY_SEPARATOR . $message['message']['path']);
                     $messageEntity->setContent($content);
                     $creator = null;
                     if ($message['message']['creator'] !== null) {
                         $creator = $repo->findOneByUsername($message['message']['creator']);
                     }
                     if ($creator === null) {
                         $creator = $this->container->get('security.context')->getToken()->getUser();
                     }
                     $messageEntity->setCreator($creator);
                     $messageEntity->setSubject($subjectEntity);
                     $messageEntity->setAuthor($message['message']['author']);
                     $this->om->persist($messageEntity);
                 }
                 $this->om->persist($subjectEntity);
             }
             $this->om->persist($entityCategory);
         }
     }
     $this->om->persist($forum);
     return $forum;
 }
示例#3
0
 public function load(ObjectManager $manager)
 {
     $creator = $this->getContainer()->get('claroline.manager.resource_manager');
     $em = $this->getContainer()->get('doctrine.orm.entity_manager');
     $user = $em->getRepository('ClarolineCoreBundle:User')->findOneBy(array('username' => $this->username));
     if ($this->parent == null) {
         $root = $em->getRepository('ClarolineCoreBundle:Resource\\ResourceNode')->findOneBy(array('parent' => null, 'workspace' => $user->getPersonalWorkspace()->getId()));
     } else {
         $root = $this->parent;
     }
     $collaborators = $em->getRepository('ClarolineCoreBundle:User')->findByWorkspace($root->getWorkspace());
     $maxOffset = count($collaborators);
     $this->log('collaborators found: ' . count($collaborators));
     --$maxOffset;
     $forum = new Forum();
     $forum->setName($this->forumName);
     $forum = $creator->create($forum, $manager->getRepository('ClarolineCoreBundle:Resource\\ResourceType')->findOneByName('claroline_forum'), $user, $root->getWorkspace(), $root);
     $forumManager = $this->getContainer()->get('claroline.manager.forum_manager');
     $category = $forumManager->createCategory($forum, $this->forumName);
     $this->log("forum {$forum->getName()} created");
     for ($i = 0; $i < $this->nbSubjects; ++$i) {
         $title = $this->container->get('claroline.utilities.lipsum_generator')->generateLipsum(5, false, 255);
         $user = $collaborators[rand(0, $maxOffset)];
         $subject = new Subject();
         $subject->setTitle($title);
         $subject->setCreator($user);
         $this->log("subject {$title} created");
         $subject->setCategory($category);
         $manager->persist($subject);
         for ($j = 0; $j < $this->nbMessages; ++$j) {
             $sender = $collaborators[rand(0, $maxOffset)];
             $message = new Message();
             $message->setSubject($subject);
             $message->setCreator($sender);
             $lipsum = $this->container->get('claroline.utilities.lipsum_generator')->generateLipsum(150, true, 1023);
             $message->setContent($lipsum);
             $manager->persist($message);
         }
         $manager->flush();
     }
     $manager->flush();
     $this->addReference("forum/{$this->forumName}", $forum);
 }
示例#4
0
 public function copy(Forum $forum)
 {
     $newForum = new Forum();
     $forum->setName($forum->getName());
     $oldCategories = $forum->getCategories();
     $this->om->persist($newForum);
     foreach ($oldCategories as $oldCategory) {
         $newCategory = new Category();
         $newCategory->setName($oldCategory->getName());
         $newCategory->setForum($newForum);
         $newCategory->setCreationDate($oldCategory->getCreationDate());
         $newCategory->setModificationDate($oldCategory->getModificationDate());
         $oldSubjects = $oldCategory->getSubjects();
         foreach ($oldSubjects as $oldSubject) {
             $newSubject = new Subject();
             $newSubject->setTitle($oldSubject->getTitle());
             $newSubject->setCreator($oldSubject->getCreator());
             $newSubject->setCategory($newCategory);
             $newSubject->setCreationDate($oldSubject->getCreationDate());
             $newSubject->setModificationDate($oldSubject->getModificationDate());
             $newSubject->setIsSticked($oldSubject->isSticked());
             $oldMessages = $oldSubject->getMessages();
             foreach ($oldMessages as $oldMessage) {
                 $newMessage = new Message();
                 $newMessage->setSubject($newSubject);
                 $newMessage->setCreator($oldMessage->getCreator());
                 $newMessage->setContent($oldMessage->getContent());
                 $newMessage->setCreationDate($oldMessage->getCreationDate());
                 $newMessage->setModificationDate($oldMessage->getModificationDate());
                 $this->om->persist($newMessage);
             }
             $this->om->persist($newSubject);
         }
         $this->om->persist($newCategory);
     }
     return $newForum;
 }
 /**
  * @param Subject $subject
  */
 public function __construct(Subject $subject)
 {
     $details = array('subject' => array('id' => $subject->getId(), 'title' => $subject->getTitle()), 'category' => array('id' => $subject->getCategory()->getId()), 'forum' => array('id' => $subject->getCategory()->getForum()->getId()));
     parent::__construct($subject->getCategory()->getForum()->getResourceNode(), $details);
 }
 public function findBySubject(Subject $subject, $getQuery = false)
 {
     $dql = "\n            SELECT m, u, pws FROM Claroline\\ForumBundle\\Entity\\Message m\n            JOIN m.creator u\n            LEFT JOIN u.personalWorkspace pws\n            JOIN m.subject subject\n            WHERE subject.id = {$subject->getId()}";
     $query = $this->_em->createQuery($dql);
     return $getQuery ? $query : $query->getResult();
 }
 /**
  * @EXT\Route(
  *     "/open/subject/{subject}",
  *     name="claro_subject_open",
  *     options={"expose"=true}
  * )
  * @EXT\Method("GET")
  *
  * @param Subject $subject
  */
 public function openSubjectAction(Subject $subject)
 {
     $forum = $subject->getCategory()->getForum();
     $this->checkAccess($forum);
     $this->forumManager->openSubject($subject);
     return new RedirectResponse($this->generateUrl('claro_forum_subjects', array('category' => $subject->getCategory()->getId())));
 }
 /**
  * @param \Claroline\ForumBundle\Entity\Message $message
  * @param \Claroline\ForumBundle\Entity\Subject $oldSubject
  * @param \Claroline\ForumBundle\Entity\Subject $newSubject
  */
 public function __construct(Message $message, Subject $oldSubject, Subject $newSubject)
 {
     $details = array('message' => array('id' => $message->getId()), 'subject' => array('oldSubjectId' => $oldSubject->getId(), 'newSubjectId' => $newSubject->getId()), 'category' => array('id' => $message->getSubject()->getCategory()->getId()), 'forum' => array('id' => $message->getSubject()->getCategory()->getForum()->getId()));
     parent::__construct($message->getSubject()->getCategory()->getForum()->getResourceNode(), $details);
 }
 /**
  * @param \Claroline\ForumBundle\Entity\Subject  $subject
  * @param \Claroline\ForumBundle\Entity\Category $oldCategory
  * @param \Claroline\ForumBundle\Entity\Category $newCategory
  */
 public function __construct(Subject $subject, Category $oldCategory, Category $newCategory)
 {
     $details = array('subject' => array('id' => $subject->getId()), 'category' => array('oldCategoryId' => $oldCategory->getId(), 'newCategoryId' => $newCategory->getId()), 'forum' => array('id' => $subject->getCategory()->getForum()->getId()));
     parent::__construct($subject->getCategory()->getForum()->getResourceNode(), $details);
 }