I've got a block of code and I've got an expression I need to add into that block of code as a function but I am not sure how to do it. My PHP skills are a little limited.
I need to add logic to the code to include the following as a constant in the block. So everytime a user adds that block to a screen or sees the block it will contain this logic. The link is the same every time except for the $course->id part which is pulling the course id from the database for the particular course the link is in at the time it is clicked on.
<?php
echo '<a href="http://reports.myschool?courseid='.$course->id.'">Your link text</a>';
?>
I am pasting below the code for the main block file. Can you help me figure out how to add in the link above so it will be present in the block each time it is added to a course?
The block also has the ability to dynamically add links but I want this one to be in there no matter what and then to reference the courseid number for the course it is attached to and go to that URL.
Thanks so much!!
class block_test extends block_list {
function init() {
$this->title = get_string('blockname', 'block_test');
$this->version = 2006053000;
}
function get_content() {
if ($this->content !== NULL) {
return $this->content;
}
$this->content = new stdClass;
$this->content->items = array();
$this->content->icons = array();
$this->content->footer = '';
$rs = get_records('block_test');
if (!is_array($rs)) {
$rs = array();
}
$rs = stripslashes_safe($rs);
foreach ($rs as $link) {
$temp = 'allow_' . $link->id;
if (isset($this->config->$temp)) {
if ($this->config->$temp == 1) {
$this->add_link($link);
}
} else if ($link->defaultshow == 1) {
$this->add_link($link);
}
}
return $this->content;
}
function add_link($link) {
global $CFG;
$target = !empty($CFG->block_test_window) ? ' target="_blank"' : '';
$this->content->items[] = '<a href="' . $link->url . '"' . $target . '>'. $link->linktext . '</a><br /><em>' .$link->notes . '</em>';
$this->content->icons[] = '<img src="' . $CFG->pixpath . '/f/web.gif" height="16" width="16" alt="" />';
}
function instance_allow_config() {
return true;
}
function has_config() {
return true;
}
}
?>
Mod Note: Please use [noparse]
[/noparse] tags around PHP code.