All pastes #2056986 Raw Edit

Miscellany

public text v1 · immutable
#2056986 ·published 2011-05-11 19:47 UTC
rendered paste body
class ProductGalleryForm extends BaseProductGalleryForm
{
  public function configure()
  {
    unset(
      #$this[''],
      $this['created_at'],
      $this['updated_at']
    );

    $uploadDirName  = sfConfig::get('sf_upload_dir').'/products';
    $picPath       = '/uploads/products'.'/'.$this->getObject()->getPic();;

    $this->setWidget('product_id', new sfWidgetFormInputHidden());
    $this->setDefault('product_id', $this->getObject()->Owner->getId());

    $this->setWidget('pic', new sfWidgetFormInputFileEditable(array(
        'label'     => 'ExtraPic',
        'file_src'  => $picPath,
        'is_image'  => true,
        'edit_mode' => ($this->getObject()->getPic() AND !$this->getObject()->isNew() ? true: false),
        'template'  => '<table><tr>
          <td>
            %input% 
          </td>
          <td>
            <a rel="extraPics" href="'.$picPath.'" target="_blank"><img
            src="'.thumbnail_path('uploads/products/'.$this->getObject()->getPic(), 50, 50, 'products').'" /></a>
          </tr>
          </table>',
    )));

    $this->setValidator(
      'pic', new sfValidatorFile(array(
        'required'   => false,
        'path'       => $uploadDirName,
        'max_size' => '10240000', // bytes (1MB)
        'mime_types' => array(
          'image/gif',
          'image/jpeg',
          'image/png'
        )
    )));


    if ($this->object->exists())
    {
      $this->widgetSchema['delete'] = new sfWidgetFormInputCheckbox();
      $this->validatorSchema['delete'] = new sfValidatorPass();
    }

    $this->validatorSchema->setOption('allow_extra_fields', true);
    $this->validatorSchema->setOption('filter_extra_fields', false);

  }

  private function getSizeName($size=0, $postfix_id=0)
  {
    $size_postfix_names = array('byte','Kb','Mb','Gb','Tb');
    if ($size < 1024)
     return $size.' '.$size_postfix_names[$postfix_id];
    $postfix_id++;
    return getSizeName(round($size/1024,1), $postfix_id);
  }

}