Merge remote-tracking branch 'origin/master'

pull/5095/head
Angel Fernando Quiroz Campos 2 years ago
commit 2c125c3990
  1. 2
      assets/vue/views/assignments/AssignmentsCreate.vue
  2. 1
      public/main/inc/lib/document.lib.php
  3. 28
      public/main/inc/lib/events.lib.php
  4. 12
      src/CoreBundle/Controller/ResourceController.php
  5. 100
      src/CoreBundle/Entity/TrackEDownloads.php
  6. 6
      src/CoreBundle/Framework/Container.php
  7. 36
      src/CoreBundle/Migrations/Schema/V200/Version20240114215900.php
  8. 39
      src/CoreBundle/Repository/TrackEDownloadsRepository.php

@ -42,4 +42,4 @@ function onSubmit(publicationStudent) {
.catch((error) => showErrorNotification(error))
.finally(() => (isFormLoading.value = false))
}
</script>
</script>

@ -2227,6 +2227,7 @@ class DocumentManager
public static function enough_space($file_size, $max_dir_space)
{
if ($max_dir_space) {
$max_dir_space = $max_dir_space * 1024 * 1024;
$courseEntity = api_get_course_entity();
$repo = Container::getDocumentRepository();
$total = $repo->getFolderSize($courseEntity->getResourceNode(), $courseEntity);

@ -7,6 +7,7 @@ use Chamilo\CoreBundle\Entity\Course as CourseEntity;
use Chamilo\CoreBundle\Entity\Session as SessionEntity;
use Chamilo\CoreBundle\Entity\TrackEAttemptQualify;
use Chamilo\CoreBundle\Entity\TrackEDefault;
use Chamilo\CoreBundle\Entity\TrackEDownloads;
use Chamilo\CoreBundle\Entity\TrackEExercise;
use Chamilo\CoreBundle\Entity\User;
use Chamilo\CoreBundle\Framework\Container;
@ -272,24 +273,19 @@ class Event
return false;
}
$table = Database::get_main_table(TABLE_STATISTIC_TRACK_E_DOWNLOADS);
$documentUrl = Database::escape_string($documentUrl);
$user = api_get_user_entity();
$course = api_get_course_entity();
$session = api_get_session_entity();
$reallyNow = api_get_utc_datetime();
$userId = api_get_user_id();
$courseId = api_get_course_int_id();
$sessionId = api_get_session_id();
$em = Database::getManager();
return Database::insert(
$table,
[
'down_user_id' => $userId,
'c_id' => $courseId,
'down_doc_path' => $documentUrl,
'down_date' => $reallyNow,
'session_id' => $sessionId,
]
);
$repository = $em->getRepository(TrackEDownloads::class);
$resourceLinkId = $course->getFirstResourceLink()->getId();
$downloadId = $repository->saveDownload($user->getId(), $resourceLinkId, $documentUrl);
return $downloadId;
}
/**

@ -10,6 +10,8 @@ use Chamilo\CoreBundle\Entity\Course;
use Chamilo\CoreBundle\Entity\ResourceLink;
use Chamilo\CoreBundle\Entity\ResourceNode;
use Chamilo\CoreBundle\Entity\Session;
use Chamilo\CoreBundle\Entity\TrackEDownloads;
use Chamilo\CoreBundle\Entity\User;
use Chamilo\CoreBundle\Repository\ResourceWithLinkInterface;
use Chamilo\CoreBundle\Security\Authorization\Voter\ResourceNodeVoter;
use Chamilo\CoreBundle\Tool\ToolChain;
@ -171,7 +173,7 @@ class ResourceController extends AbstractResourceController implements CourseCon
* @return RedirectResponse|StreamedResponse
*/
#[Route('/{tool}/{type}/{id}/download', name: 'chamilo_core_resource_download', methods: ['GET'])]
public function downloadAction(Request $request)
public function downloadAction(Request $request, EntityManagerInterface $entityManager)
{
$id = $request->get('id');
$resourceNode = $this->getResourceNodeRepository()->findOneBy(['uuid' => $id]);
@ -190,6 +192,14 @@ class ResourceController extends AbstractResourceController implements CourseCon
// If resource node has a file just download it. Don't download the children.
if ($resourceNode->hasResourceFile()) {
/** @var ?User $user */
$user = $this->getUser();
$resourceLinkId = $resourceNode->getResourceLinks()->first()->getId();
$url = $resourceNode->getResourceFile()->getOriginalName();
$downloadRepository = $entityManager->getRepository(TrackEDownloads::class);
$downloadId = $downloadRepository->saveDownload($user->getId(), $resourceLinkId, $url);
// Redirect to download single file.
return $this->processFile($request, $resourceNode, 'download');
}

@ -6,6 +6,7 @@ declare(strict_types=1);
namespace Chamilo\CoreBundle\Entity;
use Chamilo\CoreBundle\Repository\TrackEDownloadsRepository;
use DateTime;
use Doctrine\ORM\Mapping as ORM;
@ -14,9 +15,7 @@ use Doctrine\ORM\Mapping as ORM;
*/
#[ORM\Table(name: 'track_e_downloads')]
#[ORM\Index(name: 'idx_ted_user_id', columns: ['down_user_id'])]
#[ORM\Index(name: 'idx_ted_c_id', columns: ['c_id'])]
#[ORM\Index(name: 'session_id', columns: ['session_id'])]
#[ORM\Entity]
#[ORM\Entity(repositoryClass: TrackEDownloadsRepository::class)]
class TrackEDownloads
{
#[ORM\Column(name: 'down_id', type: 'integer')]
@ -30,132 +29,99 @@ class TrackEDownloads
#[ORM\Column(name: 'down_date', type: 'datetime', nullable: false)]
protected DateTime $downDate;
#[ORM\Column(name: 'c_id', type: 'integer', nullable: false)]
protected int $cId;
#[ORM\Column(name: 'down_doc_path', type: 'string', length: 255, nullable: false)]
protected string $downDocPath;
#[ORM\Column(name: 'session_id', type: 'integer', nullable: false)]
protected int $sessionId;
#[ORM\ManyToOne(targetEntity: ResourceLink::class, cascade: ['persist', 'remove'])]
#[ORM\JoinColumn(name: 'resource_link_id', referencedColumnName: 'id', onDelete: 'SET NULL', nullable: true)]
protected ?ResourceLink $resourceLink = null;
/**
* Set downUserId.
* Set downDocPath.
*
* @return TrackEDownloads
*/
public function setDownUserId(int $downUserId)
public function setDownDocPath(string $downDocPath)
{
$this->downUserId = $downUserId;
$this->downDocPath = $downDocPath;
return $this;
}
/**
* Get downUserId.
*
* @return int
*/
public function getDownUserId()
{
return $this->downUserId;
}
/**
* Set downDate.
* Get downDocPath.
*
* @return TrackEDownloads
* @return string
*/
public function setDownDate(DateTime $downDate)
public function getDownDocPath()
{
$this->downDate = $downDate;
return $this;
return $this->downDocPath;
}
/**
* Get downDate.
* Get downId.
*
* @return DateTime
* @return int
*/
public function getDownDate()
public function getDownId()
{
return $this->downDate;
return $this->downId;
}
/**
* Set cId.
* Set downUserId.
*
* @return TrackEDownloads
*/
public function setCId(int $cId)
public function setDownUserId(int $downUserId)
{
$this->cId = $cId;
$this->downUserId = $downUserId;
return $this;
}
/**
* Get cId.
* Get downUserId.
*
* @return int
*/
public function getCId()
public function getDownUserId()
{
return $this->cId;
return $this->downUserId;
}
/**
* Set downDocPath.
* Set downDate.
*
* @return TrackEDownloads
*/
public function setDownDocPath(string $downDocPath)
public function setDownDate(DateTime $downDate)
{
$this->downDocPath = $downDocPath;
$this->downDate = $downDate;
return $this;
}
/**
* Get downDocPath.
* Get downDate.
*
* @return string
* @return DateTime
*/
public function getDownDocPath()
public function getDownDate()
{
return $this->downDocPath;
return $this->downDate;
}
/**
* Set sessionId.
* Set resourceLink.
*
* @param ResourceLink|null $resourceLink
* @return TrackEDownloads
*/
public function setSessionId(int $sessionId)
public function setResourceLink(?ResourceLink $resourceLink): self
{
$this->sessionId = $sessionId;
$this->resourceLink = $resourceLink;
return $this;
}
/**
* Get sessionId.
*
* @return int
*/
public function getSessionId()
{
return $this->sessionId;
}
/**
* Get downId.
*
* @return int
*/
public function getDownId()
{
return $this->downId;
}
}

@ -35,6 +35,7 @@ use Chamilo\CoreBundle\Repository\SkillRepository;
use Chamilo\CoreBundle\Repository\SocialPostRepository;
use Chamilo\CoreBundle\Repository\SysAnnouncementRepository;
use Chamilo\CoreBundle\Repository\TagRepository;
use Chamilo\CoreBundle\Repository\TrackEDownloadsRepository;
use Chamilo\CoreBundle\Repository\TrackEExerciseRepository;
use Chamilo\CoreBundle\Repository\TrackELoginRecordRepository;
use Chamilo\CoreBundle\Serializer\UserToJsonNormalizer;
@ -574,6 +575,11 @@ class Container
return self::$container->get(TrackEExerciseRepository::class);
}
public static function getTrackEDownloadsRepository(): TrackEDownloadsRepository
{
return self::$container->get(TrackEDownloadsRepository::class);
}
public static function getWikiRepository(): CWikiRepository
{
return self::$container->get(CWikiRepository::class);

@ -0,0 +1,36 @@
<?php
declare(strict_types=1);
namespace Chamilo\CoreBundle\Migrations\Schema\V200;
use Chamilo\CoreBundle\Migrations\AbstractMigrationChamilo;
use Doctrine\DBAL\Schema\Schema;
final class Version20240114215900 extends AbstractMigrationChamilo
{
public function getDescription(): string
{
return 'Modify track_e_downloads table structure';
}
public function up(Schema $schema): void
{
$this->addSql('DROP INDEX idx_ted_c_id ON track_e_downloads;');
$this->addSql('DROP INDEX down_session_id ON track_e_downloads;');
$this->addSql('ALTER TABLE track_e_downloads ADD resource_link_id INT DEFAULT NULL, DROP c_id, DROP down_session_id;');
$this->addSql('ALTER TABLE track_e_downloads ADD CONSTRAINT FK_EEDF4DA6F004E599 FOREIGN KEY (resource_link_id) REFERENCES resource_link (id) ON DELETE SET NULL;');
$this->addSql('CREATE INDEX IDX_EEDF4DA6F004E599 ON track_e_downloads (resource_link_id);');
}
public function down(Schema $schema): void
{
$this->addSql('ALTER TABLE track_e_downloads DROP FOREIGN KEY FK_EEDF4DA6F004E599;');
$this->addSql('DROP INDEX IDX_EEDF4DA6F004E599 ON track_e_downloads;');
$this->addSql('ALTER TABLE track_e_downloads DROP resource_link_id;');
$this->addSql('ALTER TABLE track_e_downloads ADD c_id INT NOT NULL;');
$this->addSql('ALTER TABLE track_e_downloads ADD down_session_id INT DEFAULT NULL;');
$this->addSql('CREATE INDEX idx_ted_c_id ON track_e_downloads (c_id);');
$this->addSql('CREATE INDEX down_session_id ON track_e_downloads (down_session_id);');
}
}

@ -0,0 +1,39 @@
<?php
declare(strict_types=1);
/* For licensing terms, see /license.txt */
namespace Chamilo\CoreBundle\Repository;
use Chamilo\CoreBundle\Entity\ResourceLink;
use Chamilo\CoreBundle\Entity\TrackEDownloads;
use DateTime;
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
use Doctrine\Persistence\ManagerRegistry;
class TrackEDownloadsRepository extends ServiceEntityRepository
{
public function __construct(ManagerRegistry $registry)
{
parent::__construct($registry, TrackEDownloads::class);
}
public function saveDownload(int $userId, int $resourceLinkId, string $documentUrl)
{
$download = new TrackEDownloads();
$download->setDownDocPath($documentUrl);
$download->setDownUserId($userId);
$download->setDownDate(new DateTime());
$resourceLink = $this->_em->getRepository(ResourceLink::class)->find($resourceLinkId);
if ($resourceLink) {
$download->setResourceLink($resourceLink);
}
$this->_em->persist($download);
$this->_em->flush();
return $download->getDownId();
}
}
Loading…
Cancel
Save