FeedsController.php 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. <?php
  2. namespace app\FeedsController;
  3. use lithium\security\Auth;
  4. use app\models\Post;
  5. class FeedsController extends \lithium\action\Controller {
  6. //Class Variables
  7. //public $validates =
  8. public function index()
  9. {
  10. //If the user isn't authenticated
  11. if(!Auth::check('default'))
  12. {
  13. //Redirect them to the login/welcome page
  14. $this->redirect('Users::login');
  15. }
  16. //else
  17. //Figure out what user is logged in (from their session cookie presumably)
  18. /* Display the users last 20 posts in decending order. */
  19. $user = Session::read('username');
  20. //Since there can only be one of each username, getting the first occurence of $user should be fine
  21. $query = User::find('first', array('conditions' => array('username' => $user)));
  22. $feed = $query->posts;
  23. return compact($feed); //Return the feed array to the
  24. }
  25. /**
  26. * New needs to do a few things
  27. * 1) Validation,
  28. * Ensure that the post is unique,
  29. * Flood protection
  30. * Spam Protection at some point
  31. * 2) Storage
  32. * The post needs to be stored in the users feed as well as users who are friends with them
  33. *
  34. */
  35. public function new()
  36. {
  37. }
  38. /**
  39. * Hide needs to put a "HIDES" edge on the graph
  40. * By getting the users document from the database, querying its id
  41. *then doing something like $thisUser->hides($username)
  42. */
  43. public function hide($username)
  44. {
  45. }
  46. /**
  47. *Does the same sort of validation as new, but deletes a post obviously :P
  48. */
  49. public function delete($id)
  50. {
  51. $user = Auth::check('default');
  52. $post = Post::find($id);
  53. if ($post->username == $user['username']) {
  54. $post->delete();
  55. }
  56. return $this->redirect('Feed::Index');
  57. }
  58. }
  59. ?>