public function update($user) { $userDAO = new UserDAO(); //now build the array represting the php object... $fields = array('user_type' => $user->getUserType(), 'username' => $user->getUsername(), 'user_password' => $user->getUserpassword(), 'user_full_name' => $user->getUserFullName(), 'user_status' => $user->getUserStatus(), 'email' => $user->getEmail(), 'user_last_valid_login' => $user->getUserLastValidLogin(), 'user_first_invalid_login' => $user->getUserFirstInvalidLogin(), 'user_faild_login_count' => $user->getUserFailedLoginCount(), 'user_create_date' => $user->getUserCreateDate(), 'modified_by' => $user->getModifiedBy(), 'modification_date' => $user->getModificationDate()); $userDAO->update($user->getUserId(), $fields); }
if ($_POST['email'] != $user->getEmail()) { $user->setEmail($_POST['email']); $modified = true; } $_POST['birthDate'] = $_POST['yBirthDate'] . '-' . $_POST['mBirthDate'] . '-' . $_POST['dBirthDate']; if ($_POST['birthDate'] != $user->getBirthDate()) { $user->setBirthDate($_POST['birthDate']); $modified = true; } if ($_POST['address'] != $user->getAddress()) { $user->setAddress($_POST['address']); $modified = true; } if ($_POST['postalCode'] != $user->getPostalCode()) { $user->setPostalCode($_POST['postalCode']); $modified = true; } if ($_POST['city'] != $user->getCity()) { $user->setCity($_POST['city']); $modified = true; } if ($_POST['phoneNumber'] != $user->getPhoneNumber()) { $user->setPhoneNumber($_POST['phoneNumber']); $modified = true; } if ($modified) { UserDAO::update($user); } } } $presenter->data['user'] =& $user;
echo json_encode($userDAO->selectById($id), JSON_NUMERIC_CHECK); exit; }); $app->get('/users/login/:mail/?', authorize(), function ($mail) use($userDAO) { header("Content-Type: application/json"); echo json_encode($userDAO->selectByMail($mail), JSON_NUMERIC_CHECK); exit; }); $app->post('/users/?', authorize(), function () use($app, $userDAO) { header("Content-Type: application/json"); $post = $app->request->post(); if (empty($post)) { $post = (array) json_decode($app->request()->getBody()); } echo json_encode($userDAO->insert($post), JSON_NUMERIC_CHECK); exit; }); $app->delete('/users/:id/?', authorize(), function () use($userDAO) { header("Content-Type: application/json"); echo json_encode($userDAO->delete()); exit; }); $app->put('/users/:id/?', function ($id) use($app, $userDAO) { header("Content-Type: application/json"); $post = $app->request->post(); if (empty($post)) { $post = (array) json_decode($app->request()->getBody()); } echo json_encode($userDAO->update($id, $post), JSON_NUMERIC_CHECK); exit; });
function execute() { $user = json_decode($_GET['user']); $dao = new UserDAO(); $dao->update($user); }