Development

#3240 ([PATCH] Add support for sorting objects in categories)

You must first sign up to be able to contribute.

Ticket #3240 (closed enhancement: fixed)

Opened 2 years ago

Last modified 8 months ago

[PATCH] Add support for sorting objects in categories

Reported by: dstaver Assigned to: rozwell
Priority: minor Milestone:
Component: sfPropelActAsSortableBehaviorPlugin Version:
Keywords: Cc:
Qualification: Accepted

Description

I have a table called 'image'. Each image belongs to 'album' using 'album_id'. I'd like to make the images within each album sortable. However, it turns out this behaviour can only adjust the rank of all the images.

Some way to define criteria for the behaviour would be very useful. For instance in this case I'd like the behaviour to only consider objects with the same album_id as the one I'm working with when doing moveUp, moveDown, swapWith, etc...

Attachments

sfPropelActAsSortableBehaviorPlugin_key_support.diff (4.0 kB) - added by martink on 06/02/08 12:43:29.
sfPropelActAsSortableBehavior.class.php (19.9 kB) - added by angelsk on 06/13/08 12:51:25.
Patch for ticket:3240 - added optional key value sorting on top of latest svn revision
sfPropelActAsSortableBehavior.class.2.php (28.2 kB) - added by obalais on 07/03/08 16:44:36.
Array for multiple keys supported

Change History

05/20/08 20:46:52 changed by develop7

  • version deleted.

Just done it. I'll release patch soon.

05/26/08 15:46:06 changed by COil

Hi ! So did you do the patch ? I would be interested. I thought it was a native feature of the plugin, i've got the same problem as i want to rank my objects by user.

06/02/08 12:43:29 changed by martink

  • attachment sfPropelActAsSortableBehaviorPlugin_key_support.diff added.

06/02/08 12:49:06 changed by martink

key support in lib/model/Item.php

class Item extends BaseItem
{
  // whatever
}

sfPropelBehavior::add('Item', array('act_as_sortable' => array(
  'column' => 'rank',
  'key' => 'key_id',
  'new_element_position' => 'bottom'
)));

06/13/08 12:51:25 changed by angelsk

  • attachment sfPropelActAsSortableBehavior.class.php added.

Patch for ticket:3240 - added optional key value sorting on top of latest svn revision

06/13/08 12:54:53 changed by angelsk

  • summary changed from Add support for sorting objects in categories to [PATCH] Add support for sorting objects in categories.

I took the class file from the svn repository (so latest version) and added optional key support.

sfPropelBehavior::add('Item', array('act_as_sortable' => array(
  'column' => 'rank',
  'key' => 'key_id',
  'new_element_position' => 'bottom'
)));

key is optional here, if you have no key to sort by in your table - then don't set this option. It defaults to null, and sorts as normal.

If you do have a key to sort by, such as album_id, then add it here, and it will sort within the album.

NOTE: You may need to reset any existing sorting, otherwise the decremented on move can produce minus numbers :)

I've tested with and without keys, and have had no problems.

07/03/08 12:48:24 changed by obalais

Added support for multiple keys...

If you want to sort by multiple keys, just add key as an array of keys. Just have a look at the next exemple:

sfPropelBehavior::add('Category', array('act_as_sortable' => array(
  'column' => 'rank',
  'key' => array('shop_id', 'category_id'),
  'new_element_position' => 'bottom'
)));

07/03/08 16:44:36 changed by obalais

  • attachment sfPropelActAsSortableBehavior.class.2.php added.

Array for multiple keys supported

10/31/08 19:36:10 changed by Kris.Wallsmith

  • owner changed from francois to Kris.Wallsmith.

02/25/09 17:49:03 changed by barros

Hi.. Do you guys have plan to release this patch in the near future?? I guess a lot of people would be interested in this.....

Carlos

02/25/09 20:05:08 changed by COil

+1, please apply the patch.. I don't see any reason why it shouldn't be included ?

12/30/09 03:17:38 changed by rozwell

  • owner changed from Kris.Wallsmith to rozwell.
  • status changed from new to assigned.
  • qualification changed from Unreviewed to Accepted.

I'll check both patches but probably I'll apply only single-scope version for Propel 1.2 and Propel 1.3 (which will be available really soon, so keep checking ;). Also, I've written myself single scope support so I'll compare, take best of them and apply it. Version for Propel 1.4 will be done soon also. Propel 1.5 comes with Sortable Behavior so plugin won't be needed then. I'd like to make it stable so please post any bugs and ideas. Cheers, rozwell

12/30/09 06:42:04 changed by rozwell

  • status changed from assigned to closed.
  • resolution set to fixed.

Dang, I'm always forgetting about this WikiFormatting :p
I've just added Propel 1.3 branch for syfony 1.2 with single scope support, so you can try it out.
Setting as fixed for now.
rozwell

The Sensio Labs Network

Since 1998, Sensio Labs has been promoting the Open-Source software movement by providing quality web application development, training, consulting.
Sensio Labs also supports several large Open-Source projects.