gpt4 book ai didi

javascript - 根据类(class)自定义字段在类(class)页面上添加链接

转载 作者:行者123 更新时间:2023-11-29 11:36:35 25 4
gpt4 key购买 nike

我使用的是Moodle 2.7,并且数据库表mdl_course_info_field中的类(class)具有以下自定义字段 :

Full name: School course

Shrot name: school

Type: Menu of choices

Choices:

  • Highschool course

  • Prepschool course

目标是在每个类(class)页面上显示链接,其中在设置下使用高中类(class)复选框。在文件mymoodle/local/link/functions.js中有链接:

if($('#page-course-view-topcollmytheme .orangebar p')) {
$('#page-course-view-topcollmytheme #section-0 .content > .summary').append('<button class="highschoollink">Hig school course</button>');
}

如何检查如果复选框被选中以在类(class)页面上显示链接?

最佳答案

您可以使用渲染器来显示类(class)标题:

https://tracker.moodle.org/browse/MDL-36048

因此您可以在类(class)标题中包含学校链接 - 这是一个示例:

/course/format/formatname/lib.php

将此函数添加到类format_formatname

/**
* Display's a header at the top of the sections.
*
* @return renderable class
*/
public function course_content_header() {
global $DB, $PAGE, $USER;

if (!isset($PAGE)) {
return null;
}

// Only display if we are on the course-view page.
if (strpos($PAGE->pagetype, 'course-view-') !== 0) {
return null;
}

$sql = "SELECT d.data
FROM {course_info_field} f
JOIN {course_info_data} d ON d.fieldid = f.id AND d.courseid = :courseid
WHERE f.shortname = :shortname";
$params = array('courseid' => $this->courseid, 'shortname' => 'school');
$schoolname = $DB->get_field_sql($sql, $params);
$schoolurl = '';
// You should store the school url in the database somewhere.
// Using switch code for this example.
switch ($schoolname) {
case 'high school' :
$schoolurl = new moodle_url('http://www.schoolsite.com');
break;
...
}

return new format_formatname_coursecontentheader($schoolname, $schoolurl);
}

还将此类添加到/course/format/formatname/lib.php

class format_formatname_coursecontentheader implements renderable {
/**
* School name
*
* @var string $schoolname
*/
public $schoolname;

/**
* School url
*
* @var string $schoolurl
*/
public $schoolurl;

/**
* Class storing information to be passed and displayed in the course content header
*
* @param string $schoolname
* @param moodle_url $schoolurl
*/
public function __construct($schoolname, $schoolurl) {
$this->schoolname = $schoolname;
$this->schoolurl = $fields->schoolurl;
}
}

然后在/course/format/formatname/renderer.php

将此函数添加到类format_formatname_renderer

/**
* Renders course header
*
* @param renderable $courseheader
* @return string
*/
public function render_format_formatname_coursecontentheader($courseheader) {
$output = '';

$schoolname = $courseheader->schoolname;
$schoolurl = $courseheader->schoolurl;

$link = html_writer::link($schoolurl, $schoolname);

$output .= html_writer::div($link, 'format-formatname-schoollink');

return $output;
}

关于javascript - 根据类(class)自定义字段在类(class)页面上添加链接,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36483417/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com