<?php

include 'lib/AbstractGigasetXmlPhonebookApp.php';
require_once "lib/XMLAddressBook.php";
require_once "lib/XMLContact.php";

class XmlPhonebookApp extends AbstractGigasetXmlPhonebookApp
{

    public function renderPhoneAdresses($addresses, $addressesCount)
    {
        $attributes = array(
            'total' => $addressesCount,
            'first' => '1',
            'last' => $addressesCount
        );
        $addressBook = new XMLAddressBook($attributes);

        foreach ($addresses as $key => $address) {
            if ($key >= $addressesCount) {
                break;
            }
            $contact = new XMLContact();
            $contact->setID($key + 1);
            $contact->setFirstname($address->n_given);
            $contact->setLastname($address->n_family);
            $contact->setExtension($address->tel_work);
            $contact->setPrivatExtension($address->tel_home);
            $contact->setMobilePhoneExtension($address->tel_cell_ic);
            $addressBook->addScreen($contact);
        }
        $addressBook->printScreen();
    }
}
