Ejemplo n.º 1
0
 private function insertEmail()
 {
     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::jsonToEmail($json);
         $objeto->correctNullFields();
         $objeto = DBObject::insertEmail($objeto);
         if (!is_null($objeto)) {
             $success = array('status' => 'Sucesso', 'msg' => 'Email criado com sucesso.', 'data' => DBJson::emailToJson($objeto));
             $this->response($this->json($success), API::STATUS_OK);
         } else {
             $this->response('', API::STATUS_INTERNAL_SERVER_ERROR);
         }
     } else {
         $this->response('', API::STATUS_NO_CONTENT);
     }
 }
Ejemplo n.º 2
0
 /**
  * @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;
 }