<?php
/*
* This file is part of the pwp package.
* (c) 2009-2010 Victor Rad' <victor.v.rad[at]gmail.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
/**
* Images form.
*
* @package form
* @subpackage Images
* @author Victor Rad'
*/
class ImagesForm extends BaseImagesForm
{
public function configure()
{
$this->widgetSchema['image'] = new sfWidgetFormInputFileEditable(array(
'label' => 'Project Image',
'file_src' => !$this->isNew() ? $this->getObject()->buildPathImage('120x0') : '',
'is_image' => true,
'edit_mode' => !$this->isNew(),
'template' => '<div>%file%<br/>%input%</div>'
));
$this->validatorSchema['image'] = new sfValidatorFile(array(
'required' => false,
'mime_types' => 'web_images'
));
}
/**
* Saves all copies of files of images
*
* @param <type> $con
* @return <type>
*/
public function save($con = null)
{
// prepare data
$imagesPath = sfConfig::get('app_images_path');
$image = $this->getValue('image');
unset($this->values['image']);
// save image Doctrine_Record
$object = parent::save($con);
// save image file
if ($image) {
$sizes = DFactory::get('Images')->getRecord()->getImageSizes();
$image->save($object->buildPathImage('0x0', 'fs'));
// resize all image copies
foreach ($sizes as $size) {
if ('0x0' != $size) {
$object->buildPathImage($size, 'fs', true);
}
}
}
return $object;
}
}