From 4fe9ef9be06070e00fd693613990456937ec11df Mon Sep 17 00:00:00 2001 From: Julio Date: Sun, 22 Dec 2019 14:58:12 +0100 Subject: [PATCH] Add CForumThread and CForumPost as entities --- public/main/forum/forumfunction.inc.php | 19 +++-- public/main/lp/learnpath.class.php | 80 +++++++++---------- public/main/lp/learnpathList.class.php | 2 +- src/CoreBundle/Framework/Container.php | 18 +++++ src/CourseBundle/Entity/CForumPost.php | 34 ++++++-- src/CourseBundle/Entity/CForumThread.php | 24 +++++- .../Repository/CForumPostRepository.php | 13 +-- .../Repository/CForumThreadRepository.php | 13 +-- .../Resources/config/services.yml | 8 ++ 9 files changed, 134 insertions(+), 77 deletions(-) diff --git a/public/main/forum/forumfunction.inc.php b/public/main/forum/forumfunction.inc.php index f9346c5a00..08622c494e 100644 --- a/public/main/forum/forumfunction.inc.php +++ b/public/main/forum/forumfunction.inc.php @@ -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 , 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); diff --git a/public/main/lp/learnpath.class.php b/public/main/lp/learnpath.class.php index 5afa98ac78..f78157a88f 100644 --- a/public/main/lp/learnpath.class.php +++ b/public/main/lp/learnpath.class.php @@ -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 '; 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 .= '
  • '; - $return .= ''; - $return .= Display::return_icon('move_everywhere.png', get_lang('Move'), [], ICON_SIZE_TINY); - $return .= ' '; - $return .= Display::return_icon('forum.png', '', [], ICON_SIZE_TINY); - $return .= ' - - - '. - Security::remove_XSS($forum['forum_title']).' '.$link.''; + $return .= '
  • '; + $return .= ''; + $return .= Display::return_icon('move_everywhere.png', get_lang('Move'), [], ICON_SIZE_TINY); + $return .= ' '; + $return .= Display::return_icon('forum.png', '', [], ICON_SIZE_TINY); + $return .= ' + + + '. + $title.' '.$link.''; - $return .= '
  • '; + $return .= ''; - $return .= ''; } $return .= ''; diff --git a/public/main/lp/learnpathList.class.php b/public/main/lp/learnpathList.class.php index ea07bd01a2..535b4389b9 100644 --- a/public/main/lp/learnpathList.class.php +++ b/public/main/lp/learnpathList.class.php @@ -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) { diff --git a/src/CoreBundle/Framework/Container.php b/src/CoreBundle/Framework/Container.php index 597e0b203f..3525c58b03 100644 --- a/src/CoreBundle/Framework/Container.php +++ b/src/CoreBundle/Framework/Container.php @@ -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 */ diff --git a/src/CourseBundle/Entity/CForumPost.php b/src/CourseBundle/Entity/CForumPost.php index e17dd0bcfa..b95855f1c5 100644 --- a/src/CourseBundle/Entity/CForumPost.php +++ b/src/CourseBundle/Entity/CForumPost.php @@ -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(); + } } diff --git a/src/CourseBundle/Entity/CForumThread.php b/src/CourseBundle/Entity/CForumThread.php index a7d38c5f82..79da509dca 100644 --- a/src/CourseBundle/Entity/CForumThread.php +++ b/src/CourseBundle/Entity/CForumThread.php @@ -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(); + } } diff --git a/src/CourseBundle/Repository/CForumPostRepository.php b/src/CourseBundle/Repository/CForumPostRepository.php index 0b2d62ff6c..377d055182 100644 --- a/src/CourseBundle/Repository/CForumPostRepository.php +++ b/src/CourseBundle/Repository/CForumPostRepository.php @@ -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 diff --git a/src/CourseBundle/Repository/CForumThreadRepository.php b/src/CourseBundle/Repository/CForumThreadRepository.php index cbfe4b4db3..a974974614 100644 --- a/src/CourseBundle/Repository/CForumThreadRepository.php +++ b/src/CourseBundle/Repository/CForumThreadRepository.php @@ -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 * diff --git a/src/CourseBundle/Resources/config/services.yml b/src/CourseBundle/Resources/config/services.yml index 019e07da3e..2d720302f1 100644 --- a/src/CourseBundle/Resources/config/services.yml +++ b/src/CourseBundle/Resources/config/services.yml @@ -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'