Add api platform support, edit entities

pull/3262/head
Julio Montoya 6 years ago
parent 543b5e973a
commit 50f5c546ec
  1. 3
      composer.json
  2. 14
      config/packages/api_platform.yaml
  3. 20
      config/packages/fos_rest.yaml
  4. 4
      config/packages/security.yaml
  5. 55
      src/CoreBundle/Entity/Course.php
  6. 3
      src/CoreBundle/Entity/CourseRelUser.php
  7. 8
      src/CoreBundle/Entity/Illustration.php
  8. 9
      src/CoreBundle/Entity/Resource/AbstractResource.php
  9. 24
      src/CoreBundle/Entity/Resource/ResourceComment.php
  10. 68
      src/CoreBundle/Entity/Resource/ResourceFile.php
  11. 9
      src/CoreBundle/Entity/Resource/ResourceLink.php
  12. 62
      src/CoreBundle/Entity/Resource/ResourceNode.php
  13. 37
      src/CoreBundle/Entity/Resource/ResourceTag.php
  14. 36
      src/CoreBundle/Entity/Resource/ResourceUserTag.php
  15. 24
      src/CoreBundle/Entity/Session.php
  16. 13
      src/CoreBundle/Entity/Skill.php
  17. 23
      src/CoreBundle/Entity/Tool.php
  18. 23
      src/CoreBundle/Repository/CourseRepository.php
  19. 4
      src/CoreBundle/Repository/ResourceRepository.php
  20. 27
      src/CoreBundle/Traits/TimestampableAgoTrait.php
  21. 16
      src/CourseBundle/Entity/CDocument.php
  22. 1
      src/UserBundle/Controller/SecurityController.php
  23. 58
      src/UserBundle/Entity/User.php

