<?php

/**
 * Offer
 * 
 * This class has been auto-generated by the Doctrine ORM Framework
 * 
 * @package    sf
 * @subpackage model
 * @author     Atma
 * @version    SVN: $Id: Builder.php 7490 2010-03-29 19:53:27Z jwage $
 */
class Offer extends BaseOffer
{
    static public $quantity_type_select_values = array('m2' => 'м²', 'sheet' => 'лист', 'piece' => 'шт.');
    public function save(Doctrine_Connection $conn = null)
    {
        if($this->getQuantityType()){
            $this->setQuantityType(mb_strtolower($this->getQuantityType()));
        }

        parent::save($conn);

        $offer_count = Doctrine_Query::create()
            ->from("Offer")
            ->where("product_id = ?", $this->getProductId())
            ->andWhere("is_delete = 0")
            ->count();

        Doctrine_Query::create()
            ->update("Product")
            ->set("offer_count", $offer_count)
            ->where("id = ?", $this->getProductId())
            ->execute();
    }
    public function getQuantityTypeValue($culture)
    {
        $quantity_type = $this['Translation'][$culture]['quantity_type'];
        if ($this['quantity_type_select']) {
            $quantity_type = (isset(Offer::$quantity_type_select_values[$this['quantity_type_select']]) ? Offer::$quantity_type_select_values[$this['quantity_type_select']] : '');
        }
        return $quantity_type;
    }
}
