/**
  * Handles GET requests to /api/courses as defined in webapp.php.
  */
 public function get()
 {
     // Attempt to use the cached version for efficiency (if it exists).
     $file = new File(FILE_ROOT . '/cache/courses.json');
     if ($file->exists && $file->isReadable) {
         return $file;
     }
     // Otherwise, calculate the response directly.
     $response = $this->utility->createCoursesResponse(null);
     $this->response->json(ProtocolMessage::serialize($response), true);
     // "')]}\n"
 }
Exemplo n.º 2
0
        $cdp->run();
        $utility = new SchedulePlannerProtocolMessageUtility(App::getDatabase());
        $response = $utility->createCoursesResponse(null);
        $json = ProtocolMessage::serialize($response);
        try {
            $file = new File(FILE_ROOT . '/cache/courses.json');
            $file->content = "')]}\n" . $json;
        } catch (FileException $e) {
            fprintf(STDOUT, "Failed to write file cache, continuing.\n");
        }
        fprintf(STDOUT, "Done!\n");
    } else {
        fprintf(STDOUT, "Unrecognized command.\n");
    }
});
/**
 * Regenerates the cache of course data to reflect database modifications.
 * php server.php recache
 */
CLIApplication::listen('recache', function ($args) {
    $utility = new SchedulePlannerProtocolMessageUtility(App::getDatabase());
    $response = $utility->createCoursesResponse(null);
    $json = ProtocolMessage::serialize($response);
    try {
        $file = new File(FILE_ROOT . '/cache/courses.json');
        $file->content = "')]}\n" . $json;
    } catch (FileException $e) {
        fprintf(STDOUT, "Failed to write file cache, continuing.\n");
    }
    fprintf(STDOUT, "Done!\n");
});
Exemplo n.º 3
0
 /**
  * Handles requests to GET /api/user to return information about active user.
  */
 public function get()
 {
     $message = $this->utility->createUserModel($this->session);
     $this->response->json(ProtocolMessage::serialize($message), true);
 }