Liz::MiniSum - Allow for a minimal ``Systeem voor Uren Management''
use Liz::MiniSum;
$file = new Liz::MiniSum;
#!/usr/local/bin/perl
use Liz::MiniSum;
The Liz::MiniSum package allows for very simple storage of sets of records related to hours worked by people for projects.
The Liz::MiniSum module itself works best when incorporated into a client module because it moves the responsibility of aquiring a connection to a database to the client module and it allows any customisation to take place transparently to the developer.
Take for example the MiniSum method of HN.pm module:
sub MiniSum {
# Obtain the parameters # Start the file using the $hn handle as the database handle # Return the finished object
my( $hn,$token ) = @_; my( $minisum ) = Liz::MiniSum->new( $token,$hn ); $minisum; }
Because of the above code in HN.pm, it is now possible to write the following code:
$hn = new HN; $minisum = $hn->MiniSum( 'technology' );
Note that the database connection of the file is hidden in the creation of
the $hn object.
The following methods can be called without an object specification, but as a class method such as Liz::MiniSum->method().
Return list of file identification names of all minisums in the database specified. Usually not called by itself, but rather incorporated inside a Client Module.
1 Liz::SQL compatible handle or reference to routine that performs connect (default: &Connect from caller's namespace) 2 wildcard specification to match (default: all)
1 reference to list of identification names in the current database 2 reference to hash with full names
$hn = new HN;
($id,$name) = $hn->MiniSums;
$minisums = @{$id};
print "All $minisums minisums in Hospitality Net:\n";
foreach( @{$id} ) {
print " MiniSum '$$name{$_}' ($_)\n";
}
In HN.pm:
sub MiniSums { Liz::MiniSum->minisums( @_ ) }
Create a new Liz::MiniSum object. Creates connection or re-establishes connection with the MySQL database. Usually not called by itself, but rather incorporated inside a Client Module.
1 Liz::SQL compatible handle or reference to routine that performs connect (default: &Connect from caller's namespace) 2 identification name of the minisum (default: default file set for database)
1 instantiated object 2 flag whether MiniSum was just created
$hn = new HN; $minisum = $hn->MiniSum( 'technology' );
In HN.pm:
sub MiniSum { Liz::MiniSum->new( @_ ) }
Delete all tables of the MiniSum object. Please use this with caution, as it will destroy any information that is stored for this MiniSum. If called in a void context, no tables exist for this MiniSum anymore, and any references in the NextID table are also removed. Otherwise, the tables will be re-created automatically and a new object will be returned, just as if the new method was called.
1 newly created MiniSum object, current object will not work anymore
$minisum->reset;
$minisum = $minisum->reset;
The following methods allow changes to information that is associated with an entire minisum.
Specify or return the current name of the minisum object. The name can be anything to further identify the goal of the minisum.
1 new name of minisum (default: no change)
1 current/old name of minisum
$xxlink = new xxLINK; $minisum = $xxlink->MiniSum( 'eurest' ); $minisum->Name( 'Eurestjes' );
Update a field to the same value in a number of records, specified by a list of ID's.
1 field to set values of
2 new value to set
(default: empty)
3..N ID's of records in which to change the field
$minisum->UpdateFieldInIDs( 'contact','baas',@ID );
The following methods allow changes to a single record in a MiniSum.
Delete a specific Liz::MiniSum::Record object from the database.
1..N identifiers of the Liz::MiniSum::Record to be deleted
1 flag: whether action was successful
$record->delete;
Create a new Liz::MiniSum::Record object, either from existing information or for a new entry. For more documentation, see the Liz::MiniSum::Record object itself.
1 ID to create Record object with (default: none = new record)
1 instantiated Record object
$hn = new HN; $minisum = $hn->MiniSum( 'technology' );
$record = $minisum->Record; $record = $minisum->Record( $ID );
The following methods return SQL result handles or lists of information with regards to the Records in the MiniSum.
Return an SQL statement handle for a generic list of records.
The following fields may be specified with the first input parameter:
ID The ID of the record
created Timestamp value when this record was created
updated Timestamp when the record was last updated
status Status of the record
doneon Timestamp when the record is to be expired
doneby The name of the person performing the work
client The name of the client for whom the work was done
contact The name of the contact person
project The name of the project
subproject The name of the subproject
minutes How many minutes that were spent on the work
invoice Invoice information of this record
done Description of what was done
1 fields to return (comma delimited) (default: 'ID,status,doneon,doneby,client,contact,project,subproject,minutes,invoice,done,updated,created' ); 2 fieldname on which to order the result (default: 'doneon DESC,updated DESC') 3 extra condition to be applied (default: none)
1 SQL statement handle (on which method "fetchrow" can be applied)
Return an SQL statement handle for a list of records for a DoneBy.
1 DoneBy for which to return the list
(default: $ENV{'REMOTE_USER'})
2 fields to be returned (see 1st parameter of L<List>)
(default: 'ID,status,doneon,client,contact,project,subproject,minutes,invoice,done,updated,created';
3 fieldname on which to order the result
(default: 'created DESC')
4 extra condition to be applied
(default: status<>255)
5 which records to return (LIMIT specification)
(default: first 20)
1 SQL statement handle (on which method "fetchrow" can be applied)
Return a list of the clients that are currently known.
1 additional condition to be used
(default: none)
1..N Clients available
foreach ($minisum->Clients) {
print "$_\n";
}
Return a list of the contacts that are currently known for a client.
1 client for which to return the contacts
(default: all)
2 additional condition to be used
(default: none)
1..N Contacts available
foreach ($minisum->Contacts) {
print "$_\n";
}
Return a list of the donebys that are currently known.
1 additional condition to be used
(default: none)
1..N DoneBys available
foreach ($minisum->DoneBys) {
print "$_\n";
}
Return a list of the projects that are currently known for a client.
1 client for which to return the projects
(default: all)
2 additional condition to be used
(default: none)
1..N Projects available
foreach ($minisum->Projects) {
print "$_\n";
}
Return a list and a hash that contain all the different combinations of Project and SubProject for a Client.
1 client for which to obtain projects/subprojects 2 extra SQL condition to be applied (default: none)
1 reference to list with project names 2 reference to hash (keyed to project name) with references to lists of subproject names
($projects,$subprojects) = $minisum->ProjectsSubprojects;
foreach $project (@{$projects}) {
print "$project:\n";
foreach (@{$subproject->{$project}}) {
print " $_\n";
}
}
Return a list of the subprojects that are currently known.
1 client name for which to obtain subprojects
(default: all clients)
2 additional condition to be used
(default: none)
1..N SubProjects available
foreach ($minisum->SubProjects) {
print "$_\n";
}
The following methods are related to the summation of data.
Return the number of minutes that one or more persons have worked. Defaults to the number of minutes for today for the current user.
1 date for which to obtain the number of minutes, in format YYYMMDD
(default: today)
2 doneby for which to obtain the number of minutes
(default: $ENV{'REMOTE_USER'}
1 number of minutes
$minutes = $minisum->DateDoneBy2Minutes;
$minutes = $minisum->DateDoneBy2Minutes( $date,$doneby );
Convert a number of minutes to displayeable text. Can also be called as a subroutine.
1 minutes for which to create a text
1 displayable text in format HH:MM
print $minisum->Minutes2Text( $minutes );
The following methods are related to the caching of client, project and subproject combinations.
Initialize the cache of Contacts for all clients or a single client. This
effectively deletes (all|the) cached table(s) and recreates
those for the (now existing) client(s).
1..N clients for which to initialize contacts cache
(default: all)
$minisum->InitContactscCache( @client );
$minisum->InitContactscCache;
Initialize the cache of Projects and Subprojects for all clients. This efectively deletes all cached tables and recreates those for the now existing clients.
1..N clients for which to initialize cache
(default: all)
$minisum->InitProjectsSubprojectscCache( @client );
$minisum->InitProjectsSubprojectscCache;
Elizabeth Mattijsen ( lizperl@INC.nl )
(C) 1998-1999 International Network Consultants
Added extra unlink in internal subroutine InitCache to make sure files do not exist, which would cause INSERT INTO OUTFILE to fail.
Put module name between quotes to fix obscure bug in Perl 5.005x under ModPerl in method Record.
Adapted internal subroutine InitCache so that the table being read from is also locked. This should speed up things quite a bit.
Changed the default of number of records returned by ListByDoneBy back to 20 from 50.
Fixed problem in DateDoneBy2Minutes which would include deleted records.
Added subroutine/method Minutes2Text to create displayeable time format.
Added method DateDoneBy2Minutes which returns the number of minutes someone has worked on a day.
Removed method Import as the notion of importing records has been removed from the MiniSum.
Adapted methods InitContactsCache and InitProjectsSubprojectsCache and internal subroutine InitCache to accept a list of clients for which to initialize the cache, instead of just a singe client.
Adapted internal subroutine InitCache so that it will keep the old tables as much and as long as possible, so that initialization of the tables can be done during operation without too much interference.
Adapted method Contacts to use the new cache feature.
Added internal subroutine DistinctByClientCache which allows transparent searching in a cached table when available.
Added new InitContactsCache method for creating a cache of distinct contacts with a client.
Adapted method InitProjectsSubprojectsCache to use the new internal InitCache subroutine.
Added internal subroutine InitCache to create a cache of distinct
field(s) for each client.
Changed the default sort order of ListByDoneBy to 'created DESC'.
Adapted method ProjectsSubprojects so that the cache is used if no condition is specified.
Added method InitProjectsSubprojectsCache which pre-figures out which project and subproject combinations a/each client has.
Changed the default of number of records returned by ListByDoneBy from 20 to 50.
Replaced method ListDistinctProjectSubproject by method ProjectsSubprojects, which returns a much handier format, namely a reference to a list and a reference to a hash.
Changed the default condition of ListByDoneBy.
Added method ListDistinctProjectSubproject.
Changed methods Contacts, Projects and SubProjects so that the first parameter is the client for which to obtain the list of values.
Created new internal subroutine DistinctByClient that returns all distinct values of a field for a particular client.
Adapted method ListByDoneBy to limit number of records returned to a maximum of 20 (by default).
Adapted method delete so that it no longer deletes, but only sets the status to 255.
Added methods Import and UpdateFieldInIDs.
First version of this true Perl module.