public function search($params, $personal = false) { $query = Boxtypes::find(); $dataProvider = new ActiveDataProvider(['query' => $query]); $this->load($params); return $dataProvider; }
public function actionDelete($id) { $model = Boxtypes::findOne($id); if ($model && !$model->boxes) { $model->deleted = true; $model->save(false); } return $this->redirect(Url::toRoute('boxtypes/index')); }
public function actionForm($id = NULL) { $model = $id ? Boxes::findOne($id) : new \app\models\Boxes(); if (Yii::$app->request->getQueryParam('project_id')) { $model->project_id = Yii::$app->request->getQueryParam('project_id'); } if ($model->load(Yii::$app->request->post())) { $model->imageFile = UploadedFile::getInstance($model, 'imageFile'); if ($model->validate()) { // Clusters $cluster = Yii::$app->request->post('Boxes')['cluster']; if ($cluster) { if (ProjectClusters::find()->byCluster($cluster)->exists()) { $model->cluster_id = ProjectClusters::find()->byCluster($cluster)->one()['id']; } else { $clusterModel = new ProjectClusters(); $clusterModel->cluster = $cluster; $clusterModel->link('project', $model->project); $clusterModel->save(); $model->cluster_id = $clusterModel->id; } } else { $model->cluster_id = NULL; } /* Image */ if ($model->imageFile) { $model->upload(); } if ($model->deleteImage && !$model->imageFile) { $model->picture = NULL; } $model->save(); return $this->redirect(Url::toRoute('boxes/detail/' . $model->id)); } else { if (isset($_POST['Boxes']['cluster'])) { $model->cluster = Yii::$app->request->post('Boxes')['cluster']; } } } return $this->render('form', ['model' => $model, 'user' => $this->user, 'users' => Users::find()->select(['id', new \yii\db\Expression("CONCAT(username, ' (', fullname, ')') as username")])->all(), 'boxtypes' => Boxtypes::find()->all(), 'projects' => Projects::find()->select(['id', 'name'])->hasRights()->all()]); }
public function getBoxtypes() { return $this->hasMany(Boxtypes::className(), ['id' => 'boxtype_id']); }
<?php use app\models\Boxtypes; use yii\bootstrap\Html; use yii\helpers\Url; $boxtypeModel = new Boxtypes(); ?> <div class="boxtype-detail"> <h1><?php echo Html::encode($boxtype->model); ?> </h1> <?php if (Yii::$app->user->getIdentity()->hasRole('administrator')) { ?> <a href="<?php echo Url::toRoute('boxtypes/form/' . $boxtype->id); ?> " class="btn btn-info"><?php echo Yii::t('app', 'Bewerken'); ?> </a> <?php if (!$boxtype->boxes) { ?> <a href="<?php echo Url::toRoute('boxtypes/delete/' . $boxtype->id); ?> " class="btn btn-danger" data-confirm="<?php
/* Boxtype shape other */ $(document).on('change', '.boxtype-form #boxtypes-shape', function() { if(<?php echo Boxtypes::BOX_SHAPE_OTHER; ?> == $(this).val()) { $('#shape_other_container').show(); } else { $('#shape_other_container').hide(); } }); /* Boxtype chamber count */ $(document).on('change', '.boxtype-form #boxtypes-shape', function() { var boxtypesWithChambers = <?php echo json_encode(Boxtypes::getChamberBoxtypeModels()); ?> ; if(boxtypesWithChambers.indexOf(parseInt($(this).val())) !== -1) { $('#chamber_count_container').show(); } else { $('#chamber_count_container').hide(); } }); /* Boxtype material other */ $(document).on('change', '.boxtype-form #boxtypes-material', function() { if(<?php echo Boxtypes::BOX_MATERIAL_OTHER; ?> == $(this).val()) {
<?php use fedemotta\datatables\DataTables; use yii\helpers\Url; use yii\helpers\Html; use app\models\Visits; use app\models\Observations; use app\models\Boxtypes; use app\models\ProjectClusters; ?> <div class="table-responsive"> <?php echo DataTables::widget(['dataProvider' => $dataProvider, 'filterModel' => $searchModel, 'columns' => [['attribute' => 'code', 'format' => 'html', 'value' => function ($model, $key, $index, $column) { return Html::a($model['code'], Url::toRoute('boxes/detail/' . $model['id'])); }], ['attribute' => 'boxtype_id', 'format' => 'html', 'label' => 'Boxtype', 'value' => function ($model, $key, $index, $column) { $boxType = $model['boxtype_id'] ? Boxtypes::findOne($model['boxtype_id']) : NULL; return $boxType ? Html::a($boxType->model, Url::toRoute('boxtypes/detail/' . $boxType->id)) : "-"; }], ['attribute' => 'cluster_id', 'format' => 'html', 'label' => 'Cluster', 'value' => function ($model, $key, $index, $column) { $cluster = $model['cluster_id'] ? ProjectClusters::findOne($model['cluster_id']) : NULL; return $cluster ? $cluster->cluster : '-'; }], ['attribute' => 'placement_date', 'label' => Yii::t('app', 'Plaatsingsdatum')], ['label' => Yii::t('app', 'Laatste waarneming'), 'value' => function ($model, $key, $index, $column) { if (($observationModel = Observations::find()->byBox($model['id'])->one()) !== NULL) { return Visits::findOne($observationModel->visit_id)->date; } else { return "-"; } }]], 'clientOptions' => ['info' => false, 'responsive' => true, 'dom' => 'lfTrtip', 'tableTools' => ['aButtons' => [['sExtends' => 'copy', 'sButtonText' => Yii::t('app', 'Copy to clipboard')], ['sExtends' => 'csv', 'sButtonText' => Yii::t('app', 'Save to CSV')], ['sExtends' => 'pdf', 'sButtonText' => Yii::t('app', 'Save to PDF')], ['sExtends' => 'print', 'sButtonText' => Yii::t('app', 'Print')]]]]]); ?> </div>