/**
  * @inheritdoc
  */
 protected function save($model)
 {
     /** @var $model \nineinchnick\sync\models\Transaction */
     if (!$model->save(false) || !$model->saveRelations(Yii::$app->getRequest()->getBodyParams())) {
         return false;
     }
     if ($model->uploadedFiles === null || empty($model->uploadedFiles)) {
         return true;
     }
     $number = $model->getFiles()->count();
     foreach ($model->uploadedFiles as $uploadedFile) {
         $file = new File();
         $content = file_get_contents($uploadedFile->tempName);
         $file->setAttributes(['number' => ++$number, 'url' => 'file://' . $uploadedFile->name, 'filename' => $uploadedFile->name, 'size' => $uploadedFile->size, 'content' => base64_encode($content), 'mimetype' => $uploadedFile->type, 'hash' => sha1($content), 'sent_on' => date('Y-m-d H:i:s')], false);
         $file->link('transaction', $model);
         if (!$file->save()) {
             $model->addError('uploadedFiles', Yii::t('nineinchnick/sync/app', 'Failed to save uploaded file.'));
             return false;
         }
     }
     return true;
 }
Ejemplo n.º 2
0
 /**
  * @return FileQuery
  */
 public function getResponse()
 {
     return $this->hasOne(File::className(), ['request_id' => 'id'])->inverseOf('request');
 }
Ejemplo n.º 3
0
 /**
  * @return MessageQuery
  */
 public function getFile()
 {
     return $this->hasOne(File::className(), ['id' => 'file_id'])->inverseOf('messages');
 }
Ejemplo n.º 4
0
 /**
  * @return TransactionQuery
  */
 public function getFiles()
 {
     return $this->hasMany(File::className(), ['transaction_id' => 'id'])->inverseOf('transaction');
 }