X-Git-Url: http://wagnertech.de/git?a=blobdiff_plain;ds=sidebyside;f=SL%2FController%2FHelper%2FGetModels.pm;h=ec970e517ec34a04b535cd4eabc6eca4f2c30238;hb=833f083eae2a4547c49f8f92a2fdca6ba4dfe5f4;hp=481f1ee2984feea7252a7f22396e9142eafe8f7a;hpb=4f949248ec16dbf13d6d586501437281e9ad5eae;p=kivitendo-erp.git diff --git a/SL/Controller/Helper/GetModels.pm b/SL/Controller/Helper/GetModels.pm index 481f1ee29..ec970e517 100644 --- a/SL/Controller/Helper/GetModels.pm +++ b/SL/Controller/Helper/GetModels.pm @@ -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) ], - 'scalar --get_set_init' => [ qw(handlers source) ], + 'scalar --get_set_init' => [ qw(handlers source additional_url_params) ], array => [ qw(plugins) ], ); @@ -27,6 +27,13 @@ sub get { 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; @@ -106,6 +113,8 @@ sub finalize { 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 || [] }; @@ -124,6 +133,14 @@ sub register_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) = @_; @@ -183,6 +200,8 @@ sub init_source { $::form } +sub init_additional_url_params { +{} } + 1; __END__ @@ -247,6 +266,13 @@ one of the controller's functions. The value returned by C 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 with an anonymous sub adding +those parameters. + =item get_callback Returns a URL suitable for use as a callback parameter. It maps to the