abstract class Messaging_User_Object in Messaging 6.4
Messaging user's object
This will be the base class for all objects that:
- Have a user account associated
- Have language
Hierarchy
- class \Messaging_User_Object
Expanded class hierarchy of Messaging_User_Object
File
- includes/
messaging_object.class.inc, line 15 - Drupal Messaging Framework - Base classes
View source
abstract class Messaging_User_Object {
// User id and user object
public $uid;
protected $_user;
// Optional user name, when we are loading multiple rows ready for display
public $user_name;
// Language and language object
public $language;
protected $_language;
/**
* Constructor, with predefined array of data
*/
public function __construct($template = NULL) {
if ($template) {
foreach ($template as $key => $value) {
$this->{$key} = $value;
}
}
// Make sure all objects have language
if (!isset($this->language)) {
$this
->set_language();
}
}
/**
* Magic function. Set protected properties
*
* We have a problem when creating records. Serial fields are unset() by drupal_write_record
* For these fields, though they're public, when there's a __set function it is called too
*/
public function __set($name, $value) {
if ($name == 'uid' || $name == 'language') {
$this->{$name} = $value;
}
}
/**
* Get destination user
*/
public function get_user() {
if (!isset($this->_user) && isset($this->uid)) {
$this->_user = messaging_load_user($this->uid);
}
return isset($this->_user) ? $this->_user : NULL;
}
/**
* Get destination user name, either from user object or from a user_name property.
*
* When loading a listing of objects, we can save some queries by setting the user_name property
*/
public function get_user_name() {
if (!empty($this->_user)) {
$user = $this->_user;
}
elseif (!empty($this->user_name)) {
$user = new Stdclass();
$user->uid = $this->uid;
$user->name = $this->user_name;
}
else {
// Last resource, we do user loading
$user = $this
->get_user();
}
return $user ? theme('username', $user) : t('none');
}
/**
* Set user account
*
* @param $account
* User account or user id
*/
public function set_user($account) {
if (is_numeric($account)) {
$this->uid = $account;
$this->_user = NULL;
}
elseif (is_object($account)) {
$this->uid = $account->uid;
$this->_user = $account;
}
else {
$this->uid = 0;
$this->_user = $account;
}
}
/**
* Get language object
*/
public function get_language() {
if (!isset($this->_language)) {
$this
->set_language();
}
return $this->_language;
}
/**
* Set language object / property
*/
public function set_language($language = NULL) {
if ($language) {
$this->language = $language->language;
$this->_language = $language;
}
elseif (!empty($this->language) && ($languages = language_list()) && isset($languages[$this->language])) {
$this->_language = $languages[$this->language];
}
elseif ($account = $this
->get_user()) {
// Fallback to account language
return $this
->set_language(user_preferred_language($account));
}
else {
// Fallback to default language
return $this
->set_language(language_default());
}
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
Messaging_User_Object:: |
public | property | ||
Messaging_User_Object:: |
public | property | ||
Messaging_User_Object:: |
public | property | ||
Messaging_User_Object:: |
protected | property | ||
Messaging_User_Object:: |
protected | property | ||
Messaging_User_Object:: |
public | function | Get language object | |
Messaging_User_Object:: |
public | function | Get destination user | |
Messaging_User_Object:: |
public | function | Get destination user name, either from user object or from a user_name property. | |
Messaging_User_Object:: |
public | function | Set language object / property | |
Messaging_User_Object:: |
public | function | Set user account | |
Messaging_User_Object:: |
public | function | Constructor, with predefined array of data | |
Messaging_User_Object:: |
public | function | Magic function. Set protected properties |