[SOLVED] Dynamic albums (last updated albums) : display child albums only (sub-albums) ?

suprsidr
suprsidr's picture

Joined: 2005-04-17
Posts: 8339
Posted: Mon, 2010-11-01 00:20

There is no way that my last bit of code does not work, the same album won't get displayed twice, but you need to set the dynamic album module to return more than 3 albums in case the one of the first 3 are duplicates.
So have it return 24 results and the first 3 non-matching albums should be displayed.

-s
FlashYourWeb and Your Gallery with The E2 XML Media Player for Gallery2

 
MFNO

Joined: 2007-12-13
Posts: 63
Posted: Mon, 2010-11-01 11:01

Well, I don't know what to say then...

What I don't understand is, the "limit" parameter in the mediablock url seems to work only between values 1 and 4. ABove 4, it never displays more than 4 albums.
You can try it :
http://www.laurent-photo.com/mediaBlock.php?mode=dynamic&g2_view=dynamicalbum.UpdatesAlbum&limit=2&column=3&useThumb=1&showTitle=1 ==> limit works fine, only 2 albums displayed.
http://www.laurent-photo.com/mediaBlock.php?mode=dynamic&g2_view=dynamicalbum.UpdatesAlbum&limit=15&column=3&useThumb=1&showTitle=1 ==> 4 albums displayed.

Maybe I did it wrong with inserting your bit of code, so here is my complete GetDynamicChildIds function :

Quote:
function getDynamicChildIds($userId, $param = 'date', $orderBy = 'creationTimestamp', $orderDirection = ORDER_DESCENDING , $table = 'GalleryEntity', $id = 'id') {
global $gallery,$numberOfItems,$g2_itemId;
$storage = &$gallery->getStorage();
list($ret, $params) = GalleryCoreApi::fetchAllPluginParameters('module', 'dynamicalbum');
if ($ret) {
return array($ret, null);
}
$size = $params['size.'.$param];
$type = $params['type.'.$param];
if (!$size) {
return array(GalleryCoreApi::error(ERROR_PERMISSION_DENIED), null);
}

list($show, $albumId) = GalleryUtilities::getRequestVariables('show', 'albumId');
if ( empty($albumId)) {
$albumId = $g2_itemId;
}
if (! empty($show)) {
$type = $show;
}
switch ($type) {
case 'data':
$class = 'GalleryDataItem';
break;
case 'all':
$class = 'GalleryItem';
break;
case 'album':
$class = 'GalleryAlbumItem';
break;
default:
return array(GalleryCoreApi::error(ERROR_BAD_PARAMETER), null);
}
if (!isset($table)) {
$table = $class;
}

$query = '['.$table.'::'.$id.'] IS NOT NULL';
if (! empty($albumId)) {
list($ret, $sequence) = GalleryCoreApi::fetchParentSequence($albumId);
if ($ret) {
return array($ret, null);
}
if (! empty($sequence)) {
$sequence = implode('/', $sequence).'/'.(int) $albumId.'/%';
$query = '[GalleryItemAttributesMap::parentSequence] LIKE ?';
$table = 'GalleryItemAttributesMap';
$id = 'itemId';
} else {
$query = '['.$table.'::'.$id.'] <> '.(int) $albumId;
}
}
if ($table == $class) {
$class = null;
}
list($ret, $query, $data) = GalleryCoreApi::buildItemQuery($table, $id, $query, $orderBy, $orderDirection, $class, 'core.view', false, $userId);
if ($ret) {
return array($ret, null);
}
if ( empty($query)) {
return array(null, array());
}
if (! empty($sequence)) {
array_unshift($data, $sequence);
}

list($ret, $searchResults) = $gallery->search($query, $data, array('limit'=>array('count'=>$size)));
if ($ret) {
return array($ret, null);
}
$itemIds = array();
while ($result = $searchResults->nextResult()) {
$itemIds[] = $result[0];
}
/* Start item display loop */
if (! empty($itemIds)) {
$display = '';
list($ret, $childItems) = GalleryCoreApi::loadEntitiesById($itemIds, 'GalleryItem');
if ($ret) {
print "Error loading childItems:".$ret->getAsHtml();
}
$numberOfItems = count($childItems);
if (isset($_REQUEST['shuffle']) && $_REQUEST['shuffle'] == 1) {
shuffle($childItems);
}
$alreadyDisplayed = array();
foreach ($childItems as $childItem) {
/* We need to check the disabledFlag for each in dynamic mode */
$disabled = getDisabledFlag($childItem->getId());
if (!$disabled) {
if (!(hasChildAlbums($childItem->getId()))) {
$display .= getDisplay($childItem);
}
if (!hasChildAlbums($childItem->getId()) && $childItem->getParentId() != 7 && !in_array($childItem->getId(), $alreadyDisplayed)) {
$display .= getDisplay($childItem);
$alreadyDisplayed[] = $childItem->getId();
}
}
}
return $display;
}/* End item display loop */
}

 
suprsidr
suprsidr's picture

Joined: 2005-04-17
Posts: 8339
Posted: Mon, 2010-11-01 11:22
Quote:
What I don't understand is, the "limit" parameter in the mediablock url seems to work only between values 1 and 4. ABove 4, it never displays more than 4 albums.

limit only affects mediaBlock, if the dynamic album module is only returning 4 items, you'll still only have 4 items regardless of what you set mediaBlock to.

you don't want both conditions and display lines, change:

if (!(hasChildAlbums($childItem->getId()))) {
$display .= getDisplay($childItem);
}
if (!hasChildAlbums($childItem->getId()) && $childItem->getParentId() != 7 && !in_array($childItem->getId(), $alreadyDisplayed)) {
$display .= getDisplay($childItem);
$alreadyDisplayed[] = $childItem->getId();
}

