Bug 12478: working on authority results
[koha-ffzg.git] / Koha / Object.pm
index bc2746f..9d23fb4 100644 (file)
@@ -57,12 +57,12 @@ sub new {
 
     if ($attributes) {
         $self->{_result} =
-          Koha::Database->new()->schema()->resultset( $class->type() )
+          Koha::Database->new()->schema()->resultset( $class->_type() )
           ->new($attributes);
     }
 
-    croak("No type found! Koha::Object must be subclassed!")
-      unless $class->type();
+    croak("No _type found! Koha::Object must be subclassed!")
+      unless $class->_type();
 
     bless( $self, $class );
 
@@ -81,11 +81,11 @@ sub _new_from_dbic {
     # DBIC result row
     $self->{_result} = $dbic_row;
 
-    croak("No type found! Koha::Object must be subclassed!")
-      unless $class->type();
+    croak("No _type found! Koha::Object must be subclassed!")
+      unless $class->_type();
 
-    croak( "DBIC result type " . ref( $self->{_result} ) . " isn't of the type " . $class->type() )
-      unless ref( $self->{_result} ) eq "Koha::Schema::Result::" . $class->type();
+    croak( "DBIC result _type " . ref( $self->{_result} ) . " isn't of the _type " . $class->_type() )
+      unless ref( $self->{_result} ) eq "Koha::Schema::Result::" . $class->_type();
 
     bless( $self, $class );
 
@@ -98,15 +98,15 @@ If the object is new, it will be created.
 If the object previously existed, it will be updated.
 
 Returns:
-    1  if the store was a success
-    0  if the store failed
+    $self  if the store was a success
+    undef  if the store failed
 
 =cut
 
 sub store {
     my ($self) = @_;
 
-    return $self->_result()->update_or_insert() ? 1 : 0;
+    return $self->_result()->update_or_insert() ? $self : undef;
 }
 
 =head3 $object->in_storage();
@@ -190,7 +190,7 @@ sub set {
         }
     }
 
-    return $self->_result()->set_columns($properties) ? 1 : undef;
+    return $self->_result()->set_columns($properties) ? $self : undef;
 }
 
 =head3 $object->id();
@@ -207,6 +207,18 @@ sub id {
     return $id;
 }
 
+=head3 $object->unblessed();
+
+Returns an unblessed representation of object.
+
+=cut
+
+sub unblessed {
+    my ($self) = @_;
+
+    return { $self->_result->get_columns };
+}
+
 =head3 $object->_result();
 
 Returns the internal DBIC Row object
@@ -218,7 +230,7 @@ sub _result {
 
     # If we don't have a dbic row at this point, we need to create an empty one
     $self->{_result} ||=
-      Koha::Database->new()->schema()->resultset( $self->type() )->new({});
+      Koha::Database->new()->schema()->resultset( $self->_type() )->new({});
 
     return $self->{_result};
 }
@@ -255,7 +267,8 @@ sub AUTOLOAD {
     # Using direct setter/getter like $item->barcode() or $item->barcode($barcode);
     if ( grep {/^$method$/} @columns ) {
         if ( @_ ) {
-            return $self->_result()->set_column( $method, @_ );
+            $self->_result()->set_column( $method, @_ );
+            return $self;
         } else {
             my $value = $self->_result()->get_column( $method );
             return $value;
@@ -266,14 +279,14 @@ sub AUTOLOAD {
     return;
 }
 
-=head3 type
+=head3 _type
 
 This method must be defined in the child class. The value is the name of the DBIC resultset.
-For example, for borrowers, the type method will return "Borrower".
+For example, for borrowers, the _type method will return "Borrower".
 
 =cut
 
-sub type { }
+sub _type { }
 
 sub DESTROY { }