Пример #1
0
 /**
  * Returns an instance of class (singleton pattern implementation).
  *
  * @return BOL_TagDao
  */
 public static function getInstance()
 {
     if (self::$classInstance === null) {
         self::$classInstance = new self();
     }
     return self::$classInstance;
 }
Пример #2
0
 /**
  * Adds new tags to global tag list.
  * Returns tag dto for every provided tag label.
  * If tag has 
  * 
  * @param array<string> $tagList
  * @return array<BOL_Tag>
  */
 public function updateTagList($tagList)
 {
     $tagList = $tagList;
     // TODO add bad words filter
     foreach ($tagList as $key => $value) {
         // TODO badwords filter + add to construction below
         if (trim($value) === '' || false) {
             unset($tagList[$key]);
             continue;
         }
         $tagList[$key] = $value;
         //TODO add process (remove html tags and  not allowed symbols)
     }
     $tagList = array_unique($tagList);
     $tagsInDb = empty($tagList) ? array() : $this->tagDao->findTagsByLabel($tagList);
     $tagsInDbLabels = array();
     /* @var $value BOL_Tag */
     foreach ($tagsInDb as $value) {
         $tagsInDbLabels[] = $value->getLabel();
     }
     if (sizeof($tagList) !== sizeof($tagsInDb)) {
         foreach ($tagList as $value) {
             if (!in_array($value, $tagsInDbLabels)) {
                 $newTag = new BOL_Tag();
                 $newTag->setLabel($value);
                 $this->tagDao->save($newTag);
                 $tagsInDb[] = $newTag;
             }
         }
     }
     return $tagsInDb;
 }
Пример #3
0
 /**
  * 
  * @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;
 }
Пример #4
0
 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)));
 }
Пример #5
0
 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));
 }
Пример #6
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) . ');');
     }
 }
Пример #7
0
 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);
 }