Commit | Line | Data |
---|---|---|
a5a4f02d | 1 | <?php |
a9229942 | 2 | |
a5a4f02d | 3 | namespace wcf\data\article; |
a9229942 | 4 | |
a5a4f02d | 5 | use wcf\data\like\ILikeObjectTypeProvider; |
a9229942 | 6 | use wcf\data\like\object\ILikeObject; |
a5a4f02d MW |
7 | use wcf\data\object\type\AbstractObjectTypeProvider; |
8 | use wcf\system\like\IViewableLikeProvider; | |
9 | use wcf\system\WCF; | |
10 | ||
11 | /** | |
12 | * Like Object type provider for cms articles. | |
13 | * | |
a9229942 TD |
14 | * @author Marcel Werk |
15 | * @copyright 2001-2019 WoltLab GmbH | |
16 | * @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php> | |
a9229942 | 17 | * @since 3.0 |
a5a4f02d | 18 | * |
a9229942 TD |
19 | * @method LikeableArticle getObjectByID($objectID) |
20 | * @method LikeableArticle[] getObjectsByIDs(array $objectIDs) | |
a5a4f02d | 21 | */ |
a9229942 TD |
22 | class LikeableArticleProvider extends AbstractObjectTypeProvider implements |
23 | ILikeObjectTypeProvider, | |
24 | IViewableLikeProvider | |
25 | { | |
26 | /** | |
27 | * @inheritDoc | |
28 | */ | |
29 | public $className = Article::class; | |
30 | ||
31 | /** | |
32 | * @inheritDoc | |
33 | */ | |
34 | public $listClassName = ArticleList::class; | |
35 | ||
36 | /** | |
37 | * @inheritDoc | |
38 | */ | |
39 | public $decoratorClassName = LikeableArticle::class; | |
40 | ||
41 | /** | |
42 | * @inheritDoc | |
43 | */ | |
44 | public function checkPermissions(ILikeObject $object) | |
45 | { | |
46 | /** @var LikeableArticle $object */ | |
47 | return $object->articleID && $object->canRead(); | |
48 | } | |
49 | ||
50 | /** | |
51 | * @inheritDoc | |
52 | */ | |
53 | public function prepare(array $likes) | |
54 | { | |
55 | $articleIDs = []; | |
56 | foreach ($likes as $like) { | |
57 | $articleIDs[] = $like->objectID; | |
58 | } | |
59 | ||
60 | // fetch articles | |
61 | $articleList = new ViewableArticleList(); | |
62 | $articleList->setObjectIDs($articleIDs); | |
63 | $articleList->readObjects(); | |
64 | $articles = $articleList->getObjects(); | |
65 | ||
66 | // set message | |
67 | foreach ($likes as $like) { | |
68 | if (isset($articles[$like->objectID])) { | |
69 | $article = $articles[$like->objectID]; | |
70 | ||
71 | // check permissions | |
72 | if (!$article->canRead()) { | |
73 | continue; | |
74 | } | |
75 | $like->setIsAccessible(); | |
76 | ||
77 | // short output | |
78 | $text = WCF::getLanguage()->getDynamicVariable('wcf.like.title.com.woltlab.wcf.likeableArticle', [ | |
79 | 'article' => $article, | |
80 | 'reaction' => $like, | |
81 | // @deprecated 5.3 Use `$reaction` instead | |
82 | 'like' => $like, | |
83 | ]); | |
84 | $like->setTitle($text); | |
85 | ||
86 | // output | |
87 | $like->setDescription($article->getTeaser()); | |
88 | } | |
89 | } | |
90 | } | |
a5a4f02d | 91 | } |