--- loncom/interface/lonwishlist.pm 2010/08/20 10:38:41 1.7 +++ loncom/interface/lonwishlist.pm 2010/08/25 12:38:45 1.8 @@ -1,7 +1,7 @@ # The LearningOnline Network with CAPA # Routines to control the wishlist # -# $Id: lonwishlist.pm,v 1.7 2010/08/20 10:38:41 wenzelju Exp $ +# $Id: lonwishlist.pm,v 1.8 2010/08/25 12:38:45 wenzelju Exp $ # # Copyright Michigan State University Board of Trustees # @@ -61,6 +61,7 @@ my %TreeToHash; my @allFolders; my @allNodes; my $indentConst = 20; +my $foldersOption; =pod @@ -70,7 +71,7 @@ my $indentConst = 20; =item * &getWishlist() - Get the wishlist-data via lonnet::dump() and returns the got data in a hash. + Get the wishlist-data via lonnet::getkeys() and lonnet::get() and returns the got data in a hash. =item * &putWishlist(wishlist) @@ -90,14 +91,18 @@ my $indentConst = 20; # Read wishlist from user-data sub getWishlist { - my %wishlist = &Apache::lonnet::dump('wishlist'); + my @keys = &Apache::lonnet::getkeys('wishlist'); + my %wishlist = &Apache::lonnet::get('wishlist',\@keys); foreach my $i ( keys %wishlist) { #File not found. This appears at the first time using the wishlist #Create file and put 'root' into it if ($i =~m/^error:No such file/) { &Apache::lonnet::logthis($i.'! Create file by putting in the "root" of the directory tree.'); &Apache::lonnet::put('wishlist', {'root' => ''}); - %wishlist = &Apache::lonnet::dump('wishlist'); + my $options = ''; + &Apache::lonnet::put('wishlist', {'folders' => $options}); + @keys = &Apache::lonnet::getkeys('wishlist'); + %wishlist = &Apache::lonnet::get('wishlist',\@keys); } elsif ($i =~ /^(con_lost|error|no_such_host)/i) { &Apache::lonnet::logthis('ERROR while attempting to get wishlist: '.$i); @@ -105,7 +110,7 @@ sub getWishlist { } } - # if we got no keys in hash returned by dump(), return error. + # if we got no keys in hash returned by get(), return error. # wishlist will not be loaded, instead the user will be asked to try again later if ((keys %wishlist) == 0) { &Apache::lonnet::logthis('ERROR while attempting to get wishlist: no keys retrieved!'); @@ -119,6 +124,11 @@ sub getWishlist { # Write wishlist to user-data sub putWishlist { my $wishlist = shift; + $foldersOption = ''; + &getFoldersForOption(\@childrenRt); + my $options = ''.$foldersOption; + $foldersOption = ''; + $$wishlist{'folders'} = $options; &Apache::lonnet::put('wishlist',$wishlist); } @@ -327,11 +337,6 @@ sub saveChanges { Recursive call starting with all children of the root of the tree (parameter nodes is reference to an array containing the nodes of the current level). -=item * &getfoldersOption() - - Returns the option-tag build by &getFoldersForOption(nodes). Use it to transfer this to other modules (e.g. lonmenu.pm). - - =item * &getFoldersToArray(children) Puts all nodes that represent folders in the wishlist into an array. @@ -352,7 +357,6 @@ sub saveChanges { # Return the names for all exiting folders in option-tags, so # a new link or a new folder can be created in an existing folder my $indent = 0; -my $foldersOption; sub getFoldersForOption { my $nodes = shift; @@ -373,22 +377,6 @@ sub getFoldersForOption { } -sub getfoldersOption { - if (&getWishlist ne 'error') { - %TreeHash = &getWishlist(); - $root = &Tree::HashToTree(); - @childrenRt = $root->children(); - &getFoldersForOption(\@childrenRt); - my $options = ''.$foldersOption; - $foldersOption = ''; - return $options; - } - else { - return ''; - } -} - - # Put all folder-nodes to an array sub getFoldersToArray { my $children = shift; @@ -2039,7 +2027,7 @@ sub HashToTree { if ($key eq 'root') { $root = Tree->new("root"); } - else { + elsif ($key ne 'folders') { my @attributes = @{ $TreeHash{$key} }; my $tmpNode; $tmpNode = Tree->new(Entry->new(title=>$attributes[0],