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