/** * Returns an instance of class. * * @return PHOTO_BOL_PhotoFeaturedDao */ public static function getInstance() { if (self::$classInstance === null) { self::$classInstance = new self(); } return self::$classInstance; }
/** * Deletes photo * * @param int $id * @return int */ public function deletePhoto($id) { /** @var $photo PHOTO_BOL_Photo */ if (!$id || !($photo = $this->photoDao->findById($id))) { return false; } $event = new OW_Event(PHOTO_CLASS_EventHandler::EVENT_BEFORE_PHOTO_DELETE, array('id' => $id)); OW::getEventManager()->trigger($event); if ($this->photoDao->deleteById($id)) { BOL_CommentService::getInstance()->deleteEntityComments('photo_comments', $id); BOL_RateService::getInstance()->deleteEntityRates($id, 'photo_rates'); BOL_TagService::getInstance()->deleteEntityTags($id, 'photo'); // remove files $this->photoDao->removePhotoFile($id, $photo->hash, 'main'); $this->photoDao->removePhotoFile($id, $photo->hash, 'preview'); $this->photoDao->removePhotoFile($id, $photo->hash, 'original'); $this->photoFeaturedDao->markUnfeatured($id); BOL_FlagService::getInstance()->deleteByTypeAndEntityId('photo', $id); OW::getEventManager()->trigger(new OW_Event('feed.delete_item', array('entityType' => 'photo_comments', 'entityId' => $id))); $this->cleanListCache(); $event = new OW_Event(PHOTO_CLASS_EventHandler::EVENT_ON_PHOTO_DELETE, array('id' => $id)); OW::getEventManager()->trigger($event); return true; } return false; }
/** * Deletes photo * * @param int $id * @return int */ public function deletePhoto($id, $totalAlbum = FALSE) { if (!$id || !($photo = $this->photoDao->findById($id))) { return false; } if ($totalAlbum === FALSE) { $event = new OW_Event(PHOTO_CLASS_EventHandler::EVENT_BEFORE_PHOTO_DELETE, array('id' => $id)); OW::getEventManager()->trigger($event); } if ($this->photoDao->deleteById($id)) { BOL_CommentService::getInstance()->deleteEntityComments('photo_comments', $id); BOL_RateService::getInstance()->deleteEntityRates($id, 'photo_rates'); BOL_TagService::getInstance()->deleteEntityTags($id, 'photo'); $this->photoDao->removePhotoFile($id, $photo->hash, self::TYPE_SMALL); $this->photoDao->removePhotoFile($id, $photo->hash, self::TYPE_PREVIEW); $this->photoDao->removePhotoFile($id, $photo->hash, self::TYPE_MAIN); $this->photoDao->removePhotoFile($id, $photo->hash, self::TYPE_FULLSCREEN); $this->photoDao->removePhotoFile($id, $photo->hash, self::TYPE_ORIGINAL); $this->photoFeaturedDao->markUnfeatured($id); BOL_FlagService::getInstance()->deleteByTypeAndEntityId(PHOTO_CLASS_ContentProvider::ENTITY_TYPE, $id); BOL_TagService::getInstance()->deleteEntityTags($id, PHOTO_BOL_PhotoDao::PHOTO_ENTITY_TYPE); $this->cleanListCache(); OW::getEventManager()->trigger(new OW_Event(PHOTO_CLASS_EventHandler::EVENT_ON_PHOTO_DELETE, array('id' => $id))); return TRUE; } return FALSE; }
public function getLastPhotoIdList($listType, $checkPrivacy, $photoId) { $privacy = $this->getPrivacyCondition($checkPrivacy); $privaceQuery = $privacy['query']; $condition = PHOTO_BOL_PhotoService::getInstance()->getQueryCondition($listType, array('photo' => 'p', 'album' => 'a', 'featured' => 'f')); $params = array_merge($condition['params'], array('status' => 'approved', 'limit' => PHOTO_BOL_PhotoService::ID_LIST_LIMIT), $privacy['params']); switch ($listType) { case 'latest': $sql = 'SELECT `p`.`id` FROM `' . $this->getTableName() . '` AS `p` INNER JOIN `' . PHOTO_BOL_PhotoAlbumDao::getInstance()->getTableName() . '` AS `a` ON(`a`.`id` = `p`.`albumId`) ' . $condition['join'] . ' WHERE `p`.`status` = :status' . $privaceQuery . ' AND ' . $condition['where'] . ' ORDER BY `p`.`id` DESC LIMIT :limit'; break; case 'userPhotos': $ownerId = PHOTO_BOL_PhotoService::getInstance()->findPhotoOwner($photoId); $sql = 'SELECT `p`.`id` FROM `' . $this->getTableName() . '` AS `p` INNER JOIN `' . PHOTO_BOL_PhotoAlbumDao::getInstance()->getTableName() . '` AS `a` ON(`a`.`id` = `p`.`albumId`) WHERE `p`.`status` = :status AND `a`.`userId` = :userId' . $privaceQuery . ' ORDER BY `p`.`id` DESC LIMIT :limit'; $params['userId'] = $ownerId; break; case 'entityPhotos': $photo = PHOTO_BOL_PhotoService::getInstance()->findPhotoById($photoId); $album = PHOTO_BOL_PhotoAlbumService::getInstance()->findAlbumById($photo->albumId); $sql = 'SELECT `p`.`id` FROM `' . $this->getTableName() . '` AS `p` INNER JOIN `' . PHOTO_BOL_PhotoAlbumDao::getInstance()->getTableName() . '` AS `a` ON(`a`.`id` = `p`.`albumId`) WHERE `p`.`status` = :status AND `a`.`entityId` = :entityId AND `a`.`entityType` = :entityType ' . $privaceQuery . ' ORDER BY `p`.`id` DESC LIMIT :limit'; $params['id'] = $photoId; $params['entityType'] = $album->entityType; $params['entityId'] = $album->entityId; break; case 'albumPhotos': $photo = PHOTO_BOL_PhotoService::getInstance()->findPhotoById($photoId); $sql = 'SELECT `p`.`id` FROM `' . $this->getTableName() . '` AS `p` INNER JOIN `' . PHOTO_BOL_PhotoAlbumDao::getInstance()->getTableName() . '` AS `a` ON(`a`.`id` = `p`.`albumId`) WHERE `p`.`status` = :status AND `p`.`albumId` = :albumId' . $privaceQuery . ' ORDER BY `p`.`id` DESC LIMIT :limit'; $params['albumId'] = $photo->albumId; break; case 'featured': $sql = 'SELECT `p`.`id` FROM `' . $this->getTableName() . '` AS `p` INNER JOIN `' . PHOTO_BOL_PhotoAlbumDao::getInstance()->getTableName() . '` AS `a` ON(`p`.`albumId` = `a`.`id`) INNER JOIN `' . PHOTO_BOL_PhotoFeaturedDao::getInstance()->getTableName() . '` AS `f` ON(`p`.`id` = `f`.`photoId`) ' . $condition['join'] . ' WHERE `f`.`photoId` < :id AND `p`.`status` = :status' . $privaceQuery . ' AND ' . $condition['where'] . ' ORDER BY `f`.`photoId` DESC LIMIT :limit'; $params['id'] = $photoId; break; } return $this->dbo->queryForColumnList($sql, $params); }
/** * Class constructor * */ private function __construct() { $this->photoFeaturedDao = PHOTO_BOL_PhotoFeaturedDao::getInstance(); }
/** * Count photos * * @param string $listtype * @param boolean $checkPrivacy * @return int */ public function countPhotosFeature($listtype, $checkPrivacy = true) { $privacyCond = $checkPrivacy ? " AND `p`.`privacy` = 'everybody' " : ""; switch ($listtype) { case 'featured': $featuredDao = PHOTO_BOL_PhotoFeaturedDao::getInstance(); $query = "\n SELECT COUNT(`p`.`id`) \n FROM `" . $this->getTableName() . "` AS `p`\n LEFT JOIN `" . $featuredDao->getTableName() . "` AS `f` ON ( `p`.`id` = `f`.`photoId` )\n WHERE `p`.`status` = 'approved' " . $privacyCond . " AND `f`.`id` IS NOT NULL\n "; return $this->dbo->queryForColumn($query); break; case 'latest': $example = new OW_Example(); $example->andFieldEqual('status', 'approved'); if ($checkPrivacy) { $example->andFieldEqual('privacy', 'everybody'); } return $this->countByExample($example); break; } }
/** * Count photos * * @param string $listtype * @param boolean $checkPrivacy * @param null $exclude * @return int */ public function countPhotos($listtype, $checkPrivacy = true, $exclude = null) { $privacyCond = $checkPrivacy ? " AND `p`.`privacy` = 'everybody' " : ""; $excludeCond = $exclude ? ' AND `p`.`id` NOT IN (' . $this->dbo->mergeInClause($exclude) . ')' : ''; $albumDao = PHOTO_BOL_PhotoAlbumDao::getInstance(); switch ($listtype) { case 'featured': $featuredDao = PHOTO_BOL_PhotoFeaturedDao::getInstance(); $query = "\n SELECT COUNT(`p`.`id`)\n FROM `" . $this->getTableName() . "` AS `p`\n INNER JOIN `" . $albumDao->getTableName() . "` AS `a` ON ( `p`.`albumId` = `a`.`id` )\n LEFT JOIN `" . $featuredDao->getTableName() . "` AS `f` ON ( `p`.`id` = `f`.`photoId` )\n WHERE `p`.`status` = 'approved' " . $privacyCond . $excludeCond . " AND `f`.`id` IS NOT NULL\n AND `a`.`entityType` = 'user'\n "; return $this->dbo->queryForColumn($query); case 'latest': default: $query = "\n SELECT COUNT(`p`.`id`)\n FROM `" . $this->getTableName() . "` AS `p`\n INNER JOIN `" . $albumDao->getTableName() . "` AS `a` ON ( `p`.`albumId` = `a`.`id` )\n WHERE `p`.`status` = 'approved' " . $privacyCond . $excludeCond . "\n AND `a`.`entityType` = 'user'\n "; return $this->dbo->queryForColumn($query); } }