@ -161,7 +161,8 @@
"twig/extensions": "^1.5",
"vich/uploader-bundle": "^1.13",
"webit/eval-math": "~1.0",
"api-platform/api-pack": "^1.2"
"api-platform/api-pack": "^1.2",
"nesbot/carbon": "^2.33"
},
"config": {
"component-dir": "public/assets"

@ -1,7 +1,21 @@
api_platform:
title: Chamilo
mapping:
paths: ['%kernel.project_dir%/src/CoreBundle/Entity', '%kernel.project_dir%/src/CourseBundle/Entity']
patch_formats:
json: ['application/merge-patch+json']
swagger:
versions: [3]
formats:
jsonld:
mime_types:
- application/ld+json
json:
mime_types:
- application/json
html:
mime_types:
- text/html
csv:
mime_types:
- text/csv

@ -1,13 +1,13 @@
fos_rest:
routing_loader:
include_format: false
param_fetcher_listener: true
format_listener:
rules:
- {path: '^/api', priorities:['json'], fallback_format: json, prefer_extension: false}
- {path: '^/', priorities: ['html', '*/*'], fallback_format: ~, prefer_extension: true}
view:
view_response_listener: true
#fos_rest:
# routing_loader:
# include_format: false
# param_fetcher_listener: true
# format_listener:
# rules:
# - {path: '^/api2', priorities:['json'], fallback_format: json, prefer_extension: false}
# - {path: '^/', priorities: ['html', '*/*'], fallback_format: ~, prefer_extension: true}
# view:
# view_response_listener: true
# formats:
# json: true

@ -76,3 +76,7 @@ security:
path: /logout
target: /
switch_user: false
# json_login:
# check_path: app_login
# username_path: username
# password_path: password

@ -4,6 +4,10 @@
namespace Chamilo\CoreBundle\Entity;
use ApiPlatform\Core\Annotation\ApiFilter;
use ApiPlatform\Core\Annotation\ApiResource;
use ApiPlatform\Core\Bridge\Doctrine\Orm\Filter\SearchFilter;
use ApiPlatform\Core\Serializer\Filter\PropertyFilter;
use Chamilo\CoreBundle\Entity\Resource\AbstractResource;
use Chamilo\CoreBundle\Entity\Resource\ResourceInterface;
use Chamilo\CourseBundle\Entity\CGroupInfo;
@ -14,11 +18,21 @@ use Doctrine\Common\Collections\Criteria;
use Doctrine\ORM\Mapping as ORM;
use Gedmo\Mapping\Annotation as Gedmo;
use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
use Symfony\Component\Serializer\Annotation\Groups;
use Symfony\Component\Validator\Constraints as Assert;
/**
* Class Course.
*
* @ApiResource(
* attributes={"security"="is_granted('ROLE_ADMIN')"},
* normalizationContext={"groups"={"course:read"}, "swagger_definition_name"="Read"},
* denormalizationContext={"groups"={"course:write"}},
* )
*
* @ApiFilter(SearchFilter::class, properties={"title": "partial", "code": "partial"})
* @ApiFilter(PropertyFilter::class)
*
* @ORM\HasLifecycleCallbacks
* @ORM\Table(
* name="course",
@ -29,7 +43,6 @@ use Symfony\Component\Validator\Constraints as Assert;
* @UniqueEntity("code")
* @UniqueEntity("visualCode")
* @UniqueEntity("directory")
*
* @ORM\Entity
* @ORM\EntityListeners({"Chamilo\CoreBundle\Entity\Listener\CourseListener"})
*/
@ -43,7 +56,7 @@ class Course extends AbstractResource implements ResourceInterface
/**
* @var int
*
* @Groups({"course:read", "list"})
* @ORM\Column(name="id", type="integer", nullable=false, unique=false)
* @ORM\Id
* @ORM\GeneratedValue(strategy="AUTO")
@ -51,8 +64,8 @@ class Course extends AbstractResource implements ResourceInterface
protected $id;
/**
* @var string
*
* @var string the course title
* @Groups({"course:read", "course:write", "list"})
* @Assert\NotBlank()
*
* @ORM\Column(name="title", type="string", length=250, nullable=true, unique=false)
@ -171,7 +184,7 @@ class Course extends AbstractResource implements ResourceInterface
/**
* @var string
*
* @Groups({"course:read", "list"})
* @Assert\NotBlank()
*
* @Gedmo\Slug(
@ -193,7 +206,7 @@ class Course extends AbstractResource implements ResourceInterface
/**
* @var string
*
* @Groups({"course:read", "list"})
* @ORM\Column(name="course_language", type="string", length=20, nullable=true, unique=false)
*/
protected $courseLanguage;
@ -207,7 +220,7 @@ class Course extends AbstractResource implements ResourceInterface
/**
* @var CourseCategory
*
* @Groups({"course:read", "list"})
* @ORM\ManyToOne(targetEntity="Chamilo\CoreBundle\Entity\CourseCategory", inversedBy="courses")
* @ORM\JoinColumn(name="category_id", referencedColumnName="id")
*/
@ -215,7 +228,7 @@ class Course extends AbstractResource implements ResourceInterface
/**
* @var int
*
* @Groups({"course:read", "list"})
* @Assert\NotBlank()
*
* @ORM\Column(name="visibility", type="integer", nullable=true, unique=false)
@ -245,14 +258,14 @@ class Course extends AbstractResource implements ResourceInterface
/**
* @var string
*
* @Groups({"course:read", "list"})
* @ORM\Column(name="department_name", type="string", length=30, nullable=true, unique=false)
*/
protected $departmentName;
/**
* @var string
*
* @Groups({"course:read", "list"})
* @Assert\Url()
*
* @ORM\Column(name="department_url", type="string", length=180, nullable=true, unique=false)
@ -289,7 +302,7 @@ class Course extends AbstractResource implements ResourceInterface
/**
* @var \DateTime
*
* @Groups({"course:read", "list"})
* @ORM\Column(name="expiration_date", type="datetime", nullable=true, unique=false)
*/
protected $expirationDate;
@ -367,6 +380,7 @@ class Course extends AbstractResource implements ResourceInterface
$this->users = new ArrayCollection();
$this->urls = new ArrayCollection();
$this->tools = new ArrayCollection();
$this->gradebookCategories = new ArrayCollection();
$this->gradebookEvaluations = new ArrayCollection();
$this->gradebookLinks = new ArrayCollection();
@ -391,24 +405,9 @@ class Course extends AbstractResource implements ResourceInterface
return $this->sessions;
}
/**
* @param Session $session
*
* @return ArrayCollection
*/
public function getTools(Session $session = null)
public function getTools()
{
$orWhere = Criteria::expr()->eq('sessionId', 0);
if ($session) {
$orWhere = Criteria::expr()->in('sessionId', [0, $session->getId()]);
}
$criteria = Criteria::create()
->where(Criteria::expr()->isNull('sessionId'))
->orWhere($orWhere);
return $this->tools->matching($criteria);
return $this->tools;
}
/**

@ -6,6 +6,7 @@ namespace Chamilo\CoreBundle\Entity;
use Chamilo\UserBundle\Entity\User;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\Serializer\Annotation\Groups;
/**
* CourseRelUser.
@ -32,6 +33,8 @@ class CourseRelUser
protected $id;
/**
* Groups({"course_rel_user:read", "course_rel_user:write"}).
*
* @ORM\ManyToOne(targetEntity="Chamilo\UserBundle\Entity\User", inversedBy="courses", cascade={"persist"})
* @ORM\JoinColumn(name="user_id", referencedColumnName="id")
*/

