commit
8213a13688
@ -0,0 +1,188 @@ |
||||
<div id="about-course"> |
||||
<div id="course-info-top"> |
||||
<h2 class="session-title">{{ course.title }}</h2> |
||||
<div class="course-short"> |
||||
<ul> |
||||
<li class="author">{{ "Professors"|get_lang }}</li> |
||||
{% for teacher in course.teachers %} |
||||
<li>{{ teacher.complete_name }} | </li> |
||||
{% endfor %} |
||||
</ul> |
||||
|
||||
</div> |
||||
</div> |
||||
|
||||
{% set course_video = '' %} |
||||
{% for extra_field in course.extra_fields %} |
||||
{% if extra_field.value.getField().getVariable() == 'video_url' %} |
||||
{% set course_video = extra_field.value.getValue() %} |
||||
{% endif %} |
||||
{% endfor %} |
||||
|
||||
<div class="panel panel-default"> |
||||
<div class="panel-body"> |
||||
<div class="row"> |
||||
<div class="col-sm-5"> |
||||
{% if course_video %} |
||||
<div class="course-video"> |
||||
<div class="embed-responsive embed-responsive-16by9"> |
||||
{{ essence.replace(course_video) }} |
||||
</div> |
||||
</div> |
||||
{% else %} |
||||
<div class="course-image"> |
||||
<img src="{{ course.image }}" class="img-responsive" /> |
||||
</div> |
||||
{% endif %} |
||||
|
||||
<div class="share-social-media"> |
||||
<ul class="sharing-buttons"> |
||||
<li> |
||||
{{ "ShareWithYourFriends"|get_lang }} |
||||
</li> |
||||
<li> |
||||
<a href="https://www.facebook.com/sharer/sharer.php?u={{ url }}" |
||||
target="_blank" class="btn btn-facebook btn-inverse btn-xs"> |
||||
<em class="fa fa-facebook"></em> Facebook |
||||
</a> |
||||
</li> |
||||
<li> |
||||
<a href="https://twitter.com/home?{{ {'status': course.title ~ ' ' ~ url }|url_encode }}" |
||||
target="_blank" class="btn btn-twitter btn-inverse btn-xs"> |
||||
<em class="fa fa-twitter"></em> Twitter |
||||
</a> |
||||
</li> |
||||
<li> |
||||
<a href="https://www.linkedin.com/shareArticle?{{ {'mini': 'true', 'url': url , 'title': course.title }|url_encode }}" |
||||
target="_blank" class="btn btn-linkedin btn-inverse btn-xs"> |
||||
<em class="fa fa-linkedin"></em> Linkedin |
||||
</a> |
||||
</li> |
||||
</ul> |
||||
</div> |
||||
</div> |
||||
<div class="col-sm-7"> |
||||
<div class="course-description"> |
||||
{{ course.description }} |
||||
</div> |
||||
</div> |
||||
</div> |
||||
{% if course.tags %} |
||||
<div class="panel-tags"> |
||||
|
||||
<ul class="list-inline course-tags"> |
||||
<li>{{ 'Tags'|get_lang }} :</li> |
||||
{% for tag in course.tags %} |
||||
<li class="tag-value"> |
||||
<span>{{ tag.getTag }}</span> |
||||
</li> |
||||
{% endfor %} |
||||
</ul> |
||||
</div> |
||||
{% endif %} |
||||
</div> |
||||
</div> |
||||
<section id="course-info-bottom" class="course"> |
||||
<div class="row"> |
||||
<div class="col-sm-8"> |
||||
<div class="panel panel-default"> |
||||
<div class="panel-body"> |
||||
<h3 class="sub-title">{{ "CourseInformation"|get_lang }}</h3> |
||||
<div class="course-information"> |
||||
{% for topic in course.syllabus %} |
||||
{% if topic.content != '' %} |
||||
<div class="topics"> |
||||
<h4 class="title-info"> |
||||
<em class="fa fa-book"></em> {{ topic.title }} |
||||
</h4> |
||||
<div class="content-info"> |
||||
{{ topic.content }} |
||||
</div> |
||||
</div> |
||||
{% endif %} |
||||
{% endfor %} |
||||
</div> |
||||
</div> |
||||
</div> |
||||
</div> |
||||
|
||||
<div class="col-sm-4"> |
||||
<div class="panel panel-default"> |
||||
<div class="panel-body"> |
||||
{% if is_premium == false %} |
||||
<h5>{{ 'CourseSubscription'|get_lang }}</h5> |
||||
<div class="session-subscribe"> |
||||
{% if _u.logged == 0 %} |
||||
{% if 'allow_registration'|api_get_setting != 'false' %} |
||||
<a href="{{ _p.web_main ~ 'auth/inscription.php' ~ redirect_to_session }}" class="btn btn-success btn-block btn-lg"> |
||||
<i class="fa fa-pencil" aria-hidden="true"></i> {{ 'SignUp'|get_lang }} |
||||
</a> |
||||
{% endif %} |
||||
{% elseif course.subscription %} |
||||
<a href="{{ _p.web }}courses/{{ course.code }}/index.php?id_session=0" class="btn btn-lg btn-success btn-block">{{ 'CourseHomepage'|get_lang }}</a> |
||||
{% else %} |
||||
<a href="{{ _p.web }}courses/{{ course.code }}/index.php?action=subscribe&sec_token={{ token }}" class="btn btn-lg btn-success btn-block">{{ 'Subscribe'|get_lang }}</a> |
||||
{% endif %} |
||||
</div> |
||||
{% else %} |
||||
<div class="session-price"> |
||||
<div class="sale-price"> |
||||
{{ 'SalePrice'|get_lang }} |
||||
</div> |
||||
<div class="price-text"> |
||||
{{ is_premium.iso_code }} {{ is_premium.price }} |
||||
</div> |
||||
<div class="buy-box"> |
||||
<a href="{{ _p.web }}plugin/buycourses/src/process.php?i={{ is_premium.product_id }}&t={{ is_premium.product_type }}" class="btn btn-lg btn-primary btn-block">{{ 'BuyNow'|get_lang }}</a> |
||||
</div> |
||||
</div> |
||||
{% endif %} |
||||
</div> |
||||
</div> |
||||
<div class="panel panel-default"> |
||||
<div class="panel-body"> |
||||
<div class="panel-teachers"> |
||||
<h3 class="sub-title">{{ "Coaches"|get_lang }}</h3> |
||||
</div> |
||||
{% for teacher in course.teachers %} |
||||
<div class="coach-information"> |
||||
<div class="coach-header"> |
||||
<div class="coach-avatar"> |
||||
<img class="img-circle img-responsive" src="{{ teacher.image }}" alt="{{ teacher.complete_name }}"> |
||||
</div> |
||||
<div class="coach-title"> |
||||
<h4>{{ teacher.complete_name }}</h4> |
||||
<p> {{ teacher.diploma }}</p> |
||||
</div> |
||||
</div> |
||||
<div class="open-area {{ course.teachers | length >= 2 ? 'open-more' : ' ' }}"> |
||||
{{ teacher.openarea }} |
||||
</div> |
||||
</div> |
||||
{% endfor %} |
||||
|
||||
</div> |
||||
</div> |
||||
</div> |
||||
</div> |
||||
</section> |
||||
</div> |
||||
|
||||
<script type="text/javascript"> |
||||
$(document).ready(function() { |
||||
$('.course-information').readmore({ |
||||
speed: 100, |
||||
lessLink: '<a class="hide-content" href="#">{{ 'SetInvisible' | get_lang }}</a>', |
||||
moreLink: '<a class="read-more" href="#">{{ 'ReadMore' | get_lang }}</a>', |
||||
collapsedHeight: 730, |
||||
heightMargin: 100 |
||||
}); |
||||
$('.open-more').readmore({ |
||||
speed: 100, |
||||
lessLink: '<a class="hide-content" href="#">{{ 'SetInvisible' | get_lang }}</a>', |
||||
moreLink: '<a class="read-more" href="#">{{ 'ReadMore' | get_lang }}</a>', |
||||
collapsedHeight: 90, |
||||
heightMargin: 20 |
||||
}); |
||||
}); |
||||
</script> |
@ -1,25 +1,45 @@ |
||||
<p class="lead">{{ 'MyCoursePageCategoryIntroduction'|get_lang }}</p> |
||||
<ul class="media-list"> |
||||
{% import "ChamiloThemeBundle:Macros:box.html.twig" as macro %} |
||||
|
||||
<h2>{{ 'CourseCategory'|get_lang }}</h2> |
||||
<p>{{ 'MyCoursePageCategoryIntroduction'|get_lang }}</p> |
||||
{% autoescape false %} |
||||
<div class="row"> |
||||
{% for category in course_categories %} |
||||
<div class="col-sm-12"> |
||||
{% if category %} |
||||
<li class="media"> |
||||
<div class="media-left"> |
||||
<a href="{{ _p.web_self ~ '?' ~ {'category':category.code}|url_encode }}"> |
||||
<img src="{{ category.image ? _p.web_upload ~ category.image : 'session_default.png'|icon(128) }}" |
||||
alt="{{ category.name }}" width="200" class="media-object"> |
||||
|
||||
{% set image %} |
||||
<a href="{{ _p.web_self ~ '?' ~ {'category':category.code}|url_encode }}"> |
||||
<img src="{{ category.image ? _p.web_upload ~ category.image : 'session_default.png'|icon(128) }}" |
||||
alt="{{ category.name }}" class="img-fluid mb-1"> |
||||
</a> |
||||
{% endset %} |
||||
|
||||
{% set title %} |
||||
<a href="{{ _p.web_self ~ '?' ~ {'category':category.code}|url_encode }}"> |
||||
{{ category.name }} |
||||
</a> |
||||
{% endset %} |
||||
|
||||
{% set subtitle %} |
||||
{{ category.code }} |
||||
{% endset %} |
||||
|
||||
{% set content %} |
||||
{% if category.description %} |
||||
{{ category.description }} |
||||
{% endif %} |
||||
<div class="float-right"> |
||||
<a href="{{ _p.web_self ~ '?' ~ {'category':category.code}|url_encode }}" class="btn btn-outline-primary btn-sm"> |
||||
{{ 'View'|get_lang }} |
||||
</a> |
||||
</div> |
||||
<div class="media-body"> |
||||
<h4 class="media-heading">{{ category.name }}</h4> |
||||
<p>{{ category.code }}</p> |
||||
{% if category.description %} |
||||
<p>{{ category.description }}</p> |
||||
{% endif %} |
||||
<a href="{{ _p.web_self ~ '?' ~ {'category':category.code}|url_encode }}" class="btn btn-default"> |
||||
{{ 'View'|get_lang }} <span class="fa fa-arrow-right" aria-hidden="true"></span> |
||||
</a> |
||||
</div> |
||||
</li> |
||||
{% endset %} |
||||
|
||||
{{ macro.panel_row('category', title, subtitle, content, image) }} |
||||
|
||||
{% endif %} |
||||
</div> |
||||
{% endfor %} |
||||
</ul> |
||||
</div> |
||||
{% endautoescape %} |
Before Width: | Height: | Size: 3.0 KiB After Width: | Height: | Size: 1.7 KiB |
@ -0,0 +1,51 @@ |
||||
<?php |
||||
/* For licensing terms, see /license.txt */ |
||||
|
||||
namespace Chamilo\ApiBundle\GraphQL\Map; |
||||
|
||||
use Chamilo\ApiBundle\GraphQL\ApiGraphQLTrait; |
||||
use Chamilo\UserBundle\Entity\User; |
||||
use Overblog\GraphQLBundle\Resolver\ResolverMap; |
||||
use Symfony\Component\DependencyInjection\ContainerAwareInterface; |
||||
|
||||
/** |
||||
* Class EnumResolverMap. |
||||
* |
||||
* @package Chamilo\ApiBundle\GraphQL\Map |
||||
*/ |
||||
class EnumMap extends ResolverMap implements ContainerAwareInterface |
||||
{ |
||||
use ApiGraphQLTrait; |
||||
|
||||
/** |
||||
* @return array |
||||
*/ |
||||
protected function map() |
||||
{ |
||||
return [ |
||||
'UserStatus' => [ |
||||
'TEACHER' => User::TEACHER, |
||||
'SESSION_ADMIN' => User::SESSION_ADMIN, |
||||
'DRH' => User::DRH, |
||||
'STUDENT' => User::STUDENT, |
||||
], |
||||
'ImageSize' => [ |
||||
'ICON_SIZE_TINY' => ICON_SIZE_TINY, |
||||
'ICON_SIZE_SMALL' => ICON_SIZE_SMALL, |
||||
'ICON_SIZE_MEDIUM' => ICON_SIZE_MEDIUM, |
||||
'ICON_SIZE_LARGE' => ICON_SIZE_LARGE, |
||||
'ICON_SIZE_BIG' => ICON_SIZE_BIG, |
||||
'ICON_SIZE_HUGE' => ICON_SIZE_HUGE, |
||||
], |
||||
'CourseToolType' => [ |
||||
'TOOL_COURSE_DESCRIPTION' => TOOL_COURSE_DESCRIPTION, |
||||
'TOOL_ANNOUNCEMENT' => TOOL_ANNOUNCEMENT, |
||||
'TOOL_NOTEBOOK' => TOOL_NOTEBOOK, |
||||
'TOOL_FORUM' => TOOL_FORUM, |
||||
'TOOL_CALENDAR_EVENT' => TOOL_CALENDAR_EVENT, |
||||
'TOOL_DOCUMENT' => TOOL_DOCUMENT, |
||||
'TOOL_LEARNPATH' => TOOL_LEARNPATH, |
||||
], |
||||
]; |
||||
} |
||||
} |
@ -1,42 +0,0 @@ |
||||
<?php |
||||
/* For licensing terms, see /license.txt */ |
||||
|
||||
namespace Chamilo\ApiBundle\GraphQL\Map; |
||||
|
||||
use Chamilo\ApiBundle\GraphQL\ApiGraphQLTrait; |
||||
use Chamilo\UserBundle\Entity\User; |
||||
use Overblog\GraphQLBundle\Resolver\ResolverMap; |
||||
use Symfony\Component\DependencyInjection\ContainerAwareInterface; |
||||
|
||||
/** |
||||
* Class EnumResolverMap. |
||||
* |
||||
* @package Chamilo\ApiBundle\GraphQL\Map |
||||
*/ |
||||
class EnumResolverMap extends ResolverMap implements ContainerAwareInterface |
||||
{ |
||||
use ApiGraphQLTrait; |
||||
|
||||
/** |
||||
* @return array |
||||
*/ |
||||
protected function map() |
||||
{ |
||||
return [ |
||||
'UserStatus' => [ |
||||
'TEACHER' => User::TEACHER, |
||||
'SESSION_ADMIN' => User::SESSION_ADMIN, |
||||
'DRH' => User::DRH, |
||||
'STUDENT' => User::STUDENT, |
||||
], |
||||
'ImageSize' => [ |
||||
'SIZE_TINY' => ICON_SIZE_TINY, |
||||
'SIZE_SMALL' => ICON_SIZE_SMALL, |
||||
'SIZE_MEDIUM' => ICON_SIZE_MEDIUM, |
||||
'SIZE_LARGE' => ICON_SIZE_LARGE, |
||||
'SIZE_BIG' => ICON_SIZE_BIG, |
||||
'SIZE_HUGE' => ICON_SIZE_HUGE, |
||||
], |
||||
]; |
||||
} |
||||
} |
@ -0,0 +1,115 @@ |
||||
<?php |
||||
/* For licensing terms, see /license.txt */ |
||||
|
||||
namespace Chamilo\ApiBundle\GraphQL\Map; |
||||
|
||||
use Chamilo\ApiBundle\GraphQL\ApiGraphQLTrait; |
||||
use Chamilo\UserBundle\Entity\User; |
||||
use GraphQL\Type\Definition\ResolveInfo; |
||||
use Overblog\GraphQLBundle\Definition\Argument; |
||||
use Overblog\GraphQLBundle\Error\UserError; |
||||
use Overblog\GraphQLBundle\Resolver\ResolverMap; |
||||
use Symfony\Component\DependencyInjection\ContainerAwareInterface; |
||||
|
||||
/** |
||||
* Class MutationResolverMap. |
||||
* |
||||
* @package Chamilo\ApiBundle\GraphQL\Map |
||||
*/ |
||||
class MutationMap extends ResolverMap implements ContainerAwareInterface |
||||
{ |
||||
use ApiGraphQLTrait; |
||||
|
||||
/** |
||||
* @return array |
||||
*/ |
||||
protected function map() |
||||
{ |
||||
return [ |
||||
'Mutation' => [ |
||||
self::RESOLVE_FIELD => function ($value, Argument $args, \ArrayObject $context, ResolveInfo $info) { |
||||
$method = 'resolve'.ucfirst($info->fieldName); |
||||
|
||||
return $this->$method($args, $context); |
||||
}, |
||||
], |
||||
]; |
||||
} |
||||
|
||||
/** |
||||
* @param Argument $args |
||||
* |
||||
* @return array |
||||
*/ |
||||
protected function resolveAuthenticate(Argument $args) |
||||
{ |
||||
/** @var User $user */ |
||||
$user = $this->em->getRepository('ChamiloUserBundle:User')->findOneBy(['username' => $args['username']]); |
||||
|
||||
if (!$user) { |
||||
throw new UserError($this->translator->trans('User not found.')); |
||||
} |
||||
|
||||
$encoder = $this->container->get('security.password_encoder'); |
||||
$isValid = $encoder->isPasswordValid($user, $args['password']); |
||||
|
||||
if (!$isValid) { |
||||
throw new UserError($this->translator->trans('Password is not valid.')); |
||||
} |
||||
|
||||
return [ |
||||
'token' => $this->encodeToken($user), |
||||
]; |
||||
} |
||||
|
||||
/** |
||||
* @param Argument $args |
||||
* |
||||
* @return array |
||||
*/ |
||||
protected function resolveViewerSendMessage(Argument $args) |
||||
{ |
||||
$this->checkAuthorization(); |
||||
|
||||
$currentUser = $this->getCurrentUser(); |
||||
$usersRepo = $this->em->getRepository('ChamiloUserBundle:User'); |
||||
$users = $usersRepo->findUsersToSendMessage($currentUser->getId()); |
||||
$receivers = array_filter( |
||||
$args['receivers'], |
||||
function ($receiverId) use ($users) { |
||||
/** @var User $user */ |
||||
foreach ($users as $user) { |
||||
if ($user->getId() === (int) $receiverId) { |
||||
return true; |
||||
} |
||||
} |
||||
|
||||
return false; |
||||
} |
||||
); |
||||
|
||||
$result = []; |
||||
|
||||
foreach ($receivers as $receiverId) { |
||||
$messageId = \MessageManager::send_message( |
||||
$receiverId, |
||||
$args['subject'], |
||||
$args['text'], |
||||
[], |
||||
[], |
||||
0, |
||||
0, |
||||
0, |
||||
0, |
||||
$currentUser->getId() |
||||
); |
||||
|
||||
$result[] = [ |
||||
'receiverId' => $receiverId, |
||||
'sent' => (bool) $messageId, |
||||
]; |
||||
} |
||||
|
||||
return $result; |
||||
} |
||||
} |
@ -0,0 +1,482 @@ |
||||
<?php |
||||
/* For licensing terms, see /license.txt */ |
||||
|
||||
namespace Chamilo\ApiBundle\GraphQL\Map; |
||||
|
||||
use Chamilo\ApiBundle\GraphQL\ApiGraphQLTrait; |
||||
use Chamilo\ApiBundle\GraphQL\Resolver\ToolDescriptionResolver; |
||||
use Chamilo\CoreBundle\Entity\Course; |
||||
use Chamilo\CoreBundle\Entity\Message; |
||||
use Chamilo\CoreBundle\Entity\Session; |
||||
use Chamilo\CoreBundle\Entity\SessionCategory; |
||||
use Chamilo\CoreBundle\Security\Authorization\Voter\CourseVoter; |
||||
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; |
||||
use GraphQL\Type\Definition\ResolveInfo; |
||||
use Overblog\GraphQLBundle\Definition\Argument; |
||||
use Overblog\GraphQLBundle\Error\UserError; |
||||
use Overblog\GraphQLBundle\Resolver\ResolverMap; |
||||
use Symfony\Component\DependencyInjection\ContainerAwareInterface; |
||||
|
||||
/** |
||||
* Class QueryMap. |
||||
* |
||||
* @package Chamilo\ApiBundle\GraphQL\Map |
||||
*/ |
||||
class QueryMap extends ResolverMap implements ContainerAwareInterface |
||||
{ |
||||
use ApiGraphQLTrait; |
||||
|
||||
/** |
||||
* @return array |
||||
*/ |
||||
protected function map() |
||||
{ |
||||
return [ |
||||
'Query' => [ |
||||
self::RESOLVE_FIELD => function ($value, Argument $args, \ArrayObject $context, ResolveInfo $info) { |
||||
$context->offsetSet('course', null); |
||||
$context->offsetSet('session', null); |
||||
|
||||
$method = 'resolve'.ucfirst($info->fieldName); |
||||
|
||||
return $this->$method($args, $context); |
||||
}, |
||||
], |
||||
'User' => [ |
||||
self::RESOLVE_FIELD => function ( |
||||
User $user, |
||||
Argument $args, |
||||
\ArrayObject $context, |
||||
ResolveInfo $info |
||||
) { |
||||
$context->offsetSet('user', $user); |
||||
$resolver = $this->container->get('chamilo_api.graphql.resolver.user'); |
||||
|
||||
return $this->resolveField($info->fieldName, $user, $resolver, $args, $context); |
||||
}, |
||||
], |
||||
'UserMessage' => [ |
||||
self::RESOLVE_FIELD => function ( |
||||
Message $message, |
||||
Argument $args, |
||||
\ArrayObject $context, |
||||
ResolveInfo $info |
||||
) { |
||||
if ('sender' === $info->fieldName) { |
||||
return $message->getUserSender(); |
||||
} |
||||
|
||||
if ('hasAttachments' === $info->fieldName) { |
||||
return $message->getAttachments()->count() > 0; |
||||
} |
||||
|
||||
return $this->resolveField($info->fieldName, $message); |
||||
}, |
||||
], |
||||
'Course' => [ |
||||
self::RESOLVE_FIELD => function ( |
||||
Course $course, |
||||
Argument $args, |
||||
\ArrayObject $context, |
||||
ResolveInfo $info |
||||
) { |
||||
$context->offsetSet('course', $course); |
||||
$resolver = $this->container->get('chamilo_api.graphql.resolver.course'); |
||||
|
||||
return $this->resolveField($info->fieldName, $course, $resolver, $args, $context); |
||||
}, |
||||
], |
||||
'ToolDescription' => [ |
||||
self::RESOLVE_FIELD => function ( |
||||
CTool $tool, |
||||
Argument $args, |
||||
\ArrayObject $context, |
||||
ResolveInfo $info |
||||
) { |
||||
if ('descriptions' === $info->fieldName) { |
||||
$resolver = $this->container->get('chamilo_api.graphql.resolver.course'); |
||||
|
||||
return $resolver->getDescriptions($tool, $context); |
||||
} |
||||
|
||||
return $this->resolveField($info->fieldName, $tool); |
||||
}, |
||||
], |
||||
//'CourseDescription' => [], |
||||
'ToolAnnouncements' => [ |
||||
self::RESOLVE_FIELD => function ( |
||||
CTool $tool, |
||||
Argument $args, |
||||
\ArrayObject $context, |
||||
ResolveInfo $info |
||||
) { |
||||
$resolver = $this->container->get('chamilo_api.graphql.resolver.course'); |
||||
|
||||
if ('announcements' === $info->fieldName) { |
||||
return $resolver->getAnnouncements($tool, $context); |
||||
} |
||||
|
||||
if ('announcement' === $info->fieldName) { |
||||
return $resolver->getAnnouncement($args['id'], $context); |
||||
} |
||||
|
||||
return $this->resolveField($info->fieldName, $tool); |
||||
}, |
||||
], |
||||
'CourseAnnouncement' => [ |
||||
'content' => function (\stdClass $announcement, Argument $args, \ArrayObject $context) { |
||||
/** @var User $reader */ |
||||
$reader = $context->offsetGet('user'); |
||||
/** @var Course $course */ |
||||
$course = $context->offsetGet('course'); |
||||
/** @var Session $session */ |
||||
$session = $context->offsetGet('session'); |
||||
|
||||
return \AnnouncementManager::parseContent( |
||||
$reader->getId(), |
||||
$announcement->content, |
||||
$course->getCode(), |
||||
$session ? $session->getId() : 0 |
||||
); |
||||
}, |
||||
], |
||||
'ToolNotebook' => [ |
||||
self::RESOLVE_FIELD => function ( |
||||
CTool $tool, |
||||
Argument $args, |
||||
\ArrayObject $context, |
||||
ResolveInfo $info |
||||
) { |
||||
if ('notes' === $info->fieldName) { |
||||
$resolver = $this->container->get('chamilo_api.graphql.resolver.course'); |
||||
|
||||
return $resolver->getNotes($context); |
||||
} |
||||
|
||||
return $this->resolveField($info->fieldName, $tool); |
||||
}, |
||||
], |
||||
'CourseNote' => [ |
||||
'id' => function (CNotebook $note) { |
||||
return $note->getIid(); |
||||
}, |
||||
], |
||||
'ToolForums' => [ |
||||
self::RESOLVE_FIELD => function ( |
||||
CTool $tool, |
||||
Argument $args, |
||||
\ArrayObject $context, |
||||
ResolveInfo $info |
||||
) { |
||||
$resolver = $this->container->get('chamilo_api.graphql.resolver.course'); |
||||
|
||||
if ('categories' === $info->fieldName) { |
||||
return $resolver->getForumCategories($context); |
||||
} |
||||
|
||||
if ('forum' === $info->fieldName) { |
||||
return $resolver->getForum($args['id'], $context); |
||||
} |
||||
|
||||
if ('thread' === $info->fieldName) { |
||||
return $resolver->getThread($args['id'], $context); |
||||
} |
||||
|
||||
return $this->resolveField($info->fieldName, $tool); |
||||
}, |
||||
], |
||||
'CourseForumCategory' => [ |
||||
'id' => function (CForumCategory $category) { |
||||
return $category->getIid(); |
||||
}, |
||||
'title' => function (CForumCategory $category) { |
||||
return $category->getCatTitle(); |
||||
}, |
||||
'comment' => function (CForumCategory $category) { |
||||
return $category->getCatComment(); |
||||
}, |
||||
'forums' => function (CForumCategory $category, Argument $args, \ArrayObject $context) { |
||||
$resolver = $this->container->get('chamilo_api.graphql.resolver.course'); |
||||
|
||||
return $resolver->getForums($category, $context); |
||||
}, |
||||
], |
||||
'CourseForum' => [ |
||||
'id' => function (CForumForum $forum) { |
||||
return $forum->getIid(); |
||||
}, |
||||
'title' => function (CForumForum $forum) { |
||||
return $forum->getForumTitle(); |
||||
}, |
||||
'comment' => function (CForumForum $forum) { |
||||
return $forum->getForumComment(); |
||||
}, |
||||
'numberOfThreads' => function (CForumForum $forum) { |
||||
return (int) $forum->getForumThreads(); |
||||
}, |
||||
'numberOfPosts' => function (CForumForum $forum) { |
||||
return (int) $forum->getForumPosts(); |
||||
}, |
||||
'threads' => function (CForumForum $forum, Argument $args, \ArrayObject $context) { |
||||
$resolver = $this->container->get('chamilo_api.graphql.resolver.course'); |
||||
|
||||
return $resolver->getThreads($forum, $context); |
||||
}, |
||||
], |
||||
'CourseForumThread' => [ |
||||
'id' => function (CForumThread $thread) { |
||||
return $thread->getIid(); |
||||
}, |
||||
'title' => function (CForumThread $thread) { |
||||
return $thread->getThreadTitle(); |
||||
}, |
||||
'userPoster' => function (CForumThread $thread) { |
||||
$userRepo = $this->em->getRepository('ChamiloUserBundle:User'); |
||||
$user = $userRepo->find($thread->getThreadPosterId()); |
||||
|
||||
return $user; |
||||
}, |
||||
'date' => function (CForumThread $thread) { |
||||
return $thread->getThreadDate(); |
||||
}, |
||||
'sticky' => function (CForumThread $thread) { |
||||
return $thread->getThreadSticky(); |
||||
}, |
||||
'numberOfViews' => function (CForumThread $thread) { |
||||
return $thread->getThreadViews(); |
||||
}, |
||||
'numberOfReplies' => function (CForumThread $thread) { |
||||
return $thread->getThreadReplies(); |
||||
}, |
||||
'closeDate' => function (CForumThread $thread) { |
||||
return $thread->getThreadCloseDate(); |
||||
}, |
||||
'posts' => function (CForumThread $thread, Argument $args, \ArrayObject $context) { |
||||
$resolver = $this->container->get('chamilo_api.graphql.resolver.course'); |
||||
|
||||
return $resolver->getPosts($thread, $context); |
||||
} |
||||
], |
||||
'CourseForumPost' => [ |
||||
'id' => function (CForumPost $post) { |
||||
return $post->getIid(); |
||||
}, |
||||
'title' => function (CForumPost $post) { |
||||
return $post->getPostTitle(); |
||||
}, |
||||
'text' => function (CForumPost $post) { |
||||
return $post->getPostText(); |
||||
}, |
||||
'userPoster' => function (CForumPost $post) { |
||||
$userRepo = $this->em->getRepository('ChamiloUserBundle:User'); |
||||
$user = $userRepo->find($post->getPosterId()); |
||||
|
||||
return $user; |
||||
}, |
||||
'date' => function (CForumPost $post) { |
||||
return $post->getPostDate(); |
||||
}, |
||||
'parent' => function (CForumPost $post) { |
||||
$postRepo = $this->em->getRepository('ChamiloCourseBundle:CForumPost'); |
||||
$parent = $postRepo->find((int) $post->getPostParentId()); |
||||
|
||||
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')); |
||||
}, |
||||
], |
||||
'ToolDocuments' => [ |
||||
'documents' => function (CTool $tool, Argument $args, \ArrayObject $context) { |
||||
$resolver = $this->container->get('chamilo_api.graphql.resolver.course'); |
||||
|
||||
$dirId = !empty($args['dirId']) ? $args['dirId'] : null; |
||||
|
||||
return $resolver->getDocuments($dirId, $context); |
||||
}, |
||||
], |
||||
//'CourseDocument' => [], |
||||
'ToolLearningPath' => [ |
||||
'categories' => function (CTool $tool, Argument $args, \ArrayObject $context) { |
||||
$resolver = $this->container->get('chamilo_api.graphql.resolver.course'); |
||||
|
||||
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, |
||||
Argument $args, |
||||
\ArrayObject $context, |
||||
ResolveInfo $info |
||||
) { |
||||
$context->offsetSet('session', $session); |
||||
$resolver = $this->container->get('chamilo_api.graphql.resolver.session'); |
||||
|
||||
return $this->resolveField($info->fieldName, $session, $resolver, $args, $context); |
||||
}, |
||||
], |
||||
'SessionCategory' => [ |
||||
self::RESOLVE_FIELD => function ( |
||||
SessionCategory $category, |
||||
Argument $args, |
||||
\ArrayObject $context, |
||||
ResolveInfo $info |
||||
) { |
||||
if ('startDate' === $info->fieldName) { |
||||
return $category->getDateStart(); |
||||
} |
||||
|
||||
if ('endDate' === $info->fieldName) { |
||||
return $category->getDateEnd(); |
||||
} |
||||
|
||||
return $this->resolveField($info->fieldName, $category); |
||||
}, |
||||
], |
||||
]; |
||||
} |
||||
|
||||
/** |
||||
* @param string $fieldName |
||||
* @param object $object |
||||
* @param object|null $resolver |
||||
* @param Argument|null $args |
||||
* @param \ArrayObject|null $context |
||||
* |
||||
* @return mixed |
||||
*/ |
||||
private function resolveField( |
||||
$fieldName, |
||||
$object, |
||||
$resolver = null, |
||||
Argument $args = null, |
||||
\ArrayObject $context = null |
||||
) { |
||||
$method = 'get'.ucfirst($fieldName); |
||||
|
||||
if ($resolver && $args && $context && method_exists($resolver, $method)) { |
||||
return $resolver->$method($object, $args, $context); |
||||
} |
||||
|
||||
return $object->$method(); |
||||
} |
||||
|
||||
/** |
||||
* @return User |
||||
*/ |
||||
protected function resolveViewer() |
||||
{ |
||||
$this->checkAuthorization(); |
||||
|
||||
return $this->getCurrentUser(); |
||||
} |
||||
|
||||
/** |
||||
* @param Argument $args |
||||
* |
||||
* @return Course |
||||
*/ |
||||
protected function resolveCourse(Argument $args) |
||||
{ |
||||
$this->checkAuthorization(); |
||||
|
||||
$id = (int) $args['id']; |
||||
|
||||
$courseRepo = $this->em->getRepository('ChamiloCoreBundle:Course'); |
||||
$course = $courseRepo->find($id); |
||||
|
||||
if (!$course) { |
||||
throw new UserError($this->translator->trans('Course not found.')); |
||||
} |
||||
|
||||
$checker = $this->container->get('security.authorization_checker'); |
||||
|
||||
if (false === $checker->isGranted(CourseVoter::VIEW, $course)) { |
||||
throw new UserError($this->translator->trans('Not allowed')); |
||||
} |
||||
|
||||
return $course; |
||||
} |
||||
|
||||
/** |
||||
* @param Argument $args |
||||
* |
||||
* @return Session |
||||
*/ |
||||
protected function resolveSession(Argument $args) |
||||
{ |
||||
$this->checkAuthorization(); |
||||
|
||||
$sessionRepo = $this->em->getRepository('ChamiloCoreBundle:Session'); |
||||
/** @var Session $session */ |
||||
$session = $sessionRepo->find($args['id']); |
||||
|
||||
if (!$session) { |
||||
throw new UserError($this->translator->trans('Session not found.')); |
||||
} |
||||
|
||||
return $session; |
||||
} |
||||
|
||||
/** |
||||
* @param Argument $args |
||||
* |
||||
* @return SessionCategory |
||||
*/ |
||||
protected function resolveSessionCategory(Argument $args) |
||||
{ |
||||
$this->checkAuthorization(); |
||||
|
||||
$repo = $this->em->getRepository('ChamiloCoreBundle:SessionCategory'); |
||||
/** @var SessionCategory $category */ |
||||
$category = $repo->find($args['id']); |
||||
|
||||
if (!$category) { |
||||
throw new UserError($this->translator->trans('Session category not found.')); |
||||
} |
||||
|
||||
return $category; |
||||
} |
||||
} |
@ -1,277 +0,0 @@ |
||||
<?php |
||||
/* For licensing terms, see /license.txt */ |
||||
|
||||
namespace Chamilo\ApiBundle\GraphQL\Map; |
||||
|
||||
use Chamilo\ApiBundle\GraphQL\ApiGraphQLTrait; |
||||
use Chamilo\CoreBundle\Entity\Course; |
||||
use Chamilo\CoreBundle\Entity\Message; |
||||
use Chamilo\CoreBundle\Entity\Session; |
||||
use Chamilo\CoreBundle\Entity\SessionCategory; |
||||
use Chamilo\CoreBundle\Entity\SessionRelCourse; |
||||
use Chamilo\CoreBundle\Entity\SessionRelCourseRelUser; |
||||
use Chamilo\CoreBundle\Security\Authorization\Voter\CourseVoter; |
||||
use Chamilo\CoreBundle\Security\Authorization\Voter\SessionVoter; |
||||
use Chamilo\UserBundle\Entity\User; |
||||
use GraphQL\Type\Definition\ResolveInfo; |
||||
use Overblog\GraphQLBundle\Definition\Argument; |
||||
use Overblog\GraphQLBundle\Error\UserError; |
||||
use Overblog\GraphQLBundle\Resolver\ResolverMap; |
||||
use Symfony\Component\DependencyInjection\ContainerAwareInterface; |
||||
|
||||
/** |
||||
* Class RootResolverMap |
||||
* @package Chamilo\ApiBundle\GraphQL\Map |
||||
*/ |
||||
class RootResolverMap extends ResolverMap implements ContainerAwareInterface |
||||
{ |
||||
use ApiGraphQLTrait; |
||||
|
||||
/** |
||||
* @return array |
||||
*/ |
||||
protected function map() |
||||
{ |
||||
return [ |
||||
'Query' => [ |
||||
self::RESOLVE_FIELD => function ($value, Argument $args, \ArrayObject $context, ResolveInfo $info) { |
||||
switch ($info->fieldName) { |
||||
case 'viewer': |
||||
return $this->resolveViewer(); |
||||
case 'course': |
||||
return $this->resolveCourse($args['id']); |
||||
case 'session': |
||||
$this->resolveSession($args['id']); |
||||
case 'sessionCategory': |
||||
return $this->resolveSessionCategory($args['id']); |
||||
} |
||||
}, |
||||
], |
||||
'UserMessage' => [ |
||||
self::RESOLVE_FIELD => function ( |
||||
Message $message, |
||||
Argument $args, |
||||
\ArrayObject $context, |
||||
ResolveInfo $info |
||||
) { |
||||
switch ($info->fieldName) { |
||||
case 'sender': |
||||
return $message->getUserSender(); |
||||
case 'excerpt': |
||||
$striped = strip_tags($message->getContent()); |
||||
$replaced = str_replace(["\r\n", "\n"], ' ', $striped); |
||||
$trimmed = trim($replaced); |
||||
|
||||
return api_trunc_str($trimmed, $args['length']); |
||||
case 'hasAttachments': |
||||
return $message->getAttachments()->count() > 0; |
||||
default: |
||||
$method = 'get'.ucfirst($info->fieldName); |
||||
|
||||
if (method_exists($message, $method)) { |
||||
return $message->$method(); |
||||
} |
||||
|
||||
return null; |
||||
} |
||||
}, |
||||
], |
||||
'Course' => [ |
||||
self::RESOLVE_FIELD => function ( |
||||
Course $course, |
||||
Argument $args, |
||||
\ArrayObject $context, |
||||
ResolveInfo $info |
||||
) { |
||||
$context->offsetSet('course', $course); |
||||
|
||||
switch ($info->fieldName) { |
||||
case 'picture': |
||||
return \CourseManager::getPicturePath($course, $args['fullSize']); |
||||
case 'teachers': |
||||
if ($context->offsetExists('session')) { |
||||
/** @var Session $session */ |
||||
$session = $context->offsetGet('session'); |
||||
|
||||
if ($session) { |
||||
$coaches = []; |
||||
$coachSubscriptions = $session->getUserCourseSubscriptionsByStatus( |
||||
$course, |
||||
Session::COACH |
||||
); |
||||
|
||||
/** @var SessionRelCourseRelUser $coachSubscription */ |
||||
foreach ($coachSubscriptions as $coachSubscription) { |
||||
$coaches[] = $coachSubscription->getUser(); |
||||
} |
||||
|
||||
return $coaches; |
||||
} |
||||
} |
||||
|
||||
$courseRepo = $this->em->getRepository('ChamiloCoreBundle:Course'); |
||||
$teachers = $courseRepo |
||||
->getSubscribedTeachers($course) |
||||
->getQuery() |
||||
->getResult(); |
||||
|
||||
return $teachers; |
||||
default: |
||||
$method = 'get'.ucfirst($info->fieldName); |
||||
|
||||
if (method_exists($course, $method)) { |
||||
return $course->$method(); |
||||
} |
||||
|
||||
return null; |
||||
} |
||||
} |
||||
], |
||||
'Session' => [ |
||||
self::RESOLVE_FIELD => function ( |
||||
Session $session, |
||||
Argument $args, |
||||
\ArrayObject $context, |
||||
ResolveInfo $info |
||||
) { |
||||
$context->offsetSet('session', $session); |
||||
|
||||
switch ($info->fieldName) { |
||||
case 'description': |
||||
if (false === $session->getShowDescription()) { |
||||
return ''; |
||||
} |
||||
|
||||
return $session->getDescription(); |
||||
case 'numberOfUsers': |
||||
return $session->getNbrUsers(); |
||||
case 'numberOfCourses': |
||||
return $session->getNbrCourses(); |
||||
case 'courses': |
||||
$authChecker = $this->container->get('security.authorization_checker'); |
||||
$courses = []; |
||||
|
||||
/** @var SessionRelCourse $sessionCourse */ |
||||
foreach ($session->getCourses() as $sessionCourse) { |
||||
$course = $sessionCourse->getCourse(); |
||||
|
||||
$session->setCurrentCourse($course); |
||||
|
||||
if (false !== $authChecker->isGranted(SessionVoter::VIEW, $session)) { |
||||
$courses[] = $course; |
||||
} |
||||
} |
||||
|
||||
return $courses; |
||||
default: |
||||
$method = 'get'.ucfirst($info->fieldName); |
||||
|
||||
if (method_exists($session, $method)) { |
||||
return $session->$method(); |
||||
} |
||||
|
||||
return null; |
||||
} |
||||
}, |
||||
], |
||||
'SessionCategory' => [ |
||||
self::RESOLVE_FIELD => function ( |
||||
SessionCategory $category, |
||||
Argument $args, |
||||
\ArrayObject $context, |
||||
ResolveInfo $info |
||||
) { |
||||
switch ($info->fieldName) { |
||||
case 'startDate': |
||||
return $category->getDateStart(); |
||||
case 'endDate': |
||||
return $category->getDateEnd(); |
||||
default: |
||||
$method = 'get'.ucfirst($info->fieldName); |
||||
|
||||
if (method_exists($category, $method)) { |
||||
return $category->$method(); |
||||
} |
||||
|
||||
return null; |
||||
} |
||||
} |
||||
], |
||||
]; |
||||
} |
||||
|
||||
/** |
||||
* @return User |
||||
*/ |
||||
private function resolveViewer() |
||||
{ |
||||
$this->checkAuthorization(); |
||||
|
||||
return $this->getCurrentUser(); |
||||
} |
||||
|
||||
/** |
||||
* @param int $id |
||||
* |
||||
* @return Course |
||||
*/ |
||||
private function resolveCourse($id) |
||||
{ |
||||
$this->checkAuthorization(); |
||||
|
||||
$courseRepo = $this->em->getRepository('ChamiloCoreBundle:Course'); |
||||
$course = $courseRepo->find((int) $id); |
||||
|
||||
if (!$course) { |
||||
throw new UserError($this->translator->trans('Course not found.')); |
||||
} |
||||
|
||||
$checker = $this->container->get('security.authorization_checker'); |
||||
|
||||
if (false === $checker->isGranted(CourseVoter::VIEW, $course)) { |
||||
throw new UserError($this->translator->trans('Not allowed')); |
||||
} |
||||
|
||||
return $course; |
||||
} |
||||
|
||||
/** |
||||
* @param int $id |
||||
* |
||||
* @return Session |
||||
*/ |
||||
private function resolveSession($id) |
||||
{ |
||||
$this->checkAuthorization(); |
||||
|
||||
$sessionRepo = $this->em->getRepository('ChamiloCoreBundle:Session'); |
||||
/** @var Session $session */ |
||||
$session = $sessionRepo->find((int) $id); |
||||
|
||||
if (!$session) { |
||||
throw new UserError($this->translator->trans('Session not found.')); |
||||
} |
||||
|
||||
return $session; |
||||
} |
||||
|
||||
/** |
||||
* @param int $id |
||||
* |
||||
* @return SessionCategory |
||||
*/ |
||||
private function resolveSessionCategory($id) |
||||
{ |
||||
$this->checkAuthorization(); |
||||
|
||||
$repo = $this->em->getRepository('ChamiloCoreBundle:SessionCategory'); |
||||
/** @var SessionCategory $category */ |
||||
$category = $repo->find((int) $id); |
||||
|
||||
if (!$category) { |
||||
throw new UserError($this->translator->trans('Session category not found.')); |
||||
} |
||||
|
||||
return $category; |
||||
} |
||||
} |
@ -0,0 +1,48 @@ |
||||
<?php |
||||
/* For licensing terms, see /license.txt */ |
||||
|
||||
namespace Chamilo\ApiBundle\GraphQL\Map; |
||||
|
||||
use Chamilo\ApiBundle\GraphQL\ApiGraphQLTrait; |
||||
use Chamilo\CourseBundle\Entity\CTool; |
||||
use Overblog\GraphQLBundle\Resolver\ResolverMap; |
||||
use Symfony\Component\DependencyInjection\ContainerAwareInterface; |
||||
|
||||
/** |
||||
* Class UnionMap. |
||||
* |
||||
* @package Chamilo\ApiBundle\GraphQL\Map |
||||
*/ |
||||
class UnionMap extends ResolverMap implements ContainerAwareInterface |
||||
{ |
||||
use ApiGraphQLTrait; |
||||
|
||||
/** |
||||
* @return array |
||||
*/ |
||||
protected function map() |
||||
{ |
||||
return [ |
||||
'CourseTool' => [ |
||||
self::RESOLVE_TYPE => function (CTool $tool) { |
||||
switch ($tool->getName()) { |
||||
case TOOL_COURSE_DESCRIPTION: |
||||
return 'ToolDescription'; |
||||
case TOOL_ANNOUNCEMENT: |
||||
return 'ToolAnnouncements'; |
||||
case TOOL_NOTEBOOK: |
||||
return 'ToolNotebook'; |
||||
case TOOL_FORUM: |
||||
return 'ToolForums'; |
||||
case TOOL_CALENDAR_EVENT: |
||||
return 'ToolAgenda'; |
||||
case TOOL_DOCUMENT: |
||||
return 'ToolDocuments'; |
||||
case TOOL_LEARNPATH: |
||||
return 'ToolLearningPath'; |
||||
} |
||||
}, |
||||
], |
||||
]; |
||||
} |
||||
} |
@ -1,49 +0,0 @@ |
||||
<?php |
||||
/* For licensing terms, see /license.txt */ |
||||
|
||||
namespace Chamilo\ApiBundle\GraphQL\Mutation; |
||||
|
||||
use Chamilo\ApiBundle\GraphQL\ApiGraphQLTrait; |
||||
use Overblog\GraphQLBundle\Definition\Argument; |
||||
use Overblog\GraphQLBundle\Definition\Resolver\AliasedInterface; |
||||
use Overblog\GraphQLBundle\Definition\Resolver\MutationInterface; |
||||
use Symfony\Component\DependencyInjection\ContainerAwareInterface; |
||||
|
||||
/** |
||||
* Class RootMutation. |
||||
* |
||||
* @package Chamilo\ApiBundle\GraphQL\Mutation |
||||
*/ |
||||
class RootMutation implements MutationInterface, AliasedInterface, ContainerAwareInterface |
||||
{ |
||||
use ApiGraphQLTrait; |
||||
|
||||
/** |
||||
* Returns methods aliases. |
||||
* |
||||
* For instance: |
||||
* array('myMethod' => 'myAlias') |
||||
* |
||||
* @return array |
||||
*/ |
||||
public static function getAliases() |
||||
{ |
||||
return [ |
||||
'mutationAuthenticate' => 'authenticate', |
||||
]; |
||||
} |
||||
|
||||
/** |
||||
* @param Argument $args |
||||
* |
||||
* @return array |
||||
*/ |
||||
public function mutationAuthenticate(Argument $args) |
||||
{ |
||||
$token = $this->getUserToken($args['username'], $args['password']); |
||||
|
||||
return [ |
||||
'token' => $token, |
||||
]; |
||||
} |
||||
} |
@ -1,88 +0,0 @@ |
||||
<?php |
||||
/* For licensing terms, see /license.txt */ |
||||
|
||||
namespace Chamilo\ApiBundle\GraphQL\Mutation; |
||||
|
||||
use Chamilo\ApiBundle\GraphQL\ApiGraphQLTrait; |
||||
use Chamilo\UserBundle\Entity\User; |
||||
use Overblog\GraphQLBundle\Definition\Argument; |
||||
use Overblog\GraphQLBundle\Definition\Resolver\AliasedInterface; |
||||
use Overblog\GraphQLBundle\Definition\Resolver\MutationInterface; |
||||
use Symfony\Component\DependencyInjection\ContainerAwareInterface; |
||||
|
||||
/** |
||||
* Class UserMutation. |
||||
* |
||||
* @package Chamilo\ApiBundle\GraphQL\Mutation |
||||
*/ |
||||
class UserMutation implements MutationInterface, AliasedInterface, ContainerAwareInterface |
||||
{ |
||||
use ApiGraphQLTrait; |
||||
|
||||
/** |
||||
* Returns methods aliases. |
||||
* |
||||
* For instance: |
||||
* array('myMethod' => 'myAlias') |
||||
* |
||||
* @return array |
||||
*/ |
||||
public static function getAliases() |
||||
{ |
||||
return [ |
||||
'mutateSendMessage' => 'user_send_message', |
||||
]; |
||||
} |
||||
|
||||
/** |
||||
* @param Argument $args |
||||
* |
||||
* @return array |
||||
*/ |
||||
public function mutateSendMessage(Argument $args): array |
||||
{ |
||||
$this->checkAuthorization(); |
||||
|
||||
$currentUser = $this->getCurrentUser(); |
||||
$usersRepo = $this->em->getRepository('ChamiloUserBundle:User'); |
||||
$users = $usersRepo->findUsersToSendMessage($currentUser->getId()); |
||||
$result = []; |
||||
|
||||
foreach ($args['receivers'] as $receiverId) { |
||||
$sentMessage = false; |
||||
|
||||
/** @var User $user */ |
||||
foreach ($users as $user) { |
||||
if ((int) $receiverId === $user->getId()) { |
||||
$sentMessage = true; |
||||
} |
||||
} |
||||
|
||||
$item = [ |
||||
'receiverId' => $receiverId, |
||||
'sent' => false, |
||||
]; |
||||
|
||||
if ($sentMessage) { |
||||
$messageId = \MessageManager::send_message( |
||||
$receiverId, |
||||
$args['subject'], |
||||
$args['text'], |
||||
[], |
||||
[], |
||||
0, |
||||
0, |
||||
0, |
||||
0, |
||||
$currentUser->getId() |
||||
); |
||||
|
||||
$item['sent'] = (bool) $messageId; |
||||
} |
||||
|
||||
$result[] = $item; |
||||
} |
||||
|
||||
return $result; |
||||
} |
||||
} |
@ -1,88 +0,0 @@ |
||||
<?php |
||||
/* For licensing terms, see /license.txt */ |
||||
|
||||
namespace Chamilo\ApiBundle\GraphQL\Resolver; |
||||
|
||||
use Chamilo\ApiBundle\GraphQL\ApiGraphQLTrait; |
||||
use Chamilo\CourseBundle\Entity\CAnnouncement; |
||||
use Chamilo\CourseBundle\Entity\CItemProperty; |
||||
use Chamilo\UserBundle\Entity\User; |
||||
use GraphQL\Type\Definition\ResolveInfo; |
||||
use Overblog\GraphQLBundle\Definition\Argument; |
||||
use Overblog\GraphQLBundle\Definition\Resolver\ResolverInterface; |
||||
use Symfony\Component\DependencyInjection\ContainerAwareInterface; |
||||
|
||||
/** |
||||
* Class CourseAnnouncementResolver. |
||||
* |
||||
* @package Chamilo\ApiBundle\GraphQL\Resolver |
||||
*/ |
||||
class CourseAnnouncementResolver implements ResolverInterface, ContainerAwareInterface |
||||
{ |
||||
use ApiGraphQLTrait; |
||||
|
||||
/** |
||||
* @param array $item |
||||
* @param Argument $args |
||||
* @param ResolveInfo $info |
||||
* @param \ArrayObject $context |
||||
* |
||||
* @return mixed |
||||
*/ |
||||
public function __invoke(array $item, Argument $args, ResolveInfo $info, \ArrayObject $context) |
||||
{ |
||||
/** @var CAnnouncement $announcement */ |
||||
$announcement = $item['announcement']; |
||||
/** @var CItemProperty $itemProperty */ |
||||
$itemProperty = $item['item_property']; |
||||
$method = 'resolve'.ucfirst($info->fieldName); |
||||
|
||||
if (method_exists($this, $method)) { |
||||
return $this->$method($announcement, $itemProperty, $args, $context); |
||||
} |
||||
|
||||
$method = 'get'.ucfirst($info->fieldName); |
||||
|
||||
if (method_exists($announcement, $method)) { |
||||
return $announcement->$method(); |
||||
} |
||||
|
||||
if (method_exists($itemProperty, $method)) { |
||||
return $itemProperty->$method(); |
||||
} |
||||
|
||||
return null; |
||||
} |
||||
|
||||
/** |
||||
* @param CAnnouncement $announcement |
||||
* |
||||
* @return int |
||||
*/ |
||||
public function resolveId(CAnnouncement $announcement) |
||||
{ |
||||
return $announcement->getIid(); |
||||
} |
||||
|
||||
/** |
||||
* @param CAnnouncement $announcement |
||||
* @param CItemProperty $itemProperty |
||||
* |
||||
* @return User |
||||
*/ |
||||
public function resolveBy(CAnnouncement $announcement, CItemProperty $itemProperty) |
||||
{ |
||||
return $itemProperty->getInsertUser(); |
||||
} |
||||
|
||||
/** |
||||
* @param CAnnouncement $announcement |
||||
* @param CItemProperty $itemProperty |
||||
* |
||||
* @return \DateTime |
||||
*/ |
||||
public function resolveLastUpdateDate(CAnnouncement $announcement, CItemProperty $itemProperty) |
||||
{ |
||||
return $itemProperty->getLasteditDate(); |
||||
} |
||||
} |
@ -1,54 +0,0 @@ |
||||
<?php |
||||
/* For licensing terms, see /license.txt */ |
||||
|
||||
namespace Chamilo\ApiBundle\GraphQL\Resolver; |
||||
|
||||
use Chamilo\ApiBundle\GraphQL\ApiGraphQLTrait; |
||||
use Chamilo\CourseBundle\Entity\CCourseDescription; |
||||
use GraphQL\Type\Definition\ResolveInfo; |
||||
use Overblog\GraphQLBundle\Definition\Argument; |
||||
use Overblog\GraphQLBundle\Definition\Resolver\ResolverInterface; |
||||
use Symfony\Component\DependencyInjection\ContainerAwareInterface; |
||||
|
||||
/** |
||||
* Class CourseDescriptionResolver. |
||||
* |
||||
* @package Chamilo\ApiBundle\GraphQL\Resolver |
||||
*/ |
||||
class CourseDescriptionResolver implements ResolverInterface, ContainerAwareInterface |
||||
{ |
||||
use ApiGraphQLTrait; |
||||
|
||||
/** |
||||
* @param CCourseDescription $description |
||||
* @param Argument $args |
||||
* @param ResolveInfo $info |
||||
* @param \ArrayObject $context |
||||
*/ |
||||
public function __invoke(CCourseDescription $description, Argument $args, ResolveInfo $info, \ArrayObject $context) |
||||
{ |
||||
$method = 'resolve'.ucfirst($info->fieldName); |
||||
|
||||
if (method_exists($this, $method)) { |
||||
return $this->$method($description, $args, $context); |
||||
} |
||||
|
||||
$method = 'get'.ucfirst($info->fieldName); |
||||
|
||||
if (method_exists($description, $method)) { |
||||
return $description->$method(); |
||||
} |
||||
|
||||
return null; |
||||
} |
||||
|
||||
/** |
||||
* @param CCourseDescription $description |
||||
* |
||||
* @return int |
||||
*/ |
||||
public function resolveType(CCourseDescription $description) |
||||
{ |
||||
return $description->getDescriptionType(); |
||||
} |
||||
} |
@ -1,59 +0,0 @@ |
||||
<?php |
||||
/* For licensing terms, see /license.txt */ |
||||
|
||||
namespace Chamilo\ApiBundle\GraphQL\Resolver; |
||||
|
||||
use Chamilo\ApiBundle\GraphQL\ApiGraphQLTrait; |
||||
use Chamilo\CourseBundle\Entity\CTool; |
||||
use Doctrine\ORM\EntityManager; |
||||
use Overblog\GraphQLBundle\Definition\Resolver\ResolverInterface; |
||||
use Overblog\GraphQLBundle\Resolver\TypeResolver; |
||||
use Symfony\Component\DependencyInjection\ContainerAwareInterface; |
||||
use Symfony\Component\Translation\TranslatorInterface; |
||||
|
||||
/** |
||||
* Class CourseToolResolver. |
||||
* |
||||
* @package Chamilo\ApiBundle\GraphQL\Resolver |
||||
*/ |
||||
class CourseToolResolver implements ResolverInterface, ContainerAwareInterface |
||||
{ |
||||
use ApiGraphQLTrait; |
||||
|
||||
/** |
||||
* @var TypeResolver |
||||
*/ |
||||
private $typeResolver; |
||||
|
||||
/** |
||||
* CourseToolResolver constructor. |
||||
* |
||||
* @param EntityManager $entityManager |
||||
* @param TranslatorInterface $translator |
||||
* @param TypeResolver $typeResolver |
||||
*/ |
||||
public function __construct( |
||||
EntityManager $entityManager, |
||||
TranslatorInterface $translator, |
||||
TypeResolver $typeResolver |
||||
) { |
||||
$this->em = $entityManager; |
||||
$this->translator = $translator; |
||||
$this->typeResolver = $typeResolver; |
||||
} |
||||
|
||||
/** |
||||
* @param CTool $tool |
||||
* |
||||
* @return \GraphQL\Type\Definition\Type |
||||
*/ |
||||
public function __invoke(CTool $tool) |
||||
{ |
||||
switch ($tool->getName()) { |
||||
case TOOL_COURSE_DESCRIPTION: |
||||
return $this->typeResolver->resolve('ToolDescription'); |
||||
case TOOL_ANNOUNCEMENT: |
||||
return $this->typeResolver->resolve('ToolAnnouncements'); |
||||
} |
||||
} |
||||
} |
@ -1,51 +0,0 @@ |
||||
<?php |
||||
/* For licensing terms, see /license.txt */ |
||||
|
||||
namespace Chamilo\ApiBundle\GraphQL\Resolver; |
||||
|
||||
use Chamilo\CourseBundle\Entity\CTool; |
||||
use GraphQL\Type\Definition\ResolveInfo; |
||||
use Overblog\GraphQLBundle\Definition\Argument; |
||||
|
||||
/** |
||||
* Trait CourseToolResolverTrait. |
||||
* |
||||
* @package Chamilo\ApiBundle\GraphQL\Resolver |
||||
*/ |
||||
trait CourseToolResolverTrait |
||||
{ |
||||
/** |
||||
* @param CTool $tool |
||||
* @param Argument $args |
||||
* @param ResolveInfo $info |
||||
* @param \ArrayObject $context |
||||
* |
||||
* @return mixed |
||||
*/ |
||||
public function __invoke(CTool $tool, Argument $args, ResolveInfo $info, \ArrayObject $context) |
||||
{ |
||||
$method = 'resolve'.ucfirst($info->fieldName); |
||||
|
||||
if (method_exists($this, $method)) { |
||||
return $this->$method($tool, $args, $context); |
||||
} |
||||
|
||||
$method = 'get'.ucfirst($info->fieldName); |
||||
|
||||
if (method_exists($tool, $method)) { |
||||
return $tool->$method(); |
||||
} |
||||
|
||||
return null; |
||||
} |
||||
|
||||
/** |
||||
* @param CTool $tool |
||||
* |
||||
* @return bool |
||||
*/ |
||||
public function resolveIsVisible(CTool $tool): bool |
||||
{ |
||||
return (bool) $tool->getVisibility(); |
||||
} |
||||
} |
@ -0,0 +1,78 @@ |
||||
<?php |
||||
/* For licensing terms, see /license.txt */ |
||||
|
||||
namespace Chamilo\ApiBundle\GraphQL\Resolver; |
||||
|
||||
use Chamilo\ApiBundle\GraphQL\ApiGraphQLTrait; |
||||
use Chamilo\CoreBundle\Entity\Session; |
||||
use Chamilo\CoreBundle\Entity\SessionRelCourse; |
||||
use Chamilo\CoreBundle\Security\Authorization\Voter\SessionVoter; |
||||
use Symfony\Component\DependencyInjection\ContainerAwareInterface; |
||||
|
||||
/** |
||||
* Class SessionResolver. |
||||
* |
||||
* @package Chamilo\ApiBundle\GraphQL\Resolver |
||||
*/ |
||||
class SessionResolver implements ContainerAwareInterface |
||||
{ |
||||
use ApiGraphQLTrait; |
||||
|
||||
/** |
||||
* @param Session $session |
||||
* |
||||
* @return string |
||||
*/ |
||||
public function getDescription(Session $session) |
||||
{ |
||||
if (false === $session->getShowDescription()) { |
||||
return ''; |
||||
} |
||||
|
||||
return $session->getDescription(); |
||||
} |
||||
|
||||
/** |
||||
* @param Session $session |
||||
* |
||||
* @return int |
||||
*/ |
||||
public function getNumberOfUsers(Session $session) |
||||
{ |
||||
return $session->getNbrUsers(); |
||||
} |
||||
|
||||
/** |
||||
* @param Session $session |
||||
* |
||||
* @return int |
||||
*/ |
||||
public function getNumberOfCourses(Session $session) |
||||
{ |
||||
return $session->getNbrCourses(); |
||||
} |
||||
|
||||
/** |
||||
* @param Session $session |
||||
* |
||||
* @return array |
||||
*/ |
||||
public function getCourses(Session $session): array |
||||
{ |
||||
$authChecker = $this->container->get('security.authorization_checker'); |
||||
$courses = []; |
||||
|
||||
/** @var SessionRelCourse $sessionCourse */ |
||||
foreach ($session->getCourses() as $sessionCourse) { |
||||
$course = $sessionCourse->getCourse(); |
||||
|
||||
$session->setCurrentCourse($course); |
||||
|
||||
if (false !== $authChecker->isGranted(SessionVoter::VIEW, $session)) { |
||||
$courses[] = $course; |
||||
} |
||||
} |
||||
|
||||
return $courses; |
||||
} |
||||
} |
@ -1,73 +0,0 @@ |
||||
<?php |
||||
/* For licensing terms, see /license.txt */ |
||||
|
||||
namespace Chamilo\ApiBundle\GraphQL\Resolver; |
||||
|
||||
use Chamilo\ApiBundle\GraphQL\ApiGraphQLTrait; |
||||
use Chamilo\CoreBundle\Entity\Course; |
||||
use Chamilo\CoreBundle\Entity\Session; |
||||
use Chamilo\CourseBundle\Entity\CTool; |
||||
use GraphQL\Error\UserError; |
||||
use Overblog\GraphQLBundle\Definition\Argument; |
||||
use Overblog\GraphQLBundle\Definition\Resolver\ResolverInterface; |
||||
use Symfony\Component\DependencyInjection\ContainerAwareInterface; |
||||
|
||||
/** |
||||
* Class ToolAnnouncementsResolver. |
||||
* |
||||
* @package Chamilo\ApiBundle\GraphQL\Resolver |
||||
*/ |
||||
class ToolAnnouncementsResolver implements ResolverInterface, ContainerAwareInterface |
||||
{ |
||||
use ApiGraphQLTrait; |
||||
use CourseToolResolverTrait; |
||||
|
||||
/** |
||||
* @param CTool $tool |
||||
* @param Argument $args |
||||
* @param \ArrayObject $context |
||||
* |
||||
* @return array |
||||
*/ |
||||
public function resolveAnnouncements(CTool $tool, Argument $args, \ArrayObject $context): array |
||||
{ |
||||
/** @var Course $course */ |
||||
$course = $context->offsetGet('course'); |
||||
/** @var Session $session */ |
||||
$session = null; |
||||
|
||||
if ($context->offsetExists('session')) { |
||||
$session = $context->offsetGet('session'); |
||||
} |
||||
|
||||
$em = $this->container->get('chamilo_course.entity.manager.announcement_manager'); |
||||
|
||||
try { |
||||
$announcementsInfo = $em->getAnnouncements( |
||||
$this->getCurrentUser(), |
||||
$course, |
||||
null, |
||||
$session, |
||||
api_get_course_setting('allow_user_edit_announcement') === 'true', |
||||
api_get_configuration_value('hide_base_course_announcements_in_group') === true |
||||
); |
||||
} catch (\Exception $exception) { |
||||
throw new UserError($exception->getMessage()); |
||||
} |
||||
|
||||
if (empty($announcementsInfo)) { |
||||
return []; |
||||
} |
||||
|
||||
$announcements = []; |
||||
|
||||
for ($z = 0; $z < count($announcementsInfo); $z += 2) { |
||||
$announcements[] = [ |
||||
'announcement' => $announcementsInfo[$z], |
||||
'item_property' => $announcementsInfo[$z + 1], |
||||
]; |
||||
} |
||||
|
||||
return $announcements; |
||||
} |
||||
} |
@ -1,60 +0,0 @@ |
||||
<?php |
||||
/* For licensing terms, see /license.txt */ |
||||
|
||||
namespace Chamilo\ApiBundle\GraphQL\Resolver; |
||||
|
||||
use Chamilo\ApiBundle\GraphQL\ApiGraphQLTrait; |
||||
use Chamilo\CoreBundle\Entity\Course; |
||||
use Chamilo\CourseBundle\Entity\CTool; |
||||
use Overblog\GraphQLBundle\Definition\Argument; |
||||
use Overblog\GraphQLBundle\Definition\Resolver\ResolverInterface; |
||||
use Symfony\Component\DependencyInjection\ContainerAwareInterface; |
||||
|
||||
/** |
||||
* Class ToolDescriptionResolver. |
||||
* |
||||
* @package Chamilo\ApiBundle\GraphQL\Resolver |
||||
*/ |
||||
class ToolDescriptionResolver implements ResolverInterface, ContainerAwareInterface |
||||
{ |
||||
use ApiGraphQLTrait; |
||||
use CourseToolResolverTrait; |
||||
|
||||
/** |
||||
* @param CTool $tool |
||||
* @param Argument $args |
||||
* @param \ArrayObject $context |
||||
* |
||||
* @return array |
||||
*/ |
||||
public function resolveDescriptions(CTool $tool, Argument $args, \ArrayObject $context): array |
||||
{ |
||||
/** @var Course $course */ |
||||
$course = $context->offsetGet('course'); |
||||
$cd = new \CourseDescription(); |
||||
$cd->set_course_id($course->getId()); |
||||
|
||||
if ($context->offsetExists('session')) { |
||||
/** @var Session $session */ |
||||
$session = $context->offsetGet('session'); |
||||
|
||||
$cd->set_session_id($session->getId()); |
||||
} |
||||
|
||||
$descriptions = $cd->get_description_data(); |
||||
|
||||
if (empty($descriptions)) { |
||||
return []; |
||||
} |
||||
|
||||
$qb = $this->em->createQueryBuilder(); |
||||
$qb |
||||
->select('d') |
||||
->from('ChamiloCourseBundle:CCourseDescription', 'd') |
||||
->where( |
||||
$qb->expr()->in('d.id', array_keys($descriptions['descriptions'])) |
||||
); |
||||
|
||||
return $qb->getQuery()->getResult(); |
||||
} |
||||
} |
@ -1,9 +0,0 @@ |
||||
CourseToolType: |
||||
type: enum |
||||
config: |
||||
description: 'One of the types of course tool' |
||||
values: |
||||
TOOL_DESCRIPTION: |
||||
value: '@=constant("TOOL_COURSE_DESCRIPTION")' |
||||
TOOL_ANNOUNCEMENT: |
||||
value: '@=constant("TOOL_ANNOUNCEMENT")' |
@ -1,45 +0,0 @@ |
||||
Mutation: |
||||
type: object |
||||
config: |
||||
fields: |
||||
authenticate: |
||||
description: "Authenticate user." |
||||
type: "AuthenticatePayload!" |
||||
args: |
||||
username: |
||||
type: "String!" |
||||
password: |
||||
type: "String!" |
||||
resolve: "@=mutation('authenticate', [args])" |
||||
viewerSendMessage: |
||||
description: 'Send messages to user contacts.' |
||||
type: '[ViewerSendMessagePayload]!' |
||||
args: |
||||
receivers: |
||||
description: 'Unique IDs of users who will receive the message.' |
||||
type: '[Int]!' |
||||
subject: |
||||
type: 'String!' |
||||
text: |
||||
type: 'String!' |
||||
resolve: "@=mutation('user_send_message', [args, context])" |
||||
|
||||
AuthenticatePayload: |
||||
type: object |
||||
config: |
||||
fields: |
||||
token: |
||||
description: "Authorization token." |
||||
type: "String!" |
||||
|
||||
ViewerSendMessagePayload: |
||||
type: object |
||||
config: |
||||
description: 'The status for each message in queue.' |
||||
fields: |
||||
receiverId: |
||||
description: 'The unique ID for the receiver user.' |
||||
type: 'Int!' |
||||
sent: |
||||
description: "It indicates if the message was or wasn't sent." |
||||
type: 'Boolean!' |
@ -1,89 +0,0 @@ |
||||
Course: |
||||
type: object |
||||
config: |
||||
description: 'A course registered on the platform.' |
||||
fields: |
||||
tools: |
||||
description: 'List of available tools for student view.' |
||||
type: '[CourseTool]' |
||||
args: |
||||
type: |
||||
description: 'Filter by one type of tool' |
||||
type: 'CourseToolType' |
||||
|
||||
CourseTool: |
||||
type: union |
||||
config: |
||||
description: 'Course tools' |
||||
resolveType: '@=resolver("Chamilo\\ApiBundle\\GraphQL\\Resolver\\CourseToolResolver", [value])' |
||||
types: [ToolDescription, ToolAnnouncements] |
||||
|
||||
ToolDescription: |
||||
type: object |
||||
config: |
||||
description: 'Global summary of the course.' |
||||
resolveField: '@=resolver("Chamilo\\ApiBundle\\GraphQL\\Resolver\\ToolDescriptionResolver", [value, args, info, context])' |
||||
fields: |
||||
name: |
||||
type: 'String' |
||||
category: |
||||
type: 'String' |
||||
image: |
||||
type: 'String' |
||||
customIcon: |
||||
type: 'String' |
||||
isVisible: |
||||
type: 'Boolean' |
||||
descriptions: |
||||
type: '[CourseDescription]!' |
||||
|
||||
CourseDescription: |
||||
type: object |
||||
config: |
||||
description: 'A section for the course description.' |
||||
resolveField: '@=resolver("Chamilo\\ApiBundle\\GraphQL\\Resolver\\CourseDescriptionResolver", [value, args, info, context])' |
||||
fields: |
||||
id: |
||||
type: 'Int' |
||||
title: |
||||
type: 'String' |
||||
content: |
||||
type: 'String' |
||||
type: |
||||
type: 'Int' |
||||
|
||||
ToolAnnouncements: |
||||
type: object |
||||
config: |
||||
description: 'Announcements related to the course.' |
||||
resolveField: '@=resolver("Chamilo\\ApiBundle\\GraphQL\\Resolver\\ToolAnnouncementsResolver", [value, args, info, context])' |
||||
fields: |
||||
name: |
||||
type: 'String' |
||||
category: |
||||
type: 'String' |
||||
image: |
||||
type: 'String' |
||||
customIcon: |
||||
type: 'String' |
||||
isVisible: |
||||
type: 'Boolean' |
||||
announcements: |
||||
type: '[CourseAnnouncement]!' |
||||
|
||||
CourseAnnouncement: |
||||
type: object |
||||
config: |
||||
description: 'Course announcement.' |
||||
resolveField: '@=resolver("Chamilo\\ApiBundle\\GraphQL\\Resolver\\CourseAnnouncementResolver", [value, args, info, context])' |
||||
fields: |
||||
id: |
||||
type: 'Int' |
||||
title: |
||||
type: 'String' |
||||
content: |
||||
type: 'String' |
||||
by: |
||||
type: 'User' |
||||
lastUpdateDate: |
||||
type: 'DateTime' |
@ -0,0 +1,39 @@ |
||||
<?php |
||||
/* For licensing terms, see /license.txt */ |
||||
|
||||
namespace Chamilo\CoreBundle\Migrations\Schema\V200; |
||||
|
||||
use Chamilo\CoreBundle\Migrations\AbstractMigrationChamilo; |
||||
use Doctrine\DBAL\Schema\Schema; |
||||
|
||||
/** |
||||
* Class Version20180927172830. |
||||
* |
||||
* Add foreing keys between forum category - forum - forum thread - forum post |
||||
* |
||||
* @package Chamilo\CoreBundle\Migrations\Schema\V200 |
||||
*/ |
||||
class Version20180927172830 extends AbstractMigrationChamilo |
||||
{ |
||||
/** |
||||
* @param Schema $schema |
||||
*/ |
||||
public function up(Schema $schema) |
||||
{ |
||||
$this->addSql('UPDATE c_forum_post SET thread_id = NULL WHERE thread_id NOT IN (SELECT iid FROM c_forum_thread)'); |
||||
$this->addSql('UPDATE c_forum_thread SET forum_id = NULL WHERE forum_id NOT IN (SELECT iid FROM c_forum_forum)'); |
||||
$this->addSql('UPDATE c_forum_forum SET forum_category = NULL WHERE forum_category NOT IN (SELECT iid FROM c_forum_category)'); |
||||
|
||||
$this->addSql('ALTER TABLE c_forum_post ADD CONSTRAINT FK_B5BEF559E2904019 FOREIGN KEY (thread_id) REFERENCES c_forum_thread (iid)'); |
||||
$this->addSql('ALTER TABLE c_forum_forum ADD CONSTRAINT FK_47A9C9921BF9426 FOREIGN KEY (forum_category) REFERENCES c_forum_category (iid)'); |
||||
$this->addSql('CREATE INDEX IDX_47A9C9921BF9426 ON c_forum_forum (forum_category)'); |
||||
$this->addSql('ALTER TABLE c_forum_thread ADD CONSTRAINT FK_5DA7884C29CCBAD0 FOREIGN KEY (forum_id) REFERENCES c_forum_forum (iid)'); |
||||
} |
||||
|
||||
/** |
||||
* @param Schema $schema |
||||
*/ |
||||
public function down(Schema $schema) |
||||
{ |
||||
} |
||||
} |
@ -0,0 +1,119 @@ |
||||
<?php |
||||
/* For licensing terms, see /license.txt */ |
||||
|
||||
namespace Chamilo\CourseBundle\Repository; |
||||
|
||||
use Chamilo\CoreBundle\Entity\Course; |
||||
use Chamilo\CoreBundle\Entity\Session; |
||||
use Chamilo\CourseBundle\Entity\CForumCategory; |
||||
use Chamilo\CourseBundle\Entity\CItemProperty; |
||||
use Doctrine\ORM\EntityRepository; |
||||
|
||||
/** |
||||
* Class CForumCategoryRepository. |
||||
* |
||||
* @package Chamilo\CourseBundle\Repository |
||||
*/ |
||||
class CForumCategoryRepository extends EntityRepository |
||||
{ |
||||
/** |
||||
* @param bool $isAllowedToEdit |
||||
* @param Course $course |
||||
* @param Session|null $session |
||||
* |
||||
* @return array |
||||
* |
||||
* @todo Remove api_get_session_condition |
||||
*/ |
||||
public function findAllInCourse($isAllowedToEdit, Course $course, Session $session = null): array |
||||
{ |
||||
$conditionSession = api_get_session_condition( |
||||
$session ? $session->getId() : 0, |
||||
true, |
||||
true, |
||||
'fcat.sessionId' |
||||
); |
||||
$conditionVisibility = $isAllowedToEdit ? 'ip.visibility != 2' : 'ip.visibility = 1'; |
||||
|
||||
$dql = "SELECT ip, fcat |
||||
FROM ChamiloCourseBundle:CItemProperty AS ip |
||||
INNER JOIN ChamiloCourseBundle:CForumCategory fcat |
||||
WITH (fcat.catId = ip.ref AND ip.course = fcat.cId) |
||||
WHERE |
||||
ip.tool = :tool AND |
||||
ip.course = :course |
||||
$conditionSession AND |
||||
$conditionVisibility |
||||
ORDER BY fcat.catOrder ASC"; |
||||
|
||||
$result = $this |
||||
->_em |
||||
->createQuery($dql) |
||||
->setParameters(['course' => $course, 'tool' => TOOL_FORUM_CATEGORY]) |
||||
->getResult(); |
||||
|
||||
$categories = []; |
||||
|
||||
for ($i = 0; $i < count($result); $i += 2) { |
||||
/** @var CItemProperty $ip */ |
||||
$ip = $result[$i]; |
||||
/** @var CForumCategory $fc */ |
||||
$fc = $result[$i + 1]; |
||||
|
||||
$fc->setItemProperty($ip); |
||||
|
||||
$categories[] = $fc; |
||||
} |
||||
|
||||
return $categories; |
||||
} |
||||
|
||||
/** |
||||
* @param int $id |
||||
* @param Course $course |
||||
* @param Session $session |
||||
* |
||||
* @return CForumCategory|null |
||||
* |
||||
* @todo Remove api_get_session_condition |
||||
*/ |
||||
public function findOneInCourse($id, Course $course, Session $session) |
||||
{ |
||||
$conditionSession = api_get_session_condition( |
||||
$session ? $session->getId() : 0, |
||||
true, |
||||
true, |
||||
'fcat.sessionId' |
||||
); |
||||
|
||||
$dql = "SELECT ip, fcat |
||||
FROM ChamiloCourseBundle:CItemProperty AS ip |
||||
INNER JOIN ChamiloCourseBundle:CForumCategory fcat |
||||
WITH (fcat.catId = ip.ref AND ip.course = fcat.cId) |
||||
WHERE |
||||
ip.tool = :tool AND |
||||
ip.course = :course |
||||
fcat.iid = :id |
||||
$conditionSession AND |
||||
ORDER BY fcat.catOrder ASC"; |
||||
|
||||
$result = $this |
||||
->_em |
||||
->createQuery($dql) |
||||
->setParameters(['tool' => TOOL_FORUM_CATEGORY, 'course' => $course, 'id' => (int) $id]) |
||||
->getResult(); |
||||
|
||||
if (empty($result)) { |
||||
return null; |
||||
} |
||||
|
||||
/** @var CItemProperty $ip */ |
||||
$ip = $result[0]; |
||||
/** @var CForumCategory $fc */ |
||||
$fc = $result[1]; |
||||
|
||||
$fc->setItemProperty($ip); |
||||
|
||||
return $fc; |
||||
} |
||||
} |
@ -0,0 +1,119 @@ |
||||
<?php |
||||
/* For licensing terms, see /license.txt */ |
||||
|
||||
namespace Chamilo\CourseBundle\Repository; |
||||
|
||||
use Chamilo\CoreBundle\Entity\Course; |
||||
use Chamilo\CoreBundle\Entity\Session; |
||||
use Chamilo\CourseBundle\Entity\CForumCategory; |
||||
use Chamilo\CourseBundle\Entity\CForumForum; |
||||
use Chamilo\CourseBundle\Entity\CItemProperty; |
||||
use Doctrine\ORM\EntityRepository; |
||||
|
||||
/** |
||||
* Class CForumForumRepository. |
||||
* |
||||
* @package Chamilo\CourseBundle\Repository |
||||
*/ |
||||
class CForumForumRepository extends EntityRepository |
||||
{ |
||||
/** |
||||
* @param bool $isAllowedToEdit |
||||
* @param CForumCategory $category |
||||
* @param Course $course |
||||
* @param Session|null $session |
||||
* @param bool $includeGroupsForums |
||||
* |
||||
* @return array |
||||
* |
||||
* @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 |
||||
* @param Course $course |
||||
* |
||||
* @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; |
||||
} |
||||
} |
@ -0,0 +1,80 @@ |
||||
<?php |
||||
/* For licensing terms, see /license.txt */ |
||||
|
||||
namespace Chamilo\CourseBundle\Repository; |
||||
|
||||
use Chamilo\CoreBundle\Entity\Course; |
||||
use Chamilo\CourseBundle\Entity\CForumPost; |
||||
use Chamilo\CourseBundle\Entity\CForumThread; |
||||
use Chamilo\CourseBundle\Entity\CGroupInfo; |
||||
use Chamilo\UserBundle\Entity\User; |
||||
use Doctrine\ORM\EntityRepository; |
||||
|
||||
/** |
||||
* Class CForumPostRepository. |
||||
* |
||||
* @package Chamilo\CourseBundle\Repository |
||||
*/ |
||||
class CForumPostRepository extends EntityRepository |
||||
{ |
||||
/** |
||||
* @param bool $onlyVisibles |
||||
* @param bool $isAllowedToEdit |
||||
* @param CForumThread $thread |
||||
* @param Course $course |
||||
* @param User|null $currentUser |
||||
* @param CGroupInfo|null $group |
||||
* @param string $orderDirection |
||||
* |
||||
* @return array |
||||
*/ |
||||
public function findAllInCourseByThread( |
||||
$onlyVisibles, |
||||
$isAllowedToEdit, |
||||
CForumThread $thread, |
||||
Course $course, |
||||
User $currentUser = null, |
||||
CGroupInfo $group = null, |
||||
$orderDirection = 'ASC' |
||||
): array { |
||||
$conditionVisibility = $onlyVisibles ? 'p.visible = 1' : 'p.visible != 2'; |
||||
$conditionModetared = ''; |
||||
$filterModerated = true; |
||||
|
||||
if ( |
||||
(empty($group) && $isAllowedToEdit) || |
||||
( |
||||
($group ? $group->userIsTutor($currentUser) : false) || |
||||
!$onlyVisibles |
||||
) |
||||
) { |
||||
$filterModerated = false; |
||||
} |
||||
|
||||
if ($filterModerated && $thread->getForum()->isModerated() && $onlyVisibles) { |
||||
$userId = $currentUser ? $currentUser->getId() : 0; |
||||
|
||||
$conditionModetared = "AND p.status = 1 OR |
||||
(p.status = ".CForumPost::STATUS_WAITING_MODERATION." AND p.posterId = $userId) OR |
||||
(p.status = ".CForumPost::STATUS_REJECTED." AND p.poster = $userId) OR |
||||
(p.status IS NULL AND p.posterId = $userId)"; |
||||
} |
||||
|
||||
$dql = "SELECT p |
||||
FROM ChamiloCourseBundle:CForumPost p |
||||
WHERE |
||||
p.thread = :thread AND |
||||
p.cId = :course AND |
||||
$conditionVisibility |
||||
$conditionModetared |
||||
ORDER BY p.iid $orderDirection"; |
||||
|
||||
$result = $this |
||||
->_em |
||||
->createQuery($dql) |
||||
->setParameters(['thread' => $thread, 'course' => $course]) |
||||
->getResult(); |
||||
|
||||
return $result; |
||||
} |
||||
} |
@ -0,0 +1,129 @@ |
||||
<?php |
||||
/* For licensing terms, see /license.txt */ |
||||
|
||||
namespace Chamilo\CourseBundle\Repository; |
||||
|
||||
use Chamilo\CoreBundle\Entity\Course; |
||||
use Chamilo\CoreBundle\Entity\Session; |
||||
use Chamilo\CourseBundle\Entity\CForumForum; |
||||
use Chamilo\CourseBundle\Entity\CForumThread; |
||||
use Chamilo\CourseBundle\Entity\CGroupInfo; |
||||
use Chamilo\CourseBundle\Entity\CItemProperty; |
||||
use Doctrine\ORM\EntityRepository; |
||||
|
||||
/** |
||||
* Class CForumThreadRepository. |
||||
* |
||||
* @package Chamilo\CourseBundle\Repository |
||||
*/ |
||||
class CForumThreadRepository extends EntityRepository |
||||
{ |
||||
/** |
||||
* @param bool $isAllowedToEdit |
||||
* @param CForumForum $forum |
||||
* @param Course $course |
||||
* @param CGroupInfo|null $group |
||||
* @param Session|null $session |
||||
* |
||||
* @return array |
||||
* |
||||
* @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 |
||||
* @param Course $course |
||||
* @param Session|null $session |
||||
* |
||||
* @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; |
||||
} |
||||
} |
Loading…
Reference in new issue