Esempio n. 1
0
 public function uploadPhoto($file, $userId, $uploadDir = null)
 {
     if (empty($userId)) {
         throw new InvalidArgumentException("\$userId is empty!");
     }
     if (isset($this->config->maxPhotosCount) and $this->config->maxPhotosCount > 0) {
         $filter = new UserPhotosFilter();
         $filter->setUserId($userId);
         $filter->setStatusNotEqual(UserPhotoManager::MODERATION_STATUS_DECLINED);
         $userPhotos = $this->getPhotos($filter);
         if (count($userPhotos) >= $this->config->maxPhotosCount) {
             throw new UserPhotosException("Maximum photos volume reached for this user.", static::EXCEPTION_MAX_COUNT_REACHED);
         }
     }
     if ($uploadDir !== null) {
         $imageUploaderConfig = new Config();
         $imageUploaderConfig->uploadDir = $uploadDir;
         $image = ImageUploader::upload($file, null, $imageUploaderConfig);
     } else {
         $image = ImageUploader::upload($file);
     }
     $photo = new UserPhoto();
     $photo->fileName = $image->fileName;
     $photo->userId = $userId;
     $photo->status = self::MODERATION_STATUS_NEW;
     return $this->addPhoto($photo);
 }