summaryrefslogtreecommitdiff
path: root/LedgerSMB/DBObject/Menu.pm
blob: 48bff47917f93d94e7cb4fcda0bf3fccbfa11503 (plain)
  1. =head1 NAME
  2. LedgerSMB::Menu: Menu Handling Back-end Routines for LedgerSMB
  3. =head1 SYNOPSIS
  4. Provides the functions for generating the data structures for the LedgerSMB
  5. menu.
  6. =head1 COPYRIGHT
  7. Copyright (c) 2007 The LedgerSMB Core Team. Licensed under the GNU General
  8. Public License version 2 or at your option any later version. Please see the
  9. included COPYRIGHT and LICENSE files for more information.
  10. =cut
  11. package LedgerSMB::DBObject::Menu;
  12. use Config::Std;
  13. use base(qw(LedgerSMB::DBObject));
  14. 1;
  15. =head1 METHODS
  16. =over
  17. =item LedgerSMB::Menu->new()
  18. Inherited from LedgerSMB::DBObject. Please see that documnetation for details.
  19. =item $menu->generate()
  20. This function returns a list of menu items. Each list item is a hashref:
  21. keys %menu_item would return the equivalent of qw(position id level label path
  22. args). Returns the complete list and sets $menu->{menu_items} to a referene to
  23. th result set, This function does not return an entry for the top-level menu.
  24. =cut
  25. sub generate {
  26. my ($self) = shift @_;
  27. @{$self->{menu_items}} = $self->exec_method(funcname => 'menu_generate');
  28. $self->__generate;
  29. return @{$self->{menu_items}};
  30. }
  31. =over
  32. =item Menu::generate_secton($object)
  33. This class acts like Menu::Generate except it returns only a cross-section of
  34. the menu. Basically it returns all nodes which are direct children below
  35. $object->{parent_id}.
  36. =cut
  37. sub generate_section {
  38. my ($self) = shift @_;
  39. @{$self->{menu_items}} = $self->exec_method(funcname => 'menu_children');
  40. $self->__generate;
  41. return @{$self->{menu_items}};
  42. }
  43. # Private method which contains logic common to the full menu and section logic
  44. sub __generate {
  45. my ($self) = @_;
  46. $self->debug({file => '/tmp/menu'});
  47. my @args;
  48. shift @{$self->{menu_items}};
  49. for my $attribute (@{$self->{menu_items}}){
  50. @args = $self->_parse_array($attribute->{args});
  51. delete $attribute->{args};
  52. @{$attribute->{args}} = @args;
  53. for (@{$attribute->{args}}){
  54. if ($_ =~ /(module|menu|action)=/){
  55. @elems = split(/=/, $_);
  56. print STDERR join(','. @elems) . "\n";
  57. $attribute->{$elems[0]} = $elems[1];
  58. }
  59. }
  60. }
  61. }