return $ret;
}
-// a helper for expandInheritance()
+// a helper for getTrailExpansion()
function traceTrail ($tree, $trail)
{
// For each tag find its path from the root, then combine items
return $ret;
}
+// Minimize the trail: exclude all implicit tags and return the resulting trail.
+function getExplicitTagsOnly ($trail, $tree = NULL)
+{
+ if ($tree === NULL)
+ $tree = getTagTree();
+ $ret = array();
+ foreach ($tree as $taginfo)
+ {
+ if (isset ($taginfo['kids']))
+ {
+ $harvest = getExplicitTagsOnly ($trail, $taginfo['kids']);
+ if (count ($harvest) > 0)
+ {
+ $ret = array_merge ($ret, $harvest);
+ continue;
+ }
+ }
+ // This tag isn't implicit, test is for being explicit.
+ foreach ($trail as $testtag)
+ if ($taginfo['id'] == $testtag['id'])
+ {
+ $ret[] = $testtag;
+ break;
+ }
+ }
+ return $ret;
+}
+
function loadRackObjectAutoTags()
{
assertUIntArg ('object_id');
return $ret;
}
+// Build a tag trail from supplied tag id list and return it.
+function buildTrailFromIds ($tagidlist)
+{
+ $taglist = getTagList();
+ $ret = array();
+ foreach ($tagidlist as $tag_id)
+ if (isset ($taglist[$tag_id]))
+ $ret[] = $taglist[$tag_id];
+ return $ret;
+}
+
?>
global $root, $pageno, $tabno, $explicit_tags, $implicit_tags;
assertUIntArg ('object_id');
$object_id = $_REQUEST['object_id'];
- return "${root}?page=${pageno}&tab=${tabno}&object_id=${object_id}&message=" . urlencode ('This is a dummy message.');
- // FIXME: build a trail from the submitted data, minimize it;
- // then find and handle any differences between the result
- // and current explicit tag set (or wipe existing records and
- // store the whole new set instead).
- $nchanges = 0;
- foreach ($_REQUEST['taglist'] as $tag_id)
+ // Build a trail from the submitted data, minimize it,
+ // then wipe existing records and store the new set instead.
+ useDeleteBlade ('RackObjectTags', 'object_id', $object_id);
+ $newtrail = getExplicitTagsOnly (buildTrailFromIds ($_REQUEST['taglist']));
+ $n_succeeds = $n_errors = 0;
+ foreach ($newtrail as $taginfo)
{
-// if (tagOnTrail ($explicit
+ if (useInsertBlade ('RackObjectTags', array ('object_id' => $object_id, 'tag_id' => $taginfo['id'])))
+ $n_succeeds++;
+ else
+ $n_errors++;
}
+ if ($n_errors)
+ return "${root}?page=${pageno}&tab=${tabno}&object_id=${object_id}&error=" . urlencode ("Replaced trail with ${n_succeeds} tags, but experienced ${n_errors} errors.");
+ else
+ return "${root}?page=${pageno}&tab=${tabno}&object_id=${object_id}&message=" . urlencode ("New trail is ${n_succeeds} tags long");
}
?>