Campustream 1.0
A social network MQP for WPI
application/controllers/users.php
Go to the documentation of this file.
00001 <?
00002 
00006 class Users_Controller extends Controller implements REST {
00007         public $template = 'template/main';
00008         
00013         public function show($args) {
00014                 if (isset($args['username'])) {
00015                         $username = $args['username'];
00016                 } elseif (isset($_GET['username'])) {
00017                         $username = $_GET['username'];
00018                 }
00019                 
00020                 $user = ActiveCache::find('User_Model', "name:$username", 43200)->sql(
00021                         "SELECT * FROM users WHERE username = '$username' LIMIT 1"
00022                 );
00023                 
00024                 if(!$user->is_loaded()) {
00025                         View::respond_to('html', function() {
00026                                 echo "User not found.";
00027                         });
00028                         View::respond_to(array('xml','json', 'jsonp'), function() {
00029                                 Hub::http_error(404, "User not found");
00030                         });
00031                         
00032                         return false;
00033                 }
00034                 
00035                 $template = $this->template;
00036                 View::respond_to('html', function() use($user, $template) {
00037                         $view = new View('user/show');
00038                         $view->user = $user;
00039                         $template->content = $view->render();
00040                         echo $template->render();
00041                 });
00042                 
00043                 View::respond_to(array('xml','json','jsonp'), function($format) use($user) {
00044                         echo $user->{"to_$format"}();
00045                 });
00046         }
00047         
00048 }