Skip to content

Commit

Permalink
removed none working debug_kit ver 2, added filter plugin. removed al…
Browse files Browse the repository at this point in the history
…l the manual filters and added stuff to get filter plugin working in all the plugins
  • Loading branch information
dogmatic69 committed Dec 28, 2009
1 parent d541a66 commit becc57f
Show file tree
Hide file tree
Showing 18 changed files with 638 additions and 87 deletions.
7 changes: 6 additions & 1 deletion app/app_controller.php
Expand Up @@ -21,7 +21,12 @@ class AppController extends Controller
'Session',

//core components
'DebugKit.Toolbar', 'Core.Cron', 'Core.Config'
'DebugKit.Toolbar', 'Core.Cron', 'Core.Config',

// components
'Filter.Filter' => array(
'actions' => array('admin_index')
)
);

/**
Expand Down
9 changes: 1 addition & 8 deletions app/plugins/blog/controllers/comments_controller.php
Expand Up @@ -23,14 +23,8 @@ class CommentsController extends BlogAppController

var $uses = array( 'Core.Comment' );

function admin_index( $active = null )
function admin_index()
{
$conditions = array();
if ( $active !== null )
{
$conditions = array( 'Comment.active' => $active );
}

$this->paginate = array(
'fields' => array(
'Comment.id',
Expand All @@ -42,7 +36,6 @@ function admin_index( $active = null )
'Comment.foreign_id',
'Comment.created',
),
'conditions' => $conditions,
'order' => array(
'Comment.active' => 'ASC',
'Comment.created' => 'ASC',
Expand Down
34 changes: 3 additions & 31 deletions app/plugins/blog/controllers/posts_controller.php
Expand Up @@ -181,39 +181,11 @@ function admin_dashboard()
$this->set( 'dashboardCommentsCount', $this->Post->Comment->getCounts( 'Blog.Post' ) );
}

function admin_index( $active = null )
function admin_index()
{
$conditions = array();
if ( $active !== null )
{
$conditions = array( 'Post.active' => $active );
}

// $this->Post->recursive = 0;
//
// $this->paginate = array(
// 'fields' => array(
// 'Post.id',
// 'Post.title',
// 'Post.slug',
// 'Post.intro',
// 'Post.active',
// 'Post.views',
// 'Post.comment_count',
// 'Post.created',
// 'Post.locked',
// 'Post.locked_by',
// 'Post.locked_since',
// ),
// 'conditions' => $conditions
// );

$this->Post->recursive = 0;
$this->set( 'posts', $this->paginate() );

//$posts = $this->paginate( 'Post' );

//$this->set( compact( 'posts' ) );
$posts = $this->paginate( null, $this->Filter->filter );
$this->set( compact( 'posts' ) );
}

function admin_add()
Expand Down
6 changes: 3 additions & 3 deletions app/plugins/blog/views/elements/actions.ctp
Expand Up @@ -22,14 +22,14 @@
<h3><?php __( 'Posts' ); ?></h3>
<ul class="nav">
<li><?php echo $this->Html->link( __( 'Index', true ), array( 'plugin' => 'blog', 'controller' => 'posts', 'action' => 'index' ) ); ?></li>
<li><?php echo $this->Html->link( __( 'Active', true ), array( 'plugin' => 'blog', 'controller' => 'posts', 'action' => 'index', 1 ) ); ?></li>
<li><?php echo $this->Html->link( __( 'Pending', true ), array( 'plugin' => 'blog', 'controller' => 'posts', 'action' => 'index', 0 ) ); ?></li>
<li><?php echo $this->Html->link( __( 'Active', true ), array( 'plugin' => 'blog', 'controller' => 'posts', 'action' => 'index', 'Post.active' => 1 ) ); ?></li>
<li><?php echo $this->Html->link( __( 'Pending', true ), array( 'plugin' => 'blog', 'controller' => 'posts', 'action' => 'index', 'Post.active' => 0 ) ); ?></li>
<li><?php echo $this->Html->link( __( 'New', true ), array( 'plugin' => 'blog', 'controller' => 'posts', 'action' => 'add' ) ); ?></li>
</ul>
<h3><?php __( 'Comments' ); ?></h3>
<ul class="nav">
<li><?php echo $this->Html->link( __( 'Index', true ), array( 'plugin' => 'blog', 'controller' => 'comments', 'action' => 'index' ) ); ?></li>
<li><?php echo $this->Html->link( __( 'Pending', true ), array( 'plugin' => 'blog', 'controller' => 'comments', 'action' => 'index', 0 ) ); ?></li>
<li><?php echo $this->Html->link( __( 'Pending', true ), array( 'plugin' => 'blog', 'controller' => 'comments', 'action' => 'index', 'Post.active' => 0 ) ); ?></li>
</ul>
<h3><?php __( 'Maintanence' ); ?></h3>
<ul class="nav">
Expand Down
6 changes: 6 additions & 0 deletions app/plugins/cms/cms_app_controller.php
Expand Up @@ -13,6 +13,12 @@ class CmsAppController extends AppController
'Cms.Cms'
);

var $components = array(
'Filter.Filter' => array(
'actions' => array('admin_index')
)
);

function beforeFilter()
{
parent::beforeFilter();
Expand Down
2 changes: 1 addition & 1 deletion app/plugins/cms/controllers/categories_controller.php
Expand Up @@ -52,7 +52,7 @@ function view( $id = null )
function admin_index()
{
$this->Category->recursive = 0;
$this->set( 'categories', $this->paginate() );
$this->set( 'categories', $this->paginate( null, $this->Filter->filter ) );
}

function admin_view( $id = null )
Expand Down
2 changes: 1 addition & 1 deletion app/plugins/cms/controllers/contents_controller.php
Expand Up @@ -22,7 +22,7 @@ function view( $id = null )
function admin_index()
{
$this->Content->recursive = 1;
$this->set( 'contents', $this->paginate() );
$this->set( 'contents', $this->paginate( null, $this->Filter->filter ) );
}

function admin_view( $id = null )
Expand Down
2 changes: 1 addition & 1 deletion app/plugins/cms/controllers/sections_controller.php
Expand Up @@ -54,7 +54,7 @@ function admin_dashboard()
function admin_index()
{
$this->Section->recursive = 0;
$this->set( 'sections', $this->paginate() );
$this->set( 'sections', $this->paginate( null, $this->Filter->filter ) );
}

function admin_view( $id = null )
Expand Down
12 changes: 6 additions & 6 deletions app/plugins/cms/views/elements/actions.ctp
Expand Up @@ -22,22 +22,22 @@
<h3><?php __( 'Sections' ); ?></h3>
<ul class="nav">
<li><?php echo $this->Html->link( __( 'All', true ), array( 'plugin' => 'cms', 'controller' => 'sections', 'action' => 'index' ) ); ?></li>
<li><?php echo $this->Html->link( __( 'Active', true ), array( 'plugin' => 'cms', 'controller' => 'sections', 'action' => 'index', 1 ) ); ?></li>
<li><?php echo $this->Html->link( __( 'Pending', true ), array( 'plugin' => 'cms', 'controller' => 'sections', 'action' => 'index', 0 ) ); ?></li>
<li><?php echo $this->Html->link( __( 'Active', true ), array( 'plugin' => 'cms', 'controller' => 'sections', 'action' => 'index', 'Section.active' => 1 ) ); ?></li>
<li><?php echo $this->Html->link( __( 'Pending', true ), array( 'plugin' => 'cms', 'controller' => 'sections', 'action' => 'index', 'Section.active' => 0 ) ); ?></li>
<li><?php echo $this->Html->link( __( 'New', true ), array( 'plugin' => 'cms', 'controller' => 'sections', 'action' => 'add' ) ); ?></li>
</ul>
<h3><?php __( 'Categories' ); ?></h3>
<ul class="nav">
<li><?php echo $this->Html->link( __( 'All', true ), array( 'plugin' => 'cms', 'controller' => 'categories', 'action' => 'index' ) ); ?></li>
<li><?php echo $this->Html->link( __( 'Active', true ), array( 'plugin' => 'cms', 'controller' => 'categories', 'action' => 'index', 1 ) ); ?></li>
<li><?php echo $this->Html->link( __( 'Pending', true ), array( 'plugin' => 'cms', 'controller' => 'categories', 'action' => 'index', 0 ) ); ?></li>
<li><?php echo $this->Html->link( __( 'Active', true ), array( 'plugin' => 'cms', 'controller' => 'categories', 'action' => 'index', 'Category.active' => 1 ) ); ?></li>
<li><?php echo $this->Html->link( __( 'Pending', true ), array( 'plugin' => 'cms', 'controller' => 'categories', 'action' => 'index', 'Category.active' => 0 ) ); ?></li>
<li><?php echo $this->Html->link( __( 'New', true ), array( 'plugin' => 'cms', 'controller' => 'categories', 'action' => 'add' ) ); ?></li>
</ul>
<h3><?php __( 'Contents' ); ?></h3>
<ul class="nav">
<li><?php echo $this->Html->link( __( 'All', true ), array( 'plugin' => 'cms', 'controller' => 'contents', 'action' => 'index' ) ); ?></li>
<li><?php echo $this->Html->link( __( 'Active', true ), array( 'plugin' => 'cms', 'controller' => 'contents', 'action' => 'index', 1 ) ); ?></li>
<li><?php echo $this->Html->link( __( 'Pending', true ), array( 'plugin' => 'cms', 'controller' => 'contents', 'action' => 'index', 0 ) ); ?></li>
<li><?php echo $this->Html->link( __( 'Active', true ), array( 'plugin' => 'cms', 'controller' => 'contents', 'action' => 'index', 'Content.active' => 1 ) ); ?></li>
<li><?php echo $this->Html->link( __( 'Pending', true ), array( 'plugin' => 'cms', 'controller' => 'contents', 'action' => 'index', 'Content.active' => 0 ) ); ?></li>
<li><?php echo $this->Html->link( __( 'New', true ), array( 'plugin' => 'cms', 'controller' => 'contents', 'action' => 'add' ) ); ?></li>
</ul>
<h3><?php __( 'Front Page' ); ?></h3>
Expand Down
2 changes: 1 addition & 1 deletion app/plugins/core/views/elements/comments/add.ctp
Expand Up @@ -51,7 +51,7 @@
{
if ( $field != 'comment' )
{
echo $this->Form->input( 'Comment'.$field );
echo $this->Form->input( 'Comment.'.$field );
}
else
{
Expand Down
88 changes: 88 additions & 0 deletions app/plugins/filter/README.markdown
@@ -0,0 +1,88 @@
Filter Paginated Indexes using the CakePHP Filter Plugin

## Background
This plugin is a fork of Jose Gonzalez's Filter component(http://github.com/josegonzalez/cakephp-filter-component), which is something of a fork of James Fairhurst's Filter Component (http://www.jamesfairhurst.co.uk/posts/view/cakephp_filter_component/), which is in turn a fork by Maciej Grajcarek (http://blog.uplevel.pl/index.php/2008/06/cakephp-12-filter-component/) which is ITSELF a fork from Nik Chankov's code at http://nik.chankov.net/2008/03/01/filtering-component-for-your-tables/ .

That's a lot of forks...

This also contains a view helper made by 'mcurry' (http://github.com/mcurry/cakephp-filter-component).

This also uses a behavior adapted from work by 'Brenton' (http://bakery.cakephp.org/articles/view/habtm-searching) to allow for HasAndBelongsToMany and HasMany relationships.

This works for all relationships.

## Installation
- Clone from github : in your plugin directory type `git clone git://github.com/JeffreyMarvin/cakephp-filter-plugin.git`
- Add as a git submodule : in your plugin directory type `git submodule add git://github.com/JeffreyMarvin/cakephp-filter-plugin.git`
- Download an archive from github and extract it in `/plugins/filter`

## Usage
1. Include the component in your controller (AppController or otherwise)
var $components = array('Filter.Filter');
2. Use something like the following in your index
function index() {
$filterOptions = $this->Filter->filterOptions;
$posts = $this->paginate(null, $this->Filter->filter);
$this->set(compact('filterOptions', 'posts'));
}
3. Setup your view correctly:

-Option 1: Helper

Use the helper In between the row with all the column headers and the first row of data add:
<?php echo $filter->form('Post', array('name')) ?>
The first parameter is the model name.
The second parameter is an array of fields.
If you don't want to filter a particular field pass null in that spot.

-Option 2: Manually
<?php echo $form->create('Post', array('action' => 'index', 'id' => 'filters')); ?>
<table cellpadding="0" cellspacing="0">
<thead>
<tr>
<th><?php echo $paginator->sort('Name', 'name', $filter_options);?></th>
<th class="actions">Actions</th>
</tr>
<tr>
<th><?php echo $form->input('name'); ?></th>
<th>
<button type="submit" name="data[filter]" value="filter">Filter</button>
<button type="submit" name="data[reset]" value="reset">Reset</button>
</th>
</tr>
</thead>
<tbody>
// loop through and display your data
</tbody>
</table>
<?php echo $form->end(); ?>
<div class="paging">
<?php echo $paginator->prev('<< '.__('previous', true), $filter_options, null, array('class' => 'disabled'));?>
<?php echo $paginator->numbers($filter_options);?>
<?php echo $paginator->next(__('next', true).' >>', $filter_options, null, array('class' =>' disabled'));?>
</div>

4. Add Behavior to model (only necessary for HABTM and HasMany):
var $actsAs = 'Filter';

At this point, everything should theoretically work.

For action(s) other than index, add a line to the controller such as this:
$this->Filter->initialize($this, array('actions' => 'admin_index'));

To set it up for redirecting to the url with filters in it (which defaults to off), add a line to the controller such as this:
$this->Filter->initialize($this, array('redirect' => true));

To set it up to include time in the filter, add a line to the controller such as this:
$this->Filter->initialize($this, array('useTime' => true));

These different initialize options can be combined in the array.

## TODO:
<<<<<<< HEAD
1. Better code commenting - Done, left to help enforce the habit
2. Support Datetime - Mostly Done
3. Support URL redirects and parsing - Mostly Done
4. Refactor datetime filtering for ranges
5. Allow the action to be configurable
6. Support jQuery Datepicker

0 comments on commit becc57f

Please sign in to comment.