/** * Almacena los parámetros de configuración, además dependiendo de * estos se modifican las relaciones y las reglas de validación del * model. * * @param Model &$model Model que actua como este Behavior. * @param array $config Opciones de configuración. * @return void * @access public */ function setup(&$model, $config) { if (empty($config)) { $config['Picture'] = array('limit' => 5, 'allowed' => array('image/gif', 'image/jpeg', 'image/png')); } $hasOne = array(); $hasMany = array(); $has = compact('hasOne', 'hasMany'); //$config[$model->alias]=normalizeAllowedConfig($config); foreach ($config as $alias => $settings) { $settings = normalizeAllowedConfig($settings); if (is_numeric($alias)) { $alias = $settings; $settings = array(); } $settings = am($this->__default, $settings); $flags = array(); if (!empty($settings['flags'])) { $settings['flags'] = $this->__flags($model, $settings['flags']); } $this->settings[$model->name][$alias] = $settings; if (!empty($settings['copies'])) { foreach ($settings['copies'] as $name => $copy) { $settings['copies'][$name] = am(array('width' => null, 'height' => null), $copy); } } #pr('Medium.' . $model->name . '.' . $alias); #pr($settings); Configure::write('Medium.' . $model->name . '.' . $alias, $settings); $has[$settings['limit'] == 1 ? 'hasOne' : 'hasMany'][$alias] = array('className' => 'Media.Medium', 'conditions' => array($alias . '.model' => $model->name, $alias . '.alias' => $alias), 'foreignKey' => 'foreign_key', 'limit' => $settings['limit'], 'order' => $settings['limit'] == 1 ? null : array($alias . '.order' => 'ASC'), 'dependent' => true); if ($settings['required']) { $model->validate[$alias]['required'] = array('rule' => array('atLeastFiles', $alias, $settings['required']), 'required' => true, 'alowEmpty' => false, 'message' => '[:error-required-files:]'); } if ($settings['limit']) { $model->validate[$alias]['limit'] = array('rule' => array('atMostFiles', $alias, $settings['limit']), 'message' => '[:error-limit-files-allowed:]'); } $this->settings[$model->name][$alias] = $settings; } $model->bindModel($has, false); foreach ($config as $alias => $settings) { $model->{$alias}->model = $model->name; } }
function beforeValidate() { if (!$this->isFolder()) { if (!$this->loadUploader()) { return false; } $this->Uploader =& new Uploader($this->data['Upload']); if (!$this->Uploader->uploaded) { $this->invalidate('name', $this->Uploader->error); return false; } #$this->log(Configure::read("loggedUser"), 'debug'); $this->set(array('name' => $this->Uploader->file_src_name_body, 'extension' => $this->Uploader->file_src_name_ext, 'size' => $this->Uploader->file_src_size, 'mime' => $this->Uploader->file_src_mime, 'path' => str_replace(Configure::read("Media.Upload.dir") . "/", "", $_REQUEST['folder']), 'width' => $this->Uploader->image_src_x, 'height' => $this->Uploader->image_src_y, 'created_by' => Configure::read("loggedUser.User.id"), 'modified_by' => Configure::read("loggedUser.User.id"))); $settings = normalizeAllowedConfig(Configure::read('Media.Upload.config')); #$this->log($settings,'debug'); $this->validate['mime']['is-allowed']['rule'][1] = $settings['allowed']; $this->validate['size']['max_file_size']['rule'][2] = $settings['max_file_size'] * 1048576; return true; } else { unset($this->validate['mime']); } //$this->log($this->data, 'debug'); return true; }