Forums / General / Auto Incrementing Integer Class Attribute

Auto Incrementing Integer Class Attribute

Author Message

kracker (the)

Monday 12 July 2004 3:03:12 am

eZ community members,

I was creating a new class this afternoon with eZ publish (3.4.0).
The class is a todo item. The todo item class was very simple to create and worked right away.

After I got the class working. I realized one of the attributes (order) which is a integer (number) wasn't quite what I wanted. What I really wanted was the order attribute to be an auto incrementing number.

For example, for each instantiation of the class as an object in a folder would get the last number used for the order attribute from the last todo created and increment number by 1. If it was the first todo then start with 1.

Ideally I thought a todo item's order would be based first on the order of the last created order unique to each folder of todo items. Which would allow for different folders or "lists" of todo items each with their own orders. If no other todo items exist in a folder the order would start with 1 and with each new todo item created the new todo item's order would go up by 1.

The more I think about it. My idea for an auto increment (unique to folder) integer dataytpe may not be entirely well thought out. In a real life todo list the order of a item may be an auto incrementing number, that can be altered by the user to allow for reordering the list.

I am not entirely sure that such a feature doesn't already exist.
I did several searches in the documentation and forums for the keywords: auto, increment, number. So far I have not found any mentions of this kind of feature, or where in eZ publish such a feature would be best implemented.

I am posting this evening to see just what others might have to say about my idea. Perhaps I'm not looking in the right place, or I'm looking at the problem the wrong way, or such a feature doesn't yet exist and they could suggest the "eZ way" for me to work on creating the desired feature.

Any suggestions or comments on my idea would greatly be appreciated.

Respectfully,
Graham "the kracker" Brookins

FYI, here is some information on my todo class.

Todo Class Example:

- Name (Text line)
- Description (XML Text field)
- Order (Integer / Auto Increment Number)
- Date (Date field)
- Due Date (Date field)
- Status (Selection)
- Priority (Selection)
- Area (Selection)

Member since: 2001.07.13 || http://ezpedia.se7enx.com/

Paul Borgermans

Monday 12 July 2004 12:22:02 pm

Graham

The identifier datatype is your friend. You can leave the prefix and postfix fields blank, but if you change that later on in your class, the older objects will not reflect it though.

hth

-paul

eZ Publish, eZ Find, Solr expert consulting and training
http://twitter.com/paulborgermans

Stuart DH

Monday 12 July 2004 11:59:51 pm

I was looking at this last night. Does the auto increment happen site-wide with all individual folders joining the party? So if I have folders A, B and C, each with a relevant prefix, I will get A001, A002, C003, B004, A005 etc

If so, this would then enable me to sort both site-wide, as above, and by individual folder(s) so that a sort for folder A only would be A001, A002, A005 and so on. A sort of A and B would then be A001, A002, B004, A005.

Not too sure how you could alter the auto increment number, or if you would realy want to. It might be better to use a second field with fixed integers to do this. Maybe this second (priority) field could then sort before the auto integer so that all records with a priority will override the above sequence. This would mean that 4 records would sort 001,002,003,004 but if numbers 003 and 004 are given a higher priority than 002 then the list would become 001,003,004,002 etc.

I guess that all records would be given an auto-priority of 0 so if you just went down the list and added a 1 next to higher priority items then the 1's would be promoted above the rest and sorted by auto-increment first. Then all 0 priorities would join the wider list and also be sorted by auto-increment.

Is this how it could work?

http://www.wildaboutbritain.co.uk

Frederik Holljen

Tuesday 13 July 2004 12:33:53 am

The identifier is global to a class. So if you have a class "Foo" with an identifier, each instance of Foo will increment it regardless of where you put it. Since prefix and postfix is set in the class itself and not the object it is not possible to change the prefix like you suggest.

I don't quite understand what you are trying to do here though, you are talking about folders with the names A, B and C. Then you say A001 and A002. Why would you create two folders with the same name?

Priority sorting could be done they way you suggest.

kracker (the)

Wednesday 14 July 2004 5:48:35 am

Greetings,

Thanks to all who responded to my first inquiry.

In the Administration on the Content Tab the Site Root offers a feature which gives individual folders priority over other folders by displaying a form field with a number which can be changed by the administrator to increase or decrease a particular folders display order.

1) How this feature is implemented
2) Why only folders in the site root have this feature
3) Where this features is implemented
4) Can this feature be extended to other content objects not in the site root.

It would rock if these forums allowed users could assign a relevancy percentage to other users post to mark posts to point out most helpful answers or replies.

Respectfully,
Graham "the stampede" Brookins

Modest Mouse - Bukowski

Member since: 2001.07.13 || http://ezpedia.se7enx.com/

Frederik Holljen

Wednesday 14 July 2004 6:13:23 am

Priority can be set for all objects. Edit the object containing children you want to sort and change the "Sort by" field to "Priority".

Sujit Sth

Tuesday 04 January 2011 8:32:21 pm

Hi,

Sort By class attribute

eg:

{def $rss=fetch('content','list', hash('parent_node_id',77, limit,6, sort_by, array( 'attribute', false(), 'rss_import/pubdate')))} 

Here
rss_import -> class identifier

pubdate -> attribute identifier

happy sorting