Diff for /loncom/interface/lonwishlist.pm between versions 1.7 and 1.8

version 1.7, 2010/08/20 10:38:41 version 1.8, 2010/08/25 12:38:45
Line 61  my %TreeToHash; Line 61  my %TreeToHash;
 my @allFolders;  my @allFolders;
 my @allNodes;  my @allNodes;
 my $indentConst = 20;  my $indentConst = 20;
   my $foldersOption;
   
 =pod  =pod
   
Line 70  my $indentConst = 20; Line 71  my $indentConst = 20;
   
 =item * &getWishlist()  =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)  =item * &putWishlist(wishlist)
Line 90  my $indentConst = 20; Line 91  my $indentConst = 20;
   
 # Read wishlist from user-data  # Read wishlist from user-data
 sub getWishlist {  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) {      foreach my $i ( keys %wishlist) {
         #File not found. This appears at the first time using the wishlist          #File not found. This appears at the first time using the wishlist
         #Create file and put 'root' into it          #Create file and put 'root' into it
        if ($i =~m/^error:No such file/) {         if ($i =~m/^error:No such file/) {
            &Apache::lonnet::logthis($i.'! Create file by putting in the "root" of the directory tree.');             &Apache::lonnet::logthis($i.'! Create file by putting in the "root" of the directory tree.');
            &Apache::lonnet::put('wishlist', {'root' => ''});             &Apache::lonnet::put('wishlist', {'root' => ''});
            %wishlist = &Apache::lonnet::dump('wishlist');             my $options = '<option value="" selected="selected">('.&mt('Top level').')</option>';
              &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) {         elsif ($i =~ /^(con_lost|error|no_such_host)/i) {
            &Apache::lonnet::logthis('ERROR while attempting to get wishlist: '.$i);             &Apache::lonnet::logthis('ERROR while attempting to get wishlist: '.$i);
Line 105  sub getWishlist { Line 110  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      # wishlist will not be loaded, instead the user will be asked to try again later
     if ((keys %wishlist) == 0) {      if ((keys %wishlist) == 0) {
         &Apache::lonnet::logthis('ERROR while attempting to get wishlist: no keys retrieved!');          &Apache::lonnet::logthis('ERROR while attempting to get wishlist: no keys retrieved!');
Line 119  sub getWishlist { Line 124  sub getWishlist {
 # Write wishlist to user-data  # Write wishlist to user-data
 sub putWishlist {  sub putWishlist {
     my $wishlist = shift;      my $wishlist = shift;
       $foldersOption = '';
       &getFoldersForOption(\@childrenRt);
       my $options = '<option value="" selected="selected">('.&mt('Top level').')</option>'.$foldersOption;
       $foldersOption = '';
       $$wishlist{'folders'} = $options;
     &Apache::lonnet::put('wishlist',$wishlist);      &Apache::lonnet::put('wishlist',$wishlist);
 }  }
   
Line 327  sub saveChanges { Line 337  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).        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)  =item * &getFoldersToArray(children)
   
      Puts all nodes that represent folders in the wishlist into an array.        Puts all nodes that represent folders in the wishlist into an array. 
Line 352  sub saveChanges { Line 357  sub saveChanges {
 # Return the names for all exiting folders in option-tags, so  # 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  # a new link or a new folder can be created in an existing folder
 my $indent = 0;  my $indent = 0;
 my $foldersOption;  
 sub getFoldersForOption {  sub getFoldersForOption {
     my $nodes = shift;      my $nodes = shift;
   
Line 373  sub getFoldersForOption { Line 377  sub getFoldersForOption {
 }  }
   
   
 sub getfoldersOption {  
    if (&getWishlist ne 'error') {  
        %TreeHash = &getWishlist();  
        $root = &Tree::HashToTree();  
        @childrenRt = $root->children();  
        &getFoldersForOption(\@childrenRt);  
        my $options = '<option value="" selected="selected">('.&mt('Top level').')</option>'.$foldersOption;  
        $foldersOption = '';  
        return $options;  
    }  
    else {  
        return '';  
    }  
 }  
   
   
 # Put all folder-nodes to an array  # Put all folder-nodes to an array
 sub getFoldersToArray {  sub getFoldersToArray {
     my $children = shift;      my $children = shift;
Line 2039  sub HashToTree { Line 2027  sub HashToTree {
         if ($key eq 'root') {          if ($key eq 'root') {
             $root = Tree->new("root");              $root = Tree->new("root");
         }          }
         else {          elsif ($key ne 'folders') {
         my @attributes = @{ $TreeHash{$key} };          my @attributes = @{ $TreeHash{$key} };
         my $tmpNode;          my $tmpNode;
             $tmpNode = Tree->new(Entry->new(title=>$attributes[0],              $tmpNode = Tree->new(Entry->new(title=>$attributes[0],

Removed from v.1.7  
changed lines
  Added in v.1.8


FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>