コード例 #1
0
 public static function createConditions($cond_array, $report_id)
 {
     $conditions = [];
     $ids = array_filter(ArrayHelper::getColumn($cond_array, 'id'));
     //*
     $known_cond = ArrayHelper::index(ReportsConditions::find()->where(['and', ['id' => $ids], ['report_id' => $report_id]])->orderBy('order')->with('report')->all(), 'id');
     //*/
     //        $known_cond =
     foreach ($cond_array as $k => $cond_params) {
         if ($cond_params['id'] && isset($known_cond[$cond_params['id']])) {
             $cond_item = $cond[$cond_params['id']];
             $cond_item->order = $k + 1;
             $conditions[] = $cond_item;
         } else {
             $conditions[] = new self(['report_id' => $report_id, 'order' => $k + 1]);
         }
     }
     return $conditions;
 }
コード例 #2
0
 protected function findCondition($id)
 {
     if (($model = ReportsConditions::findOne($id)) !== null) {
         return $model;
     } else {
         throw new NotFoundHttpException('The requested page does not exist.');
     }
 }
コード例 #3
0
 public function beforeDelete()
 {
     if (parent::beforeDelete()) {
         return ReportsConditions::deleteAll(['report_id' => $this->id]);
     } else {
         return false;
     }
 }
コード例 #4
0
    <?php 
echo $form->field($model, "operation")->dropDownList(ReportsConditions::getOperationsList());
?>

    <?php 
echo $form->field($model, "attribute_name")->dropDownList(ArrayHelper::map($model->report->availableProps, 'attribute', 'label'));
?>

    <?php 
if (isset($model->operation)) {
    ?>

        <?php 
    echo $form->field($model, "function")->dropDownList(array_map(function ($v) {
        return $v::getLabel();
    }, ReportsConditions::getFunctionsList($model->operation)), ['prompt' => Yii::t('reportmanager', 'Select...')]);
    ?>

        <?php 
    if ($model->functionObj->paramType) {
        ?>

            <?php 
        if (isset($model->config['values']) && is_array($model->config['values'])) {
            ?>
                <?php 
            echo $form->field($model, "value")->dropDownList($model->config['values'], ['prompt' => Yii::t('reportmanager', 'Select...'), 'multiple' => true, 'size' => 16]);
            ?>
            <?php 
        } else {
            ?>
コード例 #5
0
}], 'function', ['class' => 'yii\\grid\\ActionColumn', 'template' => '{delete}', 'buttons' => ['delete' => function ($url, $model, $key) {
    // <a href="/rep/delete?id=1" title="Удалить" aria-label="Удалить" data-confirm="Вы уверены, что хотите удалить этот элемент?" data-method="post" data-pjax="0"><span class="glyphicon glyphicon-trash"></span></a>
    return 1 === 1 ? Html::a('<span class="glyphicon glyphicon-trash"></span>', $url, ['title' => Yii::t('reportmanager', 'Delete')]) : '';
}]]]]);
?>
    <?php 
echo Html::submitButton(Yii::t('reportmanager', 'Save'), ['class' => 'btn btn-primary']);
ActiveForm::end();
Pjax::end();
?>
</div>
<?php 
$this->registerJs('
    $("#add_condition").click(function(event) {
        event.preventDefault();
        $.pjax.reload({container:"#conditions", type: "POST", push: false, replace: false});  //Reload GridView
/*
        var maxValue = Math.max.apply(Math,$(\'#table_conditions tbody tr\').map(function(){ return this.getAttribute("data-index");}));
        var number = maxValue + 1;
        var col1 = ' . json_encode(Html::dropDownList('ReportsConditions[_XXX_][attribute_name]', NULL, ArrayHelper::map($report->availableProps, 'attribute', 'label'), ['class' => 'form-control', 'id' => 'reportsconditions-_XXX_-attribute_name'])) . ';
        var col2 = ' . json_encode(Html::dropDownList('ReportsConditions[_XXX_][operation]', NULL, ReportsConditions::getOperationsList(), ['class' => 'form-control'])) . ';
        var html = \'<tr data-index="\' + number + \'">\' +
                \'<td>\' + col1 + \'</td>\' +
                \'<td>\' + col2 + \'</td>\' +
                \'<td></td>\' +
                \'<td></td>\' +
                \'</td>\';
        $("#table_conditions tbody").append(html.replace(/_XXX_/g,number));
*/
    })
');