I have created this so far:
getManager()->getRepository(CustomerModel::class);
}
public function getList($from, $to)
{
$builder = $this->getCustomerQueryBuilder();
$query = $builder->getQuery();
$paginator = $this->getManager()->createPaginator($query);
$totalResults = $paginator->count();
if($totalResults <= 0) {
throw new ApiException\NotFoundException('Error message');
}
$rawCustomerList = $paginator->getIterator()->getArrayCopy();
$customerList = array_map(function($customer){
$customer['lastlogin'] = date_timestamp_get($customer['lastlogin']);
return $customer;
}, $rawCustomerList);
return $customerList;
}
/**
* @return \Doctrine\ORM\QueryBuilder
*/
private function getCustomerQueryBuilder()
{
$builder = $this->getRepository()->createQueryBuilder('Customer');
$builder
->select('Customer.id as id')
->addSelect('Customer.email as email')
->addSelect('Customer.firstname as firstName')
->addSelect('Customer.lastname as lastName')
->addSelect('Customer.lastLogin as lastlogin')
->where('Customer.active = 1');
return $builder;
}
}
and in controller I have indexAction method:
public function indexAction()
{
$result = $this->resource->getList($from, $to);
// Response
$this->View()->assign(['success' => true, 'data' => $result]);
}
This will give me the list of ALL users and what i need is to set 2 parameters for date scope ($from, $to) and get all the users with lastLogin between those 2 dates.
But I don’t know how to add parameters in Action method. In docu says that there are only these actions and we can only set one parameter for some of them:
Action name Request type parameter
indexAction get request no
getAction get request id
batchAction put request no
putAction put request id
postAction post request data fields
batchDeleteAction delete request no
deleteAction delete request id