/**
  * Add a new contact to an account
  * @param string $accessToken - Valid access token
  * @param Contact $contact - Contact to add
  * @param boolean $actionByVisitor - is the action being taken by the visitor
  * @return Contact
  */
 public function addContact($accessToken, Contact $contact, $actionByVisitor = false)
 {
     $params = array();
     if ($actionByVisitor == true) {
         $params['action_by'] = "ACTION_BY_VISITOR";
     }
     return $this->contactService->addContact($accessToken, $contact, $params);
 }
Esempio n. 2
0
        return $response->write(json_encode($contactList, true));
    } catch (Exception $e) {
        error_log($e->getMessage());
    }
    return error($response, 'GET ALL CONTACTS UNKNOWN ERROR');
});
$app->post('/addContact', function (\Slim\Http\Request $request, \Slim\Http\Response $response, $args) use($app) {
    try {
        if (!has_access($request)) {
            return access_denied($response);
        }
        $requestData = $request->getBody()->getContents();
        $data = json_decode($requestData, true);
        $contact = contactParser($data);
        $contactService = new ContactService();
        $id = $contactService->addContact($contact);
        if ($id != -1) {
            $contact->setId($id);
        } else {
            return error($response, 'ADD CONTACT IN DATABASE ERROR');
        }
        $exchangeService = new ExchangeService();
        if ($exchangeService->addContact($contact)) {
            return $response->write(json_encode($contact, true));
        } else {
            return error($response, 'ADD CONTACT IN EXCHANGE ERROR');
        }
    } catch (Exception $e) {
        error_log($e->getMessage());
    }
    return error($response, 'ADD CONTACT UNKNOWN ERROR');