public function get() { // Load API $client = \PSU::api('backend'); // Get all of the people that work at the helpdesk. $users = $client->get('support/users'); return $users; }
protected function _get_userdatabylogin($wp_id) { static $data = null; if (null === $data[$wp_id]) { $data[$wp_id] = \PSU::api('backend')->get('wp/{{wp_id}}', array('wp_id' => $wp_id)); } //end if return $data[$wp_id]; }
/** * Public method to get the results of a search query from the Directory API * @param string $query A string containing the search query */ public static function get_results($query) { // Initialize the search results array, in case the API fails $search_results = array(); // PSU::api uses Guzzle for its HTTP responses. We need to catch an exception, in case the call fails try { // Get the search results with the PSU REST API $search_results = (array) \PSU::api('backend')->get('directory/search/' . urlencode($query)); } catch (Guzzle\Http\Message\BadResponseException $e) { // Lets grab the exception and put it into the session $_SESSION['errors'][] = $e->getMessage(); // Let's get the response data so we can see the problem $response = $e->getResponse(); // Let's grab the HTTP status and status code $response_data['status'] = $response->getReasonPhrase(); $response_data['status_code'] = $response->getStatusCode(); } return $search_results; }
<?php // Generic response (don't force the trailing slash: this should catch any accidental laziness) respond('/?', function ($request, $response, $app) { // Get the available clusters with the PSU REST API $clusters = (array) \PSU::api('backend')->get('clusters'); // Sort the returned clusters array /* This sort's the clusters array by this priority: * Number of computer's free * Building name * Cluster name */ usort($clusters, function ($a, $b) { // If the number of computers free are the same if ($a->num_computers_free == $b->num_computers_free) { // If the buildings are the same if ($a->building == $b->building) { // If the cluster name is the same if ($a->name == $b->name) { // Return 0. They're equal return 0; } else { // Return the name in alphabetical order return $a->name < $b->name ? -1 : 1; } //end else } else { // Return the name of the building in alphabetical order return $a->building < $b->building ? -1 : 1; } //end else
<?php require_once PSU_EXTERNAL_DIR . '/klein/klein.php'; respond(function ($request, $response, $app) { $app->config = PSU\Config\Factory::get_config(); if (false == $app->config->get('cdn', 'enabled', true)) { define('PSU_CDN', false); } $response->psu_lazyload = function ($ids) use($request, $response, $app) { if (!is_array($ids)) { $ids = array($ids); } $qs = http_build_query(array('id' => $ids)); try { $json = \PSU::api('backend')->get("user/?{$qs}"); $people = $json; } catch (Exception $e) { // nothing...? throw $e; } $response->header('Content-Type', 'application/json'); $response->json($people); }; }); // Load routes for this hostname $webapp->host()->routes(); respond('404', function ($request, $response, $app) { $response->code(404); $response->header('Content-Type', 'text/plain'); echo '404 Not Found'; error_log(sprintf("404 %s%s", $_SERVER['HTTP_HOST'], $_SERVER['REQUEST_URI']), E_USER_NOTICE);
// Generic response (don't force the trailing slash: this should catch any accidental laziness) respond('/?', function ($request, $response, $app) { // Let's create a new person based off of who's logged in $person = new \PSUPerson($_SESSION['username']); // Let's create an array to hold the schedule data $schedule = array(); // Because this data is lazy loaded, let's just ask for it so that we force the request $person->student->levels; // Let's go through each level of the student foreach ($person->student->levels as $level) { // Let's get the current term code for that level $term_code = (array) \PSU::api('backend')->get('student/term-code/' . $level); // PSU::api uses Guzzle for its HTTP responses. We need to catch an exception, in case the call fails try { // Now let's add the schedule data for that term into our schedule array $schedule[$level] = (array) \PSU::api('backend')->get('student/schedule/{{identifier}}', array('identifier' => $person->id), array('term_code' => $term_code['term_code'])); } catch (Guzzle\Http\Message\BadResponseException $e) { // Lets grab the exception and put it into the session $_SESSION['errors'][] = $e->getMessage(); // Let's get the response data so we can see the problem $response = $e->getResponse(); // Let's grab the HTTP status and status code $response_data['status'] = $response->getReasonPhrase(); $response_data['status_code'] = $response->getStatusCode(); } } $app->tpl->assign('schedule', $schedule); // Display the template $app->tpl->assign('show_page', 'schedule'); $app->tpl->display('_wrapper.tpl'); });