Commit 74acd9e3 authored by David Johnson's avatar David Johnson

Provide methods to get the hashes of node and node_type attributes.

parent d658ea4d
......@@ -1181,11 +1181,11 @@ sub inner_elab_role($) {
return L__reservation($_[0], 'inner_elab_role'); }
#
# Lookup a specific attribute in the node_attributes table,
# Load all attributes from the node_attributes table,
#
sub NodeAttribute($$$;$)
sub LoadNodeAttributes($)
{
my ($self, $attrkey, $pattrvalue, $pattrtype) = @_;
my ($self) = @_;
return -1
if (!ref($self));
......@@ -1207,6 +1207,27 @@ sub NodeAttribute($$$;$)
$self->{"ATTRS"}->{$key} = $row;
}
}
return 0;
}
#
# Lookup a specific attribute in the node_attributes table,
#
sub NodeAttribute($$$;$)
{
my ($self, $attrkey, $pattrvalue, $pattrtype) = @_;
return -1
if (!ref($self));
my $node_id = $self->node_id();
if (!defined($self->{"ATTRS"})) {
if ($self->LoadNodeAttributes()) {
return -1;
}
}
if (!exists($self->{"ATTRS"}->{$attrkey})) {
$$pattrvalue = undef;
......@@ -1221,6 +1242,27 @@ sub NodeAttribute($$$;$)
return 0;
}
#
# Return a hash of the node attributes for this node.
#
sub GetNodeAttributes($)
{
my ($self) = @_;
return undef
if (!ref($self));
my $node_id = $self->node_id();
if (!defined($self->{"ATTRS"})) {
if ($self->LoadNodeAttributes()) {
return undef;
}
}
return $self->{"ATTRS"};
}
#
# Return type info. We cache this in the instance since node_type stuff
# does not change much.
......@@ -1263,6 +1305,24 @@ sub NodeTypeAttribute($$$;$)
return $typeinfo->GetAttribute($attrkey, $pattrvalue, $pattrtype);
}
#
# Returns a hash of node type attributes in the nodetype info.
#
sub GetNodeTypeAttributes($)
{
my ($self) = @_;
return undef
if (!ref($self));
my $typeinfo = $self->NodeTypeInfo();
return undef
if (!defined($typeinfo));
return $typeinfo->GetAttributes();
}
#
# Shortcuts to "common" type information.
# Later these might be overriden by node attributes.
......
......@@ -279,6 +279,23 @@ sub GetAttribute($$;$$)
$$pattrvalue = undef;
return -1;
}
#
# Look for an attribute.
#
sub GetAttributes($)
{
my ($self) = @_;
return undef
if (!ref($self));
$self->LoadAttributes() == 0
or return undef;
return $self->{"ATTRS"};
}
# Shortcuts for typical attributes.
sub default_osid($;$) {return GetAttribute($_[0], "default_osid", $_[1]); }
sub default_imageid($;$){return GetAttribute($_[0], "default_imageid",$_[1]); }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment