Hello all i got a a report-bundle and a service AdminUsersStatsListBlockService that need a UserRepository.php within the report bundle to access function, i tried to add the BookingBundle.php within the report bundle to the construct function but i keep constructing without it here's my code and my errors:
HERE AdminUsersStatsListBlockService.php (so i tried to add the BookingRepository here):
<?php
/*
* This file is part of the Cocorico package.
*
* (c) Cocolabs SAS <[email protected]>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Cocorico\ReportBundle\Block\Service;
use Cocorico\BookingBundle\Entity\Booking;
use Cocorico\ReportBundle\Repository\UserRepository;
use Cocorico\ReportBundle\Repository\BookingRepository; /*(added)*/
use Sonata\AdminBundle\Admin\Pool;
use Sonata\AdminBundle\Form\FormMapper;
use Sonata\BlockBundle\Block\BlockContextInterface;
use Sonata\BlockBundle\Block\Service\AbstractBlockService;
use Sonata\BlockBundle\Model\BlockInterface;
use Sonata\CoreBundle\Validator\ErrorElement;
use Symfony\Bundle\FrameworkBundle\Templating\EngineInterface;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\OptionsResolver\OptionsResolver;
class AdminUsersStatsListBlockService extends AbstractBlockService
{
protected $userRepository;
protected $bookingRepository;/*(added)*/
protected $adminPool;
/**
* @param string $name
* @param EngineInterface $templating
* @param UserRepository $userRepository
* @param Pool $adminPool
* @param BookingRepository $bookingRepository/*(added)*/
*/
public function __construct(
$name,
EngineInterface $templating,
UserRepository $userRepository,
Pool $adminPool = null,
BookingRepository $bookingRepository/*(added)*/
) {
parent::__construct($name, $templating);
$this->userRepository = $userRepository;
$this->bookingRepository = $bookingRepository;/*(added)*/
$this->adminPool = $adminPool;
}
/**
* {@inheritdoc}
*/
public function execute(BlockContextInterface $blockContext, Response $response = null)
{
$stat = $blockContext->getSetting('stat');
switch ($stat) {
case 'offerers-expiring':
$results = $this->userRepository->getTopOfferersWithBookingsStatusCount(
Booking::STATUS_EXPIRED,
null,
null,
$blockContext->getSetting('limit')
);
break;
case 'offerers-refusing':
$results = $this->userRepository->getTopOfferersWithBookingsStatusCount(
Booking::STATUS_REFUSED,
null,
null,
$blockContext->getSetting('limit')
);
break;
case 'offerers-accepting':
$results = $this->userRepository->getTopOfferersWithBookingsStatusCount(
Booking::STATUS_PAYED,
null,
null,
$blockContext->getSetting('limit')
);
break;
case 'bookings-expired-list':
$results = $this->bookingRepository->getBookingsExpired(); /*there i want to use it*/
break;
default:
$results = array();
}
return $this->renderResponse(
$blockContext->getTemplate(),
array(
'block' => $blockContext->getBlock(),
'settings' => $blockContext->getSettings(),
'results' => $results,
'admin_pool' => $this->adminPool,
),
$response
);
}
}
Here's the error i get:
request.CRITICAL: Uncaught PHP Exception Symfony\Component\Debug\Exception\FatalThrowableError: "Type error: Too few arguments to function Cocorico\ReportBundle\Block\Service\AdminUsersStatsListBlockService::__construct(), 4 passed in /var/www/Symfony/var/cache/prod/Container7aqlalh/getCocoricoReport_Admin_Block_Users_StatsListService.php on line 13 and exactly 5 expected" at /var/www/Symfony/vendor/cocorico/report-bundle/Block/Service/AdminUsersStatsListBlockService.php line 40 {"exception":"[object] (Symfony\Component\Debug\Exception\FatalThrowableError(code: 0): Type error: Too few arguments to function Cocorico\ReportBundle\Block\Service\AdminUsersStatsListBlockService::__construct(), 4 passed in /var/www/Symfony/var/cache/prod/Container7aqlalh/getCocoricoReport_Admin_Block_Users_StatsListService.php on line 13 and exactly 5 expected at /var/www/Symfony/vendor/cocorico/report-bundle/Block/Service/AdminUsersStatsListBlockService.php:40)"} []
and the container still not constructing with the BookingRepository:
<?php
use Symfony\Component\DependencyInjection\Argument\RewindableGenerator;
// This file has been auto-generated by the Symfony Dependency Injection Component for internal use.
// Returns the public 'cocorico_report.admin.block.users.stats_list' shared service.
include_once $this->targetDirs[3].'/vendor/sonata-project/block-bundle/src/Block/BlockServiceInterface.php';
include_once $this->targetDirs[3].'/vendor/sonata-project/block-bundle/src/Block/Service/BlockServiceInterface.php';
include_once $this->targetDirs[3].'/vendor/sonata-project/block-bundle/src/Block/Service/AbstractBlockService.php';
include_once $this->targetDirs[3].'/vendor/cocorico/report-bundle/Block/Service/AdminUsersStatsListBlockService.php';
return $this->services['cocorico_report.admin.block.users.stats_list'] = new \Cocorico\ReportBundle\Block\Service\AdminUsersStatsListBlockService('cocorico_report.admin.block.users.stats_list', ${($_ = isset($this->services['templating']) ? $this->services['templating'] : $this->load('getTemplatingService.php')) && false ?: '_'}, ${($_ = isset($this->services['cocorico_report.user.repository']) ? $this->services['cocorico_report.user.repository'] : $this->load('getCocoricoReport_User_RepositoryService.php')) && false ?: '_'}, ${($_ = isset($this->services['sonata.admin.pool']) ? $this->services['sonata.admin.pool'] : $this->getSonata_Admin_PoolService()) && false ?: '_'});
Edit: found this, is this the loader ? :
services:
cocorico_report.admin.block.stats:
class: Cocorico\ReportBundle\Block\Service\AdminStatsBlockService
arguments:
- "cocorico_report.admin.block.stats"
- "@templating"
- "@cocorico_report.report.manager"
tags:
- { name: sonata.block }
cocorico_report.admin.block.users.stats_list:
class: Cocorico\ReportBundle\Block\Service\AdminUsersStatsListBlockService
arguments:
- "cocorico_report.admin.block.users.stats_list"
- "@templating"
- "@cocorico_report.user.repository"
- "@sonata.admin.pool"
tags:
- { name: sonata.block }
Thanks in advance for help!:)
Pool $adminPoolis optional, butBookingRepository $bookingRepositoryis not. Try switching them around.AdminUsersStatsListBlockService::__construct(). Sending, try searching forgrep -R AdminUsersStatsListBlockService *in your program root. It may just be loaded by the autoloader, in which case no changes are needed. But if you're loading it somewhere else, you may need to fix the arguments.