App-Office-Contacts
view release on metacpan or search on metacpan
lib/App/Office/Contacts/Database/Note.pm view on Meta::CPAN
{
my($self, $note) = @_;
$self -> db -> logger -> log(debug => 'Database::Note.add(...)');
$self -> save_note_record('add', $note);
} # End of add.
# -----------------------------------------------
sub delete
{
my($self, $note_id) = @_;
$self -> db -> logger -> log(debug => "Database::Note.delete($note_id)");
$self -> db -> simple -> delete('notes', {id => $note_id})
|| die $self -> db -> simple -> error;
} # End of delete.
# -----------------------------------------------
sub get_notes
{
my($self, $entity_type, $entity_id) = @_;
$self -> db -> logger -> log(debug => "Database::Note.get_notes($entity_type, $entity_id)");
my($result) = $self -> db -> simple -> query('select * from notes where entity_type = ? and entity_id = ? order by timestamp desc', $entity_type, $entity_id)
|| die $self -> db -> simple -> error;
return $self -> db -> library -> decode_hashref_list($result -> hashes);
} # End of get_notes.
# --------------------------------------------------
sub save_note_record
{
my($self, $context, $note) = @_;
$self -> db -> logger -> log(debug => "Database::Note.save_note_record($context, ...)");
my($table_name) = 'notes';
if ($context eq 'add')
{
$$note{id} = $self -> db -> library -> insert_hashref_get_id($table_name, $note);
}
else
{
$self -> db -> simple -> update($table_name, $note, {id => $$note{id} })
|| die $self -> db -> simple -> error;
}
} # End of save_note_record.
# -----------------------------------------------
sub update
{
my($self, $note) = @_;
$self -> db -> logger -> log(debug => "Database::Note.update($$note{id})");
$self -> db -> simple -> update('notes', $note, {id => $$note{id} })
|| die $self -> db -> simple -> error;
return 'Updated note';
} # End of update.
# --------------------------------------------------
1;
=head1 NAME
App::Office::Contacts::Database::Note - A web-based contacts manager
=head1 Synopsis
See L<App::Office::Contacts/Synopsis>.
=head1 Description
L<App::Office::Contacts> implements a utf8-aware, web-based, private and group contacts manager.
=head1 Distributions
See L<App::Office::Contacts/Distributions>.
=head1 Installation
See L<App::Office::Contacts/Installation>.
This module extends L<App::Office::Contacts::Database::Base>, with these attributes:
=head1 Object attributes
=over 4
=item o (None)
=back
=head1 Methods
=head2 add($note)
Adds the given $note to the 'notes' table.
=head2 delete($note_id)
Deletes the note with the given $note_id from the 'notes' table.
=head2 get_notes($entity_type, $entity_id)
Returns a list of note with the given $entity_type ('organization' or 'person'), for the entity
with the given $entity_id.
( run in 0.557 second using v1.01-cache-2.11-cpan-99c4e6809bf )