Filter for deleted articles
[GitHub/WoltLab/WCF.git] / wcfsetup / install / files / lib / acp / page / ArticleListPage.class.php
1 <?php
2 namespace wcf\acp\page;
3 use wcf\data\article\Article;
4 use wcf\data\article\ArticleList;
5 use wcf\data\article\ViewableArticleList;
6 use wcf\data\category\CategoryNodeTree;
7 use wcf\data\user\User;
8 use wcf\page\SortablePage;
9 use wcf\system\clipboard\ClipboardHandler;
10 use wcf\system\language\LanguageFactory;
11 use wcf\system\WCF;
12 use wcf\util\StringUtil;
13
14 /**
15 * Shows a list of cms articles.
16 *
17 * @author Marcel Werk
18 * @copyright 2001-2018 WoltLab GmbH
19 * @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
20 * @package WoltLabSuite\Core\Acp\Page
21 * @since 3.0
22 *
23 * @property ArticleList $objectList
24 */
25 class ArticleListPage extends SortablePage {
26 /**
27 * @inheritDoc
28 */
29 public $activeMenuItem = 'wcf.acp.menu.link.article.list';
30
31 /**
32 * @inheritDoc
33 */
34 public $objectListClassName = ViewableArticleList::class;
35
36 /**
37 * @inheritDoc
38 */
39 public $neededModules = ['MODULE_ARTICLE'];
40
41 /**
42 * @inheritDoc
43 */
44 public $neededPermissions = ['admin.content.article.canManageArticle', 'admin.content.article.canContributeArticle'];
45
46 /**
47 * @inheritDoc
48 */
49 public $defaultSortField = 'time';
50
51 /**
52 * @inheritDoc
53 */
54 public $defaultSortOrder = 'DESC';
55
56 /**
57 * @inheritDoc
58 */
59 public $validSortFields = ['articleID', 'title', 'time', 'views', 'comments'];
60
61 /**
62 * @inheritDoc
63 */
64 public $itemsPerPage = 50;
65
66 /**
67 * category id
68 * @var integer
69 */
70 public $categoryID = 0;
71
72 /**
73 * name
74 * @var string
75 */
76 public $username = '';
77
78 /**
79 * title
80 * @var string
81 */
82 public $title = '';
83
84 /**
85 * content
86 * @var string
87 */
88 public $content = '';
89
90 /**
91 * display 'Add Article' dialog on load
92 * @var integer
93 */
94 public $showArticleAddDialog = 0;
95
96 /**
97 * publication status filter
98 * @var integer
99 */
100 public $publicationStatus = -1;
101
102 /**
103 * @var int
104 */
105 public $isDeleted = -1;
106
107 /**
108 * @inheritDoc
109 */
110 public function readParameters() {
111 parent::readParameters();
112
113 if (isset($_REQUEST['categoryID'])) $this->categoryID = intval($_REQUEST['categoryID']);
114 if (!empty($_REQUEST['username'])) $this->username = StringUtil::trim($_REQUEST['username']);
115 if (!empty($_REQUEST['title'])) $this->title = StringUtil::trim($_REQUEST['title']);
116 if (!empty($_REQUEST['content'])) $this->content = StringUtil::trim($_REQUEST['content']);
117 if (!empty($_REQUEST['showArticleAddDialog'])) $this->showArticleAddDialog = 1;
118 if (isset($_REQUEST['publicationStatus'])) $this->publicationStatus = intval($_REQUEST['publicationStatus']);
119 if (!empty($_REQUEST['isDeleted'])) $this->isDeleted = intval($_REQUEST['isDeleted']);
120 }
121
122 /**
123 * @inheritDoc
124 */
125 protected function initObjectList() {
126 parent::initObjectList();
127
128 if ($this->categoryID) {
129 $this->objectList->getConditionBuilder()->add('article.categoryID = ?', [$this->categoryID]);
130 }
131 if (!empty($this->username)) {
132 $user = User::getUserByUsername($this->username);
133 if ($user->userID) $this->objectList->getConditionBuilder()->add('article.userID = ?', [$user->userID]);
134 else $this->objectList->getConditionBuilder()->add('1=0');
135 }
136 if (!empty($this->title)) {
137 $this->objectList->getConditionBuilder()->add('article.articleID IN (SELECT articleID FROM wcf'.WCF_N.'_article_content WHERE title LIKE ?)', ['%'.$this->title.'%']);
138 }
139 if (!empty($this->content)) {
140 $this->objectList->getConditionBuilder()->add('article.articleID IN (SELECT articleID FROM wcf'.WCF_N.'_article_content WHERE content LIKE ?)', ['%'.$this->content.'%']);
141 }
142 if (!WCF::getSession()->getPermission('admin.content.article.canManageArticle')) {
143 // only show own articles
144 $this->objectList->getConditionBuilder()->add('article.userID = ?', [WCF::getUser()->userID]);
145
146 if (!WCF::getSession()->getPermission('admin.content.article.canManageOwnArticles')) {
147 // only show unpublished articles
148 $this->objectList->getConditionBuilder()->add('article.publicationStatus = ?', [Article::UNPUBLISHED]);
149 }
150 }
151
152 $this->objectList->sqlSelects = "(SELECT title FROM wcf".WCF_N."_article_content WHERE articleID = article.articleID AND (languageID IS NULL OR languageID = ".WCF::getLanguage()->languageID.") LIMIT 1) AS title";
153
154 if ($this->publicationStatus != -1) {
155 $this->objectList->getConditionBuilder()->add('article.publicationStatus = ?', [$this->publicationStatus]);
156 }
157
158 if ($this->isDeleted !== -1) {
159 $this->objectList->getConditionBuilder()->add('article.isDeleted = ?', [$this->isDeleted]);
160 }
161 }
162
163 /**
164 * @inheritDoc
165 */
166 public function assignVariables() {
167 parent::assignVariables();
168
169 WCF::getTPL()->assign([
170 'categoryID' => $this->categoryID,
171 'username' => $this->username,
172 'title' => $this->title,
173 'content' => $this->content,
174 'showArticleAddDialog' => $this->showArticleAddDialog,
175 'availableLanguages' => LanguageFactory::getInstance()->getLanguages(),
176 'categoryNodeList' => (new CategoryNodeTree('com.woltlab.wcf.article.category'))->getIterator(),
177 'publicationStatus' => $this->publicationStatus,
178 'hasMarkedItems' => ClipboardHandler::getInstance()->hasMarkedItems(ClipboardHandler::getInstance()->getObjectTypeID('com.woltlab.wcf.article')),
179 'isDeleted' => $this->isDeleted,
180 ]);
181 }
182 }