Bug 20443: Fix POD
[srvgit] / Koha / Patrons.pm
index 2257492..6943018 100644 (file)
@@ -5,18 +5,18 @@ package Koha::Patrons;
 #
 # This file is part of Koha.
 #
-# Koha is free software; you can redistribute it and/or modify it under the
-# terms of the GNU General Public License as published by the Free Software
-# Foundation; either version 3 of the License, or (at your option) any later
-# version.
+# Koha is free software; you can redistribute it and/or modify it
+# under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 3 of the License, or
+# (at your option) any later version.
 #
-# Koha is distributed in the hope that it will be useful, but WITHOUT ANY
-# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
-# A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
+# Koha is distributed in the hope that it will be useful, but
+# WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
 #
-# You should have received a copy of the GNU General Public License along
-# with Koha; if not, write to the Free Software Foundation, Inc.,
-# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+# You should have received a copy of the GNU General Public License
+# along with Koha; if not, see <http://www.gnu.org/licenses>.
 
 use Modern::Perl;
 
@@ -290,7 +290,7 @@ sub search_anonymize_candidates {
     $cond->{dateexpiry} = { '<=' => $str };
     $cond->{anonymized} = 0; # not yet done
     if( $params->{locked} ) {
-        my $fails = C4::Context->preference('FailedLoginAttempts');
+        my $fails = C4::Context->preference('FailedLoginAttempts') || 0;
         $cond->{login_attempts} = [ -and => { '!=' => undef }, { -not_in => [0, 1..$fails-1 ] } ]; # -not_in does not like undef
     }
     return $class->search( $cond );
@@ -427,6 +427,42 @@ sub update_category_to {
     return $counter;
 }
 
+=head3 filter_by_attribute_type
+
+my $patrons = Koha::Patrons->filter_by_attribute_type($attribute_type_code);
+
+Return a Koha::Patrons set with patrons having the attribute defined.
+
+=cut
+
+sub filter_by_attribute_type {
+    my ( $self, $attribute_type ) = @_;
+    my $rs = Koha::Patron::Attributes->search( { code => $attribute_type } )
+      ->_resultset()->search_related('borrowernumber');
+    return Koha::Patrons->_new_from_dbic($rs);
+}
+
+=head3 filter_by_attribute_value
+
+my $patrons = Koha::Patrons->filter_by_attribute_value($attribute_value);
+
+Return a Koha::Patrons set with patrong having the attribute value passed in parameter.
+
+=cut
+
+sub filter_by_attribute_value {
+    my ( $self, $attribute_value ) = @_;
+    my $rs = Koha::Patron::Attributes->search(
+        {
+            'borrower_attribute_types.staff_searchable' => 1,
+            attribute => { like => "%$attribute_value%" }
+        },
+        { join => 'borrower_attribute_types' }
+    )->_resultset()->search_related('borrowernumber');
+    return Koha::Patrons->_new_from_dbic($rs);
+}
+
+
 =head3 _type
 
 =cut