diff -rup image/contrib/image_attach/image_attach.module image/contrib/image_attach/image_attach.module --- image/contrib/image_attach/image_attach.module 2011-05-13 23:26:39.000000000 +0530 +++ image/contrib/image_attach/image_attach.module 2011-05-29 19:12:08.527951547 +0530 @@ -736,3 +736,18 @@ function image_attach_content_extra_fiel } } +/** + * Function for length and offset validation for views display_limit option. + */ +function image_attach_limits_validate($element, &$form_state) { + $value = 0; + if (!empty($element['#value'])) { + $value = trim($element['#value']); + if (!is_numeric($value)) { + $error_field = implode('][', $element['#parents']); + form_set_error($error_field, t('Only numbers are allowed in %field.', array('%field' => t($element['#title'])))); + return; + } + } + form_set_value($element, intval($value), &$form_state); +} diff -rup image/contrib/image_attach/image_attach_views_handler_field_attached_images.inc image/contrib/image_attach/image_attach_views_handler_field_attached_images.inc --- image/contrib/image_attach/image_attach_views_handler_field_attached_images.inc 2011-05-13 23:26:39.000000000 +0530 +++ image/contrib/image_attach/image_attach_views_handler_field_attached_images.inc 2011-05-29 19:11:34.187978802 +0530 @@ -34,7 +34,9 @@ class image_attach_views_handler_field_a $options = parent::option_definition(); $options['as_link'] = array('default' => 'none'); - + $options['display_limits']['length'] = 0; + $options['display_limits']['offset'] = 0; + return $options; } @@ -52,6 +54,27 @@ class image_attach_views_handler_field_a '#options' => array('none' => t('No link'), 'node' => t('Node'), 'image' => t('Image node')), '#default_value' => $this->options['as_link'], ); + $form['display_limits'] = array( + '#type' => 'fieldset', + '#title' => t('Display Limits'), + '#description' => t('The images are displayed in latest to oldest order.'), + '#collapsible' => TRUE, + '#collapsed' => FALSE, + ); + $form['display_limits']['length'] = array( + '#type' => 'textfield', + '#title' => t('Number of images to display'), + '#description' => t('The number of images to display per node. Negetive value will remove that many images from the end of the list. Enter 0 to display all images beginning from the offset.'), + '#default_value' => $this->options['display_limits']['length'], + '#element_validate' => array('image_attach_limits_validate'), + ); + $form['display_limits']['offset'] = array( + '#type' => 'textfield', + '#title' => t('Offset'), + '#description' => t('Offset provides the sequence number of the image to begin display from. Negetive offset is allowed.'), + '#default_value' => $this->options['display_limits']['offset'], + '#element_validate' => array('image_attach_limits_validate'), + ); } /** @@ -71,6 +94,11 @@ class image_attach_views_handler_field_a } if (count($nids)) { + // Get display limits for the current view display. + $field = $this->view->field['image_attach_images']; + $display_limits = $field->options['display_limits']; + $display_limits['length'] = $display_limits['length'] === 0 ? NULL : $display_limits['length']; + $nids_string = implode(',', $nids); $result = db_query("SELECT nid, iid FROM {image_attach} WHERE nid IN (" . $nids_string . ") ORDER BY weight"); while ($data = db_fetch_object($result)) { @@ -83,7 +111,7 @@ class image_attach_views_handler_field_a $this->handler_key = $this->options['id']; foreach ($values as $id => $v) { if (isset($attached_images[$v->{$this->aliases['image_attach_nid']}])) { - $values[$id]->image_attach_iids[$this->handler_key] = $attached_images[$v->{$this->aliases['image_attach_nid']}]; + $values[$id]->image_attach_iids = array_slice($attached_images[$v->{$this->aliases['image_attach_nid']}], $display_limits['offset'], $display_limits['length']); } } }