Remove c_item_property, use resources + format code

pull/3064/head
Julio 5 years ago
parent d67cc99c4e
commit e7b5e83652
  1. 5
      public/main/exercise/stats.php
  2. 3
      src/CourseBundle/Entity/CForumAttachment.php
  3. 3
      src/CourseBundle/Entity/CForumPost.php
  4. 97
      src/CourseBundle/Repository/CForumForumRepository.php
  5. 105
      src/CourseBundle/Repository/CForumThreadRepository.php
  6. 8
      src/GraphQlBundle/Resolver/CourseResolver.php

@ -1,10 +1,9 @@
<?php
/* See license terms in /license.txt */
require_once __DIR__.'/../inc/global.inc.php';
$this_section = SECTION_COURSES;
api_protect_course_script(true, false, true);
$showPage = false;
@ -77,7 +76,7 @@ if (!empty($question_list)) {
);
$data[$question_id]['name'] = cut($questionObj->question, 100);
$data[$question_id]['type'] = $questionObj->get_question_type_name();
$data[$question_id]['type'] = $questionObj->getExplanation();
$percentage = 0;
if ($count_students) {
$percentage = $count_users / $count_students * 100;

@ -243,9 +243,6 @@ class CForumAttachment extends AbstractResource implements ResourceInterface
return $this->cId;
}
/**
* @return CForumPost
*/
public function getPost(): CForumPost
{
return $this->post;

@ -6,6 +6,7 @@ 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;
/**
@ -132,7 +133,7 @@ class CForumPost extends AbstractResource implements ResourceInterface
protected $status;
/**
* @var CForumAttachment[]
* @var ArrayCollection|CForumAttachment[]
*
* @ORM\OneToMany(targetEntity="Chamilo\CourseBundle\Entity\CForumAttachment", mappedBy="post")
*/

@ -4,105 +4,8 @@
namespace Chamilo\CourseBundle\Repository;
use Chamilo\CoreBundle\Entity\Course;
use Chamilo\CoreBundle\Entity\Session;
use Chamilo\CoreBundle\Repository\ResourceRepository;
use Chamilo\CourseBundle\Entity\CForumCategory;
use Chamilo\CourseBundle\Entity\CForumForum;
final class CForumForumRepository extends ResourceRepository
{
/**
* @param bool $isAllowedToEdit
* @param bool $includeGroupsForums
*
* @todo Remove api_get_session_condition
*/
public function findAllInCourseByCategory(
$isAllowedToEdit,
CForumCategory $category,
Course $course,
Session $session = null,
$includeGroupsForums = true
): array {
$conditionSession = api_get_session_condition(
$session ? $session->getId() : 0,
true,
true,
'f.sessionId'
);
$conditionVisibility = $isAllowedToEdit ? 'ip.visibility != 2' : 'ip.visibility = 1';
$conditionGroups = $includeGroupsForums
? 'AND (f.forumOfGroup = 0 OR f.forumOfGroup IS NULL)'
: '';
$dql = "SELECT f, ip
FROM ChamiloCourseBundle:CForumForum AS f
INNER JOIN ChamiloCourseBundle:CItemProperty AS ip
WITH (f.iid = ip.ref AND f.cId = ip.course)
WHERE
f.forumCategory = :category AND
ip.tool = :tool AND
f.cId = :course
$conditionSession AND
$conditionVisibility
$conditionGroups
ORDER BY f.forumOrder ASC";
$result = $this
->_em
->createQuery($dql)
->setParameters(['category' => $category, 'course' => $course, 'tool' => TOOL_FORUM])
->getResult();
$forums = [];
for ($i = 0; $i < count($result); $i += 2) {
/** @var CForumForum $f */
$f = $result[$i];
/** @var CItemProperty $ip */
$ip = $result[$i + 1];
$f->setItemProperty($ip);
$forums[] = $f;
}
return $forums;
}
/**
* @param int $id
*
* @return CForumForum
*/
public function findOneInCourse($id, Course $course)
{
$dql = 'SELECT f, ip
FROM ChamiloCourseBundle:CForumForum AS f
INNER JOIN ChamiloCourseBundle:CItemProperty AS ip
WITH (f.iid = ip.ref AND f.cId = ip.course)
WHERE
f.iid = :id AND
ip.tool = :tool AND
f.cId = :course AND
ip.visibility != 2';
$result = $this
->_em
->createQuery($dql)
->setParameters(['id' => (int) $id, 'course' => $course, 'tool' => TOOL_FORUM])
->getResult();
if (empty($result)) {
return null;
}
/** @var CForumForum $f */
$f = $result[0];
/** @var CItemProperty $ip */
$ip = $result[1];
$f->setItemProperty($ip);
return $f;
}
}

@ -4,116 +4,11 @@
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;
/**
* Class CForumThreadRepository.
*/
class CForumThreadRepository extends ResourceRepository
{
/**
* @param bool $isAllowedToEdit
*
* @todo Remove api_get_session_condition
*/
public function findAllInCourseByForum(
$isAllowedToEdit,
CForumForum $forum,
Course $course,
CGroupInfo $group = null,
Session $session = null
): array {
$conditionSession = api_get_session_condition(
$session ? $session->getId() : 0,
true,
false,
't.sessionId'
);
$conditionVisibility = $isAllowedToEdit ? 'ip.visibility != 2' : 'ip.visibility = 1';
$conditionGroup = $group
? 'AND ip.group = '.$group->getIid()
: '';
$dql = "SELECT DISTINCT t, ip
FROM ChamiloCourseBundle:CForumThread t
INNER JOIN ChamiloCourseBundle:CItemProperty ip
WITH (t.iid = ip.ref AND t.cId = ip.course AND ip.tool = :tool)
WHERE
ip.course = :course AND
t.forum = :forum AND
$conditionVisibility
$conditionGroup
$conditionSession
ORDER BY t.threadSticky DESC, t.threadDate DESC";
$result = $this
->_em
->createQuery($dql)
->setParameters(['forum' => $forum, 'course' => $course, 'tool' => TOOL_FORUM_THREAD])
->getResult();
$forums = [];
for ($i = 0; $i < count($result); $i += 2) {
/** @var CForumThread $t */
$t = $result[$i];
/** @var CItemProperty $ip */
$ip = $result[$i + 1];
$t->setItemProperty($ip);
$forums[] = $t;
}
return $forums;
}
/**
* @param int $id
*
* @return CForumThread|null
*
* @todo Remove api_get_session_condition
*/
public function findOneInCourse($id, Course $course, Session $session = null)
{
$conditionSession = api_get_session_condition(
$session ? $session->getId() : 0,
true,
false,
't.sessionId'
);
$dql = "SELECT t, ip
FROM ChamiloCourseBundle:CForumThread AS t
INNER JOIN ChamiloCourseBundle:CItemProperty AS ip
WITH (t.iid = ip.ref AND t.cId = ip.course)
WHERE
t.iid = :id AND
ip.tool = :tool AND
t.cId = :course
$conditionSession";
$result = $this
->_em
->createQuery($dql)
->setParameters(['id' => (int) $id, 'course' => $course, 'tool' => TOOL_FORUM_THREAD])
->getResult();
if (empty($result)) {
return null;
}
/** @var CForumThread $t */
$t = $result[0];
/** @var CItemProperty $ip */
$ip = $result[1];
$t->setItemProperty($ip);
return $t;
}
}

@ -248,7 +248,7 @@ class CourseResolver implements ContainerAwareInterface
$threadRepo = $this->em->getRepository('ChamiloCourseBundle:CForumThread');
return $threadRepo->findAllInCourseByForum(false, $forum, $course, $session);
return $threadRepo->getResourcesByCourse($course, $session, null, $forum->getResourceNode());
}
/**
@ -264,12 +264,16 @@ class CourseResolver implements ContainerAwareInterface
$session = $context->offsetGet('session');
$threadRepo = $this->em->getRepository('ChamiloCourseBundle:CForumThread');
$thread = $threadRepo->findOneInCourse($id, $course, $session);
$thread = $threadRepo->find($id);
if (empty($thread)) {
throw new UserError($this->translator->trans('Forum thread not found in this course.'));
}
if ($thread->getCId() !== $course->getId()) {
throw new UserError($this->translator->trans('Forum thread not found in this course.'));
}
return $thread;
}

Loading…
Cancel
Save