mirror of
https://github.com/moodle/moodle.git
synced 2025-03-20 07:30:01 +01:00
portfolio MDL-16124 improved the portfolio_formats conflict resolution
This commit is contained in:
parent
29fc57afa5
commit
a1e1af19ef
@ -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() {
|
||||
|
@ -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;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user