Forums / General / sort draft list by classname

"Please Note:
  • At the specific request of Ibexa we are changing this projects name to "Exponential" or "Exponential (CMS)" effective as of August, 11th 2025.
  • This project is not associated with the original eZ Publish software or its original developer, eZ Systems or Ibexa".

sort draft list by classname

Author Message

Andreas Adelsberger

Thursday 31 May 2007 5:36:56 am

hi there!

i fetch a list of all drafts using

{let draft_list=fetch('content','draft_version_list',hash(limit,$page_limit,offset,$view_parameters.offset))}

how can i sort them for example by classname?

thanx for your help.

greetz andy

---------------------------------------
Styleflasher New Media OG
Websites. Games/Multimedia.

Andreas Adelsberger

Thursday 31 May 2007 11:13:57 am

ok, i found it out now myself.

you need the following extension:
http://ez.no/community/contribs/template_plugins/arraysortoperator

basically you have to

loop through $drafts_list
fill a new array with a string starting with the attribute you want to sort, followed by a separator, followed by the next attribute etc..

now you have a simple array where you can use your sort method.

afterwards turn the array using "explode" back into a assoziative array using "hash".

here is my code:

def $sorted_draft_array=array()}
{foreach $draft_list as $k => $v}

 {set $sorted_draft_array=$sorted_draft_array|append(concat(
 		$v.contentobject.class_name,
 		'--',
 		$v.version_name,
 		'--',
 		$v.contentobject.section_id,
 		'--',
 		$v.version,
 		'--',
 		$v.initial_language.name,
 		'--',
 		$v.modified,
 		'--',
 		$v.contentobject.id,
 		'--',
 		$v.id,
 		'--',
 		$v.contentobject.content_class.identifier,
 		'--',
 		$v.contentobject.content_class.name,
 		'--',
 		$v.initial_language.locale
 		)
 		)}


{/foreach}
{set $sorted_draft_array=$sorted_draft_array|sort('string')}

{def $narr=array()}
{set $draft_list=array()}
{foreach $sorted_draft_array as $itm}
	{set $narr=$itm|explode('--')}
	{set $draft_list=$draft_list|append(
						hash(	
						'contentobject',
										hash(
												'class_name'	,$narr.0,
												'section_id'	,$narr.2,
												'id'			,$narr.6,
												'content_class'	,hash(
																		'identifier',$narr.8,
																		'name',$narr.9
																		),
											),
						'version_name',$narr.1,
						
						'version',$narr.3,
						'initial_language',hash(
												'name',$narr.4,
												'locale',$narr.10
												),
						'modified',$narr.5,
						'id',$narr.7
						)
									)
	}
	
{/foreach}

i hope it helps!

---------------------------------------
Styleflasher New Media OG
Websites. Games/Multimedia.