GraphQL add query for learn paths #2644

pull/2715/head
Angel Fernando Quiroz Campos 7 years ago
parent 043db15f34
commit d35143964c
  1. 8
      src/ApiBundle/GraphQL/Map/QueryMap.php
  2. 68
      src/ApiBundle/GraphQL/Resolver/CourseResolver.php
  3. 7
      src/ApiBundle/GraphQL/Resources/config/schema.types.graphql

@ -14,6 +14,7 @@ use Chamilo\CourseBundle\Entity\CForumCategory;
use Chamilo\CourseBundle\Entity\CForumForum;
use Chamilo\CourseBundle\Entity\CForumPost;
use Chamilo\CourseBundle\Entity\CForumThread;
use Chamilo\CourseBundle\Entity\CLpCategory;
use Chamilo\CourseBundle\Entity\CNotebook;
use Chamilo\CourseBundle\Entity\CTool;
use Chamilo\UserBundle\Entity\User;
@ -336,6 +337,13 @@ class QueryMap extends ResolverMap implements ContainerAwareInterface
return $resolver->getLearnpathCategories($context);
},
],
'CourseLearnpathCategory' => [
'learnpaths' => function (CLpCategory $category, Argument $args, \ArrayObject $context) {
$resolver = $this->container->get('chamilo_api.graphql.resolver.course');
return $resolver->getLearnpathsByCategory($category, $context);
},
],
'Session' => [
self::RESOLVE_FIELD => function (
Session $session,

@ -492,4 +492,72 @@ class CourseResolver implements ContainerAwareInterface
return $categories;
}
/**
* @param CLpCategory $category
* @param \ArrayObject $context
*
* @return array
*/
public function getLearnpathsByCategory(CLpCategory $category, \ArrayObject $context): array
{
$user = $this->getCurrentUser();
/** @var Course $course */
$course = $context->offsetGet('course');
/** @var Session $session */
$session = $context->offsetGet('session');
$sessionId = $session ? $session->getId() : 0;
$lpList = new \LearnpathList(
$user->getId(),
$course->getCode(),
$sessionId,
null,
false,
$category->getId()
);
$flatList = $lpList->get_flat_list();
$lps = [];
foreach ($flatList as $lpId => $lpInfo) {
if (empty($lpInfo['lp_visibility'])) {
continue;
}
if (
!\learnpath::is_lp_visible_for_student($lpId, $user->getId(), $course->getCode(), $sessionId)
) {
continue;
}
$timeLimits = !empty($lpInfo['expired_on']);
if ($timeLimits) {
if (!empty($lpInfo['publicated_on']) && !empty($lpInfo['expired_on'])) {
$utc = new \DateTimeZone('UTC');
$starTime = new \DateTime($lpInfo['publicated_on'], $utc);
$endTime = new \DateTime($lpInfo['expired_on'], $utc);
$now = new \DateTime('now', $utc);
$isActived = $now > $starTime && $endTime > $now;
if (!$isActived) {
continue;
}
}
}
$progress = \learnpath::getProgress($lpId, $user->getId(), $course->getId(), $sessionId);
$lps[] = [
'id' => $lpId,
'title' => \Security::remove_XSS($lpInfo['lp_name']),
'progress' => (int) $progress,
];
}
return $lps;
}
}

@ -259,6 +259,13 @@ type ToolLearningPath {
type CourseLearnpathCategory {
id: Int
name: String
learnpaths: [CourseLearnpath!]
}
type CourseLearnpath {
id: Int
title: String
progress: Int
}
"A session registered on the platform."

Loading…
Cancel
Save