package Goo::TrailManager; ############################################################################### # Nigel Hamilton # # Copyright Nigel Hamilton 2005 # All Rights Reserved # # Author: Nigel Hamilton # Filename: Goo::TrailManager.pm # Description: Manage a Trail of Goo Actions - memex style. # # Date Change # ----------------------------------------------------------------------------- # 19/08/2005 Auto generated file # 19/08/2005 Needed a way of talking to the GooTrail database. # 20/08/2005 Added method: createDatabase # 21/08/2005 Added method: getMostRecent # 21/08/2005 Added method: getPreviousAction # 24/08/2005 Added method: getLatestActions # ############################################################################### use strict; use Goo::Action; use Goo::Loader; use Goo::Prompter; use Goo::Environment; use Goo::LiteDatabase; # 7 - keep the buffer small (thanks to miller's rule - 7 plus or minus 2) my $BUFFER_SIZE_LIMIT = 6; ############################################################################### # # reset_last_action - set the last_actionid in the trail.goo back to 0 # ############################################################################### sub reset_last_action { # the user is no longer delving into the trail Goo::ConfigFile::write_to_file("trail.goo", "last_actionid", 0); } ############################################################################### # # find_context - find the most recent goo context for the current thing # ############################################################################### sub find_context { my ($thing) = @_; # look up the goo trail for this Thing my $user = Goo::Environment::get_user(); my $filename = $thing->get_filename(); my $query = Goo::LiteDatabase::execute_sql(<is_pain() - show after the pain start # my $starting_stepid = $row->{maxstepid} - 3; my $ending_stepid = $row->{maxstepid} + 3; } ############################################################################### # # get_context - display the most recent goo context for the current thing # ############################################################################### sub get_context { my ($starting_actionid, $ending_actionid) = @_; my $query = Goo::LiteDatabase::execute_sql(<{ $row->{thing} }; $buffer_counter++; last if $buffer_counter > $buffer_max_size; #print "adding a new goo action - $row->{actionid} $row->{action} \n"; unshift(@context, Goo::Action->new($row)); $seen_thing->{ $row->{thing} } = 1; } return @context; } ############################################################################### # # create_database - save the commands for creating the database # ############################################################################### sub create_database { # each user must have their own goo trail #GooLiteDatabase::do_sql("drop table gootrail"); #GooLiteDatabase::do_sql("drop index gootrail_idx2"); # the integer primary key will automatically increment under SQLite Goo::LiteDatabase::do_sql(<new("trail.goo"); my $actionid; if ($config->{last_actionid} > 0) { # decrement the last trailid $actionid = $config->{last_actionid} - 1; } else { $actionid = get_max_actionid() - 1; } # save the details to the config file Goo::ConfigFile::write_to_file("trail.goo", "last_actionid", $actionid); return Goo::Loader::load(get_thing($actionid)); } ############################################################################### # # go_forward_one - go to the next action in the goo trail # ############################################################################### sub go_forward_one { my $config = Goo::ConfigFile->new("trail.goo"); my $actionid; if ($config->{last_actionid} > 0) { # decrement the last trailid $actionid = $config->{last_actionid} + 1; } if ($actionid > get_max_actionid()) { $actionid = get_max_actionid(); } # save the details to the config file Goo::ConfigFile::write_to_file("trail.goo", "last_actionid", $actionid); return Goo::Loader::load(get_thing($actionid)); } ############################################################################### # # get_previous_thing - return the previous action from the gootrail # ############################################################################### sub get_previous_thing { my ($thing) = @_; my $query = Goo::LiteDatabase::execute_sql(<{actionid} - 2; my @context = get_context($previous_position, $previous_position); my $previous_action = shift(@context); # Goo::Prompter::notify($previous->to_string()); return Goo::Loader::load($previous_action->get_thing()); } ############################################################################### # # get_latest_actions - return the most recent actions that have happened # ############################################################################### sub get_latest_actions { my $query = Goo::LiteDatabase::execute_sql(<{maxactionid} - 100; if ($starting_position < 1) { $starting_position = 1; } my $ending_position = $row->{maxactionid}; # print "starting position = $starting_position - $ending_position\n"; return get_context($starting_position, $ending_position); } ############################################################################### # # get_max_actionid - return the last actionid # ############################################################################### sub get_max_actionid { my $query = Goo::LiteDatabase::execute_sql(<{maxactionid}; } ############################################################################### # # get_thing - return the thing for a position in the trail # ############################################################################### sub get_thing { my ($actionid) = @_; # connect to the local SQLite DB my $query = Goo::LiteDatabase::execute_sql(<{thing}; } ############################################################################### # # save_goo_action - save a step in the goo_trail # ############################################################################### sub save_goo_action { my ($thing, $action) = @_; my $user = Goo::Environment::get_user(); # grab the filename my $filename = $thing->isa("Goo::FileThing") ? $thing->get_full_path() : $thing->get_filename(); # connect to the local SQLite DB Goo::LiteDatabase::execute_sql(< =head1 SEE ALSO