Example #1
0
 public function save()
 {
     if (isset($this->reading) and $this->reading != '') {
         $savemodel = new Calibration();
         $savemodel->measure = 'mm';
         $savemodel->height = $this->reading;
         $savemodel->sensorid = $this->sensorid;
         $savemodel->datetime = $this->date;
         $savemodel->youremail = $this->youremail;
         $savemodel->yourname = $this->yourname;
         $result = $savemodel->save();
         $this->id = $savemodel->sensorid;
         return $result;
     } else {
         $savemodel = new File();
         $savemodel->sensorid = $this->sensorid;
         $savemodel->startdate = $this->date;
         $savemodel->enddate = $this->date;
         $savemodel->status = 'processed';
         $this->file = UploadedFile::getInstance($this, 'file');
         $savemodel->extension = end(explode(".", $this->file->name));
         $result = $savemodel->save();
         // save to get the ID
         $savemodel->filename = $savemodel->id . "_" . $this->file->name;
         $path = Yii::getAlias('@app') . Yii::$app->params['uploadPath'] . $savemodel->filename;
         if ($result) {
             $this->file->saveAs($path);
         }
         $result = $savemodel->save();
         $this->id = $savemodel->sensorid;
         return $result;
     }
 }
Example #2
0
 /**
 * Creates data provider instance with search query applied
 *
 * @param array $params
 *
 * @return ActiveDataProvider
 */
 public function search($params)
 {
     $query = Calibration::find();
     $dataProvider = new ActiveDataProvider(['query' => $query]);
     $this->load($params);
     if (!$this->validate()) {
         // uncomment the following line if you do not want to any records when validation fails
         // $query->where('0=1');
         return $dataProvider;
     }
     $query->andFilterWhere(['id' => $this->id, 'datetime' => $this->datetime, 'height' => $this->height, 'sensorid' => $this->sensorid]);
     $query->andFilterWhere(['like', 'measure', $this->measure])->andFilterWhere(['like', 'yourname', $this->yourname])->andFilterWhere(['like', 'youremail', $this->youremail]);
     return $dataProvider;
 }
 /**
 * Finds the Calibration model based on its primary key value.
 * If the model is not found, a 404 HTTP exception will be thrown.
 * @param integer $id
 * @return Calibration the loaded model
 * @throws HttpException if the model cannot be found
 */
 protected function findModel($id)
 {
     if (($model = Calibration::findOne($id)) !== null) {
         return $model;
     } else {
         throw new HttpException(404, 'The requested page does not exist.');
     }
 }
Example #4
0
 /**
  * @return \yii\db\ActiveQuery
  */
 public function getCalibrations()
 {
     return $this->hasMany(\app\models\Calibration::className(), ['sensorid' => 'id']);
 }