public function loadUser($userId)
{
$userId = (int) $userId;
// get database instance
$db = Model::getContainer()->get('database');
// get user-data
$userData = (array) $db->getRecord('SELECT u.id, u.email
FROM users AS u
WHERE u.id = ?
LIMIT 1', array($userId));
// if there is no data we have to destroy this object, I know this isn't a realistic situation
if (empty($userData)) {
throw new Exception('The user (' . $userId . ') doesn\'t exist.');
}
// set properties
$this->setUserId($userData['id']);
$this->setEmail($userData['email']);
// get settings
$settings = (array) $db->getPairs('SELECT us.name, us.value
FROM users_settings AS us
WHERE us.user_id = ?', array($userId));
// loop settings and store them in the object
foreach ($settings as $key => $value) {
$this->settings[$key] = unserialize($value);
}
}