diff --git a/src/repositories/UserRepository.php b/src/repositories/UserRepository.php index ac11ac52baa060f15f90cadd4932f0bd9ec510e2..a704e0c4e3aa8ab5271341db8f732dd6cf1b6d38 100644 --- a/src/repositories/UserRepository.php +++ b/src/repositories/UserRepository.php @@ -43,6 +43,40 @@ class UserRepository extends BaseRepository $user = $this->getById($user_id); $userModel = new UserModel(); $userModel->constructFromArray($user); + $this->CallAPI("deleteURL", getenv('rest_url') . "/user/{$user_id}", ["user_id" => $user_id]); return $this->delete($userModel); } + + // Method: POST, PUT, GET etc + // Data: array("param" => "value") ==> index.php?param=value + + function CallAPI($method, $url, $data = []) + { + $curl = curl_init(); + + switch ($method) { + case "POST": + curl_setopt($curl, CURLOPT_POST, 1); + + if ($data) + curl_setopt($curl, CURLOPT_POSTFIELDS, $data); + break; + case "PUT": + curl_setopt($curl, CURLOPT_PUT, 1); + break; + default: + if ($data) + $url = sprintf("%s?%s", $url, http_build_query($data)); + } + + + curl_setopt($curl, CURLOPT_URL, $url); + curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1); + + $result = curl_exec($curl); + + curl_close($curl); + + return $result; + } }