aboutsummaryrefslogtreecommitdiff
path: root/services/userservice.php
diff options
context:
space:
mode:
authormensonge <mensonge@b3834d28-1941-0410-a4f8-b48e95affb8f>2008-11-25 15:57:29 +0000
committermensonge <mensonge@b3834d28-1941-0410-a4f8-b48e95affb8f>2008-11-25 15:57:29 +0000
commit15b91c7e661d928d8b125ec9cfbda1702319c8b4 (patch)
tree092d474c05e414bb04a8c428b8ff6cb9ccab765d /services/userservice.php
parent9aafe7551eb5a73739709e72465031db7a1531b4 (diff)
downloadsemanticscuttle-15b91c7e661d928d8b125ec9cfbda1702319c8b4.tar.gz
semanticscuttle-15b91c7e661d928d8b125ec9cfbda1702319c8b4.tar.bz2
Major refactoring: transform user into object, define parameters used into each file, ...
git-svn-id: https://semanticscuttle.svn.sourceforge.net/svnroot/semanticscuttle/trunk@173 b3834d28-1941-0410-a4f8-b48e95affb8f
Diffstat (limited to 'services/userservice.php')
-rw-r--r--services/userservice.php104
1 files changed, 99 insertions, 5 deletions
diff --git a/services/userservice.php b/services/userservice.php
index 19e81c6..241934e 100644
--- a/services/userservice.php
+++ b/services/userservice.php
@@ -76,6 +76,22 @@ class UserService {
return $users;
}
+ function & getObjectUsers($nb=0) {
+ $query = 'SELECT * FROM '. $this->getTableName() .' ORDER BY `uId` DESC';
+ if($nb>0) {
+ $query .= ' LIMIT 0, '.$nb;
+ }
+ if (! ($dbresult =& $this->db->sql_query($query)) ) {
+ message_die(GENERAL_ERROR, 'Could not get user', '', __LINE__, __FILE__, $query, $this->db);
+ return false;
+ }
+
+ while ($row = & $this->db->sql_fetchrow($dbresult)) {
+ $users[] = new User($row[$this->getFieldName('primary')], $row[$this->getFieldName('username')]);
+ }
+ return $users;
+ }
+
function _randompassword() {
$seed = (integer) md5(microtime());
mt_srand($seed);
@@ -109,10 +125,15 @@ class UserService {
return $this->_getuser($this->getFieldName('username'), $username);
}
+ function getObjectUserByUsername($username) {
+ $user = $this->_getuser($this->getFieldName('username'), $username);
+ return new User($user[$this->getFieldName('primary')], $username);
+ }
+
function getUser($id) {
return $this->_getuser($this->getFieldName('primary'), $id);
}
-
+
// Momentary useful in order to go to object code
function getObjectUser($id) {
$user = $this->_getuser($this->getFieldName('primary'), $id);
@@ -136,7 +157,7 @@ class UserService {
}
return $currentuser;
}
-
+
// Momentary useful in order to go to object code
function getCurrentObjectUser($refresh = FALSE, $newval = NULL) {
static $currentObjectUser;
@@ -152,6 +173,22 @@ class UserService {
return $currentObjectUser;
}
+ function existsUserWithUsername($username) {
+ if($this->getUserByUsername($username) != '') {
+ return true;
+ } else {
+ return false;
+ }
+ }
+
+ function existsUser($id) {
+ if($this->getUser($id) != '') {
+ return true;
+ } else {
+ return false;
+ }
+ }
+
function isAdmin($userid) {
$user = $this->getUser($userid);
@@ -446,27 +483,84 @@ class UserService {
function setCookieKey($value) { $this->cookiekey = $value; }
}
+
+/* Defines a user. Rare fields are filled if required. */
class User {
var $id;
var $username;
+ var $name;
+ var $email;
+ var $homepage;
+ var $content;
+ var $datetime;
var $isAdmin;
function User($id, $username) {
$this->id = $id;
$this->username = $username;
}
-
+
function getId() {
return $this->id;
}
-
+
function getUsername() {
return $this->username;
}
+
+ function getName() {
+ // Look for value only if not already set
+ if(!isset($this->name)) {
+ $userservice =& ServiceFactory::getServiceInstance('UserService');
+ $user = $userservice->getUser($this->id);
+ $this->name = $user['name'];
+ }
+ return $this->name;
+ }
+
+ function getEmail() {
+ // Look for value only if not already set
+ if(!isset($this->email)) {
+ $userservice =& ServiceFactory::getServiceInstance('UserService');
+ $user = $userservice->getUser($this->id);
+ $this->email = $user['email'];
+ }
+ return $this->email;
+ }
+
+ function getHomepage() {
+ // Look for value only if not already set
+ if(!isset($this->homepage)) {
+ $userservice =& ServiceFactory::getServiceInstance('UserService');
+ $user = $userservice->getUser($this->id);
+ $this->homepage = $user['homepage'];
+ }
+ return $this->homepage;
+ }
+ function getContent() {
+ // Look for value only if not already set
+ if(!isset($this->content)) {
+ $userservice =& ServiceFactory::getServiceInstance('UserService');
+ $user = $userservice->getUser($this->id);
+ $this->content = $user['uContent'];
+ }
+ return $this->content;
+ }
+
+ function getDatetime() {
+ // Look for value only if not already set
+ if(!isset($this->content)) {
+ $userservice =& ServiceFactory::getServiceInstance('UserService');
+ $user = $userservice->getUser($this->id);
+ $this->datetime = $user['uDatetime'];
+ }
+ return $this->datetime;
+ }
+
function isAdmin() {
- // Look for value if not already set
+ // Look for value only if not already set
if(!isset($this->isAdmin)) {
$userservice =& ServiceFactory::getServiceInstance('UserService');
$this->isAdmin = $userservice->isAdmin($this->id);