Hi,

For huge gallery list the node gallery module throws an error of insufficient memory size, this is error is because there is no pagination added in the existing node gallery module and it tries to load all the galleries in a single page, resolved this issue by adding pagination to it,

Attached is the pagination patch added for the same.

Comments

Plazmus’s picture

Pagination is something that definitely should be included in this brilliant gallery module and as we waiting for Views integration I'm happy that someone wrote a patch.

You saying that it will add pager for gallery list which is absolutely great, but there is still need to put a pager into single galleries for images list.

Can you include that in your patch as well ?

I uploaded 15 images to gallery and I would like to display i.e. 12 on one page.

ranjeeta’s picture

StatusFileSize
new1.34 KB

hey , i got this done for you

just add the attached patch,i hope this is exactly what you are looking for.

mssarath’s picture

Version: 6.x-1.x-dev » 6.x-2.0-alpha1

Thank you for the code,

for new 2.0 alpha1 release , the code change is implemented in

node_gallery.inc , comment line number 106 , and add this code
$result = pager_query($sql, 20, 0, NULL, $node->nid);

and in node_gallery.module insert this line in line number 513

$vars['gallery'] .= theme('pager', NULL, variable_get('default_nodes_main', 10));

sarath

Plazmus’s picture

Thanks @ranjeeta for the patch and @mssarath for update!

What I think is that maybe one of you guys could add option on "node gallery" configuration page to let specify number of galleries per node and images per gallery after which pager will appear? I assume that not everyone would like to have i.e. the same number of images per gallery page.

Then maintainer of this module could include it in next release.

I can confirm that patch for 6.x-1.x-dev version is working.

dddave’s picture

Priority: Normal » Critical

When the lack of pagination throws a memory error this should be critical, shouldn't it?

ranjeeta’s picture

i completely agree to you dddave, this is critical, i really dont understand how the pagination part has been missed in this module.

Displaying all the galleries and images in a single page is really not feasible and for huge data it becomes critical.

mssarath’s picture

Version: 6.x-2.0-alpha1 » 6.x-2.0-alpha7

Here is the code which add a textfield in common settings section in node gallery section. which ask for number of images to be displayed per gallery

file : node_gallery.admin.inc
line number 26


function node_gallery_settings_form() {
  $form['node_gallery_page_number'] = array(
    '#type' => 'textfield',
    '#title' => t('Number of gallery display a page'),
    '#default_value' => variable_get('node_gallery_page_number', 20),
    '#description' => t('Specify the number of galleries a page would display.'),
  );
  $form['node_images_page_number'] = array(
    '#type' => 'textfield',
    '#title' => t('Number of images displayed per gallery'),
    '#default_value' => variable_get('node_images_page_number', 20),
    '#description' => t('Specify the number of images displayed per gallery'),
  );
  return system_settings_form($form);
}

added , another text field in the same function to hold the value for number of images.

and in node_gallery.inc

line number 105 i changed the $result to
$result = pager_query($sql, variable_get('node_images_page_number', 10), 0, NULL, $node->nid);

giving full function below commented old $result.

function node_gallery_get_gallery_images(&$node) {
  if (in_array($node->type, node_gallery_get_types())) {
    $sql = "SELECT n.nid, n.vid, n.title, n.type, n.created, nr.body, ng.*, f.* FROM {node} n 
      INNER JOIN {node_revisions} nr ON n.vid = nr.vid INNER JOIN {node_galleries} ng 
      ON n.nid = ng.nid INNER JOIN {files} f ON ng.fid = f.fid WHERE n.nid IN (SELECT g.nid FROM {node_galleries} g WHERE g.gid = %d) AND n.status = 1
       ORDER BY ng.weight, ng.nid";
//    $result = db_query($sql, $node->nid);
$result = pager_query($sql, variable_get('node_images_page_number', 20), 0, NULL, $node->nid);

    while ($object = db_fetch_object($result)) {
      $images[$object->fid] = $object;
    }
    //get the cck field content;
    if (module_exists('content') && !empty($images) && is_array($images)) {
      foreach ($images as &$item) {
        $content_type = content_types($item->type);
        if (!empty($content_type['fields'])) {
          content_load($item);
        }
      }
    }
    return $images;
  }
}

and in node_gallery.module in function function node_gallery_preprocess_node(&$vars)

line number 536 added a pager to the galler node

$vars['gallery'] .= theme('pager', NULL, variable_get('default_nodes_main', 10));

complete if statement is given below for reference.

if ($page) {
      $vars['gallery_operations'] = node_gallery_operations('gallery', $node);
      $vars['gallery'] = theme('gallery_images_list', $node, $config);
      $vars['gallery'] .= theme('pager', NULL, variable_get('default_nodes_main', 10)); 
    }
wilson98’s picture

committed, thanks.

Tally’s picture

Status: Needs review » Needs work

I assume this comment belongs here.

As I am adding more and more images into galleries, I notice that the pagination is off.

For example, I have a gallery with 18 images in it. Node Gallery is set to display 10 images per gallery. When I display the gallery with 18 images, I have 4 pages listed for my pagination. Page 1 has 10 images. Page 2 has 8 images. Pages 3 and 4 are empty and the message: There are no photos in this gallery currently. Upload Some! is displayed.

I have another gallery with 6 images. All six show up on one page in the gallery node, but the pagination links are displayed. The second page has no images displayed.

Now, this is the interesting part. The above is true only for the user who is viewing his own gallery. If another user views the same gallery, the pagination is correct and works as expected.

kmonty’s picture

Status: Needs work » Fixed

#9. - I could not replicate the problem that you described. It seems to work fine for me. If you are still noticing the problem, please reopen the ticket.

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.