This topic contains 3 replies, has 2 voices, and was last updated by Tyler 6 years, 7 months ago.
- Topic
Hi,
I’m trying, to create a datagrid with custom source.
But I did not found the doc about that https://oroinc.com/orocrm/documentation/2.3/reference/format/datagrids#sourcethe type of data source. Currently, the only available types are orm and search, but you can also implement your own data source. Each data source may come with its own options to configure how the data is fetched.
So try something :
create my service with the tag12tags:- { name: oro_datagrid.datasource, type: reward-point }Then call the type in datagrid.yml
1234datagrids:reward-points-grid:source:type: reward-pointMy serice :
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273class RewardPointDatasource implements DatasourceInterface{/** @var RewardPointUserActionRepository */protected $rewardPointUserActionRepository;/** @var Registry $doctrine */protected $doctrine;protected $userAction;public function __construct(Registry $doctrine, $userAction){$this->doctrine = $doctrine;$this->userAction = $userAction;}public function getCustomerActionRewardPointAction(){$data = [];$this->getRPUARepository();/** @var array $rewardPointUserActions */$rewardPointUserActions = $this->rewardPointUserActionRepository->findAll();/** @var RewardPointUserAction $rewardPointUserAction */foreach ($rewardPointUserActions as $rewardPointUserAction) {$rewardPointUserAction = $rewardPointUserAction->getEntityType();$rewardPointUserAction = $this->doctrine->getRepository($rewardPointUserAction);$action = $rewardPointUserAction->find((int)$rewardPointUserAction->getEntityId());$rewardPointStrategyContext = new RewardPointStrategyContext($action);$currentData = $rewardPointStrategyContext->getData();$currentData['user'] = $rewardPointUserAction->getCustomer()->getFirstName().' '.$rewardPointUserAction->getCustomer()->getLastName();$currentData['points'] = $rewardPointUserAction->getNbRewardPoint();$data[] = new ResultRecord($currentData);}return $data;}/*** @return ObjectRepository*/protected function getRPUARepository(){if (!$this->rewardPointUserActionRepository) {$this->rewardPointUserActionRepository = $this->doctrine->getRepository($this->userAction);}return $this->rewardPointUserActionRepository;}/*** Add source to datagrid** @param DatagridInterface $grid* @param array $config*/public function process(DatagridInterface $grid, array $config){$grid->setDatasource(clone $this);}/*** Returns data extracted via datasource** @return ResultRecordInterface[]*/public function getResults(){return $this->getCustomerActionRewardPointAction();}}But it’s not seem enter into my RewardPointDatasource. May there are something to do to call this, like a listener or ?
Have you got an example ?Thanks in advance.
The forum ‘OroCRM’ is closed to new topics and replies.