Changeset 2094 for trunk/LATMOS-Accounts/lib/LATMOS/Accounts/Bases/Sql.pm
- Timestamp:
- 09/19/17 19:34:41 (7 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/LATMOS-Accounts/lib/LATMOS/Accounts/Bases/Sql.pm
r2083 r2094 18 18 our $VERSION = (q$Rev$ =~ /^Rev: (\d+) /)[0]; 19 19 20 sub SCHEMA_VERSION { 2 6};20 sub SCHEMA_VERSION { 28 }; 21 21 22 22 =head1 NAME … … 796 796 =head1 ATTRIBUTES FUNCTIONS 797 797 798 =cut 799 800 sub obj_attr_allowed_values { 801 my ($self, $otype, $attr) = @_; 802 if (my @values = $self->SUPER::obj_attr_allowed_values("$otype.$attr", 'allowed')) { 803 return @values; 804 } else { 805 $self->ListAttrValue($otype, $attr); 806 } 807 } 808 809 =head2 ListAttrValue($otype, $attribute) 810 811 List values allow for an attribute set into SQL database 812 813 =cut 814 815 sub ListAttrValue { 816 my ($self, $otype, $attr) = @_; 817 818 my @sqlvalues; 819 my $getAllow = $self->db->prepare_cached(q{ 820 SELECT * FROM attributes_values WHERE otype = ? AND attributes = ? 821 ORDER BY "value" 822 }); 823 $getAllow->execute($otype, $attr); 824 while (my $res = $getAllow->fetchrow_hashref) { 825 push(@sqlvalues, $res->{value}); 826 } 827 return @sqlvalues; 828 } 829 830 =head2 AddAttrValue($otype, $attr, @values) 831 832 Add given values to allowed attribute list 833 834 =cut 835 836 sub AddAttrValue { 837 my ($self, $otype, $attr, @values) = @_; 838 839 my $addAllow = $self->db->prepare_cached(q{ 840 INSERT INTO attributes_values (otype, attributes, "value") values (?,?,?) 841 }); 842 843 foreach my $value (@values) { 844 if ($addAllow->execute($otype, $attr, $value)) { 845 } else { 846 $self->rollback; 847 return; 848 } 849 } 850 851 return 1; 852 } 853 854 =head2 DelAttrValue 855 856 Delete a 857 858 =cut 859 860 sub DelAttrValue { 861 my ($self, $otype, $attr, @values) = @_; 862 863 if (@values) { 864 my $delAllow = $self->db->prepare_cached(q{ 865 DELETE FROM attributes_values WHERE otype = ? and attributes = ? and "value" = ? 866 }); 867 868 foreach my $value (@values) { 869 870 if ($delAllow->execute($otype, $attr, $value)) { 871 } else { 872 $self->rollback; 873 return; 874 } 875 876 } 877 return 1; 878 } else { 879 my $delAllow = $self->db->prepare_cached(q{ 880 DELETE FROM attributes_values WHERE otype = ? and attributes = ? 881 }); 882 if ($delAllow->execute($otype, $attr)) { 883 return 1; 884 } else { 885 $self->rollback; 886 return; 887 } 888 } 889 } 890 798 891 =head2 register_attribute ($otype, $attribute, $comment) 799 892
Note: See TracChangeset
for help on using the changeset viewer.