[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

SF.net SVN: ledger-smb:[3485] trunk



Revision: 3485
          http://ledger-smb.svn.sourceforge.net/ledger-smb/?rev=3485&view=rev
Author:   einhverfr
Date:     2011-07-10 15:40:35 +0000 (Sun, 10 Jul 2011)

Log Message:
-----------
more file attachment stuff

Modified Paths:
--------------
    trunk/LedgerSMB/DBObject/File.pm
    trunk/sql/modules/Files.sql

Modified: trunk/LedgerSMB/DBObject/File.pm
===================================================================
--- trunk/LedgerSMB/DBObject/File.pm	2011-07-10 11:17:36 UTC (rev 3484)
+++ trunk/LedgerSMB/DBObject/File.pm	2011-07-10 15:40:35 UTC (rev 3485)
@@ -9,9 +9,9 @@
 This provides routines for managing file attachments.  Subclasses may be used
 to provide functionality for specific types of file attachments.
 
-=head1 METHODS
+=head1 PROPERTIES/ACCESSORS
 
-=open
+=over
 
 =cut
 
@@ -20,18 +20,130 @@
 use base qw(LedgerSMB::DBObject);
 use Class::Struct;
 
-struct LedgerSMB::DBObject::file_attachement => {
-   content => '$',
-   mime_type_id =>  '$',
-   file_name   =>  '$',
-   description =>  '$',
-   id =>  '$',
-   ref_key =>  '$',
-   file_class =>  '$',
+=item  attached_by_id
+
+Entity id of the individual who attached the file.
+
+=item attached_by
+
+Entity name of individual who attached file
+
+=item attached_at 
+
+Timestamp of attachment point.
+
+=item content
+
+This stores the binary content of the file.
+
+=item mime_type_id
+
+ID of the MIME type.  Undef if unknown.
+
+=item mime_type_text
+
+Standard text code of the MIME type
+
+=item file_name
+
+File name, user specified
+
+=item description
+
+Description, user specified
+
+=item id
+
+ID of file.  undef if unknown
+
+=item ref_key
+
+Referential key for the file to attach to.
+
+=item file_class
+
+ID of the file class.
+
+=item src_class
+
+ID of class of the original attachment point (for a link)
+
+=item x-info
+
+A hash for extended information 
+
+=back
+
+=cut
+
+struct LedgerSMB::DBObject::File => {
+   attached_by_id =>  '$',
+   attached_by    =>  '$',
+   attached_at    =>  '$',
+   reference      =>  '$',
+   content        =>  '$',
+   mime_type_id   =>  '$',
+   mime_type_text =>  '$',
+   file_name      =>  '$',
+   description    =>  '$',
+   id             =>  '$',
+   ref_key        =>  '$',
+   file_class     =>  '$',
+   src_class      =>  '$',
+   x_info         =>  '%'
 };
 
+=head1 METHODS
+
+=over
+
+=item get
+
+Retrives a file.  ID and file_class properties must be set.
+
+=cut
+
+sub get{
+    my ($self) = @_;
+    my ($ref) = $self->exec_method({funcname => 'file__get'});
+    $self->merge($ref);
+}
+
+=item list({ref_key => int, file_class => int})
+
+Lists files directly attached to the object.
+
+=cut
+
+sub list{
+    my ($self, $args) = @_;
+    my @results = $self->exec_method(
+                 {funcname => 'file__list', 
+                      args => [$args->{ref_key}, $args->{file_class}]
+                 }
+     );
+    return @results;
+}
+
+=item list_links({ref_key => int, file_class => int})
+
+Lists the links directly attached to the object.
+
 =back
 
+=cut
+
+sub list_links{
+    my ($self, $args) = @_;
+    my @results = $self->exec_method(
+                 {funcname => 'file__list_links', 
+                      args => [$args->{ref_key}, $args->{file_class}]
+                 }
+     );
+    return @results;
+}
+
+
 =head1 COPYRIGHT
 
 Copyright (C) 2011 The LedgerSMB Core Team

Modified: trunk/sql/modules/Files.sql
===================================================================
--- trunk/sql/modules/Files.sql	2011-07-10 11:17:36 UTC (rev 3484)
+++ trunk/sql/modules/Files.sql	2011-07-10 15:40:35 UTC (rev 3485)
@@ -110,14 +110,63 @@
 DROP VIEW IF EXISTS file_order_links;
 DELETE FROM file_view_catalog WHERE file_class in (1, 2);
 
-CREATE OR REPLACE view file_tx_links
+CREATE OR REPLACE view file_tx_links AS
+SELECT file_id, ref_key, gl.reference, gl.type, dest_class, src_class
+       sl.refkey as dest_ref
+  FROM file_secondary_attachment sl
+  JOIN (select id, reference, 'gl' as type
+          FROM gl
+         UNION
+        SELECT id, invnumber, case when invoice then 'is' else 'ar' end as type
+          FROM ar
+         UNION
+        SELECT id, invnumber, case when invoice then 'ir' else 'ap' end as type
+          FROM ap) gl ON sl.ref_key = gl.id and sl.src_class = 1;
 -- view of links FROM transactions
 
-CREATE OR REPLACE view file_order_links
+INSERT INTO file_view_catalog (file_class, view_name) 
+     VALUES (1, 'file_tx_links');
+
+CREATE OR REPLACE view file_order_links AS
+SELECT file_id, ref_key, oe.ornumber as reference, oc.oe_class, dest_class, 
+       src_class, sl.refkey as dest_ref
+  FROM file_secondary_attachment sl   
+  JOIN oe ON sl.ref_key = oe.id
+  JOIN order_class oc ON oe.oe_class_id = oc.id
+ WHERE sl.src_class = 2;
+       
+
 -- view of links FROM orders
 
-CREATE OR REPLACE VIEW file_links
-AS
-select * from  file_tx_links
-UNION
-select * from file_order_links;
+INSERT INTO file_view_catalog (file_class, view_name) 
+     VALUES (2, 'file_order_links');
+
+
+CREATE OR REPLACE FUNCTION file_links_vrebuild()
+RETURNS bool AS
+$$
+DECLARE 
+   viewline file_catalog%rowtype;
+   stmt text;
+BEGIN
+   stmt := '';
+   FOR viewline IN
+       select * from view_catalog
+   LOOP
+       IF stmt = '' THEN
+           stmt := 'SELECT * FROM ' || quote_ident(viewline.view_name) || '
+';
+       ELSE
+           stmt := 'UNION
+SELECT * FROM '|| quote_ident(viewline.view_name) || '
+';
+       END IF; 
+   END LOOP;
+   EXECUTE 'CREATE OR REPLACE VIEW file_links AS
+' || stmt;
+   RETURN TRUE;
+END;
+$$ LANGUAGE PLPGSQL;
+
+select * from file_links_vrebuild();
+


This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.