modified Album Select Module
Barre
Joined: 2004-07-14
Posts: 48 |
Posted: Fri, 2005-05-20 11:14 | |||
Hi. Here’s my modified Album Select module that gives a new option in the admin interface to make the tree and dropdown list to actually use the sort order set in each album that was discussed in this topic This may give some negative performance in large albums and/or slow hardware. This is the changes I’ve done to the module: file: module.inc row 42 $this->setVersion('0.9.4'); row 64 /** * @see GalleryModule::registerEventListeners() */ function registerEventListeners() { GalleryCoreApi::registerEventListener( 'Gallery::ViewableTreeChange', new AlbumSelectModule()); GalleryCoreApi::registerEventListener( 'GalleryEntity::save', new AlbumSelectModule()); } row 82 foreach (array('show' => 1, 'type' => 'select', 'sort' => 'manual', 'treeLines' => 1, 'treeIcons' => 0, 'treeCookies' => 0, 'treeExpandCollapse' => 0, 'treeCloseSameLevel' => 0) as $key => $value) { row 161 $treeList = array(); $nodeId = 0; $sorter = NULL; switch ($params['sort']) { case "byAlbum" : list ($ret, $subAlbumsIds) = GalleryCoreApi::fetchChildAlbumItemIds($rootAlbum); foreach($subAlbumsIds as $subAlbumId){ $ret = $this->_buildTree($subAlbumId, $treeList, $nodeId); if ($ret->isError()) { return array($ret->wrap(__FILE__, __LINE__), null); } } break; case "byTitle" : $sorter = new AlbumSelectTreeSorter($titles); case "manual" : default : $this->_parseTree($tree, $treeList, $sorter, $nodeId); } row 211 if ($event->getEventName() == 'GalleryEntity::save') { list ($ret, $params) = GalleryCoreApi::fetchAllPluginParameters('module', 'albumselect'); if ($ret->isError()) { return array($ret->wrap(__FILE__, __LINE__), null); } $theEntity = $event->getEntity(); if($theEntity->getEntityType() == 'GalleryAlbumItem' && $params['sort']=='byAlbum') { GalleryDataCache::removeFromDisk( array('type' => 'module-data', 'module' => 'albumselect')); } } row 247 /** * Build template data for subalbum tree with album predefined sorting * @private */ function _buildTree($albumId, &$treeList, &$nodeId, $parentNode=0, $depth=0) { list ($ret, $album) = GalleryCoreApi::loadEntitiesById($albumId); if ($ret->isError()) { return $ret; } $treeList[] = array('id' => $album->getId(), 'nodeId' => ++$nodeId, 'parentNode' => $parentNode, 'depth' => $depth); list ($ret, $subAlbumsIds) = GalleryCoreApi::fetchChildAlbumItemIds($album); if ($ret->isError()) { return $ret; } $parentNode = $nodeId; foreach($subAlbumsIds as $subAlbumId){ $ret = $this->_buildTree($subAlbumId, $treeList, $nodeId, $parentNode, $depth+1); if ($ret->isError()) { return $ret; } } return $ret; } file: AlbumSelectAdmin.inc row 55 foreach (array('show', 'sort', 'treeLines', 'treeIcons', 'treeCookies', 'treeExpandCollapse', 'treeCloseSameLevel') as $key) { switch ($key) { case 'sort' : $ret = GalleryCoreApi::setPluginParameter('module', 'albumselect', 'sort', $form['sort']); break; default : $ret = GalleryCoreApi::setPluginParameter('module', 'albumselect', $key, (isset($form[$key]) && $form[$key]) ? 1 : 0); break; } if ($ret->isError()) { return array($ret->wrap(__FILE__, __LINE__), null); } } file AlbumSelectAdmin.tpl row 45 <input type="radio" id="rbSortManual"{if $form.sort eq "manual"} checked="checked"{/if} name="{g->formVar var="form[sort]"}" value="manual"/> <label for="rbSortManual"> {g->text text="Use manual sort order of albums"} </label> <br/> <input type="radio" id="rbSortTitle"{if $form.sort eq "byTitle"} checked="checked"{/if} name="{g->formVar var="form[sort]"}" value="byTitle"/> <label for="rbSortTitle"> {g->text text="Sort albums by title"} </label> <br/> <input type="radio" id="rbSortAlbum"{if $form.sort eq "byAlbum"} checked="checked"{/if} name="{g->formVar var="form[sort]"}" value="byAlbum"/> <label for="rbSortAlbum"> {g->text text="Use sort settings defined in album (could affect performance)"} </label>
|
||||
Posts: 32509
very nice. and see the answer to your event question in the other thread to delete the cache on item->save (sortOrderBy != lastsorOrderBy || sortOrderDirection != lastSortOrderDirection) events.
Posts: 48
Thanks for the info valiant, I've updated my original post and attachment.
Cheers
Posts: 8601
Barre, nice work.. any chance you could update the unit tests to cover your changes? lib/tools/phpunit/index.php?filter=albumselect
That will certainly help get your change into cvs sooner
Posts: 48
mindless, i've updated the phpunit tests and uploaded a new zip file with them.
Cheers
Posts: 8601
Barre, I'm committing changes based on your code.. here's what I added:
Thanks![/]
Posts: 3
Thanks, it works fine.
But also, how can I limit the depth of showing albums. E.g., I have root album -> sub-album -> sub-sub-album, and I want to show in album tree only root album and subalbum, something like in this topic.
I can show only two levels in "manual sort order" and "Sort albums by title".
How to do it with "sort settings defined in album"?
Posts: 8601
kost, sort on per-album basis is an option in Site Admin / Album Select.. upgrade your G2 if you don't see it.
There is no option for tree depth, but you can modify your code to do this.. edit modules/albumselect/Callbacks.inc and change:
GalleryCoreApi::fetchAlbumTree(null, null, $userId);
to:
GalleryCoreApi::fetchAlbumTree(null, 2, $userId);
(for depth 2).
This will work for manual or title sort.
For album sort, after the line with:
function _buildTree
add:
if ($depth > 2) return GalleryStatus::success();
Posts: 3
I tried to upgrade the whole gallery, it gives me a lot of errors. I think, it because I made some changes in core files, to translate Gallery. When I try to open any page after upgrade, it hangs up my server. I return to older version.
Oh, problem solved!
I add
function _buildTree($albumId, &$treeList, &$nodeId, $parentNode=0, $depth=0) {
if ($depth > 1) return GalleryStatus::success();
and it works like I want.
Thanks!