Bonjour,
j'ai créé un template operator , mon premier en fait , pour pouvoir trier les éléments d'un tableau de manière aléatoire mais cela ne semble pas fonctionner. je vous présente le code que j'ai développé pour mon fichier getshuffle.php
Le code semble bien être pris en compte par ez publish car en y laissant des erreurs il me les affiche à l'écran.
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39 <?php class getShuffle { // Constructeur function getShuffle() { $this->Operators = array('melange'); } // Retoune la liste des operateurs dans la classe function &operatorList() { return $this->Operators; } function namedParameterPerOperator() { return true; } function namedParameterList() { return array('melange' => array()); } function modify( $tpl, $operatorName, $operatorParameters, $rootNammespace, $currentNamespace, $operatorValue, $namedParameters ) { switch( $operatorName ) { case 'melange': $operatorValue = $this->melange($operatorValue); break; } } function melange($tableau) { $val = array(); $keys = array_keys($tableau); shuffle($keys); foreach($keys as $key) $val[] = $tableau[$key]; return $val; } } ?>
pour être plus précis je vous montre aussi les contenus de mes fichiers extensions/mon_extension/autoloads/eztemplateautoload.php et extension/mon_extension/settings/site.ini.append.php
eztemplateautoload.php
site.ini
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12 <?php // Operator autoloading $eZTemplateOperatorArray = array(); $eZTemplateOperatorArray[] = array( 'script' => 'extension/mon_extension/autoloads/getshuffle.php', 'class' => 'getShuffle', 'operator_names' => array( 'melange' ) ); ?>
Et voici comment j'appelle ma fonction dans la page correspondante
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3 [TemplateSettings] ExtensionAutoloadPath[]=mon_extension
Avez-vous une idée quelle erreur j'ai pu faire dans mon code ou mon appel de ma fonction ?
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 {set-block scope=root variable=cache_ttl}0{/set-block} {def $max=fetch('content', 'tree_count', hash('parent_node_id',$node.parent_node_id, class_filter_type, include, class_filter_array, array('livre_collection','livre_serie'))) $ouvrages=fetch('content', 'tree', hash('parent_node_id', $node.parent_node_id, class_filter_type, include, class_filter_array, array('livre_collection','livre_serie'), limit,$max)) } {foreach $ouvrages as $index => $ouvrage} {if $ouvrage.node_id|eq($node.node_id)} {set $ouvrages=$ouvrages|remove($index} {/if} {/foreach} {set $ouvrages=$ouvrages|melange()} {node_view_gui view=random_ouvrages content_node=$ouvrages}
Partager