Forums: Fix visibility

pull/3741/head
Julio Montoya 5 years ago
parent fa3144e048
commit 05939dc7ff
  1. 14
      public/main/forum/index.php
  2. 2
      public/main/inc/lib/document.lib.php
  3. 6
      public/main/template/default/forum/list.html.twig
  4. 2
      src/CoreBundle/Controller/ResourceController.php
  5. 36
      src/CoreBundle/Entity/AbstractResource.php
  6. 26
      src/CoreBundle/Entity/ResourceLink.php

@ -24,8 +24,8 @@ use ChamiloSession as Session;
* @copyright Patrick Cool
*/
require_once __DIR__.'/../inc/global.inc.php';
require_once 'forumfunction.inc.php';
api_protect_course_script(true);
$current_course_tool = TOOL_FORUM;
@ -43,11 +43,11 @@ function hidecontent(content){
$this_section = SECTION_COURSES;
$nameTools = get_lang('Forums');
$_course = api_get_course_info();
$courseEntity = $_course['entity'];
$courseEntity = api_get_course_entity();
$sessionId = api_get_session_id();
$sessionEntity = api_get_session_entity($sessionId);
$_user = api_get_user_info();
$courseId = $courseEntity->getId();
$hideNotifications = api_get_course_setting('hide_forum_notifications');
$hideNotifications = 1 == $hideNotifications;
@ -132,7 +132,7 @@ $user_id = api_get_user_id();
/* RETRIEVING ALL GROUPS AND THOSE OF THE USER */
// The groups of the user.
$groups_of_user = GroupManager::get_group_ids($_course['real_id'], $user_id);
$groups_of_user = GroupManager::get_group_ids($courseId, $user_id);
// All groups in the course (and sorting them as the
// id of the group = the key of the array).
@ -278,12 +278,12 @@ if (is_array($forumCategories)) {
$forumCategoryInfo['url'] = 'viewforumcategory.php?'.api_get_cidreq().'&forumcategory='.$categoryId;
$visibility = $forumCategory->isVisible($courseEntity, $sessionEntity);
if (!empty($idCategory)) {
if (!empty($categoryId)) {
if (api_is_allowed_to_edit(false, true) &&
!(0 == $categorySessionId && 0 != $sessionId)
) {
$tools .= '<a href="'.api_get_self().'?'.api_get_cidreq()
.'&action=edit&content=forumcategory&id='.$categoryId
.'&action=edit_category&content=forumcategory&id='.$categoryId
.'">'.Display::return_icon(
'edit.png',
get_lang('Edit'),
@ -329,7 +329,7 @@ if (is_array($forumCategories)) {
$forumCategoryInfo['forums'] = [];
// The forums in this category.
$forumInfo = [];
$forumsInCategory = get_forums_in_category($categoryId, $_course['real_id']);
$forumsInCategory = get_forums_in_category($categoryId, $courseId);
if (!empty($forumsInCategory)) {
$forumsDetailsList = [];

@ -1498,7 +1498,7 @@ class DocumentManager
$repo = $em->getRepository('ChamiloCourseBundle:CDocument');
/** @var CDocument $document */
$document = $repo->find($doc_id);
$link = $document->getCourseSessionResourceLink($course_info['entity']);
$link = $document->getFirstResourceLinkFromCourseSession($course_info['entity']);
if ($link && ResourceLink::VISIBILITY_PUBLISHED == $link->getVisibility()) {
return true;
}

@ -71,9 +71,9 @@
{% for category_language_item in category_language_array %}
<span class="flag-icon flag-icon-{{ languages[category_language_item | lower] }}"></span>
{% endfor %}
{# <div class="pull-right">#}
{# {{ item.tools }}#}
{# </div>#}
<div class="pull-right">
{{ item.tools }}
</div>
{% endset %}
{% endif %}

@ -393,7 +393,7 @@ class ResourceController extends AbstractResourceController implements CourseCon
/** @var ResourceLink $link */
if ($this->hasCourse()) {
$link = $resource->getCourseSessionResourceLink($this->getCourse(), $this->getSession());
$link = $resource->getFirstResourceLinkFromCourseSession($this->getCourse(), $this->getSession());
} else {
$link = $resource->getFirstResourceLink();
}

@ -348,11 +348,6 @@ abstract class AbstractResource
return $this->resourceNode;
}
public function getCourseSessionResourceLink(Course $course, Session $session = null): ?ResourceLink
{
return $this->getFirstResourceLinkFromCourseSession($course, $session);
}
public function getFirstResourceLink(): ?ResourceLink
{
$resourceNode = $this->getResourceNode();
@ -372,12 +367,12 @@ abstract class AbstractResource
*/
public function getLinkVisibility(Course $course, Session $session = null): ?ResourceLink
{
return $this->getCourseSessionResourceLink($course, $session)->getVisibility();
return $this->getFirstResourceLinkFromCourseSession($course, $session)->getVisibility();
}
public function isVisible(Course $course, Session $session = null): bool
{
$link = $this->getCourseSessionResourceLink($course, $session);
$link = $this->getFirstResourceLinkFromCourseSession($course, $session);
if (null === $link) {
return false;
}
@ -387,24 +382,31 @@ abstract class AbstractResource
public function getFirstResourceLinkFromCourseSession(Course $course, Session $session = null): ?ResourceLink
{
$criteria = Criteria::create();
/*$criteria = Criteria::create();
$criteria
->where(Criteria::expr()->eq('course', $course))
->where(Criteria::expr()->eq('course', $course->getId()))
->andWhere(
Criteria::expr()->eq('session', $session)
);
)
->setFirstResult(0)
->setMaxResults(1)
;*/
$resourceNode = $this->getResourceNode();
$result = null;
if ($resourceNode && $resourceNode->getResourceLinks()->count() > 0) {
//var_dump($resourceNode->getResourceLinks()->count());
foreach ($resourceNode->getResourceLinks() as $link) {
//var_dump(get_class($link));
$links = $resourceNode->getResourceLinks();
$found = false;
foreach ($links as $link) {
if ($link->getCourse() === $course && $link->getSession() === $session) {
$found = true;
break;
}
}
$result = $resourceNode->getResourceLinks()->matching($criteria)->first();
//$result = $links->matching($criteria)->count();
//var_dump($result);
if ($result) {
return $result;
//var_dump($result);
if ($found) {
return $link;
}
}

@ -175,6 +175,11 @@ class ResourceLink
return $this;
}
public function getCourse(): ?Course
{
return $this->course;
}
public function setCourse(Course $course = null): self
{
$this->course = $course;
@ -182,6 +187,11 @@ class ResourceLink
return $this;
}
public function getSession(): ?Session
{
return $this->session;
}
public function setSession(Session $session = null): self
{
$this->session = $session;
@ -231,22 +241,6 @@ class ResourceLink
return null !== $this->user;
}
/**
* Get course.
*/
public function getCourse(): ?Course
{
return $this->course;
}
/**
* Get session.
*/
public function getSession(): ?Session
{
return $this->session;
}
public function setResourceNode(ResourceNode $resourceNode): self
{
$this->resourceNode = $resourceNode;

Loading…
Cancel
Save