Jump to content
Sign in to follow this  
kate1987

Добавить пагинацию в Галереи

Recommended Posts

Здравствуйте

Использую расширение Галерея для вывода изображений (Opencart 1.5.5)

В ней нужно добавить пагинацию по 9 элементов на страницу

ДЛя этого в модели добавила подсчет количества изображений

public function getTotalImage() {
	
                $sql = "SELECT COUNT(DISTINCT ps.gallery_image_id ) AS total FROM " . DB_PREFIX . "gallery";
				
				
				
		$name = 'gallery.' . md5($sql);
                $results = $this->cache->get($name);
		if($results===false) {
                    $query = $this->db->query($sql);
		
                    if (isset($query->row['total'])) {
                            //return $query->row['total'];
                        $results = $query->row['total'];
                    } else {
                           // return 0;	
                        $results = 0;
                    }
                    $this->cache->set($name, $results);
                }  
                return $results;
	}

Дальше в контроллере вывела переменные нужные

$image_total = $this->model_gallery_gallery->getTotalImage();

		$pagination = new Pagination();
			$pagination->total = $image_total;
			$pagination->page = $page;
			$pagination->limit = $limit;
			$pagination->text = $this->language->get('text_pagination');
			$pagination->url = $this->url->link('gallery/gallery', 'path=' . $this->request->get['path'] . $url . '&page={page}');
		
			$this->data['pagination'] = $pagination->render();

Ну и наконец в самот файле gallery_list.tpl Добавила

     <div class="pagination"><?php echo $pagination; ?></div>

Как результат пустая строка

 

Можете подсказать где я ошиблась?

Share this post


Link to post
Share on other sites

пробовала еще просто в контроллере добавить

			if (isset($this->request->get['page'])) {
         $page = $this->request->get['page'];
      
      } else {
         $page = 1;
      }
      
      $this->data['pagination'] = '';
      if (isset($this->request->get['gallery_image_id'])) {      
         $pagination = new Pagination();
         $pagination->total = sizeof($this->data['gallerys']);
         $pagination->page = $page;
         $pagination->limit = $this->config->get('config_catalog_limit');
         $pagination->text = $this->language->get('text_pagination');
         $pagination->url = $this->url->link('gallery/gallery', 'gallery_id=' . $this->request->get['gallery_id'] . '&page={page}');
            
         $this->data['pagination'] = $pagination->render();
      }

