|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
/* For licensing terms, see /license.txt */ |
|
6
|
|
|
|
|
7
|
|
|
namespace Chamilo\CoreBundle\Controller\Api; |
|
8
|
|
|
|
|
9
|
|
|
use Chamilo\CoreBundle\Entity\User; |
|
10
|
|
|
use Chamilo\CourseBundle\Entity\CStudentPublication; |
|
11
|
|
|
use Chamilo\CourseBundle\Repository\CStudentPublicationRepository; |
|
12
|
|
|
use Doctrine\ORM\EntityManager; |
|
13
|
|
|
use Symfony\Component\HttpFoundation\Request; |
|
14
|
|
|
use Symfony\Component\HttpKernel\KernelInterface; |
|
15
|
|
|
use Symfony\Contracts\Translation\TranslatorInterface; |
|
16
|
|
|
use Symfony\Bundle\SecurityBundle\Security; |
|
17
|
|
|
|
|
18
|
|
|
class CreateStudentPublicationFileAction extends BaseResourceFileAction |
|
19
|
|
|
{ |
|
20
|
|
|
public function __invoke( |
|
21
|
|
|
Request $request, |
|
22
|
|
|
CStudentPublicationRepository $repo, |
|
23
|
|
|
EntityManager $em, |
|
24
|
|
|
KernelInterface $kernel, |
|
25
|
|
|
TranslatorInterface $translator, |
|
26
|
|
|
Security $security |
|
27
|
|
|
): CStudentPublication { |
|
28
|
|
|
$fileExistsOption = $request->get('fileExistsOption', 'rename'); |
|
29
|
|
|
|
|
30
|
|
|
$studentPublication = new CStudentPublication(); |
|
31
|
|
|
|
|
32
|
|
|
$result = $this->handleCreateFileRequest( |
|
33
|
|
|
$studentPublication, |
|
34
|
|
|
$repo, |
|
35
|
|
|
$request, |
|
36
|
|
|
$em, |
|
37
|
|
|
$fileExistsOption, |
|
38
|
|
|
$translator |
|
39
|
|
|
); |
|
40
|
|
|
|
|
41
|
|
|
$studentPublication->setTitle($result['title']); |
|
42
|
|
|
$studentPublication->setFiletype($result['filetype']); |
|
43
|
|
|
$studentPublication->setDescription($result['comment'] ?? ''); |
|
44
|
|
|
$studentPublication->setContainsFile(1); |
|
45
|
|
|
$studentPublication->setAccepted(true); |
|
46
|
|
|
$studentPublication->setActive(1); |
|
47
|
|
|
$studentPublication->setSentDate(new \DateTime()); |
|
48
|
|
|
|
|
49
|
|
|
/** @var User $user */ |
|
50
|
|
|
$user = $security->getUser(); |
|
51
|
|
|
if ($user instanceof User) { |
|
|
|
|
|
|
52
|
|
|
$studentPublication->setUser($user); |
|
53
|
|
|
} |
|
54
|
|
|
|
|
55
|
|
|
$parentId = (int) $request->get('parentId'); |
|
56
|
|
|
if ($parentId > 0) { |
|
57
|
|
|
$parentEntity = $repo->find($parentId); |
|
58
|
|
|
if ($parentEntity) { |
|
59
|
|
|
$studentPublication->setPublicationParent($parentEntity); |
|
60
|
|
|
} |
|
61
|
|
|
} |
|
62
|
|
|
|
|
63
|
|
|
return $studentPublication; |
|
64
|
|
|
} |
|
65
|
|
|
} |
|
66
|
|
|
|