private function insertTelefone() { if ($this->get_request_method() !== 'POST') { $this->response('', API::STATUS_NOT_ACCEPTABLE); } $json = json_decode(file_get_contents("php://input"), true); if (!empty($json)) { $objeto = DBJson::jsonToTelefone($json); $objeto->correctNullFields(); $objeto = DBObject::insertTelefone($objeto); if (!is_null($objeto)) { $success = array('status' => 'Sucesso', 'msg' => 'Telefone criado com sucesso.', 'data' => DBJson::telefoneToJson($objeto)); $this->response($this->json($success), API::STATUS_OK); } else { $this->response('', API::STATUS_INTERNAL_SERVER_ERROR); } } else { $this->response('', API::STATUS_NO_CONTENT); } }
/** * @param $objeto O contato. * @param bool|false $noTelefones Se a lista de telefones do contato nao deve ser incluida no json. * @param bool|false $noEmails Se a lista de emails do contato nao deve ser incluida no json. * @return array O contato no formato json. */ public static function contatoToJson($objeto, $noTelefones = false, $noEmails = false) { $json = array('id' => $objeto->getId(), 'nome' => $objeto->getNome(), 'sobrenome' => $objeto->getSobrenome()); if (!$noTelefones) { $jsonTelefones = array(); foreach ($objeto->getTelefones() as $telefone) { $jsonTelefones[] = DBJson::telefoneToJson($telefone, true); } $json['telefones'] = $jsonTelefones; } if (!$noEmails) { $jsonEmails = array(); foreach ($objeto->getEmails() as $email) { $jsonEmails[] = DBJson::emailToJson($email, true); } $json['emails'] = $jsonEmails; } return $json; }