📄 galleryalbums.class.php
字号:
/** * updates an album in the db * * @param album A GalleryAlbum object that already exists in the db. * @param Returns true if successful or false otherwise. */ function updateAlbum( $album ) { if ($album->getId() == $album->getParentId()){ return false; } if ($album->getParentId() != 0) { $parentAlbums = $this->getAllParentAlbumIds( $this->getAlbum( $album->getParentId(), -1, false, false ) ) ; foreach ( $parentAlbums as $parentAlbum ) { if ( $parentAlbum == $album->getId() ) return false; } } // load the previous version of this album $prevVersion = $this->getAlbum( $album->getId()); $result = $this->update( $album ); if( $result ) { // remove the album from the cache $this->_cache->removeData( $album->getId(), CACHE_GALLERYALBUM ); // remove the cached album hierarchy array $this->_cache->removeData( $album->getOwnerId(), CACHE_USERALBUMS ); // and the cache for nested albums too $this->_cache->removeData( $album->getOwnerId(), CACHE_USERALBUMS_NESTED ); // update the counters of the parent album if( $prevVersion->getParentId() != $album->getParentId()) { // increase the counter of the new album $parent = $album->getParent(); if( $parent ) { $parent->setNumChildren( $parent->getNumChildren() + 1 ); // update the objects $this->updateAlbum( $parent ); } // decrease the number of children in the previous parent $prevParent = $prevVersion->getParent(); if( $prevParent ) { $prevParent->setNumChildren( $prevParent->getNumChildren() - 1 ); // update the objects $this->updateAlbum( $prevParent ); } } } return( $result ); } /** * removes an album from the db * * @param albumId The album identifier * @param userId The user identifier to whom the album belongs (optional) * @return True if successful or false otherwise. */ function deleteAlbum( $albumId, $userId = -1 ) { // remove the cached album hierarchy array 1st .. // too bad we need to load the album before deleting it, but this method // won't get called all to often anyway :) $album = $this->getAlbum( $albumId ); if( empty( $album ) ) return false; if( $userId > -1 ) if( $album->getOwnerId() != $userId ) return false; $this->delete( "id", $albumId ); $this->_cache->removeData( $album->getOwnerId(), CACHE_USERALBUMS ); $this->_cache->removeData( $album->getOwnerId(), CACHE_USERALBUMS_NESTED ); //$this->delete( "parent_id", $album->getId()); // update the counters $parent = $album->getParent(); if( $parent ) { $parent->setNumChildren( $parent->getNumChildren() - 1 ); $this->updateAlbum( $parent ); } return( true ); } /** * Removes all the albums from the given ownerId * * @param ownerId The blog identifier */ function deleteUserAlbums( $ownerId ) { $userAlbums = $this->getUserAlbums( $ownerId, false, -1); // remove resources belong to the owner one by one foreach( $userAlbums as $album ) { $this->deleteAlbum( $album->getId(), $album->getOwnerId() ); } return true; } /** * returns all the albums of the blog in an array. The key of the array is the * parent id of all the albums in the position, and each position is either an * array with all the albums that share the same parent id or empty if none * * @param userId * @param albumId - unused * @return An associative array */ function getUserAlbumsGroupedByParentId( $userId, $albumId = 0 ) { $userAlbums = $this->getUserAlbums( $userId ); $albums = Array(); if( $userAlbums ) { foreach( $userAlbums as $album ) { $key = $album->getParentId(); if( isset($albums["$key"] )) { if( $albums["$key"] == "" ) $albums["$key"] = Array(); } $albums["$key"][] = $album; $ids[] = $album->getId(); } } return $albums; } /** * returns the albums of a blog ordered in the same way as they are nested. Please use * $album->getValue("level") to check their proper nesting. * * @param userId */ function getNestedAlbumList( $userId ) { $nestedAlbums = $this->_cache->getData( $userId, CACHE_USERALBUMS_NESTED ); if( !$nestedAlbums ) { // cache the data for later use... this is quite a costly operation so // it's probably worth caching it! $albums = $this->getUserAlbumsGroupedByParentId( $userId ); $nestedAlbums = $this->_getNestedAlbumList( $albums ); $this->_cache->setData( $userId, CACHE_USERALBUMS_NESTED, $nestedAlbums ); } return $nestedAlbums; } /** * @static * @private */ function _getNestedAlbumList( $albums, $start = 0, $level = -1 ) { $level++; if( !array_key_exists( $start, $albums ) || $albums["$start"] == "" ) return Array(); foreach( $albums["$start"] as $album ) { // do the replacing $album->setValue( "level", $level ); $results[] = $album; // make a recursive call $tmp = $this->_getNestedAlbumList( $albums, $album->getId(), $level); foreach( $tmp as $tmpAlbum ) $results[] = $tmpAlbum; } return $results; } /** * @see Model::getSearchConditions() */ function getSearchConditions( $searchTerms ) { $db =& Db::getDb(); if( $db->isFullTextSupported()) { $query = "MATCH(normalized_name,normalized_description) AGAINST ('{$searchTerms}')"; } else { $query = "name LIKE '%".Db::qstr( $searchTerms )."%' OR normalized_description LIKE '%".Db::qstr( $searchTerms )."%'"; } return( $query ); } /** * @see Model::mapRow() * @private */ function mapRow( $row ) { $album = new GalleryAlbum( $row["owner_id"], $row["name"], $row["description"], $row["flags"], $row["parent_id"], $row["date"], unserialize($row["properties"]), $row["show_album"], $row["id"] ); $album->setNumResources( $row['num_resources'] ); $album->setNumChildren( $row['num_children'] ); $album->setMangledName( $row['mangled_name'] ); return $album; } }?>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -