Skip to content

Commit

Permalink
Added pagination support
Browse files Browse the repository at this point in the history
Added pagination support for galleries list
  • Loading branch information
ChristianGiupponi committed Jul 7, 2012
1 parent efb8bb5 commit 63642f0
Show file tree
Hide file tree
Showing 6 changed files with 82 additions and 16 deletions.
26 changes: 26 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# PyroCMS Gallery

* [Website](http://pyrocms.com/)
* [Documentation](http://pyrocms.com/docs)
* [License](http://pyrocms.com/legal/license)
* [Forums](http://pyrocms.com/forums)
* Version: 1.3


## Description

This module allow you to create and manage as much galleries as you need.
Easy to use and well integrated with the File module to allow you to manage files in the easiest way!
In this new version has been added the pagination for the galleries, you can choose the number of displayed galleries in the Settings section of your Control Panel.

## Installation

Just upload the zip via Control Panel or FTP the folder in /addons/default/ or in /addons/shared_addons/ folder.


## Thanks

### Contributors

* [PyroCMS Team](http://www.pyrocms.com)
* [Christian Giupponi](https://github.com/ChristianGiupponi) (Pagination update)
2 changes: 2 additions & 0 deletions config/routes.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@
$route['galleries/admin(:any)?'] = 'admin$1';

// Rewrite the URLs
$route['galleries/index'] = 'galleries';
$route['galleries/index/(:any)'] = 'galleries/index/$1';
$route['galleries/(:any)/(:num)'] = 'galleries/image/$1/$2';
$route['galleries/(:any)'] = 'galleries/gallery/$1';
?>
40 changes: 32 additions & 8 deletions controllers/galleries.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@ public function __construct()
$this->lang->load('galleries');
$this->lang->load('gallery_images');
$this->load->helper('html');

//Load pagination library
$this->load->library('pagination');
}

/**
Expand All @@ -38,11 +41,27 @@ public function __construct()
*/
public function index()
{
$data->galleries = $this->gallery_m->get_all_with_filename();


//Get the total number of the galleries
$tot_galleries = $this->gallery_m->tot_galleries();

//Pagination config
$config['base_url'] = base_url().'galleries/index/';
$config['total_rows'] = $tot_galleries;
$config['per_page'] = Settings::get('per_page');
$config['uri_segment'] = 3;

//Get galleries
$galleries = $this->gallery_m->get_all_with_filename(NULL,NULL,$config['per_page'],$this->uri->segment(3));

//Initialize
$this->pagination->initialize($config);

//Template
$this->template
->title($this->module_details['name'])
->build('index', $data);
->set('galleries', $galleries)
->build('index');
}

/**
Expand All @@ -55,6 +74,9 @@ public function index()
public function gallery($slug = NULL)
{
$slug or show_404();

//Get the total number of the galleries
$tot_galleries = $this->gallery_m->tot_galleries();

$gallery = $this->gallery_m->get_by('slug', $slug) or show_404();
$gallery_images = $this->gallery_image_m->get_images_by_gallery($gallery->id);
Expand All @@ -66,11 +88,13 @@ public function gallery($slug = NULL)
$this->template->append_metadata('<script type="text/javascript">' . PHP_EOL . $gallery->js . PHP_EOL . '</script>');
}

$this->template->build('gallery', array(
'gallery' => $gallery,
'gallery_images' => $gallery_images,
'sub_galleries' => $sub_galleries
));
$this->template

->build('gallery', array(
'gallery' => $gallery,
'gallery_images' => $gallery_images,
'sub_galleries' => $sub_galleries
));
}

/**
Expand Down
10 changes: 6 additions & 4 deletions details.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

class Module_Galleries extends Module {

public $version = '1.2';
public $version = '1.3';

public function info()
{
Expand Down Expand Up @@ -92,17 +92,20 @@ public function install()
KEY `gallery_id` (`gallery_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8
";

$gallery_settings = "INSERT INTO `".$this->db->dbprefix('settings')."` (`slug`, `title`, `description`, `type`, `default`, `value`, `options`, `is_required`, `is_gui`, `module`, `order`) VALUES ('per_page', 'Per page', 'You can set the number of galleries to show in a single page', 'text', '10', '', '', '1', '1', 'galleries', '1001');";

if($this->db->query($galleries) && $this->db->query($gallery_images))
if($this->db->query($galleries) && $this->db->query($gallery_images) && $this->db->query($gallery_settings) )
{
return TRUE;
}
}

public function uninstall()
{
$sql_settings = "DELETE FROM ".$this->db->dbprefix('settings')." WHERE slug = 'per_page' ";
if($this->dbforge->drop_table('galleries') &&
$this->dbforge->drop_table('gallery_images'))
$this->dbforge->drop_table('gallery_images') && $this->db->query($sql_settings) )
{
return TRUE;
}
Expand All @@ -111,7 +114,6 @@ public function uninstall()

public function upgrade($old_version)
{
// Your Upgrade Logic
return TRUE;
}

Expand Down
16 changes: 13 additions & 3 deletions models/gallery_m.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,11 @@
*/
class Gallery_m extends MY_Model {

public function tot_galleries(){

return $this->db->count_all_results('galleries');
}

/**
* Get all galleries along with the total number of photos in each gallery
*
Expand Down Expand Up @@ -52,11 +57,11 @@ public function get_all()
* @access public
* @return mixed
*/
public function get_all_with_filename($where = NULL, $value = NULL)
public function get_all_with_filename($where = NULL, $value = NULL, $num = NULL, $offset = NULL)
{
$this->db
->select('galleries.*, files.filename, files.extension, files.id as file_id, file_folders.parent_id as parent')
->from('galleries')

->join('gallery_images', 'gallery_images.file_id = galleries.thumbnail_id', 'left')
->join('files', 'files.id = gallery_images.file_id', 'left')
->join('file_folders', 'file_folders.id = galleries.folder_id', 'left')
Expand All @@ -67,8 +72,13 @@ public function get_all_with_filename($where = NULL, $value = NULL)
{
$this->db->where($where, $value);
}

if( $num!=NULL or $offset!=NULL)
{
return $this->db->get('galleries',$num,$offset)->result();
}

return $this->db->get()->result();
return $this->db->get('galleries')->result();
}

/**
Expand Down
4 changes: 3 additions & 1 deletion views/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,9 @@
</div>

</div>
<?php endif; endforeach; else: ?>
<?php endif; endforeach;
echo $this->pagination->create_links();
else: ?>

<p><?php echo lang('galleries.no_galleries_error'); ?></p>

Expand Down

0 comments on commit 63642f0

Please sign in to comment.