App-Office-Contacts

 view release on metacpan or  search on metacpan

lib/App/Office/Contacts/Database/Person.pm  view on Meta::CPAN

		{                                       # Table:
			people_id => $$id{id},              # phone_people
			number_id => $$id{phone_number_id}, # phone_numbers
			type_id   => $$number{type_id},     # phone_number_types
			type_name => $$number{type_name},   # phone_number_types
		};
	}

	# Phase 2: Get new data for this person, from the CGI form fields.

	%new_type = ();

	my(%new_number);

	for $count (map{s/phone_number_//; $_} grep{/phone_number_\d/} sort keys %$person)
	{
		$number = $$person{"phone_number_$count"};

		if ($number)
		{
			$new_number{$number} = $count;
			$new_type{$number}   = $$person{"phone_number_type_id_$count"};
		}
	}

	# Phase 3: Combine old and new phone numbers but avoid duplications.

	my(%number) = (%old_number, %new_number);

	for $number (keys %number)
	{
		if ($old_number{$number} && $new_number{$number})
		{
			# The phone number type might have changed.

			if ($old_number{$number}{type_id} != $new_type{$number})
			{
				$old_number{$number}{type_id} = $new_type{$number};

				$self -> db -> phone_number -> update_phone_number_type($$person{creator_id}, $old_number{$number});
			}
		}
		elsif ($old_number{$number}) # And ! new number.
		{
			# Number has vanished, so delete old number.

			$self -> db -> phone_number -> delete_phone_number_person($$person{creator_id}, $old_number{$number}{people_id});
		}
		else # ! old number, just new one.
		{
			# Number has appeared, so add new number.

			$self -> db -> phone_number -> save_phone_number_for_person($context, $person, $new_number{$number});
		}
	}

} # End of save_person_transaction.

# --------------------------------------------------

sub update
{
	my($self, $person) = @_;

	$self -> db -> logger -> log(debug => "Database::Person.update($$person{name})");

	$self -> save_person_transaction('update', $person);

} # End of update.

# --------------------------------------------------

1;

=head1 NAME

App::Office::Contacts::Database::Person - 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>.

=head1 Object attributes

This module extends L<App::Office::Contacts::Database::Base>, with these attributes:

=over 4

=item o (None)

=back

=head1 Methods

=head2 add($person)

Adds $person to the I<people> table.

=head2 build_person_record($user_id, $people)

Returns an arrayref of hashrefs for the given $people. Keys in this hashref are:

=over 4

=item o	communication_type_id

=item o	email_phone

=item o	facebook_tag



( run in 0.529 second using v1.01-cache-2.11-cpan-99c4e6809bf )