to:

if (!hasChildAlbums($childItem->getId()) && $childItem->getParentId() != 7 && !in_array($childItem->getId(), $alreadyDisplayed)) {
$display .= getDisplay($childItem);
$alreadyDisplayed[] = $childItem->getId();
}

-s
FlashYourWeb and Your Gallery with The E2 XML Media Player for Gallery2

 
MFNO

Joined: 2007-12-13
Posts: 63
Posted: Mon, 2010-11-01 16:20

You know what ? It worked :-) It actually works ! All your time and thinking led to the solution. I can barely realize right now... Thank you AGAIN. I know what a bore it was, but thanx to you, I can use Gallery like I wanted to, and, I say it again, this UpdatedAlbum feature was very important to me.

As I am grateful to you and the whole "community", I'll do my best very soon to sum up in this topic the complete solution in one post, and will edit my first post, so that people who are interested in this could get immediately to the solution.
Again, I am super-lame at PHP and other codes, but I understood what you did, and it was a great learning experience. I hope it could be useful to others.

Thank you again.

 
MFNO

Joined: 2007-12-13
Posts: 63
Posted: Fri, 2010-12-17 22:46

I wanted to thank the whole community by summing up what helped me solve this problem (so that if someone has the same problem I had, he/she doesn't need to read all the discussion).

As advised by suprsidr, I checked out mediablock and eventually find the solution to my problem there.

What I did, step by step :

- I first downloaded the mediablock.php page and tried to unerstand how it works, the different parameters as explained on mediablock website http://www.flashyourweb.com/staticpages/index.php?page=mediaBlock
This is important as you want to make sure what you wanna display in the end.

- I changed a part in line 28 of mediablock.php from that :

Quote:
$ret = GalleryEmbed::init(array('fullInit'=>true, 'embedUri'=>'/gallery2/main.php', 'g2Uri'=>'/gallery2/'));

to that :

Quote:
$ret = GalleryEmbed::init(array('fullInit'=>false, 'embedUri'=>'http://www.laurent-photo.com/main.php', 'g2Uri'=>'http://www.laurent-photo.com/'));

- I uploaded mediablock.php on my website.

- the link I used is this one in the end : http://www.laurent-photo.com/mediaBlock.php?mode=dynamic&g2_view=dynamicalbum.UpdatesAlbum&limit=3&column=3&useThumb=1&showTitle=1
It's easy to understand each part with the explanations above (see mediablock website)

- In mediablock.php, I changed this part (around line 268) :

Quote:
foreach ($childItems as $childItem) {
/* We need to check the disabledFlag for each in dynamic mode */
$disabled = getDisabledFlag($childItem->getId());
if (!$disabled) {
if (!($childItem->entityType == "GalleryAlbumItem")) {
$display .= getDisplay($childItem);
}
}
}
return $display;
}/* End item display loop */
}

to this :

Quote:
$alreadyDisplayed = array();
foreach ($childItems as $childItem) {
/* We need to check the disabledFlag for each in dynamic mode */
$disabled = getDisabledFlag($childItem->getId());
if (!$disabled) {
if (!hasChildAlbums($childItem->getId()) && $childItem->getParentId() != 7 && !in_array($childItem->getId(), $alreadyDisplayed)) {
$display .= getDisplay($childItem);
$alreadyDisplayed[] = $childItem->getId();
}
}
}
return $display;
}/* End item display loop */
}

- another change to the mediablock.php code, I changed this part :

Quote:
function getLink($item) {
global $gallery;
$urlGenerator = &$gallery->getUrlGenerator();
$link = $urlGenerator->generateUrl(array('view'=>'core.ShowItem', 'itemId'=>$item->getId()), array('forceFullUrl'=>true, 'forceSessionId'=>true));
return $link;
}

to this :

Quote:
function getLink($item) {
global $gallery;
$id = (isset($_REQUEST['linkToParent']) && $_REQUEST['linkToParent'] == 1)?$item->getParentId():$item->getId();
$urlGenerator = &$gallery->getUrlGenerator();
$link = $urlGenerator->generateUrl(array('view'=>'core.ShowItem', 'itemId'=>$id), array('forceFullUrl'=>true, 'forceSessionId'=>false));
return $link;
}

- make sure in the admin modules page, the updated albums settings (in dynamic albums module) is set to "display albums only", and the number of albums is big enough (I set mine to 15, I don't care, cause through mediablock.php url I only display as many as I want, i.e. 3)

- just added a call to this madiablock url in my album.tpl page :

Quote:
{php}
@readfile('http://www.laurent-photo.com/mediaBlock.php?mode=dynamic&g2_view=dynamicalbum.UpdatesAlbum&limit=3&column=3&useThumb=1&showTitle=1');
{/php}

Thank you suprsidr again.

 
fanky

Joined: 2011-08-19
Posts: 2
Posted: Tue, 2011-08-23 05:24

So I understood well, right ?
I am not supposed to use mediablock if I only use gallery itself with no integration at all. Am I right ?
English is not my native language, so I am not sure I understand every thing, hence my weird questions sometimes.

But anyways, if something exists that can be done outside of Gallery through Gallery, I don't understand it couldn't be done directly in Gallery, even with some code...

 
suprsidr
suprsidr's picture

Joined: 2005-04-17
Posts: 8339
Posted: Tue, 2011-08-23 12:05
Quote:
I am not supposed to use mediablock if I only use gallery itself with no integration at all. Am I right ?

No.
when you edit line 28 set the embedUri to that of your gallery integration.

-s
FlashYourWeb and Your Gallery with The E2 XML Media Player for Gallery2