Skip to content

Commit

Permalink
portfolio MDL-16124 improved the portfolio_formats conflict resolution
Browse files Browse the repository at this point in the history
  • Loading branch information
Penny Leach committed Mar 21, 2010
1 parent 29fc57a commit a1e1af1
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 19 deletions.
19 changes: 1 addition & 18 deletions lib/portfolio/caller.php
Expand Up @@ -448,24 +448,7 @@ protected function add_format($format) {
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() {
Expand Down
15 changes: 14 additions & 1 deletion lib/portfoliolib.php
Expand Up @@ -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;
}
Expand Down

0 comments on commit a1e1af1

Please sign in to comment.