library/Garp/Model/Behavior/Weighable.php
public function beforeInsert(&$args) {
        $model = $args[0];
        $data = &$args[1];
        foreach ($this->_relationConfig as $foreignModel => $modelRelationConfig) {
            $foreignKey = $modelRelationConfig[self::FOREIGN_KEY_COLUMN_KEY];
            // only act if the foreign key column is filled
            if (!empty($data[$foreignKey])) {
                $maxWeight = $this->findHighestWeight($model, $data[$foreignKey], $modelRelationConfig);
                $data[$modelRelationConfig[self::WEIGHT_COLUMN_KEY]] = ($maxWeight+1);
            }
        }
    }
public function beforeInsert(&$args) {
        $model = $args[0];
        $data = &$args[1];
        foreach ($this->_relationConfig as $foreignModel => $modelRelationConfig) {
            $foreignKey = $modelRelationConfig[self::FOREIGN_KEY_COLUMN_KEY];
            // only act if the foreign key column is filled
            if (!empty($data[$foreignKey])) {
                $maxWeight = $this->findHighestWeight($model, $data[$foreignKey], $modelRelationConfig);
                $data[$modelRelationConfig[self::WEIGHT_COLUMN_KEY]] = ($maxWeight+1);
            }
        }
    }
public function beforeInsert ( & $ args ) { $ model = $ args [ 0 ] ; $ data = & $ args [ 1 ] ; foreach ( $ this -> _relationConfig as $ foreignModel => $ modelRelationConfig ) { $ foreignKey = $ modelRelationConfig [ self :: FOREIGN_KEY_COLUMN_KEY ] ; // only act if the foreign key column is filled if ( ! empty ( $ data [ $ foreignKey ] ) ) { $ maxWeight = $ this -> findHighestWeight ( $ model , $ data [ $ foreignKey ] , $ modelRelationConfig ) ; $ data [ $ modelRelationConfig [ self :: WEIGHT_COLUMN_KEY ] ] = ( $ maxWeight + 1 ) ; } } }
BeforeInsert callback, find and insert the current highest 'weight' value + 1
in the weight column
@param Array $args
@return Void
BeforeInsert callback find and insert the current highest weight value + 1 in the weight column