summaryrefslogtreecommitdiff
path: root/src/SemanticScuttle/Service/User.php
diff options
context:
space:
mode:
Diffstat (limited to 'src/SemanticScuttle/Service/User.php')
-rw-r--r--src/SemanticScuttle/Service/User.php111
1 files changed, 61 insertions, 50 deletions
diff --git a/src/SemanticScuttle/Service/User.php b/src/SemanticScuttle/Service/User.php
index 407632b..bc88c0b 100644
--- a/src/SemanticScuttle/Service/User.php
+++ b/src/SemanticScuttle/Service/User.php
@@ -1,28 +1,39 @@
<?php
-class UserService {
- var $db;
- var $fields = array(
+class SemanticScuttle_Service_User extends SemanticScuttle_Service
+{
+ protected $db;
+ protected $fields = array(
'primary' => 'uId',
'username' => 'username',
'password' => 'password');
- var $profileurl;
- var $tablename;
- var $sessionkey;
- var $cookiekey;
- var $cookietime = 1209600; // 2 weeks
-
- function &getInstance(&$db) {
+ protected $profileurl;
+ protected $tablename;
+ protected $sessionkey;
+ protected $cookiekey;
+ protected $cookietime = 1209600; // 2 weeks
+
+ /**
+ * Returns the single service instance
+ *
+ * @param DB $db Database object
+ *
+ * @return SemanticScuttle_Service
+ */
+ public static function getInstance($db)
+ {
static $instance;
- if (!isset($instance))
- $instance =& new UserService($db);
+ if (!isset($instance)) {
+ $instance = new self($db);
+ }
return $instance;
}
- function UserService(& $db) {
- $this->db =& $db;
- $this->tablename = $GLOBALS['tableprefix'] .'users';
+ protected function __construct($db)
+ {
+ $this->db = $db;
+ $this->tablename = $GLOBALS['tableprefix'] .'users';
$this->sessionkey = INSTALLATION_ID.'-currentuserid';
- $this->cookiekey = INSTALLATION_ID.'-login';
+ $this->cookiekey = INSTALLATION_ID.'-login';
$this->profileurl = createURL('profile', '%2$s');
$this->updateSessionStability();
}
@@ -436,21 +447,21 @@ class UserService {
return true;
}
- function getAllUsers ( ) {
- $query = 'SELECT * FROM '. $this->getTableName();
-
- if (! ($dbresult =& $this->db->sql_query($query)) ) {
- message_die(GENERAL_ERROR, 'Could not get users', '', __LINE__, __FILE__, $query, $this->db);
- return false;
- }
-
- $rows = array();
-
- while ( $row = $this->db->sql_fetchrow($dbresult) ) {
- $rows[] = $row;
- }
- $this->db->sql_freeresult($dbresult);
- return $rows;
+ function getAllUsers ( ) {
+ $query = 'SELECT * FROM '. $this->getTableName();
+
+ if (! ($dbresult =& $this->db->sql_query($query)) ) {
+ message_die(GENERAL_ERROR, 'Could not get users', '', __LINE__, __FILE__, $query, $this->db);
+ return false;
+ }
+
+ $rows = array();
+
+ while ( $row = $this->db->sql_fetchrow($dbresult) ) {
+ $rows[] = $row;
+ }
+ $this->db->sql_freeresult($dbresult);
+ return $rows;
}
// Returns an array with admin uIds
@@ -461,18 +472,18 @@ class UserService {
$admins[] = $this->getIdFromUser($adminName);
}
return $admins;
- }
-
- function deleteUser($uId) {
- $query = 'DELETE FROM '. $this->getTableName() .' WHERE uId = '. intval($uId);
-
- if (!($dbresult = & $this->db->sql_query($query))) {
- message_die(GENERAL_ERROR, 'Could not delete user', '', __LINE__, __FILE__, $query, $this->db);
- return false;
- }
-
- return true;
- }
+ }
+
+ function deleteUser($uId) {
+ $query = 'DELETE FROM '. $this->getTableName() .' WHERE uId = '. intval($uId);
+
+ if (!($dbresult = & $this->db->sql_query($query))) {
+ message_die(GENERAL_ERROR, 'Could not delete user', '', __LINE__, __FILE__, $query, $this->db);
+ return false;
+ }
+
+ return true;
+ }
function sanitisePassword($password) {
@@ -601,7 +612,7 @@ class User {
function getName() {
// Look for value only if not already set
if(!isset($this->name)) {
- $userservice =& ServiceFactory::getServiceInstance('UserService');
+ $userservice =SemanticScuttle_Service_Factory::getServiceInstance('User');
$user = $userservice->getUser($this->id);
$this->name = $user['name'];
}
@@ -611,7 +622,7 @@ class User {
function getEmail() {
// Look for value only if not already set
if(!isset($this->email)) {
- $userservice =& ServiceFactory::getServiceInstance('UserService');
+ $userservice =SemanticScuttle_Service_Factory::getServiceInstance('User');
$user = $userservice->getUser($this->id);
$this->email = $user['email'];
}
@@ -621,7 +632,7 @@ class User {
function getHomepage() {
// Look for value only if not already set
if(!isset($this->homepage)) {
- $userservice =& ServiceFactory::getServiceInstance('UserService');
+ $userservice =SemanticScuttle_Service_Factory::getServiceInstance('User');
$user = $userservice->getUser($this->id);
$this->homepage = $user['homepage'];
}
@@ -631,7 +642,7 @@ class User {
function getContent() {
// Look for value only if not already set
if(!isset($this->content)) {
- $userservice =& ServiceFactory::getServiceInstance('UserService');
+ $userservice =SemanticScuttle_Service_Factory::getServiceInstance('User');
$user = $userservice->getUser($this->id);
$this->content = $user['uContent'];
}
@@ -641,7 +652,7 @@ class User {
function getDatetime() {
// Look for value only if not already set
if(!isset($this->content)) {
- $userservice =& ServiceFactory::getServiceInstance('UserService');
+ $userservice =SemanticScuttle_Service_Factory::getServiceInstance('User');
$user = $userservice->getUser($this->id);
$this->datetime = $user['uDatetime'];
}
@@ -651,14 +662,14 @@ class User {
function isAdmin() {
// Look for value only if not already set
if(!isset($this->isAdmin)) {
- $userservice =& ServiceFactory::getServiceInstance('UserService');
+ $userservice =SemanticScuttle_Service_Factory::getServiceInstance('User');
$this->isAdmin = $userservice->isAdmin($this->id);
}
return $this->isAdmin;
}
function getNbBookmarks($range = 'public') {
- $bookmarkservice =& ServiceFactory::getServiceInstance('BookmarkService');
+ $bookmarkservice =SemanticScuttle_Service_Factory::getServiceInstance('Bookmark');
return $bookmarkservice->countBookmarks($this->getId(), $range);
}
}