2929
3030namespace VuFind \Controller ;
3131
32- use VuFind \Db \Service \TagServiceInterface ;
3332use VuFind \Exception \BadRequest as BadRequestException ;
3433use VuFind \Exception \Forbidden as ForbiddenException ;
3534use VuFind \Exception \Mail as MailException ;
35+ use VuFind \Ratings \RatingsService ;
36+ use VuFind \Record \ResourcePopulator ;
3637use VuFind \RecordDriver \AbstractBase as AbstractRecordDriver ;
38+ use VuFind \Tags ;
3739use VuFindSearch \ParamBag ;
3840
3941use function in_array ;
@@ -163,13 +165,8 @@ public function addcommentAction()
163165 // something has gone wrong (or user submitted blank form) and we
164166 // should do nothing:
165167 if (!empty ($ comment )) {
166- $ table = $ this ->getTable ('Resource ' );
167- $ resource = $ table ->findResource (
168- $ driver ->getUniqueId (),
169- $ driver ->getSourceIdentifier (),
170- true ,
171- $ driver
172- );
168+ $ populator = $ this ->serviceLocator ->get (ResourcePopulator::class);
169+ $ resource = $ populator ->getOrCreateResourceForDriver ($ driver );
173170 $ commentsService = $ this ->getDbService (
174171 \VuFind \Db \Service \CommentsServiceInterface::class
175172 );
@@ -180,7 +177,8 @@ public function addcommentAction()
180177 $ driver ->isRatingAllowed ()
181178 && '0 ' !== ($ rating = $ this ->params ()->fromPost ('rating ' , '0 ' ))
182179 ) {
183- $ driver ->addOrUpdateRating ($ user ->getId (), intval ($ rating ));
180+ $ ratingsService = $ this ->serviceLocator ->get (RatingsService::class);
181+ $ ratingsService ->saveRating ($ driver , $ user ->getId (), intval ($ rating ));
184182 }
185183
186184 $ this ->flashMessenger ()->addMessage ('add_comment_success ' , 'success ' );
@@ -241,12 +239,11 @@ public function addtagAction()
241239
242240 // Save tags, if any:
243241 if ($ tags = $ this ->params ()->fromPost ('tag ' )) {
244- $ tagParser = $ this ->serviceLocator ->get (\VuFind \Tags::class);
245- $ this ->getDbService (TagServiceInterface::class)->addTagsToRecord (
246- $ driver ->getUniqueID (),
247- $ driver ->getSourceIdentifier (),
242+ $ tagHelper = $ this ->serviceLocator ->get (Tags::class);
243+ $ tagHelper ->addTagsToRecord (
244+ $ driver ,
248245 $ user ,
249- $ tagParser ->parse ($ tags )
246+ $ tagHelper ->parse ($ tags )
250247 );
251248 $ this ->flashMessenger ()
252249 ->addMessage (['msg ' => 'add_tag_success ' ], 'success ' );
@@ -281,9 +278,8 @@ public function deletetagAction()
281278
282279 // Save tags, if any:
283280 if ($ tag = $ this ->params ()->fromPost ('tag ' )) {
284- $ this ->getDbService (TagServiceInterface::class)->deleteTagsFromRecord (
285- $ driver ->getUniqueID (),
286- $ driver ->getSourceIdentifier (),
281+ $ this ->serviceLocator ->get (Tags::class)->deleteTagsFromRecord (
282+ $ driver ,
287283 $ user ,
288284 [$ tag ]
289285 );
@@ -323,7 +319,9 @@ public function ratingAction()
323319 ) {
324320 throw new BadRequestException ('error_inconsistent_parameters ' );
325321 }
326- $ driver ->addOrUpdateRating (
322+ $ ratingsService = $ this ->serviceLocator ->get (RatingsService::class);
323+ $ ratingsService ->saveRating (
324+ $ driver ,
327325 $ user ->getId (),
328326 '' === $ rating ? null : intval ($ rating )
329327 );
@@ -335,12 +333,10 @@ public function ratingAction()
335333 }
336334
337335 // Display the "add rating" form:
338- $ view = $ this ->createViewModel (
339- [
340- 'currentRating ' => $ user ? $ driver ->getRatingData ($ user ->getId ()) : null ,
341- ]
342- );
343- return $ view ;
336+ $ currentRating = $ user
337+ ? $ this ->serviceLocator ->get (RatingsService::class)->getRatingData ($ driver , $ user ->getId ())
338+ : null ;
339+ return $ this ->createViewModel (compact ('currentRating ' ));
344340 }
345341
346342 /**
@@ -420,9 +416,8 @@ protected function processSave()
420416 // Perform the save operation:
421417 $ driver = $ this ->loadRecord ();
422418 $ post = $ this ->getRequest ()->getPost ()->toArray ();
423- $ tagParser = $ this ->serviceLocator ->get (\VuFind \Tags::class);
424- $ post ['mytags ' ]
425- = $ tagParser ->parse ($ post ['mytags ' ] ?? '' );
419+ $ tagParser = $ this ->serviceLocator ->get (Tags::class);
420+ $ post ['mytags ' ] = $ tagParser ->parse ($ post ['mytags ' ] ?? '' );
426421 $ favorites = $ this ->serviceLocator
427422 ->get (\VuFind \Favorites \FavoritesService::class);
428423 $ results = $ favorites ->save ($ post , $ user , $ driver );
0 commit comments