Update entities api parameters

pull/3262/head
Julio Montoya 5 years ago
parent cd7c4741a8
commit 43fbda4023
  1. 1
      src/CoreBundle/Controller/Admin/AdminController.php
  2. 4
      src/CoreBundle/Controller/Admin/PluginsController.php
  3. 4
      src/CoreBundle/Controller/Admin/SettingsController.php
  4. 10
      src/CoreBundle/Controller/IndexController.php
  5. 16
      src/CoreBundle/Controller/ResourceApiController.php
  6. 10
      src/CoreBundle/Entity/Course.php
  7. 20
      src/CoreBundle/Entity/CourseCategory.php
  8. 44
      src/CoreBundle/Entity/Session.php
  9. 10
      src/CoreBundle/Entity/SessionCategory.php
  10. 5
      src/CoreBundle/Entity/Skill.php
  11. 63
      src/CoreBundle/Entity/User.php

@ -5,7 +5,6 @@
namespace Chamilo\CoreBundle\Controller\Admin; namespace Chamilo\CoreBundle\Controller\Admin;
use Chamilo\CoreBundle\Controller\BaseController; use Chamilo\CoreBundle\Controller\BaseController;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template;
use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response; use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route; use Symfony\Component\Routing\Annotation\Route;

@ -4,14 +4,14 @@
namespace Chamilo\CoreBundle\Controller\Admin; namespace Chamilo\CoreBundle\Controller\Admin;
use Chamilo\CoreBundle\Controller\BaseController;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Security; use Sensio\Bundle\FrameworkExtraBundle\Configuration\Security;
use Sylius\Bundle\SettingsBundle\Controller\SettingsController as SyliusSettingsController;
use Symfony\Component\Routing\Annotation\Route; use Symfony\Component\Routing\Annotation\Route;
/** /**
* Class SettingsController. * Class SettingsController.
*/ */
class PluginsController extends SyliusSettingsController class PluginsController extends BaseController
{ {
/** /**
* @Security("has_role('ROLE_ADMIN')") * @Security("has_role('ROLE_ADMIN')")

@ -4,9 +4,9 @@
namespace Chamilo\CoreBundle\Controller\Admin; namespace Chamilo\CoreBundle\Controller\Admin;
use Chamilo\CoreBundle\Controller\BaseController;
use Chamilo\CoreBundle\Manager\SettingsManager; use Chamilo\CoreBundle\Manager\SettingsManager;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Security; use Sensio\Bundle\FrameworkExtraBundle\Configuration\Security;
use Sylius\Bundle\SettingsBundle\Controller\SettingsController as SyliusSettingsController;
use Sylius\Bundle\SettingsBundle\Form\Factory\SettingsFormFactory; use Sylius\Bundle\SettingsBundle\Form\Factory\SettingsFormFactory;
use Symfony\Component\Form\Extension\Core\Type\SubmitType; use Symfony\Component\Form\Extension\Core\Type\SubmitType;
use Symfony\Component\Form\Extension\Core\Type\TextType; use Symfony\Component\Form\Extension\Core\Type\TextType;
@ -19,7 +19,7 @@ use Symfony\Contracts\Translation\TranslatorInterface;
/** /**
* Class SettingsController. * Class SettingsController.
*/ */
class SettingsController extends SyliusSettingsController class SettingsController extends BaseController
{ {
public static function getSubscribedServices(): array public static function getSubscribedServices(): array
{ {

@ -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. * Toggle the student view action.
* *

@ -14,10 +14,11 @@ use Chamilo\CoreBundle\Traits\ResourceControllerTrait;
use Chamilo\CourseBundle\Controller\CourseControllerInterface; use Chamilo\CourseBundle\Controller\CourseControllerInterface;
use Doctrine\Common\Collections\Criteria; use Doctrine\Common\Collections\Criteria;
use Doctrine\ORM\QueryBuilder; use Doctrine\ORM\QueryBuilder;
use FOS\RestBundle\Controller\AbstractFOSRestController; /*use FOS\RestBundle\Controller\AbstractFOSRestController;
use FOS\RestBundle\Controller\Annotations as Rest; use FOS\RestBundle\Controller\Annotations as Rest;
use FOS\RestBundle\Request\ParamFetcher; 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\Request;
use Symfony\Component\HttpFoundation\Response; use Symfony\Component\HttpFoundation\Response;
@ -27,14 +28,14 @@ use Symfony\Component\HttpFoundation\Response;
* *
* debug api routes with: bin/console debug:router | grep api * 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 CourseControllerTrait;
use ResourceControllerTrait; use ResourceControllerTrait;
use ControllerTrait; use ControllerTrait;
/** /**
* @Rest\View(serializerGroups={"list"}) *
*/ */
public function getResourcesListAction($id, Request $request) 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) 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); $repository = $this->getRepositoryFromRequest($request);
@ -89,7 +88,6 @@ class ResourceApiController extends AbstractFOSRestController implements CourseC
} }
/** /**
* @Rest\View(serializerGroups={"list"})
*/ */
public function postResourceCommentAction($id, Request $request) public function postResourceCommentAction($id, Request $request)
{ {

@ -5,6 +5,7 @@
namespace Chamilo\CoreBundle\Entity; namespace Chamilo\CoreBundle\Entity;
use ApiPlatform\Core\Annotation\ApiFilter; use ApiPlatform\Core\Annotation\ApiFilter;
use ApiPlatform\Core\Annotation\ApiProperty;
use ApiPlatform\Core\Annotation\ApiResource; use ApiPlatform\Core\Annotation\ApiResource;
use ApiPlatform\Core\Annotation\ApiSubresource; use ApiPlatform\Core\Annotation\ApiSubresource;
use ApiPlatform\Core\Bridge\Doctrine\Orm\Filter\OrderFilter; use ApiPlatform\Core\Bridge\Doctrine\Orm\Filter\OrderFilter;
@ -26,12 +27,12 @@ use Symfony\Component\Validator\Constraints as Assert;
* Class Course. * Class Course.
* *
* @ApiResource( * @ApiResource(
* attributes={"security"="is_granted('ROLE_ADMIN')"}, * iri="https://schema.org/Course",
* normalizationContext={"groups"={"course:read"}, "swagger_definition_name"="Read"}, * normalizationContext={"groups"={"course:read"}, "swagger_definition_name"="Read"},
* denormalizationContext={"groups"={"course:write"}}, * 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(PropertyFilter::class)
* @ApiFilter(OrderFilter::class, properties={"id", "title"}) * @ApiFilter(OrderFilter::class, properties={"id", "title"})
* *
@ -79,7 +80,7 @@ class Course extends AbstractResource implements ResourceInterface
/** /**
* @var string * @var string
* @Assert\NotBlank() * @Assert\NotBlank()
* * @ApiProperty(iri="http://schema.org/courseCode")
* @Groups({"course:read", "course:write"}) * @Groups({"course:read", "course:write"})
* *
* @Gedmo\Slug( * @Gedmo\Slug(
@ -227,7 +228,8 @@ class Course extends AbstractResource implements ResourceInterface
/** /**
* @var CourseCategory * @var CourseCategory
* @Groups({"course:read", "list"}) * @ApiSubresource()
* @Groups({"course:read", "course:write"})
* @ORM\ManyToOne(targetEntity="Chamilo\CoreBundle\Entity\CourseCategory", inversedBy="courses") * @ORM\ManyToOne(targetEntity="Chamilo\CoreBundle\Entity\CourseCategory", inversedBy="courses")
* @ORM\JoinColumn(name="category_id", referencedColumnName="id") * @ORM\JoinColumn(name="category_id", referencedColumnName="id")
*/ */

@ -4,12 +4,18 @@
namespace Chamilo\CoreBundle\Entity; namespace Chamilo\CoreBundle\Entity;
use ApiPlatform\Core\Annotation\ApiResource;
use Doctrine\Common\Collections\ArrayCollection; use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\ORM\Mapping as ORM; use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\Serializer\Annotation\Groups;
use Symfony\Component\Validator\Constraints as Assert;
/** /**
* CourseCategory. * CourseCategory.
* * @ApiResource(
* normalizationContext={"groups"={"course_category:read"}, "swagger_definition_name"="Read"},
* denormalizationContext={"groups"={"course_category:write"}},
* )
* @ORM\Table( * @ORM\Table(
* name="course_category", * name="course_category",
* uniqueConstraints={ * uniqueConstraints={
@ -26,7 +32,7 @@ class CourseCategory
{ {
/** /**
* @var int * @var int
* * @Groups({"course_category:read", "course:read"})
* @ORM\Column(name="id", type="integer") * @ORM\Column(name="id", type="integer")
* @ORM\Id * @ORM\Id
* @ORM\GeneratedValue() * @ORM\GeneratedValue()
@ -40,14 +46,16 @@ class CourseCategory
/** /**
* @var string * @var string
* * @Assert\NotBlank()
* @Groups({"course_category:read", "course_category:write", "course:read"})
* @ORM\Column(name="name", type="text", nullable=false) * @ORM\Column(name="name", type="text", nullable=false)
*/ */
protected $name; protected $name;
/** /**
* @var string * @var string
* * @Assert\NotBlank()
* @Groups({"course_category:read", "course_category:write", "course:read"})
* @ORM\Column(name="code", type="string", length=40, nullable=false) * @ORM\Column(name="code", type="string", length=40, nullable=false)
*/ */
protected $code; protected $code;
@ -95,7 +103,7 @@ class CourseCategory
/** /**
* @var string * @var string
* * @Groups({"course_category:read", "course_category:write"})
* @ORM\Column(name="description", type="text", nullable=true) * @ORM\Column(name="description", type="text", nullable=true)
*/ */
protected $description; protected $description;
@ -349,7 +357,7 @@ class CourseCategory
return $this; return $this;
} }
public function getDescription(): string public function getDescription()
{ {
return $this->description; return $this->description;
} }

@ -15,13 +15,10 @@ use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\Serializer\Annotation\Groups; use Symfony\Component\Serializer\Annotation\Groups;
use Symfony\Component\Validator\Constraints as Assert; use Symfony\Component\Validator\Constraints as Assert;
//use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
//use Gedmo\Mapping\Annotation as Gedmo;
/** /**
* @ApiResource( * @ApiResource(
* attributes={"security"="is_granted('ROLE_ADMIN')"}, * normalizationContext={"groups"={"session:read"}, "swagger_definition_name"="Read"},
* normalizationContext={"groups"={"session:read"}} * denormalizationContext={"groups"={"session:write"}},
* ) * )
* *
* @ApiFilter(SearchFilter::class, properties={"name": "partial"}) * @ApiFilter(SearchFilter::class, properties={"name": "partial"})
@ -172,11 +169,12 @@ class Session
protected $nbrClasses; 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 * @var int
@ -253,14 +251,14 @@ class Session
* @var User * @var User
* @Groups({"session:read", "session:write"}) * @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") * @ORM\JoinColumn(name="id_coach", referencedColumnName="id")
*/ */
protected $generalCoach; protected $generalCoach;
/** /**
* @Groups({"session:read"}) * @Groups({"session:read", "session:write"})
* @ORM\ManyToOne(targetEntity="Chamilo\CoreBundle\Entity\SessionCategory", inversedBy="session") * @ORM\ManyToOne(targetEntity="SessionCategory", inversedBy="session")
* @ORM\JoinColumn(name="session_category_id", referencedColumnName="id") * @ORM\JoinColumn(name="session_category_id", referencedColumnName="id")
*/ */
protected $category; protected $category;
@ -699,30 +697,6 @@ class Session
return $this->nbrClasses; 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. * Set visibility.
* *

@ -4,10 +4,16 @@
namespace Chamilo\CoreBundle\Entity; namespace Chamilo\CoreBundle\Entity;
use ApiPlatform\Core\Annotation\ApiResource;
use Doctrine\ORM\Mapping as ORM; use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\Serializer\Annotation\Groups;
/** /**
* SessionCategory. * SessionCategory.
* @ApiResource(
* normalizationContext={"groups"={"session_category:read"}, "swagger_definition_name"="Read"},
* denormalizationContext={"groups"={"session_category:write"}},
* )
* *
* @ORM\Table(name="session_category") * @ORM\Table(name="session_category")
* @ORM\Entity * @ORM\Entity
@ -16,7 +22,7 @@ class SessionCategory
{ {
/** /**
* @var int * @var int
* * @Groups({"session_category:read"})
* @ORM\Column(name="id", type="integer", nullable=false, unique=false) * @ORM\Column(name="id", type="integer", nullable=false, unique=false)
* @ORM\Id * @ORM\Id
* @ORM\GeneratedValue * @ORM\GeneratedValue
@ -36,7 +42,7 @@ class SessionCategory
/** /**
* @var string * @var string
* * @Groups({"session_category:read", "session_category:write"})
* @ORM\Column(name="name", type="string", length=100, nullable=true, unique=false) * @ORM\Column(name="name", type="string", length=100, nullable=true, unique=false)
*/ */
protected $name; protected $name;

@ -58,7 +58,7 @@ class Skill
/** /**
* @var string * @var string
* @Groups({"skill:read"}) * @Groups({"skill:read", "skill:write"})
* @Assert\NotBlank() * @Assert\NotBlank()
* *
* @ORM\Column(name="name", type="string", length=255, nullable=false) * @ORM\Column(name="name", type="string", length=255, nullable=false)
@ -67,6 +67,8 @@ class Skill
/** /**
* @var string * @var string
* @Assert\NotBlank()
* @Groups({"skill:read", "skill:write"})
* *
* @ORM\Column(name="short_code", type="string", length=100, nullable=false) * @ORM\Column(name="short_code", type="string", length=100, nullable=false)
*/ */
@ -74,6 +76,7 @@ class Skill
/** /**
* @var string * @var string
* @Groups({"skill:read", "skill:write"})
* *
* @ORM\Column(name="description", type="text", nullable=false) * @ORM\Column(name="description", type="text", nullable=false)
*/ */

@ -5,6 +5,7 @@
namespace Chamilo\CoreBundle\Entity; namespace Chamilo\CoreBundle\Entity;
use ApiPlatform\Core\Annotation\ApiFilter; use ApiPlatform\Core\Annotation\ApiFilter;
use ApiPlatform\Core\Annotation\ApiProperty;
use ApiPlatform\Core\Annotation\ApiResource; use ApiPlatform\Core\Annotation\ApiResource;
use ApiPlatform\Core\Annotation\ApiSubresource; use ApiPlatform\Core\Annotation\ApiSubresource;
use ApiPlatform\Core\Bridge\Doctrine\Orm\Filter\BooleanFilter; use ApiPlatform\Core\Bridge\Doctrine\Orm\Filter\BooleanFilter;
@ -24,6 +25,7 @@ use Symfony\Component\Validator\Mapping\ClassMetadata;
/** /**
* @ApiResource( * @ApiResource(
* iri="http://schema.org/Person",
* attributes={"security"="is_granted('ROLE_ADMIN')"}, * attributes={"security"="is_granted('ROLE_ADMIN')"},
* normalizationContext={"groups"={"user:read"}}, * normalizationContext={"groups"={"user:read"}},
* denormalizationContext={"groups"={"user:write"}}, * denormalizationContext={"groups"={"user:write"}},
@ -74,6 +76,7 @@ class User implements UserInterface, EquatableInterface
/** /**
* @var string * @var string
* @ApiProperty(iri="http://schema.org/name")
* @Groups({"user:read", "user:write"}) * @Groups({"user:read", "user:write"})
* @ORM\Column(name="firstname", type="string", length=64, nullable=true, unique=false) * @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 $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 public function getCourseGroupsAsTutorFromCourse(Course $course): ArrayCollection
{ {
$criteria = Criteria::create(); $criteria = Criteria::create();

Loading…
Cancel
Save