@ -4,16 +4,22 @@
namespace Chamilo\CoreBundle\Entity;
use ApiPlatform\Core\Annotation\ApiResource;
use APY\DataGridBundle\Grid\Mapping as GRID;
use Chamilo\CoreBundle\Entity\Resource\AbstractResource;
use Chamilo\CoreBundle\Entity\Resource\ResourceInterface;
use Chamilo\CourseBundle\Traits\PersonalResourceTrait;
use Doctrine\ORM\Mapping as ORM;
use Gedmo\Timestampable\Traits\TimestampableEntity;
use Symfony\Component\Serializer\Annotation\Groups;
/**
* Illustration.
*
* @ApiResource(
* attributes={"security"="is_granted('ROLE_ADMIN')"},
* normalizationContext={"groups"={"illustration:read"}}
* )
* @ORM\Table(name="illustration")
* @ORM\Entity
* @GRID\Source(columns="id, name, resourceNode.createdAt", filterable=false, groups={"resource"})
@ -34,7 +40,7 @@ class Illustration extends AbstractResource implements ResourceInterface
/**
* @var string
*
* @Groups({"illustration:read"})
* @ORM\Column(name="name", type="string", length=255, nullable=false)
*/
protected $name;

@ -4,12 +4,14 @@
namespace Chamilo\CoreBundle\Entity\Resource;
use ApiPlatform\Core\Annotation\ApiSubresource;
use APY\DataGridBundle\Grid\Mapping as GRID;
use Chamilo\CoreBundle\Entity\Course;
use Chamilo\CoreBundle\Entity\Session;
use Doctrine\Common\Collections\Criteria;
use Doctrine\ORM\Mapping as ORM;
use JMS\Serializer\Annotation\Groups;
use Symfony\Component\Serializer\Annotation\Groups;
use Symfony\Component\Validator\Constraints as Assert;
/**
* @ORM\MappedSuperclass
@ -19,8 +21,11 @@ use JMS\Serializer\Annotation\Groups;
abstract class AbstractResource
{
/**
* SerializedName("description").
* @Assert\Valid()
* @ApiSubresource()
* @Groups({"resource_node:read", "document:read"})
* @GRID\Column(field="resourceNode.createdAt", title="Date added", type="datetime")
* @Groups({"list"})
* @ORM\OneToOne(
* targetEntity="Chamilo\CoreBundle\Entity\Resource\ResourceNode", cascade={"remove"}, orphanRemoval=true
* )

@ -4,17 +4,23 @@
namespace Chamilo\CoreBundle\Entity\Resource;
use ApiPlatform\Core\Annotation\ApiResource;
use Chamilo\CoreBundle\Traits\TimestampableAgoTrait;
use Chamilo\UserBundle\Entity\User;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\ORM\Mapping as ORM;
use Gedmo\Mapping\Annotation as Gedmo;
use Gedmo\Timestampable\Traits\TimestampableEntity;
use Gedmo\Tree\Traits\NestedSetEntity;
use JMS\Serializer\Annotation as JMS;
use JMS\Serializer\Annotation\Groups;
use Symfony\Component\Serializer\Annotation\Groups;
use Symfony\Component\Validator\Constraints as Assert;
/**
* @ApiResource(
* attributes={"security"="is_granted('ROLE_ADMIN')"},
* normalizationContext={"groups"={"comment:read"}}
* )
*
* @Gedmo\Tree(type="nested")
* @ORM\Entity(repositoryClass="Gedmo\Tree\Entity\Repository\NestedTreeRepository")
* @ORM\Table(name="resource_comment")
@ -22,13 +28,14 @@ use Symfony\Component\Validator\Constraints as Assert;
class ResourceComment
{
use TimestampableEntity;
use TimestampableAgoTrait;
use NestedSetEntity;
/**
* @ORM\Id
* @ORM\Column(type="integer")
* @ORM\GeneratedValue(strategy="AUTO")
* @Groups({"list"})
* @Groups({"comment:read"})
*/
protected $id;
@ -41,7 +48,7 @@ class ResourceComment
/**
* @var User
*
* @Groups({"list"})
* @Groups({"comment:read"})
* @ORM\ManyToOne(targetEntity="Chamilo\UserBundle\Entity\User")
* @ORM\JoinColumn(name="author_id", referencedColumnName="id", onDelete="SET NULL")
*/
@ -50,7 +57,7 @@ class ResourceComment
/**
* @var string
*
* @Groups({"list"})
* @Groups({"comment:read"})
* @Assert\NotBlank()
*
* @ORM\Column(name="content", type="string", nullable=false)
@ -70,20 +77,18 @@ class ResourceComment
/**
* @var \DateTime
* @Groups({"list"})
* @Groups({"comment:read"})
* @Gedmo\Timestampable(on="create")
* @ORM\Column(type="datetime")
* @JMS\Type("DateTime")
*/
protected $createdAt;
/**
* @var \DateTime
*
* @Groups({"list"})
* @Groups({"comment:read"})
* @Gedmo\Timestampable(on="update")
* @ORM\Column(type="datetime")
* @JMS\Type("DateTime")
*/
protected $updatedAt;
@ -100,6 +105,7 @@ class ResourceComment
public function __construct()
{
$this->createdAt = new \DateTimeImmutable();
$this->content = '';
$this->children = new ArrayCollection();
}

