From: Joshua Rüsweg Date: Wed, 29 Aug 2018 13:04:54 +0000 (+0200) Subject: Add watched articles page X-Git-Tag: 5.2.0_Alpha_1~364^2~55 X-Git-Url: https://git.stricted.de/?a=commitdiff_plain;h=46c50ded50104ad89663af61a433e7652ad571f7;p=GitHub%2FWoltLab%2FWCF.git Add watched articles page See #2642 --- diff --git a/com.woltlab.wcf/menuItem.xml b/com.woltlab.wcf/menuItem.xml index 7944df241c..8b46b4c481 100644 --- a/com.woltlab.wcf/menuItem.xml +++ b/com.woltlab.wcf/menuItem.xml @@ -13,7 +13,12 @@ Articles com.woltlab.wcf.ArticleList - + + com.woltlab.wcf.ArticleList + Abonnierte Artikel + Watched Articles + com.woltlab.wcf.WatchedArticleList + com.woltlab.wcf.MainMenu Mitglieder diff --git a/com.woltlab.wcf/page.xml b/com.woltlab.wcf/page.xml index 8ae5f9c886..a8b1cf596a 100644 --- a/com.woltlab.wcf/page.xml +++ b/com.woltlab.wcf/page.xml @@ -518,6 +518,22 @@ Artikel + + system + wcf\page\WatchedArticleListPage + wcf\system\page\handler\WatchedArticleListPageHandler + Abonnierte Artikel + Watched Articles + module_article + com.woltlab.wcf.ArticleList + + + Watched Articles + + + Abonnierte Artikel + + system wcf\page\CategoryArticleListPage diff --git a/com.woltlab.wcf/templates/watchedArticleList.tpl b/com.woltlab.wcf/templates/watchedArticleList.tpl new file mode 100644 index 0000000000..51fa6ad904 --- /dev/null +++ b/com.woltlab.wcf/templates/watchedArticleList.tpl @@ -0,0 +1,117 @@ +{capture assign='headContent'} + {if $pageNo < $pages} + + {/if} + {if $pageNo > 1} + + {/if} +{/capture} + +{capture assign='headerNavigation'}> + {if ARTICLE_ENABLE_VISIT_TRACKING} +
  • + {/if} +{/capture} + +{capture assign='sidebarRight'} + {if !$labelGroups|empty} +
    +
    +

    {lang}wcf.label.label{/lang}

    + +
    +
    + {foreach from=$labelGroups item=labelGroup} + {if $labelGroup|count} +
    {$labelGroup->getTitle()}
    +
    +
      + +
    + +
    + {/if} + {/foreach} +
    +
    + +
    +
    +
    +
    + + + {/if} +{/capture} + +{include file='header'} + +{hascontent} +
    + {content} + {pages print=true assign='pagesLinks' controller='WatchedArticleList' link="pageNo=%d"} + {/content} +
    +{/hascontent} + +{if $objects|count} +
    + {include file='articleListItems'} +
    +{else} +

    {lang}wcf.global.noItems{/lang}

    +{/if} + +
    + {hascontent} +
    + {content}{@$pagesLinks}{/content} +
    + {/hascontent} + + {hascontent} + + {/hascontent} +
    + +{if ARTICLE_ENABLE_VISIT_TRACKING} + +{/if} + +{include file='footer'} diff --git a/wcfsetup/install/files/lib/data/article/ViewableArticle.class.php b/wcfsetup/install/files/lib/data/article/ViewableArticle.class.php index 0d48d4d22a..dd231f5ec8 100644 --- a/wcfsetup/install/files/lib/data/article/ViewableArticle.class.php +++ b/wcfsetup/install/files/lib/data/article/ViewableArticle.class.php @@ -52,6 +52,12 @@ class ViewableArticle extends DatabaseObjectDecorator { */ protected static $unreadArticles; + /** + * number of unread articles in watched categories + * @var integer + */ + protected static $unreadWatchedArticles; + /** * list of assigned labels * @var Label[] @@ -237,4 +243,51 @@ class ViewableArticle extends DatabaseObjectDecorator { return self::$unreadArticles; } + + /** + * Returns the number of unread articles in watched categories. + * + * @return integer + */ + public static function getWatchedUnreadArticles() { + if (self::$unreadWatchedArticles === null) { + self::$unreadWatchedArticles = 0; + + if (WCF::getUser()->userID) { + $unreadArticles = UserStorageHandler::getInstance()->getField('unreadWatchedArticles'); + + // cache does not exist or is outdated + if ($unreadArticles === null) { + $categoryIDs = ArticleCategory::getSubscribedCategoryIDs(); + if (!empty($categoryIDs)) { + $conditionBuilder = new PreparedStatementConditionBuilder(); + $conditionBuilder->add('article.categoryID IN (?)', [$categoryIDs]); + $conditionBuilder->add('article.time > ?', [VisitTracker::getInstance()->getVisitTime('com.woltlab.wcf.article')]); + $conditionBuilder->add('article.isDeleted = ?', [0]); + $conditionBuilder->add('article.publicationStatus = ?', [Article::PUBLISHED]); + $conditionBuilder->add('(article.time > tracked_visit.visitTime OR tracked_visit.visitTime IS NULL)'); + + $sql = "SELECT COUNT(*) + FROM wcf".WCF_N."_article article + LEFT JOIN wcf".WCF_N."_tracked_visit tracked_visit + ON (tracked_visit.objectTypeID = ".VisitTracker::getInstance()->getObjectTypeID('com.woltlab.wcf.article')." + AND tracked_visit.objectID = article.articleID + AND tracked_visit.userID = ".WCF::getUser()->userID.") + ".$conditionBuilder; + $statement = WCF::getDB()->prepareStatement($sql); + $statement->execute($conditionBuilder->getParameters()); + self::$unreadWatchedArticles = $statement->fetchSingleColumn(); + } + + // update storage unreadEntries + UserStorageHandler::getInstance()->update(WCF::getUser()->userID, 'unreadWatchedArticles', self::$unreadWatchedArticles); + } + else { + self::$unreadWatchedArticles = $unreadArticles; + } + } + } + + return self::$unreadWatchedArticles; + } } diff --git a/wcfsetup/install/files/lib/page/WatchedArticleListPage.class.php b/wcfsetup/install/files/lib/page/WatchedArticleListPage.class.php new file mode 100644 index 0000000000..0f365e41de --- /dev/null +++ b/wcfsetup/install/files/lib/page/WatchedArticleListPage.class.php @@ -0,0 +1,49 @@ + + * @package WoltLabSuite\Core\Page + * @since 3.2 + */ +class WatchedArticleListPage extends ArticleListPage { + /** + * @inheritDoc + */ + public $loginRequired = true; + + /** + * @inheritDoc + */ + public $controllerName = 'WatchedArticleList'; + + /** + * @inheritDoc + */ + public function readParameters() { + parent::readParameters(); + + if (empty(ArticleCategory::getSubscribedCategoryIDs())) { + throw new IllegalLinkException(); + } + + $this->canonicalURL = LinkHandler::getInstance()->getLink('WatchedArticleList', $this->controllerParameters, ($this->pageNo > 1 ? 'pageNo=' . $this->pageNo : '')); + } + + /** + * @inheritDoc + */ + protected function initObjectList() { + $this->objectList = new CategoryArticleList(ArticleCategory::getSubscribedCategoryIDs()); + + $this->applyFilters(); + } +} diff --git a/wcfsetup/install/files/lib/system/page/handler/WatchedArticleListPageHandler.class.php b/wcfsetup/install/files/lib/system/page/handler/WatchedArticleListPageHandler.class.php new file mode 100644 index 0000000000..15597444c7 --- /dev/null +++ b/wcfsetup/install/files/lib/system/page/handler/WatchedArticleListPageHandler.class.php @@ -0,0 +1,31 @@ + + * @package WoltLabSuite\Core\System\Page\Handler + * @since 3.2 + */ +class WatchedArticleListPageHandler extends AbstractMenuPageHandler { + /** @noinspection PhpMissingParentCallCommonInspection */ + /** + * @inheritDoc + */ + public function getOutstandingItemCount(/** @noinspection PhpUnusedParameterInspection */$objectID = null) { + return ARTICLE_ENABLE_VISIT_TRACKING ? ViewableArticle::getWatchedUnreadArticles() : 0; + } + + /** @noinspection PhpMissingParentCallCommonInspection */ + /** + * @inheritDoc + */ + public function isVisible($objectID = null) { + return !empty(ArticleCategory::getSubscribedCategoryIDs()); + } +}