public function setup(Model $model, $settings = array()) {
        if (!$settings) {
            return;
        }

        if (!isset($this->_columns[$model->alias])) {
            $this->_columns[$model->alias] = array();
        }

        foreach ($settings as $field => $attachment) {
            $attachment = Set::merge($this->_defaultSettings, $attachment + array(
                'dbColumn' => $field
            ));

            // Fix dbColumn if they set it to empty
            if (!$attachment['dbColumn']) {
                $attachment['dbColumn'] = $field;
            }

            $columns = array($attachment['dbColumn'] => $field);

            // Set defaults if not defined
            if (!$attachment['tempDir']) {
                $attachment['tempDir'] = TMP;
            }

            if (!$attachment['uploadDir']) {
                $attachment['finalPath'] = $attachment['finalPath'] ?: '/files/uploads/';
                $attachment['uploadDir'] = WWW_ROOT . $attachment['finalPath'];
            }

            // Merge transform settings with defaults
            if ($attachment['transforms']) {
                foreach ($attachment['transforms'] as $dbColumn => $transform) {
                    $transform = Set::merge($this->_transformSettings, $transform + array(
                        'uploadDir' => $attachment['uploadDir'],
                        'finalPath' => $attachment['finalPath'],
                        'dbColumn' => $dbColumn
                    ));

                    if ($transform['self']) {
                        $transform['dbColumn'] = $attachment['dbColumn'];
                    }

                    $columns[$transform['dbColumn']] = $field;
                    $attachment['transforms'][$dbColumn] = $transform;
                }
            }

            $this->settings[$model->alias][$field] = $attachment;
            $this->_columns[$model->alias] += $columns;
        }
    }
public function setup(Model $model, $settings = array()) {
        if (!$settings) {
            return;
        }

        if (!isset($this->_columns[$model->alias])) {
            $this->_columns[$model->alias] = array();
        }

        foreach ($settings as $field => $attachment) {
            $attachment = Set::merge($this->_defaultSettings, $attachment + array(
                'dbColumn' => $field
            ));

            // Fix dbColumn if they set it to empty
            if (!$attachment['dbColumn']) {
                $attachment['dbColumn'] = $field;
            }

            $columns = array($attachment['dbColumn'] => $field);

            // Set defaults if not defined
            if (!$attachment['tempDir']) {
                $attachment['tempDir'] = TMP;
            }

            if (!$attachment['uploadDir']) {
                $attachment['finalPath'] = $attachment['finalPath'] ?: '/files/uploads/';
                $attachment['uploadDir'] = WWW_ROOT . $attachment['finalPath'];
            }

            // Merge transform settings with defaults
            if ($attachment['transforms']) {
                foreach ($attachment['transforms'] as $dbColumn => $transform) {
                    $transform = Set::merge($this->_transformSettings, $transform + array(
                        'uploadDir' => $attachment['uploadDir'],
                        'finalPath' => $attachment['finalPath'],
                        'dbColumn' => $dbColumn
                    ));

                    if ($transform['self']) {
                        $transform['dbColumn'] = $attachment['dbColumn'];
                    }

                    $columns[$transform['dbColumn']] = $field;
                    $attachment['transforms'][$dbColumn] = $transform;
                }
            }

            $this->settings[$model->alias][$field] = $attachment;
            $this->_columns[$model->alias] += $columns;
        }
    }
public function setup ( Model $ model , $ settings = array ( ) ) { if ( ! $ settings ) { return ; } if ( ! isset ( $ this -> _columns [ $ model -> alias ] ) ) { $ this -> _columns [ $ model -> alias ] = array ( ) ; } foreach ( $ settings as $ field => $ attachment ) { $ attachment = Set :: merge ( $ this -> _defaultSettings , $ attachment + array ( 'dbColumn' => $ field ) ) ; // Fix dbColumn if they set it to empty if ( ! $ attachment [ 'dbColumn' ] ) { $ attachment [ 'dbColumn' ] = $ field ; } $ columns = array ( $ attachment [ 'dbColumn' ] => $ field ) ; // Set defaults if not defined if ( ! $ attachment [ 'tempDir' ] ) { $ attachment [ 'tempDir' ] = TMP ; } if ( ! $ attachment [ 'uploadDir' ] ) { $ attachment [ 'finalPath' ] = $ attachment [ 'finalPath' ] ? : '/files/uploads/' ; $ attachment [ 'uploadDir' ] = WWW_ROOT . $ attachment [ 'finalPath' ] ; } // Merge transform settings with defaults if ( $ attachment [ 'transforms' ] ) { foreach ( $ attachment [ 'transforms' ] as $ dbColumn => $ transform ) { $ transform = Set :: merge ( $ this -> _transformSettings , $ transform + array ( 'uploadDir' => $ attachment [ 'uploadDir' ] , 'finalPath' => $ attachment [ 'finalPath' ] , 'dbColumn' => $ dbColumn ) ) ; if ( $ transform [ 'self' ] ) { $ transform [ 'dbColumn' ] = $ attachment [ 'dbColumn' ] ; } $ columns [ $ transform [ 'dbColumn' ] ] = $ field ; $ attachment [ 'transforms' ] [ $ dbColumn ] = $ transform ; } } $ this -> settings [ $ model -> alias ] [ $ field ] = $ attachment ; $ this -> _columns [ $ model -> alias ] += $ columns ; } }
Save attachment settings.

@param Model $model
@param array $settings
Save attachment settings .