public static function ExtractUser($data, $singleResult = false, $UserExtension = '', $CourseStatusExtension = '', $CourseExtension = '', $isResult = true) { // generates an assoc array of users by using a defined list of its // attributes $users = DBJson::getObjectsByAttributes($data, User::getDBPrimaryKey(), User::getDBConvert(), $UserExtension); // generates an assoc array of course stats by using a defined list of // its attributes $courseStatus = DBJson::getObjectsByAttributes($data, CourseStatus::getDBPrimaryKey(), CourseStatus::getDBConvert(), $CourseStatusExtension); // generates an assoc array of courses by using a defined list of // its attributes $courses = DBJson::getObjectsByAttributes($data, Course::getDBPrimaryKey(), Course::getDBConvert(), $CourseExtension); $settings = DBJson::getObjectsByAttributes($data, Setting::getDBPrimaryKey(), Setting::getDBConvert()); // concatenates the courses and the associated settings $res = DBJson::concatObjectListResult($data, $courses, Course::getDBPrimaryKey(), Course::getDBConvert()['C_settings'], $settings, Setting::getDBPrimaryKey()); // concatenates the course stats and the associated courses $res = DBJson::concatObjectListsSingleResult($data, $courseStatus, CourseStatus::getDBPrimaryKey(), CourseStatus::getDBConvert()['CS_course'], $res, Course::getDBPrimaryKey(), $CourseExtension, $CourseStatusExtension); // concatenates the users and the associated course stats $res = DBJson::concatResultObjectLists($data, $users, User::getDBPrimaryKey(), User::getDBConvert()['U_courses'], $res, CourseStatus::getDBPrimaryKey(), $CourseStatusExtension, $UserExtension); if ($isResult) { // to reindex // $res = array_merge($res); $res = User::decodeUser($res, false); if ($singleResult) { // only one object as result if (count($res) > 0) { $res = $res[0]; } } } return $res; }
/** * Create User in DB * * @param User $data UserData which contains the created User * @return true if user is created */ public function createUser($data) { global $databaseURI; $data = User::encodeUser($data); $url = "{$databaseURI}/user"; $message = null; $answer = http_post_data($url, $data, false, $message); if ($message == '201') { $user = User::decodeUser($answer); if ($user->getStatus() == '201') { return true; } } return false; }
/** * the constructor * * @param $data an assoc array with the object informations */ public function __construct($data = array()) { if ($data === null) { $data = array(); } foreach ($data as $key => $value) { if (isset($key)) { if ($key == 'member' || $key == 'leader') { $this->{$key} = User::decodeUser($value, false); } else { $func = 'set' . strtoupper($key[0]) . substr($key, 1); $methodVariable = array($this, $func); if (is_callable($methodVariable)) { $this->{$func}($value); } else { $this->{$key} = $value; } } } } }
$lastName = $foundValues['lastName']; $firstName = $foundValues['firstName']; $email = isset($foundValues['email']) ? $foundValues['email'] : null; $userName = $foundValues['userName']; $password = $foundValues['password']; $passwordRepeat = $foundValues['passwordRepeat']; // both passwords are equal if ($password == $passwordRepeat) { $salt = $auth->generateSalt(); $passwordHash = $auth->hashPassword($password, $salt); $newUser = User::createUser(null, $userName, $email, $firstName, $lastName, null, 1, $passwordHash, $salt, 0); $newUserSettings = User::encodeUser($newUser); $URI = $databaseURI . "/user"; $answer = http_post_data($URI, $newUserSettings, true, $message); if ($message == "201") { $user = User::decodeUser($answer); if ($user->getStatus() == '201') { $notifications[] = MakeNotification("success", Language::Get('main', 'successCreateUser', $langTemplate)); } else { $notifications[] = MakeNotification("error", Language::Get('main', 'errorCreateUser', $langTemplate)); } } else { $notifications[] = MakeNotification("error", Language::Get('main', 'errorCreateUser', $langTemplate)); } } else { $notifications[] = MakeNotification("error", Language::Get('main', 'invalidPasswordRepeat', $langTemplate)); } } else { $notifications = $notifications + $f->notifications; } }