public function search($params, $personal = false) { $query = Boxtypes::find(); $dataProvider = new ActiveDataProvider(['query' => $query]); $this->load($params); return $dataProvider; }
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 actionIndex() { return $this->render('index', ['boxtypes' => Boxtypes::find()->all()]); }