public static function user($request, $context) { //print_r($request); if (!empty($request['id'])) { $user = utilisateurTable::getUserById($request['id']); if (empty($user)) { return context::ERROR; } $tweet = tweetTable::getTweetsPostedBy($request['id']); $data['user'] = $user[0]; $data['tweet'] = $tweet; $context->data = $data; if ($context->getSessionAttribute('is_logged') == 1 && $request['id'] == $context->getSessionAttribute('id')) { return context::SUCCESS; } else { return context::ACCESS; } } else { if ($context->getSessionAttribute('is_logged') == 1) { $user = utilisateurTable::getUserById($context->getSessionAttribute('id')); $tweet = tweetTable::getTweetsPostedBy($context->getSessionAttribute('id')); $data['user'] = $user[0]; $data['tweet'] = $tweet; $context->data = $data; return context::SUCCESS; } } return context::ERROR; }
public static function voirProfil($request, $context) { try { // Au cas où, on controle la validité de if (!key_exists("id", $request) || !is_numeric($request["id"])) { throw new Exception("L'utilisateur que tu cherches n'existe pas."); } else { // On cherche le profil et les tweets dans la base, on les mets dans la session $u = utilisateurTable::getUserById($request["id"]); if (is_null($u)) { throw new Exception("L'utilisateur que tu cherches n'existe pas."); } $tweets = tweetTable::getTweetsPostedBy($request["id"], 10); mainController::marquerTweetsVotes($tweets); context::setSessionAttribute("utilisateurProfil", $u); context::setSessionAttribute("tweetsProfil", $tweets); return context::SUCCESS; } } catch (Exception $e) { context::setSessionAttribute("erreur", $e); return context::ERROR; } }