Пример #1
0
 /**
  * Get user data.
  *
  * @param null|string|int $key
  * @return mixed|User
  */
 public function getUser($key = null)
 {
     $user = new User((array) $this->user());
     if ($key !== null) {
         return $user->get($key);
     }
     return $user;
 }
Пример #2
0
 /**
  * Upload user profile image.
  *
  * @param User $user
  */
 protected function _uploadAvatar(User $user)
 {
     if (isset($this->_tmpImage) && file_exists($this->_tmpImage['tmp_name'])) {
         $imageInfo = pathinfo($this->_tmpImage['name']);
         $imageName = 'orig_' . $user->get('id') . '.' . $imageInfo['extension'];
         $folderPath = $this->_path->entityFolderPath($user->get('id'), DS);
         $imagePath = $folderPath . $imageName;
         $Folder = new Folder();
         //  Delete user folder if upload new image.
         if (is_dir($folderPath)) {
             $Folder->delete($folderPath);
         }
         if (!is_dir($folderPath)) {
             $Folder->create($folderPath);
         }
         if (is_dir($folderPath) && move_uploaded_file($this->_tmpImage['tmp_name'], $imagePath)) {
             $user->set('image', $imageName);
             $thumbName = 'thumb_' . $user->get('id') . '.' . $imageInfo['extension'];
             //  Resize original image.
             $Resize = new ImageThumbnail($imagePath);
             $Resize->sizeWidth(450);
             $Resize->save($imagePath);
             //  Resize and crop thumb.
             $Thumbnail = new ImageThumbnail($imagePath);
             $Thumbnail->setResize(false);
             $Thumbnail->setSize($this->_config['thumbWidth'], $this->_config['thumbHeight']);
             $Thumbnail->save($folderPath . $thumbName);
         }
     }
 }