total in serch model
This commit is contained in:
parent
3de2cb7a4a
commit
3daeae0293
@ -47,23 +47,9 @@ class UserCardController extends Controller
|
|||||||
$searchModel = new UserCardSearch();
|
$searchModel = new UserCardSearch();
|
||||||
$dataProvider = $searchModel->search(Yii::$app->request->queryParams);
|
$dataProvider = $searchModel->search(Yii::$app->request->queryParams);
|
||||||
|
|
||||||
$total = 0;
|
|
||||||
if(Yii::$app->request->queryParams)
|
|
||||||
foreach (Yii::$app->request->queryParams as $params) {
|
|
||||||
|
|
||||||
$total = \common\models\UserCard::find()->filterWhere([
|
|
||||||
'fio' => UserCard::getParameter($params, 'fio'),
|
|
||||||
'email' => UserCard::getParameter($params, 'email'),
|
|
||||||
'status' => UserCard::getParameter($params, 'status'),
|
|
||||||
'skills' => UserCard::getParameter($params, 'skills'),
|
|
||||||
])->sum('salary');
|
|
||||||
}
|
|
||||||
else $total = \common\models\UserCard::find()->sum('salary');
|
|
||||||
|
|
||||||
return $this->render('index', [
|
return $this->render('index', [
|
||||||
'searchModel' => $searchModel,
|
'searchModel' => $searchModel,
|
||||||
'dataProvider' => $dataProvider,
|
'dataProvider' => $dataProvider,
|
||||||
'total' => $total,
|
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -14,6 +14,7 @@ use backend\modules\card\models\UserCard;
|
|||||||
class UserCardSearch extends UserCard
|
class UserCardSearch extends UserCard
|
||||||
{
|
{
|
||||||
public $skills;
|
public $skills;
|
||||||
|
public $total;
|
||||||
/**
|
/**
|
||||||
* {@inheritdoc}
|
* {@inheritdoc}
|
||||||
*/
|
*/
|
||||||
@ -86,6 +87,10 @@ class UserCardSearch extends UserCard
|
|||||||
|
|
||||||
$query->orderBy('user_card.created_at DESC');
|
$query->orderBy('user_card.created_at DESC');
|
||||||
|
|
||||||
|
$sumQuery = clone $query;
|
||||||
|
|
||||||
|
$this->total = $sumQuery->sum('salary');
|
||||||
|
|
||||||
return $dataProvider;
|
return $dataProvider;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -8,7 +8,6 @@ use yii\widgets\ListView;
|
|||||||
/* @var $this yii\web\View */
|
/* @var $this yii\web\View */
|
||||||
/* @var $searchModel backend\modules\card\models\UserCardSearch */
|
/* @var $searchModel backend\modules\card\models\UserCardSearch */
|
||||||
/* @var $dataProvider yii\data\ActiveDataProvider */
|
/* @var $dataProvider yii\data\ActiveDataProvider */
|
||||||
/* @var $total */
|
|
||||||
|
|
||||||
$this->title = 'Профили';
|
$this->title = 'Профили';
|
||||||
$this->params['breadcrumbs'][] = $this->title;
|
$this->params['breadcrumbs'][] = $this->title;
|
||||||
@ -86,6 +85,6 @@ $this->params['breadcrumbs'][] = $this->title;
|
|||||||
['class' => 'yii\grid\ActionColumn'],
|
['class' => 'yii\grid\ActionColumn'],
|
||||||
],
|
],
|
||||||
]);
|
]);
|
||||||
echo "<h3>Сумма зарплат: " . $total . "</h3>";
|
echo "<h3>Сумма зарплат: " . $searchModel->total . "</h3>";
|
||||||
?>
|
?>
|
||||||
</div>
|
</div>
|
Loading…
Reference in New Issue
Block a user