public static function showDetails() { $userData = array_key_exists('userData', $_SESSION) ? $_SESSION['userData'] : null; $skillAssocs = array_key_exists('skillAssocs', $_SESSION) ? $_SESSION['skillAssocs'] : array(); if (is_null($userData)) { echo '<p>Unknown user data</p>'; } else { echo '<h1>UserData for userId #' . $userData->getUserId() . '</h1>'; echo '<section>'; echo '<fieldset><legend>User Data</legend>'; echo 'Username: '******'<br><br>' . "\n"; echo 'Skill Level: ' . $userData->getSkillLevel() . '<br><br>' . "\n"; echo 'Skills: '; foreach ($skillAssocs as $skillAssoc) { $skills = SkillsDB::getSkillsBy('skillId', $skillAssoc->getSkillId()); $skill = $skills[0]; echo $skill->getSkillName() . " "; } echo "<br><br>"; echo 'Profile Pic: ' . $userData->getProfilePic() . '<br><br>' . "\n"; echo 'Started Hobby: ' . $userData->getStartedHobby() . '<br><br>' . "\n"; echo 'Fav Color: ' . $userData->getFavColor() . '<br><br>' . "\n"; echo 'Url: ' . $userData->getUrl() . '<br><br>' . "\n"; echo 'Phone: ' . $userData->getPhone() . '<br><br>' . "\n"; // Insert RobotData echo '</fieldset><br>'; echo '</section>'; } }
public static function run() { $action = array_key_exists('action', $_SESSION) ? $_SESSION['action'] : ""; $arguments = array_key_exists('arguments', $_SESSION) ? $_SESSION['arguments'] : ""; switch ($action) { case "create": self::newSkill(); break; case "show": if ($arguments == 'all') { $_SESSION['skills'] = SkillsDB::getSkillsBy(); $_SESSION['headertitle'] = "botspace skills"; SkillView::showAll(); } else { $skills = SkillsDB::getSkillsBy('skillId', $arguments); $_SESSION['skill'] = $skills[0]; self::show(); } break; case "update": echo "Update"; self::updateUser(); break; default: } }
public static function addUserData($userData) { $query = "INSERT INTO UserData (userId, user_name, skill_level, \r\n\t\t\t\tprofile_pic, started_hobby, fav_color, url, phone) VALUES\r\n\t\t\t\t(:userId, :user_name, :skill_level, :profile_pic,\r\n\t\t\t\t:started_hobby, :fav_color, :url, :phone)"; // TODO: Add a functionalized RobotData INSERT query // TODO: Functionalize the SkillAssoc INSERT query try { // check null and check for errors // check for User by given userId; throw exception if non-existent if (is_null($userData) || $userData->getErrorCount() > 0) { throw new PDOException("Invalid UserData object can't be inserted: "); } $newUserId = $userData->getUserId(); if (!isset($newUserId)) { throw new PDOException("UserId not specified"); } // Verify that the specified user exists in the database $db = Database::getDB(); $users = UsersDB::getUserValuesBy('userId', $newUserId, 'userId'); if ($users[0] != $newUserId) { throw new PDOException("Cannot associate UserData with invalid User"); } $statement = $db->prepare($query); $statement->bindValue(":userId", $newUserId); $statement->bindValue(":user_name", $userData->getUserName()); $statement->bindValue(":skill_level", $userData->getSkillLevel()); // TODO: Have the profile pic uploaded to a designated folder and moved $statement->bindValue(":profile_pic", $userData->getProfilePic()); $statement->bindValue(":started_hobby", $userData->getStartedHobby()); $statement->bindValue(":fav_color", $userData->getFavColor()); $statement->bindValue(":url", $userData->getUrl()); $statement->bindValue(":phone", $userData->getPhone()); $statement->execute(); $statement->closeCursor(); $returnId = $db->lastInsertId("userDataId"); // Handle skill area associations separately since they're going into a different table $query = "INSERT INTO SkillAssocs (userDataId, skillId) VALUES\r\n\t\t\t\t\t(:userDataId, :skillId)"; // TODO: Review this for instances where this can go wrong foreach ($userData->getSkillAreas() as $skill) { // Translate the skill (a string) to a skillId (an integer), // then create a skill association $skillArray = SkillsDB::getSkillsBy('skill_name', $skill); $skillObject = $skillArray[0]; $skillstatement = $db->prepare($query); $skillstatement->bindValue(":userDataId", $returnId); $skillstatement->bindValue(":skillId", $skillObject->getSkillId()); $skillstatement->execute(); $skillstatement->closeCursor(); $skillAssocId = $db->lastInsertId("skillAssocId"); } $userData->setUserDataId($returnId); } catch (Exception $e) { // Not permanent error handling $userData->setError('userDataId', 'USER_DATA_INVALID'); } return $userData; }
public function testGetSkillsBySkillId() { $myDB = DBMaker::create('botspacetest'); Database::clearDB(); $db = Database::getDB('botspacetest', 'C:\\xampp\\myConfig.ini'); $skills = SkillsDB::getSkillsBy('skillId', 9); $this->assertEquals(count($skills), 1, 'The database should return exactly on Skill'); $skill = $skills[0]; $this->assertEquals(9, $skill->getSkillId(), 'The database should have exactly one Skill with the provided skillId'); }
public static function show() { $arguments = array_key_exists('arguments', $_SESSION) ? $_SESSION['arguments'] : 0; $userData = $_SESSION['userData']; if (!is_null($userData)) { $_SESSION['userData'] = $userData; $skillAssocs = SkillAssocsDB::getSkillAssocsBy('userDataId', $userData->getUserDataId()); $skills = array(); foreach ($skillAssocs as $skillAssoc) { $skillsArray = SkillsDB::getSkillsBy('skillId', $skillAssoc->getSkillId()); $skill = $skillsArray[0]; array_push($skills, $skill); } //$_SESSION['skillAssocs'] = $skillAssocs; $_SESSION['skills'] = $skills; UserDataView::show(); } else { HomeView::show(); } }
public static function getSkillsBy($type = null, $value = null) { $skillRows = SkillsDB::getSkillsRowsBy($type, $value); return SkillsDB::getSkillsArray($skillRows); }
public static function showDetails() { $base = array_key_exists('base', $_SESSION) ? $_SESSION['base'] : ""; $user = array_key_exists('user', $_SESSION) ? $_SESSION['user'] : null; $userData = array_key_exists('userData', $_SESSION) ? $_SESSION['userData'] : null; $skillAssocs = array_key_exists('skillAssocs', $_SESSION) ? $_SESSION['skillAssocs'] : array(); $userRobots = array_key_exists('userRobots', $_SESSION) ? $_SESSION['userRobots'] : array(); if (!is_null($user) && !is_null($userData)) { echo '<h1>Profile for ' . $userData->getUserName() . '</h1>'; echo '<section>'; // TODO: put this function into a separate class if (UserDataView::CurrentUserCanEditProfileWithUserDataId($userData->getUserId())) { echo '<p>'; echo '<a class="btn btn-primary" '; echo 'role="button" '; echo 'href="/' . $base . '/user/update/' . $userData->getUserDataId() . '" '; echo '>Edit Credentials</a>'; echo '</p>'; } echo '<fieldset><legend>Login Info</legend>'; echo 'Email: ' . $user->getEmail() . '<br><br>' . "\n"; echo 'Password: '******'********'; //$user->getPassword().'<br><br>'."\n"; echo '</fieldset><br>'; echo '</section>'; echo '<section>'; // TODO: put this function into a separate class if (UserDataView::CurrentUserCanEditProfileWithUserDataId($userData->getUserId())) { echo '<p>'; echo '<a class="btn btn-primary" '; echo 'role="button" '; echo 'href="/' . $base . '/userdata/update/' . $userData->getUserDataId() . '" '; echo '>Edit Profile Data</a>'; echo '</p>'; } echo '<fieldset><legend>User Data</legend>'; echo 'Username: '******'<br><br>' . "\n"; echo 'Skill Level: ' . $userData->getSkillLevel() . '<br><br>' . "\n"; echo 'Skills: '; foreach ($skillAssocs as $skillAssoc) { $skills = SkillsDB::getSkillsBy('skillId', $skillAssoc->getSkillId()); $skill = $skills[0]; echo $skill->getSkillName() . " "; } echo "<br><br>"; echo 'Profile Pic: ' . $userData->getProfilePic() . '<br><br>' . "\n"; echo 'Started Hobby: ' . $userData->getStartedHobby() . '<br><br>' . "\n"; echo 'Fav Color: ' . $userData->getFavColor() . '<br><br>' . "\n"; echo 'Url: ' . $userData->getUrl() . '<br><br>' . "\n"; echo 'Phone: ' . $userData->getPhone() . '<br><br>' . "\n"; echo '</fieldset><br>'; echo '</section>'; echo '<section>'; echo '<fieldset><legend>' . $userData->getUserName() . "'s " . 'Robots</legend>'; if (count($userRobots) == 0) { echo '<p>No robots yet</p>'; } else { echo '<ul>'; foreach ($userRobots as $robot) { // TODO: change this to redirect to a robot profile echo '<li><a href="/' . $base . '/robotdata/show/' . $robot->getRobotId() . '">' . $robot->getRobotName() . '</a></li>'; } echo '</ul>'; } echo '</fieldset><br>'; echo '</section>'; } else { echo '<p>Unknown user</p>'; } }