Well the problem is that I can’t show everything because it’s licensed code.
I thought I gave quite everything that was needed, but maybe the controller part will help.
It’s actually really simple it’s just a classic ActiveController.
We have a route like this :
public function actionCompleteIndex()
{
$customerContact = $this->getCurrentCustomerContact();
$searchModel = new CandidateCompleteFilter();
$searchModel->customerContact = $customerContact;
return $searchModel->search(\Yii::$app->request->queryParams, $this->getCurrentCustomerContact());
}
Here is the Filter :
public function search($params, CustomerContact $customerContact): ActiveDataProvider
{
$this->load($params, '');
$query = Candidate::find()
->where(['=', 'candidate.unavailable', 0])
->groupBy('candidate.id');
$whereTo = 'WHERE customer_id = ' . $customerContact->customer_id . ' ';
if (isset($this->contract_since)) {
$to = (new \DateTime())->sub(new \DateInterval('P' . $this->contract_since . 'M'))->format('Y-m-d');
$whereTo .= " AND `to` > '" . $to . "' ";
}
$query
->leftJoin("(SELECT *, row_number() OVER (PARTITION BY candidate_id ORDER BY `to` DESC) AS rn
FROM contract
$whereTo) lastContract", 'rn = 1 AND lastContract.candidate_id = candidate.id')
;
$dataProvider = new ActiveDataProvider([
'query' => $query,
'pagination' => ['pageSize' => 50],
'sort' => [
'params' => array_merge(\Yii::$app->request->queryParams, ['#' => 'candidate']),
'defaultOrder' => [
'candidateFullName' => SORT_ASC,
],
'attributes' => [
'candidateFullName' => [
'asc' => ['candidateFullName' => new Expression('CONCAT_WS(" ", candidate.last_name, candidate.first_name) ASC')],
'desc' => ['candidateFullName' => new Expression('CONCAT_WS(" ", candidate.last_name, candidate.first_name) DESC')],
],
],
],
]);
$query->andWhere('lastContract.id IS NOT NULL');
$countQuery = clone $query;
$countQuery->select('COUNT(*) as count');
$dataProvider->setTotalCount($countQuery->createCommand()->query()->read()['count']);
return $dataProvider;
}
(I know the query is a bit dirty but you do what you have to do for performances)
And then the Candidate object is just a Model extending the common one, removing some fields and adding lastContract as an extraField :
public function extraFields()
{
return ['lastContract'];
}
(and you already have the relations)
I don’t know what else i can give to you. The route where the bug appears is candidate/complete-index, so everything else is plain framework code for me. Thank you for helping tho