Esempio n. 1
0
 public function post()
 {
     if ($this->validate()) {
         $image = new PhotoActiveRecord();
         $image->userId = Yii::$app->user->identity->id;
         $image->name = $this->name . '';
         $image->photo = file_get_contents($this->file->tempName);
         $image->posted = date('Y-m-d H-i-s');
         $imagick = new \Imagick();
         $imagick->readImageBlob($image->photo);
         $size = $imagick->getImageGeometry();
         if ($size['width'] > 800) {
             foreach ($imagick as $frame) {
                 $frame->thumbnailImage(800, 0);
             }
         }
         $image->thumbnail = $imagick->getImagesBlob();
         if (!$image->save()) {
             return false;
         }
         $tags = split(',', $this->tags);
         foreach ($tags as $item) {
             if ($item != '') {
                 $tag = new TagsActiveRecord();
                 $tag->photo = $image->id;
                 $tag->tag = trim($item);
                 if (!$tag->save()) {
                     return false;
                 }
             }
         }
         return true;
     }
     return false;
 }
Esempio n. 2
0
 public function register()
 {
     if ($this->validate()) {
         $user = new User();
         $user->username = $this->username;
         $user->password = $this->password;
         $user->fio = $this->fio;
         $user->pol = $this->pol;
         $user->birthday = $this->birthday;
         $user->country = $this->country;
         $user->place = $this->place;
         $user->email = $this->email;
         $user->registerDate = date('Y-m-d H:i:s');
         Yii::trace($this->birthday);
         Yii::trace($user->birthday . ' ' . $user->registerDate);
         if (!$user->save()) {
             return false;
         }
         if (!Yii::$app->user->login(User::findByUsername($this->username), 0)) {
             return false;
         }
         $photo = new PhotoActiveRecord();
         $photo->userId = Yii::$app->user->identity->id;
         $photo->photo = file_get_contents($this->photo->tempName);
         $imagick = new \Imagick();
         $imagick->readImageBlob($photo->photo);
         foreach ($imagick as $frame) {
             $frame->thumbnailImage(800, 0);
         }
         $photo->thumbnail = $imagick->getImagesBlob();
         $photo->posted = date('Y-m-d H:i:s');
         $photo->name = $this->fio;
         if (!$photo->save()) {
             return false;
         }
         $user->photo = $photo->id;
         $user->save();
         return true;
     }
     return false;
 }
Esempio n. 3
0
 public function search()
 {
     switch ($this->type) {
         case 'name':
             return PhotoActiveRecord::find()->where(['like', 'name', $this->text])->orderBy(['posted' => SORT_DESC])->asArray();
         case 'tag':
             $tags = TagsActiveRecord::find()->where(['like', 'tag', $this->text])->select(['photo'])->asArray();
             return PhotoActiveRecord::find()->where(['in', 'id', $tags])->orderBy(['posted' => SORT_DESC])->asArray();
         case 'users':
             return (new Query())->from('user')->where(['like', 'fio', $this->text])->join('left join', 'photo', 'user.photo = photo.id')->select(['id' => 'user.id', 'thumbnail' => 'photo.thumbnail', 'name' => 'fio', 'username', 'pol', 'email', 'registerDate'])->orderBy(['registerDate' => SORT_DESC]);
         case 'tags':
             return TagsActiveRecord::find()->where(['like', 'tag', $this->text])->select(['id', 'tag'])->distinct()->asArray();
         case 'comments':
             return (new Query())->from('comments')->join('join', 'user', 'comments.userId = user.id')->select(['id' => 'comments.id', 'photoId', 'body', 'created', 'fio'])->orderBy(['created' => SORT_DESC]);
     }
     return null;
 }
 public static function saveEditingPhoto($id)
 {
     $editable = EditingPhotoActiveRecord::findOne($id);
     if ($editable == null) {
         return null;
     }
     $photo = PhotoActiveRecord::findOne($editable->photoId);
     if ($photo == null) {
         return null;
     }
     $image = new Imagick();
     $image->readImageBlob($editable->photo);
     $image = EditingPhotoActiveRecord::filter($editable->filter, $image);
     if ($editable->reduceNoise != 0) {
         for ($i = 0; $i < $editable->reduceNoise; $i++) {
             foreach ($image as $frame) {
                 $frame->enhanceImage();
             }
         }
     }
     if ($editable->blur != 0) {
         foreach ($image as $frame) {
             $frame->blurImage($editable->blur, 5);
         }
     }
     if ($editable->brightness != 0) {
         foreach ($image as $frame) {
             $frame->modulateImage(100 + $editable->brightness, 100, 100);
         }
     }
     $photo->photo = $image->getImagesBlob();
     $photo->thumbnail = $editable->thumbnail;
     if ($photo->save()) {
         return $editable->delete();
     } else {
         return false;
     }
 }
Esempio n. 5
0
 public function actionDeleteimage()
 {
     if (Yii::$app->request->isPost && !Yii::$app->user->isGuest && Yii::$app->user->identity->role == 'admin') {
         $id = Yii::$app->request->post('id');
         if ($id != null) {
             return PhotoActiveRecord::findOne($id)->delete();
         }
     }
     return false;
 }
Esempio n. 6
0
 public static function userPhotos($userId)
 {
     return PhotoActiveRecord::find()->where(['userId' => $userId])->orderBy(['posted' => SORT_DESC])->asArray()->all();
 }
Esempio n. 7
0
 public function actionEdit($id)
 {
     $photo = PhotoActiveRecord::findOne($id);
     $editable = EditingPhotoActiveRecord::createEditingPhoto($photo->id);
     return $this->render('edit', ['photo' => $editable]);
 }