Esempio n. 1
1
 public function vCardAction()
 {
     $contact = $this->contactService->find($this->params('id'));
     if (!$contact) {
         return $this->notFoundAction();
     }
     $builder = new VCardBuilder();
     switch (true) {
         case $contact instanceof Company:
             $vcard = $builder->buildCompany($contact);
             break;
         case $contact instanceof Person:
             $vcard = $builder->buildPerson($contact);
             break;
         default:
             throw new RuntimeException('Invalid type provided.');
     }
     $data = $vcard->serialize();
     $response = new Response();
     $response->setStatusCode(Response::STATUS_CODE_200);
     $response->setContent($data);
     $headers = $response->getHeaders();
     $headers->addHeaderLine('Content-Disposition', 'attachment; filename="' . $contact->getDisplayName() . '.vcf"');
     $headers->addHeaderLine('Content-Length', strlen($data));
     $headers->addHeaderLine('Content-Type', 'text/plain');
     return $response;
 }
Esempio n. 2
0
 public function viewAction()
 {
     $contact = $this->contactService->find($this->params('id'));
     if (!$contact) {
         return $this->notFoundAction();
     }
     $viewModel = new ViewModel();
     switch (true) {
         case $contact instanceof Company:
             $viewModel->setVariable('company', $contact);
             $viewModel->setTemplate('zource-contact/company/view');
             break;
         case $contact instanceof Person:
             $viewModel->setVariable('person', $contact);
             $viewModel->setTemplate('zource-contact/person/view');
             break;
         default:
             throw new RuntimeException('Invalid type provided.');
     }
     return $viewModel;
 }