Beispiel #1
0
 public function create()
 {
     $isValid = false;
     $this->imageFile = UploadedFile::getInstance($this, 'imageFile');
     $user = User::findOne(Yii::$app->user->getId());
     $bulletin = new Bulletin();
     if (isset($this->imageFile)) {
         $imagePath = '/uploads/' . $this->imageFile->baseName . '.' . $this->imageFile->extension;
         $this->imageFile->saveAs(Yii::getAlias('@webroot') . $imagePath);
         $m_image = new Image();
         $m_image->url = $imagePath;
         if ($m_image->save()) {
             $image = Image::findOne($m_image->getPrimaryKey());
             $bulletin->link('image', $image);
             $bulletin->link('user', $user);
             $isValid = true;
         } else {
             $isValid = false;
         }
     }
     $bulletin->title = $this->title;
     $bulletin->description = $this->description;
     if ($bulletin->save()) {
         $isValid = true;
     } else {
         $isValid = false;
     }
     return $isValid;
 }
Beispiel #2
0
 /**
  * Signs user up.
  *
  * @return User|null the saved model or null if saving fails
  */
 public function signup()
 {
     if ($this->validate()) {
         $user = new User();
         $user->username = $this->username;
         $user->email = $this->email;
         $user->setPassword($this->password);
         $user->generateAuthKey();
         if ($user->save()) {
             $image = new Image();
             $image->url = "/uploads/none-avatar.png";
             $image->save();
             $profile = new Profile();
             $profile->link('user', $user);
             $profile->link('image', $image);
             $profile->save();
             return $user;
         }
     }
     return null;
 }
Beispiel #3
0
 public function save()
 {
     if ($this->validate()) {
         $isValid = false;
         $this->imageFile = UploadedFile::getInstance($this, 'imageFile');
         $user = User::findOne(Yii::$app->user->getId());
         if (isset($user->profile)) {
             $profile = Profile::findOne($user->profile->id);
         } else {
             $profile = new Profile();
         }
         if (isset($this->imageFile)) {
             $imagePath = '/uploads/' . $this->imageFile->baseName . '.' . $this->imageFile->extension;
             $this->imageFile->saveAs(Yii::getAlias('@webroot') . $imagePath);
             $m_image = new Image();
             $m_image->url = $imagePath;
             if ($m_image->save()) {
                 $image = Image::findOne($m_image->getPrimaryKey());
                 $profile->link('image', $image);
                 $isValid = true;
             } else {
                 $isValid = false;
             }
         }
         $profile->firstname = $this->firstname;
         $profile->lastname = $this->lastname;
         $profile->aboutme = $this->aboutme;
         $profile->link('user', $user);
         if ($profile->save()) {
             $isValid = true;
         } else {
             $isValid = false;
         }
         return $isValid;
     } else {
         return false;
     }
 }
Beispiel #4
0
 /**
  * @return \yii\db\ActiveQuery
  */
 public function getImage2()
 {
     return $this->hasOne(Image::className(), ['id' => 'image2']);
 }
Beispiel #5
0
 public function getImage()
 {
     return $this->hasOne(Image::className(), ['id' => 'image_id'])->viaTable(Profile::tableName(), ['user_id' => 'id']);
 }
Beispiel #6
0
 public function actionIndex()
 {
     $url_image = Image::getImageUrl();
     return $this->render('index');
 }
Beispiel #7
0
 /**
  * Finds the Image model based on its primary key value.
  * If the model is not found, a 404 HTTP exception will be thrown.
  *
  * @param integer $id
  *
  * @return Image the loaded model
  * @throws NotFoundHttpException if the model cannot be found
  */
 protected function findImageModel($id)
 {
     if ($id === null) {
         return new Image();
     }
     if (($model = Image::findOne($id)) !== null) {
         return $model;
     } else {
         throw new NotFoundHttpException('Запрошенная страница не найдена');
     }
 }