Hello Julian, hello all,
I just made some modifications to the myCourses block that I wanted to share with you:
- height and width can be configured
- names are no longer truncated, instead a scrollbar is displayed if necessary
- inserted a <noscript> function: if
javascript is disabled a link to the MyMoodle page will be shown instead
feel free to adopt whatever you want for an upcoming release
there are two files which need to be changed!
all text to be inserted is marked green, text to be deleted is marked red.
first file:MOODLE_DIR/blocks/myCourses/HTML_TreeMenu-1.2.0/TreeMenu.phpheight and width can be defined within the code, if you want height to be flexible just remove that part!
code should be starting around line 618:
/**
* Returns the HTML for the menu. This method can be
* used instead of printMenu() to use the menu system
* with a template system.
*
* @access public
* @return string The HTML for the menu
*/
function toHTML()
{
static $count = 0;
$menuObj = $this->jsObjectName . '_' . ++$count;
global $CFG;
$html = "\n";
$html = '<div style="width:168px; height:250px; overflow:auto; border:solid 0px">'; $html .= '<script Xlanguage="javascript" type="text/javascript">' . "\n//<![CDATA[\n\t";
$html .= sprintf('%s = new TreeMenu("%s", "%s", "%s", "%s", %s, %s);',
$menuObj,
$this->images,
$menuObj,
$this->linkTarget,
$this->defaultClass,
$this->usePersistence ? 'true' : 'false',
$this->noTopLevelImages ? 'true' : 'false');
$html .= "\n";
/**
* Loop through subnodes
*/
if (isset($this->menu->items)) {
for ($i=0; $i<count($this->menu->items); $i++) {
$html .= $this->_nodeToHTML($this->menu->items[$i], $menuObj);
}
}
$html .= sprintf("\n\t%s.drawMenu();", $menuObj);
$html .= sprintf("\n\t%s.writeOutput();", $menuObj);
if ($this->usePersistence && $this->isDynamic) {
$html .= sprintf("\n\t%s.resetBranches();", $menuObj);
}
$enrol = get_string('enrol','block_myCourses');
$mymoodle = get_string('mymoodle','block_myCourses'); $html .= "\n// ]]>\n</script>
<noscript><center><a href=\"$CFG->wwwroot/my\">$mymoodle</a></center></noscript></div><center><a href=\"$CFG->wwwroot/course\">$enrol</a></center>";
return $html;
}
/**
* Prints a node of the menu
*
* @access private
*/
function _nodeToHTML($nodeObj, $prefix, $return = 'newNode', $currentDepth = 0, $maxDepthPrefix = null)
{
$prefix = empty($maxDepthPrefix) ? $prefix : $maxDepthPrefix;
$charLength = $CFG->block_myCourses_charLength;
$expanded = $this->isDynamic ? ($nodeObj->expanded ? 'true' : 'false') : 'true';
$isDynamic = $this->isDynamic ? ($nodeObj->isDynamic ? 'true' : 'false') : 'false';
$html = sprintf("\t %s = %s.addItem(new TreeNode('%s', %s, %s, %s, %s, '%s', '%s', %s));\n",
$return,
$prefix,
substr(str_replace("'", "\\'", $nodeObj->text),0
,35),
!empty($nodeObj->icon) ? "'" . $nodeObj->icon . "'" : 'null',
!empty($nodeObj->link) ? "'" . $nodeObj->link . "'" : 'null',
$expanded,
$isDynamic,
$nodeObj->cssClass,
$nodeObj->linkTarget,
!empty($nodeObj->expandedIcon) ? "'" . $nodeObj->expandedIcon . "'" : 'null');
foreach ($nodeObj->events as $event => $handler) {
$html .= sprintf("\t %s.setEvent('%s', '%s');\n",
$return,
$event,
str_replace(array("\r", "\n", "'"), array('\r', '\n', "\'"), $handler));
}
if ($this->maxDepth > 0 AND $currentDepth == $this->maxDepth) {
$maxDepthPrefix = $prefix;
}
second file:MOODLE_DIR/blocks/myCourses/lang/en_utf8/block_myCourses.phphere you can define what is shown, wenn javascript is disabled.
enter a new line right beneath the last string-definition:
$string['mymoodle'] = 'Show MyMoodle';
any comments welcome!
have fun,
mario