/** * This method formats a URL for the specified routing item class name, incorporating * the get parameters specified in the get parameter map. * @param String $routingItemClassPath The class path of the target routing item. * @param array $getParamMap A map of get parameters to be included in the URL (optional). * @return String The formatted URL. */ public static function formatRoutingItemUrl($routingItemClassPath, array $getParamMap = NULL) { ClassLoader::requireClassOnce($routingItemClassPath); $routingClassName = ClassLoader::parseClassName($routingItemClassPath); $url = UrlFormatter::getBaseUrl() . '?' . IndexRoutingItem::INDEX_ROUTING_ITEM_GET_PARAM . '='; $url .= $routingClassName::getRoutingKey(); if ($getParamMap != NULL) { foreach ($getParamMap as $key => $value) { $url .= "&{$key}={$value}"; } } return $url; }
<?php ClassLoader::requireClassOnce('views/View'); ClassLoader::requireClassOnce('actions/SaveJourneyAction'); ClassLoader::requireClassOnce('util/UrlFormatter'); ClassLoader::requireClassOnce('util/DbConnectionUtil'); ClassLoader::requireClassOnce('model/ImageData'); ClassLoader::requireClassOnce('model/ImageAttribute'); class FinishJourneyView extends View { public function __construct() { parent::__construct(FALSE); } public static function getRoutingKey() { return 'FinishJourneyView'; } private function displayImageDetailLink(ImageData $imageData) { $imageDetailsUrl = UrlFormatter::formatRoutingItemUrl('views/ImageDetailsView', array(ImageDetailsView::GET_PARAM_IMAGE_ID => $imageData->getId())); $thumbnailUrl = UrlFormatter::formatImageUrl($imageData->getThumbnailUri()); ?> <a target="_blank" href="<?php echo $imageDetailsUrl; ?> "><img src="<?php echo $thumbnailUrl; ?> "/></a> <?php
<?php ClassLoader::requireClassOnce('model/User'); ClassLoader::requireClassOnce('util/DbConnectionUtil'); ClassLoader::requireClassOnce('util/Settings'); /** * This class provides utility functions for verifying user authentication. * @author craigb */ class UserAuthUtil { /** * Checks whether or not the requester is an authenticated user. * @return boolean Whether or not the requester is an authenticated user. */ public static function isRequesterAuthenticated() { return isset($_SESSION['AUTHENTICATED_USER']); } /** * If the requester is authenticated, returns a reference to the user object associated * with the requester. * @return A reference to the user object associated with the requester, or NULL if the requester isn't * authenticated. */ public static function getAuthenticatedUser() { if (UserAuthUtil::isRequesterAuthenticated()) { return $_SESSION['AUTHENTICATED_USER']; } else { return NULL;
<?php ClassLoader::requireClassOnce('model/DbData'); /** * This class encapsulates user preference data. * @author craigb */ class UserPreferences extends DbData { private $userId; /** * Constructs a new user preferences object. * @param $id The DB id of this object. * @param $userId The id of the user this object corresponds to. */ public function __construct($id, $userId) { parent::__construct($id); $this->userId = $userId; } /** * Returns the id of the user this object corresponds to. * @return The id of the user this object corresponds to. */ public function getUserId() { return $this->userId; } /** * Sets the id of the user this preferences object corresponds to. * @param int $userId The id of the user this preferences object corresponds to.
<?php ClassLoader::requireClassOnce('views/View'); ClassLoader::requireClassOnce('util/UrlFormatter'); /** * This class encapsulates the functionality of displaying the image collection search view to the requester. * @author craigb */ class ImageCollectionSearchView extends View { /** * Constructs a new landing page view. */ public function __construct() { parent::__construct(FALSE); } /** * This function returns the routing key for the this class. * @return String The index routing key for the this class. */ public static function getRoutingKey() { return 'ImageCollectionSearch'; } /** * This function performs the processing of the user request. * @param User $user The requesting user. If the user is not null, then by convention * actions will assume the user is authenticated, otherwise not. * @throws Exception If an error was encountered while processing this request, an exception * will be thrown.
<?php ClassLoader::requireClassOnce('util/IndexRoutingItem'); ClassLoader::requireClassOnce('model/User'); ClassLoader::requireClassOnce('util/RequestParser'); /** * This class encapsulates the functionality of accessing javascript resources for this application. * This provides the flexibility of requiring authentication for specified scripts if it becomes necessary. * @author craigb */ class AccessJavascriptAction extends IndexRoutingItem { // This constant defines the get parameter for specifying the javascript file to access const JAVASCRIPT_FILE_GET_PARAM = 'js_file'; private $baseJavascriptDir; /** * Constructs a new access javascript action object. */ public function __construct() { parent::__construct(FALSE); $this->baseJavascriptDir = dirname(dirname(__FILE__)) . '/js/'; } /** * This function returns the index routing key for the this class. * @return String The index routing key for the this class. */ public static function getRoutingKey() { return 'AccessJavascript'; }
<?php /** * This is a test script which tests creation, insertion, updating, and retrieval of the class: User.class.php * @author craigb */ error_reporting(E_ALL | E_STRICT); // includes require_once dirname(dirname(__FILE__)) . '/util/ClassLoader.class.php'; ClassLoader::requireClassOnce('model/User'); ClassLoader::requireClassOnce('model/UserRole'); ClassLoader::requireClassOnce('model/UserPreferences'); ClassLoader::requireClassOnce('util/DbConnectionUtil'); // create a new test user printf("Testing user creation..."); $testNetId = 'testNetId'; $testEmail = '*****@*****.**'; $testRealName = 'Test User'; $testRoleTypes = array(UserRole::USER_ROLE_TYPE_EDITOR, UserRole::USER_ROLE_TYPE_VIEWER); $testUser = User::generateNewUser($testNetId, $testEmail, $testRealName, $testRoleTypes, TRUE); print "PASSED\n"; // insert the new user printf("Testing user insertion..."); $dbConnection = DbConnectionUtil::getDbConnection(); $testUser->save($dbConnection); print "PASSED\n"; // retrieve the user $userId = $testUser->getId(); printf("Testing user retrieval, id: {$userId} ..."); $testUser = NULL; $testUser = User::loadUserByNetId($dbConnection, $testNetId);
<?php ClassLoader::requireClassOnce('views/View'); ClassLoader::requireClassOnce('util/UrlFormatter'); ClassLoader::requireClassOnce('model/User'); ClassLoader::requireClassOnce('model/UserRole'); ClassLoader::requireClassOnce('util/RequestParser'); ClassLoader::requireClassOnce('util/DbConnectionUtil'); ClassLoader::requireClassOnce('model/ImageData'); class ImageSearchResultsView extends View { const POST_PARAM_TITLE = 'title'; const POST_PARAM_AUTHOR = 'author'; const POST_PARAM_YEAR = 'year'; const POST_PARAM_ATTRIBUTE = 'attribute'; public function __construct() { parent::__construct(FALSE); } public static function getRoutingKey() { return 'ImageSearchResults'; } public function processRequest(User $user = NULL) { parent::displayHeader($user, 'Image Search Results'); // compose and execute query $dbConnection = DbConnectionUtil::getDbConnection(); $queryString = 'SELECT imd.id FROM image_data imd '; $attribute = RequestParser::parseRequestParam($_REQUEST, ImageSearchResultsView::POST_PARAM_ATTRIBUTE, RequestParser::PARAM_FILTER_TYPE_ALPHA_NUMERIC_WS_ONLY); if ($attribute != NULL) {
<?php ClassLoader::requireClassOnce('util/IndexRoutingItem'); ClassLoader::requireClassOnce('util/Settings'); ClassLoader::requireClassOnce('util/DbConnectionUtil'); ClassLoader::requireClassOnce('model/User'); ClassLoader::requireClassOnce('views/LoginView'); /** * This class implements an action which provides login functionality. * @author craigb */ class LoginAction extends IndexRoutingItem { const POST_PARAM_USERNAME = '******'; const POST_PARAM_PASSWORD = '******'; /** * Constructs a new logout action object. */ public function __construct() { parent::__construct(FALSE); } /** * This abstract function returns the routing key for the this class. * @return String The index routing key for the this class. */ public static function getRoutingKey() { return 'Login'; } /**
<?php ClassLoader::requireClassOnce('views/View'); ClassLoader::requireClassOnce('views/JourneyStepView'); ClassLoader::requireClassOnce('util/UrlFormatter'); ClassLoader::requireClassOnce('util/DbConnectionUtil'); ClassLoader::requireClassOnce('model/ImageData'); ClassLoader::requireClassOnce('model/ImageAttribute'); ClassLoader::requireClassOnce('model/Journey'); class StartJourneyView extends View { const NUM_START_SELECTION_COUNT = 6; public function __construct() { parent::__construct(FALSE); } public static function getRoutingKey() { return 'StartJourneyView'; } public function processRequest(User $user = NULL) { parent::displayHeader($user, 'Start Journey'); // TODO query for existing journeys // query for distinct image attributes $dbConnection = DbConnectionUtil::getDbConnection(); $distinctAttributeList = ImageAttribute::loadExistingValues($dbConnection); // randomly select attributes, foreach attribute, retrieve the id of a unique image, store in sourceImageList shuffle($distinctAttributeList); $sourceImageIdList = array(); for ($i = 0; $i < self::NUM_START_SELECTION_COUNT && count($distinctAttributeList) > 0; $i++) {
<?php ClassLoader::requireClassOnce('views/View'); ClassLoader::requireClassOnce('util/UrlFormatter'); ClassLoader::requireClassOnce('actions/LoginAction'); class LoginView extends View { private $previousAttemptErrorMessage = NULL; public function __construct() { parent::__construct(FALSE); } public static function getRoutingKey() { return 'LoginView'; } public function setPreviousAttemptErrorMessage($errorMessage) { $this->previousAttemptErrorMessage = $errorMessage; } public function processRequest(User $user = NULL) { parent::displayHeader($user, 'Login'); $loginActionUrl = UrlFormatter::formatRoutingItemUrl('actions/LoginAction'); $usernameField = LoginAction::POST_PARAM_USERNAME; $passwordField = LoginAction::POST_PARAM_PASSWORD; ?> <script type="text/javascript"> function validate( ) { var result = true; $("#errorSection").html( "" );
<?php ClassLoader::requireClassOnce('views/View'); ClassLoader::requireClassOnce('views/ImageSearchResultsView'); ClassLoader::requireClassOnce('util/UrlFormatter'); ClassLoader::requireClassOnce('model/User'); ClassLoader::requireClassOnce('model/UserRole'); /** * This class encapsulates the functionality of displaying the image search view to the requester. * @author craigb */ class ImageSearchView extends View { /** * Constructs a new landing page view. */ public function __construct() { parent::__construct(FALSE); } /** * This function returns the routing key for the this class. * @return String The index routing key for the this class. */ public static function getRoutingKey() { return 'ImageSearch'; } /** * This function performs the processing of the user request. * @param User $user The requesting user. If the user is not null, then by convention
/** * This function loads and maps the index routing item which corresponds to the specified action class path into * the specified index routing item map. * @param String $classPath The class path of the index routing item to be loaded. * @param array &$indexRoutingItemMap A reference to the index routing item map which the loaded action * will be mapped into. * @return IndexRoutingItem The index routing item which was created. */ function loadAndMapIndexRoutingItem($classPath, array &$indexRoutingItemMap) { ClassLoader::requireClassOnce($classPath); $className = ClassLoader::parseClassName($classPath); $newIndexRoutingItem = new $className(); $indexRoutingItemMap[$className::getRoutingKey()] = $newIndexRoutingItem; return $newIndexRoutingItem; }
<?php ClassLoader::requireClassOnce('model/DbData'); ClassLoader::requireClassOnce('model/UserRole'); ClassLoader::requireClassOnce('model/UserPreferences'); /** * This class encapsulates user data. * @author craigb */ class User extends DbData { private $username; private $password; private $email; private $enabled; /** * Constructs a new User object. * @param int $id The DB id for this user. * @param String $username The username for this user. * @param String $password The password for this user. * @param String $email The email for this user. * @param Datetime $lastLogin The last login time for this user. * @param boolean $enabled Whether or not this user account is enabled. */ public function __construct($id, $username, $password, $email, $lastLogin, $enabled) { parent::__construct($id); $this->username = $username; $this->password = $password; $this->email = $email; $this->lastLogin = $lastLogin;