mirror of
https://github.com/moodle/moodle.git
synced 2025-08-04 16:36:37 +02:00

generated properly. Updated /mod/data/fields.php - deletion of a field now also deletes data_contents and any files associated as well. Add/update/delete fields - template now gets updates in the following cases: 1) Deletion: remove template tags for the field from all templates 2) Edit: search and replace template tags for the field in all templates 3) Add: append template tag for field into the signe and rss templates, but only if these templates are not empty. Otherwise we'd rather the user uses the automatic template generation facility, which produces better display.
69 lines
No EOL
2.8 KiB
PHP
69 lines
No EOL
2.8 KiB
PHP
<?php // $Id$
|
|
//
|
|
// This function provides automatic linking to data contents of text
|
|
// fields where these fields have autolink enabled.
|
|
//
|
|
// Original code by Williams, Stronk7, Martin D.
|
|
// Modified for data module by Vy-Shane SF.
|
|
|
|
function data_filter($courseid, $text) {
|
|
global $CFG;
|
|
|
|
static $nothingtodo;
|
|
static $contentlist;
|
|
|
|
if (!empty($nothingtodo)) { // We've been here in this page already
|
|
return $text;
|
|
}
|
|
|
|
// if we don't have a courseid, we can't run the query, so
|
|
if (empty($courseid)) {
|
|
return $text;
|
|
}
|
|
|
|
// Create a list of all the resources to search for. It may be cached already.
|
|
if (empty($contentlist)) {
|
|
// We look for text field contents only, and only if the field has
|
|
// autolink enabled (param1).
|
|
$sql = 'SELECT DISTINCT(dc.id) AS contentid, ' .
|
|
'dr.id AS recordid, ' .
|
|
'dc.content AS content, ' .
|
|
'd.id AS dataid ' .
|
|
'FROM data AS d, ' .
|
|
'data_fields AS df, ' .
|
|
'data_records AS dr, ' .
|
|
'data_content AS dc ' .
|
|
"WHERE d.course = '$courseid' " .
|
|
'AND d.id = df.dataid ' .
|
|
'AND df.id = dc.fieldid ' .
|
|
'AND d.id = dr.dataid ' .
|
|
'AND dr.id = dc.recordid ' .
|
|
"AND df.type = 'text' " .
|
|
'AND df.param1 = 1';
|
|
|
|
if (!$datacontents = recordset_to_array(get_recordset_sql($sql))) {
|
|
return $text;
|
|
}
|
|
|
|
$contentlist = array();
|
|
|
|
foreach ($datacontents as $datacontent) {
|
|
$currentcontent = trim($datacontent->content);
|
|
$strippedcontent = strip_tags($currentcontent);
|
|
|
|
if (!empty($strippedcontent)) {
|
|
$contentlist[] = new filterobject(
|
|
$currentcontent,
|
|
'<a class="data autolink" title="'.
|
|
$strippedcontent.'" href="'.
|
|
$CFG->wwwroot.'/mod/data/view.php?d='. $datacontent->dataid .
|
|
'&rid='. $datacontent->recordid .'" target="'.
|
|
$CFG->framename.'">',
|
|
'</a>', false, true);
|
|
}
|
|
} // End foreach
|
|
}
|
|
return filter_phrases($text, $contentlist); // Look for all these links in the text
|
|
}
|
|
|
|
?>
|