Exemplo n.º 1
0
 public function setUserProfile($userid, $changedprofile)
 {
     /*
      * not including:
      * zipcode
      * userimage
      * userimage_thumbnail
      * height
      * armspan
      * apeindex
      * weight
      */
     $validprofile = array("email", "firstname", "lastname", "birthday", "date_climbingstart", "gender", "main_gym", "aboutme", "countryCode", "main_crag");
     //check validity of each property
     $profileisvalid = true;
     foreach ($changedprofile as $key => $val) {
         if (in_array($key, $validprofile)) {
             if ($key == "email" && !filter_var($val, FILTER_VALIDATE_EMAIL)) {
                 //if invalid email
                 return ["result" => false, "error" => "Invalid email address."];
             } else {
                 if (in_array($key, array("birthday", "date_climbingstart"))) {
                     //validate date
                     $date = DateTime::createFromFormat('Y-m-d', $val);
                     $date_errors = DateTime::getLastErrors();
                     if ($date_errors['warning_count'] + $date_errors['error_count'] > 0) {
                         return ["result" => false, "error" => "Invalid date for: [" . $key . "]"];
                     }
                 } else {
                     if ($key == "gender" && !in_array($val, array("Male", "Female", "Other"))) {
                         return ["result" => false, "error" => "Invalid gender specified"];
                     } else {
                         if (in_array($key, array("main_gym", "main_crag"))) {
                             //check that this gym id exists
                             $areaType = $key == "main_gym" ? 1 : 0;
                             $areaExists = ClimbingAreaDAO::climbingAreaExists($val, $areaType);
                             if (!$areaExists) {
                                 return ["result" => false, "error" => "Climbing area does not exist."];
                             }
                         } else {
                             if ($key == "countryCode") {
                                 //check that CountryCode exists
                             }
                         }
                     }
                 }
             }
         } else {
             $profileisvalid = false;
             break;
         }
     }
     if ($profileisvalid) {
         $prepStr = DBHelper::genPrepareString($changedprofile);
         $stmtStr = "UPDATE userdata SET " . $prepStr . " WHERE userid=:userid";
         $stmt = $this->db->prepare($stmtStr);
         $executeArray = DBHelper::genExecuteArray($changedprofile);
         $executeArray[':userid'] = $userid;
         return ["result" => $stmt->execute($executeArray)];
     }
 }
Exemplo n.º 2
0
<?php

//TODO: Replace with phpunit
include "../core/bootstrap.php";
$dbHelper = new DBHelper();
$propKeys = array("prop1", "prop2", "prop3");
echo $dbHelper::genPlaceholderList($propKeys) . "\n\n";
$userService = new UserService();
var_dump($userService->registerUser("tester8", "test", "*****@*****.**"));
$CDAO = new ClimbingAreaDAO();
$areaid = 7;
$indoor = 1;
var_dump($CDAO->climbingAreaExists($areaid, $indoor));
$UserDAO = new UserDAO();
echo $UserDAO->getNumUsers();
var_dump($UserDAO->getUserPrefs(954));
var_dump($UserDAO->setUserPrefs(954, array("show_boulder" => 1, "minL" => 3)));
var_dump($UserDAO->getUserPrefs(954));
var_dump($UserDAO->getUserProfile(954));
var_dump($UserDAO->getUserRecords(954));
$WorkoutService = new WorkoutLoggingService();
$workout_segments_abs = array(array("climb_type" => "boulder", "ascent_type" => "flash", "grade_index" => 1, "reps" => 1), array("climb_type" => "toprope", "ascent_type" => "project", "grade_index" => 9, "reps" => 5), array("climb_type" => "lead", "ascent_type" => "redpoint", "grade_index" => 11, "reps" => 6), array("climb_type" => "boulder", "ascent_type" => "onsight", "grade_index" => 13, "reps" => 2));
var_dump($WorkoutService->calcWorkoutPoints($workout_segments_abs));
// Save a workout
$DBManager = new DBConnectionManager();
$db = $DBManager->connect();
// userid, date_workout, gymid, boulder_notes,
// tr_notes, lead_notes, other_notes
$userid = 4;
$workout_info = array("userid" => $userid, "date_workout" => "2015-10-23", "gymid" => 1, "boulder_notes" => "bouldering!", "tr_notes" => "tr rocks", "lead_notes" => "", "other_notes" => "other notes!!!");
$workout_info["boulder_points"] = 200;