]> wagnertech.de Git - kivitendo-erp.git/blobdiff - SL/Controller/Helper/GetModels.pm
PriceRule: Waren auch im Einkauf zulassen.
[kivitendo-erp.git] / SL / Controller / Helper / GetModels.pm
index 143e5fe6fd8723c73381f5fa7dab21311ea57116..52ded48f3c827b4837c997c12f6480ac5dfba605 100644 (file)
@@ -11,7 +11,7 @@ use Scalar::Util qw(weaken);
 
 use Rose::Object::MakeMethods::Generic (
   scalar => [ qw(controller model query with_objects filtered sorted paginated finalized final_params) ],
 
 use Rose::Object::MakeMethods::Generic (
   scalar => [ qw(controller model query with_objects filtered sorted paginated finalized final_params) ],
-  'scalar --get_set_init' => [ qw(handlers source) ],
+  'scalar --get_set_init' => [ qw(handlers source additional_url_params) ],
   array => [ qw(plugins) ],
 );
 
   array => [ qw(plugins) ],
 );
 
@@ -27,6 +27,13 @@ sub get {
   return $self->manager->get_all(%params);
 }
 
   return $self->manager->get_all(%params);
 }
 
+sub count {
+  my ($self) = @_;
+  my %params = $self->finalize;
+
+  return $self->manager->get_all_count(%params);
+}
+
 sub disable_plugin {
   my ($self, $plugin) = @_;
   die 'cannot change internal state after finalize was called' if $self->finalized;
 sub disable_plugin {
   my ($self, $plugin) = @_;
   die 'cannot change internal state after finalize was called' if $self->finalized;
@@ -106,6 +113,8 @@ sub finalize {
 
   return %{ $self->final_params } if $self->finalized;
 
 
   return %{ $self->final_params } if $self->finalized;
 
+  $self->register_handlers(callback => sub { shift; (@_, %{ $self->additional_url_params }) }) if %{ $self->additional_url_params };
+
   push @{ $params{query}        ||= [] }, @{ $self->query || [] };
   push @{ $params{with_objects} ||= [] }, @{ $self->with_objects || [] };
 
   push @{ $params{query}        ||= [] }, @{ $self->query || [] };
   push @{ $params{with_objects} ||= [] }, @{ $self->with_objects || [] };
 
@@ -124,6 +133,14 @@ sub register_handlers {
   map { push @{ $handlers->{$_} }, $additional_handlers{$_} if $additional_handlers{$_} } keys %$handlers;
 }
 
   map { push @{ $handlers->{$_} }, $additional_handlers{$_} if $additional_handlers{$_} } keys %$handlers;
 }
 
+sub add_additional_url_params {
+  my ($self, %params) = @_;
+
+  $self->additional_url_params({ %{ $self->additional_url_params }, %params });
+
+  return $self;
+}
+
 sub get_models_url_params {
   my ($self, $sub_name_or_code) = @_;
 
 sub get_models_url_params {
   my ($self, $sub_name_or_code) = @_;
 
@@ -137,7 +154,7 @@ sub get_models_url_params {
     );
   };
 
     );
   };
 
-  $self->registere_handlers('callback' => $callback);
+  $self->register_handlers('callback' => $callback);
 }
 
 sub get_callback {
 }
 
 sub get_callback {
@@ -183,6 +200,8 @@ sub init_source {
   $::form
 }
 
   $::form
 }
 
+sub init_additional_url_params { +{} }
+
 1;
 __END__
 
 1;
 __END__
 
@@ -220,13 +239,13 @@ paginating footers.
 
 Information about the requested data query can be stored into the object up to
 a certain point, from which on the object becomes locked and can only be
 
 Information about the requested data query can be stored into the object up to
 a certain point, from which on the object becomes locked and can only be
-accessed for information. (Seee TODO STAGES).
+accessed for information. (See C<STATES>).
 
 =head1 INTERFACE METHODS
 
 =over 4
 
 
 =head1 INTERFACE METHODS
 
 =over 4
 
-=item new PARMAS
+=item new PARAMS
 
 Create a new GetModels object. Params must have at least an entry
 C<controller>, other than that, see C<CONFIGURATION> for options.
 
 Create a new GetModels object. Params must have at least an entry
 C<controller>, other than that, see C<CONFIGURATION> for options.
@@ -247,6 +266,13 @@ one of the controller's functions.
 The value returned by C<SUB> must be either a single hash
 reference or a hash of key/value pairs to add to the URL.
 
 The value returned by C<SUB> must be either a single hash
 reference or a hash of key/value pairs to add to the URL.
 
+=item add_additional_url_params C<%params>
+
+Sets additional parameters that will be added to each URL generated by
+this model (e.g. for pagination/sorting). This is just sugar for a
+proper call to L<get_models_url_params> with an anonymous sub adding
+those parameters.
+
 =item get_callback
 
 Returns a URL suitable for use as a callback parameter. It maps to the
 =item get_callback
 
 Returns a URL suitable for use as a callback parameter. It maps to the
@@ -293,6 +319,8 @@ certain plugin methods.
 
 =head1 DELEGATION METHODS
 
 
 =head1 DELEGATION METHODS
 
+All of these finalize.
+
 Methods delegating to C<Sorted>:
 
 =over 4
 Methods delegating to C<Sorted>:
 
 =over 4
@@ -336,16 +364,16 @@ This is the state after creating a new object.
 
 =item Init
 
 
 =item Init
 
-In this state every information needed from the source ($::form) has beed read
+In this state every information needed from the source ($::form) has been read
 and subsequent changes to the source have no effect. In the current
 and subsequent changes to the source have no effect. In the current
-implementation this will called immediately during creation, so that the return
-value of C<new> is already in state C<Init>.
+implementation this will happen during creation, so that the return value of
+C<new> is already in state C<Init>.
 
 =item Finalized
 
 In this state no new configuration will be accepted so that information gotten
 through the various methods is consistent. Every information retrieval method
 
 =item Finalized
 
 In this state no new configuration will be accepted so that information gotten
 through the various methods is consistent. Every information retrieval method
-will trigger finalizing.
+will trigger finalize.
 
 =back
 
 
 =back
 
@@ -376,7 +404,7 @@ Configuration for plugins. If the option for any plugin is omitted, it defaults
 to enabled and configured by default. Giving a falsish value as first argument
 will disable the plugin.
 
 to enabled and configured by default. Giving a falsish value as first argument
 will disable the plugin.
 
-If the value is a hashref, it will be passed to the plugin C<init> method.
+If the value is a hashref, it will be passed to the plugin's C<init> method.
 
 =item query
 
 
 =item query