From 43fbda4023a3b43e5193bd25fc71a6a5cc573b88 Mon Sep 17 00:00:00 2001 From: Julio Montoya Date: Mon, 11 May 2020 16:38:18 +0200 Subject: [PATCH] Update entities api parameters --- .../Controller/Admin/AdminController.php | 1 - .../Controller/Admin/PluginsController.php | 4 +- .../Controller/Admin/SettingsController.php | 4 +- src/CoreBundle/Controller/IndexController.php | 10 +++ .../Controller/ResourceApiController.php | 16 +++-- src/CoreBundle/Entity/Course.php | 10 +-- src/CoreBundle/Entity/CourseCategory.php | 20 ++++-- src/CoreBundle/Entity/Session.php | 44 +++---------- src/CoreBundle/Entity/SessionCategory.php | 10 ++- src/CoreBundle/Entity/Skill.php | 5 +- src/CoreBundle/Entity/User.php | 63 +++++++++++++++++++ 11 files changed, 125 insertions(+), 62 deletions(-) diff --git a/src/CoreBundle/Controller/Admin/AdminController.php b/src/CoreBundle/Controller/Admin/AdminController.php index 74c43041b5..5c537276e1 100644 --- a/src/CoreBundle/Controller/Admin/AdminController.php +++ b/src/CoreBundle/Controller/Admin/AdminController.php @@ -5,7 +5,6 @@ namespace Chamilo\CoreBundle\Controller\Admin; use Chamilo\CoreBundle\Controller\BaseController; -use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Response; use Symfony\Component\Routing\Annotation\Route; diff --git a/src/CoreBundle/Controller/Admin/PluginsController.php b/src/CoreBundle/Controller/Admin/PluginsController.php index e70f610363..941570dc77 100644 --- a/src/CoreBundle/Controller/Admin/PluginsController.php +++ b/src/CoreBundle/Controller/Admin/PluginsController.php @@ -4,14 +4,14 @@ namespace Chamilo\CoreBundle\Controller\Admin; +use Chamilo\CoreBundle\Controller\BaseController; use Sensio\Bundle\FrameworkExtraBundle\Configuration\Security; -use Sylius\Bundle\SettingsBundle\Controller\SettingsController as SyliusSettingsController; use Symfony\Component\Routing\Annotation\Route; /** * Class SettingsController. */ -class PluginsController extends SyliusSettingsController +class PluginsController extends BaseController { /** * @Security("has_role('ROLE_ADMIN')") diff --git a/src/CoreBundle/Controller/Admin/SettingsController.php b/src/CoreBundle/Controller/Admin/SettingsController.php index fe0e2eac06..985eeb2bf0 100644 --- a/src/CoreBundle/Controller/Admin/SettingsController.php +++ b/src/CoreBundle/Controller/Admin/SettingsController.php @@ -4,9 +4,9 @@ namespace Chamilo\CoreBundle\Controller\Admin; +use Chamilo\CoreBundle\Controller\BaseController; use Chamilo\CoreBundle\Manager\SettingsManager; use Sensio\Bundle\FrameworkExtraBundle\Configuration\Security; -use Sylius\Bundle\SettingsBundle\Controller\SettingsController as SyliusSettingsController; use Sylius\Bundle\SettingsBundle\Form\Factory\SettingsFormFactory; use Symfony\Component\Form\Extension\Core\Type\SubmitType; use Symfony\Component\Form\Extension\Core\Type\TextType; @@ -19,7 +19,7 @@ use Symfony\Contracts\Translation\TranslatorInterface; /** * Class SettingsController. */ -class SettingsController extends SyliusSettingsController +class SettingsController extends BaseController { public static function getSubscribedServices(): array { diff --git a/src/CoreBundle/Controller/IndexController.php b/src/CoreBundle/Controller/IndexController.php index aafa485ce0..81e89a2b2e 100644 --- a/src/CoreBundle/Controller/IndexController.php +++ b/src/CoreBundle/Controller/IndexController.php @@ -30,6 +30,16 @@ class IndexController extends BaseController ); } + public function courses(): Response + { + return $this->render( + '@ChamiloCore/Index/courses.html.twig', + [ + 'content' => '', + ] + ); + } + /** * Toggle the student view action. * diff --git a/src/CoreBundle/Controller/ResourceApiController.php b/src/CoreBundle/Controller/ResourceApiController.php index 50949a35f2..0a99af0b3d 100644 --- a/src/CoreBundle/Controller/ResourceApiController.php +++ b/src/CoreBundle/Controller/ResourceApiController.php @@ -14,10 +14,11 @@ use Chamilo\CoreBundle\Traits\ResourceControllerTrait; use Chamilo\CourseBundle\Controller\CourseControllerInterface; use Doctrine\Common\Collections\Criteria; use Doctrine\ORM\QueryBuilder; -use FOS\RestBundle\Controller\AbstractFOSRestController; +/*use FOS\RestBundle\Controller\AbstractFOSRestController; use FOS\RestBundle\Controller\Annotations as Rest; use FOS\RestBundle\Request\ParamFetcher; -use FOS\RestBundle\View\View; +use FOS\RestBundle\View\View;*/ +use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Response; @@ -27,14 +28,14 @@ use Symfony\Component\HttpFoundation\Response; * * debug api routes with: bin/console debug:router | grep api */ -class ResourceApiController extends AbstractFOSRestController implements CourseControllerInterface +class ResourceApiController extends AbstractController implements CourseControllerInterface { use CourseControllerTrait; use ResourceControllerTrait; use ControllerTrait; /** - * @Rest\View(serializerGroups={"list"}) + * */ public function getResourcesListAction($id, Request $request) { @@ -57,7 +58,7 @@ class ResourceApiController extends AbstractFOSRestController implements CourseC } /** - * @Rest\View(serializerGroups={"list"}) + * */ public function getResourceAction($id, Request $request) { @@ -71,10 +72,8 @@ class ResourceApiController extends AbstractFOSRestController implements CourseC } /** - * @Rest\QueryParam(name="orderBy", default="createdAt", nullable=true, description="Ordering") - * @Rest\View(serializerGroups={"list"}) */ - public function getResourceCommentsAction($id, Request $request, ParamFetcher $paramFetcher) + public function getResourceCommentsAction($id, Request $request, $paramFetcher) { $repository = $this->getRepositoryFromRequest($request); @@ -89,7 +88,6 @@ class ResourceApiController extends AbstractFOSRestController implements CourseC } /** - * @Rest\View(serializerGroups={"list"}) */ public function postResourceCommentAction($id, Request $request) { diff --git a/src/CoreBundle/Entity/Course.php b/src/CoreBundle/Entity/Course.php index d36ad25688..cc96f95176 100644 --- a/src/CoreBundle/Entity/Course.php +++ b/src/CoreBundle/Entity/Course.php @@ -5,6 +5,7 @@ namespace Chamilo\CoreBundle\Entity; use ApiPlatform\Core\Annotation\ApiFilter; +use ApiPlatform\Core\Annotation\ApiProperty; use ApiPlatform\Core\Annotation\ApiResource; use ApiPlatform\Core\Annotation\ApiSubresource; use ApiPlatform\Core\Bridge\Doctrine\Orm\Filter\OrderFilter; @@ -26,12 +27,12 @@ use Symfony\Component\Validator\Constraints as Assert; * Class Course. * * @ApiResource( - * attributes={"security"="is_granted('ROLE_ADMIN')"}, + * iri="https://schema.org/Course", * normalizationContext={"groups"={"course:read"}, "swagger_definition_name"="Read"}, * denormalizationContext={"groups"={"course:write"}}, * ) * - * @ApiFilter(SearchFilter::class, properties={"title": "partial", "code": "partial"}) + * @ApiFilter(SearchFilter::class, properties={"title": "partial", "code": "partial", "category": "partial"}) * @ApiFilter(PropertyFilter::class) * @ApiFilter(OrderFilter::class, properties={"id", "title"}) * @@ -79,7 +80,7 @@ class Course extends AbstractResource implements ResourceInterface /** * @var string * @Assert\NotBlank() - * + * @ApiProperty(iri="http://schema.org/courseCode") * @Groups({"course:read", "course:write"}) * * @Gedmo\Slug( @@ -227,7 +228,8 @@ class Course extends AbstractResource implements ResourceInterface /** * @var CourseCategory - * @Groups({"course:read", "list"}) + * @ApiSubresource() + * @Groups({"course:read", "course:write"}) * @ORM\ManyToOne(targetEntity="Chamilo\CoreBundle\Entity\CourseCategory", inversedBy="courses") * @ORM\JoinColumn(name="category_id", referencedColumnName="id") */ diff --git a/src/CoreBundle/Entity/CourseCategory.php b/src/CoreBundle/Entity/CourseCategory.php index 6742b93a79..e017f5497b 100644 --- a/src/CoreBundle/Entity/CourseCategory.php +++ b/src/CoreBundle/Entity/CourseCategory.php @@ -4,12 +4,18 @@ namespace Chamilo\CoreBundle\Entity; +use ApiPlatform\Core\Annotation\ApiResource; use Doctrine\Common\Collections\ArrayCollection; use Doctrine\ORM\Mapping as ORM; +use Symfony\Component\Serializer\Annotation\Groups; +use Symfony\Component\Validator\Constraints as Assert; /** * CourseCategory. - * + * @ApiResource( + * normalizationContext={"groups"={"course_category:read"}, "swagger_definition_name"="Read"}, + * denormalizationContext={"groups"={"course_category:write"}}, + * ) * @ORM\Table( * name="course_category", * uniqueConstraints={ @@ -26,7 +32,7 @@ class CourseCategory { /** * @var int - * + * @Groups({"course_category:read", "course:read"}) * @ORM\Column(name="id", type="integer") * @ORM\Id * @ORM\GeneratedValue() @@ -40,14 +46,16 @@ class CourseCategory /** * @var string - * + * @Assert\NotBlank() + * @Groups({"course_category:read", "course_category:write", "course:read"}) * @ORM\Column(name="name", type="text", nullable=false) */ protected $name; /** * @var string - * + * @Assert\NotBlank() + * @Groups({"course_category:read", "course_category:write", "course:read"}) * @ORM\Column(name="code", type="string", length=40, nullable=false) */ protected $code; @@ -95,7 +103,7 @@ class CourseCategory /** * @var string - * + * @Groups({"course_category:read", "course_category:write"}) * @ORM\Column(name="description", type="text", nullable=true) */ protected $description; @@ -349,7 +357,7 @@ class CourseCategory return $this; } - public function getDescription(): string + public function getDescription() { return $this->description; } diff --git a/src/CoreBundle/Entity/Session.php b/src/CoreBundle/Entity/Session.php index 28598dffea..4010b7ae54 100644 --- a/src/CoreBundle/Entity/Session.php +++ b/src/CoreBundle/Entity/Session.php @@ -15,13 +15,10 @@ use Doctrine\ORM\Mapping as ORM; use Symfony\Component\Serializer\Annotation\Groups; use Symfony\Component\Validator\Constraints as Assert; -//use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity; -//use Gedmo\Mapping\Annotation as Gedmo; - /** * @ApiResource( - * attributes={"security"="is_granted('ROLE_ADMIN')"}, - * normalizationContext={"groups"={"session:read"}} + * normalizationContext={"groups"={"session:read"}, "swagger_definition_name"="Read"}, + * denormalizationContext={"groups"={"session:write"}}, * ) * * @ApiFilter(SearchFilter::class, properties={"name": "partial"}) @@ -172,11 +169,12 @@ class Session protected $nbrClasses; /** - * @var int + * @var User * - * @ORM\Column(name="session_admin_id", type="integer", nullable=true, unique=false) + * @ORM\ManyToOne(targetEntity="Chamilo\CoreBundle\Entity\User", inversedBy="receivedMessages") + * @ORM\JoinColumn(name="session_admin_id", referencedColumnName="id", nullable=true) */ - protected $sessionAdminId; + protected $sessionAdmin; /** * @var int @@ -253,14 +251,14 @@ class Session * @var User * @Groups({"session:read", "session:write"}) * - * @ORM\ManyToOne(targetEntity="Chamilo\CoreBundle\Entity\User", inversedBy="sessionAsGeneralCoach") + * @ORM\ManyToOne(targetEntity="User", inversedBy="sessionAsGeneralCoach") * @ORM\JoinColumn(name="id_coach", referencedColumnName="id") */ protected $generalCoach; /** - * @Groups({"session:read"}) - * @ORM\ManyToOne(targetEntity="Chamilo\CoreBundle\Entity\SessionCategory", inversedBy="session") + * @Groups({"session:read", "session:write"}) + * @ORM\ManyToOne(targetEntity="SessionCategory", inversedBy="session") * @ORM\JoinColumn(name="session_category_id", referencedColumnName="id") */ protected $category; @@ -699,30 +697,6 @@ class Session return $this->nbrClasses; } - /** - * Set sessionAdminId. - * - * @param int $sessionAdminId - * - * @return Session - */ - public function setSessionAdminId($sessionAdminId) - { - $this->sessionAdminId = $sessionAdminId; - - return $this; - } - - /** - * Get sessionAdminId. - * - * @return int - */ - public function getSessionAdminId() - { - return $this->sessionAdminId; - } - /** * Set visibility. * diff --git a/src/CoreBundle/Entity/SessionCategory.php b/src/CoreBundle/Entity/SessionCategory.php index d5c36717f8..8d6d307eec 100644 --- a/src/CoreBundle/Entity/SessionCategory.php +++ b/src/CoreBundle/Entity/SessionCategory.php @@ -4,10 +4,16 @@ namespace Chamilo\CoreBundle\Entity; +use ApiPlatform\Core\Annotation\ApiResource; use Doctrine\ORM\Mapping as ORM; +use Symfony\Component\Serializer\Annotation\Groups; /** * SessionCategory. + * @ApiResource( + * normalizationContext={"groups"={"session_category:read"}, "swagger_definition_name"="Read"}, + * denormalizationContext={"groups"={"session_category:write"}}, + * ) * * @ORM\Table(name="session_category") * @ORM\Entity @@ -16,7 +22,7 @@ class SessionCategory { /** * @var int - * + * @Groups({"session_category:read"}) * @ORM\Column(name="id", type="integer", nullable=false, unique=false) * @ORM\Id * @ORM\GeneratedValue @@ -36,7 +42,7 @@ class SessionCategory /** * @var string - * + * @Groups({"session_category:read", "session_category:write"}) * @ORM\Column(name="name", type="string", length=100, nullable=true, unique=false) */ protected $name; diff --git a/src/CoreBundle/Entity/Skill.php b/src/CoreBundle/Entity/Skill.php index fe3bc0c164..a441cfbb86 100644 --- a/src/CoreBundle/Entity/Skill.php +++ b/src/CoreBundle/Entity/Skill.php @@ -58,7 +58,7 @@ class Skill /** * @var string - * @Groups({"skill:read"}) + * @Groups({"skill:read", "skill:write"}) * @Assert\NotBlank() * * @ORM\Column(name="name", type="string", length=255, nullable=false) @@ -67,6 +67,8 @@ class Skill /** * @var string + * @Assert\NotBlank() + * @Groups({"skill:read", "skill:write"}) * * @ORM\Column(name="short_code", type="string", length=100, nullable=false) */ @@ -74,6 +76,7 @@ class Skill /** * @var string + * @Groups({"skill:read", "skill:write"}) * * @ORM\Column(name="description", type="text", nullable=false) */ diff --git a/src/CoreBundle/Entity/User.php b/src/CoreBundle/Entity/User.php index 02820b63b8..681afb1033 100644 --- a/src/CoreBundle/Entity/User.php +++ b/src/CoreBundle/Entity/User.php @@ -5,6 +5,7 @@ namespace Chamilo\CoreBundle\Entity; use ApiPlatform\Core\Annotation\ApiFilter; +use ApiPlatform\Core\Annotation\ApiProperty; use ApiPlatform\Core\Annotation\ApiResource; use ApiPlatform\Core\Annotation\ApiSubresource; use ApiPlatform\Core\Bridge\Doctrine\Orm\Filter\BooleanFilter; @@ -24,6 +25,7 @@ use Symfony\Component\Validator\Mapping\ClassMetadata; /** * @ApiResource( + * iri="http://schema.org/Person", * attributes={"security"="is_granted('ROLE_ADMIN')"}, * normalizationContext={"groups"={"user:read"}}, * denormalizationContext={"groups"={"user:write"}}, @@ -74,6 +76,7 @@ class User implements UserInterface, EquatableInterface /** * @var string + * @ApiProperty(iri="http://schema.org/name") * @Groups({"user:read", "user:write"}) * @ORM\Column(name="firstname", type="string", length=64, nullable=true, unique=false) */ @@ -2077,6 +2080,66 @@ class User implements UserInterface, EquatableInterface return $this->locale; } + /** + * @return string + */ + public function getApiToken() + { + return $this->apiToken; + } + + /** + * @param string $apiToken + * + * @return User + */ + public function setApiToken($apiToken) + { + $this->apiToken = $apiToken; + + return $this; + } + + /** + * @return string + */ + public function getWebsite(): string + { + return $this->website; + } + + /** + * @param string $website + * + * @return User + */ + public function setWebsite(string $website): User + { + $this->website = $website; + + return $this; + } + + /** + * @return string + */ + public function getBiography(): string + { + return $this->biography; + } + + /** + * @param string $biography + * + * @return User + */ + public function setBiography(string $biography): User + { + $this->biography = $biography; + + return $this; + } + public function getCourseGroupsAsTutorFromCourse(Course $course): ArrayCollection { $criteria = Criteria::create();