diff --git a/public/main/inc/lib/tracking.lib.php b/public/main/inc/lib/tracking.lib.php index 32c28603f9..e17fa823e1 100644 --- a/public/main/inc/lib/tracking.lib.php +++ b/public/main/inc/lib/tracking.lib.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); diff --git a/public/main/tracking/course_log_tools.php b/public/main/tracking/course_log_tools.php index 6cf1da3256..79761f1eb9 100644 --- a/public/main/tracking/course_log_tools.php +++ b/public/main/tracking/course_log_tools.php @@ -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 ' '; 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 ' '.$row['count_down'].' '.get_lang('clicks').' '; if ($export_csv) { $temp = [ - $row['down_doc_path'], + $row['npath'], $row['count_down'].' '.get_lang('clicks', ''), ]; $csv_content[] = $temp; diff --git a/src/CoreBundle/Entity/TrackEDownloads.php b/src/CoreBundle/Entity/TrackEDownloads.php index 1b217d1cd2..80f81863f7 100644 --- a/src/CoreBundle/Entity/TrackEDownloads.php +++ b/src/CoreBundle/Entity/TrackEDownloads.php @@ -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'])] diff --git a/src/CoreBundle/Migrations/Schema/V200/Version20240119173000.php b/src/CoreBundle/Migrations/Schema/V200/Version20240119173000.php new file mode 100644 index 0000000000..2ff0830bcb --- /dev/null +++ b/src/CoreBundle/Migrations/Schema/V200/Version20240119173000.php @@ -0,0 +1,26 @@ +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'); + } +}