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; }
public function deleteAction() { $person = $this->contactService->findPerson($this->params('id')); if (!$person) { return $this->notFoundAction(); } $this->contactService->deleteContact($person); return $this->redirect()->toRoute('contacts'); }
public function deleteAction() { $company = $this->contactService->findCompany($this->params('id')); if (!$company) { return $this->notFoundAction(); } $this->contactService->deleteContact($company); return $this->redirect()->toRoute('contacts'); }
public function indexAction() { switch ($this->params()->fromQuery('filter')) { case 'companies': $filter = ContactEntry::TYPE_COMPANY; break; case 'people': $filter = ContactEntry::TYPE_PERSON; break; default: $filter = null; break; } /** @var Paginator $contactsPaginator */ $contactsPaginator = $this->contactService->getOverviewPaginator($filter); $contactsPaginator->setCurrentPageNumber($this->params()->fromQuery('page', 1)); $contactsPaginator->setItemCountPerPage(50); return new ViewModel(['contactsPaginator' => $contactsPaginator]); }
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; }