Development

Changeset 1381

You must first sign up to be able to contribute.

Changeset 1381

Show
Ignore:
Timestamp:
05/23/06 20:26:26 (3 years ago)
Author:
fabien
Message:

added constants expansion for image dir and filename in file uploading (admin generator)

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/data/generator/sfPropelAdmin/default/template/actions/actions.class.php

    r1368 r1381  
    9595<?php $input_type = $this->getParameterValue('edit.fields.'.$column->getName().'.type') ?> 
    9696<?php if ($input_type == 'admin_input_upload_tag'): ?> 
    97 <?php $upload_dir = $this->getParameterValue('edit.fields.'.$column->getName().'.upload_dir') ?> 
    98       $currentFile = sfConfig::get('sf_upload_dir').'/<?php echo $upload_dir ?>/'.$this-><?php echo $this->getSingularName() ?>->get<?php echo $column->getPhpName() ?>(); 
     97<?php $upload_dir = $this->replaceConstants($this->getParameterValue('edit.fields.'.$column->getName().'.upload_dir')) ?> 
     98      $currentFile = sfConfig::get('sf_upload_dir')."/<?php echo $upload_dir ?>/".$this-><?php echo $this->getSingularName() ?>->get<?php echo $column->getPhpName() ?>(); 
    9999      if (is_file($currentFile)) 
    100100      { 
     
    142142<?php endif; ?> 
    143143<?php if ($input_type == 'admin_input_upload_tag'): ?> 
    144 <?php $upload_dir = $this->getParameterValue('edit.fields.'.$column->getName().'.upload_dir') ?> 
    145     $currentFile = sfConfig::get('sf_upload_dir').'/<?php echo $upload_dir ?>/'.$this-><?php echo $this->getSingularName() ?>->get<?php echo $column->getPhpName() ?>(); 
     144<?php $upload_dir = $this->replaceConstants($this->getParameterValue('edit.fields.'.$column->getName().'.upload_dir')) ?> 
     145    $currentFile = sfConfig::get('sf_upload_dir')."/<?php echo $upload_dir ?>/".$this-><?php echo $this->getSingularName() ?>->get<?php echo $column->getPhpName() ?>(); 
    146146    if (!$this->getRequest()->hasErrors() && isset($<?php echo $this->getSingularName() ?>['<?php echo $name ?>_remove'])) 
    147147    { 
     
    160160<?php endif; ?> 
    161161<?php if ($input_type == 'admin_input_upload_tag'): ?> 
     162<?php if ($this->getParameterValue('edit.fields.'.$column->getName().'.filename')): ?> 
     163      $fileName = '<?php echo str_replace("'", "\\'", $this->getParameterValue('edit.fields.'.$column->getName().'.filename')) ?>'; 
     164<?php else: ?> 
    162165      $fileName = md5($this->getRequest()->getFileName('<?php echo $this->getSingularName() ?>[<?php echo $name ?>]').time()); 
     166<?php endif ?> 
    163167      $ext = $this->getRequest()->getFileExtension('<?php echo $this->getSingularName() ?>[<?php echo $name ?>]'); 
    164168      if (is_file($currentFile)) 
     
    166170        unlink($currentFile); 
    167171      } 
    168       $this->getRequest()->moveFile('<?php echo $this->getSingularName() ?>[<?php echo $name ?>]', sfConfig::get('sf_upload_dir').'/<?php echo $upload_dir ?>/'.$fileName.$ext); 
     172      $this->getRequest()->moveFile('<?php echo $this->getSingularName() ?>[<?php echo $name ?>]', sfConfig::get('sf_upload_dir')."/<?php echo $upload_dir ?>/".$fileName.$ext); 
    169173      $this-><?php echo $this->getSingularName() ?>->set<?php echo $column->getPhpName() ?>($fileName.$ext); 
    170174<?php elseif ($type == CreoleTypes::DATE || $type == CreoleTypes::TIMESTAMP): ?> 
  • trunk/lib/generator/sfPropelAdminGenerator.class.php

    r1370 r1381  
    502502  } 
    503503 
     504  public function replaceConstants($value) 
     505  { 
     506    // find %%xx%% strings 
     507    preg_match_all('/%%([^%]+)%%/', $value, $matches, PREG_PATTERN_ORDER); 
     508    $this->params['tmp']['display'] = array(); 
     509    foreach ($matches[1] as $name) 
     510    { 
     511      $this->params['tmp']['display'][] = $name; 
     512    } 
     513 
     514    foreach ($this->getColumns('tmp.display') as $column) 
     515    { 
     516      $value = str_replace('%%'.$column->getName().'%%', '{$this->'.$this->getSingularName().'->get'.$column->getPhpName().'()}', $value); 
     517    } 
     518 
     519    return $value; 
     520  } 
     521 
    504522  public function getColumnListTag($column, $params = array()) 
    505523  { 

The Sensio Labs Network

Since 1998, Sensio Labs has been promoting the Open-Source software movement by providing quality web application development, training, consulting, and supporting several large Open-Source projects.