Esempio n. 1
0
 /**
  * Returns an instance of class (singleton pattern implementation).
  *
  * @return BOL_EntityTagDao
  */
 public static function getInstance()
 {
     if (self::$classInstance === null) {
         self::$classInstance = new self();
     }
     return self::$classInstance;
 }
Esempio n. 2
0
 public function findTaggedPhotosByTagId($tagId, $first, $limit, $checkPrivacy = NULL)
 {
     if (empty($tagId)) {
         return array();
     }
     $condition = PHOTO_BOL_PhotoService::getInstance()->getQueryCondition('searchByHashtag', array('photo' => 'p', 'album' => 'a'));
     $sql = 'SELECT `p`.*, `a`.`userId`
         FROM `' . $this->getTableName() . '` AS `p`
             INNER JOIN `' . PHOTO_BOL_PhotoAlbumDao::getInstance()->getTableName() . '` AS `a` ON(`p`.`albumId` = `a`.`id`)
             INNER JOIN `' . BOL_EntityTagDao::getInstance()->getTableName() . '` AS `e` ON(`e`.`entityId` = `p`.`id`)
         ' . $condition['join'] . '
         WHERE `e`.`tagId` = :tagId AND `p`.`status` = :status AND ' . $condition['where'] . ($checkPrivacy !== NULL ? $checkPrivacy ? ' AND (`p`.`' . self::PRIVACY . '` = :everybody OR `p`.`' . self::PRIVACY . '` = :friends)' : ' AND `p`.`' . self::PRIVACY . '` = :everybody' : '') . '
         ORDER BY `p`.`id` DESC
         LIMIT :first, :limit';
     if ($checkPrivacy !== NULL) {
         switch ($checkPrivacy) {
             case TRUE:
                 $params['friends'] = self::PRIVACY_FRIENDS_ONLY;
             case FALSE:
                 $params['everybody'] = self::PRIVACY_EVERYBODY;
         }
     }
     return $this->dbo->queryForList($sql, array_merge($condition['params'], array('tagId' => $tagId, 'first' => (int) $first, 'limit' => (int) $limit, 'everybody' => PHOTO_BOL_PhotoDao::PRIVACY_EVERYBODY, 'status' => 'approved')));
 }
Esempio n. 3
0
 public function updatePhotoTags()
 {
     if (OW::getConfig()->getValue('photo', 'update_tag_process')) {
         $sql = 'SELECT `et`.`id`, `et`.`entityId`, `et`.`tagId`
             FROM `' . BOL_EntityTagDao::getInstance()->getTableName() . '` AS `et`
                 INNER JOIN `' . PHOTO_BOL_PhotoDao::getInstance()->getTableName() . '` AS `p` ON(`et`.`entityId` = `p`.`id`)
             WHERE `et`.`entityType` = :entityType AND
                 `et`.`id` NOT IN (SELECT `entityTagId` FROM `' . OW_DB_PREFIX . 'photo_update_tag`) AND
                 `p`.`dimension` IS NULL
             LIMIT :limit';
         $tagList = OW::getDbo()->queryForList($sql, array('entityType' => 'photo', 'limit' => 500));
         if (empty($tagList)) {
             OW::getConfig()->saveConfig('photo', 'update_tag_process', false);
             return;
         }
         $photoTagList = array();
         $tagIdList = array();
         foreach ($tagList as $tag) {
             if (!array_key_exists($tag['entityId'], $photoTagList)) {
                 $photoTagList[$tag['entityId']] = array();
             }
             $photoTagList[$tag['entityId']][] = $tag['tagId'];
             $tagIdList[] = $tag['id'];
         }
         foreach ($photoTagList as $photoId => $photoTag) {
             $tags = BOL_TagDao::getInstance()->findByIdList($photoTag);
             if (empty($tags)) {
                 continue;
             }
             $str = array();
             foreach ($tags as $tag) {
                 $str[] = '#' . implode('', array_map('trim', explode(' ', $tag->label)));
             }
             $photo = PHOTO_BOL_PhotoDao::getInstance()->findById($photoId);
             $photo->description .= ' ' . implode(' ', $str);
             PHOTO_BOL_PhotoDao::getInstance()->save($photo);
         }
         OW::getDbo()->query('INSERT IGNORE INTO `' . OW_DB_PREFIX . 'photo_update_tag`(`entityTagId`) VALUES(' . implode('),(', $tagIdList) . ');');
     }
 }
Esempio n. 4
0
 /**
  * Returns tag list with popularity for provided entity item.
  * 
  * @param integer $entityId
  * @param string $entityType
  * @return array
  */
 public function findEntityTagsWithPopularity($entityId, $entityType)
 {
     $query = "SELECT * FROM\n\t    \t\t(\n\t    \t\t\tSELECT `et`.*, COUNT(*) AS `count`, `t`.`label` AS `label` FROM `" . BOL_EntityTagDao::getInstance()->getTableName() . "` AS `et`\n\t\t\t\t\tINNER JOIN `" . $this->getTableName() . "` AS `t`\n\t\t\t\t\tON ( `et`.`tagId` = `t`.`id`)\n\t\t\t\t\tWHERE `et`.`entityId` = :entityId AND `et`.`entityType` = :entityType\n\t\t\t\t\tGROUP BY `tagId` ORDER BY `count` DESC\n\t\t\t\t) AS `t` \n\t\t\t\tORDER BY `t`.`label`";
     return $this->dbo->queryForList($query, array('entityId' => $entityId, 'entityType' => $entityType));
 }
Esempio n. 5
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. 6
0
 public function beforeTagDelete(OW_Event $event)
 {
     $params = $event->getParams();
     $tagId = $params['tagId'];
     $tag = UTAGS_BOL_Service::getInstance()->findTagById($tagId);
     if (empty($tagId) || $tag->entityType != UTAGS_BOL_Service::ENTITY_TYPE_CUSTOM) {
         return;
     }
     BOL_EntityTagDao::getInstance()->deleteById($tag->entityId);
 }
Esempio n. 7
0
 public function updateEntityItemStatus($entityType, $entityId, $status = true)
 {
     $this->entityTagDao->updateEntityStatus($entityType, (int) $entityId, (int) $status);
 }