/** * Create Record model or update an existing Record model. Create Files and attach to Record model. * If update is successful, the browser will be redirected to the 'upload' page. * @return array|string|Response * @throws \yii\web\NotFoundHttpException */ public function run() { $recordId = Yii::$app->request->get('id'); if ($recordId) { $model = $this->controller()->findModel(Record::className(), $recordId); } else { $model = new Record(); $model->scenario = Record::SCENARIO_UPLOAD; } $model->user_id = Yii::$app->user->id; if (Yii::$app->request->isAjax && $model->load(Yii::$app->request->post())) { Yii::$app->response->format = Response::FORMAT_JSON; return ActiveForm::validate($model); } $post = Yii::$app->request->post(); if ($model->load($post) && $model->validate()) { if ($this->saveRecord($model, $post)) { Yii::$app->trigger(EventNames::UPLOAD_SUCCESS, new UploadEvent(['record' => $model, 'user_id' => Yii::$app->user->id])); } return $this->controller()->redirect(['upload', 'id' => $model->id]); } $media = self::media(); $uploadUrl = $media->uploadRoute; $handleUrl = $media->handleRoute; $dropZone = $media->dropZone; $maxFileSize = $media->maxFileSize; $maxChunkSize = $media->maxChunkSize; $acceptMimeTypes = $media->acceptMimeTypes; $view = $recordId ? 'edit' : 'upload'; return $this->controller()->render($view, ['model' => $model, 'handleUrl' => $handleUrl, 'uploadUrl' => $uploadUrl, 'dropZone' => $dropZone, 'maxFileSize' => $maxFileSize, 'maxChunkSize' => $maxChunkSize, 'acceptMimeTypes' => $acceptMimeTypes]); }
public function run($id = 0) { if (!$id) { $this->controller()->redirect(['search']); } $record = $this->controller()->findModel(Record::className(), $id); Yii::$app->view->params['aside'] = Timeline::widget(['stages' => self::collectCaseStages($record), 'remaining' => self::calculateRemainingDays($record)]); return $this->controller()->render('review', ['model' => $record, 'form' => $this->getForm($record)]); }
/** * @return \yii\db\ActiveQuery */ public function getRecord() { return $this->hasOne(Record::className(), ['user_id' => 'id']); }
public function getRecords() { return $this->hasMany(Record::className(), ['window_id' => 'id'])->inverseOf('window'); }
/** * Deletes an existing Record model. * If deletion is successful, the browser will be redirected to the 'index' page. * @param integer $id * @return mixed */ public function actionDelete($id) { $this->findModel(Record::className(), $id)->delete(); return $this->redirect(['manage']); }