public function create(Application $app, Request $request) { $message = $request->get('message'); $user_id = intval($app['session']->get('user')['id']); if (strlen($message) <= 140) { $tweet = new Tweet($app); $tweet->save('tweets', array('tweet' => $message, 'user_id' => $user_id, 'created_at' => date("Y-m-d H:i:s"), 'updated_at' => date("Y-m-d H:i:s"))); $user_tweets = $tweet->find('tweets', array('user_id' => $user_id)); echo var_dump($user_tweets); } else { $error_message = "Please limit the message to 140 charecters."; } return $app->render('tweets.php.twig', array('tweets' => $user_tweets, 'error_message' => $this->error_message)); }
public function postTweet() { checkUnauthorizedAccess(); if (post('tweet')) { $fromid = UserRepository::getIdByUsername($_SESSION['username']); $toid = getIdFromURL(); $content = htmlentities(trim(post('content'))); $tag = htmlentities(trim(post('tag'))); $photo = post('selectPhoto'); $tweet = new Tweet(); $tweet->setFromid($fromid); $tweet->setToid($toid); $tweet->setContent($content); $tweet->setImage($photo); $tweet->setTag($tag); try { TweetRepository::postTweet($tweet); redirect(\route\Route::get("twitterWall")->generate(array("id" => $toid))); } catch (\PDOException $e) { $e->getMessage(); } } }
public static function postTweet(Tweet $tweet) { $db = Database::getInstance(); $query = $db->prepare('INSERT INTO tweets (fromid,toid,content,tag, image) VALUES (?, ?, ?, ?, ?)'); $query->execute([$tweet->getFromid(), $tweet->getToid(), $tweet->getContent(), $tweet->getTag(), $tweet->getImage()]); }