1 | <?php |
||
2 | |||
3 | namespace Elgg\Likes; |
||
4 | |||
5 | use Elgg\Services\AjaxResponse; |
||
6 | |||
7 | /** |
||
8 | * Ajax response handler |
||
9 | */ |
||
10 | class AjaxResponseHandler { |
||
11 | |||
12 | /** |
||
13 | * Alter ajax response to send back likes count |
||
14 | * |
||
15 | * @param string $hook Hook name (AjaxResponse::RESPONSE_HOOK) |
||
16 | * @param string $type 'all' |
||
17 | * @param \Elgg\Services\AjaxResponse $response Ajax response |
||
18 | * @param array $params Hook params |
||
19 | * |
||
20 | * @return void|\Elgg\Services\AjaxResponse |
||
21 | */ |
||
22 | public function __invoke($hook, $type, AjaxResponse $response, $params) { |
||
23 | $entity = get_entity(get_input('guid')); |
||
0 ignored issues
–
show
Bug
introduced
by
Loading history...
|
|||
24 | if (!$entity) { |
||
25 | return; |
||
26 | } |
||
27 | |||
28 | $response->getData()->likes_status = [ |
||
29 | 'guid' => $entity->guid, |
||
30 | 'count' => likes_count($entity), |
||
31 | 'count_menu_item' => elgg_view_menu_item(_likes_count_menu_item($entity)), |
||
32 | 'like_menu_item' => elgg_view_menu_item(_likes_menu_item($entity)), |
||
33 | 'is_liked' => DataService::instance()->currentUserLikesEntity($entity->guid), |
||
34 | ]; |
||
35 | |||
36 | return $response; |
||
37 | } |
||
38 | } |
||
39 |