66 * SPDX-License-Identifier: AGPL-3.0-or-later
77 */
88
9- namespace OCA \Polls \Reference ;
9+ namespace OCA \Polls \Provider ;
1010
1111use Exception ;
1212use OCA \Polls \AppInfo \Application ;
1313use OCA \Polls \Exceptions \ForbiddenException ;
1414use OCA \Polls \Exceptions \NotFoundException ;
1515use OCA \Polls \Service \PollService ;
16+ use OCP \Collaboration \Reference \ADiscoverableReferenceProvider ;
1617use OCP \Collaboration \Reference \IReference ;
17- use OCP \Collaboration \Reference \IReferenceProvider ;
18+ use OCP \Collaboration \Reference \ISearchableReferenceProvider ;
1819use OCP \Collaboration \Reference \Reference ;
1920use OCP \IL10N ;
2021use OCP \IURLGenerator ;
2122
22- class PollReferenceProvider implements IReferenceProvider {
23+ class ReferenceProvider extends ADiscoverableReferenceProvider implements ISearchableReferenceProvider {
2324
2425 /** @psalm-suppress PossiblyUnusedMethod */
2526 public function __construct (
@@ -38,7 +39,7 @@ public function matchReference(string $referenceText): bool {
3839 return ($ this ->extractPollId ($ referenceText ) !== 0 );
3940 }
4041
41- private function extractPollId ($ referenceText ): int {
42+ public function extractPollId (string $ referenceText ): int {
4243 $ matchingUrls = [
4344 $ this ->urlGenerator ->getAbsoluteURL ('/apps/ ' . Application::APP_ID . '/vote ' ), // poll url base without index.php
4445 $ this ->urlGenerator ->getAbsoluteURL ('/index.php/apps/ ' . Application::APP_ID . '/vote ' ), // poll url base with index.php
@@ -60,6 +61,10 @@ private function extractPollId($referenceText): int {
6061 public function resolveReference (string $ referenceText ): ?IReference {
6162 if ($ this ->matchReference ($ referenceText )) {
6263 $ pollId = $ this ->extractPollId ($ referenceText );
64+ $ expired = false ;
65+ $ expiry = 0 ;
66+ $ participated = false ;
67+
6368
6469 if ($ pollId ) {
6570 try {
@@ -69,6 +74,9 @@ public function resolveReference(string $referenceText): ?IReference {
6974 $ ownerId = $ poll ->getUser ()->getId ();
7075 $ ownerDisplayName = $ poll ->getUser ()->getDisplayName ();
7176 $ url = $ poll ->getVoteUrl ();
77+ $ expired = $ poll ->getExpired ();
78+ $ expiry = $ poll ->getExpire ();
79+ $ participated = $ poll ->getCurrentUserVotes () ? true : false ;
7280
7381 } catch (NotFoundException $ e ) {
7482 $ pollId = 0 ;
@@ -91,15 +99,11 @@ public function resolveReference(string $referenceText): ?IReference {
9199 return null ;
92100 }
93101
94- $ imageUrl = $ this ->urlGenerator ->getAbsoluteURL (
95- $ this ->urlGenerator ->imagePath (Application::APP_ID , 'polls.svg ' )
96- );
97-
98102 $ reference = new Reference ($ referenceText );
99103 $ reference ->setTitle ($ title );
100104 $ reference ->setDescription ($ description ? $ description : $ this ->l10n ->t ('No description available. ' ));
101- $ reference ->setImageUrl ($ imageUrl );
102- $ reference ->setRichObject (Application::APP_ID . '_poll_widget ' , [
105+ $ reference ->setImageUrl ($ this -> getIconUrl () );
106+ $ reference ->setRichObject (Application::APP_ID . '_reference_widget ' , [
103107 'id ' => $ pollId ,
104108 'poll ' => [
105109 'id ' => $ pollId ,
@@ -108,6 +112,9 @@ public function resolveReference(string $referenceText): ?IReference {
108112 'ownerDisplayName ' => $ ownerDisplayName ,
109113 'ownerId ' => $ ownerId ,
110114 'url ' => $ url ,
115+ 'expired ' => $ expired ,
116+ 'expiry ' => $ expiry ,
117+ 'participated ' => $ participated ,
111118 ],
112119 ]);
113120 return $ reference ;
@@ -129,4 +136,22 @@ public function getCachePrefix(string $referenceId): string {
129136 public function getCacheKey (string $ referenceId ): ?string {
130137 return $ this ->userId ?? '' ;
131138 }
139+ public function getId (): string {
140+ return Application::APP_ID ;
141+ }
142+ public function getTitle (): string {
143+ return $ this ->l10n ->t ('Poll ' );
144+ }
145+
146+ public function getIconUrl (): string {
147+ return $ this ->urlGenerator ->imagePath (Application::APP_ID , 'polls.svg ' );
148+ }
149+
150+ public function getOrder (): int {
151+ return 51 ;
152+ }
153+
154+ public function getSupportedSearchProviderIds (): array {
155+ return ['search-poll ' ];
156+ }
132157}
0 commit comments