/** * @param Terms $termsAgg * @throws ErrorException */ private function addAggregation(Terms $termsAgg) { foreach ($this->aggregation as $parameter => $queryAttr) { $aggregationModel = new Aggregation(); $aggregationModel->parameter = $parameter; $aggregationModel->attributes = $queryAttr; $itemAgg = $aggregationModel->getElasticaAggregations(); $itemAgg->setField($parameter); $termsAgg->addAggregation($itemAgg); $this->aggregationList[] = ['type' => $aggregationModel->type, 'index' => $aggregationModel->getAggregationName(), 'title' => (string) $aggregationModel]; } }
/** * Adding query aggregation * * @return array */ public function actionAddAggregation() { $parameterId = \Yii::$app->request->post('parameterId'); if (!$parameterId || !in_array($parameterId, array_keys(Aggregation::getParameters()))) { return $this->replyError(Yii::t('analytics', 'Parameter not found')); } $aggregationModel = new Aggregation(); $aggregationModel->parameter = $parameterId; return $this->replyOk($this->renderPartial('forms/aggregation', ['aggregationModel' => $aggregationModel])); }
<?php echo Html::radioList('group[position]', Group::GROUP_VERTICAL, Group::getPositions()); ?> </div> <h3><?php echo Yii::t('analytics', 'Aggregations'); ?> </h3> <div class="panel panel-default analytycs-aggregation"> <div class="panel-body"> <div class="row"> <div class="col-md-4"> <?php $allAggregationParametrs = Aggregation::getParameters(); ?> <?php echo Html::dropDownList('aggregation', '', $allAggregationParametrs, ['size' => count($allAggregationParametrs), 'id' => 'aggregation-select']); ?> <div class="row"> <div class="col-md-12"> <?php echo Html::button(Yii::t('analytics', 'Add'), ['class' => 'btn btn-sm btn-block btn-primary']); ?> </div> </div> </div> <div class="col-md-8"> <div id="aggregationList"> <table class="table table-condensed table-striped"><tbody></tbody></table>
<?php use anmoroz\analytics\models\Aggregation; use yii\helpers\Html; ?> <tr id="parametr_aggregation_<?php echo $aggregationModel->parameter; ?> "> <td> <?php echo Aggregation::getParameters($aggregationModel->parameter); ?> </td> <td> <?php echo Html::dropDownList('aggregation[' . $aggregationModel->parameter . '][type]', $aggregationModel->type, Aggregation::getTypes(), ['class' => 'form-control input-small']); ?> </td> <td width="130"> <?php echo Html::textInput('aggregation[' . $aggregationModel->parameter . '][additionalValue]', $aggregationModel->additionalValue, ['class' => 'form-control jsAggrAdditionalValue', 'type' => 'number', 'min' => 1, 'max' => 100, 'style' => 'display: none;']); ?> </td> <?php echo $this->render('_deleteButtonCell'); ?> </tr>