diff --git a/public/main/inc/lib/add_course.lib.inc.php b/public/main/inc/lib/add_course.lib.inc.php index 6532296a8a..a16c806bef 100644 --- a/public/main/inc/lib/add_course.lib.inc.php +++ b/public/main/inc/lib/add_course.lib.inc.php @@ -831,7 +831,7 @@ class AddCourse } // Adding the course to an URL. - UrlManager::add_course_to_url($course_id, $accessUrlId); + //UrlManager::add_course_to_url($course_id, $accessUrlId); // Add event to the system log. $user_id = api_get_user_id(); diff --git a/public/main/inc/lib/api.lib.php b/public/main/inc/lib/api.lib.php index 9f6431119b..6c123c5b15 100644 --- a/public/main/inc/lib/api.lib.php +++ b/public/main/inc/lib/api.lib.php @@ -1689,7 +1689,12 @@ function api_get_user_info_from_entity( $result['registration_date'] = $user->getRegistrationDate()->format('Y-m-d H:i:s'); $result['hr_dept_id'] = $user->getHrDeptId(); $result['expiration_date'] = $user->getExpirationDate()->format('Y-m-d H:i:s'); - $result['last_login'] = $user->getLastLogin()->format('Y-m-d H:i:s'); + + $result['last_login'] = null; + if ($user->getLastLogin()) { + $result['last_login'] = $user->getLastLogin()->format('Y-m-d H:i:s'); + } + $result['competences'] = $user->getCompetences(); $result['diplomas'] = $user->getDiplomas(); $result['teach'] = $user->getTeach(); @@ -3846,12 +3851,12 @@ function api_not_allowed( $message = null, $responseCode = 0 ) { - throw new Exception('You are not allowed'); + /*throw new Exception('You are not allowed'); $message = empty($message) ? get_lang('You are not allowed') : $message; Session::write('error_message', $message); header('Location: '.api_get_path(WEB_PUBLIC_PATH).'error'); - exit; + exit;*/ } /** diff --git a/public/main/inc/lib/usermanager.lib.php b/public/main/inc/lib/usermanager.lib.php index a16e79b7d2..7bcbbdeede 100644 --- a/public/main/inc/lib/usermanager.lib.php +++ b/public/main/inc/lib/usermanager.lib.php @@ -2,7 +2,7 @@ /* For licensing terms, see /license.txt */ use Chamilo\CoreBundle\Entity\ExtraField as EntityExtraField; -use Chamilo\CoreBundle\Entity\Resource\ResourceNode; +use Chamilo\CoreBundle\Entity\ResourceNode; use Chamilo\CoreBundle\Entity\SkillRelUser; use Chamilo\CoreBundle\Entity\SkillRelUserComment; use Chamilo\CoreBundle\Framework\Container; @@ -63,7 +63,6 @@ class UserManager * Create/update/delete methods are available in the UserManager * (based in the Sonata\UserBundle\Entity\UserManager). * - * @return \Sonata\UserBundle\Entity\UserManager */ public static function getManager() { @@ -311,10 +310,7 @@ class UserManager } $userManager = self::getManager(); - - /** @var User $user */ - $user = $userManager->createUser(); - + $user = new User(); $user ->setLastname($lastName) ->setFirstname($firstName) @@ -339,48 +335,48 @@ class UserManager $user->setExpirationDate($expirationDate); } - try { - $factory = Container::$container->get('Chamilo\CoreBundle\Repository\ResourceFactory'); - $repo = $factory->createRepository('global', 'users'); - $userManager->updateUser($user); + $em = Database::getManager(); + $repo = Container::$container->get('Chamilo\CoreBundle\Repository\UserRepository'); + $repo->updateUser($user, false); + /*$factory = Container::$container->get('Chamilo\CoreBundle\Repository\ResourceFactory'); + $repo = $factory->createRepository('global', 'users');*/ + + // Add user as a node + if ($addUserToNode) { + $resourceNode = new ResourceNode(); + $resourceNode + ->setTitle($loginName) + ->setCreator(api_get_user_entity($creatorId)) + ->setResourceType($repo->getResourceType()) + // ->setParent($url->getResourceNode()) + ; + $em->persist($resourceNode); + $user->setResourceNode($resourceNode); + } - // Add user as a node - if ($addUserToNode) { - $resourceNode = new ResourceNode(); - $resourceNode - ->setTitle($loginName) - ->setCreator(api_get_user_entity($creatorId)) - ->setResourceType($repo->getResourceType()) - // ->setParent($url->getResourceNode()) - ; - $repo->getEntityManager()->persist($resourceNode); - $user->setResourceNode($resourceNode); - } + $em->persist($user); + $em->flush($user); - $repo->getEntityManager()->persist($user); + $userId = $user->getId(); - $userId = $user->getId(); + // Add user to a group + $statusToGroup = [ + COURSEMANAGER => 'TEACHER', + STUDENT => 'STUDENT', + DRH => 'RRHH', + SESSIONADMIN => 'SESSION_ADMIN', + STUDENT_BOSS => 'STUDENT_BOSS', + INVITEE => 'INVITEE', + ]; - // Add user to a group - $statusToGroup = [ - COURSEMANAGER => 'TEACHER', - STUDENT => 'STUDENT', - DRH => 'RRHH', - SESSIONADMIN => 'SESSION_ADMIN', - STUDENT_BOSS => 'STUDENT_BOSS', - INVITEE => 'INVITEE', - ]; + $group = Container::$container->get('Chamilo\CoreBundle\Repository\GroupRepository')->findOneBy(['code' => $statusToGroup[$status]]); + if ($group) { + $user->addGroup($group); + $repo->updateUser($user); + } - $group = Container::$container->get('Chamilo\CoreBundle\Repository\GroupRepository')->findOneBy(['code' => $statusToGroup[$status]]); - if ($group) { - $user->addGroup($group); - $userManager->updateUser($user); - } + $em->flush(); - $repo->getEntityManager()->flush(); - } catch (Exception $e) { - error_log($e->getMessage()); - } if (!empty($userId)) { $return = $userId; $sql = "UPDATE $table_user SET user_id = $return WHERE id = $return"; diff --git a/public/main/webservices/api/tests/SaveUserTest.php b/public/main/webservices/api/tests/SaveUserTest.php index c64211f25b..9ea701853e 100644 --- a/public/main/webservices/api/tests/SaveUserTest.php +++ b/public/main/webservices/api/tests/SaveUserTest.php @@ -2,7 +2,7 @@ /* For licensing terms, see /license.txt */ require_once __DIR__.'/V2TestCase.php'; -require_once __DIR__.'/../../../../vendor/autoload.php'; +require_once __DIR__.'/../../../../../vendor/autoload.php'; /** * Class SaveUserTest @@ -28,11 +28,12 @@ class SaveUserTest extends V2TestCase $loginName = 'testUser'.time(); $email = 'testUser@local'; $status = 5; + $userId = $this->integer( [ 'loginname' => $loginName, - 'firstname' => 'Małgorzata', - 'lastname' => 'Summer', + 'firstname' => $loginName, + 'lastname' => $loginName, 'original_user_id_name' => 'external_user_id', 'original_user_id_value' => $loginName, 'email' => $email, @@ -74,8 +75,8 @@ class SaveUserTest extends V2TestCase 'original_user_id_value' => $loginName, 'status' => 5, 'password' => 'test', - 'firstname' => 'Małgorzata', - 'lastname' => 'Summer', + 'firstname' => $loginName, + 'lastname' => $loginName, 'extra' => [ ['field_name' => $extraFieldName, 'field_value' => $extraFieldOriginalValue], ], diff --git a/src/CoreBundle/Controller/Admin/AdminController.php b/src/CoreBundle/Controller/Admin/AdminController.php index 84683c38e3..53a125c429 100644 --- a/src/CoreBundle/Controller/Admin/AdminController.php +++ b/src/CoreBundle/Controller/Admin/AdminController.php @@ -11,6 +11,7 @@ use Symfony\Component\Routing\Annotation\Route; /** * Class Administrator. + * * @Route("/admin") */ class AdminController extends BaseController diff --git a/src/CoreBundle/Controller/CourseHomeController.php b/src/CoreBundle/Controller/CourseHomeController.php index a6293f27c4..90ebc2ed04 100644 --- a/src/CoreBundle/Controller/CourseHomeController.php +++ b/src/CoreBundle/Controller/CourseHomeController.php @@ -120,7 +120,6 @@ class CourseHomeController extends ToolBaseController 'tool' ); $result = $qb->getQuery()->getResult(); - $tools = []; /** @var CTool $item */ foreach ($result as $item) { diff --git a/src/CoreBundle/Controller/ResourceApiController.php b/src/CoreBundle/Controller/ResourceApiController.php index 8e23bd9978..4123d4b3b9 100644 --- a/src/CoreBundle/Controller/ResourceApiController.php +++ b/src/CoreBundle/Controller/ResourceApiController.php @@ -34,9 +34,6 @@ class ResourceApiController extends AbstractController implements CourseControll use ResourceControllerTrait; use ControllerTrait; - /** - * - */ public function getResourcesListAction($id, Request $request) { $repository = $this->getRepositoryFromRequest($request); @@ -57,9 +54,6 @@ class ResourceApiController extends AbstractController implements CourseControll return $qb->getQuery()->getResult(); } - /** - * - */ public function getResourceAction($id, Request $request) { $repository = $this->getRepositoryFromRequest($request); @@ -71,8 +65,6 @@ class ResourceApiController extends AbstractController implements CourseControll return $resource; } - /** - */ public function getResourceCommentsAction($id, Request $request, $paramFetcher) { $repository = $this->getRepositoryFromRequest($request); @@ -87,8 +79,6 @@ class ResourceApiController extends AbstractController implements CourseControll return $resource->getResourceNode()->getComments()->matching($criteria); } - /** - */ public function postResourceCommentAction($id, Request $request) { $repository = $this->getRepositoryFromRequest($request); diff --git a/src/CoreBundle/Entity/AbstractResource.php b/src/CoreBundle/Entity/AbstractResource.php index 115edf3364..a7add3ce98 100644 --- a/src/CoreBundle/Entity/AbstractResource.php +++ b/src/CoreBundle/Entity/AbstractResource.php @@ -6,8 +6,6 @@ namespace Chamilo\CoreBundle\Entity; 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 Symfony\Component\Serializer\Annotation\Groups; @@ -27,9 +25,7 @@ abstract class AbstractResource * @ApiSubresource() * @Groups({"resource_node:read", "resource_node:write", "document:read","document:write"}) * @GRID\Column(field="resourceNode.createdAt", title="Date added", type="datetime") - * @ORM\OneToOne( - * targetEntity="Chamilo\CoreBundle\Entity\ResourceNode", cascade={"remove"}, orphanRemoval=true - * ) + * @ORM\OneToOne(targetEntity="Chamilo\CoreBundle\Entity\ResourceNode", cascade={"persist", "remove"}, orphanRemoval=true) * @ORM\JoinColumn(name="resource_node_id", referencedColumnName="id", onDelete="CASCADE") */ public $resourceNode; diff --git a/src/CoreBundle/Entity/AccessUrl.php b/src/CoreBundle/Entity/AccessUrl.php index 3c60a9d38c..c4b69d0c96 100644 --- a/src/CoreBundle/Entity/AccessUrl.php +++ b/src/CoreBundle/Entity/AccessUrl.php @@ -4,14 +4,18 @@ namespace Chamilo\CoreBundle\Entity; -use Chamilo\CoreBundle\Entity\AbstractResource; -use Chamilo\CoreBundle\Entity\ResourceInterface; +use ApiPlatform\Core\Annotation\ApiResource; use Chamilo\CoreBundle\Traits\CourseTrait; 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; /** - * AccessUrl. + * @ApiResource( + * normalizationContext={"groups"={"access_url:read"}, "swagger_definition_name"="Read"}, + * denormalizationContext={"groups"={"access_url:write","course_category:write"}}, + * ) * * @Gedmo\Tree(type="nested") * @ORM\Table(name="access_url") @@ -109,6 +113,9 @@ class AccessUrl extends AbstractResource implements ResourceInterface /** * @var string + * @Assert\NotBlank() + * + * @Groups({"access_url:read", "access_url:write"}) * * @ORM\Column(name="url", type="string", length=255, nullable=false, unique=false) */ diff --git a/src/CoreBundle/Entity/Course.php b/src/CoreBundle/Entity/Course.php index 02886ea117..abdd3d93da 100644 --- a/src/CoreBundle/Entity/Course.php +++ b/src/CoreBundle/Entity/Course.php @@ -11,9 +11,6 @@ use ApiPlatform\Core\Annotation\ApiSubresource; use ApiPlatform\Core\Bridge\Doctrine\Orm\Filter\OrderFilter; use ApiPlatform\Core\Bridge\Doctrine\Orm\Filter\SearchFilter; use ApiPlatform\Core\Serializer\Filter\PropertyFilter; -use Chamilo\CoreBundle\Entity\AbstractResource; -use Chamilo\CoreBundle\Entity\ResourceInterface; -use Chamilo\CoreBundle\Entity\ResourceLink; use Chamilo\CourseBundle\Entity\CGroupInfo; use Chamilo\CourseBundle\Entity\CTool; use Doctrine\Common\Collections\ArrayCollection; @@ -98,7 +95,7 @@ class Course extends AbstractResource implements ResourceInterface * @var CourseRelUser[]|ArrayCollection * * @ApiSubresource() - * + * @Groups({"course:read"}) * "orphanRemoval" is needed to delete the CourseRelUser relation * in the CourseAdmin class. The setUsers, getUsers, removeUsers and * addUsers methods need to be added. @@ -431,11 +428,11 @@ class Course extends AbstractResource implements ResourceInterface public function setTools($tools) { foreach ($tools as $tool) { - $this->addTools($tool); + $this->addTool($tool); } } - public function addTools(CTool $tool) + public function addTool(CTool $tool) { $tool->setCourse($this); $this->tools[] = $tool; diff --git a/src/CoreBundle/Entity/CourseCategory.php b/src/CoreBundle/Entity/CourseCategory.php index 5faa99602d..49bd870345 100644 --- a/src/CoreBundle/Entity/CourseCategory.php +++ b/src/CoreBundle/Entity/CourseCategory.php @@ -16,6 +16,7 @@ use Symfony\Component\Validator\Constraints as Assert; /** * CourseCategory. + * * @ApiResource( * normalizationContext={"groups"={"course_category:read", "course:read"}, "swagger_definition_name"="Read"}, * denormalizationContext={"groups"={"course_category:write", "course:write"}}, diff --git a/src/CoreBundle/Entity/CourseRelUser.php b/src/CoreBundle/Entity/CourseRelUser.php index 8534a0a772..e9c72f5e85 100644 --- a/src/CoreBundle/Entity/CourseRelUser.php +++ b/src/CoreBundle/Entity/CourseRelUser.php @@ -13,7 +13,6 @@ use Symfony\Component\Serializer\Annotation\Groups; * * @ApiResource( * shortName="CourseSubscription", - * attributes={"security"="is_granted('ROLE_ADMIN')"}, * normalizationContext={"groups"={"course_rel_user:read"}} * ) * @@ -25,7 +24,6 @@ use Symfony\Component\Serializer\Annotation\Groups; * } * ) * @ORM\Entity - * @ORM\Table(name="course_rel_user") */ class CourseRelUser { @@ -39,6 +37,8 @@ class CourseRelUser protected $id; /** + * @Groups({"course:read"}) + * * @ORM\ManyToOne(targetEntity="Chamilo\CoreBundle\Entity\User", inversedBy="courses", cascade={"persist"}) * @ORM\JoinColumn(name="user_id", referencedColumnName="id") */ diff --git a/src/CoreBundle/Entity/Illustration.php b/src/CoreBundle/Entity/Illustration.php index 96bb0afb03..a2a2d5fc4c 100644 --- a/src/CoreBundle/Entity/Illustration.php +++ b/src/CoreBundle/Entity/Illustration.php @@ -6,8 +6,6 @@ namespace Chamilo\CoreBundle\Entity; use ApiPlatform\Core\Annotation\ApiResource; use APY\DataGridBundle\Grid\Mapping as GRID; -use Chamilo\CoreBundle\Entity\AbstractResource; -use Chamilo\CoreBundle\Entity\ResourceInterface; use Chamilo\CourseBundle\Traits\PersonalResourceTrait; use Doctrine\ORM\Mapping as ORM; use Gedmo\Timestampable\Traits\TimestampableEntity; diff --git a/src/CoreBundle/Entity/Listener/CourseListener.php b/src/CoreBundle/Entity/Listener/CourseListener.php index 092ef68d44..b28b1c4747 100644 --- a/src/CoreBundle/Entity/Listener/CourseListener.php +++ b/src/CoreBundle/Entity/Listener/CourseListener.php @@ -61,8 +61,6 @@ class CourseListener //$url = $course->getCurrentUrl(); //$repo = $args->getEntityManager()->getRepository('ChamiloCoreBundle:Course'); ///$this->checkLimit($repo, $course, $url); - /// - // $repo = $args->getEntityManager()->getRepository('ChamiloCoreBundle:Course'); $this->toolChain->addToolsInCourse($this->toolRepository, $course); } } @@ -71,6 +69,7 @@ class CourseListener { /** @var AccessUrlRelCourse $urlRelCourse */ if ($course) { + /*$urlRelCourse = $course->getUrls()->first(); $url = $urlRelCourse->getUrl();*/ //$url = $course->getCurrentUrl(); diff --git a/src/CoreBundle/Entity/Listener/ResourceListener.php b/src/CoreBundle/Entity/Listener/ResourceListener.php index 775794acb1..3f6750d1a2 100644 --- a/src/CoreBundle/Entity/Listener/ResourceListener.php +++ b/src/CoreBundle/Entity/Listener/ResourceListener.php @@ -5,6 +5,7 @@ namespace Chamilo\CoreBundle\Entity\Listener; use Chamilo\CoreBundle\Entity\AbstractResource; +use Chamilo\CoreBundle\Entity\Course; use Chamilo\CoreBundle\Entity\ResourceNode; use Chamilo\CoreBundle\ToolChain; use Cocur\Slugify\SlugifyInterface; @@ -34,6 +35,10 @@ class ResourceListener public function prePersist(AbstractResource $resource, LifecycleEventArgs $args) { + if (!$resource instanceof Course) { + return true; + } + // Add resource node $em = $args->getEntityManager(); $id = $this->request->getCurrentRequest()->getSession()->get('access_url_id'); diff --git a/src/CoreBundle/Entity/Listener/SessionListener.php b/src/CoreBundle/Entity/Listener/SessionListener.php index 379020e456..48caf9e84f 100644 --- a/src/CoreBundle/Entity/Listener/SessionListener.php +++ b/src/CoreBundle/Entity/Listener/SessionListener.php @@ -5,11 +5,8 @@ namespace Chamilo\CoreBundle\Entity\Listener; use Chamilo\CoreBundle\Entity\AccessUrl; -use Chamilo\CoreBundle\Entity\AccessUrlRelSession; use Chamilo\CoreBundle\Entity\Session; use Chamilo\CoreBundle\Repository\SessionRepository; -use Chamilo\CoreBundle\ToolChain; -use Cocur\Slugify\SlugifyInterface; use Doctrine\ORM\Event\LifecycleEventArgs; use Symfony\Component\HttpFoundation\RequestStack; use Symfony\Component\Security\Core\Security; diff --git a/src/CoreBundle/Entity/PersonalFile.php b/src/CoreBundle/Entity/PersonalFile.php index 29164b7570..f93978b097 100644 --- a/src/CoreBundle/Entity/PersonalFile.php +++ b/src/CoreBundle/Entity/PersonalFile.php @@ -5,8 +5,6 @@ namespace Chamilo\CoreBundle\Entity; use APY\DataGridBundle\Grid\Mapping as GRID; -use Chamilo\CoreBundle\Entity\AbstractResource; -use Chamilo\CoreBundle\Entity\ResourceInterface; use Doctrine\ORM\Mapping as ORM; use Gedmo\Timestampable\Traits\TimestampableEntity; diff --git a/src/CoreBundle/Entity/ResourceComment.php b/src/CoreBundle/Entity/ResourceComment.php index 15360350e5..f619af1c14 100644 --- a/src/CoreBundle/Entity/ResourceComment.php +++ b/src/CoreBundle/Entity/ResourceComment.php @@ -5,7 +5,6 @@ namespace Chamilo\CoreBundle\Entity; use ApiPlatform\Core\Annotation\ApiResource; -use Chamilo\CoreBundle\Entity\User; use Chamilo\CoreBundle\Traits\TimestampableAgoTrait; use Doctrine\Common\Collections\ArrayCollection; use Doctrine\ORM\Mapping as ORM; diff --git a/src/CoreBundle/Entity/ResourceFile.php b/src/CoreBundle/Entity/ResourceFile.php index 215f5fe213..4ae0d35286 100644 --- a/src/CoreBundle/Entity/ResourceFile.php +++ b/src/CoreBundle/Entity/ResourceFile.php @@ -10,6 +10,7 @@ use ApiPlatform\Core\Annotation\ApiResource; use ApiPlatform\Core\Bridge\Doctrine\Orm\Filter\OrderFilter; use ApiPlatform\Core\Bridge\Doctrine\Orm\Filter\SearchFilter; use ApiPlatform\Core\Serializer\Filter\PropertyFilter; +use Chamilo\CoreBundle\Controller\CreateResourceFileAction; use Doctrine\ORM\Mapping as ORM; use Gedmo\Timestampable\Traits\TimestampableEntity; use Symfony\Component\HttpFoundation\File\File; @@ -17,7 +18,6 @@ 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; -use Chamilo\CoreBundle\Controller\CreateResourceFileAction; // //* attributes={"security"="is_granted('ROLE_ADMIN')"}, @@ -414,20 +414,12 @@ class ResourceFile } } - /** - * @return string|null - */ public function getContentUrl(): ?string { return $this->contentUrl; } - /** - * @param string|null $contentUrl - * - * @return ResourceFile - */ - public function setContentUrl(?string $contentUrl): ResourceFile + public function setContentUrl(?string $contentUrl): self { $this->contentUrl = $contentUrl; diff --git a/src/CoreBundle/Entity/ResourceLink.php b/src/CoreBundle/Entity/ResourceLink.php index f532124b2c..652dae2356 100644 --- a/src/CoreBundle/Entity/ResourceLink.php +++ b/src/CoreBundle/Entity/ResourceLink.php @@ -12,8 +12,8 @@ use Symfony\Component\Serializer\Annotation\Groups; /** * @ApiResource( - * normalizationContext={"groups"={"resource_link:read", "course:read"}}, - * + * shortName="ResourceLink", + * normalizationContext={"groups"={"resource_link:read", "course:read"}} * ) * @ORM\Entity * @ORM\Table(name="resource_link") @@ -28,12 +28,12 @@ class ResourceLink /** * @ORM\Id * @ORM\Column(type="integer") - * @ORM\GeneratedValue(strategy="AUTO") + * @ORM\GeneratedValue */ protected $id; /** - * @Groups({"resource_link:read", "resource_node:read", "course:read"}) + * * * @ORM\ManyToOne(targetEntity="Chamilo\CoreBundle\Entity\ResourceNode", inversedBy="resourceLinks") * @ORM\JoinColumn(name="resource_node_id", referencedColumnName="id", onDelete="SET NULL") @@ -41,7 +41,6 @@ class ResourceLink protected $resourceNode; /** - * @Groups({"resource_link:read", "resource_node:read", "course:read"}) * * @ORM\ManyToOne(targetEntity="Chamilo\CoreBundle\Entity\Course", inversedBy="resourceLinks") * @ORM\JoinColumn(name="c_id", referencedColumnName="id", nullable=true) diff --git a/src/CoreBundle/Entity/ResourceNode.php b/src/CoreBundle/Entity/ResourceNode.php index b4952c947e..92dc8236da 100644 --- a/src/CoreBundle/Entity/ResourceNode.php +++ b/src/CoreBundle/Entity/ResourceNode.php @@ -5,14 +5,11 @@ 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; use ApiPlatform\Core\Bridge\Doctrine\Orm\Filter\SearchFilter; use ApiPlatform\Core\Serializer\Filter\PropertyFilter; -use Chamilo\CoreBundle\Entity\Session; -use Chamilo\CoreBundle\Entity\User; use Chamilo\CoreBundle\Traits\TimestampableAgoTrait; use Doctrine\Common\Collections\ArrayCollection; use Doctrine\Common\Collections\Criteria; @@ -73,8 +70,6 @@ class ResourceNode protected $slug; /** - * @Groups({"resource_node:read", "resource_node:write"}) - * * @ORM\ManyToOne(targetEntity="ResourceType") * @ORM\JoinColumn(name="resource_type_id", referencedColumnName="id", nullable=false) */ @@ -85,7 +80,7 @@ class ResourceNode * * @var ResourceLink[] * - * @ORM\OneToMany(targetEntity="ResourceLink", mappedBy="resourceNode", cascade={"remove"}) + * @ORM\OneToMany(targetEntity="ResourceLink", mappedBy="resourceNode", cascade={"persist", "remove"}) */ protected $resourceLinks; @@ -111,6 +106,9 @@ class ResourceNode protected $creator; /** + * @ApiSubresource() + * + * @Groups({"resource_node:read", "document:read"}) * @Gedmo\TreeParent * @ORM\ManyToOne( * targetEntity="ResourceNode", @@ -139,6 +137,7 @@ class ResourceNode protected $children; /** + * @Groups({"resource_node:read", "document:read"}) * @Gedmo\TreePath(appendId=true,separator="`") * * @ORM\Column(name="path", type="text", nullable=true) diff --git a/src/CoreBundle/Entity/ResourceType.php b/src/CoreBundle/Entity/ResourceType.php index 6aee051411..8d9338379b 100644 --- a/src/CoreBundle/Entity/ResourceType.php +++ b/src/CoreBundle/Entity/ResourceType.php @@ -4,7 +4,6 @@ namespace Chamilo\CoreBundle\Entity; -use Chamilo\CoreBundle\Entity\Tool; use Doctrine\ORM\Mapping as ORM; use Gedmo\Timestampable\Traits\TimestampableEntity; use Symfony\Component\Validator\Constraints as Assert; diff --git a/src/CoreBundle/Entity/Session.php b/src/CoreBundle/Entity/Session.php index 34262d8a68..4871b38c67 100644 --- a/src/CoreBundle/Entity/Session.php +++ b/src/CoreBundle/Entity/Session.php @@ -1290,28 +1290,18 @@ class Session return $this; } - /** - * @return User - */ public function getSessionAdmin(): User { return $this->sessionAdmin; } - /** - * @param User $sessionAdmin - * - * @return Session - */ - public function setSessionAdmin(User $sessionAdmin): Session + public function setSessionAdmin(User $sessionAdmin): self { $this->sessionAdmin = $sessionAdmin; return $this; } - - public function isUserGeneralCoach(User $user): bool { $generalCoach = $this->getGeneralCoach(); diff --git a/src/CoreBundle/Entity/SessionCategory.php b/src/CoreBundle/Entity/SessionCategory.php index 8d6d307eec..45dbc49b7a 100644 --- a/src/CoreBundle/Entity/SessionCategory.php +++ b/src/CoreBundle/Entity/SessionCategory.php @@ -10,6 +10,7 @@ use Symfony\Component\Serializer\Annotation\Groups; /** * SessionCategory. + * * @ApiResource( * normalizationContext={"groups"={"session_category:read"}, "swagger_definition_name"="Read"}, * denormalizationContext={"groups"={"session_category:write"}}, diff --git a/src/CoreBundle/Entity/Ticket.php b/src/CoreBundle/Entity/Ticket.php index df63eb7ecd..d9e88f361e 100644 --- a/src/CoreBundle/Entity/Ticket.php +++ b/src/CoreBundle/Entity/Ticket.php @@ -4,8 +4,6 @@ namespace Chamilo\CoreBundle\Entity; -use Chamilo\CoreBundle\Entity\Course; -use Chamilo\CoreBundle\Entity\Session; use Doctrine\ORM\Mapping as ORM; /** diff --git a/src/CoreBundle/Entity/TicketAssignedLog.php b/src/CoreBundle/Entity/TicketAssignedLog.php index dbd429fc12..5bab07da67 100644 --- a/src/CoreBundle/Entity/TicketAssignedLog.php +++ b/src/CoreBundle/Entity/TicketAssignedLog.php @@ -4,7 +4,6 @@ namespace Chamilo\CoreBundle\Entity; -use Chamilo\CoreBundle\Entity\User; use Doctrine\ORM\Mapping as ORM; /** diff --git a/src/CoreBundle/Entity/Tool.php b/src/CoreBundle/Entity/Tool.php index 0115e1e102..bf5091ddb6 100644 --- a/src/CoreBundle/Entity/Tool.php +++ b/src/CoreBundle/Entity/Tool.php @@ -4,7 +4,6 @@ namespace Chamilo\CoreBundle\Entity; -use Chamilo\CoreBundle\Entity\ResourceType; use Doctrine\Common\Collections\ArrayCollection; use Doctrine\Common\Collections\Criteria; use Doctrine\ORM\Mapping as ORM; diff --git a/src/CoreBundle/Entity/User.php b/src/CoreBundle/Entity/User.php index 27db649f79..003e0b8b31 100644 --- a/src/CoreBundle/Entity/User.php +++ b/src/CoreBundle/Entity/User.php @@ -10,7 +10,6 @@ use ApiPlatform\Core\Annotation\ApiResource; use ApiPlatform\Core\Annotation\ApiSubresource; use ApiPlatform\Core\Bridge\Doctrine\Orm\Filter\BooleanFilter; use ApiPlatform\Core\Bridge\Doctrine\Orm\Filter\SearchFilter; -use Chamilo\CoreBundle\Entity\ResourceNode; use Doctrine\Common\Collections\ArrayCollection; use Doctrine\Common\Collections\Collection; use Doctrine\Common\Collections\Criteria; @@ -112,7 +111,7 @@ class User implements UserInterface, EquatableInterface /** * @var string - * @Groups({"user:read", "user:write"}) + * @Groups({"user:read", "user:write", "course:read"}) * @Assert\NotBlank() * @ORM\Column(name="username", type="string", length=100, nullable=false, unique=true) */ @@ -582,8 +581,8 @@ class User implements UserInterface, EquatableInterface $this->groups = new ArrayCollection(); //$this->extraFields = new ArrayCollection(); //$this->userId = 0; - //$this->createdAt = new \DateTime(); - //$this->updatedAt = new \DateTime(); + $this->createdAt = new \DateTime(); + $this->updatedAt = new \DateTime(); $this->enabled = false; $this->locked = false; @@ -1485,8 +1484,6 @@ class User implements UserInterface, EquatableInterface return $this; } - - /** * Set lastLogin. * @@ -2125,40 +2122,24 @@ class User implements UserInterface, EquatableInterface return $this; } - /** - * @return string - */ public function getWebsite(): string { return $this->website; } - /** - * @param string $website - * - * @return User - */ - public function setWebsite(string $website): User + public function setWebsite(string $website): self { $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 + public function setBiography(string $biography): self { $this->biography = $biography; @@ -2174,6 +2155,4 @@ class User implements UserInterface, EquatableInterface return $this->courseGroupsAsTutor->matching($criteria); } - - } diff --git a/src/CourseBundle/EventListener/CourseAccessListener.php b/src/CoreBundle/EventListener/CourseAccessListener.php similarity index 92% rename from src/CourseBundle/EventListener/CourseAccessListener.php rename to src/CoreBundle/EventListener/CourseAccessListener.php index 734accaf1b..3a88250dad 100644 --- a/src/CourseBundle/EventListener/CourseAccessListener.php +++ b/src/CoreBundle/EventListener/CourseAccessListener.php @@ -2,11 +2,12 @@ /* For licensing terms, see /license.txt */ -namespace Chamilo\CourseBundle\EventListener; +namespace Chamilo\CoreBundle\EventListener; use Chamilo\CoreBundle\Entity\TrackECourseAccess; use Chamilo\CourseBundle\Event\CourseAccess; use Doctrine\ORM\EntityManager; +use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\RequestStack; /** @@ -19,7 +20,7 @@ class CourseAccessListener protected $em; /** - * @var \Symfony\Component\HttpFoundation\Request + * @var Request */ protected $request; diff --git a/src/CourseBundle/EventListener/CourseListener.php b/src/CoreBundle/EventListener/CourseListener.php similarity index 99% rename from src/CourseBundle/EventListener/CourseListener.php rename to src/CoreBundle/EventListener/CourseListener.php index 63c03caa7e..904ce8b58a 100644 --- a/src/CourseBundle/EventListener/CourseListener.php +++ b/src/CoreBundle/EventListener/CourseListener.php @@ -2,7 +2,7 @@ /* For licensing terms, see /license.txt */ -namespace Chamilo\CourseBundle\EventListener; +namespace Chamilo\CoreBundle\EventListener; use Chamilo\CoreBundle\Entity\Course; use Chamilo\CoreBundle\Entity\User; @@ -73,6 +73,7 @@ class CourseListener $courseFromSession = $sessionHandler->get('course'); if ($courseId === $courseFromSession->getId()) { $course = $courseFromSession; + $courseInfo = $sessionHandler->get('_course'); } } @@ -80,6 +81,7 @@ class CourseListener /** @var EntityManager $em */ $em = $container->get('doctrine')->getManager(); $course = $em->getRepository('ChamiloCoreBundle:Course')->find($courseId); + //dump("get course from DB $courseId"); $courseInfo = api_get_course_info($course->getCode()); } diff --git a/src/CourseBundle/EventListener/SessionAccessListener.php b/src/CoreBundle/EventListener/SessionAccessListener.php similarity index 96% rename from src/CourseBundle/EventListener/SessionAccessListener.php rename to src/CoreBundle/EventListener/SessionAccessListener.php index 29d2050af5..54218166d9 100644 --- a/src/CourseBundle/EventListener/SessionAccessListener.php +++ b/src/CoreBundle/EventListener/SessionAccessListener.php @@ -2,7 +2,7 @@ /* For licensing terms, see /license.txt */ -namespace Chamilo\CourseBundle\EventListener; +namespace Chamilo\CoreBundle\EventListener; use Chamilo\CoreBundle\Entity\TrackECourseAccess; use Chamilo\CourseBundle\Event\SessionAccess; diff --git a/src/CoreBundle/EventSubscriber/ResolveResourceFileContentUrlSubscriber.php b/src/CoreBundle/EventSubscriber/ResolveResourceFileContentUrlSubscriber.php index 3e72110afd..32ab974785 100644 --- a/src/CoreBundle/EventSubscriber/ResolveResourceFileContentUrlSubscriber.php +++ b/src/CoreBundle/EventSubscriber/ResolveResourceFileContentUrlSubscriber.php @@ -6,13 +6,12 @@ namespace Chamilo\CoreBundle\EventSubscriber; use ApiPlatform\Core\EventListener\EventPriorities; use ApiPlatform\Core\Util\RequestAttributesExtractor; -use Chamilo\CoreBundle\Entity\Resource\ResourceFile; +use Chamilo\CoreBundle\Entity\ResourceFile; use Symfony\Component\EventDispatcher\EventSubscriberInterface; use Symfony\Component\HttpFoundation\Response; use Symfony\Component\HttpKernel\Event\ViewEvent; use Symfony\Component\HttpKernel\KernelEvents; use Symfony\Component\Routing\Generator\UrlGeneratorInterface; -use Symfony\Component\Routing\RouterInterface; use Vich\UploaderBundle\Storage\StorageInterface; class ResolveResourceFileContentUrlSubscriber implements EventSubscriberInterface @@ -65,8 +64,6 @@ class ResolveResourceFileContentUrlSubscriber implements EventSubscriberInterfac ]; $mediaObject->contentUrl = $this->generator->generate('chamilo_core_resource_view_file', $params); - - //$mediaObject->contentUrl = $this->storage->resolveUri($mediaObject, 'file'); } } } diff --git a/src/CoreBundle/Repository/IllustrationRepository.php b/src/CoreBundle/Repository/IllustrationRepository.php index 4ce44d42d7..289ee18168 100644 --- a/src/CoreBundle/Repository/IllustrationRepository.php +++ b/src/CoreBundle/Repository/IllustrationRepository.php @@ -6,9 +6,9 @@ namespace Chamilo\CoreBundle\Repository; use APY\DataGridBundle\Grid\Column\Column; use APY\DataGridBundle\Grid\Grid; +use Chamilo\CoreBundle\Entity\AbstractResource; use Chamilo\CoreBundle\Entity\Course; use Chamilo\CoreBundle\Entity\Illustration; -use Chamilo\CoreBundle\Entity\AbstractResource; use Chamilo\CoreBundle\Entity\ResourceFile; use Chamilo\CoreBundle\Entity\ResourceNode; use Chamilo\CoreBundle\Entity\Session; diff --git a/src/CoreBundle/Repository/ResourceRepository.php b/src/CoreBundle/Repository/ResourceRepository.php index 39c5503fc6..fde463ca70 100644 --- a/src/CoreBundle/Repository/ResourceRepository.php +++ b/src/CoreBundle/Repository/ResourceRepository.php @@ -8,8 +8,8 @@ use APY\DataGridBundle\Grid\Action\RowAction; use APY\DataGridBundle\Grid\Row; use Chamilo\CoreBundle\Component\Resource\Settings; use Chamilo\CoreBundle\Component\Resource\Template; -use Chamilo\CoreBundle\Entity\Course; use Chamilo\CoreBundle\Entity\AbstractResource; +use Chamilo\CoreBundle\Entity\Course; use Chamilo\CoreBundle\Entity\ResourceFile; use Chamilo\CoreBundle\Entity\ResourceInterface; use Chamilo\CoreBundle\Entity\ResourceLink; @@ -26,7 +26,6 @@ use Chamilo\CourseBundle\Entity\CGroupInfo; use Cocur\Slugify\SlugifyInterface; use Doctrine\ORM\EntityManager; use Doctrine\ORM\EntityRepository; -use Doctrine\ORM\EntityRepository as BaseEntityRepository; use Doctrine\ORM\QueryBuilder; use League\Flysystem\FilesystemInterface; use Symfony\Component\Filesystem\Exception\FileNotFoundException; @@ -41,7 +40,7 @@ use Symfony\Component\Security\Core\Authorization\AuthorizationCheckerInterface; * Class ResourceRepository. * Extends EntityRepository is needed to process settings. */ -class ResourceRepository extends BaseEntityRepository +class ResourceRepository extends EntityRepository { /** * @var EntityRepository @@ -254,21 +253,21 @@ class ResourceRepository extends BaseEntityRepository public function addResourceToCourse(AbstractResource $resource, int $visibility, User $creator, Course $course, Session $session = null, CGroupInfo $group = null, UploadedFile $file = null) { - $node = $this->createNodeForResource($resource, $creator, $course->getResourceNode(), $file); + $resourceNode = $this->createNodeForResource($resource, $creator, $course->getResourceNode(), $file); - $this->addResourceNodeToCourse($node, $visibility, $course, $session, $group); + $this->addResourceNodeToCourse($resourceNode, $visibility, $course, $session, $group); } public function addResourceToCourseWithParent(AbstractResource $resource, ResourceNode $parentNode, int $visibility, User $creator, Course $course, Session $session = null, CGroupInfo $group = null, UploadedFile $file = null) { - $node = $this->createNodeForResource($resource, $creator, $parentNode, $file); + $resourceNode = $this->createNodeForResource($resource, $creator, $parentNode, $file); - $this->addResourceNodeToCourse($node, $visibility, $course, $session, $group); + $this->addResourceNodeToCourse($resourceNode, $visibility, $course, $session, $group); } public function addResourceNodeToCourse(ResourceNode $resourceNode, int $visibility, Course $course, Session $session = null, CGroupInfo $group = null, User $toUser = null): void { - if (empty($visibility)) { + if (0 === $visibility) { $visibility = ResourceLink::VISIBILITY_PUBLISHED; } @@ -304,15 +303,14 @@ class ResourceRepository extends BaseEntityRepository } $em = $this->getEntityManager(); + $em->persist($resourceNode); $em->persist($link); } public function addResourceToMe(ResourceNode $resourceNode): ResourceLink { $resourceLink = new ResourceLink(); - $resourceLink - ->setResourceNode($resourceNode) - ; + $resourceLink->setResourceNode($resourceNode); $this->getEntityManager()->persist($resourceLink); $this->getEntityManager()->flush(); @@ -353,15 +351,15 @@ class ResourceRepository extends BaseEntityRepository return $resourceLink; } - public function addResourceToCourseGroup( - ResourceNode $resourceNode, - CGroupInfo $group - ) { - $exists = $resourceNode->getResourceLinks()->exists(function ($key, $element) use ($group) { - if ($element->getGroup()) { - return $group->getIid() == $element->getGroup()->getIid(); + public function addResourceToCourseGroup(ResourceNode $resourceNode, CGroupInfo $group) + { + $exists = $resourceNode->getResourceLinks()->exists( + function ($key, $element) use ($group) { + if ($element->getGroup()) { + return $group->getIid() == $element->getGroup()->getIid(); + } } - }); + ); if (false === $exists) { $resourceLink = new ResourceLink(); @@ -863,7 +861,6 @@ class ResourceRepository extends BaseEntityRepository $em = $this->getEntityManager(); $resourceType = $this->getResourceType(); - $resourceNode = new ResourceNode(); $resourceName = $resource->getResourceName(); $extension = $this->slugify->slugify(pathinfo($resourceName, PATHINFO_EXTENSION)); @@ -875,6 +872,7 @@ class ResourceRepository extends BaseEntityRepository $slug = sprintf('%s.%s', $this->slugify->slugify($originalBasename), $originalExtension); } + $resourceNode = new ResourceNode(); $resourceNode ->setTitle($resourceName) ->setSlug($slug) diff --git a/src/CoreBundle/Repository/UserRepository.php b/src/CoreBundle/Repository/UserRepository.php index bf0e732e1d..3f1aa34ab9 100644 --- a/src/CoreBundle/Repository/UserRepository.php +++ b/src/CoreBundle/Repository/UserRepository.php @@ -16,6 +16,7 @@ use Chamilo\CoreBundle\Entity\Session; use Chamilo\CoreBundle\Entity\SessionRelCourseRelUser; use Chamilo\CoreBundle\Entity\SkillRelUser; use Chamilo\CoreBundle\Entity\SkillRelUserComment; +use Chamilo\CoreBundle\Entity\Ticket; use Chamilo\CoreBundle\Entity\TrackEAccess; use Chamilo\CoreBundle\Entity\TrackEAttempt; use Chamilo\CoreBundle\Entity\TrackECourseAccess; @@ -45,10 +46,10 @@ use Chamilo\CourseBundle\Entity\CStudentPublication; use Chamilo\CourseBundle\Entity\CStudentPublicationComment; use Chamilo\CourseBundle\Entity\CSurveyAnswer; use Chamilo\CourseBundle\Entity\CWiki; -use Chamilo\CoreBundle\Entity\Ticket; use Doctrine\Common\Collections\Criteria; use Doctrine\ORM\Query\Expr\Join; use Symfony\Bridge\Doctrine\Security\User\UserLoaderInterface; +use Symfony\Component\Security\Core\Encoder\UserPasswordEncoderInterface; use Symfony\Component\Security\Core\Exception\UsernameNotFoundException; use Symfony\Component\Security\Core\User\PasswordUpgraderInterface; use Symfony\Component\Security\Core\User\UserInterface; @@ -65,6 +66,16 @@ use Symfony\Component\Serializer\Serializer; */ class UserRepository extends ResourceRepository implements UserLoaderInterface, PasswordUpgraderInterface { + /** + * @var UserPasswordEncoderInterface + */ + protected $encoder; + + public function setEncoder(UserPasswordEncoderInterface $encoder){ + + $this->encoder = $encoder; + } + public function loadUserByUsername($username) { return $this->findBy(['username' => $username]); @@ -80,26 +91,35 @@ class UserRepository extends ResourceRepository implements UserLoaderInterface, } } - public function updateCanonicalFields(UserInterface $user) + public function canonicalize($string) { - //$user->setUsernameCanonical($this->canonicalizeUsername($user->getUsername())); - //$user->setEmailCanonical($this->canonicalizeEmail($user->getEmail())); + $encoding = mb_detect_encoding($string); + $result = $encoding + ? mb_convert_case($string, MB_CASE_LOWER, $encoding) + : mb_convert_case($string, MB_CASE_LOWER); + + return $result; } + public function updateCanonicalFields(UserInterface $user) + { + $user->setUsernameCanonical($this->canonicalize($user->getUsername())); + $user->setEmailCanonical($this->canonicalize($user->getEmail())); + } - /** - * {@inheritDoc} - */ public function updatePassword(UserInterface $user) { + //UserPasswordEncoderInterface $passwordEncoder if (0 !== strlen($password = $user->getPlainPassword())) { - // $encoder = $this->getEncoder($user); + $password = $this->encoder->encodePassword($user, $password); + $user->setPassword($password); + $user->eraseCredentials(); + // $encoder = $this->getEncoder($user); //$user->setPassword($encoder->encodePassword($password, $user->getSalt())); //$user->eraseCredentials(); } } - public function upgradePassword(UserInterface $user, string $newEncodedPassword): void { // this code is only an example; the exact code will depend on diff --git a/src/CoreBundle/Resources/config/repositories.yml b/src/CoreBundle/Resources/config/repositories.yml index 73c4e7aed8..5f9de0e594 100644 --- a/src/CoreBundle/Resources/config/repositories.yml +++ b/src/CoreBundle/Resources/config/repositories.yml @@ -34,5 +34,7 @@ services: Chamilo\CoreBundle\Repository\UserRepository: arguments: $className: 'Chamilo\CoreBundle\Entity\User' + calls: + - [setEncoder, ['@security.user_password_encoder.generic']] Chamilo\CoreBundle\Repository\GroupRepository: ~ diff --git a/src/CoreBundle/Resources/config/services.yml b/src/CoreBundle/Resources/config/services.yml index 1a9dbaf32f..bb2f328a6a 100644 --- a/src/CoreBundle/Resources/config/services.yml +++ b/src/CoreBundle/Resources/config/services.yml @@ -153,6 +153,36 @@ services: tags: - {name: doctrine.orm.entity_listener, entity_manager: default, lazy: true} + chamilo_course.listener.course: + class: Chamilo\CoreBundle\EventListener\CourseListener + calls: + - [setContainer, ['@service_container']] + tags: + - {name: kernel.event_listener, event: kernel.request, method: onKernelRequest, priority: 6} + - {name: kernel.event_listener, event: kernel.response, method: onKernelResponse} + - {name: kernel.event_listener, event: kernel.controller, method: onKernelController} + + # Sets the user access in a course listener + chamilo_course.listener.course_access: + class: Chamilo\CoreBundle\EventListener\CourseAccessListener + arguments: + - '@doctrine.orm.entity_manager' + calls: + - [setRequest, ['@request_stack']] + tags: + - {name: kernel.event_listener, event: chamilo_course.course.access, method: onCourseAccessEvent} + + # Sets the user access in a course session listener + chamilo_course.listener.session_access: + class: Chamilo\CoreBundle\EventListener\SessionAccessListener + arguments: + - '@doctrine.orm.entity_manager' + calls: + - [setRequest, ['@request_stack']] + tags: + - {name: kernel.event_listener, event: chamilo_course.course.session, method: onSessionAccessEvent} + + # When Course entity is loaded chamilo_core.listener.course: class: Chamilo\CoreBundle\Entity\Listener\CourseListener diff --git a/src/CoreBundle/ToolChain.php b/src/CoreBundle/ToolChain.php index b26222f304..fd3a7a3caa 100644 --- a/src/CoreBundle/ToolChain.php +++ b/src/CoreBundle/ToolChain.php @@ -170,10 +170,6 @@ class ToolChain foreach ($tools as $tool) { $visibility = in_array($tool->getName(), $toolVisibility, true); $criteria = ['name' => $tool->getName()]; - // Skip global tools. - /*if ($tool->isCourseTool() === false) { - continue; - }*/ if (!isset($toolList[$tool->getName()])) { continue; } @@ -190,7 +186,7 @@ class ToolChain ; $toolRepository->addResourceToCourse($courseTool, ResourceLink::VISIBILITY_PUBLISHED, $user, $course); - $course->addTools($courseTool); + $course->addTool($courseTool); } return $course; diff --git a/src/CourseBundle/Entity/CDocument.php b/src/CourseBundle/Entity/CDocument.php index dd31e58c67..ebcf31500b 100644 --- a/src/CourseBundle/Entity/CDocument.php +++ b/src/CourseBundle/Entity/CDocument.php @@ -5,21 +5,19 @@ namespace Chamilo\CourseBundle\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; 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\AbstractResource; +use Chamilo\CoreBundle\Entity\Course; use Chamilo\CoreBundle\Entity\ResourceInterface; use Chamilo\CoreBundle\Entity\Session; use Chamilo\CourseBundle\Traits\ShowCourseResourcesInSessionTrait; use Doctrine\ORM\Event\LifecycleEventArgs; use Doctrine\ORM\Mapping as ORM; use Symfony\Component\Serializer\Annotation\Groups; + //* attributes={"security"="is_granted('ROLE_ADMIN')"}, /** * @ApiResource( @@ -27,7 +25,7 @@ use Symfony\Component\Serializer\Annotation\Groups; * normalizationContext={"groups"={"document:read", "resource_node:read"}}, * denormalizationContext={"groups"={"document:write"}} * ) - * @ApiFilter(SearchFilter::class, properties={"title": "partial", "resourceNode": "exact"}) + * @ApiFilter(SearchFilter::class, properties={"title": "partial", "resourceNode.parent": "exact"}) * @ApiFilter( * OrderFilter::class, * properties={ diff --git a/src/CourseBundle/Entity/CExerciseCategory.php b/src/CourseBundle/Entity/CExerciseCategory.php index 8d0ccecf42..6d59f0ce26 100644 --- a/src/CourseBundle/Entity/CExerciseCategory.php +++ b/src/CourseBundle/Entity/CExerciseCategory.php @@ -5,8 +5,8 @@ namespace Chamilo\CourseBundle\Entity; use APY\DataGridBundle\Grid\Mapping as GRID; -use Chamilo\CoreBundle\Entity\Course; use Chamilo\CoreBundle\Entity\AbstractResource; +use Chamilo\CoreBundle\Entity\Course; use Chamilo\CoreBundle\Entity\ResourceInterface; use Doctrine\ORM\Mapping as ORM; use Gedmo\Mapping\Annotation as Gedmo; diff --git a/src/CourseBundle/Entity/CGroupInfo.php b/src/CourseBundle/Entity/CGroupInfo.php index 9d6ec7adfb..b521df3073 100644 --- a/src/CourseBundle/Entity/CGroupInfo.php +++ b/src/CourseBundle/Entity/CGroupInfo.php @@ -4,8 +4,8 @@ namespace Chamilo\CourseBundle\Entity; -use Chamilo\CoreBundle\Entity\Course; use Chamilo\CoreBundle\Entity\AbstractResource; +use Chamilo\CoreBundle\Entity\Course; use Chamilo\CoreBundle\Entity\ResourceInterface; use Chamilo\CoreBundle\Entity\User; use Chamilo\CoreBundle\Traits\CourseTrait; diff --git a/src/CourseBundle/Entity/CQuiz.php b/src/CourseBundle/Entity/CQuiz.php index 7b46e320ce..59376b1ffc 100644 --- a/src/CourseBundle/Entity/CQuiz.php +++ b/src/CourseBundle/Entity/CQuiz.php @@ -4,8 +4,8 @@ namespace Chamilo\CourseBundle\Entity; -use Chamilo\CoreBundle\Entity\Course; use Chamilo\CoreBundle\Entity\AbstractResource; +use Chamilo\CoreBundle\Entity\Course; use Chamilo\CoreBundle\Entity\ResourceInterface; use Chamilo\CourseBundle\Traits\ShowCourseResourcesInSessionTrait; use Doctrine\ORM\Event\LifecycleEventArgs; diff --git a/src/CourseBundle/Entity/CTool.php b/src/CourseBundle/Entity/CTool.php index 3a73ff7f98..b7cf46e919 100644 --- a/src/CourseBundle/Entity/CTool.php +++ b/src/CourseBundle/Entity/CTool.php @@ -5,8 +5,8 @@ namespace Chamilo\CourseBundle\Entity; use APY\DataGridBundle\Grid\Mapping as GRID; -use Chamilo\CoreBundle\Entity\Course; use Chamilo\CoreBundle\Entity\AbstractResource; +use Chamilo\CoreBundle\Entity\Course; use Chamilo\CoreBundle\Entity\ResourceInterface; use Chamilo\CoreBundle\Entity\Session; use Chamilo\CoreBundle\Entity\Tool; diff --git a/src/CourseBundle/Repository/CForumPostRepository.php b/src/CourseBundle/Repository/CForumPostRepository.php index c5f351a3ce..6ff64b7e2b 100644 --- a/src/CourseBundle/Repository/CForumPostRepository.php +++ b/src/CourseBundle/Repository/CForumPostRepository.php @@ -4,8 +4,8 @@ namespace Chamilo\CourseBundle\Repository; -use Chamilo\CoreBundle\Entity\Course; use Chamilo\CoreBundle\Entity\AbstractResource; +use Chamilo\CoreBundle\Entity\Course; use Chamilo\CoreBundle\Entity\User; use Chamilo\CoreBundle\Repository\ResourceRepository; use Chamilo\CourseBundle\Entity\CForumPost; diff --git a/src/CourseBundle/Repository/CShortcutRepository.php b/src/CourseBundle/Repository/CShortcutRepository.php index 38550eb98f..4224af8ebe 100644 --- a/src/CourseBundle/Repository/CShortcutRepository.php +++ b/src/CourseBundle/Repository/CShortcutRepository.php @@ -4,8 +4,8 @@ namespace Chamilo\CourseBundle\Repository; -use Chamilo\CoreBundle\Entity\Course; use Chamilo\CoreBundle\Entity\AbstractResource; +use Chamilo\CoreBundle\Entity\Course; use Chamilo\CoreBundle\Entity\ResourceNode; use Chamilo\CoreBundle\Entity\Session; use Chamilo\CoreBundle\Entity\User; diff --git a/src/CourseBundle/Resources/config/services.yml b/src/CourseBundle/Resources/config/services.yml index 4b00858848..adf935514e 100644 --- a/src/CourseBundle/Resources/config/services.yml +++ b/src/CourseBundle/Resources/config/services.yml @@ -162,31 +162,3 @@ services: $className: 'Chamilo\CourseBundle\Entity\CTool' # Event Listeners - chamilo_course.listener.course: - class: Chamilo\CourseBundle\EventListener\CourseListener - calls: - - [setContainer, ['@service_container']] - tags: - - {name: kernel.event_listener, event: kernel.request, method: onKernelRequest, priority: 6} - - {name: kernel.event_listener, event: kernel.response, method: onKernelResponse} - - {name: kernel.event_listener, event: kernel.controller, method: onKernelController} - - # Sets the user access in a course listener - chamilo_course.listener.course_access: - class: Chamilo\CourseBundle\EventListener\CourseAccessListener - arguments: - - '@doctrine.orm.entity_manager' - calls: - - [setRequest, ['@request_stack']] - tags: - - {name: kernel.event_listener, event: chamilo_course.course.access, method: onCourseAccessEvent} - - # Sets the user access in a course session listener - chamilo_course.listener.session_access: - class: Chamilo\CourseBundle\EventListener\SessionAccessListener - arguments: - - '@doctrine.orm.entity_manager' - calls: - - [setRequest, ['@request_stack']] - tags: - - {name: kernel.event_listener, event: chamilo_course.course.session, method: onSessionAccessEvent} diff --git a/tests/datafiller/data_users.php b/tests/datafiller/data_users.php index 065ce2a96b..892478fcfb 100755 --- a/tests/datafiller/data_users.php +++ b/tests/datafiller/data_users.php @@ -439,17 +439,6 @@ $users[] = [ 'creator_id' => 1, 'active' => 1, ]; -$users[] = [ - 'username' => 'mdolata', - 'pass' => 'mdolata', - 'firstname' => 'Małgorzata', - 'lastname' => 'Summer', - 'status' => 5, - 'auth_source' => 'platform', - 'email' => 'mdolata@example.com', - 'creator_id' => 1, - 'active' => 1, -]; $users[] = [ 'username' => 'adaniel', 'pass' => 'adaniel', diff --git a/tests/scripts/migrate_item_property.php b/tests/scripts/migrate_item_property.php index 5087a19e99..72aa5e89af 100644 --- a/tests/scripts/migrate_item_property.php +++ b/tests/scripts/migrate_item_property.php @@ -3,11 +3,11 @@ use Chamilo\CourseBundle\Entity\CDocument; use Chamilo\CoreBundle\Framework\Container; -use Chamilo\CoreBundle\Entity\Resource\ResourceNode; -use Chamilo\CoreBundle\Entity\Resource\ResourceLink; -use Chamilo\CoreBundle\Entity\Resource\ResourceFile; -use Chamilo\CoreBundle\Entity\Resource\ResourceType; -use Chamilo\CoreBundle\Entity\Resource\ResourceRight; +use Chamilo\CoreBundle\Entity\ResourceNode; +use Chamilo\CoreBundle\Entity\ResourceLink; +use Chamilo\CoreBundle\Entity\ResourceFile; +use Chamilo\CoreBundle\Entity\ResourceType; +use Chamilo\CoreBundle\Entity\ResourceRight; use Chamilo\MediaBundle\Entity\Media; use Chamilo\CoreBundle\Security\Authorization\Voter\ResourceNodeVoter; @@ -25,10 +25,10 @@ echo 'change course id in the query'; require_once __DIR__.'/../../main/inc/global.inc.php'; -$sql = "SELECT - d.id, +$sql = "SELECT + d.id, d.c_id, - d.session_id, + d.session_id, i.to_group_id, i.to_user_id, i.iid, @@ -36,18 +36,18 @@ $sql = "SELECT insert_date, lastedit_date, tool, - visibility - FROM c_item_property i - INNER JOIN c_document d - ON (d.iid = i.ref AND i.c_id = d.c_id) - WHERE - i.tool = 'document' AND + visibility + FROM c_item_property i + INNER JOIN c_document d + ON (d.iid = i.ref AND i.c_id = d.c_id) + WHERE + i.tool = 'document' AND d.c_id = 12 ORDER BY d.path"; $result = Database::query($sql); $em = Database::getManager(); -$resourceType = $em->getRepository('ChamiloCoreBundle:Resource\ResourceType')->findOneBy(['name' => 'document']); +$resourceType = $em->getRepository('ChamiloCoreBundle:ResourceType')->findOneBy(['name' => 'document']); $coursePath = api_get_path(SYS_PATH).'app/courses/'; $mediaManager = Container::$container->get('sonata.media.manager.media'); $documentManager = $em->getRepository('ChamiloCourseBundle:CDocument');