GraphQL add query for course agenda #2644

pull/2715/head
Angel Fernando Quiroz Campos 7 years ago
parent ad6838511a
commit 5227842cc6
  1. 1
      src/ApiBundle/GraphQL/Map/EnumMap.php
  2. 30
      src/ApiBundle/GraphQL/Map/QueryMap.php
  3. 2
      src/ApiBundle/GraphQL/Map/UnionMap.php
  4. 41
      src/ApiBundle/GraphQL/Resolver/CourseResolver.php
  5. 24
      src/ApiBundle/GraphQL/Resources/config/schema.types.graphql

@ -42,6 +42,7 @@ class EnumMap extends ResolverMap implements ContainerAwareInterface
'TOOL_ANNOUNCEMENT' => TOOL_ANNOUNCEMENT,
'TOOL_NOTEBOOK' => TOOL_NOTEBOOK,
'TOOL_FORUM' => TOOL_FORUM,
'TOOL_CALENDAR_EVENT' => TOOL_CALENDAR_EVENT,
],
];
}

@ -289,6 +289,36 @@ class QueryMap extends ResolverMap implements ContainerAwareInterface
return $parent;
},
],
'ToolAgenda' => [
self::RESOLVE_FIELD => function (
CTool $tool,
Argument $args,
\ArrayObject $context,
ResolveInfo $info
) {
if ('events' === $info->fieldName) {
$resolver = $this->container->get('chamilo_api.graphql.resolver.course');
return $resolver->getAgenda($context);
}
return $this->resolveField($info->fieldName, $tool);
},
],
'CourseAgendaEvent' => [
'id' => function (array $event) {
return $event['unique_id'];
},
'description' => function (array $event) {
return $event['comment'];
},
'startDate' => function (array $event) {
return new \DateTime($event['start'], new \DateTimeZone('UTC'));
},
'endDate' => function (array $event) {
return new \DateTime($event['end'], new \DateTimeZone('UTC'));
},
],
'Session' => [
self::RESOLVE_FIELD => function (
Session $session,

@ -34,6 +34,8 @@ class UnionMap extends ResolverMap implements ContainerAwareInterface
return 'ToolNotebook';
case TOOL_FORUM:
return 'ToolForums';
case TOOL_CALENDAR_EVENT:
return 'ToolAgenda';
}
},
],

@ -343,4 +343,45 @@ class CourseResolver implements ContainerAwareInterface
return $posts;
}
/**
* @param \ArrayObject $context
*
* @return array
*/
public function getAgenda(\ArrayObject $context): array
{
/** @var Session|null $session */
$session = $context->offsetGet('session');
/** @var Course $course */
$course = $context->offsetGet('course');
$agenda = new \Agenda(
'course',
$this->getCurrentUser()->getId(),
$course->getId(),
$session ? $session->getId() : 0
);
$result = $agenda->parseAgendaFilter(null);
$firstDay = new \DateTime('now', new \DateTimeZone('UTC'));
$firstDay->modify('first day of this month');
$firstDay->setTime(0, 0);
$lastDay = new \DateTime('now', new \DateTimeZone('UTC'));
$lastDay->modify('last day of this month');
$lastDay->setTime(0, 0);
$groupId = current($result['groups']);
$userId = current($result['users']);
$events = $agenda->getEvents(
$firstDay->getTimestamp(),
$lastDay->getTimestamp(),
$course->getId(),
$groupId,
$userId,
'array'
);
return $events;
}
}

@ -207,6 +207,27 @@ type CourseForumPost {
status: Int
}
"A comprehensive diary/calendar tool"
type ToolAgenda {
name: String
category: String
image: String
customIcon: String
events: [CourseAgendaEvent!]
}
type CourseAgendaEvent {
id: Int
className: String
title: String
description: String
startDate: DateTime
endDate: DateTime
allDay: Boolean
borderColor: String
backgroundColor: String
}
"A session registered on the platform."
type Session {
"The unique ID of the session."
@ -238,7 +259,7 @@ type SessionCategory {
# Unions
union CourseTool = ToolDescription | ToolAnnouncements | ToolNotebook | ToolForums
union CourseTool = ToolDescription | ToolAnnouncements | ToolNotebook | ToolForums | ToolAgenda
# Enums
@ -276,6 +297,7 @@ enum CourseToolType {
TOOL_ANNOUNCEMENT
TOOL_NOTEBOOK
TOOL_FORUM
TOOL_CALENDAR_EVENT
}
# Scalars

Loading…
Cancel
Save