if ($this->isDismissed === null) {
if (WCF::getUser()->userID) {
- UserStorageHandler::getInstance()->loadStorage(array(WCF::getUser()->userID));
- $dismissedNotices = UserStorageHandler::getInstance()->getStorage(array(WCF::getUser()->userID), 'dismissedNotices');
- if ($dismissedNotices[WCF::getUser()->userID] === null) {
+ $dismissedNotices = UserStorageHandler::getInstance()->getField('dismissedNotices');
+ if ($dismissedNotices === null) {
$sql = "SELECT noticeID
FROM wcf".WCF_N."_notice_dismissed
WHERE userID = ?";
UserStorageHandler::getInstance()->update(WCF::getUser()->userID, 'dismissedNotices', serialize($noticeIDs));
}
else {
- $dismissedNoticeIDs = @unserialize($dismissedNotices[WCF::getUser()->userID]);
+ $dismissedNoticeIDs = @unserialize($dismissedNotices);
$this->isDismissed = in_array($this->noticeID, $dismissedNoticeIDs);
}
}
$this->groupIDs = UserGroup::getGroupIDsByType(array(UserGroup::GUESTS, UserGroup::EVERYONE));
}
else {
- // load storage data
- UserStorageHandler::getInstance()->loadStorage(array($this->userID));
-
// get group ids
- $data = UserStorageHandler::getInstance()->getStorage(array($this->userID), 'groupIDs');
+ $data = UserStorageHandler::getInstance()->getField('groupIDs', $this->userID);
// cache does not exist or is outdated
- if ($data[$this->userID] === null || $skipCache) {
+ if ($data === null || $skipCache) {
$this->groupIDs = array();
$sql = "SELECT groupID
FROM wcf".WCF_N."_user_to_group
}
}
else {
- $this->groupIDs = unserialize($data[$this->userID]);
+ $this->groupIDs = unserialize($data);
}
}
$this->languageIDs = array();
if ($this->userID) {
- // load storage data
- UserStorageHandler::getInstance()->loadStorage(array($this->userID));
-
// get language ids
- $data = UserStorageHandler::getInstance()->getStorage(array($this->userID), 'languageIDs');
+ $data = UserStorageHandler::getInstance()->getField('languageIDs', $this->userID);
// cache does not exist or is outdated
- if ($data[$this->userID] === null) {
+ if ($data === null) {
$sql = "SELECT languageID
FROM wcf".WCF_N."_user_to_language
WHERE userID = ?";
UserStorageHandler::getInstance()->update($this->userID, 'languageIDs', serialize($this->languageIDs));
}
else {
- $this->languageIDs = unserialize($data[$this->userID]);
+ $this->languageIDs = unserialize($data);
}
}
else if (!WCF::getSession()->spiderID) {
$this->followingUserIDs = array();
if ($this->userID) {
- // load storage data
- UserStorageHandler::getInstance()->loadStorage(array($this->userID));
-
// get ids
- $data = UserStorageHandler::getInstance()->getStorage(array($this->userID), 'followingUserIDs');
+ $data = UserStorageHandler::getInstance()->getField('followingUserIDs', $this->userID);
// cache does not exist or is outdated
- if ($data[$this->userID] === null) {
+ if ($data === null) {
$sql = "SELECT followUserID
FROM wcf".WCF_N."_user_follow
WHERE userID = ?";
UserStorageHandler::getInstance()->update($this->userID, 'followingUserIDs', serialize($this->followingUserIDs));
}
else {
- $this->followingUserIDs = unserialize($data[$this->userID]);
+ $this->followingUserIDs = unserialize($data);
}
}
}
$this->followerUserIDs = array();
if ($this->userID) {
- // load storage data
- UserStorageHandler::getInstance()->loadStorage(array($this->userID));
-
// get ids
- $data = UserStorageHandler::getInstance()->getStorage(array($this->userID), 'followerUserIDs');
+ $data = UserStorageHandler::getInstance()->getField('followerUserIDs', $this->userID);
// cache does not exist or is outdated
- if ($data[$this->userID] === null) {
+ if ($data === null) {
$sql = "SELECT userID
FROM wcf".WCF_N."_user_follow
WHERE followUserID = ?";
UserStorageHandler::getInstance()->update($this->userID, 'followerUserIDs', serialize($this->followerUserIDs));
}
else {
- $this->followerUserIDs = unserialize($data[$this->userID]);
+ $this->followerUserIDs = unserialize($data);
}
}
}
$this->ignoredUserIDs = array();
if ($this->userID) {
- // load storage data
- UserStorageHandler::getInstance()->loadStorage(array($this->userID));
-
// get ids
- $data = UserStorageHandler::getInstance()->getStorage(array($this->userID), 'ignoredUserIDs');
+ $data = UserStorageHandler::getInstance()->getField('ignoredUserIDs', $this->userID);
// cache does not exist or is outdated
- if ($data[$this->userID] === null) {
+ if ($data === null) {
$sql = "SELECT ignoreUserID
FROM wcf".WCF_N."_user_ignore
WHERE userID = ?";
UserStorageHandler::getInstance()->update($this->userID, 'ignoredUserIDs', serialize($this->ignoredUserIDs));
}
else {
- $this->ignoredUserIDs = unserialize($data[$this->userID]);
+ $this->ignoredUserIDs = unserialize($data);
}
}
}
if ($this->canSeeAvatar()) {
if ($this->avatarID) {
if (!$this->fileHash) {
- // load storage data
- UserStorageHandler::getInstance()->loadStorage(array($this->userID));
- $data = UserStorageHandler::getInstance()->getStorage(array($this->userID), 'avatar');
-
- if ($data[$this->userID] === null) {
+ $data = UserStorageHandler::getInstance()->getField('avatar', $this->userID);
+ if ($data === null) {
$this->avatar = new UserAvatar($this->avatarID);
UserStorageHandler::getInstance()->update($this->userID, 'avatar', serialize($this->avatar));
}
else {
- $this->avatar = unserialize($data[$this->userID]);
+ $this->avatar = unserialize($data);
}
}
else {
}
else {
// load storage data
- UserStorageHandler::getInstance()->loadStorage(array($this->userID));
- $data = UserStorageHandler::getInstance()->getStorage(array($this->userID), 'userRank');
+ $data = UserStorageHandler::getInstance()->getField('userRank', $this->userID);
- if ($data[$this->userID] === null) {
+ if ($data === null) {
$this->rank = new UserRank($this->rankID);
UserStorageHandler::getInstance()->update($this->userID, 'userRank', serialize($this->rank));
}
else {
- $this->rank = unserialize($data[$this->userID]);
+ $this->rank = unserialize($data);
}
}
}
* @return integer
*/
public function getOutstandingModerationCount() {
- // load storage data
- UserStorageHandler::getInstance()->loadStorage(array(WCF::getUser()->userID));
-
// get count
- $data = UserStorageHandler::getInstance()->getStorage(array(WCF::getUser()->userID), 'outstandingModerationCount');
- $count = $data[WCF::getUser()->userID];
+ $count = UserStorageHandler::getInstance()->getField('outstandingModerationCount');
// cache does not exist or is outdated
if ($count === null) {
$this->collapsedContent[$objectTypeID] = array();
if (WCF::getUser()->userID) {
- // get data from storage
- UserStorageHandler::getInstance()->loadStorage(array(WCF::getUser()->userID));
-
- // get ids
- $data = UserStorageHandler::getInstance()->getStorage(array(WCF::getUser()->userID), 'collapsedContent-'.$objectTypeID);
+ $data = UserStorageHandler::getInstance()->getField('collapsedContent-'.$objectTypeID);
// cache does not exist or is outdated
- if ($data[WCF::getUser()->userID] === null) {
+ if ($data === null) {
$sql = "SELECT objectID
FROM wcf".WCF_N."_user_collapsible_content
WHERE objectTypeID = ?
UserStorageHandler::getInstance()->update(WCF::getUser()->userID, 'collapsedContent-'.$objectTypeID, serialize($this->collapsedContent[$objectTypeID]));
}
else {
- $this->collapsedContent[$objectTypeID] = @unserialize($data[WCF::getUser()->userID]);
+ $this->collapsedContent[$objectTypeID] = @unserialize($data);
}
}
else {
$this->notificationCount = 0;
if (WCF::getUser()->userID) {
- // load storage data
- UserStorageHandler::getInstance()->loadStorage(array(WCF::getUser()->userID));
-
- // get ids
- $data = UserStorageHandler::getInstance()->getStorage(array(WCF::getUser()->userID), 'userNotificationCount');
+ $data = UserStorageHandler::getInstance()->getField('userNotificationCount');
// cache does not exist or is outdated
if ($data[WCF::getUser()->userID] === null || $skipCache) {
UserStorageHandler::getInstance()->update(WCF::getUser()->userID, 'userNotificationCount', serialize($this->notificationCount));
}
else {
- $this->notificationCount = unserialize($data[WCF::getUser()->userID]);
+ $this->notificationCount = unserialize($data);
}
}
}
return $data;
}
+ /**
+ * Returns the value of the given field for a certain user or null if no
+ * such value exists. If no userID is given, the id of the current user
+ * is used.
+ *
+ * In contrast to getStorage(), this method calls loadStorage() if no stored
+ * data for the user has been loaded yet!
+ *
+ * @param string $field
+ * @param integer $userID
+ * @return mixed
+ */
+ public function getField($field, $userID = null) {
+ if ($userID === null) {
+ $userID = WCF::getUser()->userID;
+ }
+
+ if (!$userID) {
+ return null;
+ }
+
+ // make sure stored data is loaded
+ if (!isset($this->cache[$userID])) {
+ $this->loadStorage(array($userID));
+ }
+
+ if (isset($this->cache[$userID][$field])) {
+ return $this->cache[$userID][$field];
+ }
+
+ return null;
+ }
+
/**
* Inserts new data records into database.
*
if ($this->userVisits === null) {
if (WCF::getUser()->userID) {
- // get data from storage
- UserStorageHandler::getInstance()->loadStorage(array(WCF::getUser()->userID));
-
- // get ids
- $data = UserStorageHandler::getInstance()->getStorage(array(WCF::getUser()->userID), 'trackedUserVisits');
+ $data = UserStorageHandler::getInstance()->getField('trackedUserVisits');
// cache does not exist or is outdated
- if ($data[WCF::getUser()->userID] === null) {
+ if ($data === null) {
$this->userVisits = array();
$sql = "SELECT objectTypeID, visitTime
FROM wcf".WCF_N."_tracked_visit_type
UserStorageHandler::getInstance()->update(WCF::getUser()->userID, 'trackedUserVisits', serialize($this->userVisits));
}
else {
- $this->userVisits = @unserialize($data[WCF::getUser()->userID]);
+ $this->userVisits = @unserialize($data);
}
}
else {