Esempio n. 1
0
 public function ajaxUpdatePhoto()
 {
     if (!OW::getRequest()->isAjax()) {
         exit;
     }
     $photoId = $_POST['photoId'];
     if ($this->photoService->findPhotoOwner($photoId) != OW::getUser()->getId() && !OW::getUser()->isAuthorized('photo', 'upload')) {
         exit(json_encode(array('result' => FALSE, 'msg' => OW::getLanguage()->text('photo', 'auth_edit_permissions'))));
     }
     $form = new PHOTO_CLASS_EditForm($photoId);
     if ($form->isValid($_POST)) {
         $values = $form->getValues();
         $userId = OW::getUser()->getId();
         $photo = $this->photoService->findPhotoById($values['photoId']);
         $album = $this->photoAlbumService->findAlbumById($photo->albumId);
         $isNewAlbum = FALSE;
         if (($albumName = htmlspecialchars(trim($values['album-name']))) != $album->name) {
             if (($album = $this->photoAlbumService->findAlbumByName($albumName, $userId)) === NULL) {
                 $album = new PHOTO_BOL_PhotoAlbum();
                 $album->name = $albumName;
                 $album->userId = $userId;
                 $album->entityId = $userId;
                 $album->entityType = 'user';
                 $album->createDatetime = time();
                 $album->description = !empty($values['description']) ? htmlspecialchars(trim($values['description'])) : '';
                 $this->photoAlbumService->addAlbum($album);
                 $isNewAlbum = TRUE;
             }
         }
         if ($photo->albumId != $album->id) {
             OW::getEventManager()->trigger(new OW_Event(PHOTO_CLASS_EventHandler::EVENT_BEFORE_PHOTO_MOVE, array('fromAlbum' => $photo->albumId, 'toAlbum' => $album->id, 'photoIdList' => array($photo->id))));
             if ($this->photoService->movePhotosToAlbum(array($photo->id), $album->id, $isNewAlbum)) {
                 OW::getEventManager()->trigger(new OW_Event(PHOTO_CLASS_EventHandler::EVENT_AFTER_PHOTO_MOVE, array('fromAlbum' => $photo->albumId, 'toAlbum' => $album->id, 'photoIdList' => array($photo->id))));
             }
         }
         $photo->albumId = $album->id;
         $photo->description = htmlspecialchars(trim($values['photo-desc']));
         if ($this->photoService->updatePhoto($photo)) {
             BOL_EntityTagDao::getInstance()->deleteItemsForEntityItem($photo->id, 'photo');
             BOL_TagService::getInstance()->updateEntityTags($photo->id, 'photo', $this->photoService->descToHashtag($photo->description));
             PHOTO_BOL_SearchService::getInstance()->deleteSearchItem(PHOTO_BOL_SearchService::ENTITY_TYPE_PHOTO, $photo->id);
             PHOTO_BOL_SearchService::getInstance()->addSearchIndex(PHOTO_BOL_SearchService::ENTITY_TYPE_PHOTO, $photo->id, $photo->description);
             $newPhoto = $this->photoService->findPhotoById($photo->id);
             exit(json_encode(array('result' => true, 'id' => $photo->id, 'description' => $photo->description, 'albumName' => $album->name, 'albumUrl' => OW::getRouter()->urlForRoute('photo_user_album', array('user' => OW::getUser()->getUserObject()->getUsername(), 'album' => $album->id)), 'msg' => OW::getLanguage()->text('photo', 'photo_updated'), 'msgApproval' => OW::getLanguage()->text('photo', 'photo_uploaded_pending_approval'), 'photo' => get_object_vars($newPhoto))));
         }
     } else {
         $result = array('result' => FALSE);
         $errors = array_filter($form->getErrors(), 'count');
         if (!empty($errors[key($errors)][0])) {
             $result['msg'] = $errors[key($errors)][0];
         }
         exit(json_encode($result));
     }
 }
Esempio n. 2
0
 public function ajaxUpdatePhoto()
 {
     if (OW::getRequest()->isAjax()) {
         $photoId = (int) $_POST['id'];
         $form = new PHOTO_CLASS_EditForm($photoId);
         if ($form->isValid($_POST)) {
             $values = $form->getValues();
             $photoService = PHOTO_BOL_PhotoService::getInstance();
             $albumService = PHOTO_BOL_PhotoAlbumService::getInstance();
             $photo = $photoService->findPhotoById($photoId);
             if ($photo) {
                 if (strlen($albumName = strip_tags(trim($values['album'])))) {
                     $userId = $photoService->findPhotoOwner($photoId);
                     if (!$userId) {
                         exit(json_encode(array('result' => false, 'id' => $photoId)));
                     }
                     $album = $albumService->findAlbumByName($albumName, $userId);
                     if (!$album) {
                         $album = new PHOTO_BOL_PhotoAlbum();
                         $album->name = $albumName;
                         $album->userId = $userId;
                         $album->createDatetime = time();
                         $albumService->addAlbum($album);
                     }
                     $albumId = $album->id;
                 } else {
                     exit(json_encode(array('result' => false)));
                 }
                 $photo->albumId = $albumId;
                 $photo->description = $values['description'];
                 BOL_TagService::getInstance()->updateEntityTags($photo->id, 'photo', $values['tags']);
                 if ($photoService->updatePhoto($photo)) {
                     exit(json_encode(array('result' => true, 'id' => $photo->id)));
                 }
             }
         }
     }
 }