@ -4,17 +4,22 @@
namespace Chamilo\CoreBundle\Entity\Resource;
use ApiPlatform\Core\Annotation\ApiProperty;
use ApiPlatform\Core\Annotation\ApiResource;
use Doctrine\ORM\Mapping as ORM;
use Gedmo\Timestampable\Traits\TimestampableEntity;
use JMS\Serializer\Annotation\Groups;
use Symfony\Component\HttpFoundation\File\File;
use Symfony\Component\HttpFoundation\File\UploadedFile;
use Symfony\Component\Serializer\Annotation\Groups;
use Symfony\Component\Validator\Constraints as Assert;
use Vich\UploaderBundle\Mapping\Annotation as Vich;
/**
* @ApiResource(
* attributes={"security"="is_granted('ROLE_ADMIN')"},
* normalizationContext={"groups"={"resource_file:read"}}
* )
* @ORM\Entity
*
* @Vich\Uploadable
*
* @ORM\Table(name="resource_file")
@ -32,7 +37,7 @@ class ResourceFile
/**
* @Assert\NotBlank()
* @Groups({"list"})
* @Groups({"resource_file:read", "document:read"})
*
* @var string
*
@ -43,32 +48,32 @@ class ResourceFile
/**
* @var string
*/
protected $description;
//protected $description;
/**
* @var bool
*/
protected $enabled = false;
//protected $enabled;
/**
* @var int
*/
protected $width;
//protected $width;
/**
* @var int
*/
protected $height;
//protected $height;
/**
* @var float
*/
protected $length;
//protected $length;
/**
* @var string
*/
protected $copyright;
//protected $copyright;
/**
* @var string
@ -93,6 +98,7 @@ class ResourceFile
/**
* @var int
* @Groups({"resource_file:read", "document:read"})
*
* @ORM\Column(type="integer", nullable=true)
*/
@ -100,7 +106,8 @@ class ResourceFile
/**
* @var File
*
* @Groups({"resource_file:read", "document:read"})
* @Assert\NotNull(groups={"media_object_create"})
* @Vich\UploadableField(
* mapping="resources",
* fileNameProperty="name",
@ -119,6 +126,14 @@ class ResourceFile
*/
protected $crop;
/**
* @var string|null
*
* @ApiProperty(iri="http://schema.org/contentUrl")
* @Groups({"media_object_read"})
*/
public $contentUrl;
/**
* @var ResourceNode
*
@ -138,7 +153,6 @@ class ResourceFile
*/
public function __construct()
{
$this->enabled = true;
$this->metadata = [];
}
@ -185,18 +199,6 @@ class ResourceFile
return $this;
}
public function getHash(): string
{
return $this->hash;
}
public function setHash(string $hash): self
{
$this->hash = $hash;
return $this;
}
public function getSize(): int
{
return (int) $this->size;
@ -212,12 +214,12 @@ class ResourceFile
return $this;
}
public function getCopyright(): string
/*public function getCopyright(): string
{
return (string) $this->copyright;
}
}*/
public function getContentType(): string
/*public function getContentType(): string
{
return (string) $this->contentType;
}
@ -227,9 +229,9 @@ class ResourceFile
$this->contentType = $contentType;
return $this;
}
}*/
public function getExtension(): string
/*public function getExtension(): string
{
return $this->extension;
}
@ -239,7 +241,7 @@ class ResourceFile
$this->extension = $extension;
return $this;
}
}*/
public function getResourceNode(): ResourceNode
{
@ -253,7 +255,7 @@ class ResourceFile
return $this;
}
public function isEnabled(): bool
/*public function isEnabled(): bool
{
return $this->enabled;
}
@ -263,7 +265,7 @@ class ResourceFile
$this->enabled = $enabled;
return $this;
}
}*/
/**
* @return int
@ -283,7 +285,7 @@ class ResourceFile
return $this;
}
public function getDescription(): string
/*public function getDescription(): string
{
return $this->description;
}
@ -293,7 +295,7 @@ class ResourceFile
$this->description = $description;
return $this;
}
}*/
public function getMimeType(): string
{

@ -4,6 +4,7 @@
namespace Chamilo\CoreBundle\Entity\Resource;
use ApiPlatform\Core\Annotation\ApiResource;
use Chamilo\CoreBundle\Entity\Course;
use Chamilo\CoreBundle\Entity\Session;
use Chamilo\CoreBundle\Entity\Usergroup;
@ -13,6 +14,9 @@ use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\ORM\Mapping as ORM;
/**
* @ApiResource(
* attributes={"security"="is_granted('ROLE_ADMIN')"}
* )
* @ORM\Entity
* @ORM\Table(name="resource_link")
*/
@ -344,11 +348,6 @@ class ResourceLink
return self::VISIBILITY_DRAFT === $this->getVisibility();
}
public function getResource()
{
// return $this;
}
public static function getVisibilityList(): array
{
return [

@ -4,22 +4,30 @@
namespace Chamilo\CoreBundle\Entity\Resource;
use Chamilo\CoreBundle\Entity\Course;
use ApiPlatform\Core\Annotation\ApiFilter;
use ApiPlatform\Core\Annotation\ApiResource;
use ApiPlatform\Core\Serializer\Filter\PropertyFilter;
use Chamilo\CoreBundle\Entity\Session;
use Chamilo\CoreBundle\Traits\TimestampableAgoTrait;
use Chamilo\UserBundle\Entity\User;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Criteria;
use Doctrine\ORM\Mapping as ORM;
use Gedmo\Mapping\Annotation as Gedmo;
use Gedmo\Timestampable\Traits\TimestampableEntity;
use JMS\Serializer\Annotation as JMS;
use JMS\Serializer\Annotation\Groups;
use Symfony\Component\Routing\RouterInterface;
use Symfony\Component\Serializer\Annotation\Groups;
use Symfony\Component\Validator\Constraints as Assert;
/**
* Base entity for all resources.
*
* @ApiResource(
* attributes={"security"="is_granted('ROLE_ADMIN')"},
* collectionOperations={"get"},
* normalizationContext={"groups"={"resource_node:read", "document:read"}}
* )
* @ApiFilter(PropertyFilter::class)
* @ORM\Entity(repositoryClass="Chamilo\CoreBundle\Repository\ResourceNodeRepository")
*
* @ORM\Table(name="resource_node")
@ -30,9 +38,10 @@ class ResourceNode
{
public const PATH_SEPARATOR = '`';
use TimestampableEntity;
use TimestampableAgoTrait;
/**
* @Groups({"list"})
* @Groups({"resource_node:read", "document:read"})
* @ORM\Id
* @ORM\Column(type="integer")
* @ORM\GeneratedValue(strategy="AUTO")
@ -41,7 +50,7 @@ class ResourceNode
/**
* @Assert\NotBlank()
* @Groups({"list"})
* @Groups({"resource_node:read", "document:read"})
* @Gedmo\TreePathSource
*
* @ORM\Column(name="title", type="string", length=255, nullable=false)
@ -57,7 +66,7 @@ class ResourceNode
protected $slug;
/**
* @ORM\ManyToOne(targetEntity="ResourceType", inversedBy="resourceNodes")
* @ORM\ManyToOne(targetEntity="ResourceType")
* @ORM\JoinColumn(name="resource_type_id", referencedColumnName="id", nullable=false)
*/
protected $resourceType;
@ -70,8 +79,9 @@ class ResourceNode
protected $resourceLinks;
/**
* @var ResourceFile
* @Groups({"list"})
* @var ResourceFile available file for this node
*
* @Groups({"resource_node:read", "document:read"})
*
* @ORM\OneToOne(targetEntity="ResourceFile", inversedBy="resourceNode", orphanRemoval=true)
* @ORM\JoinColumn(name="resource_file_id", referencedColumnName="id", onDelete="CASCADE")
@ -79,7 +89,9 @@ class ResourceNode
protected $resourceFile;
/**
* @Groups({"list"})
* @var User the creator of this node
* @Assert\Valid()
* @Groups({"resource_node:read", "document:read"})
* @ORM\ManyToOne(
* targetEntity="Chamilo\UserBundle\Entity\User", inversedBy="resourceNodes"
* )
@ -89,7 +101,6 @@ class ResourceNode
/**
* @Gedmo\TreeParent
*
* @ORM\ManyToOne(
* targetEntity="ResourceNode",
* inversedBy="children"
@ -123,13 +134,6 @@ class ResourceNode
*/
protected $path;
/**
* Shortcut to access Course resource from ResourceNode.
*
* ORM\OneToOne(targetEntity="Chamilo\CoreBundle\Entity\Course", mappedBy="resourceNode")
*/
//protected $course;
/**
* Shortcut to access Course resource from ResourceNode.
*
@ -147,20 +151,18 @@ class ResourceNode
/**
* @var \DateTime
*
* @Groups({"list"})
* @Groups({"resource_node:read", "list"})
* @Gedmo\Timestampable(on="create")
* @ORM\Column(type="datetime")
* @JMS\Type("DateTime")
*/
protected $createdAt;
/**
* @var \DateTime
*
* @Groups({"list"})
* @Groups({"resource_node:read", "list"})
* @Gedmo\Timestampable(on="update")
* @ORM\Column(type="datetime")
* @JMS\Type("DateTime")
*/
protected $updatedAt;
@ -183,24 +185,6 @@ class ResourceNode
return (string) $this->getPathForDisplay();
}
/**
* @return Course
*/
public function getCourse(): ?Course
{
return $this->course;
}
public function isCourseNode(): bool
{
return null !== $this->course;
}
public function isIllustrationNode(): bool
{
return null !== $this->illustration;
}
/**
* Returns the resource id.
*

@ -1,37 +0,0 @@
<?php
/* For licensing terms, see /license.txt */
namespace Chamilo\CoreBundle\Entity\Resource;
use Doctrine\ORM\Mapping as ORM;
use Gedmo\Timestampable\Traits\TimestampableEntity;
/**
* @ORM\Entity
* @ORM\Table(name="resource_tag")
*/
class ResourceTag
{
use TimestampableEntity;
/**
* @ORM\Id
* @ORM\Column(type="integer")
* @ORM\GeneratedValue(strategy="AUTO")
*/
protected $id;
/**
* @var string
*
* @ORM\Column(name="name", type="string", nullable=false)
*/
protected $name;
/**
* @ORM\ManyToOne(targetEntity="Chamilo\UserBundle\Entity\User")
* @ORM\JoinColumn(name="author_id", referencedColumnName="id", onDelete="SET NULL")
*/
protected $author;
}

@ -1,36 +0,0 @@
<?php
/* For licensing terms, see /license.txt */
namespace Chamilo\CoreBundle\Entity\Resource;
use Doctrine\ORM\Mapping as ORM;
use Gedmo\Timestampable\Traits\TimestampableEntity;
/**
* @ORM\Entity
* @ORM\Table(name="resource_user_tag")
*/
class ResourceUserTag
{
use TimestampableEntity;
/**
* @ORM\Id
* @ORM\Column(type="integer")
* @ORM\GeneratedValue(strategy="AUTO")
*/
protected $id;
/**
* @ORM\ManyToOne(targetEntity="Chamilo\UserBundle\Entity\User")
* @ORM\JoinColumn(name="user_id", referencedColumnName="id", onDelete="SET NULL")
*/
protected $user;
/**
* @ORM\ManyToOne(targetEntity="Chamilo\CoreBundle\Entity\Resource\ResourceTag")
* @ORM\JoinColumn(name="tag_id", referencedColumnName="id", onDelete="SET NULL")
*/
protected $tag;
}

@ -4,20 +4,28 @@
namespace Chamilo\CoreBundle\Entity;
use ApiPlatform\Core\Annotation\ApiFilter;
use ApiPlatform\Core\Annotation\ApiResource;
use ApiPlatform\Core\Bridge\Doctrine\Orm\Filter\SearchFilter;
use Chamilo\CourseBundle\Entity\CStudentPublication;
use Chamilo\UserBundle\Entity\User;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\Common\Collections\Criteria;
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;
/**
* Class Session.
* UniqueEntity("name").
* @ApiResource(
* attributes={"security"="is_granted('ROLE_ADMIN')"},
* normalizationContext={"groups"={"session:read"}}
* )
*
* @ApiFilter(SearchFilter::class, properties={"name": "partial"})
* @ORM\Table(
* name="session",
* uniqueConstraints={@ORM\UniqueConstraint(name="name", columns={"name"})},
@ -42,7 +50,7 @@ class Session
/**
* @var int
*
* @Groups({"session:read", "list"})
* @ORM\Column(name="id", type="integer", nullable=false, unique=false)
* @ORM\Id
* @ORM\GeneratedValue(strategy="AUTO")
@ -114,13 +122,15 @@ class Session
/**
* @var string
*
* @Assert\NotBlank()
* @Groups({"session:read", "list"})
* @ORM\Column(name="name", type="string", length=150, nullable=false, unique=false)
*/
protected $name;
/**
* @var string
* @Groups({"session:read", "list"})
*
* @ORM\Column(name="description", type="text", nullable=true, unique=false)
*/
@ -184,7 +194,7 @@ class Session
/**
* @var \DateTime
*
* @Groups({"session:read", "list"})
* @ORM\Column(name="display_start_date", type="datetime", nullable=true, unique=false)
*/
protected $displayStartDate;
@ -233,7 +243,8 @@ class Session
/**
* @var int
*
* @Groups({"session:read", "list"})
* +\
* @ORM\Column(name="status", type="integer", nullable=false)
*/
protected $status;
@ -245,6 +256,7 @@ class Session
protected $generalCoach;
/**
* @Groups({"session:read", "list"})
* @ORM\ManyToOne(targetEntity="Chamilo\CoreBundle\Entity\SessionCategory", inversedBy="session")
* @ORM\JoinColumn(name="session_category_id", referencedColumnName="id")
*/

@ -4,17 +4,22 @@
namespace Chamilo\CoreBundle\Entity;
use ApiPlatform\Core\Annotation\ApiResource;
use Chamilo\CoreBundle\Component\Utils\ChamiloApi;
use Chamilo\SkillBundle\Entity\Profile;
use Chamilo\SkillBundle\Entity\SkillRelCourse;
use Chamilo\SkillBundle\Entity\SkillRelItem;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Criteria;
use Doctrine\ORM\Mapping as ORM;
use Gedmo\Mapping\Annotation as Gedmo;
use Symfony\Component\Serializer\Annotation\Groups;
use Symfony\Component\Validator\Constraints as Assert;
/**
* Skill.
* @ApiResource(
* attributes={"security"="is_granted('ROLE_ADMIN')"},
* normalizationContext={"groups"={"skill:read"}}
* )
*
* @ORM\Table(name="skill")
* @ORM\Entity(repositoryClass="Chamilo\CoreBundle\Repository\SkillRepository")
@ -47,7 +52,7 @@ class Skill
/**
* @var int
*
* @Groups({"skill:read"})
* @ORM\Column(name="id", type="integer")
* @ORM\Id
* @ORM\GeneratedValue
@ -56,6 +61,8 @@ class Skill
/**
* @var string
* @Groups({"skill:read"})
* @Assert\NotBlank()
*
* @ORM\Column(name="name", type="string", length=255, nullable=false)
*/

@ -49,48 +49,45 @@ class Tool
/**
* @return ArrayCollection
*/
public function getToolResourceRight()
/*public function getToolResourceRight()
{
return $this->toolResourceRight;
}
}*/
/**
* @param ArrayCollection $toolResourceRight
*/
public function setToolResourceRight($toolResourceRight)
/*public function setToolResourceRight($toolResourceRight)
{
$this->toolResourceRight = new ArrayCollection();
foreach ($toolResourceRight as $item) {
$this->addToolResourceRight($item);
}
}
}*/
/**
* @return $this
*/
public function addToolResourceRight(ToolResourceRight $toolResourceRight)
/*public function addToolResourceRight(ToolResourceRight $toolResourceRight)
{
$toolResourceRight->setTool($this);
$this->toolResourceRight[] = $toolResourceRight;
return $this;
}
}*/
public function getResourceNodes()
/*public function getResourceNodes()
{
return $this->resourceNodes;
}
}*/
/**
* @return $this
*/
public function setResourceNodes($resourceNodes)
/*public function setResourceNodes($resourceNodes)
{
$this->resourceNodes = $resourceNodes;
return $this;
}
}*/
/**
* Get id.

@ -6,6 +6,9 @@ namespace Chamilo\CoreBundle\Repository;
use Chamilo\CoreBundle\Entity\Course;
use Chamilo\CoreBundle\Entity\Resource\ResourceNode;
use Chamilo\CoreBundle\Entity\Session;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Criteria;
use Doctrine\ORM\Query\Expr\Join;
use Doctrine\ORM\QueryBuilder;
@ -16,6 +19,26 @@ use Doctrine\ORM\QueryBuilder;
*/
class CourseRepository extends ResourceRepository
{
/**
* @param Session $session
*
* @return ArrayCollection
*/
public function getTools(Course $course, Session $session = null)
{
$orWhere = Criteria::expr()->eq('sessionId', 0);
if ($session) {
$orWhere = Criteria::expr()->in('sessionId', [0, $session->getId()]);
}
$criteria = Criteria::create()
->where(Criteria::expr()->isNull('sessionId'))
->orWhere($orWhere);
return $course->getTools()->matching($criteria);
}
public function deleteCourse(Course $course): void
{
$em = $this->getEntityManager();

@ -27,7 +27,6 @@ use Cocur\Slugify\SlugifyInterface;
use Doctrine\ORM\EntityManager;
use Doctrine\ORM\EntityRepository;
use Doctrine\ORM\EntityRepository as BaseEntityRepository;
use Doctrine\ORM\Query\Expr\Join;
use Doctrine\ORM\QueryBuilder;
use League\Flysystem\FilesystemInterface;
use Symfony\Component\Filesystem\Exception\FileNotFoundException;
@ -696,8 +695,7 @@ class ResourceRepository extends BaseEntityRepository
//->addSelect('node')
;
$resource = $qb->getQuery()->getOneOrNullResult();
return $resource;
return $qb->getQuery()->getOneOrNullResult();
}
public function rowCanBeEdited(RowAction $action, Row $row, Session $session = null): ?RowAction

@ -0,0 +1,27 @@
<?php
/* For licensing terms, see /license.txt */
namespace Chamilo\CoreBundle\Traits;
use Carbon\Carbon;
use Symfony\Component\Serializer\Annotation\Groups;
trait TimestampableAgoTrait
{
/**
* @Groups({"api"})
*/
public function getCreatedAtAgo(): string
{
return Carbon::instance($this->getCreatedAt())->diffForHumans();
}
/**
* @Groups({"api"})
*/
public function getUpdatedAtAgo(): string
{
return Carbon::instance($this->getUpdatedAt())->diffForHumans();
}
}

@ -4,6 +4,10 @@
namespace Chamilo\CourseBundle\Entity;
use ApiPlatform\Core\Annotation\ApiFilter;
use ApiPlatform\Core\Annotation\ApiResource;
use ApiPlatform\Core\Bridge\Doctrine\Orm\Filter\SearchFilter;
use ApiPlatform\Core\Serializer\Filter\PropertyFilter;
use APY\DataGridBundle\Grid\Mapping as GRID;
use Chamilo\CoreBundle\Entity\Course;
use Chamilo\CoreBundle\Entity\Resource\AbstractResource;
@ -12,10 +16,16 @@ use Chamilo\CoreBundle\Entity\Session;
use Chamilo\CourseBundle\Traits\ShowCourseResourcesInSessionTrait;
use Doctrine\ORM\Event\LifecycleEventArgs;
use Doctrine\ORM\Mapping as ORM;
use JMS\Serializer\Annotation\Groups;
use Symfony\Component\Serializer\Annotation\Groups;
/**
* CDocument.
* @ApiResource(
* shortName="Documents",
* attributes={"security"="is_granted('ROLE_ADMIN')"},
* normalizationContext={"groups"={"document:read", "resource_node"}, "swagger_definition_name"="Read"}
* )
* @ApiFilter(PropertyFilter::class)
* @ApiFilter(SearchFilter::class, properties={"title": "partial", "course.code": "partial"})
*
* @ORM\Table(
* name="c_document",
@ -38,7 +48,7 @@ class CDocument extends AbstractResource implements ResourceInterface
/**
* @var int
* @Groups({"list"})
* @Groups({"list", "document:read"})
* @ORM\Column(name="iid", type="integer")
* @ORM\Id
* @ORM\GeneratedValue

@ -37,7 +37,6 @@ class SecurityController extends AbstractController
{
$helper = $this->authenticationUtils;
$error = $helper->getLastAuthenticationError();
$form = $this->createForm(LoginType::class, ['_username' => $helper->getLastUsername()]);
return $this->render('@ChamiloUser/login.html.twig', [

@ -4,6 +4,10 @@
namespace Chamilo\UserBundle\Entity;
use ApiPlatform\Core\Annotation\ApiFilter;
use ApiPlatform\Core\Annotation\ApiResource;
use ApiPlatform\Core\Bridge\Doctrine\Orm\Filter\BooleanFilter;
use ApiPlatform\Core\Bridge\Doctrine\Orm\Filter\SearchFilter;
use Chamilo\CoreBundle\Entity\AccessUrl;
use Chamilo\CoreBundle\Entity\AccessUrlRelUser;
use Chamilo\CoreBundle\Entity\Course;
@ -16,15 +20,24 @@ use Doctrine\Common\Collections\Collection;
use Doctrine\Common\Collections\Criteria;
use Doctrine\ORM\Event\LifecycleEventArgs;
use Doctrine\ORM\Mapping as ORM;
use JMS\Serializer\Annotation\Groups;
use Sonata\UserBundle\Entity\BaseUser;
use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
use Symfony\Component\Security\Core\User\EquatableInterface;
use Symfony\Component\Security\Core\User\UserInterface;
use Symfony\Component\Serializer\Annotation\Groups;
use Symfony\Component\Validator\Constraints as Assert;
use Symfony\Component\Validator\Mapping\ClassMetadata;
/**
* @ApiResource(
* attributes={"security"="is_granted('ROLE_ADMIN')"},
* normalizationContext={"groups"={"user:read"}},
* denormalizationContext={"groups"={"user:write"}},
* )
*
* @ApiFilter(SearchFilter::class, properties={"username": "partial", "firstname" : "partial"})
* @ApiFilter(BooleanFilter::class, properties={"isActive"})
*
* @ORM\HasLifecycleCallbacks
* @ORM\Table(
* name="user",
@ -34,7 +47,6 @@ use Symfony\Component\Validator\Mapping\ClassMetadata;
* }
* )
* @UniqueEntity("username")
*
* @ORM\Entity()
*
* @ORM\AttributeOverrides({
@ -83,32 +95,51 @@ class User extends BaseUser implements ThemeUser, EquatableInterface //implement
/**
* @var int
*
* @Groups({"user:read", "list"})
* @ORM\Column(name="id", type="integer")
* @ORM\Id
* @ORM\GeneratedValue(strategy="AUTO")
* @Groups({"list"})
*/
protected $id;
/**
* @Groups({"list"})
* @var string
* @Groups({"user:read", "user:write"})
*/
protected $firstname;
/**
* @var string
* @Groups({"user:read", "user:write"})
*/
protected $lastname;
/**
* @var string
* @Groups({"user:read", "user:write"})
* @Assert\NotBlank()
*/
protected $username;
/**
* @var int
*
* @ORM\Column(name="user_id", type="integer", nullable=true)
* @var string
* @Groups({"user:read", "user:write"})
* @Assert\NotBlank()
* @Assert\Email()
*/
protected $userId;
protected $email;
/**
* @var string
*/
protected $password;
/**
* @var int
*
* @ORM\Column(name="username", type="string", length=100, nullable=false, unique=true)
* @ORM\Column(name="user_id", type="integer", nullable=true)
*/
//protected $username;
protected $userId;
/**
* @var string
@ -662,10 +693,7 @@ class User extends BaseUser implements ThemeUser, EquatableInterface //implement
$this->courses = $courses;
}
/**
* @return ArrayCollection
*/
public function getCourses()
public function getCourses(): Collection
{
return $this->courses;
}

Loading…
Cancel
Save