diff --git a/lib/portfolio/caller.php b/lib/portfolio/caller.php index d5026d8aed1..32ee370670a 100644 --- a/lib/portfolio/caller.php +++ b/lib/portfolio/caller.php @@ -448,24 +448,7 @@ abstract class portfolio_caller_base { if (in_array($format, $this->supportedformats)) { return; } - $formatobj = portfolio_format_object($format); - // TODO look at replacing this code with another call to - //$this->supportedformats = portfolio_most_specific_formats($this->supportedformats, $formats); - //requires testing forum, which is the only place this is implemented right now - foreach ($this->supportedformats as $key => $f) { - $f2obj = portfolio_format_object($f); - $class = get_class($f2obj); - if ($formatobj instanceof $class) { - unset($this->supportedformats[$key]); - } - if ($formatobj->conflicts($f)) { - unset($this->supportedformats[$key]); - } - if ($f2obj->conflicts($format)) { - unset($this->supportedformats[$key]); - } - } - $this->supportedformats[] = $format; + $this->supportedformats = portfolio_most_specific_formats(array($format), $this->supportedformats); } public function get_mimetype() { diff --git a/lib/portfoliolib.php b/lib/portfoliolib.php index 1dda06e2e3e..b71d9ea00f8 100644 --- a/lib/portfoliolib.php +++ b/lib/portfoliolib.php @@ -670,31 +670,44 @@ function portfolio_most_specific_formats($specificformats, $generalformats) { } else if (empty($generalformats)) { return $specificformats; } - foreach ($specificformats as $f) { + $removedformats = array(); + foreach ($specificformats as $k => $f) { // look for something less specific and remove it, ie outside of the inheritance tree of the current formats. if (!array_key_exists($f, $allformats)) { if (!portfolio_format_is_abstract($f)) { throw new portfolio_button_exception('invalidformat', 'portfolio', $f); } } + if (in_array($f, $removedformats)) { + // already been removed from the general list + debugging("skipping $f because it was already removed"); + unset($specificformats[$k]); + } require_once($CFG->libdir . '/portfolio/formats.php'); $fobj = new $allformats[$f]; foreach ($generalformats as $key => $cf) { + if (in_array($cf, $removedformats)) { + debugging("skipping $cf because it was already removed"); + continue; + } $cfclass = $allformats[$cf]; $cfobj = new $allformats[$cf]; if ($fobj instanceof $cfclass && $cfclass != get_class($fobj)) { debugging("unsetting $key $cf because it's not specific enough ($f is better)"); unset($generalformats[$key]); + $removedformats[] = $cf; continue; } // check for conflicts if ($fobj->conflicts($cf)) { debugging("unsetting $key $cf because it conflicts with $f"); unset($generalformats[$key]); + $removedformats[] = $cf; continue; } if ($cfobj->conflicts($f)) { debugging("unsetting $key $cf because it reverse-conflicts with $f"); + $removedformats[] = $cf; unset($generalformats[$key]); continue; }