<defaultvalue>1</defaultvalue>
<options>module_trophy</options>
</option>
+ <option name="message_sidebar_enable_articles">
+ <categoryname>message.sidebar</categoryname>
+ <optiontype>boolean</optiontype>
+ <defaultvalue>1</defaultvalue>
+ </option>
<option name="message_sidebar_user_options">
<categoryname>message.sidebar</categoryname>
<optiontype>useroptions</optiontype>
<dd>{#$userProfile->trophyPoints}</dd>
{/if}
+ {if MESSAGE_SIDEBAR_ENABLE_ARTICLES && $userProfile->articles}
+ <dt><a href="{link controller='ArticleList' userID=$userProfile->userID}{/link}" class="jsTooltip" title="{lang user=$userProfile}wcf.article.showArticlesWritten{/lang}">{lang}wcf.user.articles{/lang}</a></dt>
+ <dd>{#$userProfile->articles}</dd>
+ {/if}
+
{event name='userCredits'}
{if MESSAGE_SIDEBAR_USER_OPTIONS && $userProfile->isAccessible('canViewProfile')}
define('MODULE_USER_COVER_PHOTO', 1);
define('IMAGE_ALLOW_EXTERNAL_SOURCE', 0);
define('MESSAGE_ENABLE_TOC', 1);
+define('MESSAGE_SIDEBAR_ENABLE_ARTICLES', 1);
UserStorageHandler::getInstance()->resetAll('unreadArticles');
}
+ if ($article->publicationStatus == Article::PUBLISHED) {
+ ArticleEditor::updateArticleCounter([$article->userID => 1]);
+ }
+
return $article;
}
if (ARTICLE_ENABLE_VISIT_TRACKING) {
UserStorageHandler::getInstance()->resetAll('unreadArticles');
}
+
+ $publicationStatus = (isset($this->parameters['data']['publicationStatus'])) ? $this->parameters['data']['publicationStatus'] : null;
+ if ($publicationStatus !== null) {
+ $usersToArticles = [];
+ /** @var ArticleEditor $articleEditor */
+ foreach ($this->objects as $articleEditor) {
+ if ($publicationStatus != $articleEditor->publicationStatus) {
+ // The article was published before or was now published.
+ if ($publicationStatus == Article::PUBLISHED || $articleEditor->publicationStatus == Article::PUBLISHED) {
+ if (!isset($usersToArticles[$articleEditor->userID])) {
+ $usersToArticles[$articleEditor->userID] = 0;
+ }
+
+ $usersToArticles[$articleEditor->userID] += ($publicationStatus == Article::PUBLISHED) ? 1 : -1;
+ }
+ }
+ }
+
+ if (!empty($usersToArticles)) {
+ ArticleEditor::updateArticleCounter($usersToArticles);
+ }
+ }
}
/**
* Publishes articles.
*/
public function publish() {
+ $usersToArticles = [];
foreach ($this->getObjects() as $articleEditor) {
$articleEditor->update([
'time' => TIME_NOW,
'publicationStatus' => Article::PUBLISHED,
'publicationDate' => 0
]);
+
+ if (!isset($usersToArticles[$articleEditor->userID])) {
+ $usersToArticles[$articleEditor->userID] = 0;
+ }
+
+ $usersToArticles[$articleEditor->userID]++;
}
+ ArticleEditor::updateArticleCounter($usersToArticles);
+
$this->unmarkItems();
}
* Unpublishes articles.
*/
public function unpublish() {
+ $usersToArticles = [];
foreach ($this->getObjects() as $articleEditor) {
$articleEditor->update(['publicationStatus' => Article::UNPUBLISHED]);
+
+ if (!isset($usersToArticles[$articleEditor->userID])) {
+ $usersToArticles[$articleEditor->userID] = 0;
+ }
+
+ $usersToArticles[$articleEditor->userID]--;
}
+ ArticleEditor::updateArticleCounter($usersToArticles);
+
$this->unmarkItems();
}
declare(strict_types=1);
namespace wcf\data\article;
use wcf\data\DatabaseObjectEditor;
+use wcf\system\WCF;
/**
* Provides functions to edit cms articles.
* @inheritDoc
*/
protected static $baseClass = Article::class;
+
+ /**
+ * Updates the article counter of the given user ids.
+ *
+ * @param int[] $users user id => article counter increase/decrease
+ * @since 3.2
+ */
+ public static function updateArticleCounter(array $users) {
+ $sql = "UPDATE wcf".WCF_N."_user
+ SET articles = articles + ?
+ WHERE userID = ?";
+ $statement = WCF::getDB()->prepareStatement($sql);
+ foreach ($users as $userID => $articles) {
+ $statement->execute([$articles, $userID]);
+ }
+ }
}
* @property-read integer $disableCoverPhoto is `1` if the user's cover photo has been disabled, otherwise `0`
* @property-read string $disableCoverPhotoReason reason why the user's cover photo is disabled
* @property-read integer $disableCoverPhotoExpires timestamp at which the user's cover photo will automatically be enabled again
+ * @property-read integer $articles number of articles written by the user
*/
final class User extends DatabaseObject implements IRouteController, IUserContent {
/**
use wcf\data\article\AccessibleArticleList;
use wcf\data\label\group\ViewableLabelGroup;
use wcf\data\object\type\ObjectTypeCache;
+use wcf\data\user\User;
+use wcf\system\exception\IllegalLinkException;
use wcf\system\label\LabelHandler;
use wcf\system\request\LinkHandler;
use wcf\system\WCF;
*/
public $controllerParameters = ['application' => 'wcf'];
+ /**
+ * @var User
+ * @since 3.2
+ */
+ public $user;
+
/**
* @inheritDoc
*/
}
}
+ if (!empty($_GET['userID'])) {
+ $this->user = new User(intval($_GET['userID']));
+ if (!$this->user->userID) {
+ throw new IllegalLinkException();
+ }
+
+ $this->controllerParameters['userID'] = $this->user->userID;
+ }
+
if (!empty($_POST)) {
$labelParameters = '';
if (!empty($this->labelIDs)) {
exit;
}
- $this->canonicalURL = LinkHandler::getInstance()->getLink('ArticleList', [], ($this->pageNo > 1 ? 'pageNo=' . $this->pageNo : ''));
+ $this->canonicalURL = LinkHandler::getInstance()->getLink('ArticleList', $this->controllerParameters, ($this->pageNo > 1 ? 'pageNo=' . $this->pageNo : ''));
}
/**
}
protected function applyFilters() {
+ if ($this->user) {
+ $this->objectList->getConditionBuilder()->add("article.userID = ?", [$this->user->userID]);
+ }
+
// filter by label
if (!empty($this->labelIDs)) {
$objectTypeID = ObjectTypeCache::getInstance()->getObjectTypeByName('com.woltlab.wcf.label.object', 'com.woltlab.wcf.article')->objectTypeID;
'labelGroups' => $this->labelGroups,
'labelIDs' => $this->labelIDs,
'controllerName' => $this->controllerName,
- 'controllerObject' => null
+ 'controllerObject' => null,
+ 'user' => $this->user
]);
}
}
// update activity points
UserActivityPointHandler::getInstance()->updateUsers($userIDs);
+ // update article counter
+ $conditionBuilder = new PreparedStatementConditionBuilder();
+ $conditionBuilder->add('user_table.userID IN (?)', [$userIDs]);
+ $sql = "UPDATE wcf".WCF_N."_user user_table
+ SET articles = (
+ SELECT COUNT(*)
+ FROM wcf".WCF_N."_article
+ WHERE userID = user_table.userID
+ )
+ ".$conditionBuilder;
+ $statement = WCF::getDB()->prepareStatement($sql);
+ $statement->execute($conditionBuilder->getParameters());
+
// update like counter
if (MODULE_LIKE) {
- $conditionBuilder = new PreparedStatementConditionBuilder();
- $conditionBuilder->add('user_table.userID IN (?)', [$userIDs]);
$sql = "UPDATE wcf".WCF_N."_user user_table
SET likesReceived = (
SELECT COUNT(*)
// update trophy points
if (MODULE_TROPHY) {
- $conditionBuilder = new PreparedStatementConditionBuilder();
- $conditionBuilder->add('user_table.userID IN (?)', [$userIDs]);
$sql = "UPDATE wcf".WCF_N."_user user_table
SET trophyPoints = (
SELECT COUNT(*)
<item name="wcf.article.sortField.time"><![CDATA[Datum]]></item>
<item name="wcf.article.sortField.views"><![CDATA[Zugriffe]]></item>
<item name="wcf.article.markAllAsRead"><![CDATA[Alle Artikel als gelesen markieren]]></item>
+ <item name="wcf.article.showArticlesWritten"><![CDATA[Artikel von {$user->username}]]></item>
</category>
<category name="wcf.attachment">
<item name="wcf.user.sortField.registrationDate"><![CDATA[Registrierungsdatum]]></item>
<item name="wcf.user.sortField.username"><![CDATA[Benutzername]]></item>
<item name="wcf.user.sortField.lastActivityTime"><![CDATA[Letzte Aktivität]]></item>
+ <item name="wcf.user.articles"><![CDATA[Artikel]]></item>
</category>
<category name="wcf.user.menu">
<item name="wcf.article.sortField.time"><![CDATA[Date]]></item>
<item name="wcf.article.sortField.views"><![CDATA[Views]]></item>
<item name="wcf.article.markAllAsRead"><![CDATA[Mark All Articles as Read]]></item>
+ <item name="wcf.article.showArticlesWritten"><![CDATA[Articles by {$user->username}]]></item>
</category>
<category name="wcf.attachment">
<item name="wcf.user.sortField.registrationDate"><![CDATA[Registration Date]]></item>
<item name="wcf.user.sortField.username"><![CDATA[Username]]></item>
<item name="wcf.user.sortField.lastActivityTime"><![CDATA[Last Activity]]></item>
+ <item name="wcf.user.articles"><![CDATA[Articles]]></item>
</category>
<category name="wcf.user.menu">
disableCoverPhoto TINYINT(1) NOT NULL DEFAULT 0,
disableCoverPhotoReason TEXT,
disableCoverPhotoExpires INT(10) NOT NULL DEFAULT 0,
+ articles INT(10) NOT NULL DEFAULT 0,
KEY username (username),
KEY email (email),