Add CForumThread and CForumPost as entities

pull/3064/head
Julio 6 years ago
parent 68eaa416a2
commit 4fe9ef9be0
  1. 19
      public/main/forum/forumfunction.inc.php
  2. 80
      public/main/lp/learnpath.class.php
  3. 2
      public/main/lp/learnpathList.class.php
  4. 18
      src/CoreBundle/Framework/Container.php
  5. 34
      src/CourseBundle/Entity/CForumPost.php
  6. 24
      src/CourseBundle/Entity/CForumThread.php
  7. 13
      src/CourseBundle/Repository/CForumPostRepository.php
  8. 13
      src/CourseBundle/Repository/CForumThreadRepository.php
  9. 8
      src/CourseBundle/Resources/config/services.yml

@ -2094,14 +2094,23 @@ function get_last_post_information($forum_id, $show_invisibles = false, $course_
* @param int|null $courseId Optional If is null then it is considered the current course
* @param int|null $sessionId Optional. If is null then it is considered the current session
*
* @return array containing all the information about the threads
*
* @author Patrick Cool <patrick.cool@UGent.be>, Ghent University
*
* @version february 2006, dokeos 1.8
*/
function get_threads($forum_id, $courseId = null, $sessionId = null)
{
$repo = Container::getForumRepository();
$courseId = empty($courseId) ? api_get_course_int_id() : $courseId;
$course = api_get_course_entity($courseId);
$session = api_get_session_entity($sessionId);
$qb = $repo->getResourcesByCourse($course, $session);
/*$qb->andWhere('resource.forumCategory = :catId')
->setParameter('catId', $cat_id);
*/
return $qb->getQuery()->getResult();
$groupId = api_get_group_id();
$sessionId = $sessionId !== null ? (int) $sessionId : api_get_session_id();
$table_item_property = Database::get_course_table(TABLE_ITEM_PROPERTY);

@ -10308,14 +10308,10 @@ class learnpath
$a_forums = [];
foreach ($forumCategories as $forumCategory) {
// The forums in this category.
$forumsInCategory = get_forums_in_category($forumCategory['cat_id']);
$forumsInCategory = get_forums_in_category($forumCategory->getIid());
if (!empty($forumsInCategory)) {
foreach ($forumList as $forum) {
if (isset($forum['forum_category']) &&
$forum['forum_category'] == $forumCategory['cat_id']
) {
$a_forums[] = $forum;
}
$a_forums[] = $forum;
}
}
}
@ -10349,48 +10345,48 @@ class learnpath
</script>';
foreach ($a_forums as $forum) {
if (!empty($forum['forum_id'])) {
$link = Display::url(
Display::return_icon('preview_view.png', get_lang('Preview')),
api_get_path(WEB_CODE_PATH).'forum/viewforum.php?'.api_get_cidreq().'&forum='.$forum['forum_id'],
['target' => '_blank']
);
$forumId = $forum->getIid();
$title = Security::remove_XSS($forum->getForumTitle());
$link = Display::url(
Display::return_icon('preview_view.png', get_lang('Preview')),
api_get_path(WEB_CODE_PATH).'forum/viewforum.php?'.api_get_cidreq().'&forum='.$forumId,
['target' => '_blank']
);
$return .= '<li class="lp_resource_element" data_id="'.$forum['forum_id'].'" data_type="'.TOOL_FORUM.'" title="'.$forum['forum_title'].'" >';
$return .= '<a class="moved" href="#">';
$return .= Display::return_icon('move_everywhere.png', get_lang('Move'), [], ICON_SIZE_TINY);
$return .= ' </a>';
$return .= Display::return_icon('forum.png', '', [], ICON_SIZE_TINY);
$return .= '<a onclick="javascript:toggle_forum('.$forum['forum_id'].');" style="cursor:hand; vertical-align:middle">
<img src="'.Display::returnIconPath('add.png').'" id="forum_'.$forum['forum_id'].'_opener" align="absbottom" />
</a>
<a class="moved" href="'.api_get_self().'?'.api_get_cidreq().'&action=add_item&type='.TOOL_FORUM.'&forum_id='.$forum['forum_id'].'&lp_id='.$this->lp_id.'" style="vertical-align:middle">'.
Security::remove_XSS($forum['forum_title']).' '.$link.'</a>';
$return .= '<li class="lp_resource_element" data_id="'.$forumId.'" data_type="'.TOOL_FORUM.'" title="'.$title.'" >';
$return .= '<a class="moved" href="#">';
$return .= Display::return_icon('move_everywhere.png', get_lang('Move'), [], ICON_SIZE_TINY);
$return .= ' </a>';
$return .= Display::return_icon('forum.png', '', [], ICON_SIZE_TINY);
$return .= '<a onclick="javascript:toggle_forum('.$forumId.');" style="cursor:hand; vertical-align:middle">
<img src="'.Display::returnIconPath('add.png').'" id="forum_'.$forumId.'_opener" align="absbottom" />
</a>
<a class="moved" href="'.api_get_self().'?'.api_get_cidreq().'&action=add_item&type='.TOOL_FORUM.'&forum_id='.$forumId.'&lp_id='.$this->lp_id.'" style="vertical-align:middle">'.
$title.' '.$link.'</a>';
$return .= '</li>';
$return .= '</li>';
$return .= '<div style="display:none" id="forum_'.$forum['forum_id'].'_content">';
$a_threads = get_threads($forum['forum_id']);
if (is_array($a_threads)) {
foreach ($a_threads as $thread) {
$link = Display::url(
Display::return_icon('preview_view.png', get_lang('Preview')),
api_get_path(WEB_CODE_PATH).'forum/viewthread.php?'.api_get_cidreq().'&forum='.$forum['forum_id'].'&thread='.$thread['thread_id'],
['target' => '_blank']
);
$return .= '<div style="display:none" id="forum_'.$forumId.'_content">';
$a_threads = get_threads($forumId);
if (is_array($a_threads)) {
foreach ($a_threads as $thread) {
$link = Display::url(
Display::return_icon('preview_view.png', get_lang('Preview')),
api_get_path(WEB_CODE_PATH).'forum/viewthread.php?'.api_get_cidreq().'&forum='.$forum['forum_id'].'&thread='.$thread['thread_id'],
['target' => '_blank']
);
$return .= '<li class="lp_resource_element" data_id="'.$thread['thread_id'].'" data_type="'.TOOL_THREAD.'" title="'.$thread['thread_title'].'" >';
$return .= '&nbsp;<a class="moved" href="#">';
$return .= Display::return_icon('move_everywhere.png', get_lang('Move'), [], ICON_SIZE_TINY);
$return .= ' </a>';
$return .= Display::return_icon('forumthread.png', get_lang('Thread'), [], ICON_SIZE_TINY);
$return .= '<a class="moved" href="'.api_get_self().'?'.api_get_cidreq().'&action=add_item&type='.TOOL_THREAD.'&thread_id='.$thread['thread_id'].'&lp_id='.$this->lp_id.'">'.
Security::remove_XSS($thread['thread_title']).' '.$link.'</a>';
$return .= '</li>';
}
$return .= '<li class="lp_resource_element" data_id="'.$thread['thread_id'].'" data_type="'.TOOL_THREAD.'" title="'.$thread['thread_title'].'" >';
$return .= '&nbsp;<a class="moved" href="#">';
$return .= Display::return_icon('move_everywhere.png', get_lang('Move'), [], ICON_SIZE_TINY);
$return .= ' </a>';
$return .= Display::return_icon('forumthread.png', get_lang('Thread'), [], ICON_SIZE_TINY);
$return .= '<a class="moved" href="'.api_get_self().'?'.api_get_cidreq().'&action=add_item&type='.TOOL_THREAD.'&thread_id='.$thread['thread_id'].'&lp_id='.$this->lp_id.'">'.
Security::remove_XSS($thread['thread_title']).' '.$link.'</a>';
$return .= '</li>';
}
$return .= '</div>';
}
$return .= '</div>';
}
$return .= '</ul>';

@ -138,7 +138,7 @@ class LearnpathList
$session_id
);*/
$visibility = $row->isVisible($courseEntity, $sessionEntity);
var_dump($visibility);
// If option is not true then don't show invisible LP to user
if ($ignoreLpVisibility === false) {
if ($showBlockedPrerequisite !== true && !$isAllowToEdit) {

@ -15,6 +15,8 @@ use Chamilo\CourseBundle\Repository\CDocumentRepository;
use Chamilo\CourseBundle\Repository\CExerciseCategoryRepository;
use Chamilo\CourseBundle\Repository\CForumCategoryRepository;
use Chamilo\CourseBundle\Repository\CForumForumRepository;
use Chamilo\CourseBundle\Repository\CForumPostRepository;
use Chamilo\CourseBundle\Repository\CForumThreadRepository;
use Chamilo\CourseBundle\Repository\CLpCategoryRepository;
use Chamilo\CourseBundle\Repository\CLpRepository;
use Chamilo\CourseBundle\Repository\CQuizQuestionCategoryRepository;
@ -321,6 +323,22 @@ class Container
return self::$container->get('Chamilo\CourseBundle\Repository\CForumCategoryRepository');
}
/**
* @return CForumPostRepository
*/
public static function getForumPostRepository()
{
return self::$container->get('Chamilo\CourseBundle\Repository\CForumPostRepository');
}
/**
* @return CForumThreadRepository
*/
public static function getForumThreadRepository()
{
return self::$container->get('Chamilo\CourseBundle\Repository\CForumThreadRepository');
}
/**
* @return CQuizQuestionRepository
*/

@ -4,6 +4,8 @@
namespace Chamilo\CourseBundle\Entity;
use Chamilo\CoreBundle\Entity\Resource\AbstractResource;
use Chamilo\CoreBundle\Entity\Resource\ResourceInterface;
use Doctrine\ORM\Mapping as ORM;
/**
@ -20,13 +22,13 @@ use Doctrine\ORM\Mapping as ORM;
* @ORM\Index(name="c_id_visible_post_date", columns={"c_id", "visible", "post_date"})
* }
* )
* @ORM\Entity(repositoryClass="Chamilo\CourseBundle\Repository\CForumPostRepository")
* @ORM\Entity()
*/
class CForumPost
class CForumPost extends AbstractResource implements ResourceInterface
{
const STATUS_VALIDATED = 1;
const STATUS_WAITING_MODERATION = 2;
const STATUS_REJECTED = 3;
public const STATUS_VALIDATED = 1;
public const STATUS_WAITING_MODERATION = 2;
public const STATUS_REJECTED = 3;
/**
* @var int
@ -129,6 +131,15 @@ class CForumPost
*/
protected $status;
public function __construct()
{
}
public function __toString(): string
{
return (string) $this->getPostTitle();
}
/**
* Set postTitle.
*
@ -444,4 +455,17 @@ class CForumPost
{
return $this->iid;
}
/**
* Resource identifier.
*/
public function getResourceIdentifier(): int
{
return $this->getIid();
}
public function getResourceName(): string
{
return $this->getPostTitle();
}
}

@ -4,6 +4,8 @@
namespace Chamilo\CourseBundle\Entity;
use Chamilo\CoreBundle\Entity\Resource\AbstractResource;
use Chamilo\CoreBundle\Entity\Resource\ResourceInterface;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\ORM\Mapping as ORM;
@ -17,9 +19,9 @@ use Doctrine\ORM\Mapping as ORM;
* @ORM\Index(name="idx_forum_thread_forum_id", columns={"forum_id"})
* }
* )
* @ORM\Entity(repositoryClass="Chamilo\CourseBundle\Repository\CForumThreadRepository")
* @ORM\Entity()
*/
class CForumThread
class CForumThread extends AbstractResource implements ResourceInterface
{
/**
* @var int
@ -186,6 +188,11 @@ class CForumThread
$this->threadViews = 0;
}
public function __toString(): string
{
return (string) $this->getThreadTitle();
}
/**
* @return bool
*/
@ -673,4 +680,17 @@ class CForumThread
{
return $this->itemProperty;
}
/**
* Resource identifier.
*/
public function getResourceIdentifier(): int
{
return $this->getIid();
}
public function getResourceName(): string
{
return $this->getThreadTitle();
}
}

@ -5,26 +5,17 @@
namespace Chamilo\CourseBundle\Repository;
use Chamilo\CoreBundle\Entity\Course;
use Chamilo\CoreBundle\Repository\ResourceRepository;
use Chamilo\CourseBundle\Entity\CForumPost;
use Chamilo\CourseBundle\Entity\CForumThread;
use Chamilo\CourseBundle\Entity\CGroupInfo;
use Chamilo\UserBundle\Entity\User;
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
use Doctrine\Common\Persistence\ManagerRegistry;
/**
* Class CForumPostRepository.
*/
class CForumPostRepository extends ServiceEntityRepository
class CForumPostRepository extends ResourceRepository
{
/**
* CForumPostRepository constructor.
*/
public function __construct(ManagerRegistry $registry)
{
parent::__construct($registry, CForumPost::class);
}
/**
* @param bool $onlyVisibles
* @param bool $isAllowedToEdit

@ -6,26 +6,17 @@ namespace Chamilo\CourseBundle\Repository;
use Chamilo\CoreBundle\Entity\Course;
use Chamilo\CoreBundle\Entity\Session;
use Chamilo\CoreBundle\Repository\ResourceRepository;
use Chamilo\CourseBundle\Entity\CForumForum;
use Chamilo\CourseBundle\Entity\CForumThread;
use Chamilo\CourseBundle\Entity\CGroupInfo;
use Chamilo\CourseBundle\Entity\CItemProperty;
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
use Doctrine\Common\Persistence\ManagerRegistry;
/**
* Class CForumThreadRepository.
*/
class CForumThreadRepository extends ServiceEntityRepository
class CForumThreadRepository extends ResourceRepository
{
/**
* CForumPostRepository constructor.
*/
public function __construct(ManagerRegistry $registry)
{
parent::__construct($registry, CForumThread::class);
}
/**
* @param bool $isAllowedToEdit
*

@ -86,6 +86,14 @@ services:
arguments:
$className: 'Chamilo\CourseBundle\Entity\CForumCategory'
Chamilo\CourseBundle\Repository\CForumPostRepository:
arguments:
$className: 'Chamilo\CourseBundle\Entity\CForumPost'
Chamilo\CourseBundle\Repository\CForumThreadRepository:
arguments:
$className: 'Chamilo\CourseBundle\Entity\CForumThread'
Chamilo\CourseBundle\Repository\CGroupInfoRepository:
arguments:
$className: 'Chamilo\CourseBundle\Entity\CGroupInfo'

Loading…
Cancel
Save