Add association mapping forum category - forum - forum thread - forum post #2644

pull/2715/head
Angel Fernando Quiroz Campos 7 years ago
parent b4c9e97f91
commit 0aeedf0ac4
  1. 12
      main/forum/forumfunction.inc.php
  2. 2
      main/lp/learnpath.class.php
  3. 2
      main/webservices/cm_webservice_forum.php
  4. 39
      src/CoreBundle/Migrations/Schema/V200/Version20180927172830.php
  5. 18
      src/CourseBundle/Entity/CForumCategory.php
  6. 39
      src/CourseBundle/Entity/CForumForum.php
  7. 23
      src/CourseBundle/Entity/CForumPost.php
  8. 37
      src/CourseBundle/Entity/CForumThread.php

@ -1002,7 +1002,7 @@ function delete_post($post_id)
'parent_of_deleted_post' => $post->getPostParentId(),
'course' => $course_id,
'post' => $post->getPostId(),
'thread_of_deleted_post' => $post->getThreadId(),
'thread_of_deleted_post' => $post->getThread() ? $post->getThread()->getIid() : 0,
'forum_of_deleted_post' => $post->getForumId(),
]);
@ -2020,7 +2020,7 @@ function getThreadInfo($threadId, $cId)
if ($forumThread) {
$thread['threadId'] = $forumThread->getThreadId();
$thread['threadTitle'] = $forumThread->getThreadTitle();
$thread['forumId'] = $forumThread->getForumId();
$thread['forumId'] = $forumThread->getForum() ? $forumThread->getForum()->getIid() : 0;
$thread['sessionId'] = $forumThread->getSessionId();
$thread['threadSticky'] = $forumThread->getThreadSticky();
$thread['locked'] = $forumThread->getLocked();
@ -2121,7 +2121,7 @@ function getPosts(
'post_id' => $post->getPostId(),
'post_title' => $post->getPostTitle(),
'post_text' => $post->getPostText(),
'thread_id' => $post->getThreadId(),
'thread_id' => $post->getThread() ? $post->getThread()->getIid() : 0,
'forum_id' => $post->getForumId(),
'poster_id' => $post->getPosterId(),
'poster_name' => $post->getPosterName(),
@ -2710,12 +2710,14 @@ function store_thread(
}
$clean_post_title = $values['post_title'];
$forum = $em->find('ChamiloCourseBundle:CForumForum', $values['forum_id']);
// We first store an entry in the forum_thread table because the thread_id is used in the forum_post table.
$lastThread = new CForumThread();
$lastThread
->setCId($course_id)
->setThreadTitle($clean_post_title)
->setForumId($values['forum_id'])
->setForum($forum)
->setThreadPosterId($userId)
->setThreadPosterName(isset($values['poster_name']) ? $values['poster_name'] : null)
->setThreadDate($post_date)
@ -2810,7 +2812,7 @@ function store_thread(
->setCId($course_id)
->setPostTitle($clean_post_title)
->setPostText($values['post_text'])
->setThreadId($lastThread->getIid())
->setThread($lastThread)
->setForumId($values['forum_id'])
->setPosterId($userId)
->setPosterName(isset($values['poster_name']) ? $values['poster_name'] : null)

@ -13224,7 +13224,7 @@ EOD;
/** @var \Chamilo\CourseBundle\Entity\CForumThread $thread */
$thread = $repo->find($threadId);
if ($thread) {
$itemList['forum'][] = $thread->getForumId();
$itemList['forum'][] = $thread->getForum() ? $thread->getForum()->getIid() : 0;
$threadList[] = $thread->getIid();
}
}

@ -276,7 +276,7 @@ class WSCMForum extends WSCM
$post
->setPostTitle($title)
->setPostText(isset($content) ? (api_html_entity_decode($content)) : null)
->setThreadId($thread_id)
->setThread($thread_id)
->setForumId($forum_id)
->setPosterId($user_id)
->setPostDate($postDate)

@ -0,0 +1,39 @@
<?php
/* For licensing terms, see /license.txt */
namespace Chamilo\CoreBundle\Migrations\Schema\V200;
use Chamilo\CoreBundle\Migrations\AbstractMigrationChamilo;
use Doctrine\DBAL\Schema\Schema;
/**
* Class Version20180927172830.
*
* Add foreing keys between forum category - forum - forum thread - forum post
*
* @package Chamilo\CoreBundle\Migrations\Schema\V200
*/
class Version20180927172830 extends AbstractMigrationChamilo
{
/**
* @param Schema $schema
*/
public function up(Schema $schema)
{
$this->addSql('UPDATE c_forum_post SET thread_id = NULL WHERE thread_id NOT IN (SELECT iid FROM c_forum_thread)');
$this->addSql('UPDATE c_forum_thread SET forum_id = NULL WHERE forum_id NOT IN (SELECT iid FROM c_forum_forum)');
$this->addSql('UPDATE c_forum_forum SET forum_category = NULL WHERE forum_category NOT IN (SELECT iid FROM c_forum_category)');
$this->addSql('ALTER TABLE c_forum_post ADD CONSTRAINT FK_B5BEF559E2904019 FOREIGN KEY (thread_id) REFERENCES c_forum_thread (iid)');
$this->addSql('ALTER TABLE c_forum_forum ADD CONSTRAINT FK_47A9C9921BF9426 FOREIGN KEY (forum_category) REFERENCES c_forum_category (iid)');
$this->addSql('CREATE INDEX IDX_47A9C9921BF9426 ON c_forum_forum (forum_category)');
$this->addSql('ALTER TABLE c_forum_thread ADD CONSTRAINT FK_5DA7884C29CCBAD0 FOREIGN KEY (forum_id) REFERENCES c_forum_forum (iid)');
}
/**
* @param Schema $schema
*/
public function down(Schema $schema)
{
}
}

@ -3,6 +3,7 @@
namespace Chamilo\CourseBundle\Entity;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\ORM\Mapping as ORM;
/**
@ -82,6 +83,13 @@ class CForumCategory
*/
private $itemProperty;
/**
* @var ArrayCollection
*
* @ORM\OneToMany(targetEntity="Chamilo\CourseBundle\Entity\CForumForum", mappedBy="forumCategory")
*/
private $forums;
/**
* Get iid.
*
@ -260,6 +268,16 @@ class CForumCategory
return $this->cId;
}
/**
* Get forums.
*
* @return ArrayCollection
*/
public function getForums()
{
return $this->forums;
}
/**
* @param CItemProperty $itemProperty
*

@ -3,6 +3,7 @@
namespace Chamilo\CourseBundle\Entity;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\ORM\Mapping as ORM;
/**
@ -77,9 +78,10 @@ class CForumForum
protected $forumLastPost;
/**
* @var int
* @var CForumCategory|null
*
* @ORM\Column(name="forum_category", type="integer", nullable=true)
* @ORM\ManyToOne(targetEntity="Chamilo\CourseBundle\Entity\CForumCategory", inversedBy="forums")
* @ORM\JoinColumn(name="forum_category", referencedColumnName="iid")
*/
protected $forumCategory;
@ -195,6 +197,13 @@ class CForumForum
*/
protected $moderated;
/**
* @var ArrayCollection
*
* @ORM\OneToMany(targetEntity="Chamilo\CourseBundle\Entity\CForumThread", mappedBy="forum")
*/
protected $threads;
/**
* Set forumTitle.
*
@ -318,11 +327,11 @@ class CForumForum
/**
* Set forumCategory.
*
* @param int $forumCategory
* @param CForumCategory|null $forumCategory
*
* @return CForumForum
*/
public function setForumCategory($forumCategory)
public function setForumCategory(CForumCategory $forumCategory = null)
{
$this->forumCategory = $forumCategory;
@ -332,7 +341,7 @@ class CForumForum
/**
* Get forumCategory.
*
* @return int
* @return CForumCategory|null
*/
public function getForumCategory()
{
@ -762,4 +771,24 @@ class CForumForum
return $this;
}
/**
* Get iid.
*
* @return int
*/
public function getIid()
{
return $this->iid;
}
/**
* Get threads.
*
* @return ArrayCollection
*/
public function getThreads()
{
return $this->threads;
}
}

@ -65,11 +65,12 @@ class CForumPost
protected $postText;
/**
* @var int
* @var CForumThread|null
*
* @ORM\Column(name="thread_id", type="integer", nullable=true)
* @ORM\ManyToOne(targetEntity="Chamilo\CourseBundle\Entity\CForumThread", inversedBy="posts")
* @ORM\JoinColumn(name="thread_id", referencedColumnName="iid")
*/
protected $threadId;
protected $thread;
/**
* @var int
@ -176,27 +177,27 @@ class CForumPost
}
/**
* Set threadId.
* Set thread.
*
* @param int $threadId
* @param CForumThread|null $thread
*
* @return CForumPost
*/
public function setThreadId($threadId)
public function setThread(CForumThread $thread = null)
{
$this->threadId = $threadId;
$this->thread = $thread;
return $this;
}
/**
* Get threadId.
* Get thread.
*
* @return int
* @return CForumThread|null
*/
public function getThreadId()
public function getThread()
{
return $this->threadId;
return $this->thread;
}
/**

@ -3,6 +3,7 @@
namespace Chamilo\CourseBundle\Entity;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\ORM\Mapping as ORM;
/**
@ -50,11 +51,12 @@ class CForumThread
protected $threadTitle;
/**
* @var int
* @var CForumForum|null
*
* @ORM\Column(name="forum_id", type="integer", nullable=true)
* @ORM\ManyToOne(targetEntity="Chamilo\CourseBundle\Entity\CForumForum", inversedBy="threads")
* @ORM\JoinColumn(name="forum_id", referencedColumnName="iid")
*/
protected $forumId;
protected $forum;
/**
* @var int
@ -161,6 +163,13 @@ class CForumThread
*/
protected $lpItemId;
/**
* @var ArrayCollection
*
* @ORM\OneToMany(targetEntity="Chamilo\CourseBundle\Entity\CForumPost", mappedBy="thread")
*/
protected $posts;
/**
* Constructor.
*/
@ -218,15 +227,15 @@ class CForumThread
}
/**
* Set forumId.
* Set forum.
*
* @param int $forumId
* @param CForumForum|null $forum
*
* @return CForumThread
*/
public function setForumId($forumId)
public function setForum(CForumForum $forum = null)
{
$this->forumId = $forumId;
$this->forum = $forum;
return $this;
}
@ -234,11 +243,11 @@ class CForumThread
/**
* Get forumId.
*
* @return int
* @return CForumForum|null
*/
public function getForumId()
public function getForum()
{
return $this->forumId;
return $this->forum;
}
/**
@ -634,4 +643,12 @@ class CForumThread
{
return $this->iid;
}
/**
* @return ArrayCollection
*/
public function getPosts()
{
return $this->posts;
}
}

Loading…
Cancel
Save