AddStatsCommand.php
6 years ago
AddStatsCommandHandler.php
2 years ago
GetStatsCommand.php
7 years ago
GetStatsCommandHandler.php
2 years ago
AddStatsCommandHandler.php
71 lines
| 1 | <?php |
| 2 | /** |
| 3 | * @copyright © TMS-Plugins. All rights reserved. |
| 4 | * @licence See LICENCE.md for license details. |
| 5 | */ |
| 6 | |
| 7 | namespace AmeliaBooking\Application\Commands\Stats; |
| 8 | |
| 9 | use AmeliaBooking\Application\Commands\CommandHandler; |
| 10 | use AmeliaBooking\Application\Commands\CommandResult; |
| 11 | use AmeliaBooking\Application\Services\Stats\StatsService; |
| 12 | |
| 13 | /** |
| 14 | * Class AddStatsCommandHandler |
| 15 | * |
| 16 | * @package AmeliaBooking\Application\Commands\Stats |
| 17 | */ |
| 18 | class AddStatsCommandHandler extends CommandHandler |
| 19 | { |
| 20 | |
| 21 | /** |
| 22 | * @var array |
| 23 | */ |
| 24 | public $mandatoryFields = [ |
| 25 | 'providerId', |
| 26 | 'serviceId' |
| 27 | ]; |
| 28 | |
| 29 | /** |
| 30 | * @param AddStatsCommand $command |
| 31 | * |
| 32 | * @return CommandResult |
| 33 | * @throws \Slim\Exception\ContainerValueNotFoundException |
| 34 | * @throws \AmeliaBooking\Domain\Common\Exceptions\InvalidArgumentException |
| 35 | * @throws \Interop\Container\Exception\ContainerException |
| 36 | * @throws \AmeliaBooking\Infrastructure\Common\Exceptions\QueryExecutionException |
| 37 | */ |
| 38 | public function handle(AddStatsCommand $command) |
| 39 | { |
| 40 | $result = new CommandResult(); |
| 41 | |
| 42 | /** @var StatsService $statsAS */ |
| 43 | $statsAS = $this->container->get('application.stats.service'); |
| 44 | |
| 45 | $this->checkMandatoryFields($command); |
| 46 | |
| 47 | $data = [ |
| 48 | 'providerId' => $command->getField('providerId'), |
| 49 | 'serviceId' => $command->getField('serviceId'), |
| 50 | 'locationId' => $command->getField('locationId') |
| 51 | ]; |
| 52 | |
| 53 | $data = apply_filters('amelia_before_stats_added_filter', $data); |
| 54 | |
| 55 | do_action('amelia_before_stats_added', $data); |
| 56 | |
| 57 | $statsAS->addEmployeesViewsStats($data['providerId']); |
| 58 | |
| 59 | $statsAS->addServicesViewsStats($data['serviceId']); |
| 60 | |
| 61 | $statsAS->addLocationsViewsStats($data['locationId']); |
| 62 | |
| 63 | do_action('amelia_after_stats_added', $data); |
| 64 | |
| 65 | $result->setResult(CommandResult::RESULT_SUCCESS); |
| 66 | $result->setMessage('Successfully added stats.'); |
| 67 | |
| 68 | return $result; |
| 69 | } |
| 70 | } |
| 71 |