но тоже не помогло(

Share this post


Link to post
Share on other sites

>> Можете подсказать где я ошиблась?

1.

$sql = "SELECT COUNT(DISTINCT ps.gallery_image_id ) AS total FROM " . DB_PREFIX . "gallery";
2.

$results = $this->cache->get($name);
...
                        $results = $query->row['total'];
3.

			$pagination->page = $page;
			$pagination->limit = $limit;
4. >> пробовала еще просто в контроллере добавить...

= = =

надо смотреть весь контроллер, код выборки изображений в модели.

Share this post


Link to post
Share on other sites

контроллер. На переменные сайт не ругается, все пропускает

<?php

class ControllerGalleryGallery extends Controller
{
    public function index()
    {
        $this->document->addScript('catalog/view/javascript/jquery/colorbox/jquery.colorbox-min.js');
        $this->document->addStyle('catalog/view/javascript/jquery/colorbox/colorbox.css');
        $this->document->addStyle('catalog/view/theme/default/stylesheet/stylesheet_gallery.css');
        $this->load->model('gallery/gallery');
        $this->load->model('tool/image');


        $this->data['breadcrumbs'] = array();

        $this->data['breadcrumbs'][] = array(
            'text' => $this->language->get('text_home'),
            'href' => $this->url->link('common/home'),
            'separator' => false
        );


        /*if (isset($this->request->get['gallery_id'])) {



            $gallery_info = $this->model_gallery_gallery->getGallery($gallery_id);
                if ($gallery_info) {
                       $this->data['breadcrumbs'][] = array(
                           'text'      => $gallery_info['name'],
                        'href'      => $this->url->link('gallery/gallery', 'token=' . $this->session->data['token'] . $url, 'SSL'),
                        'separator' => $this->language->get('text_separator')
                    );
                }
        } else {
            $gallery_id = 0;
        }*/


        if (isset($this->request->get['gallery_id'])) {
            $this->data['continue'] = $this->url->link('gallery/gallery');

            $gallery_id = $this->request->get['gallery_id'];

            $this->data['parent_id'] = $this->model_gallery_gallery->getGalleryParid($gallery_id);

            $url = '';

            // у всех изображений с раздела "Наши проекты" делаем watermark, id раздела = 2
            if ($this->data['parent_id'] == 2)
                $type = 'watermark';
            else
                $type = '';


            if ($this->data['parent_id'] > 0) {
                $parrent_name = $this->model_gallery_gallery->getGalleryName($this->data['parent_id']);
                $url .= 'parent_id=' . $this->data['parent_id'] . '&';

                $this->data['breadcrumbs'][] = array(
                    'text' => $parrent_name,
                    'href' => $this->url->link('gallery/gallety', 'gallery_id=' . $this->data['parent_id']),
                    'separator' => false
                );
            }

            $this->data['name'] = $this->model_gallery_gallery->getGalleryName($gallery_id);

            $this->data['breadcrumbs'][] = array(
                'text' => $this->data['name'],
                'href' => $this->url->link('gallery/gallety', $url . 'gallery_id=' . $gallery_id),
                'separator' => false
            );
	  		
		  	$this->document->setTitle($this->data['name']);           


            $this->data['description'] = html_entity_decode($this->model_gallery_gallery->getGalleryDescription($gallery_id), ENT_QUOTES, 'UTF-8');


            $this->data['gallerys'] = array();

            $results_tmp = $this->model_gallery_gallery->getGalleryChild($gallery_id);


            //print '$results_tmp = '.print_r($results_tmp,true);
            $results = array();
            foreach ($results_tmp as $result) {
                $results[$result['gallery_id']] = $result;
            }
            unset($results_tmp);


            $names = array();

            foreach ($results as $result) {
                $image = $this->model_gallery_gallery->getGalleryImage($result['gallery_id']);

                $name = $result['name'];
                $result_tmp = $result;
                while ($result_tmp['parent_id'] != 0) {
                    $result_tmp = $results[$result_tmp['parent_id']];
                    if (empty($result_tmp)) continue;
                    $name = $result_tmp['name'] . '   ' . $name;
                }

                $url = '';
                $parent_parent_id = $this->model_gallery_gallery->getGalleryParid($result['gallery_id']);
                if (!empty($parent_parent_id))
                    $url .= 'parent_id=' . $parent_parent_id . '&';

                $names[] = $name;

                $image_total = $this->model_gallery_gallery->getGalleryImageCount($result['gallery_id']);
                /*if($_SERVER['REMOTE_ADDR']=='91.201.246.12'){
                    echo '--<pre style="text-align: left;">';
                    print_r($url);
                    echo '</pre>';
                }*/
                $this->data['gallerys'][] = array(
                    'gallery_id' => $result['gallery_id'],
                    'parent_id' => $result['parent_id'],

                    'name' => $name . ' (' . $image_total . ')',
                    'link' => $this->url->link('gallery/gallery', $url . 'gallery_id=' . $result['gallery_id']),
                    'image' => $this->model_tool_image->resize($image['image'], 200, 200)
                );
            }

            //array_multisort($names, SORT_ASC, $this->data['gallerys']);
            //print_r($this->data['gallerys']);

            $results = $this->model_gallery_gallery->getGallery($gallery_id);


            foreach ($results as $result) {


                $title = html_entity_decode($result['title'], ENT_QUOTES, 'UTF-8');
				
				


                if (file_exists(DIR_IMAGE . $result['image'])) {
                    $this->data['image'][] = array(
                        'title' => $title,
						

                        'preview' => $this->model_tool_image->resize($result['image'], 330, 330),
                        'image' => $this->model_tool_image->resize($result['image'], 700, 700, $type),
                    );
                }
            }

            //print_r($this->data['gallerys']);

            if (file_exists(DIR_TEMPLATE . $this->config->get('config_template') . '/template/' . $this->config->get('config_stylesheet') . '/gallery/gallery_list.tpl')) {
                $this->template = $this->config->get('config_template') . '/template/' . $this->config->get('config_stylesheet') . '/gallery/gallery_list.tpl';
            } else {
                $this->template = 'default/template/gallery/gallery_list.tpl';
            }

            $this->children = array(
                'common/column_left',
                'common/column_right',
                'common/content_top',
                'common/content_bottom',
                'common/footer',
                'common/header'
            );

            $this->response->setOutput($this->render());


        } else {

            $this->data['gallerys'] = array();

            $results_tmp = $this->model_gallery_gallery->getGallerys();

            $results = array();
            foreach ($results_tmp as $result) {
                $results[$result['gallery_id']] = $result;
            }
            unset($results_tmp);

            $names = array();


            foreach ($results as $result) {
                $image = $this->model_gallery_gallery->getGalleryImage($result['gallery_id']);

                $name = $result['name'];
                $result_tmp = $result;
                while ($result_tmp['parent_id'] != 0) {
                    $result_tmp = $results[$result_tmp['parent_id']];
                    $name = $result_tmp['name'] . ' > ' . $name;
                }

                $names[] = $name;

                $url = '';
                $parent_parent_id = $this->model_gallery_gallery->getGalleryParid($result['gallery_id']);
                if (!empty($parent_parent_id))
                    $url .= 'parent_id=' . $parent_parent_id . '&';

                $this->data['gallerys'][] = array(
                    'gallery_id' => $result['gallery_id'],
                    'parent_id' => $results[$result_tmp['parent_id']],

                    'name' => $name, //$result['name'],
                    'link' => $this->url->link('gallery/gallery', $url . 'gallery_id=' . $result['gallery_id']),

                    'image' => $this->model_tool_image->resize($image['image'], 140, 140)
                );
            }


            array_multisort($names, SORT_ASC, $this->data['gallerys']);
			
			
if (isset($this->request->get['page'])) {
$page = $this->request->get['page'];
} else {
$page = 1;
}

print_r($page);

$data = array(
/*  'start' => ($page – 1) * $this->config->get('config_admin_limit'),*/


     'start' => ($page - 1) * 2,
'limit' => $this->config->get('config_admin_limit')
);




$get_total_records = $this->model_gallery_gallery->getTotal();

$pagination = new Pagination();

$url = '';
$pagination = new Pagination();
$pagination->total = $get_total_records;
$pagination->page = $page;

$pagination->limit = $this->config->get('config_admin_limit');
$pagination->text = $this->language->get('text_pagination');
$pagination->url = $this->url->link('gallery/gallery', 'token=' . $this->session->data['token'] . $url . '&page={page}', 'SSL');

$this->data['pagination'] = $pagination->render(); 



/*if (isset($this->request->get['page'])) {
                $page = $this->request->get['page'];
            } else {
                $page = 1;
            }
            
            print_r($page);
            
            $data = array(
                'start' => ($page - 1) * 2,
                'limit' => 2
            );
            $get_total_records = $this->model_gallery_gallery->getTotal($data);
                    
            $pagination = new Pagination();

            $url = '';
            $pagination = new Pagination();
            $pagination->total = $get_total_records;
            $pagination->page = $page;
            $pagination->limit = 2;
            $pagination->text = $this->language->get('text_pagination');
            $pagination->url = $this->url->link('gallery/gallery', 'token=' . $this->session->data['token'] . $url . '&page={page}', 'SSL');
            
            $this->data['pagination'] = $pagination->render();
			*/
			

            if (file_exists(DIR_TEMPLATE . $this->config->get('config_template') . '/template/' . $this->config->get('config_stylesheet') . '/gallery/gallery_image.tpl')) {
                $this->template = $this->config->get('config_template') . '/template/' . $this->config->get('config_stylesheet') . '/gallery/gallery_image.tpl';
            } else {
                $this->template = 'default/template/gallery/gallery_image.tpl';
            }

            $this->children = array(
                'common/column_left',
                'common/column_right',
                'common/content_top',
                'common/content_bottom',
                'common/footer',
                'common/header'
            );

            $this->response->setOutput($this->render());
        }

    }

}

?>
Edited by afwollis
spoiler

Share this post


Link to post
Share on other sites

Че то я не увидела подсчет изображений в модели уже был

  public function getGalleryImageCount($gallery_id) {
		$query = $this->db->query("SELECT COUNT(bi.gallery_id) as `c` FROM " . DB_PREFIX . "gallery_image bi LEFT JOIN " . DB_PREFIX . "gallery_image_description bid ON (bi.gallery_image_id  = bid.gallery_image_id) WHERE bi.gallery_id = '" . (int)$gallery_id . "' AND bid.language_id = '" . (int)$this->config->get('config_language_id') . "' LIMIT 1");

		return $query->row['c'];
	}

	public function getGallerys($data) {
		
		$sql = "SELECT * FROM " . DB_PREFIX . "gallery WHERE status = 1 ORDER BY sort_order ASC";
		if (isset($data['start']) || isset($data['limit'])) {
			if ($data['start'] < 0) {
				$data['start'] = 0;
			}				

			if ($data['limit'] < 1) {
				$data['limit'] = 9;
			}	
		
			$sql .= " LIMIT " . (int)$data['start'] . "," . (int)$data['limit'];
		}

в котроллере сейчас

if (isset($this->request->get['page'])) {
$page = $this->request->get['page'];
} else {
$page = 1;
}

print_r($page);

$data = array(
'start' => ($page - 1) * $this->config->get('config_admin_limit'),
'limit' => $this->config->get('config_admin_limit')
);

$get_total_records = $this->model_gallery_gallery->getGalleryImageCount();

$pagination = new Pagination();

$url = '';
$pagination = new Pagination();
$pagination->total = $get_total_records;
$pagination->page = $page;

$pagination->limit = $this->config->get('config_admin_limit');
$pagination->text = $this->language->get('text_pagination');
$pagination->url = $this->url->link('gallery/gallery', 'token=' . $this->session->data['token'] . $url . '&page={page}', 'SSL');

$this->data['pagination'] = $pagination->render(); 

Share this post


Link to post
Share on other sites

public function getGalleryImageCount($gallery_id) {...
$get_total_records = $this->model_gallery_gallery->getGalleryImageCount();
опять теряем $gallery_id ???

но самое главное:

вы чего там вообще склеиваете? мухи,котлеты... всё смешали.

вам бы убрать всё лишнее, вернув к исходному состоянию, определиться, чего именно будете разбивать на страницы (галлереи или изображения в галлерее) и тогда можно будет решать задачу.

Share this post


Link to post
Share on other sites

) считать будем изображения в галлерее

то есть с таблицы gallery_image, это

 public function getGalleryImageCount($gallery_id) {
		$query = $this->db->query("SELECT COUNT(bi.gallery_id) as `c` FROM " . DB_PREFIX . "gallery_image bi LEFT JOIN " . DB_PREFIX . "gallery_image_description bid ON (bi.gallery_image_id  = bid.gallery_image_id) WHERE bi.gallery_id = '" . (int)$gallery_id . "' AND bid.language_id = '" . (int)$this->config->get('config_language_id') . "' LIMIT 1");

		return $query->row['c'];
	}

я думаю правильно

Потому что количество изображений выводит норм

 

 

в контроллере

$get_total_records = $this->model_gallery_gallery->getGalleryImageCount($gallery_id);

поправила

 

 

Но что то все равно не хочет работать(

Share this post


Link to post
Share on other sites

оригинальные контроллер и модель прицепите архивом.

Share this post


Link to post
Share on other sites

посмотрел.

там у вас реально другой код и никаких

Че то я не увидела подсчет изображений в модели уже был

public function getGalleryImageCount($gallery_id) {
в помине нет.

меняли вы вообще выборку галерей, а не изображений.

@по воздуху@ тяжко, но всё же попробовал сделать.

замените свои файлы прикрепленными

gal_fixed.zip

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
You are posting as a guest. If you have an account, please sign in.
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Sign in to follow this  

  • Recently Browsing   0 members

    No registered users viewing this page.

×

Important Information

On our site, cookies are used and personal data is processed to improve the user interface. To find out what and what personal data we are processing, please go to the link. If you click "I agree," it means that you understand and accept all the conditions specified in this Privacy Notice.