Bonjour à tous,

Alors voilà, je conçois un nouveau composant pour J1.5.

J'ai quasiment terminé la partie "liste" côté admin, et tout fonctionne bien sauf... ces @!$(%&! de boutons OrderUp et OrderDown, qui, normalement, permettent de faire monter ou descendre un item dans une liste ordonnée.

Ca fait 2 jours que je bute là-dessus : le saveOrder fonctionne parfaitement bien, mais lorsque je clique sur ces deux boutons, la page se rafraichit (sans message d'aucune sorte), et rien ne change dans l'ordre des items !

Dans ma table, j'ai bien entendu une colonne "ordering", et j'ai implémenté le code suivant, conformément à ce que j'ai pu voir dans le composant weblinks (liste des catégories) ou dans d'autres composants que j'ai scrutés de façon approfondie :

Dans la vue (view.html.php) :

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
$rows                   = & $this->get( 'Data' );
$total                  = & $this->get( 'Total' );
$pageNav                = & $this->get( 'Pagination' );
...
$filter_order            = $mainframe->getUserStateFromRequest( $option.'.cities_list.filter_order',        'filter_order',         'a.ordering',    'cmd' );
$filter_order_Dir        = $mainframe->getUserStateFromRequest( $option.'.cities_list.filter_order_Dir',    'filter_order_Dir',     '',        'word' );
...
$lists['order_Dir']     = $filter_order_Dir;
$lists['order']         = $filter_order;
$ordering = ($lists['order'] == 'a.ordering');
...
$this->assignRef( 'rows',               $rows );
$this->assignRef( 'total',              $total );
$this->assignRef( 'pageNav',            $pageNav );
$this->assignRef( 'ordering',           $ordering );
Dans le template (default.php) :

Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
<span><?php echo $this->pageNav->orderUpIcon   ( $i, true,     'orderup',   'Move Up',   $this->ordering ); ?></span>
<span><?php echo $this->pageNav->orderDownIcon ( $i, $n, true, 'orderdown', 'Move Down', $this->ordering ); ?></span>
<?php $disabled = $this->ordering ?  '' : '"disabled=disabled"'; ?>
<input type="text" name="order[]" size="5" value="<?php echo $row->ordering; ?>" <?php echo $disabled; ?> class="text_area" style="text-align: center" />
Dans le controller (cities_list.php) :

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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
/**
 * Order Up a [City]
 *
 * @access public
 * @return void
 * @since 1.0.0
 */
Function orderup() {
 
    // Check for request forgeries
    JRequest::checkToken() or jexit( 'Invalid Token' );
 
    // Load [Cities_List] model
    $model = $this->getModel( 'cities_list' );
 
    // Load the move up method
    $model->move(-1);
 
    // Redirect to the [cities_list] view
    $this->setRedirect( 'index.php?option=com_component&view=Cities_List' );
 
}
 
 
/**
 * Order Down a [City]
 *
 * @access public
 * @return void
 * @since 1.0.0
 */
Function orderdown() {
 
    // Check for request forgeries
    JRequest::checkToken() or jexit( 'Invalid Token' );
 
    // Load [Cities_List] model
    $model = $this->getModel( 'cities_list' );
 
    // Load the move down method
    $model->move(1);
 
    // Redirect to the [cities_list] view
    $this->setRedirect( 'index.php?option=com_component&view=Cities_List' );
 
}
 
 
/**
 * Save Order of [Cities]
 *
 * @access public
 * @return void
 * @since 1.0.0
 */
Function saveOrder() {
 
    // Get values
    $cid    = JRequest::getVar( 'cid', array( 0 ), 'post', 'array' );
    $order  = JRequest::getVar( 'order', array( 0 ), 'post', 'array' );
    JArrayHelper::toInteger( $order, array( 0 ) );
 
    // Load [Cities_List] model
    $model  = $this->getModel( 'cities_list' );
 
    // Load the saveOrder method
    $model->saveorder( $cid, $order );
 
    // Redirect to the [cities_list] view
    $msg = JText::_( 'LABEL_ENTITY_CITIES_NEW_CITIES_ORDERING_SAVED' );
    $this->setRedirect( 'index.php?option=com_component&view=Cities_List' );
 
}
Dans le model (cities_list.php)

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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
/**
 * Method to move (order up/down) [Cities]
 *
 * @access  public
 * @return  boolean
 * @since   1.0
 */
function move( $direction ) {
 
    // Check for request forgeries
    JRequest::checkToken() or jexit( 'Invalid Token in [Save Order] method' );
 
    // Load table class
    $row =& $this->getTable( 'cities' );
    if ( $row ) {
        $this->setError( 'pas bon, bob !' . $this->_db->getErrorMsg() );
        return false;
    }
    //$row =& JTable::getInstance('cities', '');
 
    // Load the [City] to move
    if ( ! $row->load( $this->_id ) ) {
        $this->setError( $this->_db->getErrorMsg() );
        return false;
    }
 
    // Call move method of JTABLE
    if ( ! $row->move( $direction ) ) {
        $this->setError( $this->_db->getErrorMsg() );
        return false;
    }
    return true;
 
}
 
 
/**
 * Method to save ordering of [Cities]
 *
 * @access  public
 * @return  boolean
 * @since   1.0
 */
function saveorder( $cid = array(), $order ) {
 
    // Check for request forgeries
    JRequest::checkToken() or jexit( 'Invalid Token in [Save Order] method' );
 
    // Get [Cities] list
    $query = 'SELECT * FROM #__cities';
    $itemlist = $this->_getList( $query, $this->getState( 'limitstart' ), $this->getState( 'limit' ) );
 
    // Build the ordering array
    $order_array = array();
    foreach( $itemlist as $item ) {
        $order_array[$item->id] = ( $item->ordering * 2 ) + ( $item->id / 100 );
    }
 
    // Modify ordering in ordering array
    $count = count( $cid );
    for( $i=0; $i < $count; $i++ ) {
        $neworder = ( $order[$i] * 2 ) + ( $cid[$i] / 100 );
        if ( $order_array[$cid[$i]] != $neworder ) {
            $order_array[$cid[$i]] = $neworder-1;
        }
    }
 
    // Sort the ordering array
    asort( $order_array );
    $order_array = array_keys( $order_array );
 
    // Load table class
    $row =& $this->getTable( 'cities' );
 
    // Update ordering values
    $count = count( $order_array );
    for( $i=0; $i < $count; $i++ ) {
        $row->load( (int) $order_array[$i] );
        if ( $row->ordering != $i+1 ) {
            $row->ordering = $i+1;
            if ( !$row->store() ) {
                $this->setError( $this->_db->getErrorMsg() );
                return false;
            }
        }
    }
 
    return true;
 
}
J'ai vraiment besoin de l'aide d'un expert sur le sujet...
J'ai tout exploré, mais je ne vois vraiment pas d'où vient le pb !
Merci d'avance