Added CMS pages to the search index
[GitHub/WoltLab/WCF.git] / wcfsetup / install / files / lib / system / search / PageSearch.class.php
1 <?php
2 namespace wcf\system\search;
3 use wcf\data\object\type\ObjectTypeCache;
4 use wcf\data\page\content\SearchResultPageContent;
5 use wcf\data\page\content\SearchResultPageContentList;
6 use wcf\form\IForm;
7 use wcf\system\database\util\PreparedStatementConditionBuilder;
8 use wcf\system\WCF;
9
10 /**
11 * An implementation of ISearchableObjectType for searching in cms pages.
12 *
13 * @author Marcel Werk
14 * @copyright 2001-2017 WoltLab GmbH
15 * @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
16 * @package WoltLabSuite\Core\System\Search
17 * @since 3.1
18 */
19 class PageSearch extends AbstractSearchableObjectType {
20 /**
21 * message data cache
22 * @var SearchResultPageContent[]
23 */
24 public $messageCache = [];
25
26 /**
27 * @inheritDoc
28 */
29 public function cacheObjects(array $objectIDs, array $additionalData = null) {
30 $list = new SearchResultPageContentList();
31 $list->setObjectIDs($objectIDs);
32 $list->readObjects();
33 foreach ($list->getObjects() as $content) {
34 $this->messageCache[$content->pageContentID] = $content;
35 }
36 }
37
38 /**
39 * @inheritDoc
40 */
41 public function getObject($objectID) {
42 if (isset($this->messageCache[$objectID])) {
43 return $this->messageCache[$objectID];
44 }
45
46 return null;
47 }
48
49 /**
50 * @inheritDoc
51 */
52 public function getTableName() {
53 return 'wcf'.WCF_N.'_page_content';
54 }
55
56 /**
57 * @inheritDoc
58 */
59 public function getIDFieldName() {
60 return $this->getTableName().'.pageContentID';
61 }
62
63 /**
64 * @inheritDoc
65 */
66 public function getSubjectFieldName() {
67 return $this->getTableName().'.title';
68 }
69
70 /**
71 * @inheritDoc
72 */
73 public function getUsernameFieldName() {
74 return "''";
75 }
76
77 /**
78 * @inheritDoc
79 */
80 public function getTimeFieldName() {
81 return 'wcf'.WCF_N.'_page_content.pageContentID';
82 }
83
84 /** @noinspection PhpMissingParentCallCommonInspection */
85 /**
86 * @inheritDoc
87 */
88 public function getConditions(IForm $form = null) {
89 $conditionBuilder = new PreparedStatementConditionBuilder();
90 $conditionBuilder->add('wcf'.WCF_N.'_page.pageType IN (?) AND wcf'.WCF_N.'_page.isDisabled = ?', [['text', 'html'], 0]);
91
92 // acl
93 $objectTypeID = ObjectTypeCache::getInstance()->getObjectTypeIDByName('com.woltlab.wcf.acl.simple', 'com.woltlab.wcf.page');
94 $conditionBuilder->add('(
95 wcf'.WCF_N.'_page_content.pageID NOT IN (
96 SELECT objectID FROM wcf' . WCF_N . '_acl_simple_to_group WHERE objectTypeID = ?
97 UNION
98 SELECT objectID FROM wcf' . WCF_N . '_acl_simple_to_user WHERE objectTypeID = ?
99 )
100 OR
101 wcf'.WCF_N.'_page_content.pageID IN (
102 SELECT objectID FROM wcf' . WCF_N . '_acl_simple_to_group WHERE objectTypeID = ? AND groupID IN (?)
103 UNION
104 SELECT objectID FROM wcf' . WCF_N . '_acl_simple_to_user WHERE objectTypeID = ? AND userID = ?
105 )
106 )', [$objectTypeID, $objectTypeID, $objectTypeID, WCF::getUser()->getGroupIDs(), $objectTypeID, WCF::getUser()->userID]);
107
108 return $conditionBuilder;
109 }
110
111 /** @noinspection PhpMissingParentCallCommonInspection */
112 /**
113 * @inheritDoc
114 */
115 public function getJoins() {
116 return 'INNER JOIN wcf'.WCF_N.'_page ON (wcf'.WCF_N.'_page.pageID = '.$this->getTableName().'.pageID)';
117 }
118 }