/** * Constructor. * */ private function __construct() { $this->tagDao = BOL_TagDao::getInstance(); $this->entityTagDao = BOL_EntityTagDao::getInstance(); $this->configs[self::CONFIG_DEFAULT_TAGS_COUNT] = 20; $this->configs[self::CONFIG_MIN_FONT_SIZE] = 10; $this->configs[self::CONFIG_MAX_FONT_SIZE] = 30; }
/** * * @param int $photoId * @param int $tagText * @return BOL_EntityTag */ public function addTag($photoId, $tagText) { $tags = BOL_TagDao::getInstance()->findTagsByLabel(array($tagText)); if (empty($tags)) { $tag = new BOL_Tag(); $tag->label = $tagText; BOL_TagDao::getInstance()->save($tag); } else { $tag = $tags[0]; } $entityTagItem = new BOL_EntityTag(); $entityTagItem->setEntityId($photoId)->setEntityType(self::ENTITY_PHOTO)->setTagId($tag->getId()); BOL_EntityTagDao::getInstance()->save($entityTagItem); return $entityTagItem; }
public function getPhotoIdListByTagIdList($tagIdList) { if (empty($tagIdList)) { return array(); } $condition = PHOTO_BOL_PhotoService::getInstance()->getQueryCondition('searchByHashtag', array('photo' => 'photo', 'album' => 'album', 'tag' => 'tag', 'entityTag' => 'entity')); $sql = 'SELECT `p`.`id` FROM `' . $this->getTableName() . '` AS `p` INNER JOIN `' . BOL_EntityTagDao::getInstance()->getTableName() . '` AS `entity` ON(`entity`.`entityId` = `p`.`id`) INNER JOIN `' . BOL_TagDao::getInstance()->getTableName() . '` AS `tag` ON(`tag`.`id` = `entity`.`tagId`) INNER JOIN `' . PHOTO_BOL_PhotoAlbumDao::getInstance()->getTableName() . '` AS `album` ON(`p`.`albumId` = `album`.`id`) ' . $condition['join'] . ' WHERE `entity`.`entityType` = :entityType AND `tag`.`id` IN(' . implode(',', array_map('intval', $tagIdList)) . ') AND ' . $condition['where'] . ' ORDER BY 1 DESC'; return $this->dbo->queryForColumnList($sql, array_merge($condition['params'], array('entityType' => self::PHOTO_ENTITY_TYPE))); }
public function findEntityCountByTag($entityType, $tag) { $query = "SELECT COUNT(*) from `" . BOL_TagDao::getInstance()->getTableName() . "` AS `t` INNER JOIN `" . $this->getTableName() . "` AS `et` ON(`et`.`" . self::TAG_ID . "`=`t`.`id`)\n where `t`.`" . BOL_TagDao::LABEL . "` = :tag AND `et`.`" . self::ENTITY_TYPE . "` = :entityType AND `et`.`" . self::ACTIVE . "` = 1"; return (int) $this->dbo->queryForColumn($query, array('tag' => $tag, 'entityType' => $entityType)); }
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) . ');'); } }
public function getPhotoList($params) { $listType = $params['listType']; $page = !empty($params['offset']) ? abs((int) $params['offset']) : 1; $idList = !empty($params['idList']) ? $params['idList'] : array(); $photosPerPage = (int) OW::getConfig()->getValue('photo', 'photos_per_page'); switch ($listType) { case 'albumPhotos': $photos = $this->photoService->findPhotoListByAlbumId($params['albumId'], $page, $photosPerPage, $idList); break; case 'userPhotos': $photos = $this->photoService->findPhotoListByUserId($params['userId'], $page, $photosPerPage, $idList); break; case 'tag': $tags = BOL_TagDao::getInstance()->findTagsByLabel(array(ltrim($params['searchVal'], '#'))); if (empty($tags)) { $photos = array(); break; } $params['id'] = $tags[0]->id; case 'hash': $photos = $this->photoService->findTaggedPhotosByTagId($params['id'], $page, $photosPerPage); break; case 'user': $photos = $this->photoService->findPhotoListByUserId($params['id'], $page, $photosPerPage); break; case 'desc': $photos = $this->photoService->findPhotoListByDesc($params['searchVal'], $params['id'], $page, $photosPerPage); break; case 'latest': case 'featured': case 'toprated': case 'most_discussed': $photos = $this->photoService->findPhotoListByUserId(ow::getUser()->getId(), $page, $photosPerPage, $idList); // $photos = $this->photoService->findPhotoList($listType, $page, $photosPerPage); break; default: $event = new OW_Event('photo.getPhotosByListType', array('listType' => $listType, 'page' => $page, 'photosPerPage' => $photosPerPage), array()); OW::getEventManager()->trigger($event); $photos = $event->getData(); break; } return $this->generatePhotoList($photos); }