Callback problem

vfortin

Joined: 2007-05-23
Posts: 8
Posted: Sun, 2007-06-03 21:27

Hi there,

Following the instructions on this page:
http://codex.gallery2.org/Gallery2:Themes:Reference:Callbacks
I created my own callback called "LoadChildren" and added it to the CoreCallbacks class in Callbacks.inc.

But when I call it with

{g->callback type="core.LoadChildren" item=$item|default:$theme.item

I get this error message:

Notice: Undefined index: core

This is likely a PHP/Smarty newbie error.
Can somebody tell me what I'm doing wrong here?

Thanks!

 
valiant

Joined: 2003-01-04
Posts: 32509
Posted: Sun, 2007-06-03 22:34

your example is missing the closing "}" curly bracket.

> Notice: Undefined index: core

isn't that accompanied by a file / line number? check your code in Callbacks.inc, and the code you added in the .tpl file.

--------------
Documentation: Support / Troubleshooting | Installation, Upgrade, Configuration and Usage

 
vfortin

Joined: 2007-05-23
Posts: 8
Posted: Tue, 2007-06-05 00:09

Thanks valiant,
You're right, something is wrong about my code.

The callback I'm trying to write is nothing more than a modified LoadPeers. I want to retrieve the album children instead of the peers.

I'm suspecting one of the GalleryCoreApi function to return an empty array but my PHP knowledge stops here.
Can you tell what I'm doing wrong?

This is the call from the album.tpl:

{g->callback type="core.LoadChildren" item=$child
	     windowSize=$windowSize|default:$theme.params.maxMicroThumbs
	     addEnds=false loadThumbnails=true}

...and this is the callback:
EDIT: Btw I only messed with the first statements to pass the $item instead of the $parent. My problem probably lies somewhere around here.

case 'LoadChildren':
      $item = $params['item'];

      if (isset($item->getChildrenFunction)) {
		  $parent = $item;
		  list ($ret, $peerIds) = call_user_func($parent->getChildrenFunction, $userId);
		  if ($ret) {
		     return $ret;
		  }

    } else if ($item['id'] > 0) {
		  list ($ret, $canViewParent) = GalleryCoreApi::hasItemPermission($item['id'], 'core.view', $userId);
		  if ($ret) {
        return $ret;
		  }
		  if ($canViewParent) {
        list ($ret, $parent) = GalleryCoreApi::loadEntitiesById($item['id']);
		      if ($ret) {
            return $ret;
		      }
        list ($ret, $peerIds) = GalleryCoreApi::fetchChildItemIds($item, null, null, $userId);
		    if ($ret) {
          return $ret;
        }
      }
	  }


	  if (!empty($peerIds)) {
		  foreach ($peerIds as $i => $id) {
		    if ($id == $item['id']) {
			   $peerItemIndex = $i;
			   break;
		    }
		  }
	  }

    if (isset($peerItemIndex)) {
  		$windowSize = isset($params['windowSize']) ? ($params['windowSize'] - 1) : 6;
      $addEnds = isset($params['addEnds']) ? $params['addEnds'] : true;
		  $peerLast = count($peerIds) - 1;
		  $peerNeighborStart = max($peerItemIndex - (int)($windowSize/2), 0);
		  $peerNeighborEnd = min($peerItemIndex + (int)(($windowSize+1)/2), $peerLast);
		  /* If the window is pinned to one end, expand it to the entire windowSize */
		  if ($peerNeighborStart == 0) {
		    $peerNeighborEnd = min($peerLast, $windowSize);
		  } else if ($peerNeighborEnd == $peerLast) {
		    $peerNeighborStart = max($peerLast - $windowSize, 0);
		  }
		  if ($peerNeighborStart > 0 && $addEnds) {
		    $peerMap[0] = $peerIds[0];
		  }
		  for ($i = $peerNeighborStart; $i <= $peerNeighborEnd; $i++) {
		    $peerMap[$i] = $peerIds[$i];
		  }
		  if ($peerNeighborEnd < $peerLast && $addEnds) {
		    $peerMap[$peerLast] = $peerIds[$peerLast];
		  }

		list ($ret, $peerItems) = GalleryCoreApi::loadEntitiesById($peerMap);
		if ($ret) {
		  return $ret;
		}
		if (!empty($params['loadThumbnails'])) {
		    list ($ret, $thumbTable) = GalleryCoreApi::fetchThumbnailsByItemIds($peerMap);
		    if ($ret) {
          return $ret;
		    }
		}
		$j = 0;
		foreach ($peerMap as $i => $id) {
      $peer = (array)$peerItems[$j++];
		  $peer['peerIndex'] = $i + 1;
		    if (isset($thumbTable[$id])) {
          $peer['thumbnail'] = (array)$thumbTable[$id];
		    }
		  $peers[] = $peer;
		}
		$block['core']['LoadChildren'] = array('peers' => $peers,
		    'peerCount' => count($peerIds), 'thisPeerIndex' => $peerItemIndex + 1,
		    'parent' => (array)$parent);
	  } else {
		  $block['core']['LoadChildren'] = array('peers' => array(), 'peerCount' => 0);
	  }
	  return null;
 
erlis

Joined: 2004-01-16
Posts: 205
Posted: Tue, 2007-09-18 07:37

Did you manage to get LoadChildren to work?

 
vfortin

Joined: 2007-05-23
Posts: 8
Posted: Tue, 2007-09-18 23:20

Nope, sorry.
I think it goes against the natural workflow of the software.
All my questions regarding this here remained unanswered.

 
erlis

Joined: 2004-01-16
Posts: 205
Posted: Sun, 2007-09-23 11:44