Tracking: Fix query on track_e_download and make track_e_download.down_doc_path nullable - refs #4861

pull/5101/head
Yannick Warnier 2 years ago
parent 72291d348e
commit b0ae2ecdc9
  1. 26
      public/main/inc/lib/tracking.lib.php
  2. 13
      public/main/tracking/course_log_tools.php
  3. 2
      src/CoreBundle/Entity/TrackEDownloads.php
  4. 26
      src/CoreBundle/Migrations/Schema/V200/Version20240119173000.php

@ -4491,19 +4491,27 @@ class Tracking
$data = [];
$TABLETRACK_DOWNLOADS = Database::get_main_table(TABLE_STATISTIC_TRACK_E_DOWNLOADS);
$tableResourceLink = Database::get_main_table('resource_link');
$tableResourceNode = Database::get_main_table('resource_node');
$condition_session = '';
$session_id = intval($session_id);
if (!empty($session_id)) {
$condition_session = ' AND session_id = '.$session_id;
}
$sql = "SELECT
down_doc_path,
COUNT(DISTINCT down_user_id),
COUNT(down_doc_path) as count_down
FROM $TABLETRACK_DOWNLOADS
WHERE c_id = $courseId
$condition_session = ' AND l.session_id = '.$session_id;
}
$sql = "SELECT t.resource_link_id as lid,
n.path as npath,
n.title as ntitle,
n.uuid as uuid,
n.id as nid,
COUNT(t.down_id) as count_down
FROM $TABLETRACK_DOWNLOADS t
INNER JOIN $tableResourceLink l
ON t.resource_link_id = l.id
INNER JOIN $tableResourceNode n
ON l.resource_node_id = n.id
WHERE l.c_id = $courseId
$condition_session
GROUP BY down_doc_path
GROUP BY nid
ORDER BY count_down DESC
LIMIT 0, $limit";
$rs = Database::query($sql);

@ -389,20 +389,23 @@ if ($documentReporting) {
if (!empty($documents_most_downloaded)) {
foreach ($documents_most_downloaded as $row) {
///* @var CDocument $document */
//$document = Container::getDocumentRepository()->findOneBy(['resourceNode' => $row['nid']]);
// Only show path to documents tool for now.
//$viewLink = api_get_path(WEB_PATH).'resources/document/'.$course->getResourceNode()->getId().'/show?'.$course_path_params.'&id=/api/documents/'.$document->getIid();
$viewLink = api_get_path(WEB_PATH).'resources/document/'.$course->getResourceNode()->getId().'/show?'.$course_path_params;
echo '<tr>
<td>';
echo Display::url(
$row['down_doc_path'],
api_get_path(
WEB_CODE_PATH
).'document/show_content.php?file='.$row['down_doc_path'].$course_path_params
$row['ntitle'],
$viewLink
);
echo '</td>
<td align="right">'.$row['count_down'].' '.get_lang('clicks').'</td>
</tr>';
if ($export_csv) {
$temp = [
$row['down_doc_path'],
$row['npath'],
$row['count_down'].' '.get_lang('clicks', ''),
];
$csv_content[] = $temp;

@ -29,7 +29,7 @@ class TrackEDownloads
#[ORM\Column(name: 'down_date', type: 'datetime', nullable: false)]
protected DateTime $downDate;
#[ORM\Column(name: 'down_doc_path', type: 'string', length: 255, nullable: false)]
#[ORM\Column(name: 'down_doc_path', type: 'string', length: 255, nullable: true)]
protected string $downDocPath;
#[ORM\ManyToOne(targetEntity: ResourceLink::class, cascade: ['persist', 'remove'])]

@ -0,0 +1,26 @@
<?php
declare(strict_types=1);
namespace Chamilo\CoreBundle\Migrations\Schema\V200;
use Chamilo\CoreBundle\Migrations\AbstractMigrationChamilo;
use Doctrine\DBAL\Schema\Schema;
final class Version20240119173000 extends AbstractMigrationChamilo
{
public function getDescription(): string
{
return 'Modify track_e_downloads table structure - make down_doc_path nullable';
}
public function up(Schema $schema): void
{
$this->addSql('ALTER TABLE track_e_downloads CHANGE COLUMN down_doc_path down_doc_path varchar(255) DEFAULT NULL');
}
public function down(Schema $schema): void
{
$this->addSql('ALTER TABLE track_e_downloads CHANGE COLUMN down_doc_path down_doc_path varchar(255) NOT NULL');
}
}
Loading…
Cancel
Save