library/Garp/Model/Behavior/Weighable.php
public function beforeUpdate(&$args) {
        $model = $args[0];
        $data = &$args[1];
        $where = $args[2];
        
        foreach ($this->_relationConfig as $foreignModel => $modelRelationConfig) {
            $foreignKey = $modelRelationConfig[self::FOREIGN_KEY_COLUMN_KEY];
            $weightColumn = $modelRelationConfig[self::WEIGHT_COLUMN_KEY];
            /**
             * Only act if the foreign key field is filled, since weight is calculated per foreign key.
             * This means duplicate weight values might occur in the database, but the foreign key 
             * will always differ.
             * You should be able to add a UNIQUE INDEX to your table containing the foreign key column and the
             * weight column.
             */
            if (array_key_exists($foreignKey, $data) && $data[$foreignKey]) {
                /**
                 * If the weight column is not given in the new data, fetch it. 
                 * This is quite the pickle, since the given WHERE clause might update (and thus fetch)
                 * multiple records, but we can only provide one set of modified data to apply to every 
                 * matching record. 
                 * This is currently not fixed. If a WHERE clause is given that matches multiple records,
                 * the current weight of the first record found is used.
                 */
                if (!array_key_exists($weightColumn, $data)) {
                    $data[$weightColumn] = $this->findCurrentWeight($model, $where, $data[$foreignKey], $modelRelationConfig);
                }
            
                // only act if the foreign key column is filled, and the weight column is null
                if (!$data[$weightColumn]) {
                    $maxWeight = $this->findHighestWeight($model, $data[$foreignKey], $modelRelationConfig);
                    $data[$weightColumn] = ($maxWeight+1);
                }
            }
        }
    }
public function beforeUpdate(&$args) {
        $model = $args[0];
        $data = &$args[1];
        $where = $args[2];
        
        foreach ($this->_relationConfig as $foreignModel => $modelRelationConfig) {
            $foreignKey = $modelRelationConfig[self::FOREIGN_KEY_COLUMN_KEY];
            $weightColumn = $modelRelationConfig[self::WEIGHT_COLUMN_KEY];
            /**
             * Only act if the foreign key field is filled, since weight is calculated per foreign key.
             * This means duplicate weight values might occur in the database, but the foreign key 
             * will always differ.
             * You should be able to add a UNIQUE INDEX to your table containing the foreign key column and the
             * weight column.
             */
            if (array_key_exists($foreignKey, $data) && $data[$foreignKey]) {
                /**
                 * If the weight column is not given in the new data, fetch it. 
                 * This is quite the pickle, since the given WHERE clause might update (and thus fetch)
                 * multiple records, but we can only provide one set of modified data to apply to every 
                 * matching record. 
                 * This is currently not fixed. If a WHERE clause is given that matches multiple records,
                 * the current weight of the first record found is used.
                 */
                if (!array_key_exists($weightColumn, $data)) {
                    $data[$weightColumn] = $this->findCurrentWeight($model, $where, $data[$foreignKey], $modelRelationConfig);
                }
            
                // only act if the foreign key column is filled, and the weight column is null
                if (!$data[$weightColumn]) {
                    $maxWeight = $this->findHighestWeight($model, $data[$foreignKey], $modelRelationConfig);
                    $data[$weightColumn] = ($maxWeight+1);
                }
            }
        }
    }
public function beforeUpdate ( & $ args ) { $ model = $ args [ 0 ] ; $ data = & $ args [ 1 ] ; $ where = $ args [ 2 ] ; foreach ( $ this -> _relationConfig as $ foreignModel => $ modelRelationConfig ) { $ foreignKey = $ modelRelationConfig [ self :: FOREIGN_KEY_COLUMN_KEY ] ; $ weightColumn = $ modelRelationConfig [ self :: WEIGHT_COLUMN_KEY ] ; /**
             * Only act if the foreign key field is filled, since weight is calculated per foreign key.
             * This means duplicate weight values might occur in the database, but the foreign key 
             * will always differ.
             * You should be able to add a UNIQUE INDEX to your table containing the foreign key column and the
             * weight column.
             */ if ( array_key_exists ( $ foreignKey , $ data ) && $ data [ $ foreignKey ] ) { /**
                 * If the weight column is not given in the new data, fetch it. 
                 * This is quite the pickle, since the given WHERE clause might update (and thus fetch)
                 * multiple records, but we can only provide one set of modified data to apply to every 
                 * matching record. 
                 * This is currently not fixed. If a WHERE clause is given that matches multiple records,
                 * the current weight of the first record found is used.
                 */ if ( ! array_key_exists ( $ weightColumn , $ data ) ) { $ data [ $ weightColumn ] = $ this -> findCurrentWeight ( $ model , $ where , $ data [ $ foreignKey ] , $ modelRelationConfig ) ; } // only act if the foreign key column is filled, and the weight column is null if ( ! $ data [ $ weightColumn ] ) { $ maxWeight = $ this -> findHighestWeight ( $ model , $ data [ $ foreignKey ] , $ modelRelationConfig ) ; $ data [ $ weightColumn ] = ( $ maxWeight + 1 ) ; } } } }
BeforeUpdate callback, find and insert current highest 'weight' value + 1, if it is null
@param Array $args
@return Void
BeforeUpdate callback find and insert current highest weight value + 1 if it is null