Good morning. My intention with my code is to send you a list of hyperlinks to download to a user. The idea is to change the background of the hyperlink when a person clicks and is marked (either with the font color changed or the link has a different background color). The conditions of the if are irrelevant (they are what I put in my code) and the only line that is below each one, leaves me the variable $ data- > link as a clickable link. So far everything is normal, but I need $ data- > link to be a clickable link with the features I mentioned.
<?php
if ($fd->componente == 'mod_resource'){
$data->link= preg_replace('!(((f|ht)tp(s)?://)[-a-zA-Zа-яА-Я()0-9@:%_+.~#?&;//=]+)!i','<a href="$1" target="_blank">$1</a>',"$CFG->wwwroot/mod/resource/view.php?id=".$fd->idmodulocurso);
}
else if ($fd->componente == 'mod_folder'){
$data->link= preg_replace('!(((f|ht)tp(s)?://)[-a-zA-Zа-яА-Я()0-9@:%_+.~#?&;//=]+)!i', '<a href="$1" target="_blank">$1</a>', "$CFG->wwwroot/pluginfile.php/". $fd->idcontexto . "/mod_folder/content/0/". rawurlencode($fd->nombrearchivo)) ;
}
?>
All this is in the context of a code page, I leave it to you if it helps to understand the context (a query in moodle format to a database)
<?php
require (dirname(dirname(__FILE__)) . '/config.php');
global $DB;
global $DB;
$query = "SELECT f.id AS id,
c.fullname AS nombrecurso,
c.shortname AS nombrecortocurso,
cx.contextlevel AS nivelcontexto,
f.contextid AS idcontexto,
f.filename AS nombrearchivo,
f.component AS componente,
cm.course AS idcurso,
cm.id AS idmodulocurso
FROM {files} f
INNER JOIN {context} cx ON (f.contextid = cx.id)
INNER JOIN {course_modules} cm ON (cx.instanceid=cm.id)
INNER JOIN {course} c ON (cm.course=c.id) AND f.filename <> ? AND f.component <> ? AND f.timecreated > ?";
$files_data=$DB->get_records_sql($query,array('.','user','0'));
$table = new html_table();
$table->head = array('File_name','Course_name','Link');
foreach ($files_data as $fd) {
$data = new stdClass();
$data->nombre = $fd->nombrearchivo;
$data->nombrecurso = $fd->nombrecurso;
if ($fd->componente == 'mod_resource'){
$data->link= preg_replace('!(((f|ht)tp(s)?://)[-a-zA-Zа-яА-Я()0-9@:%_+.~#?&;//=]+)!i', '<a href="$1" target="_blank">$1</a>', "$CFG->wwwroot/mod/resource/view.php?id=".$fd->idmodulocurso);
}
else if ($fd->componente == 'mod_folder'){
$data->link= preg_replace('!(((f|ht)tp(s)?://)[-a-zA-Zа-яА-Я()0-9@:%_+.~#?&;//=]+)!i', '<a href="$1" target="_blank">$1</a>', "$CFG->wwwroot/pluginfile.php/". $fd->idcontexto . "/mod_folder/content/0/". rawurlencode($fd->nombrearchivo)) ;
}
$table->data[] = array($data->nombre, $data->nombrecurso,$data->link);
}
echo html_writer::table($table);
?>