Exemple #1
0
 public function afterAvatarChange(OW_Event $event)
 {
     $params = $event->getParams();
     $userId = $params['userId'];
     $avatar = $this->avatarService->findByUserId($userId);
     $uAvatar = new UAVATARS_BOL_Avatar();
     $uAvatar->avatarId = $avatar->id;
     $uAvatar->userId = $userId;
     $avatarPath = $this->avatarService->getAvatarPath($userId, 3);
     $tmpPath = OW::getPluginManager()->getPlugin("uavatars")->getPluginFilesDir() . uniqid("tmp-") . '.jpg';
     if (!OW::getStorage()->copyFileToLocalFS($avatarPath, $tmpPath)) {
         return;
     }
     $photoStatus = $avatar->status == "active" ? "approved" : "approval";
     $photoId = $this->photoBridge->addPhoto($userId, $tmpPath, "", null, false, $photoStatus);
     @unlink($tmpPath);
     if (empty($photoId)) {
         return;
     }
     $uAvatar->photoId = $photoId;
     $uAvatar->timeStamp = time();
     $avatarPreview = $this->avatarService->getAvatarPath($userId, 2);
     $fileName = $this->uAvatarsService->storeAvatarImage($avatarPreview);
     if (empty($fileName)) {
         return;
     }
     if (!empty($uAvatar->fileName)) {
         $userfilesDir = OW::getPluginManager()->getPlugin('uavatars')->getUserFilesDir();
         OW::getStorage()->removeFile($userfilesDir . $uAvatar->fileName);
     }
     $uAvatar->fileName = $fileName;
     $this->uAvatarsService->saveAvatar($uAvatar);
 }
Exemple #2
0
 public function afterAvatarChange(OW_Event $event)
 {
     $params = $event->getParams();
     $userId = $params['userId'];
     $avatar = $this->avatarService->findByUserId($userId);
     if ($params['upload']) {
         $uAvatar = new UAVATARS_BOL_Avatar();
         $uAvatar->avatarId = $avatar->id;
         $uAvatar->userId = $userId;
         $avatarPath = $this->avatarService->getAvatarPath($userId, 3);
         $photoId = $this->photoBridge->addPhoto($userId, $avatarPath);
         if (empty($photoId)) {
             return;
         }
         $uAvatar->photoId = $photoId;
         $uAvatar->timeStamp = time();
     } else {
         $uAvatar = $this->uAvatarsService->findLastByUserId($userId);
     }
     $avatarPreview = $this->avatarService->getAvatarPath($userId, 2);
     $fileName = $this->uAvatarsService->storeAvatarImage($avatarPreview);
     if (empty($fileName)) {
         return;
     }
     if (!empty($uAvatar->fileName)) {
         $userfilesDir = OW::getPluginManager()->getPlugin('uavatars')->getUserFilesDir();
         OW::getStorage()->removeFile($userfilesDir . $uAvatar->fileName);
     }
     $uAvatar->fileName = $fileName;
     $this->uAvatarsService->saveAvatar($uAvatar);
 }