示例#1
0
 /**
  * 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]);
 }
示例#2
0
 public function actionEdit()
 {
     $data = Yii::$app->request->post('Record');
     $result = array();
     if (is_numeric($data['id']) && $data['id'] > 0) {
         $model = Record::findOne($data['id']);
         if (!$model) {
             $result['status'] = 0;
             $result['message'] = '未找到该记录';
         }
     } else {
         $model = new Record();
     }
     if ($model->load(Yii::$app->request->post())) {
         if ($model->save()) {
             $result['status'] = 1;
             $result['message'] = '保存成功';
         }
     }
     $errors = $model->getFirstErrors();
     if ($errors) {
         $result['status'] = 0;
         $result['message'] = current($errors);
     }
     return $this->renderJson($result);
 }
示例#3
0
 /**
  * Creates a new Record model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  * @return mixed
  */
 public function actionCreate()
 {
     $model = new Record();
     if ($model->load(Yii::$app->request->post()) && $model->save()) {
         return $this->redirect(['view', 'id' => $model->id]);
     } else {
         return $this->render('create', ['model' => $model]);
     }
 }
 public function actionIndex()
 {
     $model = new Record();
     if ($model->load(Yii::$app->request->post()) && $model->save()) {
         return $this->redirect('site/list');
     } else {
         $data = $model->departmentInfo();
         //if max count boys, we doesnt display department
         $department = [];
         foreach ($data as $key => $item) {
             if ($item['boys_count'] != $item['max_boys']) {
                 $department[$key] = $item['name'];
             }
         }
         return $this->render('index', ['model' => $model, 'data' => $data, 'department' => $department]);
     }
 }