[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
SF.net SVN: ledger-smb:[3486] trunk/LedgerSMB/DBObject/File.pm
- Subject: SF.net SVN: ledger-smb:[3486] trunk/LedgerSMB/DBObject/File.pm
- From: ..hidden..
- Date: Mon, 11 Jul 2011 08:36:18 +0000
Revision: 3486
http://ledger-smb.svn.sourceforge.net/ledger-smb/?rev=3486&view=rev
Author: einhverfr
Date: 2011-07-11 08:36:18 +0000 (Mon, 11 Jul 2011)
Log Message:
-----------
File attachment changes
Modified Paths:
--------------
trunk/LedgerSMB/DBObject/File.pm
Modified: trunk/LedgerSMB/DBObject/File.pm
===================================================================
--- trunk/LedgerSMB/DBObject/File.pm 2011-07-10 15:40:35 UTC (rev 3485)
+++ trunk/LedgerSMB/DBObject/File.pm 2011-07-11 08:36:18 UTC (rev 3486)
@@ -17,8 +17,8 @@
package LedgerSMB::DBOBject::File;
-use base qw(LedgerSMB::DBObject);
use Class::Struct;
+use LedgerSMB::DBObject;
=item attached_by_id
@@ -70,8 +70,11 @@
=item x-info
-A hash for extended information
+A hash for extended information
+Note additionally the $self hashref contains the basic required attributes for
+DBObject, namely dbh, _roles, and _locale.
+
=back
=cut
@@ -90,6 +93,7 @@
ref_key => '$',
file_class => '$',
src_class => '$',
+ dbobject => 'LedgerSMB::DBObject',
x_info => '%'
};
@@ -97,6 +101,58 @@
=over
+=item new_dbobject
+
+$file->new_dbobject({base => (LedgerSMB | LedgerSMB::Form),
+locale => LedgerSMB::Locale});
+
+Creates a new file object. Locale only needs to be specified when using
+LedgerSMB::Form objects since these are not included.
+
+Returns 0 on success.
+
+Error codes on exit (OR'd):
+
+1: No database handle included
+2: No locale handle included
+4: Invalid base.
+
+
+=cut
+
+sub new_dbobject{
+ use LedgerSMB;
+ my ($self, $args) = @_;
+ my $dbobject;
+ my $rc = 0; # Success
+ if (LedgerSMB::Form->isa($args->{base})){
+ use LedgerSMB::Locale;
+ my $lsmb = LedgerSMB->new();
+ $lsmb->merge($args->{base});
+ if (LedgerSMB::Locale->isa($args->{locale})){
+ $lsmb->{_locale} = $args->{locale};
+ my $dbobject = LedgerSMB::DBObject({base => $lsmb});
+ } else {
+ $rc | 2; # No locale
+ }
+ }
+ elsif (LedgerSMB->isa($args->{base})){
+ my $dbobject = LedgerSMB::DBObject({base => $args->{base}});
+ }
+ else {
+ $rc | 4; # Incorrect base type
+ }
+ if (!$dbobject->{dbh}){
+ $rc | 1; # No database handle
+ }
+ if ($rc){
+ return $rc; # Return error.
+ } else {
+ $self->dbobject($dbobject);
+ return 0;
+ }
+}
+
=item get
Retrives a file. ID and file_class properties must be set.
@@ -143,7 +199,35 @@
return @results;
}
+=item exec_method
+Provides a compatible interface to LedgerSMB::DBObject::exec_method
+
+=cut
+
+sub exec_method{
+ my ($self, $args) = @_;
+ if (!scalar @{$args->{args}}){
+ $self->dbobject->{attached_by_id} = $self->attached_by_id;
+ $self->dbobject->{attached_by} = $self->attached_by;
+ $self->dbobject->{attached_at} = $self->attached_at;
+ $self->dbobject->{reference} = $self->reference;
+ $self->dbobject->{content} = $self->content;
+ $self->dbobject->{mime_type_id} = $self->mime_type_id;
+ $self->dbobject->{mime_type_text} = $self->mime_type_text;
+ $self->dbobject->{file_name} = $self->file_name;
+ $self->dbobject->{description} = $self->description;
+ $self->dbobject->{id} = $self->id;
+ $self->dbobject->{ref_key} = $self->ref_key;
+ $self->dbobject->{file_class} = $self->file_class;
+ $self->dbobject->{src_class} = $self->src_class;
+ $self->dbobject->{dbobject} = $self->dbobject;
+ $self->dbobject->{x_info} = $self->x_info;
+ }
+ $self->dbobject->exec_method($args);
+
+}
+
=head1 COPYRIGHT
Copyright (C) 2011 The LedgerSMB Core Team
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.