library/Garp/Model/Behavior/Weighable.php
public function findHighestWeight(Garp_Model $model, $foreignKey, array $modelRelationConfig) {
        $foreignKeyColumn = $model->getAdapter()->quoteIdentifier($modelRelationConfig[self::FOREIGN_KEY_COLUMN_KEY]);
        $weightColumn     = $model->getAdapter()->quoteIdentifier($modelRelationConfig[self::WEIGHT_COLUMN_KEY]);
        $select = $model->select()
                        ->from($model->getName(), array('max' => 'MAX('.$weightColumn.')'))
                        ->where($foreignKeyColumn.' = ?', $foreignKey)
                        ;

        $result = $model->fetchRow($select);
        if ($result && $result->max) {
            return $result->max;
        }
        return 0;
    }
public function findHighestWeight(Garp_Model $model, $foreignKey, array $modelRelationConfig) {
        $foreignKeyColumn = $model->getAdapter()->quoteIdentifier($modelRelationConfig[self::FOREIGN_KEY_COLUMN_KEY]);
        $weightColumn     = $model->getAdapter()->quoteIdentifier($modelRelationConfig[self::WEIGHT_COLUMN_KEY]);
        $select = $model->select()
                        ->from($model->getName(), array('max' => 'MAX('.$weightColumn.')'))
                        ->where($foreignKeyColumn.' = ?', $foreignKey)
                        ;

        $result = $model->fetchRow($select);
        if ($result && $result->max) {
            return $result->max;
        }
        return 0;
    }
public function findHighestWeight ( Garp_Model $ model , $ foreignKey , array $ modelRelationConfig ) { $ foreignKeyColumn = $ model -> getAdapter ( ) -> quoteIdentifier ( $ modelRelationConfig [ self :: FOREIGN_KEY_COLUMN_KEY ] ) ; $ weightColumn = $ model -> getAdapter ( ) -> quoteIdentifier ( $ modelRelationConfig [ self :: WEIGHT_COLUMN_KEY ] ) ; $ select = $ model -> select ( ) -> from ( $ model -> getName ( ) , array ( 'max' => 'MAX(' . $ weightColumn . ')' ) ) -> where ( $ foreignKeyColumn . ' = ?' , $ foreignKey ) ; $ result = $ model -> fetchRow ( $ select ) ; if ( $ result && $ result -> max ) { return $ result -> max ; } return 0 ; }
Find the highest weight value for a certain relationship with a foreign key
@param Garp_Model $model
@param Int $foreignKey
@param Array $modelRelationConfig
@return Int
Find the highest weight value for a certain relationship with a foreign key