<?php

require_once dirname(__FILE__).'/../lib/offerGeneratorConfiguration.class.php';
require_once dirname(__FILE__).'/../lib/offerGeneratorHelper.class.php';

/**
 * offer actions.
 *
 * @package    sf
 * @subpackage offer
 * @author     Atma
 * @version    SVN: $Id: actions.class.php 23810 2009-11-12 11:07:44Z Kris.Wallsmith $
 */
class offerActions extends autoOfferActions
{
    public function executeUpdate(sfWebRequest $request)
    {
        parent::executeUpdate($request);
        return sfView::NONE;
    }
    public function executeCreate(sfWebRequest $request)
    {
        parent::executeCreate($request);
        return sfView::NONE;
    }
    protected function processForm(sfWebRequest $request, sfForm $form)
    {
        $form->bind($request->getParameter($form->getName()), $request->getFiles($form->getName()));
        if ($form->isValid())
        {
            try
            {
                $offer = $form->save();
                echo $this->getPartial('cat/struct_form', array('form' => new OfferForm($offer), 'parent_id' => Cat::$parentId, 'link' => '/arm/offer' . ($offer ? '/' . $offer->getId() : '')));
                return sfView::NONE;
            }
            catch (Doctrine_Validator_Exception $e)
            {
                $errorStack = $form->getObject()->getErrorStack();
                return sfView::NONE;
            }
            $this->dispatcher->notify(new sfEvent($this, 'admin.save_object', array('object' => $offer)));
        }
        echo $this->getPartial('cat/struct_form', array('form' => $form, 'parent_id' => Cat::$parentId, 'link' => '/arm/offer' . ($this->offer && $this->offer->getId() ? '/' . $this->offer->getId() : '')));
    }
}
