/**
  * Upload an image
  *
  * @param integer $membershipId
  * @param array $image
  *      string name
  *      string type
  *      string tmp_name
  *      integer error
  *      integer size
  * @param string $oldImage
  * @param boolean $deleteImage
  * @throws \Membership\Exception\MembershipException
  * @return void
  */
 protected function uploadImage($membershipId, array $image, $oldImage = null, $deleteImage = false)
 {
     // upload the membership's image
     if (!empty($image['name'])) {
         // delete old image
         if ($oldImage) {
             if (true !== ($result = $this->deleteImage($oldImage))) {
                 throw new MembershipException('Image deleting failed');
             }
         }
         // upload a new one
         if (false === ($imageName = FileSystemUtility::uploadResourceFile($membershipId, $image, self::$imagesDir))) {
             throw new MembershipException('Avatar uploading failed');
         }
         // resize the image
         ImageUtility::resizeResourceImage($imageName, self::$imagesDir, (int) ApplicationSettingService::getSetting('membership_image_width'), (int) ApplicationSettingService::getSetting('membership_image_height'));
         $update = $this->update()->table('membership_level')->set(['image' => $imageName])->where(['id' => $membershipId]);
         $statement = $this->prepareStatementForSqlObject($update);
         $statement->execute();
     } elseif ($deleteImage && $oldImage) {
         // just delete the membership's image
         if (true !== ($result = $this->deleteImage($oldImage))) {
             throw new MembershipException('Image deleting failed');
         }
         $update = $this->update()->table('membership_level')->set(['image' => null])->where(['id' => $membershipId]);
         $statement = $this->prepareStatementForSqlObject($update);
         $statement->execute();
     }
 }
 /**
  * Upload an image
  *
  * @param integer $imageId
  * @param array $image
  *      string name
  *      string type
  *      string tmp_name
  *      integer error
  *      integer size
  * @param string $oldImage
  * @throws \MiniPhotoGallery\Exception\MiniPhotoGalleryException
  * @return void
  */
 protected function uploadImage($imageId, array $image, $oldImage = null)
 {
     if (!empty($image['name'])) {
         // delete an old image
         if ($oldImage) {
             if (true !== ($result = $this->deleteMiniPhotoGalleryImage($oldImage))) {
                 throw new MiniPhotoGalleryException('Image deleting failed');
             }
         }
         // upload the image
         if (false === ($imageName = FileSystemUtility::uploadResourceFile($imageId, $image, self::$imagesDir))) {
             throw new MiniPhotoGalleryException('Image uploading failed');
         }
         // resize the image
         ImageUtility::resizeResourceImage($imageName, self::$imagesDir, (int) SettingService::getSetting('miniphotogallery_thumbnail_width'), (int) SettingService::getSetting('miniphotogallery_thumbnail_height'), self::$thumbnailsDir);
         $update = $this->update()->table('miniphotogallery_image')->set(['image' => $imageName])->where(['id' => $imageId]);
         $statement = $this->prepareStatementForSqlObject($update);
         $statement->execute();
     }
 }
Exemplo n.º 3
0
 /**
  * Upload an avatar
  *
  * @param integer $userId
  * @param array $avatar
  *      string name
  *      string type
  *      string tmp_name
  *      integer error
  *      integer size
  * @param string $oldAvatar
  * @param boolean $deleteAvatar
  * @throws User\Exception\UserException
  * @return void
  */
 protected function uploadAvatar($userId, array $avatar, $oldAvatar = null, $deleteAvatar = false)
 {
     // upload the user's avatar
     if (!empty($avatar['name'])) {
         // delete old avatar
         if ($oldAvatar) {
             if (true !== ($result = $this->deleteUserAvatar($oldAvatar))) {
                 throw new UserException('Avatar deleting failed');
             }
         }
         // upload the new
         if (false === ($avatarName = FileSystemUtility::uploadResourceFile($userId, $avatar, self::$avatarsDir))) {
             throw new UserException('Avatar uploading failed');
         }
         // resize the avatar
         ImageUtility::resizeResourceImage($avatarName, self::$avatarsDir, (int) SettingService::getSetting('user_thumbnail_width'), (int) SettingService::getSetting('user_thumbnail_height'), self::$thumbnailsDir);
         ImageUtility::resizeResourceImage($avatarName, self::$avatarsDir, (int) SettingService::getSetting('user_avatar_width'), (int) SettingService::getSetting('user_avatar_height'));
         $update = $this->update()->table('user_list')->set(['avatar' => $avatarName])->where(['user_id' => $userId]);
         $statement = $this->prepareStatementForSqlObject($update);
         $statement->execute();
     } elseif ($deleteAvatar && $oldAvatar) {
         // just delete the user's avatar
         if (true !== ($result = $this->deleteUserAvatar($oldAvatar))) {
             throw new UserException('Avatar deleting failed');
         }
         $update = $this->update()->table('user_list')->set(['avatar' => ''])->where(['user_id' => $userId]);
         $statement = $this->prepareStatementForSqlObject($update);
         $statement->execute();
     }
 }
 /**
  * Upload an news image
  *
  * @param integer $newsId
  * @param array $image
  *      string name
  *      string type
  *      string tmp_name
  *      integer error
  *      integer size
  * @param string $oldImage
  * @param boolean $deleteImage
  * @throws \News\Exception\NewsException
  * @return void
  */
 protected function uploadImage($newsId, array $image, $oldImage = null, $deleteImage = false)
 {
     // upload the news's image
     if (!empty($image['name'])) {
         // delete an old image
         if ($oldImage) {
             if (true !== ($result = $this->deleteNewsImage($oldImage))) {
                 throw new NewsException('Image deleting failed');
             }
         }
         // upload the image
         if (false === ($imageName = FileSystemUtility::uploadResourceFile($newsId, $image, self::$imagesDir))) {
             throw new NewsException('Image uploading failed');
         }
         // resize the image
         ImageUtility::resizeResourceImage($imageName, self::$imagesDir, (int) SettingService::getSetting('news_thumbnail_width'), (int) SettingService::getSetting('news_thumbnail_height'), self::$thumbnailsDir);
         ImageUtility::resizeResourceImage($imageName, self::$imagesDir, (int) SettingService::getSetting('news_image_width'), (int) SettingService::getSetting('news_image_height'));
         $update = $this->update()->table('news_list')->set(['image' => $imageName])->where(['id' => $newsId]);
         $statement = $this->prepareStatementForSqlObject($update);
         $statement->execute();
     } elseif ($deleteImage && $oldImage) {
         // just delete the news's image
         if (true !== ($result = $this->deleteNewsImage($oldImage))) {
             throw new NewsException('Image deleting failed');
         }
         $update = $this->update()->table('news_list')->set(['image' => null])->where(['id' => $newsId]);
         $statement = $this->prepareStatementForSqlObject($update);
         $statement->execute();
     }
 }