From 850e85b7b29b6d550a04059c11f2edd26ed595ed Mon Sep 17 00:00:00 2001 From: jamiesensei Date: Fri, 11 May 2007 22:22:14 +0000 Subject: [PATCH] some changes to make it easier to override editing icons in child classes and to make several lists work well with each other on the same page. --- lib/listlib.php | 48 ++++++++++++++++++++++++++++++------------------ 1 file changed, 30 insertions(+), 18 deletions(-) diff --git a/lib/listlib.php b/lib/listlib.php index 5d8bc55c56..edda7d2fe8 100644 --- a/lib/listlib.php +++ b/lib/listlib.php @@ -59,7 +59,7 @@ class moodle_list{ * * @var list_item or derived class */ - var $parentitem; + var $parentitem = null; var $table; var $fieldnamesparent = 'parent'; var $sortby = 'parent, sortorder, name'; @@ -380,6 +380,10 @@ class moodle_list{ * @return unknown */ function process_actions($left, $right, $moveup, $movedown){ + //should this action be processed by this list object? + if (!(array_key_exists($left, $this->records) || array_key_exists($right, $this->records) || array_key_exists($moveup, $this->records) || array_key_exists($movedown, $this->records))){ + return false; + } if (!empty($left)) { $this->move_item_left($left); } else if (!empty($right)) { @@ -425,7 +429,7 @@ class list_item{ var $item; var $fieldnamesname = 'name'; var $attributes; - var $iconhtml = ''; + var $icons = array(); /** * * @var moodle_list @@ -486,52 +490,60 @@ class list_item{ } else { $childrenhtml = ''; } - return $this->item_html($extraargs).$this->iconhtml.(($childrenhtml !='')?("\n".$childrenhtml):''); + return $this->item_html($extraargs).' '.(join($this->icons, '')).(($childrenhtml !='')?("\n".$childrenhtml):''); } function set_icon_html($first, $last, &$lastitem){ global $CFG; $strmoveup = get_string('moveup'); $strmovedown = get_string('movedown'); + $strmoveleft = get_string('maketoplevelitem', 'question'); $pixpath = $CFG->pixpath; - $icons = ' '; + $icons = array(); if (isset($this->parentlist->parentitem)) { $parentitem =& $this->parentlist->parentitem; if (isset($parentitem->parentlist->parentitem)){ $action = get_string('makechildof', 'question', $parentitem->parentlist->parentitem->name); } else { - $action = get_string('maketoplevelitem', 'question'); + $action = $strmoveleft; } - $icons .= ' - ' . $action. ' '; + $icons['left'] = $this->image_icon($action, $this->parentlist->pageurl->out_action(array('left'=>$this->id)), 'left'); } else { - $icons .= ''; + $icons['left'] = $this->image_spacer(); } if (!$first) { - $icons .= ' - ' . $strmoveup. ' '; + $icons['up'] = $this->image_icon($strmoveup, $this->parentlist->pageurl->out_action(array('up'=>$this->id)), 'up'); } else { - $icons .= ''; + $icons['up'] = $this->image_spacer(); } if (!$last) { - $icons .= ' - ' .$strmovedown. ' '; + $icons['down'] = $this->image_icon($strmovedown, $this->parentlist->pageurl->out_action(array('movedown'=>$this->id)), 'down'); } else { - $icons .= ''; + $icons['down'] = $this->image_spacer(); } if (!empty($lastitem)) { $makechildof = get_string('makechildof', 'question', $lastitem->name); - $icons .= ' - ' . $makechildof. ' '; + $icons['right'] = $this->image_icon($makechildof, $this->parentlist->pageurl->out_action(array('right'=>$this->id)), 'right'); } else { - $icons .= ''; + $icons['right'] = $this->image_spacer(); } - $this->iconhtml = $icons; + $this->icons = $icons; + } + function image_icon($action, $url, $icon){ + global $CFG; + $pixpath = $CFG->pixpath; + return ' + ' . $action. ' '; + } + function image_spacer(){ + global $CFG; + $pixpath = $CFG->pixpath; + return ''; } /** * Recurse down tree creating list_items, called from moodle_list::list_from_records -- 2.39.5